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 | |
Adrian Bunk | a9cff90 | 2006-01-15 06:56:15 -0200 | [diff] [blame] | 637 | static struct i2c_vbi_ram_value vbi_ram_default[] = |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 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 | { |
Mauro Carvalho Chehab | e36eaa7 | 2006-01-23 09:48:34 -0200 | [diff] [blame^] | 749 | u8 msb_id, lsb_id, msb_rom, lsb_rom; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 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 | msb_id=tvp5150_read(c,TVP5150_MSB_DEV_ID); |
| 753 | lsb_id=tvp5150_read(c,TVP5150_LSB_DEV_ID); |
| 754 | msb_rom=tvp5150_read(c,TVP5150_ROM_MAJOR_VER); |
| 755 | lsb_rom=tvp5150_read(c,TVP5150_ROM_MINOR_VER); |
| 756 | |
Mauro Carvalho Chehab | e36eaa7 | 2006-01-23 09:48:34 -0200 | [diff] [blame^] | 757 | if ((msb_rom==4)&&(lsb_rom==0)) { /* Is TVP5150AM1 */ |
| 758 | tvp5150_info("tvp%02x%02xam1 detected.\n",msb_id, lsb_id); |
| 759 | |
| 760 | /* ITU-T BT.656.4 timing */ |
| 761 | tvp5150_write(c,TVP5150_REV_SELECT,0); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 762 | } else { |
Mauro Carvalho Chehab | e36eaa7 | 2006-01-23 09:48:34 -0200 | [diff] [blame^] | 763 | if ((msb_rom==3)||(lsb_rom==0x21)) { /* Is TVP5150A */ |
| 764 | tvp5150_info("tvp%02x%02xa detected.\n",msb_id, lsb_id); |
| 765 | } else { |
| 766 | tvp5150_info("*** unknown tvp%02x%02x chip detected.\n",msb_id,lsb_id); |
| 767 | tvp5150_info("*** Rom ver is %d.%d\n",msb_rom,lsb_rom); |
| 768 | } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 769 | } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 770 | |
| 771 | /* Initializes TVP5150 to its default values */ |
| 772 | tvp5150_write_inittab(c, tvp5150_init_default); |
| 773 | |
| 774 | /* Initializes VDP registers */ |
| 775 | tvp5150_vdp_init(c, vbi_ram_default); |
| 776 | |
| 777 | /* Selects decoder input */ |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 778 | tvp5150_selmux(c, decoder->input); |
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 | /* Initializes TVP5150 to stream enabled values */ |
| 781 | tvp5150_write_inittab(c, tvp5150_init_enable); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 782 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 783 | /* Initialize image preferences */ |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 784 | tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright >> 8); |
| 785 | tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast >> 8); |
| 786 | tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast >> 8); |
| 787 | tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 788 | |
| 789 | tvp5150_set_std(c, decoder->norm); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 790 | }; |
| 791 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 792 | static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl) |
| 793 | { |
| 794 | /* struct tvp5150 *decoder = i2c_get_clientdata(c); */ |
| 795 | |
| 796 | switch (ctrl->id) { |
| 797 | case V4L2_CID_BRIGHTNESS: |
| 798 | ctrl->value = tvp5150_read(c, TVP5150_BRIGHT_CTL); |
| 799 | return 0; |
| 800 | case V4L2_CID_CONTRAST: |
| 801 | ctrl->value = tvp5150_read(c, TVP5150_CONTRAST_CTL); |
| 802 | return 0; |
| 803 | case V4L2_CID_SATURATION: |
| 804 | ctrl->value = tvp5150_read(c, TVP5150_SATURATION_CTL); |
| 805 | return 0; |
| 806 | case V4L2_CID_HUE: |
| 807 | ctrl->value = tvp5150_read(c, TVP5150_HUE_CTL); |
| 808 | return 0; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 809 | } |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 810 | return -EINVAL; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | static int tvp5150_set_ctrl(struct i2c_client *c, struct v4l2_control *ctrl) |
| 814 | { |
| 815 | /* struct tvp5150 *decoder = i2c_get_clientdata(c); */ |
| 816 | |
| 817 | switch (ctrl->id) { |
| 818 | case V4L2_CID_BRIGHTNESS: |
| 819 | tvp5150_write(c, TVP5150_BRIGHT_CTL, ctrl->value); |
| 820 | return 0; |
| 821 | case V4L2_CID_CONTRAST: |
| 822 | tvp5150_write(c, TVP5150_CONTRAST_CTL, ctrl->value); |
| 823 | return 0; |
| 824 | case V4L2_CID_SATURATION: |
| 825 | tvp5150_write(c, TVP5150_SATURATION_CTL, ctrl->value); |
| 826 | return 0; |
| 827 | case V4L2_CID_HUE: |
| 828 | tvp5150_write(c, TVP5150_HUE_CTL, ctrl->value); |
| 829 | return 0; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 830 | } |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 831 | return -EINVAL; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 832 | } |
| 833 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 834 | /**************************************************************************** |
| 835 | I2C Command |
| 836 | ****************************************************************************/ |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 837 | static int tvp5150_command(struct i2c_client *c, |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 838 | unsigned int cmd, void *arg) |
| 839 | { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 840 | struct tvp5150 *decoder = i2c_get_clientdata(c); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 841 | |
| 842 | switch (cmd) { |
| 843 | |
| 844 | case 0: |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 845 | case VIDIOC_INT_RESET: |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 846 | case DECODER_INIT: |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 847 | tvp5150_reset(c); |
| 848 | break; |
| 849 | case VIDIOC_S_STD: |
| 850 | if (decoder->norm == *(v4l2_std_id *)arg) |
| 851 | break; |
| 852 | return tvp5150_set_std(c, *(v4l2_std_id *)arg); |
| 853 | case VIDIOC_G_STD: |
| 854 | *(v4l2_std_id *)arg = decoder->norm; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 855 | break; |
| 856 | |
Mauro Carvalho Chehab | 21dcd8c | 2006-01-09 15:25:37 -0200 | [diff] [blame] | 857 | #ifdef CONFIG_VIDEO_ADV_DEBUG |
| 858 | case VIDIOC_INT_G_REGISTER: |
| 859 | { |
| 860 | struct v4l2_register *reg = arg; |
| 861 | |
| 862 | if (reg->i2c_id != I2C_DRIVERID_TVP5150) |
| 863 | return -EINVAL; |
| 864 | reg->val = tvp5150_read(c, reg->reg & 0xff); |
| 865 | break; |
| 866 | } |
| 867 | |
| 868 | case VIDIOC_INT_S_REGISTER: |
| 869 | { |
| 870 | struct v4l2_register *reg = arg; |
| 871 | |
| 872 | if (reg->i2c_id != I2C_DRIVERID_TVP5150) |
| 873 | return -EINVAL; |
| 874 | if (!capable(CAP_SYS_ADMIN)) |
| 875 | return -EPERM; |
| 876 | tvp5150_write(c, reg->reg & 0xff, reg->val & 0xff); |
| 877 | break; |
| 878 | } |
| 879 | #endif |
| 880 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 881 | case DECODER_DUMP: |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 882 | dump_reg(c); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 883 | break; |
| 884 | |
| 885 | case DECODER_GET_CAPABILITIES: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 886 | { |
| 887 | struct video_decoder_capability *cap = arg; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 888 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 889 | cap->flags = VIDEO_DECODER_PAL | |
| 890 | VIDEO_DECODER_NTSC | |
| 891 | VIDEO_DECODER_SECAM | |
| 892 | VIDEO_DECODER_AUTO | VIDEO_DECODER_CCIR; |
| 893 | cap->inputs = 3; |
| 894 | cap->outputs = 1; |
| 895 | break; |
| 896 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 897 | case DECODER_GET_STATUS: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 898 | { |
| 899 | break; |
| 900 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 901 | |
| 902 | case DECODER_SET_GPIO: |
| 903 | break; |
| 904 | |
| 905 | case DECODER_SET_VBI_BYPASS: |
| 906 | break; |
| 907 | |
| 908 | case DECODER_SET_NORM: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 909 | { |
| 910 | int *iarg = arg; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 911 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 912 | switch (*iarg) { |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 913 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 914 | case VIDEO_MODE_NTSC: |
| 915 | break; |
| 916 | |
| 917 | case VIDEO_MODE_PAL: |
| 918 | break; |
| 919 | |
| 920 | case VIDEO_MODE_SECAM: |
| 921 | break; |
| 922 | |
| 923 | case VIDEO_MODE_AUTO: |
| 924 | break; |
| 925 | |
| 926 | default: |
| 927 | return -EINVAL; |
| 928 | |
| 929 | } |
| 930 | decoder->norm = *iarg; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 931 | break; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 932 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 933 | case DECODER_SET_INPUT: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 934 | { |
| 935 | int *iarg = arg; |
| 936 | if (*iarg < 0 || *iarg > 3) { |
| 937 | return -EINVAL; |
| 938 | } |
| 939 | |
| 940 | decoder->input = *iarg; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 941 | tvp5150_selmux(c, decoder->input); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 942 | |
| 943 | break; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 944 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 945 | case DECODER_SET_OUTPUT: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 946 | { |
| 947 | int *iarg = arg; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 948 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 949 | /* not much choice of outputs */ |
| 950 | if (*iarg != 0) { |
| 951 | return -EINVAL; |
| 952 | } |
| 953 | break; |
| 954 | } |
| 955 | case DECODER_ENABLE_OUTPUT: |
| 956 | { |
| 957 | int *iarg = arg; |
| 958 | |
| 959 | decoder->enable = (*iarg != 0); |
| 960 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 961 | tvp5150_selmux(c, decoder->input); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 962 | |
| 963 | break; |
| 964 | } |
| 965 | case VIDIOC_QUERYCTRL: |
| 966 | { |
| 967 | struct v4l2_queryctrl *qc = arg; |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 968 | int i; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 969 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 970 | tvp5150_dbg(1, "VIDIOC_QUERYCTRL called\n"); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 971 | |
Mauro Carvalho Chehab | c0477ad | 2006-01-09 15:25:14 -0200 | [diff] [blame] | 972 | for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 973 | if (qc->id && qc->id == tvp5150_qctrl[i].id) { |
| 974 | memcpy(qc, &(tvp5150_qctrl[i]), |
| 975 | sizeof(*qc)); |
| 976 | return 0; |
| 977 | } |
| 978 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 979 | return -EINVAL; |
| 980 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 981 | case VIDIOC_G_CTRL: |
| 982 | { |
| 983 | struct v4l2_control *ctrl = arg; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 984 | tvp5150_dbg(1, "VIDIOC_G_CTRL called\n"); |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 985 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 986 | return tvp5150_get_ctrl(c, ctrl); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 987 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 988 | case VIDIOC_S_CTRL: |
| 989 | { |
| 990 | struct v4l2_control *ctrl = arg; |
| 991 | u8 i, n; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 992 | n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]); |
| 993 | for (i = 0; i < n; i++) |
| 994 | if (ctrl->id == tvp5150_qctrl[i].id) { |
| 995 | if (ctrl->value < |
| 996 | tvp5150_qctrl[i].minimum |
| 997 | || ctrl->value > |
| 998 | tvp5150_qctrl[i].maximum) |
| 999 | return -ERANGE; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1000 | tvp5150_dbg(1, |
| 1001 | "VIDIOC_S_CTRL: id=%d, value=%d\n", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1002 | ctrl->id, ctrl->value); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1003 | return tvp5150_set_ctrl(c, ctrl); |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1004 | } |
| 1005 | return -EINVAL; |
| 1006 | } |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 1007 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 1008 | case DECODER_SET_PICTURE: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1009 | { |
| 1010 | struct video_picture *pic = arg; |
| 1011 | if (decoder->bright != pic->brightness) { |
| 1012 | /* We want 0 to 255 we get 0-65535 */ |
| 1013 | decoder->bright = pic->brightness; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1014 | tvp5150_write(c, TVP5150_BRIGHT_CTL, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1015 | decoder->bright >> 8); |
| 1016 | } |
| 1017 | if (decoder->contrast != pic->contrast) { |
| 1018 | /* We want 0 to 255 we get 0-65535 */ |
| 1019 | decoder->contrast = pic->contrast; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1020 | tvp5150_write(c, TVP5150_CONTRAST_CTL, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1021 | decoder->contrast >> 8); |
| 1022 | } |
| 1023 | if (decoder->sat != pic->colour) { |
| 1024 | /* We want 0 to 255 we get 0-65535 */ |
| 1025 | decoder->sat = pic->colour; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1026 | tvp5150_write(c, TVP5150_SATURATION_CTL, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1027 | decoder->contrast >> 8); |
| 1028 | } |
| 1029 | if (decoder->hue != pic->hue) { |
| 1030 | /* We want -128 to 127 we get 0-65535 */ |
| 1031 | decoder->hue = pic->hue; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1032 | tvp5150_write(c, TVP5150_HUE_CTL, |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1033 | (decoder->hue - 32768) >> 8); |
| 1034 | } |
| 1035 | break; |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 1036 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 1037 | default: |
| 1038 | return -EINVAL; |
| 1039 | } |
| 1040 | |
| 1041 | return 0; |
| 1042 | } |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1043 | |
| 1044 | /**************************************************************************** |
| 1045 | I2C Client & Driver |
| 1046 | ****************************************************************************/ |
| 1047 | static struct i2c_driver driver; |
| 1048 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1049 | static struct i2c_client client_template = { |
| 1050 | .name = "(unset)", |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1051 | .driver = &driver, |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1052 | }; |
| 1053 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1054 | static int tvp5150_detect_client(struct i2c_adapter *adapter, |
| 1055 | int address, int kind) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1056 | { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1057 | struct i2c_client *c; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1058 | struct tvp5150 *core; |
| 1059 | int rv; |
| 1060 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1061 | if (debug) |
| 1062 | printk( KERN_INFO |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1063 | "tvp5150.c: detecting tvp5150 client on address 0x%x\n", |
| 1064 | address << 1); |
| 1065 | |
| 1066 | client_template.adapter = adapter; |
| 1067 | client_template.addr = address; |
| 1068 | |
| 1069 | /* Check if the adapter supports the needed features */ |
| 1070 | if (!i2c_check_functionality |
| 1071 | (adapter, |
| 1072 | I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) |
| 1073 | return 0; |
| 1074 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1075 | c = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); |
| 1076 | if (c == 0) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1077 | return -ENOMEM; |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1078 | memcpy(c, &client_template, sizeof(struct i2c_client)); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1079 | |
Panagiotis Issaris | 7408187 | 2006-01-11 19:40:56 -0200 | [diff] [blame] | 1080 | core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1081 | if (core == 0) { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1082 | kfree(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1083 | return -ENOMEM; |
| 1084 | } |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1085 | i2c_set_clientdata(c, core); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1086 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1087 | rv = i2c_attach_client(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1088 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1089 | core->norm = V4L2_STD_ALL; |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 1090 | core->input = 2; |
| 1091 | core->enable = 1; |
| 1092 | core->bright = 32768; |
| 1093 | core->contrast = 32768; |
| 1094 | core->hue = 32768; |
| 1095 | core->sat = 32768; |
| 1096 | |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1097 | if (rv) { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1098 | kfree(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1099 | kfree(core); |
| 1100 | return rv; |
| 1101 | } |
| 1102 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1103 | if (debug > 1) |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1104 | dump_reg(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1105 | return 0; |
| 1106 | } |
| 1107 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1108 | static int tvp5150_attach_adapter(struct i2c_adapter *adapter) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1109 | { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1110 | if (debug) |
| 1111 | printk( KERN_INFO |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1112 | "tvp5150.c: starting probe for adapter %s (0x%x)\n", |
| 1113 | adapter->name, adapter->id); |
| 1114 | return i2c_probe(adapter, &addr_data, &tvp5150_detect_client); |
| 1115 | } |
| 1116 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1117 | static int tvp5150_detach_client(struct i2c_client *c) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1118 | { |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1119 | struct tvp5150 *decoder = i2c_get_clientdata(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1120 | int err; |
| 1121 | |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1122 | tvp5150_dbg(1, |
| 1123 | "tvp5150.c: removing tvp5150 adapter on address 0x%x\n", |
| 1124 | c->addr << 1); |
| 1125 | |
| 1126 | err = i2c_detach_client(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1127 | if (err) { |
| 1128 | return err; |
| 1129 | } |
| 1130 | |
| 1131 | kfree(decoder); |
Mauro Carvalho Chehab | e1bc80a | 2006-01-09 15:25:36 -0200 | [diff] [blame] | 1132 | kfree(c); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1133 | |
| 1134 | return 0; |
| 1135 | } |
| 1136 | |
| 1137 | /* ----------------------------------------------------------------------- */ |
| 1138 | |
| 1139 | static struct i2c_driver driver = { |
Laurent Riffard | 604f28e | 2005-11-26 20:43:39 +0100 | [diff] [blame] | 1140 | .driver = { |
Laurent Riffard | 604f28e | 2005-11-26 20:43:39 +0100 | [diff] [blame] | 1141 | .name = "tvp5150", |
| 1142 | }, |
Mauro Carvalho Chehab | cab462f | 2006-01-09 15:53:26 -0200 | [diff] [blame] | 1143 | .id = I2C_DRIVERID_TVP5150, |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1144 | |
| 1145 | .attach_adapter = tvp5150_attach_adapter, |
| 1146 | .detach_client = tvp5150_detach_client, |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 1147 | |
| 1148 | .command = tvp5150_command, |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1149 | }; |
| 1150 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1151 | static int __init tvp5150_init(void) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1152 | { |
| 1153 | return i2c_add_driver(&driver); |
| 1154 | } |
| 1155 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame] | 1156 | static void __exit tvp5150_exit(void) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 1157 | { |
| 1158 | i2c_del_driver(&driver); |
| 1159 | } |
| 1160 | |
| 1161 | module_init(tvp5150_init); |
| 1162 | module_exit(tvp5150_exit); |