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> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #include <linux/videodev.h> |
Mauro Carvalho Chehab | 18f3fa1 | 2007-07-02 15:39:57 -0300 | [diff] [blame] | 38 | #include <linux/video_encoder.h> |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 39 | #include <media/v4l2-common.h> |
| 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 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 46 | static int debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | module_param(debug, int, 0); |
| 48 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | /* ----------------------------------------------------------------------- */ |
| 51 | |
| 52 | struct adv7170 { |
| 53 | unsigned char reg[128]; |
| 54 | |
| 55 | int norm; |
| 56 | int input; |
| 57 | int enable; |
| 58 | int bright; |
| 59 | int contrast; |
| 60 | int hue; |
| 61 | int sat; |
| 62 | }; |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | static char *inputs[] = { "pass_through", "play_back" }; |
| 65 | static char *norms[] = { "PAL", "NTSC" }; |
| 66 | |
| 67 | /* ----------------------------------------------------------------------- */ |
| 68 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 69 | static inline int adv7170_write(struct i2c_client *client, u8 reg, u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | { |
| 71 | struct adv7170 *encoder = i2c_get_clientdata(client); |
| 72 | |
| 73 | encoder->reg[reg] = value; |
| 74 | return i2c_smbus_write_byte_data(client, reg, value); |
| 75 | } |
| 76 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 77 | static inline int adv7170_read(struct i2c_client *client, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | { |
| 79 | return i2c_smbus_read_byte_data(client, reg); |
| 80 | } |
| 81 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 82 | static int adv7170_write_block(struct i2c_client *client, |
| 83 | const u8 *data, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
| 85 | int ret = -1; |
| 86 | u8 reg; |
| 87 | |
| 88 | /* the adv7170 has an autoincrement function, use it if |
| 89 | * the adapter understands raw I2C */ |
| 90 | if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { |
| 91 | /* do raw I2C, not smbus compatible */ |
| 92 | struct adv7170 *encoder = i2c_get_clientdata(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | u8 block_data[32]; |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 94 | int block_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | while (len >= 2) { |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 97 | block_len = 0; |
| 98 | block_data[block_len++] = reg = data[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | do { |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 100 | block_data[block_len++] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | encoder->reg[reg++] = data[1]; |
| 102 | len -= 2; |
| 103 | data += 2; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 104 | } while (len >= 2 && data[0] == reg && block_len < 32); |
| 105 | ret = i2c_master_send(client, block_data, block_len); |
| 106 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | break; |
| 108 | } |
| 109 | } else { |
| 110 | /* do some slow I2C emulation kind of thing */ |
| 111 | while (len >= 2) { |
| 112 | reg = *data++; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 113 | ret = adv7170_write(client, reg, *data++); |
| 114 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | break; |
| 116 | len -= 2; |
| 117 | } |
| 118 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | return ret; |
| 120 | } |
| 121 | |
| 122 | /* ----------------------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | #define TR0MODE 0x4c |
| 125 | #define TR0RST 0x80 |
| 126 | |
| 127 | #define TR1CAPT 0x00 |
| 128 | #define TR1PLAY 0x00 |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | static const unsigned char init_NTSC[] = { |
| 131 | 0x00, 0x10, // MR0 |
| 132 | 0x01, 0x20, // MR1 |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 133 | 0x02, 0x0e, // MR2 RTC control: bits 2 and 1 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | 0x03, 0x80, // MR3 |
| 135 | 0x04, 0x30, // MR4 |
| 136 | 0x05, 0x00, // Reserved |
| 137 | 0x06, 0x00, // Reserved |
| 138 | 0x07, TR0MODE, // TM0 |
| 139 | 0x08, TR1CAPT, // TM1 |
| 140 | 0x09, 0x16, // Fsc0 |
| 141 | 0x0a, 0x7c, // Fsc1 |
| 142 | 0x0b, 0xf0, // Fsc2 |
| 143 | 0x0c, 0x21, // Fsc3 |
| 144 | 0x0d, 0x00, // Subcarrier Phase |
| 145 | 0x0e, 0x00, // Closed Capt. Ext 0 |
| 146 | 0x0f, 0x00, // Closed Capt. Ext 1 |
| 147 | 0x10, 0x00, // Closed Capt. 0 |
| 148 | 0x11, 0x00, // Closed Capt. 1 |
| 149 | 0x12, 0x00, // Pedestal Ctl 0 |
| 150 | 0x13, 0x00, // Pedestal Ctl 1 |
| 151 | 0x14, 0x00, // Pedestal Ctl 2 |
| 152 | 0x15, 0x00, // Pedestal Ctl 3 |
| 153 | 0x16, 0x00, // CGMS_WSS_0 |
| 154 | 0x17, 0x00, // CGMS_WSS_1 |
| 155 | 0x18, 0x00, // CGMS_WSS_2 |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 156 | 0x19, 0x00, // Teletext Ctl |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | static const unsigned char init_PAL[] = { |
| 160 | 0x00, 0x71, // MR0 |
| 161 | 0x01, 0x20, // MR1 |
| 162 | 0x02, 0x0e, // MR2 RTC control: bits 2 and 1 |
| 163 | 0x03, 0x80, // MR3 |
| 164 | 0x04, 0x30, // MR4 |
| 165 | 0x05, 0x00, // Reserved |
| 166 | 0x06, 0x00, // Reserved |
| 167 | 0x07, TR0MODE, // TM0 |
| 168 | 0x08, TR1CAPT, // TM1 |
| 169 | 0x09, 0xcb, // Fsc0 |
| 170 | 0x0a, 0x8a, // Fsc1 |
| 171 | 0x0b, 0x09, // Fsc2 |
| 172 | 0x0c, 0x2a, // Fsc3 |
| 173 | 0x0d, 0x00, // Subcarrier Phase |
| 174 | 0x0e, 0x00, // Closed Capt. Ext 0 |
| 175 | 0x0f, 0x00, // Closed Capt. Ext 1 |
| 176 | 0x10, 0x00, // Closed Capt. 0 |
| 177 | 0x11, 0x00, // Closed Capt. 1 |
| 178 | 0x12, 0x00, // Pedestal Ctl 0 |
| 179 | 0x13, 0x00, // Pedestal Ctl 1 |
| 180 | 0x14, 0x00, // Pedestal Ctl 2 |
| 181 | 0x15, 0x00, // Pedestal Ctl 3 |
| 182 | 0x16, 0x00, // CGMS_WSS_0 |
| 183 | 0x17, 0x00, // CGMS_WSS_1 |
| 184 | 0x18, 0x00, // CGMS_WSS_2 |
| 185 | 0x19, 0x00, // Teletext Ctl |
| 186 | }; |
| 187 | |
| 188 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 189 | static int adv7170_command(struct i2c_client *client, unsigned cmd, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
| 191 | struct adv7170 *encoder = i2c_get_clientdata(client); |
| 192 | |
| 193 | switch (cmd) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | case 0: |
| 195 | #if 0 |
| 196 | /* This is just for testing!!! */ |
| 197 | adv7170_write_block(client, init_common, |
| 198 | sizeof(init_common)); |
| 199 | adv7170_write(client, 0x07, TR0MODE | TR0RST); |
| 200 | adv7170_write(client, 0x07, TR0MODE); |
| 201 | #endif |
| 202 | break; |
| 203 | |
| 204 | case ENCODER_GET_CAPABILITIES: |
| 205 | { |
| 206 | struct video_encoder_capability *cap = arg; |
| 207 | |
| 208 | cap->flags = VIDEO_ENCODER_PAL | |
| 209 | VIDEO_ENCODER_NTSC; |
| 210 | cap->inputs = 2; |
| 211 | cap->outputs = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | break; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 213 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
| 215 | case ENCODER_SET_NORM: |
| 216 | { |
| 217 | int iarg = *(int *) arg; |
| 218 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 219 | v4l_dbg(1, debug, client, "set norm %d\n", iarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | switch (iarg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | case VIDEO_MODE_NTSC: |
| 223 | adv7170_write_block(client, init_NTSC, |
| 224 | sizeof(init_NTSC)); |
| 225 | if (encoder->input == 0) |
| 226 | adv7170_write(client, 0x02, 0x0e); // Enable genlock |
| 227 | adv7170_write(client, 0x07, TR0MODE | TR0RST); |
| 228 | adv7170_write(client, 0x07, TR0MODE); |
| 229 | break; |
| 230 | |
| 231 | case VIDEO_MODE_PAL: |
| 232 | adv7170_write_block(client, init_PAL, |
| 233 | sizeof(init_PAL)); |
| 234 | if (encoder->input == 0) |
| 235 | adv7170_write(client, 0x02, 0x0e); // Enable genlock |
| 236 | adv7170_write(client, 0x07, TR0MODE | TR0RST); |
| 237 | adv7170_write(client, 0x07, TR0MODE); |
| 238 | break; |
| 239 | |
| 240 | default: |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 241 | v4l_dbg(1, debug, client, "illegal norm: %d\n", iarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 244 | v4l_dbg(1, debug, client, "switched to %s\n", norms[iarg]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | encoder->norm = iarg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | break; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 247 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | case ENCODER_SET_INPUT: |
| 250 | { |
| 251 | int iarg = *(int *) arg; |
| 252 | |
| 253 | /* RJ: *iarg = 0: input is from decoder |
| 254 | *iarg = 1: input is from ZR36060 |
| 255 | *iarg = 2: color bar */ |
| 256 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 257 | v4l_dbg(1, debug, client, "set input from %s\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | iarg == 0 ? "decoder" : "ZR36060"); |
| 259 | |
| 260 | switch (iarg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | case 0: |
| 262 | adv7170_write(client, 0x01, 0x20); |
| 263 | adv7170_write(client, 0x08, TR1CAPT); /* TR1 */ |
| 264 | adv7170_write(client, 0x02, 0x0e); // Enable genlock |
| 265 | adv7170_write(client, 0x07, TR0MODE | TR0RST); |
| 266 | adv7170_write(client, 0x07, TR0MODE); |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 267 | /* udelay(10); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | break; |
| 269 | |
| 270 | case 1: |
| 271 | adv7170_write(client, 0x01, 0x00); |
| 272 | adv7170_write(client, 0x08, TR1PLAY); /* TR1 */ |
| 273 | adv7170_write(client, 0x02, 0x08); |
| 274 | adv7170_write(client, 0x07, TR0MODE | TR0RST); |
| 275 | adv7170_write(client, 0x07, TR0MODE); |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 276 | /* udelay(10); */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | break; |
| 278 | |
| 279 | default: |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 280 | v4l_dbg(1, debug, client, "illegal input: %d\n", iarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | } |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 283 | v4l_dbg(1, debug, client, "switched to %s\n", inputs[iarg]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | encoder->input = iarg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | break; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 286 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | |
| 288 | case ENCODER_SET_OUTPUT: |
| 289 | { |
| 290 | int *iarg = arg; |
| 291 | |
| 292 | /* not much choice of outputs */ |
| 293 | if (*iarg != 0) { |
| 294 | return -EINVAL; |
| 295 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | break; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 297 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | case ENCODER_ENABLE_OUTPUT: |
| 300 | { |
| 301 | int *iarg = arg; |
| 302 | |
| 303 | encoder->enable = !!*iarg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | break; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 305 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | |
| 307 | default: |
| 308 | return -EINVAL; |
| 309 | } |
| 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
| 314 | /* ----------------------------------------------------------------------- */ |
| 315 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 316 | static unsigned short normal_i2c[] = { |
| 317 | 0xd4 >> 1, 0xd6 >> 1, /* adv7170 IDs */ |
| 318 | 0x54 >> 1, 0x56 >> 1, /* adv7171 IDs */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | I2C_CLIENT_END |
| 320 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 322 | I2C_CLIENT_INSMOD; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 323 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 324 | static int adv7170_probe(struct i2c_client *client, |
| 325 | const struct i2c_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | struct adv7170 *encoder; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 328 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | /* Check if the adapter supports the needed features */ |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 331 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 332 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 334 | v4l_info(client, "chip found @ 0x%x (%s)\n", |
| 335 | client->addr << 1, client->adapter->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 336 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 337 | encoder = kzalloc(sizeof(struct adv7170), GFP_KERNEL); |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 338 | if (encoder == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | encoder->norm = VIDEO_MODE_NTSC; |
| 341 | encoder->input = 0; |
| 342 | encoder->enable = 1; |
| 343 | i2c_set_clientdata(client, encoder); |
| 344 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | i = adv7170_write_block(client, init_NTSC, sizeof(init_NTSC)); |
| 346 | if (i >= 0) { |
| 347 | i = adv7170_write(client, 0x07, TR0MODE | TR0RST); |
| 348 | i = adv7170_write(client, 0x07, TR0MODE); |
| 349 | i = adv7170_read(client, 0x12); |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 350 | v4l_dbg(1, debug, client, "revision %d\n", i & 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | } |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 352 | if (i < 0) |
| 353 | v4l_dbg(1, debug, client, "init error 0x%x\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | return 0; |
| 355 | } |
| 356 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 357 | static int adv7170_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | { |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 359 | kfree(i2c_get_clientdata(client)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | return 0; |
| 361 | } |
| 362 | |
| 363 | /* ----------------------------------------------------------------------- */ |
| 364 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 365 | static const struct i2c_device_id adv7170_id[] = { |
| 366 | { "adv7170", 0 }, |
| 367 | { "adv7171", 0 }, |
| 368 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | }; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 370 | MODULE_DEVICE_TABLE(i2c, adv7170_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 372 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
| 373 | .name = "adv7170", |
| 374 | .driverid = I2C_DRIVERID_ADV7170, |
| 375 | .command = adv7170_command, |
| 376 | .probe = adv7170_probe, |
| 377 | .remove = adv7170_remove, |
| 378 | .id_table = adv7170_id, |
| 379 | }; |