1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * vp27smpx - driver version 0.0.1
5 * Copyright (C) 2007 Hans Verkuil <hverkuil@xs4all.nl>
7 * Based on a tvaudio patch from Takahiro Adachi <tadachi@tadachi-net.com>
8 * and Kazuhiko Kawakami <kazz-0@mail.goo.ne.jp>
11 #include <linux/module.h>
12 #include <linux/types.h>
13 #include <linux/slab.h>
14 #include <linux/ioctl.h>
15 #include <linux/uaccess.h>
16 #include <linux/i2c.h>
17 #include <linux/videodev2.h>
18 #include <media/v4l2-device.h>
20 MODULE_DESCRIPTION("vp27smpx driver");
21 MODULE_AUTHOR("Hans Verkuil");
22 MODULE_LICENSE("GPL");
25 /* ----------------------------------------------------------------------- */
27 struct vp27smpx_state
{
28 struct v4l2_subdev sd
;
33 static inline struct vp27smpx_state
*to_state(struct v4l2_subdev
*sd
)
35 return container_of(sd
, struct vp27smpx_state
, sd
);
38 static void vp27smpx_set_audmode(struct v4l2_subdev
*sd
, u32 audmode
)
40 struct vp27smpx_state
*state
= to_state(sd
);
41 struct i2c_client
*client
= v4l2_get_subdevdata(sd
);
42 u8 data
[3] = { 0x00, 0x00, 0x04 };
45 case V4L2_TUNER_MODE_MONO
:
46 case V4L2_TUNER_MODE_LANG1
:
48 case V4L2_TUNER_MODE_STEREO
:
49 case V4L2_TUNER_MODE_LANG1_LANG2
:
52 case V4L2_TUNER_MODE_LANG2
:
57 if (i2c_master_send(client
, data
, sizeof(data
)) != sizeof(data
))
58 v4l2_err(sd
, "I/O error setting audmode\n");
60 state
->audmode
= audmode
;
63 static int vp27smpx_s_radio(struct v4l2_subdev
*sd
)
65 struct vp27smpx_state
*state
= to_state(sd
);
71 static int vp27smpx_s_std(struct v4l2_subdev
*sd
, v4l2_std_id norm
)
73 struct vp27smpx_state
*state
= to_state(sd
);
79 static int vp27smpx_s_tuner(struct v4l2_subdev
*sd
, const struct v4l2_tuner
*vt
)
81 struct vp27smpx_state
*state
= to_state(sd
);
84 vp27smpx_set_audmode(sd
, vt
->audmode
);
88 static int vp27smpx_g_tuner(struct v4l2_subdev
*sd
, struct v4l2_tuner
*vt
)
90 struct vp27smpx_state
*state
= to_state(sd
);
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
;
101 static int vp27smpx_log_status(struct v4l2_subdev
*sd
)
103 struct vp27smpx_state
*state
= to_state(sd
);
105 v4l2_info(sd
, "Audio Mode: %u%s\n", state
->audmode
,
106 state
->radio
? " (Radio)" : "");
110 /* ----------------------------------------------------------------------- */
112 static const struct v4l2_subdev_core_ops vp27smpx_core_ops
= {
113 .log_status
= vp27smpx_log_status
,
116 static const struct v4l2_subdev_tuner_ops vp27smpx_tuner_ops
= {
117 .s_radio
= vp27smpx_s_radio
,
118 .s_tuner
= vp27smpx_s_tuner
,
119 .g_tuner
= vp27smpx_g_tuner
,
122 static const struct v4l2_subdev_video_ops vp27smpx_video_ops
= {
123 .s_std
= vp27smpx_s_std
,
126 static const struct v4l2_subdev_ops vp27smpx_ops
= {
127 .core
= &vp27smpx_core_ops
,
128 .tuner
= &vp27smpx_tuner_ops
,
129 .video
= &vp27smpx_video_ops
,
132 /* ----------------------------------------------------------------------- */
134 /* i2c implementation */
138 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
141 static int vp27smpx_probe(struct i2c_client
*client
,
142 const struct i2c_device_id
*id
)
144 struct vp27smpx_state
*state
;
145 struct v4l2_subdev
*sd
;
147 /* Check if the adapter supports the needed features */
148 if (!i2c_check_functionality(client
->adapter
, I2C_FUNC_SMBUS_BYTE_DATA
))
151 v4l_info(client
, "chip found @ 0x%x (%s)\n",
152 client
->addr
<< 1, client
->adapter
->name
);
154 state
= devm_kzalloc(&client
->dev
, sizeof(*state
), GFP_KERNEL
);
158 v4l2_i2c_subdev_init(sd
, client
, &vp27smpx_ops
);
159 state
->audmode
= V4L2_TUNER_MODE_STEREO
;
161 /* initialize vp27smpx */
162 vp27smpx_set_audmode(sd
, state
->audmode
);
166 static int vp27smpx_remove(struct i2c_client
*client
)
168 struct v4l2_subdev
*sd
= i2c_get_clientdata(client
);
170 v4l2_device_unregister_subdev(sd
);
174 /* ----------------------------------------------------------------------- */
176 static const struct i2c_device_id vp27smpx_id
[] = {
180 MODULE_DEVICE_TABLE(i2c
, vp27smpx_id
);
182 static struct i2c_driver vp27smpx_driver
= {
186 .probe
= vp27smpx_probe
,
187 .remove
= vp27smpx_remove
,
188 .id_table
= vp27smpx_id
,
191 module_i2c_driver(vp27smpx_driver
);