~ubuntu-branches/ubuntu/precise/linux-ti-omap4/precise

« back to all changes in this revision

Viewing changes to drivers/media/video/tvp5150.c

  • Committer: Bazaar Package Importer
  • Author(s): Paolo Pisati
  • Date: 2011-06-29 15:23:51 UTC
  • mfrom: (26.1.1 natty-proposed)
  • Revision ID: james.westby@ubuntu.com-20110629152351-xs96tm303d95rpbk
Tags: 3.0.0-1200.2
* Rebased against 3.0.0-6.7
* BSP from TI based on 3.0.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
#include <media/v4l2-device.h>
13
13
#include <media/tvp5150.h>
14
14
#include <media/v4l2-chip-ident.h>
 
15
#include <media/v4l2-ctrls.h>
15
16
 
16
17
#include "tvp5150_reg.h"
17
18
 
24
25
module_param(debug, int, 0);
25
26
MODULE_PARM_DESC(debug, "Debug level (0-2)");
26
27
 
27
 
/* supported controls */
28
 
static struct v4l2_queryctrl tvp5150_qctrl[] = {
29
 
        {
30
 
                .id = V4L2_CID_BRIGHTNESS,
31
 
                .type = V4L2_CTRL_TYPE_INTEGER,
32
 
                .name = "Brightness",
33
 
                .minimum = 0,
34
 
                .maximum = 255,
35
 
                .step = 1,
36
 
                .default_value = 128,
37
 
                .flags = 0,
38
 
        }, {
39
 
                .id = V4L2_CID_CONTRAST,
40
 
                .type = V4L2_CTRL_TYPE_INTEGER,
41
 
                .name = "Contrast",
42
 
                .minimum = 0,
43
 
                .maximum = 255,
44
 
                .step = 0x1,
45
 
                .default_value = 128,
46
 
                .flags = 0,
47
 
        }, {
48
 
                 .id = V4L2_CID_SATURATION,
49
 
                 .type = V4L2_CTRL_TYPE_INTEGER,
50
 
                 .name = "Saturation",
51
 
                 .minimum = 0,
52
 
                 .maximum = 255,
53
 
                 .step = 0x1,
54
 
                 .default_value = 128,
55
 
                 .flags = 0,
56
 
        }, {
57
 
                .id = V4L2_CID_HUE,
58
 
                .type = V4L2_CTRL_TYPE_INTEGER,
59
 
                .name = "Hue",
60
 
                .minimum = -128,
61
 
                .maximum = 127,
62
 
                .step = 0x1,
63
 
                .default_value = 0,
64
 
                .flags = 0,
65
 
        }
66
 
};
67
 
 
68
28
struct tvp5150 {
69
29
        struct v4l2_subdev sd;
 
30
        struct v4l2_ctrl_handler hdl;
70
31
 
71
32
        v4l2_std_id norm;       /* Current set standard */
72
33
        u32 input;
73
34
        u32 output;
74
35
        int enable;
75
 
        int bright;
76
 
        int contrast;
77
 
        int hue;
78
 
        int sat;
79
36
};
80
37
 
81
38
static inline struct tvp5150 *to_tvp5150(struct v4l2_subdev *sd)
83
40
        return container_of(sd, struct tvp5150, sd);
84
41
}
85
42
 
 
43
static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
 
44
{
 
45
        return &container_of(ctrl->handler, struct tvp5150, hdl)->sd;
 
46
}
 
47
 
