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