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 | * vpx3220a, vpx3216b & vpx3214c video decoder driver version 0.0.1 |
| 3 | * |
| 4 | * Copyright (C) 2001 Laurent Pinchart <lpinchart@freegates.be> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 19 | */ |
| 20 | |
| 21 | #include <linux/module.h> |
| 22 | #include <linux/init.h> |
| 23 | #include <linux/delay.h> |
| 24 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | #include <asm/uaccess.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/i2c.h> |
Mauro Carvalho Chehab | 5e87efa | 2006-06-05 10:26:32 -0300 | [diff] [blame] | 27 | #include <media/v4l2-common.h> |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 28 | #include <media/v4l2-i2c-drv-legacy.h> |
| 29 | #include <linux/videodev.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/video_decoder.h> |
| 31 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 32 | MODULE_DESCRIPTION("vpx3220a/vpx3216b/vpx3214c video decoder driver"); |
| 33 | MODULE_AUTHOR("Laurent Pinchart"); |
| 34 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 36 | static int debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | module_param(debug, int, 0); |
| 38 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); |
| 39 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | #define VPX_TIMEOUT_COUNT 10 |
| 41 | |
| 42 | /* ----------------------------------------------------------------------- */ |
| 43 | |
| 44 | struct vpx3220 { |
| 45 | unsigned char reg[255]; |
| 46 | |
| 47 | int norm; |
| 48 | int input; |
| 49 | int enable; |
| 50 | int bright; |
| 51 | int contrast; |
| 52 | int hue; |
| 53 | int sat; |
| 54 | }; |
| 55 | |
| 56 | static char *inputs[] = { "internal", "composite", "svideo" }; |
| 57 | |
| 58 | /* ----------------------------------------------------------------------- */ |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 59 | |
| 60 | static inline int vpx3220_write(struct i2c_client *client, u8 reg, u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | { |
| 62 | struct vpx3220 *decoder = i2c_get_clientdata(client); |
| 63 | |
| 64 | decoder->reg[reg] = value; |
| 65 | return i2c_smbus_write_byte_data(client, reg, value); |
| 66 | } |
| 67 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 68 | static inline int vpx3220_read(struct i2c_client *client, u8 reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | { |
| 70 | return i2c_smbus_read_byte_data(client, reg); |
| 71 | } |
| 72 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 73 | static int vpx3220_fp_status(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | { |
| 75 | unsigned char status; |
| 76 | unsigned int i; |
| 77 | |
| 78 | for (i = 0; i < VPX_TIMEOUT_COUNT; i++) { |
| 79 | status = vpx3220_read(client, 0x29); |
| 80 | |
| 81 | if (!(status & 4)) |
| 82 | return 0; |
| 83 | |
| 84 | udelay(10); |
| 85 | |
| 86 | if (need_resched()) |
| 87 | cond_resched(); |
| 88 | } |
| 89 | |
| 90 | return -1; |
| 91 | } |
| 92 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 93 | static int vpx3220_fp_write(struct i2c_client *client, u8 fpaddr, u16 data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 94 | { |
| 95 | /* Write the 16-bit address to the FPWR register */ |
| 96 | if (i2c_smbus_write_word_data(client, 0x27, swab16(fpaddr)) == -1) { |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 97 | v4l_dbg(1, debug, client, "%s: failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | return -1; |
| 99 | } |
| 100 | |
| 101 | if (vpx3220_fp_status(client) < 0) |
| 102 | return -1; |
| 103 | |
| 104 | /* Write the 16-bit data to the FPDAT register */ |
| 105 | if (i2c_smbus_write_word_data(client, 0x28, swab16(data)) == -1) { |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 106 | v4l_dbg(1, debug, client, "%s: failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | return -1; |
| 108 | } |
| 109 | |
| 110 | return 0; |
| 111 | } |
| 112 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 113 | static u16 vpx3220_fp_read(struct i2c_client *client, u16 fpaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | { |
| 115 | s16 data; |
| 116 | |
| 117 | /* Write the 16-bit address to the FPRD register */ |
| 118 | if (i2c_smbus_write_word_data(client, 0x26, swab16(fpaddr)) == -1) { |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 119 | v4l_dbg(1, debug, client, "%s: failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | return -1; |
| 121 | } |
| 122 | |
| 123 | if (vpx3220_fp_status(client) < 0) |
| 124 | return -1; |
| 125 | |
| 126 | /* Read the 16-bit data from the FPDAT register */ |
| 127 | data = i2c_smbus_read_word_data(client, 0x28); |
| 128 | if (data == -1) { |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 129 | v4l_dbg(1, debug, client, "%s: failed\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | return -1; |
| 131 | } |
| 132 | |
| 133 | return swab16(data); |
| 134 | } |
| 135 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 136 | static int vpx3220_write_block(struct i2c_client *client, const u8 *data, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | { |
| 138 | u8 reg; |
| 139 | int ret = -1; |
| 140 | |
| 141 | while (len >= 2) { |
| 142 | reg = *data++; |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 143 | ret = vpx3220_write(client, reg, *data++); |
| 144 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | break; |
| 146 | len -= 2; |
| 147 | } |
| 148 | |
| 149 | return ret; |
| 150 | } |
| 151 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 152 | static int vpx3220_write_fp_block(struct i2c_client *client, |
| 153 | const u16 *data, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | { |
| 155 | u8 reg; |
| 156 | int ret = 0; |
| 157 | |
| 158 | while (len > 1) { |
| 159 | reg = *data++; |
| 160 | ret |= vpx3220_fp_write(client, reg, *data++); |
| 161 | len -= 2; |
| 162 | } |
| 163 | |
| 164 | return ret; |
| 165 | } |
| 166 | |
| 167 | /* ---------------------------------------------------------------------- */ |
| 168 | |
| 169 | static const unsigned short init_ntsc[] = { |
| 170 | 0x1c, 0x00, /* NTSC tint angle */ |
| 171 | 0x88, 17, /* Window 1 vertical */ |
| 172 | 0x89, 240, /* Vertical lines in */ |
| 173 | 0x8a, 240, /* Vertical lines out */ |
| 174 | 0x8b, 000, /* Horizontal begin */ |
| 175 | 0x8c, 640, /* Horizontal length */ |
| 176 | 0x8d, 640, /* Number of pixels */ |
| 177 | 0x8f, 0xc00, /* Disable window 2 */ |
Ronald S. Bultje | 9b3acc2 | 2005-10-16 20:29:24 -0700 | [diff] [blame] | 178 | 0xf0, 0x73, /* 13.5 MHz transport, Forced |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | * mode, latch windows */ |
| 180 | 0xf2, 0x13, /* NTSC M, composite input */ |
| 181 | 0xe7, 0x1e1, /* Enable vertical standard |
| 182 | * locking @ 240 lines */ |
| 183 | }; |
| 184 | |
| 185 | static const unsigned short init_pal[] = { |
| 186 | 0x88, 23, /* Window 1 vertical begin */ |
Ronald S. Bultje | 9b3acc2 | 2005-10-16 20:29:24 -0700 | [diff] [blame] | 187 | 0x89, 288, /* Vertical lines in (16 lines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | * skipped by the VFE) */ |
Ronald S. Bultje | 9b3acc2 | 2005-10-16 20:29:24 -0700 | [diff] [blame] | 189 | 0x8a, 288, /* Vertical lines out (16 lines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | * skipped by the VFE) */ |
| 191 | 0x8b, 16, /* Horizontal begin */ |
| 192 | 0x8c, 768, /* Horizontal length */ |
| 193 | 0x8d, 784, /* Number of pixels |
| 194 | * Must be >= Horizontal begin + Horizontal length */ |
| 195 | 0x8f, 0xc00, /* Disable window 2 */ |
Ronald S. Bultje | 9b3acc2 | 2005-10-16 20:29:24 -0700 | [diff] [blame] | 196 | 0xf0, 0x77, /* 13.5 MHz transport, Forced |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | * mode, latch windows */ |
| 198 | 0xf2, 0x3d1, /* PAL B,G,H,I, composite input */ |
Ronald S. Bultje | 9b3acc2 | 2005-10-16 20:29:24 -0700 | [diff] [blame] | 199 | 0xe7, 0x241, /* PAL/SECAM set to 288 lines */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | }; |
| 201 | |
| 202 | static const unsigned short init_secam[] = { |
Ronald S. Bultje | 9b3acc2 | 2005-10-16 20:29:24 -0700 | [diff] [blame] | 203 | 0x88, 23, /* Window 1 vertical begin */ |
| 204 | 0x89, 288, /* Vertical lines in (16 lines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | * skipped by the VFE) */ |
Ronald S. Bultje | 9b3acc2 | 2005-10-16 20:29:24 -0700 | [diff] [blame] | 206 | 0x8a, 288, /* Vertical lines out (16 lines |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | * skipped by the VFE) */ |
| 208 | 0x8b, 16, /* Horizontal begin */ |
| 209 | 0x8c, 768, /* Horizontal length */ |
| 210 | 0x8d, 784, /* Number of pixels |
| 211 | * Must be >= Horizontal begin + Horizontal length */ |
| 212 | 0x8f, 0xc00, /* Disable window 2 */ |
Ronald S. Bultje | 9b3acc2 | 2005-10-16 20:29:24 -0700 | [diff] [blame] | 213 | 0xf0, 0x77, /* 13.5 MHz transport, Forced |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | * mode, latch windows */ |
| 215 | 0xf2, 0x3d5, /* SECAM, composite input */ |
Ronald S. Bultje | 9b3acc2 | 2005-10-16 20:29:24 -0700 | [diff] [blame] | 216 | 0xe7, 0x241, /* PAL/SECAM set to 288 lines */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | }; |
| 218 | |
| 219 | static const unsigned char init_common[] = { |
| 220 | 0xf2, 0x00, /* Disable all outputs */ |
| 221 | 0x33, 0x0d, /* Luma : VIN2, Chroma : CIN |
| 222 | * (clamp off) */ |
| 223 | 0xd8, 0xa8, /* HREF/VREF active high, VREF |
| 224 | * pulse = 2, Odd/Even flag */ |
| 225 | 0x20, 0x03, /* IF compensation 0dB/oct */ |
| 226 | 0xe0, 0xff, /* Open up all comparators */ |
| 227 | 0xe1, 0x00, |
| 228 | 0xe2, 0x7f, |
| 229 | 0xe3, 0x80, |
| 230 | 0xe4, 0x7f, |
| 231 | 0xe5, 0x80, |
| 232 | 0xe6, 0x00, /* Brightness set to 0 */ |
| 233 | 0xe7, 0xe0, /* Contrast to 1.0, noise shaping |
| 234 | * 10 to 8 2-bit error diffusion */ |
| 235 | 0xe8, 0xf8, /* YUV422, CbCr binary offset, |
| 236 | * ... (p.32) */ |
| 237 | 0xea, 0x18, /* LLC2 connected, output FIFO |
| 238 | * reset with VACTintern */ |
| 239 | 0xf0, 0x8a, /* Half full level to 10, bus |
| 240 | * shuffler [7:0, 23:16, 15:8] */ |
| 241 | 0xf1, 0x18, /* Single clock, sync mode, no |
| 242 | * FE delay, no HLEN counter */ |
| 243 | 0xf8, 0x12, /* Port A, PIXCLK, HF# & FE# |
| 244 | * strength to 2 */ |
| 245 | 0xf9, 0x24, /* Port B, HREF, VREF, PREF & |
| 246 | * ALPHA strength to 4 */ |
| 247 | }; |
| 248 | |
| 249 | static const unsigned short init_fp[] = { |
| 250 | 0x59, 0, |
| 251 | 0xa0, 2070, /* ACC reference */ |
| 252 | 0xa3, 0, |
| 253 | 0xa4, 0, |
| 254 | 0xa8, 30, |
| 255 | 0xb2, 768, |
| 256 | 0xbe, 27, |
| 257 | 0x58, 0, |
| 258 | 0x26, 0, |
| 259 | 0x4b, 0x298, /* PLL gain */ |
| 260 | }; |
| 261 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 262 | static void vpx3220_dump_i2c(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | { |
| 264 | int len = sizeof(init_common); |
| 265 | const unsigned char *data = init_common; |
| 266 | |
| 267 | while (len > 1) { |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 268 | v4l_dbg(1, debug, client, "i2c reg 0x%02x data 0x%02x\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | *data, vpx3220_read(client, *data)); |
| 270 | data += 2; |
| 271 | len -= 2; |
| 272 | } |
| 273 | } |
| 274 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 275 | static int vpx3220_command(struct i2c_client *client, unsigned cmd, void *arg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | { |
| 277 | struct vpx3220 *decoder = i2c_get_clientdata(client); |
| 278 | |
| 279 | switch (cmd) { |
| 280 | case 0: |
| 281 | { |
| 282 | vpx3220_write_block(client, init_common, |
| 283 | sizeof(init_common)); |
| 284 | vpx3220_write_fp_block(client, init_fp, |
| 285 | sizeof(init_fp) >> 1); |
| 286 | switch (decoder->norm) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | case VIDEO_MODE_NTSC: |
| 288 | vpx3220_write_fp_block(client, init_ntsc, |
| 289 | sizeof(init_ntsc) >> 1); |
| 290 | break; |
| 291 | |
| 292 | case VIDEO_MODE_PAL: |
| 293 | vpx3220_write_fp_block(client, init_pal, |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 294 | sizeof(init_pal) >> 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 295 | break; |
| 296 | case VIDEO_MODE_SECAM: |
| 297 | vpx3220_write_fp_block(client, init_secam, |
| 298 | sizeof(init_secam) >> 1); |
| 299 | break; |
| 300 | default: |
| 301 | vpx3220_write_fp_block(client, init_pal, |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 302 | sizeof(init_pal) >> 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | break; |
| 304 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | break; |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 306 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | |
| 308 | case DECODER_DUMP: |
| 309 | { |
| 310 | vpx3220_dump_i2c(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | break; |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 312 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
| 314 | case DECODER_GET_CAPABILITIES: |
| 315 | { |
| 316 | struct video_decoder_capability *cap = arg; |
| 317 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 318 | v4l_dbg(1, debug, client, "DECODER_GET_CAPABILITIES\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | cap->flags = VIDEO_DECODER_PAL | |
| 321 | VIDEO_DECODER_NTSC | |
| 322 | VIDEO_DECODER_SECAM | |
| 323 | VIDEO_DECODER_AUTO | |
| 324 | VIDEO_DECODER_CCIR; |
| 325 | cap->inputs = 3; |
| 326 | cap->outputs = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | break; |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 328 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | case DECODER_GET_STATUS: |
| 331 | { |
| 332 | int res = 0, status; |
| 333 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 334 | v4l_dbg(1, debug, client, "DECODER_GET_STATUS\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | status = vpx3220_fp_read(client, 0x0f3); |
| 337 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 338 | v4l_dbg(1, debug, client, "status: 0x%04x\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
| 340 | if (status < 0) |
| 341 | return status; |
| 342 | |
| 343 | if ((status & 0x20) == 0) { |
| 344 | res |= DECODER_STATUS_GOOD | DECODER_STATUS_COLOR; |
| 345 | |
| 346 | switch (status & 0x18) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | case 0x00: |
| 348 | case 0x10: |
| 349 | case 0x14: |
| 350 | case 0x18: |
| 351 | res |= DECODER_STATUS_PAL; |
| 352 | break; |
| 353 | |
| 354 | case 0x08: |
| 355 | res |= DECODER_STATUS_SECAM; |
| 356 | break; |
| 357 | |
| 358 | case 0x04: |
| 359 | case 0x0c: |
| 360 | case 0x1c: |
| 361 | res |= DECODER_STATUS_NTSC; |
| 362 | break; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | *(int *) arg = res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | break; |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 368 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
| 370 | case DECODER_SET_NORM: |
| 371 | { |
| 372 | int *iarg = arg, data; |
Ronald S. Bultje | de21eb6 | 2005-10-16 20:29:25 -0700 | [diff] [blame] | 373 | int temp_input; |
| 374 | |
| 375 | /* Here we back up the input selection because it gets |
| 376 | overwritten when we fill the registers with the |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 377 | choosen video norm */ |
Ronald S. Bultje | de21eb6 | 2005-10-16 20:29:25 -0700 | [diff] [blame] | 378 | temp_input = vpx3220_fp_read(client, 0xf2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 380 | v4l_dbg(1, debug, client, "DECODER_SET_NORM %d\n", *iarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | switch (*iarg) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | case VIDEO_MODE_NTSC: |
| 383 | vpx3220_write_fp_block(client, init_ntsc, |
| 384 | sizeof(init_ntsc) >> 1); |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 385 | v4l_dbg(1, debug, client, "norm switched to NTSC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | break; |
| 387 | |
| 388 | case VIDEO_MODE_PAL: |
| 389 | vpx3220_write_fp_block(client, init_pal, |
| 390 | sizeof(init_pal) >> 1); |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 391 | v4l_dbg(1, debug, client, "norm switched to PAL\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | break; |
| 393 | |
| 394 | case VIDEO_MODE_SECAM: |
| 395 | vpx3220_write_fp_block(client, init_secam, |
| 396 | sizeof(init_secam) >> 1); |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 397 | v4l_dbg(1, debug, client, "norm switched to SECAM\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | break; |
| 399 | |
| 400 | case VIDEO_MODE_AUTO: |
| 401 | /* FIXME This is only preliminary support */ |
| 402 | data = vpx3220_fp_read(client, 0xf2) & 0x20; |
| 403 | vpx3220_fp_write(client, 0xf2, 0x00c0 | data); |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 404 | v4l_dbg(1, debug, client, "norm switched to AUTO\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | break; |
| 406 | |
| 407 | default: |
| 408 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
| 410 | decoder->norm = *iarg; |
Ronald S. Bultje | de21eb6 | 2005-10-16 20:29:25 -0700 | [diff] [blame] | 411 | |
| 412 | /* And here we set the backed up video input again */ |
| 413 | vpx3220_fp_write(client, 0xf2, temp_input | 0x0010); |
| 414 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | break; |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 416 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
| 418 | case DECODER_SET_INPUT: |
| 419 | { |
| 420 | int *iarg = arg, data; |
| 421 | |
| 422 | /* RJ: *iarg = 0: ST8 (PCTV) input |
| 423 | *iarg = 1: COMPOSITE input |
| 424 | *iarg = 2: SVHS input */ |
| 425 | |
| 426 | const int input[3][2] = { |
| 427 | {0x0c, 0}, |
| 428 | {0x0d, 0}, |
| 429 | {0x0e, 1} |
| 430 | }; |
| 431 | |
| 432 | if (*iarg < 0 || *iarg > 2) |
| 433 | return -EINVAL; |
| 434 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 435 | v4l_dbg(1, debug, client, "input switched to %s\n", inputs[*iarg]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
| 437 | vpx3220_write(client, 0x33, input[*iarg][0]); |
| 438 | |
| 439 | data = vpx3220_fp_read(client, 0xf2) & ~(0x0020); |
| 440 | if (data < 0) |
| 441 | return data; |
| 442 | /* 0x0010 is required to latch the setting */ |
| 443 | vpx3220_fp_write(client, 0xf2, |
| 444 | data | (input[*iarg][1] << 5) | 0x0010); |
| 445 | |
| 446 | udelay(10); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | break; |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 448 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
| 450 | case DECODER_SET_OUTPUT: |
| 451 | { |
| 452 | int *iarg = arg; |
| 453 | |
| 454 | /* not much choice of outputs */ |
| 455 | if (*iarg != 0) { |
| 456 | return -EINVAL; |
| 457 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | break; |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 459 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
| 461 | case DECODER_ENABLE_OUTPUT: |
| 462 | { |
| 463 | int *iarg = arg; |
| 464 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 465 | v4l_dbg(1, debug, client, "DECODER_ENABLE_OUTPUT %d\n", *iarg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | vpx3220_write(client, 0xf2, (*iarg ? 0x1b : 0x00)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | break; |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 469 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
| 471 | case DECODER_SET_PICTURE: |
| 472 | { |
| 473 | struct video_picture *pic = arg; |
| 474 | |
| 475 | if (decoder->bright != pic->brightness) { |
| 476 | /* We want -128 to 128 we get 0-65535 */ |
| 477 | decoder->bright = pic->brightness; |
| 478 | vpx3220_write(client, 0xe6, |
| 479 | (decoder->bright - 32768) >> 8); |
| 480 | } |
| 481 | if (decoder->contrast != pic->contrast) { |
| 482 | /* We want 0 to 64 we get 0-65535 */ |
| 483 | /* Bit 7 and 8 is for noise shaping */ |
| 484 | decoder->contrast = pic->contrast; |
| 485 | vpx3220_write(client, 0xe7, |
| 486 | (decoder->contrast >> 10) + 192); |
| 487 | } |
| 488 | if (decoder->sat != pic->colour) { |
| 489 | /* We want 0 to 4096 we get 0-65535 */ |
| 490 | decoder->sat = pic->colour; |
| 491 | vpx3220_fp_write(client, 0xa0, |
| 492 | decoder->sat >> 4); |
| 493 | } |
| 494 | if (decoder->hue != pic->hue) { |
| 495 | /* We want -512 to 512 we get 0-65535 */ |
| 496 | decoder->hue = pic->hue; |
| 497 | vpx3220_fp_write(client, 0x1c, |
| 498 | ((decoder->hue - 32768) >> 6) & 0xFFF); |
| 499 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | break; |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 501 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | |
| 503 | default: |
| 504 | return -EINVAL; |
| 505 | } |
| 506 | |
| 507 | return 0; |
| 508 | } |
| 509 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 510 | static int vpx3220_init_client(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | { |
| 512 | vpx3220_write_block(client, init_common, sizeof(init_common)); |
| 513 | vpx3220_write_fp_block(client, init_fp, sizeof(init_fp) >> 1); |
| 514 | /* Default to PAL */ |
| 515 | vpx3220_write_fp_block(client, init_pal, sizeof(init_pal) >> 1); |
| 516 | |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | /* ----------------------------------------------------------------------- |
Joe Perches | c84e603 | 2008-02-03 17:18:59 +0200 | [diff] [blame] | 521 | * Client management code |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | */ |
| 523 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 524 | static unsigned short normal_i2c[] = { 0x86 >> 1, 0x8e >> 1, I2C_CLIENT_END }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 526 | I2C_CLIENT_INSMOD; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 527 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 528 | static int vpx3220_probe(struct i2c_client *client, |
| 529 | const struct i2c_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | struct vpx3220 *decoder; |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 532 | const char *name = NULL; |
| 533 | u8 ver; |
| 534 | u16 pn; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
| 536 | /* Check if the adapter supports the needed features */ |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 537 | if (!i2c_check_functionality(client->adapter, |
| 538 | I2C_FUNC_SMBUS_BYTE_DATA | I2C_FUNC_SMBUS_WORD_DATA)) |
| 539 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 541 | decoder = kzalloc(sizeof(struct vpx3220), GFP_KERNEL); |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 542 | if (decoder == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | decoder->norm = VIDEO_MODE_PAL; |
| 545 | decoder->input = 0; |
| 546 | decoder->enable = 1; |
| 547 | decoder->bright = 32768; |
| 548 | decoder->contrast = 32768; |
| 549 | decoder->hue = 32768; |
| 550 | decoder->sat = 32768; |
| 551 | i2c_set_clientdata(client, decoder); |
| 552 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 553 | ver = i2c_smbus_read_byte_data(client, 0x00); |
| 554 | pn = (i2c_smbus_read_byte_data(client, 0x02) << 8) + |
| 555 | i2c_smbus_read_byte_data(client, 0x01); |
| 556 | if (ver == 0xec) { |
| 557 | switch (pn) { |
| 558 | case 0x4680: |
| 559 | name = "vpx3220a"; |
| 560 | break; |
| 561 | case 0x4260: |
| 562 | name = "vpx3216b"; |
| 563 | break; |
| 564 | case 0x4280: |
| 565 | name = "vpx3214c"; |
| 566 | break; |
| 567 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | } |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 569 | if (name) |
| 570 | v4l_info(client, "%s found @ 0x%x (%s)\n", name, |
| 571 | client->addr << 1, client->adapter->name); |
| 572 | else |
| 573 | v4l_info(client, "chip (%02x:%04x) found @ 0x%x (%s)\n", |
| 574 | ver, pn, client->addr << 1, client->adapter->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | |
| 576 | vpx3220_init_client(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | return 0; |
| 578 | } |
| 579 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 580 | static int vpx3220_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | { |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 582 | kfree(i2c_get_clientdata(client)); |
| 583 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | } |
| 585 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 586 | static const struct i2c_device_id vpx3220_id[] = { |
| 587 | { "vpx3220a", 0 }, |
| 588 | { "vpx3216b", 0 }, |
| 589 | { "vpx3214c", 0 }, |
| 590 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | }; |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 592 | MODULE_DEVICE_TABLE(i2c, vpx3220_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
Hans Verkuil | 23848b6 | 2008-09-07 08:01:39 -0300 | [diff] [blame] | 594 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
| 595 | .name = "vpx3220", |
| 596 | .driverid = I2C_DRIVERID_VPX3220, |
| 597 | .command = vpx3220_command, |
| 598 | .probe = vpx3220_probe, |
| 599 | .remove = vpx3220_remove, |
| 600 | .id_table = vpx3220_id, |
| 601 | }; |