Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * |
| 3 | * i2c tv tuner chip device driver |
| 4 | * core core, i.e. kernel interfaces, registering and so on |
| 5 | */ |
| 6 | |
| 7 | #include <linux/module.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | #include <linux/string.h> |
| 10 | #include <linux/timer.h> |
| 11 | #include <linux/delay.h> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/poll.h> |
| 15 | #include <linux/i2c.h> |
| 16 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/init.h> |
Hans Verkuil | 75b4c26 | 2009-04-01 03:32:22 -0300 | [diff] [blame] | 18 | #include <linux/videodev2.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <media/tuner.h> |
Michael Krufky | 4adad28 | 2007-08-27 21:59:08 -0300 | [diff] [blame] | 20 | #include <media/tuner-types.h> |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 21 | #include <media/v4l2-device.h> |
Hans Verkuil | 35ea11f | 2008-07-20 08:12:02 -0300 | [diff] [blame] | 22 | #include <media/v4l2-ioctl.h> |
Michael Krufky | 96c0b7c | 2007-08-27 21:23:08 -0300 | [diff] [blame] | 23 | #include "mt20xx.h" |
Michael Krufky | 910bb3e | 2007-08-27 21:22:20 -0300 | [diff] [blame] | 24 | #include "tda8290.h" |
Michael Krufky | 7ab10bf | 2007-08-27 21:23:40 -0300 | [diff] [blame] | 25 | #include "tea5761.h" |
Michael Krufky | 8d0936e | 2007-08-27 21:24:27 -0300 | [diff] [blame] | 26 | #include "tea5767.h" |
Mauro Carvalho Chehab | 215b95b | 2007-10-23 15:24:06 -0300 | [diff] [blame] | 27 | #include "tuner-xc2028.h" |
Michael Krufky | 4adad28 | 2007-08-27 21:59:08 -0300 | [diff] [blame] | 28 | #include "tuner-simple.h" |
Michael Krufky | 31c9584 | 2007-10-21 20:48:48 -0300 | [diff] [blame] | 29 | #include "tda9887.h" |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 30 | #include "xc5000.h" |
Michael Krufky | 9346389 | 2009-09-15 23:04:18 -0300 | [diff] [blame] | 31 | #include "tda18271.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | #define UNSET (-1U) |
| 34 | |
Hans Verkuil | 9dd659d | 2007-11-04 11:03:36 -0300 | [diff] [blame] | 35 | #define PREFIX t->i2c->driver->driver.name |
Michael Krufky | 241020d | 2007-10-30 09:46:10 -0300 | [diff] [blame] | 36 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 37 | /* |
| 38 | * Driver modprobe parameters |
| 39 | */ |
| 40 | |
| 41 | /* insmod options used at init time => read/only */ |
| 42 | static unsigned int addr; |
| 43 | static unsigned int no_autodetect; |
| 44 | static unsigned int show_i2c; |
| 45 | |
| 46 | module_param(addr, int, 0444); |
| 47 | module_param(no_autodetect, int, 0444); |
| 48 | module_param(show_i2c, int, 0444); |
| 49 | |
| 50 | /* insmod options used at runtime => read/write */ |
| 51 | static int tuner_debug; |
| 52 | static unsigned int tv_range[2] = { 44, 958 }; |
| 53 | static unsigned int radio_range[2] = { 65, 108 }; |
| 54 | static char pal[] = "--"; |
| 55 | static char secam[] = "--"; |
| 56 | static char ntsc[] = "-"; |
| 57 | |
| 58 | module_param_named(debug,tuner_debug, int, 0644); |
| 59 | module_param_array(tv_range, int, NULL, 0644); |
| 60 | module_param_array(radio_range, int, NULL, 0644); |
| 61 | module_param_string(pal, pal, sizeof(pal), 0644); |
| 62 | module_param_string(secam, secam, sizeof(secam), 0644); |
| 63 | module_param_string(ntsc, ntsc, sizeof(ntsc), 0644); |
| 64 | |
| 65 | /* |
| 66 | * Static vars |
| 67 | */ |
| 68 | |
| 69 | static struct xc5000_config xc5000_cfg; |
| 70 | static LIST_HEAD(tuner_list); |
| 71 | |
| 72 | /* |
| 73 | * Debug macros |
| 74 | */ |
| 75 | |
| 76 | #define tuner_warn(fmt, arg...) do { \ |
| 77 | printk(KERN_WARNING "%s %d-%04x: " fmt, PREFIX, \ |
| 78 | i2c_adapter_id(t->i2c->adapter), \ |
| 79 | t->i2c->addr, ##arg); \ |
| 80 | } while (0) |
| 81 | |
| 82 | #define tuner_info(fmt, arg...) do { \ |
| 83 | printk(KERN_INFO "%s %d-%04x: " fmt, PREFIX, \ |
| 84 | i2c_adapter_id(t->i2c->adapter), \ |
| 85 | t->i2c->addr, ##arg); \ |
| 86 | } while (0) |
| 87 | |
| 88 | #define tuner_err(fmt, arg...) do { \ |
| 89 | printk(KERN_ERR "%s %d-%04x: " fmt, PREFIX, \ |
| 90 | i2c_adapter_id(t->i2c->adapter), \ |
| 91 | t->i2c->addr, ##arg); \ |
| 92 | } while (0) |
| 93 | |
| 94 | #define tuner_dbg(fmt, arg...) do { \ |
| 95 | if (tuner_debug) \ |
| 96 | printk(KERN_DEBUG "%s %d-%04x: " fmt, PREFIX, \ |
| 97 | i2c_adapter_id(t->i2c->adapter), \ |
| 98 | t->i2c->addr, ##arg); \ |
| 99 | } while (0) |
| 100 | |
| 101 | /* |
| 102 | * Internal struct used inside the driver |
| 103 | */ |
| 104 | |
| 105 | struct tuner { |
| 106 | /* device */ |
| 107 | struct dvb_frontend fe; |
| 108 | struct i2c_client *i2c; |
| 109 | struct v4l2_subdev sd; |
| 110 | struct list_head list; |
| 111 | |
| 112 | /* keep track of the current settings */ |
| 113 | v4l2_std_id std; |
| 114 | unsigned int tv_freq; |
| 115 | unsigned int radio_freq; |
| 116 | unsigned int audmode; |
| 117 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 118 | enum v4l2_tuner_type mode; |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 119 | unsigned int mode_mask; /* Combination of allowable modes */ |
| 120 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 121 | bool standby; /* Standby mode */ |
| 122 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 123 | unsigned int type; /* chip type id */ |
| 124 | unsigned int config; |
| 125 | const char *name; |
| 126 | }; |
| 127 | |
| 128 | /* |
| 129 | * tuner attach/detach logic |
| 130 | */ |
| 131 | |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 132 | /** This macro allows us to probe dynamically, avoiding static links */ |
Mauro Carvalho Chehab | ff13817 | 2008-04-29 23:02:33 -0300 | [diff] [blame] | 133 | #ifdef CONFIG_MEDIA_ATTACH |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 134 | #define tuner_symbol_probe(FUNCTION, ARGS...) ({ \ |
| 135 | int __r = -EINVAL; \ |
| 136 | typeof(&FUNCTION) __a = symbol_request(FUNCTION); \ |
| 137 | if (__a) { \ |
| 138 | __r = (int) __a(ARGS); \ |
Andrew Morton | a1355e5 | 2008-04-30 11:40:17 -0300 | [diff] [blame] | 139 | symbol_put(FUNCTION); \ |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 140 | } else { \ |
| 141 | printk(KERN_ERR "TUNER: Unable to find " \ |
| 142 | "symbol "#FUNCTION"()\n"); \ |
| 143 | } \ |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 144 | __r; \ |
| 145 | }) |
| 146 | |
| 147 | static void tuner_detach(struct dvb_frontend *fe) |
| 148 | { |
| 149 | if (fe->ops.tuner_ops.release) { |
| 150 | fe->ops.tuner_ops.release(fe); |
| 151 | symbol_put_addr(fe->ops.tuner_ops.release); |
| 152 | } |
| 153 | if (fe->ops.analog_ops.release) { |
| 154 | fe->ops.analog_ops.release(fe); |
| 155 | symbol_put_addr(fe->ops.analog_ops.release); |
| 156 | } |
| 157 | } |
| 158 | #else |
| 159 | #define tuner_symbol_probe(FUNCTION, ARGS...) ({ \ |
| 160 | FUNCTION(ARGS); \ |
| 161 | }) |
| 162 | |
| 163 | static void tuner_detach(struct dvb_frontend *fe) |
| 164 | { |
| 165 | if (fe->ops.tuner_ops.release) |
| 166 | fe->ops.tuner_ops.release(fe); |
| 167 | if (fe->ops.analog_ops.release) |
| 168 | fe->ops.analog_ops.release(fe); |
| 169 | } |
| 170 | #endif |
| 171 | |
Michael Krufky | f7f427e | 2007-12-16 22:02:26 -0300 | [diff] [blame] | 172 | |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 173 | static inline struct tuner *to_tuner(struct v4l2_subdev *sd) |
| 174 | { |
| 175 | return container_of(sd, struct tuner, sd); |
| 176 | } |
| 177 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 178 | /* |
| 179 | * struct analog_demod_ops callbacks |
| 180 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 182 | static void fe_set_params(struct dvb_frontend *fe, |
| 183 | struct analog_parameters *params) |
Michael Krufky | e18f944 | 2007-08-21 01:25:48 -0300 | [diff] [blame] | 184 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 185 | struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops; |
| 186 | struct tuner *t = fe->analog_demod_priv; |
Michael Krufky | e18f944 | 2007-08-21 01:25:48 -0300 | [diff] [blame] | 187 | |
Michael Krufky | e18f944 | 2007-08-21 01:25:48 -0300 | [diff] [blame] | 188 | if (NULL == fe_tuner_ops->set_analog_params) { |
| 189 | tuner_warn("Tuner frontend module has no way to set freq\n"); |
| 190 | return; |
| 191 | } |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 192 | fe_tuner_ops->set_analog_params(fe, params); |
Michael Krufky | e18f944 | 2007-08-21 01:25:48 -0300 | [diff] [blame] | 193 | } |
| 194 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 195 | static void fe_standby(struct dvb_frontend *fe) |
Michael Krufky | e18f944 | 2007-08-21 01:25:48 -0300 | [diff] [blame] | 196 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 197 | struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops; |
Michael Krufky | e18f944 | 2007-08-21 01:25:48 -0300 | [diff] [blame] | 198 | |
| 199 | if (fe_tuner_ops->sleep) |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 200 | fe_tuner_ops->sleep(fe); |
Michael Krufky | e18f944 | 2007-08-21 01:25:48 -0300 | [diff] [blame] | 201 | } |
| 202 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 203 | static int fe_has_signal(struct dvb_frontend *fe) |
Michael Krufky | 1f5ef19 | 2007-08-31 17:38:02 -0300 | [diff] [blame] | 204 | { |
Michael Krufky | 1419683 | 2007-10-14 18:11:53 -0300 | [diff] [blame] | 205 | u16 strength = 0; |
Michael Krufky | 1f5ef19 | 2007-08-31 17:38:02 -0300 | [diff] [blame] | 206 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 207 | if (fe->ops.tuner_ops.get_rf_strength) |
| 208 | fe->ops.tuner_ops.get_rf_strength(fe, &strength); |
Michael Krufky | 1f5ef19 | 2007-08-31 17:38:02 -0300 | [diff] [blame] | 209 | |
| 210 | return strength; |
| 211 | } |
| 212 | |
Michael Krufky | f1c9a28 | 2007-12-16 19:27:23 -0300 | [diff] [blame] | 213 | static int fe_set_config(struct dvb_frontend *fe, void *priv_cfg) |
| 214 | { |
| 215 | struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops; |
| 216 | struct tuner *t = fe->analog_demod_priv; |
| 217 | |
| 218 | if (fe_tuner_ops->set_config) |
| 219 | return fe_tuner_ops->set_config(fe, priv_cfg); |
| 220 | |
| 221 | tuner_warn("Tuner frontend module has no way to set config\n"); |
| 222 | |
| 223 | return 0; |
| 224 | } |
| 225 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 226 | static void tuner_status(struct dvb_frontend *fe); |
Michael Krufky | 1dde7a4 | 2007-10-21 13:40:56 -0300 | [diff] [blame] | 227 | |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 228 | static struct analog_demod_ops tuner_analog_ops = { |
Michael Krufky | c7919d5 | 2007-12-08 17:06:30 -0300 | [diff] [blame] | 229 | .set_params = fe_set_params, |
Michael Krufky | 1dde7a4 | 2007-10-21 13:40:56 -0300 | [diff] [blame] | 230 | .standby = fe_standby, |
Michael Krufky | 1dde7a4 | 2007-10-21 13:40:56 -0300 | [diff] [blame] | 231 | .has_signal = fe_has_signal, |
Michael Krufky | f1c9a28 | 2007-12-16 19:27:23 -0300 | [diff] [blame] | 232 | .set_config = fe_set_config, |
Michael Krufky | 1dde7a4 | 2007-10-21 13:40:56 -0300 | [diff] [blame] | 233 | .tuner_status = tuner_status |
| 234 | }; |
| 235 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 236 | /* |
| 237 | * Functions that are common to both TV and radio |
| 238 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 240 | static void set_tv_freq(struct i2c_client *c, unsigned int freq); |
| 241 | static void set_radio_freq(struct i2c_client *c, unsigned int freq); |
| 242 | static const struct v4l2_subdev_ops tuner_ops; |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 243 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 244 | static void set_type(struct i2c_client *c, unsigned int type, |
Hartmut Hackmann | de956c1 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 245 | unsigned int new_mode_mask, unsigned int new_config, |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 246 | int (*tuner_callback) (void *dev, int component, int cmd, int arg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 248 | struct tuner *t = to_tuner(i2c_get_clientdata(c)); |
Michael Krufky | e18f944 | 2007-08-21 01:25:48 -0300 | [diff] [blame] | 249 | struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops; |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 250 | struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 251 | unsigned char buffer[4]; |
Michael Krufky | d6eef49 | 2009-10-24 16:42:16 -0300 | [diff] [blame] | 252 | int tune_now = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 254 | if (type == UNSET || type == TUNER_ABSENT) { |
| 255 | tuner_dbg ("tuner 0x%02x: Tuner type absent\n",c->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | return; |
| 257 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | t->type = type; |
Michael Krufky | e7ddcd9 | 2009-03-28 15:35:26 -0300 | [diff] [blame] | 260 | /* prevent invalid config values */ |
Roel Kluin | f14a297 | 2009-10-23 07:59:42 -0300 | [diff] [blame] | 261 | t->config = new_config < 256 ? new_config : 0; |
Hartmut Hackmann | cfeb883 | 2007-04-27 12:31:17 -0300 | [diff] [blame] | 262 | if (tuner_callback != NULL) { |
| 263 | tuner_dbg("defining GPIO callback\n"); |
Michael Krufky | d7cba04 | 2008-09-12 13:31:45 -0300 | [diff] [blame] | 264 | t->fe.callback = tuner_callback; |
Hartmut Hackmann | cfeb883 | 2007-04-27 12:31:17 -0300 | [diff] [blame] | 265 | } |
Hartmut Hackmann | 80f90fb | 2007-04-27 12:31:18 -0300 | [diff] [blame] | 266 | |
Michael Krufky | b208319 | 2007-05-29 22:54:06 -0300 | [diff] [blame] | 267 | /* discard private data, in case set_type() was previously called */ |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 268 | tuner_detach(&t->fe); |
| 269 | t->fe.analog_demod_priv = NULL; |
Michael Krufky | be2b85a | 2007-06-04 14:40:27 -0300 | [diff] [blame] | 270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | switch (t->type) { |
| 272 | case TUNER_MT2032: |
Mauro Carvalho Chehab | 09fee5f | 2008-04-30 15:29:57 -0300 | [diff] [blame] | 273 | if (!dvb_attach(microtune_attach, |
| 274 | &t->fe, t->i2c->adapter, t->i2c->addr)) |
| 275 | goto attach_failed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | break; |
| 277 | case TUNER_PHILIPS_TDA8290: |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 278 | { |
Mauro Carvalho Chehab | 09fee5f | 2008-04-30 15:29:57 -0300 | [diff] [blame] | 279 | struct tda829x_config cfg = { |
| 280 | .lna_cfg = t->config, |
Mauro Carvalho Chehab | 09fee5f | 2008-04-30 15:29:57 -0300 | [diff] [blame] | 281 | }; |
| 282 | if (!dvb_attach(tda829x_attach, &t->fe, t->i2c->adapter, |
| 283 | t->i2c->addr, &cfg)) |
| 284 | goto attach_failed; |
Michael Krufky | 5bea1cd | 2007-10-22 09:56:38 -0300 | [diff] [blame] | 285 | break; |
| 286 | } |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 287 | case TUNER_TEA5767: |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 288 | if (!dvb_attach(tea5767_attach, &t->fe, |
| 289 | t->i2c->adapter, t->i2c->addr)) |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 290 | goto attach_failed; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 291 | t->mode_mask = T_RADIO; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 292 | break; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 293 | case TUNER_TEA5761: |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 294 | if (!dvb_attach(tea5761_attach, &t->fe, |
| 295 | t->i2c->adapter, t->i2c->addr)) |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 296 | goto attach_failed; |
Mauro Carvalho Chehab | 8573a9e | 2007-04-08 01:09:11 -0300 | [diff] [blame] | 297 | t->mode_mask = T_RADIO; |
| 298 | break; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 299 | case TUNER_PHILIPS_FMD1216ME_MK3: |
| 300 | buffer[0] = 0x0b; |
| 301 | buffer[1] = 0xdc; |
| 302 | buffer[2] = 0x9c; |
| 303 | buffer[3] = 0x60; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 304 | i2c_master_send(c, buffer, 4); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 305 | mdelay(1); |
| 306 | buffer[2] = 0x86; |
| 307 | buffer[3] = 0x54; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 308 | i2c_master_send(c, buffer, 4); |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 309 | if (!dvb_attach(simple_tuner_attach, &t->fe, |
| 310 | t->i2c->adapter, t->i2c->addr, t->type)) |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 311 | goto attach_failed; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 312 | break; |
Hartmut Hackmann | 93df341 | 2005-11-08 21:36:31 -0800 | [diff] [blame] | 313 | case TUNER_PHILIPS_TD1316: |
| 314 | buffer[0] = 0x0b; |
| 315 | buffer[1] = 0xdc; |
| 316 | buffer[2] = 0x86; |
| 317 | buffer[3] = 0xa4; |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 318 | i2c_master_send(c, buffer, 4); |
| 319 | if (!dvb_attach(simple_tuner_attach, &t->fe, |
| 320 | t->i2c->adapter, t->i2c->addr, t->type)) |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 321 | goto attach_failed; |
Markus Rechberger | ac272ed | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 322 | break; |
Mauro Carvalho Chehab | 690c544 | 2007-10-29 11:33:18 -0300 | [diff] [blame] | 323 | case TUNER_XC2028: |
| 324 | { |
Michel Ludwig | a37b4c9 | 2007-11-16 07:46:14 -0300 | [diff] [blame] | 325 | struct xc2028_config cfg = { |
| 326 | .i2c_adap = t->i2c->adapter, |
| 327 | .i2c_addr = t->i2c->addr, |
Michel Ludwig | a37b4c9 | 2007-11-16 07:46:14 -0300 | [diff] [blame] | 328 | }; |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 329 | if (!dvb_attach(xc2028_attach, &t->fe, &cfg)) |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 330 | goto attach_failed; |
Michael Krufky | d6eef49 | 2009-10-24 16:42:16 -0300 | [diff] [blame] | 331 | tune_now = 0; |
Mauro Carvalho Chehab | 690c544 | 2007-10-29 11:33:18 -0300 | [diff] [blame] | 332 | break; |
| 333 | } |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 334 | case TUNER_TDA9887: |
Mauro Carvalho Chehab | 09fee5f | 2008-04-30 15:29:57 -0300 | [diff] [blame] | 335 | if (!dvb_attach(tda9887_attach, |
| 336 | &t->fe, t->i2c->adapter, t->i2c->addr)) |
| 337 | goto attach_failed; |
Mauro Carvalho Chehab | 1539623 | 2006-06-23 16:13:56 -0300 | [diff] [blame] | 338 | break; |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 339 | case TUNER_XC5000: |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 340 | { |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 341 | xc5000_cfg.i2c_address = t->i2c->addr; |
Devin Heitmueller | ea22786 | 2009-03-11 02:58:53 -0300 | [diff] [blame] | 342 | /* if_khz will be set when the digital dvb_attach() occurs */ |
| 343 | xc5000_cfg.if_khz = 0; |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 344 | if (!dvb_attach(xc5000_attach, |
Michael Krufky | 3065096 | 2008-09-06 14:56:58 -0300 | [diff] [blame] | 345 | &t->fe, t->i2c->adapter, &xc5000_cfg)) |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 346 | goto attach_failed; |
Michael Krufky | d6eef49 | 2009-10-24 16:42:16 -0300 | [diff] [blame] | 347 | tune_now = 0; |
Steven Toth | 27c685a | 2008-01-05 16:50:14 -0300 | [diff] [blame] | 348 | break; |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 349 | } |
Michael Krufky | 9346389 | 2009-09-15 23:04:18 -0300 | [diff] [blame] | 350 | case TUNER_NXP_TDA18271: |
| 351 | { |
| 352 | struct tda18271_config cfg = { |
| 353 | .config = t->config, |
Mauro Carvalho Chehab | e350d44 | 2010-09-26 22:58:28 -0300 | [diff] [blame] | 354 | .small_i2c = TDA18271_03_BYTE_CHUNK_INIT, |
Michael Krufky | 9346389 | 2009-09-15 23:04:18 -0300 | [diff] [blame] | 355 | }; |
| 356 | |
| 357 | if (!dvb_attach(tda18271_attach, &t->fe, t->i2c->addr, |
| 358 | t->i2c->adapter, &cfg)) |
| 359 | goto attach_failed; |
Michael Krufky | d6eef49 | 2009-10-24 16:42:16 -0300 | [diff] [blame] | 360 | tune_now = 0; |
Michael Krufky | 9346389 | 2009-09-15 23:04:18 -0300 | [diff] [blame] | 361 | break; |
| 362 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | default: |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 364 | if (!dvb_attach(simple_tuner_attach, &t->fe, |
| 365 | t->i2c->adapter, t->i2c->addr, t->type)) |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 366 | goto attach_failed; |
| 367 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | break; |
| 369 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 370 | |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 371 | if ((NULL == analog_ops->set_params) && |
Michael Krufky | 1dde7a4 | 2007-10-21 13:40:56 -0300 | [diff] [blame] | 372 | (fe_tuner_ops->set_analog_params)) { |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 373 | |
Michael Krufky | 7271e60 | 2008-05-26 16:08:40 +0200 | [diff] [blame] | 374 | t->name = fe_tuner_ops->info.name; |
Michael Krufky | e18f944 | 2007-08-21 01:25:48 -0300 | [diff] [blame] | 375 | |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 376 | t->fe.analog_demod_priv = t; |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 377 | memcpy(analog_ops, &tuner_analog_ops, |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 378 | sizeof(struct analog_demod_ops)); |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 379 | |
Michael Krufky | a55db8c | 2007-12-09 13:52:51 -0300 | [diff] [blame] | 380 | } else { |
Michael Krufky | 7271e60 | 2008-05-26 16:08:40 +0200 | [diff] [blame] | 381 | t->name = analog_ops->info.name; |
Michael Krufky | e18f944 | 2007-08-21 01:25:48 -0300 | [diff] [blame] | 382 | } |
| 383 | |
Michael Krufky | 7271e60 | 2008-05-26 16:08:40 +0200 | [diff] [blame] | 384 | tuner_dbg("type set to %s\n", t->name); |
Michael Krufky | e18f944 | 2007-08-21 01:25:48 -0300 | [diff] [blame] | 385 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 386 | t->mode_mask = new_mode_mask; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 387 | |
Michael Krufky | d6eef49 | 2009-10-24 16:42:16 -0300 | [diff] [blame] | 388 | /* Some tuners require more initialization setup before use, |
| 389 | such as firmware download or device calibration. |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 390 | trying to set a frequency here will just fail |
| 391 | FIXME: better to move set_freq to the tuner code. This is needed |
| 392 | on analog tuners for PLL to properly work |
| 393 | */ |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 394 | if (tune_now) { |
| 395 | if (V4L2_TUNER_RADIO == t->mode) |
| 396 | set_radio_freq(c, t->radio_freq); |
| 397 | else |
| 398 | set_tv_freq(c, t->tv_freq); |
| 399 | } |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 400 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 401 | tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n", |
Laurent Riffard | 604f28e | 2005-11-26 20:43:39 +0100 | [diff] [blame] | 402 | c->adapter->name, c->driver->driver.name, c->addr << 1, type, |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 403 | t->mode_mask); |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 404 | return; |
| 405 | |
| 406 | attach_failed: |
| 407 | tuner_dbg("Tuner attach for type = %d failed.\n", t->type); |
| 408 | t->type = TUNER_ABSENT; |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 409 | |
| 410 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } |
| 412 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 413 | /* |
| 414 | * This function apply tuner config to tuner specified |
| 415 | * by tun_setup structure. I addr is unset, then admin status |
| 416 | * and tun addr status is more precise then current status, |
| 417 | * it's applied. Otherwise status and type are applied only to |
| 418 | * tuner with exactly the same addr. |
| 419 | */ |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 420 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 421 | static void set_addr(struct i2c_client *c, struct tuner_setup *tun_setup) |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 422 | { |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 423 | struct tuner *t = to_tuner(i2c_get_clientdata(c)); |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 424 | |
Hartmut Hackmann | de956c1 | 2007-04-27 12:31:12 -0300 | [diff] [blame] | 425 | if ( (t->type == UNSET && ((tun_setup->addr == ADDR_UNSET) && |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 426 | (t->mode_mask & tun_setup->mode_mask))) || |
| 427 | (tun_setup->addr == c->addr)) { |
| 428 | set_type(c, tun_setup->type, tun_setup->mode_mask, |
| 429 | tun_setup->config, tun_setup->tuner_callback); |
Mauro Carvalho Chehab | b9ef6bb | 2008-04-26 11:29:34 -0300 | [diff] [blame] | 430 | } else |
| 431 | tuner_dbg("set addr discarded for type %i, mask %x. " |
| 432 | "Asked to change tuner at addr 0x%02x, with mask %x\n", |
| 433 | t->type, t->mode_mask, |
| 434 | tun_setup->addr, tun_setup->mode_mask); |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 437 | static int tuner_s_type_addr(struct v4l2_subdev *sd, struct tuner_setup *type) |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 438 | { |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 439 | struct tuner *t = to_tuner(sd); |
| 440 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 441 | |
| 442 | tuner_dbg("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x, config=0x%02x\n", |
| 443 | type->type, |
| 444 | type->addr, |
| 445 | type->mode_mask, |
| 446 | type->config); |
| 447 | |
| 448 | set_addr(client, type); |
| 449 | return 0; |
| 450 | } |
| 451 | |
| 452 | static int tuner_s_config(struct v4l2_subdev *sd, const struct v4l2_priv_tun_config *cfg) |
| 453 | { |
| 454 | struct tuner *t = to_tuner(sd); |
| 455 | struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops; |
| 456 | |
| 457 | if (t->type != cfg->tuner) |
| 458 | return 0; |
| 459 | |
| 460 | if (analog_ops->set_config) { |
| 461 | analog_ops->set_config(&t->fe, cfg->priv); |
| 462 | return 0; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 463 | } |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 464 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 465 | tuner_dbg("Tuner frontend module has no way to set config\n"); |
Mauro Carvalho Chehab | 793cf9e | 2005-09-09 13:03:37 -0700 | [diff] [blame] | 466 | return 0; |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 467 | } |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 468 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 469 | /* Search for existing radio and/or TV tuners on the given I2C adapter. |
| 470 | Note that when this function is called from tuner_probe you can be |
| 471 | certain no other devices will be added/deleted at the same time, I2C |
| 472 | core protects against that. */ |
| 473 | static void tuner_lookup(struct i2c_adapter *adap, |
| 474 | struct tuner **radio, struct tuner **tv) |
| 475 | { |
| 476 | struct tuner *pos; |
| 477 | |
| 478 | *radio = NULL; |
| 479 | *tv = NULL; |
| 480 | |
| 481 | list_for_each_entry(pos, &tuner_list, list) { |
| 482 | int mode_mask; |
| 483 | |
| 484 | if (pos->i2c->adapter != adap || |
| 485 | strcmp(pos->i2c->driver->driver.name, "tuner")) |
| 486 | continue; |
| 487 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 488 | mode_mask = pos->mode_mask; |
| 489 | pos->standby = 1; |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 490 | if (*radio == NULL && mode_mask == T_RADIO) |
| 491 | *radio = pos; |
| 492 | /* Note: currently TDA9887 is the only demod-only |
| 493 | device. If other devices appear then we need to |
| 494 | make this test more general. */ |
| 495 | else if (*tv == NULL && pos->type != TUNER_TDA9887 && |
| 496 | (pos->mode_mask & (T_ANALOG_TV | T_DIGITAL_TV))) |
| 497 | *tv = pos; |
| 498 | } |
| 499 | } |
| 500 | |
| 501 | /* During client attach, set_type is called by adapter's attach_inform callback. |
| 502 | set_type must then be completed by tuner_probe. |
| 503 | */ |
| 504 | static int tuner_probe(struct i2c_client *client, |
| 505 | const struct i2c_device_id *id) |
| 506 | { |
| 507 | struct tuner *t; |
| 508 | struct tuner *radio; |
| 509 | struct tuner *tv; |
| 510 | |
| 511 | t = kzalloc(sizeof(struct tuner), GFP_KERNEL); |
| 512 | if (NULL == t) |
| 513 | return -ENOMEM; |
| 514 | v4l2_i2c_subdev_init(&t->sd, client, &tuner_ops); |
| 515 | t->i2c = client; |
| 516 | t->name = "(tuner unset)"; |
| 517 | t->type = UNSET; |
| 518 | t->audmode = V4L2_TUNER_MODE_STEREO; |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 519 | t->standby = 1; |
| 520 | t->radio_freq = 87.5 * 16000; /* Initial freq range */ |
| 521 | t->tv_freq = 400 * 16; /* Sets freq to VHF High - needed for some PLL's to properly start */ |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 522 | |
| 523 | if (show_i2c) { |
| 524 | unsigned char buffer[16]; |
| 525 | int i, rc; |
| 526 | |
| 527 | memset(buffer, 0, sizeof(buffer)); |
| 528 | rc = i2c_master_recv(client, buffer, sizeof(buffer)); |
| 529 | tuner_info("I2C RECV = "); |
| 530 | for (i = 0; i < rc; i++) |
| 531 | printk(KERN_CONT "%02x ", buffer[i]); |
| 532 | printk("\n"); |
| 533 | } |
| 534 | |
| 535 | /* autodetection code based on the i2c addr */ |
| 536 | if (!no_autodetect) { |
| 537 | switch (client->addr) { |
| 538 | case 0x10: |
| 539 | if (tuner_symbol_probe(tea5761_autodetection, |
| 540 | t->i2c->adapter, |
| 541 | t->i2c->addr) >= 0) { |
| 542 | t->type = TUNER_TEA5761; |
| 543 | t->mode_mask = T_RADIO; |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 544 | tuner_lookup(t->i2c->adapter, &radio, &tv); |
| 545 | if (tv) |
| 546 | tv->mode_mask &= ~T_RADIO; |
| 547 | |
| 548 | goto register_client; |
| 549 | } |
| 550 | kfree(t); |
| 551 | return -ENODEV; |
| 552 | case 0x42: |
| 553 | case 0x43: |
| 554 | case 0x4a: |
| 555 | case 0x4b: |
| 556 | /* If chip is not tda8290, don't register. |
| 557 | since it can be tda9887*/ |
| 558 | if (tuner_symbol_probe(tda829x_probe, t->i2c->adapter, |
| 559 | t->i2c->addr) >= 0) { |
| 560 | tuner_dbg("tda829x detected\n"); |
| 561 | } else { |
| 562 | /* Default is being tda9887 */ |
| 563 | t->type = TUNER_TDA9887; |
| 564 | t->mode_mask = T_RADIO | T_ANALOG_TV | |
| 565 | T_DIGITAL_TV; |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 566 | goto register_client; |
| 567 | } |
| 568 | break; |
| 569 | case 0x60: |
| 570 | if (tuner_symbol_probe(tea5767_autodetection, |
| 571 | t->i2c->adapter, t->i2c->addr) |
| 572 | >= 0) { |
| 573 | t->type = TUNER_TEA5767; |
| 574 | t->mode_mask = T_RADIO; |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 575 | /* Sets freq to FM range */ |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 576 | tuner_lookup(t->i2c->adapter, &radio, &tv); |
| 577 | if (tv) |
| 578 | tv->mode_mask &= ~T_RADIO; |
| 579 | |
| 580 | goto register_client; |
| 581 | } |
| 582 | break; |
| 583 | } |
| 584 | } |
| 585 | |
| 586 | /* Initializes only the first TV tuner on this adapter. Why only the |
| 587 | first? Because there are some devices (notably the ones with TI |
| 588 | tuners) that have more than one i2c address for the *same* device. |
| 589 | Experience shows that, except for just one case, the first |
| 590 | address is the right one. The exception is a Russian tuner |
| 591 | (ACORP_Y878F). So, the desired behavior is just to enable the |
| 592 | first found TV tuner. */ |
| 593 | tuner_lookup(t->i2c->adapter, &radio, &tv); |
| 594 | if (tv == NULL) { |
| 595 | t->mode_mask = T_ANALOG_TV | T_DIGITAL_TV; |
| 596 | if (radio == NULL) |
| 597 | t->mode_mask |= T_RADIO; |
| 598 | tuner_dbg("Setting mode_mask to 0x%02x\n", t->mode_mask); |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 599 | } |
| 600 | |
| 601 | /* Should be just before return */ |
| 602 | register_client: |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 603 | /* Sets a default mode */ |
| 604 | if (t->mode_mask & T_ANALOG_TV) { |
| 605 | t->mode = V4L2_TUNER_ANALOG_TV; |
| 606 | } else if (t->mode_mask & T_RADIO) { |
| 607 | t->mode = V4L2_TUNER_RADIO; |
| 608 | } else { |
| 609 | t->mode = V4L2_TUNER_DIGITAL_TV; |
| 610 | } |
| 611 | set_type(client, t->type, t->mode_mask, t->config, t->fe.callback); |
| 612 | list_add_tail(&t->list, &tuner_list); |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 613 | |
| 614 | tuner_info("Tuner %d found with type(s)%s%s%s.\n", |
| 615 | t->type, |
| 616 | t->mode_mask & T_RADIO ? " radio" : "", |
| 617 | t->mode_mask & T_ANALOG_TV ? " TV" : "", |
| 618 | t->mode_mask & T_ANALOG_TV ? " DTV" : ""); |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 619 | return 0; |
| 620 | } |
| 621 | |
| 622 | static int tuner_remove(struct i2c_client *client) |
| 623 | { |
| 624 | struct tuner *t = to_tuner(i2c_get_clientdata(client)); |
| 625 | |
| 626 | v4l2_device_unregister_subdev(&t->sd); |
| 627 | tuner_detach(&t->fe); |
| 628 | t->fe.analog_demod_priv = NULL; |
| 629 | |
| 630 | list_del(&t->list); |
| 631 | kfree(t); |
| 632 | return 0; |
| 633 | } |
| 634 | |
| 635 | /* |
| 636 | * Functions that are specific for TV mode |
| 637 | */ |
| 638 | |
| 639 | /* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */ |
| 640 | static void set_tv_freq(struct i2c_client *c, unsigned int freq) |
| 641 | { |
| 642 | struct tuner *t = to_tuner(i2c_get_clientdata(c)); |
| 643 | struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops; |
| 644 | |
| 645 | struct analog_parameters params = { |
| 646 | .mode = t->mode, |
| 647 | .audmode = t->audmode, |
| 648 | .std = t->std |
| 649 | }; |
| 650 | |
| 651 | if (t->type == UNSET) { |
| 652 | tuner_warn ("tuner type not set\n"); |
| 653 | return; |
| 654 | } |
| 655 | if (NULL == analog_ops->set_params) { |
| 656 | tuner_warn ("Tuner has no way to set tv freq\n"); |
| 657 | return; |
| 658 | } |
| 659 | if (freq < tv_range[0] * 16 || freq > tv_range[1] * 16) { |
| 660 | tuner_dbg ("TV freq (%d.%02d) out of range (%d-%d)\n", |
| 661 | freq / 16, freq % 16 * 100 / 16, tv_range[0], |
| 662 | tv_range[1]); |
| 663 | /* V4L2 spec: if the freq is not possible then the closest |
| 664 | possible value should be selected */ |
| 665 | if (freq < tv_range[0] * 16) |
| 666 | freq = tv_range[0] * 16; |
| 667 | else |
| 668 | freq = tv_range[1] * 16; |
| 669 | } |
| 670 | params.frequency = freq; |
| 671 | tuner_dbg("tv freq set to %d.%02d\n", |
| 672 | freq / 16, freq % 16 * 100 / 16); |
| 673 | t->tv_freq = freq; |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 674 | t->standby = false; |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 675 | |
| 676 | analog_ops->set_params(&t->fe, ¶ms); |
| 677 | } |
| 678 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 679 | /* get more precise norm info from insmod option */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | static int tuner_fixup_std(struct tuner *t) |
| 681 | { |
| 682 | if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | switch (pal[0]) { |
Hans Verkuil | e71ced1 | 2006-12-11 15:51:43 -0300 | [diff] [blame] | 684 | case '6': |
| 685 | tuner_dbg ("insmod fixup: PAL => PAL-60\n"); |
| 686 | t->std = V4L2_STD_PAL_60; |
| 687 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | case 'b': |
| 689 | case 'B': |
| 690 | case 'g': |
| 691 | case 'G': |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 692 | tuner_dbg ("insmod fixup: PAL => PAL-BG\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 693 | t->std = V4L2_STD_PAL_BG; |
| 694 | break; |
| 695 | case 'i': |
| 696 | case 'I': |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 697 | tuner_dbg ("insmod fixup: PAL => PAL-I\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | t->std = V4L2_STD_PAL_I; |
| 699 | break; |
| 700 | case 'd': |
| 701 | case 'D': |
| 702 | case 'k': |
| 703 | case 'K': |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 704 | tuner_dbg ("insmod fixup: PAL => PAL-DK\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | t->std = V4L2_STD_PAL_DK; |
| 706 | break; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 707 | case 'M': |
| 708 | case 'm': |
| 709 | tuner_dbg ("insmod fixup: PAL => PAL-M\n"); |
| 710 | t->std = V4L2_STD_PAL_M; |
| 711 | break; |
| 712 | case 'N': |
| 713 | case 'n': |
Mauro Carvalho Chehab | 7e57819 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 714 | if (pal[1] == 'c' || pal[1] == 'C') { |
| 715 | tuner_dbg("insmod fixup: PAL => PAL-Nc\n"); |
| 716 | t->std = V4L2_STD_PAL_Nc; |
| 717 | } else { |
| 718 | tuner_dbg ("insmod fixup: PAL => PAL-N\n"); |
| 719 | t->std = V4L2_STD_PAL_N; |
| 720 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 721 | break; |
Mauro Carvalho Chehab | 21d4df3 | 2005-09-09 13:03:59 -0700 | [diff] [blame] | 722 | case '-': |
| 723 | /* default parameter, do nothing */ |
| 724 | break; |
| 725 | default: |
| 726 | tuner_warn ("pal= argument not recognised\n"); |
| 727 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | } |
| 729 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 730 | if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) { |
| 731 | switch (secam[0]) { |
Mauro Carvalho Chehab | 7e57819 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 732 | case 'b': |
| 733 | case 'B': |
| 734 | case 'g': |
| 735 | case 'G': |
| 736 | case 'h': |
| 737 | case 'H': |
| 738 | tuner_dbg("insmod fixup: SECAM => SECAM-BGH\n"); |
| 739 | t->std = V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H; |
| 740 | break; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 741 | case 'd': |
| 742 | case 'D': |
| 743 | case 'k': |
| 744 | case 'K': |
| 745 | tuner_dbg ("insmod fixup: SECAM => SECAM-DK\n"); |
| 746 | t->std = V4L2_STD_SECAM_DK; |
| 747 | break; |
| 748 | case 'l': |
| 749 | case 'L': |
Mauro Carvalho Chehab | 800d3c6 | 2005-11-13 16:07:48 -0800 | [diff] [blame] | 750 | if ((secam[1]=='C')||(secam[1]=='c')) { |
| 751 | tuner_dbg ("insmod fixup: SECAM => SECAM-L'\n"); |
| 752 | t->std = V4L2_STD_SECAM_LC; |
| 753 | } else { |
| 754 | tuner_dbg ("insmod fixup: SECAM => SECAM-L\n"); |
| 755 | t->std = V4L2_STD_SECAM_L; |
| 756 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 757 | break; |
Mauro Carvalho Chehab | 21d4df3 | 2005-09-09 13:03:59 -0700 | [diff] [blame] | 758 | case '-': |
| 759 | /* default parameter, do nothing */ |
| 760 | break; |
| 761 | default: |
| 762 | tuner_warn ("secam= argument not recognised\n"); |
| 763 | break; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 764 | } |
| 765 | } |
| 766 | |
Mauro Carvalho Chehab | 7e57819 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 767 | if ((t->std & V4L2_STD_NTSC) == V4L2_STD_NTSC) { |
| 768 | switch (ntsc[0]) { |
| 769 | case 'm': |
| 770 | case 'M': |
| 771 | tuner_dbg("insmod fixup: NTSC => NTSC-M\n"); |
| 772 | t->std = V4L2_STD_NTSC_M; |
| 773 | break; |
| 774 | case 'j': |
| 775 | case 'J': |
| 776 | tuner_dbg("insmod fixup: NTSC => NTSC_M_JP\n"); |
| 777 | t->std = V4L2_STD_NTSC_M_JP; |
| 778 | break; |
Hans Verkuil | d97a11e | 2006-02-07 06:48:40 -0200 | [diff] [blame] | 779 | case 'k': |
| 780 | case 'K': |
| 781 | tuner_dbg("insmod fixup: NTSC => NTSC_M_KR\n"); |
| 782 | t->std = V4L2_STD_NTSC_M_KR; |
| 783 | break; |
Mauro Carvalho Chehab | 7e57819 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 784 | case '-': |
| 785 | /* default parameter, do nothing */ |
| 786 | break; |
| 787 | default: |
| 788 | tuner_info("ntsc= argument not recognised\n"); |
| 789 | break; |
| 790 | } |
| 791 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | return 0; |
| 793 | } |
| 794 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 795 | /* |
| 796 | * Functions that are specific for Radio mode |
| 797 | */ |
| 798 | |
| 799 | static void set_radio_freq(struct i2c_client *c, unsigned int freq) |
| 800 | { |
| 801 | struct tuner *t = to_tuner(i2c_get_clientdata(c)); |
| 802 | struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops; |
| 803 | |
| 804 | struct analog_parameters params = { |
| 805 | .mode = t->mode, |
| 806 | .audmode = t->audmode, |
| 807 | .std = t->std |
| 808 | }; |
| 809 | |
| 810 | if (t->type == UNSET) { |
| 811 | tuner_warn ("tuner type not set\n"); |
| 812 | return; |
| 813 | } |
| 814 | if (NULL == analog_ops->set_params) { |
| 815 | tuner_warn ("tuner has no way to set radio frequency\n"); |
| 816 | return; |
| 817 | } |
| 818 | if (freq < radio_range[0] * 16000 || freq > radio_range[1] * 16000) { |
| 819 | tuner_dbg ("radio freq (%d.%02d) out of range (%d-%d)\n", |
| 820 | freq / 16000, freq % 16000 * 100 / 16000, |
| 821 | radio_range[0], radio_range[1]); |
| 822 | /* V4L2 spec: if the freq is not possible then the closest |
| 823 | possible value should be selected */ |
| 824 | if (freq < radio_range[0] * 16000) |
| 825 | freq = radio_range[0] * 16000; |
| 826 | else |
| 827 | freq = radio_range[1] * 16000; |
| 828 | } |
| 829 | params.frequency = freq; |
| 830 | tuner_dbg("radio freq set to %d.%02d\n", |
| 831 | freq / 16000, freq % 16000 * 100 / 16000); |
| 832 | t->radio_freq = freq; |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 833 | t->standby = false; |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 834 | |
| 835 | analog_ops->set_params(&t->fe, ¶ms); |
| 836 | } |
| 837 | |
Mauro Carvalho Chehab | e2d25a2 | 2011-02-04 10:09:07 -0300 | [diff] [blame] | 838 | /** |
| 839 | * check_mode - Verify if tuner supports the requested mode |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 840 | * @t: a pointer to the module's internal struct_tuner |
Mauro Carvalho Chehab | e2d25a2 | 2011-02-04 10:09:07 -0300 | [diff] [blame] | 841 | * |
| 842 | * This function checks if the tuner is capable of tuning analog TV, |
| 843 | * digital TV or radio, depending on what the caller wants. If the |
| 844 | * tuner can't support that mode, it returns -EINVAL. Otherwise, it |
| 845 | * returns 0. |
| 846 | * This function is needed for boards that have a separate tuner for |
| 847 | * radio (like devices with tea5767). |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 848 | */ |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 849 | static inline int check_mode(struct tuner *t, enum v4l2_tuner_type mode) |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 850 | { |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 851 | if ((1 << mode & t->mode_mask) == 0) { |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 852 | return -EINVAL; |
| 853 | } |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 854 | return 0; |
| 855 | } |
| 856 | |
Mauro Carvalho Chehab | e2d25a2 | 2011-02-04 10:09:07 -0300 | [diff] [blame] | 857 | /** |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 858 | * set_mode_freq - Switch tuner to other mode. |
| 859 | * @client: struct i2c_client pointer |
| 860 | * @t: a pointer to the module's internal struct_tuner |
| 861 | * @mode: enum v4l2_type (radio or TV) |
| 862 | * @freq: frequency to set (0 means to use the previous one) |
Mauro Carvalho Chehab | e2d25a2 | 2011-02-04 10:09:07 -0300 | [diff] [blame] | 863 | * |
| 864 | * If tuner doesn't support the needed mode (radio or TV), prints a |
| 865 | * debug message and returns -EINVAL, changing internal state to T_STANDBY. |
| 866 | * Otherwise, changes the state and sets frequency to the last value, if |
| 867 | * the tuner can sleep or if it supports both Radio and TV. |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 868 | */ |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 869 | static int set_mode_freq(struct i2c_client *client, struct tuner *t, |
| 870 | enum v4l2_tuner_type mode, unsigned int freq) |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 871 | { |
| 872 | struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops; |
| 873 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 874 | if (mode != t->mode) { |
| 875 | if (check_mode(t, mode) == -EINVAL) { |
| 876 | tuner_dbg("Tuner doesn't support mode %d. " |
| 877 | "Putting tuner to sleep\n", mode); |
| 878 | t->standby = true; |
| 879 | if (analog_ops->standby) |
| 880 | analog_ops->standby(&t->fe); |
| 881 | return -EINVAL; |
| 882 | } |
| 883 | t->mode = mode; |
| 884 | tuner_dbg("Changing to mode %d\n", mode); |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 885 | } |
Mauro Carvalho Chehab | e2d25a2 | 2011-02-04 10:09:07 -0300 | [diff] [blame] | 886 | if (t->mode == V4L2_TUNER_RADIO) { |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 887 | if (freq) |
| 888 | t->radio_freq = freq; |
| 889 | set_radio_freq(client, t->radio_freq); |
Mauro Carvalho Chehab | e2d25a2 | 2011-02-04 10:09:07 -0300 | [diff] [blame] | 890 | } else { |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 891 | if (freq) |
| 892 | t->tv_freq = freq; |
| 893 | set_tv_freq(client, t->tv_freq); |
Mauro Carvalho Chehab | e2d25a2 | 2011-02-04 10:09:07 -0300 | [diff] [blame] | 894 | } |
| 895 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 896 | return 0; |
| 897 | } |
| 898 | |
Mauro Carvalho Chehab | e2d25a2 | 2011-02-04 10:09:07 -0300 | [diff] [blame] | 899 | /* |
| 900 | * Functions that should be broken into separate radio/TV functions |
| 901 | */ |
| 902 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 903 | static void set_freq(struct i2c_client *c, unsigned long freq) |
| 904 | { |
| 905 | struct tuner *t = to_tuner(i2c_get_clientdata(c)); |
| 906 | |
| 907 | switch (t->mode) { |
| 908 | case V4L2_TUNER_RADIO: |
| 909 | set_radio_freq(c, freq); |
| 910 | break; |
| 911 | case V4L2_TUNER_ANALOG_TV: |
| 912 | case V4L2_TUNER_DIGITAL_TV: |
| 913 | set_tv_freq(c, freq); |
| 914 | break; |
| 915 | default: |
| 916 | tuner_dbg("freq set: unknown mode: 0x%04x!\n",t->mode); |
| 917 | } |
| 918 | } |
| 919 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 920 | /** |
| 921 | * tuner_status - Dumps the current tuner status at dmesg |
| 922 | * @fe: pointer to struct dvb_frontend |
| 923 | * |
| 924 | * This callback is used only for driver debug purposes, answering to |
| 925 | * VIDIOC_LOG_STATUS. No changes should happen on this call. |
| 926 | */ |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 927 | static void tuner_status(struct dvb_frontend *fe) |
Mauro Carvalho Chehab | 7e57819 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 928 | { |
Michael Krufky | 4e9154b | 2007-10-21 19:39:50 -0300 | [diff] [blame] | 929 | struct tuner *t = fe->analog_demod_priv; |
Mauro Carvalho Chehab | 7e57819 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 930 | unsigned long freq, freq_fraction; |
Michael Krufky | a07c877 | 2008-04-29 03:54:19 -0300 | [diff] [blame] | 931 | struct dvb_tuner_ops *fe_tuner_ops = &fe->ops.tuner_ops; |
| 932 | struct analog_demod_ops *analog_ops = &fe->ops.analog_ops; |
Mauro Carvalho Chehab | 7e57819 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 933 | const char *p; |
| 934 | |
| 935 | switch (t->mode) { |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 936 | case V4L2_TUNER_RADIO: |
| 937 | p = "radio"; |
| 938 | break; |
| 939 | case V4L2_TUNER_DIGITAL_TV: |
| 940 | p = "digital TV"; |
| 941 | break; |
| 942 | case V4L2_TUNER_ANALOG_TV: |
| 943 | default: |
| 944 | p = "analog TV"; |
| 945 | break; |
Mauro Carvalho Chehab | 7e57819 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 946 | } |
| 947 | if (t->mode == V4L2_TUNER_RADIO) { |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 948 | freq = t->radio_freq / 16000; |
| 949 | freq_fraction = (t->radio_freq % 16000) * 100 / 16000; |
Mauro Carvalho Chehab | 7e57819 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 950 | } else { |
Hans Verkuil | 27487d4 | 2006-01-15 15:04:52 -0200 | [diff] [blame] | 951 | freq = t->tv_freq / 16; |
| 952 | freq_fraction = (t->tv_freq % 16) * 100 / 16; |
Mauro Carvalho Chehab | 7e57819 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 953 | } |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 954 | tuner_info("Tuner mode: %s%s\n", p, |
| 955 | t->standby ? " on standby mode" : ""); |
Mauro Carvalho Chehab | 7e57819 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 956 | tuner_info("Frequency: %lu.%02lu MHz\n", freq, freq_fraction); |
Mauro Carvalho Chehab | 4ae5c2e | 2006-03-25 15:53:38 -0300 | [diff] [blame] | 957 | tuner_info("Standard: 0x%08lx\n", (unsigned long)t->std); |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 958 | if (t->mode != V4L2_TUNER_RADIO) |
| 959 | return; |
Michael Krufky | e18f944 | 2007-08-21 01:25:48 -0300 | [diff] [blame] | 960 | if (fe_tuner_ops->get_status) { |
| 961 | u32 tuner_status; |
| 962 | |
| 963 | fe_tuner_ops->get_status(&t->fe, &tuner_status); |
| 964 | if (tuner_status & TUNER_STATUS_LOCKED) |
| 965 | tuner_info("Tuner is locked.\n"); |
| 966 | if (tuner_status & TUNER_STATUS_STEREO) |
| 967 | tuner_info("Stereo: yes\n"); |
| 968 | } |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 969 | if (analog_ops->has_signal) |
| 970 | tuner_info("Signal strength: %d\n", |
| 971 | analog_ops->has_signal(fe)); |
Mauro Carvalho Chehab | 7e57819 | 2006-01-09 15:25:27 -0200 | [diff] [blame] | 972 | } |
Hans Verkuil | 8a4b275 | 2006-01-23 17:11:09 -0200 | [diff] [blame] | 973 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 974 | /** |
| 975 | * tuner_s_power - controls the power state of the tuner |
| 976 | * @sd: pointer to struct v4l2_subdev |
| 977 | * @on: a zero value puts the tuner to sleep |
| 978 | */ |
Laurent Pinchart | 622b828 | 2009-10-05 10:48:17 -0300 | [diff] [blame] | 979 | static int tuner_s_power(struct v4l2_subdev *sd, int on) |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 980 | { |
| 981 | struct tuner *t = to_tuner(sd); |
Michael Krufky | bc3e5c7 | 2007-12-21 11:18:32 -0300 | [diff] [blame] | 982 | struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 984 | /* FIXME: Why this function don't wake the tuner if on != 0 ? */ |
Laurent Pinchart | 622b828 | 2009-10-05 10:48:17 -0300 | [diff] [blame] | 985 | if (on) |
| 986 | return 0; |
| 987 | |
Mauro Carvalho Chehab | 16a5e53 | 2008-12-20 07:17:10 -0300 | [diff] [blame] | 988 | tuner_dbg("Putting tuner to sleep\n"); |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 989 | t->standby = true; |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 990 | if (analog_ops->standby) |
| 991 | analog_ops->standby(&t->fe); |
| 992 | return 0; |
| 993 | } |
| 994 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 995 | /* ---------------------------------------------------------------------- */ |
| 996 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 997 | static int tuner_s_radio(struct v4l2_subdev *sd) |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 998 | { |
| 999 | struct tuner *t = to_tuner(sd); |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 1000 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Mauro Carvalho Chehab | 7f17112 | 2007-10-18 19:56:47 -0300 | [diff] [blame] | 1001 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1002 | if (set_mode_freq(client, t, V4L2_TUNER_RADIO, 0) == -EINVAL) |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1003 | return 0; |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1004 | return 0; |
| 1005 | } |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 1006 | |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1007 | /* --- v4l ioctls --- */ |
| 1008 | /* take care: bttv does userspace copying, we'll get a |
| 1009 | kernel pointer here... */ |
| 1010 | static int tuner_s_std(struct v4l2_subdev *sd, v4l2_std_id std) |
| 1011 | { |
| 1012 | struct tuner *t = to_tuner(sd); |
| 1013 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1015 | if (set_mode_freq(client, t, V4L2_TUNER_ANALOG_TV, 0) == -EINVAL) |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1016 | return 0; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 1017 | |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1018 | t->std = std; |
| 1019 | tuner_fixup_std(t); |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1020 | |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1021 | return 0; |
| 1022 | } |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 1023 | |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1024 | static int tuner_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f) |
| 1025 | { |
| 1026 | struct tuner *t = to_tuner(sd); |
| 1027 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Michael Krufky | e18f944 | 2007-08-21 01:25:48 -0300 | [diff] [blame] | 1028 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1029 | if (set_mode_freq(client, t, f->type, f->frequency) == -EINVAL) |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1030 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1035 | static int tuner_g_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *f) |
| 1036 | { |
| 1037 | struct tuner *t = to_tuner(sd); |
| 1038 | struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops; |
| 1039 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1040 | if (check_mode(t, f->type) == -EINVAL) |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1041 | return 0; |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1042 | f->type = t->mode; |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1043 | if (fe_tuner_ops->get_frequency && !t->standby) { |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1044 | u32 abs_freq; |
| 1045 | |
| 1046 | fe_tuner_ops->get_frequency(&t->fe, &abs_freq); |
| 1047 | f->frequency = (V4L2_TUNER_RADIO == t->mode) ? |
Julia Lawall | 75b697f | 2009-08-01 16:48:41 -0300 | [diff] [blame] | 1048 | DIV_ROUND_CLOSEST(abs_freq * 2, 125) : |
| 1049 | DIV_ROUND_CLOSEST(abs_freq, 62500); |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1050 | } else { |
| 1051 | f->frequency = (V4L2_TUNER_RADIO == t->mode) ? |
| 1052 | t->radio_freq : t->tv_freq; |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1053 | } |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1054 | return 0; |
| 1055 | } |
| 1056 | |
| 1057 | static int tuner_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) |
| 1058 | { |
| 1059 | struct tuner *t = to_tuner(sd); |
| 1060 | struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops; |
| 1061 | struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops; |
| 1062 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1063 | if (check_mode(t, vt->type) == -EINVAL) |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1064 | return 0; |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1065 | vt->type = t->mode; |
| 1066 | if (analog_ops->get_afc) |
| 1067 | vt->afc = analog_ops->get_afc(&t->fe); |
| 1068 | if (t->mode == V4L2_TUNER_ANALOG_TV) |
| 1069 | vt->capability |= V4L2_TUNER_CAP_NORM; |
| 1070 | if (t->mode != V4L2_TUNER_RADIO) { |
| 1071 | vt->rangelow = tv_range[0] * 16; |
| 1072 | vt->rangehigh = tv_range[1] * 16; |
| 1073 | return 0; |
| 1074 | } |
| 1075 | |
| 1076 | /* radio mode */ |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1077 | vt->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO; |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1078 | if (fe_tuner_ops->get_status) { |
| 1079 | u32 tuner_status; |
| 1080 | |
| 1081 | fe_tuner_ops->get_status(&t->fe, &tuner_status); |
| 1082 | vt->rxsubchans = |
| 1083 | (tuner_status & TUNER_STATUS_STEREO) ? |
| 1084 | V4L2_TUNER_SUB_STEREO : |
| 1085 | V4L2_TUNER_SUB_MONO; |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1086 | } |
| 1087 | if (analog_ops->has_signal) |
| 1088 | vt->signal = analog_ops->has_signal(&t->fe); |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1089 | vt->capability |= V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO; |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1090 | vt->audmode = t->audmode; |
| 1091 | vt->rangelow = radio_range[0] * 16000; |
| 1092 | vt->rangehigh = radio_range[1] * 16000; |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1093 | |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1094 | return 0; |
| 1095 | } |
| 1096 | |
| 1097 | static int tuner_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) |
| 1098 | { |
| 1099 | struct tuner *t = to_tuner(sd); |
| 1100 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 1101 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1102 | if (set_mode_freq(client, t, vt->type, 0) == -EINVAL) |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1103 | return 0; |
| 1104 | |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1105 | if (t->mode == V4L2_TUNER_RADIO) |
| 1106 | t->audmode = vt->audmode; |
| 1107 | |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1108 | return 0; |
| 1109 | } |
| 1110 | |
| 1111 | static int tuner_log_status(struct v4l2_subdev *sd) |
| 1112 | { |
| 1113 | struct tuner *t = to_tuner(sd); |
| 1114 | struct analog_demod_ops *analog_ops = &t->fe.ops.analog_ops; |
| 1115 | |
| 1116 | if (analog_ops->tuner_status) |
| 1117 | analog_ops->tuner_status(&t->fe); |
| 1118 | return 0; |
| 1119 | } |
| 1120 | |
Jean Delvare | 21b48a7 | 2007-03-12 19:20:15 -0300 | [diff] [blame] | 1121 | static int tuner_suspend(struct i2c_client *c, pm_message_t state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1122 | { |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1123 | struct tuner *t = to_tuner(i2c_get_clientdata(c)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | |
Hans Verkuil | 9dd659d | 2007-11-04 11:03:36 -0300 | [diff] [blame] | 1125 | tuner_dbg("suspend\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | /* FIXME: power down ??? */ |
| 1127 | return 0; |
| 1128 | } |
| 1129 | |
Jean Delvare | 21b48a7 | 2007-03-12 19:20:15 -0300 | [diff] [blame] | 1130 | static int tuner_resume(struct i2c_client *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | { |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1132 | struct tuner *t = to_tuner(i2c_get_clientdata(c)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
Hans Verkuil | 9dd659d | 2007-11-04 11:03:36 -0300 | [diff] [blame] | 1134 | tuner_dbg("resume\n"); |
Mauro Carvalho Chehab | cbde689 | 2011-02-04 10:42:09 -0300 | [diff] [blame^] | 1135 | if (V4L2_TUNER_RADIO == t->mode) |
| 1136 | set_freq(c, t->radio_freq); |
| 1137 | else |
| 1138 | set_freq(c, t->tv_freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | return 0; |
| 1140 | } |
| 1141 | |
Hans Verkuil | 75b4c26 | 2009-04-01 03:32:22 -0300 | [diff] [blame] | 1142 | static int tuner_command(struct i2c_client *client, unsigned cmd, void *arg) |
| 1143 | { |
| 1144 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
| 1145 | |
| 1146 | /* TUNER_SET_CONFIG is still called by tuner-simple.c, so we have |
| 1147 | to handle it here. |
| 1148 | There must be a better way of doing this... */ |
| 1149 | switch (cmd) { |
| 1150 | case TUNER_SET_CONFIG: |
| 1151 | return tuner_s_config(sd, arg); |
| 1152 | } |
| 1153 | return -ENOIOCTLCMD; |
| 1154 | } |
| 1155 | |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1156 | /* ----------------------------------------------------------------------- */ |
| 1157 | |
| 1158 | static const struct v4l2_subdev_core_ops tuner_core_ops = { |
| 1159 | .log_status = tuner_log_status, |
Hans Verkuil | f41737e | 2009-04-01 03:52:39 -0300 | [diff] [blame] | 1160 | .s_std = tuner_s_std, |
Laurent Pinchart | 622b828 | 2009-10-05 10:48:17 -0300 | [diff] [blame] | 1161 | .s_power = tuner_s_power, |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1162 | }; |
| 1163 | |
| 1164 | static const struct v4l2_subdev_tuner_ops tuner_tuner_ops = { |
Hans Verkuil | e8a4a9e | 2008-11-24 18:21:40 -0300 | [diff] [blame] | 1165 | .s_radio = tuner_s_radio, |
| 1166 | .g_tuner = tuner_g_tuner, |
| 1167 | .s_tuner = tuner_s_tuner, |
| 1168 | .s_frequency = tuner_s_frequency, |
| 1169 | .g_frequency = tuner_g_frequency, |
| 1170 | .s_type_addr = tuner_s_type_addr, |
| 1171 | .s_config = tuner_s_config, |
| 1172 | }; |
| 1173 | |
| 1174 | static const struct v4l2_subdev_ops tuner_ops = { |
| 1175 | .core = &tuner_core_ops, |
| 1176 | .tuner = &tuner_tuner_ops, |
| 1177 | }; |
| 1178 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1179 | /* ----------------------------------------------------------------------- */ |
| 1180 | |
Jean Delvare | af29486 | 2008-05-18 20:49:40 +0200 | [diff] [blame] | 1181 | /* This driver supports many devices and the idea is to let the driver |
| 1182 | detect which device is present. So rather than listing all supported |
| 1183 | devices here, we pretend to support a single, fake device type. */ |
| 1184 | static const struct i2c_device_id tuner_id[] = { |
| 1185 | { "tuner", }, /* autodetect */ |
| 1186 | { } |
| 1187 | }; |
| 1188 | MODULE_DEVICE_TABLE(i2c, tuner_id); |
| 1189 | |
Hans Verkuil | 02a2098 | 2010-09-15 15:36:23 -0300 | [diff] [blame] | 1190 | static struct i2c_driver tuner_driver = { |
| 1191 | .driver = { |
| 1192 | .owner = THIS_MODULE, |
| 1193 | .name = "tuner", |
| 1194 | }, |
| 1195 | .probe = tuner_probe, |
| 1196 | .remove = tuner_remove, |
| 1197 | .command = tuner_command, |
| 1198 | .suspend = tuner_suspend, |
| 1199 | .resume = tuner_resume, |
| 1200 | .id_table = tuner_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | }; |
| 1202 | |
Hans Verkuil | 02a2098 | 2010-09-15 15:36:23 -0300 | [diff] [blame] | 1203 | static __init int init_tuner(void) |
| 1204 | { |
| 1205 | return i2c_add_driver(&tuner_driver); |
| 1206 | } |
| 1207 | |
| 1208 | static __exit void exit_tuner(void) |
| 1209 | { |
| 1210 | i2c_del_driver(&tuner_driver); |
| 1211 | } |
| 1212 | |
| 1213 | module_init(init_tuner); |
| 1214 | module_exit(exit_tuner); |
| 1215 | |
Mauro Carvalho Chehab | 9f3f71e | 2011-02-03 23:32:07 -0300 | [diff] [blame] | 1216 | MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners"); |
| 1217 | MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer"); |
| 1218 | MODULE_LICENSE("GPL"); |