Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * tvp5150 - Texas Instruments TVP5150A(M) video decoder driver |
| 3 | * |
| 4 | * Copyright (c) 2005 Mauro Carvalho Chehab (mchehab@brturbo.com.br) |
| 5 | * This code is placed under the terms of the GNU General Public License |
| 6 | */ |
| 7 | |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 8 | #include <linux/i2c.h> |
| 9 | #include <linux/videodev.h> |
| 10 | #include <linux/delay.h> |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 11 | #include <linux/video_decoder.h> |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 12 | #include <media/v4l2-common.h> |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 13 | |
| 14 | #include "tvp5150_reg.h" |
| 15 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 16 | MODULE_DESCRIPTION("Texas Instruments TVP5150A video decoder driver"); /* standard i2c insmod options */ |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 17 | MODULE_AUTHOR("Mauro Carvalho Chehab"); |
| 18 | MODULE_LICENSE("GPL"); |
| 19 | |
| 20 | static unsigned short normal_i2c[] = { |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 21 | 0xb8 >> 1, |
| 22 | 0xba >> 1, |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 23 | I2C_CLIENT_END |
| 24 | }; |
| 25 | |
| 26 | I2C_CLIENT_INSMOD; |
| 27 | |
| 28 | static int debug = 0; |
| 29 | module_param(debug, int, 0); |
| 30 | MODULE_PARM_DESC(debug, "Debug level (0-1)"); |
| 31 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 32 | #define tvp5150_info(fmt, arg...) do { \ |
Mauro Carvalho Chehab | cab462f | 2006-01-09 15:53:26 -0200 | [diff] [blame] | 33 | printk(KERN_INFO "%s %d-%04x: " fmt, c->driver->driver.name, \ |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 34 | i2c_adapter_id(c->adapter), c->addr , ## arg); } while (0) |
| 35 | #define tvp5150_dbg(num, fmt, arg...) \ |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 36 | do { \ |
| 37 | if (debug >= num) \ |
Mauro Carvalho Chehab | cab462f | 2006-01-09 15:53:26 -0200 | [diff] [blame] | 38 | printk(KERN_DEBUG "%s debug %d-%04x: " fmt,\ |
| 39 | c->driver->driver.name, \ |
| 40 | i2c_adapter_id(c->adapter), \ |
| 41 | c->addr , ## arg); } while (0) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 42 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 43 | /* supported controls */ |
| 44 | static struct v4l2_queryctrl tvp5150_qctrl[] = { |
| 45 | { |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 46 | .id = V4L2_CID_BRIGHTNESS, |
| 47 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 48 | .name = "Brightness", |
| 49 | .minimum = 0, |
| 50 | .maximum = 255, |
| 51 | .step = 1, |
| 52 | .default_value = 0, |
| 53 | .flags = 0, |
| 54 | }, { |
| 55 | .id = V4L2_CID_CONTRAST, |
| 56 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 57 | .name = "Contrast", |
| 58 | .minimum = 0, |
| 59 | .maximum = 255, |
| 60 | .step = 0x1, |
| 61 | .default_value = 0x10, |
| 62 | .flags = 0, |
| 63 | }, { |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 64 | .id = V4L2_CID_SATURATION, |
| 65 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 66 | .name = "Saturation", |
| 67 | .minimum = 0, |
| 68 | .maximum = 255, |
| 69 | .step = 0x1, |
| 70 | .default_value = 0x10, |
| 71 | .flags = 0, |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 72 | }, { |
| 73 | .id = V4L2_CID_HUE, |
| 74 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 75 | .name = "Hue", |
| 76 | .minimum = -128, |
| 77 | .maximum = 127, |
| 78 | .step = 0x1, |
| 79 | .default_value = 0x10, |
| 80 | .flags = 0, |
| 81 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 82 | }; |
| 83 | |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 84 | struct tvp5150 { |
| 85 | struct i2c_client *client; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 86 | |
| 87 | int norm; |
| 88 | int input; |
| 89 | int enable; |
| 90 | int bright; |
| 91 | int contrast; |
| 92 | int hue; |
| 93 | int sat; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 94 | }; |
| 95 | |
Arjan van de Ven | 858119e | 2006-01-14 13:20:43 -0800 | [diff] [blame^] | 96 | static int tvp5150_read(struct i2c_client *c, unsigned char addr) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 97 | { |
| 98 | unsigned char buffer[1]; |
| 99 | int rc; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 100 | |
| 101 | buffer[0] = addr; |
| 102 | if (1 != (rc = i2c_master_send(c, buffer, 1))) |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 103 | tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 1)\n", rc); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 104 | |
| 105 | msleep(10); |
| 106 | |
| 107 | if (1 != (rc = i2c_master_recv(c, buffer, 1))) |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 108 | tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 1)\n", rc); |
| 109 | |
| 110 | tvp5150_dbg(2, "tvp5150: read 0x%02x = 0x%02x\n", addr, buffer[0]); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 111 | |
| 112 | return (buffer[0]); |
| 113 | } |
| 114 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 115 | static inline void tvp5150_write(struct i2c_client *c, unsigned char addr, |
| 116 | unsigned char value) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 117 | { |
| 118 | unsigned char buffer[2]; |
| 119 | int rc; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 120 | |
| 121 | buffer[0] = addr; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 122 | buffer[1] = value; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 123 | tvp5150_dbg(2, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 124 | if (2 != (rc = i2c_master_send(c, buffer, 2))) |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 125 | tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 2)\n", rc); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 126 | } |
| 127 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 128 | static void dump_reg(struct i2c_client *c) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 129 | { |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 130 | printk("tvp5150: Video input source selection #1 = 0x%02x\n", |
| 131 | tvp5150_read(c, TVP5150_VD_IN_SRC_SEL_1)); |
| 132 | printk("tvp5150: Analog channel controls = 0x%02x\n", |
| 133 | tvp5150_read(c, TVP5150_ANAL_CHL_CTL)); |
| 134 | printk("tvp5150: Operation mode controls = 0x%02x\n", |
| 135 | tvp5150_read(c, TVP5150_OP_MODE_CTL)); |
| 136 | printk("tvp5150: Miscellaneous controls = 0x%02x\n", |
| 137 | tvp5150_read(c, TVP5150_MISC_CTL)); |
| 138 | printk("tvp5150: Autoswitch mask: TVP5150A / TVP5150AM = 0x%02x\n", |
| 139 | tvp5150_read(c, TVP5150_AUTOSW_MSK)); |
| 140 | printk("tvp5150: Color killer threshold control = 0x%02x\n", |
| 141 | tvp5150_read(c, TVP5150_COLOR_KIL_THSH_CTL)); |
| 142 | printk("tvp5150: Luminance processing control #1 = 0x%02x\n", |
| 143 | tvp5150_read(c, TVP5150_LUMA_PROC_CTL_1)); |
| 144 | printk("tvp5150: Luminance processing control #2 = 0x%02x\n", |
| 145 | tvp5150_read(c, TVP5150_LUMA_PROC_CTL_2)); |
| 146 | printk("tvp5150: Brightness control = 0x%02x\n", |
| 147 | tvp5150_read(c, TVP5150_BRIGHT_CTL)); |
| 148 | printk("tvp5150: Color saturation control = 0x%02x\n", |
| 149 | tvp5150_read(c, TVP5150_SATURATION_CTL)); |
| 150 | printk("tvp5150: Hue control = 0x%02x\n", |
| 151 | tvp5150_read(c, TVP5150_HUE_CTL)); |
| 152 | printk("tvp5150: Contrast control = 0x%02x\n", |
| 153 | tvp5150_read(c, TVP5150_CONTRAST_CTL)); |
| 154 | printk("tvp5150: Outputs and data rates select = 0x%02x\n", |
| 155 | tvp5150_read(c, TVP5150_DATA_RATE_SEL)); |
| 156 | printk("tvp5150: Luminance processing control #3 = 0x%02x\n", |
| 157 | tvp5150_read(c, TVP5150_LUMA_PROC_CTL_3)); |
| 158 | printk("tvp5150: Configuration shared pins = 0x%02x\n", |
| 159 | tvp5150_read(c, TVP5150_CONF_SHARED_PIN)); |
| 160 | printk("tvp5150: Active video cropping start MSB = 0x%02x\n", |
| 161 | tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_MSB)); |
| 162 | printk("tvp5150: Active video cropping start LSB = 0x%02x\n", |
| 163 | tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_LSB)); |
| 164 | printk("tvp5150: Active video cropping stop MSB = 0x%02x\n", |
| 165 | tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_MSB)); |
| 166 | printk("tvp5150: Active video cropping stop LSB = 0x%02x\n", |
| 167 | tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_LSB)); |
| 168 | printk("tvp5150: Genlock/RTC = 0x%02x\n", |
| 169 | tvp5150_read(c, TVP5150_GENLOCK)); |
| 170 | printk("tvp5150: Horizontal sync start = 0x%02x\n", |
| 171 | tvp5150_read(c, TVP5150_HORIZ_SYNC_START)); |
| 172 | printk("tvp5150: Vertical blanking start = 0x%02x\n", |
| 173 | tvp5150_read(c, TVP5150_VERT_BLANKING_START)); |
| 174 | printk("tvp5150: Vertical blanking stop = 0x%02x\n", |
| 175 | tvp5150_read(c, TVP5150_VERT_BLANKING_STOP)); |
| 176 | printk("tvp5150: Chrominance processing control #1 = 0x%02x\n", |
| 177 | tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_1)); |
| 178 | printk("tvp5150: Chrominance processing control #2 = 0x%02x\n", |
| 179 | tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_2)); |
| 180 | printk("tvp5150: Interrupt reset register B = 0x%02x\n", |
| 181 | tvp5150_read(c, TVP5150_INT_RESET_REG_B)); |
| 182 | printk("tvp5150: Interrupt enable register B = 0x%02x\n", |
| 183 | tvp5150_read(c, TVP5150_INT_ENABLE_REG_B)); |
| 184 | printk("tvp5150: Interrupt configuration register B = 0x%02x\n", |
| 185 | tvp5150_read(c, TVP5150_INTT_CONFIG_REG_B)); |
| 186 | printk("tvp5150: Video standard = 0x%02x\n", |
| 187 | tvp5150_read(c, TVP5150_VIDEO_STD)); |
| 188 | printk("tvp5150: Cb gain factor = 0x%02x\n", |
| 189 | tvp5150_read(c, TVP5150_CB_GAIN_FACT)); |
| 190 | printk("tvp5150: Cr gain factor = 0x%02x\n", |
| 191 | tvp5150_read(c, TVP5150_CR_GAIN_FACTOR)); |
| 192 | printk("tvp5150: Macrovision on counter = 0x%02x\n", |
| 193 | tvp5150_read(c, TVP5150_MACROVISION_ON_CTR)); |
| 194 | printk("tvp5150: Macrovision off counter = 0x%02x\n", |
| 195 | tvp5150_read(c, TVP5150_MACROVISION_OFF_CTR)); |
| 196 | printk("tvp5150: revision select (TVP5150AM1 only) = 0x%02x\n", |
| 197 | tvp5150_read(c, TVP5150_REV_SELECT)); |
| 198 | printk("tvp5150: MSB of device ID = 0x%02x\n", |
| 199 | tvp5150_read(c, TVP5150_MSB_DEV_ID)); |
| 200 | printk("tvp5150: LSB of device ID = 0x%02x\n", |
| 201 | tvp5150_read(c, TVP5150_LSB_DEV_ID)); |
| 202 | printk("tvp5150: ROM major version = 0x%02x\n", |
| 203 | tvp5150_read(c, TVP5150_ROM_MAJOR_VER)); |
| 204 | printk("tvp5150: ROM minor version = 0x%02x\n", |
| 205 | tvp5150_read(c, TVP5150_ROM_MINOR_VER)); |
| 206 | printk("tvp5150: Vertical line count MSB = 0x%02x\n", |
| 207 | tvp5150_read(c, TVP5150_VERT_LN_COUNT_MSB)); |
| 208 | printk("tvp5150: Vertical line count LSB = 0x%02x\n", |
| 209 | tvp5150_read(c, TVP5150_VERT_LN_COUNT_LSB)); |
| 210 | printk("tvp5150: Interrupt status register B = 0x%02x\n", |
| 211 | tvp5150_read(c, TVP5150_INT_STATUS_REG_B)); |
| 212 | printk("tvp5150: Interrupt active register B = 0x%02x\n", |
| 213 | tvp5150_read(c, TVP5150_INT_ACTIVE_REG_B)); |
| 214 | printk("tvp5150: Status register #1 = 0x%02x\n", |
| 215 | tvp5150_read(c, TVP5150_STATUS_REG_1)); |
| 216 | printk("tvp5150: Status register #2 = 0x%02x\n", |
| 217 | tvp5150_read(c, TVP5150_STATUS_REG_2)); |
| 218 | printk("tvp5150: Status register #3 = 0x%02x\n", |
| 219 | tvp5150_read(c, TVP5150_STATUS_REG_3)); |
| 220 | printk("tvp5150: Status register #4 = 0x%02x\n", |
| 221 | tvp5150_read(c, TVP5150_STATUS_REG_4)); |
| 222 | printk("tvp5150: Status register #5 = 0x%02x\n", |
| 223 | tvp5150_read(c, TVP5150_STATUS_REG_5)); |
| 224 | printk("tvp5150: Closed caption data registers = 0x%02x\n", |
| 225 | tvp5150_read(c, TVP5150_CC_DATA_REG1)); |
| 226 | printk("tvp5150: Closed caption data registers = 0x%02x\n", |
| 227 | tvp5150_read(c, TVP5150_CC_DATA_REG2)); |
| 228 | printk("tvp5150: Closed caption data registers = 0x%02x\n", |
| 229 | tvp5150_read(c, TVP5150_CC_DATA_REG3)); |
| 230 | printk("tvp5150: Closed caption data registers = 0x%02x\n", |
| 231 | tvp5150_read(c, TVP5150_CC_DATA_REG4)); |
| 232 | printk("tvp5150: WSS data registers = 0x%02x\n", |
| 233 | tvp5150_read(c, TVP5150_WSS_DATA_REG1)); |
| 234 | printk("tvp5150: WSS data registers = 0x%02x\n", |
| 235 | tvp5150_read(c, TVP5150_WSS_DATA_REG2)); |
| 236 | printk("tvp5150: WSS data registers = 0x%02x\n", |
| 237 | tvp5150_read(c, TVP5150_WSS_DATA_REG3)); |
| 238 | printk("tvp5150: WSS data registers = 0x%02x\n", |
| 239 | tvp5150_read(c, TVP5150_WSS_DATA_REG4)); |
| 240 | printk("tvp5150: WSS data registers = 0x%02x\n", |
| 241 | tvp5150_read(c, TVP5150_WSS_DATA_REG5)); |
| 242 | printk("tvp5150: WSS data registers = 0x%02x\n", |
| 243 | tvp5150_read(c, TVP5150_WSS_DATA_REG6)); |
| 244 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 245 | tvp5150_read(c, TVP5150_VPS_DATA_REG1)); |
| 246 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 247 | tvp5150_read(c, TVP5150_VPS_DATA_REG2)); |
| 248 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 249 | tvp5150_read(c, TVP5150_VPS_DATA_REG3)); |
| 250 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 251 | tvp5150_read(c, TVP5150_VPS_DATA_REG4)); |
| 252 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 253 | tvp5150_read(c, TVP5150_VPS_DATA_REG5)); |
| 254 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 255 | tvp5150_read(c, TVP5150_VPS_DATA_REG6)); |
| 256 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 257 | tvp5150_read(c, TVP5150_VPS_DATA_REG7)); |
| 258 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 259 | tvp5150_read(c, TVP5150_VPS_DATA_REG8)); |
| 260 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 261 | tvp5150_read(c, TVP5150_VPS_DATA_REG9)); |
| 262 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 263 | tvp5150_read(c, TVP5150_VPS_DATA_REG10)); |
| 264 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 265 | tvp5150_read(c, TVP5150_VPS_DATA_REG11)); |
| 266 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 267 | tvp5150_read(c, TVP5150_VPS_DATA_REG12)); |
| 268 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 269 | tvp5150_read(c, TVP5150_VPS_DATA_REG13)); |
| 270 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 271 | tvp5150_read(c, TVP5150_VITC_DATA_REG1)); |
| 272 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 273 | tvp5150_read(c, TVP5150_VITC_DATA_REG2)); |
| 274 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 275 | tvp5150_read(c, TVP5150_VITC_DATA_REG3)); |
| 276 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 277 | tvp5150_read(c, TVP5150_VITC_DATA_REG4)); |
| 278 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 279 | tvp5150_read(c, TVP5150_VITC_DATA_REG5)); |
| 280 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 281 | tvp5150_read(c, TVP5150_VITC_DATA_REG6)); |
| 282 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 283 | tvp5150_read(c, TVP5150_VITC_DATA_REG7)); |
| 284 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 285 | tvp5150_read(c, TVP5150_VITC_DATA_REG8)); |
| 286 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 287 | tvp5150_read(c, TVP5150_VITC_DATA_REG9)); |
| 288 | printk("tvp5150: VBI FIFO read data = 0x%02x\n", |
| 289 | tvp5150_read(c, TVP5150_VBI_FIFO_READ_DATA)); |
| 290 | printk("tvp5150: Teletext filter 1 = 0x%02x\n", |
| 291 | tvp5150_read(c, TVP5150_TELETEXT_FIL_1_1)); |
| 292 | printk("tvp5150: Teletext filter 1 = 0x%02x\n", |
| 293 | tvp5150_read(c, TVP5150_TELETEXT_FIL_1_2)); |
| 294 | printk("tvp5150: Teletext filter 1 = 0x%02x\n", |
| 295 | tvp5150_read(c, TVP5150_TELETEXT_FIL_1_3)); |
| 296 | printk("tvp5150: Teletext filter 1 = 0x%02x\n", |
| 297 | tvp5150_read(c, TVP5150_TELETEXT_FIL_1_4)); |
| 298 | printk("tvp5150: Teletext filter 1 = 0x%02x\n", |
| 299 | tvp5150_read(c, TVP5150_TELETEXT_FIL_1_5)); |
| 300 | printk("tvp5150: Teletext filter 2 = 0x%02x\n", |
| 301 | tvp5150_read(c, TVP5150_TELETEXT_FIL_2_1)); |
| 302 | printk("tvp5150: Teletext filter 2 = 0x%02x\n", |
| 303 | tvp5150_read(c, TVP5150_TELETEXT_FIL_2_2)); |
| 304 | printk("tvp5150: Teletext filter 2 = 0x%02x\n", |
| 305 | tvp5150_read(c, TVP5150_TELETEXT_FIL_2_3)); |
| 306 | printk("tvp5150: Teletext filter 2 = 0x%02x\n", |
| 307 | tvp5150_read(c, TVP5150_TELETEXT_FIL_2_4)); |
| 308 | printk("tvp5150: Teletext filter 2 = 0x%02x\n", |
| 309 | tvp5150_read(c, TVP5150_TELETEXT_FIL_2_5)); |
| 310 | printk("tvp5150: Teletext filter enable = 0x%02x\n", |
| 311 | tvp5150_read(c, TVP5150_TELETEXT_FIL_ENA)); |
| 312 | printk("tvp5150: Interrupt status register A = 0x%02x\n", |
| 313 | tvp5150_read(c, TVP5150_INT_STATUS_REG_A)); |
| 314 | printk("tvp5150: Interrupt enable register A = 0x%02x\n", |
| 315 | tvp5150_read(c, TVP5150_INT_ENABLE_REG_A)); |
| 316 | printk("tvp5150: Interrupt configuration = 0x%02x\n", |
| 317 | tvp5150_read(c, TVP5150_INT_CONF)); |
| 318 | printk("tvp5150: VDP configuration RAM data = 0x%02x\n", |
| 319 | tvp5150_read(c, TVP5150_VDP_CONF_RAM_DATA)); |
| 320 | printk("tvp5150: Configuration RAM address low byte = 0x%02x\n", |
| 321 | tvp5150_read(c, TVP5150_CONF_RAM_ADDR_LOW)); |
| 322 | printk("tvp5150: Configuration RAM address high byte = 0x%02x\n", |
| 323 | tvp5150_read(c, TVP5150_CONF_RAM_ADDR_HIGH)); |
| 324 | printk("tvp5150: VDP status register = 0x%02x\n", |
| 325 | tvp5150_read(c, TVP5150_VDP_STATUS_REG)); |
| 326 | printk("tvp5150: FIFO word count = 0x%02x\n", |
| 327 | tvp5150_read(c, TVP5150_FIFO_WORD_COUNT)); |
| 328 | printk("tvp5150: FIFO interrupt threshold = 0x%02x\n", |
| 329 | tvp5150_read(c, TVP5150_FIFO_INT_THRESHOLD)); |
| 330 | printk("tvp5150: FIFO reset = 0x%02x\n", |
| 331 | tvp5150_read(c, TVP5150_FIFO_RESET)); |
| 332 | printk("tvp5150: Line number interrupt = 0x%02x\n", |
| 333 | tvp5150_read(c, TVP5150_LINE_NUMBER_INT)); |
| 334 | printk("tvp5150: Pixel alignment register low byte = 0x%02x\n", |
| 335 | tvp5150_read(c, TVP5150_PIX_ALIGN_REG_LOW)); |
| 336 | printk("tvp5150: Pixel alignment register high byte = 0x%02x\n", |
| 337 | tvp5150_read(c, TVP5150_PIX_ALIGN_REG_HIGH)); |
| 338 | printk("tvp5150: FIFO output control = 0x%02x\n", |
| 339 | tvp5150_read(c, TVP5150_FIFO_OUT_CTRL)); |
| 340 | printk("tvp5150: Full field enable 1 = 0x%02x\n", |
| 341 | tvp5150_read(c, TVP5150_FULL_FIELD_ENA_1)); |
| 342 | printk("tvp5150: Full field enable 2 = 0x%02x\n", |
| 343 | tvp5150_read(c, TVP5150_FULL_FIELD_ENA_2)); |
| 344 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 345 | tvp5150_read(c, TVP5150_LINE_MODE_REG_1)); |
| 346 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 347 | tvp5150_read(c, TVP5150_LINE_MODE_REG_2)); |
| 348 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 349 | tvp5150_read(c, TVP5150_LINE_MODE_REG_3)); |
| 350 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 351 | tvp5150_read(c, TVP5150_LINE_MODE_REG_4)); |
| 352 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 353 | tvp5150_read(c, TVP5150_LINE_MODE_REG_5)); |
| 354 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 355 | tvp5150_read(c, TVP5150_LINE_MODE_REG_6)); |
| 356 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 357 | tvp5150_read(c, TVP5150_LINE_MODE_REG_7)); |
| 358 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 359 | tvp5150_read(c, TVP5150_LINE_MODE_REG_8)); |
| 360 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 361 | tvp5150_read(c, TVP5150_LINE_MODE_REG_9)); |
| 362 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 363 | tvp5150_read(c, TVP5150_LINE_MODE_REG_10)); |
| 364 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 365 | tvp5150_read(c, TVP5150_LINE_MODE_REG_11)); |
| 366 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 367 | tvp5150_read(c, TVP5150_LINE_MODE_REG_12)); |
| 368 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 369 | tvp5150_read(c, TVP5150_LINE_MODE_REG_13)); |
| 370 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 371 | tvp5150_read(c, TVP5150_LINE_MODE_REG_14)); |
| 372 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 373 | tvp5150_read(c, TVP5150_LINE_MODE_REG_15)); |
| 374 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 375 | tvp5150_read(c, TVP5150_LINE_MODE_REG_16)); |
| 376 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 377 | tvp5150_read(c, TVP5150_LINE_MODE_REG_17)); |
| 378 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 379 | tvp5150_read(c, TVP5150_LINE_MODE_REG_18)); |
| 380 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 381 | tvp5150_read(c, TVP5150_LINE_MODE_REG_19)); |
| 382 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 383 | tvp5150_read(c, TVP5150_LINE_MODE_REG_20)); |
| 384 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 385 | tvp5150_read(c, TVP5150_LINE_MODE_REG_21)); |
| 386 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 387 | tvp5150_read(c, TVP5150_LINE_MODE_REG_22)); |
| 388 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 389 | tvp5150_read(c, TVP5150_LINE_MODE_REG_23)); |
| 390 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 391 | tvp5150_read(c, TVP5150_LINE_MODE_REG_24)); |
| 392 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 393 | tvp5150_read(c, TVP5150_LINE_MODE_REG_25)); |
| 394 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 395 | tvp5150_read(c, TVP5150_LINE_MODE_REG_27)); |
| 396 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 397 | tvp5150_read(c, TVP5150_LINE_MODE_REG_28)); |
| 398 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 399 | tvp5150_read(c, TVP5150_LINE_MODE_REG_29)); |
| 400 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 401 | tvp5150_read(c, TVP5150_LINE_MODE_REG_30)); |
| 402 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 403 | tvp5150_read(c, TVP5150_LINE_MODE_REG_31)); |
| 404 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 405 | tvp5150_read(c, TVP5150_LINE_MODE_REG_32)); |
| 406 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 407 | tvp5150_read(c, TVP5150_LINE_MODE_REG_33)); |
| 408 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 409 | tvp5150_read(c, TVP5150_LINE_MODE_REG_34)); |
| 410 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 411 | tvp5150_read(c, TVP5150_LINE_MODE_REG_35)); |
| 412 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 413 | tvp5150_read(c, TVP5150_LINE_MODE_REG_36)); |
| 414 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 415 | tvp5150_read(c, TVP5150_LINE_MODE_REG_37)); |
| 416 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 417 | tvp5150_read(c, TVP5150_LINE_MODE_REG_38)); |
| 418 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 419 | tvp5150_read(c, TVP5150_LINE_MODE_REG_39)); |
| 420 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 421 | tvp5150_read(c, TVP5150_LINE_MODE_REG_40)); |
| 422 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 423 | tvp5150_read(c, TVP5150_LINE_MODE_REG_41)); |
| 424 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 425 | tvp5150_read(c, TVP5150_LINE_MODE_REG_42)); |
| 426 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 427 | tvp5150_read(c, TVP5150_LINE_MODE_REG_43)); |
| 428 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 429 | tvp5150_read(c, TVP5150_LINE_MODE_REG_44)); |
| 430 | printk("tvp5150: Full field mode register = 0x%02x\n", |
| 431 | tvp5150_read(c, TVP5150_FULL_FIELD_MODE_REG)); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 432 | } |
| 433 | |
| 434 | /**************************************************************************** |
| 435 | Basic functions |
| 436 | ****************************************************************************/ |
| 437 | enum tvp5150_input { |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 438 | TVP5150_ANALOG_CH0 = 0, |
| 439 | TVP5150_SVIDEO = 1, |
| 440 | TVP5150_ANALOG_CH1 = 2, |
| 441 | TVP5150_BLACK_SCREEN = 8 |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 442 | }; |
| 443 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 444 | static inline void tvp5150_selmux(struct i2c_client *c, |
| 445 | enum tvp5150_input input) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 446 | { |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 447 | int opmode=0; |
| 448 | |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 449 | struct tvp5150 *decoder = i2c_get_clientdata(c); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 450 | |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 451 | if (!decoder->enable) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 452 | input |= TVP5150_BLACK_SCREEN; |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 453 | |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 454 | switch (input) { |
| 455 | case TVP5150_ANALOG_CH0: |
| 456 | case TVP5150_ANALOG_CH1: |
| 457 | opmode=0x30; /* TV Mode */ |
| 458 | break; |
| 459 | default: |
| 460 | opmode=0; /* Auto Mode */ |
| 461 | break; |
| 462 | } |
| 463 | |
| 464 | tvp5150_write(c, TVP5150_OP_MODE_CTL, opmode); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 465 | tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 466 | }; |
| 467 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 468 | struct i2c_reg_value { |
| 469 | unsigned char reg; |
| 470 | unsigned char value; |
| 471 | }; |
| 472 | |
| 473 | /* Default values as sugested at TVP5150AM1 datasheet */ |
| 474 | static const struct i2c_reg_value tvp5150_init_default[] = { |
| 475 | { /* 0x00 */ |
| 476 | TVP5150_VD_IN_SRC_SEL_1,0x00 |
| 477 | }, |
| 478 | { /* 0x01 */ |
| 479 | TVP5150_ANAL_CHL_CTL,0x15 |
| 480 | }, |
| 481 | { /* 0x02 */ |
| 482 | TVP5150_OP_MODE_CTL,0x00 |
| 483 | }, |
| 484 | { /* 0x03 */ |
| 485 | TVP5150_MISC_CTL,0x01 |
| 486 | }, |
| 487 | { /* 0x06 */ |
| 488 | TVP5150_COLOR_KIL_THSH_CTL,0x10 |
| 489 | }, |
| 490 | { /* 0x07 */ |
| 491 | TVP5150_LUMA_PROC_CTL_1,0x60 |
| 492 | }, |
| 493 | { /* 0x08 */ |
| 494 | TVP5150_LUMA_PROC_CTL_2,0x00 |
| 495 | }, |
| 496 | { /* 0x09 */ |
| 497 | TVP5150_BRIGHT_CTL,0x80 |
| 498 | }, |
| 499 | { /* 0x0a */ |
| 500 | TVP5150_SATURATION_CTL,0x80 |
| 501 | }, |
| 502 | { /* 0x0b */ |
| 503 | TVP5150_HUE_CTL,0x00 |
| 504 | }, |
| 505 | { /* 0x0c */ |
| 506 | TVP5150_CONTRAST_CTL,0x80 |
| 507 | }, |
| 508 | { /* 0x0d */ |
| 509 | TVP5150_DATA_RATE_SEL,0x47 |
| 510 | }, |
| 511 | { /* 0x0e */ |
| 512 | TVP5150_LUMA_PROC_CTL_3,0x00 |
| 513 | }, |
| 514 | { /* 0x0f */ |
| 515 | TVP5150_CONF_SHARED_PIN,0x08 |
| 516 | }, |
| 517 | { /* 0x11 */ |
| 518 | TVP5150_ACT_VD_CROP_ST_MSB,0x00 |
| 519 | }, |
| 520 | { /* 0x12 */ |
| 521 | TVP5150_ACT_VD_CROP_ST_LSB,0x00 |
| 522 | }, |
| 523 | { /* 0x13 */ |
| 524 | TVP5150_ACT_VD_CROP_STP_MSB,0x00 |
| 525 | }, |
| 526 | { /* 0x14 */ |
| 527 | TVP5150_ACT_VD_CROP_STP_LSB,0x00 |
| 528 | }, |
| 529 | { /* 0x15 */ |
| 530 | TVP5150_GENLOCK,0x01 |
| 531 | }, |
| 532 | { /* 0x16 */ |
| 533 | TVP5150_HORIZ_SYNC_START,0x80 |
| 534 | }, |
| 535 | { /* 0x18 */ |
| 536 | TVP5150_VERT_BLANKING_START,0x00 |
| 537 | }, |
| 538 | { /* 0x19 */ |
| 539 | TVP5150_VERT_BLANKING_STOP,0x00 |
| 540 | }, |
| 541 | { /* 0x1a */ |
| 542 | TVP5150_CHROMA_PROC_CTL_1,0x0c |
| 543 | }, |
| 544 | { /* 0x1b */ |
| 545 | TVP5150_CHROMA_PROC_CTL_2,0x14 |
| 546 | }, |
| 547 | { /* 0x1c */ |
| 548 | TVP5150_INT_RESET_REG_B,0x00 |
| 549 | }, |
| 550 | { /* 0x1d */ |
| 551 | TVP5150_INT_ENABLE_REG_B,0x00 |
| 552 | }, |
| 553 | { /* 0x1e */ |
| 554 | TVP5150_INTT_CONFIG_REG_B,0x00 |
| 555 | }, |
| 556 | { /* 0x28 */ |
| 557 | TVP5150_VIDEO_STD,0x00 |
| 558 | }, |
| 559 | { /* 0x2e */ |
| 560 | TVP5150_MACROVISION_ON_CTR,0x0f |
| 561 | }, |
| 562 | { /* 0x2f */ |
| 563 | TVP5150_MACROVISION_OFF_CTR,0x01 |
| 564 | }, |
| 565 | { /* 0xbb */ |
| 566 | TVP5150_TELETEXT_FIL_ENA,0x00 |
| 567 | }, |
| 568 | { /* 0xc0 */ |
| 569 | TVP5150_INT_STATUS_REG_A,0x00 |
| 570 | }, |
| 571 | { /* 0xc1 */ |
| 572 | TVP5150_INT_ENABLE_REG_A,0x00 |
| 573 | }, |
| 574 | { /* 0xc2 */ |
| 575 | TVP5150_INT_CONF,0x04 |
| 576 | }, |
| 577 | { /* 0xc8 */ |
| 578 | TVP5150_FIFO_INT_THRESHOLD,0x80 |
| 579 | }, |
| 580 | { /* 0xc9 */ |
| 581 | TVP5150_FIFO_RESET,0x00 |
| 582 | }, |
| 583 | { /* 0xca */ |
| 584 | TVP5150_LINE_NUMBER_INT,0x00 |
| 585 | }, |
| 586 | { /* 0xcb */ |
| 587 | TVP5150_PIX_ALIGN_REG_LOW,0x4e |
| 588 | }, |
| 589 | { /* 0xcc */ |
| 590 | TVP5150_PIX_ALIGN_REG_HIGH,0x00 |
| 591 | }, |
| 592 | { /* 0xcd */ |
| 593 | TVP5150_FIFO_OUT_CTRL,0x01 |
| 594 | }, |
| 595 | { /* 0xcf */ |
| 596 | TVP5150_FULL_FIELD_ENA_1,0x00 |
| 597 | }, |
| 598 | { /* 0xd0 */ |
| 599 | TVP5150_FULL_FIELD_ENA_2,0x00 |
| 600 | }, |
| 601 | { /* 0xfc */ |
| 602 | TVP5150_FULL_FIELD_MODE_REG,0x7f |
| 603 | }, |
| 604 | { /* end of data */ |
| 605 | 0xff,0xff |
| 606 | } |
| 607 | }; |
| 608 | |
| 609 | /* Default values as sugested at TVP5150AM1 datasheet */ |
| 610 | static const struct i2c_reg_value tvp5150_init_enable[] = { |
| 611 | { |
| 612 | TVP5150_CONF_SHARED_PIN, 2 |
| 613 | },{ /* Automatic offset and AGC enabled */ |
| 614 | TVP5150_ANAL_CHL_CTL, 0x15 |
| 615 | },{ /* Activate YCrCb output 0x9 or 0xd ? */ |
| 616 | TVP5150_MISC_CTL, 0x6f |
| 617 | },{ /* Activates video std autodetection for all standards */ |
| 618 | TVP5150_AUTOSW_MSK, 0x0 |
| 619 | },{ /* Default format: 0x47. For 4:2:2: 0x40 */ |
| 620 | TVP5150_DATA_RATE_SEL, 0x47 |
| 621 | },{ |
| 622 | TVP5150_CHROMA_PROC_CTL_1, 0x0c |
| 623 | },{ |
| 624 | TVP5150_CHROMA_PROC_CTL_2, 0x54 |
| 625 | },{ /* Non documented, but initialized on WinTV USB2 */ |
| 626 | 0x27, 0x20 |
| 627 | },{ |
| 628 | 0xff,0xff |
| 629 | } |
| 630 | }; |
| 631 | |
| 632 | struct i2c_vbi_ram_value { |
| 633 | u16 reg; |
| 634 | unsigned char values[26]; |
| 635 | }; |
| 636 | |
| 637 | struct i2c_vbi_ram_value vbi_ram_default[] = |
| 638 | { |
| 639 | {0x010, /* WST SECAM 6 */ |
| 640 | { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x26, 0xe6, 0xb4, 0x0e, 0x0, 0x0, 0x0, 0x10, 0x0 } |
| 641 | }, |
| 642 | {0x030, /* WST PAL B 6 */ |
| 643 | { 0xaa, 0xaa, 0xff, 0xff , 0x27, 0x2e, 0x20, 0x2b, 0xa6, 0x72, 0x10, 0x0, 0x0, 0x0, 0x10, 0x0 } |
| 644 | }, |
| 645 | {0x050, /* WST PAL C 6 */ |
| 646 | { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x22, 0xa6, 0x98, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 } |
| 647 | }, |
| 648 | {0x070, /* WST NTSC 6 */ |
| 649 | { 0xaa, 0xaa, 0xff, 0xff , 0x27, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 } |
| 650 | }, |
| 651 | {0x090, /* NABTS, NTSC 6 */ |
| 652 | { 0xaa, 0xaa, 0xff, 0xff , 0xe7, 0x2e, 0x20, 0x22, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x15, 0x0 } |
| 653 | }, |
| 654 | {0x0b0, /* NABTS, NTSC-J 6 */ |
| 655 | { 0xaa, 0xaa, 0xff, 0xff , 0xa7, 0x2e, 0x20, 0x23, 0x69, 0x93, 0x0d, 0x0, 0x0, 0x0, 0x10, 0x0 } |
| 656 | }, |
| 657 | {0x0d0, /* CC, PAL/SECAM 6 */ |
| 658 | { 0xaa, 0x2a, 0xff, 0x3f , 0x04, 0x51, 0x6e, 0x02, 0xa6, 0x7b, 0x09, 0x0, 0x0, 0x0, 0x27, 0x0 } |
| 659 | }, |
| 660 | {0x0f0, /* CC, NTSC 6 */ |
| 661 | { 0xaa, 0x2a, 0xff, 0x3f , 0x04, 0x51, 0x6e, 0x02, 0x69, 0x8c, 0x09, 0x0, 0x0, 0x0, 0x27, 0x0 } |
| 662 | }, |
| 663 | {0x110, /* WSS, PAL/SECAM 6 */ |
| 664 | { 0x5b, 0x55, 0xc5, 0xff , 0x0, 0x71, 0x6e, 0x42, 0xa6, 0xcd, 0x0f, 0x0, 0x0, 0x0, 0x3a, 0x0 } |
| 665 | }, |
| 666 | {0x130, /* WSS, NTSC C */ |
| 667 | { 0x38, 0x00, 0x3f, 0x00 , 0x0, 0x71, 0x6e, 0x43, 0x69, 0x7c, 0x08, 0x0, 0x0, 0x0, 0x39, 0x0 } |
| 668 | }, |
| 669 | {0x150, /* VITC, PAL/SECAM 6 */ |
| 670 | { 0x0, 0x0, 0x0, 0x0 , 0x0, 0x8f, 0x6d, 0x49, 0xa6, 0x85, 0x08, 0x0, 0x0, 0x0, 0x4c, 0x0 } |
| 671 | }, |
| 672 | {0x170, /* VITC, NTSC 6 */ |
| 673 | { 0x0, 0x0, 0x0, 0x0 , 0x0, 0x8f, 0x6d, 0x49, 0x69, 0x94, 0x08, 0x0, 0x0, 0x0, 0x4c, 0x0 } |
| 674 | }, |
| 675 | { (u16)-1 } |
| 676 | }; |
| 677 | |
| 678 | static int tvp5150_write_inittab(struct i2c_client *c, |
| 679 | const struct i2c_reg_value *regs) |
| 680 | { |
| 681 | while (regs->reg != 0xff) { |
| 682 | tvp5150_write(c, regs->reg, regs->value); |
| 683 | regs++; |
| 684 | } |
| 685 | return 0; |
| 686 | } |
| 687 | |
| 688 | static int tvp5150_vdp_init(struct i2c_client *c, |
| 689 | const struct i2c_vbi_ram_value *regs) |
| 690 | { |
| 691 | unsigned int i; |
| 692 | |
| 693 | /* Disable Full Field */ |
| 694 | tvp5150_write(c, TVP5150_FULL_FIELD_ENA_1, 0); |
| 695 | |
| 696 | /* Before programming, Line mode should be at 0xff */ |
| 697 | for (i=TVP5150_FULL_FIELD_ENA_2; i<=TVP5150_LINE_MODE_REG_44; i++) |
| 698 | tvp5150_write(c, i, 0xff); |
| 699 | |
| 700 | /* Load Ram Table */ |
| 701 | while (regs->reg != (u16)-1 ) { |
| 702 | tvp5150_write(c, TVP5150_CONF_RAM_ADDR_HIGH,regs->reg>>8); |
| 703 | tvp5150_write(c, TVP5150_CONF_RAM_ADDR_LOW,regs->reg); |
| 704 | |
| 705 | for (i=0;i<16;i++) |
| 706 | tvp5150_write(c, TVP5150_VDP_CONF_RAM_DATA,regs->values[i]); |
| 707 | |
| 708 | regs++; |
| 709 | } |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | static int tvp5150_set_std(struct i2c_client *c, v4l2_std_id std) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 714 | { |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 715 | struct tvp5150 *decoder = i2c_get_clientdata(c); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 716 | int fmt=0; |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 717 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 718 | decoder->norm=std; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 719 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 720 | /* First tests should be against specific std */ |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 721 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 722 | if (std == V4L2_STD_ALL) { |
| 723 | fmt=0; /* Autodetect mode */ |
| 724 | } else if (std & V4L2_STD_NTSC_443) { |
| 725 | fmt=0xa; |
| 726 | } else if (std & V4L2_STD_PAL_M) { |
| 727 | fmt=0x6; |
| 728 | } else if (std & (V4L2_STD_PAL_N| V4L2_STD_PAL_Nc)) { |
| 729 | fmt=0x8; |
| 730 | } else { |
| 731 | /* Then, test against generic ones */ |
| 732 | if (std & V4L2_STD_NTSC) { |
| 733 | fmt=0x2; |
| 734 | } else if (std & V4L2_STD_PAL) { |
| 735 | fmt=0x4; |
| 736 | } else if (std & V4L2_STD_SECAM) { |
| 737 | fmt=0xc; |
| 738 | } |
| 739 | } |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 740 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 741 | tvp5150_dbg(1,"Set video std register to %d.\n",fmt); |
| 742 | tvp5150_write(c, TVP5150_VIDEO_STD, fmt); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 743 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 744 | return 0; |
| 745 | } |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 746 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 747 | static inline void tvp5150_reset(struct i2c_client *c) |
| 748 | { |
| 749 | u8 type, ver_656, msb_id, lsb_id, msb_rom, lsb_rom; |
| 750 | struct tvp5150 *decoder = i2c_get_clientdata(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 751 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 752 | type=tvp5150_read(c,TVP5150_AUTOSW_MSK); |
| 753 | msb_id=tvp5150_read(c,TVP5150_MSB_DEV_ID); |
| 754 | lsb_id=tvp5150_read(c,TVP5150_LSB_DEV_ID); |
| 755 | msb_rom=tvp5150_read(c,TVP5150_ROM_MAJOR_VER); |
| 756 | lsb_rom=tvp5150_read(c,TVP5150_ROM_MINOR_VER); |
| 757 | |
| 758 | if (type==0xdc) { |
| 759 | ver_656=tvp5150_read(c,TVP5150_REV_SELECT); |
| 760 | tvp5150_info("tvp%02x%02xam1 detected 656 version is %d.\n",msb_id, lsb_id,ver_656); |
| 761 | } else if (type==0xfc) { |
| 762 | tvp5150_info("tvp%02x%02xa detected.\n",msb_id, lsb_id); |
| 763 | } else { |
| 764 | tvp5150_info("unknown tvp%02x%02x chip detected(%d).\n",msb_id,lsb_id,type); |
| 765 | } |
| 766 | tvp5150_info("Rom ver is %d.%d\n",msb_rom,lsb_rom); |
| 767 | |
| 768 | /* Initializes TVP5150 to its default values */ |
| 769 | tvp5150_write_inittab(c, tvp5150_init_default); |
| 770 | |
| 771 | /* Initializes VDP registers */ |
| 772 | tvp5150_vdp_init(c, vbi_ram_default); |
| 773 | |
| 774 | /* Selects decoder input */ |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 775 | tvp5150_selmux(c, decoder->input); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 776 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 777 | /* Initializes TVP5150 to stream enabled values */ |
| 778 | tvp5150_write_inittab(c, tvp5150_init_enable); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 779 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 780 | /* Initialize image preferences */ |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 781 | tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright >> 8); |
| 782 | tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast >> 8); |
| 783 | tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast >> 8); |
| 784 | tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 785 | |
| 786 | tvp5150_set_std(c, decoder->norm); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 787 | }; |
| 788 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 789 | static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl) |
| 790 | { |
| 791 | /* struct tvp5150 *decoder = i2c_get_clientdata(c); */ |
| 792 | |
| 793 | switch (ctrl->id) { |
| 794 | case V4L2_CID_BRIGHTNESS: |
| 795 | ctrl->value = tvp5150_read(c, TVP5150_BRIGHT_CTL); |
| 796 | return 0; |
| 797 | case V4L2_CID_CONTRAST: |
| 798 | ctrl->value = tvp5150_read(c, TVP5150_CONTRAST_CTL); |
| 799 | return 0; |
| 800 | case V4L2_CID_SATURATION: |
| 801 | ctrl->value = tvp5150_read(c, TVP5150_SATURATION_CTL); |
| 802 | return 0; |
| 803 | case V4L2_CID_HUE: |
| 804 | ctrl->value = tvp5150_read(c, TVP5150_HUE_CTL); |
| 805 | return 0; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 806 | } |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 807 | return -EINVAL; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | static int tvp5150_set_ctrl(struct i2c_client *c, struct v4l2_control *ctrl) |
| 811 | { |
| 812 | /* struct tvp5150 *decoder = i2c_get_clientdata(c); */ |
| 813 | |
| 814 | switch (ctrl->id) { |
| 815 | case V4L2_CID_BRIGHTNESS: |
| 816 | tvp5150_write(c, TVP5150_BRIGHT_CTL, ctrl->value); |
| 817 | return 0; |
| 818 | case V4L2_CID_CONTRAST: |
| 819 | tvp5150_write(c, TVP5150_CONTRAST_CTL, ctrl->value); |
| 820 | return 0; |
| 821 | case V4L2_CID_SATURATION: |
| 822 | tvp5150_write(c, TVP5150_SATURATION_CTL, ctrl->value); |
| 823 | return 0; |
| 824 | case V4L2_CID_HUE: |
| 825 | tvp5150_write(c, TVP5150_HUE_CTL, ctrl->value); |
| 826 | return 0; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 827 | } |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 828 | return -EINVAL; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 829 | } |
| 830 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 831 | /**************************************************************************** |
| 832 | I2C Command |
| 833 | ****************************************************************************/ |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 834 | static int tvp5150_command(struct i2c_client *c, |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 835 | unsigned int cmd, void *arg) |
| 836 | { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 837 | struct tvp5150 *decoder = i2c_get_clientdata(c); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 838 | |
| 839 | switch (cmd) { |
| 840 | |
| 841 | case 0: |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 842 | case VIDIOC_INT_RESET: |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 843 | case DECODER_INIT: |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 844 | tvp5150_reset(c); |
| 845 | break; |
| 846 | case VIDIOC_S_STD: |
| 847 | if (decoder->norm == *(v4l2_std_id *)arg) |
| 848 | break; |
| 849 | return tvp5150_set_std(c, *(v4l2_std_id *)arg); |
| 850 | case VIDIOC_G_STD: |
| 851 | *(v4l2_std_id *)arg = decoder->norm; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 852 | break; |
| 853 | |
Mauro Carvalho Chehab | 21dcd8c | 2006-01-09 15:25:37 -0200 | [diff] [blame] | 854 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 855 | case VIDIOC_INT_G_REGISTER: |
| 856 | { |
| 857 | struct v4l2_register *reg = arg; |
| 858 | |
| 859 | if (reg->i2c_id != I2C_DRIVERID_TVP5150) |
| 860 | return -EINVAL; |
| 861 | reg->val = tvp5150_read(c, reg->reg & 0xff); |
| 862 | break; |
| 863 | } |
| 864 | |
| 865 | case VIDIOC_INT_S_REGISTER: |
| 866 | { |
| 867 | struct v4l2_register *reg = arg; |
| 868 | |
| 869 | if (reg->i2c_id != I2C_DRIVERID_TVP5150) |
| 870 | return -EINVAL; |
| 871 | if (!capable(CAP_SYS_ADMIN)) |
| 872 | return -EPERM; |
| 873 | tvp5150_write(c, reg->reg & 0xff, reg->val & 0xff); |
| 874 | break; |
| 875 | } |
| 876 | #endif |
| 877 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 878 | case DECODER_DUMP: |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 879 | dump_reg(c); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 880 | break; |
| 881 | |
| 882 | case DECODER_GET_CAPABILITIES: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 883 | { |
| 884 | struct video_decoder_capability *cap = arg; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 885 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 886 | cap->flags = VIDEO_DECODER_PAL | |
| 887 | VIDEO_DECODER_NTSC | |
| 888 | VIDEO_DECODER_SECAM | |
| 889 | VIDEO_DECODER_AUTO | VIDEO_DECODER_CCIR; |
| 890 | cap->inputs = 3; |
| 891 | cap->outputs = 1; |
| 892 | break; |
| 893 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 894 | case DECODER_GET_STATUS: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 895 | { |
| 896 | break; |
| 897 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 898 | |
| 899 | case DECODER_SET_GPIO: |
| 900 | break; |
| 901 | |
| 902 | case DECODER_SET_VBI_BYPASS: |
| 903 | break; |
| 904 | |
| 905 | case DECODER_SET_NORM: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 906 | { |
| 907 | int *iarg = arg; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 908 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 909 | switch (*iarg) { |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 910 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 911 | case VIDEO_MODE_NTSC: |
| 912 | break; |
| 913 | |
| 914 | case VIDEO_MODE_PAL: |
| 915 | break; |
| 916 | |
| 917 | case VIDEO_MODE_SECAM: |
| 918 | break; |
| 919 | |
| 920 | case VIDEO_MODE_AUTO: |
| 921 | break; |
| 922 | |
| 923 | default: |
| 924 | return -EINVAL; |
| 925 | |
| 926 | } |
| 927 | decoder->norm = *iarg; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 928 | break; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 929 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 930 | case DECODER_SET_INPUT: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 931 | { |
| 932 | int *iarg = arg; |
| 933 | if (*iarg < 0 || *iarg > 3) { |
| 934 | return -EINVAL; |
| 935 | } |
| 936 | |
| 937 | decoder->input = *iarg; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 938 | tvp5150_selmux(c, decoder->input); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 939 | |
| 940 | break; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 941 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 942 | case DECODER_SET_OUTPUT: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 943 | { |
| 944 | int *iarg = arg; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 945 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 946 | /* not much choice of outputs */ |
| 947 | if (*iarg != 0) { |
| 948 | return -EINVAL; |
| 949 | } |
| 950 | break; |
| 951 | } |
| 952 | case DECODER_ENABLE_OUTPUT: |
| 953 | { |
| 954 | int *iarg = arg; |
| 955 | |
| 956 | decoder->enable = (*iarg != 0); |
| 957 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 958 | tvp5150_selmux(c, decoder->input); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 959 | |
| 960 | break; |
| 961 | } |
| 962 | case VIDIOC_QUERYCTRL: |
| 963 | { |
| 964 | struct v4l2_queryctrl *qc = arg; |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 965 | int i; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 966 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 967 | tvp5150_dbg(1, "VIDIOC_QUERYCTRL called\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 968 | |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 969 | for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 970 | if (qc->id && qc->id == tvp5150_qctrl[i].id) { |
| 971 | memcpy(qc, &(tvp5150_qctrl[i]), |
| 972 | sizeof(*qc)); |
| 973 | return 0; |
| 974 | } |
| 975 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 976 | return -EINVAL; |
| 977 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 978 | case VIDIOC_G_CTRL: |
| 979 | { |
| 980 | struct v4l2_control *ctrl = arg; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 981 | tvp5150_dbg(1, "VIDIOC_G_CTRL called\n"); |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 982 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 983 | return tvp5150_get_ctrl(c, ctrl); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 984 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 985 | case VIDIOC_S_CTRL: |
| 986 | { |
| 987 | struct v4l2_control *ctrl = arg; |
| 988 | u8 i, n; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 989 | n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]); |
| 990 | for (i = 0; i < n; i++) |
| 991 | if (ctrl->id == tvp5150_qctrl[i].id) { |
| 992 | if (ctrl->value < |
| 993 | tvp5150_qctrl[i].minimum |
| 994 | || ctrl->value > |
| 995 | tvp5150_qctrl[i].maximum) |
| 996 | return -ERANGE; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 997 | tvp5150_dbg(1, |
| 998 | "VIDIOC_S_CTRL: id=%d, value=%d\n", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 999 | ctrl->id, ctrl->value); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1000 | return tvp5150_set_ctrl(c, ctrl); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1001 | } |
| 1002 | return -EINVAL; |
| 1003 | } |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 1004 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 1005 | case DECODER_SET_PICTURE: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1006 | { |
| 1007 | struct video_picture *pic = arg; |
| 1008 | if (decoder->bright != pic->brightness) { |
| 1009 | /* We want 0 to 255 we get 0-65535 */ |
| 1010 | decoder->bright = pic->brightness; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1011 | tvp5150_write(c, TVP5150_BRIGHT_CTL, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1012 | decoder->bright >> 8); |
| 1013 | } |
| 1014 | if (decoder->contrast != pic->contrast) { |
| 1015 | /* We want 0 to 255 we get 0-65535 */ |
| 1016 | decoder->contrast = pic->contrast; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1017 | tvp5150_write(c, TVP5150_CONTRAST_CTL, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1018 | decoder->contrast >> 8); |
| 1019 | } |
| 1020 | if (decoder->sat != pic->colour) { |
| 1021 | /* We want 0 to 255 we get 0-65535 */ |
| 1022 | decoder->sat = pic->colour; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1023 | tvp5150_write(c, TVP5150_SATURATION_CTL, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1024 | decoder->contrast >> 8); |
| 1025 | } |
| 1026 | if (decoder->hue != pic->hue) { |
| 1027 | /* We want -128 to 127 we get 0-65535 */ |
| 1028 | decoder->hue = pic->hue; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1029 | tvp5150_write(c, TVP5150_HUE_CTL, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1030 | (decoder->hue - 32768) >> 8); |
| 1031 | } |
| 1032 | break; |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 1033 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 1034 | default: |
| 1035 | return -EINVAL; |
| 1036 | } |
| 1037 | |
| 1038 | return 0; |
| 1039 | } |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1040 | |
| 1041 | /**************************************************************************** |
| 1042 | I2C Client & Driver |
| 1043 | ****************************************************************************/ |
| 1044 | static struct i2c_driver driver; |
| 1045 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1046 | static struct i2c_client client_template = { |
| 1047 | .name = "(unset)", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1048 | .driver = &driver, |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1049 | }; |
| 1050 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1051 | static int tvp5150_detect_client(struct i2c_adapter *adapter, |
| 1052 | int address, int kind) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1053 | { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1054 | struct i2c_client *c; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1055 | struct tvp5150 *core; |
| 1056 | int rv; |
| 1057 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1058 | if (debug) |
| 1059 | printk( KERN_INFO |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1060 | "tvp5150.c: detecting tvp5150 client on address 0x%x\n", |
| 1061 | address << 1); |
| 1062 | |
| 1063 | client_template.adapter = adapter; |
| 1064 | client_template.addr = address; |
| 1065 | |
| 1066 | /* Check if the adapter supports the needed features */ |
| 1067 | if (!i2c_check_functionality |
| 1068 | (adapter, |
| 1069 | I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) |
| 1070 | return 0; |
| 1071 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1072 | c = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); |
| 1073 | if (c == 0) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1074 | return -ENOMEM; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1075 | memcpy(c, &client_template, sizeof(struct i2c_client)); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1076 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 1077 | core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1078 | if (core == 0) { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1079 | kfree(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1080 | return -ENOMEM; |
| 1081 | } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1082 | i2c_set_clientdata(c, core); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1083 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1084 | rv = i2c_attach_client(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1085 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1086 | core->norm = V4L2_STD_ALL; |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 1087 | core->input = 2; |
| 1088 | core->enable = 1; |
| 1089 | core->bright = 32768; |
| 1090 | core->contrast = 32768; |
| 1091 | core->hue = 32768; |
| 1092 | core->sat = 32768; |
| 1093 | |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1094 | if (rv) { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1095 | kfree(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1096 | kfree(core); |
| 1097 | return rv; |
| 1098 | } |
| 1099 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1100 | if (debug > 1) |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1101 | dump_reg(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1102 | return 0; |
| 1103 | } |
| 1104 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1105 | static int tvp5150_attach_adapter(struct i2c_adapter *adapter) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1106 | { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1107 | if (debug) |
| 1108 | printk( KERN_INFO |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1109 | "tvp5150.c: starting probe for adapter %s (0x%x)\n", |
| 1110 | adapter->name, adapter->id); |
| 1111 | return i2c_probe(adapter, &addr_data, &tvp5150_detect_client); |
| 1112 | } |
| 1113 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1114 | static int tvp5150_detach_client(struct i2c_client *c) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1115 | { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1116 | struct tvp5150 *decoder = i2c_get_clientdata(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1117 | int err; |
| 1118 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1119 | tvp5150_dbg(1, |
| 1120 | "tvp5150.c: removing tvp5150 adapter on address 0x%x\n", |
| 1121 | c->addr << 1); |
| 1122 | |
| 1123 | err = i2c_detach_client(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1124 | if (err) { |
| 1125 | return err; |
| 1126 | } |
| 1127 | |
| 1128 | kfree(decoder); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1129 | kfree(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1130 | |
| 1131 | return 0; |
| 1132 | } |
| 1133 | |
| 1134 | /* ----------------------------------------------------------------------- */ |
| 1135 | |
| 1136 | static struct i2c_driver driver = { |
Laurent Riffard | 604f28e | 2005-11-26 20:43:39 +0100 | [diff] [blame] | 1137 | .driver = { |
Laurent Riffard | 604f28e | 2005-11-26 20:43:39 +0100 | [diff] [blame] | 1138 | .name = "tvp5150", |
| 1139 | }, |
Mauro Carvalho Chehab | cab462f | 2006-01-09 15:53:26 -0200 | [diff] [blame] | 1140 | .id = I2C_DRIVERID_TVP5150, |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1141 | |
| 1142 | .attach_adapter = tvp5150_attach_adapter, |
| 1143 | .detach_client = tvp5150_detach_client, |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 1144 | |
| 1145 | .command = tvp5150_command, |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1146 | }; |
| 1147 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1148 | static int __init tvp5150_init(void) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1149 | { |
| 1150 | return i2c_add_driver(&driver); |
| 1151 | } |
| 1152 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1153 | static void __exit tvp5150_exit(void) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1154 | { |
| 1155 | i2c_del_driver(&driver); |
| 1156 | } |
| 1157 | |
| 1158 | module_init(tvp5150_init); |
| 1159 | module_exit(tvp5150_exit); |