blob: 97e24769e65b22ebb2a84beb3d37c65c77ec2dec [file] [log] [blame]
Hans Verkuilac247432007-07-27 06:56:50 -03001/*
2 * vp27smpx - driver version 0.0.1
3 *
4 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
5 *
Kazuhiko Kawakamida80be22007-08-18 11:39:28 -03006 * Based on a tvaudio patch from Takahiro Adachi <tadachi@tadachi-net.com>
7 * and Kazuhiko Kawakami <kazz-0@mail.goo.ne.jp>
Hans Verkuilac247432007-07-27 06:56:50 -03008 *
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.
13 *
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.
18 *
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.
22 */
23
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>
Hans Verkuil45eea272007-09-13 11:11:44 -030033#include <media/v4l2-i2c-drv-legacy.h>
Hans Verkuilac247432007-07-27 06:56:50 -030034
35MODULE_DESCRIPTION("vp27smpx driver");
36MODULE_AUTHOR("Hans Verkuil");
37MODULE_LICENSE("GPL");
38
39static unsigned short normal_i2c[] = { 0xb6 >> 1, I2C_CLIENT_END };
40
41
42I2C_CLIENT_INSMOD;
43
44/* ----------------------------------------------------------------------- */
45
46struct vp27smpx_state {
47 int radio;
48 u32 audmode;
49};
50
51static void vp27smpx_set_audmode(struct i2c_client *client, u32 audmode)
52{
53 struct vp27smpx_state *state = i2c_get_clientdata(client);
54 u8 data[3] = { 0x00, 0x00, 0x04 };
55
56 switch (audmode) {
57 case V4L2_TUNER_MODE_MONO:
58 case V4L2_TUNER_MODE_LANG1:
59 break;
60 case V4L2_TUNER_MODE_STEREO:
61 case V4L2_TUNER_MODE_LANG1_LANG2:
62 data[1] = 0x01;
63 break;
64 case V4L2_TUNER_MODE_LANG2:
65 data[1] = 0x02;
66 break;
67 }
68
69 if (i2c_master_send(client, data, sizeof(data)) != sizeof(data)) {
70 v4l_err(client, "%s: I/O error setting audmode\n", client->name);
71 }
72 else {
73 state->audmode = audmode;
74 }
75}
76
Hans Verkuil45eea272007-09-13 11:11:44 -030077static int vp27smpx_command(struct i2c_client *client, unsigned int cmd, void *arg)
Hans Verkuilac247432007-07-27 06:56:50 -030078{
79 struct vp27smpx_state *state = i2c_get_clientdata(client);
80 struct v4l2_tuner *vt = arg;
81
82 switch (cmd) {
83 case AUDC_SET_RADIO:
84 state->radio = 1;
85 break;
86
87 case VIDIOC_S_STD:
88 state->radio = 0;
89 break;
90
91 case VIDIOC_S_TUNER:
92 if (!state->radio)
93 vp27smpx_set_audmode(client, vt->audmode);
94 break;
95
96 case VIDIOC_G_TUNER:
97 if (state->radio)
98 break;
99 vt->audmode = state->audmode;
100 vt->capability = V4L2_TUNER_CAP_STEREO |
101 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
102 vt->rxsubchans = V4L2_TUNER_SUB_MONO;
103 break;
104
105 case VIDIOC_G_CHIP_IDENT:
106 return v4l2_chip_ident_i2c_client(client, arg, V4L2_IDENT_VP27SMPX, 0);
107
108 case VIDIOC_LOG_STATUS:
109 v4l_info(client, "Audio Mode: %u%s\n", state->audmode,
110 state->radio ? " (Radio)" : "");
111 break;
112
113 default:
114 return -EINVAL;
115 }
116 return 0;
117}
118
119/* ----------------------------------------------------------------------- */
120
121/* i2c implementation */
122
123/*
124 * Generic i2c probe
125 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
126 */
127
Hans Verkuil45eea272007-09-13 11:11:44 -0300128static int vp27smpx_probe(struct i2c_client *client)
Hans Verkuilac247432007-07-27 06:56:50 -0300129{
Hans Verkuilac247432007-07-27 06:56:50 -0300130 struct vp27smpx_state *state;
131
132 /* Check if the adapter supports the needed features */
Hans Verkuil45eea272007-09-13 11:11:44 -0300133 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
Hans Verkuil188f3452007-09-16 10:47:15 -0300134 return -EIO;
Hans Verkuilac247432007-07-27 06:56:50 -0300135
Hans Verkuilac247432007-07-27 06:56:50 -0300136 snprintf(client->name, sizeof(client->name) - 1, "vp27smpx");
137
Hans Verkuil45eea272007-09-13 11:11:44 -0300138 v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name);
Hans Verkuilac247432007-07-27 06:56:50 -0300139
140 state = kzalloc(sizeof(struct vp27smpx_state), GFP_KERNEL);
141 if (state == NULL) {
Hans Verkuilac247432007-07-27 06:56:50 -0300142 return -ENOMEM;
143 }
144 state->audmode = V4L2_TUNER_MODE_STEREO;
145 i2c_set_clientdata(client, state);
146
147 /* initialize vp27smpx */
148 vp27smpx_set_audmode(client, state->audmode);
Hans Verkuilac247432007-07-27 06:56:50 -0300149 return 0;
150}
151
Hans Verkuil45eea272007-09-13 11:11:44 -0300152static int vp27smpx_remove(struct i2c_client *client)
Hans Verkuilac247432007-07-27 06:56:50 -0300153{
Hans Verkuil45eea272007-09-13 11:11:44 -0300154 kfree(i2c_get_clientdata(client));
Hans Verkuilac247432007-07-27 06:56:50 -0300155 return 0;
156}
157
158/* ----------------------------------------------------------------------- */
159
Hans Verkuil45eea272007-09-13 11:11:44 -0300160static struct v4l2_i2c_driver_data v4l2_i2c_data = {
161 .name = "vp27smpx",
162 .driverid = I2C_DRIVERID_VP27SMPX,
163 .command = vp27smpx_command,
164 .probe = vp27smpx_probe,
165 .remove = vp27smpx_remove,
Hans Verkuilac247432007-07-27 06:56:50 -0300166};
167