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