Linux 4.19.133
[linux/fpc-iii.git] / drivers / media / i2c / vp27smpx.c
blobc6611a3f2b3d9e1782666a00289528a889ddd232
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.
20 #include <linux/module.h>
21 #include <linux/types.h>
22 #include <linux/slab.h>
23 #include <linux/ioctl.h>
24 #include <linux/uaccess.h>
25 #include <linux/i2c.h>
26 #include <linux/videodev2.h>
27 #include <media/v4l2-device.h>
29 MODULE_DESCRIPTION("vp27smpx driver");
30 MODULE_AUTHOR("Hans Verkuil");
31 MODULE_LICENSE("GPL");
34 /* ----------------------------------------------------------------------- */
36 struct vp27smpx_state {
37 struct v4l2_subdev sd;
38 int radio;
39 u32 audmode;
42 static inline struct vp27smpx_state *to_state(struct v4l2_subdev *sd)
44 return container_of(sd, struct vp27smpx_state, sd);
47 static void vp27smpx_set_audmode(struct v4l2_subdev *sd, u32 audmode)
49 struct vp27smpx_state *state = to_state(sd);
50 struct i2c_client *client = v4l2_get_subdevdata(sd);
51 u8 data[3] = { 0x00, 0x00, 0x04 };
53 switch (audmode) {
54 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;
66 if (i2c_master_send(client, data, sizeof(data)) != sizeof(data))
67 v4l2_err(sd, "I/O error setting audmode\n");
68 else
69 state->audmode = audmode;
72 static int vp27smpx_s_radio(struct v4l2_subdev *sd)
74 struct vp27smpx_state *state = to_state(sd);
76 state->radio = 1;
77 return 0;
80 static int vp27smpx_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
82 struct vp27smpx_state *state = to_state(sd);
84 state->radio = 0;
85 return 0;
88 static int vp27smpx_s_tuner(struct v4l2_subdev *sd, const struct v4l2_tuner *vt)
90 struct vp27smpx_state *state = to_state(sd);
92 if (!state->radio)
93 vp27smpx_set_audmode(sd, vt->audmode);
94 return 0;
97 static int vp27smpx_g_tuner(struct v4l2_subdev *sd, struct v4l2_tuner *vt)
99 struct vp27smpx_state *state = to_state(sd);
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;
110 static int vp27smpx_log_status(struct v4l2_subdev *sd)
112 struct vp27smpx_state *state = to_state(sd);
114 v4l2_info(sd, "Audio Mode: %u%s\n", state->audmode,
115 state->radio ? " (Radio)" : "");
116 return 0;
119 /* ----------------------------------------------------------------------- */
121 static const struct v4l2_subdev_core_ops vp27smpx_core_ops = {
122 .log_status = vp27smpx_log_status,
125 static const struct v4l2_subdev_tuner_ops vp27smpx_tuner_ops = {
126 .s_radio = vp27smpx_s_radio,
127 .s_tuner = vp27smpx_s_tuner,
128 .g_tuner = vp27smpx_g_tuner,
131 static const struct v4l2_subdev_video_ops vp27smpx_video_ops = {
132 .s_std = vp27smpx_s_std,
135 static const struct v4l2_subdev_ops vp27smpx_ops = {
136 .core = &vp27smpx_core_ops,
137 .tuner = &vp27smpx_tuner_ops,
138 .video = &vp27smpx_video_ops,
141 /* ----------------------------------------------------------------------- */
143 /* i2c implementation */
146 * Generic i2c probe
147 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
150 static int vp27smpx_probe(struct i2c_client *client,
151 const struct i2c_device_id *id)
153 struct vp27smpx_state *state;
154 struct v4l2_subdev *sd;
156 /* Check if the adapter supports the needed features */
157 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
158 return -EIO;
160 v4l_info(client, "chip found @ 0x%x (%s)\n",
161 client->addr << 1, client->adapter->name);
163 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
164 if (state == NULL)
165 return -ENOMEM;
166 sd = &state->sd;
167 v4l2_i2c_subdev_init(sd, client, &vp27smpx_ops);
168 state->audmode = V4L2_TUNER_MODE_STEREO;
170 /* initialize vp27smpx */
171 vp27smpx_set_audmode(sd, state->audmode);
172 return 0;
175 static int vp27smpx_remove(struct i2c_client *client)
177 struct v4l2_subdev *sd = i2c_get_clientdata(client);
179 v4l2_device_unregister_subdev(sd);
180 return 0;
183 /* ----------------------------------------------------------------------- */
185 static const struct i2c_device_id vp27smpx_id[] = {
186 { "vp27smpx", 0 },
189 MODULE_DEVICE_TABLE(i2c, vp27smpx_id);
191 static struct i2c_driver vp27smpx_driver = {
192 .driver = {
193 .name = "vp27smpx",
195 .probe = vp27smpx_probe,
196 .remove = vp27smpx_remove,
197 .id_table = vp27smpx_id,
200 module_i2c_driver(vp27smpx_driver);