aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorRichard Röjfors <richard.rojfors.ext@mocean-labs.com>2009-09-18 20:17:20 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2009-09-18 23:53:39 -0400
commit6789cb5230f8b06271b6a89ace20449af14be303 (patch)
tree1a1b7d5a0bb082a8fc1d2b68d57227a2be8fe4cd /drivers
parent40d2951758d788a0375d27062caf9cc75de735a9 (diff)
V4L/DVB (13019): video: initial support for ADV7180
This is an initial driver for Analog Devices ADV7180 Video Decoder. So far it only supports query standard. [akpm@linux-foundation.org: remove unneeded cast] Cc: Hans Verkuil <hverkuil@xs4all.nl> Signed-off-by: Richard Röjfors <richard.rojfors.ext@mocean-labs.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Douglas Schilling Landgraf <dougsland@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/video/Kconfig9
-rw-r--r--drivers/media/video/Makefile1
-rw-r--r--drivers/media/video/adv7180.c202
3 files changed, 212 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
266comment "Video decoders" 266comment "Video decoders"
267 267
268config 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
268config VIDEO_BT819 277config 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
45obj-$(CONFIG_VIDEO_SAA7191) += saa7191.o 45obj-$(CONFIG_VIDEO_SAA7191) += saa7191.o
46obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o 46obj-$(CONFIG_VIDEO_ADV7170) += adv7170.o
47obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o 47obj-$(CONFIG_VIDEO_ADV7175) += adv7175.o
48obj-$(CONFIG_VIDEO_ADV7180) += adv7180.o
48obj-$(CONFIG_VIDEO_ADV7343) += adv7343.o 49obj-$(CONFIG_VIDEO_ADV7343) += adv7343.o
49obj-$(CONFIG_VIDEO_VPX3220) += vpx3220.o 50obj-$(CONFIG_VIDEO_VPX3220) += vpx3220.o
50obj-$(CONFIG_VIDEO_BT819) += bt819.o 51obj-$(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
54struct adv7180_state {
55 struct v4l2_subdev sd;
56};
57
58static 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
84static inline struct adv7180_state *to_state(struct v4l2_subdev *sd)
85{
86 return container_of(sd, struct adv7180_state, sd);
87}
88
89static 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
97static 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
105static const struct v4l2_subdev_video_ops adv7180_video_ops = {
106 .querystd = adv7180_querystd,
107};
108
109static const struct v4l2_subdev_core_ops adv7180_core_ops = {
110 .g_chip_ident = adv7180_g_chip_ident,
111};
112
113static 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
123static 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
160static 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
169static const struct i2c_device_id adv7180_id[] = {
170 {DRIVER_NAME, 0},
171 {},
172};
173
174MODULE_DEVICE_TABLE(i2c, adv7180_id);
175
176static 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
186static __init int adv7180_init(void)
187{
188 return i2c_add_driver(&adv7180_driver);
189}
190
191static __exit void adv7180_exit(void)
192{
193 i2c_del_driver(&adv7180_driver);
194}
195
196module_init(adv7180_init);
197module_exit(adv7180_exit);
198
199MODULE_DESCRIPTION("Analog Devices ADV7180 video decoder driver");
200MODULE_AUTHOR("Mocean Laboratories");
201MODULE_LICENSE("GPL v2");
202