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