Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame^] | 2 | * $Id: tuner-core.c,v 1.58 2005/07/14 03:06:43 mchehab Exp $ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * i2c tv tuner chip device driver |
| 5 | * core core, i.e. kernel interfaces, registering and so on |
| 6 | */ |
| 7 | |
| 8 | #include <linux/module.h> |
| 9 | #include <linux/moduleparam.h> |
| 10 | #include <linux/kernel.h> |
| 11 | #include <linux/sched.h> |
| 12 | #include <linux/string.h> |
| 13 | #include <linux/timer.h> |
| 14 | #include <linux/delay.h> |
| 15 | #include <linux/errno.h> |
| 16 | #include <linux/slab.h> |
| 17 | #include <linux/poll.h> |
| 18 | #include <linux/i2c.h> |
| 19 | #include <linux/types.h> |
| 20 | #include <linux/videodev.h> |
| 21 | #include <linux/init.h> |
| 22 | |
| 23 | #include <media/tuner.h> |
| 24 | #include <media/audiochip.h> |
| 25 | |
| 26 | #define UNSET (-1U) |
| 27 | |
| 28 | /* standard i2c insmod options */ |
| 29 | static unsigned short normal_i2c[] = { |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 30 | 0x4b, /* tda8290 */ |
Mauro Carvalho Chehab | f5bec39 | 2005-06-23 22:05:13 -0700 | [diff] [blame] | 31 | 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, |
| 32 | 0x68, 0x69, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | I2C_CLIENT_END |
| 34 | }; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 35 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | I2C_CLIENT_INSMOD; |
| 37 | |
| 38 | /* insmod options used at init time => read/only */ |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 39 | static unsigned int addr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | module_param(addr, int, 0444); |
| 41 | |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame^] | 42 | static unsigned int no_autodetect = 0; |
| 43 | module_param(no_autodetect, int, 0444); |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | /* insmod options used at runtime => read/write */ |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 46 | unsigned int tuner_debug = 0; |
| 47 | module_param(tuner_debug, int, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 49 | static unsigned int tv_range[2] = { 44, 958 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | static unsigned int radio_range[2] = { 65, 108 }; |
| 51 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 52 | module_param_array(tv_range, int, NULL, 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | module_param_array(radio_range, int, NULL, 0644); |
| 54 | |
| 55 | MODULE_DESCRIPTION("device driver for various TV and TV+FM radio tuners"); |
| 56 | MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer"); |
| 57 | MODULE_LICENSE("GPL"); |
| 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | static struct i2c_driver driver; |
| 60 | static struct i2c_client client_template; |
| 61 | |
| 62 | /* ---------------------------------------------------------------------- */ |
| 63 | |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 64 | /* Set tuner frequency, freq in Units of 62.5kHz = 1/16MHz */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static void set_tv_freq(struct i2c_client *c, unsigned int freq) |
| 66 | { |
| 67 | struct tuner *t = i2c_get_clientdata(c); |
| 68 | |
| 69 | if (t->type == UNSET) { |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 70 | tuner_warn ("tuner type not set\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | return; |
| 72 | } |
| 73 | if (NULL == t->tv_freq) { |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 74 | tuner_warn ("Tuner has no way to set tv freq\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | return; |
| 76 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 77 | if (freq < tv_range[0] * 16 || freq > tv_range[1] * 16) { |
| 78 | tuner_dbg ("TV freq (%d.%02d) out of range (%d-%d)\n", |
| 79 | freq / 16, freq % 16 * 100 / 16, tv_range[0], |
| 80 | tv_range[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 82 | t->tv_freq(c, freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static void set_radio_freq(struct i2c_client *c, unsigned int freq) |
| 86 | { |
| 87 | struct tuner *t = i2c_get_clientdata(c); |
| 88 | |
| 89 | if (t->type == UNSET) { |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 90 | tuner_warn ("tuner type not set\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | return; |
| 92 | } |
| 93 | if (NULL == t->radio_freq) { |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 94 | tuner_warn ("tuner has no way to set radio frequency\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | return; |
| 96 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 97 | if (freq <= radio_range[0] * 16000 || freq >= radio_range[1] * 16000) { |
| 98 | tuner_dbg ("radio freq (%d.%02d) out of range (%d-%d)\n", |
| 99 | freq / 16000, freq % 16000 * 100 / 16000, |
| 100 | radio_range[0], radio_range[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 102 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 103 | t->radio_freq(c, freq); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 104 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
| 107 | static void set_freq(struct i2c_client *c, unsigned long freq) |
| 108 | { |
| 109 | struct tuner *t = i2c_get_clientdata(c); |
| 110 | |
| 111 | switch (t->mode) { |
| 112 | case V4L2_TUNER_RADIO: |
| 113 | tuner_dbg("radio freq set to %lu.%02lu\n", |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 114 | freq / 16000, freq % 16000 * 100 / 16000); |
| 115 | set_radio_freq(c, freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | break; |
| 117 | case V4L2_TUNER_ANALOG_TV: |
| 118 | case V4L2_TUNER_DIGITAL_TV: |
| 119 | tuner_dbg("tv freq set to %lu.%02lu\n", |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 120 | freq / 16, freq % 16 * 100 / 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | set_tv_freq(c, freq); |
| 122 | break; |
| 123 | } |
| 124 | t->freq = freq; |
| 125 | } |
| 126 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 127 | static void set_type(struct i2c_client *c, unsigned int type, |
| 128 | unsigned int new_mode_mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | { |
| 130 | struct tuner *t = i2c_get_clientdata(c); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 131 | unsigned char buffer[4]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 133 | if (type == UNSET || type == TUNER_ABSENT) { |
| 134 | tuner_dbg ("tuner 0x%02x: Tuner type absent\n",c->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | return; |
| 136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 138 | if (type >= tuner_count) { |
| 139 | tuner_warn ("tuner 0x%02x: Tuner count greater than %d\n",c->addr,tuner_count); |
| 140 | return; |
| 141 | } |
| 142 | |
| 143 | /* This code detects calls by card attach_inform */ |
| 144 | if (NULL == t->i2c.dev.driver) { |
| 145 | tuner_dbg ("tuner 0x%02x: called during i2c_client register by adapter's attach_inform\n", c->addr); |
| 146 | |
| 147 | t->type=type; |
| 148 | return; |
| 149 | } |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 150 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | t->type = type; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | switch (t->type) { |
| 154 | case TUNER_MT2032: |
| 155 | microtune_init(c); |
| 156 | break; |
| 157 | case TUNER_PHILIPS_TDA8290: |
| 158 | tda8290_init(c); |
| 159 | break; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 160 | case TUNER_TEA5767: |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 161 | if (tea5767_tuner_init(c) == EINVAL) { |
| 162 | t->type = TUNER_ABSENT; |
| 163 | t->mode_mask = T_UNINITIALIZED; |
| 164 | return; |
| 165 | } |
| 166 | t->mode_mask = T_RADIO; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 167 | break; |
| 168 | case TUNER_PHILIPS_FMD1216ME_MK3: |
| 169 | buffer[0] = 0x0b; |
| 170 | buffer[1] = 0xdc; |
| 171 | buffer[2] = 0x9c; |
| 172 | buffer[3] = 0x60; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 173 | i2c_master_send(c, buffer, 4); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 174 | mdelay(1); |
| 175 | buffer[2] = 0x86; |
| 176 | buffer[3] = 0x54; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 177 | i2c_master_send(c, buffer, 4); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 178 | default_tuner_init(c); |
| 179 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | default: |
| 181 | default_tuner_init(c); |
| 182 | break; |
| 183 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 184 | |
| 185 | if (t->mode_mask == T_UNINITIALIZED) |
| 186 | t->mode_mask = new_mode_mask; |
| 187 | |
| 188 | set_freq(c, t->freq); |
| 189 | tuner_dbg("%s %s I2C addr 0x%02x with type %d used for 0x%02x\n", |
| 190 | c->adapter->name, c->driver->name, c->addr << 1, type, |
| 191 | t->mode_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | } |
| 193 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 194 | /* |
| 195 | * This function apply tuner config to tuner specified |
| 196 | * by tun_setup structure. I addr is unset, then admin status |
| 197 | * and tun addr status is more precise then current status, |
| 198 | * it's applied. Otherwise status and type are applied only to |
| 199 | * tuner with exactly the same addr. |
| 200 | */ |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 201 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 202 | 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] | 203 | { |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 204 | struct tuner *t = i2c_get_clientdata(c); |
| 205 | |
| 206 | if (tun_setup->addr == ADDR_UNSET) { |
| 207 | if (t->mode_mask & tun_setup->mode_mask) |
| 208 | set_type(c, tun_setup->type, tun_setup->mode_mask); |
| 209 | } else if (tun_setup->addr == c->addr) { |
| 210 | set_type(c, tun_setup->type, tun_setup->mode_mask); |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 211 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 212 | } |
| 213 | |
| 214 | static inline int check_mode(struct tuner *t, char *cmd) |
| 215 | { |
| 216 | if (1 << t->mode & t->mode_mask) { |
| 217 | switch (t->mode) { |
| 218 | case V4L2_TUNER_RADIO: |
| 219 | tuner_dbg("Cmd %s accepted for radio\n", cmd); |
| 220 | break; |
| 221 | case V4L2_TUNER_ANALOG_TV: |
| 222 | tuner_dbg("Cmd %s accepted for analog TV\n", cmd); |
| 223 | break; |
| 224 | case V4L2_TUNER_DIGITAL_TV: |
| 225 | tuner_dbg("Cmd %s accepted for digital TV\n", cmd); |
| 226 | break; |
| 227 | } |
| 228 | return 0; |
| 229 | } |
| 230 | return EINVAL; |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 231 | } |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | static char pal[] = "-"; |
Bert Wesarg | 975e046 | 2005-04-16 15:25:43 -0700 | [diff] [blame] | 234 | module_param_string(pal, pal, sizeof(pal), 0644); |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 235 | static char secam[] = "-"; |
| 236 | module_param_string(secam, secam, sizeof(secam), 0644); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 238 | /* get more precise norm info from insmod option */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | static int tuner_fixup_std(struct tuner *t) |
| 240 | { |
| 241 | if ((t->std & V4L2_STD_PAL) == V4L2_STD_PAL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | switch (pal[0]) { |
| 243 | case 'b': |
| 244 | case 'B': |
| 245 | case 'g': |
| 246 | case 'G': |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 247 | tuner_dbg ("insmod fixup: PAL => PAL-BG\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | t->std = V4L2_STD_PAL_BG; |
| 249 | break; |
| 250 | case 'i': |
| 251 | case 'I': |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 252 | tuner_dbg ("insmod fixup: PAL => PAL-I\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | t->std = V4L2_STD_PAL_I; |
| 254 | break; |
| 255 | case 'd': |
| 256 | case 'D': |
| 257 | case 'k': |
| 258 | case 'K': |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 259 | tuner_dbg ("insmod fixup: PAL => PAL-DK\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | t->std = V4L2_STD_PAL_DK; |
| 261 | break; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 262 | case 'M': |
| 263 | case 'm': |
| 264 | tuner_dbg ("insmod fixup: PAL => PAL-M\n"); |
| 265 | t->std = V4L2_STD_PAL_M; |
| 266 | break; |
| 267 | case 'N': |
| 268 | case 'n': |
| 269 | tuner_dbg ("insmod fixup: PAL => PAL-N\n"); |
| 270 | t->std = V4L2_STD_PAL_N; |
| 271 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | } |
| 273 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 274 | if ((t->std & V4L2_STD_SECAM) == V4L2_STD_SECAM) { |
| 275 | switch (secam[0]) { |
| 276 | case 'd': |
| 277 | case 'D': |
| 278 | case 'k': |
| 279 | case 'K': |
| 280 | tuner_dbg ("insmod fixup: SECAM => SECAM-DK\n"); |
| 281 | t->std = V4L2_STD_SECAM_DK; |
| 282 | break; |
| 283 | case 'l': |
| 284 | case 'L': |
| 285 | tuner_dbg ("insmod fixup: SECAM => SECAM-L\n"); |
| 286 | t->std = V4L2_STD_SECAM_L; |
| 287 | break; |
| 288 | } |
| 289 | } |
| 290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | return 0; |
| 292 | } |
| 293 | |
| 294 | /* ---------------------------------------------------------------------- */ |
| 295 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 296 | /* static var Used only in tuner_attach and tuner_probe */ |
| 297 | static unsigned default_mode_mask; |
| 298 | |
| 299 | /* During client attach, set_type is called by adapter's attach_inform callback. |
| 300 | set_type must then be completed by tuner_attach. |
| 301 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | static int tuner_attach(struct i2c_adapter *adap, int addr, int kind) |
| 303 | { |
| 304 | struct tuner *t; |
| 305 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 306 | client_template.adapter = adap; |
| 307 | client_template.addr = addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 309 | t = kmalloc(sizeof(struct tuner), GFP_KERNEL); |
| 310 | if (NULL == t) |
| 311 | return -ENOMEM; |
| 312 | memset(t, 0, sizeof(struct tuner)); |
| 313 | memcpy(&t->i2c, &client_template, sizeof(struct i2c_client)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | i2c_set_clientdata(&t->i2c, t); |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 315 | t->type = UNSET; |
| 316 | t->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */ |
| 317 | t->audmode = V4L2_TUNER_MODE_STEREO; |
| 318 | t->mode_mask = T_UNINITIALIZED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 320 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 321 | tuner_info("chip found @ 0x%x (%s)\n", addr << 1, adap->name); |
| 322 | |
| 323 | /* TEA5767 autodetection code - only for addr = 0xc0 */ |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame^] | 324 | if (!no_autodetect) { |
| 325 | if (addr == 0x60) { |
| 326 | if (tea5767_autodetection(&t->i2c) != EINVAL) { |
| 327 | t->type = TUNER_TEA5767; |
| 328 | t->mode_mask = T_RADIO; |
| 329 | t->mode = T_STANDBY; |
| 330 | t->freq = 87.5 * 16; /* Sets freq to FM range */ |
| 331 | default_mode_mask &= ~T_RADIO; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 332 | |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame^] | 333 | i2c_attach_client (&t->i2c); |
| 334 | set_type(&t->i2c,t->type, t->mode_mask); |
| 335 | return 0; |
| 336 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
| 340 | /* Initializes only the first adapter found */ |
| 341 | if (default_mode_mask != T_UNINITIALIZED) { |
| 342 | tuner_dbg ("Setting mode_mask to 0x%02x\n", default_mode_mask); |
| 343 | t->mode_mask = default_mode_mask; |
| 344 | t->freq = 400 * 16; /* Sets freq to VHF High */ |
| 345 | default_mode_mask = T_UNINITIALIZED; |
| 346 | } |
| 347 | |
| 348 | /* Should be just before return */ |
| 349 | i2c_attach_client (&t->i2c); |
| 350 | set_type (&t->i2c,t->type, t->mode_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | static int tuner_probe(struct i2c_adapter *adap) |
| 355 | { |
| 356 | if (0 != addr) { |
Mauro Carvalho Chehab | f5bec39 | 2005-06-23 22:05:13 -0700 | [diff] [blame] | 357 | normal_i2c[0] = addr; |
| 358 | normal_i2c[1] = I2C_CLIENT_END; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 361 | default_mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV; |
Mauro Carvalho Chehab | 391cd72 | 2005-06-23 22:02:43 -0700 | [diff] [blame] | 362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | if (adap->class & I2C_CLASS_TV_ANALOG) |
| 364 | return i2c_probe(adap, &addr_data, tuner_attach); |
| 365 | return 0; |
| 366 | } |
| 367 | |
| 368 | static int tuner_detach(struct i2c_client *client) |
| 369 | { |
| 370 | struct tuner *t = i2c_get_clientdata(client); |
Mauro Carvalho Chehab | 391cd72 | 2005-06-23 22:02:43 -0700 | [diff] [blame] | 371 | int err; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 373 | err = i2c_detach_client(&t->i2c); |
Mauro Carvalho Chehab | 391cd72 | 2005-06-23 22:02:43 -0700 | [diff] [blame] | 374 | if (err) { |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 375 | tuner_warn |
| 376 | ("Client deregistration failed, client not detached.\n"); |
Mauro Carvalho Chehab | 391cd72 | 2005-06-23 22:02:43 -0700 | [diff] [blame] | 377 | return err; |
| 378 | } |
| 379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | kfree(t); |
| 381 | return 0; |
| 382 | } |
| 383 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 384 | /* |
| 385 | * Switch tuner to other mode. If tuner support both tv and radio, |
| 386 | * set another frequency to some value (This is needed for some pal |
| 387 | * tuners to avoid locking). Otherwise, just put second tuner in |
| 388 | * standby mode. |
| 389 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 391 | static inline int set_mode(struct i2c_client *client, struct tuner *t, int mode, char *cmd) |
| 392 | { |
| 393 | if (mode != t->mode) { |
| 394 | |
| 395 | t->mode = mode; |
| 396 | if (check_mode(t, cmd) == EINVAL) { |
| 397 | t->mode = T_STANDBY; |
| 398 | if (V4L2_TUNER_RADIO == mode) { |
| 399 | set_tv_freq(client, 400 * 16); |
| 400 | } else { |
| 401 | set_radio_freq(client, 87.5 * 16000); |
| 402 | } |
| 403 | return EINVAL; |
| 404 | } |
| 405 | } |
| 406 | return 0; |
| 407 | } |
| 408 | |
| 409 | #define switch_v4l2() if (!t->using_v4l2) \ |
| 410 | tuner_dbg("switching to v4l2\n"); \ |
| 411 | t->using_v4l2 = 1; |
| 412 | |
| 413 | static inline int check_v4l2(struct tuner *t) |
| 414 | { |
| 415 | if (t->using_v4l2) { |
| 416 | tuner_dbg ("ignore v4l1 call\n"); |
| 417 | return EINVAL; |
| 418 | } |
| 419 | return 0; |
| 420 | } |
| 421 | |
| 422 | static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | { |
| 424 | struct tuner *t = i2c_get_clientdata(client); |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 425 | unsigned int *iarg = (int *)arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 427 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /* --- configuration --- */ |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 429 | case TUNER_SET_TYPE_ADDR: |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 430 | tuner_dbg ("Calling set_type_addr for type=%d, addr=0x%02x, mode=0x%02x\n", |
| 431 | ((struct tuner_setup *)arg)->type, |
| 432 | ((struct tuner_setup *)arg)->addr, |
| 433 | ((struct tuner_setup *)arg)->mode_mask); |
| 434 | |
| 435 | set_addr(client, (struct tuner_setup *)arg); |
Mauro Carvalho Chehab | 391cd72 | 2005-06-23 22:02:43 -0700 | [diff] [blame] | 436 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | case AUDC_SET_RADIO: |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 438 | set_mode(client,t,V4L2_TUNER_RADIO, "AUDC_SET_RADIO"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | break; |
| 440 | case AUDC_CONFIG_PINNACLE: |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 441 | if (check_mode(t, "AUDC_CONFIG_PINNACLE") == EINVAL) |
| 442 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | switch (*iarg) { |
| 444 | case 2: |
| 445 | tuner_dbg("pinnacle pal\n"); |
| 446 | t->radio_if2 = 33300 * 1000; |
| 447 | break; |
| 448 | case 3: |
| 449 | tuner_dbg("pinnacle ntsc\n"); |
| 450 | t->radio_if2 = 41300 * 1000; |
| 451 | break; |
| 452 | } |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 453 | break; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 454 | case TDA9887_SET_CONFIG: |
| 455 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | /* --- v4l ioctls --- */ |
| 457 | /* take care: bttv does userspace copying, we'll get a |
| 458 | kernel pointer here... */ |
| 459 | case VIDIOCSCHAN: |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 460 | { |
| 461 | static const v4l2_std_id map[] = { |
| 462 | [VIDEO_MODE_PAL] = V4L2_STD_PAL, |
| 463 | [VIDEO_MODE_NTSC] = V4L2_STD_NTSC_M, |
| 464 | [VIDEO_MODE_SECAM] = V4L2_STD_SECAM, |
| 465 | [4 /* bttv */ ] = V4L2_STD_PAL_M, |
| 466 | [5 /* bttv */ ] = V4L2_STD_PAL_N, |
| 467 | [6 /* bttv */ ] = V4L2_STD_NTSC_M_JP, |
| 468 | }; |
| 469 | struct video_channel *vc = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 471 | if (check_v4l2(t) == EINVAL) |
| 472 | return 0; |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 473 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 474 | if (set_mode(client,t,V4L2_TUNER_ANALOG_TV, "VIDIOCSCHAN")==EINVAL) |
| 475 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 477 | if (vc->norm < ARRAY_SIZE(map)) |
| 478 | t->std = map[vc->norm]; |
| 479 | tuner_fixup_std(t); |
| 480 | if (t->freq) |
| 481 | set_tv_freq(client, t->freq); |
| 482 | return 0; |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 483 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 484 | case VIDIOCSFREQ: |
| 485 | { |
| 486 | unsigned long *v = arg; |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 487 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 488 | if (check_mode(t, "VIDIOCSFREQ") == EINVAL) |
| 489 | return 0; |
| 490 | if (check_v4l2(t) == EINVAL) |
| 491 | return 0; |
| 492 | |
| 493 | set_freq(client, *v); |
| 494 | return 0; |
| 495 | } |
| 496 | case VIDIOCGTUNER: |
| 497 | { |
| 498 | struct video_tuner *vt = arg; |
| 499 | |
| 500 | if (check_mode(t, "VIDIOCGTUNER") == EINVAL) |
| 501 | return 0; |
| 502 | if (check_v4l2(t) == EINVAL) |
| 503 | return 0; |
| 504 | |
| 505 | if (V4L2_TUNER_RADIO == t->mode) { |
| 506 | if (t->has_signal) |
| 507 | vt->signal = t->has_signal(client); |
| 508 | if (t->is_stereo) { |
| 509 | if (t->is_stereo(client)) |
| 510 | vt->flags |= |
| 511 | VIDEO_TUNER_STEREO_ON; |
| 512 | else |
| 513 | vt->flags &= |
| 514 | ~VIDEO_TUNER_STEREO_ON; |
| 515 | } |
| 516 | vt->flags |= VIDEO_TUNER_LOW; /* Allow freqs at 62.5 Hz */ |
| 517 | |
| 518 | vt->rangelow = radio_range[0] * 16000; |
| 519 | vt->rangehigh = radio_range[1] * 16000; |
| 520 | |
| 521 | } else { |
| 522 | vt->rangelow = tv_range[0] * 16; |
| 523 | vt->rangehigh = tv_range[1] * 16; |
| 524 | } |
| 525 | |
| 526 | return 0; |
| 527 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | case VIDIOCGAUDIO: |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 529 | { |
| 530 | struct video_audio *va = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 532 | if (check_mode(t, "VIDIOCGAUDIO") == EINVAL) |
| 533 | return 0; |
| 534 | if (check_v4l2(t) == EINVAL) |
| 535 | return 0; |
| 536 | |
| 537 | if (V4L2_TUNER_RADIO == t->mode && t->is_stereo) |
| 538 | va->mode = t->is_stereo(client) |
| 539 | ? VIDEO_SOUND_STEREO : VIDEO_SOUND_MONO; |
| 540 | return 0; |
| 541 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
| 543 | case VIDIOC_S_STD: |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 544 | { |
| 545 | v4l2_std_id *id = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 547 | if (set_mode (client, t, V4L2_TUNER_ANALOG_TV, "VIDIOC_S_STD") |
| 548 | == EINVAL) |
| 549 | return 0; |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 550 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 551 | switch_v4l2(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 553 | t->std = *id; |
| 554 | tuner_fixup_std(t); |
| 555 | if (t->freq) |
| 556 | set_freq(client, t->freq); |
| 557 | break; |
Mauro Carvalho Chehab | 56fc08c | 2005-06-23 22:05:07 -0700 | [diff] [blame] | 558 | } |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 559 | case VIDIOC_S_FREQUENCY: |
| 560 | { |
| 561 | struct v4l2_frequency *f = arg; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 562 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 563 | t->freq = f->frequency; |
| 564 | switch_v4l2(); |
| 565 | if (V4L2_TUNER_RADIO == f->type && |
| 566 | V4L2_TUNER_RADIO != t->mode) { |
| 567 | if (set_mode (client, t, f->type, "VIDIOC_S_FREQUENCY") |
| 568 | == EINVAL) |
| 569 | return 0; |
| 570 | } |
| 571 | set_freq(client,t->freq); |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 572 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 573 | break; |
| 574 | } |
| 575 | case VIDIOC_G_FREQUENCY: |
| 576 | { |
| 577 | struct v4l2_frequency *f = arg; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 578 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 579 | if (check_mode(t, "VIDIOC_G_FREQUENCY") == EINVAL) |
| 580 | return 0; |
| 581 | switch_v4l2(); |
| 582 | f->type = t->mode; |
| 583 | f->frequency = t->freq; |
| 584 | break; |
| 585 | } |
| 586 | case VIDIOC_G_TUNER: |
| 587 | { |
| 588 | struct v4l2_tuner *tuner = arg; |
Mauro Carvalho Chehab | 586b0ca | 2005-06-28 20:45:21 -0700 | [diff] [blame] | 589 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 590 | if (check_mode(t, "VIDIOC_G_TUNER") == EINVAL) |
| 591 | return 0; |
| 592 | switch_v4l2(); |
| 593 | |
| 594 | if (V4L2_TUNER_RADIO == t->mode) { |
| 595 | |
| 596 | if (t->has_signal) |
| 597 | tuner->signal = t->has_signal(client); |
| 598 | |
| 599 | if (t->is_stereo) { |
| 600 | if (t->is_stereo(client)) { |
| 601 | tuner->rxsubchans = |
| 602 | V4L2_TUNER_SUB_STEREO | |
| 603 | V4L2_TUNER_SUB_MONO; |
| 604 | } else { |
| 605 | tuner->rxsubchans = |
| 606 | V4L2_TUNER_SUB_MONO; |
| 607 | } |
| 608 | } |
| 609 | |
| 610 | tuner->capability |= |
| 611 | V4L2_TUNER_CAP_LOW | V4L2_TUNER_CAP_STEREO; |
| 612 | |
| 613 | tuner->audmode = t->audmode; |
| 614 | |
| 615 | tuner->rangelow = radio_range[0] * 16000; |
| 616 | tuner->rangehigh = radio_range[1] * 16000; |
| 617 | } else { |
| 618 | tuner->rangelow = tv_range[0] * 16; |
| 619 | tuner->rangehigh = tv_range[1] * 16; |
| 620 | } |
| 621 | break; |
| 622 | } |
| 623 | case VIDIOC_S_TUNER: |
| 624 | { |
| 625 | struct v4l2_tuner *tuner = arg; |
| 626 | |
| 627 | if (check_mode(t, "VIDIOC_S_TUNER") == EINVAL) |
| 628 | return 0; |
| 629 | |
| 630 | switch_v4l2(); |
| 631 | |
| 632 | if (V4L2_TUNER_RADIO == t->mode) { |
| 633 | t->audmode = tuner->audmode; |
| 634 | set_radio_freq(client, t->freq); |
| 635 | } |
| 636 | break; |
| 637 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | default: |
Mauro Carvalho Chehab | c5287ba | 2005-07-15 03:56:28 -0700 | [diff] [blame^] | 639 | tuner_dbg("Unimplemented IOCTL 0x%08x(dir=%d,tp=0x%02x,nr=%d,sz=%d)\n", |
| 640 | cmd, _IOC_DIR(cmd), _IOC_TYPE(cmd), |
| 641 | _IOC_NR(cmd), _IOC_SIZE(cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | break; |
| 643 | } |
| 644 | |
| 645 | return 0; |
| 646 | } |
| 647 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 648 | static int tuner_suspend(struct device *dev, u32 state, u32 level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | { |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 650 | struct i2c_client *c = container_of (dev, struct i2c_client, dev); |
| 651 | struct tuner *t = i2c_get_clientdata (c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 653 | tuner_dbg ("suspend\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | /* FIXME: power down ??? */ |
| 655 | return 0; |
| 656 | } |
| 657 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 658 | static int tuner_resume(struct device *dev, u32 level) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | { |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 660 | struct i2c_client *c = container_of (dev, struct i2c_client, dev); |
| 661 | struct tuner *t = i2c_get_clientdata (c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 663 | tuner_dbg ("resume\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | if (t->freq) |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 665 | set_freq(c, t->freq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | /* ----------------------------------------------------------------------- */ |
| 670 | |
| 671 | static struct i2c_driver driver = { |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 672 | .owner = THIS_MODULE, |
| 673 | .name = "tuner", |
| 674 | .id = I2C_DRIVERID_TUNER, |
| 675 | .flags = I2C_DF_NOTIFY, |
| 676 | .attach_adapter = tuner_probe, |
| 677 | .detach_client = tuner_detach, |
| 678 | .command = tuner_command, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | .driver = { |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 680 | .suspend = tuner_suspend, |
| 681 | .resume = tuner_resume, |
| 682 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | }; |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 684 | static struct i2c_client client_template = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | I2C_DEVNAME("(tuner unset)"), |
Mauro Carvalho Chehab | f7ce3cc | 2005-07-12 13:58:55 -0700 | [diff] [blame] | 686 | .flags = I2C_CLIENT_ALLOW_USE, |
| 687 | .driver = &driver, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | }; |
| 689 | |
| 690 | static int __init tuner_init_module(void) |
| 691 | { |
| 692 | return i2c_add_driver(&driver); |
| 693 | } |
| 694 | |
| 695 | static void __exit tuner_cleanup_module(void) |
| 696 | { |
| 697 | i2c_del_driver(&driver); |
| 698 | } |
| 699 | |
| 700 | module_init(tuner_init_module); |
| 701 | module_exit(tuner_cleanup_module); |
| 702 | |
| 703 | /* |
| 704 | * Overrides for Emacs so that we follow Linus's tabbing style. |
| 705 | * --------------------------------------------------------------------------- |
| 706 | * Local variables: |
| 707 | * c-basic-offset: 8 |
| 708 | * End: |
| 709 | */ |