2013-06-04 18:22:30 +04:00
/*
* vsp1_wpf . c - - R - Car VSP1 Write Pixel Formatter
*
2014-02-06 21:42:31 +04:00
* Copyright ( C ) 2013 - 2014 Renesas Electronics Corporation
2013-06-04 18:22:30 +04:00
*
* Contact : Laurent Pinchart ( laurent . pinchart @ ideasonboard . com )
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*/
# include <linux/device.h>
# include <media/v4l2-subdev.h>
# include "vsp1.h"
2015-11-15 03:27:52 +03:00
# include "vsp1_dl.h"
2013-06-04 18:22:30 +04:00
# include "vsp1_rwpf.h"
# include "vsp1_video.h"
# define WPF_MAX_WIDTH 2048
# define WPF_MAX_HEIGHT 2048
/* -----------------------------------------------------------------------------
* Device Access
*/
static inline void vsp1_wpf_write ( struct vsp1_rwpf * wpf , u32 reg , u32 data )
{
2015-09-07 07:40:25 +03:00
vsp1_mod_write ( & wpf - > entity ,
reg + wpf - > entity . index * VI6_WPF_OFFSET , data ) ;
2013-06-04 18:22:30 +04:00
}
/* -----------------------------------------------------------------------------
* V4L2 Subdevice Core Operations
*/
static int wpf_s_stream ( struct v4l2_subdev * subdev , int enable )
{
2014-05-28 03:35:36 +04:00
struct vsp1_pipeline * pipe = to_vsp1_pipeline ( & subdev - > entity ) ;
2013-06-04 18:22:30 +04:00
struct vsp1_rwpf * wpf = to_rwpf ( subdev ) ;
struct vsp1_device * vsp1 = wpf - > entity . vsp1 ;
2013-08-25 03:49:58 +04:00
const struct v4l2_rect * crop = & wpf - > crop ;
2013-06-04 18:22:30 +04:00
unsigned int i ;
u32 srcrpf = 0 ;
u32 outfmt = 0 ;
2014-05-22 02:00:05 +04:00
2013-06-04 18:22:30 +04:00
if ( ! enable ) {
vsp1_write ( vsp1 , VI6_WPF_IRQ_ENB ( wpf - > entity . index ) , 0 ) ;
2015-09-07 07:40:25 +03:00
vsp1_write ( vsp1 , wpf - > entity . index * VI6_WPF_OFFSET +
VI6_WPF_SRCRPF , 0 ) ;
2013-06-04 18:22:30 +04:00
return 0 ;
}
2014-11-27 04:25:02 +03:00
/* Sources. If the pipeline has a single input and BRU is not used,
* configure it as the master layer . Otherwise configure all
* inputs as sub - layers and select the virtual RPF as the master
* layer .
2013-07-11 01:03:46 +04:00
*/
2015-12-06 01:17:10 +03:00
for ( i = 0 ; i < vsp1 - > info - > rpf_count ; + + i ) {
2013-06-04 18:22:30 +04:00
struct vsp1_rwpf * input = pipe - > inputs [ i ] ;
2015-08-05 22:40:31 +03:00
if ( ! input )
continue ;
2014-11-27 04:25:02 +03:00
srcrpf | = ( ! pipe - > bru & & pipe - > num_inputs = = 1 )
2013-07-11 01:03:46 +04:00
? VI6_WPF_SRCRPF_RPF_ACT_MST ( input - > entity . index )
: VI6_WPF_SRCRPF_RPF_ACT_SUB ( input - > entity . index ) ;
2013-06-04 18:22:30 +04:00
}
2014-11-27 04:25:02 +03:00
if ( pipe - > bru | | pipe - > num_inputs > 1 )
2013-07-11 01:03:46 +04:00
srcrpf | = VI6_WPF_SRCRPF_VIRACT_MST ;
2013-06-04 18:22:30 +04:00
vsp1_wpf_write ( wpf , VI6_WPF_SRCRPF , srcrpf ) ;
2013-08-25 03:49:58 +04:00
/* Destination stride. */
2013-06-04 18:22:30 +04:00
if ( ! pipe - > lif ) {
2015-07-28 20:00:43 +03:00
struct v4l2_pix_format_mplane * format = & wpf - > format ;
2013-06-04 18:22:30 +04:00
vsp1_wpf_write ( wpf , VI6_WPF_DSTM_STRIDE_Y ,
format - > plane_fmt [ 0 ] . bytesperline ) ;
if ( format - > num_planes > 1 )
vsp1_wpf_write ( wpf , VI6_WPF_DSTM_STRIDE_C ,
format - > plane_fmt [ 1 ] . bytesperline ) ;
}
2013-08-25 03:49:58 +04:00
vsp1_wpf_write ( wpf , VI6_WPF_HSZCLIP , VI6_WPF_SZCLIP_EN |
( crop - > left < < VI6_WPF_SZCLIP_OFST_SHIFT ) |
( crop - > width < < VI6_WPF_SZCLIP_SIZE_SHIFT ) ) ;
vsp1_wpf_write ( wpf , VI6_WPF_VSZCLIP , VI6_WPF_SZCLIP_EN |
( crop - > top < < VI6_WPF_SZCLIP_OFST_SHIFT ) |
( crop - > height < < VI6_WPF_SZCLIP_SIZE_SHIFT ) ) ;
2013-06-04 18:22:30 +04:00
/* Format */
if ( ! pipe - > lif ) {
2015-07-28 20:00:43 +03:00
const struct vsp1_format_info * fmtinfo = wpf - > fmtinfo ;
2013-06-04 18:22:30 +04:00
outfmt = fmtinfo - > hwfmt < < VI6_WPF_OUTFMT_WRFMT_SHIFT ;
2014-05-27 03:12:53 +04:00
if ( fmtinfo - > alpha )
outfmt | = VI6_WPF_OUTFMT_PXA ;
2013-06-04 18:22:30 +04:00
if ( fmtinfo - > swap_yc )
outfmt | = VI6_WPF_OUTFMT_SPYCS ;
if ( fmtinfo - > swap_uv )
outfmt | = VI6_WPF_OUTFMT_SPUVS ;
vsp1_wpf_write ( wpf , VI6_WPF_DSWAP , fmtinfo - > swap ) ;
}
if ( wpf - > entity . formats [ RWPF_PAD_SINK ] . code ! =
wpf - > entity . formats [ RWPF_PAD_SOURCE ] . code )
outfmt | = VI6_WPF_OUTFMT_CSC ;
2015-11-01 17:19:42 +03:00
outfmt | = wpf - > alpha < < VI6_WPF_OUTFMT_PDV_SHIFT ;
2013-06-04 18:22:30 +04:00
vsp1_wpf_write ( wpf , VI6_WPF_OUTFMT , outfmt ) ;
2015-09-07 07:40:25 +03:00
vsp1_mod_write ( & wpf - > entity , VI6_DPR_WPF_FPORCH ( wpf - > entity . index ) ,
VI6_DPR_WPF_FPORCH_FP_WPFN ) ;
2013-06-04 18:22:30 +04:00
2015-09-07 07:40:25 +03:00
vsp1_mod_write ( & wpf - > entity , VI6_WPF_WRBCK_CTRL , 0 ) ;
2013-06-04 18:22:30 +04:00
/* Enable interrupts */
vsp1_write ( vsp1 , VI6_WPF_IRQ_STA ( wpf - > entity . index ) , 0 ) ;
vsp1_write ( vsp1 , VI6_WPF_IRQ_ENB ( wpf - > entity . index ) ,
VI6_WFP_IRQ_ENB_FREE ) ;
return 0 ;
}
/* -----------------------------------------------------------------------------
* V4L2 Subdevice Operations
*/
static struct v4l2_subdev_video_ops wpf_video_ops = {
. s_stream = wpf_s_stream ,
} ;
static struct v4l2_subdev_pad_ops wpf_pad_ops = {
. enum_mbus_code = vsp1_rwpf_enum_mbus_code ,
. enum_frame_size = vsp1_rwpf_enum_frame_size ,
. get_fmt = vsp1_rwpf_get_format ,
. set_fmt = vsp1_rwpf_set_format ,
2013-08-25 03:49:58 +04:00
. get_selection = vsp1_rwpf_get_selection ,
. set_selection = vsp1_rwpf_set_selection ,
2013-06-04 18:22:30 +04:00
} ;
static struct v4l2_subdev_ops wpf_ops = {
. video = & wpf_video_ops ,
. pad = & wpf_pad_ops ,
} ;
/* -----------------------------------------------------------------------------
* Video Device Operations
*/
2015-11-01 18:48:11 +03:00
static void wpf_set_memory ( struct vsp1_rwpf * wpf )
2013-06-04 18:22:30 +04:00
{
2015-11-01 18:48:11 +03:00
vsp1_wpf_write ( wpf , VI6_WPF_DSTM_ADDR_Y , wpf - > buf_addr [ 0 ] ) ;
vsp1_wpf_write ( wpf , VI6_WPF_DSTM_ADDR_C0 , wpf - > buf_addr [ 1 ] ) ;
vsp1_wpf_write ( wpf , VI6_WPF_DSTM_ADDR_C1 , wpf - > buf_addr [ 2 ] ) ;
2013-06-04 18:22:30 +04:00
}
2015-07-28 20:05:56 +03:00
static const struct vsp1_rwpf_operations wpf_vdev_ops = {
2015-07-28 22:04:47 +03:00
. set_memory = wpf_set_memory ,
2013-06-04 18:22:30 +04:00
} ;
/* -----------------------------------------------------------------------------
* Initialization and Cleanup
*/
2015-11-15 03:27:52 +03:00
static void vsp1_wpf_destroy ( struct vsp1_entity * entity )
{
struct vsp1_rwpf * wpf = container_of ( entity , struct vsp1_rwpf , entity ) ;
vsp1_dlm_destroy ( wpf - > dlm ) ;
}
2013-06-04 18:22:30 +04:00
struct vsp1_rwpf * vsp1_wpf_create ( struct vsp1_device * vsp1 , unsigned int index )
{
struct v4l2_subdev * subdev ;
struct vsp1_rwpf * wpf ;
int ret ;
wpf = devm_kzalloc ( vsp1 - > dev , sizeof ( * wpf ) , GFP_KERNEL ) ;
if ( wpf = = NULL )
return ERR_PTR ( - ENOMEM ) ;
2015-07-28 20:05:56 +03:00
wpf - > ops = & wpf_vdev_ops ;
2013-06-04 18:22:30 +04:00
wpf - > max_width = WPF_MAX_WIDTH ;
wpf - > max_height = WPF_MAX_HEIGHT ;
2015-11-15 03:27:52 +03:00
wpf - > entity . destroy = vsp1_wpf_destroy ;
2013-06-04 18:22:30 +04:00
wpf - > entity . type = VSP1_ENTITY_WPF ;
wpf - > entity . index = index ;
ret = vsp1_entity_init ( vsp1 , & wpf - > entity , 2 ) ;
if ( ret < 0 )
return ERR_PTR ( ret ) ;
2015-11-15 03:27:52 +03:00
/* Initialize the display list manager if the WPF is used for display */
if ( ( vsp1 - > info - > features & VSP1_HAS_LIF ) & & index = = 0 ) {
2015-11-15 03:48:27 +03:00
wpf - > dlm = vsp1_dlm_create ( vsp1 , index , 4 ) ;
2015-11-15 03:27:52 +03:00
if ( ! wpf - > dlm ) {
ret = - ENOMEM ;
goto error ;
}
}
2013-06-04 18:22:30 +04:00
/* Initialize the V4L2 subdev. */
subdev = & wpf - > entity . subdev ;
v4l2_subdev_init ( subdev , & wpf_ops ) ;
2015-08-05 23:14:41 +03:00
subdev - > entity . ops = & vsp1 - > media_ops ;
2013-06-04 18:22:30 +04:00
subdev - > internal_ops = & vsp1_subdev_internal_ops ;
snprintf ( subdev - > name , sizeof ( subdev - > name ) , " %s wpf.%u " ,
dev_name ( vsp1 - > dev ) , index ) ;
v4l2_set_subdevdata ( subdev , wpf ) ;
subdev - > flags | = V4L2_SUBDEV_FL_HAS_DEVNODE ;
vsp1_entity_init_formats ( subdev , NULL ) ;
2014-05-22 02:00:05 +04:00
/* Initialize the control handler. */
2015-11-01 17:19:42 +03:00
ret = vsp1_rwpf_init_ctrls ( wpf ) ;
if ( ret < 0 ) {
2014-05-22 02:00:05 +04:00
dev_err ( vsp1 - > dev , " wpf%u: failed to initialize controls \n " ,
index ) ;
goto error ;
}
2013-06-04 18:22:30 +04:00
return wpf ;
2014-05-28 19:49:13 +04:00
error :
vsp1_entity_destroy ( & wpf - > entity ) ;
2013-06-04 18:22:30 +04:00
return ERR_PTR ( ret ) ;
}