Merge branch 'kvm-arm/vgic-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git...
[firefly-linux-kernel-4.4.55.git] / drivers / staging / media / go7007 / wis-sony-tuner.c
1 /*
2  * Copyright (C) 2005-2006 Micronas USA Inc.
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License (Version 2) as
6  * published by the Free Software Foundation.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software Foundation,
15  * Inc., 59 Temple Place - Suite 330, Boston MA 02111-1307, USA.
16  */
17
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/i2c.h>
21 #include <linux/videodev2.h>
22 #include <linux/slab.h>
23 #include <media/tuner.h>
24 #include <media/v4l2-common.h>
25 #include <media/v4l2-ioctl.h>
26
27 #include "wis-i2c.h"
28
29 /* #define MPX_DEBUG */
30
31 /* AS(IF/MPX) pin:      LOW      HIGH/OPEN
32  * IF/MPX address:   0x42/0x40   0x43/0x44
33  */
34 #define IF_I2C_ADDR     0x43
35 #define MPX_I2C_ADDR    0x44
36
37 static v4l2_std_id force_band;
38 static char force_band_str[] = "-";
39 module_param_string(force_band, force_band_str, sizeof(force_band_str), 0644);
40 static int force_mpx_mode = -1;
41 module_param(force_mpx_mode, int, 0644);
42
43 /* Store tuner info in the same format as tuner.c, so maybe we can put the
44  * Sony tuner support in there. */
45 struct sony_tunertype {
46         char *name;
47         unsigned char Vendor; /* unused here */
48         unsigned char Type; /* unused here */
49
50         unsigned short thresh1; /*  band switch VHF_LO <=> VHF_HI */
51         unsigned short thresh2; /*  band switch VHF_HI <=> UHF */
52         unsigned char VHF_L;
53         unsigned char VHF_H;
54         unsigned char UHF;
55         unsigned char config;
56         unsigned short IFPCoff;
57 };
58
59 /* This array is indexed by (tuner_type - 200) */
60 static struct sony_tunertype sony_tuners[] = {
61         { "Sony PAL+SECAM (BTF-PG472Z)", 0, 0,
62           16*144.25, 16*427.25, 0x01, 0x02, 0x04, 0xc6, 623},
63         { "Sony NTSC_JP (BTF-PK467Z)", 0, 0,
64           16*220.25, 16*467.25, 0x01, 0x02, 0x04, 0xc6, 940},
65         { "Sony NTSC (BTF-PB463Z)", 0, 0,
66           16*130.25, 16*364.25, 0x01, 0x02, 0x04, 0xc6, 732},
67 };
68
69 struct wis_sony_tuner {
70         int type;
71         v4l2_std_id std;
72         unsigned int freq;
73         int mpxmode;
74         u32 audmode;
75 };
76
77 /* Basically the same as default_set_tv_freq() in tuner.c */
78 static int set_freq(struct i2c_client *client, int freq)
79 {
80         struct wis_sony_tuner *t = i2c_get_clientdata(client);
81         char *band_name;
82         int n;
83         int band_select;
84         struct sony_tunertype *tun;
85         u8 buffer[4];
86
87         tun = &sony_tuners[t->type - 200];
88         if (freq < tun->thresh1) {
89                 band_name = "VHF_L";
90                 band_select = tun->VHF_L;
91         } else if (freq < tun->thresh2) {
92                 band_name = "VHF_H";
93                 band_select = tun->VHF_H;
94         } else {
95                 band_name = "UHF";
96                 band_select = tun->UHF;
97         }
98         dev_dbg(&client->dev, "tuning to frequency %d.%04d (%s)\n",
99                 freq / 16, (freq % 16) * 625, band_name);
100         n = freq + tun->IFPCoff;
101
102         buffer[0] = n >> 8;
103         buffer[1] = n & 0xff;
104         buffer[2] = tun->config;
105         buffer[3] = band_select;
106         i2c_master_send(client, buffer, 4);
107
108         return 0;
109 }
110
111 static int mpx_write(struct i2c_client *client, int dev, int addr, int val)
112 {
113         u8 buffer[5];
114         struct i2c_msg msg;
115
116         buffer[0] = dev;
117         buffer[1] = addr >> 8;
118         buffer[2] = addr & 0xff;
119         buffer[3] = val >> 8;
120         buffer[4] = val & 0xff;
121         msg.addr = MPX_I2C_ADDR;
122         msg.flags = 0;
123         msg.len = 5;
124         msg.buf = buffer;
125         i2c_transfer(client->adapter, &msg, 1);
126         return 0;
127 }
128
129 /*
130  * MPX register values for the BTF-PG472Z:
131  *
132  *                                 FM_     NICAM_  SCART_
133  *          MODUS  SOURCE    ACB   PRESCAL PRESCAL PRESCAL SYSTEM  VOLUME
134  *         10/0030 12/0008 12/0013 12/000E 12/0010 12/0000 10/0020 12/0000
135  *         ---------------------------------------------------------------
136  * Auto     1003    0020    0100    2603    5000    XXXX    0001    7500
137  *
138  * B/G
139  *  Mono    1003    0020    0100    2603    5000    XXXX    0003    7500
140  *  A2      1003    0020    0100    2601    5000    XXXX    0003    7500
141  *  NICAM   1003    0120    0100    2603    5000    XXXX    0008    7500
142  *
143  * I
144  *  Mono    1003    0020    0100    2603    7900    XXXX    000A    7500
145  *  NICAM   1003    0120    0100    2603    7900    XXXX    000A    7500
146  *
147  * D/K
148  *  Mono    1003    0020    0100    2603    5000    XXXX    0004    7500
149  *  A2-1    1003    0020    0100    2601    5000    XXXX    0004    7500
150  *  A2-2    1003    0020    0100    2601    5000    XXXX    0005    7500
151  *  A2-3    1003    0020    0100    2601    5000    XXXX    0007    7500
152  *  NICAM   1003    0120    0100    2603    5000    XXXX    000B    7500
153  *
154  * L/L'
155  *  Mono    0003    0200    0100    7C03    5000    2200    0009    7500
156  *  NICAM   0003    0120    0100    7C03    5000    XXXX    0009    7500
157  *
158  * M
159  *  Mono    1003    0200    0100    2B03    5000    2B00    0002    7500
160  *
161  * For Asia, replace the 0x26XX in FM_PRESCALE with 0x14XX.
162  *
163  * Bilingual selection in A2/NICAM:
164  *
165  *         High byte of SOURCE     Left chan   Right chan
166  *                 0x01              MAIN         SUB
167  *                 0x03              MAIN         MAIN
168  *                 0x04              SUB          SUB
169  *
170  * Force mono in NICAM by setting the high byte of SOURCE to 0x02 (L/L') or
171  * 0x00 (all other bands).  Force mono in A2 with FMONO_A2:
172  *
173  *                      FMONO_A2
174  *                      10/0022
175  *                      --------
176  *     Forced mono ON     07F0
177  *     Forced mono OFF    0190
178  */
179
180 static struct {
181         enum { AUD_MONO, AUD_A2, AUD_NICAM, AUD_NICAM_L } audio_mode;
182         u16 modus;
183         u16 source;
184         u16 acb;
185         u16 fm_prescale;
186         u16 nicam_prescale;
187         u16 scart_prescale;
188         u16 system;
189         u16 volume;
190 } mpx_audio_modes[] = {
191         /* Auto */      { AUD_MONO,     0x1003, 0x0020, 0x0100, 0x2603,
192                                         0x5000, 0x0000, 0x0001, 0x7500 },
193         /* B/G Mono */  { AUD_MONO,     0x1003, 0x0020, 0x0100, 0x2603,
194                                         0x5000, 0x0000, 0x0003, 0x7500 },
195         /* B/G A2 */    { AUD_A2,       0x1003, 0x0020, 0x0100, 0x2601,
196                                         0x5000, 0x0000, 0x0003, 0x7500 },
197         /* B/G NICAM */ { AUD_NICAM,    0x1003, 0x0120, 0x0100, 0x2603,
198                                         0x5000, 0x0000, 0x0008, 0x7500 },
199         /* I Mono */    { AUD_MONO,     0x1003, 0x0020, 0x0100, 0x2603,
200                                         0x7900, 0x0000, 0x000A, 0x7500 },
201         /* I NICAM */   { AUD_NICAM,    0x1003, 0x0120, 0x0100, 0x2603,
202                                         0x7900, 0x0000, 0x000A, 0x7500 },
203         /* D/K Mono */  { AUD_MONO,     0x1003, 0x0020, 0x0100, 0x2603,
204                                         0x5000, 0x0000, 0x0004, 0x7500 },
205         /* D/K A2-1 */  { AUD_A2,       0x1003, 0x0020, 0x0100, 0x2601,
206                                         0x5000, 0x0000, 0x0004, 0x7500 },
207         /* D/K A2-2 */  { AUD_A2,       0x1003, 0x0020, 0x0100, 0x2601,
208                                         0x5000, 0x0000, 0x0005, 0x7500 },
209         /* D/K A2-3 */  { AUD_A2,       0x1003, 0x0020, 0x0100, 0x2601,
210                                         0x5000, 0x0000, 0x0007, 0x7500 },
211         /* D/K NICAM */ { AUD_NICAM,    0x1003, 0x0120, 0x0100, 0x2603,
212                                         0x5000, 0x0000, 0x000B, 0x7500 },
213         /* L/L' Mono */ { AUD_MONO,     0x0003, 0x0200, 0x0100, 0x7C03,
214                                         0x5000, 0x2200, 0x0009, 0x7500 },
215         /* L/L' NICAM */{ AUD_NICAM_L,  0x0003, 0x0120, 0x0100, 0x7C03,
216                                         0x5000, 0x0000, 0x0009, 0x7500 },
217 };
218
219 #define MPX_NUM_MODES   ARRAY_SIZE(mpx_audio_modes)
220
221 static int mpx_setup(struct i2c_client *client)
222 {
223         struct wis_sony_tuner *t = i2c_get_clientdata(client);
224         u16 source = 0;
225         u8 buffer[3];
226         struct i2c_msg msg;
227
228         /* reset MPX */
229         buffer[0] = 0x00;
230         buffer[1] = 0x80;
231         buffer[2] = 0x00;
232         msg.addr = MPX_I2C_ADDR;
233         msg.flags = 0;
234         msg.len = 3;
235         msg.buf = buffer;
236         i2c_transfer(client->adapter, &msg, 1);
237         buffer[1] = 0x00;
238         i2c_transfer(client->adapter, &msg, 1);
239
240         if (mpx_audio_modes[t->mpxmode].audio_mode != AUD_MONO) {
241                 switch (t->audmode) {
242                 case V4L2_TUNER_MODE_MONO:
243                         switch (mpx_audio_modes[t->mpxmode].audio_mode) {
244                         case AUD_A2:
245                                 source = mpx_audio_modes[t->mpxmode].source;
246                                 break;
247                         case AUD_NICAM:
248                                 source = 0x0000;
249                                 break;
250                         case AUD_NICAM_L:
251                                 source = 0x0200;
252                                 break;
253                         default:
254                                 break;
255                         }
256                         break;
257                 case V4L2_TUNER_MODE_STEREO:
258                         source = mpx_audio_modes[t->mpxmode].source;
259                         break;
260                 case V4L2_TUNER_MODE_LANG1:
261                         source = 0x0300;
262                         break;
263                 case V4L2_TUNER_MODE_LANG2:
264                         source = 0x0400;
265                         break;
266                 }
267                 source |= mpx_audio_modes[t->mpxmode].source & 0x00ff;
268         } else
269                 source = mpx_audio_modes[t->mpxmode].source;
270
271         mpx_write(client, 0x10, 0x0030, mpx_audio_modes[t->mpxmode].modus);
272         mpx_write(client, 0x12, 0x0008, source);
273         mpx_write(client, 0x12, 0x0013, mpx_audio_modes[t->mpxmode].acb);
274         mpx_write(client, 0x12, 0x000e,
275                         mpx_audio_modes[t->mpxmode].fm_prescale);
276         mpx_write(client, 0x12, 0x0010,
277                         mpx_audio_modes[t->mpxmode].nicam_prescale);
278         mpx_write(client, 0x12, 0x000d,
279                         mpx_audio_modes[t->mpxmode].scart_prescale);
280         mpx_write(client, 0x10, 0x0020, mpx_audio_modes[t->mpxmode].system);
281         mpx_write(client, 0x12, 0x0000, mpx_audio_modes[t->mpxmode].volume);
282         if (mpx_audio_modes[t->mpxmode].audio_mode == AUD_A2)
283                 mpx_write(client, 0x10, 0x0022,
284                         t->audmode == V4L2_TUNER_MODE_MONO ?  0x07f0 : 0x0190);
285
286 #ifdef MPX_DEBUG
287         {
288                 u8 buf1[3], buf2[2];
289                 struct i2c_msg msgs[2];
290
291                 dev_dbg(&client->dev,
292                         "MPX registers: %04x %04x %04x %04x %04x %04x %04x %04x\n",
293                         mpx_audio_modes[t->mpxmode].modus,
294                         source,
295                         mpx_audio_modes[t->mpxmode].acb,
296                         mpx_audio_modes[t->mpxmode].fm_prescale,
297                         mpx_audio_modes[t->mpxmode].nicam_prescale,
298                         mpx_audio_modes[t->mpxmode].scart_prescale,
299                         mpx_audio_modes[t->mpxmode].system,
300                         mpx_audio_modes[t->mpxmode].volume);
301                 buf1[0] = 0x11;
302                 buf1[1] = 0x00;
303                 buf1[2] = 0x7e;
304                 msgs[0].addr = MPX_I2C_ADDR;
305                 msgs[0].flags = 0;
306                 msgs[0].len = 3;
307                 msgs[0].buf = buf1;
308                 msgs[1].addr = MPX_I2C_ADDR;
309                 msgs[1].flags = I2C_M_RD;
310                 msgs[1].len = 2;
311                 msgs[1].buf = buf2;
312                 i2c_transfer(client->adapter, msgs, 2);
313                 dev_dbg(&client->dev, "MPX system: %02x%02x\n",
314                         buf2[0], buf2[1]);
315                 buf1[0] = 0x11;
316                 buf1[1] = 0x02;
317                 buf1[2] = 0x00;
318                 i2c_transfer(client->adapter, msgs, 2);
319                 dev_dbg(&client->dev, "MPX status: %02x%02x\n",
320                         buf2[0], buf2[1]);
321         }
322 #endif
323         return 0;
324 }
325
326 /*
327  * IF configuration values for the BTF-PG472Z:
328  *
329  *      B/G: 0x94 0x70 0x49
330  *      I:   0x14 0x70 0x4a
331  *      D/K: 0x14 0x70 0x4b
332  *      L:   0x04 0x70 0x4b
333  *      L':  0x44 0x70 0x53
334  *      M:   0x50 0x30 0x4c
335  */
336
337 static int set_if(struct i2c_client *client)
338 {
339         struct wis_sony_tuner *t = i2c_get_clientdata(client);
340         u8 buffer[4];
341         struct i2c_msg msg;
342         int default_mpx_mode = 0;
343
344         /* configure IF */
345         buffer[0] = 0;
346         if (t->std & V4L2_STD_PAL_BG) {
347                 buffer[1] = 0x94;
348                 buffer[2] = 0x70;
349                 buffer[3] = 0x49;
350                 default_mpx_mode = 1;
351         } else if (t->std & V4L2_STD_PAL_I) {
352                 buffer[1] = 0x14;
353                 buffer[2] = 0x70;
354                 buffer[3] = 0x4a;
355                 default_mpx_mode = 4;
356         } else if (t->std & V4L2_STD_PAL_DK) {
357                 buffer[1] = 0x14;
358                 buffer[2] = 0x70;
359                 buffer[3] = 0x4b;
360                 default_mpx_mode = 6;
361         } else if (t->std & V4L2_STD_SECAM_L) {
362                 buffer[1] = 0x04;
363                 buffer[2] = 0x70;
364                 buffer[3] = 0x4b;
365                 default_mpx_mode = 11;
366         }
367         msg.addr = IF_I2C_ADDR;
368         msg.flags = 0;
369         msg.len = 4;
370         msg.buf = buffer;
371         i2c_transfer(client->adapter, &msg, 1);
372
373         /* Select MPX mode if not forced by the user */
374         if (force_mpx_mode >= 0 && force_mpx_mode < MPX_NUM_MODES)
375                 t->mpxmode = force_mpx_mode;
376         else
377                 t->mpxmode = default_mpx_mode;
378         dev_dbg(&client->dev, "setting MPX to mode %d\n", t->mpxmode);
379         mpx_setup(client);
380
381         return 0;
382 }
383
384 static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
385 {
386         struct wis_sony_tuner *t = i2c_get_clientdata(client);
387
388         switch (cmd) {
389 #if 0
390 #ifdef TUNER_SET_TYPE_ADDR
391         case TUNER_SET_TYPE_ADDR:
392         {
393                 struct tuner_setup *tun_setup = arg;
394                 int *type = &tun_setup->type;
395 #else
396         case TUNER_SET_TYPE:
397         {
398                 int *type = arg;
399 #endif
400
401                 if (t->type >= 0) {
402                         if (t->type != *type)
403                                 dev_err(&client->dev,
404                                         "type already set to %d, ignoring request for %d\n",
405                                         t->type, *type);
406                         break;
407                 }
408                 t->type = *type;
409                 switch (t->type) {
410                 case TUNER_SONY_BTF_PG472Z:
411                         switch (force_band_str[0]) {
412                         case 'b':
413                         case 'B':
414                         case 'g':
415                         case 'G':
416                                 dev_info(&client->dev,
417                                          "forcing tuner to PAL-B/G bands\n");
418                                 force_band = V4L2_STD_PAL_BG;
419                                 break;
420                         case 'i':
421                         case 'I':
422                                 dev_info(&client->dev,
423                                          "forcing tuner to PAL-I band\n");
424                                 force_band = V4L2_STD_PAL_I;
425                                 break;
426                         case 'd':
427                         case 'D':
428                         case 'k':
429                         case 'K':
430                                 dev_info(&client->dev,
431                                          "forcing tuner to PAL-D/K bands\n");
432                                 force_band = V4L2_STD_PAL_I;
433                                 break;
434                         case 'l':
435                         case 'L':
436                                 dev_info(&client->dev,
437                                          "forcing tuner to SECAM-L band\n");
438                                 force_band = V4L2_STD_SECAM_L;
439                                 break;
440                         default:
441                                 force_band = 0;
442                                 break;
443                         }
444                         if (force_band)
445                                 t->std = force_band;
446                         else
447                                 t->std = V4L2_STD_PAL_BG;
448                         set_if(client);
449                         break;
450                 case TUNER_SONY_BTF_PK467Z:
451                         t->std = V4L2_STD_NTSC_M_JP;
452                         break;
453                 case TUNER_SONY_BTF_PB463Z:
454                         t->std = V4L2_STD_NTSC_M;
455                         break;
456                 default:
457                         dev_err(&client->dev,
458                                 "tuner type %d is not supported by this module\n",
459                                 *type);
460                         break;
461                 }
462                 if (type >= 0)
463                         dev_info(&clinet->dev,
464                                  "type set to %d (%s)\n",
465                                  t->type, sony_tuners[t->type - 200].name);
466                 break;
467         }
468 #endif
469         case VIDIOC_G_FREQUENCY:
470         {
471                 struct v4l2_frequency *f = arg;
472
473                 f->frequency = t->freq;
474                 break;
475         }
476         case VIDIOC_S_FREQUENCY:
477         {
478                 struct v4l2_frequency *f = arg;
479
480                 t->freq = f->frequency;
481                 set_freq(client, t->freq);
482                 break;
483         }
484         case VIDIOC_ENUMSTD:
485         {
486                 struct v4l2_standard *std = arg;
487
488                 switch (t->type) {
489                 case TUNER_SONY_BTF_PG472Z:
490                         switch (std->index) {
491                         case 0:
492                                 v4l2_video_std_construct(std,
493                                                 V4L2_STD_PAL_BG, "PAL-B/G");
494                                 break;
495                         case 1:
496                                 v4l2_video_std_construct(std,
497                                                 V4L2_STD_PAL_I, "PAL-I");
498                                 break;
499                         case 2:
500                                 v4l2_video_std_construct(std,
501                                                 V4L2_STD_PAL_DK, "PAL-D/K");
502                                 break;
503                         case 3:
504                                 v4l2_video_std_construct(std,
505                                                 V4L2_STD_SECAM_L, "SECAM-L");
506                                 break;
507                         default:
508                                 std->id = 0; /* hack to indicate EINVAL */
509                                 break;
510                         }
511                         break;
512                 case TUNER_SONY_BTF_PK467Z:
513                         if (std->index != 0) {
514                                 std->id = 0; /* hack to indicate EINVAL */
515                                 break;
516                         }
517                         v4l2_video_std_construct(std,
518                                         V4L2_STD_NTSC_M_JP, "NTSC-J");
519                         break;
520                 case TUNER_SONY_BTF_PB463Z:
521                         if (std->index != 0) {
522                                 std->id = 0; /* hack to indicate EINVAL */
523                                 break;
524                         }
525                         v4l2_video_std_construct(std, V4L2_STD_NTSC_M, "NTSC");
526                         break;
527                 }
528                 break;
529         }
530         case VIDIOC_G_STD:
531         {
532                 v4l2_std_id *std = arg;
533
534                 *std = t->std;
535                 break;
536         }
537         case VIDIOC_S_STD:
538         {
539                 v4l2_std_id *std = arg;
540                 v4l2_std_id old = t->std;
541
542                 switch (t->type) {
543                 case TUNER_SONY_BTF_PG472Z:
544                         if (force_band && (*std & force_band) != *std &&
545                                         *std != V4L2_STD_PAL &&
546                                         *std != V4L2_STD_SECAM) {
547                                 dev_dbg(&client->dev,
548                                         "ignoring requested TV standard in favor of force_band value\n");
549                                 t->std = force_band;
550                         } else if (*std & V4L2_STD_PAL_BG) { /* default */
551                                 t->std = V4L2_STD_PAL_BG;
552                         } else if (*std & V4L2_STD_PAL_I) {
553                                 t->std = V4L2_STD_PAL_I;
554                         } else if (*std & V4L2_STD_PAL_DK) {
555                                 t->std = V4L2_STD_PAL_DK;
556                         } else if (*std & V4L2_STD_SECAM_L) {
557                                 t->std = V4L2_STD_SECAM_L;
558                         } else {
559                                 dev_err(&client->dev,
560                                         "TV standard not supported\n");
561                                 *std = 0; /* hack to indicate EINVAL */
562                                 break;
563                         }
564                         if (old != t->std)
565                                 set_if(client);
566                         break;
567                 case TUNER_SONY_BTF_PK467Z:
568                         if (!(*std & V4L2_STD_NTSC_M_JP)) {
569                                 dev_err(&client->dev,
570                                         "TV standard not supported\n");
571                                 *std = 0; /* hack to indicate EINVAL */
572                         }
573                         break;
574                 case TUNER_SONY_BTF_PB463Z:
575                         if (!(*std & V4L2_STD_NTSC_M)) {
576                                 dev_err(&client->dev,
577                                         "TV standard not supported\n");
578                                 *std = 0; /* hack to indicate EINVAL */
579                         }
580                         break;
581                 }
582                 break;
583         }
584         case VIDIOC_QUERYSTD:
585         {
586                 v4l2_std_id *std = arg;
587
588                 switch (t->type) {
589                 case TUNER_SONY_BTF_PG472Z:
590                         if (force_band)
591                                 *std = force_band;
592                         else
593                                 *std = V4L2_STD_PAL_BG | V4L2_STD_PAL_I |
594                                         V4L2_STD_PAL_DK | V4L2_STD_SECAM_L;
595                         break;
596                 case TUNER_SONY_BTF_PK467Z:
597                         *std = V4L2_STD_NTSC_M_JP;
598                         break;
599                 case TUNER_SONY_BTF_PB463Z:
600                         *std = V4L2_STD_NTSC_M;
601                         break;
602                 }
603                 break;
604         }
605         case VIDIOC_G_TUNER:
606         {
607                 struct v4l2_tuner *tun = arg;
608
609                 memset(tun, 0, sizeof(*tun));
610                 strcpy(tun->name, "Television");
611                 tun->type = V4L2_TUNER_ANALOG_TV;
612                 tun->rangelow = 0UL; /* does anything use these? */
613                 tun->rangehigh = 0xffffffffUL;
614                 switch (t->type) {
615                 case TUNER_SONY_BTF_PG472Z:
616                         tun->capability = V4L2_TUNER_CAP_NORM |
617                                 V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 |
618                                 V4L2_TUNER_CAP_LANG2;
619                         tun->rxsubchans = V4L2_TUNER_SUB_MONO |
620                                 V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_LANG1 |
621                                 V4L2_TUNER_SUB_LANG2;
622                         break;
623                 case TUNER_SONY_BTF_PK467Z:
624                 case TUNER_SONY_BTF_PB463Z:
625                         tun->capability = V4L2_TUNER_CAP_STEREO;
626                         tun->rxsubchans = V4L2_TUNER_SUB_MONO |
627                                                 V4L2_TUNER_SUB_STEREO;
628                         break;
629                 }
630                 tun->audmode = t->audmode;
631                 return 0;
632         }
633         case VIDIOC_S_TUNER:
634         {
635                 struct v4l2_tuner *tun = arg;
636
637                 switch (t->type) {
638                 case TUNER_SONY_BTF_PG472Z:
639                         if (tun->audmode != t->audmode) {
640                                 t->audmode = tun->audmode;
641                                 mpx_setup(client);
642                         }
643                         break;
644                 case TUNER_SONY_BTF_PK467Z:
645                 case TUNER_SONY_BTF_PB463Z:
646                         break;
647                 }
648                 return 0;
649         }
650         default:
651                 break;
652         }
653         return 0;
654 }
655
656 static int wis_sony_tuner_probe(struct i2c_client *client,
657                                 const struct i2c_device_id *id)
658 {
659         struct i2c_adapter *adapter = client->adapter;
660         struct wis_sony_tuner *t;
661
662         if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_I2C_BLOCK))
663                 return -ENODEV;
664
665         t = kmalloc(sizeof(struct wis_sony_tuner), GFP_KERNEL);
666         if (t == NULL)
667                 return -ENOMEM;
668
669         t->type = -1;
670         t->freq = 0;
671         t->mpxmode = 0;
672         t->audmode = V4L2_TUNER_MODE_STEREO;
673         i2c_set_clientdata(client, t);
674
675         dev_dbg(&client->dev, "initializing tuner at address %d on %s\n",
676                 client->addr, adapter->name);
677
678         return 0;
679 }
680
681 static int wis_sony_tuner_remove(struct i2c_client *client)
682 {
683         struct wis_sony_tuner *t = i2c_get_clientdata(client);
684
685         kfree(t);
686         return 0;
687 }
688
689 static const struct i2c_device_id wis_sony_tuner_id[] = {
690         { "wis_sony_tuner", 0 },
691         { }
692 };
693 MODULE_DEVICE_TABLE(i2c, wis_sony_tuner_id);
694
695 static struct i2c_driver wis_sony_tuner_driver = {
696         .driver = {
697                 .name   = "WIS Sony TV Tuner I2C driver",
698         },
699         .probe          = wis_sony_tuner_probe,
700         .remove         = wis_sony_tuner_remove,
701         .command        = tuner_command,
702         .id_table       = wis_sony_tuner_id,
703 };
704
705 module_i2c_driver(wis_sony_tuner_driver);
706
707 MODULE_LICENSE("GPL v2");