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