2 * vp27smpx - driver version 0.0.1
4 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
6 * Based on a tvaudio patch from Takahiro Adachi <tadachi@tadachi-net.com>
7 * and Kazuhiko Kawakami <kazz-0@mail.goo.ne.jp>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 #include <linux/module.h>
25 #include <linux/types.h>
26 #include <linux/slab.h>
27 #include <linux/ioctl.h>
28 #include <asm/uaccess.h>
29 #include <linux/i2c.h>
30 #include <linux/videodev2.h>
31 #include <media/v4l2-device.h>
33 MODULE_DESCRIPTION("vp27smpx driver");
34 MODULE_AUTHOR("Hans Verkuil");
35 MODULE_LICENSE("GPL");
38 /* ----------------------------------------------------------------------- */
40 struct vp27smpx_state
{
41 struct v4l2_subdev sd
;
46 static inline struct vp27smpx_state
*to_state(struct v4l2_subdev
*sd
)
48 return container_of(sd
, struct vp27smpx_state
, sd
);
51 static void vp27smpx_set_audmode(struct v4l2_subdev
*sd
, u32 audmode
)
53 struct vp27smpx_state
*state
= to_state(sd
);
54 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
55 u8 data
[3] = { 0x00, 0x00, 0x04 };
58 case V4L2_TUNER_MODE_MONO
:
59 case V4L2_TUNER_MODE_LANG1
:
61 case V4L2_TUNER_MODE_STEREO
:
62 case V4L2_TUNER_MODE_LANG1_LANG2
:
65 case V4L2_TUNER_MODE_LANG2
:
70 if (i2c_master_send(client
, data
, sizeof(data
)) != sizeof(data
))
71 v4l2_err(sd
, "I/O error setting audmode\n");
73 state
->audmode
= audmode
;
76 static int vp27smpx_s_radio(struct v4l2_subdev
*sd
)
78 struct vp27smpx_state
*state
= to_state(sd
);
84 static int vp27smpx_s_std(struct v4l2_subdev
*sd
, v4l2_std_id norm
)
86 struct vp27smpx_state
*state
= to_state(sd
);
92 static int vp27smpx_s_tuner(struct v4l2_subdev
*sd
, const struct v4l2_tuner
*vt
)
94 struct vp27smpx_state
*state
= to_state(sd
);
97 vp27smpx_set_audmode(sd
, vt
->audmode
);
101 static int vp27smpx_g_tuner(struct v4l2_subdev
*sd
, struct v4l2_tuner
*vt
)
103 struct vp27smpx_state
*state
= to_state(sd
);
107 vt
->audmode
= state
->audmode
;
108 vt
->capability
= V4L2_TUNER_CAP_STEREO
|
109 V4L2_TUNER_CAP_LANG1
| V4L2_TUNER_CAP_LANG2
;
110 vt
->rxsubchans
= V4L2_TUNER_SUB_MONO
;
114 static int vp27smpx_log_status(struct v4l2_subdev
*sd
)
116 struct vp27smpx_state
*state
= to_state(sd
);
118 v4l2_info(sd
, "Audio Mode: %u%s\n", state
->audmode
,
119 state
->radio
? " (Radio)" : "");
123 /* ----------------------------------------------------------------------- */
125 static const struct v4l2_subdev_core_ops vp27smpx_core_ops
= {
126 .log_status
= vp27smpx_log_status
,
129 static const struct v4l2_subdev_tuner_ops vp27smpx_tuner_ops
= {
130 .s_radio
= vp27smpx_s_radio
,
131 .s_tuner
= vp27smpx_s_tuner
,
132 .g_tuner
= vp27smpx_g_tuner
,
135 static const struct v4l2_subdev_video_ops vp27smpx_video_ops
= {
136 .s_std
= vp27smpx_s_std
,
139 static const struct v4l2_subdev_ops vp27smpx_ops
= {
140 .core
= &vp27smpx_core_ops
,
141 .tuner
= &vp27smpx_tuner_ops
,
142 .video
= &vp27smpx_video_ops
,
145 /* ----------------------------------------------------------------------- */
147 /* i2c implementation */
151 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
154 static int vp27smpx_probe(struct i2c_client
*client
,
155 const struct i2c_device_id
*id
)
157 struct vp27smpx_state
*state
;
158 struct v4l2_subdev
*sd
;
160 /* Check if the adapter supports the needed features */
161 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
164 v4l_info(client
, "chip found @ 0x%x (%s)\n",
165 client
->addr
<< 1, client
->adapter
->name
);
167 state
= devm_kzalloc(&client
->dev
, sizeof(*state
), GFP_KERNEL
);
171 v4l2_i2c_subdev_init(sd
, client
, &vp27smpx_ops
);
172 state
->audmode
= V4L2_TUNER_MODE_STEREO
;
174 /* initialize vp27smpx */
175 vp27smpx_set_audmode(sd
, state
->audmode
);
179 static int vp27smpx_remove(struct i2c_client
*client
)
181 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
183 v4l2_device_unregister_subdev(sd
);
187 /* ----------------------------------------------------------------------- */
189 static const struct i2c_device_id vp27smpx_id
[] = {
193 MODULE_DEVICE_TABLE(i2c
, vp27smpx_id
);
195 static struct i2c_driver vp27smpx_driver
= {
199 .probe
= vp27smpx_probe
,
200 .remove
= vp27smpx_remove
,
201 .id_table
= vp27smpx_id
,
204 module_i2c_driver(vp27smpx_driver
);