aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--drivers/media/video/Kconfig10
-rw-r--r--drivers/media/video/Makefile1
-rw-r--r--drivers/media/video/cs5345.c168
-rw-r--r--include/media/cs5345.h39
-rw-r--r--include/media/v4l2-chip-ident.h3
5 files changed, 221 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
diff --git a/include/media/cs5345.h b/include/media/cs5345.h
new file mode 100644
index 000000000000..6ccae24e65ed
--- /dev/null
+++ b/include/media/cs5345.h
@@ -0,0 +1,39 @@
1/*
2 cs5345.h - definition for cs5345 inputs and outputs
3
4 Copyright (C) 2007 Hans Verkuil (hverkuil@xs4all.nl)
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#ifndef _CS5345_H_
22#define _CS5345_H_
23
24/* CS5345 HW inputs */
25#define CS5345_IN_MIC 0
26#define CS5345_IN_1 1
27#define CS5345_IN_2 2
28#define CS5345_IN_3 3
29#define CS5345_IN_4 4
30#define CS5345_IN_5 5
31#define CS5345_IN_6 6
32
33#define CS5345_MCLK_1 0x00
34#define CS5345_MCLK_1_5 0x10
35#define CS5345_MCLK_2 0x20
36#define CS5345_MCLK_3 0x30
37#define CS5345_MCLK_4 0x40
38
39#endif
diff --git a/include/media/v4l2-chip-ident.h b/include/media/v4l2-chip-ident.h
index 2442c281e4fe..032bb75f69c2 100644
--- a/include/media/v4l2-chip-ident.h
+++ b/include/media/v4l2-chip-ident.h
@@ -68,6 +68,9 @@ enum {
68 /* module vp27smpx: just ident 2700 */ 68 /* module vp27smpx: just ident 2700 */
69 V4L2_IDENT_VP27SMPX = 2700, 69 V4L2_IDENT_VP27SMPX = 2700,
70 70
71 /* module cs5345: just ident 5345 */
72 V4L2_IDENT_CS5345 = 5345,
73
71 /* module wm8739: just ident 8739 */ 74 /* module wm8739: just ident 8739 */
72 V4L2_IDENT_WM8739 = 8739, 75 V4L2_IDENT_WM8739 = 8739,
73 76