diff options
author | Guennadi Liakhovetski <g.liakhovetski@gmx.de> | 2009-08-25 10:28:22 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-09-18 23:18:27 -0400 |
commit | 40e2e0927003424c25807b575dd40da2b8685857 (patch) | |
tree | 917ca8fd5f7598194d264ec92a08b312d4932b90 /drivers/media/video/tw9910.c | |
parent | bc1937b41d8253e2b554da385023a92189d38917 (diff) |
V4L/DVB (12506): soc-camera: convert to platform device
Convert soc-camera core and all drivers to platform device API. We already
converted platforms to register a platform device for each soc-camera client,
now we remove the compatibility code and switch completely to the new scheme.
This is a preparatory step for the v4l2-subdev conversion.
Signed-off-by: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/tw9910.c')
-rw-r--r-- | drivers/media/video/tw9910.c | 110 |
1 files changed, 58 insertions, 52 deletions
diff --git a/drivers/media/video/tw9910.c b/drivers/media/video/tw9910.c index aa5065ea09ed..d780a509faa9 100644 --- a/drivers/media/video/tw9910.c +++ b/drivers/media/video/tw9910.c | |||
@@ -224,8 +224,6 @@ struct tw9910_hsync_ctrl { | |||
224 | 224 | ||
225 | struct tw9910_priv { | 225 | struct tw9910_priv { |
226 | struct tw9910_video_info *info; | 226 | struct tw9910_video_info *info; |
227 | struct i2c_client *client; | ||
228 | struct soc_camera_device icd; | ||
229 | const struct tw9910_scale_ctrl *scale; | 227 | const struct tw9910_scale_ctrl *scale; |
230 | }; | 228 | }; |
231 | 229 | ||
@@ -511,35 +509,38 @@ tw9910_select_norm(struct soc_camera_device *icd, u32 width, u32 height) | |||
511 | */ | 509 | */ |
512 | static int tw9910_init(struct soc_camera_device *icd) | 510 | static int tw9910_init(struct soc_camera_device *icd) |
513 | { | 511 | { |
514 | struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); | 512 | struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); |
513 | struct soc_camera_link *icl = to_soc_camera_link(icd); | ||
515 | int ret = 0; | 514 | int ret = 0; |
516 | 515 | ||
517 | if (priv->info->link.power) { | 516 | if (icl->power) { |
518 | ret = priv->info->link.power(&priv->client->dev, 1); | 517 | ret = icl->power(&client->dev, 1); |
519 | if (ret < 0) | 518 | if (ret < 0) |
520 | return ret; | 519 | return ret; |
521 | } | 520 | } |
522 | 521 | ||
523 | if (priv->info->link.reset) | 522 | if (icl->reset) |
524 | ret = priv->info->link.reset(&priv->client->dev); | 523 | ret = icl->reset(&client->dev); |
525 | 524 | ||
526 | return ret; | 525 | return ret; |
527 | } | 526 | } |
528 | 527 | ||
529 | static int tw9910_release(struct soc_camera_device *icd) | 528 | static int tw9910_release(struct soc_camera_device *icd) |
530 | { | 529 | { |
531 | struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); | 530 | struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); |
531 | struct soc_camera_link *icl = to_soc_camera_link(icd); | ||
532 | int ret = 0; | 532 | int ret = 0; |
533 | 533 | ||
534 | if (priv->info->link.power) | 534 | if (icl->power) |
535 | ret = priv->info->link.power(&priv->client->dev, 0); | 535 | ret = icl->power(&client->dev, 0); |
536 | 536 | ||
537 | return ret; | 537 | return ret; |
538 | } | 538 | } |
539 | 539 | ||
540 | static int tw9910_start_capture(struct soc_camera_device *icd) | 540 | static int tw9910_start_capture(struct soc_camera_device *icd) |
541 | { | 541 | { |
542 | struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); | 542 | struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); |
543 | struct tw9910_priv *priv = i2c_get_clientdata(client); | ||
543 | 544 | ||
544 | if (!priv->scale) { | 545 | if (!priv->scale) { |
545 | dev_err(&icd->dev, "norm select error\n"); | 546 | dev_err(&icd->dev, "norm select error\n"); |
@@ -567,8 +568,9 @@ static int tw9910_set_bus_param(struct soc_camera_device *icd, | |||
567 | 568 | ||
568 | static unsigned long tw9910_query_bus_param(struct soc_camera_device *icd) | 569 | static unsigned long tw9910_query_bus_param(struct soc_camera_device *icd) |
569 | { | 570 | { |
570 | struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); | 571 | struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); |
571 | struct soc_camera_link *icl = priv->client->dev.platform_data; | 572 | struct tw9910_priv *priv = i2c_get_clientdata(client); |
573 | struct soc_camera_link *icl = to_soc_camera_link(icd); | ||
572 | unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER | | 574 | unsigned long flags = SOCAM_PCLK_SAMPLE_RISING | SOCAM_MASTER | |
573 | SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH | | 575 | SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_HIGH | |
574 | SOCAM_DATA_ACTIVE_HIGH | priv->info->buswidth; | 576 | SOCAM_DATA_ACTIVE_HIGH | priv->info->buswidth; |
@@ -610,13 +612,13 @@ static int tw9910_enum_input(struct soc_camera_device *icd, | |||
610 | static int tw9910_get_register(struct soc_camera_device *icd, | 612 | static int tw9910_get_register(struct soc_camera_device *icd, |
611 | struct v4l2_dbg_register *reg) | 613 | struct v4l2_dbg_register *reg) |
612 | { | 614 | { |
613 | struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); | 615 | struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); |
614 | int ret; | 616 | int ret; |
615 | 617 | ||
616 | if (reg->reg > 0xff) | 618 | if (reg->reg > 0xff) |
617 | return -EINVAL; | 619 | return -EINVAL; |
618 | 620 | ||
619 | ret = i2c_smbus_read_byte_data(priv->client, reg->reg); | 621 | ret = i2c_smbus_read_byte_data(client, reg->reg); |
620 | if (ret < 0) | 622 | if (ret < 0) |
621 | return ret; | 623 | return ret; |
622 | 624 | ||
@@ -631,20 +633,21 @@ static int tw9910_get_register(struct soc_camera_device *icd, | |||
631 | static int tw9910_set_register(struct soc_camera_device *icd, | 633 | static int tw9910_set_register(struct soc_camera_device *icd, |
632 | struct v4l2_dbg_register *reg) | 634 | struct v4l2_dbg_register *reg) |
633 | { | 635 | { |
634 | struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); | 636 | struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); |
635 | 637 | ||
636 | if (reg->reg > 0xff || | 638 | if (reg->reg > 0xff || |
637 | reg->val > 0xff) | 639 | reg->val > 0xff) |
638 | return -EINVAL; | 640 | return -EINVAL; |
639 | 641 | ||
640 | return i2c_smbus_write_byte_data(priv->client, reg->reg, reg->val); | 642 | return i2c_smbus_write_byte_data(client, reg->reg, reg->val); |
641 | } | 643 | } |
642 | #endif | 644 | #endif |
643 | 645 | ||
644 | static int tw9910_set_crop(struct soc_camera_device *icd, | 646 | static int tw9910_set_crop(struct soc_camera_device *icd, |
645 | struct v4l2_rect *rect) | 647 | struct v4l2_rect *rect) |
646 | { | 648 | { |
647 | struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); | 649 | struct i2c_client *client = to_i2c_client(to_soc_camera_control(icd)); |
650 | struct tw9910_priv *priv = i2c_get_clientdata(client); | ||
648 | int ret = -EINVAL; | 651 | int ret = -EINVAL; |
649 | u8 val; | 652 | u8 val; |
650 | 653 | ||
@@ -658,8 +661,8 @@ static int tw9910_set_crop(struct soc_camera_device *icd, | |||
658 | /* | 661 | /* |
659 | * reset hardware | 662 | * reset hardware |
660 | */ | 663 | */ |
661 | tw9910_reset(priv->client); | 664 | tw9910_reset(client); |
662 | ret = tw9910_write_array(priv->client, tw9910_default_regs); | 665 | ret = tw9910_write_array(client, tw9910_default_regs); |
663 | if (ret < 0) | 666 | if (ret < 0) |
664 | goto tw9910_set_fmt_error; | 667 | goto tw9910_set_fmt_error; |
665 | 668 | ||
@@ -670,7 +673,7 @@ static int tw9910_set_crop(struct soc_camera_device *icd, | |||
670 | if (SOCAM_DATAWIDTH_16 == priv->info->buswidth) | 673 | if (SOCAM_DATAWIDTH_16 == priv->info->buswidth) |
671 | val = LEN; | 674 | val = LEN; |
672 | 675 | ||
673 | ret = tw9910_mask_set(priv->client, OPFORM, LEN, val); | 676 | ret = tw9910_mask_set(client, OPFORM, LEN, val); |
674 | if (ret < 0) | 677 | if (ret < 0) |
675 | goto tw9910_set_fmt_error; | 678 | goto tw9910_set_fmt_error; |
676 | 679 | ||
@@ -698,28 +701,28 @@ static int tw9910_set_crop(struct soc_camera_device *icd, | |||
698 | val = 0; | 701 | val = 0; |
699 | } | 702 | } |
700 | 703 | ||
701 | ret = tw9910_mask_set(priv->client, VBICNTL, RTSEL_MASK, val); | 704 | ret = tw9910_mask_set(client, VBICNTL, RTSEL_MASK, val); |
702 | if (ret < 0) | 705 | if (ret < 0) |
703 | goto tw9910_set_fmt_error; | 706 | goto tw9910_set_fmt_error; |
704 | 707 | ||
705 | /* | 708 | /* |
706 | * set scale | 709 | * set scale |
707 | */ | 710 | */ |
708 | ret = tw9910_set_scale(priv->client, priv->scale); | 711 | ret = tw9910_set_scale(client, priv->scale); |
709 | if (ret < 0) | 712 | if (ret < 0) |
710 | goto tw9910_set_fmt_error; | 713 | goto tw9910_set_fmt_error; |
711 | 714 | ||
712 | /* | 715 | /* |
713 | * set cropping | 716 | * set cropping |
714 | */ | 717 | */ |
715 | ret = tw9910_set_cropping(priv->client, &tw9910_cropping_ctrl); | 718 | ret = tw9910_set_cropping(client, &tw9910_cropping_ctrl); |
716 | if (ret < 0) | 719 | if (ret < 0) |
717 | goto tw9910_set_fmt_error; | 720 | goto tw9910_set_fmt_error; |
718 | 721 | ||
719 | /* | 722 | /* |
720 | * set hsync | 723 | * set hsync |
721 | */ | 724 | */ |
722 | ret = tw9910_set_hsync(priv->client, &tw9910_hsync_ctrl); | 725 | ret = tw9910_set_hsync(client, &tw9910_hsync_ctrl); |
723 | if (ret < 0) | 726 | if (ret < 0) |
724 | goto tw9910_set_fmt_error; | 727 | goto tw9910_set_fmt_error; |
725 | 728 | ||
@@ -727,7 +730,7 @@ static int tw9910_set_crop(struct soc_camera_device *icd, | |||
727 | 730 | ||
728 | tw9910_set_fmt_error: | 731 | tw9910_set_fmt_error: |
729 | 732 | ||
730 | tw9910_reset(priv->client); | 733 | tw9910_reset(client); |
731 | priv->scale = NULL; | 734 | priv->scale = NULL; |
732 | 735 | ||
733 | return ret; | 736 | return ret; |
@@ -784,9 +787,10 @@ static int tw9910_try_fmt(struct soc_camera_device *icd, | |||
784 | return 0; | 787 | return 0; |
785 | } | 788 | } |
786 | 789 | ||
787 | static int tw9910_video_probe(struct soc_camera_device *icd) | 790 | static int tw9910_video_probe(struct soc_camera_device *icd, |
791 | struct i2c_client *client) | ||
788 | { | 792 | { |
789 | struct tw9910_priv *priv = container_of(icd, struct tw9910_priv, icd); | 793 | struct tw9910_priv *priv = i2c_get_clientdata(client); |
790 | s32 val; | 794 | s32 val; |
791 | int ret; | 795 | int ret; |
792 | 796 | ||
@@ -810,10 +814,18 @@ static int tw9910_video_probe(struct soc_camera_device *icd) | |||
810 | icd->formats = tw9910_color_fmt; | 814 | icd->formats = tw9910_color_fmt; |
811 | icd->num_formats = ARRAY_SIZE(tw9910_color_fmt); | 815 | icd->num_formats = ARRAY_SIZE(tw9910_color_fmt); |
812 | 816 | ||
817 | /* Switch master clock on */ | ||
818 | ret = soc_camera_video_start(icd, &client->dev); | ||
819 | if (ret) | ||
820 | return ret; | ||
821 | |||
813 | /* | 822 | /* |
814 | * check and show Product ID | 823 | * check and show Product ID |
815 | */ | 824 | */ |
816 | val = i2c_smbus_read_byte_data(priv->client, ID); | 825 | val = i2c_smbus_read_byte_data(client, ID); |
826 | |||
827 | soc_camera_video_stop(icd); | ||
828 | |||
817 | if (0x0B != GET_ID(val) || | 829 | if (0x0B != GET_ID(val) || |
818 | 0x00 != GET_ReV(val)) { | 830 | 0x00 != GET_ReV(val)) { |
819 | dev_err(&icd->dev, | 831 | dev_err(&icd->dev, |
@@ -824,25 +836,14 @@ static int tw9910_video_probe(struct soc_camera_device *icd) | |||
824 | dev_info(&icd->dev, | 836 | dev_info(&icd->dev, |
825 | "tw9910 Product ID %0x:%0x\n", GET_ID(val), GET_ReV(val)); | 837 | "tw9910 Product ID %0x:%0x\n", GET_ID(val), GET_ReV(val)); |
826 | 838 | ||
827 | ret = soc_camera_video_start(icd); | ||
828 | if (ret < 0) | ||
829 | return ret; | ||
830 | |||
831 | icd->vdev->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL; | 839 | icd->vdev->tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL; |
832 | icd->vdev->current_norm = V4L2_STD_NTSC; | 840 | icd->vdev->current_norm = V4L2_STD_NTSC; |
833 | 841 | ||
834 | return ret; | 842 | return ret; |
835 | } | 843 | } |
836 | 844 | ||
837 | static void tw9910_video_remove(struct soc_camera_device *icd) | ||
838 | { | ||
839 | soc_camera_video_stop(icd); | ||
840 | } | ||
841 | |||
842 | static struct soc_camera_ops tw9910_ops = { | 845 | static struct soc_camera_ops tw9910_ops = { |
843 | .owner = THIS_MODULE, | 846 | .owner = THIS_MODULE, |
844 | .probe = tw9910_video_probe, | ||
845 | .remove = tw9910_video_remove, | ||
846 | .init = tw9910_init, | 847 | .init = tw9910_init, |
847 | .release = tw9910_release, | 848 | .release = tw9910_release, |
848 | .start_capture = tw9910_start_capture, | 849 | .start_capture = tw9910_start_capture, |
@@ -871,18 +872,25 @@ static int tw9910_probe(struct i2c_client *client, | |||
871 | { | 872 | { |
872 | struct tw9910_priv *priv; | 873 | struct tw9910_priv *priv; |
873 | struct tw9910_video_info *info; | 874 | struct tw9910_video_info *info; |
874 | struct soc_camera_device *icd; | 875 | struct soc_camera_device *icd = client->dev.platform_data; |
876 | struct i2c_adapter *adapter = | ||
877 | to_i2c_adapter(client->dev.parent); | ||
878 | struct soc_camera_link *icl; | ||
875 | const struct tw9910_scale_ctrl *scale; | 879 | const struct tw9910_scale_ctrl *scale; |
876 | int i, ret; | 880 | int i, ret; |
877 | 881 | ||
878 | if (!client->dev.platform_data) | 882 | if (!icd) { |
883 | dev_err(&client->dev, "TW9910: missing soc-camera data!\n"); | ||
879 | return -EINVAL; | 884 | return -EINVAL; |
885 | } | ||
880 | 886 | ||
881 | info = container_of(client->dev.platform_data, | 887 | icl = to_soc_camera_link(icd); |
882 | struct tw9910_video_info, link); | 888 | if (!icl) |
889 | return -EINVAL; | ||
883 | 890 | ||
884 | if (!i2c_check_functionality(to_i2c_adapter(client->dev.parent), | 891 | info = container_of(icl, struct tw9910_video_info, link); |
885 | I2C_FUNC_SMBUS_BYTE_DATA)) { | 892 | |
893 | if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA)) { | ||
886 | dev_err(&client->dev, | 894 | dev_err(&client->dev, |
887 | "I2C-Adapter doesn't support " | 895 | "I2C-Adapter doesn't support " |
888 | "I2C_FUNC_SMBUS_BYTE_DATA\n"); | 896 | "I2C_FUNC_SMBUS_BYTE_DATA\n"); |
@@ -894,12 +902,9 @@ static int tw9910_probe(struct i2c_client *client, | |||
894 | return -ENOMEM; | 902 | return -ENOMEM; |
895 | 903 | ||
896 | priv->info = info; | 904 | priv->info = info; |
897 | priv->client = client; | ||
898 | i2c_set_clientdata(client, priv); | 905 | i2c_set_clientdata(client, priv); |
899 | 906 | ||
900 | icd = &priv->icd; | ||
901 | icd->ops = &tw9910_ops; | 907 | icd->ops = &tw9910_ops; |
902 | icd->control = &client->dev; | ||
903 | icd->iface = info->link.bus_id; | 908 | icd->iface = info->link.bus_id; |
904 | 909 | ||
905 | /* | 910 | /* |
@@ -925,9 +930,9 @@ static int tw9910_probe(struct i2c_client *client, | |||
925 | icd->height_min = min(scale[i].height, icd->height_min); | 930 | icd->height_min = min(scale[i].height, icd->height_min); |
926 | } | 931 | } |
927 | 932 | ||
928 | ret = soc_camera_device_register(icd); | 933 | ret = tw9910_video_probe(icd, client); |
929 | |||
930 | if (ret) { | 934 | if (ret) { |
935 | icd->ops = NULL; | ||
931 | i2c_set_clientdata(client, NULL); | 936 | i2c_set_clientdata(client, NULL); |
932 | kfree(priv); | 937 | kfree(priv); |
933 | } | 938 | } |
@@ -938,8 +943,9 @@ static int tw9910_probe(struct i2c_client *client, | |||
938 | static int tw9910_remove(struct i2c_client *client) | 943 | static int tw9910_remove(struct i2c_client *client) |
939 | { | 944 | { |
940 | struct tw9910_priv *priv = i2c_get_clientdata(client); | 945 | struct tw9910_priv *priv = i2c_get_clientdata(client); |
946 | struct soc_camera_device *icd = client->dev.platform_data; | ||
941 | 947 | ||
942 | soc_camera_device_unregister(&priv->icd); | 948 | icd->ops = NULL; |
943 | i2c_set_clientdata(client, NULL); | 949 | i2c_set_clientdata(client, NULL); |
944 | kfree(priv); | 950 | kfree(priv); |
945 | return 0; | 951 | return 0; |