aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2007-12-18 17:40:44 -0500
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-01-25 16:04:08 -0500
commit6fb377f85cb8c2c1580ce8b134c887a7b53c7aa9 (patch)
treeb3f840769f841790797d918a36154ec8cda20113 /drivers
parent0b394def21e7d3bd02aeee5570473582ce7984ec (diff)
V4L/DVB (6869): cs5345: new i2c driver
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/Kconfig10
-rw-r--r--drivers/media/video/Makefile1
-rw-r--r--drivers/media/video/cs5345.c168
3 files changed, 179 insertions, 0 deletions
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 6c7835629bcd..7431f6da5cae 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -109,6 +109,16 @@ config VIDEO_MSP3400
109 To compile this driver as a module, choose M here: the 109 To compile this driver as a module, choose M here: the
110 module will be called msp3400. 110 module will be called msp3400.
111 111
112config VIDEO_CS5345
113 tristate "Cirrus Logic CS5345 audio ADC"
114 depends on VIDEO_V4L2 && I2C && EXPERIMENTAL
115 ---help---
116 Support for the Cirrus Logic CS5345 24-bit, 192 kHz
117 stereo A/D converter.
118
119 To compile this driver as a module, choose M here: the
120 module will be called cs5345.
121
112config VIDEO_CS53L32A 122config VIDEO_CS53L32A
113 tristate "Cirrus Logic CS53L32A audio ADC" 123 tristate "Cirrus Logic CS53L32A audio ADC"
114 depends on VIDEO_V4L2 && I2C 124 depends on VIDEO_V4L2 && I2C
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index a837e1ea518f..74a2a1c45fe3 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -66,6 +66,7 @@ obj-$(CONFIG_VIDEO_USBVISION) += usbvision/
66obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o 66obj-$(CONFIG_VIDEO_TVP5150) += tvp5150.o
67obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/ 67obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2/
68obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o 68obj-$(CONFIG_VIDEO_MSP3400) += msp3400.o
69obj-$(CONFIG_VIDEO_CS5345) += cs5345.o
69obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o 70obj-$(CONFIG_VIDEO_CS53L32A) += cs53l32a.o
70obj-$(CONFIG_VIDEO_M52790) += m52790.o 71obj-$(CONFIG_VIDEO_M52790) += m52790.o
71obj-$(CONFIG_VIDEO_TLV320AIC23B) += tlv320aic23b.o 72obj-$(CONFIG_VIDEO_TLV320AIC23B) += tlv320aic23b.o
diff --git a/drivers/media/video/cs5345.c b/drivers/media/video/cs5345.c
new file mode 100644
index 000000000000..fae469ce16f5
--- /dev/null
+++ b/drivers/media/video/cs5345.c
@@ -0,0 +1,168 @@
1/*
2 * cs5345 Cirrus Logic 24-bit, 192 kHz Stereo Audio ADC
3 * Copyright (C) 2007 Hans Verkuil
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20
21#include <linux/version.h>
22#include <linux/module.h>
23#include <linux/kernel.h>
24#include <linux/i2c.h>
25#include <linux/videodev2.h>
26#include <media/v4l2-i2c-drv.h>
27#include <media/v4l2-common.h>
28#include <media/v4l2-chip-ident.h>
29
30MODULE_DESCRIPTION("i2c device driver for cs5345 Audio ADC");
31MODULE_AUTHOR("Hans Verkuil");
32MODULE_LICENSE("GPL");
33
34static int debug;
35
36module_param(debug, bool, 0644);
37
38MODULE_PARM_DESC(debug, "Debugging messages\n\t\t\t0=Off (default), 1=On");
39
40
41/* ----------------------------------------------------------------------- */
42
43static inline int cs5345_write(struct i2c_client *client, u8 reg, u8 value)
44{
45 return i2c_smbus_write_byte_data(client, reg, value);
46}
47
48static inline int cs5345_read(struct i2c_client *client, u8 reg)
49{
50 return i2c_smbus_read_byte_data(client, reg);
51}
52
53static int cs5345_command(struct i2c_client *client, unsigned cmd, void *arg)
54{
55 struct v4l2_routing *route = arg;
56 struct v4l2_control *ctrl = arg;
57
58 switch (cmd) {
59 case VIDIOC_INT_G_AUDIO_ROUTING:
60 route->input = cs5345_read(client, 0x09) & 7;
61 route->input |= cs5345_read(client, 0x05) & 0x70;
62 route->output = 0;
63 break;
64
65 case VIDIOC_INT_S_AUDIO_ROUTING:
66 if ((route->input & 0xf) > 6) {
67 v4l_err(client, "Invalid input %d.\n", route->input);
68 return -EINVAL;
69 }
70 cs5345_write(client, 0x09, route->input & 0xf);
71 cs5345_write(client, 0x05, route->input & 0xf0);
72 break;
73
74 case VIDIOC_G_CTRL:
75 if (ctrl->id == V4L2_CID_AUDIO_MUTE) {
76 ctrl->value = (cs5345_read(client, 0x04) & 0x08) != 0;
77 break;
78 }
79 if (ctrl->id != V4L2_CID_AUDIO_VOLUME)
80 return -EINVAL;
81 ctrl->value = cs5345_read(client, 0x07) & 0x3f;
82 if (ctrl->value >= 32)
83 ctrl->value = ctrl->value - 64;
84 break;
85
86 case VIDIOC_S_CTRL:
87 break;
88 if (ctrl->id == V4L2_CID_AUDIO_MUTE) {
89 cs5345_write(client, 0x04, ctrl->value ? 0x80 : 0);
90 break;
91 }
92 if (ctrl->id != V4L2_CID_AUDIO_VOLUME)
93 return -EINVAL;
94 if (ctrl->value > 24 || ctrl->value < -24)
95 return -EINVAL;
96 cs5345_write(client, 0x07, ((u8)ctrl->value) & 0x3f);
97 cs5345_write(client, 0x08, ((u8)ctrl->value) & 0x3f);
98 break;
99
100#ifdef CONFIG_VIDEO_ADV_DEBUG
101 case VIDIOC_DBG_G_REGISTER:
102 case VIDIOC_DBG_S_REGISTER:
103 {
104 struct v4l2_register *reg = arg;
105
106 if (!v4l2_chip_match_i2c_client(client,
107 reg->match_type, reg->match_chip))
108 return -EINVAL;
109 if (!capable(CAP_SYS_ADMIN))
110 return -EPERM;
111 if (cmd == VIDIOC_DBG_G_REGISTER)
112 reg->val = cs5345_read(client, reg->reg & 0x1f);
113 else
114 cs5345_write(client, reg->reg & 0x1f, reg->val & 0x1f);
115 break;
116 }
117#endif
118
119 case VIDIOC_G_CHIP_IDENT:
120 return v4l2_chip_ident_i2c_client(client,
121 arg, V4L2_IDENT_CS5345, 0);
122
123 case VIDIOC_LOG_STATUS:
124 {
125 u8 v = cs5345_read(client, 0x09) & 7;
126 u8 m = cs5345_read(client, 0x04);
127 int vol = cs5345_read(client, 0x08) & 0x3f;
128
129 v4l_info(client, "Input: %d%s\n", v,
130 (m & 0x80) ? " (muted)" : "");
131 if (vol >= 32)
132 vol = vol - 64;
133 v4l_info(client, "Volume: %d dB\n", vol);
134 break;
135 }
136
137 default:
138 return -EINVAL;
139 }
140 return 0;
141}
142
143/* ----------------------------------------------------------------------- */
144
145static int cs5345_probe(struct i2c_client *client)
146{
147 /* Check if the adapter supports the needed features */
148 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
149 return -EIO;
150
151 v4l_info(client, "chip found @ 0x%x (%s)\n",
152 client->addr << 1, client->adapter->name);
153
154 cs5345_write(client, 0x02, 0x00);
155 cs5345_write(client, 0x04, 0x01);
156 cs5345_write(client, 0x09, 0x01);
157 return 0;
158}
159
160/* ----------------------------------------------------------------------- */
161
162static struct v4l2_i2c_driver_data v4l2_i2c_data = {
163 .name = "cs5345",
164 .driverid = I2C_DRIVERID_CS5345,
165 .command = cs5345_command,
166 .probe = cs5345_probe,
167};
168