blob: a6330a351eaaedd18618934e2b8002811311448e [file] [log] [blame]
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001/*
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 Chehabcd4665c2005-11-08 21:36:40 -08008#include <linux/i2c.h>
9#include <linux/videodev.h>
10#include <linux/delay.h>
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -080011#include <linux/video_decoder.h>
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -020012#include <media/v4l2-common.h>
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080013
14#include "tvp5150_reg.h"
15
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -080016MODULE_DESCRIPTION("Texas Instruments TVP5150A video decoder driver"); /* standard i2c insmod options */
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080017MODULE_AUTHOR("Mauro Carvalho Chehab");
18MODULE_LICENSE("GPL");
19
20static unsigned short normal_i2c[] = {
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -080021 0xb8 >> 1,
22 0xba >> 1,
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080023 I2C_CLIENT_END
24};
25
26I2C_CLIENT_INSMOD;
27
28static int debug = 0;
29module_param(debug, int, 0);
30MODULE_PARM_DESC(debug, "Debug level (0-1)");
31
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -020032#define tvp5150_info(fmt, arg...) do { \
Mauro Carvalho Chehabcab462f2006-01-09 15:53:26 -020033 printk(KERN_INFO "%s %d-%04x: " fmt, c->driver->driver.name, \
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -020034 i2c_adapter_id(c->adapter), c->addr , ## arg); } while (0)
35#define tvp5150_dbg(num, fmt, arg...) \
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080036 do { \
37 if (debug >= num) \
Mauro Carvalho Chehabcab462f2006-01-09 15:53:26 -020038 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 Chehabcd4665c2005-11-08 21:36:40 -080042
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -080043/* supported controls */
44static struct v4l2_queryctrl tvp5150_qctrl[] = {
45 {
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -020046 .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.orga6c2ba22005-11-08 21:37:07 -080064 .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 Chehabc0477ad2006-01-09 15:25:14 -020072 }, {
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.orga6c2ba22005-11-08 21:37:07 -080082};
83
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080084struct tvp5150 {
85 struct i2c_client *client;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -080086
87 int norm;
88 int input;
89 int enable;
90 int bright;
91 int contrast;
92 int hue;
93 int sat;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080094};
95
Arjan van de Ven858119e2006-01-14 13:20:43 -080096static int tvp5150_read(struct i2c_client *c, unsigned char addr)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -080097{
98 unsigned char buffer[1];
99 int rc;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800100
101 buffer[0] = addr;
102 if (1 != (rc = i2c_master_send(c, buffer, 1)))
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200103 tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 1)\n", rc);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800104
105 msleep(10);
106
107 if (1 != (rc = i2c_master_recv(c, buffer, 1)))
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200108 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 Chehabcd4665c2005-11-08 21:36:40 -0800111
112 return (buffer[0]);
113}
114
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800115static inline void tvp5150_write(struct i2c_client *c, unsigned char addr,
116 unsigned char value)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800117{
118 unsigned char buffer[2];
119 int rc;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800120
121 buffer[0] = addr;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800122 buffer[1] = value;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200123 tvp5150_dbg(2, "tvp5150: writing 0x%02x 0x%02x\n", buffer[0], buffer[1]);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800124 if (2 != (rc = i2c_master_send(c, buffer, 2)))
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200125 tvp5150_dbg(0, "i2c i/o error: rc == %d (should be 2)\n", rc);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800126}
127
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800128static void dump_reg(struct i2c_client *c)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800129{
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800130 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 Chehabcd4665c2005-11-08 21:36:40 -0800432}
433
434/****************************************************************************
435 Basic functions
436 ****************************************************************************/
437enum tvp5150_input {
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800438 TVP5150_ANALOG_CH0 = 0,
439 TVP5150_SVIDEO = 1,
440 TVP5150_ANALOG_CH1 = 2,
441 TVP5150_BLACK_SCREEN = 8
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800442};
443
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800444static inline void tvp5150_selmux(struct i2c_client *c,
445 enum tvp5150_input input)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800446{
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200447 int opmode=0;
448
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -0800449 struct tvp5150 *decoder = i2c_get_clientdata(c);
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800450
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -0800451 if (!decoder->enable)
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800452 input |= TVP5150_BLACK_SCREEN;
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -0800453
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200454 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.orga6c2ba22005-11-08 21:37:07 -0800465 tvp5150_write(c, TVP5150_VD_IN_SRC_SEL_1, input);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800466};
467
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200468struct i2c_reg_value {
469 unsigned char reg;
470 unsigned char value;
471};
472
473/* Default values as sugested at TVP5150AM1 datasheet */
474static 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 */
610static 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
632struct i2c_vbi_ram_value {
633 u16 reg;
634 unsigned char values[26];
635};
636
Adrian Bunka9cff902006-01-15 06:56:15 -0200637static struct i2c_vbi_ram_value vbi_ram_default[] =
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200638{
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
678static 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
688static 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
713static int tvp5150_set_std(struct i2c_client *c, v4l2_std_id std)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800714{
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -0800715 struct tvp5150 *decoder = i2c_get_clientdata(c);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200716 int fmt=0;
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -0800717
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200718 decoder->norm=std;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800719
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200720 /* First tests should be against specific std */
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800721
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200722 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 Chehabcd4665c2005-11-08 21:36:40 -0800740
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200741 tvp5150_dbg(1,"Set video std register to %d.\n",fmt);
742 tvp5150_write(c, TVP5150_VIDEO_STD, fmt);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800743
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200744 return 0;
745}
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800746
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200747static inline void tvp5150_reset(struct i2c_client *c)
748{
Mauro Carvalho Chehabe36eaa72006-01-23 09:48:34 -0200749 u8 msb_id, lsb_id, msb_rom, lsb_rom;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200750 struct tvp5150 *decoder = i2c_get_clientdata(c);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800751
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200752 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 Chehabe36eaa72006-01-23 09:48:34 -0200757 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 Chehabe1bc80a2006-01-09 15:25:36 -0200762 } else {
Mauro Carvalho Chehabe36eaa72006-01-23 09:48:34 -0200763 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 Chehabe1bc80a2006-01-09 15:25:36 -0200769 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200770
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 Chehab4c86f972005-11-08 21:36:43 -0800778 tvp5150_selmux(c, decoder->input);
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800779
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200780 /* Initializes TVP5150 to stream enabled values */
781 tvp5150_write_inittab(c, tvp5150_init_enable);
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800782
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200783 /* Initialize image preferences */
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -0800784 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 Chehabe1bc80a2006-01-09 15:25:36 -0200788
789 tvp5150_set_std(c, decoder->norm);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -0800790};
791
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800792static 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.orga6c2ba22005-11-08 21:37:07 -0800809 }
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200810 return -EINVAL;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800811}
812
813static 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.orga6c2ba22005-11-08 21:37:07 -0800830 }
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200831 return -EINVAL;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800832}
833
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800834/****************************************************************************
835 I2C Command
836 ****************************************************************************/
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200837static int tvp5150_command(struct i2c_client *c,
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800838 unsigned int cmd, void *arg)
839{
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200840 struct tvp5150 *decoder = i2c_get_clientdata(c);
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800841
842 switch (cmd) {
843
844 case 0:
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200845 case VIDIOC_INT_RESET:
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800846 case DECODER_INIT:
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200847 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 Chehab84486d52005-11-08 21:36:41 -0800855 break;
856
Mauro Carvalho Chehab21dcd8c2006-01-09 15:25:37 -0200857#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 Chehab84486d52005-11-08 21:36:41 -0800881 case DECODER_DUMP:
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200882 dump_reg(c);
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800883 break;
884
885 case DECODER_GET_CAPABILITIES:
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800886 {
887 struct video_decoder_capability *cap = arg;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800888
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800889 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 Chehab84486d52005-11-08 21:36:41 -0800897 case DECODER_GET_STATUS:
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800898 {
899 break;
900 }
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800901
902 case DECODER_SET_GPIO:
903 break;
904
905 case DECODER_SET_VBI_BYPASS:
906 break;
907
908 case DECODER_SET_NORM:
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800909 {
910 int *iarg = arg;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800911
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800912 switch (*iarg) {
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800913
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800914 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 Chehab84486d52005-11-08 21:36:41 -0800931 break;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800932 }
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800933 case DECODER_SET_INPUT:
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800934 {
935 int *iarg = arg;
936 if (*iarg < 0 || *iarg > 3) {
937 return -EINVAL;
938 }
939
940 decoder->input = *iarg;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200941 tvp5150_selmux(c, decoder->input);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800942
943 break;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800944 }
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800945 case DECODER_SET_OUTPUT:
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800946 {
947 int *iarg = arg;
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -0800948
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800949 /* 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 Chehabe1bc80a2006-01-09 15:25:36 -0200961 tvp5150_selmux(c, decoder->input);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800962
963 break;
964 }
965 case VIDIOC_QUERYCTRL:
966 {
967 struct v4l2_queryctrl *qc = arg;
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200968 int i;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800969
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200970 tvp5150_dbg(1, "VIDIOC_QUERYCTRL called\n");
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800971
Mauro Carvalho Chehabc0477ad2006-01-09 15:25:14 -0200972 for (i = 0; i < ARRAY_SIZE(tvp5150_qctrl); i++)
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800973 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 Chehab84486d52005-11-08 21:36:41 -0800979 return -EINVAL;
980 }
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800981 case VIDIOC_G_CTRL:
982 {
983 struct v4l2_control *ctrl = arg;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200984 tvp5150_dbg(1, "VIDIOC_G_CTRL called\n");
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -0800985
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -0200986 return tvp5150_get_ctrl(c, ctrl);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800987 }
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800988 case VIDIOC_S_CTRL:
989 {
990 struct v4l2_control *ctrl = arg;
991 u8 i, n;
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -0800992 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 Chehabe1bc80a2006-01-09 15:25:36 -02001000 tvp5150_dbg(1,
1001 "VIDIOC_S_CTRL: id=%d, value=%d\n",
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001002 ctrl->id, ctrl->value);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001003 return tvp5150_set_ctrl(c, ctrl);
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001004 }
1005 return -EINVAL;
1006 }
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -08001007
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -08001008 case DECODER_SET_PICTURE:
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001009 {
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 Chehabe1bc80a2006-01-09 15:25:36 -02001014 tvp5150_write(c, TVP5150_BRIGHT_CTL,
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001015 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 Chehabe1bc80a2006-01-09 15:25:36 -02001020 tvp5150_write(c, TVP5150_CONTRAST_CTL,
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001021 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 Chehabe1bc80a2006-01-09 15:25:36 -02001026 tvp5150_write(c, TVP5150_SATURATION_CTL,
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001027 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 Chehabe1bc80a2006-01-09 15:25:36 -02001032 tvp5150_write(c, TVP5150_HUE_CTL,
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001033 (decoder->hue - 32768) >> 8);
1034 }
1035 break;
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -08001036 }
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -08001037 default:
1038 return -EINVAL;
1039 }
1040
1041 return 0;
1042}
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001043
1044/****************************************************************************
1045 I2C Client & Driver
1046 ****************************************************************************/
1047static struct i2c_driver driver;
1048
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001049static struct i2c_client client_template = {
1050 .name = "(unset)",
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001051 .driver = &driver,
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001052};
1053
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001054static int tvp5150_detect_client(struct i2c_adapter *adapter,
1055 int address, int kind)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001056{
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001057 struct i2c_client *c;
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001058 struct tvp5150 *core;
1059 int rv;
1060
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001061 if (debug)
1062 printk( KERN_INFO
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001063 "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 Chehabe1bc80a2006-01-09 15:25:36 -02001075 c = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
1076 if (c == 0)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001077 return -ENOMEM;
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001078 memcpy(c, &client_template, sizeof(struct i2c_client));
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001079
Panagiotis Issaris74081872006-01-11 19:40:56 -02001080 core = kzalloc(sizeof(struct tvp5150), GFP_KERNEL);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001081 if (core == 0) {
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001082 kfree(c);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001083 return -ENOMEM;
1084 }
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001085 i2c_set_clientdata(c, core);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001086
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001087 rv = i2c_attach_client(c);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001088
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001089 core->norm = V4L2_STD_ALL;
Mauro Carvalho Chehab4c86f972005-11-08 21:36:43 -08001090 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 Chehabcd4665c2005-11-08 21:36:40 -08001097 if (rv) {
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001098 kfree(c);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001099 kfree(core);
1100 return rv;
1101 }
1102
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001103 if (debug > 1)
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001104 dump_reg(c);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001105 return 0;
1106}
1107
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001108static int tvp5150_attach_adapter(struct i2c_adapter *adapter)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001109{
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001110 if (debug)
1111 printk( KERN_INFO
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001112 "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 Chehabe1bc80a2006-01-09 15:25:36 -02001117static int tvp5150_detach_client(struct i2c_client *c)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001118{
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001119 struct tvp5150 *decoder = i2c_get_clientdata(c);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001120 int err;
1121
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001122 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 Chehabcd4665c2005-11-08 21:36:40 -08001127 if (err) {
1128 return err;
1129 }
1130
1131 kfree(decoder);
Mauro Carvalho Chehabe1bc80a2006-01-09 15:25:36 -02001132 kfree(c);
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001133
1134 return 0;
1135}
1136
1137/* ----------------------------------------------------------------------- */
1138
1139static struct i2c_driver driver = {
Laurent Riffard604f28e2005-11-26 20:43:39 +01001140 .driver = {
Laurent Riffard604f28e2005-11-26 20:43:39 +01001141 .name = "tvp5150",
1142 },
Mauro Carvalho Chehabcab462f2006-01-09 15:53:26 -02001143 .id = I2C_DRIVERID_TVP5150,
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001144
1145 .attach_adapter = tvp5150_attach_adapter,
1146 .detach_client = tvp5150_detach_client,
Mauro Carvalho Chehab84486d52005-11-08 21:36:41 -08001147
1148 .command = tvp5150_command,
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001149};
1150
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001151static int __init tvp5150_init(void)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001152{
1153 return i2c_add_driver(&driver);
1154}
1155
akpm@osdl.orga6c2ba22005-11-08 21:37:07 -08001156static void __exit tvp5150_exit(void)
Mauro Carvalho Chehabcd4665c2005-11-08 21:36:40 -08001157{
1158 i2c_del_driver(&driver);
1159}
1160
1161module_init(tvp5150_init);
1162module_exit(tvp5150_exit);