diff options
-rw-r--r-- | drivers/media/video/Kconfig | 9 | ||||
-rw-r--r-- | drivers/media/video/Makefile | 1 | ||||
-rw-r--r-- | drivers/media/video/adv7180.c | 202 | ||||
-rw-r--r-- | include/media/v4l2-chip-ident.h | 3 |
4 files changed, 215 insertions, 0 deletions
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig index dc71eaea6af8..e6186b338a12 100644 --- a/drivers/media/video/Kconfig +++ b/drivers/media/video/Kconfig | |||
@@ -265,6 +265,15 @@ config VIDEO_SAA6588 | |||
265 | 265 | ||
266 | comment "Video decoders" | 266 | comment "Video decoders" |
267 | 267 | ||
268 | config VIDEO_ADV7180 | ||
269 | tristate "Analog Devices ADV7180 decoder" | ||
270 | depends on VIDEO_V4L2 && I2C | ||
271 | ---help--- | ||
272 | Support for the Analog Devices ADV7180 video decoder. | ||
273 | |||
274 | To compile this driver as a module, choose M here: the | ||
275 | module will be called adv7180. | ||
276 | |||
268 | config VIDEO_BT819 | 277 | config VIDEO_BT819 |
269 | tristate "BT819A VideoStream decoder" | 278 | tristate "BT819A VideoStream decoder" |
270 | depends on VIDEO_V4L2 && I2C | 279 | depends on VIDEO_V4L2 && I2C |
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile index 040bc0492007..e541932a789b 100644 --- a/drivers/media/video/Makefile +++ b/drivers/media/video/Makefile | |||
@@ -45,6 +45,7 @@ obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o | |||
45 | obj-$(CONFIG_VIDEO_SAA7191) += saa7191.o | 45 | obj-$(CONFIG_VIDEO_SAA7191) += saa7191.o |
46 | obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o | 46 | obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o |
47 | obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o | 47 | obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o |
48 | obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o | ||
48 | obj-$(CONFIG_VIDEO_ADV7343) += adv7343.o | 49 | obj-$(CONFIG_VIDEO_ADV7343) += adv7343.o |
49 | obj-$(CONFIG_VIDEO_VPX3220) += vpx3220.o | 50 | obj-$(CONFIG_VIDEO_VPX3220) += vpx3220.o |
50 | obj-$(CONFIG_VIDEO_BT819) += bt819.o | 51 | obj-$(CONFIG_VIDEO_BT819) += bt819.o |
diff --git a/drivers/media/video/adv7180.c b/drivers/media/video/adv7180.c new file mode 100644 index 000000000000..1b3cbd02a7fd --- /dev/null +++ b/drivers/media/video/adv7180.c | |||
@@ -0,0 +1,202 @@ | |||
1 | /* | ||
2 | * adv7180.c Analog Devices ADV7180 video decoder driver | ||
3 | * Copyright (c) 2009 Intel Corporation | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License version 2 as | ||
7 | * published by the Free Software Foundation. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the Free Software | ||
16 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | ||
17 | */ | ||
18 | |||
19 | #include <linux/module.h> | ||
20 | #include <linux/init.h> | ||
21 | #include <linux/errno.h> | ||
22 | #include <linux/kernel.h> | ||
23 | #include <linux/interrupt.h> | ||
24 | #include <linux/i2c.h> | ||
25 | #include <linux/i2c-id.h> | ||
26 | #include <media/v4l2-ioctl.h> | ||
27 | #include <linux/videodev2.h> | ||
28 | #include <media/v4l2-device.h> | ||
29 | #include <media/v4l2-chip-ident.h> | ||
30 | |||
31 | #define DRIVER_NAME "adv7180" | ||
32 | |||
33 | #define ADV7180_INPUT_CONTROL_REG 0x00 | ||
34 | #define ADV7180_INPUT_CONTROL_PAL_BG_NTSC_J_SECAM 0x00 | ||
35 | #define ADV7180_AUTODETECT_ENABLE_REG 0x07 | ||
36 | #define ADV7180_AUTODETECT_DEFAULT 0x7f | ||
37 | |||
38 | |||
39 | #define ADV7180_STATUS1_REG 0x10 | ||
40 | #define ADV7180_STATUS1_AUTOD_MASK 0x70 | ||
41 | #define ADV7180_STATUS1_AUTOD_NTSM_M_J 0x00 | ||
42 | #define ADV7180_STATUS1_AUTOD_NTSC_4_43 0x10 | ||
43 | #define ADV7180_STATUS1_AUTOD_PAL_M 0x20 | ||
44 | #define ADV7180_STATUS1_AUTOD_PAL_60 0x30 | ||
45 | #define ADV7180_STATUS1_AUTOD_PAL_B_G 0x40 | ||
46 | #define ADV7180_STATUS1_AUTOD_SECAM 0x50 | ||
47 | #define ADV7180_STATUS1_AUTOD_PAL_COMB 0x60 | ||
48 | #define ADV7180_STATUS1_AUTOD_SECAM_525 0x70 | ||
49 | |||
50 | #define ADV7180_IDENT_REG 0x11 | ||
51 | #define ADV7180_ID_7180 0x18 | ||
52 | |||
53 | |||
54 | struct adv7180_state { | ||
55 | struct v4l2_subdev sd; | ||
56 | }; | ||
57 | |||
58 | static v4l2_std_id determine_norm(struct i2c_client *client) | ||
59 | { | ||
60 | u8 status1 = i2c_smbus_read_byte_data(client, ADV7180_STATUS1_REG); | ||
61 | |||
62 | switch (status1 & ADV7180_STATUS1_AUTOD_MASK) { | ||
63 | case ADV7180_STATUS1_AUTOD_NTSM_M_J: | ||
64 | return V4L2_STD_NTSC_M_JP; | ||
65 | case ADV7180_STATUS1_AUTOD_NTSC_4_43: | ||
66 | return V4L2_STD_NTSC_443; | ||
67 | case ADV7180_STATUS1_AUTOD_PAL_M: | ||
68 | return V4L2_STD_PAL_M; | ||
69 | case ADV7180_STATUS1_AUTOD_PAL_60: | ||
70 | return V4L2_STD_PAL_60; | ||
71 | case ADV7180_STATUS1_AUTOD_PAL_B_G: | ||
72 | return V4L2_STD_PAL; | ||
73 | case ADV7180_STATUS1_AUTOD_SECAM: | ||
74 | return V4L2_STD_SECAM; | ||
75 | case ADV7180_STATUS1_AUTOD_PAL_COMB: | ||
76 | return V4L2_STD_PAL_Nc | V4L2_STD_PAL_N; | ||
77 | case ADV7180_STATUS1_AUTOD_SECAM_525: | ||
78 | return V4L2_STD_SECAM; | ||
79 | default: | ||
80 | return V4L2_STD_UNKNOWN; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | static inline struct adv7180_state *to_state(struct v4l2_subdev *sd) | ||
85 | { | ||
86 | return container_of(sd, struct adv7180_state, sd); | ||
87 | } | ||
88 | |||
89 | static int adv7180_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) | ||
90 | { | ||
91 | struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
92 | |||
93 | *std = determine_norm(client); | ||
94 | return 0; | ||
95 | } | ||
96 | |||
97 | static int adv7180_g_chip_ident(struct v4l2_subdev *sd, | ||
98 | struct v4l2_dbg_chip_ident *chip) | ||
99 | { | ||
100 | struct i2c_client *client = v4l2_get_subdevdata(sd); | ||
101 | |||
102 | return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7180, 0); | ||
103 | } | ||
104 | |||
105 | static const struct v4l2_subdev_video_ops adv7180_video_ops = { | ||
106 | .querystd = adv7180_querystd, | ||
107 | }; | ||
108 | |||
109 | static const struct v4l2_subdev_core_ops adv7180_core_ops = { | ||
110 | .g_chip_ident = adv7180_g_chip_ident, | ||
111 | }; | ||
112 | |||
113 | static const struct v4l2_subdev_ops adv7180_ops = { | ||
114 | .core = &adv7180_core_ops, | ||
115 | .video = &adv7180_video_ops, | ||
116 | }; | ||
117 | |||
118 | /* | ||
119 | * Generic i2c probe | ||
120 | * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' | ||
121 | */ | ||
122 | |||
123 | static int adv7180_probe(struct i2c_client *client, | ||
124 | const struct i2c_device_id *id) | ||
125 | { | ||
126 | struct adv7180_state *state; | ||
127 | struct v4l2_subdev *sd; | ||
128 | int ret; | ||
129 | |||
130 | /* Check if the adapter supports the needed features */ | ||
131 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) | ||
132 | return -EIO; | ||
133 | |||
134 | v4l_info(client, "chip found @ 0x%02x (%s)\n", | ||
135 | client->addr << 1, client->adapter->name); | ||
136 | |||
137 | state = kzalloc(sizeof(struct adv7180_state), GFP_KERNEL); | ||
138 | if (state == NULL) | ||
139 | return -ENOMEM; | ||
140 | sd = &state->sd; | ||
141 | v4l2_i2c_subdev_init(sd, client, &adv7180_ops); | ||
142 | |||
143 | /* Initialize adv7180 */ | ||
144 | /* enable autodetection */ | ||
145 | ret = i2c_smbus_write_byte_data(client, ADV7180_INPUT_CONTROL_REG, | ||
146 | ADV7180_INPUT_CONTROL_PAL_BG_NTSC_J_SECAM); | ||
147 | if (ret > 0) | ||
148 | ret = i2c_smbus_write_byte_data(client, | ||
149 | ADV7180_AUTODETECT_ENABLE_REG, | ||
150 | ADV7180_AUTODETECT_DEFAULT); | ||
151 | if (ret < 0) { | ||
152 | printk(KERN_ERR DRIVER_NAME | ||
153 | ": Failed to communicate to chip: %d\n", ret); | ||
154 | return ret; | ||
155 | } | ||
156 | |||
157 | return 0; | ||
158 | } | ||
159 | |||
160 | static int adv7180_remove(struct i2c_client *client) | ||
161 | { | ||
162 | struct v4l2_subdev *sd = i2c_get_clientdata(client); | ||
163 | |||
164 | v4l2_device_unregister_subdev(sd); | ||
165 | kfree(to_state(sd)); | ||
166 | return 0; | ||
167 | } | ||
168 | |||
169 | static const struct i2c_device_id adv7180_id[] = { | ||
170 | {DRIVER_NAME, 0}, | ||
171 | {}, | ||
172 | }; | ||
173 | |||
174 | MODULE_DEVICE_TABLE(i2c, adv7180_id); | ||
175 | |||
176 | static struct i2c_driver adv7180_driver = { | ||
177 | .driver = { | ||
178 | .owner = THIS_MODULE, | ||
179 | .name = DRIVER_NAME, | ||
180 | }, | ||
181 | .probe = adv7180_probe, | ||
182 | .remove = adv7180_remove, | ||
183 | .id_table = adv7180_id, | ||
184 | }; | ||
185 | |||
186 | static __init int adv7180_init(void) | ||
187 | { | ||
188 | return i2c_add_driver(&adv7180_driver); | ||
189 | } | ||
190 | |||
191 | static __exit void adv7180_exit(void) | ||
192 | { | ||
193 | i2c_del_driver(&adv7180_driver); | ||
194 | } | ||
195 | |||
196 | module_init(adv7180_init); | ||
197 | module_exit(adv7180_exit); | ||
198 | |||
199 | MODULE_DESCRIPTION("Analog Devices ADV7180 video decoder driver"); | ||
200 | MODULE_AUTHOR("Mocean Laboratories"); | ||
201 | MODULE_LICENSE("GPL v2"); | ||
202 | |||
diff --git a/include/media/v4l2-chip-ident.h b/include/media/v4l2-chip-ident.h index 94e908c0d7a0..cf16689adba7 100644 --- a/include/media/v4l2-chip-ident.h +++ b/include/media/v4l2-chip-ident.h | |||
@@ -135,6 +135,9 @@ enum { | |||
135 | /* module adv7175: just ident 7175 */ | 135 | /* module adv7175: just ident 7175 */ |
136 | V4L2_IDENT_ADV7175 = 7175, | 136 | V4L2_IDENT_ADV7175 = 7175, |
137 | 137 | ||
138 | /* module adv7180: just ident 7180 */ | ||
139 | V4L2_IDENT_ADV7180 = 7180, | ||
140 | |||
138 | /* module saa7185: just ident 7185 */ | 141 | /* module saa7185: just ident 7185 */ |
139 | V4L2_IDENT_SAA7185 = 7185, | 142 | V4L2_IDENT_SAA7185 = 7185, |
140 | 143 | ||