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