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