blob: 54cc0dadd7554830eeed8e76715f9b5ddb3b0213 [file] [log] [blame]
Chaithrika U S63a8e712009-06-09 05:54:02 -03001/*
2 * vpif - DM646x Video Port Interface driver
3 * VPIF is a receiver and transmitter for video data. It has two channels(0, 1)
4 * that receiveing video byte stream and two channels(2, 3) for video output.
5 * The hardware supports SDTV, HDTV formats, raw data capture.
6 * Currently, the driver supports NTSC and PAL standards.
7 *
8 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation version 2.
13 *
14 * This program is distributed .as is. WITHOUT ANY WARRANTY of any
15 * kind, whether express or implied; without even the implied warranty
16 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
19
20#include <linux/init.h>
21#include <linux/module.h>
Muralidharan Karicherid28a6df2009-09-16 14:31:20 -030022#include <linux/platform_device.h>
23#include <linux/spinlock.h>
Chaithrika U S63a8e712009-06-09 05:54:02 -030024#include <linux/kernel.h>
Muralidharan Karicherid28a6df2009-09-16 14:31:20 -030025#include <linux/io.h>
26#include <mach/hardware.h>
Chaithrika U S63a8e712009-06-09 05:54:02 -030027
28#include "vpif.h"
29
30MODULE_DESCRIPTION("TI DaVinci Video Port Interface driver");
31MODULE_LICENSE("GPL");
32
33#define VPIF_CH0_MAX_MODES (22)
34#define VPIF_CH1_MAX_MODES (02)
35#define VPIF_CH2_MAX_MODES (15)
36#define VPIF_CH3_MAX_MODES (02)
37
Muralidharan Karicherid28a6df2009-09-16 14:31:20 -030038static resource_size_t res_len;
39static struct resource *res;
40spinlock_t vpif_lock;
41
42void __iomem *vpif_base;
43
Mats Randgaardaa444402010-12-16 12:17:42 -030044/**
45 * ch_params: video standard configuration parameters for vpif
46 * The table must include all presets from supported subdevices.
47 */
48const struct vpif_channel_config_params ch_params[] = {
49 /* SDTV formats */
50 {
51 .name = "NTSC_M",
52 .width = 720,
53 .height = 480,
54 .frm_fmt = 0,
55 .ycmux_mode = 1,
56 .eav2sav = 268,
57 .sav2eav = 1440,
58 .l1 = 1,
59 .l3 = 23,
60 .l5 = 263,
61 .l7 = 266,
62 .l9 = 286,
63 .l11 = 525,
64 .vsize = 525,
65 .capture_format = 0,
66 .vbi_supported = 1,
67 .hd_sd = 0,
68 .stdid = V4L2_STD_525_60,
69 },
70 {
71 .name = "PAL_BDGHIK",
72 .width = 720,
73 .height = 576,
74 .frm_fmt = 0,
75 .ycmux_mode = 1,
76 .eav2sav = 280,
77 .sav2eav = 1440,
78 .l1 = 1,
79 .l3 = 23,
80 .l5 = 311,
81 .l7 = 313,
82 .l9 = 336,
83 .l11 = 624,
84 .vsize = 625,
85 .capture_format = 0,
86 .vbi_supported = 1,
87 .hd_sd = 0,
88 .stdid = V4L2_STD_625_50,
89 },
90};
91
92const unsigned int vpif_ch_params_count = ARRAY_SIZE(ch_params);
93
Chaithrika U S63a8e712009-06-09 05:54:02 -030094static inline void vpif_wr_bit(u32 reg, u32 bit, u32 val)
95{
96 if (val)
97 vpif_set_bit(reg, bit);
98 else
99 vpif_clr_bit(reg, bit);
100}
101
102/* This structure is used to keep track of VPIF size register's offsets */
103struct vpif_registers {
104 u32 h_cfg, v_cfg_00, v_cfg_01, v_cfg_02, v_cfg, ch_ctrl;
105 u32 line_offset, vanc0_strt, vanc0_size, vanc1_strt;
106 u32 vanc1_size, width_mask, len_mask;
107 u8 max_modes;
108};
109
110static const struct vpif_registers vpifregs[VPIF_NUM_CHANNELS] = {
111 /* Channel0 */
112 {
113 VPIF_CH0_H_CFG, VPIF_CH0_V_CFG_00, VPIF_CH0_V_CFG_01,
114 VPIF_CH0_V_CFG_02, VPIF_CH0_V_CFG_03, VPIF_CH0_CTRL,
115 VPIF_CH0_IMG_ADD_OFST, 0, 0, 0, 0, 0x1FFF, 0xFFF,
116 VPIF_CH0_MAX_MODES,
117 },
118 /* Channel1 */
119 {
120 VPIF_CH1_H_CFG, VPIF_CH1_V_CFG_00, VPIF_CH1_V_CFG_01,
121 VPIF_CH1_V_CFG_02, VPIF_CH1_V_CFG_03, VPIF_CH1_CTRL,
122 VPIF_CH1_IMG_ADD_OFST, 0, 0, 0, 0, 0x1FFF, 0xFFF,
123 VPIF_CH1_MAX_MODES,
124 },
125 /* Channel2 */
126 {
127 VPIF_CH2_H_CFG, VPIF_CH2_V_CFG_00, VPIF_CH2_V_CFG_01,
128 VPIF_CH2_V_CFG_02, VPIF_CH2_V_CFG_03, VPIF_CH2_CTRL,
129 VPIF_CH2_IMG_ADD_OFST, VPIF_CH2_VANC0_STRT, VPIF_CH2_VANC0_SIZE,
130 VPIF_CH2_VANC1_STRT, VPIF_CH2_VANC1_SIZE, 0x7FF, 0x7FF,
131 VPIF_CH2_MAX_MODES
132 },
133 /* Channel3 */
134 {
135 VPIF_CH3_H_CFG, VPIF_CH3_V_CFG_00, VPIF_CH3_V_CFG_01,
136 VPIF_CH3_V_CFG_02, VPIF_CH3_V_CFG_03, VPIF_CH3_CTRL,
137 VPIF_CH3_IMG_ADD_OFST, VPIF_CH3_VANC0_STRT, VPIF_CH3_VANC0_SIZE,
138 VPIF_CH3_VANC1_STRT, VPIF_CH3_VANC1_SIZE, 0x7FF, 0x7FF,
139 VPIF_CH3_MAX_MODES
140 },
141};
142
143/* vpif_set_mode_info:
144 * This function is used to set horizontal and vertical config parameters
145 * As per the standard in the channel, configure the values of L1, L3,
146 * L5, L7 L9, L11 in VPIF Register , also write width and height
147 */
148static void vpif_set_mode_info(const struct vpif_channel_config_params *config,
149 u8 channel_id, u8 config_channel_id)
150{
151 u32 value;
152
153 value = (config->eav2sav & vpifregs[config_channel_id].width_mask);
154 value <<= VPIF_CH_LEN_SHIFT;
155 value |= (config->sav2eav & vpifregs[config_channel_id].width_mask);
156 regw(value, vpifregs[channel_id].h_cfg);
157
158 value = (config->l1 & vpifregs[config_channel_id].len_mask);
159 value <<= VPIF_CH_LEN_SHIFT;
160 value |= (config->l3 & vpifregs[config_channel_id].len_mask);
161 regw(value, vpifregs[channel_id].v_cfg_00);
162
163 value = (config->l5 & vpifregs[config_channel_id].len_mask);
164 value <<= VPIF_CH_LEN_SHIFT;
165 value |= (config->l7 & vpifregs[config_channel_id].len_mask);
166 regw(value, vpifregs[channel_id].v_cfg_01);
167
168 value = (config->l9 & vpifregs[config_channel_id].len_mask);
169 value <<= VPIF_CH_LEN_SHIFT;
170 value |= (config->l11 & vpifregs[config_channel_id].len_mask);
171 regw(value, vpifregs[channel_id].v_cfg_02);
172
173 value = (config->vsize & vpifregs[config_channel_id].len_mask);
174 regw(value, vpifregs[channel_id].v_cfg);
175}
176
177/* config_vpif_params
178 * Function to set the parameters of a channel
179 * Mainly modifies the channel ciontrol register
180 * It sets frame format, yc mux mode
181 */
182static void config_vpif_params(struct vpif_params *vpifparams,
183 u8 channel_id, u8 found)
184{
185 const struct vpif_channel_config_params *config = &vpifparams->std_info;
186 u32 value, ch_nip, reg;
187 u8 start, end;
188 int i;
189
190 start = channel_id;
191 end = channel_id + found;
192
193 for (i = start; i < end; i++) {
194 reg = vpifregs[i].ch_ctrl;
195 if (channel_id < 2)
196 ch_nip = VPIF_CAPTURE_CH_NIP;
197 else
198 ch_nip = VPIF_DISPLAY_CH_NIP;
199
200 vpif_wr_bit(reg, ch_nip, config->frm_fmt);
201 vpif_wr_bit(reg, VPIF_CH_YC_MUX_BIT, config->ycmux_mode);
202 vpif_wr_bit(reg, VPIF_CH_INPUT_FIELD_FRAME_BIT,
203 vpifparams->video_params.storage_mode);
204
205 /* Set raster scanning SDR Format */
206 vpif_clr_bit(reg, VPIF_CH_SDR_FMT_BIT);
207 vpif_wr_bit(reg, VPIF_CH_DATA_MODE_BIT, config->capture_format);
208
209 if (channel_id > 1) /* Set the Pixel enable bit */
210 vpif_set_bit(reg, VPIF_DISPLAY_PIX_EN_BIT);
211 else if (config->capture_format) {
212 /* Set the polarity of various pins */
213 vpif_wr_bit(reg, VPIF_CH_FID_POLARITY_BIT,
Muralidharan Karicherid28a6df2009-09-16 14:31:20 -0300214 vpifparams->iface.fid_pol);
Chaithrika U S63a8e712009-06-09 05:54:02 -0300215 vpif_wr_bit(reg, VPIF_CH_V_VALID_POLARITY_BIT,
Muralidharan Karicherid28a6df2009-09-16 14:31:20 -0300216 vpifparams->iface.vd_pol);
Chaithrika U S63a8e712009-06-09 05:54:02 -0300217 vpif_wr_bit(reg, VPIF_CH_H_VALID_POLARITY_BIT,
Muralidharan Karicherid28a6df2009-09-16 14:31:20 -0300218 vpifparams->iface.hd_pol);
Chaithrika U S63a8e712009-06-09 05:54:02 -0300219
220 value = regr(reg);
221 /* Set data width */
222 value &= ((~(unsigned int)(0x3)) <<
223 VPIF_CH_DATA_WIDTH_BIT);
Muralidharan Karicherid28a6df2009-09-16 14:31:20 -0300224 value |= ((vpifparams->params.data_sz) <<
Chaithrika U S63a8e712009-06-09 05:54:02 -0300225 VPIF_CH_DATA_WIDTH_BIT);
226 regw(value, reg);
227 }
228
229 /* Write the pitch in the driver */
230 regw((vpifparams->video_params.hpitch),
231 vpifregs[i].line_offset);
232 }
233}
234
235/* vpif_set_video_params
236 * This function is used to set video parameters in VPIF register
237 */
238int vpif_set_video_params(struct vpif_params *vpifparams, u8 channel_id)
239{
240 const struct vpif_channel_config_params *config = &vpifparams->std_info;
241 int found = 1;
242
243 vpif_set_mode_info(config, channel_id, channel_id);
244 if (!config->ycmux_mode) {
245 /* YC are on separate channels (HDTV formats) */
246 vpif_set_mode_info(config, channel_id + 1, channel_id);
247 found = 2;
248 }
249
250 config_vpif_params(vpifparams, channel_id, found);
251
252 regw(0x80, VPIF_REQ_SIZE);
253 regw(0x01, VPIF_EMULATION_CTRL);
254
255 return found;
256}
257EXPORT_SYMBOL(vpif_set_video_params);
258
259void vpif_set_vbi_display_params(struct vpif_vbi_params *vbiparams,
260 u8 channel_id)
261{
262 u32 value;
263
264 value = 0x3F8 & (vbiparams->hstart0);
265 value |= 0x3FFFFFF & ((vbiparams->vstart0) << 16);
266 regw(value, vpifregs[channel_id].vanc0_strt);
267
268 value = 0x3F8 & (vbiparams->hstart1);
269 value |= 0x3FFFFFF & ((vbiparams->vstart1) << 16);
270 regw(value, vpifregs[channel_id].vanc1_strt);
271
272 value = 0x3F8 & (vbiparams->hsize0);
273 value |= 0x3FFFFFF & ((vbiparams->vsize0) << 16);
274 regw(value, vpifregs[channel_id].vanc0_size);
275
276 value = 0x3F8 & (vbiparams->hsize1);
277 value |= 0x3FFFFFF & ((vbiparams->vsize1) << 16);
278 regw(value, vpifregs[channel_id].vanc1_size);
279
280}
281EXPORT_SYMBOL(vpif_set_vbi_display_params);
282
283int vpif_channel_getfid(u8 channel_id)
284{
285 return (regr(vpifregs[channel_id].ch_ctrl) & VPIF_CH_FID_MASK)
286 >> VPIF_CH_FID_SHIFT;
287}
288EXPORT_SYMBOL(vpif_channel_getfid);
289
Muralidharan Karicherid28a6df2009-09-16 14:31:20 -0300290static int __init vpif_probe(struct platform_device *pdev)
Chaithrika U S63a8e712009-06-09 05:54:02 -0300291{
Muralidharan Karicherid28a6df2009-09-16 14:31:20 -0300292 int status = 0;
293
294 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
295 if (!res)
296 return -ENOENT;
297
298 res_len = res->end - res->start + 1;
299
300 res = request_mem_region(res->start, res_len, res->name);
301 if (!res)
302 return -EBUSY;
303
304 vpif_base = ioremap(res->start, res_len);
305 if (!vpif_base) {
306 status = -EBUSY;
307 goto fail;
308 }
309
310 spin_lock_init(&vpif_lock);
311 dev_info(&pdev->dev, "vpif probe success\n");
312 return 0;
313
314fail:
315 release_mem_region(res->start, res_len);
316 return status;
Chaithrika U S63a8e712009-06-09 05:54:02 -0300317}
Muralidharan Karicherid28a6df2009-09-16 14:31:20 -0300318
Uwe Kleine-König0b0a8602009-12-10 17:02:16 -0300319static int __devexit vpif_remove(struct platform_device *pdev)
Muralidharan Karicherid28a6df2009-09-16 14:31:20 -0300320{
321 iounmap(vpif_base);
322 release_mem_region(res->start, res_len);
323 return 0;
324}
325
326static struct platform_driver vpif_driver = {
327 .driver = {
328 .name = "vpif",
329 .owner = THIS_MODULE,
330 },
331 .remove = __devexit_p(vpif_remove),
332 .probe = vpif_probe,
333};
334
335static void vpif_exit(void)
336{
337 platform_driver_unregister(&vpif_driver);
338}
339
340static int __init vpif_init(void)
341{
342 return platform_driver_register(&vpif_driver);
343}
344subsys_initcall(vpif_init);
345module_exit(vpif_exit);
346