Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * adv7170 - adv7170, adv7171 video encoder driver version 0.0.1 |
| 3 | * |
| 4 | * Copyright (C) 2002 Maxim Yevtyushkin <max@linuxmedialabs.com> |
| 5 | * |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 6 | * Based on adv7176 driver by: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * Copyright (C) 1998 Dave Perks <dperks@ibm.net> |
| 9 | * Copyright (C) 1999 Wolfgang Scherr <scherr@net4you.net> |
| 10 | * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx> |
| 11 | * - some corrections for Pinnacle Systems Inc. DC10plus card. |
| 12 | * |
| 13 | * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net> |
| 14 | * - moved over to linux>=2.4.x i2c protocol (1/1/2003) |
| 15 | * |
| 16 | * This program is free software; you can redistribute it and/or modify |
| 17 | * it under the terms of the GNU General Public License as published by |
| 18 | * the Free Software Foundation; either version 2 of the License, or |
| 19 | * (at your option) any later version. |
| 20 | * |
| 21 | * This program is distributed in the hope that it will be useful, |
| 22 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | * GNU General Public License for more details. |
| 25 | * |
| 26 | * You should have received a copy of the GNU General Public License |
| 27 | * along with this program; if not, write to the Free Software |
| 28 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 29 | */ |
| 30 | |
| 31 | #include <linux/module.h> |
Mauro Carvalho Chehab | 18f3fa1 | 2007-07-02 15:39:57 -0300 | [diff] [blame] | 32 | #include <linux/types.h> |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 33 | #include <linux/ioctl.h> |
Mauro Carvalho Chehab | 18f3fa1 | 2007-07-02 15:39:57 -0300 | [diff] [blame] | 34 | #include <asm/uaccess.h> |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 35 | #include <linux/i2c.h> |
| 36 | #include <linux/i2c-id.h> |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 37 | #include <linux/videodev2.h> |
| 38 | #include <media/v4l2-device.h> |
| 39 | #include <media/v4l2-chip-ident.h> |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 40 | #include <media/v4l2-i2c-drv-legacy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | |
| 42 | MODULE_DESCRIPTION("Analog Devices ADV7170 video encoder driver"); |
| 43 | MODULE_AUTHOR("Maxim Yevtyushkin"); |
| 44 | MODULE_LICENSE("GPL"); |
| 45 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 46 | static unsigned short normal_i2c[] = { |
| 47 | 0xd4 >> 1, 0xd6 >> 1, /* adv7170 IDs */ |
| 48 | 0x54 >> 1, 0x56 >> 1, /* adv7171 IDs */ |
| 49 | I2C_CLIENT_END |
| 50 | }; |
| 51 | |
| 52 | I2C_CLIENT_INSMOD; |
| 53 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 54 | static int debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | module_param(debug, int, 0); |
| 56 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); |
| 57 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | /* ----------------------------------------------------------------------- */ |
| 59 | |
| 60 | struct adv7170 { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 61 | struct v4l2_subdev sd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | unsigned char reg[128]; |
| 63 | |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 64 | v4l2_std_id norm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | int input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 68 | static inline struct adv7170 *to_adv7170(struct v4l2_subdev *sd) |
| 69 | { |
| 70 | return container_of(sd, struct adv7170, sd); |
| 71 | } |
| 72 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | static char *inputs[] = { "pass_through", "play_back" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | /* ----------------------------------------------------------------------- */ |
| 76 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 77 | static inline int adv7170_write(struct v4l2_subdev *sd, u8 reg, u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 79 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 80 | struct adv7170 *encoder = to_adv7170(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
| 82 | encoder->reg[reg] = value; |
| 83 | return i2c_smbus_write_byte_data(client, reg, value); |
| 84 | } |
| 85 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 86 | static inline int adv7170_read(struct v4l2_subdev *sd, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 88 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 89 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | return i2c_smbus_read_byte_data(client, reg); |
| 91 | } |
| 92 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 93 | static int adv7170_write_block(struct v4l2_subdev *sd, |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 94 | const u8 *data, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 96 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 97 | struct adv7170 *encoder = to_adv7170(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | int ret = -1; |
| 99 | u8 reg; |
| 100 | |
| 101 | /* the adv7170 has an autoincrement function, use it if |
| 102 | * the adapter understands raw I2C */ |
| 103 | if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { |
| 104 | /* do raw I2C, not smbus compatible */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | u8 block_data[32]; |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 106 | int block_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | while (len >= 2) { |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 109 | block_len = 0; |
| 110 | block_data[block_len++] = reg = data[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | do { |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 112 | block_data[block_len++] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | encoder->reg[reg++] = data[1]; |
| 114 | len -= 2; |
| 115 | data += 2; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 116 | } while (len >= 2 && data[0] == reg && block_len < 32); |
| 117 | ret = i2c_master_send(client, block_data, block_len); |
| 118 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | break; |
| 120 | } |
| 121 | } else { |
| 122 | /* do some slow I2C emulation kind of thing */ |
| 123 | while (len >= 2) { |
| 124 | reg = *data++; |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 125 | ret = adv7170_write(sd, reg, *data++); |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 126 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | break; |
| 128 | len -= 2; |
| 129 | } |
| 130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | return ret; |
| 132 | } |
| 133 | |
| 134 | /* ----------------------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | #define TR0MODE 0x4c |
| 137 | #define TR0RST 0x80 |
| 138 | |
| 139 | #define TR1CAPT 0x00 |
| 140 | #define TR1PLAY 0x00 |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | static const unsigned char init_NTSC[] = { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 143 | 0x00, 0x10, /* MR0 */ |
| 144 | 0x01, 0x20, /* MR1 */ |
| 145 | 0x02, 0x0e, /* MR2 RTC control: bits 2 and 1 */ |
| 146 | 0x03, 0x80, /* MR3 */ |
| 147 | 0x04, 0x30, /* MR4 */ |
| 148 | 0x05, 0x00, /* Reserved */ |
| 149 | 0x06, 0x00, /* Reserved */ |
| 150 | 0x07, TR0MODE, /* TM0 */ |
| 151 | 0x08, TR1CAPT, /* TM1 */ |
| 152 | 0x09, 0x16, /* Fsc0 */ |
| 153 | 0x0a, 0x7c, /* Fsc1 */ |
| 154 | 0x0b, 0xf0, /* Fsc2 */ |
| 155 | 0x0c, 0x21, /* Fsc3 */ |
| 156 | 0x0d, 0x00, /* Subcarrier Phase */ |
| 157 | 0x0e, 0x00, /* Closed Capt. Ext 0 */ |
| 158 | 0x0f, 0x00, /* Closed Capt. Ext 1 */ |
| 159 | 0x10, 0x00, /* Closed Capt. 0 */ |
| 160 | 0x11, 0x00, /* Closed Capt. 1 */ |
| 161 | 0x12, 0x00, /* Pedestal Ctl 0 */ |
| 162 | 0x13, 0x00, /* Pedestal Ctl 1 */ |
| 163 | 0x14, 0x00, /* Pedestal Ctl 2 */ |
| 164 | 0x15, 0x00, /* Pedestal Ctl 3 */ |
| 165 | 0x16, 0x00, /* CGMS_WSS_0 */ |
| 166 | 0x17, 0x00, /* CGMS_WSS_1 */ |
| 167 | 0x18, 0x00, /* CGMS_WSS_2 */ |
| 168 | 0x19, 0x00, /* Teletext Ctl */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | }; |
| 170 | |
| 171 | static const unsigned char init_PAL[] = { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 172 | 0x00, 0x71, /* MR0 */ |
| 173 | 0x01, 0x20, /* MR1 */ |
| 174 | 0x02, 0x0e, /* MR2 RTC control: bits 2 and 1 */ |
| 175 | 0x03, 0x80, /* MR3 */ |
| 176 | 0x04, 0x30, /* MR4 */ |
| 177 | 0x05, 0x00, /* Reserved */ |
| 178 | 0x06, 0x00, /* Reserved */ |
| 179 | 0x07, TR0MODE, /* TM0 */ |
| 180 | 0x08, TR1CAPT, /* TM1 */ |
| 181 | 0x09, 0xcb, /* Fsc0 */ |
| 182 | 0x0a, 0x8a, /* Fsc1 */ |
| 183 | 0x0b, 0x09, /* Fsc2 */ |
| 184 | 0x0c, 0x2a, /* Fsc3 */ |
| 185 | 0x0d, 0x00, /* Subcarrier Phase */ |
| 186 | 0x0e, 0x00, /* Closed Capt. Ext 0 */ |
| 187 | 0x0f, 0x00, /* Closed Capt. Ext 1 */ |
| 188 | 0x10, 0x00, /* Closed Capt. 0 */ |
| 189 | 0x11, 0x00, /* Closed Capt. 1 */ |
| 190 | 0x12, 0x00, /* Pedestal Ctl 0 */ |
| 191 | 0x13, 0x00, /* Pedestal Ctl 1 */ |
| 192 | 0x14, 0x00, /* Pedestal Ctl 2 */ |
| 193 | 0x15, 0x00, /* Pedestal Ctl 3 */ |
| 194 | 0x16, 0x00, /* CGMS_WSS_0 */ |
| 195 | 0x17, 0x00, /* CGMS_WSS_1 */ |
| 196 | 0x18, 0x00, /* CGMS_WSS_2 */ |
| 197 | 0x19, 0x00, /* Teletext Ctl */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | }; |
| 199 | |
| 200 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 201 | static int adv7170_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 203 | struct adv7170 *encoder = to_adv7170(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 205 | v4l2_dbg(1, debug, sd, "set norm %llx\n", std); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 207 | if (std & V4L2_STD_NTSC) { |
| 208 | adv7170_write_block(sd, init_NTSC, sizeof(init_NTSC)); |
| 209 | if (encoder->input == 0) |
| 210 | adv7170_write(sd, 0x02, 0x0e); /* Enable genlock */ |
| 211 | adv7170_write(sd, 0x07, TR0MODE | TR0RST); |
| 212 | adv7170_write(sd, 0x07, TR0MODE); |
| 213 | } else if (std & V4L2_STD_PAL) { |
| 214 | adv7170_write_block(sd, init_PAL, sizeof(init_PAL)); |
| 215 | if (encoder->input == 0) |
| 216 | adv7170_write(sd, 0x02, 0x0e); /* Enable genlock */ |
| 217 | adv7170_write(sd, 0x07, TR0MODE | TR0RST); |
| 218 | adv7170_write(sd, 0x07, TR0MODE); |
| 219 | } else { |
| 220 | v4l2_dbg(1, debug, sd, "illegal norm: %llx\n", std); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | return -EINVAL; |
| 222 | } |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 223 | v4l2_dbg(1, debug, sd, "switched to %llx\n", std); |
| 224 | encoder->norm = std; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | return 0; |
| 226 | } |
| 227 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 228 | static int adv7170_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route) |
| 229 | { |
| 230 | struct adv7170 *encoder = to_adv7170(sd); |
| 231 | |
| 232 | /* RJ: route->input = 0: input is from decoder |
| 233 | route->input = 1: input is from ZR36060 |
| 234 | route->input = 2: color bar */ |
| 235 | |
| 236 | v4l2_dbg(1, debug, sd, "set input from %s\n", |
| 237 | route->input == 0 ? "decoder" : "ZR36060"); |
| 238 | |
| 239 | switch (route->input) { |
| 240 | case 0: |
| 241 | adv7170_write(sd, 0x01, 0x20); |
| 242 | adv7170_write(sd, 0x08, TR1CAPT); /* TR1 */ |
| 243 | adv7170_write(sd, 0x02, 0x0e); /* Enable genlock */ |
| 244 | adv7170_write(sd, 0x07, TR0MODE | TR0RST); |
| 245 | adv7170_write(sd, 0x07, TR0MODE); |
| 246 | /* udelay(10); */ |
| 247 | break; |
| 248 | |
| 249 | case 1: |
| 250 | adv7170_write(sd, 0x01, 0x00); |
| 251 | adv7170_write(sd, 0x08, TR1PLAY); /* TR1 */ |
| 252 | adv7170_write(sd, 0x02, 0x08); |
| 253 | adv7170_write(sd, 0x07, TR0MODE | TR0RST); |
| 254 | adv7170_write(sd, 0x07, TR0MODE); |
| 255 | /* udelay(10); */ |
| 256 | break; |
| 257 | |
| 258 | default: |
| 259 | v4l2_dbg(1, debug, sd, "illegal input: %d\n", route->input); |
| 260 | return -EINVAL; |
| 261 | } |
| 262 | v4l2_dbg(1, debug, sd, "switched to %s\n", inputs[route->input]); |
| 263 | encoder->input = route->input; |
| 264 | return 0; |
| 265 | } |
| 266 | |
| 267 | static int adv7170_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) |
| 268 | { |
| 269 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 270 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 271 | return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7170, 0); |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | static int adv7170_command(struct i2c_client *client, unsigned cmd, void *arg) |
| 275 | { |
| 276 | return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg); |
| 277 | } |
| 278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | /* ----------------------------------------------------------------------- */ |
| 280 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 281 | static const struct v4l2_subdev_core_ops adv7170_core_ops = { |
| 282 | .g_chip_ident = adv7170_g_chip_ident, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 285 | static const struct v4l2_subdev_video_ops adv7170_video_ops = { |
| 286 | .s_std_output = adv7170_s_std_output, |
| 287 | .s_routing = adv7170_s_routing, |
| 288 | }; |
| 289 | |
| 290 | static const struct v4l2_subdev_ops adv7170_ops = { |
| 291 | .core = &adv7170_core_ops, |
| 292 | .video = &adv7170_video_ops, |
| 293 | }; |
| 294 | |
| 295 | /* ----------------------------------------------------------------------- */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 296 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 297 | static int adv7170_probe(struct i2c_client *client, |
| 298 | const struct i2c_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | struct adv7170 *encoder; |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 301 | struct v4l2_subdev *sd; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 302 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | |
| 304 | /* Check if the adapter supports the needed features */ |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 305 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 306 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 308 | v4l_info(client, "chip found @ 0x%x (%s)\n", |
| 309 | client->addr << 1, client->adapter->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 311 | encoder = kzalloc(sizeof(struct adv7170), GFP_KERNEL); |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 312 | if (encoder == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | return -ENOMEM; |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 314 | sd = &encoder->sd; |
| 315 | v4l2_i2c_subdev_init(sd, client, &adv7170_ops); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 316 | encoder->norm = V4L2_STD_NTSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | encoder->input = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 319 | i = adv7170_write_block(sd, init_NTSC, sizeof(init_NTSC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | if (i >= 0) { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 321 | i = adv7170_write(sd, 0x07, TR0MODE | TR0RST); |
| 322 | i = adv7170_write(sd, 0x07, TR0MODE); |
| 323 | i = adv7170_read(sd, 0x12); |
| 324 | v4l2_dbg(1, debug, sd, "revision %d\n", i & 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | } |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 326 | if (i < 0) |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 327 | v4l2_dbg(1, debug, sd, "init error 0x%x\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 331 | static int adv7170_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 333 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
| 334 | |
| 335 | v4l2_device_unregister_subdev(sd); |
| 336 | kfree(to_adv7170(sd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | /* ----------------------------------------------------------------------- */ |
| 341 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 342 | static const struct i2c_device_id adv7170_id[] = { |
| 343 | { "adv7170", 0 }, |
| 344 | { "adv7171", 0 }, |
| 345 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | }; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 347 | MODULE_DEVICE_TABLE(i2c, adv7170_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 349 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
| 350 | .name = "adv7170", |
| 351 | .driverid = I2C_DRIVERID_ADV7170, |
| 352 | .command = adv7170_command, |
| 353 | .probe = adv7170_probe, |
| 354 | .remove = adv7170_remove, |
| 355 | .id_table = adv7170_id, |
| 356 | }; |