Full support for Ginger Console
[linux-ginger.git] / drivers / media / video / adv7180.c
blob1b3cbd02a7fd411bda6f7b248c2a5465443a53a6
1 /*
2 * adv7180.c Analog Devices ADV7180 video decoder driver
3 * Copyright (c) 2009 Intel Corporation
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.
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.
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.
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>
31 #define DRIVER_NAME "adv7180"
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
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
50 #define ADV7180_IDENT_REG 0x11
51 #define ADV7180_ID_7180 0x18
54 struct adv7180_state {
55 struct v4l2_subdev sd;
58 static v4l2_std_id determine_norm(struct i2c_client *client)
60 u8 status1 = i2c_smbus_read_byte_data(client, ADV7180_STATUS1_REG);
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;
84 static inline struct adv7180_state *to_state(struct v4l2_subdev *sd)
86 return container_of(sd, struct adv7180_state, sd);
89 static int adv7180_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
91 struct i2c_client *client = v4l2_get_subdevdata(sd);
93 *std = determine_norm(client);
94 return 0;
97 static int adv7180_g_chip_ident(struct v4l2_subdev *sd,
98 struct v4l2_dbg_chip_ident *chip)
100 struct i2c_client *client = v4l2_get_subdevdata(sd);
102 return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7180, 0);
105 static const struct v4l2_subdev_video_ops adv7180_video_ops = {
106 .querystd = adv7180_querystd,
109 static const struct v4l2_subdev_core_ops adv7180_core_ops = {
110 .g_chip_ident = adv7180_g_chip_ident,
113 static const struct v4l2_subdev_ops adv7180_ops = {
114 .core = &adv7180_core_ops,
115 .video = &adv7180_video_ops,
119 * Generic i2c probe
120 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
123 static int adv7180_probe(struct i2c_client *client,
124 const struct i2c_device_id *id)
126 struct adv7180_state *state;
127 struct v4l2_subdev *sd;
128 int ret;
130 /* Check if the adapter supports the needed features */
131 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
132 return -EIO;
134 v4l_info(client, "chip found @ 0x%02x (%s)\n",
135 client->addr << 1, client->adapter->name);
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);
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;
157 return 0;
160 static int adv7180_remove(struct i2c_client *client)
162 struct v4l2_subdev *sd = i2c_get_clientdata(client);
164 v4l2_device_unregister_subdev(sd);
165 kfree(to_state(sd));
166 return 0;
169 static const struct i2c_device_id adv7180_id[] = {
170 {DRIVER_NAME, 0},
174 MODULE_DEVICE_TABLE(i2c, adv7180_id);
176 static struct i2c_driver adv7180_driver = {
177 .driver = {
178 .owner = THIS_MODULE,
179 .name = DRIVER_NAME,
181 .probe = adv7180_probe,
182 .remove = adv7180_remove,
183 .id_table = adv7180_id,
186 static __init int adv7180_init(void)
188 return i2c_add_driver(&adv7180_driver);
191 static __exit void adv7180_exit(void)
193 i2c_del_driver(&adv7180_driver);
196 module_init(adv7180_init);
197 module_exit(adv7180_exit);
199 MODULE_DESCRIPTION("Analog Devices ADV7180 video decoder driver");
200 MODULE_AUTHOR("Mocean Laboratories");
201 MODULE_LICENSE("GPL v2");