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