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/videodev.h>
31 #include <media/v4l2-common.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 {
47 static void vp27smpx_set_audmode(struct i2c_client *client, u32 audmode)
49 struct vp27smpx_state *state = i2c_get_clientdata(client);
50 u8 data[3] = { 0x00, 0x00, 0x04 };
53 case V4L2_TUNER_MODE_MONO:
54 case V4L2_TUNER_MODE_LANG1:
56 case V4L2_TUNER_MODE_STEREO:
57 case V4L2_TUNER_MODE_LANG1_LANG2:
60 case V4L2_TUNER_MODE_LANG2:
65 if (i2c_master_send(client, data, sizeof(data)) != sizeof(data))
66 v4l_err(client, "%s: I/O error setting audmode\n",
69 state->audmode = audmode;
72 static int vp27smpx_command(struct i2c_client *client, unsigned cmd, void *arg)
74 struct vp27smpx_state *state = i2c_get_clientdata(client);
75 struct v4l2_tuner *vt = arg;
88 vp27smpx_set_audmode(client, vt->audmode);
94 vt->audmode = state->audmode;
95 vt->capability = V4L2_TUNER_CAP_STEREO |
96 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
97 vt->rxsubchans = V4L2_TUNER_SUB_MONO;
100 case VIDIOC_G_CHIP_IDENT:
101 return v4l2_chip_ident_i2c_client(client, arg,
102 V4L2_IDENT_VP27SMPX, 0);
104 case VIDIOC_LOG_STATUS:
105 v4l_info(client, "Audio Mode: %u%s\n", state->audmode,
106 state->radio ? " (Radio)" : "");
115 /* ----------------------------------------------------------------------- */
117 /* i2c implementation */
121 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
124 static int vp27smpx_probe(struct i2c_client *client,
125 const struct i2c_device_id *id)
127 struct vp27smpx_state *state;
129 /* Check if the adapter supports the needed features */
130 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
133 v4l_info(client, "chip found @ 0x%x (%s)\n",
134 client->addr << 1, client->adapter->name);
136 state = kzalloc(sizeof(struct vp27smpx_state), GFP_KERNEL);
139 state->audmode = V4L2_TUNER_MODE_STEREO;
140 i2c_set_clientdata(client, state);
142 /* initialize vp27smpx */
143 vp27smpx_set_audmode(client, state->audmode);
147 static int vp27smpx_remove(struct i2c_client *client)
149 kfree(i2c_get_clientdata(client));
153 /* ----------------------------------------------------------------------- */
155 static const struct i2c_device_id vp27smpx_id[] = {
159 MODULE_DEVICE_TABLE(i2c, vp27smpx_id);
161 static struct v4l2_i2c_driver_data v4l2_i2c_data = {
163 .driverid = I2C_DRIVERID_VP27SMPX,
164 .command = vp27smpx_command,
165 .probe = vp27smpx_probe,
166 .remove = vp27smpx_remove,
167 .id_table = vp27smpx_id,