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