diff options
author | Richard Röjfors <richard.rojfors@mocean-labs.com> | 2009-09-22 05:05:42 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2009-12-05 15:40:41 -0500 |
commit | d31242943a73aba0e5cfd0ea674b5e694b4a39e6 (patch) | |
tree | 8d0212c11c101233e2534a799da134d9ff07849e /drivers/media/video/adv7180.c | |
parent | e3c6e1aaa5db7822524f5b1355960fd732910068 (diff) |
V4L/DVB (13173): adv7180: Support for getting input status
This patch adds support to the ADV7180 driver to check the input
status.
Since the status is held in the same register as the input standard
a small restructuring of the code is done to reuse the code for
reading the register
Signed-off-by: Richard Röjfors <richard.rojfors@mocean-labs.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/video/adv7180.c')
-rw-r--r-- | drivers/media/video/adv7180.c | 66 |
1 files changed, 54 insertions, 12 deletions
diff --git a/drivers/media/video/adv7180.c b/drivers/media/video/adv7180.c index 1b3cbd02a7fd..f3fce398020a 100644 --- a/drivers/media/video/adv7180.c +++ b/drivers/media/video/adv7180.c | |||
@@ -30,14 +30,31 @@ | |||
30 | 30 | ||
31 | #define DRIVER_NAME "adv7180" | 31 | #define DRIVER_NAME "adv7180" |
32 | 32 | ||
33 | #define ADV7180_INPUT_CONTROL_REG 0x00 | 33 | #define ADV7180_INPUT_CONTROL_REG 0x00 |
34 | #define ADV7180_INPUT_CONTROL_PAL_BG_NTSC_J_SECAM 0x00 | 34 | #define ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM 0x00 |
35 | #define ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM_PED 0x10 | ||
36 | #define ADV7180_INPUT_CONTROL_AD_PAL_N_NTSC_J_SECAM 0x20 | ||
37 | #define ADV7180_INPUT_CONTROL_AD_PAL_N_NTSC_M_SECAM 0x30 | ||
38 | #define ADV7180_INPUT_CONTROL_NTSC_J 0x40 | ||
39 | #define ADV7180_INPUT_CONTROL_NTSC_M 0x50 | ||
40 | #define ADV7180_INPUT_CONTROL_PAL60 0x60 | ||
41 | #define ADV7180_INPUT_CONTROL_NTSC_443 0x70 | ||
42 | #define ADV7180_INPUT_CONTROL_PAL_BG 0x80 | ||
43 | #define ADV7180_INPUT_CONTROL_PAL_N 0x90 | ||
44 | #define ADV7180_INPUT_CONTROL_PAL_M 0xa0 | ||
45 | #define ADV7180_INPUT_CONTROL_PAL_M_PED 0xb0 | ||
46 | #define ADV7180_INPUT_CONTROL_PAL_COMB_N 0xc0 | ||
47 | #define ADV7180_INPUT_CONTROL_PAL_COMB_N_PED 0xd0 | ||
48 | #define ADV7180_INPUT_CONTROL_PAL_SECAM 0xe0 | ||
49 | #define ADV7180_INPUT_CONTROL_PAL_SECAM_PED 0xf0 | ||
50 | |||
35 | #define ADV7180_AUTODETECT_ENABLE_REG 0x07 | 51 | #define ADV7180_AUTODETECT_ENABLE_REG 0x07 |
36 | #define ADV7180_AUTODETECT_DEFAULT 0x7f | 52 | #define ADV7180_AUTODETECT_DEFAULT 0x7f |
37 | 53 | ||
38 | 54 | ||
39 | #define ADV7180_STATUS1_REG 0x10 | 55 | #define ADV7180_STATUS1_REG 0x10 |
40 | #define ADV7180_STATUS1_AUTOD_MASK 0x70 | 56 | #define ADV7180_STATUS1_IN_LOCK 0x01 |
57 | #define ADV7180_STATUS1_AUTOD_MASK 0x70 | ||
41 | #define ADV7180_STATUS1_AUTOD_NTSM_M_J 0x00 | 58 | #define ADV7180_STATUS1_AUTOD_NTSM_M_J 0x00 |
42 | #define ADV7180_STATUS1_AUTOD_NTSC_4_43 0x10 | 59 | #define ADV7180_STATUS1_AUTOD_NTSC_4_43 0x10 |
43 | #define ADV7180_STATUS1_AUTOD_PAL_M 0x20 | 60 | #define ADV7180_STATUS1_AUTOD_PAL_M 0x20 |
@@ -55,13 +72,11 @@ struct adv7180_state { | |||
55 | struct v4l2_subdev sd; | 72 | struct v4l2_subdev sd; |
56 | }; | 73 | }; |
57 | 74 | ||
58 | static v4l2_std_id determine_norm(struct i2c_client *client) | 75 | static v4l2_std_id adv7180_std_to_v4l2(u8 status1) |
59 | { | 76 | { |
60 | u8 status1 = i2c_smbus_read_byte_data(client, ADV7180_STATUS1_REG); | ||
61 | |||
62 | switch (status1 & ADV7180_STATUS1_AUTOD_MASK) { | 77 | switch (status1 & ADV7180_STATUS1_AUTOD_MASK) { |
63 | case ADV7180_STATUS1_AUTOD_NTSM_M_J: | 78 | case ADV7180_STATUS1_AUTOD_NTSM_M_J: |
64 | return V4L2_STD_NTSC_M_JP; | 79 | return V4L2_STD_NTSC; |
65 | case ADV7180_STATUS1_AUTOD_NTSC_4_43: | 80 | case ADV7180_STATUS1_AUTOD_NTSC_4_43: |
66 | return V4L2_STD_NTSC_443; | 81 | return V4L2_STD_NTSC_443; |
67 | case ADV7180_STATUS1_AUTOD_PAL_M: | 82 | case ADV7180_STATUS1_AUTOD_PAL_M: |
@@ -81,6 +96,30 @@ static v4l2_std_id determine_norm(struct i2c_client *client) | |||
81 | } | 96 | } |
82 | } | 97 | } |
83 | 98 | ||
99 | static u32 adv7180_status_to_v4l2(u8 status1) | ||
100 | { | ||
101 | if (!(status1 & ADV7180_STATUS1_IN_LOCK)) | ||
102 | return V4L2_IN_ST_NO_SIGNAL; | ||
103 | |||
104 | return 0; | ||
105 | } | ||
106 | |||
107 | static int __adv7180_status(struct i2c_client *client, u32 *status, | ||
108 | v4l2_std_id *std) | ||
109 | { | ||
110 | int status1 = i2c_smbus_read_byte_data(client, ADV7180_STATUS1_REG); | ||
111 | |||
112 | if (status1 < 0) | ||
113 | return status1; | ||
114 | |||
115 | if (status) | ||
116 | *status = adv7180_status_to_v4l2(status1); | ||
117 | if (std) | ||
118 | *std = adv7180_std_to_v4l2(status1); | ||
119 | |||
120 | return 0; | ||
121 | } | ||
122 | |||
84 | static inline struct adv7180_state *to_state(struct v4l2_subdev *sd) | 123 | static inline struct adv7180_state *to_state(struct v4l2_subdev *sd) |
85 | { | 124 | { |
86 | return container_of(sd, struct adv7180_state, sd); | 125 | return container_of(sd, struct adv7180_state, sd); |
@@ -88,10 +127,12 @@ static inline struct adv7180_state *to_state(struct v4l2_subdev *sd) | |||
88 | 127 | ||
89 | static int adv7180_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) | 128 | static int adv7180_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) |
90 | { | 129 | { |
91 | struct i2c_client *client = v4l2_get_subdevdata(sd); | 130 | return __adv7180_status(v4l2_get_subdevdata(sd), NULL, std); |
131 | } | ||
92 | 132 | ||
93 | *std = determine_norm(client); | 133 | static int adv7180_g_input_status(struct v4l2_subdev *sd, u32 *status) |
94 | return 0; | 134 | { |
135 | return __adv7180_status(v4l2_get_subdevdata(sd), status, NULL); | ||
95 | } | 136 | } |
96 | 137 | ||
97 | static int adv7180_g_chip_ident(struct v4l2_subdev *sd, | 138 | static int adv7180_g_chip_ident(struct v4l2_subdev *sd, |
@@ -104,6 +145,7 @@ static int adv7180_g_chip_ident(struct v4l2_subdev *sd, | |||
104 | 145 | ||
105 | static const struct v4l2_subdev_video_ops adv7180_video_ops = { | 146 | static const struct v4l2_subdev_video_ops adv7180_video_ops = { |
106 | .querystd = adv7180_querystd, | 147 | .querystd = adv7180_querystd, |
148 | .g_input_status = adv7180_g_input_status, | ||
107 | }; | 149 | }; |
108 | 150 | ||
109 | static const struct v4l2_subdev_core_ops adv7180_core_ops = { | 151 | static const struct v4l2_subdev_core_ops adv7180_core_ops = { |
@@ -143,7 +185,7 @@ static int adv7180_probe(struct i2c_client *client, | |||
143 | /* Initialize adv7180 */ | 185 | /* Initialize adv7180 */ |
144 | /* enable autodetection */ | 186 | /* enable autodetection */ |
145 | ret = i2c_smbus_write_byte_data(client, ADV7180_INPUT_CONTROL_REG, | 187 | ret = i2c_smbus_write_byte_data(client, ADV7180_INPUT_CONTROL_REG, |
146 | ADV7180_INPUT_CONTROL_PAL_BG_NTSC_J_SECAM); | 188 | ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM); |
147 | if (ret > 0) | 189 | if (ret > 0) |
148 | ret = i2c_smbus_write_byte_data(client, | 190 | ret = i2c_smbus_write_byte_data(client, |
149 | ADV7180_AUTODETECT_ENABLE_REG, | 191 | ADV7180_AUTODETECT_ENABLE_REG, |