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