17 #include <linux/module.h>
18 #include <linux/kernel.h>
19 #include <linux/string.h>
22 #include <linux/errno.h>
23 #include <linux/slab.h>
24 #include <linux/poll.h>
25 #include <linux/i2c.h>
26 #include <linux/types.h>
28 #include <linux/videodev2.h>
46 #define PREFIX (t->i2c->driver->driver.name)
53 static unsigned int addr;
54 static unsigned int no_autodetect;
55 static unsigned int show_i2c;
62 static int tuner_debug;
63 static unsigned int tv_range[2] = { 44, 958 };
64 static unsigned int radio_range[2] = { 65, 108 };
65 static char pal[] =
"--";
66 static char secam[] =
"--";
67 static char ntsc[] =
"-";
87 #define tuner_warn(fmt, arg...) do { \
88 printk(KERN_WARNING "%s %d-%04x: " fmt, PREFIX, \
89 i2c_adapter_id(t->i2c->adapter), \
90 t->i2c->addr, ##arg); \
93 #define tuner_info(fmt, arg...) do { \
94 printk(KERN_INFO "%s %d-%04x: " fmt, PREFIX, \
95 i2c_adapter_id(t->i2c->adapter), \
96 t->i2c->addr, ##arg); \
99 #define tuner_err(fmt, arg...) do { \
100 printk(KERN_ERR "%s %d-%04x: " fmt, PREFIX, \
101 i2c_adapter_id(t->i2c->adapter), \
102 t->i2c->addr, ##arg); \
105 #define tuner_dbg(fmt, arg...) do { \
107 printk(KERN_DEBUG "%s %d-%04x: " fmt, PREFIX, \
108 i2c_adapter_id(t->i2c->adapter), \
109 t->i2c->addr, ##arg); \
151 #ifdef CONFIG_MEDIA_ATTACH
152 #define tuner_symbol_probe(FUNCTION, ARGS...) ({ \
154 typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
156 __r = (int) __a(ARGS); \
157 symbol_put(FUNCTION); \
159 printk(KERN_ERR "TUNER: Unable to find " \
160 "symbol "#FUNCTION"()\n"); \
167 if (fe->
ops.tuner_ops.release) {
168 fe->
ops.tuner_ops.release(fe);
171 if (fe->
ops.analog_ops.release) {
172 fe->
ops.analog_ops.release(fe);
177 #define tuner_symbol_probe(FUNCTION, ARGS...) ({ \
183 if (fe->
ops.tuner_ops.release)
184 fe->
ops.tuner_ops.release(fe);
185 if (fe->
ops.analog_ops.release)
186 fe->
ops.analog_ops.release(fe);
207 tuner_warn(
"Tuner frontend module has no way to set freq\n");
217 if (fe_tuner_ops->
sleep)
218 fe_tuner_ops->
sleep(fe);
225 if (fe->
ops.tuner_ops.get_rf_strength)
226 fe->
ops.tuner_ops.get_rf_strength(fe, &strength);
235 if (fe->
ops.tuner_ops.get_afc)
236 fe->
ops.tuner_ops.get_afc(fe, &afc);
241 static int fe_set_config(
struct dvb_frontend *fe,
void *priv_cfg)
247 return fe_tuner_ops->
set_config(fe, priv_cfg);
249 tuner_warn(
"Tuner frontend module has no way to set config\n");
257 .set_params = fe_set_params,
258 .standby = fe_standby,
259 .has_signal = fe_has_signal,
260 .get_afc = fe_get_afc,
261 .set_config = fe_set_config,
285 unsigned int new_mode_mask,
unsigned int new_config,
288 struct tuner *t = to_tuner(i2c_get_clientdata(c));
294 if (type ==
UNSET || type == TUNER_ABSENT) {
301 t->
config = new_config < 256 ? new_config : 0;
302 if (tuner_callback !=
NULL) {
304 t->
fe.callback = tuner_callback;
308 tuner_detach(&t->
fe);
309 t->
fe.analog_demod_priv =
NULL;
314 &t->
fe, t->
i2c->adapter, t->
i2c->addr))
317 case TUNER_PHILIPS_TDA8290:
329 t->
i2c->adapter, t->
i2c->addr))
335 t->
i2c->adapter, t->
i2c->addr))
339 case TUNER_PHILIPS_FMD1216ME_MK3:
340 case TUNER_PHILIPS_FMD1216MEX_MK3:
354 case TUNER_PHILIPS_TD1316:
367 .i2c_adap = t->
i2c->adapter,
368 .i2c_addr = t->
i2c->addr,
377 &t->
fe, t->
i2c->adapter, t->
i2c->addr))
389 &t->
fe, t->
i2c->adapter, &xc5000_cfg))
404 &t->
fe, t->
i2c->adapter, &xc5000c_cfg))
409 case TUNER_NXP_TDA18271:
417 t->
i2c->adapter, &cfg))
430 .set_smoothedcvbs = 0,
434 &t->
fe, t->
i2c->adapter, &xc4000_cfg))
452 t->
fe.analog_demod_priv =
t;
453 memcpy(analog_ops, &tuner_analog_ops,
477 tuner_dbg(
"%s %s I2C addr 0x%02x with type %d used for 0x%02x\n",
484 t->
type = TUNER_ABSENT;
504 struct tuner_setup *tun_setup)
506 struct tuner *t = to_tuner(sd);
507 struct i2c_client *c = v4l2_get_subdevdata(sd);
509 tuner_dbg(
"Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x, config=0x%02x\n",
512 tun_setup->mode_mask,
515 if ((t->
type ==
UNSET && ((tun_setup->addr == ADDR_UNSET) &&
516 (t->
mode_mask & tun_setup->mode_mask))) ||
517 (tun_setup->addr == c->
addr)) {
518 set_type(c, tun_setup->type, tun_setup->mode_mask,
519 tun_setup->config, tun_setup->tuner_callback);
521 tuner_dbg(
"set addr discarded for type %i, mask %x. "
522 "Asked to change tuner at addr 0x%02x, with mask %x\n",
524 tun_setup->addr, tun_setup->mode_mask);
541 struct tuner *t = to_tuner(sd);
552 tuner_dbg(
"Tuner frontend module has no way to set config\n");
581 if (pos->
i2c->adapter != adap ||
582 strcmp(pos->
i2c->driver->driver.name,
"tuner"))
586 if (*radio ==
NULL && mode_mask == T_RADIO)
591 else if (*tv ==
NULL && pos->
type != TUNER_TDA9887 &&
624 t->
name =
"(tuner unset)";
632 unsigned char buffer[16];
635 memset(buffer, 0,
sizeof(buffer));
638 for (i = 0; i <
rc; i++)
644 if (!no_autodetect) {
645 switch (client->
addr) {
649 t->
i2c->addr) >= 0) {
650 t->
type = TUNER_TEA5761;
652 tuner_lookup(t->
i2c->adapter, &radio, &tv);
656 goto register_client;
667 t->
i2c->addr) >= 0) {
671 t->
type = TUNER_TDA9887;
673 goto register_client;
678 t->
i2c->adapter, t->
i2c->addr)
680 t->
type = TUNER_TEA5767;
683 tuner_lookup(t->
i2c->adapter, &radio, &tv);
687 goto register_client;
700 tuner_lookup(t->
i2c->adapter, &radio, &tv);
718 tuner_info(
"Tuner %d found with type(s)%s%s.\n",
721 t->
mode_mask & T_ANALOG_TV ?
" TV" :
"");
731 static int tuner_remove(
struct i2c_client *client)
733 struct tuner *t = to_tuner(i2c_get_clientdata(client));
736 tuner_detach(&t->
fe);
737 t->
fe.analog_demod_priv =
NULL;
772 t_mode = T_ANALOG_TV;
793 if (mode != t->
mode) {
794 if (check_mode(t, mode) == -
EINVAL) {
795 tuner_dbg(
"Tuner doesn't support mode %d. "
796 "Putting tuner to sleep\n", mode);
803 tuner_dbg(
"Changing to mode %d\n", mode);
813 static void set_freq(
struct tuner *t,
unsigned int freq)
815 struct i2c_client *client = v4l2_get_subdevdata(&t->
sd);
820 set_radio_freq(client, freq);
824 set_tv_freq(client, freq);
838 static void set_tv_freq(
struct i2c_client *c,
unsigned int freq)
840 struct tuner *t = to_tuner(i2c_get_clientdata(c));
854 tuner_warn(
"Tuner has no way to set tv freq\n");
857 if (freq < tv_range[0] * 16 || freq > tv_range[1] * 16) {
858 tuner_dbg(
"TV freq (%d.%02d) out of range (%d-%d)\n",
859 freq / 16, freq % 16 * 100 / 16, tv_range[0],
863 if (freq < tv_range[0] * 16)
864 freq = tv_range[0] * 16;
866 freq = tv_range[1] * 16;
870 freq / 16, freq % 16 * 100 / 16);
915 if (
pal[1] ==
'c' ||
pal[1] ==
'C')
923 if (secam[0] !=
'-' && (std &
V4L2_STD_SECAM) == V4L2_STD_SECAM) {
941 if ((secam[1] ==
'C') || (secam[1] ==
'c'))
945 tuner_warn(
"secam= argument not recognised\n");
962 tuner_info(
"ntsc= argument not recognised\n");
979 static void set_radio_freq(
struct i2c_client *c,
unsigned int freq)
981 struct tuner *t = to_tuner(i2c_get_clientdata(c));
995 tuner_warn(
"tuner has no way to set radio frequency\n");
998 if (freq < radio_range[0] * 16000 || freq > radio_range[1] * 16000) {
999 tuner_dbg(
"radio freq (%d.%02d) out of range (%d-%d)\n",
1000 freq / 16000, freq % 16000 * 100 / 16000,
1001 radio_range[0], radio_range[1]);
1004 if (freq < radio_range[0] * 16000)
1005 freq = radio_range[0] * 16000;
1007 freq = radio_range[1] * 16000;
1010 tuner_dbg(
"radio freq set to %d.%02d\n",
1011 freq / 16000, freq % 16000 * 100 / 16000);
1032 unsigned long freq, freq_fraction;
1051 freq_fraction = (t->
radio_freq % 16000) * 100 / 16000;
1054 freq_fraction = (t->
tv_freq % 16) * 100 / 16;
1057 t->
standby ?
" on standby mode" :
"");
1058 tuner_info(
"Frequency: %lu.%02lu MHz\n", freq, freq_fraction);
1082 struct tuner *t = to_tuner(sd);
1098 static int tuner_s_power(
struct v4l2_subdev *sd,
int on)
1100 struct tuner *t = to_tuner(sd);
1120 struct tuner *t = to_tuner(sd);
1125 t->
std = tuner_fixup_std(t, std);
1127 tuner_dbg(
"Fixup standard %llx to %llx\n", std, t->
std);
1134 struct tuner *t = to_tuner(sd);
1153 struct tuner *t = to_tuner(sd);
1184 struct tuner *t = to_tuner(sd);
1216 vt->
rangelow = radio_range[0] * 16000;
1233 struct tuner *t = to_tuner(sd);
1245 static int tuner_log_status(
struct v4l2_subdev *sd)
1247 struct tuner *t = to_tuner(sd);
1255 #ifdef CONFIG_PM_SLEEP
1256 static int tuner_suspend(
struct device *dev)
1259 struct tuner *t = to_tuner(i2c_get_clientdata(c));
1270 static int tuner_resume(
struct device *dev)
1273 struct tuner *t = to_tuner(i2c_get_clientdata(c));
1285 static int tuner_command(
struct i2c_client *client,
unsigned cmd,
void *arg)
1287 struct v4l2_subdev *sd = i2c_get_clientdata(client);
1294 return tuner_s_config(sd, arg);
1304 .log_status = tuner_log_status,
1305 .s_std = tuner_s_std,
1306 .s_power = tuner_s_power,
1310 .s_radio = tuner_s_radio,
1311 .g_tuner = tuner_g_tuner,
1312 .s_tuner = tuner_s_tuner,
1313 .s_frequency = tuner_s_frequency,
1314 .g_frequency = tuner_g_frequency,
1315 .s_type_addr = tuner_s_type_addr,
1316 .s_config = tuner_s_config,
1320 .core = &tuner_core_ops,
1321 .tuner = &tuner_tuner_ops,
1328 static const struct dev_pm_ops tuner_pm_ops = {
1342 .pm = &tuner_pm_ops,
1344 .probe = tuner_probe,
1345 .remove = tuner_remove,
1346 .command = tuner_command,
1347 .id_table = tuner_id,