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

V4L/DVB (6385): Adds the capability of configuring tea5767 support

tea5767 has several possible configurations. Before the patch, the
driver were assuming the more common configuration. However, some newer
cards, like MSI @nyware Master requires other configurations, like
de-activating a gpio port and changing chip Xtal.

This patch adds the capability of altering device configuration at
runtime. This may also be used later to activate some features like
auto-mute when signal is weak.

Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>

+81 -27
+62 -27
drivers/media/video/tea5767.c
··· 22 22 23 23 #define PREFIX "tea5767 " 24 24 25 - struct tea5767_priv { 26 - struct tuner_i2c_props i2c_props; 25 + /*****************************************************************************/ 27 26 28 - u32 frequency; 27 + struct tea5767_priv { 28 + struct tuner_i2c_props i2c_props; 29 + u32 frequency; 30 + struct tea5767_ctrl ctrl; 29 31 }; 30 32 31 33 /*****************************************************************************/ ··· 129 127 /* Reserved for future extensions */ 130 128 #define TEA5767_RESERVED_MASK 0xff 131 129 132 - enum tea5767_xtal_freq { 133 - TEA5767_LOW_LO_32768 = 0, 134 - TEA5767_HIGH_LO_32768 = 1, 135 - TEA5767_LOW_LO_13MHz = 2, 136 - TEA5767_HIGH_LO_13MHz = 3, 137 - }; 138 - 139 - 140 130 /*****************************************************************************/ 141 131 142 - static void tea5767_status_dump(unsigned char *buffer) 132 + static void tea5767_status_dump(struct tea5767_priv *priv, 133 + unsigned char *buffer) 143 134 { 144 135 unsigned int div, frq; 145 136 ··· 148 153 149 154 div = ((buffer[0] & 0x3f) << 8) | buffer[1]; 150 155 151 - switch (TEA5767_HIGH_LO_32768) { 156 + switch (priv->ctrl.xtal_freq) { 152 157 case TEA5767_HIGH_LO_13MHz: 153 158 frq = (div * 50000 - 700000 - 225000) / 4; /* Freq in KHz */ 154 159 break; ··· 197 202 198 203 tuner_dbg("radio freq = %d.%03d MHz\n", frq/16000,(frq/16)%1000); 199 204 200 - /* Rounds freq to next decimal value - for 62.5 KHz step */ 201 - /* frq = 20*(frq/16)+radio_frq[frq%16]; */ 205 + buffer[2] = 0; 202 206 203 - buffer[2] = TEA5767_PORT1_HIGH; 204 - buffer[3] = TEA5767_PORT2_HIGH | TEA5767_HIGH_CUT_CTRL | 205 - TEA5767_ST_NOISE_CTL | TEA5767_JAPAN_BAND; 206 - buffer[4] = 0; 207 + if (priv->ctrl.port1) 208 + buffer[2] |= TEA5767_PORT1_HIGH; 207 209 208 210 if (params->audmode == V4L2_TUNER_MODE_MONO) { 209 211 tuner_dbg("TEA5767 set to mono\n"); ··· 209 217 tuner_dbg("TEA5767 set to stereo\n"); 210 218 } 211 219 212 - /* Should be replaced */ 213 - switch (TEA5767_HIGH_LO_32768) { 220 + 221 + buffer[3] = 0; 222 + 223 + if (priv->ctrl.port2) 224 + buffer[3] |= TEA5767_PORT2_HIGH; 225 + 226 + if (priv->ctrl.high_cut) 227 + buffer[3] |= TEA5767_HIGH_CUT_CTRL; 228 + 229 + if (priv->ctrl.st_noise) 230 + buffer[3] |= TEA5767_ST_NOISE_CTL; 231 + 232 + if (priv->ctrl.soft_mute) 233 + buffer[3] |= TEA5767_SOFT_MUTE; 234 + 235 + if (priv->ctrl.japan_band) 236 + buffer[3] |= TEA5767_JAPAN_BAND; 237 + 238 + buffer[4] = 0; 239 + 240 + if (priv->ctrl.deemph_75) 241 + buffer[4] |= TEA5767_DEEMPH_75; 242 + 243 + if (priv->ctrl.pllref) 244 + buffer[4] |= TEA5767_PLLREF_ENABLE; 245 + 246 + 247 + /* Rounds freq to next decimal value - for 62.5 KHz step */ 248 + /* frq = 20*(frq/16)+radio_frq[frq%16]; */ 249 + 250 + switch (priv->ctrl.xtal_freq) { 214 251 case TEA5767_HIGH_LO_13MHz: 215 252 tuner_dbg("radio HIGH LO inject xtal @ 13 MHz\n"); 216 253 buffer[2] |= TEA5767_HIGH_LO_INJECT; 217 - buffer[4] |= TEA5767_PLLREF_ENABLE; 218 254 div = (frq * (4000 / 16) + 700000 + 225000 + 25000) / 50000; 219 255 break; 220 256 case TEA5767_LOW_LO_13MHz: 221 257 tuner_dbg("radio LOW LO inject xtal @ 13 MHz\n"); 222 258 223 - buffer[4] |= TEA5767_PLLREF_ENABLE; 224 259 div = (frq * (4000 / 16) - 700000 - 225000 + 25000) / 50000; 225 260 break; 226 261 case TEA5767_LOW_LO_32768: ··· 275 256 if (5 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props, buffer, 5))) 276 257 tuner_warn("i2c i/o error: rc == %d (should be 5)\n", rc); 277 258 else 278 - tea5767_status_dump(buffer); 259 + tea5767_status_dump(priv, buffer); 279 260 } 280 261 281 262 priv->frequency = frq * 125 / 2; ··· 417 398 { 418 399 struct tea5767_priv *priv = fe->tuner_priv; 419 400 *frequency = priv->frequency; 401 + 402 + return 0; 403 + } 404 + 405 + static int tea5767_set_config (struct dvb_frontend *fe, void *priv_cfg) 406 + { 407 + struct tea5767_priv *priv = fe->tuner_priv; 408 + 409 + memcpy(&priv->ctrl, priv_cfg, sizeof(priv->ctrl)); 410 + 420 411 return 0; 421 412 } 422 413 ··· 436 407 }, 437 408 438 409 .set_analog_params = set_radio_freq, 410 + .set_config = tea5767_set_config, 439 411 .sleep = tea5767_standby, 440 412 .release = tea5767_release, 441 413 .get_frequency = tea5767_get_frequency, ··· 455 425 return NULL; 456 426 fe->tuner_priv = priv; 457 427 458 - priv->i2c_props.addr = i2c_addr; 459 - priv->i2c_props.adap = i2c_adap; 428 + priv->i2c_props.addr = i2c_addr; 429 + priv->i2c_props.adap = i2c_adap; 430 + priv->ctrl.xtal_freq = TEA5767_HIGH_LO_32768; 431 + priv->ctrl.port1 = 1; 432 + priv->ctrl.port2 = 1; 433 + priv->ctrl.high_cut = 1; 434 + priv->ctrl.st_noise = 1; 435 + priv->ctrl.japan_band = 1; 460 436 461 437 memcpy(&fe->ops.tuner_ops, &tea5767_tuner_ops, 462 438 sizeof(struct dvb_tuner_ops)); ··· 471 435 472 436 return fe; 473 437 } 474 - 475 438 476 439 EXPORT_SYMBOL_GPL(tea5767_attach); 477 440 EXPORT_SYMBOL_GPL(tea5767_autodetection);
+19
drivers/media/video/tea5767.h
··· 20 20 #include <linux/i2c.h> 21 21 #include "dvb_frontend.h" 22 22 23 + enum tea5767_xtal { 24 + TEA5767_LOW_LO_32768 = 0, 25 + TEA5767_HIGH_LO_32768 = 1, 26 + TEA5767_LOW_LO_13MHz = 2, 27 + TEA5767_HIGH_LO_13MHz = 3, 28 + }; 29 + 30 + struct tea5767_ctrl { 31 + unsigned int port1:1; 32 + unsigned int port2:1; 33 + unsigned int high_cut:1; 34 + unsigned int st_noise:1; 35 + unsigned int soft_mute:1; 36 + unsigned int japan_band:1; 37 + unsigned int deemph_75:1; 38 + unsigned int pllref:1; 39 + enum tea5767_xtal xtal_freq; 40 + }; 41 + 23 42 #if defined(CONFIG_TUNER_TEA5767) || (defined(CONFIG_TUNER_TEA5767_MODULE) && defined(MODULE)) 24 43 extern int tea5767_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr); 25 44