13 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/types.h>
16 #include <linux/errno.h>
19 #include <linux/device.h>
22 #include <linux/list.h>
24 #include <linux/slab.h>
38 static struct fimc_fmt fimc_formats[] = {
56 .name =
"ARGB8888, 32 bpp",
80 .name =
"YUV 4:2:2 packed, YCbYCr",
89 .name =
"YUV 4:2:2 packed, CbYCrY",
98 .name =
"YUV 4:2:2 packed, CrYCbY",
107 .name =
"YUV 4:2:2 packed, YCrYCb",
116 .name =
"YUV 4:2:2 planar, Y/Cb/Cr",
124 .name =
"YUV 4:2:2 planar, Y/CbCr",
132 .name =
"YUV 4:2:2 planar, Y/CrCb",
140 .name =
"YUV 4:2:0 planar, YCbCr",
148 .name =
"YUV 4:2:0 planar, Y/CbCr",
156 .name =
"YUV 4:2:0 non-contig. 2p, Y/CbCr",
164 .name =
"YUV 4:2:0 non-contig. 3p, Y/Cb/Cr",
167 .depth = { 8, 2, 2 },
172 .name =
"YUV 4:2:0 non-contig. 2p, tiled",
180 .name =
"JPEG encoded data",
189 .name =
"S5C73MX interleaved UYVY/JPEG",
206 return &fimc_formats[
index];
210 int dw,
int dh,
int rotation)
212 if (rotation == 90 || rotation == 270)
216 return (sw == dw && sh == dh) ? 0 : -
EINVAL;
233 if (src >= tar * tmp) {
234 *shift = sh, *ratio =
tmp;
238 *shift = 0, *ratio = 1;
259 if (tx <= 0 || ty <= 0) {
260 dev_err(dev,
"Invalid target size: %dx%d", tx, ty);
266 if (sx <= 0 || sy <= 0) {
267 dev_err(dev,
"Invalid source size: %dx%d", sx, sy);
297 if (s_frame->
fmt->color == d_frame->
fmt->color
314 spin_lock(&fimc->
slock);
324 spin_unlock(&fimc->
slock);
335 fimc->
vid_cap.reqbufs_count == 1;
339 spin_unlock(&fimc->
slock);
355 dbg(
"memplanes= %d, colplanes= %d, pix_size= %d",
356 frame->
fmt->memplanes, frame->
fmt->colplanes, pix_size);
358 paddr->
y = vb2_dma_contig_plane_dma_addr(vb, 0);
360 if (frame->
fmt->memplanes == 1) {
361 switch (frame->
fmt->colplanes) {
368 paddr->
cb = (
u32)(paddr->
y + pix_size);
372 paddr->
cb = (
u32)(paddr->
y + pix_size);
384 }
else if (!frame->
fmt->mdataplanes) {
385 if (frame->
fmt->memplanes >= 2)
386 paddr->
cb = vb2_dma_contig_plane_dma_addr(vb, 1);
388 if (frame->
fmt->memplanes == 3)
389 paddr->
cr = vb2_dma_contig_plane_dma_addr(vb, 2);
392 dbg(
"PHYS_ADDR: y= 0x%X cb= 0x%X cr= 0x%X ret= %d",
393 paddr->
y, paddr->
cb, paddr->
cr, ret);
406 switch (ctx->
s_frame.fmt->color) {
423 switch (ctx->
d_frame.fmt->color) {
446 for (i = 0; i < f->
fmt->colplanes; i++)
447 depth += f->
fmt->depth[i];
462 if (f->
fmt->colplanes == 3) {
472 dbg(
"in_offset: color= %d, y_h= %d, y_v= %d",
508 effect->
pat_cb = ctx->
ctrls.colorfx_cbcr->val >> 8;
509 effect->
pat_cr = ctx->
ctrls.colorfx_cbcr->val & 0xff;
521 #define ctrl_to_ctx(__ctrl) \
522 container_of((__ctrl)->handler, struct fimc_ctx, ctrls.handler)
545 (ctx->
state & flags) == flags) {
552 if ((ctrl->
val == 90 || ctrl->
val == 270) &&
564 ret = fimc_set_color_effect(ctx, ctrl->
val);
582 ret = __fimc_s_ctrl(ctx, ctrl);
583 spin_unlock_irqrestore(&ctx->
fimc_dev->slock, flags);
589 .s_ctrl = fimc_s_ctrl,
595 unsigned int max_alpha = fimc_get_alpha_mask(ctx->
d_frame.fmt);
599 if (ctx->
ctrls.ready)
627 if (!handler->
error) {
632 return handler->
error;
641 ctrls->
ready =
false;
663 fimc_set_color_effect(ctx, ctrls->
colorfx->cur.val);
685 v4l2_ctrl_lock(ctrl);
691 v4l2_ctrl_unlock(ctrl);
708 if (frame->
fmt->colplanes == 1)
709 bpl = (bpl * frame->
fmt->depth[0]) / 8;
727 if (frame->
fmt->colplanes == 1)
762 if (fmt->
colplanes > 1 && (bpl == 0 || bpl < pix->width))
766 (bpl == 0 || ((bpl * 8) / fmt->
depth[i]) < pix->
width))
796 fmt = &fimc_formats[
i];
797 if (!(fmt->
flags & mask))
799 if (pixelformat && fmt->
fourcc == *pixelformat)
801 if (mbus_code && fmt->
mbus_code == *mbus_code)
810 static void fimc_clk_put(
struct fimc_dev *fimc)
814 if (IS_ERR_OR_NULL(fimc->
clock[i]))
822 static int fimc_clk_get(
struct fimc_dev *fimc)
828 if (IS_ERR(fimc->
clock[i]))
840 dev_err(&fimc->
pdev->dev,
"failed to get clock: %s\n",
845 static int fimc_m2m_suspend(
struct fimc_dev *fimc)
852 spin_unlock_irqrestore(&fimc->
slock, flags);
857 spin_unlock_irqrestore(&fimc->
slock, flags);
864 return timeout == 0 ? -
EAGAIN : 0;
867 static int fimc_m2m_resume(
struct fimc_dev *fimc)
874 spin_unlock_irqrestore(&fimc->
slock, flags);
891 dev_err(&pdev->
dev,
"Invalid platform device id: %d\n",
904 pdata = pdev->
dev.platform_data;
914 dev_err(&pdev->
dev,
"Failed to obtain io memory\n");
920 dev_err(&pdev->
dev,
"Failed to get IRQ resource\n");
924 ret = fimc_clk_get(fimc);
930 ret = devm_request_irq(&pdev->
dev, res->
start, fimc_irq_handler,
931 0, dev_name(&pdev->
dev), fimc);
933 dev_err(&pdev->
dev,
"failed to install irq (%d)\n", ret);
941 platform_set_drvdata(pdev, fimc);
943 ret = pm_runtime_get_sync(&pdev->
dev);
953 dev_dbg(&pdev->
dev,
"FIMC.%d registered successfully\n", fimc->
id);
955 pm_runtime_put(&pdev->
dev);
958 pm_runtime_put(&pdev->
dev);
966 static int fimc_runtime_resume(
struct device *
dev)
970 dbg(
"fimc%d: state: 0x%lx", fimc->
id, fimc->
state);
980 return fimc_m2m_resume(fimc);
983 static int fimc_runtime_suspend(
struct device *dev)
991 ret = fimc_m2m_suspend(fimc);
995 dbg(
"fimc%d: state: 0x%lx", fimc->
id, fimc->
state);
999 #ifdef CONFIG_PM_SLEEP
1000 static int fimc_resume(
struct device *dev)
1003 unsigned long flags;
1005 dbg(
"fimc%d: state: 0x%lx", fimc->
id, fimc->
state);
1011 spin_unlock_irqrestore(&fimc->
slock, flags);
1015 spin_unlock_irqrestore(&fimc->
slock, flags);
1020 return fimc_m2m_resume(fimc);
1023 static int fimc_suspend(
struct device *dev)
1027 dbg(
"fimc%d: state: 0x%lx", fimc->
id, fimc->
state);
1034 return fimc_m2m_suspend(fimc);
1040 struct fimc_dev *fimc = platform_get_drvdata(pdev);
1042 pm_runtime_disable(&pdev->
dev);
1043 pm_runtime_set_suspended(&pdev->
dev);
1058 .scaler_en_w = 3264,
1059 .scaler_dis_w = 8192,
1060 .in_rot_en_h = 1920,
1061 .in_rot_dis_w = 8192,
1062 .out_rot_en_w = 1920,
1063 .out_rot_dis_w = 4224,
1066 .scaler_en_w = 4224,
1067 .scaler_dis_w = 8192,
1068 .in_rot_en_h = 1920,
1069 .in_rot_dis_w = 8192,
1070 .out_rot_en_w = 1920,
1071 .out_rot_dis_w = 4224,
1074 .scaler_en_w = 1920,
1075 .scaler_dis_w = 8192,
1076 .in_rot_en_h = 1280,
1077 .in_rot_dis_w = 8192,
1078 .out_rot_en_w = 1280,
1079 .out_rot_dis_w = 1920,
1082 .scaler_en_w = 1920,
1083 .scaler_dis_w = 8192,
1084 .in_rot_en_h = 1366,
1085 .in_rot_dis_w = 8192,
1086 .out_rot_en_w = 1366,
1087 .out_rot_dis_w = 1920,
1095 .min_inp_pixsize = 16,
1096 .min_out_pixsize = 16,
1097 .hor_offs_align = 8,
1098 .min_vsize_align = 16,
1100 .pix_limit = &s5p_pix_limit[0],
1105 .min_inp_pixsize = 16,
1106 .min_out_pixsize = 16,
1107 .hor_offs_align = 8,
1108 .min_vsize_align = 16,
1110 .pix_limit = &s5p_pix_limit[1],
1118 .min_inp_pixsize = 16,
1119 .min_out_pixsize = 16,
1120 .hor_offs_align = 8,
1121 .min_vsize_align = 16,
1123 .pix_limit = &s5p_pix_limit[1],
1131 .has_mainscaler_ext = 1,
1132 .min_inp_pixsize = 16,
1133 .min_out_pixsize = 16,
1134 .hor_offs_align = 1,
1135 .min_vsize_align = 1,
1137 .pix_limit = &s5p_pix_limit[2],
1143 .min_inp_pixsize = 16,
1144 .min_out_pixsize = 16,
1145 .hor_offs_align = 8,
1146 .min_vsize_align = 16,
1148 .pix_limit = &s5p_pix_limit[2],
1157 .has_mainscaler_ext = 1,
1159 .min_inp_pixsize = 16,
1160 .min_out_pixsize = 16,
1161 .hor_offs_align = 2,
1162 .min_vsize_align = 1,
1163 .out_buf_count = 32,
1164 .pix_limit = &s5p_pix_limit[1],
1171 .has_mainscaler_ext = 1,
1173 .min_inp_pixsize = 16,
1174 .min_out_pixsize = 16,
1175 .hor_offs_align = 2,
1176 .min_vsize_align = 1,
1177 .out_buf_count = 32,
1178 .pix_limit = &s5p_pix_limit[3],
1184 [0] = &fimc0_variant_s5p,
1185 [1] = &fimc0_variant_s5p,
1186 [2] = &fimc2_variant_s5p,
1189 .lclk_frequency = 133000000
UL,
1195 [0] = &fimc0_variant_s5pv210,
1196 [1] = &fimc1_variant_s5pv210,
1197 [2] = &fimc2_variant_s5pv210,
1200 .lclk_frequency = 166000000
UL,
1206 [0] = &fimc0_variant_exynos4,
1207 [1] = &fimc0_variant_exynos4,
1208 [2] = &fimc0_variant_exynos4,
1209 [3] = &fimc3_variant_exynos4,
1212 .lclk_frequency = 166000000
UL,
1218 .driver_data = (
unsigned long)&fimc_drvdata_s5p,
1220 .name =
"s5pv210-fimc",
1221 .driver_data = (
unsigned long)&fimc_drvdata_s5pv210,
1223 .name =
"exynos4-fimc",
1224 .driver_data = (
unsigned long)&fimc_drvdata_exynos4,
1230 static const struct dev_pm_ops fimc_pm_ops = {
1236 .
probe = fimc_probe,
1238 .id_table = fimc_driver_ids,