blob: c6611a3f2b3d9e1782666a00289528a889ddd232 [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.
Hans Verkuilac247432007-07-27 06:56:50 -030018 */
19
20#include <linux/module.h>
21#include <linux/types.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090022#include <linux/slab.h>
Hans Verkuilac247432007-07-27 06:56:50 -030023#include <linux/ioctl.h>
Linus Torvalds7c0f6ba2016-12-24 11:46:01 -080024#include <linux/uaccess.h>
Hans Verkuilac247432007-07-27 06:56:50 -030025#include <linux/i2c.h>
Hans Verkuil33b687c2008-07-25 05:32:50 -030026#include <linux/videodev2.h>
Hans Verkuild9460f02008-11-29 13:01:28 -030027#include <media/v4l2-device.h>
Hans Verkuilac247432007-07-27 06:56:50 -030028
29MODULE_DESCRIPTION("vp27smpx driver");
30MODULE_AUTHOR("Hans Verkuil");
31MODULE_LICENSE("GPL");
32
Hans Verkuilac247432007-07-27 06:56:50 -030033
34/* ----------------------------------------------------------------------- */
35
36struct vp27smpx_state {
Hans Verkuild9460f02008-11-29 13:01:28 -030037 struct v4l2_subdev sd;
Hans Verkuilac247432007-07-27 06:56:50 -030038 int radio;
39 u32 audmode;
40};
41
Hans Verkuild9460f02008-11-29 13:01:28 -030042static inline struct vp27smpx_state *to_state(struct v4l2_subdev *sd)
Hans Verkuilac247432007-07-27 06:56:50 -030043{
Hans Verkuild9460f02008-11-29 13:01:28 -030044 return container_of(sd, struct vp27smpx_state, sd);
45}
46
47static void vp27smpx_set_audmode(struct v4l2_subdev *sd, u32 audmode)
48{
49 struct vp27smpx_state *state = to_state(sd);
50 struct i2c_client *client = v4l2_get_subdevdata(sd);
Hans Verkuilac247432007-07-27 06:56:50 -030051 u8 data[3] = { 0x00, 0x00, 0x04 };
52
53 switch (audmode) {
Hans Verkuil35df38c2007-12-12 07:40:54 -030054 case V4L2_TUNER_MODE_MONO:
55 case V4L2_TUNER_MODE_LANG1:
56 break;
57 case V4L2_TUNER_MODE_STEREO:
58 case V4L2_TUNER_MODE_LANG1_LANG2:
59 data[1] = 0x01;
60 break;
61 case V4L2_TUNER_MODE_LANG2:
62 data[1] = 0x02;
63 break;
Hans Verkuilac247432007-07-27 06:56:50 -030064 }
65
Hans Verkuil35df38c2007-12-12 07:40:54 -030066 if (i2c_master_send(client, data, sizeof(data)) != sizeof(data))
Hans Verkuild9460f02008-11-29 13:01:28 -030067 v4l2_err(sd, "I/O error setting audmode\n");
Hans Verkuil35df38c2007-12-12 07:40:54 -030068 else
Hans Verkuilac247432007-07-27 06:56:50 -030069 state->audmode = audmode;
Hans Verkuilac247432007-07-27 06:56:50 -030070}
71
Hans Verkuild9460f02008-11-29 13:01:28 -030072static int vp27smpx_s_radio(struct v4l2_subdev *sd)
Hans Verkuilac247432007-07-27 06:56:50 -030073{
Hans Verkuild9460f02008-11-29 13:01:28 -030074 struct vp27smpx_state *state = to_state(sd);
Hans Verkuilac247432007-07-27 06:56:50 -030075
Hans Verkuild9460f02008-11-29 13:01:28 -030076 state->radio = 1;
Hans Verkuilac247432007-07-27 06:56:50 -030077 return 0;
78}
79
Hans Verkuild9460f02008-11-29 13:01:28 -030080static int vp27smpx_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
81{
82 struct vp27smpx_state *state = to_state(sd);
83
84 state->radio = 0;
85 return 0;
86}
87
Hans Verkuil2f73c7c2013-03-15 06:10:06 -030088static int vp27smpx_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
Hans Verkuild9460f02008-11-29 13:01:28 -030089{
90 struct vp27smpx_state *state = to_state(sd);
91
92 if (!state->radio)
93 vp27smpx_set_audmode(sd, vt->audmode);
94 return 0;
95}
96
97static int vp27smpx_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
98{
99 struct vp27smpx_state *state = to_state(sd);
100
101 if (state->radio)
102 return 0;
103 vt->audmode = state->audmode;
104 vt->capability = V4L2_TUNER_CAP_STEREO |
105 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
106 vt->rxsubchans = V4L2_TUNER_SUB_MONO;
107 return 0;
108}
109
Hans Verkuild9460f02008-11-29 13:01:28 -0300110static int vp27smpx_log_status(struct v4l2_subdev *sd)
111{
112 struct vp27smpx_state *state = to_state(sd);
113
114 v4l2_info(sd, "Audio Mode: %u%s\n", state->audmode,
115 state->radio ? " (Radio)" : "");
116 return 0;
117}
118
Hans Verkuild9460f02008-11-29 13:01:28 -0300119/* ----------------------------------------------------------------------- */
120
121static const struct v4l2_subdev_core_ops vp27smpx_core_ops = {
122 .log_status = vp27smpx_log_status,
Hans Verkuild9460f02008-11-29 13:01:28 -0300123};
124
125static const struct v4l2_subdev_tuner_ops vp27smpx_tuner_ops = {
126 .s_radio = vp27smpx_s_radio,
Hans Verkuild9460f02008-11-29 13:01:28 -0300127 .s_tuner = vp27smpx_s_tuner,
128 .g_tuner = vp27smpx_g_tuner,
129};
130
Laurent Pinchart8774bed2014-04-28 16:53:01 -0300131static const struct v4l2_subdev_video_ops vp27smpx_video_ops = {
132 .s_std = vp27smpx_s_std,
133};
134
Hans Verkuild9460f02008-11-29 13:01:28 -0300135static const struct v4l2_subdev_ops vp27smpx_ops = {
136 .core = &vp27smpx_core_ops,
137 .tuner = &vp27smpx_tuner_ops,
Laurent Pinchart8774bed2014-04-28 16:53:01 -0300138 .video = &vp27smpx_video_ops,
Hans Verkuild9460f02008-11-29 13:01:28 -0300139};
140
Hans Verkuilac247432007-07-27 06:56:50 -0300141/* ----------------------------------------------------------------------- */
142
143/* i2c implementation */
144
145/*
146 * Generic i2c probe
147 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
148 */
149
Jean Delvared2653e92008-04-29 23:11:39 +0200150static int vp27smpx_probe(struct i2c_client *client,
151 const struct i2c_device_id *id)
Hans Verkuilac247432007-07-27 06:56:50 -0300152{
Hans Verkuilac247432007-07-27 06:56:50 -0300153 struct vp27smpx_state *state;
Hans Verkuild9460f02008-11-29 13:01:28 -0300154 struct v4l2_subdev *sd;
Hans Verkuilac247432007-07-27 06:56:50 -0300155
156 /* Check if the adapter supports the needed features */
Hans Verkuil45eea272007-09-13 11:11:44 -0300157 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
Hans Verkuil188f3452007-09-16 10:47:15 -0300158 return -EIO;
Hans Verkuilac247432007-07-27 06:56:50 -0300159
Hans Verkuil35df38c2007-12-12 07:40:54 -0300160 v4l_info(client, "chip found @ 0x%x (%s)\n",
161 client->addr << 1, client->adapter->name);
Hans Verkuilac247432007-07-27 06:56:50 -0300162
Laurent Pinchartc02b2112013-05-02 08:29:43 -0300163 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
Hans Verkuil35df38c2007-12-12 07:40:54 -0300164 if (state == NULL)
Hans Verkuilac247432007-07-27 06:56:50 -0300165 return -ENOMEM;
Hans Verkuild9460f02008-11-29 13:01:28 -0300166 sd = &state->sd;
167 v4l2_i2c_subdev_init(sd, client, &vp27smpx_ops);
Hans Verkuilac247432007-07-27 06:56:50 -0300168 state->audmode = V4L2_TUNER_MODE_STEREO;
Hans Verkuilac247432007-07-27 06:56:50 -0300169
170 /* initialize vp27smpx */
Hans Verkuild9460f02008-11-29 13:01:28 -0300171 vp27smpx_set_audmode(sd, state->audmode);
Hans Verkuilac247432007-07-27 06:56:50 -0300172 return 0;
173}
174
Hans Verkuil45eea272007-09-13 11:11:44 -0300175static int vp27smpx_remove(struct i2c_client *client)
Hans Verkuilac247432007-07-27 06:56:50 -0300176{
Hans Verkuild9460f02008-11-29 13:01:28 -0300177 struct v4l2_subdev *sd = i2c_get_clientdata(client);
178
179 v4l2_device_unregister_subdev(sd);
Hans Verkuilac247432007-07-27 06:56:50 -0300180 return 0;
181}
182
183/* ----------------------------------------------------------------------- */
184
Jean Delvareaf294862008-05-18 20:49:40 +0200185static const struct i2c_device_id vp27smpx_id[] = {
186 { "vp27smpx", 0 },
187 { }
188};
189MODULE_DEVICE_TABLE(i2c, vp27smpx_id);
190
Hans Verkuil1f352662010-09-15 14:56:12 -0300191static struct i2c_driver vp27smpx_driver = {
192 .driver = {
Hans Verkuil1f352662010-09-15 14:56:12 -0300193 .name = "vp27smpx",
194 },
195 .probe = vp27smpx_probe,
196 .remove = vp27smpx_remove,
197 .id_table = vp27smpx_id,
Hans Verkuilac247432007-07-27 06:56:50 -0300198};
Hans Verkuil1f352662010-09-15 14:56:12 -0300199
Axel Linc6e8d862012-02-12 06:56:32 -0300200module_i2c_driver(vp27smpx_driver);