Merge branch 'v6v7' into devel
[linux/fpc-iii.git] / drivers / media / video / vp27smpx.c
blobc15efb6e7771987240000a38040454521552a930
1 /*
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>
32 #include <media/v4l2-chip-ident.h>
34 MODULE_DESCRIPTION("vp27smpx driver");
35 MODULE_AUTHOR("Hans Verkuil");
36 MODULE_LICENSE("GPL");
39 /* ----------------------------------------------------------------------- */
41 struct vp27smpx_state {
42 struct v4l2_subdev sd;
43 int radio;
44 u32 audmode;
47 static inline struct vp27smpx_state *to_state(struct v4l2_subdev *sd)
49 return container_of(sd, struct vp27smpx_state, sd);
52 static void vp27smpx_set_audmode(struct v4l2_subdev *sd, u32 audmode)
54 struct vp27smpx_state *state = to_state(sd);
55 struct i2c_client *client = v4l2_get_subdevdata(sd);
56 u8 data[3] = { 0x00, 0x00, 0x04 };
58 switch (audmode) {
59 case V4L2_TUNER_MODE_MONO:
60 case V4L2_TUNER_MODE_LANG1:
61 break;
62 case V4L2_TUNER_MODE_STEREO:
63 case V4L2_TUNER_MODE_LANG1_LANG2:
64 data[1] = 0x01;
65 break;
66 case V4L2_TUNER_MODE_LANG2:
67 data[1] = 0x02;
68 break;
71 if (i2c_master_send(client, data, sizeof(data)) != sizeof(data))
72 v4l2_err(sd, "I/O error setting audmode\n");
73 else
74 state->audmode = audmode;
77 static int vp27smpx_s_radio(struct v4l2_subdev *sd)
79 struct vp27smpx_state *state = to_state(sd);
81 state->radio = 1;
82 return 0;
85 static int vp27smpx_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
87 struct vp27smpx_state *state = to_state(sd);
89 state->radio = 0;
90 return 0;
93 static int vp27smpx_s_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
95 struct vp27smpx_state *state = to_state(sd);
97 if (!state->radio)
98 vp27smpx_set_audmode(sd, vt->audmode);
99 return 0;
102 static int vp27smpx_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
104 struct vp27smpx_state *state = to_state(sd);
106 if (state->radio)
107 return 0;
108 vt->audmode = state->audmode;
109 vt->capability = V4L2_TUNER_CAP_STEREO |
110 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
111 vt->rxsubchans = V4L2_TUNER_SUB_MONO;
112 return 0;
115 static int vp27smpx_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip)
117 struct i2c_client *client = v4l2_get_subdevdata(sd);
119 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_VP27SMPX, 0);
122 static int vp27smpx_log_status(struct v4l2_subdev *sd)
124 struct vp27smpx_state *state = to_state(sd);
126 v4l2_info(sd, "Audio Mode: %u%s\n", state->audmode,
127 state->radio ? " (Radio)" : "");
128 return 0;
131 /* ----------------------------------------------------------------------- */
133 static const struct v4l2_subdev_core_ops vp27smpx_core_ops = {
134 .log_status = vp27smpx_log_status,
135 .g_chip_ident = vp27smpx_g_chip_ident,
136 .s_std = vp27smpx_s_std,
139 static const struct v4l2_subdev_tuner_ops vp27smpx_tuner_ops = {
140 .s_radio = vp27smpx_s_radio,
141 .s_tuner = vp27smpx_s_tuner,
142 .g_tuner = vp27smpx_g_tuner,
145 static const struct v4l2_subdev_ops vp27smpx_ops = {
146 .core = &vp27smpx_core_ops,
147 .tuner = &vp27smpx_tuner_ops,
150 /* ----------------------------------------------------------------------- */
152 /* i2c implementation */
155 * Generic i2c probe
156 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
159 static int vp27smpx_probe(struct i2c_client *client,
160 const struct i2c_device_id *id)
162 struct vp27smpx_state *state;
163 struct v4l2_subdev *sd;
165 /* Check if the adapter supports the needed features */
166 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
167 return -EIO;
169 v4l_info(client, "chip found @ 0x%x (%s)\n",
170 client->addr << 1, client->adapter->name);
172 state = kzalloc(sizeof(struct vp27smpx_state), GFP_KERNEL);
173 if (state == NULL)
174 return -ENOMEM;
175 sd = &state->sd;
176 v4l2_i2c_subdev_init(sd, client, &vp27smpx_ops);
177 state->audmode = V4L2_TUNER_MODE_STEREO;
179 /* initialize vp27smpx */
180 vp27smpx_set_audmode(sd, state->audmode);
181 return 0;
184 static int vp27smpx_remove(struct i2c_client *client)
186 struct v4l2_subdev *sd = i2c_get_clientdata(client);
188 v4l2_device_unregister_subdev(sd);
189 kfree(to_state(sd));
190 return 0;
193 /* ----------------------------------------------------------------------- */
195 static const struct i2c_device_id vp27smpx_id[] = {
196 { "vp27smpx", 0 },
199 MODULE_DEVICE_TABLE(i2c, vp27smpx_id);
201 static struct i2c_driver vp27smpx_driver = {
202 .driver = {
203 .owner = THIS_MODULE,
204 .name = "vp27smpx",
206 .probe = vp27smpx_probe,
207 .remove = vp27smpx_remove,
208 .id_table = vp27smpx_id,
211 static __init int init_vp27smpx(void)
213 return i2c_add_driver(&vp27smpx_driver);
216 static __exit void exit_vp27smpx(void)
218 i2c_del_driver(&vp27smpx_driver);
221 module_init(init_vp27smpx);
222 module_exit(exit_vp27smpx);