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/err.h>
21 #include <linux/init.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/pm_runtime.h>
27 #include <linux/spinlock.h>
28 #include <linux/v4l2-dv-timings.h>
32 MODULE_DESCRIPTION("TI DaVinci Video Port Interface driver");
33 MODULE_LICENSE("GPL");
35 #define VPIF_CH0_MAX_MODES 22
36 #define VPIF_CH1_MAX_MODES 2
37 #define VPIF_CH2_MAX_MODES 15
38 #define VPIF_CH3_MAX_MODES 2
41 EXPORT_SYMBOL_GPL(vpif_lock
);
43 void __iomem
*vpif_base
;
44 EXPORT_SYMBOL_GPL(vpif_base
);
47 * vpif_ch_params: video standard configuration parameters for vpif
48 * The table must include all presets from supported subdevices.
50 const struct vpif_channel_config_params vpif_ch_params
[] = {
67 .dv_timings
= V4L2_DV_BT_CEA_720X480P59_94
,
84 .dv_timings
= V4L2_DV_BT_CEA_720X576P50
,
101 .dv_timings
= V4L2_DV_BT_CEA_1280X720P50
,
118 .dv_timings
= V4L2_DV_BT_CEA_1280X720P60
,
138 .dv_timings
= V4L2_DV_BT_CEA_1920X1080I50
,
158 .dv_timings
= V4L2_DV_BT_CEA_1920X1080I60
,
175 .dv_timings
= V4L2_DV_BT_CEA_1920X1080P60
,
197 .stdid
= V4L2_STD_525_60
,
200 .name
= "PAL_BDGHIK",
217 .stdid
= V4L2_STD_625_50
,
220 EXPORT_SYMBOL_GPL(vpif_ch_params
);
222 const unsigned int vpif_ch_params_count
= ARRAY_SIZE(vpif_ch_params
);
223 EXPORT_SYMBOL_GPL(vpif_ch_params_count
);
225 static inline void vpif_wr_bit(u32 reg
, u32 bit
, u32 val
)
228 vpif_set_bit(reg
, bit
);
230 vpif_clr_bit(reg
, bit
);
233 /* This structure is used to keep track of VPIF size register's offsets */
234 struct vpif_registers
{
235 u32 h_cfg
, v_cfg_00
, v_cfg_01
, v_cfg_02
, v_cfg
, ch_ctrl
;
236 u32 line_offset
, vanc0_strt
, vanc0_size
, vanc1_strt
;
237 u32 vanc1_size
, width_mask
, len_mask
;
241 static const struct vpif_registers vpifregs
[VPIF_NUM_CHANNELS
] = {
244 VPIF_CH0_H_CFG
, VPIF_CH0_V_CFG_00
, VPIF_CH0_V_CFG_01
,
245 VPIF_CH0_V_CFG_02
, VPIF_CH0_V_CFG_03
, VPIF_CH0_CTRL
,
246 VPIF_CH0_IMG_ADD_OFST
, 0, 0, 0, 0, 0x1FFF, 0xFFF,
251 VPIF_CH1_H_CFG
, VPIF_CH1_V_CFG_00
, VPIF_CH1_V_CFG_01
,
252 VPIF_CH1_V_CFG_02
, VPIF_CH1_V_CFG_03
, VPIF_CH1_CTRL
,
253 VPIF_CH1_IMG_ADD_OFST
, 0, 0, 0, 0, 0x1FFF, 0xFFF,
258 VPIF_CH2_H_CFG
, VPIF_CH2_V_CFG_00
, VPIF_CH2_V_CFG_01
,
259 VPIF_CH2_V_CFG_02
, VPIF_CH2_V_CFG_03
, VPIF_CH2_CTRL
,
260 VPIF_CH2_IMG_ADD_OFST
, VPIF_CH2_VANC0_STRT
, VPIF_CH2_VANC0_SIZE
,
261 VPIF_CH2_VANC1_STRT
, VPIF_CH2_VANC1_SIZE
, 0x7FF, 0x7FF,
266 VPIF_CH3_H_CFG
, VPIF_CH3_V_CFG_00
, VPIF_CH3_V_CFG_01
,
267 VPIF_CH3_V_CFG_02
, VPIF_CH3_V_CFG_03
, VPIF_CH3_CTRL
,
268 VPIF_CH3_IMG_ADD_OFST
, VPIF_CH3_VANC0_STRT
, VPIF_CH3_VANC0_SIZE
,
269 VPIF_CH3_VANC1_STRT
, VPIF_CH3_VANC1_SIZE
, 0x7FF, 0x7FF,
274 /* vpif_set_mode_info:
275 * This function is used to set horizontal and vertical config parameters
276 * As per the standard in the channel, configure the values of L1, L3,
277 * L5, L7 L9, L11 in VPIF Register , also write width and height
279 static void vpif_set_mode_info(const struct vpif_channel_config_params
*config
,
280 u8 channel_id
, u8 config_channel_id
)
284 value
= (config
->eav2sav
& vpifregs
[config_channel_id
].width_mask
);
285 value
<<= VPIF_CH_LEN_SHIFT
;
286 value
|= (config
->sav2eav
& vpifregs
[config_channel_id
].width_mask
);
287 regw(value
, vpifregs
[channel_id
].h_cfg
);
289 value
= (config
->l1
& vpifregs
[config_channel_id
].len_mask
);
290 value
<<= VPIF_CH_LEN_SHIFT
;
291 value
|= (config
->l3
& vpifregs
[config_channel_id
].len_mask
);
292 regw(value
, vpifregs
[channel_id
].v_cfg_00
);
294 value
= (config
->l5
& vpifregs
[config_channel_id
].len_mask
);
295 value
<<= VPIF_CH_LEN_SHIFT
;
296 value
|= (config
->l7
& vpifregs
[config_channel_id
].len_mask
);
297 regw(value
, vpifregs
[channel_id
].v_cfg_01
);
299 value
= (config
->l9
& vpifregs
[config_channel_id
].len_mask
);
300 value
<<= VPIF_CH_LEN_SHIFT
;
301 value
|= (config
->l11
& vpifregs
[config_channel_id
].len_mask
);
302 regw(value
, vpifregs
[channel_id
].v_cfg_02
);
304 value
= (config
->vsize
& vpifregs
[config_channel_id
].len_mask
);
305 regw(value
, vpifregs
[channel_id
].v_cfg
);
308 /* config_vpif_params
309 * Function to set the parameters of a channel
310 * Mainly modifies the channel ciontrol register
311 * It sets frame format, yc mux mode
313 static void config_vpif_params(struct vpif_params
*vpifparams
,
314 u8 channel_id
, u8 found
)
316 const struct vpif_channel_config_params
*config
= &vpifparams
->std_info
;
317 u32 value
, ch_nip
, reg
;
322 end
= channel_id
+ found
;
324 for (i
= start
; i
< end
; i
++) {
325 reg
= vpifregs
[i
].ch_ctrl
;
327 ch_nip
= VPIF_CAPTURE_CH_NIP
;
329 ch_nip
= VPIF_DISPLAY_CH_NIP
;
331 vpif_wr_bit(reg
, ch_nip
, config
->frm_fmt
);
332 vpif_wr_bit(reg
, VPIF_CH_YC_MUX_BIT
, config
->ycmux_mode
);
333 vpif_wr_bit(reg
, VPIF_CH_INPUT_FIELD_FRAME_BIT
,
334 vpifparams
->video_params
.storage_mode
);
336 /* Set raster scanning SDR Format */
337 vpif_clr_bit(reg
, VPIF_CH_SDR_FMT_BIT
);
338 vpif_wr_bit(reg
, VPIF_CH_DATA_MODE_BIT
, config
->capture_format
);
340 if (channel_id
> 1) /* Set the Pixel enable bit */
341 vpif_set_bit(reg
, VPIF_DISPLAY_PIX_EN_BIT
);
342 else if (config
->capture_format
) {
343 /* Set the polarity of various pins */
344 vpif_wr_bit(reg
, VPIF_CH_FID_POLARITY_BIT
,
345 vpifparams
->iface
.fid_pol
);
346 vpif_wr_bit(reg
, VPIF_CH_V_VALID_POLARITY_BIT
,
347 vpifparams
->iface
.vd_pol
);
348 vpif_wr_bit(reg
, VPIF_CH_H_VALID_POLARITY_BIT
,
349 vpifparams
->iface
.hd_pol
);
354 VPIF_CH_DATA_WIDTH_BIT
);
355 value
|= ((vpifparams
->params
.data_sz
) <<
356 VPIF_CH_DATA_WIDTH_BIT
);
360 /* Write the pitch in the driver */
361 regw((vpifparams
->video_params
.hpitch
),
362 vpifregs
[i
].line_offset
);
366 /* vpif_set_video_params
367 * This function is used to set video parameters in VPIF register
369 int vpif_set_video_params(struct vpif_params
*vpifparams
, u8 channel_id
)
371 const struct vpif_channel_config_params
*config
= &vpifparams
->std_info
;
374 vpif_set_mode_info(config
, channel_id
, channel_id
);
375 if (!config
->ycmux_mode
) {
376 /* YC are on separate channels (HDTV formats) */
377 vpif_set_mode_info(config
, channel_id
+ 1, channel_id
);
381 config_vpif_params(vpifparams
, channel_id
, found
);
383 regw(0x80, VPIF_REQ_SIZE
);
384 regw(0x01, VPIF_EMULATION_CTRL
);
388 EXPORT_SYMBOL(vpif_set_video_params
);
390 void vpif_set_vbi_display_params(struct vpif_vbi_params
*vbiparams
,
395 value
= 0x3F8 & (vbiparams
->hstart0
);
396 value
|= 0x3FFFFFF & ((vbiparams
->vstart0
) << 16);
397 regw(value
, vpifregs
[channel_id
].vanc0_strt
);
399 value
= 0x3F8 & (vbiparams
->hstart1
);
400 value
|= 0x3FFFFFF & ((vbiparams
->vstart1
) << 16);
401 regw(value
, vpifregs
[channel_id
].vanc1_strt
);
403 value
= 0x3F8 & (vbiparams
->hsize0
);
404 value
|= 0x3FFFFFF & ((vbiparams
->vsize0
) << 16);
405 regw(value
, vpifregs
[channel_id
].vanc0_size
);
407 value
= 0x3F8 & (vbiparams
->hsize1
);
408 value
|= 0x3FFFFFF & ((vbiparams
->vsize1
) << 16);
409 regw(value
, vpifregs
[channel_id
].vanc1_size
);
412 EXPORT_SYMBOL(vpif_set_vbi_display_params
);
414 int vpif_channel_getfid(u8 channel_id
)
416 return (regr(vpifregs
[channel_id
].ch_ctrl
) & VPIF_CH_FID_MASK
)
417 >> VPIF_CH_FID_SHIFT
;
419 EXPORT_SYMBOL(vpif_channel_getfid
);
421 static int vpif_probe(struct platform_device
*pdev
)
423 static struct resource
*res
;
425 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
426 vpif_base
= devm_ioremap_resource(&pdev
->dev
, res
);
427 if (IS_ERR(vpif_base
))
428 return PTR_ERR(vpif_base
);
430 pm_runtime_enable(&pdev
->dev
);
431 pm_runtime_get(&pdev
->dev
);
433 spin_lock_init(&vpif_lock
);
434 dev_info(&pdev
->dev
, "vpif probe success\n");
438 static int vpif_remove(struct platform_device
*pdev
)
440 pm_runtime_disable(&pdev
->dev
);
445 static int vpif_suspend(struct device
*dev
)
451 static int vpif_resume(struct device
*dev
)
457 static const struct dev_pm_ops vpif_pm
= {
458 .suspend
= vpif_suspend
,
459 .resume
= vpif_resume
,
462 #define vpif_pm_ops (&vpif_pm)
464 #define vpif_pm_ops NULL
467 static struct platform_driver vpif_driver
= {
472 .remove
= vpif_remove
,
476 static void vpif_exit(void)
478 platform_driver_unregister(&vpif_driver
);
481 static int __init
vpif_init(void)
483 return platform_driver_register(&vpif_driver
);
485 subsys_initcall(vpif_init
);
486 module_exit(vpif_exit
);