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 | |
| 8 | #include <linux/videodev.h> |
| 9 | #include <linux/i2c.h> |
| 10 | #include <linux/videodev.h> |
| 11 | #include <linux/delay.h> |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 12 | #include <linux/video_decoder.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 | |
| 32 | #define dprintk(num, format, args...) \ |
| 33 | do { \ |
| 34 | if (debug >= num) \ |
| 35 | printk(format , ##args); \ |
| 36 | } while (0) |
| 37 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 38 | /* supported controls */ |
| 39 | static struct v4l2_queryctrl tvp5150_qctrl[] = { |
| 40 | { |
| 41 | .id = V4L2_CID_BRIGHTNESS, |
| 42 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 43 | .name = "Brightness", |
| 44 | .minimum = 0, |
| 45 | .maximum = 255, |
| 46 | .step = 1, |
| 47 | .default_value = 0, |
| 48 | .flags = 0, |
| 49 | }, { |
| 50 | .id = V4L2_CID_CONTRAST, |
| 51 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 52 | .name = "Contrast", |
| 53 | .minimum = 0, |
| 54 | .maximum = 255, |
| 55 | .step = 0x1, |
| 56 | .default_value = 0x10, |
| 57 | .flags = 0, |
| 58 | }, { |
| 59 | .id = V4L2_CID_SATURATION, |
| 60 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 61 | .name = "Saturation", |
| 62 | .minimum = 0, |
| 63 | .maximum = 255, |
| 64 | .step = 0x1, |
| 65 | .default_value = 0x10, |
| 66 | .flags = 0, |
| 67 | }, { |
| 68 | .id = V4L2_CID_HUE, |
| 69 | .type = V4L2_CTRL_TYPE_INTEGER, |
| 70 | .name = "Hue", |
| 71 | .minimum = -128, |
| 72 | .maximum = 127, |
| 73 | .step = 0x1, |
| 74 | .default_value = 0x10, |
| 75 | .flags = 0, |
| 76 | } |
| 77 | }; |
| 78 | |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 79 | struct tvp5150 { |
| 80 | struct i2c_client *client; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 81 | |
| 82 | int norm; |
| 83 | int input; |
| 84 | int enable; |
| 85 | int bright; |
| 86 | int contrast; |
| 87 | int hue; |
| 88 | int sat; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 89 | }; |
| 90 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 91 | static inline int tvp5150_read(struct i2c_client *c, unsigned char addr) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 92 | { |
| 93 | unsigned char buffer[1]; |
| 94 | int rc; |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 95 | |
| 96 | buffer[0] = addr; |
| 97 | if (1 != (rc = i2c_master_send(c, buffer, 1))) |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 98 | dprintk(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] | 99 | |
| 100 | msleep(10); |
| 101 | |
| 102 | if (1 != (rc = i2c_master_recv(c, buffer, 1))) |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 103 | dprintk(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 | return (buffer[0]); |
| 106 | } |
| 107 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 108 | static inline void tvp5150_write(struct i2c_client *c, unsigned char addr, |
| 109 | unsigned char value) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 110 | { |
| 111 | unsigned char buffer[2]; |
| 112 | int rc; |
| 113 | /* struct tvp5150 *core = i2c_get_clientdata(c); */ |
| 114 | |
| 115 | buffer[0] = addr; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 116 | buffer[1] = value; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 117 | dprintk(1, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 118 | if (2 != (rc = i2c_master_send(c, buffer, 2))) |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 119 | dprintk(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] | 120 | } |
| 121 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 122 | static void dump_reg(struct i2c_client *c) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 123 | { |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 124 | printk("tvp5150: Video input source selection #1 = 0x%02x\n", |
| 125 | tvp5150_read(c, TVP5150_VD_IN_SRC_SEL_1)); |
| 126 | printk("tvp5150: Analog channel controls = 0x%02x\n", |
| 127 | tvp5150_read(c, TVP5150_ANAL_CHL_CTL)); |
| 128 | printk("tvp5150: Operation mode controls = 0x%02x\n", |
| 129 | tvp5150_read(c, TVP5150_OP_MODE_CTL)); |
| 130 | printk("tvp5150: Miscellaneous controls = 0x%02x\n", |
| 131 | tvp5150_read(c, TVP5150_MISC_CTL)); |
| 132 | printk("tvp5150: Autoswitch mask: TVP5150A / TVP5150AM = 0x%02x\n", |
| 133 | tvp5150_read(c, TVP5150_AUTOSW_MSK)); |
| 134 | printk("tvp5150: Color killer threshold control = 0x%02x\n", |
| 135 | tvp5150_read(c, TVP5150_COLOR_KIL_THSH_CTL)); |
| 136 | printk("tvp5150: Luminance processing control #1 = 0x%02x\n", |
| 137 | tvp5150_read(c, TVP5150_LUMA_PROC_CTL_1)); |
| 138 | printk("tvp5150: Luminance processing control #2 = 0x%02x\n", |
| 139 | tvp5150_read(c, TVP5150_LUMA_PROC_CTL_2)); |
| 140 | printk("tvp5150: Brightness control = 0x%02x\n", |
| 141 | tvp5150_read(c, TVP5150_BRIGHT_CTL)); |
| 142 | printk("tvp5150: Color saturation control = 0x%02x\n", |
| 143 | tvp5150_read(c, TVP5150_SATURATION_CTL)); |
| 144 | printk("tvp5150: Hue control = 0x%02x\n", |
| 145 | tvp5150_read(c, TVP5150_HUE_CTL)); |
| 146 | printk("tvp5150: Contrast control = 0x%02x\n", |
| 147 | tvp5150_read(c, TVP5150_CONTRAST_CTL)); |
| 148 | printk("tvp5150: Outputs and data rates select = 0x%02x\n", |
| 149 | tvp5150_read(c, TVP5150_DATA_RATE_SEL)); |
| 150 | printk("tvp5150: Luminance processing control #3 = 0x%02x\n", |
| 151 | tvp5150_read(c, TVP5150_LUMA_PROC_CTL_3)); |
| 152 | printk("tvp5150: Configuration shared pins = 0x%02x\n", |
| 153 | tvp5150_read(c, TVP5150_CONF_SHARED_PIN)); |
| 154 | printk("tvp5150: Active video cropping start MSB = 0x%02x\n", |
| 155 | tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_MSB)); |
| 156 | printk("tvp5150: Active video cropping start LSB = 0x%02x\n", |
| 157 | tvp5150_read(c, TVP5150_ACT_VD_CROP_ST_LSB)); |
| 158 | printk("tvp5150: Active video cropping stop MSB = 0x%02x\n", |
| 159 | tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_MSB)); |
| 160 | printk("tvp5150: Active video cropping stop LSB = 0x%02x\n", |
| 161 | tvp5150_read(c, TVP5150_ACT_VD_CROP_STP_LSB)); |
| 162 | printk("tvp5150: Genlock/RTC = 0x%02x\n", |
| 163 | tvp5150_read(c, TVP5150_GENLOCK)); |
| 164 | printk("tvp5150: Horizontal sync start = 0x%02x\n", |
| 165 | tvp5150_read(c, TVP5150_HORIZ_SYNC_START)); |
| 166 | printk("tvp5150: Vertical blanking start = 0x%02x\n", |
| 167 | tvp5150_read(c, TVP5150_VERT_BLANKING_START)); |
| 168 | printk("tvp5150: Vertical blanking stop = 0x%02x\n", |
| 169 | tvp5150_read(c, TVP5150_VERT_BLANKING_STOP)); |
| 170 | printk("tvp5150: Chrominance processing control #1 = 0x%02x\n", |
| 171 | tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_1)); |
| 172 | printk("tvp5150: Chrominance processing control #2 = 0x%02x\n", |
| 173 | tvp5150_read(c, TVP5150_CHROMA_PROC_CTL_2)); |
| 174 | printk("tvp5150: Interrupt reset register B = 0x%02x\n", |
| 175 | tvp5150_read(c, TVP5150_INT_RESET_REG_B)); |
| 176 | printk("tvp5150: Interrupt enable register B = 0x%02x\n", |
| 177 | tvp5150_read(c, TVP5150_INT_ENABLE_REG_B)); |
| 178 | printk("tvp5150: Interrupt configuration register B = 0x%02x\n", |
| 179 | tvp5150_read(c, TVP5150_INTT_CONFIG_REG_B)); |
| 180 | printk("tvp5150: Video standard = 0x%02x\n", |
| 181 | tvp5150_read(c, TVP5150_VIDEO_STD)); |
| 182 | printk("tvp5150: Cb gain factor = 0x%02x\n", |
| 183 | tvp5150_read(c, TVP5150_CB_GAIN_FACT)); |
| 184 | printk("tvp5150: Cr gain factor = 0x%02x\n", |
| 185 | tvp5150_read(c, TVP5150_CR_GAIN_FACTOR)); |
| 186 | printk("tvp5150: Macrovision on counter = 0x%02x\n", |
| 187 | tvp5150_read(c, TVP5150_MACROVISION_ON_CTR)); |
| 188 | printk("tvp5150: Macrovision off counter = 0x%02x\n", |
| 189 | tvp5150_read(c, TVP5150_MACROVISION_OFF_CTR)); |
| 190 | printk("tvp5150: revision select (TVP5150AM1 only) = 0x%02x\n", |
| 191 | tvp5150_read(c, TVP5150_REV_SELECT)); |
| 192 | printk("tvp5150: MSB of device ID = 0x%02x\n", |
| 193 | tvp5150_read(c, TVP5150_MSB_DEV_ID)); |
| 194 | printk("tvp5150: LSB of device ID = 0x%02x\n", |
| 195 | tvp5150_read(c, TVP5150_LSB_DEV_ID)); |
| 196 | printk("tvp5150: ROM major version = 0x%02x\n", |
| 197 | tvp5150_read(c, TVP5150_ROM_MAJOR_VER)); |
| 198 | printk("tvp5150: ROM minor version = 0x%02x\n", |
| 199 | tvp5150_read(c, TVP5150_ROM_MINOR_VER)); |
| 200 | printk("tvp5150: Vertical line count MSB = 0x%02x\n", |
| 201 | tvp5150_read(c, TVP5150_VERT_LN_COUNT_MSB)); |
| 202 | printk("tvp5150: Vertical line count LSB = 0x%02x\n", |
| 203 | tvp5150_read(c, TVP5150_VERT_LN_COUNT_LSB)); |
| 204 | printk("tvp5150: Interrupt status register B = 0x%02x\n", |
| 205 | tvp5150_read(c, TVP5150_INT_STATUS_REG_B)); |
| 206 | printk("tvp5150: Interrupt active register B = 0x%02x\n", |
| 207 | tvp5150_read(c, TVP5150_INT_ACTIVE_REG_B)); |
| 208 | printk("tvp5150: Status register #1 = 0x%02x\n", |
| 209 | tvp5150_read(c, TVP5150_STATUS_REG_1)); |
| 210 | printk("tvp5150: Status register #2 = 0x%02x\n", |
| 211 | tvp5150_read(c, TVP5150_STATUS_REG_2)); |
| 212 | printk("tvp5150: Status register #3 = 0x%02x\n", |
| 213 | tvp5150_read(c, TVP5150_STATUS_REG_3)); |
| 214 | printk("tvp5150: Status register #4 = 0x%02x\n", |
| 215 | tvp5150_read(c, TVP5150_STATUS_REG_4)); |
| 216 | printk("tvp5150: Status register #5 = 0x%02x\n", |
| 217 | tvp5150_read(c, TVP5150_STATUS_REG_5)); |
| 218 | printk("tvp5150: Closed caption data registers = 0x%02x\n", |
| 219 | tvp5150_read(c, TVP5150_CC_DATA_REG1)); |
| 220 | printk("tvp5150: Closed caption data registers = 0x%02x\n", |
| 221 | tvp5150_read(c, TVP5150_CC_DATA_REG2)); |
| 222 | printk("tvp5150: Closed caption data registers = 0x%02x\n", |
| 223 | tvp5150_read(c, TVP5150_CC_DATA_REG3)); |
| 224 | printk("tvp5150: Closed caption data registers = 0x%02x\n", |
| 225 | tvp5150_read(c, TVP5150_CC_DATA_REG4)); |
| 226 | printk("tvp5150: WSS data registers = 0x%02x\n", |
| 227 | tvp5150_read(c, TVP5150_WSS_DATA_REG1)); |
| 228 | printk("tvp5150: WSS data registers = 0x%02x\n", |
| 229 | tvp5150_read(c, TVP5150_WSS_DATA_REG2)); |
| 230 | printk("tvp5150: WSS data registers = 0x%02x\n", |
| 231 | tvp5150_read(c, TVP5150_WSS_DATA_REG3)); |
| 232 | printk("tvp5150: WSS data registers = 0x%02x\n", |
| 233 | tvp5150_read(c, TVP5150_WSS_DATA_REG4)); |
| 234 | printk("tvp5150: WSS data registers = 0x%02x\n", |
| 235 | tvp5150_read(c, TVP5150_WSS_DATA_REG5)); |
| 236 | printk("tvp5150: WSS data registers = 0x%02x\n", |
| 237 | tvp5150_read(c, TVP5150_WSS_DATA_REG6)); |
| 238 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 239 | tvp5150_read(c, TVP5150_VPS_DATA_REG1)); |
| 240 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 241 | tvp5150_read(c, TVP5150_VPS_DATA_REG2)); |
| 242 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 243 | tvp5150_read(c, TVP5150_VPS_DATA_REG3)); |
| 244 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 245 | tvp5150_read(c, TVP5150_VPS_DATA_REG4)); |
| 246 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 247 | tvp5150_read(c, TVP5150_VPS_DATA_REG5)); |
| 248 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 249 | tvp5150_read(c, TVP5150_VPS_DATA_REG6)); |
| 250 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 251 | tvp5150_read(c, TVP5150_VPS_DATA_REG7)); |
| 252 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 253 | tvp5150_read(c, TVP5150_VPS_DATA_REG8)); |
| 254 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 255 | tvp5150_read(c, TVP5150_VPS_DATA_REG9)); |
| 256 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 257 | tvp5150_read(c, TVP5150_VPS_DATA_REG10)); |
| 258 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 259 | tvp5150_read(c, TVP5150_VPS_DATA_REG11)); |
| 260 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 261 | tvp5150_read(c, TVP5150_VPS_DATA_REG12)); |
| 262 | printk("tvp5150: VPS data registers = 0x%02x\n", |
| 263 | tvp5150_read(c, TVP5150_VPS_DATA_REG13)); |
| 264 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 265 | tvp5150_read(c, TVP5150_VITC_DATA_REG1)); |
| 266 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 267 | tvp5150_read(c, TVP5150_VITC_DATA_REG2)); |
| 268 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 269 | tvp5150_read(c, TVP5150_VITC_DATA_REG3)); |
| 270 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 271 | tvp5150_read(c, TVP5150_VITC_DATA_REG4)); |
| 272 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 273 | tvp5150_read(c, TVP5150_VITC_DATA_REG5)); |
| 274 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 275 | tvp5150_read(c, TVP5150_VITC_DATA_REG6)); |
| 276 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 277 | tvp5150_read(c, TVP5150_VITC_DATA_REG7)); |
| 278 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 279 | tvp5150_read(c, TVP5150_VITC_DATA_REG8)); |
| 280 | printk("tvp5150: VITC data registers = 0x%02x\n", |
| 281 | tvp5150_read(c, TVP5150_VITC_DATA_REG9)); |
| 282 | printk("tvp5150: VBI FIFO read data = 0x%02x\n", |
| 283 | tvp5150_read(c, TVP5150_VBI_FIFO_READ_DATA)); |
| 284 | printk("tvp5150: Teletext filter 1 = 0x%02x\n", |
| 285 | tvp5150_read(c, TVP5150_TELETEXT_FIL_1_1)); |
| 286 | printk("tvp5150: Teletext filter 1 = 0x%02x\n", |
| 287 | tvp5150_read(c, TVP5150_TELETEXT_FIL_1_2)); |
| 288 | printk("tvp5150: Teletext filter 1 = 0x%02x\n", |
| 289 | tvp5150_read(c, TVP5150_TELETEXT_FIL_1_3)); |
| 290 | printk("tvp5150: Teletext filter 1 = 0x%02x\n", |
| 291 | tvp5150_read(c, TVP5150_TELETEXT_FIL_1_4)); |
| 292 | printk("tvp5150: Teletext filter 1 = 0x%02x\n", |
| 293 | tvp5150_read(c, TVP5150_TELETEXT_FIL_1_5)); |
| 294 | printk("tvp5150: Teletext filter 2 = 0x%02x\n", |
| 295 | tvp5150_read(c, TVP5150_TELETEXT_FIL_2_1)); |
| 296 | printk("tvp5150: Teletext filter 2 = 0x%02x\n", |
| 297 | tvp5150_read(c, TVP5150_TELETEXT_FIL_2_2)); |
| 298 | printk("tvp5150: Teletext filter 2 = 0x%02x\n", |
| 299 | tvp5150_read(c, TVP5150_TELETEXT_FIL_2_3)); |
| 300 | printk("tvp5150: Teletext filter 2 = 0x%02x\n", |
| 301 | tvp5150_read(c, TVP5150_TELETEXT_FIL_2_4)); |
| 302 | printk("tvp5150: Teletext filter 2 = 0x%02x\n", |
| 303 | tvp5150_read(c, TVP5150_TELETEXT_FIL_2_5)); |
| 304 | printk("tvp5150: Teletext filter enable = 0x%02x\n", |
| 305 | tvp5150_read(c, TVP5150_TELETEXT_FIL_ENA)); |
| 306 | printk("tvp5150: Interrupt status register A = 0x%02x\n", |
| 307 | tvp5150_read(c, TVP5150_INT_STATUS_REG_A)); |
| 308 | printk("tvp5150: Interrupt enable register A = 0x%02x\n", |
| 309 | tvp5150_read(c, TVP5150_INT_ENABLE_REG_A)); |
| 310 | printk("tvp5150: Interrupt configuration = 0x%02x\n", |
| 311 | tvp5150_read(c, TVP5150_INT_CONF)); |
| 312 | printk("tvp5150: VDP configuration RAM data = 0x%02x\n", |
| 313 | tvp5150_read(c, TVP5150_VDP_CONF_RAM_DATA)); |
| 314 | printk("tvp5150: Configuration RAM address low byte = 0x%02x\n", |
| 315 | tvp5150_read(c, TVP5150_CONF_RAM_ADDR_LOW)); |
| 316 | printk("tvp5150: Configuration RAM address high byte = 0x%02x\n", |
| 317 | tvp5150_read(c, TVP5150_CONF_RAM_ADDR_HIGH)); |
| 318 | printk("tvp5150: VDP status register = 0x%02x\n", |
| 319 | tvp5150_read(c, TVP5150_VDP_STATUS_REG)); |
| 320 | printk("tvp5150: FIFO word count = 0x%02x\n", |
| 321 | tvp5150_read(c, TVP5150_FIFO_WORD_COUNT)); |
| 322 | printk("tvp5150: FIFO interrupt threshold = 0x%02x\n", |
| 323 | tvp5150_read(c, TVP5150_FIFO_INT_THRESHOLD)); |
| 324 | printk("tvp5150: FIFO reset = 0x%02x\n", |
| 325 | tvp5150_read(c, TVP5150_FIFO_RESET)); |
| 326 | printk("tvp5150: Line number interrupt = 0x%02x\n", |
| 327 | tvp5150_read(c, TVP5150_LINE_NUMBER_INT)); |
| 328 | printk("tvp5150: Pixel alignment register low byte = 0x%02x\n", |
| 329 | tvp5150_read(c, TVP5150_PIX_ALIGN_REG_LOW)); |
| 330 | printk("tvp5150: Pixel alignment register high byte = 0x%02x\n", |
| 331 | tvp5150_read(c, TVP5150_PIX_ALIGN_REG_HIGH)); |
| 332 | printk("tvp5150: FIFO output control = 0x%02x\n", |
| 333 | tvp5150_read(c, TVP5150_FIFO_OUT_CTRL)); |
| 334 | printk("tvp5150: Full field enable 1 = 0x%02x\n", |
| 335 | tvp5150_read(c, TVP5150_FULL_FIELD_ENA_1)); |
| 336 | printk("tvp5150: Full field enable 2 = 0x%02x\n", |
| 337 | tvp5150_read(c, TVP5150_FULL_FIELD_ENA_2)); |
| 338 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 339 | tvp5150_read(c, TVP5150_LINE_MODE_REG_1)); |
| 340 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 341 | tvp5150_read(c, TVP5150_LINE_MODE_REG_2)); |
| 342 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 343 | tvp5150_read(c, TVP5150_LINE_MODE_REG_3)); |
| 344 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 345 | tvp5150_read(c, TVP5150_LINE_MODE_REG_4)); |
| 346 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 347 | tvp5150_read(c, TVP5150_LINE_MODE_REG_5)); |
| 348 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 349 | tvp5150_read(c, TVP5150_LINE_MODE_REG_6)); |
| 350 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 351 | tvp5150_read(c, TVP5150_LINE_MODE_REG_7)); |
| 352 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 353 | tvp5150_read(c, TVP5150_LINE_MODE_REG_8)); |
| 354 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 355 | tvp5150_read(c, TVP5150_LINE_MODE_REG_9)); |
| 356 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 357 | tvp5150_read(c, TVP5150_LINE_MODE_REG_10)); |
| 358 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 359 | tvp5150_read(c, TVP5150_LINE_MODE_REG_11)); |
| 360 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 361 | tvp5150_read(c, TVP5150_LINE_MODE_REG_12)); |
| 362 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 363 | tvp5150_read(c, TVP5150_LINE_MODE_REG_13)); |
| 364 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 365 | tvp5150_read(c, TVP5150_LINE_MODE_REG_14)); |
| 366 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 367 | tvp5150_read(c, TVP5150_LINE_MODE_REG_15)); |
| 368 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 369 | tvp5150_read(c, TVP5150_LINE_MODE_REG_16)); |
| 370 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 371 | tvp5150_read(c, TVP5150_LINE_MODE_REG_17)); |
| 372 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 373 | tvp5150_read(c, TVP5150_LINE_MODE_REG_18)); |
| 374 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 375 | tvp5150_read(c, TVP5150_LINE_MODE_REG_19)); |
| 376 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 377 | tvp5150_read(c, TVP5150_LINE_MODE_REG_20)); |
| 378 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 379 | tvp5150_read(c, TVP5150_LINE_MODE_REG_21)); |
| 380 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 381 | tvp5150_read(c, TVP5150_LINE_MODE_REG_22)); |
| 382 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 383 | tvp5150_read(c, TVP5150_LINE_MODE_REG_23)); |
| 384 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 385 | tvp5150_read(c, TVP5150_LINE_MODE_REG_24)); |
| 386 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 387 | tvp5150_read(c, TVP5150_LINE_MODE_REG_25)); |
| 388 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 389 | tvp5150_read(c, TVP5150_LINE_MODE_REG_27)); |
| 390 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 391 | tvp5150_read(c, TVP5150_LINE_MODE_REG_28)); |
| 392 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 393 | tvp5150_read(c, TVP5150_LINE_MODE_REG_29)); |
| 394 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 395 | tvp5150_read(c, TVP5150_LINE_MODE_REG_30)); |
| 396 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 397 | tvp5150_read(c, TVP5150_LINE_MODE_REG_31)); |
| 398 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 399 | tvp5150_read(c, TVP5150_LINE_MODE_REG_32)); |
| 400 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 401 | tvp5150_read(c, TVP5150_LINE_MODE_REG_33)); |
| 402 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 403 | tvp5150_read(c, TVP5150_LINE_MODE_REG_34)); |
| 404 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 405 | tvp5150_read(c, TVP5150_LINE_MODE_REG_35)); |
| 406 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 407 | tvp5150_read(c, TVP5150_LINE_MODE_REG_36)); |
| 408 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 409 | tvp5150_read(c, TVP5150_LINE_MODE_REG_37)); |
| 410 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 411 | tvp5150_read(c, TVP5150_LINE_MODE_REG_38)); |
| 412 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 413 | tvp5150_read(c, TVP5150_LINE_MODE_REG_39)); |
| 414 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 415 | tvp5150_read(c, TVP5150_LINE_MODE_REG_40)); |
| 416 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 417 | tvp5150_read(c, TVP5150_LINE_MODE_REG_41)); |
| 418 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 419 | tvp5150_read(c, TVP5150_LINE_MODE_REG_42)); |
| 420 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 421 | tvp5150_read(c, TVP5150_LINE_MODE_REG_43)); |
| 422 | printk("tvp5150: Line mode registers = 0x%02x\n", |
| 423 | tvp5150_read(c, TVP5150_LINE_MODE_REG_44)); |
| 424 | printk("tvp5150: Full field mode register = 0x%02x\n", |
| 425 | tvp5150_read(c, TVP5150_FULL_FIELD_MODE_REG)); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 426 | } |
| 427 | |
| 428 | /**************************************************************************** |
| 429 | Basic functions |
| 430 | ****************************************************************************/ |
| 431 | enum tvp5150_input { |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 432 | TVP5150_ANALOG_CH0 = 0, |
| 433 | TVP5150_SVIDEO = 1, |
| 434 | TVP5150_ANALOG_CH1 = 2, |
| 435 | TVP5150_BLACK_SCREEN = 8 |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 436 | }; |
| 437 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 438 | static inline void tvp5150_selmux(struct i2c_client *c, |
| 439 | enum tvp5150_input input) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 440 | { |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 441 | struct tvp5150 *decoder = i2c_get_clientdata(c); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 442 | |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 443 | if (!decoder->enable) |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 444 | input |= TVP5150_BLACK_SCREEN; |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 445 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 446 | tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 447 | }; |
| 448 | |
| 449 | static inline void tvp5150_reset(struct i2c_client *c) |
| 450 | { |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 451 | struct tvp5150 *decoder = i2c_get_clientdata(c); |
| 452 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 453 | tvp5150_write(c, TVP5150_CONF_SHARED_PIN, 2); |
| 454 | |
| 455 | /* Automatic offset and AGC enabled */ |
| 456 | tvp5150_write(c, TVP5150_ANAL_CHL_CTL, 0x15); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 457 | |
| 458 | /* Normal Operation */ |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 459 | // tvp5150_write(c, TVP5150_OP_MODE_CTL, 0x00); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 460 | |
| 461 | /* Activate YCrCb output 0x9 or 0xd ? */ |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 462 | tvp5150_write(c, TVP5150_MISC_CTL, 0x6f); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 463 | |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 464 | /* Activates video std autodetection for all standards */ |
| 465 | tvp5150_write(c, TVP5150_AUTOSW_MSK, 0x0); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 466 | |
| 467 | /* Default format: 0x47, 4:2:2: 0x40 */ |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 468 | tvp5150_write(c, TVP5150_DATA_RATE_SEL, 0x47); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 469 | |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 470 | tvp5150_selmux(c, decoder->input); |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 471 | |
| 472 | tvp5150_write(c, TVP5150_CHROMA_PROC_CTL_1, 0x0c); |
| 473 | tvp5150_write(c, TVP5150_CHROMA_PROC_CTL_2, 0x54); |
| 474 | |
| 475 | tvp5150_write(c, 0x27, 0x20); /* ?????????? */ |
| 476 | |
| 477 | tvp5150_write(c, TVP5150_VIDEO_STD, 0x0); /* Auto switch */ |
| 478 | |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 479 | tvp5150_write(c, TVP5150_BRIGHT_CTL, decoder->bright >> 8); |
| 480 | tvp5150_write(c, TVP5150_CONTRAST_CTL, decoder->contrast >> 8); |
| 481 | tvp5150_write(c, TVP5150_SATURATION_CTL, decoder->contrast >> 8); |
| 482 | tvp5150_write(c, TVP5150_HUE_CTL, (decoder->hue - 32768) >> 8); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 483 | }; |
| 484 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 485 | static int tvp5150_get_ctrl(struct i2c_client *c, struct v4l2_control *ctrl) |
| 486 | { |
| 487 | /* struct tvp5150 *decoder = i2c_get_clientdata(c); */ |
| 488 | |
| 489 | switch (ctrl->id) { |
| 490 | case V4L2_CID_BRIGHTNESS: |
| 491 | ctrl->value = tvp5150_read(c, TVP5150_BRIGHT_CTL); |
| 492 | return 0; |
| 493 | case V4L2_CID_CONTRAST: |
| 494 | ctrl->value = tvp5150_read(c, TVP5150_CONTRAST_CTL); |
| 495 | return 0; |
| 496 | case V4L2_CID_SATURATION: |
| 497 | ctrl->value = tvp5150_read(c, TVP5150_SATURATION_CTL); |
| 498 | return 0; |
| 499 | case V4L2_CID_HUE: |
| 500 | ctrl->value = tvp5150_read(c, TVP5150_HUE_CTL); |
| 501 | return 0; |
| 502 | default: |
| 503 | return -EINVAL; |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | static int tvp5150_set_ctrl(struct i2c_client *c, struct v4l2_control *ctrl) |
| 508 | { |
| 509 | /* struct tvp5150 *decoder = i2c_get_clientdata(c); */ |
| 510 | |
| 511 | switch (ctrl->id) { |
| 512 | case V4L2_CID_BRIGHTNESS: |
| 513 | tvp5150_write(c, TVP5150_BRIGHT_CTL, ctrl->value); |
| 514 | return 0; |
| 515 | case V4L2_CID_CONTRAST: |
| 516 | tvp5150_write(c, TVP5150_CONTRAST_CTL, ctrl->value); |
| 517 | return 0; |
| 518 | case V4L2_CID_SATURATION: |
| 519 | tvp5150_write(c, TVP5150_SATURATION_CTL, ctrl->value); |
| 520 | return 0; |
| 521 | case V4L2_CID_HUE: |
| 522 | tvp5150_write(c, TVP5150_HUE_CTL, ctrl->value); |
| 523 | return 0; |
| 524 | default: |
| 525 | return -EINVAL; |
| 526 | } |
| 527 | } |
| 528 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 529 | /**************************************************************************** |
| 530 | I2C Command |
| 531 | ****************************************************************************/ |
| 532 | static int tvp5150_command(struct i2c_client *client, |
| 533 | unsigned int cmd, void *arg) |
| 534 | { |
| 535 | struct tvp5150 *decoder = i2c_get_clientdata(client); |
| 536 | |
| 537 | switch (cmd) { |
| 538 | |
| 539 | case 0: |
| 540 | case DECODER_INIT: |
| 541 | tvp5150_reset(client); |
| 542 | break; |
| 543 | |
| 544 | case DECODER_DUMP: |
| 545 | dump_reg(client); |
| 546 | break; |
| 547 | |
| 548 | case DECODER_GET_CAPABILITIES: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 549 | { |
| 550 | struct video_decoder_capability *cap = arg; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 551 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 552 | cap->flags = VIDEO_DECODER_PAL | |
| 553 | VIDEO_DECODER_NTSC | |
| 554 | VIDEO_DECODER_SECAM | |
| 555 | VIDEO_DECODER_AUTO | VIDEO_DECODER_CCIR; |
| 556 | cap->inputs = 3; |
| 557 | cap->outputs = 1; |
| 558 | break; |
| 559 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 560 | case DECODER_GET_STATUS: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 561 | { |
| 562 | break; |
| 563 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 564 | |
| 565 | case DECODER_SET_GPIO: |
| 566 | break; |
| 567 | |
| 568 | case DECODER_SET_VBI_BYPASS: |
| 569 | break; |
| 570 | |
| 571 | case DECODER_SET_NORM: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 572 | { |
| 573 | int *iarg = arg; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 574 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 575 | switch (*iarg) { |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 576 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 577 | case VIDEO_MODE_NTSC: |
| 578 | break; |
| 579 | |
| 580 | case VIDEO_MODE_PAL: |
| 581 | break; |
| 582 | |
| 583 | case VIDEO_MODE_SECAM: |
| 584 | break; |
| 585 | |
| 586 | case VIDEO_MODE_AUTO: |
| 587 | break; |
| 588 | |
| 589 | default: |
| 590 | return -EINVAL; |
| 591 | |
| 592 | } |
| 593 | decoder->norm = *iarg; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 594 | break; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 595 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 596 | case DECODER_SET_INPUT: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 597 | { |
| 598 | int *iarg = arg; |
| 599 | if (*iarg < 0 || *iarg > 3) { |
| 600 | return -EINVAL; |
| 601 | } |
| 602 | |
| 603 | decoder->input = *iarg; |
| 604 | tvp5150_selmux(client, decoder->input); |
| 605 | |
| 606 | break; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 607 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 608 | case DECODER_SET_OUTPUT: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 609 | { |
| 610 | int *iarg = arg; |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 611 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 612 | /* not much choice of outputs */ |
| 613 | if (*iarg != 0) { |
| 614 | return -EINVAL; |
| 615 | } |
| 616 | break; |
| 617 | } |
| 618 | case DECODER_ENABLE_OUTPUT: |
| 619 | { |
| 620 | int *iarg = arg; |
| 621 | |
| 622 | decoder->enable = (*iarg != 0); |
| 623 | |
| 624 | tvp5150_selmux(client, decoder->input); |
| 625 | |
| 626 | break; |
| 627 | } |
| 628 | case VIDIOC_QUERYCTRL: |
| 629 | { |
| 630 | struct v4l2_queryctrl *qc = arg; |
| 631 | u8 i, n; |
| 632 | |
| 633 | dprintk(1, KERN_DEBUG "VIDIOC_QUERYCTRL"); |
| 634 | |
| 635 | n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]); |
| 636 | for (i = 0; i < n; i++) |
| 637 | if (qc->id && qc->id == tvp5150_qctrl[i].id) { |
| 638 | memcpy(qc, &(tvp5150_qctrl[i]), |
| 639 | sizeof(*qc)); |
| 640 | return 0; |
| 641 | } |
| 642 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 643 | return -EINVAL; |
| 644 | } |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 645 | case VIDIOC_G_CTRL: |
| 646 | { |
| 647 | struct v4l2_control *ctrl = arg; |
| 648 | dprintk(1, KERN_DEBUG "VIDIOC_G_CTRL"); |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 649 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 650 | return tvp5150_get_ctrl(client, ctrl); |
| 651 | } |
| 652 | case VIDIOC_S_CTRL_OLD: /* ??? */ |
| 653 | case VIDIOC_S_CTRL: |
| 654 | { |
| 655 | struct v4l2_control *ctrl = arg; |
| 656 | u8 i, n; |
| 657 | dprintk(1, KERN_DEBUG "VIDIOC_S_CTRL"); |
| 658 | n = sizeof(tvp5150_qctrl) / sizeof(tvp5150_qctrl[0]); |
| 659 | for (i = 0; i < n; i++) |
| 660 | if (ctrl->id == tvp5150_qctrl[i].id) { |
| 661 | if (ctrl->value < |
| 662 | tvp5150_qctrl[i].minimum |
| 663 | || ctrl->value > |
| 664 | tvp5150_qctrl[i].maximum) |
| 665 | return -ERANGE; |
| 666 | dprintk(1, |
| 667 | KERN_DEBUG |
| 668 | "VIDIOC_S_CTRL: id=%d, value=%d", |
| 669 | ctrl->id, ctrl->value); |
| 670 | return tvp5150_set_ctrl(client, ctrl); |
| 671 | } |
| 672 | return -EINVAL; |
| 673 | } |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 674 | |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 675 | case DECODER_SET_PICTURE: |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 676 | { |
| 677 | struct video_picture *pic = arg; |
| 678 | if (decoder->bright != pic->brightness) { |
| 679 | /* We want 0 to 255 we get 0-65535 */ |
| 680 | decoder->bright = pic->brightness; |
| 681 | tvp5150_write(client, TVP5150_BRIGHT_CTL, |
| 682 | decoder->bright >> 8); |
| 683 | } |
| 684 | if (decoder->contrast != pic->contrast) { |
| 685 | /* We want 0 to 255 we get 0-65535 */ |
| 686 | decoder->contrast = pic->contrast; |
| 687 | tvp5150_write(client, TVP5150_CONTRAST_CTL, |
| 688 | decoder->contrast >> 8); |
| 689 | } |
| 690 | if (decoder->sat != pic->colour) { |
| 691 | /* We want 0 to 255 we get 0-65535 */ |
| 692 | decoder->sat = pic->colour; |
| 693 | tvp5150_write(client, TVP5150_SATURATION_CTL, |
| 694 | decoder->contrast >> 8); |
| 695 | } |
| 696 | if (decoder->hue != pic->hue) { |
| 697 | /* We want -128 to 127 we get 0-65535 */ |
| 698 | decoder->hue = pic->hue; |
| 699 | tvp5150_write(client, TVP5150_HUE_CTL, |
| 700 | (decoder->hue - 32768) >> 8); |
| 701 | } |
| 702 | break; |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 703 | } |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 704 | default: |
| 705 | return -EINVAL; |
| 706 | } |
| 707 | |
| 708 | return 0; |
| 709 | } |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 710 | |
| 711 | /**************************************************************************** |
| 712 | I2C Client & Driver |
| 713 | ****************************************************************************/ |
| 714 | static struct i2c_driver driver; |
| 715 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 716 | static struct i2c_client client_template = { |
| 717 | .name = "(unset)", |
| 718 | .flags = I2C_CLIENT_ALLOW_USE, |
| 719 | .driver = &driver, |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 720 | }; |
| 721 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 722 | static int tvp5150_detect_client(struct i2c_adapter *adapter, |
| 723 | int address, int kind) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 724 | { |
| 725 | struct i2c_client *client; |
| 726 | struct tvp5150 *core; |
| 727 | int rv; |
| 728 | |
| 729 | dprintk(1, |
| 730 | KERN_INFO |
| 731 | "tvp5150.c: detecting tvp5150 client on address 0x%x\n", |
| 732 | address << 1); |
| 733 | |
| 734 | client_template.adapter = adapter; |
| 735 | client_template.addr = address; |
| 736 | |
| 737 | /* Check if the adapter supports the needed features */ |
| 738 | if (!i2c_check_functionality |
| 739 | (adapter, |
| 740 | I2C_FUNC_SMBUS_READ_BYTE | I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) |
| 741 | return 0; |
| 742 | |
| 743 | client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL); |
| 744 | if (client == 0) |
| 745 | return -ENOMEM; |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 746 | memcpy(client, &client_template, sizeof(struct i2c_client)); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 747 | |
| 748 | core = kmalloc(sizeof(struct tvp5150), GFP_KERNEL); |
| 749 | if (core == 0) { |
| 750 | kfree(client); |
| 751 | return -ENOMEM; |
| 752 | } |
| 753 | memset(core, 0, sizeof(struct tvp5150)); |
| 754 | i2c_set_clientdata(client, core); |
| 755 | |
| 756 | rv = i2c_attach_client(client); |
| 757 | |
Mauro Carvalho Chehab | 4c86f97 | 2005-11-08 21:36:43 -0800 | [diff] [blame] | 758 | core->norm = VIDEO_MODE_AUTO; |
| 759 | core->input = 2; |
| 760 | core->enable = 1; |
| 761 | core->bright = 32768; |
| 762 | core->contrast = 32768; |
| 763 | core->hue = 32768; |
| 764 | core->sat = 32768; |
| 765 | |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 766 | if (rv) { |
| 767 | kfree(client); |
| 768 | kfree(core); |
| 769 | return rv; |
| 770 | } |
| 771 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 772 | if (debug > 1) |
| 773 | dump_reg(client); |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 774 | |
| 775 | return 0; |
| 776 | } |
| 777 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 778 | static int tvp5150_attach_adapter(struct i2c_adapter *adapter) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 779 | { |
| 780 | dprintk(1, |
| 781 | KERN_INFO |
| 782 | "tvp5150.c: starting probe for adapter %s (0x%x)\n", |
| 783 | adapter->name, adapter->id); |
| 784 | return i2c_probe(adapter, &addr_data, &tvp5150_detect_client); |
| 785 | } |
| 786 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 787 | static int tvp5150_detach_client(struct i2c_client *client) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 788 | { |
| 789 | struct tvp5150 *decoder = i2c_get_clientdata(client); |
| 790 | int err; |
| 791 | |
| 792 | err = i2c_detach_client(client); |
| 793 | if (err) { |
| 794 | return err; |
| 795 | } |
| 796 | |
| 797 | kfree(decoder); |
| 798 | kfree(client); |
| 799 | |
| 800 | return 0; |
| 801 | } |
| 802 | |
| 803 | /* ----------------------------------------------------------------------- */ |
| 804 | |
| 805 | static struct i2c_driver driver = { |
| 806 | .owner = THIS_MODULE, |
| 807 | .name = "tvp5150", |
| 808 | |
| 809 | /* FIXME */ |
| 810 | .id = I2C_DRIVERID_SAA7110, |
| 811 | .flags = I2C_DF_NOTIFY, |
| 812 | |
| 813 | .attach_adapter = tvp5150_attach_adapter, |
| 814 | .detach_client = tvp5150_detach_client, |
Mauro Carvalho Chehab | 84486d5 | 2005-11-08 21:36:41 -0800 | [diff] [blame] | 815 | |
| 816 | .command = tvp5150_command, |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 817 | }; |
| 818 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 819 | static int __init tvp5150_init(void) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 820 | { |
| 821 | return i2c_add_driver(&driver); |
| 822 | } |
| 823 | |
akpm@osdl.org | a6c2ba2 | 2005-11-08 21:37:07 -0800 | [diff] [blame^] | 824 | static void __exit tvp5150_exit(void) |
Mauro Carvalho Chehab | cd4665c | 2005-11-08 21:36:40 -0800 | [diff] [blame] | 825 | { |
| 826 | i2c_del_driver(&driver); |
| 827 | } |
| 828 | |
| 829 | module_init(tvp5150_init); |
| 830 | module_exit(tvp5150_exit); |