2 * vsp1_wpf.c -- R-Car VSP1 Write Pixel Formatter
4 * Copyright (C) 2013-2014 Renesas Electronics Corporation
6 * Contact: Laurent Pinchart (laurent.pinchart@ideasonboard.com)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/device.h>
16 #include <media/v4l2-subdev.h>
20 #include "vsp1_rwpf.h"
21 #include "vsp1_video.h"
23 #define WPF_MAX_WIDTH 2048
24 #define WPF_MAX_HEIGHT 2048
26 /* -----------------------------------------------------------------------------
30 static inline void vsp1_wpf_write(struct vsp1_rwpf
*wpf
, u32 reg
, u32 data
)
32 vsp1_mod_write(&wpf
->entity
,
33 reg
+ wpf
->entity
.index
* VI6_WPF_OFFSET
, data
);
36 /* -----------------------------------------------------------------------------
37 * V4L2 Subdevice Core Operations
40 static int wpf_s_stream(struct v4l2_subdev
*subdev
, int enable
)
42 struct vsp1_pipeline
*pipe
= to_vsp1_pipeline(&subdev
->entity
);
43 struct vsp1_rwpf
*wpf
= to_rwpf(subdev
);
44 struct vsp1_device
*vsp1
= wpf
->entity
.vsp1
;
45 const struct v4l2_mbus_framefmt
*source_format
;
46 const struct v4l2_mbus_framefmt
*sink_format
;
47 const struct v4l2_rect
*crop
= &wpf
->crop
;
53 vsp1_write(vsp1
, VI6_WPF_IRQ_ENB(wpf
->entity
.index
), 0);
54 vsp1_write(vsp1
, wpf
->entity
.index
* VI6_WPF_OFFSET
+
59 /* Sources. If the pipeline has a single input and BRU is not used,
60 * configure it as the master layer. Otherwise configure all
61 * inputs as sub-layers and select the virtual RPF as the master
64 for (i
= 0; i
< vsp1
->info
->rpf_count
; ++i
) {
65 struct vsp1_rwpf
*input
= pipe
->inputs
[i
];
70 srcrpf
|= (!pipe
->bru
&& pipe
->num_inputs
== 1)
71 ? VI6_WPF_SRCRPF_RPF_ACT_MST(input
->entity
.index
)
72 : VI6_WPF_SRCRPF_RPF_ACT_SUB(input
->entity
.index
);
75 if (pipe
->bru
|| pipe
->num_inputs
> 1)
76 srcrpf
|= VI6_WPF_SRCRPF_VIRACT_MST
;
78 vsp1_wpf_write(wpf
, VI6_WPF_SRCRPF
, srcrpf
);
80 /* Destination stride. */
82 struct v4l2_pix_format_mplane
*format
= &wpf
->format
;
84 vsp1_wpf_write(wpf
, VI6_WPF_DSTM_STRIDE_Y
,
85 format
->plane_fmt
[0].bytesperline
);
86 if (format
->num_planes
> 1)
87 vsp1_wpf_write(wpf
, VI6_WPF_DSTM_STRIDE_C
,
88 format
->plane_fmt
[1].bytesperline
);
91 vsp1_wpf_write(wpf
, VI6_WPF_HSZCLIP
, VI6_WPF_SZCLIP_EN
|
92 (crop
->left
<< VI6_WPF_SZCLIP_OFST_SHIFT
) |
93 (crop
->width
<< VI6_WPF_SZCLIP_SIZE_SHIFT
));
94 vsp1_wpf_write(wpf
, VI6_WPF_VSZCLIP
, VI6_WPF_SZCLIP_EN
|
95 (crop
->top
<< VI6_WPF_SZCLIP_OFST_SHIFT
) |
96 (crop
->height
<< VI6_WPF_SZCLIP_SIZE_SHIFT
));
99 sink_format
= vsp1_entity_get_pad_format(&wpf
->entity
,
102 source_format
= vsp1_entity_get_pad_format(&wpf
->entity
,
107 const struct vsp1_format_info
*fmtinfo
= wpf
->fmtinfo
;
109 outfmt
= fmtinfo
->hwfmt
<< VI6_WPF_OUTFMT_WRFMT_SHIFT
;
112 outfmt
|= VI6_WPF_OUTFMT_PXA
;
113 if (fmtinfo
->swap_yc
)
114 outfmt
|= VI6_WPF_OUTFMT_SPYCS
;
115 if (fmtinfo
->swap_uv
)
116 outfmt
|= VI6_WPF_OUTFMT_SPUVS
;
118 vsp1_wpf_write(wpf
, VI6_WPF_DSWAP
, fmtinfo
->swap
);
121 if (sink_format
->code
!= source_format
->code
)
122 outfmt
|= VI6_WPF_OUTFMT_CSC
;
124 outfmt
|= wpf
->alpha
<< VI6_WPF_OUTFMT_PDV_SHIFT
;
125 vsp1_wpf_write(wpf
, VI6_WPF_OUTFMT
, outfmt
);
127 vsp1_mod_write(&wpf
->entity
, VI6_DPR_WPF_FPORCH(wpf
->entity
.index
),
128 VI6_DPR_WPF_FPORCH_FP_WPFN
);
130 vsp1_mod_write(&wpf
->entity
, VI6_WPF_WRBCK_CTRL
, 0);
132 /* Enable interrupts */
133 vsp1_write(vsp1
, VI6_WPF_IRQ_STA(wpf
->entity
.index
), 0);
134 vsp1_write(vsp1
, VI6_WPF_IRQ_ENB(wpf
->entity
.index
),
135 VI6_WFP_IRQ_ENB_FREE
);
140 /* -----------------------------------------------------------------------------
141 * V4L2 Subdevice Operations
144 static struct v4l2_subdev_video_ops wpf_video_ops
= {
145 .s_stream
= wpf_s_stream
,
148 static struct v4l2_subdev_pad_ops wpf_pad_ops
= {
149 .init_cfg
= vsp1_entity_init_cfg
,
150 .enum_mbus_code
= vsp1_rwpf_enum_mbus_code
,
151 .enum_frame_size
= vsp1_rwpf_enum_frame_size
,
152 .get_fmt
= vsp1_rwpf_get_format
,
153 .set_fmt
= vsp1_rwpf_set_format
,
154 .get_selection
= vsp1_rwpf_get_selection
,
155 .set_selection
= vsp1_rwpf_set_selection
,
158 static struct v4l2_subdev_ops wpf_ops
= {
159 .video
= &wpf_video_ops
,
163 /* -----------------------------------------------------------------------------
164 * VSP1 Entity Operations
167 static void vsp1_wpf_destroy(struct vsp1_entity
*entity
)
169 struct vsp1_rwpf
*wpf
= entity_to_rwpf(entity
);
171 vsp1_dlm_destroy(wpf
->dlm
);
174 static void wpf_set_memory(struct vsp1_entity
*entity
)
176 struct vsp1_rwpf
*wpf
= entity_to_rwpf(entity
);
178 vsp1_wpf_write(wpf
, VI6_WPF_DSTM_ADDR_Y
, wpf
->mem
.addr
[0]);
179 vsp1_wpf_write(wpf
, VI6_WPF_DSTM_ADDR_C0
, wpf
->mem
.addr
[1]);
180 vsp1_wpf_write(wpf
, VI6_WPF_DSTM_ADDR_C1
, wpf
->mem
.addr
[2]);
183 static const struct vsp1_entity_operations wpf_entity_ops
= {
184 .destroy
= vsp1_wpf_destroy
,
185 .set_memory
= wpf_set_memory
,
188 /* -----------------------------------------------------------------------------
189 * Initialization and Cleanup
192 struct vsp1_rwpf
*vsp1_wpf_create(struct vsp1_device
*vsp1
, unsigned int index
)
194 struct vsp1_rwpf
*wpf
;
198 wpf
= devm_kzalloc(vsp1
->dev
, sizeof(*wpf
), GFP_KERNEL
);
200 return ERR_PTR(-ENOMEM
);
202 wpf
->max_width
= WPF_MAX_WIDTH
;
203 wpf
->max_height
= WPF_MAX_HEIGHT
;
205 wpf
->entity
.ops
= &wpf_entity_ops
;
206 wpf
->entity
.type
= VSP1_ENTITY_WPF
;
207 wpf
->entity
.index
= index
;
209 sprintf(name
, "wpf.%u", index
);
210 ret
= vsp1_entity_init(vsp1
, &wpf
->entity
, name
, 2, &wpf_ops
);
214 /* Initialize the display list manager. */
215 wpf
->dlm
= vsp1_dlm_create(vsp1
, index
, 4);
221 /* Initialize the control handler. */
222 ret
= vsp1_rwpf_init_ctrls(wpf
);
224 dev_err(vsp1
->dev
, "wpf%u: failed to initialize controls\n",
232 vsp1_entity_destroy(&wpf
->entity
);