86
48
static int tvp5150_read(struct v4l2_subdev *sd, unsigned char addr)
87
49
{
88
50
        struct i2c_client *c = v4l2_get_subdevdata(sd);
775
737
static int tvp5150_reset(struct v4l2_subdev *sd, u32 val)
776
738
{
777
739
        struct tvp5150 *decoder = to_tvp5150(sd);
778
 
        u8 msb_id, lsb_id, msb_rom, lsb_rom;
779
 
 
780
 
        msb_id = tvp5150_read(sd, TVP5150_MSB_DEV_ID);
781
 
        lsb_id = tvp5150_read(sd, TVP5150_LSB_DEV_ID);
782
 
        msb_rom = tvp5150_read(sd, TVP5150_ROM_MAJOR_VER);
783
 
        lsb_rom = tvp5150_read(sd, TVP5150_ROM_MINOR_VER);
784
 
 
785
 
        if (msb_rom == 4 && lsb_rom == 0) { /* Is TVP5150AM1 */
786
 
                v4l2_info(sd, "tvp%02x%02xam1 detected.\n", msb_id, lsb_id);
787
 
 
788
 
                /* ITU-T BT.656.4 timing */
789
 
                tvp5150_write(sd, TVP5150_REV_SELECT, 0);
790
 
        } else {
791
 
                if (msb_rom == 3 || lsb_rom == 0x21) { /* Is TVP5150A */
792
 
                        v4l2_info(sd, "tvp%02x%02xa detected.\n", msb_id, lsb_id);
793
 
                } else {
794
 
                        v4l2_info(sd, "*** unknown tvp%02x%02x chip detected.\n",
795
 
                                        msb_id, lsb_id);
796
 
                        v4l2_info(sd, "*** Rom ver is %d.%d\n", msb_rom, lsb_rom);
797
 
                }
798
 
        }
799
740
 
800
741
        /* Initializes TVP5150 to its default values */
801
742
        tvp5150_write_inittab(sd, tvp5150_init_default);
810
751
        tvp5150_write_inittab(sd, tvp5150_init_enable);
811
752
 
812
753
        /* Initialize image preferences */
813
 
        tvp5150_write(sd, TVP5150_BRIGHT_CTL, decoder->bright);
814
 
        tvp5150_write(sd, TVP5150_CONTRAST_CTL, decoder->contrast);
815
 
        tvp5150_write(sd, TVP5150_SATURATION_CTL, decoder->contrast);
816
 
        tvp5150_write(sd, TVP5150_HUE_CTL, decoder->hue);
 
754
        v4l2_ctrl_handler_setup(&decoder->hdl);
817
755
 
818
756
        tvp5150_set_std(sd, decoder->norm);
819
757
        return 0;
820
758
};
821
759
 
822
 
static int tvp5150_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
823
 
{
824
 
        v4l2_dbg(1, debug, sd, "g_ctrl called\n");
825
 
 
826
 
        switch (ctrl->id) {
827
 
        case V4L2_CID_BRIGHTNESS:
828
 
                ctrl->value = tvp5150_read(sd, TVP5150_BRIGHT_CTL);
829
 
                return 0;
830
 
        case V4L2_CID_CONTRAST:
831
 
                ctrl->value = tvp5150_read(sd, TVP5150_CONTRAST_CTL);
832
 
                return 0;
833
 
        case V4L2_CID_SATURATION:
834
 
                ctrl->value = tvp5150_read(sd, TVP5150_SATURATION_CTL);
835
 
                return 0;
836
 
        case V4L2_CID_HUE:
837
 
                ctrl->value = tvp5150_read(sd, TVP5150_HUE_CTL);
838
 
                return 0;
839
 
        }
840
 
        return -EINVAL;
841
 
}
842
 
 
843
 
static int tvp5150_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
844
 
{
845
 
        u8 i, n;
846
 
        n = ARRAY_SIZE(tvp5150_qctrl);
847
 
 
848
 
        for (i = 0; i < n; i++) {
849
 
                if (ctrl->id != tvp5150_qctrl[i].id)
850
 
                        continue;
851
 
                if (ctrl->value < tvp5150_qctrl[i].minimum ||
852
 
                    ctrl->value > tvp5150_qctrl[i].maximum)
853
 
                        return -ERANGE;
854
 
                v4l2_dbg(1, debug, sd, "s_ctrl: id=%d, value=%d\n",
855
 
                                        ctrl->id, ctrl->value);
856
 
                break;
857
 
        }
858
 
 
859
 
        switch (ctrl->id) {
860
 
        case V4L2_CID_BRIGHTNESS:
861
 
                tvp5150_write(sd, TVP5150_BRIGHT_CTL, ctrl->value);
862
 
                return 0;
863
 
        case V4L2_CID_CONTRAST:
864
 
                tvp5150_write(sd, TVP5150_CONTRAST_CTL, ctrl->value);
865
 
                return 0;
866
 
        case V4L2_CID_SATURATION:
867
 
                tvp5150_write(sd, TVP5150_SATURATION_CTL, ctrl->value);
868
 
                return 0;
869
 
        case V4L2_CID_HUE:
870
 
                tvp5150_write(sd, TVP5150_HUE_CTL, ctrl->value);
 
760
static int tvp5150_s_ctrl(struct v4l2_ctrl *ctrl)
 
761
{
 
762
        struct v4l2_subdev *sd = to_sd(ctrl);
 
763
 
 
764
        switch (ctrl->id) {
 
765
        case V4L2_CID_BRIGHTNESS:
 
766
                tvp5150_write(sd, TVP5150_BRIGHT_CTL, ctrl->val);
 
767
                return 0;
 
768
        case V4L2_CID_CONTRAST:
 
769
                tvp5150_write(sd, TVP5150_CONTRAST_CTL, ctrl->val);
 
770
                return 0;
 
771
        case V4L2_CID_SATURATION:
 
772
                tvp5150_write(sd, TVP5150_SATURATION_CTL, ctrl->val);
 
773
                return 0;
 
774
        case V4L2_CID_HUE:
 
775
                tvp5150_write(sd, TVP5150_HUE_CTL, ctrl->val);
871
776
                return 0;
872
777
        }
873
778
        return -EINVAL;
995
900
        return 0;
996
901
}
997
902
 
998
 
static int tvp5150_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc)
999
 
{
1000
 
        int i;
1001
 
 
1002
 
        v4l2_dbg(1, debug, sd, "queryctrl called\n");
1003
 
 
1004
 
        for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++)
1005
 
                if (qc->id && qc->id == tvp5150_qctrl[i].id) {
1006
 
                        memcpy(qc, &(tvp5150_qctrl[i]),
1007
 
                               sizeof(*qc));
1008
 
                        return 0;
1009
 
                }
1010
 
 
1011
 
        return -EINVAL;
1012
 
}
1013
 
 
1014
903
/* ----------------------------------------------------------------------- */
1015
904
 
 
905
static const struct v4l2_ctrl_ops tvp5150_ctrl_ops = {
 
906
        .s_ctrl = tvp5150_s_ctrl,
 
907
};
 
908
 
1016
909
static const struct v4l2_subdev_core_ops tvp5150_core_ops = {
1017
910
        .log_status = tvp5150_log_status,
1018
 
        .g_ctrl = tvp5150_g_ctrl,
1019
 
        .s_ctrl = tvp5150_s_ctrl,
1020
 
        .queryctrl = tvp5150_queryctrl,
 
911
        .g_ext_ctrls = v4l2_subdev_g_ext_ctrls,
 
912
        .try_ext_ctrls = v4l2_subdev_try_ext_ctrls,
 
913
        .s_ext_ctrls = v4l2_subdev_s_ext_ctrls,
 
914
        .g_ctrl = v4l2_subdev_g_ctrl,
 
915
        .s_ctrl = v4l2_subdev_s_ctrl,
 
916
        .queryctrl = v4l2_subdev_queryctrl,
 
917
        .querymenu = v4l2_subdev_querymenu,
1021
918
        .s_std = tvp5150_s_std,
1022
919
        .reset = tvp5150_reset,
1023
920
        .g_chip_ident = tvp5150_g_chip_ident,
1059
956
{
1060
957
        struct tvp5150 *core;
1061
958
        struct v4l2_subdev *sd;
 
959
        u8 msb_id, lsb_id, msb_rom, lsb_rom;
1062
960
 
1063
961
        /* Check if the adapter supports the needed features */
1064
962
        if (!i2c_check_functionality(c->adapter,
1074
972
        v4l_info(c, "chip found @ 0x%02x (%s)\n",
1075
973
                 c->addr << 1, c->adapter->name);
1076
974
 
 
975
        msb_id = tvp5150_read(sd, TVP5150_MSB_DEV_ID);
 
976
        lsb_id = tvp5150_read(sd, TVP5150_LSB_DEV_ID);
 
977
        msb_rom = tvp5150_read(sd, TVP5150_ROM_MAJOR_VER);
 
978
        lsb_rom = tvp5150_read(sd, TVP5150_ROM_MINOR_VER);
 
979
 
 
980
        if (msb_rom == 4 && lsb_rom == 0) { /* Is TVP5150AM1 */
 
981
                v4l2_info(sd, "tvp%02x%02xam1 detected.\n", msb_id, lsb_id);
 
982
 
 
983
                /* ITU-T BT.656.4 timing */
 
984
                tvp5150_write(sd, TVP5150_REV_SELECT, 0);
 
985
        } else {
 
986
                if (msb_rom == 3 || lsb_rom == 0x21) { /* Is TVP5150A */
 
987
                        v4l2_info(sd, "tvp%02x%02xa detected.\n", msb_id, lsb_id);
 
988
                } else {
 
989
                        v4l2_info(sd, "*** unknown tvp%02x%02x chip detected.\n",
 
990
                                        msb_id, lsb_id);
 
991
                        v4l2_info(sd, "*** Rom ver is %d.%d\n", msb_rom, lsb_rom);
 
992
                }
 
993
        }
 
994
 
1077
995
        core->norm = V4L2_STD_ALL;      /* Default is autodetect */
1078
996
        core->input = TVP5150_COMPOSITE1;
1079
997
        core->enable = 1;
1080
 
        core->bright = 128;
1081
 
        core->contrast = 128;
1082
 
        core->hue = 0;
1083
 
        core->sat = 128;
 
998
 
 
999
        v4l2_ctrl_handler_init(&core->hdl, 4);
 
1000
        v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
 
1001
                        V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
 
1002
        v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
 
1003
                        V4L2_CID_CONTRAST, 0, 255, 1, 128);
 
1004
        v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
 
1005
                        V4L2_CID_SATURATION, 0, 255, 1, 128);
 
1006
        v4l2_ctrl_new_std(&core->hdl, &tvp5150_ctrl_ops,
 
1007
                        V4L2_CID_HUE, -128, 127, 1, 0);
 
1008
        sd->ctrl_handler = &core->hdl;
 
1009
        if (core->hdl.error) {
 
1010
                int err = core->hdl.error;
 
1011
 
 
1012
                v4l2_ctrl_handler_free(&core->hdl);
 
1013
                kfree(core);
 
1014
                return err;
 
1015
        }
 
1016
        v4l2_ctrl_handler_setup(&core->hdl);
1084
1017
 
1085
1018
        if (debug > 1)
1086
1019
                tvp5150_log_status(sd);
1090
1023
static int tvp5150_remove(struct i2c_client *c)
1091
1024
{
1092
1025
        struct v4l2_subdev *sd = i2c_get_clientdata(c);
 
1026
        struct tvp5150 *decoder = to_tvp5150(sd);
1093
1027
 
1094
1028
        v4l2_dbg(1, debug, sd,
1095
1029
                "tvp5150.c: removing tvp5150 adapter on address 0x%x\n",
1096
1030
                c->addr << 1);
1097
1031
 
1098
1032
        v4l2_device_unregister_subdev(sd);
 
1033
        v4l2_ctrl_handler_free(&decoder->hdl);
1099
1034
        kfree(to_tvp5150(sd));
1100
1035
        return 0;
1101
1036
}