aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/video/wm8775.c
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2007-09-13 10:08:25 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-01-25 16:01:18 -0500
commitd9a53aa9024e507df01f257494956e906a92c864 (patch)
tree3f38a586237c437d5c89f466917c0daaa551b32d /drivers/media/video/wm8775.c
parent8ffbc6559493c64d6194c92d856196fdaeb8a5fb (diff)
V4L/DVB (6452): wm8775: convert to bus-based I2C API
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Mauro Carvalho Chehab <mchehab@infradead.org>
Diffstat (limited to 'drivers/media/video/wm8775.c')
-rw-r--r--drivers/media/video/wm8775.c78
1 files changed, 15 insertions, 63 deletions
diff --git a/drivers/media/video/wm8775.c b/drivers/media/video/wm8775.c
index 9f7e894ef962..c31a0c34b08b 100644
--- a/drivers/media/video/wm8775.c
+++ b/drivers/media/video/wm8775.c
@@ -34,6 +34,7 @@
34#include <linux/videodev.h> 34#include <linux/videodev.h>
35#include <media/v4l2-common.h> 35#include <media/v4l2-common.h>
36#include <media/v4l2-chip-ident.h> 36#include <media/v4l2-chip-ident.h>
37#include <media/v4l2-i2c-drv-legacy.h>
37 38
38MODULE_DESCRIPTION("wm8775 driver"); 39MODULE_DESCRIPTION("wm8775 driver");
39MODULE_AUTHOR("Ulf Eklund, Hans Verkuil"); 40MODULE_AUTHOR("Ulf Eklund, Hans Verkuil");
@@ -44,6 +45,7 @@ static unsigned short normal_i2c[] = { 0x36 >> 1, I2C_CLIENT_END };
44 45
45I2C_CLIENT_INSMOD; 46I2C_CLIENT_INSMOD;
46 47
48
47/* ----------------------------------------------------------------------- */ 49/* ----------------------------------------------------------------------- */
48 50
49enum { 51enum {
@@ -76,8 +78,7 @@ static int wm8775_write(struct i2c_client *client, int reg, u16 val)
76 return -1; 78 return -1;
77} 79}
78 80
79static int wm8775_command(struct i2c_client *client, unsigned int cmd, 81static int wm8775_command(struct i2c_client *client, unsigned int cmd, void *arg)
80 void *arg)
81{ 82{
82 struct wm8775_state *state = i2c_get_clientdata(client); 83 struct wm8775_state *state = i2c_get_clientdata(client);
83 struct v4l2_routing *route = arg; 84 struct v4l2_routing *route = arg;
@@ -159,31 +160,18 @@ static int wm8775_command(struct i2c_client *client, unsigned int cmd,
159 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' 160 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
160 */ 161 */
161 162
162static struct i2c_driver i2c_driver; 163static int wm8775_probe(struct i2c_client *client)
163
164static int wm8775_attach(struct i2c_adapter *adapter, int address, int kind)
165{ 164{
166 struct i2c_client *client;
167 struct wm8775_state *state; 165 struct wm8775_state *state;
168 166
169 /* Check if the adapter supports the needed features */ 167 /* Check if the adapter supports the needed features */
170 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 168 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
171 return 0; 169 return -EIO;
172
173 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
174 if (client == 0)
175 return -ENOMEM;
176
177 client->addr = address;
178 client->adapter = adapter;
179 client->driver = &i2c_driver;
180 snprintf(client->name, sizeof(client->name) - 1, "wm8775");
181 170
182 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name); 171 v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name);
183 172
184 state = kmalloc(sizeof(struct wm8775_state), GFP_KERNEL); 173 state = kmalloc(sizeof(struct wm8775_state), GFP_KERNEL);
185 if (state == NULL) { 174 if (state == NULL) {
186 kfree(client);
187 return -ENOMEM; 175 return -ENOMEM;
188 } 176 }
189 state->input = 2; 177 state->input = 2;
@@ -208,56 +196,20 @@ static int wm8775_attach(struct i2c_adapter *adapter, int address, int kind)
208 wm8775_write(client, R20, 0x07a); /* Transient window 4ms, lower PGA gain */ 196 wm8775_write(client, R20, 0x07a); /* Transient window 4ms, lower PGA gain */
209 /* limit -1dB */ 197 /* limit -1dB */
210 wm8775_write(client, R21, 0x102); /* LRBOTH = 1, use input 2. */ 198 wm8775_write(client, R21, 0x102); /* LRBOTH = 1, use input 2. */
211 i2c_attach_client(client);
212
213 return 0; 199 return 0;
214} 200}
215 201
216static int wm8775_probe(struct i2c_adapter *adapter) 202static int wm8775_remove(struct i2c_client *client)
217{ 203{
218 if (adapter->class & I2C_CLASS_TV_ANALOG) 204 kfree(i2c_get_clientdata(client));
219 return i2c_probe(adapter, &addr_data, wm8775_attach);
220 return 0;
221}
222
223static int wm8775_detach(struct i2c_client *client)
224{
225 struct wm8775_state *state = i2c_get_clientdata(client);
226 int err;
227
228 err = i2c_detach_client(client);
229 if (err) {
230 return err;
231 }
232 kfree(state);
233 kfree(client);
234
235 return 0; 205 return 0;
236} 206}
237 207
238/* ----------------------------------------------------------------------- */ 208static struct v4l2_i2c_driver_data v4l2_i2c_data = {
239 209 .name = "wm8775",
240/* i2c implementation */ 210 .driverid = I2C_DRIVERID_WM8775,
241static struct i2c_driver i2c_driver = { 211 .command = wm8775_command,
242 .driver = { 212 .probe = wm8775_probe,
243 .name = "wm8775", 213 .remove = wm8775_remove,
244 },
245 .id = I2C_DRIVERID_WM8775,
246 .attach_adapter = wm8775_probe,
247 .detach_client = wm8775_detach,
248 .command = wm8775_command,
249}; 214};
250 215
251
252static int __init wm8775_init_module(void)
253{
254 return i2c_add_driver(&i2c_driver);
255}
256
257static void __exit wm8775_cleanup_module(void)
258{
259 i2c_del_driver(&i2c_driver);
260}
261
262module_init(wm8775_init_module);
263module_exit(wm8775_cleanup_module);