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> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 33 | #include <linux/slab.h> |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 34 | #include <linux/ioctl.h> |
Mauro Carvalho Chehab | 18f3fa1 | 2007-07-02 15:39:57 -0300 | [diff] [blame] | 35 | #include <asm/uaccess.h> |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 36 | #include <linux/i2c.h> |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 37 | #include <linux/videodev2.h> |
| 38 | #include <media/v4l2-device.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
| 40 | MODULE_DESCRIPTION("Analog Devices ADV7170 video encoder driver"); |
| 41 | MODULE_AUTHOR("Maxim Yevtyushkin"); |
| 42 | MODULE_LICENSE("GPL"); |
| 43 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 44 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 45 | static int debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | module_param(debug, int, 0); |
| 47 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); |
| 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | /* ----------------------------------------------------------------------- */ |
| 50 | |
| 51 | struct adv7170 { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 52 | struct v4l2_subdev sd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | unsigned char reg[128]; |
| 54 | |
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 | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 59 | static inline struct adv7170 *to_adv7170(struct v4l2_subdev *sd) |
| 60 | { |
| 61 | return container_of(sd, struct adv7170, sd); |
| 62 | } |
| 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | static char *inputs[] = { "pass_through", "play_back" }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 66 | static u32 adv7170_codes[] = { |
| 67 | MEDIA_BUS_FMT_UYVY8_2X8, |
| 68 | MEDIA_BUS_FMT_UYVY8_1X16, |
Christian Gmeiner | 0d37d35 | 2011-10-27 18:50:21 -0300 | [diff] [blame] | 69 | }; |
| 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* ----------------------------------------------------------------------- */ |
| 72 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 73 | 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] | 74 | { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 75 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 76 | struct adv7170 *encoder = to_adv7170(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | encoder->reg[reg] = value; |
| 79 | return i2c_smbus_write_byte_data(client, reg, value); |
| 80 | } |
| 81 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 82 | static inline int adv7170_read(struct v4l2_subdev *sd, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 84 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 85 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | return i2c_smbus_read_byte_data(client, reg); |
| 87 | } |
| 88 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 89 | static int adv7170_write_block(struct v4l2_subdev *sd, |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 90 | const u8 *data, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 92 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 93 | struct adv7170 *encoder = to_adv7170(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | int ret = -1; |
| 95 | u8 reg; |
| 96 | |
| 97 | /* the adv7170 has an autoincrement function, use it if |
| 98 | * the adapter understands raw I2C */ |
| 99 | if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { |
| 100 | /* do raw I2C, not smbus compatible */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | u8 block_data[32]; |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 102 | int block_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | while (len >= 2) { |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 105 | block_len = 0; |
| 106 | block_data[block_len++] = reg = data[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | do { |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 108 | block_data[block_len++] = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | encoder->reg[reg++] = data[1]; |
| 110 | len -= 2; |
| 111 | data += 2; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 112 | } while (len >= 2 && data[0] == reg && block_len < 32); |
| 113 | ret = i2c_master_send(client, block_data, block_len); |
| 114 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | break; |
| 116 | } |
| 117 | } else { |
| 118 | /* do some slow I2C emulation kind of thing */ |
| 119 | while (len >= 2) { |
| 120 | reg = *data++; |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 121 | ret = adv7170_write(sd, reg, *data++); |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 122 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | break; |
| 124 | len -= 2; |
| 125 | } |
| 126 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | return ret; |
| 128 | } |
| 129 | |
| 130 | /* ----------------------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | #define TR0MODE 0x4c |
| 133 | #define TR0RST 0x80 |
| 134 | |
| 135 | #define TR1CAPT 0x00 |
| 136 | #define TR1PLAY 0x00 |
| 137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | static const unsigned char init_NTSC[] = { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 139 | 0x00, 0x10, /* MR0 */ |
| 140 | 0x01, 0x20, /* MR1 */ |
| 141 | 0x02, 0x0e, /* MR2 RTC control: bits 2 and 1 */ |
| 142 | 0x03, 0x80, /* MR3 */ |
| 143 | 0x04, 0x30, /* MR4 */ |
| 144 | 0x05, 0x00, /* Reserved */ |
| 145 | 0x06, 0x00, /* Reserved */ |
| 146 | 0x07, TR0MODE, /* TM0 */ |
| 147 | 0x08, TR1CAPT, /* TM1 */ |
| 148 | 0x09, 0x16, /* Fsc0 */ |
| 149 | 0x0a, 0x7c, /* Fsc1 */ |
| 150 | 0x0b, 0xf0, /* Fsc2 */ |
| 151 | 0x0c, 0x21, /* Fsc3 */ |
| 152 | 0x0d, 0x00, /* Subcarrier Phase */ |
| 153 | 0x0e, 0x00, /* Closed Capt. Ext 0 */ |
| 154 | 0x0f, 0x00, /* Closed Capt. Ext 1 */ |
| 155 | 0x10, 0x00, /* Closed Capt. 0 */ |
| 156 | 0x11, 0x00, /* Closed Capt. 1 */ |
| 157 | 0x12, 0x00, /* Pedestal Ctl 0 */ |
| 158 | 0x13, 0x00, /* Pedestal Ctl 1 */ |
| 159 | 0x14, 0x00, /* Pedestal Ctl 2 */ |
| 160 | 0x15, 0x00, /* Pedestal Ctl 3 */ |
| 161 | 0x16, 0x00, /* CGMS_WSS_0 */ |
| 162 | 0x17, 0x00, /* CGMS_WSS_1 */ |
| 163 | 0x18, 0x00, /* CGMS_WSS_2 */ |
| 164 | 0x19, 0x00, /* Teletext Ctl */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | }; |
| 166 | |
| 167 | static const unsigned char init_PAL[] = { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 168 | 0x00, 0x71, /* MR0 */ |
| 169 | 0x01, 0x20, /* MR1 */ |
| 170 | 0x02, 0x0e, /* MR2 RTC control: bits 2 and 1 */ |
| 171 | 0x03, 0x80, /* MR3 */ |
| 172 | 0x04, 0x30, /* MR4 */ |
| 173 | 0x05, 0x00, /* Reserved */ |
| 174 | 0x06, 0x00, /* Reserved */ |
| 175 | 0x07, TR0MODE, /* TM0 */ |
| 176 | 0x08, TR1CAPT, /* TM1 */ |
| 177 | 0x09, 0xcb, /* Fsc0 */ |
| 178 | 0x0a, 0x8a, /* Fsc1 */ |
| 179 | 0x0b, 0x09, /* Fsc2 */ |
| 180 | 0x0c, 0x2a, /* Fsc3 */ |
| 181 | 0x0d, 0x00, /* Subcarrier Phase */ |
| 182 | 0x0e, 0x00, /* Closed Capt. Ext 0 */ |
| 183 | 0x0f, 0x00, /* Closed Capt. Ext 1 */ |
| 184 | 0x10, 0x00, /* Closed Capt. 0 */ |
| 185 | 0x11, 0x00, /* Closed Capt. 1 */ |
| 186 | 0x12, 0x00, /* Pedestal Ctl 0 */ |
| 187 | 0x13, 0x00, /* Pedestal Ctl 1 */ |
| 188 | 0x14, 0x00, /* Pedestal Ctl 2 */ |
| 189 | 0x15, 0x00, /* Pedestal Ctl 3 */ |
| 190 | 0x16, 0x00, /* CGMS_WSS_0 */ |
| 191 | 0x17, 0x00, /* CGMS_WSS_1 */ |
| 192 | 0x18, 0x00, /* CGMS_WSS_2 */ |
| 193 | 0x19, 0x00, /* Teletext Ctl */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | }; |
| 195 | |
| 196 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 197 | 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] | 198 | { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 199 | struct adv7170 *encoder = to_adv7170(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Hans Verkuil | cc5cef8 | 2009-03-06 10:15:01 -0300 | [diff] [blame] | 201 | v4l2_dbg(1, debug, sd, "set norm %llx\n", (unsigned long long)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 | if (std & V4L2_STD_NTSC) { |
| 204 | adv7170_write_block(sd, init_NTSC, sizeof(init_NTSC)); |
| 205 | if (encoder->input == 0) |
| 206 | adv7170_write(sd, 0x02, 0x0e); /* Enable genlock */ |
| 207 | adv7170_write(sd, 0x07, TR0MODE | TR0RST); |
| 208 | adv7170_write(sd, 0x07, TR0MODE); |
| 209 | } else if (std & V4L2_STD_PAL) { |
| 210 | adv7170_write_block(sd, init_PAL, sizeof(init_PAL)); |
| 211 | if (encoder->input == 0) |
| 212 | adv7170_write(sd, 0x02, 0x0e); /* Enable genlock */ |
| 213 | adv7170_write(sd, 0x07, TR0MODE | TR0RST); |
| 214 | adv7170_write(sd, 0x07, TR0MODE); |
| 215 | } else { |
Hans Verkuil | cc5cef8 | 2009-03-06 10:15:01 -0300 | [diff] [blame] | 216 | v4l2_dbg(1, debug, sd, "illegal norm: %llx\n", |
| 217 | (unsigned long long)std); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | return -EINVAL; |
| 219 | } |
Hans Verkuil | cc5cef8 | 2009-03-06 10:15:01 -0300 | [diff] [blame] | 220 | v4l2_dbg(1, debug, sd, "switched to %llx\n", (unsigned long long)std); |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 221 | encoder->norm = std; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | return 0; |
| 223 | } |
| 224 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 225 | static int adv7170_s_routing(struct v4l2_subdev *sd, |
| 226 | u32 input, u32 output, u32 config) |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 227 | { |
| 228 | struct adv7170 *encoder = to_adv7170(sd); |
| 229 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 230 | /* RJ: input = 0: input is from decoder |
| 231 | input = 1: input is from ZR36060 |
| 232 | input = 2: color bar */ |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 233 | |
| 234 | v4l2_dbg(1, debug, sd, "set input from %s\n", |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 235 | input == 0 ? "decoder" : "ZR36060"); |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 236 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 237 | switch (input) { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 238 | case 0: |
| 239 | adv7170_write(sd, 0x01, 0x20); |
| 240 | adv7170_write(sd, 0x08, TR1CAPT); /* TR1 */ |
| 241 | adv7170_write(sd, 0x02, 0x0e); /* Enable genlock */ |
| 242 | adv7170_write(sd, 0x07, TR0MODE | TR0RST); |
| 243 | adv7170_write(sd, 0x07, TR0MODE); |
| 244 | /* udelay(10); */ |
| 245 | break; |
| 246 | |
| 247 | case 1: |
| 248 | adv7170_write(sd, 0x01, 0x00); |
| 249 | adv7170_write(sd, 0x08, TR1PLAY); /* TR1 */ |
| 250 | adv7170_write(sd, 0x02, 0x08); |
| 251 | adv7170_write(sd, 0x07, TR0MODE | TR0RST); |
| 252 | adv7170_write(sd, 0x07, TR0MODE); |
| 253 | /* udelay(10); */ |
| 254 | break; |
| 255 | |
| 256 | default: |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 257 | v4l2_dbg(1, debug, sd, "illegal input: %d\n", input); |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 258 | return -EINVAL; |
| 259 | } |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 260 | v4l2_dbg(1, debug, sd, "switched to %s\n", inputs[input]); |
| 261 | encoder->input = input; |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 262 | return 0; |
| 263 | } |
| 264 | |
Christian Gmeiner | 0d37d35 | 2011-10-27 18:50:21 -0300 | [diff] [blame] | 265 | static int adv7170_enum_fmt(struct v4l2_subdev *sd, unsigned int index, |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 266 | u32 *code) |
Christian Gmeiner | 0d37d35 | 2011-10-27 18:50:21 -0300 | [diff] [blame] | 267 | { |
| 268 | if (index >= ARRAY_SIZE(adv7170_codes)) |
| 269 | return -EINVAL; |
| 270 | |
| 271 | *code = adv7170_codes[index]; |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | static int adv7170_g_fmt(struct v4l2_subdev *sd, |
| 276 | struct v4l2_mbus_framefmt *mf) |
| 277 | { |
| 278 | u8 val = adv7170_read(sd, 0x7); |
| 279 | |
| 280 | if ((val & 0x40) == (1 << 6)) |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 281 | mf->code = MEDIA_BUS_FMT_UYVY8_1X16; |
Christian Gmeiner | 0d37d35 | 2011-10-27 18:50:21 -0300 | [diff] [blame] | 282 | else |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 283 | mf->code = MEDIA_BUS_FMT_UYVY8_2X8; |
Christian Gmeiner | 0d37d35 | 2011-10-27 18:50:21 -0300 | [diff] [blame] | 284 | |
| 285 | mf->colorspace = V4L2_COLORSPACE_SMPTE170M; |
| 286 | mf->width = 0; |
| 287 | mf->height = 0; |
| 288 | mf->field = V4L2_FIELD_ANY; |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | static int adv7170_s_fmt(struct v4l2_subdev *sd, |
| 294 | struct v4l2_mbus_framefmt *mf) |
| 295 | { |
| 296 | u8 val = adv7170_read(sd, 0x7); |
| 297 | int ret; |
| 298 | |
| 299 | switch (mf->code) { |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 300 | case MEDIA_BUS_FMT_UYVY8_2X8: |
Christian Gmeiner | 0d37d35 | 2011-10-27 18:50:21 -0300 | [diff] [blame] | 301 | val &= ~0x40; |
| 302 | break; |
| 303 | |
Boris BREZILLON | f5fe58f | 2014-11-10 14:28:29 -0300 | [diff] [blame] | 304 | case MEDIA_BUS_FMT_UYVY8_1X16: |
Christian Gmeiner | 0d37d35 | 2011-10-27 18:50:21 -0300 | [diff] [blame] | 305 | val |= 0x40; |
| 306 | break; |
| 307 | |
| 308 | default: |
| 309 | v4l2_dbg(1, debug, sd, |
| 310 | "illegal v4l2_mbus_framefmt code: %d\n", mf->code); |
| 311 | return -EINVAL; |
| 312 | } |
| 313 | |
| 314 | ret = adv7170_write(sd, 0x7, val); |
| 315 | |
| 316 | return ret; |
| 317 | } |
| 318 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | /* ----------------------------------------------------------------------- */ |
| 320 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 321 | static const struct v4l2_subdev_video_ops adv7170_video_ops = { |
| 322 | .s_std_output = adv7170_s_std_output, |
| 323 | .s_routing = adv7170_s_routing, |
Christian Gmeiner | 0d37d35 | 2011-10-27 18:50:21 -0300 | [diff] [blame] | 324 | .s_mbus_fmt = adv7170_s_fmt, |
| 325 | .g_mbus_fmt = adv7170_g_fmt, |
| 326 | .enum_mbus_fmt = adv7170_enum_fmt, |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 327 | }; |
| 328 | |
| 329 | static const struct v4l2_subdev_ops adv7170_ops = { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 330 | .video = &adv7170_video_ops, |
| 331 | }; |
| 332 | |
| 333 | /* ----------------------------------------------------------------------- */ |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 334 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 335 | static int adv7170_probe(struct i2c_client *client, |
| 336 | const struct i2c_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | struct adv7170 *encoder; |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 339 | struct v4l2_subdev *sd; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 340 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | |
| 342 | /* Check if the adapter supports the needed features */ |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 343 | if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA)) |
| 344 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 346 | v4l_info(client, "chip found @ 0x%x (%s)\n", |
| 347 | client->addr << 1, client->adapter->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | |
Laurent Pinchart | c02b211 | 2013-05-02 08:29:43 -0300 | [diff] [blame] | 349 | encoder = devm_kzalloc(&client->dev, sizeof(*encoder), GFP_KERNEL); |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 350 | if (encoder == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | return -ENOMEM; |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 352 | sd = &encoder->sd; |
| 353 | v4l2_i2c_subdev_init(sd, client, &adv7170_ops); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 354 | encoder->norm = V4L2_STD_NTSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | encoder->input = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 357 | i = adv7170_write_block(sd, init_NTSC, sizeof(init_NTSC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | if (i >= 0) { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 359 | i = adv7170_write(sd, 0x07, TR0MODE | TR0RST); |
| 360 | i = adv7170_write(sd, 0x07, TR0MODE); |
| 361 | i = adv7170_read(sd, 0x12); |
| 362 | v4l2_dbg(1, debug, sd, "revision %d\n", i & 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | } |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 364 | if (i < 0) |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 365 | v4l2_dbg(1, debug, sd, "init error 0x%x\n", i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | return 0; |
| 367 | } |
| 368 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 369 | static int adv7170_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | { |
Hans Verkuil | 7d9ef21 | 2009-02-19 14:47:22 -0300 | [diff] [blame] | 371 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
| 372 | |
| 373 | v4l2_device_unregister_subdev(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | return 0; |
| 375 | } |
| 376 | |
| 377 | /* ----------------------------------------------------------------------- */ |
| 378 | |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 379 | static const struct i2c_device_id adv7170_id[] = { |
| 380 | { "adv7170", 0 }, |
| 381 | { "adv7171", 0 }, |
| 382 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | }; |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 384 | MODULE_DEVICE_TABLE(i2c, adv7170_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Hans Verkuil | c961180 | 2010-09-15 15:49:56 -0300 | [diff] [blame] | 386 | static struct i2c_driver adv7170_driver = { |
| 387 | .driver = { |
| 388 | .owner = THIS_MODULE, |
| 389 | .name = "adv7170", |
| 390 | }, |
| 391 | .probe = adv7170_probe, |
| 392 | .remove = adv7170_remove, |
| 393 | .id_table = adv7170_id, |
Hans Verkuil | b9a21f8 | 2008-09-07 07:58:20 -0300 | [diff] [blame] | 394 | }; |
Hans Verkuil | c961180 | 2010-09-15 15:49:56 -0300 | [diff] [blame] | 395 | |
Axel Lin | c6e8d86 | 2012-02-12 06:56:32 -0300 | [diff] [blame] | 396 | module_i2c_driver(adv7170_driver); |