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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame^] | 29 | #include <linux/slab.h> |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 30 | #include <linux/ioctl.h> |
Mauro Carvalho Chehab | 18f3fa1 | 2007-07-02 15:39:57 -0300 | [diff] [blame] | 31 | #include <asm/uaccess.h> |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 32 | #include <linux/i2c.h> |
| 33 | #include <linux/i2c-id.h> |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 34 | #include <linux/videodev2.h> |
| 35 | #include <media/v4l2-device.h> |
| 36 | #include <media/v4l2-chip-ident.h> |
Hans Verkuil | 2d26698 | 2009-02-19 17:41:19 -0300 | [diff] [blame] | 37 | #include <media/v4l2-i2c-drv.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | MODULE_DESCRIPTION("Analog Devices ADV7175 video encoder driver"); |
| 40 | MODULE_AUTHOR("Dave Perks"); |
| 41 | MODULE_LICENSE("GPL"); |
| 42 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 43 | #define I2C_ADV7175 0xd4 |
| 44 | #define I2C_ADV7176 0x54 |
| 45 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 46 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 47 | static int debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | module_param(debug, int, 0); |
| 49 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); |
| 50 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | /* ----------------------------------------------------------------------- */ |
| 52 | |
| 53 | struct adv7175 { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 54 | struct v4l2_subdev sd; |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 55 | v4l2_std_id norm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | int input; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 59 | static inline struct adv7175 *to_adv7175(struct v4l2_subdev *sd) |
| 60 | { |
| 61 | return container_of(sd, struct adv7175, sd); |
| 62 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | static char *inputs[] = { "pass_through", "play_back", "color_bar" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
| 66 | /* ----------------------------------------------------------------------- */ |
| 67 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 68 | 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] | 69 | { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 70 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 71 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | return i2c_smbus_write_byte_data(client, reg, value); |
| 73 | } |
| 74 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 75 | static inline int adv7175_read(struct v4l2_subdev *sd, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 77 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | return i2c_smbus_read_byte_data(client, reg); |
| 80 | } |
| 81 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 82 | static int adv7175_write_block(struct v4l2_subdev *sd, |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 83 | const u8 *data, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 85 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | int ret = -1; |
| 87 | u8 reg; |
| 88 | |
| 89 | /* the adv7175 has an autoincrement function, use it if |
| 90 | * the adapter understands raw I2C */ |
| 91 | if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { |
| 92 | /* do raw I2C, not smbus compatible */ |
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++] = data[1]; |
Jean Delvare | 2467a67 | 2006-03-22 03:48:34 -0300 | [diff] [blame] | 101 | reg++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | len -= 2; |
| 103 | data += 2; |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -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 | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 113 | ret = adv7175_write(sd, reg, *data++); |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 114 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | break; |
| 116 | len -= 2; |
| 117 | } |
| 118 | } |
| 119 | |
| 120 | return ret; |
| 121 | } |
| 122 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 123 | static void set_subcarrier_freq(struct v4l2_subdev *sd, int pass_through) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
| 125 | /* for some reason pass_through NTSC needs |
| 126 | * a different sub-carrier freq to remain stable. */ |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 127 | if (pass_through) |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 128 | adv7175_write(sd, 0x02, 0x00); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | else |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 130 | adv7175_write(sd, 0x02, 0x55); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 132 | adv7175_write(sd, 0x03, 0x55); |
| 133 | adv7175_write(sd, 0x04, 0x55); |
| 134 | adv7175_write(sd, 0x05, 0x25); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | } |
| 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /* ----------------------------------------------------------------------- */ |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 138 | /* Output filter: S-Video Composite */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 140 | #define MR050 0x11 /* 0x09 */ |
| 141 | #define MR060 0x14 /* 0x0c */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 143 | /* ----------------------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
| 145 | #define TR0MODE 0x46 |
| 146 | #define TR0RST 0x80 |
| 147 | |
| 148 | #define TR1CAPT 0x80 |
| 149 | #define TR1PLAY 0x00 |
| 150 | |
| 151 | static const unsigned char init_common[] = { |
| 152 | |
| 153 | 0x00, MR050, /* MR0, PAL enabled */ |
| 154 | 0x01, 0x00, /* MR1 */ |
| 155 | 0x02, 0x0c, /* subc. freq. */ |
| 156 | 0x03, 0x8c, /* subc. freq. */ |
| 157 | 0x04, 0x79, /* subc. freq. */ |
| 158 | 0x05, 0x26, /* subc. freq. */ |
| 159 | 0x06, 0x40, /* subc. phase */ |
| 160 | |
| 161 | 0x07, TR0MODE, /* TR0, 16bit */ |
| 162 | 0x08, 0x21, /* */ |
| 163 | 0x09, 0x00, /* */ |
| 164 | 0x0a, 0x00, /* */ |
| 165 | 0x0b, 0x00, /* */ |
| 166 | 0x0c, TR1CAPT, /* TR1 */ |
| 167 | 0x0d, 0x4f, /* MR2 */ |
| 168 | 0x0e, 0x00, /* */ |
| 169 | 0x0f, 0x00, /* */ |
| 170 | 0x10, 0x00, /* */ |
| 171 | 0x11, 0x00, /* */ |
| 172 | }; |
| 173 | |
| 174 | static const unsigned char init_pal[] = { |
| 175 | 0x00, MR050, /* MR0, PAL enabled */ |
| 176 | 0x01, 0x00, /* MR1 */ |
| 177 | 0x02, 0x0c, /* subc. freq. */ |
| 178 | 0x03, 0x8c, /* subc. freq. */ |
| 179 | 0x04, 0x79, /* subc. freq. */ |
| 180 | 0x05, 0x26, /* subc. freq. */ |
| 181 | 0x06, 0x40, /* subc. phase */ |
| 182 | }; |
| 183 | |
| 184 | static const unsigned char init_ntsc[] = { |
| 185 | 0x00, MR060, /* MR0, NTSC enabled */ |
| 186 | 0x01, 0x00, /* MR1 */ |
| 187 | 0x02, 0x55, /* subc. freq. */ |
| 188 | 0x03, 0x55, /* subc. freq. */ |
| 189 | 0x04, 0x55, /* subc. freq. */ |
| 190 | 0x05, 0x25, /* subc. freq. */ |
| 191 | 0x06, 0x1a, /* subc. phase */ |
| 192 | }; |
| 193 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 194 | static int adv7175_init(struct v4l2_subdev *sd, u32 val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 196 | /* This is just for testing!!! */ |
| 197 | adv7175_write_block(sd, init_common, sizeof(init_common)); |
| 198 | adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 199 | adv7175_write(sd, 0x07, TR0MODE); |
| 200 | return 0; |
| 201 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 203 | static int adv7175_s_std_output(struct v4l2_subdev *sd, v4l2_std_id std) |
| 204 | { |
| 205 | struct adv7175 *encoder = to_adv7175(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 207 | if (std & V4L2_STD_NTSC) { |
| 208 | adv7175_write_block(sd, init_ntsc, sizeof(init_ntsc)); |
| 209 | if (encoder->input == 0) |
| 210 | adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */ |
| 211 | adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 212 | adv7175_write(sd, 0x07, TR0MODE); |
| 213 | } else if (std & V4L2_STD_PAL) { |
| 214 | adv7175_write_block(sd, init_pal, sizeof(init_pal)); |
| 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_SECAM) { |
| 220 | /* This is an attempt to convert |
| 221 | * SECAM->PAL (typically it does not work |
| 222 | * due to genlock: when decoder is in SECAM |
| 223 | * and encoder in in PAL the subcarrier can |
| 224 | * not be syncronized with horizontal |
| 225 | * quency) */ |
| 226 | adv7175_write_block(sd, init_pal, sizeof(init_pal)); |
| 227 | if (encoder->input == 0) |
| 228 | adv7175_write(sd, 0x0d, 0x49); /* Disable genlock */ |
| 229 | adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 230 | adv7175_write(sd, 0x07, TR0MODE); |
| 231 | } else { |
Hans Verkuil | cc5cef8 | 2009-03-06 10:15:01 -0300 | [diff] [blame] | 232 | v4l2_dbg(1, debug, sd, "illegal norm: %llx\n", |
| 233 | (unsigned long long)std); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | return -EINVAL; |
| 235 | } |
Hans Verkuil | cc5cef8 | 2009-03-06 10:15:01 -0300 | [diff] [blame] | 236 | v4l2_dbg(1, debug, sd, "switched to %llx\n", (unsigned long long)std); |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 237 | encoder->norm = std; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | return 0; |
| 239 | } |
| 240 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 241 | static int adv7175_s_routing(struct v4l2_subdev *sd, |
| 242 | u32 input, u32 output, u32 config) |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 243 | { |
| 244 | struct adv7175 *encoder = to_adv7175(sd); |
| 245 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 246 | /* RJ: input = 0: input is from decoder |
| 247 | input = 1: input is from ZR36060 |
| 248 | input = 2: color bar */ |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 249 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 250 | switch (input) { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 251 | case 0: |
| 252 | adv7175_write(sd, 0x01, 0x00); |
| 253 | |
| 254 | if (encoder->norm & V4L2_STD_NTSC) |
| 255 | set_subcarrier_freq(sd, 1); |
| 256 | |
| 257 | adv7175_write(sd, 0x0c, TR1CAPT); /* TR1 */ |
| 258 | if (encoder->norm & V4L2_STD_SECAM) |
| 259 | adv7175_write(sd, 0x0d, 0x49); /* Disable genlock */ |
| 260 | else |
| 261 | adv7175_write(sd, 0x0d, 0x4f); /* Enable genlock */ |
| 262 | adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 263 | adv7175_write(sd, 0x07, TR0MODE); |
| 264 | /*udelay(10);*/ |
| 265 | break; |
| 266 | |
| 267 | case 1: |
| 268 | adv7175_write(sd, 0x01, 0x00); |
| 269 | |
| 270 | if (encoder->norm & V4L2_STD_NTSC) |
| 271 | set_subcarrier_freq(sd, 0); |
| 272 | |
| 273 | adv7175_write(sd, 0x0c, TR1PLAY); /* TR1 */ |
| 274 | adv7175_write(sd, 0x0d, 0x49); |
| 275 | adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 276 | adv7175_write(sd, 0x07, TR0MODE); |
| 277 | /* udelay(10); */ |
| 278 | break; |
| 279 | |
| 280 | case 2: |
| 281 | adv7175_write(sd, 0x01, 0x80); |
| 282 | |
| 283 | if (encoder->norm & V4L2_STD_NTSC) |
| 284 | set_subcarrier_freq(sd, 0); |
| 285 | |
| 286 | adv7175_write(sd, 0x0d, 0x49); |
| 287 | adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 288 | adv7175_write(sd, 0x07, TR0MODE); |
| 289 | /* udelay(10); */ |
| 290 | break; |
| 291 | |
| 292 | default: |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 293 | v4l2_dbg(1, debug, sd, "illegal input: %d\n", input); |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 294 | return -EINVAL; |
| 295 | } |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 296 | v4l2_dbg(1, debug, sd, "switched to %s\n", inputs[input]); |
| 297 | encoder->input = input; |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 298 | return 0; |
| 299 | } |
| 300 | |
| 301 | static int adv7175_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) |
| 302 | { |
| 303 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 304 | |
| 305 | return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_ADV7175, 0); |
| 306 | } |
| 307 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | /* ----------------------------------------------------------------------- */ |
| 309 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 310 | static const struct v4l2_subdev_core_ops adv7175_core_ops = { |
| 311 | .g_chip_ident = adv7175_g_chip_ident, |
| 312 | .init = adv7175_init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 315 | static const struct v4l2_subdev_video_ops adv7175_video_ops = { |
| 316 | .s_std_output = adv7175_s_std_output, |
| 317 | .s_routing = adv7175_s_routing, |
| 318 | }; |
| 319 | |
| 320 | static const struct v4l2_subdev_ops adv7175_ops = { |
| 321 | .core = &adv7175_core_ops, |
| 322 | .video = &adv7175_video_ops, |
| 323 | }; |
| 324 | |
| 325 | /* ----------------------------------------------------------------------- */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 326 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 327 | static int adv7175_probe(struct i2c_client *client, |
| 328 | const struct i2c_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | { |
| 330 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | struct adv7175 *encoder; |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 332 | struct v4l2_subdev *sd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | |
| 334 | /* Check if the adapter supports the needed features */ |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 335 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 336 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 338 | v4l_info(client, "chip found @ 0x%x (%s)\n", |
| 339 | client->addr << 1, client->adapter->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 341 | encoder = kzalloc(sizeof(struct adv7175), GFP_KERNEL); |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 342 | if (encoder == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | return -ENOMEM; |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 344 | sd = &encoder->sd; |
| 345 | v4l2_i2c_subdev_init(sd, client, &adv7175_ops); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 346 | encoder->norm = V4L2_STD_NTSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | encoder->input = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 349 | i = adv7175_write_block(sd, init_common, sizeof(init_common)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | if (i >= 0) { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 351 | i = adv7175_write(sd, 0x07, TR0MODE | TR0RST); |
| 352 | i = adv7175_write(sd, 0x07, TR0MODE); |
| 353 | i = adv7175_read(sd, 0x12); |
| 354 | v4l2_dbg(1, debug, sd, "revision %d\n", i & 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 356 | if (i < 0) |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 357 | v4l2_dbg(1, debug, sd, "init error 0x%x\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | return 0; |
| 359 | } |
| 360 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 361 | static int adv7175_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | { |
Hans Verkuil | 35631dc | 2009-02-19 14:56:37 -0300 | [diff] [blame] | 363 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
| 364 | |
| 365 | v4l2_device_unregister_subdev(sd); |
| 366 | kfree(to_adv7175(sd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | /* ----------------------------------------------------------------------- */ |
| 371 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 372 | static const struct i2c_device_id adv7175_id[] = { |
| 373 | { "adv7175", 0 }, |
| 374 | { "adv7176", 0 }, |
| 375 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | }; |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 377 | MODULE_DEVICE_TABLE(i2c, adv7175_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 379 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
| 380 | .name = "adv7175", |
Hans Verkuil | bba0d98 | 2008-09-07 07:58:46 -0300 | [diff] [blame] | 381 | .probe = adv7175_probe, |
| 382 | .remove = adv7175_remove, |
| 383 | .id_table = adv7175_id, |
| 384 | }; |