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