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