Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] tda8261: don't use set_state/get_state callbacks

Those callbacks are meant to be used only on some very specific
cases. There's absolutely no need to do that at tda8261, as
the only parameter that it allows to be set/get is the frequency.

So, use the standard get_params() and get_frequency() kABI
ops.

There's no need to touch at any bridge driver, as all interactions
are done via the macros at tda8261_cfg.h.

Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

+63 -99
+52 -73
drivers/media/dvb-frontends/tda8261.c
··· 83 83 static const u32 div_tab[] = { 2000, 1000, 500, 250, 125 }; /* kHz */ 84 84 static const u8 ref_div[] = { 0x00, 0x01, 0x02, 0x05, 0x07 }; 85 85 86 - static int tda8261_get_state(struct dvb_frontend *fe, 87 - enum tuner_param param, 88 - struct tuner_state *tstate) 86 + static int tda8261_get_frequency(struct dvb_frontend *fe, u32 *frequency) 89 87 { 90 88 struct tda8261_state *state = fe->tuner_priv; 91 - int err = 0; 92 89 93 - switch (param) { 94 - case DVBFE_TUNER_FREQUENCY: 95 - tstate->frequency = state->frequency; 96 - break; 97 - case DVBFE_TUNER_BANDWIDTH: 98 - tstate->bandwidth = 40000000; /* FIXME! need to calculate Bandwidth */ 99 - break; 100 - default: 101 - pr_err("%s: Unknown parameter (param=%d)\n", __func__, param); 102 - err = -EINVAL; 103 - break; 104 - } 90 + *frequency = state->frequency; 105 91 106 - return err; 92 + return 0; 107 93 } 108 94 109 - static int tda8261_set_state(struct dvb_frontend *fe, 110 - enum tuner_param param, 111 - struct tuner_state *tstate) 95 + static int tda8261_set_params(struct dvb_frontend *fe) 112 96 { 97 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 113 98 struct tda8261_state *state = fe->tuner_priv; 114 99 const struct tda8261_config *config = state->config; 115 100 u32 frequency, N, status = 0; 116 101 u8 buf[4]; 117 102 int err = 0; 118 103 119 - if (param & DVBFE_TUNER_FREQUENCY) { 120 - /** 121 - * N = Max VCO Frequency / Channel Spacing 122 - * Max VCO Frequency = VCO frequency + (channel spacing - 1) 123 - * (to account for half channel spacing on either side) 124 - */ 125 - frequency = tstate->frequency; 126 - if ((frequency < 950000) || (frequency > 2150000)) { 127 - pr_warn("%s: Frequency beyond limits, frequency=%d\n", __func__, frequency); 128 - return -EINVAL; 129 - } 130 - N = (frequency + (div_tab[config->step_size] - 1)) / div_tab[config->step_size]; 131 - pr_debug("%s: Step size=%d, Divider=%d, PG=0x%02x (%d)\n", 132 - __func__, config->step_size, div_tab[config->step_size], N, N); 133 - 134 - buf[0] = (N >> 8) & 0xff; 135 - buf[1] = N & 0xff; 136 - buf[2] = (0x01 << 7) | ((ref_div[config->step_size] & 0x07) << 1); 137 - 138 - if (frequency < 1450000) 139 - buf[3] = 0x00; 140 - else if (frequency < 2000000) 141 - buf[3] = 0x40; 142 - else if (frequency < 2150000) 143 - buf[3] = 0x80; 144 - 145 - /* Set params */ 146 - if ((err = tda8261_write(state, buf)) < 0) { 147 - pr_err("%s: I/O Error\n", __func__); 148 - return err; 149 - } 150 - /* sleep for some time */ 151 - pr_debug("%s: Waiting to Phase LOCK\n", __func__); 152 - msleep(20); 153 - /* check status */ 154 - if ((err = tda8261_get_status(fe, &status)) < 0) { 155 - pr_err("%s: I/O Error\n", __func__); 156 - return err; 157 - } 158 - if (status == 1) { 159 - pr_debug("%s: Tuner Phase locked: status=%d\n", __func__, status); 160 - state->frequency = frequency; /* cache successful state */ 161 - } else { 162 - pr_debug("%s: No Phase lock: status=%d\n", __func__, status); 163 - } 164 - } else { 165 - pr_err("%s: Unknown parameter (param=%d)\n", __func__, param); 104 + /* 105 + * N = Max VCO Frequency / Channel Spacing 106 + * Max VCO Frequency = VCO frequency + (channel spacing - 1) 107 + * (to account for half channel spacing on either side) 108 + */ 109 + frequency = c->frequency; 110 + if ((frequency < 950000) || (frequency > 2150000)) { 111 + pr_warn("%s: Frequency beyond limits, frequency=%d\n", 112 + __func__, frequency); 166 113 return -EINVAL; 114 + } 115 + N = (frequency + (div_tab[config->step_size] - 1)) / div_tab[config->step_size]; 116 + pr_debug("%s: Step size=%d, Divider=%d, PG=0x%02x (%d)\n", 117 + __func__, config->step_size, div_tab[config->step_size], N, N); 118 + 119 + buf[0] = (N >> 8) & 0xff; 120 + buf[1] = N & 0xff; 121 + buf[2] = (0x01 << 7) | ((ref_div[config->step_size] & 0x07) << 1); 122 + 123 + if (frequency < 1450000) 124 + buf[3] = 0x00; 125 + else if (frequency < 2000000) 126 + buf[3] = 0x40; 127 + else if (frequency < 2150000) 128 + buf[3] = 0x80; 129 + 130 + /* Set params */ 131 + err = tda8261_write(state, buf); 132 + if (err < 0) { 133 + pr_err("%s: I/O Error\n", __func__); 134 + return err; 135 + } 136 + /* sleep for some time */ 137 + pr_debug("%s: Waiting to Phase LOCK\n", __func__); 138 + msleep(20); 139 + /* check status */ 140 + if ((err = tda8261_get_status(fe, &status)) < 0) { 141 + pr_err("%s: I/O Error\n", __func__); 142 + return err; 143 + } 144 + if (status == 1) { 145 + pr_debug("%s: Tuner Phase locked: status=%d\n", __func__, 146 + status); 147 + state->frequency = frequency; /* cache successful state */ 148 + } else { 149 + pr_debug("%s: No Phase lock: status=%d\n", __func__, status); 167 150 } 168 151 169 152 return 0; ··· 165 182 166 183 .info = { 167 184 .name = "TDA8261", 168 - // .tuner_name = NULL, 169 185 .frequency_min = 950000, 170 186 .frequency_max = 2150000, 171 187 .frequency_step = 0 172 188 }, 173 189 174 - .set_state = tda8261_set_state, 175 - .get_state = tda8261_get_state, 190 + .set_params = tda8261_set_params, 191 + .get_frequency = tda8261_get_frequency, 176 192 .get_status = tda8261_get_status, 177 193 .release = tda8261_release 178 194 }; ··· 192 210 fe->ops.tuner_ops = tda8261_ops; 193 211 194 212 fe->ops.tuner_ops.info.frequency_step = div_tab[config->step_size]; 195 - // fe->ops.tuner_ops.tuner_name = &config->buf; 196 213 197 - // printk("%s: Attaching %s TDA8261 8PSK/QPSK tuner\n", 198 - // __func__, fe->ops.tuner_ops.tuner_name); 199 214 pr_info("%s: Attaching TDA8261 8PSK/QPSK tuner\n", __func__); 200 215 201 216 return fe;
+11 -26
drivers/media/dvb-frontends/tda8261_cfg.h
··· 21 21 { 22 22 struct dvb_frontend_ops *frontend_ops = &fe->ops; 23 23 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; 24 - struct tuner_state t_state; 25 24 int err = 0; 26 25 27 - if (tuner_ops->get_state) { 28 - err = tuner_ops->get_state(fe, DVBFE_TUNER_FREQUENCY, &t_state); 26 + if (tuner_ops->get_frequency) { 27 + err = tuner_ops->get_frequency(fe, frequency); 29 28 if (err < 0) { 30 - printk("%s: Invalid parameter\n", __func__); 29 + pr_err("%s: Invalid parameter\n", __func__); 31 30 return err; 32 31 } 33 - *frequency = t_state.frequency; 34 - printk("%s: Frequency=%d\n", __func__, t_state.frequency); 32 + pr_debug("%s: Frequency=%d\n", __func__, *frequency); 35 33 } 36 34 return 0; 37 35 } ··· 38 40 { 39 41 struct dvb_frontend_ops *frontend_ops = &fe->ops; 40 42 struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; 41 - struct tuner_state t_state; 43 + struct dtv_frontend_properties *c = &fe->dtv_property_cache; 42 44 int err = 0; 43 45 44 - t_state.frequency = frequency; 45 - 46 - if (tuner_ops->set_state) { 47 - err = tuner_ops->set_state(fe, DVBFE_TUNER_FREQUENCY, &t_state); 46 + if (tuner_ops->set_params) { 47 + err = tuner_ops->set_params(fe); 48 48 if (err < 0) { 49 - printk("%s: Invalid parameter\n", __func__); 49 + pr_err("%s: Invalid parameter\n", __func__); 50 50 return err; 51 51 } 52 52 } 53 - printk("%s: Frequency=%d\n", __func__, t_state.frequency); 53 + pr_debug("%s: Frequency=%d\n", __func__, c->frequency); 54 54 return 0; 55 55 } 56 56 57 57 static int tda8261_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth) 58 58 { 59 - struct dvb_frontend_ops *frontend_ops = &fe->ops; 60 - struct dvb_tuner_ops *tuner_ops = &frontend_ops->tuner_ops; 61 - struct tuner_state t_state; 62 - int err = 0; 59 + /* FIXME! need to calculate Bandwidth */ 60 + *bandwidth = 40000000; 63 61 64 - if (tuner_ops->get_state) { 65 - err = tuner_ops->get_state(fe, DVBFE_TUNER_BANDWIDTH, &t_state); 66 - if (err < 0) { 67 - printk("%s: Invalid parameter\n", __func__); 68 - return err; 69 - } 70 - *bandwidth = t_state.bandwidth; 71 - printk("%s: Bandwidth=%d\n", __func__, t_state.bandwidth); 72 - } 73 62 return 0; 74 63 }