Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * saa7110 - Philips SAA7110(A) video decoder driver |
| 3 | * |
| 4 | * Copyright (C) 1998 Pauline Middelink <middelin@polyware.nl> |
| 5 | * |
| 6 | * Copyright (C) 1999 Wolfgang Scherr <scherr@net4you.net> |
| 7 | * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx> |
| 8 | * - some corrections for Pinnacle Systems Inc. DC10plus card. |
| 9 | * |
| 10 | * Changes by Ronald Bultje <rbultje@ronald.bitfreak.net> |
| 11 | * - moved over to linux>=2.4.x i2c protocol (1/1/2003) |
| 12 | * |
| 13 | * This program is free software; you can redistribute it and/or modify |
| 14 | * it under the terms of the GNU General Public License as published by |
| 15 | * the Free Software Foundation; either version 2 of the License, or |
| 16 | * (at your option) any later version. |
| 17 | * |
| 18 | * This program is distributed in the hope that it will be useful, |
| 19 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 20 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 21 | * GNU General Public License for more details. |
| 22 | * |
| 23 | * You should have received a copy of the GNU General Public License |
| 24 | * along with this program; if not, write to the Free Software |
| 25 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 26 | */ |
| 27 | |
| 28 | #include <linux/module.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/types.h> |
| 31 | #include <linux/delay.h> |
| 32 | #include <linux/slab.h> |
| 33 | #include <linux/wait.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | #include <asm/uaccess.h> |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 35 | #include <linux/i2c.h> |
| 36 | #include <linux/videodev.h> |
| 37 | #include <linux/video_decoder.h> |
| 38 | #include <media/v4l2-common.h> |
| 39 | #include <media/v4l2-i2c-drv-legacy.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 41 | MODULE_DESCRIPTION("Philips SAA7110 video decoder driver"); |
| 42 | MODULE_AUTHOR("Pauline Middelink"); |
| 43 | MODULE_LICENSE("GPL"); |
| 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 | #define SAA7110_MAX_INPUT 9 /* 6 CVBS, 3 SVHS */ |
Jean Delvare | 8182ff6 | 2008-10-24 15:08:28 -0300 | [diff] [blame] | 50 | #define SAA7110_MAX_OUTPUT 1 /* 1 YUV */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #define SAA7110_NR_REG 0x35 |
| 53 | |
| 54 | struct saa7110 { |
| 55 | u8 reg[SAA7110_NR_REG]; |
| 56 | |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 57 | v4l2_std_id norm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | int input; |
| 59 | int enable; |
| 60 | int bright; |
| 61 | int contrast; |
| 62 | int hue; |
| 63 | int sat; |
| 64 | |
| 65 | wait_queue_head_t wq; |
| 66 | }; |
| 67 | |
| 68 | /* ----------------------------------------------------------------------- */ |
| 69 | /* I2C support functions */ |
| 70 | /* ----------------------------------------------------------------------- */ |
| 71 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 72 | static int saa7110_write(struct i2c_client *client, u8 reg, u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | { |
| 74 | struct saa7110 *decoder = i2c_get_clientdata(client); |
| 75 | |
| 76 | decoder->reg[reg] = value; |
| 77 | return i2c_smbus_write_byte_data(client, reg, value); |
| 78 | } |
| 79 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 80 | static int saa7110_write_block(struct i2c_client *client, const u8 *data, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | { |
| 82 | int ret = -1; |
| 83 | u8 reg = *data; /* first register to write to */ |
| 84 | |
| 85 | /* Sanity check */ |
| 86 | if (reg + (len - 1) > SAA7110_NR_REG) |
| 87 | return ret; |
| 88 | |
| 89 | /* the saa7110 has an autoincrement function, use it if |
| 90 | * the adapter understands raw I2C */ |
| 91 | if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { |
| 92 | struct saa7110 *decoder = i2c_get_clientdata(client); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 94 | ret = i2c_master_send(client, data, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* Cache the written data */ |
| 97 | memcpy(decoder->reg + reg, data + 1, len - 1); |
| 98 | } else { |
| 99 | for (++data, --len; len; len--) { |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 100 | ret = saa7110_write(client, reg++, *data++); |
| 101 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | break; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | return ret; |
| 107 | } |
| 108 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 109 | static inline int saa7110_read(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | { |
| 111 | return i2c_smbus_read_byte(client); |
| 112 | } |
| 113 | |
| 114 | /* ----------------------------------------------------------------------- */ |
| 115 | /* SAA7110 functions */ |
| 116 | /* ----------------------------------------------------------------------- */ |
| 117 | |
| 118 | #define FRESP_06H_COMPST 0x03 //0x13 |
| 119 | #define FRESP_06H_SVIDEO 0x83 //0xC0 |
| 120 | |
| 121 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 122 | static int saa7110_selmux(struct i2c_client *client, int chan) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | static const unsigned char modes[9][8] = { |
| 125 | /* mode 0 */ |
| 126 | {FRESP_06H_COMPST, 0xD9, 0x17, 0x40, 0x03, |
| 127 | 0x44, 0x75, 0x16}, |
| 128 | /* mode 1 */ |
| 129 | {FRESP_06H_COMPST, 0xD8, 0x17, 0x40, 0x03, |
| 130 | 0x44, 0x75, 0x16}, |
| 131 | /* mode 2 */ |
| 132 | {FRESP_06H_COMPST, 0xBA, 0x07, 0x91, 0x03, |
| 133 | 0x60, 0xB5, 0x05}, |
| 134 | /* mode 3 */ |
| 135 | {FRESP_06H_COMPST, 0xB8, 0x07, 0x91, 0x03, |
| 136 | 0x60, 0xB5, 0x05}, |
| 137 | /* mode 4 */ |
| 138 | {FRESP_06H_COMPST, 0x7C, 0x07, 0xD2, 0x83, |
| 139 | 0x60, 0xB5, 0x03}, |
| 140 | /* mode 5 */ |
| 141 | {FRESP_06H_COMPST, 0x78, 0x07, 0xD2, 0x83, |
| 142 | 0x60, 0xB5, 0x03}, |
| 143 | /* mode 6 */ |
| 144 | {FRESP_06H_SVIDEO, 0x59, 0x17, 0x42, 0xA3, |
| 145 | 0x44, 0x75, 0x12}, |
| 146 | /* mode 7 */ |
| 147 | {FRESP_06H_SVIDEO, 0x9A, 0x17, 0xB1, 0x13, |
| 148 | 0x60, 0xB5, 0x14}, |
| 149 | /* mode 8 */ |
| 150 | {FRESP_06H_SVIDEO, 0x3C, 0x27, 0xC1, 0x23, |
| 151 | 0x44, 0x75, 0x21} |
| 152 | }; |
| 153 | struct saa7110 *decoder = i2c_get_clientdata(client); |
| 154 | const unsigned char *ptr = modes[chan]; |
| 155 | |
| 156 | saa7110_write(client, 0x06, ptr[0]); /* Luminance control */ |
| 157 | saa7110_write(client, 0x20, ptr[1]); /* Analog Control #1 */ |
| 158 | saa7110_write(client, 0x21, ptr[2]); /* Analog Control #2 */ |
| 159 | saa7110_write(client, 0x22, ptr[3]); /* Mixer Control #1 */ |
| 160 | saa7110_write(client, 0x2C, ptr[4]); /* Mixer Control #2 */ |
| 161 | saa7110_write(client, 0x30, ptr[5]); /* ADCs gain control */ |
| 162 | saa7110_write(client, 0x31, ptr[6]); /* Mixer Control #3 */ |
| 163 | saa7110_write(client, 0x21, ptr[7]); /* Analog Control #2 */ |
| 164 | decoder->input = chan; |
| 165 | |
| 166 | return 0; |
| 167 | } |
| 168 | |
| 169 | static const unsigned char initseq[1 + SAA7110_NR_REG] = { |
| 170 | 0, 0x4C, 0x3C, 0x0D, 0xEF, 0xBD, 0xF2, 0x03, 0x00, |
| 171 | /* 0x08 */ 0xF8, 0xF8, 0x60, 0x60, 0x00, 0x86, 0x18, 0x90, |
| 172 | /* 0x10 */ 0x00, 0x59, 0x40, 0x46, 0x42, 0x1A, 0xFF, 0xDA, |
| 173 | /* 0x18 */ 0xF2, 0x8B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 174 | /* 0x20 */ 0xD9, 0x16, 0x40, 0x41, 0x80, 0x41, 0x80, 0x4F, |
| 175 | /* 0x28 */ 0xFE, 0x01, 0xCF, 0x0F, 0x03, 0x01, 0x03, 0x0C, |
| 176 | /* 0x30 */ 0x44, 0x71, 0x02, 0x8C, 0x02 |
| 177 | }; |
| 178 | |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 179 | static v4l2_std_id determine_norm(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | { |
| 181 | DEFINE_WAIT(wait); |
| 182 | struct saa7110 *decoder = i2c_get_clientdata(client); |
| 183 | int status; |
| 184 | |
| 185 | /* mode changed, start automatic detection */ |
| 186 | saa7110_write_block(client, initseq, sizeof(initseq)); |
| 187 | saa7110_selmux(client, decoder->input); |
| 188 | prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE); |
Mauro Carvalho Chehab | 09df5cbe | 2007-07-17 16:25:38 -0300 | [diff] [blame] | 189 | schedule_timeout(msecs_to_jiffies(250)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | finish_wait(&decoder->wq, &wait); |
| 191 | status = saa7110_read(client); |
| 192 | if (status & 0x40) { |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 193 | v4l_dbg(1, debug, client, "status=0x%02x (no signal)\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | return decoder->norm; // no change |
| 195 | } |
| 196 | if ((status & 3) == 0) { |
| 197 | saa7110_write(client, 0x06, 0x83); |
| 198 | if (status & 0x20) { |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 199 | v4l_dbg(1, debug, client, "status=0x%02x (NTSC/no color)\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | //saa7110_write(client,0x2E,0x81); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 201 | return V4L2_STD_NTSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 203 | v4l_dbg(1, debug, client, "status=0x%02x (PAL/no color)\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | //saa7110_write(client,0x2E,0x9A); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 205 | return V4L2_STD_PAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | } |
| 207 | //saa7110_write(client,0x06,0x03); |
| 208 | if (status & 0x20) { /* 60Hz */ |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 209 | v4l_dbg(1, debug, client, "status=0x%02x (NTSC)\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | saa7110_write(client, 0x0D, 0x86); |
| 211 | saa7110_write(client, 0x0F, 0x50); |
| 212 | saa7110_write(client, 0x11, 0x2C); |
| 213 | //saa7110_write(client,0x2E,0x81); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 214 | return V4L2_STD_NTSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | /* 50Hz -> PAL/SECAM */ |
| 218 | saa7110_write(client, 0x0D, 0x86); |
| 219 | saa7110_write(client, 0x0F, 0x10); |
| 220 | saa7110_write(client, 0x11, 0x59); |
| 221 | //saa7110_write(client,0x2E,0x9A); |
| 222 | |
| 223 | prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE); |
Mauro Carvalho Chehab | 09df5cbe | 2007-07-17 16:25:38 -0300 | [diff] [blame] | 224 | schedule_timeout(msecs_to_jiffies(250)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | finish_wait(&decoder->wq, &wait); |
| 226 | |
| 227 | status = saa7110_read(client); |
| 228 | if ((status & 0x03) == 0x01) { |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 229 | v4l_dbg(1, debug, client, "status=0x%02x (SECAM)\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | saa7110_write(client, 0x0D, 0x87); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 231 | return V4L2_STD_SECAM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 233 | v4l_dbg(1, debug, client, "status=0x%02x (PAL)\n", status); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 234 | return V4L2_STD_PAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | static int |
| 238 | saa7110_command (struct i2c_client *client, |
| 239 | unsigned int cmd, |
| 240 | void *arg) |
| 241 | { |
| 242 | struct saa7110 *decoder = i2c_get_clientdata(client); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 243 | struct v4l2_routing *route = arg; |
| 244 | v4l2_std_id std; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | int v; |
| 246 | |
| 247 | switch (cmd) { |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 248 | case VIDIOC_INT_INIT: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | //saa7110_write_block(client, initseq, sizeof(initseq)); |
| 250 | break; |
| 251 | |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 252 | case VIDIOC_INT_G_INPUT_STATUS: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 254 | int res = V4L2_IN_ST_NO_SIGNAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
| 257 | status = saa7110_read(client); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 258 | v4l_dbg(1, debug, client, "status=0x%02x norm=%llx\n", |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 259 | status, decoder->norm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (!(status & 0x40)) |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 261 | res = 0; |
| 262 | if (!(status & 0x03)) |
| 263 | res |= V4L2_IN_ST_NO_COLOR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | *(int *) arg = res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | break; |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 267 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 269 | case VIDIOC_QUERYSTD: |
| 270 | { |
| 271 | *(v4l2_std_id *)arg = determine_norm(client); |
| 272 | break; |
| 273 | } |
| 274 | |
| 275 | case VIDIOC_S_STD: |
| 276 | std = *(v4l2_std_id *) arg; |
| 277 | if (decoder->norm != std) { |
| 278 | decoder->norm = std; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | //saa7110_write(client, 0x06, 0x03); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 280 | if (std & V4L2_STD_NTSC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | saa7110_write(client, 0x0D, 0x86); |
| 282 | saa7110_write(client, 0x0F, 0x50); |
| 283 | saa7110_write(client, 0x11, 0x2C); |
| 284 | //saa7110_write(client, 0x2E, 0x81); |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 285 | v4l_dbg(1, debug, client, "switched to NTSC\n"); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 286 | } else if (std & V4L2_STD_PAL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | saa7110_write(client, 0x0D, 0x86); |
| 288 | saa7110_write(client, 0x0F, 0x10); |
| 289 | saa7110_write(client, 0x11, 0x59); |
| 290 | //saa7110_write(client, 0x2E, 0x9A); |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 291 | v4l_dbg(1, debug, client, "switched to PAL\n"); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 292 | } else if (std & V4L2_STD_SECAM) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | saa7110_write(client, 0x0D, 0x87); |
| 294 | saa7110_write(client, 0x0F, 0x10); |
| 295 | saa7110_write(client, 0x11, 0x59); |
| 296 | //saa7110_write(client, 0x2E, 0x9A); |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 297 | v4l_dbg(1, debug, client, "switched to SECAM\n"); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 298 | } else { |
| 299 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | } |
| 301 | } |
| 302 | break; |
| 303 | |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 304 | case VIDIOC_INT_S_VIDEO_ROUTING: |
| 305 | if (route->input < 0 || route->input >= SAA7110_MAX_INPUT) { |
| 306 | v4l_dbg(1, debug, client, "input=%d not available\n", route->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | return -EINVAL; |
| 308 | } |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 309 | if (decoder->input != route->input) { |
| 310 | saa7110_selmux(client, route->input); |
| 311 | v4l_dbg(1, debug, client, "switched to input=%d\n", route->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | break; |
| 314 | |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 315 | case VIDIOC_STREAMON: |
| 316 | case VIDIOC_STREAMOFF: |
| 317 | v = cmd == VIDIOC_STREAMON; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | if (decoder->enable != v) { |
| 319 | decoder->enable = v; |
| 320 | saa7110_write(client, 0x0E, v ? 0x18 : 0x80); |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 321 | v4l_dbg(1, debug, client, "YUV %s\n", v ? "on" : "off"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
| 323 | break; |
| 324 | |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 325 | case VIDIOC_QUERYCTRL: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | { |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 327 | struct v4l2_queryctrl *qc = arg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 329 | switch (qc->id) { |
| 330 | case V4L2_CID_BRIGHTNESS: |
| 331 | return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128); |
| 332 | case V4L2_CID_CONTRAST: |
| 333 | case V4L2_CID_SATURATION: |
| 334 | return v4l2_ctrl_query_fill(qc, 0, 127, 1, 64); |
| 335 | case V4L2_CID_HUE: |
| 336 | return v4l2_ctrl_query_fill(qc, -128, 127, 1, 0); |
| 337 | default: |
| 338 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | break; |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 341 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 343 | case VIDIOC_G_CTRL: |
| 344 | { |
| 345 | struct v4l2_control *ctrl = arg; |
| 346 | |
| 347 | switch (ctrl->id) { |
| 348 | case V4L2_CID_BRIGHTNESS: |
| 349 | ctrl->value = decoder->bright; |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 350 | break; |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 351 | case V4L2_CID_CONTRAST: |
| 352 | ctrl->value = decoder->contrast; |
| 353 | break; |
| 354 | case V4L2_CID_SATURATION: |
| 355 | ctrl->value = decoder->sat; |
| 356 | break; |
| 357 | case V4L2_CID_HUE: |
| 358 | ctrl->value = decoder->hue; |
| 359 | break; |
| 360 | default: |
| 361 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | } |
| 363 | break; |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 364 | } |
| 365 | |
| 366 | case VIDIOC_S_CTRL: |
| 367 | { |
| 368 | struct v4l2_control *ctrl = arg; |
| 369 | |
| 370 | switch (ctrl->id) { |
| 371 | case V4L2_CID_BRIGHTNESS: |
| 372 | if (decoder->bright != ctrl->value) { |
| 373 | decoder->bright = ctrl->value; |
| 374 | saa7110_write(client, 0x19, decoder->bright); |
| 375 | } |
| 376 | break; |
| 377 | case V4L2_CID_CONTRAST: |
| 378 | if (decoder->contrast != ctrl->value) { |
| 379 | decoder->contrast = ctrl->value; |
| 380 | saa7110_write(client, 0x13, decoder->contrast); |
| 381 | } |
| 382 | break; |
| 383 | case V4L2_CID_SATURATION: |
| 384 | if (decoder->sat != ctrl->value) { |
| 385 | decoder->sat = ctrl->value; |
| 386 | saa7110_write(client, 0x12, decoder->sat); |
| 387 | } |
| 388 | break; |
| 389 | case V4L2_CID_HUE: |
| 390 | if (decoder->hue != ctrl->value) { |
| 391 | decoder->hue = ctrl->value; |
| 392 | saa7110_write(client, 0x07, decoder->hue); |
| 393 | } |
| 394 | break; |
| 395 | default: |
| 396 | return -EINVAL; |
| 397 | } |
| 398 | break; |
| 399 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
| 401 | default: |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 402 | v4l_dbg(1, debug, client, "unknown command %08x\n", cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | return -EINVAL; |
| 404 | } |
| 405 | return 0; |
| 406 | } |
| 407 | |
| 408 | /* ----------------------------------------------------------------------- */ |
| 409 | |
| 410 | /* |
| 411 | * Generic i2c probe |
| 412 | * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1' |
| 413 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 415 | static unsigned short normal_i2c[] = { 0x9c >> 1, 0x9e >> 1, I2C_CLIENT_END }; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 416 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 417 | I2C_CLIENT_INSMOD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 419 | static int saa7110_probe(struct i2c_client *client, |
| 420 | const struct i2c_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | struct saa7110 *decoder; |
| 423 | int rv; |
| 424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | /* Check if the adapter supports the needed features */ |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 426 | if (!i2c_check_functionality(client->adapter, |
| 427 | I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) |
| 428 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 430 | v4l_info(client, "chip found @ 0x%x (%s)\n", |
| 431 | client->addr << 1, client->adapter->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 433 | decoder = kzalloc(sizeof(struct saa7110), GFP_KERNEL); |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 434 | if (!decoder) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | return -ENOMEM; |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame^] | 436 | decoder->norm = V4L2_STD_PAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | decoder->input = 0; |
| 438 | decoder->enable = 1; |
| 439 | decoder->bright = 32768; |
| 440 | decoder->contrast = 32768; |
| 441 | decoder->hue = 32768; |
| 442 | decoder->sat = 32768; |
| 443 | init_waitqueue_head(&decoder->wq); |
| 444 | i2c_set_clientdata(client, decoder); |
| 445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | rv = saa7110_write_block(client, initseq, sizeof(initseq)); |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 447 | if (rv < 0) { |
| 448 | v4l_dbg(1, debug, client, "init status %d\n", rv); |
| 449 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 450 | int ver, status; |
| 451 | saa7110_write(client, 0x21, 0x10); |
| 452 | saa7110_write(client, 0x0e, 0x18); |
| 453 | saa7110_write(client, 0x0D, 0x04); |
| 454 | ver = saa7110_read(client); |
| 455 | saa7110_write(client, 0x0D, 0x06); |
| 456 | //mdelay(150); |
| 457 | status = saa7110_read(client); |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 458 | v4l_dbg(1, debug, client, "version %x, status=0x%02x\n", |
| 459 | ver, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | saa7110_write(client, 0x0D, 0x86); |
| 461 | saa7110_write(client, 0x0F, 0x10); |
| 462 | saa7110_write(client, 0x11, 0x59); |
| 463 | //saa7110_write(client, 0x2E, 0x9A); |
| 464 | } |
| 465 | |
| 466 | //saa7110_selmux(client,0); |
| 467 | //determine_norm(client); |
| 468 | /* setup and implicit mode 0 select has been performed */ |
| 469 | |
| 470 | return 0; |
| 471 | } |
| 472 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 473 | static int saa7110_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | { |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 475 | kfree(i2c_get_clientdata(client)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | return 0; |
| 477 | } |
| 478 | |
| 479 | /* ----------------------------------------------------------------------- */ |
| 480 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 481 | static const struct i2c_device_id saa7110_id[] = { |
| 482 | { "saa7110", 0 }, |
| 483 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | }; |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 485 | MODULE_DEVICE_TABLE(i2c, saa7110_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 487 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
| 488 | .name = "saa7110", |
| 489 | .driverid = I2C_DRIVERID_SAA7110, |
| 490 | .command = saa7110_command, |
| 491 | .probe = saa7110_probe, |
| 492 | .remove = saa7110_remove, |
| 493 | .id_table = saa7110_id, |
| 494 | }; |