diff options
author | Hans Verkuil <hverkuil@xs4all.nl> | 2009-02-11 17:23:57 -0500 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-03-30 11:42:45 -0400 |
commit | c3fda7f835b025f3c020fa0865086fd23609e7ca (patch) | |
tree | 9318c496d0ed8607a93a1077199fca9580487094 /drivers/media/video/saa6588.c | |
parent | b5ffc223e48417c2db0a4ce1beacdbab6503a472 (diff) |
V4L/DVB (10537): saa6588: convert to v4l2_subdev.
Signed-off-by: Hans Verkuil <hverkuil@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/saa6588.c')
-rw-r--r-- | drivers/media/video/saa6588.c | 115 |
1 files changed, 71 insertions, 44 deletions
diff --git a/drivers/media/video/saa6588.c b/drivers/media/video/saa6588.c index 7c74ac4dd183..4d31c320ac17 100644 --- a/drivers/media/video/saa6588.c +++ b/drivers/media/video/saa6588.c | |||
@@ -32,7 +32,7 @@ | |||
32 | #include <asm/uaccess.h> | 32 | #include <asm/uaccess.h> |
33 | 33 | ||
34 | #include <media/rds.h> | 34 | #include <media/rds.h> |
35 | #include <media/v4l2-common.h> | 35 | #include <media/v4l2-device.h> |
36 | #include <media/v4l2-i2c-drv-legacy.h> | 36 | #include <media/v4l2-i2c-drv-legacy.h> |
37 | 37 | ||
38 | /* Addresses to scan */ | 38 | /* Addresses to scan */ |
@@ -74,7 +74,7 @@ MODULE_LICENSE("GPL"); | |||
74 | #define dprintk if (debug) printk | 74 | #define dprintk if (debug) printk |
75 | 75 | ||
76 | struct saa6588 { | 76 | struct saa6588 { |
77 | struct i2c_client *client; | 77 | struct v4l2_subdev sd; |
78 | struct work_struct work; | 78 | struct work_struct work; |
79 | struct timer_list timer; | 79 | struct timer_list timer; |
80 | spinlock_t lock; | 80 | spinlock_t lock; |
@@ -88,6 +88,11 @@ struct saa6588 { | |||
88 | int data_available_for_read; | 88 | int data_available_for_read; |
89 | }; | 89 | }; |
90 | 90 | ||
91 | static inline struct saa6588 *to_saa6588(struct v4l2_subdev *sd) | ||
92 | { | ||
93 | return container_of(sd, struct saa6588, sd); | ||
94 | } | ||
95 | |||
91 | /* ---------------------------------------------------------------------- */ | 96 | /* ---------------------------------------------------------------------- */ |
92 | 97 | ||
93 | /* | 98 | /* |
@@ -257,6 +262,7 @@ static void block_to_buf(struct saa6588 *s, unsigned char *blockbuf) | |||
257 | 262 | ||
258 | static void saa6588_i2c_poll(struct saa6588 *s) | 263 | static void saa6588_i2c_poll(struct saa6588 *s) |
259 | { | 264 | { |
265 | struct i2c_client *client = v4l2_get_subdevdata(&s->sd); | ||
260 | unsigned long flags; | 266 | unsigned long flags; |
261 | unsigned char tmpbuf[6]; | 267 | unsigned char tmpbuf[6]; |
262 | unsigned char blocknum; | 268 | unsigned char blocknum; |
@@ -264,7 +270,7 @@ static void saa6588_i2c_poll(struct saa6588 *s) | |||
264 | 270 | ||
265 | /* Although we only need 3 bytes, we have to read at least 6. | 271 | /* Although we only need 3 bytes, we have to read at least 6. |
266 | SAA6588 returns garbage otherwise */ | 272 | SAA6588 returns garbage otherwise */ |
267 | if (6 != i2c_master_recv(s->client, &tmpbuf[0], 6)) { | 273 | if (6 != i2c_master_recv(client, &tmpbuf[0], 6)) { |
268 | if (debug > 1) | 274 | if (debug > 1) |
269 | dprintk(PREFIX "read error!\n"); | 275 | dprintk(PREFIX "read error!\n"); |
270 | return; | 276 | return; |
@@ -332,6 +338,7 @@ static void saa6588_work(struct work_struct *work) | |||
332 | 338 | ||
333 | static int saa6588_configure(struct saa6588 *s) | 339 | static int saa6588_configure(struct saa6588 *s) |
334 | { | 340 | { |
341 | struct i2c_client *client = v4l2_get_subdevdata(&s->sd); | ||
335 | unsigned char buf[3]; | 342 | unsigned char buf[3]; |
336 | int rc; | 343 | int rc; |
337 | 344 | ||
@@ -379,7 +386,7 @@ static int saa6588_configure(struct saa6588 *s) | |||
379 | dprintk(PREFIX "writing: 0w=0x%02x 1w=0x%02x 2w=0x%02x\n", | 386 | dprintk(PREFIX "writing: 0w=0x%02x 1w=0x%02x 2w=0x%02x\n", |
380 | buf[0], buf[1], buf[2]); | 387 | buf[0], buf[1], buf[2]); |
381 | 388 | ||
382 | rc = i2c_master_send(s->client, buf, 3); | 389 | rc = i2c_master_send(client, buf, 3); |
383 | if (rc != 3) | 390 | if (rc != 3) |
384 | printk(PREFIX "i2c i/o error: rc == %d (should be 3)\n", rc); | 391 | printk(PREFIX "i2c i/o error: rc == %d (should be 3)\n", rc); |
385 | 392 | ||
@@ -388,10 +395,64 @@ static int saa6588_configure(struct saa6588 *s) | |||
388 | 395 | ||
389 | /* ---------------------------------------------------------------------- */ | 396 | /* ---------------------------------------------------------------------- */ |
390 | 397 | ||
398 | static long saa6588_ioctl(struct v4l2_subdev *sd, unsigned int cmd, void *arg) | ||
399 | { | ||
400 | struct saa6588 *s = to_saa6588(sd); | ||
401 | struct rds_command *a = arg; | ||
402 | |||
403 | switch (cmd) { | ||
404 | /* --- open() for /dev/radio --- */ | ||
405 | case RDS_CMD_OPEN: | ||
406 | a->result = 0; /* return error if chip doesn't work ??? */ | ||
407 | break; | ||
408 | /* --- close() for /dev/radio --- */ | ||
409 | case RDS_CMD_CLOSE: | ||
410 | s->data_available_for_read = 1; | ||
411 | wake_up_interruptible(&s->read_queue); | ||
412 | a->result = 0; | ||
413 | break; | ||
414 | /* --- read() for /dev/radio --- */ | ||
415 | case RDS_CMD_READ: | ||
416 | read_from_buf(s, a); | ||
417 | break; | ||
418 | /* --- poll() for /dev/radio --- */ | ||
419 | case RDS_CMD_POLL: | ||
420 | a->result = 0; | ||
421 | if (s->data_available_for_read) { | ||
422 | a->result |= POLLIN | POLLRDNORM; | ||
423 | } | ||
424 | poll_wait(a->instance, &s->read_queue, a->event_list); | ||
425 | break; | ||
426 | |||
427 | default: | ||
428 | /* nothing */ | ||
429 | return -ENOIOCTLCMD; | ||
430 | } | ||
431 | return 0; | ||
432 | } | ||
433 | |||
434 | static int saa6588_command(struct i2c_client *client, unsigned cmd, void *arg) | ||
435 | { | ||
436 | return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg); | ||
437 | } | ||
438 | |||
439 | /* ----------------------------------------------------------------------- */ | ||
440 | |||
441 | static const struct v4l2_subdev_core_ops saa6588_core_ops = { | ||
442 | .ioctl = saa6588_ioctl, | ||
443 | }; | ||
444 | |||
445 | static const struct v4l2_subdev_ops saa6588_ops = { | ||
446 | .core = &saa6588_core_ops, | ||
447 | }; | ||
448 | |||
449 | /* ---------------------------------------------------------------------- */ | ||
450 | |||
391 | static int saa6588_probe(struct i2c_client *client, | 451 | static int saa6588_probe(struct i2c_client *client, |
392 | const struct i2c_device_id *id) | 452 | const struct i2c_device_id *id) |
393 | { | 453 | { |
394 | struct saa6588 *s; | 454 | struct saa6588 *s; |
455 | struct v4l2_subdev *sd; | ||
395 | 456 | ||
396 | v4l_info(client, "saa6588 found @ 0x%x (%s)\n", | 457 | v4l_info(client, "saa6588 found @ 0x%x (%s)\n", |
397 | client->addr << 1, client->adapter->name); | 458 | client->addr << 1, client->adapter->name); |
@@ -400,7 +461,6 @@ static int saa6588_probe(struct i2c_client *client, | |||
400 | if (s == NULL) | 461 | if (s == NULL) |
401 | return -ENOMEM; | 462 | return -ENOMEM; |
402 | 463 | ||
403 | s->client = client; | ||
404 | s->buf_size = bufblocks * 3; | 464 | s->buf_size = bufblocks * 3; |
405 | 465 | ||
406 | s->buffer = kmalloc(s->buf_size, GFP_KERNEL); | 466 | s->buffer = kmalloc(s->buf_size, GFP_KERNEL); |
@@ -408,6 +468,8 @@ static int saa6588_probe(struct i2c_client *client, | |||
408 | kfree(s); | 468 | kfree(s); |
409 | return -ENOMEM; | 469 | return -ENOMEM; |
410 | } | 470 | } |
471 | sd = &s->sd; | ||
472 | v4l2_i2c_subdev_init(sd, client, &saa6588_ops); | ||
411 | spin_lock_init(&s->lock); | 473 | spin_lock_init(&s->lock); |
412 | s->block_count = 0; | 474 | s->block_count = 0; |
413 | s->wr_index = 0; | 475 | s->wr_index = 0; |
@@ -415,7 +477,6 @@ static int saa6588_probe(struct i2c_client *client, | |||
415 | s->last_blocknum = 0xff; | 477 | s->last_blocknum = 0xff; |
416 | init_waitqueue_head(&s->read_queue); | 478 | init_waitqueue_head(&s->read_queue); |
417 | s->data_available_for_read = 0; | 479 | s->data_available_for_read = 0; |
418 | i2c_set_clientdata(client, s); | ||
419 | 480 | ||
420 | saa6588_configure(s); | 481 | saa6588_configure(s); |
421 | 482 | ||
@@ -430,7 +491,10 @@ static int saa6588_probe(struct i2c_client *client, | |||
430 | 491 | ||
431 | static int saa6588_remove(struct i2c_client *client) | 492 | static int saa6588_remove(struct i2c_client *client) |
432 | { | 493 | { |
433 | struct saa6588 *s = i2c_get_clientdata(client); | 494 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
495 | struct saa6588 *s = to_saa6588(sd); | ||
496 | |||
497 | v4l2_device_unregister_subdev(sd); | ||
434 | 498 | ||
435 | del_timer_sync(&s->timer); | 499 | del_timer_sync(&s->timer); |
436 | flush_scheduled_work(); | 500 | flush_scheduled_work(); |
@@ -440,43 +504,6 @@ static int saa6588_remove(struct i2c_client *client) | |||
440 | return 0; | 504 | return 0; |
441 | } | 505 | } |
442 | 506 | ||
443 | static int saa6588_command(struct i2c_client *client, unsigned int cmd, | ||
444 | void *arg) | ||
445 | { | ||
446 | struct saa6588 *s = i2c_get_clientdata(client); | ||
447 | struct rds_command *a = (struct rds_command *)arg; | ||
448 | |||
449 | switch (cmd) { | ||
450 | /* --- open() for /dev/radio --- */ | ||
451 | case RDS_CMD_OPEN: | ||
452 | a->result = 0; /* return error if chip doesn't work ??? */ | ||
453 | break; | ||
454 | /* --- close() for /dev/radio --- */ | ||
455 | case RDS_CMD_CLOSE: | ||
456 | s->data_available_for_read = 1; | ||
457 | wake_up_interruptible(&s->read_queue); | ||
458 | a->result = 0; | ||
459 | break; | ||
460 | /* --- read() for /dev/radio --- */ | ||
461 | case RDS_CMD_READ: | ||
462 | read_from_buf(s, a); | ||
463 | break; | ||
464 | /* --- poll() for /dev/radio --- */ | ||
465 | case RDS_CMD_POLL: | ||
466 | a->result = 0; | ||
467 | if (s->data_available_for_read) { | ||
468 | a->result |= POLLIN | POLLRDNORM; | ||
469 | } | ||
470 | poll_wait(a->instance, &s->read_queue, a->event_list); | ||
471 | break; | ||
472 | |||
473 | default: | ||
474 | /* nothing */ | ||
475 | break; | ||
476 | } | ||
477 | return 0; | ||
478 | } | ||
479 | |||
480 | /* ----------------------------------------------------------------------- */ | 507 | /* ----------------------------------------------------------------------- */ |
481 | 508 | ||
482 | static const struct i2c_device_id saa6588_id[] = { | 509 | static const struct i2c_device_id saa6588_id[] = { |