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 | * adv7175 - adv7175a video encoder driver version 0.0.3 |
| 3 | * |
| 4 | * Copyright (C) 1998 Dave Perks <dperks@ibm.net> |
| 5 | * Copyright (C) 1999 Wolfgang Scherr <scherr@net4you.net> |
| 6 | * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx> |
| 7 | * - some corrections for Pinnacle Systems Inc. DC10plus card. |
| 8 | * |
| 9 | * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net> |
| 10 | * - moved over to linux>=2.4.x i2c protocol (9/9/2002) |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 25 | */ |
| 26 | |
| 27 | #include <linux/module.h> |
Mauro Carvalho Chehab | 18f3fa1 | 2007-07-02 15:39:57 -0300 | [diff] [blame] | 28 | #include <linux/types.h> |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 29 | #include <linux/ioctl.h> |
Mauro Carvalho Chehab | 18f3fa1 | 2007-07-02 15:39:57 -0300 | [diff] [blame] | 30 | #include <asm/uaccess.h> |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 31 | #include <linux/i2c.h> |
| 32 | #include <linux/i2c-id.h> |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 33 | #include <linux/videodev2.h> |
| 34 | #include <media/v4l2-device.h> |
| 35 | #include <media/v4l2-chip-ident.h> |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 36 | #include <media/v4l2-i2c-drv-legacy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | MODULE_DESCRIPTION("Analog Devices ADV7175 video encoder driver"); |
| 39 | MODULE_AUTHOR("Dave Perks"); |
| 40 | MODULE_LICENSE("GPL"); |
| 41 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 42 | #define I2C_ADV7175 0xd4 |
| 43 | #define I2C_ADV7176 0x54 |
| 44 | |
| 45 | static unsigned short normal_i2c[] = { |
| 46 | I2C_ADV7175 >> 1, (I2C_ADV7175 >> 1) + 1, |
| 47 | I2C_ADV7176 >> 1, (I2C_ADV7176 >> 1) + 1, |
| 48 | I2C_CLIENT_END |
| 49 | }; |
| 50 | |
| 51 | I2C_CLIENT_INSMOD; |
| 52 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 53 | static int debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | module_param(debug, int, 0); |
| 55 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); |
| 56 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | /* ----------------------------------------------------------------------- */ |
| 58 | |
| 59 | struct adv7175 { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 60 | struct v4l2_subdev sd; |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 61 | v4l2_std_id norm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | int input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | }; |
| 64 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 65 | static inline struct adv7175 *to_adv7175(struct v4l2_subdev *sd) |
| 66 | { |
| 67 | return container_of(sd, struct adv7175, sd); |
| 68 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | static char *inputs[] = { "pass_through", "play_back", "color_bar" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | /* ----------------------------------------------------------------------- */ |
| 73 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 74 | static inline int adv7175_write(struct v4l2_subdev *sd, u8 reg, u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 76 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 77 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | return i2c_smbus_write_byte_data(client, reg, value); |
| 79 | } |
| 80 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 81 | static inline int adv7175_read(struct v4l2_subdev *sd, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 83 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | return i2c_smbus_read_byte_data(client, reg); |
| 86 | } |
| 87 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 88 | static int adv7175_write_block(struct v4l2_subdev *sd, |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 89 | const u8 *data, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 91 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | int ret = -1; |
| 93 | u8 reg; |
| 94 | |
| 95 | /* the adv7175 has an autoincrement function, use it if |
| 96 | * the adapter understands raw I2C */ |
| 97 | if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { |
| 98 | /* do raw I2C, not smbus compatible */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | u8 block_data[32]; |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 100 | int block_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | while (len >= 2) { |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 103 | block_len = 0; |
| 104 | block_data[block_len++] = reg = data[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | do { |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 106 | block_data[block_len++] = data[1]; |
Jean Delvare | 2467a67 | 2006-03-22 03:48:34 -0300 | [diff] [blame] | 107 | reg++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | len -= 2; |
| 109 | data += 2; |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 110 | } while (len >= 2 && data[0] == reg && block_len < 32); |
| 111 | ret = i2c_master_send(client, block_data, block_len); |
| 112 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | break; |
| 114 | } |
| 115 | } else { |
| 116 | /* do some slow I2C emulation kind of thing */ |
| 117 | while (len >= 2) { |
| 118 | reg = *data++; |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 119 | ret = adv7175_write(sd, reg, *data++); |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 120 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | break; |
| 122 | len -= 2; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | return ret; |
| 127 | } |
| 128 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 129 | static void set_subcarrier_freq(struct v4l2_subdev *sd, int pass_through) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | { |
| 131 | /* for some reason pass_through NTSC needs |
| 132 | * a different sub-carrier freq to remain stable. */ |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 133 | if (pass_through) |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 134 | adv7175_write(sd, 0x02, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | else |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 136 | adv7175_write(sd, 0x02, 0x55); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 138 | adv7175_write(sd, 0x03, 0x55); |
| 139 | adv7175_write(sd, 0x04, 0x55); |
| 140 | adv7175_write(sd, 0x05, 0x25); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | } |
| 142 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | /* ----------------------------------------------------------------------- */ |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 144 | /* Output filter: S-Video Composite */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 146 | #define MR050 0x11 /* 0x09 */ |
| 147 | #define MR060 0x14 /* 0x0c */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 149 | /* ----------------------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
| 151 | #define TR0MODE 0x46 |
| 152 | #define TR0RST 0x80 |
| 153 | |
| 154 | #define TR1CAPT 0x80 |
| 155 | #define TR1PLAY 0x00 |
| 156 | |
| 157 | static const unsigned char init_common[] = { |
| 158 | |
| 159 | 0x00, MR050, /* MR0, PAL enabled */ |
| 160 | 0x01, 0x00, /* MR1 */ |
| 161 | 0x02, 0x0c, /* subc. freq. */ |
| 162 | 0x03, 0x8c, /* subc. freq. */ |
| 163 | 0x04, 0x79, /* subc. freq. */ |
| 164 | 0x05, 0x26, /* subc. freq. */ |
| 165 | 0x06, 0x40, /* subc. phase */ |
| 166 | |
| 167 | 0x07, TR0MODE, /* TR0, 16bit */ |
| 168 | 0x08, 0x21, /* */ |
| 169 | 0x09, 0x00, /* */ |
| 170 | 0x0a, 0x00, /* */ |
| 171 | 0x0b, 0x00, /* */ |
| 172 | 0x0c, TR1CAPT, /* TR1 */ |
| 173 | 0x0d, 0x4f, /* MR2 */ |
| 174 | 0x0e, 0x00, /* */ |
| 175 | 0x0f, 0x00, /* */ |
| 176 | 0x10, 0x00, /* */ |
| 177 | 0x11, 0x00, /* */ |
| 178 | }; |
| 179 | |
| 180 | static const unsigned char init_pal[] = { |
| 181 | 0x00, MR050, /* MR0, PAL enabled */ |
| 182 | 0x01, 0x00, /* MR1 */ |
| 183 | 0x02, 0x0c, /* subc. freq. */ |
| 184 | 0x03, 0x8c, /* subc. freq. */ |
| 185 | 0x04, 0x79, /* subc. freq. */ |
| 186 | 0x05, 0x26, /* subc. freq. */ |
| 187 | 0x06, 0x40, /* subc. phase */ |
| 188 | }; |
| 189 | |
| 190 | static const unsigned char init_ntsc[] = { |
| 191 | 0x00, MR060, /* MR0, NTSC enabled */ |
| 192 | 0x01, 0x00, /* MR1 */ |
| 193 | 0x02, 0x55, /* subc. freq. */ |
| 194 | 0x03, 0x55, /* subc. freq. */ |
| 195 | 0x04, 0x55, /* subc. freq. */ |
| 196 | 0x05, 0x25, /* subc. freq. */ |
| 197 | 0x06, 0x1a, /* subc. phase */ |
| 198 | }; |
| 199 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 200 | static int adv7175_init(struct v4l2_subdev *sd, u32 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 202 | /* This is just for testing!!! */ |
| 203 | adv7175_write_block(sd, init_common, sizeof(init_common)); |
| 204 | adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 205 | adv7175_write(sd, 0x07, TR0MODE); |
| 206 | return 0; |
| 207 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 209 | static int adv7175_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std) |
| 210 | { |
| 211 | struct adv7175 *encoder = to_adv7175(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 213 | if (std & V4L2_STD_NTSC) { |
| 214 | adv7175_write_block(sd, init_ntsc, sizeof(init_ntsc)); |
| 215 | if (encoder->input == 0) |
| 216 | adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */ |
| 217 | adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 218 | adv7175_write(sd, 0x07, TR0MODE); |
| 219 | } else if (std & V4L2_STD_PAL) { |
| 220 | adv7175_write_block(sd, init_pal, sizeof(init_pal)); |
| 221 | if (encoder->input == 0) |
| 222 | adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */ |
| 223 | adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 224 | adv7175_write(sd, 0x07, TR0MODE); |
| 225 | } else if (std & V4L2_STD_SECAM) { |
| 226 | /* This is an attempt to convert |
| 227 | * SECAM->PAL (typically it does not work |
| 228 | * due to genlock: when decoder is in SECAM |
| 229 | * and encoder in in PAL the subcarrier can |
| 230 | * not be syncronized with horizontal |
| 231 | * quency) */ |
| 232 | adv7175_write_block(sd, init_pal, sizeof(init_pal)); |
| 233 | if (encoder->input == 0) |
| 234 | adv7175_write(sd, 0x0d, 0x49); /* Disable genlock */ |
| 235 | adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 236 | adv7175_write(sd, 0x07, TR0MODE); |
| 237 | } else { |
| 238 | v4l2_dbg(1, debug, sd, "illegal norm: %llx\n", std); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | return -EINVAL; |
| 240 | } |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 241 | v4l2_dbg(1, debug, sd, "switched to %llx\n", std); |
| 242 | encoder->norm = std; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | return 0; |
| 244 | } |
| 245 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 246 | static int adv7175_s_routing(struct v4l2_subdev *sd, const struct v4l2_routing *route) |
| 247 | { |
| 248 | struct adv7175 *encoder = to_adv7175(sd); |
| 249 | |
| 250 | /* RJ: route->input = 0: input is from decoder |
| 251 | route->input = 1: input is from ZR36060 |
| 252 | route->input = 2: color bar */ |
| 253 | |
| 254 | switch (route->input) { |
| 255 | case 0: |
| 256 | adv7175_write(sd, 0x01, 0x00); |
| 257 | |
| 258 | if (encoder->norm & V4L2_STD_NTSC) |
| 259 | set_subcarrier_freq(sd, 1); |
| 260 | |
| 261 | adv7175_write(sd, 0x0c, TR1CAPT); /* TR1 */ |
| 262 | if (encoder->norm & V4L2_STD_SECAM) |
| 263 | adv7175_write(sd, 0x0d, 0x49); /* Disable genlock */ |
| 264 | else |
| 265 | adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */ |
| 266 | adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 267 | adv7175_write(sd, 0x07, TR0MODE); |
| 268 | /*udelay(10);*/ |
| 269 | break; |
| 270 | |
| 271 | case 1: |
| 272 | adv7175_write(sd, 0x01, 0x00); |
| 273 | |
| 274 | if (encoder->norm & V4L2_STD_NTSC) |
| 275 | set_subcarrier_freq(sd, 0); |
| 276 | |
| 277 | adv7175_write(sd, 0x0c, TR1PLAY); /* TR1 */ |
| 278 | adv7175_write(sd, 0x0d, 0x49); |
| 279 | adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 280 | adv7175_write(sd, 0x07, TR0MODE); |
| 281 | /* udelay(10); */ |
| 282 | break; |
| 283 | |
| 284 | case 2: |
| 285 | adv7175_write(sd, 0x01, 0x80); |
| 286 | |
| 287 | if (encoder->norm & V4L2_STD_NTSC) |
| 288 | set_subcarrier_freq(sd, 0); |
| 289 | |
| 290 | adv7175_write(sd, 0x0d, 0x49); |
| 291 | adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 292 | adv7175_write(sd, 0x07, TR0MODE); |
| 293 | /* udelay(10); */ |
| 294 | break; |
| 295 | |
| 296 | default: |
| 297 | v4l2_dbg(1, debug, sd, "illegal input: %d\n", route->input); |
| 298 | return -EINVAL; |
| 299 | } |
| 300 | v4l2_dbg(1, debug, sd, "switched to %s\n", inputs[route->input]); |
| 301 | encoder->input = route->input; |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | static int adv7175_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) |
| 306 | { |
| 307 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 308 | |
| 309 | return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7175, 0); |
| 310 | } |
| 311 | |
| 312 | static int adv7175_command(struct i2c_client *client, unsigned cmd, void *arg) |
| 313 | { |
| 314 | return v4l2_subdev_command(i2c_get_clientdata(client), cmd, arg); |
| 315 | } |
| 316 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | /* ----------------------------------------------------------------------- */ |
| 318 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 319 | static const struct v4l2_subdev_core_ops adv7175_core_ops = { |
| 320 | .g_chip_ident = adv7175_g_chip_ident, |
| 321 | .init = adv7175_init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 324 | static const struct v4l2_subdev_video_ops adv7175_video_ops = { |
| 325 | .s_std_output = adv7175_s_std_output, |
| 326 | .s_routing = adv7175_s_routing, |
| 327 | }; |
| 328 | |
| 329 | static const struct v4l2_subdev_ops adv7175_ops = { |
| 330 | .core = &adv7175_core_ops, |
| 331 | .video = &adv7175_video_ops, |
| 332 | }; |
| 333 | |
| 334 | /* ----------------------------------------------------------------------- */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 335 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 336 | static int adv7175_probe(struct i2c_client *client, |
| 337 | const struct i2c_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | { |
| 339 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | struct adv7175 *encoder; |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 341 | struct v4l2_subdev *sd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | /* Check if the adapter supports the needed features */ |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 344 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 345 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 346 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 347 | v4l_info(client, "chip found @ 0x%x (%s)\n", |
| 348 | client->addr << 1, client->adapter->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 350 | encoder = kzalloc(sizeof(struct adv7175), GFP_KERNEL); |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 351 | if (encoder == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | return -ENOMEM; |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 353 | sd = &encoder->sd; |
| 354 | v4l2_i2c_subdev_init(sd, client, &adv7175_ops); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 355 | encoder->norm = V4L2_STD_NTSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | encoder->input = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 358 | i = adv7175_write_block(sd, init_common, sizeof(init_common)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | if (i >= 0) { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 360 | i = adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 361 | i = adv7175_write(sd, 0x07, TR0MODE); |
| 362 | i = adv7175_read(sd, 0x12); |
| 363 | v4l2_dbg(1, debug, sd, "revision %d\n", i & 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | } |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 365 | if (i < 0) |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 366 | v4l2_dbg(1, debug, sd, "init error 0x%x\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | return 0; |
| 368 | } |
| 369 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 370 | static int adv7175_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame^] | 372 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
| 373 | |
| 374 | v4l2_device_unregister_subdev(sd); |
| 375 | kfree(to_adv7175(sd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | return 0; |
| 377 | } |
| 378 | |
| 379 | /* ----------------------------------------------------------------------- */ |
| 380 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 381 | static const struct i2c_device_id adv7175_id[] = { |
| 382 | { "adv7175", 0 }, |
| 383 | { "adv7176", 0 }, |
| 384 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | }; |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 386 | MODULE_DEVICE_TABLE(i2c, adv7175_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 388 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
| 389 | .name = "adv7175", |
| 390 | .driverid = I2C_DRIVERID_ADV7175, |
| 391 | .command = adv7175_command, |
| 392 | .probe = adv7175_probe, |
| 393 | .remove = adv7175_remove, |
| 394 | .id_table = adv7175_id, |
| 395 | }; |