aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorHans Verkuil <hverkuil@xs4all.nl>2007-09-14 03:58:31 -0400
committerMauro Carvalho Chehab <mchehab@infradead.org>2008-01-25 16:01:26 -0500
commit2b14e0314631bac6388c4501f3103ab5af22c0f0 (patch)
tree73260e1fe18d893e0e697b7e5a1f5773f0e3a604 /drivers
parent266669776c12b92bab6e0bba4b3124ae920df194 (diff)
V4L/DVB (6463): upd64031a: 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')
-rw-r--r--drivers/media/video/upd64031a.c69
1 files changed, 12 insertions, 57 deletions
diff --git a/drivers/media/video/upd64031a.c b/drivers/media/video/upd64031a.c
index 0b2a961efd22..b060ce34071c 100644
--- a/drivers/media/video/upd64031a.c
+++ b/drivers/media/video/upd64031a.c
@@ -28,6 +28,7 @@
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29#include <media/v4l2-common.h> 29#include <media/v4l2-common.h>
30#include <media/v4l2-chip-ident.h> 30#include <media/v4l2-chip-ident.h>
31#include <media/v4l2-i2c-drv-legacy.h>
31#include <media/upd64031a.h> 32#include <media/upd64031a.h>
32 33
33// --------------------- read registers functions define ----------------------- 34// --------------------- read registers functions define -----------------------
@@ -193,32 +194,18 @@ static int upd64031a_command(struct i2c_client *client, unsigned int cmd, void *
193 194
194/* i2c implementation */ 195/* i2c implementation */
195 196
196static struct i2c_driver i2c_driver; 197static int upd64031a_probe(struct i2c_client *client)
197
198static int upd64031a_attach(struct i2c_adapter *adapter, int address, int kind)
199{ 198{
200 struct i2c_client *client;
201 struct upd64031a_state *state; 199 struct upd64031a_state *state;
202 int i; 200 int i;
203 201
204 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) 202 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
205 return 0; 203 return 0;
206 204
207 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL); 205 v4l_info(client, "chip found @ 0x%x (%s)\n", client->addr << 1, client->adapter->name);
208 if (client == NULL) {
209 return -ENOMEM;
210 }
211
212 client->addr = address;
213 client->adapter = adapter;
214 client->driver = &i2c_driver;
215 snprintf(client->name, sizeof(client->name) - 1, "uPD64031A");
216
217 v4l_info(client, "chip found @ 0x%x (%s)\n", address << 1, adapter->name);
218 206
219 state = kmalloc(sizeof(struct upd64031a_state), GFP_KERNEL); 207 state = kmalloc(sizeof(struct upd64031a_state), GFP_KERNEL);
220 if (state == NULL) { 208 if (state == NULL) {
221 kfree(client);
222 return -ENOMEM; 209 return -ENOMEM;
223 } 210 }
224 i2c_set_clientdata(client, state); 211 i2c_set_clientdata(client, state);
@@ -229,54 +216,22 @@ static int upd64031a_attach(struct i2c_adapter *adapter, int address, int kind)
229 for (i = 0; i < TOT_REGS; i++) { 216 for (i = 0; i < TOT_REGS; i++) {
230 upd64031a_write(client, i, state->regs[i]); 217 upd64031a_write(client, i, state->regs[i]);
231 } 218 }
232
233 i2c_attach_client(client);
234
235 return 0; 219 return 0;
236} 220}
237 221
238static int upd64031a_probe(struct i2c_adapter *adapter) 222static int upd64031a_remove(struct i2c_client *client)
239{ 223{
240 if (adapter->class & I2C_CLASS_TV_ANALOG) 224 kfree(i2c_get_clientdata(client));
241 return i2c_probe(adapter, &addr_data, upd64031a_attach);
242 return 0;
243}
244
245static int upd64031a_detach(struct i2c_client *client)
246{
247 int err;
248
249 err = i2c_detach_client(client);
250 if (err)
251 return err;
252
253 kfree(client);
254 return 0; 225 return 0;
255} 226}
256 227
257/* ----------------------------------------------------------------------- */ 228/* ----------------------------------------------------------------------- */
258 229
259/* i2c implementation */ 230
260static struct i2c_driver i2c_driver = { 231static struct v4l2_i2c_driver_data v4l2_i2c_data = {
261 .driver = { 232 .name = "upd64031a",
262 .name = "upd64031a", 233 .driverid = I2C_DRIVERID_UPD64031A,
263 },
264 .id = I2C_DRIVERID_UPD64031A,
265 .attach_adapter = upd64031a_probe,
266 .detach_client = upd64031a_detach,
267 .command = upd64031a_command, 234 .command = upd64031a_command,
235 .probe = upd64031a_probe,
236 .remove = upd64031a_remove,
268}; 237};
269
270
271static int __init upd64031a_init_module(void)
272{
273 return i2c_add_driver(&i2c_driver);
274}
275
276static void __exit upd64031a_exit_module(void)
277{
278 i2c_del_driver(&i2c_driver);
279}
280
281module_init(upd64031a_init_module);
282module_exit(upd64031a_exit_module);