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> |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 36 | #include <linux/videodev2.h> |
| 37 | #include <media/v4l2-device.h> |
| 38 | #include <media/v4l2-chip-ident.h> |
Hans Verkuil | 2d26698 | 2009-02-19 17:41:19 -0300 | [diff] [blame] | 39 | #include <media/v4l2-i2c-drv.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 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 45 | |
Douglas Schilling Landgraf | ff699e6 | 2008-04-22 14:41:48 -0300 | [diff] [blame] | 46 | static int debug; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | module_param(debug, int, 0); |
| 48 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); |
| 49 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define SAA7110_MAX_INPUT 9 /* 6 CVBS, 3 SVHS */ |
Jean Delvare | 8182ff6 | 2008-10-24 15:08:28 -0300 | [diff] [blame] | 51 | #define SAA7110_MAX_OUTPUT 1 /* 1 YUV */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | #define SAA7110_NR_REG 0x35 |
| 54 | |
| 55 | struct saa7110 { |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 56 | struct v4l2_subdev sd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | u8 reg[SAA7110_NR_REG]; |
| 58 | |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 59 | v4l2_std_id norm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | int input; |
| 61 | int enable; |
| 62 | int bright; |
| 63 | int contrast; |
| 64 | int hue; |
| 65 | int sat; |
| 66 | |
| 67 | wait_queue_head_t wq; |
| 68 | }; |
| 69 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 70 | static inline struct saa7110 *to_saa7110(struct v4l2_subdev *sd) |
| 71 | { |
| 72 | return container_of(sd, struct saa7110, sd); |
| 73 | } |
| 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | /* ----------------------------------------------------------------------- */ |
| 76 | /* I2C support functions */ |
| 77 | /* ----------------------------------------------------------------------- */ |
| 78 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 79 | static int saa7110_write(struct v4l2_subdev *sd, u8 reg, u8 value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 81 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 82 | struct saa7110 *decoder = to_saa7110(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | decoder->reg[reg] = value; |
| 85 | return i2c_smbus_write_byte_data(client, reg, value); |
| 86 | } |
| 87 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 88 | static int saa7110_write_block(struct v4l2_subdev *sd, const u8 *data, unsigned int len) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 90 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 91 | struct saa7110 *decoder = to_saa7110(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | int ret = -1; |
| 93 | u8 reg = *data; /* first register to write to */ |
| 94 | |
| 95 | /* Sanity check */ |
| 96 | if (reg + (len - 1) > SAA7110_NR_REG) |
| 97 | return ret; |
| 98 | |
| 99 | /* the saa7110 has an autoincrement function, use it if |
| 100 | * the adapter understands raw I2C */ |
| 101 | if (i2c_check_functionality(client->adapter, I2C_FUNC_I2C)) { |
Jean Delvare | 9aa45e3 | 2006-03-22 03:48:35 -0300 | [diff] [blame] | 102 | ret = i2c_master_send(client, data, len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | /* Cache the written data */ |
| 105 | memcpy(decoder->reg + reg, data + 1, len - 1); |
| 106 | } else { |
| 107 | for (++data, --len; len; len--) { |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 108 | ret = saa7110_write(sd, reg++, *data++); |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 109 | if (ret < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | break; |
| 111 | } |
| 112 | } |
| 113 | |
| 114 | return ret; |
| 115 | } |
| 116 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 117 | static inline int saa7110_read(struct v4l2_subdev *sd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 119 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | return i2c_smbus_read_byte(client); |
| 122 | } |
| 123 | |
| 124 | /* ----------------------------------------------------------------------- */ |
| 125 | /* SAA7110 functions */ |
| 126 | /* ----------------------------------------------------------------------- */ |
| 127 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 128 | #define FRESP_06H_COMPST 0x03 /*0x13*/ |
| 129 | #define FRESP_06H_SVIDEO 0x83 /*0xC0*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 132 | static int saa7110_selmux(struct v4l2_subdev *sd, int chan) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | { |
| 134 | static const unsigned char modes[9][8] = { |
| 135 | /* mode 0 */ |
| 136 | {FRESP_06H_COMPST, 0xD9, 0x17, 0x40, 0x03, |
| 137 | 0x44, 0x75, 0x16}, |
| 138 | /* mode 1 */ |
| 139 | {FRESP_06H_COMPST, 0xD8, 0x17, 0x40, 0x03, |
| 140 | 0x44, 0x75, 0x16}, |
| 141 | /* mode 2 */ |
| 142 | {FRESP_06H_COMPST, 0xBA, 0x07, 0x91, 0x03, |
| 143 | 0x60, 0xB5, 0x05}, |
| 144 | /* mode 3 */ |
| 145 | {FRESP_06H_COMPST, 0xB8, 0x07, 0x91, 0x03, |
| 146 | 0x60, 0xB5, 0x05}, |
| 147 | /* mode 4 */ |
| 148 | {FRESP_06H_COMPST, 0x7C, 0x07, 0xD2, 0x83, |
| 149 | 0x60, 0xB5, 0x03}, |
| 150 | /* mode 5 */ |
| 151 | {FRESP_06H_COMPST, 0x78, 0x07, 0xD2, 0x83, |
| 152 | 0x60, 0xB5, 0x03}, |
| 153 | /* mode 6 */ |
| 154 | {FRESP_06H_SVIDEO, 0x59, 0x17, 0x42, 0xA3, |
| 155 | 0x44, 0x75, 0x12}, |
| 156 | /* mode 7 */ |
| 157 | {FRESP_06H_SVIDEO, 0x9A, 0x17, 0xB1, 0x13, |
| 158 | 0x60, 0xB5, 0x14}, |
| 159 | /* mode 8 */ |
| 160 | {FRESP_06H_SVIDEO, 0x3C, 0x27, 0xC1, 0x23, |
| 161 | 0x44, 0x75, 0x21} |
| 162 | }; |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 163 | struct saa7110 *decoder = to_saa7110(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | const unsigned char *ptr = modes[chan]; |
| 165 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 166 | saa7110_write(sd, 0x06, ptr[0]); /* Luminance control */ |
| 167 | saa7110_write(sd, 0x20, ptr[1]); /* Analog Control #1 */ |
| 168 | saa7110_write(sd, 0x21, ptr[2]); /* Analog Control #2 */ |
| 169 | saa7110_write(sd, 0x22, ptr[3]); /* Mixer Control #1 */ |
| 170 | saa7110_write(sd, 0x2C, ptr[4]); /* Mixer Control #2 */ |
| 171 | saa7110_write(sd, 0x30, ptr[5]); /* ADCs gain control */ |
| 172 | saa7110_write(sd, 0x31, ptr[6]); /* Mixer Control #3 */ |
| 173 | saa7110_write(sd, 0x21, ptr[7]); /* Analog Control #2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | decoder->input = chan; |
| 175 | |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | static const unsigned char initseq[1 + SAA7110_NR_REG] = { |
| 180 | 0, 0x4C, 0x3C, 0x0D, 0xEF, 0xBD, 0xF2, 0x03, 0x00, |
| 181 | /* 0x08 */ 0xF8, 0xF8, 0x60, 0x60, 0x00, 0x86, 0x18, 0x90, |
| 182 | /* 0x10 */ 0x00, 0x59, 0x40, 0x46, 0x42, 0x1A, 0xFF, 0xDA, |
| 183 | /* 0x18 */ 0xF2, 0x8B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 184 | /* 0x20 */ 0xD9, 0x16, 0x40, 0x41, 0x80, 0x41, 0x80, 0x4F, |
| 185 | /* 0x28 */ 0xFE, 0x01, 0xCF, 0x0F, 0x03, 0x01, 0x03, 0x0C, |
| 186 | /* 0x30 */ 0x44, 0x71, 0x02, 0x8C, 0x02 |
| 187 | }; |
| 188 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 189 | static v4l2_std_id determine_norm(struct v4l2_subdev *sd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | { |
| 191 | DEFINE_WAIT(wait); |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 192 | struct saa7110 *decoder = to_saa7110(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | int status; |
| 194 | |
| 195 | /* mode changed, start automatic detection */ |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 196 | saa7110_write_block(sd, initseq, sizeof(initseq)); |
| 197 | saa7110_selmux(sd, decoder->input); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE); |
Mauro Carvalho Chehab | 09df5cb | 2007-07-17 16:25:38 -0300 | [diff] [blame] | 199 | schedule_timeout(msecs_to_jiffies(250)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | finish_wait(&decoder->wq, &wait); |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 201 | status = saa7110_read(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | if (status & 0x40) { |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 203 | v4l2_dbg(1, debug, sd, "status=0x%02x (no signal)\n", status); |
| 204 | return decoder->norm; /* no change*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | } |
| 206 | if ((status & 3) == 0) { |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 207 | saa7110_write(sd, 0x06, 0x83); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | if (status & 0x20) { |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 209 | v4l2_dbg(1, debug, sd, "status=0x%02x (NTSC/no color)\n", status); |
| 210 | /*saa7110_write(sd,0x2E,0x81);*/ |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 211 | return V4L2_STD_NTSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | } |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 213 | v4l2_dbg(1, debug, sd, "status=0x%02x (PAL/no color)\n", status); |
| 214 | /*saa7110_write(sd,0x2E,0x9A);*/ |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 215 | return V4L2_STD_PAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | } |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 217 | /*saa7110_write(sd,0x06,0x03);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | if (status & 0x20) { /* 60Hz */ |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 219 | v4l2_dbg(1, debug, sd, "status=0x%02x (NTSC)\n", status); |
| 220 | saa7110_write(sd, 0x0D, 0x86); |
| 221 | saa7110_write(sd, 0x0F, 0x50); |
| 222 | saa7110_write(sd, 0x11, 0x2C); |
| 223 | /*saa7110_write(sd,0x2E,0x81);*/ |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 224 | return V4L2_STD_NTSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } |
| 226 | |
| 227 | /* 50Hz -> PAL/SECAM */ |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 228 | saa7110_write(sd, 0x0D, 0x86); |
| 229 | saa7110_write(sd, 0x0F, 0x10); |
| 230 | saa7110_write(sd, 0x11, 0x59); |
| 231 | /*saa7110_write(sd,0x2E,0x9A);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | |
| 233 | prepare_to_wait(&decoder->wq, &wait, TASK_UNINTERRUPTIBLE); |
Mauro Carvalho Chehab | 09df5cb | 2007-07-17 16:25:38 -0300 | [diff] [blame] | 234 | schedule_timeout(msecs_to_jiffies(250)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | finish_wait(&decoder->wq, &wait); |
| 236 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 237 | status = saa7110_read(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | if ((status & 0x03) == 0x01) { |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 239 | v4l2_dbg(1, debug, sd, "status=0x%02x (SECAM)\n", status); |
| 240 | saa7110_write(sd, 0x0D, 0x87); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 241 | return V4L2_STD_SECAM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 243 | v4l2_dbg(1, debug, sd, "status=0x%02x (PAL)\n", status); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 244 | return V4L2_STD_PAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 247 | static int saa7110_g_input_status(struct v4l2_subdev *sd, u32 *pstatus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | { |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 249 | struct saa7110 *decoder = to_saa7110(sd); |
| 250 | int res = V4L2_IN_ST_NO_SIGNAL; |
| 251 | int status = saa7110_read(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 253 | v4l2_dbg(1, debug, sd, "status=0x%02x norm=%llx\n", |
Hans Verkuil | cc5cef8 | 2009-03-06 10:15:01 -0300 | [diff] [blame] | 254 | status, (unsigned long long)decoder->norm); |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 255 | if (!(status & 0x40)) |
| 256 | res = 0; |
| 257 | if (!(status & 0x03)) |
| 258 | res |= V4L2_IN_ST_NO_COLOR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 260 | *pstatus = res; |
| 261 | return 0; |
| 262 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 264 | static int saa7110_querystd(struct v4l2_subdev *sd, v4l2_std_id *std) |
| 265 | { |
| 266 | *(v4l2_std_id *)std = determine_norm(sd); |
| 267 | return 0; |
| 268 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 270 | static int saa7110_s_std(struct v4l2_subdev *sd, v4l2_std_id std) |
| 271 | { |
| 272 | struct saa7110 *decoder = to_saa7110(sd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 274 | if (decoder->norm != std) { |
| 275 | decoder->norm = std; |
| 276 | /*saa7110_write(sd, 0x06, 0x03);*/ |
| 277 | if (std & V4L2_STD_NTSC) { |
| 278 | saa7110_write(sd, 0x0D, 0x86); |
| 279 | saa7110_write(sd, 0x0F, 0x50); |
| 280 | saa7110_write(sd, 0x11, 0x2C); |
| 281 | /*saa7110_write(sd, 0x2E, 0x81);*/ |
| 282 | v4l2_dbg(1, debug, sd, "switched to NTSC\n"); |
| 283 | } else if (std & V4L2_STD_PAL) { |
| 284 | saa7110_write(sd, 0x0D, 0x86); |
| 285 | saa7110_write(sd, 0x0F, 0x10); |
| 286 | saa7110_write(sd, 0x11, 0x59); |
| 287 | /*saa7110_write(sd, 0x2E, 0x9A);*/ |
| 288 | v4l2_dbg(1, debug, sd, "switched to PAL\n"); |
| 289 | } else if (std & V4L2_STD_SECAM) { |
| 290 | saa7110_write(sd, 0x0D, 0x87); |
| 291 | saa7110_write(sd, 0x0F, 0x10); |
| 292 | saa7110_write(sd, 0x11, 0x59); |
| 293 | /*saa7110_write(sd, 0x2E, 0x9A);*/ |
| 294 | v4l2_dbg(1, debug, sd, "switched to SECAM\n"); |
| 295 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | return -EINVAL; |
| 297 | } |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 298 | } |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 299 | return 0; |
| 300 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 302 | static int saa7110_s_routing(struct v4l2_subdev *sd, |
| 303 | u32 input, u32 output, u32 config) |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 304 | { |
| 305 | struct saa7110 *decoder = to_saa7110(sd); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 306 | |
Roel Kluin | f14a297 | 2009-10-23 07:59:42 -0300 | [diff] [blame] | 307 | if (input >= SAA7110_MAX_INPUT) { |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 308 | v4l2_dbg(1, debug, sd, "input=%d not available\n", input); |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 309 | return -EINVAL; |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 310 | } |
Hans Verkuil | 5325b42 | 2009-04-02 11:26:22 -0300 | [diff] [blame] | 311 | if (decoder->input != input) { |
| 312 | saa7110_selmux(sd, input); |
| 313 | v4l2_dbg(1, debug, sd, "switched to input=%d\n", input); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 314 | } |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 315 | return 0; |
| 316 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 318 | static int saa7110_s_stream(struct v4l2_subdev *sd, int enable) |
| 319 | { |
| 320 | struct saa7110 *decoder = to_saa7110(sd); |
| 321 | |
| 322 | if (decoder->enable != enable) { |
| 323 | decoder->enable = enable; |
| 324 | saa7110_write(sd, 0x0E, enable ? 0x18 : 0x80); |
| 325 | v4l2_dbg(1, debug, sd, "YUV %s\n", enable ? "on" : "off"); |
| 326 | } |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | static int saa7110_queryctrl(struct v4l2_subdev *sd, struct v4l2_queryctrl *qc) |
| 331 | { |
| 332 | switch (qc->id) { |
| 333 | case V4L2_CID_BRIGHTNESS: |
| 334 | return v4l2_ctrl_query_fill(qc, 0, 255, 1, 128); |
| 335 | case V4L2_CID_CONTRAST: |
| 336 | case V4L2_CID_SATURATION: |
| 337 | return v4l2_ctrl_query_fill(qc, 0, 127, 1, 64); |
| 338 | case V4L2_CID_HUE: |
| 339 | return v4l2_ctrl_query_fill(qc, -128, 127, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | return -EINVAL; |
| 342 | } |
| 343 | return 0; |
| 344 | } |
| 345 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 346 | static int saa7110_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
| 347 | { |
| 348 | struct saa7110 *decoder = to_saa7110(sd); |
| 349 | |
| 350 | switch (ctrl->id) { |
| 351 | case V4L2_CID_BRIGHTNESS: |
| 352 | ctrl->value = decoder->bright; |
| 353 | break; |
| 354 | case V4L2_CID_CONTRAST: |
| 355 | ctrl->value = decoder->contrast; |
| 356 | break; |
| 357 | case V4L2_CID_SATURATION: |
| 358 | ctrl->value = decoder->sat; |
| 359 | break; |
| 360 | case V4L2_CID_HUE: |
| 361 | ctrl->value = decoder->hue; |
| 362 | break; |
| 363 | default: |
| 364 | return -EINVAL; |
| 365 | } |
| 366 | return 0; |
| 367 | } |
| 368 | |
| 369 | static int saa7110_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl) |
| 370 | { |
| 371 | struct saa7110 *decoder = to_saa7110(sd); |
| 372 | |
| 373 | switch (ctrl->id) { |
| 374 | case V4L2_CID_BRIGHTNESS: |
| 375 | if (decoder->bright != ctrl->value) { |
| 376 | decoder->bright = ctrl->value; |
| 377 | saa7110_write(sd, 0x19, decoder->bright); |
| 378 | } |
| 379 | break; |
| 380 | case V4L2_CID_CONTRAST: |
| 381 | if (decoder->contrast != ctrl->value) { |
| 382 | decoder->contrast = ctrl->value; |
| 383 | saa7110_write(sd, 0x13, decoder->contrast); |
| 384 | } |
| 385 | break; |
| 386 | case V4L2_CID_SATURATION: |
| 387 | if (decoder->sat != ctrl->value) { |
| 388 | decoder->sat = ctrl->value; |
| 389 | saa7110_write(sd, 0x12, decoder->sat); |
| 390 | } |
| 391 | break; |
| 392 | case V4L2_CID_HUE: |
| 393 | if (decoder->hue != ctrl->value) { |
| 394 | decoder->hue = ctrl->value; |
| 395 | saa7110_write(sd, 0x07, decoder->hue); |
| 396 | } |
| 397 | break; |
| 398 | default: |
| 399 | return -EINVAL; |
| 400 | } |
| 401 | return 0; |
| 402 | } |
| 403 | |
| 404 | static int saa7110_g_chip_ident(struct v4l2_subdev *sd, struct v4l2_dbg_chip_ident *chip) |
| 405 | { |
| 406 | struct i2c_client *client = v4l2_get_subdevdata(sd); |
| 407 | |
| 408 | return v4l2_chip_ident_i2c_client(client, chip, V4L2_IDENT_SAA7110, 0); |
| 409 | } |
| 410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | /* ----------------------------------------------------------------------- */ |
| 412 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 413 | static const struct v4l2_subdev_core_ops saa7110_core_ops = { |
| 414 | .g_chip_ident = saa7110_g_chip_ident, |
| 415 | .g_ctrl = saa7110_g_ctrl, |
| 416 | .s_ctrl = saa7110_s_ctrl, |
| 417 | .queryctrl = saa7110_queryctrl, |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 418 | .s_std = saa7110_s_std, |
| 419 | }; |
Mauro Carvalho Chehab | d56410e | 2006-03-25 09:19:53 -0300 | [diff] [blame] | 420 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 421 | static const struct v4l2_subdev_video_ops saa7110_video_ops = { |
| 422 | .s_routing = saa7110_s_routing, |
| 423 | .s_stream = saa7110_s_stream, |
| 424 | .querystd = saa7110_querystd, |
| 425 | .g_input_status = saa7110_g_input_status, |
| 426 | }; |
| 427 | |
| 428 | static const struct v4l2_subdev_ops saa7110_ops = { |
| 429 | .core = &saa7110_core_ops, |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 430 | .video = &saa7110_video_ops, |
| 431 | }; |
| 432 | |
| 433 | /* ----------------------------------------------------------------------- */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 435 | static int saa7110_probe(struct i2c_client *client, |
| 436 | const struct i2c_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | struct saa7110 *decoder; |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 439 | struct v4l2_subdev *sd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | int rv; |
| 441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | /* Check if the adapter supports the needed features */ |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 443 | if (!i2c_check_functionality(client->adapter, |
| 444 | I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) |
| 445 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 447 | v4l_info(client, "chip found @ 0x%x (%s)\n", |
| 448 | client->addr << 1, client->adapter->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 450 | decoder = kzalloc(sizeof(struct saa7110), GFP_KERNEL); |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 451 | if (!decoder) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | return -ENOMEM; |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 453 | sd = &decoder->sd; |
| 454 | v4l2_i2c_subdev_init(sd, client, &saa7110_ops); |
Hans Verkuil | 107063c | 2009-02-18 17:26:06 -0300 | [diff] [blame] | 455 | decoder->norm = V4L2_STD_PAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | decoder->input = 0; |
| 457 | decoder->enable = 1; |
| 458 | decoder->bright = 32768; |
| 459 | decoder->contrast = 32768; |
| 460 | decoder->hue = 32768; |
| 461 | decoder->sat = 32768; |
| 462 | init_waitqueue_head(&decoder->wq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 464 | rv = saa7110_write_block(sd, initseq, sizeof(initseq)); |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 465 | if (rv < 0) { |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 466 | v4l2_dbg(1, debug, sd, "init status %d\n", rv); |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 467 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | int ver, status; |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 469 | saa7110_write(sd, 0x21, 0x10); |
| 470 | saa7110_write(sd, 0x0e, 0x18); |
| 471 | saa7110_write(sd, 0x0D, 0x04); |
| 472 | ver = saa7110_read(sd); |
| 473 | saa7110_write(sd, 0x0D, 0x06); |
| 474 | /*mdelay(150);*/ |
| 475 | status = saa7110_read(sd); |
| 476 | v4l2_dbg(1, debug, sd, "version %x, status=0x%02x\n", |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 477 | ver, status); |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 478 | saa7110_write(sd, 0x0D, 0x86); |
| 479 | saa7110_write(sd, 0x0F, 0x10); |
| 480 | saa7110_write(sd, 0x11, 0x59); |
| 481 | /*saa7110_write(sd, 0x2E, 0x9A);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | } |
| 483 | |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 484 | /*saa7110_selmux(sd,0);*/ |
| 485 | /*determine_norm(sd);*/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | /* setup and implicit mode 0 select has been performed */ |
| 487 | |
| 488 | return 0; |
| 489 | } |
| 490 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 491 | static int saa7110_remove(struct i2c_client *client) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
Hans Verkuil | e794684 | 2009-02-19 12:24:27 -0300 | [diff] [blame] | 493 | struct v4l2_subdev *sd = i2c_get_clientdata(client); |
| 494 | |
| 495 | v4l2_device_unregister_subdev(sd); |
| 496 | kfree(to_saa7110(sd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 | return 0; |
| 498 | } |
| 499 | |
| 500 | /* ----------------------------------------------------------------------- */ |
| 501 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 502 | static const struct i2c_device_id saa7110_id[] = { |
| 503 | { "saa7110", 0 }, |
| 504 | { } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | }; |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 506 | MODULE_DEVICE_TABLE(i2c, saa7110_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 508 | static struct v4l2_i2c_driver_data v4l2_i2c_data = { |
| 509 | .name = "saa7110", |
Hans Verkuil | 85ede69 | 2008-09-07 08:00:32 -0300 | [diff] [blame] | 510 | .probe = saa7110_probe, |
| 511 | .remove = saa7110_remove, |
| 512 | .id_table = saa7110_id, |
| 513 | }; |