aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/tea6420.c
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2008-07-25 09:31:23 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2008-10-12 07:36:47 -0400
commita832781cd383e70929c0ceece23f8a5b62e2152b (patch)
tree966f4f97ee68a0d62c59c431d7a00d63c4ac1a19 /drivers/media/video/tea6420.c
parent7d341a6a52f115512d60b2de89b2ebde54da8eff (diff)
V4L/DVB (8630): First mxb cleanup phase
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/tea6420.c')
-rw-r--r--drivers/media/video/tea6420.c147
1 files changed, 51 insertions, 96 deletions
diff --git a/drivers/media/video/tea6420.c b/drivers/media/video/tea6420.c
index b5c8957d130e..e50820969e64 100644
--- a/drivers/media/video/tea6420.c
+++ b/drivers/media/video/tea6420.c
@@ -2,6 +2,7 @@
2 tea6420 - i2c-driver for the tea6420 by SGS Thomson 2 tea6420 - i2c-driver for the tea6420 by SGS Thomson
3 3
4 Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de> 4 Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de>
5 Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
5 6
6 The tea6420 is a bus controlled audio-matrix with 5 stereo inputs, 7 The tea6420 is a bus controlled audio-matrix with 5 stereo inputs,
7 4 stereo outputs and gain control for each output. 8 4 stereo outputs and gain control for each output.
@@ -30,15 +31,18 @@
30#include <linux/module.h> 31#include <linux/module.h>
31#include <linux/ioctl.h> 32#include <linux/ioctl.h>
32#include <linux/i2c.h> 33#include <linux/i2c.h>
33 34#include <media/v4l2-common.h>
35#include <media/v4l2-i2c-drv-legacy.h>
34#include "tea6420.h" 36#include "tea6420.h"
35 37
36static int debug; /* insmod parameter */ 38MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
39MODULE_DESCRIPTION("tea6420 driver");
40MODULE_LICENSE("GPL");
41
42static int debug;
37module_param(debug, int, 0644); 43module_param(debug, int, 0644);
38MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
39 44
40#define dprintk(args...) \ 45MODULE_PARM_DESC(debug, "Debug level (0-1)");
41 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __func__, __LINE__); printk(args); } } while (0)
42 46
43/* addresses to scan, found only at 0x4c and/or 0x4d (7-Bit) */ 47/* addresses to scan, found only at 0x4c and/or 0x4d (7-Bit) */
44static unsigned short normal_i2c[] = { I2C_ADDR_TEA6420_1, I2C_ADDR_TEA6420_2, I2C_CLIENT_END }; 48static unsigned short normal_i2c[] = { I2C_ADDR_TEA6420_1, I2C_ADDR_TEA6420_2, I2C_CLIENT_END };
@@ -46,23 +50,20 @@ static unsigned short normal_i2c[] = { I2C_ADDR_TEA6420_1, I2C_ADDR_TEA6420_2, I
46/* magic definition of all other variables and things */ 50/* magic definition of all other variables and things */
47I2C_CLIENT_INSMOD; 51I2C_CLIENT_INSMOD;
48 52
49static struct i2c_driver driver;
50static struct i2c_client client_template;
51
52/* make a connection between the input 'i' and the output 'o' 53/* make a connection between the input 'i' and the output 'o'
53 with gain 'g' for the tea6420-client 'client' (note: i = 6 means 'mute') */ 54 with gain 'g' for the tea6420-client 'client' (note: i = 6 means 'mute') */
54static int tea6420_switch(struct i2c_client *client, int i, int o, int g) 55static int tea6420_switch(struct i2c_client *client, int i, int o, int g)
55{ 56{
56 u8 byte = 0; 57 u8 byte;
57 int ret; 58 int ret;
58 59
59 dprintk("adr:0x%02x, i:%d, o:%d, g:%d\n", client->addr, i, o, g); 60 v4l_dbg(1, debug, client, "i=%d, o=%d, g=%d\n", i, o, g);
60 61
61 /* check if the parameters are valid */ 62 /* check if the parameters are valid */
62 if (i < 1 || i > 6 || o < 1 || o > 4 || g < 0 || g > 6 || g % 2 != 0) 63 if (i < 1 || i > 6 || o < 1 || o > 4 || g < 0 || g > 6 || g % 2 != 0)
63 return -1; 64 return -1;
64 65
65 byte = ((o - 1) << 5); 66 byte = ((o - 1) << 5);
66 byte |= (i - 1); 67 byte |= (i - 1);
67 68
68 /* to understand this, have a look at the tea6420-specs (p.5) */ 69 /* to understand this, have a look at the tea6420-specs (p.5) */
@@ -82,40 +83,41 @@ static int tea6420_switch(struct i2c_client *client, int i, int o, int g)
82 83
83 ret = i2c_smbus_write_byte(client, byte); 84 ret = i2c_smbus_write_byte(client, byte);
84 if (ret) { 85 if (ret) {
85 dprintk("i2c_smbus_write_byte() failed, ret:%d\n", ret); 86 v4l_dbg(1, debug, client,
87 "i2c_smbus_write_byte() failed, ret:%d\n", ret);
86 return -EIO; 88 return -EIO;
87 } 89 }
88
89 return 0; 90 return 0;
90} 91}
91 92
92/* this function is called by i2c_probe */ 93static int tea6420_command(struct i2c_client *client, unsigned cmd, void *arg)
93static int tea6420_detect(struct i2c_adapter *adapter, int address, int kind)
94{ 94{
95 struct i2c_client *client; 95 struct tea6420_multiplex *a = (struct tea6420_multiplex *)arg;
96 int err = 0, i = 0; 96 int result = 0;
97 97
98 /* let's see whether this adapter can support what we need */ 98 switch (cmd) {
99 if (0 == i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE)) { 99 case TEA6420_SWITCH:
100 return 0; 100 result = tea6420_switch(client, a->in, a->out, a->gain);
101 break;
102 default:
103 return -ENOIOCTLCMD;
101 } 104 }
102 105
103 /* allocate memory for client structure */ 106 return result;
104 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); 107}
105 if (!client) {
106 return -ENOMEM;
107 }
108 108
109 /* fill client structure */ 109/* this function is called by i2c_probe */
110 memcpy(client, &client_template, sizeof(struct i2c_client)); 110static int tea6420_probe(struct i2c_client *client,
111 client->addr = address; 111 const struct i2c_device_id *id)
112 client->adapter = adapter; 112{
113 int err, i;
113 114
114 /* tell the i2c layer a new client has arrived */ 115 /* let's see whether this adapter can support what we need */
115 if (0 != (err = i2c_attach_client(client))) { 116 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_BYTE))
116 kfree(client); 117 return -EIO;
117 return err; 118
118 } 119 v4l_info(client, "chip found @ 0x%x (%s)\n",
120 client->addr << 1, client->adapter->name);
119 121
120 /* set initial values: set "mute"-input to all outputs at gain 0 */ 122 /* set initial values: set "mute"-input to all outputs at gain 0 */
121 err = 0; 123 err = 0;
@@ -123,78 +125,31 @@ static int tea6420_detect(struct i2c_adapter *adapter, int address, int kind)
123 err += tea6420_switch(client, 6, i, 0); 125 err += tea6420_switch(client, 6, i, 0);
124 } 126 }
125 if (err) { 127 if (err) {
126 dprintk("could not initialize tea6420\n"); 128 v4l_dbg(1, debug, client, "could not initialize tea6420\n");
127 kfree(client); 129 kfree(client);
128 return -ENODEV; 130 return -ENODEV;
129 } 131 }
130
131 printk("tea6420: detected @ 0x%02x on adapter %s\n", address, &client->adapter->name[0]);
132
133 return 0; 132 return 0;
134} 133}
135 134
136static int attach(struct i2c_adapter *adapter) 135static int tea6420_legacy_probe(struct i2c_adapter *adapter)
137{ 136{
138 /* let's see whether this is a know adapter we can attach to */ 137 /* Let's see whether this is a known adapter we can attach to.
139 if (adapter->id != I2C_HW_SAA7146) { 138 Prevents conflicts with tvaudio.c. */
140 dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id); 139 return adapter->id == I2C_HW_SAA7146;
141 return -ENODEV;
142 }
143
144 return i2c_probe(adapter, &addr_data, &tea6420_detect);
145}
146
147static int detach(struct i2c_client *client)
148{
149 int ret = i2c_detach_client(client);
150 kfree(client);
151 return ret;
152}
153
154static int command(struct i2c_client *client, unsigned int cmd, void *arg)
155{
156 struct tea6420_multiplex *a = (struct tea6420_multiplex *)arg;
157 int result = 0;
158
159 switch (cmd) {
160 case TEA6420_SWITCH:
161 result = tea6420_switch(client, a->in, a->out, a->gain);
162 break;
163 default:
164 return -ENOIOCTLCMD;
165 }
166
167 return result;
168} 140}
169 141
170static struct i2c_driver driver = { 142static const struct i2c_device_id tea6420_id[] = {
171 .driver = { 143 { "tea6420", 0 },
172 .name = "tea6420", 144 { }
173 },
174 .id = I2C_DRIVERID_TEA6420,
175 .attach_adapter = attach,
176 .detach_client = detach,
177 .command = command,
178}; 145};
146MODULE_DEVICE_TABLE(i2c, tea6420_id);
179 147
180static struct i2c_client client_template = { 148static struct v4l2_i2c_driver_data v4l2_i2c_data = {
181 .name = "tea6420", 149 .name = "tea6420",
182 .driver = &driver, 150 .driverid = I2C_DRIVERID_TEA6420,
151 .command = tea6420_command,
152 .probe = tea6420_probe,
153 .legacy_probe = tea6420_legacy_probe,
154 .id_table = tea6420_id,
183}; 155};
184
185static int __init this_module_init(void)
186{
187 return i2c_add_driver(&driver);
188}
189
190static void __exit this_module_exit(void)
191{
192 i2c_del_driver(&driver);
193}
194
195module_init(this_module_init);
196module_exit(this_module_exit);
197
198MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
199MODULE_DESCRIPTION("tea6420 driver");
200MODULE_LICENSE("GPL");