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/ioctl.h>
27 #include <asm/uaccess.h>
28 #include <linux/i2c.h>
29 #include <linux/i2c-id.h>
30 #include <linux/videodev2.h>
31 #include <media/v4l2-device.h>
32 #include <media/v4l2-chip-ident.h>
33 #include <media/v4l2-i2c-drv.h>
35 MODULE_DESCRIPTION("vp27smpx driver");
36 MODULE_AUTHOR("Hans Verkuil");
37 MODULE_LICENSE("GPL");
40 /* ----------------------------------------------------------------------- */
42 struct vp27smpx_state {
43 struct v4l2_subdev sd;
48 static inline struct vp27smpx_state *to_state(struct v4l2_subdev *sd)
50 return container_of(sd, struct vp27smpx_state, sd);
53 static void vp27smpx_set_audmode(struct v4l2_subdev *sd, u32 audmode)
55 struct vp27smpx_state *state = to_state(sd);
56 struct i2c_client *client = v4l2_get_subdevdata(sd);
57 u8 data[3] = { 0x00, 0x00, 0x04 };
60 case V4L2_TUNER_MODE_MONO:
61 case V4L2_TUNER_MODE_LANG1:
63 case V4L2_TUNER_MODE_STEREO:
64 case V4L2_TUNER_MODE_LANG1_LANG2:
67 case V4L2_TUNER_MODE_LANG2:
72 if (i2c_master_send(client, data, sizeof(data)) != sizeof(data))
73 v4l2_err(sd, "I/O error setting audmode\n");
75 state->audmode = audmode;
78 static int vp27smpx_s_radio(struct v4l2_subdev *sd)
80 struct vp27smpx_state *state = to_state(sd);
86 static int vp27smpx_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
88 struct vp27smpx_state *state = to_state(sd);
94 static int vp27smpx_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
96 struct vp27smpx_state *state = to_state(sd);
99 vp27smpx_set_audmode(sd, vt->audmode);
103 static int vp27smpx_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
105 struct vp27smpx_state *state = to_state(sd);
109 vt->audmode = state->audmode;
110 vt->capability = V4L2_TUNER_CAP_STEREO |
111 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
112 vt->rxsubchans = V4L2_TUNER_SUB_MONO;
116 static int vp27smpx_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
118 struct i2c_client *client = v4l2_get_subdevdata(sd);
120 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_VP27SMPX, 0);
123 static int vp27smpx_log_status(struct v4l2_subdev *sd)
125 struct vp27smpx_state *state = to_state(sd);
127 v4l2_info(sd, "Audio Mode: %u%s\n", state->audmode,
128 state->radio ? " (Radio)" : "");
132 static int vp27smpx_command(struct i2c_client *client, unsigned cmd, void *arg)
134 return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg);
137 /* ----------------------------------------------------------------------- */
139 static const struct v4l2_subdev_core_ops vp27smpx_core_ops = {
140 .log_status = vp27smpx_log_status,
141 .g_chip_ident = vp27smpx_g_chip_ident,
144 static const struct v4l2_subdev_tuner_ops vp27smpx_tuner_ops = {
145 .s_radio = vp27smpx_s_radio,
146 .s_std = vp27smpx_s_std,
147 .s_tuner = vp27smpx_s_tuner,
148 .g_tuner = vp27smpx_g_tuner,
151 static const struct v4l2_subdev_ops vp27smpx_ops = {
152 .core = &vp27smpx_core_ops,
153 .tuner = &vp27smpx_tuner_ops,
156 /* ----------------------------------------------------------------------- */
158 /* i2c implementation */
162 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
165 static int vp27smpx_probe(struct i2c_client *client,
166 const struct i2c_device_id *id)
168 struct vp27smpx_state *state;
169 struct v4l2_subdev *sd;
171 /* Check if the adapter supports the needed features */
172 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
175 v4l_info(client, "chip found @ 0x%x (%s)\n",
176 client->addr << 1, client->adapter->name);
178 state = kzalloc(sizeof(struct vp27smpx_state), GFP_KERNEL);
182 v4l2_i2c_subdev_init(sd, client, &vp27smpx_ops);
183 state->audmode = V4L2_TUNER_MODE_STEREO;
185 /* initialize vp27smpx */
186 vp27smpx_set_audmode(sd, state->audmode);
190 static int vp27smpx_remove(struct i2c_client *client)
192 struct v4l2_subdev *sd = i2c_get_clientdata(client);
194 v4l2_device_unregister_subdev(sd);
199 /* ----------------------------------------------------------------------- */
201 static const struct i2c_device_id vp27smpx_id[] = {
205 MODULE_DEVICE_TABLE(i2c, vp27smpx_id);
207 static struct v4l2_i2c_driver_data v4l2_i2c_data = {
209 .driverid = I2C_DRIVERID_VP27SMPX,
210 .command = vp27smpx_command,
211 .probe = vp27smpx_probe,
212 .remove = vp27smpx_remove,
213 .id_table = vp27smpx_id,