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