2 * vpif - 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.
8 * Copyright (C) 2009 Texas Instruments Incorporated - http://www.ti.com/
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.
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.
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/platform_device.h>
23 #include <linux/spinlock.h>
24 #include <linux/kernel.h>
26 #include <linux/err.h>
27 #include <linux/pm_runtime.h>
28 #include <linux/v4l2-dv-timings.h>
30 #include <mach/hardware.h>
34 MODULE_DESCRIPTION("TI DaVinci Video Port Interface driver");
35 MODULE_LICENSE("GPL");
37 #define VPIF_CH0_MAX_MODES (22)
38 #define VPIF_CH1_MAX_MODES (02)
39 #define VPIF_CH2_MAX_MODES (15)
40 #define VPIF_CH3_MAX_MODES (02)
42 static resource_size_t res_len
;
43 static struct resource
*res
;
46 void __iomem
*vpif_base
;
47 EXPORT_SYMBOL_GPL(vpif_base
);
50 * vpif_ch_params: video standard configuration parameters for vpif
51 * The table must include all presets from supported subdevices.
53 const struct vpif_channel_config_params vpif_ch_params
[] = {
70 .dv_timings
= V4L2_DV_BT_CEA_720X480P59_94
,
87 .dv_timings
= V4L2_DV_BT_CEA_720X576P50
,
104 .dv_timings
= V4L2_DV_BT_CEA_1280X720P50
,
121 .dv_timings
= V4L2_DV_BT_CEA_1280X720P60
,
141 .dv_timings
= V4L2_DV_BT_CEA_1920X1080I50
,
161 .dv_timings
= V4L2_DV_BT_CEA_1920X1080I60
,
178 .dv_timings
= V4L2_DV_BT_CEA_1920X1080P60
,
200 .stdid
= V4L2_STD_525_60
,
203 .name
= "PAL_BDGHIK",
220 .stdid
= V4L2_STD_625_50
,
223 EXPORT_SYMBOL_GPL(vpif_ch_params
);
225 const unsigned int vpif_ch_params_count
= ARRAY_SIZE(vpif_ch_params
);
226 EXPORT_SYMBOL_GPL(vpif_ch_params_count
);
228 static inline void vpif_wr_bit(u32 reg
, u32 bit
, u32 val
)
231 vpif_set_bit(reg
, bit
);
233 vpif_clr_bit(reg
, bit
);
236 /* This structure is used to keep track of VPIF size register's offsets */
237 struct vpif_registers
{
238 u32 h_cfg
, v_cfg_00
, v_cfg_01
, v_cfg_02
, v_cfg
, ch_ctrl
;
239 u32 line_offset
, vanc0_strt
, vanc0_size
, vanc1_strt
;
240 u32 vanc1_size
, width_mask
, len_mask
;
244 static const struct vpif_registers vpifregs
[VPIF_NUM_CHANNELS
] = {
247 VPIF_CH0_H_CFG
, VPIF_CH0_V_CFG_00
, VPIF_CH0_V_CFG_01
,
248 VPIF_CH0_V_CFG_02
, VPIF_CH0_V_CFG_03
, VPIF_CH0_CTRL
,
249 VPIF_CH0_IMG_ADD_OFST
, 0, 0, 0, 0, 0x1FFF, 0xFFF,
254 VPIF_CH1_H_CFG
, VPIF_CH1_V_CFG_00
, VPIF_CH1_V_CFG_01
,
255 VPIF_CH1_V_CFG_02
, VPIF_CH1_V_CFG_03
, VPIF_CH1_CTRL
,
256 VPIF_CH1_IMG_ADD_OFST
, 0, 0, 0, 0, 0x1FFF, 0xFFF,
261 VPIF_CH2_H_CFG
, VPIF_CH2_V_CFG_00
, VPIF_CH2_V_CFG_01
,
262 VPIF_CH2_V_CFG_02
, VPIF_CH2_V_CFG_03
, VPIF_CH2_CTRL
,
263 VPIF_CH2_IMG_ADD_OFST
, VPIF_CH2_VANC0_STRT
, VPIF_CH2_VANC0_SIZE
,
264 VPIF_CH2_VANC1_STRT
, VPIF_CH2_VANC1_SIZE
, 0x7FF, 0x7FF,
269 VPIF_CH3_H_CFG
, VPIF_CH3_V_CFG_00
, VPIF_CH3_V_CFG_01
,
270 VPIF_CH3_V_CFG_02
, VPIF_CH3_V_CFG_03
, VPIF_CH3_CTRL
,
271 VPIF_CH3_IMG_ADD_OFST
, VPIF_CH3_VANC0_STRT
, VPIF_CH3_VANC0_SIZE
,
272 VPIF_CH3_VANC1_STRT
, VPIF_CH3_VANC1_SIZE
, 0x7FF, 0x7FF,
277 /* vpif_set_mode_info:
278 * This function is used to set horizontal and vertical config parameters
279 * As per the standard in the channel, configure the values of L1, L3,
280 * L5, L7 L9, L11 in VPIF Register , also write width and height
282 static void vpif_set_mode_info(const struct vpif_channel_config_params
*config
,
283 u8 channel_id
, u8 config_channel_id
)
287 value
= (config
->eav2sav
& vpifregs
[config_channel_id
].width_mask
);
288 value
<<= VPIF_CH_LEN_SHIFT
;
289 value
|= (config
->sav2eav
& vpifregs
[config_channel_id
].width_mask
);
290 regw(value
, vpifregs
[channel_id
].h_cfg
);
292 value
= (config
->l1
& vpifregs
[config_channel_id
].len_mask
);
293 value
<<= VPIF_CH_LEN_SHIFT
;
294 value
|= (config
->l3
& vpifregs
[config_channel_id
].len_mask
);
295 regw(value
, vpifregs
[channel_id
].v_cfg_00
);
297 value
= (config
->l5
& vpifregs
[config_channel_id
].len_mask
);
298 value
<<= VPIF_CH_LEN_SHIFT
;
299 value
|= (config
->l7
& vpifregs
[config_channel_id
].len_mask
);
300 regw(value
, vpifregs
[channel_id
].v_cfg_01
);
302 value
= (config
->l9
& vpifregs
[config_channel_id
].len_mask
);
303 value
<<= VPIF_CH_LEN_SHIFT
;
304 value
|= (config
->l11
& vpifregs
[config_channel_id
].len_mask
);
305 regw(value
, vpifregs
[channel_id
].v_cfg_02
);
307 value
= (config
->vsize
& vpifregs
[config_channel_id
].len_mask
);
308 regw(value
, vpifregs
[channel_id
].v_cfg
);
311 /* config_vpif_params
312 * Function to set the parameters of a channel
313 * Mainly modifies the channel ciontrol register
314 * It sets frame format, yc mux mode
316 static void config_vpif_params(struct vpif_params
*vpifparams
,
317 u8 channel_id
, u8 found
)
319 const struct vpif_channel_config_params
*config
= &vpifparams
->std_info
;
320 u32 value
, ch_nip
, reg
;
325 end
= channel_id
+ found
;
327 for (i
= start
; i
< end
; i
++) {
328 reg
= vpifregs
[i
].ch_ctrl
;
330 ch_nip
= VPIF_CAPTURE_CH_NIP
;
332 ch_nip
= VPIF_DISPLAY_CH_NIP
;
334 vpif_wr_bit(reg
, ch_nip
, config
->frm_fmt
);
335 vpif_wr_bit(reg
, VPIF_CH_YC_MUX_BIT
, config
->ycmux_mode
);
336 vpif_wr_bit(reg
, VPIF_CH_INPUT_FIELD_FRAME_BIT
,
337 vpifparams
->video_params
.storage_mode
);
339 /* Set raster scanning SDR Format */
340 vpif_clr_bit(reg
, VPIF_CH_SDR_FMT_BIT
);
341 vpif_wr_bit(reg
, VPIF_CH_DATA_MODE_BIT
, config
->capture_format
);
343 if (channel_id
> 1) /* Set the Pixel enable bit */
344 vpif_set_bit(reg
, VPIF_DISPLAY_PIX_EN_BIT
);
345 else if (config
->capture_format
) {
346 /* Set the polarity of various pins */
347 vpif_wr_bit(reg
, VPIF_CH_FID_POLARITY_BIT
,
348 vpifparams
->iface
.fid_pol
);
349 vpif_wr_bit(reg
, VPIF_CH_V_VALID_POLARITY_BIT
,
350 vpifparams
->iface
.vd_pol
);
351 vpif_wr_bit(reg
, VPIF_CH_H_VALID_POLARITY_BIT
,
352 vpifparams
->iface
.hd_pol
);
357 VPIF_CH_DATA_WIDTH_BIT
);
358 value
|= ((vpifparams
->params
.data_sz
) <<
359 VPIF_CH_DATA_WIDTH_BIT
);
363 /* Write the pitch in the driver */
364 regw((vpifparams
->video_params
.hpitch
),
365 vpifregs
[i
].line_offset
);
369 /* vpif_set_video_params
370 * This function is used to set video parameters in VPIF register
372 int vpif_set_video_params(struct vpif_params
*vpifparams
, u8 channel_id
)
374 const struct vpif_channel_config_params
*config
= &vpifparams
->std_info
;
377 vpif_set_mode_info(config
, channel_id
, channel_id
);
378 if (!config
->ycmux_mode
) {
379 /* YC are on separate channels (HDTV formats) */
380 vpif_set_mode_info(config
, channel_id
+ 1, channel_id
);
384 config_vpif_params(vpifparams
, channel_id
, found
);
386 regw(0x80, VPIF_REQ_SIZE
);
387 regw(0x01, VPIF_EMULATION_CTRL
);
391 EXPORT_SYMBOL(vpif_set_video_params
);
393 void vpif_set_vbi_display_params(struct vpif_vbi_params
*vbiparams
,
398 value
= 0x3F8 & (vbiparams
->hstart0
);
399 value
|= 0x3FFFFFF & ((vbiparams
->vstart0
) << 16);
400 regw(value
, vpifregs
[channel_id
].vanc0_strt
);
402 value
= 0x3F8 & (vbiparams
->hstart1
);
403 value
|= 0x3FFFFFF & ((vbiparams
->vstart1
) << 16);
404 regw(value
, vpifregs
[channel_id
].vanc1_strt
);
406 value
= 0x3F8 & (vbiparams
->hsize0
);
407 value
|= 0x3FFFFFF & ((vbiparams
->vsize0
) << 16);
408 regw(value
, vpifregs
[channel_id
].vanc0_size
);
410 value
= 0x3F8 & (vbiparams
->hsize1
);
411 value
|= 0x3FFFFFF & ((vbiparams
->vsize1
) << 16);
412 regw(value
, vpifregs
[channel_id
].vanc1_size
);
415 EXPORT_SYMBOL(vpif_set_vbi_display_params
);
417 int vpif_channel_getfid(u8 channel_id
)
419 return (regr(vpifregs
[channel_id
].ch_ctrl
) & VPIF_CH_FID_MASK
)
420 >> VPIF_CH_FID_SHIFT
;
422 EXPORT_SYMBOL(vpif_channel_getfid
);
424 static int vpif_probe(struct platform_device
*pdev
)
428 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
432 res_len
= resource_size(res
);
434 res
= request_mem_region(res
->start
, res_len
, res
->name
);
438 vpif_base
= ioremap(res
->start
, res_len
);
444 pm_runtime_enable(&pdev
->dev
);
445 pm_runtime_get(&pdev
->dev
);
447 spin_lock_init(&vpif_lock
);
448 dev_info(&pdev
->dev
, "vpif probe success\n");
452 release_mem_region(res
->start
, res_len
);
456 static int vpif_remove(struct platform_device
*pdev
)
458 pm_runtime_disable(&pdev
->dev
);
460 release_mem_region(res
->start
, res_len
);
465 static int vpif_suspend(struct device
*dev
)
471 static int vpif_resume(struct device
*dev
)
477 static const struct dev_pm_ops vpif_pm
= {
478 .suspend
= vpif_suspend
,
479 .resume
= vpif_resume
,
482 #define vpif_pm_ops (&vpif_pm)
484 #define vpif_pm_ops NULL
487 static struct platform_driver vpif_driver
= {
490 .owner
= THIS_MODULE
,
493 .remove
= vpif_remove
,
497 static void vpif_exit(void)
499 platform_driver_unregister(&vpif_driver
);
502 static int __init
vpif_init(void)
504 return platform_driver_register(&vpif_driver
);
506 subsys_initcall(vpif_init
);
507 module_exit(vpif_exit
);