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_pipe.h"
21 #include "vsp1_rwpf.h"
22 #include "vsp1_video.h"
24 #define WPF_GEN2_MAX_WIDTH 2048U
25 #define WPF_GEN2_MAX_HEIGHT 2048U
26 #define WPF_GEN3_MAX_WIDTH 8190U
27 #define WPF_GEN3_MAX_HEIGHT 8190U
29 /* -----------------------------------------------------------------------------
33 static inline void vsp1_wpf_write(struct vsp1_rwpf
*wpf
,
34 struct vsp1_dl_list
*dl
, u32 reg
, u32 data
)
36 vsp1_dl_list_write(dl
, reg
+ wpf
->entity
.index
* VI6_WPF_OFFSET
, data
);
39 /* -----------------------------------------------------------------------------
40 * V4L2 Subdevice Core Operations
43 static int wpf_s_stream(struct v4l2_subdev
*subdev
, int enable
)
45 struct vsp1_rwpf
*wpf
= to_rwpf(subdev
);
46 struct vsp1_device
*vsp1
= wpf
->entity
.vsp1
;
51 /* Write to registers directly when stopping the stream as there will be
52 * no pipeline run to apply the display list.
54 vsp1_write(vsp1
, VI6_WPF_IRQ_ENB(wpf
->entity
.index
), 0);
55 vsp1_write(vsp1
, wpf
->entity
.index
* VI6_WPF_OFFSET
+
61 /* -----------------------------------------------------------------------------
62 * V4L2 Subdevice Operations
65 static const struct v4l2_subdev_video_ops wpf_video_ops
= {
66 .s_stream
= wpf_s_stream
,
69 static const struct v4l2_subdev_ops wpf_ops
= {
70 .video
= &wpf_video_ops
,
71 .pad
= &vsp1_rwpf_pad_ops
,
74 /* -----------------------------------------------------------------------------
75 * VSP1 Entity Operations
78 static void vsp1_wpf_destroy(struct vsp1_entity
*entity
)
80 struct vsp1_rwpf
*wpf
= entity_to_rwpf(entity
);
82 vsp1_dlm_destroy(wpf
->dlm
);
85 static void wpf_set_memory(struct vsp1_entity
*entity
, struct vsp1_dl_list
*dl
)
87 struct vsp1_rwpf
*wpf
= entity_to_rwpf(entity
);
89 vsp1_wpf_write(wpf
, dl
, VI6_WPF_DSTM_ADDR_Y
, wpf
->mem
.addr
[0]);
90 vsp1_wpf_write(wpf
, dl
, VI6_WPF_DSTM_ADDR_C0
, wpf
->mem
.addr
[1]);
91 vsp1_wpf_write(wpf
, dl
, VI6_WPF_DSTM_ADDR_C1
, wpf
->mem
.addr
[2]);
94 static void wpf_configure(struct vsp1_entity
*entity
,
95 struct vsp1_pipeline
*pipe
,
96 struct vsp1_dl_list
*dl
, bool full
)
98 struct vsp1_rwpf
*wpf
= to_rwpf(&entity
->subdev
);
99 struct vsp1_device
*vsp1
= wpf
->entity
.vsp1
;
100 const struct v4l2_mbus_framefmt
*source_format
;
101 const struct v4l2_mbus_framefmt
*sink_format
;
102 const struct v4l2_rect
*crop
;
111 crop
= vsp1_rwpf_get_crop(wpf
, wpf
->entity
.config
);
113 vsp1_wpf_write(wpf
, dl
, VI6_WPF_HSZCLIP
, VI6_WPF_SZCLIP_EN
|
114 (crop
->left
<< VI6_WPF_SZCLIP_OFST_SHIFT
) |
115 (crop
->width
<< VI6_WPF_SZCLIP_SIZE_SHIFT
));
116 vsp1_wpf_write(wpf
, dl
, VI6_WPF_VSZCLIP
, VI6_WPF_SZCLIP_EN
|
117 (crop
->top
<< VI6_WPF_SZCLIP_OFST_SHIFT
) |
118 (crop
->height
<< VI6_WPF_SZCLIP_SIZE_SHIFT
));
121 sink_format
= vsp1_entity_get_pad_format(&wpf
->entity
,
124 source_format
= vsp1_entity_get_pad_format(&wpf
->entity
,
129 const struct v4l2_pix_format_mplane
*format
= &wpf
->format
;
130 const struct vsp1_format_info
*fmtinfo
= wpf
->fmtinfo
;
132 outfmt
= fmtinfo
->hwfmt
<< VI6_WPF_OUTFMT_WRFMT_SHIFT
;
135 outfmt
|= VI6_WPF_OUTFMT_PXA
;
136 if (fmtinfo
->swap_yc
)
137 outfmt
|= VI6_WPF_OUTFMT_SPYCS
;
138 if (fmtinfo
->swap_uv
)
139 outfmt
|= VI6_WPF_OUTFMT_SPUVS
;
141 /* Destination stride and byte swapping. */
142 vsp1_wpf_write(wpf
, dl
, VI6_WPF_DSTM_STRIDE_Y
,
143 format
->plane_fmt
[0].bytesperline
);
144 if (format
->num_planes
> 1)
145 vsp1_wpf_write(wpf
, dl
, VI6_WPF_DSTM_STRIDE_C
,
146 format
->plane_fmt
[1].bytesperline
);
148 vsp1_wpf_write(wpf
, dl
, VI6_WPF_DSWAP
, fmtinfo
->swap
);
151 if (sink_format
->code
!= source_format
->code
)
152 outfmt
|= VI6_WPF_OUTFMT_CSC
;
154 outfmt
|= wpf
->alpha
<< VI6_WPF_OUTFMT_PDV_SHIFT
;
155 vsp1_wpf_write(wpf
, dl
, VI6_WPF_OUTFMT
, outfmt
);
157 vsp1_dl_list_write(dl
, VI6_DPR_WPF_FPORCH(wpf
->entity
.index
),
158 VI6_DPR_WPF_FPORCH_FP_WPFN
);
160 vsp1_dl_list_write(dl
, VI6_WPF_WRBCK_CTRL
, 0);
162 /* Sources. If the pipeline has a single input and BRU is not used,
163 * configure it as the master layer. Otherwise configure all
164 * inputs as sub-layers and select the virtual RPF as the master
167 for (i
= 0; i
< vsp1
->info
->rpf_count
; ++i
) {
168 struct vsp1_rwpf
*input
= pipe
->inputs
[i
];
173 srcrpf
|= (!pipe
->bru
&& pipe
->num_inputs
== 1)
174 ? VI6_WPF_SRCRPF_RPF_ACT_MST(input
->entity
.index
)
175 : VI6_WPF_SRCRPF_RPF_ACT_SUB(input
->entity
.index
);
178 if (pipe
->bru
|| pipe
->num_inputs
> 1)
179 srcrpf
|= VI6_WPF_SRCRPF_VIRACT_MST
;
181 vsp1_wpf_write(wpf
, dl
, VI6_WPF_SRCRPF
, srcrpf
);
183 /* Enable interrupts */
184 vsp1_dl_list_write(dl
, VI6_WPF_IRQ_STA(wpf
->entity
.index
), 0);
185 vsp1_dl_list_write(dl
, VI6_WPF_IRQ_ENB(wpf
->entity
.index
),
186 VI6_WFP_IRQ_ENB_FREE
);
189 static const struct vsp1_entity_operations wpf_entity_ops
= {
190 .destroy
= vsp1_wpf_destroy
,
191 .set_memory
= wpf_set_memory
,
192 .configure
= wpf_configure
,
195 /* -----------------------------------------------------------------------------
196 * Initialization and Cleanup
199 struct vsp1_rwpf
*vsp1_wpf_create(struct vsp1_device
*vsp1
, unsigned int index
)
201 struct vsp1_rwpf
*wpf
;
205 wpf
= devm_kzalloc(vsp1
->dev
, sizeof(*wpf
), GFP_KERNEL
);
207 return ERR_PTR(-ENOMEM
);
209 if (vsp1
->info
->gen
== 2) {
210 wpf
->max_width
= WPF_GEN2_MAX_WIDTH
;
211 wpf
->max_height
= WPF_GEN2_MAX_HEIGHT
;
213 wpf
->max_width
= WPF_GEN3_MAX_WIDTH
;
214 wpf
->max_height
= WPF_GEN3_MAX_HEIGHT
;
217 wpf
->entity
.ops
= &wpf_entity_ops
;
218 wpf
->entity
.type
= VSP1_ENTITY_WPF
;
219 wpf
->entity
.index
= index
;
221 sprintf(name
, "wpf.%u", index
);
222 ret
= vsp1_entity_init(vsp1
, &wpf
->entity
, name
, 2, &wpf_ops
,
223 MEDIA_ENT_F_PROC_VIDEO_PIXEL_FORMATTER
);
227 /* Initialize the display list manager. */
228 wpf
->dlm
= vsp1_dlm_create(vsp1
, index
, 4);
234 /* Initialize the control handler. */
235 ret
= vsp1_rwpf_init_ctrls(wpf
);
237 dev_err(vsp1
->dev
, "wpf%u: failed to initialize controls\n",
245 vsp1_entity_destroy(&wpf
->entity
);