2 * Copyright (C) 2005-2006 Micronas USA Inc.
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.
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.
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.
18 #include <linux/module.h>
19 #include <linux/init.h>
20 #include <linux/i2c.h>
21 #include <linux/videodev2.h>
22 #include <media/tuner.h>
23 #include <media/v4l2-common.h>
24 #include <media/v4l2-ioctl.h>
25 #include <media/v4l2-device.h>
26 #include <linux/slab.h>
28 MODULE_DESCRIPTION("sony-btf-mpx driver");
29 MODULE_LICENSE("GPL v2");
32 module_param(debug
, int, 0644);
33 MODULE_PARM_DESC(debug
, "debug level 0=off(default) 1=on\n");
35 /* #define MPX_DEBUG */
40 * AS(IF/MPX) pin: LOW HIGH/OPEN
41 * IF/MPX address: 0x42/0x40 0x43/0x44
45 static int force_mpx_mode
= -1;
46 module_param(force_mpx_mode
, int, 0644);
49 struct v4l2_subdev sd
;
54 static inline struct sony_btf_mpx
*to_state(struct v4l2_subdev
*sd
)
56 return container_of(sd
, struct sony_btf_mpx
, sd
);
59 static int mpx_write(struct i2c_client
*client
, int dev
, int addr
, int val
)
65 buffer
[1] = addr
>> 8;
66 buffer
[2] = addr
& 0xff;
68 buffer
[4] = val
& 0xff;
69 msg
.addr
= client
->addr
;
73 i2c_transfer(client
->adapter
, &msg
, 1);
78 * MPX register values for the BTF-PG472Z:
81 * MODUS SOURCE ACB PRESCAL PRESCAL PRESCAL SYSTEM VOLUME
82 * 10/0030 12/0008 12/0013 12/000E 12/0010 12/0000 10/0020 12/0000
83 * ---------------------------------------------------------------
84 * Auto 1003 0020 0100 2603 5000 XXXX 0001 7500
87 * Mono 1003 0020 0100 2603 5000 XXXX 0003 7500
88 * A2 1003 0020 0100 2601 5000 XXXX 0003 7500
89 * NICAM 1003 0120 0100 2603 5000 XXXX 0008 7500
92 * Mono 1003 0020 0100 2603 7900 XXXX 000A 7500
93 * NICAM 1003 0120 0100 2603 7900 XXXX 000A 7500
96 * Mono 1003 0020 0100 2603 5000 XXXX 0004 7500
97 * A2-1 1003 0020 0100 2601 5000 XXXX 0004 7500
98 * A2-2 1003 0020 0100 2601 5000 XXXX 0005 7500
99 * A2-3 1003 0020 0100 2601 5000 XXXX 0007 7500
100 * NICAM 1003 0120 0100 2603 5000 XXXX 000B 7500
103 * Mono 0003 0200 0100 7C03 5000 2200 0009 7500
104 * NICAM 0003 0120 0100 7C03 5000 XXXX 0009 7500
107 * Mono 1003 0200 0100 2B03 5000 2B00 0002 7500
109 * For Asia, replace the 0x26XX in FM_PRESCALE with 0x14XX.
111 * Bilingual selection in A2/NICAM:
113 * High byte of SOURCE Left chan Right chan
118 * Force mono in NICAM by setting the high byte of SOURCE to 0x02 (L/L') or
119 * 0x00 (all other bands). Force mono in A2 with FMONO_A2:
124 * Forced mono ON 07F0
125 * Forced mono OFF 0190
128 static const struct {
129 enum { AUD_MONO
, AUD_A2
, AUD_NICAM
, AUD_NICAM_L
} audio_mode
;
138 } mpx_audio_modes
[] = {
139 /* Auto */ { AUD_MONO
, 0x1003, 0x0020, 0x0100, 0x2603,
140 0x5000, 0x0000, 0x0001, 0x7500 },
141 /* B/G Mono */ { AUD_MONO
, 0x1003, 0x0020, 0x0100, 0x2603,
142 0x5000, 0x0000, 0x0003, 0x7500 },
143 /* B/G A2 */ { AUD_A2
, 0x1003, 0x0020, 0x0100, 0x2601,
144 0x5000, 0x0000, 0x0003, 0x7500 },
145 /* B/G NICAM */ { AUD_NICAM
, 0x1003, 0x0120, 0x0100, 0x2603,
146 0x5000, 0x0000, 0x0008, 0x7500 },
147 /* I Mono */ { AUD_MONO
, 0x1003, 0x0020, 0x0100, 0x2603,
148 0x7900, 0x0000, 0x000A, 0x7500 },
149 /* I NICAM */ { AUD_NICAM
, 0x1003, 0x0120, 0x0100, 0x2603,
150 0x7900, 0x0000, 0x000A, 0x7500 },
151 /* D/K Mono */ { AUD_MONO
, 0x1003, 0x0020, 0x0100, 0x2603,
152 0x5000, 0x0000, 0x0004, 0x7500 },
153 /* D/K A2-1 */ { AUD_A2
, 0x1003, 0x0020, 0x0100, 0x2601,
154 0x5000, 0x0000, 0x0004, 0x7500 },
155 /* D/K A2-2 */ { AUD_A2
, 0x1003, 0x0020, 0x0100, 0x2601,
156 0x5000, 0x0000, 0x0005, 0x7500 },
157 /* D/K A2-3 */ { AUD_A2
, 0x1003, 0x0020, 0x0100, 0x2601,
158 0x5000, 0x0000, 0x0007, 0x7500 },
159 /* D/K NICAM */ { AUD_NICAM
, 0x1003, 0x0120, 0x0100, 0x2603,
160 0x5000, 0x0000, 0x000B, 0x7500 },
161 /* L/L' Mono */ { AUD_MONO
, 0x0003, 0x0200, 0x0100, 0x7C03,
162 0x5000, 0x2200, 0x0009, 0x7500 },
163 /* L/L' NICAM */{ AUD_NICAM_L
, 0x0003, 0x0120, 0x0100, 0x7C03,
164 0x5000, 0x0000, 0x0009, 0x7500 },
167 #define MPX_NUM_MODES ARRAY_SIZE(mpx_audio_modes)
169 static int mpx_setup(struct sony_btf_mpx
*t
)
171 struct i2c_client
*client
= v4l2_get_subdevdata(&t
->sd
);
175 int mode
= t
->mpxmode
;
181 msg
.addr
= client
->addr
;
185 i2c_transfer(client
->adapter
, &msg
, 1);
187 i2c_transfer(client
->adapter
, &msg
, 1);
189 if (t
->audmode
!= V4L2_TUNER_MODE_MONO
)
192 if (mpx_audio_modes
[mode
].audio_mode
!= AUD_MONO
) {
193 switch (t
->audmode
) {
194 case V4L2_TUNER_MODE_MONO
:
195 switch (mpx_audio_modes
[mode
].audio_mode
) {
197 source
= mpx_audio_modes
[mode
].source
;
209 case V4L2_TUNER_MODE_STEREO
:
210 source
= mpx_audio_modes
[mode
].source
;
212 case V4L2_TUNER_MODE_LANG1
:
215 case V4L2_TUNER_MODE_LANG2
:
219 source
|= mpx_audio_modes
[mode
].source
& 0x00ff;
221 source
= mpx_audio_modes
[mode
].source
;
223 mpx_write(client
, 0x10, 0x0030, mpx_audio_modes
[mode
].modus
);
224 mpx_write(client
, 0x12, 0x0008, source
);
225 mpx_write(client
, 0x12, 0x0013, mpx_audio_modes
[mode
].acb
);
226 mpx_write(client
, 0x12, 0x000e,
227 mpx_audio_modes
[mode
].fm_prescale
);
228 mpx_write(client
, 0x12, 0x0010,
229 mpx_audio_modes
[mode
].nicam_prescale
);
230 mpx_write(client
, 0x12, 0x000d,
231 mpx_audio_modes
[mode
].scart_prescale
);
232 mpx_write(client
, 0x10, 0x0020, mpx_audio_modes
[mode
].system
);
233 mpx_write(client
, 0x12, 0x0000, mpx_audio_modes
[mode
].volume
);
234 if (mpx_audio_modes
[mode
].audio_mode
== AUD_A2
)
235 mpx_write(client
, 0x10, 0x0022,
236 t
->audmode
== V4L2_TUNER_MODE_MONO
? 0x07f0 : 0x0190);
241 struct i2c_msg msgs
[2];
244 "MPX registers: %04x %04x %04x %04x %04x %04x %04x %04x\n",
245 mpx_audio_modes
[mode
].modus
,
247 mpx_audio_modes
[mode
].acb
,
248 mpx_audio_modes
[mode
].fm_prescale
,
249 mpx_audio_modes
[mode
].nicam_prescale
,
250 mpx_audio_modes
[mode
].scart_prescale
,
251 mpx_audio_modes
[mode
].system
,
252 mpx_audio_modes
[mode
].volume
);
256 msgs
[0].addr
= client
->addr
;
260 msgs
[1].addr
= client
->addr
;
261 msgs
[1].flags
= I2C_M_RD
;
264 i2c_transfer(client
->adapter
, msgs
, 2);
265 v4l2_info(client
, "MPX system: %02x%02x\n",
270 i2c_transfer(client
->adapter
, msgs
, 2);
271 v4l2_info(client
, "MPX status: %02x%02x\n",
279 static int sony_btf_mpx_s_std(struct v4l2_subdev
*sd
, v4l2_std_id std
)
281 struct sony_btf_mpx
*t
= to_state(sd
);
282 int default_mpx_mode
= 0;
284 if (std
& V4L2_STD_PAL_BG
)
285 default_mpx_mode
= 1;
286 else if (std
& V4L2_STD_PAL_I
)
287 default_mpx_mode
= 4;
288 else if (std
& V4L2_STD_PAL_DK
)
289 default_mpx_mode
= 6;
290 else if (std
& V4L2_STD_SECAM_L
)
291 default_mpx_mode
= 11;
293 if (default_mpx_mode
!= t
->mpxmode
) {
294 t
->mpxmode
= default_mpx_mode
;
300 static int sony_btf_mpx_g_tuner(struct v4l2_subdev
*sd
, struct v4l2_tuner
*vt
)
302 struct sony_btf_mpx
*t
= to_state(sd
);
304 vt
->capability
= V4L2_TUNER_CAP_NORM
|
305 V4L2_TUNER_CAP_STEREO
| V4L2_TUNER_CAP_LANG1
|
306 V4L2_TUNER_CAP_LANG2
;
307 vt
->rxsubchans
= V4L2_TUNER_SUB_MONO
|
308 V4L2_TUNER_SUB_STEREO
| V4L2_TUNER_SUB_LANG1
|
309 V4L2_TUNER_SUB_LANG2
;
310 vt
->audmode
= t
->audmode
;
314 static int sony_btf_mpx_s_tuner(struct v4l2_subdev
*sd
, const struct v4l2_tuner
*vt
)
316 struct sony_btf_mpx
*t
= to_state(sd
);
318 if (vt
->type
!= V4L2_TUNER_ANALOG_TV
)
321 if (vt
->audmode
!= t
->audmode
) {
322 t
->audmode
= vt
->audmode
;
328 /* --------------------------------------------------------------------------*/
330 static const struct v4l2_subdev_core_ops sony_btf_mpx_core_ops
= {
331 .s_std
= sony_btf_mpx_s_std
,
334 static const struct v4l2_subdev_tuner_ops sony_btf_mpx_tuner_ops
= {
335 .s_tuner
= sony_btf_mpx_s_tuner
,
336 .g_tuner
= sony_btf_mpx_g_tuner
,
339 static const struct v4l2_subdev_ops sony_btf_mpx_ops
= {
340 .core
= &sony_btf_mpx_core_ops
,
341 .tuner
= &sony_btf_mpx_tuner_ops
,
344 /* --------------------------------------------------------------------------*/
346 static int sony_btf_mpx_probe(struct i2c_client
*client
,
347 const struct i2c_device_id
*id
)
349 struct sony_btf_mpx
*t
;
350 struct v4l2_subdev
*sd
;
352 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_SMBUS_I2C_BLOCK
))
355 v4l_info(client
, "chip found @ 0x%x (%s)\n",
356 client
->addr
<< 1, client
->adapter
->name
);
358 t
= kzalloc(sizeof(struct sony_btf_mpx
), GFP_KERNEL
);
363 v4l2_i2c_subdev_init(sd
, client
, &sony_btf_mpx_ops
);
365 /* Initialize sony_btf_mpx */
367 t
->audmode
= V4L2_TUNER_MODE_STEREO
;
372 static int sony_btf_mpx_remove(struct i2c_client
*client
)
374 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
376 v4l2_device_unregister_subdev(sd
);
382 /* ----------------------------------------------------------------------- */
384 static const struct i2c_device_id sony_btf_mpx_id
[] = {
385 { "sony-btf-mpx", 0 },
388 MODULE_DEVICE_TABLE(i2c
, sony_btf_mpx_id
);
390 static struct i2c_driver sony_btf_mpx_driver
= {
392 .owner
= THIS_MODULE
,
393 .name
= "sony-btf-mpx",
395 .probe
= sony_btf_mpx_probe
,
396 .remove
= sony_btf_mpx_remove
,
397 .id_table
= sony_btf_mpx_id
,
399 module_i2c_driver(sony_btf_mpx_driver
);