diff options
author | Rusty Russell <rusty@rustcorp.com.au> | 2008-12-31 07:35:57 -0500 |
---|---|---|
committer | Rusty Russell <rusty@rustcorp.com.au> | 2008-12-31 07:35:57 -0500 |
commit | 2ca1a615835d9f4990f42102ab1f2ef434e7e89c (patch) | |
tree | 726cf3d5f29a6c66c44e4bd68e7ebed2fd83d059 /drivers/media/video/tvaudio.c | |
parent | e12f0102ac81d660c9f801d0a0e10ccf4537a9de (diff) | |
parent | 6a94cb73064c952255336cc57731904174b2c58f (diff) |
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Conflicts:
arch/x86/kernel/io_apic.c
Diffstat (limited to 'drivers/media/video/tvaudio.c')
-rw-r--r-- | drivers/media/video/tvaudio.c | 707 |
1 files changed, 383 insertions, 324 deletions
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c index 3720f0e03a16..d0c794da735b 100644 --- a/drivers/media/video/tvaudio.c +++ b/drivers/media/video/tvaudio.c | |||
@@ -33,8 +33,7 @@ | |||
33 | #include <linux/freezer.h> | 33 | #include <linux/freezer.h> |
34 | 34 | ||
35 | #include <media/tvaudio.h> | 35 | #include <media/tvaudio.h> |
36 | #include <media/v4l2-common.h> | 36 | #include <media/v4l2-device.h> |
37 | #include <media/v4l2-ioctl.h> | ||
38 | #include <media/v4l2-chip-ident.h> | 37 | #include <media/v4l2-chip-ident.h> |
39 | #include <media/v4l2-i2c-drv-legacy.h> | 38 | #include <media/v4l2-i2c-drv-legacy.h> |
40 | 39 | ||
@@ -110,7 +109,7 @@ struct CHIPDESC { | |||
110 | 109 | ||
111 | /* current state of the chip */ | 110 | /* current state of the chip */ |
112 | struct CHIPSTATE { | 111 | struct CHIPSTATE { |
113 | struct i2c_client *c; | 112 | struct v4l2_subdev sd; |
114 | 113 | ||
115 | /* chip-specific description - should point to | 114 | /* chip-specific description - should point to |
116 | an entry at CHIPDESC table */ | 115 | an entry at CHIPDESC table */ |
@@ -132,6 +131,11 @@ struct CHIPSTATE { | |||
132 | int audmode; | 131 | int audmode; |
133 | }; | 132 | }; |
134 | 133 | ||
134 | static inline struct CHIPSTATE *to_state(struct v4l2_subdev *sd) | ||
135 | { | ||
136 | return container_of(sd, struct CHIPSTATE, sd); | ||
137 | } | ||
138 | |||
135 | /* ---------------------------------------------------------------------- */ | 139 | /* ---------------------------------------------------------------------- */ |
136 | /* i2c addresses */ | 140 | /* i2c addresses */ |
137 | 141 | ||
@@ -152,34 +156,34 @@ I2C_CLIENT_INSMOD; | |||
152 | 156 | ||
153 | static int chip_write(struct CHIPSTATE *chip, int subaddr, int val) | 157 | static int chip_write(struct CHIPSTATE *chip, int subaddr, int val) |
154 | { | 158 | { |
159 | struct v4l2_subdev *sd = &chip->sd; | ||
160 | struct i2c_client *c = v4l2_get_subdevdata(sd); | ||
155 | unsigned char buffer[2]; | 161 | unsigned char buffer[2]; |
156 | 162 | ||
157 | if (subaddr < 0) { | 163 | if (subaddr < 0) { |
158 | v4l_dbg(1, debug, chip->c, "%s: chip_write: 0x%x\n", | 164 | v4l2_dbg(1, debug, sd, "chip_write: 0x%x\n", val); |
159 | chip->c->name, val); | ||
160 | chip->shadow.bytes[1] = val; | 165 | chip->shadow.bytes[1] = val; |
161 | buffer[0] = val; | 166 | buffer[0] = val; |
162 | if (1 != i2c_master_send(chip->c,buffer,1)) { | 167 | if (1 != i2c_master_send(c, buffer, 1)) { |
163 | v4l_warn(chip->c, "%s: I/O error (write 0x%x)\n", | 168 | v4l2_warn(sd, "I/O error (write 0x%x)\n", val); |
164 | chip->c->name, val); | ||
165 | return -1; | 169 | return -1; |
166 | } | 170 | } |
167 | } else { | 171 | } else { |
168 | if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) { | 172 | if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) { |
169 | v4l_info(chip->c, | 173 | v4l2_info(sd, |
170 | "Tried to access a non-existent register: %d\n", | 174 | "Tried to access a non-existent register: %d\n", |
171 | subaddr); | 175 | subaddr); |
172 | return -EINVAL; | 176 | return -EINVAL; |
173 | } | 177 | } |
174 | 178 | ||
175 | v4l_dbg(1, debug, chip->c, "%s: chip_write: reg%d=0x%x\n", | 179 | v4l2_dbg(1, debug, sd, "chip_write: reg%d=0x%x\n", |
176 | chip->c->name, subaddr, val); | 180 | subaddr, val); |
177 | chip->shadow.bytes[subaddr+1] = val; | 181 | chip->shadow.bytes[subaddr+1] = val; |
178 | buffer[0] = subaddr; | 182 | buffer[0] = subaddr; |
179 | buffer[1] = val; | 183 | buffer[1] = val; |
180 | if (2 != i2c_master_send(chip->c,buffer,2)) { | 184 | if (2 != i2c_master_send(c, buffer, 2)) { |
181 | v4l_warn(chip->c, "%s: I/O error (write reg%d=0x%x)\n", | 185 | v4l2_warn(sd, "I/O error (write reg%d=0x%x)\n", |
182 | chip->c->name, subaddr, val); | 186 | subaddr, val); |
183 | return -1; | 187 | return -1; |
184 | } | 188 | } |
185 | } | 189 | } |
@@ -189,12 +193,14 @@ static int chip_write(struct CHIPSTATE *chip, int subaddr, int val) | |||
189 | static int chip_write_masked(struct CHIPSTATE *chip, | 193 | static int chip_write_masked(struct CHIPSTATE *chip, |
190 | int subaddr, int val, int mask) | 194 | int subaddr, int val, int mask) |
191 | { | 195 | { |
196 | struct v4l2_subdev *sd = &chip->sd; | ||
197 | |||
192 | if (mask != 0) { | 198 | if (mask != 0) { |
193 | if (subaddr < 0) { | 199 | if (subaddr < 0) { |
194 | val = (chip->shadow.bytes[1] & ~mask) | (val & mask); | 200 | val = (chip->shadow.bytes[1] & ~mask) | (val & mask); |
195 | } else { | 201 | } else { |
196 | if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) { | 202 | if (subaddr + 1 >= ARRAY_SIZE(chip->shadow.bytes)) { |
197 | v4l_info(chip->c, | 203 | v4l2_info(sd, |
198 | "Tried to access a non-existent register: %d\n", | 204 | "Tried to access a non-existent register: %d\n", |
199 | subaddr); | 205 | subaddr); |
200 | return -EINVAL; | 206 | return -EINVAL; |
@@ -208,45 +214,51 @@ static int chip_write_masked(struct CHIPSTATE *chip, | |||
208 | 214 | ||
209 | static int chip_read(struct CHIPSTATE *chip) | 215 | static int chip_read(struct CHIPSTATE *chip) |
210 | { | 216 | { |
217 | struct v4l2_subdev *sd = &chip->sd; | ||
218 | struct i2c_client *c = v4l2_get_subdevdata(sd); | ||
211 | unsigned char buffer; | 219 | unsigned char buffer; |
212 | 220 | ||
213 | if (1 != i2c_master_recv(chip->c,&buffer,1)) { | 221 | if (1 != i2c_master_recv(c, &buffer, 1)) { |
214 | v4l_warn(chip->c, "%s: I/O error (read)\n", | 222 | v4l2_warn(sd, "I/O error (read)\n"); |
215 | chip->c->name); | ||
216 | return -1; | 223 | return -1; |
217 | } | 224 | } |
218 | v4l_dbg(1, debug, chip->c, "%s: chip_read: 0x%x\n",chip->c->name, buffer); | 225 | v4l2_dbg(1, debug, sd, "chip_read: 0x%x\n", buffer); |
219 | return buffer; | 226 | return buffer; |
220 | } | 227 | } |
221 | 228 | ||
222 | static int chip_read2(struct CHIPSTATE *chip, int subaddr) | 229 | static int chip_read2(struct CHIPSTATE *chip, int subaddr) |
223 | { | 230 | { |
231 | struct v4l2_subdev *sd = &chip->sd; | ||
232 | struct i2c_client *c = v4l2_get_subdevdata(sd); | ||
224 | unsigned char write[1]; | 233 | unsigned char write[1]; |
225 | unsigned char read[1]; | 234 | unsigned char read[1]; |
226 | struct i2c_msg msgs[2] = { | 235 | struct i2c_msg msgs[2] = { |
227 | { chip->c->addr, 0, 1, write }, | 236 | { c->addr, 0, 1, write }, |
228 | { chip->c->addr, I2C_M_RD, 1, read } | 237 | { c->addr, I2C_M_RD, 1, read } |
229 | }; | 238 | }; |
239 | |||
230 | write[0] = subaddr; | 240 | write[0] = subaddr; |
231 | 241 | ||
232 | if (2 != i2c_transfer(chip->c->adapter,msgs,2)) { | 242 | if (2 != i2c_transfer(c->adapter, msgs, 2)) { |
233 | v4l_warn(chip->c, "%s: I/O error (read2)\n", chip->c->name); | 243 | v4l2_warn(sd, "I/O error (read2)\n"); |
234 | return -1; | 244 | return -1; |
235 | } | 245 | } |
236 | v4l_dbg(1, debug, chip->c, "%s: chip_read2: reg%d=0x%x\n", | 246 | v4l2_dbg(1, debug, sd, "chip_read2: reg%d=0x%x\n", |
237 | chip->c->name, subaddr,read[0]); | 247 | subaddr, read[0]); |
238 | return read[0]; | 248 | return read[0]; |
239 | } | 249 | } |
240 | 250 | ||
241 | static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd) | 251 | static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd) |
242 | { | 252 | { |
253 | struct v4l2_subdev *sd = &chip->sd; | ||
254 | struct i2c_client *c = v4l2_get_subdevdata(sd); | ||
243 | int i; | 255 | int i; |
244 | 256 | ||
245 | if (0 == cmd->count) | 257 | if (0 == cmd->count) |
246 | return 0; | 258 | return 0; |
247 | 259 | ||
248 | if (cmd->count + cmd->bytes[0] - 1 >= ARRAY_SIZE(chip->shadow.bytes)) { | 260 | if (cmd->count + cmd->bytes[0] - 1 >= ARRAY_SIZE(chip->shadow.bytes)) { |
249 | v4l_info(chip->c, | 261 | v4l2_info(sd, |
250 | "Tried to access a non-existent register range: %d to %d\n", | 262 | "Tried to access a non-existent register range: %d to %d\n", |
251 | cmd->bytes[0] + 1, cmd->bytes[0] + cmd->count - 1); | 263 | cmd->bytes[0] + 1, cmd->bytes[0] + cmd->count - 1); |
252 | return -EINVAL; | 264 | return -EINVAL; |
@@ -255,19 +267,19 @@ static int chip_cmd(struct CHIPSTATE *chip, char *name, audiocmd *cmd) | |||
255 | /* FIXME: it seems that the shadow bytes are wrong bellow !*/ | 267 | /* FIXME: it seems that the shadow bytes are wrong bellow !*/ |
256 | 268 | ||
257 | /* update our shadow register set; print bytes if (debug > 0) */ | 269 | /* update our shadow register set; print bytes if (debug > 0) */ |
258 | v4l_dbg(1, debug, chip->c, "%s: chip_cmd(%s): reg=%d, data:", | 270 | v4l2_dbg(1, debug, sd, "chip_cmd(%s): reg=%d, data:", |
259 | chip->c->name, name,cmd->bytes[0]); | 271 | name, cmd->bytes[0]); |
260 | for (i = 1; i < cmd->count; i++) { | 272 | for (i = 1; i < cmd->count; i++) { |
261 | if (debug) | 273 | if (debug) |
262 | printk(" 0x%x",cmd->bytes[i]); | 274 | printk(KERN_CONT " 0x%x", cmd->bytes[i]); |
263 | chip->shadow.bytes[i+cmd->bytes[0]] = cmd->bytes[i]; | 275 | chip->shadow.bytes[i+cmd->bytes[0]] = cmd->bytes[i]; |
264 | } | 276 | } |
265 | if (debug) | 277 | if (debug) |
266 | printk("\n"); | 278 | printk(KERN_CONT "\n"); |
267 | 279 | ||
268 | /* send data to the chip */ | 280 | /* send data to the chip */ |
269 | if (cmd->count != i2c_master_send(chip->c,cmd->bytes,cmd->count)) { | 281 | if (cmd->count != i2c_master_send(c, cmd->bytes, cmd->count)) { |
270 | v4l_warn(chip->c, "%s: I/O error (%s)\n", chip->c->name, name); | 282 | v4l2_warn(sd, "I/O error (%s)\n", name); |
271 | return -1; | 283 | return -1; |
272 | } | 284 | } |
273 | return 0; | 285 | return 0; |
@@ -290,9 +302,10 @@ static int chip_thread(void *data) | |||
290 | { | 302 | { |
291 | struct CHIPSTATE *chip = data; | 303 | struct CHIPSTATE *chip = data; |
292 | struct CHIPDESC *desc = chip->desc; | 304 | struct CHIPDESC *desc = chip->desc; |
305 | struct v4l2_subdev *sd = &chip->sd; | ||
293 | int mode; | 306 | int mode; |
294 | 307 | ||
295 | v4l_dbg(1, debug, chip->c, "%s: thread started\n", chip->c->name); | 308 | v4l2_dbg(1, debug, sd, "thread started\n"); |
296 | set_freezable(); | 309 | set_freezable(); |
297 | for (;;) { | 310 | for (;;) { |
298 | set_current_state(TASK_INTERRUPTIBLE); | 311 | set_current_state(TASK_INTERRUPTIBLE); |
@@ -302,7 +315,7 @@ static int chip_thread(void *data) | |||
302 | try_to_freeze(); | 315 | try_to_freeze(); |
303 | if (kthread_should_stop()) | 316 | if (kthread_should_stop()) |
304 | break; | 317 | break; |
305 | v4l_dbg(1, debug, chip->c, "%s: thread wakeup\n", chip->c->name); | 318 | v4l2_dbg(1, debug, sd, "thread wakeup\n"); |
306 | 319 | ||
307 | /* don't do anything for radio or if mode != auto */ | 320 | /* don't do anything for radio or if mode != auto */ |
308 | if (chip->radio || chip->mode != 0) | 321 | if (chip->radio || chip->mode != 0) |
@@ -314,8 +327,7 @@ static int chip_thread(void *data) | |||
314 | continue; | 327 | continue; |
315 | 328 | ||
316 | /* chip detected a new audio mode - set it */ | 329 | /* chip detected a new audio mode - set it */ |
317 | v4l_dbg(1, debug, chip->c, "%s: thread checkmode\n", | 330 | v4l2_dbg(1, debug, sd, "thread checkmode\n"); |
318 | chip->c->name); | ||
319 | 331 | ||
320 | chip->prevmode = mode; | 332 | chip->prevmode = mode; |
321 | 333 | ||
@@ -334,7 +346,7 @@ static int chip_thread(void *data) | |||
334 | mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000)); | 346 | mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000)); |
335 | } | 347 | } |
336 | 348 | ||
337 | v4l_dbg(1, debug, chip->c, "%s: thread exiting\n", chip->c->name); | 349 | v4l2_dbg(1, debug, sd, "thread exiting\n"); |
338 | return 0; | 350 | return 0; |
339 | } | 351 | } |
340 | 352 | ||
@@ -363,6 +375,7 @@ static int chip_thread(void *data) | |||
363 | 375 | ||
364 | static int tda9840_getmode(struct CHIPSTATE *chip) | 376 | static int tda9840_getmode(struct CHIPSTATE *chip) |
365 | { | 377 | { |
378 | struct v4l2_subdev *sd = &chip->sd; | ||
366 | int val, mode; | 379 | int val, mode; |
367 | 380 | ||
368 | val = chip_read(chip); | 381 | val = chip_read(chip); |
@@ -372,7 +385,7 @@ static int tda9840_getmode(struct CHIPSTATE *chip) | |||
372 | if (val & TDA9840_ST_STEREO) | 385 | if (val & TDA9840_ST_STEREO) |
373 | mode |= V4L2_TUNER_MODE_STEREO; | 386 | mode |= V4L2_TUNER_MODE_STEREO; |
374 | 387 | ||
375 | v4l_dbg(1, debug, chip->c, "tda9840_getmode(): raw chip read: %d, return: %d\n", | 388 | v4l2_dbg(1, debug, sd, "tda9840_getmode(): raw chip read: %d, return: %d\n", |
376 | val, mode); | 389 | val, mode); |
377 | return mode; | 390 | return mode; |
378 | } | 391 | } |
@@ -668,6 +681,7 @@ static void tda985x_setmode(struct CHIPSTATE *chip, int mode) | |||
668 | 681 | ||
669 | static int tda9873_getmode(struct CHIPSTATE *chip) | 682 | static int tda9873_getmode(struct CHIPSTATE *chip) |
670 | { | 683 | { |
684 | struct v4l2_subdev *sd = &chip->sd; | ||
671 | int val,mode; | 685 | int val,mode; |
672 | 686 | ||
673 | val = chip_read(chip); | 687 | val = chip_read(chip); |
@@ -676,23 +690,24 @@ static int tda9873_getmode(struct CHIPSTATE *chip) | |||
676 | mode |= V4L2_TUNER_MODE_STEREO; | 690 | mode |= V4L2_TUNER_MODE_STEREO; |
677 | if (val & TDA9873_DUAL) | 691 | if (val & TDA9873_DUAL) |
678 | mode |= V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; | 692 | mode |= V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; |
679 | v4l_dbg(1, debug, chip->c, "tda9873_getmode(): raw chip read: %d, return: %d\n", | 693 | v4l2_dbg(1, debug, sd, "tda9873_getmode(): raw chip read: %d, return: %d\n", |
680 | val, mode); | 694 | val, mode); |
681 | return mode; | 695 | return mode; |
682 | } | 696 | } |
683 | 697 | ||
684 | static void tda9873_setmode(struct CHIPSTATE *chip, int mode) | 698 | static void tda9873_setmode(struct CHIPSTATE *chip, int mode) |
685 | { | 699 | { |
700 | struct v4l2_subdev *sd = &chip->sd; | ||
686 | int sw_data = chip->shadow.bytes[TDA9873_SW+1] & ~ TDA9873_TR_MASK; | 701 | int sw_data = chip->shadow.bytes[TDA9873_SW+1] & ~ TDA9873_TR_MASK; |
687 | /* int adj_data = chip->shadow.bytes[TDA9873_AD+1] ; */ | 702 | /* int adj_data = chip->shadow.bytes[TDA9873_AD+1] ; */ |
688 | 703 | ||
689 | if ((sw_data & TDA9873_INP_MASK) != TDA9873_INTERNAL) { | 704 | if ((sw_data & TDA9873_INP_MASK) != TDA9873_INTERNAL) { |
690 | v4l_dbg(1, debug, chip->c, "tda9873_setmode(): external input\n"); | 705 | v4l2_dbg(1, debug, sd, "tda9873_setmode(): external input\n"); |
691 | return; | 706 | return; |
692 | } | 707 | } |
693 | 708 | ||
694 | v4l_dbg(1, debug, chip->c, "tda9873_setmode(): chip->shadow.bytes[%d] = %d\n", TDA9873_SW+1, chip->shadow.bytes[TDA9873_SW+1]); | 709 | v4l2_dbg(1, debug, sd, "tda9873_setmode(): chip->shadow.bytes[%d] = %d\n", TDA9873_SW+1, chip->shadow.bytes[TDA9873_SW+1]); |
695 | v4l_dbg(1, debug, chip->c, "tda9873_setmode(): sw_data = %d\n", sw_data); | 710 | v4l2_dbg(1, debug, sd, "tda9873_setmode(): sw_data = %d\n", sw_data); |
696 | 711 | ||
697 | switch (mode) { | 712 | switch (mode) { |
698 | case V4L2_TUNER_MODE_MONO: | 713 | case V4L2_TUNER_MODE_MONO: |
@@ -713,7 +728,7 @@ static void tda9873_setmode(struct CHIPSTATE *chip, int mode) | |||
713 | } | 728 | } |
714 | 729 | ||
715 | chip_write(chip, TDA9873_SW, sw_data); | 730 | chip_write(chip, TDA9873_SW, sw_data); |
716 | v4l_dbg(1, debug, chip->c, "tda9873_setmode(): req. mode %d; chip_write: %d\n", | 731 | v4l2_dbg(1, debug, sd, "tda9873_setmode(): req. mode %d; chip_write: %d\n", |
717 | mode, sw_data); | 732 | mode, sw_data); |
718 | } | 733 | } |
719 | 734 | ||
@@ -822,6 +837,8 @@ static struct tda9874a_MODES { | |||
822 | 837 | ||
823 | static int tda9874a_setup(struct CHIPSTATE *chip) | 838 | static int tda9874a_setup(struct CHIPSTATE *chip) |
824 | { | 839 | { |
840 | struct v4l2_subdev *sd = &chip->sd; | ||
841 | |||
825 | chip_write(chip, TDA9874A_AGCGR, 0x00); /* 0 dB */ | 842 | chip_write(chip, TDA9874A_AGCGR, 0x00); /* 0 dB */ |
826 | chip_write(chip, TDA9874A_GCONR, tda9874a_GCONR); | 843 | chip_write(chip, TDA9874A_GCONR, tda9874a_GCONR); |
827 | chip_write(chip, TDA9874A_MSR, (tda9874a_mode) ? 0x03:0x02); | 844 | chip_write(chip, TDA9874A_MSR, (tda9874a_mode) ? 0x03:0x02); |
@@ -852,13 +869,14 @@ static int tda9874a_setup(struct CHIPSTATE *chip) | |||
852 | chip_write(chip, TDA9874A_SDACOSR, (tda9874a_mode) ? 0x81:0x80); | 869 | chip_write(chip, TDA9874A_SDACOSR, (tda9874a_mode) ? 0x81:0x80); |
853 | chip_write(chip, TDA9874A_AOSR, 0x00); /* or 0x10 */ | 870 | chip_write(chip, TDA9874A_AOSR, 0x00); /* or 0x10 */ |
854 | } | 871 | } |
855 | v4l_dbg(1, debug, chip->c, "tda9874a_setup(): %s [0x%02X].\n", | 872 | v4l2_dbg(1, debug, sd, "tda9874a_setup(): %s [0x%02X].\n", |
856 | tda9874a_modelist[tda9874a_STD].name,tda9874a_STD); | 873 | tda9874a_modelist[tda9874a_STD].name,tda9874a_STD); |
857 | return 1; | 874 | return 1; |
858 | } | 875 | } |
859 | 876 | ||
860 | static int tda9874a_getmode(struct CHIPSTATE *chip) | 877 | static int tda9874a_getmode(struct CHIPSTATE *chip) |
861 | { | 878 | { |
879 | struct v4l2_subdev *sd = &chip->sd; | ||
862 | int dsr,nsr,mode; | 880 | int dsr,nsr,mode; |
863 | int necr; /* just for debugging */ | 881 | int necr; /* just for debugging */ |
864 | 882 | ||
@@ -895,16 +913,18 @@ static int tda9874a_getmode(struct CHIPSTATE *chip) | |||
895 | mode |= V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; | 913 | mode |= V4L2_TUNER_MODE_LANG1 | V4L2_TUNER_MODE_LANG2; |
896 | } | 914 | } |
897 | 915 | ||
898 | v4l_dbg(1, debug, chip->c, "tda9874a_getmode(): DSR=0x%X, NSR=0x%X, NECR=0x%X, return: %d.\n", | 916 | v4l2_dbg(1, debug, sd, "tda9874a_getmode(): DSR=0x%X, NSR=0x%X, NECR=0x%X, return: %d.\n", |
899 | dsr, nsr, necr, mode); | 917 | dsr, nsr, necr, mode); |
900 | return mode; | 918 | return mode; |
901 | } | 919 | } |
902 | 920 | ||
903 | static void tda9874a_setmode(struct CHIPSTATE *chip, int mode) | 921 | static void tda9874a_setmode(struct CHIPSTATE *chip, int mode) |
904 | { | 922 | { |
923 | struct v4l2_subdev *sd = &chip->sd; | ||
924 | |||
905 | /* Disable/enable NICAM auto-muting (based on DSR.RSSF status bit). */ | 925 | /* Disable/enable NICAM auto-muting (based on DSR.RSSF status bit). */ |
906 | /* If auto-muting is disabled, we can hear a signal of degrading quality. */ | 926 | /* If auto-muting is disabled, we can hear a signal of degrading quality. */ |
907 | if(tda9874a_mode) { | 927 | if (tda9874a_mode) { |
908 | if(chip->shadow.bytes[MAXREGS-2] & 0x20) /* DSR.RSSF=1 */ | 928 | if(chip->shadow.bytes[MAXREGS-2] & 0x20) /* DSR.RSSF=1 */ |
909 | tda9874a_NCONR &= 0xfe; /* enable */ | 929 | tda9874a_NCONR &= 0xfe; /* enable */ |
910 | else | 930 | else |
@@ -941,7 +961,7 @@ static void tda9874a_setmode(struct CHIPSTATE *chip, int mode) | |||
941 | chip_write(chip, TDA9874A_AOSR, aosr); | 961 | chip_write(chip, TDA9874A_AOSR, aosr); |
942 | chip_write(chip, TDA9874A_MDACOSR, mdacosr); | 962 | chip_write(chip, TDA9874A_MDACOSR, mdacosr); |
943 | 963 | ||
944 | v4l_dbg(1, debug, chip->c, "tda9874a_setmode(): req. mode %d; AOSR=0x%X, MDACOSR=0x%X.\n", | 964 | v4l2_dbg(1, debug, sd, "tda9874a_setmode(): req. mode %d; AOSR=0x%X, MDACOSR=0x%X.\n", |
945 | mode, aosr, mdacosr); | 965 | mode, aosr, mdacosr); |
946 | 966 | ||
947 | } else { /* dic == 0x07 */ | 967 | } else { /* dic == 0x07 */ |
@@ -976,13 +996,14 @@ static void tda9874a_setmode(struct CHIPSTATE *chip, int mode) | |||
976 | chip_write(chip, TDA9874A_FMMR, fmmr); | 996 | chip_write(chip, TDA9874A_FMMR, fmmr); |
977 | chip_write(chip, TDA9874A_AOSR, aosr); | 997 | chip_write(chip, TDA9874A_AOSR, aosr); |
978 | 998 | ||
979 | v4l_dbg(1, debug, chip->c, "tda9874a_setmode(): req. mode %d; FMMR=0x%X, AOSR=0x%X.\n", | 999 | v4l2_dbg(1, debug, sd, "tda9874a_setmode(): req. mode %d; FMMR=0x%X, AOSR=0x%X.\n", |
980 | mode, fmmr, aosr); | 1000 | mode, fmmr, aosr); |
981 | } | 1001 | } |
982 | } | 1002 | } |
983 | 1003 | ||
984 | static int tda9874a_checkit(struct CHIPSTATE *chip) | 1004 | static int tda9874a_checkit(struct CHIPSTATE *chip) |
985 | { | 1005 | { |
1006 | struct v4l2_subdev *sd = &chip->sd; | ||
986 | int dic,sic; /* device id. and software id. codes */ | 1007 | int dic,sic; /* device id. and software id. codes */ |
987 | 1008 | ||
988 | if(-1 == (dic = chip_read2(chip,TDA9874A_DIC))) | 1009 | if(-1 == (dic = chip_read2(chip,TDA9874A_DIC))) |
@@ -990,10 +1011,10 @@ static int tda9874a_checkit(struct CHIPSTATE *chip) | |||
990 | if(-1 == (sic = chip_read2(chip,TDA9874A_SIC))) | 1011 | if(-1 == (sic = chip_read2(chip,TDA9874A_SIC))) |
991 | return 0; | 1012 | return 0; |
992 | 1013 | ||
993 | v4l_dbg(1, debug, chip->c, "tda9874a_checkit(): DIC=0x%X, SIC=0x%X.\n", dic, sic); | 1014 | v4l2_dbg(1, debug, sd, "tda9874a_checkit(): DIC=0x%X, SIC=0x%X.\n", dic, sic); |
994 | 1015 | ||
995 | if((dic == 0x11)||(dic == 0x07)) { | 1016 | if((dic == 0x11)||(dic == 0x07)) { |
996 | v4l_info(chip->c, "found tda9874%s.\n", (dic == 0x11) ? "a":"h"); | 1017 | v4l2_info(sd, "found tda9874%s.\n", (dic == 0x11) ? "a" : "h"); |
997 | tda9874a_dic = dic; /* remember device id. */ | 1018 | tda9874a_dic = dic; /* remember device id. */ |
998 | return 1; | 1019 | return 1; |
999 | } | 1020 | } |
@@ -1113,12 +1134,12 @@ static int tda8425_shift12(int val) { return (val >> 12) | 0xf0; } | |||
1113 | static int tda8425_initialize(struct CHIPSTATE *chip) | 1134 | static int tda8425_initialize(struct CHIPSTATE *chip) |
1114 | { | 1135 | { |
1115 | struct CHIPDESC *desc = chip->desc; | 1136 | struct CHIPDESC *desc = chip->desc; |
1137 | struct i2c_client *c = v4l2_get_subdevdata(&chip->sd); | ||
1116 | int inputmap[4] = { /* tuner */ TDA8425_S1_CH2, /* radio */ TDA8425_S1_CH1, | 1138 | int inputmap[4] = { /* tuner */ TDA8425_S1_CH2, /* radio */ TDA8425_S1_CH1, |
1117 | /* extern */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF}; | 1139 | /* extern */ TDA8425_S1_CH1, /* intern */ TDA8425_S1_OFF}; |
1118 | 1140 | ||
1119 | if (chip->c->adapter->id == I2C_HW_B_RIVA) { | 1141 | if (c->adapter->id == I2C_HW_B_RIVA) |
1120 | memcpy (desc->inputmap, inputmap, sizeof (inputmap)); | 1142 | memcpy(desc->inputmap, inputmap, sizeof(inputmap)); |
1121 | } | ||
1122 | return 0; | 1143 | return 0; |
1123 | } | 1144 | } |
1124 | 1145 | ||
@@ -1215,9 +1236,11 @@ static audiocmd ta8874z_sub = {2, { TA8874Z_MODE_SUB, TA8874Z_SEPARATION_DEFAULT | |||
1215 | 1236 | ||
1216 | static void ta8874z_setmode(struct CHIPSTATE *chip, int mode) | 1237 | static void ta8874z_setmode(struct CHIPSTATE *chip, int mode) |
1217 | { | 1238 | { |
1239 | struct v4l2_subdev *sd = &chip->sd; | ||
1218 | int update = 1; | 1240 | int update = 1; |
1219 | audiocmd *t = NULL; | 1241 | audiocmd *t = NULL; |
1220 | v4l_dbg(1, debug, chip->c, "ta8874z_setmode(): mode: 0x%02x\n", mode); | 1242 | |
1243 | v4l2_dbg(1, debug, sd, "ta8874z_setmode(): mode: 0x%02x\n", mode); | ||
1221 | 1244 | ||
1222 | switch(mode){ | 1245 | switch(mode){ |
1223 | case V4L2_TUNER_MODE_MONO: | 1246 | case V4L2_TUNER_MODE_MONO: |
@@ -1479,142 +1502,11 @@ static struct CHIPDESC chiplist[] = { | |||
1479 | 1502 | ||
1480 | 1503 | ||
1481 | /* ---------------------------------------------------------------------- */ | 1504 | /* ---------------------------------------------------------------------- */ |
1482 | /* i2c registration */ | ||
1483 | |||
1484 | static int chip_probe(struct i2c_client *client, const struct i2c_device_id *id) | ||
1485 | { | ||
1486 | struct CHIPSTATE *chip; | ||
1487 | struct CHIPDESC *desc; | ||
1488 | |||
1489 | if (debug) { | ||
1490 | printk(KERN_INFO "tvaudio: TV audio decoder + audio/video mux driver\n"); | ||
1491 | printk(KERN_INFO "tvaudio: known chips: "); | ||
1492 | for (desc = chiplist; desc->name != NULL; desc++) | ||
1493 | printk("%s%s", (desc == chiplist) ? "" : ", ", desc->name); | ||
1494 | printk("\n"); | ||
1495 | } | ||
1496 | |||
1497 | chip = kzalloc(sizeof(*chip),GFP_KERNEL); | ||
1498 | if (!chip) | ||
1499 | return -ENOMEM; | ||
1500 | chip->c = client; | ||
1501 | i2c_set_clientdata(client, chip); | ||
1502 | 1505 | ||
1503 | /* find description for the chip */ | 1506 | static int tvaudio_g_ctrl(struct v4l2_subdev *sd, |
1504 | v4l_dbg(1, debug, client, "chip found @ 0x%x\n", client->addr<<1); | ||
1505 | for (desc = chiplist; desc->name != NULL; desc++) { | ||
1506 | if (0 == *(desc->insmodopt)) | ||
1507 | continue; | ||
1508 | if (client->addr < desc->addr_lo || | ||
1509 | client->addr > desc->addr_hi) | ||
1510 | continue; | ||
1511 | if (desc->checkit && !desc->checkit(chip)) | ||
1512 | continue; | ||
1513 | break; | ||
1514 | } | ||
1515 | if (desc->name == NULL) { | ||
1516 | v4l_dbg(1, debug, client, "no matching chip description found\n"); | ||
1517 | kfree(chip); | ||
1518 | return -EIO; | ||
1519 | } | ||
1520 | v4l_info(client, "%s found @ 0x%x (%s)\n", desc->name, client->addr<<1, client->adapter->name); | ||
1521 | if (desc->flags) { | ||
1522 | v4l_dbg(1, debug, client, "matches:%s%s%s.\n", | ||
1523 | (desc->flags & CHIP_HAS_VOLUME) ? " volume" : "", | ||
1524 | (desc->flags & CHIP_HAS_BASSTREBLE) ? " bass/treble" : "", | ||
1525 | (desc->flags & CHIP_HAS_INPUTSEL) ? " audiomux" : ""); | ||
1526 | } | ||
1527 | |||
1528 | /* fill required data structures */ | ||
1529 | if (!id) | ||
1530 | strlcpy(client->name, desc->name, I2C_NAME_SIZE); | ||
1531 | chip->desc = desc; | ||
1532 | chip->shadow.count = desc->registers+1; | ||
1533 | chip->prevmode = -1; | ||
1534 | chip->audmode = V4L2_TUNER_MODE_LANG1; | ||
1535 | |||
1536 | /* initialization */ | ||
1537 | if (desc->initialize != NULL) | ||
1538 | desc->initialize(chip); | ||
1539 | else | ||
1540 | chip_cmd(chip,"init",&desc->init); | ||
1541 | |||
1542 | if (desc->flags & CHIP_HAS_VOLUME) { | ||
1543 | if (!desc->volfunc) { | ||
1544 | /* This shouldn't be happen. Warn user, but keep working | ||
1545 | without volume controls | ||
1546 | */ | ||
1547 | v4l_info(chip->c, "volume callback undefined!\n"); | ||
1548 | desc->flags &= ~CHIP_HAS_VOLUME; | ||
1549 | } else { | ||
1550 | chip->left = desc->leftinit ? desc->leftinit : 65535; | ||
1551 | chip->right = desc->rightinit ? desc->rightinit : 65535; | ||
1552 | chip_write(chip, desc->leftreg, | ||
1553 | desc->volfunc(chip->left)); | ||
1554 | chip_write(chip, desc->rightreg, | ||
1555 | desc->volfunc(chip->right)); | ||
1556 | } | ||
1557 | } | ||
1558 | if (desc->flags & CHIP_HAS_BASSTREBLE) { | ||
1559 | if (!desc->bassfunc || !desc->treblefunc) { | ||
1560 | /* This shouldn't be happen. Warn user, but keep working | ||
1561 | without bass/treble controls | ||
1562 | */ | ||
1563 | v4l_info(chip->c, "bass/treble callbacks undefined!\n"); | ||
1564 | desc->flags &= ~CHIP_HAS_BASSTREBLE; | ||
1565 | } else { | ||
1566 | chip->treble = desc->trebleinit ? | ||
1567 | desc->trebleinit : 32768; | ||
1568 | chip->bass = desc->bassinit ? | ||
1569 | desc->bassinit : 32768; | ||
1570 | chip_write(chip, desc->bassreg, | ||
1571 | desc->bassfunc(chip->bass)); | ||
1572 | chip_write(chip, desc->treblereg, | ||
1573 | desc->treblefunc(chip->treble)); | ||
1574 | } | ||
1575 | } | ||
1576 | |||
1577 | chip->thread = NULL; | ||
1578 | if (desc->flags & CHIP_NEED_CHECKMODE) { | ||
1579 | if (!desc->getmode || !desc->setmode) { | ||
1580 | /* This shouldn't be happen. Warn user, but keep working | ||
1581 | without kthread | ||
1582 | */ | ||
1583 | v4l_info(chip->c, "set/get mode callbacks undefined!\n"); | ||
1584 | return 0; | ||
1585 | } | ||
1586 | /* start async thread */ | ||
1587 | init_timer(&chip->wt); | ||
1588 | chip->wt.function = chip_thread_wake; | ||
1589 | chip->wt.data = (unsigned long)chip; | ||
1590 | chip->thread = kthread_run(chip_thread, chip, chip->c->name); | ||
1591 | if (IS_ERR(chip->thread)) { | ||
1592 | v4l_warn(chip->c, "%s: failed to create kthread\n", | ||
1593 | chip->c->name); | ||
1594 | chip->thread = NULL; | ||
1595 | } | ||
1596 | } | ||
1597 | return 0; | ||
1598 | } | ||
1599 | |||
1600 | static int chip_remove(struct i2c_client *client) | ||
1601 | { | ||
1602 | struct CHIPSTATE *chip = i2c_get_clientdata(client); | ||
1603 | |||
1604 | del_timer_sync(&chip->wt); | ||
1605 | if (chip->thread) { | ||
1606 | /* shutdown async thread */ | ||
1607 | kthread_stop(chip->thread); | ||
1608 | chip->thread = NULL; | ||
1609 | } | ||
1610 | |||
1611 | kfree(chip); | ||
1612 | return 0; | ||
1613 | } | ||
1614 | |||
1615 | static int tvaudio_get_ctrl(struct CHIPSTATE *chip, | ||
1616 | struct v4l2_control *ctrl) | 1507 | struct v4l2_control *ctrl) |
1617 | { | 1508 | { |
1509 | struct CHIPSTATE *chip = to_state(sd); | ||
1618 | struct CHIPDESC *desc = chip->desc; | 1510 | struct CHIPDESC *desc = chip->desc; |
1619 | 1511 | ||
1620 | switch (ctrl->id) { | 1512 | switch (ctrl->id) { |
@@ -1652,9 +1544,10 @@ static int tvaudio_get_ctrl(struct CHIPSTATE *chip, | |||
1652 | return -EINVAL; | 1544 | return -EINVAL; |
1653 | } | 1545 | } |
1654 | 1546 | ||
1655 | static int tvaudio_set_ctrl(struct CHIPSTATE *chip, | 1547 | static int tvaudio_s_ctrl(struct v4l2_subdev *sd, |
1656 | struct v4l2_control *ctrl) | 1548 | struct v4l2_control *ctrl) |
1657 | { | 1549 | { |
1550 | struct CHIPSTATE *chip = to_state(sd); | ||
1658 | struct CHIPDESC *desc = chip->desc; | 1551 | struct CHIPDESC *desc = chip->desc; |
1659 | 1552 | ||
1660 | switch (ctrl->id) { | 1553 | switch (ctrl->id) { |
@@ -1726,161 +1619,327 @@ static int tvaudio_set_ctrl(struct CHIPSTATE *chip, | |||
1726 | /* ---------------------------------------------------------------------- */ | 1619 | /* ---------------------------------------------------------------------- */ |
1727 | /* video4linux interface */ | 1620 | /* video4linux interface */ |
1728 | 1621 | ||
1729 | static int chip_command(struct i2c_client *client, | 1622 | static int tvaudio_s_radio(struct v4l2_subdev *sd) |
1730 | unsigned int cmd, void *arg) | ||
1731 | { | 1623 | { |
1732 | struct CHIPSTATE *chip = i2c_get_clientdata(client); | 1624 | struct CHIPSTATE *chip = to_state(sd); |
1733 | struct CHIPDESC *desc = chip->desc; | ||
1734 | 1625 | ||
1735 | if (debug > 0) { | 1626 | chip->radio = 1; |
1736 | v4l_i2c_print_ioctl(chip->c, cmd); | 1627 | chip->watch_stereo = 0; |
1737 | printk("\n"); | 1628 | /* del_timer(&chip->wt); */ |
1629 | return 0; | ||
1630 | } | ||
1631 | |||
1632 | static int tvaudio_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) | ||
1633 | { | ||
1634 | struct CHIPSTATE *chip = to_state(sd); | ||
1635 | struct CHIPDESC *desc = chip->desc; | ||
1636 | |||
1637 | switch (qc->id) { | ||
1638 | case V4L2_CID_AUDIO_MUTE: | ||
1639 | break; | ||
1640 | case V4L2_CID_AUDIO_VOLUME: | ||
1641 | case V4L2_CID_AUDIO_BALANCE: | ||
1642 | if (!(desc->flags & CHIP_HAS_VOLUME)) | ||
1643 | return -EINVAL; | ||
1644 | break; | ||
1645 | case V4L2_CID_AUDIO_BASS: | ||
1646 | case V4L2_CID_AUDIO_TREBLE: | ||
1647 | if (!(desc->flags & CHIP_HAS_BASSTREBLE)) | ||
1648 | return -EINVAL; | ||
1649 | break; | ||
1650 | default: | ||
1651 | return -EINVAL; | ||
1738 | } | 1652 | } |
1653 | return v4l2_ctrl_query_fill_std(qc); | ||
1654 | } | ||
1655 | |||
1656 | static int tvaudio_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *rt) | ||
1657 | { | ||
1658 | struct CHIPSTATE *chip = to_state(sd); | ||
1659 | struct CHIPDESC *desc = chip->desc; | ||
1739 | 1660 | ||
1740 | switch (cmd) { | 1661 | if (!(desc->flags & CHIP_HAS_INPUTSEL) || rt->input >= 4) |
1741 | case AUDC_SET_RADIO: | 1662 | return -EINVAL; |
1742 | chip->radio = 1; | 1663 | /* There are four inputs: tuner, radio, extern and intern. */ |
1664 | chip->input = rt->input; | ||
1665 | if (chip->muted) | ||
1666 | return 0; | ||
1667 | chip_write_masked(chip, desc->inputreg, | ||
1668 | desc->inputmap[chip->input], desc->inputmask); | ||
1669 | return 0; | ||
1670 | } | ||
1671 | |||
1672 | static int tvaudio_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) | ||
1673 | { | ||
1674 | struct CHIPSTATE *chip = to_state(sd); | ||
1675 | struct CHIPDESC *desc = chip->desc; | ||
1676 | int mode = 0; | ||
1677 | |||
1678 | if (chip->radio) | ||
1679 | return 0; | ||
1680 | switch (vt->audmode) { | ||
1681 | case V4L2_TUNER_MODE_MONO: | ||
1682 | case V4L2_TUNER_MODE_STEREO: | ||
1683 | case V4L2_TUNER_MODE_LANG1: | ||
1684 | case V4L2_TUNER_MODE_LANG2: | ||
1685 | mode = vt->audmode; | ||
1686 | break; | ||
1687 | case V4L2_TUNER_MODE_LANG1_LANG2: | ||
1688 | mode = V4L2_TUNER_MODE_STEREO; | ||
1689 | break; | ||
1690 | default: | ||
1691 | return -EINVAL; | ||
1692 | } | ||
1693 | chip->audmode = vt->audmode; | ||
1694 | |||
1695 | if (desc->setmode && mode) { | ||
1743 | chip->watch_stereo = 0; | 1696 | chip->watch_stereo = 0; |
1744 | /* del_timer(&chip->wt); */ | 1697 | /* del_timer(&chip->wt); */ |
1745 | break; | 1698 | chip->mode = mode; |
1746 | /* --- v4l ioctls --- */ | 1699 | desc->setmode(chip, mode); |
1747 | /* take care: bttv does userspace copying, we'll get a | ||
1748 | kernel pointer here... */ | ||
1749 | case VIDIOC_QUERYCTRL: | ||
1750 | { | ||
1751 | struct v4l2_queryctrl *qc = arg; | ||
1752 | |||
1753 | switch (qc->id) { | ||
1754 | case V4L2_CID_AUDIO_MUTE: | ||
1755 | break; | ||
1756 | case V4L2_CID_AUDIO_VOLUME: | ||
1757 | case V4L2_CID_AUDIO_BALANCE: | ||
1758 | if (!(desc->flags & CHIP_HAS_VOLUME)) | ||
1759 | return -EINVAL; | ||
1760 | break; | ||
1761 | case V4L2_CID_AUDIO_BASS: | ||
1762 | case V4L2_CID_AUDIO_TREBLE: | ||
1763 | if (!(desc->flags & CHIP_HAS_BASSTREBLE)) | ||
1764 | return -EINVAL; | ||
1765 | break; | ||
1766 | default: | ||
1767 | return -EINVAL; | ||
1768 | } | ||
1769 | return v4l2_ctrl_query_fill_std(qc); | ||
1770 | } | 1700 | } |
1771 | case VIDIOC_S_CTRL: | 1701 | return 0; |
1772 | return tvaudio_set_ctrl(chip, arg); | 1702 | } |
1773 | 1703 | ||
1774 | case VIDIOC_G_CTRL: | 1704 | static int tvaudio_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt) |
1775 | return tvaudio_get_ctrl(chip, arg); | 1705 | { |
1776 | case VIDIOC_INT_G_AUDIO_ROUTING: | 1706 | struct CHIPSTATE *chip = to_state(sd); |
1777 | { | 1707 | struct CHIPDESC *desc = chip->desc; |
1778 | struct v4l2_routing *rt = arg; | 1708 | int mode = V4L2_TUNER_MODE_MONO; |
1779 | 1709 | ||
1780 | rt->input = chip->input; | 1710 | if (chip->radio) |
1781 | rt->output = 0; | 1711 | return 0; |
1782 | break; | 1712 | vt->audmode = chip->audmode; |
1713 | vt->rxsubchans = 0; | ||
1714 | vt->capability = V4L2_TUNER_CAP_STEREO | | ||
1715 | V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2; | ||
1716 | |||
1717 | if (desc->getmode) | ||
1718 | mode = desc->getmode(chip); | ||
1719 | |||
1720 | if (mode & V4L2_TUNER_MODE_MONO) | ||
1721 | vt->rxsubchans |= V4L2_TUNER_SUB_MONO; | ||
1722 | if (mode & V4L2_TUNER_MODE_STEREO) | ||
1723 | vt->rxsubchans |= V4L2_TUNER_SUB_STEREO; | ||
1724 | /* Note: for SAP it should be mono/lang2 or stereo/lang2. | ||
1725 | When this module is converted fully to v4l2, then this | ||
1726 | should change for those chips that can detect SAP. */ | ||
1727 | if (mode & V4L2_TUNER_MODE_LANG1) | ||
1728 | vt->rxsubchans = V4L2_TUNER_SUB_LANG1 | | ||
1729 | V4L2_TUNER_SUB_LANG2; | ||
1730 | return 0; | ||
1731 | } | ||
1732 | |||
1733 | static int tvaudio_s_std(struct v4l2_subdev *sd, v4l2_std_id std) | ||
1734 | { | ||
1735 | struct CHIPSTATE *chip = to_state(sd); | ||
1736 | |||
1737 | chip->radio = 0; | ||
1738 | return 0; | ||
1739 | } | ||
1740 | |||
1741 | static int tvaudio_s_frequency(struct v4l2_subdev *sd, struct v4l2_frequency *freq) | ||
1742 | { | ||
1743 | struct CHIPSTATE *chip = to_state(sd); | ||
1744 | struct CHIPDESC *desc = chip->desc; | ||
1745 | |||
1746 | chip->mode = 0; /* automatic */ | ||
1747 | |||
1748 | /* For chips that provide getmode and setmode, and doesn't | ||
1749 | automatically follows the stereo carrier, a kthread is | ||
1750 | created to set the audio standard. In this case, when then | ||
1751 | the video channel is changed, tvaudio starts on MONO mode. | ||
1752 | After waiting for 2 seconds, the kernel thread is called, | ||
1753 | to follow whatever audio standard is pointed by the | ||
1754 | audio carrier. | ||
1755 | */ | ||
1756 | if (chip->thread) { | ||
1757 | desc->setmode(chip, V4L2_TUNER_MODE_MONO); | ||
1758 | if (chip->prevmode != V4L2_TUNER_MODE_MONO) | ||
1759 | chip->prevmode = -1; /* reset previous mode */ | ||
1760 | mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000)); | ||
1783 | } | 1761 | } |
1784 | case VIDIOC_INT_S_AUDIO_ROUTING: | 1762 | return 0; |
1785 | { | 1763 | } |
1786 | struct v4l2_routing *rt = arg; | ||
1787 | 1764 | ||
1788 | if (!(desc->flags & CHIP_HAS_INPUTSEL) || rt->input >= 4) | 1765 | static int tvaudio_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_chip_ident *chip) |
1789 | return -EINVAL; | 1766 | { |
1790 | /* There are four inputs: tuner, radio, extern and intern. */ | 1767 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
1791 | chip->input = rt->input; | 1768 | |
1792 | if (chip->muted) | 1769 | return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_TVAUDIO, 0); |
1793 | break; | 1770 | } |
1794 | chip_write_masked(chip, desc->inputreg, | 1771 | |
1795 | desc->inputmap[chip->input], desc->inputmask); | 1772 | static int tvaudio_command(struct i2c_client *client, unsigned cmd, void *arg) |
1796 | break; | 1773 | { |
1774 | return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg); | ||
1775 | } | ||
1776 | |||
1777 | /* ----------------------------------------------------------------------- */ | ||
1778 | |||
1779 | static const struct v4l2_subdev_core_ops tvaudio_core_ops = { | ||
1780 | .g_chip_ident = tvaudio_g_chip_ident, | ||
1781 | .queryctrl = tvaudio_queryctrl, | ||
1782 | .g_ctrl = tvaudio_g_ctrl, | ||
1783 | .s_ctrl = tvaudio_s_ctrl, | ||
1784 | }; | ||
1785 | |||
1786 | static const struct v4l2_subdev_tuner_ops tvaudio_tuner_ops = { | ||
1787 | .s_radio = tvaudio_s_radio, | ||
1788 | .s_frequency = tvaudio_s_frequency, | ||
1789 | .s_std = tvaudio_s_std, | ||
1790 | .s_tuner = tvaudio_s_tuner, | ||
1791 | .s_tuner = tvaudio_g_tuner, | ||
1792 | }; | ||
1793 | |||
1794 | static const struct v4l2_subdev_audio_ops tvaudio_audio_ops = { | ||
1795 | .s_routing = tvaudio_s_routing, | ||
1796 | }; | ||
1797 | |||
1798 | static const struct v4l2_subdev_ops tvaudio_ops = { | ||
1799 | .core = &tvaudio_core_ops, | ||
1800 | .tuner = &tvaudio_tuner_ops, | ||
1801 | .audio = &tvaudio_audio_ops, | ||
1802 | }; | ||
1803 | |||
1804 | /* ----------------------------------------------------------------------- */ | ||
1805 | |||
1806 | |||
1807 | /* i2c registration */ | ||
1808 | |||
1809 | static int tvaudio_probe(struct i2c_client *client, const struct i2c_device_id *id) | ||
1810 | { | ||
1811 | struct CHIPSTATE *chip; | ||
1812 | struct CHIPDESC *desc; | ||
1813 | struct v4l2_subdev *sd; | ||
1814 | |||
1815 | if (debug) { | ||
1816 | printk(KERN_INFO "tvaudio: TV audio decoder + audio/video mux driver\n"); | ||
1817 | printk(KERN_INFO "tvaudio: known chips: "); | ||
1818 | for (desc = chiplist; desc->name != NULL; desc++) | ||
1819 | printk("%s%s", (desc == chiplist) ? "" : ", ", desc->name); | ||
1820 | printk("\n"); | ||
1797 | } | 1821 | } |
1798 | case VIDIOC_S_TUNER: | ||
1799 | { | ||
1800 | struct v4l2_tuner *vt = arg; | ||
1801 | int mode = 0; | ||
1802 | 1822 | ||
1803 | if (chip->radio) | 1823 | chip = kzalloc(sizeof(*chip), GFP_KERNEL); |
1804 | break; | 1824 | if (!chip) |
1805 | switch (vt->audmode) { | 1825 | return -ENOMEM; |
1806 | case V4L2_TUNER_MODE_MONO: | 1826 | sd = &chip->sd; |
1807 | case V4L2_TUNER_MODE_STEREO: | 1827 | v4l2_i2c_subdev_init(sd, client, &tvaudio_ops); |
1808 | case V4L2_TUNER_MODE_LANG1: | ||
1809 | case V4L2_TUNER_MODE_LANG2: | ||
1810 | mode = vt->audmode; | ||
1811 | break; | ||
1812 | case V4L2_TUNER_MODE_LANG1_LANG2: | ||
1813 | mode = V4L2_TUNER_MODE_STEREO; | ||
1814 | break; | ||
1815 | default: | ||
1816 | return -EINVAL; | ||
1817 | } | ||
1818 | chip->audmode = vt->audmode; | ||
1819 | 1828 | ||
1820 | if (desc->setmode && mode) { | 1829 | /* find description for the chip */ |
1821 | chip->watch_stereo = 0; | 1830 | v4l2_dbg(1, debug, sd, "chip found @ 0x%x\n", client->addr<<1); |
1822 | /* del_timer(&chip->wt); */ | 1831 | for (desc = chiplist; desc->name != NULL; desc++) { |
1823 | chip->mode = mode; | 1832 | if (0 == *(desc->insmodopt)) |
1824 | desc->setmode(chip, mode); | 1833 | continue; |
1825 | } | 1834 | if (client->addr < desc->addr_lo || |
1835 | client->addr > desc->addr_hi) | ||
1836 | continue; | ||
1837 | if (desc->checkit && !desc->checkit(chip)) | ||
1838 | continue; | ||
1826 | break; | 1839 | break; |
1827 | } | 1840 | } |
1828 | case VIDIOC_G_TUNER: | 1841 | if (desc->name == NULL) { |
1829 | { | 1842 | v4l2_dbg(1, debug, sd, "no matching chip description found\n"); |
1830 | struct v4l2_tuner *vt = arg; | 1843 | kfree(chip); |
1831 | int mode = V4L2_TUNER_MODE_MONO; | 1844 | return -EIO; |
1845 | } | ||
1846 | v4l2_info(sd, "%s found @ 0x%x (%s)\n", desc->name, client->addr<<1, client->adapter->name); | ||
1847 | if (desc->flags) { | ||
1848 | v4l2_dbg(1, debug, sd, "matches:%s%s%s.\n", | ||
1849 | (desc->flags & CHIP_HAS_VOLUME) ? " volume" : "", | ||
1850 | (desc->flags & CHIP_HAS_BASSTREBLE) ? " bass/treble" : "", | ||
1851 | (desc->flags & CHIP_HAS_INPUTSEL) ? " audiomux" : ""); | ||
1852 | } | ||
1832 | 1853 | ||
1833 | if (chip->radio) | 1854 | /* fill required data structures */ |
1834 | break; | 1855 | if (!id) |
1835 | vt->audmode = chip->audmode; | 1856 | strlcpy(client->name, desc->name, I2C_NAME_SIZE); |
1836 | vt->rxsubchans = 0; | 1857 | chip->desc = desc; |
1837 | vt->capability = V4L2_TUNER_CAP_STEREO | | 1858 | chip->shadow.count = desc->registers+1; |
1838 | V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2; | 1859 | chip->prevmode = -1; |
1860 | chip->audmode = V4L2_TUNER_MODE_LANG1; | ||
1839 | 1861 | ||
1840 | if (desc->getmode) | 1862 | /* initialization */ |
1841 | mode = desc->getmode(chip); | 1863 | if (desc->initialize != NULL) |
1864 | desc->initialize(chip); | ||
1865 | else | ||
1866 | chip_cmd(chip, "init", &desc->init); | ||
1842 | 1867 | ||
1843 | if (mode & V4L2_TUNER_MODE_MONO) | 1868 | if (desc->flags & CHIP_HAS_VOLUME) { |
1844 | vt->rxsubchans |= V4L2_TUNER_SUB_MONO; | 1869 | if (!desc->volfunc) { |
1845 | if (mode & V4L2_TUNER_MODE_STEREO) | 1870 | /* This shouldn't be happen. Warn user, but keep working |
1846 | vt->rxsubchans |= V4L2_TUNER_SUB_STEREO; | 1871 | without volume controls |
1847 | /* Note: for SAP it should be mono/lang2 or stereo/lang2. | 1872 | */ |
1848 | When this module is converted fully to v4l2, then this | 1873 | v4l2_info(sd, "volume callback undefined!\n"); |
1849 | should change for those chips that can detect SAP. */ | 1874 | desc->flags &= ~CHIP_HAS_VOLUME; |
1850 | if (mode & V4L2_TUNER_MODE_LANG1) | 1875 | } else { |
1851 | vt->rxsubchans = V4L2_TUNER_SUB_LANG1 | | 1876 | chip->left = desc->leftinit ? desc->leftinit : 65535; |
1852 | V4L2_TUNER_SUB_LANG2; | 1877 | chip->right = desc->rightinit ? desc->rightinit : 65535; |
1853 | break; | 1878 | chip_write(chip, desc->leftreg, |
1879 | desc->volfunc(chip->left)); | ||
1880 | chip_write(chip, desc->rightreg, | ||
1881 | desc->volfunc(chip->right)); | ||
1882 | } | ||
1854 | } | 1883 | } |
1855 | case VIDIOC_S_STD: | 1884 | if (desc->flags & CHIP_HAS_BASSTREBLE) { |
1856 | chip->radio = 0; | 1885 | if (!desc->bassfunc || !desc->treblefunc) { |
1857 | break; | 1886 | /* This shouldn't be happen. Warn user, but keep working |
1858 | case VIDIOC_S_FREQUENCY: | 1887 | without bass/treble controls |
1859 | chip->mode = 0; /* automatic */ | 1888 | */ |
1860 | 1889 | v4l2_info(sd, "bass/treble callbacks undefined!\n"); | |
1861 | /* For chips that provide getmode and setmode, and doesn't | 1890 | desc->flags &= ~CHIP_HAS_BASSTREBLE; |
1862 | automatically follows the stereo carrier, a kthread is | 1891 | } else { |
1863 | created to set the audio standard. In this case, when then | 1892 | chip->treble = desc->trebleinit ? |
1864 | the video channel is changed, tvaudio starts on MONO mode. | 1893 | desc->trebleinit : 32768; |
1865 | After waiting for 2 seconds, the kernel thread is called, | 1894 | chip->bass = desc->bassinit ? |
1866 | to follow whatever audio standard is pointed by the | 1895 | desc->bassinit : 32768; |
1867 | audio carrier. | 1896 | chip_write(chip, desc->bassreg, |
1868 | */ | 1897 | desc->bassfunc(chip->bass)); |
1869 | if (chip->thread) { | 1898 | chip_write(chip, desc->treblereg, |
1870 | desc->setmode(chip,V4L2_TUNER_MODE_MONO); | 1899 | desc->treblefunc(chip->treble)); |
1871 | if (chip->prevmode != V4L2_TUNER_MODE_MONO) | ||
1872 | chip->prevmode = -1; /* reset previous mode */ | ||
1873 | mod_timer(&chip->wt, jiffies+msecs_to_jiffies(2000)); | ||
1874 | } | 1900 | } |
1875 | break; | 1901 | } |
1876 | 1902 | ||
1877 | case VIDIOC_G_CHIP_IDENT: | 1903 | chip->thread = NULL; |
1878 | return v4l2_chip_ident_i2c_client(client, arg, V4L2_IDENT_TVAUDIO, 0); | 1904 | if (desc->flags & CHIP_NEED_CHECKMODE) { |
1905 | if (!desc->getmode || !desc->setmode) { | ||
1906 | /* This shouldn't be happen. Warn user, but keep working | ||
1907 | without kthread | ||
1908 | */ | ||
1909 | v4l2_info(sd, "set/get mode callbacks undefined!\n"); | ||
1910 | return 0; | ||
1911 | } | ||
1912 | /* start async thread */ | ||
1913 | init_timer(&chip->wt); | ||
1914 | chip->wt.function = chip_thread_wake; | ||
1915 | chip->wt.data = (unsigned long)chip; | ||
1916 | chip->thread = kthread_run(chip_thread, chip, client->name); | ||
1917 | if (IS_ERR(chip->thread)) { | ||
1918 | v4l2_warn(sd, "failed to create kthread\n"); | ||
1919 | chip->thread = NULL; | ||
1920 | } | ||
1879 | } | 1921 | } |
1880 | return 0; | 1922 | return 0; |
1881 | } | 1923 | } |
1882 | 1924 | ||
1883 | static int chip_legacy_probe(struct i2c_adapter *adap) | 1925 | static int tvaudio_remove(struct i2c_client *client) |
1926 | { | ||
1927 | struct v4l2_subdev *sd = i2c_get_clientdata(client); | ||
1928 | struct CHIPSTATE *chip = to_state(sd); | ||
1929 | |||
1930 | del_timer_sync(&chip->wt); | ||
1931 | if (chip->thread) { | ||
1932 | /* shutdown async thread */ | ||
1933 | kthread_stop(chip->thread); | ||
1934 | chip->thread = NULL; | ||
1935 | } | ||
1936 | |||
1937 | v4l2_device_unregister_subdev(sd); | ||
1938 | kfree(chip); | ||
1939 | return 0; | ||
1940 | } | ||
1941 | |||
1942 | static int tvaudio_legacy_probe(struct i2c_adapter *adap) | ||
1884 | { | 1943 | { |
1885 | /* don't attach on saa7146 based cards, | 1944 | /* don't attach on saa7146 based cards, |
1886 | because dedicated drivers are used */ | 1945 | because dedicated drivers are used */ |
@@ -1894,18 +1953,18 @@ static int chip_legacy_probe(struct i2c_adapter *adap) | |||
1894 | /* This driver supports many devices and the idea is to let the driver | 1953 | /* This driver supports many devices and the idea is to let the driver |
1895 | detect which device is present. So rather than listing all supported | 1954 | detect which device is present. So rather than listing all supported |
1896 | devices here, we pretend to support a single, fake device type. */ | 1955 | devices here, we pretend to support a single, fake device type. */ |
1897 | static const struct i2c_device_id chip_id[] = { | 1956 | static const struct i2c_device_id tvaudio_id[] = { |
1898 | { "tvaudio", 0 }, | 1957 | { "tvaudio", 0 }, |
1899 | { } | 1958 | { } |
1900 | }; | 1959 | }; |
1901 | MODULE_DEVICE_TABLE(i2c, chip_id); | 1960 | MODULE_DEVICE_TABLE(i2c, tvaudio_id); |
1902 | 1961 | ||
1903 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { | 1962 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
1904 | .name = "tvaudio", | 1963 | .name = "tvaudio", |
1905 | .driverid = I2C_DRIVERID_TVAUDIO, | 1964 | .driverid = I2C_DRIVERID_TVAUDIO, |
1906 | .command = chip_command, | 1965 | .command = tvaudio_command, |
1907 | .probe = chip_probe, | 1966 | .probe = tvaudio_probe, |
1908 | .remove = chip_remove, | 1967 | .remove = tvaudio_remove, |
1909 | .legacy_probe = chip_legacy_probe, | 1968 | .legacy_probe = tvaudio_legacy_probe, |
1910 | .id_table = chip_id, | 1969 | .id_table = tvaudio_id, |
1911 | }; | 1970 | }; |