aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/cs53l32a.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/media/video/cs53l32a.c')
-rw-r--r--drivers/media/video/cs53l32a.c92
1 files changed, 41 insertions, 51 deletions
diff --git a/drivers/media/video/cs53l32a.c b/drivers/media/video/cs53l32a.c
index 643ead1a87ee..b421068f7ea3 100644
--- a/drivers/media/video/cs53l32a.c
+++ b/drivers/media/video/cs53l32a.c
@@ -27,7 +27,7 @@
27#include <linux/i2c.h> 27#include <linux/i2c.h>
28#include <linux/i2c-id.h> 28#include <linux/i2c-id.h>
29#include <linux/videodev.h> 29#include <linux/videodev.h>
30#include <media/audiochip.h> 30#include <media/v4l2-common.h>
31 31
32MODULE_DESCRIPTION("i2c device driver for cs53l32a Audio ADC"); 32MODULE_DESCRIPTION("i2c device driver for cs53l32a Audio ADC");
33MODULE_AUTHOR("Martin Vaughan"); 33MODULE_AUTHOR("Martin Vaughan");
@@ -39,21 +39,6 @@ module_param(debug, bool, 0644);
39 39
40MODULE_PARM_DESC(debug, "Debugging messages\n\t\t\t0=Off (default), 1=On"); 40MODULE_PARM_DESC(debug, "Debugging messages\n\t\t\t0=Off (default), 1=On");
41 41
42#define cs53l32a_dbg(fmt, arg...) \
43 do { \
44 if (debug) \
45 printk(KERN_INFO "%s debug %d-%04x: " fmt, \
46 client->driver->driver.name, \
47 i2c_adapter_id(client->adapter), client->addr , ## arg); \
48 } while (0)
49
50#define cs53l32a_err(fmt, arg...) do { \
51 printk(KERN_ERR "%s %d-%04x: " fmt, client->driver->driver.name, \
52 i2c_adapter_id(client->adapter), client->addr , ## arg); } while (0)
53#define cs53l32a_info(fmt, arg...) do { \
54 printk(KERN_INFO "%s %d-%04x: " fmt, client->driver->driver.name, \
55 i2c_adapter_id(client->adapter), client->addr , ## arg); } while (0)
56
57static unsigned short normal_i2c[] = { 0x22 >> 1, I2C_CLIENT_END }; 42static unsigned short normal_i2c[] = { 0x22 >> 1, I2C_CLIENT_END };
58 43
59 44
@@ -74,50 +59,59 @@ static int cs53l32a_read(struct i2c_client *client, u8 reg)
74static int cs53l32a_command(struct i2c_client *client, unsigned int cmd, 59static int cs53l32a_command(struct i2c_client *client, unsigned int cmd,
75 void *arg) 60 void *arg)
76{ 61{
77 int *input = arg; 62 struct v4l2_audio *input = arg;
63 struct v4l2_control *ctrl = arg;
78 64
79 switch (cmd) { 65 switch (cmd) {
80 case AUDC_SET_INPUT: 66 case VIDIOC_S_AUDIO:
81 switch (*input) { 67 /* There are 2 physical inputs, but the second input can be
82 case AUDIO_TUNER: 68 placed in two modes, the first mode bypasses the PGA (gain),
83 cs53l32a_write(client, 0x01, 0x01); 69 the second goes through the PGA. Hence there are three
84 break; 70 possible inputs to choose from. */
85 case AUDIO_EXTERN: 71 if (input->index > 2) {
86 cs53l32a_write(client, 0x01, 0x21); 72 v4l_err(client, "Invalid input %d.\n", input->index);
87 break;
88 case AUDIO_MUTE:
89 cs53l32a_write(client, 0x03, 0xF0);
90 break;
91 case AUDIO_UNMUTE:
92 cs53l32a_write(client, 0x03, 0x30);
93 break;
94 default:
95 cs53l32a_err("Invalid input %d.\n", *input);
96 return -EINVAL; 73 return -EINVAL;
97 } 74 }
75 cs53l32a_write(client, 0x01, 0x01 + (input->index << 4));
76 break;
77
78 case VIDIOC_G_AUDIO:
79 memset(input, 0, sizeof(*input));
80 input->index = (cs53l32a_read(client, 0x01) >> 4) & 3;
81 break;
82
83 case VIDIOC_G_CTRL:
84 if (ctrl->id == V4L2_CID_AUDIO_MUTE) {
85 ctrl->value = (cs53l32a_read(client, 0x03) & 0xc0) != 0;
86 break;
87 }
88 if (ctrl->id != V4L2_CID_AUDIO_VOLUME)
89 return -EINVAL;
90 ctrl->value = (s8)cs53l32a_read(client, 0x04);
98 break; 91 break;
99 92
100 case VIDIOC_S_CTRL: 93 case VIDIOC_S_CTRL:
101 { 94 if (ctrl->id == V4L2_CID_AUDIO_MUTE) {
102 struct v4l2_control *ctrl = arg; 95 cs53l32a_write(client, 0x03, ctrl->value ? 0xf0 : 0x30);
103
104 if (ctrl->id != V4L2_CID_AUDIO_VOLUME)
105 return -EINVAL;
106 if (ctrl->value > 12 || ctrl->value < -90)
107 return -EINVAL;
108 cs53l32a_write(client, 0x04, (u8) ctrl->value);
109 cs53l32a_write(client, 0x05, (u8) ctrl->value);
110 break; 96 break;
111 } 97 }
98 if (ctrl->id != V4L2_CID_AUDIO_VOLUME)
99 return -EINVAL;
100 if (ctrl->value > 12 || ctrl->value < -96)
101 return -EINVAL;
102 cs53l32a_write(client, 0x04, (u8) ctrl->value);
103 cs53l32a_write(client, 0x05, (u8) ctrl->value);
104 break;
112 105
113 case VIDIOC_LOG_STATUS: 106 case VIDIOC_LOG_STATUS:
114 { 107 {
115 u8 v = cs53l32a_read(client, 0x01); 108 u8 v = cs53l32a_read(client, 0x01);
116 u8 m = cs53l32a_read(client, 0x03); 109 u8 m = cs53l32a_read(client, 0x03);
110 s8 vol = cs53l32a_read(client, 0x04);
117 111
118 cs53l32a_info("Input: %s%s\n", 112 v4l_info(client, "Input: %d%s\n", (v >> 4) & 3,
119 v == 0x21 ? "external line in" : "tuner",
120 (m & 0xC0) ? " (muted)" : ""); 113 (m & 0xC0) ? " (muted)" : "");
114 v4l_info(client, "Volume: %d dB\n", vol);
121 break; 115 break;
122 } 116 }
123 117
@@ -157,12 +151,12 @@ static int cs53l32a_attach(struct i2c_adapter *adapter, int address, int kind)
157 client->driver = &i2c_driver; 151 client->driver = &i2c_driver;
158 snprintf(client->name, sizeof(client->name) - 1, "cs53l32a"); 152 snprintf(client->name, sizeof(client->name) - 1, "cs53l32a");
159 153
160 cs53l32a_info("chip found @ 0x%x (%s)\n", address << 1, adapter->name); 154 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name);
161 155
162 for (i = 1; i <= 7; i++) { 156 for (i = 1; i <= 7; i++) {
163 u8 v = cs53l32a_read(client, i); 157 u8 v = cs53l32a_read(client, i);
164 158
165 cs53l32a_dbg("Read Reg %d %02x\n", i, v); 159 v4l_dbg(1, client, "Read Reg %d %02x\n", i, v);
166 } 160 }
167 161
168 /* Set cs53l32a internal register for Adaptec 2010/2410 setup */ 162 /* Set cs53l32a internal register for Adaptec 2010/2410 setup */
@@ -180,7 +174,7 @@ static int cs53l32a_attach(struct i2c_adapter *adapter, int address, int kind)
180 for (i = 1; i <= 7; i++) { 174 for (i = 1; i <= 7; i++) {
181 u8 v = cs53l32a_read(client, i); 175 u8 v = cs53l32a_read(client, i);
182 176
183 cs53l32a_dbg("Read Reg %d %02x\n", i, v); 177 v4l_dbg(1, client, "Read Reg %d %02x\n", i, v);
184 } 178 }
185 179
186 i2c_attach_client(client); 180 i2c_attach_client(client);
@@ -190,11 +184,7 @@ static int cs53l32a_attach(struct i2c_adapter *adapter, int address, int kind)
190 184
191static int cs53l32a_probe(struct i2c_adapter *adapter) 185static int cs53l32a_probe(struct i2c_adapter *adapter)
192{ 186{
193#ifdef I2C_CLASS_TV_ANALOG
194 if (adapter->class & I2C_CLASS_TV_ANALOG) 187 if (adapter->class & I2C_CLASS_TV_ANALOG)
195#else
196 if (adapter->id == I2C_HW_B_BT848)
197#endif
198 return i2c_probe(adapter, &addr_data, cs53l32a_attach); 188 return i2c_probe(adapter, &addr_data, cs53l32a_attach);
199 return 0; 189 return 0;
200} 190}