Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1 | /* |
Sylwester Nawrocki | 97d9742 | 2012-05-08 15:51:24 -0300 | [diff] [blame] | 2 | * Samsung S5P/EXYNOS4 SoC series FIMC (CAMIF) driver |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 3 | * |
Sylwester Nawrocki | 0c9204d | 2012-04-25 06:55:42 -0300 | [diff] [blame] | 4 | * Copyright (C) 2010-2012 Samsung Electronics Co., Ltd. |
| 5 | * Sylwester Nawrocki <s.nawrocki@samsung.com> |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published |
| 9 | * by the Free Software Foundation, either version 2 of the License, |
| 10 | * or (at your option) any later version. |
| 11 | */ |
| 12 | |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/kernel.h> |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 15 | #include <linux/types.h> |
| 16 | #include <linux/errno.h> |
| 17 | #include <linux/bug.h> |
| 18 | #include <linux/interrupt.h> |
| 19 | #include <linux/device.h> |
| 20 | #include <linux/platform_device.h> |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 21 | #include <linux/pm_runtime.h> |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 22 | #include <linux/list.h> |
Sylwester Nawrocki | 88fa831 | 2013-03-20 10:44:39 -0300 | [diff] [blame] | 23 | #include <linux/mfd/syscon.h> |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 24 | #include <linux/io.h> |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 25 | #include <linux/of.h> |
| 26 | #include <linux/of_device.h> |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 27 | #include <linux/slab.h> |
| 28 | #include <linux/clk.h> |
| 29 | #include <media/v4l2-ioctl.h> |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 30 | #include <media/videobuf2-core.h> |
| 31 | #include <media/videobuf2-dma-contig.h> |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 32 | |
| 33 | #include "fimc-core.h" |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 34 | #include "fimc-reg.h" |
Sylwester Nawrocki | 56fa1a6 | 2013-03-24 16:54:25 +0100 | [diff] [blame] | 35 | #include "media-dev.h" |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 36 | |
Sylwester Nawrocki | a25be18 | 2010-12-27 15:34:43 -0300 | [diff] [blame] | 37 | static char *fimc_clocks[MAX_FIMC_CLOCKS] = { |
Sylwester Nawrocki | ebdfea8 | 2011-06-10 15:36:45 -0300 | [diff] [blame] | 38 | "sclk_fimc", "fimc" |
Sylwester Nawrocki | a25be18 | 2010-12-27 15:34:43 -0300 | [diff] [blame] | 39 | }; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 40 | |
| 41 | static struct fimc_fmt fimc_formats[] = { |
| 42 | { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 43 | .name = "RGB565", |
Sylwester Nawrocki | f83f71f | 2011-11-04 10:07:06 -0300 | [diff] [blame] | 44 | .fourcc = V4L2_PIX_FMT_RGB565, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 45 | .depth = { 16 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 46 | .color = FIMC_FMT_RGB565, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 47 | .memplanes = 1, |
| 48 | .colplanes = 1, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 49 | .flags = FMT_FLAGS_M2M, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 50 | }, { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 51 | .name = "BGR666", |
| 52 | .fourcc = V4L2_PIX_FMT_BGR666, |
| 53 | .depth = { 32 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 54 | .color = FIMC_FMT_RGB666, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 55 | .memplanes = 1, |
| 56 | .colplanes = 1, |
| 57 | .flags = FMT_FLAGS_M2M, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 58 | }, { |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 59 | .name = "ARGB8888, 32 bpp", |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 60 | .fourcc = V4L2_PIX_FMT_RGB32, |
| 61 | .depth = { 32 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 62 | .color = FIMC_FMT_RGB888, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 63 | .memplanes = 1, |
| 64 | .colplanes = 1, |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 65 | .flags = FMT_FLAGS_M2M | FMT_HAS_ALPHA, |
| 66 | }, { |
| 67 | .name = "ARGB1555", |
| 68 | .fourcc = V4L2_PIX_FMT_RGB555, |
| 69 | .depth = { 16 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 70 | .color = FIMC_FMT_RGB555, |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 71 | .memplanes = 1, |
| 72 | .colplanes = 1, |
| 73 | .flags = FMT_FLAGS_M2M_OUT | FMT_HAS_ALPHA, |
| 74 | }, { |
| 75 | .name = "ARGB4444", |
| 76 | .fourcc = V4L2_PIX_FMT_RGB444, |
| 77 | .depth = { 16 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 78 | .color = FIMC_FMT_RGB444, |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 79 | .memplanes = 1, |
| 80 | .colplanes = 1, |
| 81 | .flags = FMT_FLAGS_M2M_OUT | FMT_HAS_ALPHA, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 82 | }, { |
Sylwester Nawrocki | 88fa831 | 2013-03-20 10:44:39 -0300 | [diff] [blame] | 83 | .name = "YUV 4:4:4", |
| 84 | .mbus_code = V4L2_MBUS_FMT_YUV10_1X30, |
| 85 | .flags = FMT_FLAGS_WRITEBACK, |
| 86 | }, { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 87 | .name = "YUV 4:2:2 packed, YCbYCr", |
| 88 | .fourcc = V4L2_PIX_FMT_YUYV, |
| 89 | .depth = { 16 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 90 | .color = FIMC_FMT_YCBYCR422, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 91 | .memplanes = 1, |
| 92 | .colplanes = 1, |
| 93 | .mbus_code = V4L2_MBUS_FMT_YUYV8_2X8, |
| 94 | .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM, |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 95 | }, { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 96 | .name = "YUV 4:2:2 packed, CbYCrY", |
| 97 | .fourcc = V4L2_PIX_FMT_UYVY, |
| 98 | .depth = { 16 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 99 | .color = FIMC_FMT_CBYCRY422, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 100 | .memplanes = 1, |
| 101 | .colplanes = 1, |
| 102 | .mbus_code = V4L2_MBUS_FMT_UYVY8_2X8, |
| 103 | .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 104 | }, { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 105 | .name = "YUV 4:2:2 packed, CrYCbY", |
| 106 | .fourcc = V4L2_PIX_FMT_VYUY, |
| 107 | .depth = { 16 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 108 | .color = FIMC_FMT_CRYCBY422, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 109 | .memplanes = 1, |
| 110 | .colplanes = 1, |
| 111 | .mbus_code = V4L2_MBUS_FMT_VYUY8_2X8, |
| 112 | .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 113 | }, { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 114 | .name = "YUV 4:2:2 packed, YCrYCb", |
| 115 | .fourcc = V4L2_PIX_FMT_YVYU, |
| 116 | .depth = { 16 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 117 | .color = FIMC_FMT_YCRYCB422, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 118 | .memplanes = 1, |
| 119 | .colplanes = 1, |
| 120 | .mbus_code = V4L2_MBUS_FMT_YVYU8_2X8, |
| 121 | .flags = FMT_FLAGS_M2M | FMT_FLAGS_CAM, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 122 | }, { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 123 | .name = "YUV 4:2:2 planar, Y/Cb/Cr", |
| 124 | .fourcc = V4L2_PIX_FMT_YUV422P, |
| 125 | .depth = { 12 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 126 | .color = FIMC_FMT_YCBYCR422, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 127 | .memplanes = 1, |
| 128 | .colplanes = 3, |
| 129 | .flags = FMT_FLAGS_M2M, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 130 | }, { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 131 | .name = "YUV 4:2:2 planar, Y/CbCr", |
| 132 | .fourcc = V4L2_PIX_FMT_NV16, |
| 133 | .depth = { 16 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 134 | .color = FIMC_FMT_YCBYCR422, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 135 | .memplanes = 1, |
| 136 | .colplanes = 2, |
| 137 | .flags = FMT_FLAGS_M2M, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 138 | }, { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 139 | .name = "YUV 4:2:2 planar, Y/CrCb", |
| 140 | .fourcc = V4L2_PIX_FMT_NV61, |
| 141 | .depth = { 16 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 142 | .color = FIMC_FMT_YCRYCB422, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 143 | .memplanes = 1, |
| 144 | .colplanes = 2, |
| 145 | .flags = FMT_FLAGS_M2M, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 146 | }, { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 147 | .name = "YUV 4:2:0 planar, YCbCr", |
| 148 | .fourcc = V4L2_PIX_FMT_YUV420, |
| 149 | .depth = { 12 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 150 | .color = FIMC_FMT_YCBCR420, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 151 | .memplanes = 1, |
| 152 | .colplanes = 3, |
| 153 | .flags = FMT_FLAGS_M2M, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 154 | }, { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 155 | .name = "YUV 4:2:0 planar, Y/CbCr", |
| 156 | .fourcc = V4L2_PIX_FMT_NV12, |
| 157 | .depth = { 12 }, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 158 | .color = FIMC_FMT_YCBCR420, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 159 | .memplanes = 1, |
| 160 | .colplanes = 2, |
| 161 | .flags = FMT_FLAGS_M2M, |
| 162 | }, { |
Sylwester Nawrocki | 0a198bc | 2012-05-22 13:50:14 -0300 | [diff] [blame] | 163 | .name = "YUV 4:2:0 non-contig. 2p, Y/CbCr", |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 164 | .fourcc = V4L2_PIX_FMT_NV12M, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 165 | .color = FIMC_FMT_YCBCR420, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 166 | .depth = { 8, 4 }, |
| 167 | .memplanes = 2, |
| 168 | .colplanes = 2, |
| 169 | .flags = FMT_FLAGS_M2M, |
| 170 | }, { |
Sylwester Nawrocki | 0a198bc | 2012-05-22 13:50:14 -0300 | [diff] [blame] | 171 | .name = "YUV 4:2:0 non-contig. 3p, Y/Cb/Cr", |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 172 | .fourcc = V4L2_PIX_FMT_YUV420M, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 173 | .color = FIMC_FMT_YCBCR420, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 174 | .depth = { 8, 2, 2 }, |
| 175 | .memplanes = 3, |
| 176 | .colplanes = 3, |
| 177 | .flags = FMT_FLAGS_M2M, |
| 178 | }, { |
Sylwester Nawrocki | 0a198bc | 2012-05-22 13:50:14 -0300 | [diff] [blame] | 179 | .name = "YUV 4:2:0 non-contig. 2p, tiled", |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 180 | .fourcc = V4L2_PIX_FMT_NV12MT, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 181 | .color = FIMC_FMT_YCBCR420, |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 182 | .depth = { 8, 4 }, |
| 183 | .memplanes = 2, |
| 184 | .colplanes = 2, |
| 185 | .flags = FMT_FLAGS_M2M, |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 186 | }, { |
| 187 | .name = "JPEG encoded data", |
| 188 | .fourcc = V4L2_PIX_FMT_JPEG, |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 189 | .color = FIMC_FMT_JPEG, |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 190 | .depth = { 8 }, |
| 191 | .memplanes = 1, |
| 192 | .colplanes = 1, |
| 193 | .mbus_code = V4L2_MBUS_FMT_JPEG_1X8, |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 194 | .flags = FMT_FLAGS_CAM | FMT_FLAGS_COMPRESSED, |
| 195 | }, { |
| 196 | .name = "S5C73MX interleaved UYVY/JPEG", |
| 197 | .fourcc = V4L2_PIX_FMT_S5C_UYVY_JPG, |
| 198 | .color = FIMC_FMT_YUYV_JPEG, |
| 199 | .depth = { 8 }, |
| 200 | .memplanes = 2, |
| 201 | .colplanes = 1, |
| 202 | .mdataplanes = 0x2, /* plane 1 holds frame meta data */ |
| 203 | .mbus_code = V4L2_MBUS_FMT_S5C_UYVY_JPEG_1X8, |
| 204 | .flags = FMT_FLAGS_CAM | FMT_FLAGS_COMPRESSED, |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 205 | }, |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 206 | }; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 207 | |
Sylwester Nawrocki | bb7c276 | 2012-04-27 09:33:23 -0300 | [diff] [blame] | 208 | struct fimc_fmt *fimc_get_format(unsigned int index) |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 209 | { |
Sylwester Nawrocki | 97d9742 | 2012-05-08 15:51:24 -0300 | [diff] [blame] | 210 | if (index >= ARRAY_SIZE(fimc_formats)) |
| 211 | return NULL; |
| 212 | |
| 213 | return &fimc_formats[index]; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 214 | } |
| 215 | |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 216 | int fimc_check_scaler_ratio(struct fimc_ctx *ctx, int sw, int sh, |
| 217 | int dw, int dh, int rotation) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 218 | { |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 219 | if (rotation == 90 || rotation == 270) |
| 220 | swap(dw, dh); |
Hyunwoong Kim | 1b09f29 | 2010-12-28 22:12:43 -0300 | [diff] [blame] | 221 | |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 222 | if (!ctx->scaler.enabled) |
| 223 | return (sw == dw && sh == dh) ? 0 : -EINVAL; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 224 | |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 225 | if ((sw >= SCALER_MAX_HRATIO * dw) || (sh >= SCALER_MAX_VRATIO * dh)) |
Hyunwoong Kim | 1b09f29 | 2010-12-28 22:12:43 -0300 | [diff] [blame] | 226 | return -EINVAL; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 227 | |
| 228 | return 0; |
| 229 | } |
| 230 | |
| 231 | static int fimc_get_scaler_factor(u32 src, u32 tar, u32 *ratio, u32 *shift) |
| 232 | { |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 233 | u32 sh = 6; |
| 234 | |
| 235 | if (src >= 64 * tar) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 236 | return -EINVAL; |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 237 | |
| 238 | while (sh--) { |
| 239 | u32 tmp = 1 << sh; |
| 240 | if (src >= tar * tmp) { |
| 241 | *shift = sh, *ratio = tmp; |
| 242 | return 0; |
| 243 | } |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 244 | } |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 245 | *shift = 0, *ratio = 1; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 246 | return 0; |
| 247 | } |
| 248 | |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 249 | int fimc_set_scaler_info(struct fimc_ctx *ctx) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 250 | { |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 251 | const struct fimc_variant *variant = ctx->fimc_dev->variant; |
Sylwester Nawrocki | 30c9939 | 2011-06-10 15:36:48 -0300 | [diff] [blame] | 252 | struct device *dev = &ctx->fimc_dev->pdev->dev; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 253 | struct fimc_scaler *sc = &ctx->scaler; |
| 254 | struct fimc_frame *s_frame = &ctx->s_frame; |
| 255 | struct fimc_frame *d_frame = &ctx->d_frame; |
| 256 | int tx, ty, sx, sy; |
| 257 | int ret; |
| 258 | |
Sylwester Nawrocki | 47654df | 2010-10-08 05:01:22 -0300 | [diff] [blame] | 259 | if (ctx->rotation == 90 || ctx->rotation == 270) { |
| 260 | ty = d_frame->width; |
| 261 | tx = d_frame->height; |
| 262 | } else { |
| 263 | tx = d_frame->width; |
| 264 | ty = d_frame->height; |
| 265 | } |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 266 | if (tx <= 0 || ty <= 0) { |
Sylwester Nawrocki | 969e877 | 2012-12-07 16:40:08 -0300 | [diff] [blame] | 267 | dev_err(dev, "Invalid target size: %dx%d\n", tx, ty); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 268 | return -EINVAL; |
| 269 | } |
| 270 | |
| 271 | sx = s_frame->width; |
| 272 | sy = s_frame->height; |
| 273 | if (sx <= 0 || sy <= 0) { |
Sylwester Nawrocki | 969e877 | 2012-12-07 16:40:08 -0300 | [diff] [blame] | 274 | dev_err(dev, "Invalid source size: %dx%d\n", sx, sy); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 275 | return -EINVAL; |
| 276 | } |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 277 | sc->real_width = sx; |
| 278 | sc->real_height = sy; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 279 | |
| 280 | ret = fimc_get_scaler_factor(sx, tx, &sc->pre_hratio, &sc->hfactor); |
| 281 | if (ret) |
| 282 | return ret; |
| 283 | |
| 284 | ret = fimc_get_scaler_factor(sy, ty, &sc->pre_vratio, &sc->vfactor); |
| 285 | if (ret) |
| 286 | return ret; |
| 287 | |
| 288 | sc->pre_dst_width = sx / sc->pre_hratio; |
| 289 | sc->pre_dst_height = sy / sc->pre_vratio; |
| 290 | |
Hyunwoong Kim | b241c6d | 2010-12-28 11:27:13 -0300 | [diff] [blame] | 291 | if (variant->has_mainscaler_ext) { |
| 292 | sc->main_hratio = (sx << 14) / (tx << sc->hfactor); |
| 293 | sc->main_vratio = (sy << 14) / (ty << sc->vfactor); |
| 294 | } else { |
| 295 | sc->main_hratio = (sx << 8) / (tx << sc->hfactor); |
| 296 | sc->main_vratio = (sy << 8) / (ty << sc->vfactor); |
| 297 | |
| 298 | } |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 299 | |
| 300 | sc->scaleup_h = (tx >= sx) ? 1 : 0; |
| 301 | sc->scaleup_v = (ty >= sy) ? 1 : 0; |
| 302 | |
| 303 | /* check to see if input and output size/format differ */ |
| 304 | if (s_frame->fmt->color == d_frame->fmt->color |
| 305 | && s_frame->width == d_frame->width |
| 306 | && s_frame->height == d_frame->height) |
| 307 | sc->copy_mode = 1; |
| 308 | else |
| 309 | sc->copy_mode = 0; |
| 310 | |
| 311 | return 0; |
| 312 | } |
| 313 | |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 314 | static irqreturn_t fimc_irq_handler(int irq, void *priv) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 315 | { |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 316 | struct fimc_dev *fimc = priv; |
Sylwester Nawrocki | 4ecbf5d | 2011-02-23 08:24:33 -0300 | [diff] [blame] | 317 | struct fimc_ctx *ctx; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 318 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 319 | fimc_hw_clear_irq(fimc); |
| 320 | |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 321 | spin_lock(&fimc->slock); |
| 322 | |
Sylwester Nawrocki | 4ecbf5d | 2011-02-23 08:24:33 -0300 | [diff] [blame] | 323 | if (test_and_clear_bit(ST_M2M_PEND, &fimc->state)) { |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 324 | if (test_and_clear_bit(ST_M2M_SUSPENDING, &fimc->state)) { |
| 325 | set_bit(ST_M2M_SUSPENDED, &fimc->state); |
| 326 | wake_up(&fimc->irq_queue); |
| 327 | goto out; |
| 328 | } |
Sylwester Nawrocki | 4ecbf5d | 2011-02-23 08:24:33 -0300 | [diff] [blame] | 329 | ctx = v4l2_m2m_get_curr_priv(fimc->m2m.m2m_dev); |
| 330 | if (ctx != NULL) { |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 331 | spin_unlock(&fimc->slock); |
Sylwester Nawrocki | 4ecbf5d | 2011-02-23 08:24:33 -0300 | [diff] [blame] | 332 | fimc_m2m_job_finish(ctx, VB2_BUF_STATE_DONE); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 333 | |
Sylwester Nawrocki | 4ecbf5d | 2011-02-23 08:24:33 -0300 | [diff] [blame] | 334 | if (ctx->state & FIMC_CTX_SHUT) { |
| 335 | ctx->state &= ~FIMC_CTX_SHUT; |
| 336 | wake_up(&fimc->irq_queue); |
| 337 | } |
Sylwester Nawrocki | efb13c3 | 2012-03-19 13:11:40 -0300 | [diff] [blame] | 338 | return IRQ_HANDLED; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 339 | } |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 340 | } else if (test_bit(ST_CAPT_PEND, &fimc->state)) { |
Sylwester Nawrocki | 97d9742 | 2012-05-08 15:51:24 -0300 | [diff] [blame] | 341 | int last_buf = test_bit(ST_CAPT_JPEG, &fimc->state) && |
| 342 | fimc->vid_cap.reqbufs_count == 1; |
| 343 | fimc_capture_irq_handler(fimc, !last_buf); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 344 | } |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 345 | out: |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 346 | spin_unlock(&fimc->slock); |
| 347 | return IRQ_HANDLED; |
| 348 | } |
| 349 | |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 350 | /* The color format (colplanes, memplanes) must be already configured. */ |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 351 | int fimc_prepare_addr(struct fimc_ctx *ctx, struct vb2_buffer *vb, |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 352 | struct fimc_frame *frame, struct fimc_addr *paddr) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 353 | { |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 354 | int ret = 0; |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 355 | u32 pix_size; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 356 | |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 357 | if (vb == NULL || frame == NULL) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 358 | return -EINVAL; |
| 359 | |
| 360 | pix_size = frame->width * frame->height; |
| 361 | |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 362 | dbg("memplanes= %d, colplanes= %d, pix_size= %d", |
| 363 | frame->fmt->memplanes, frame->fmt->colplanes, pix_size); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 364 | |
Marek Szyprowski | ba7fcb0 | 2011-08-29 03:20:56 -0300 | [diff] [blame] | 365 | paddr->y = vb2_dma_contig_plane_dma_addr(vb, 0); |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 366 | |
| 367 | if (frame->fmt->memplanes == 1) { |
| 368 | switch (frame->fmt->colplanes) { |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 369 | case 1: |
| 370 | paddr->cb = 0; |
| 371 | paddr->cr = 0; |
| 372 | break; |
| 373 | case 2: |
| 374 | /* decompose Y into Y/Cb */ |
| 375 | paddr->cb = (u32)(paddr->y + pix_size); |
| 376 | paddr->cr = 0; |
| 377 | break; |
| 378 | case 3: |
| 379 | paddr->cb = (u32)(paddr->y + pix_size); |
| 380 | /* decompose Y into Y/Cb/Cr */ |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 381 | if (FIMC_FMT_YCBCR420 == frame->fmt->color) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 382 | paddr->cr = (u32)(paddr->cb |
| 383 | + (pix_size >> 2)); |
| 384 | else /* 422 */ |
| 385 | paddr->cr = (u32)(paddr->cb |
| 386 | + (pix_size >> 1)); |
| 387 | break; |
| 388 | default: |
| 389 | return -EINVAL; |
| 390 | } |
Sylwester Nawrocki | 14783d2 | 2012-09-24 11:08:45 -0300 | [diff] [blame] | 391 | } else if (!frame->fmt->mdataplanes) { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 392 | if (frame->fmt->memplanes >= 2) |
Marek Szyprowski | ba7fcb0 | 2011-08-29 03:20:56 -0300 | [diff] [blame] | 393 | paddr->cb = vb2_dma_contig_plane_dma_addr(vb, 1); |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 394 | |
| 395 | if (frame->fmt->memplanes == 3) |
Marek Szyprowski | ba7fcb0 | 2011-08-29 03:20:56 -0300 | [diff] [blame] | 396 | paddr->cr = vb2_dma_contig_plane_dma_addr(vb, 2); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 397 | } |
| 398 | |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 399 | dbg("PHYS_ADDR: y= 0x%X cb= 0x%X cr= 0x%X ret= %d", |
| 400 | paddr->y, paddr->cb, paddr->cr, ret); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 401 | |
| 402 | return ret; |
| 403 | } |
| 404 | |
| 405 | /* Set order for 1 and 2 plane YCBCR 4:2:2 formats. */ |
Sylwester Nawrocki | 9e803a0 | 2011-06-10 15:36:53 -0300 | [diff] [blame] | 406 | void fimc_set_yuv_order(struct fimc_ctx *ctx) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 407 | { |
| 408 | /* The one only mode supported in SoC. */ |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 409 | ctx->in_order_2p = FIMC_REG_CIOCTRL_ORDER422_2P_LSB_CRCB; |
| 410 | ctx->out_order_2p = FIMC_REG_CIOCTRL_ORDER422_2P_LSB_CRCB; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 411 | |
| 412 | /* Set order for 1 plane input formats. */ |
| 413 | switch (ctx->s_frame.fmt->color) { |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 414 | case FIMC_FMT_YCRYCB422: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 415 | ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCRYCB; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 416 | break; |
Sylwester Nawrocki | 4397979 | 2013-03-21 14:22:34 -0300 | [diff] [blame] | 417 | case FIMC_FMT_CBYCRY422: |
| 418 | ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CBYCRY; |
| 419 | break; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 420 | case FIMC_FMT_CRYCBY422: |
Sylwester Nawrocki | 4397979 | 2013-03-21 14:22:34 -0300 | [diff] [blame] | 421 | ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_CRYCBY; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 422 | break; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 423 | case FIMC_FMT_YCBYCR422: |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 424 | default: |
Sylwester Nawrocki | 4397979 | 2013-03-21 14:22:34 -0300 | [diff] [blame] | 425 | ctx->in_order_1p = FIMC_REG_MSCTRL_ORDER422_YCBYCR; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 426 | break; |
| 427 | } |
| 428 | dbg("ctx->in_order_1p= %d", ctx->in_order_1p); |
| 429 | |
| 430 | switch (ctx->d_frame.fmt->color) { |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 431 | case FIMC_FMT_YCRYCB422: |
Sylwester Nawrocki | c83a1ff | 2012-05-02 06:14:49 -0300 | [diff] [blame] | 432 | ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCRYCB; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 433 | break; |
Sylwester Nawrocki | 4397979 | 2013-03-21 14:22:34 -0300 | [diff] [blame] | 434 | case FIMC_FMT_CBYCRY422: |
| 435 | ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CBYCRY; |
| 436 | break; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 437 | case FIMC_FMT_CRYCBY422: |
Sylwester Nawrocki | 4397979 | 2013-03-21 14:22:34 -0300 | [diff] [blame] | 438 | ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_CRYCBY; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 439 | break; |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 440 | case FIMC_FMT_YCBYCR422: |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 441 | default: |
Sylwester Nawrocki | 4397979 | 2013-03-21 14:22:34 -0300 | [diff] [blame] | 442 | ctx->out_order_1p = FIMC_REG_CIOCTRL_ORDER422_YCBYCR; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 443 | break; |
| 444 | } |
| 445 | dbg("ctx->out_order_1p= %d", ctx->out_order_1p); |
| 446 | } |
| 447 | |
Sylwester Nawrocki | 9e803a0 | 2011-06-10 15:36:53 -0300 | [diff] [blame] | 448 | void fimc_prepare_dma_offset(struct fimc_ctx *ctx, struct fimc_frame *f) |
Sylwester Nawrocki | ddc79e0 | 2010-09-06 03:53:44 -0300 | [diff] [blame] | 449 | { |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 450 | bool pix_hoff = ctx->fimc_dev->drv_data->dma_pix_hoff; |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 451 | u32 i, depth = 0; |
| 452 | |
| 453 | for (i = 0; i < f->fmt->colplanes; i++) |
| 454 | depth += f->fmt->depth[i]; |
Sylwester Nawrocki | ddc79e0 | 2010-09-06 03:53:44 -0300 | [diff] [blame] | 455 | |
| 456 | f->dma_offset.y_h = f->offs_h; |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 457 | if (!pix_hoff) |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 458 | f->dma_offset.y_h *= (depth >> 3); |
Sylwester Nawrocki | ddc79e0 | 2010-09-06 03:53:44 -0300 | [diff] [blame] | 459 | |
| 460 | f->dma_offset.y_v = f->offs_v; |
| 461 | |
| 462 | f->dma_offset.cb_h = f->offs_h; |
| 463 | f->dma_offset.cb_v = f->offs_v; |
| 464 | |
| 465 | f->dma_offset.cr_h = f->offs_h; |
| 466 | f->dma_offset.cr_v = f->offs_v; |
| 467 | |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 468 | if (!pix_hoff) { |
Sylwester Nawrocki | ef7af59 | 2010-12-08 14:05:08 -0300 | [diff] [blame] | 469 | if (f->fmt->colplanes == 3) { |
Sylwester Nawrocki | ddc79e0 | 2010-09-06 03:53:44 -0300 | [diff] [blame] | 470 | f->dma_offset.cb_h >>= 1; |
| 471 | f->dma_offset.cr_h >>= 1; |
| 472 | } |
Sylwester Nawrocki | 3d112d9 | 2012-04-26 06:26:29 -0300 | [diff] [blame] | 473 | if (f->fmt->color == FIMC_FMT_YCBCR420) { |
Sylwester Nawrocki | ddc79e0 | 2010-09-06 03:53:44 -0300 | [diff] [blame] | 474 | f->dma_offset.cb_v >>= 1; |
| 475 | f->dma_offset.cr_v >>= 1; |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | dbg("in_offset: color= %d, y_h= %d, y_v= %d", |
| 480 | f->fmt->color, f->dma_offset.y_h, f->dma_offset.y_v); |
| 481 | } |
| 482 | |
Sachin Kamat | 7e566be | 2012-05-26 11:11:54 -0300 | [diff] [blame] | 483 | static int fimc_set_color_effect(struct fimc_ctx *ctx, enum v4l2_colorfx colorfx) |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 484 | { |
| 485 | struct fimc_effect *effect = &ctx->effect; |
| 486 | |
| 487 | switch (colorfx) { |
| 488 | case V4L2_COLORFX_NONE: |
| 489 | effect->type = FIMC_REG_CIIMGEFF_FIN_BYPASS; |
| 490 | break; |
| 491 | case V4L2_COLORFX_BW: |
| 492 | effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY; |
| 493 | effect->pat_cb = 128; |
| 494 | effect->pat_cr = 128; |
| 495 | break; |
| 496 | case V4L2_COLORFX_SEPIA: |
| 497 | effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY; |
| 498 | effect->pat_cb = 115; |
| 499 | effect->pat_cr = 145; |
| 500 | break; |
| 501 | case V4L2_COLORFX_NEGATIVE: |
| 502 | effect->type = FIMC_REG_CIIMGEFF_FIN_NEGATIVE; |
| 503 | break; |
| 504 | case V4L2_COLORFX_EMBOSS: |
| 505 | effect->type = FIMC_REG_CIIMGEFF_FIN_EMBOSSING; |
| 506 | break; |
| 507 | case V4L2_COLORFX_ART_FREEZE: |
| 508 | effect->type = FIMC_REG_CIIMGEFF_FIN_ARTFREEZE; |
| 509 | break; |
| 510 | case V4L2_COLORFX_SILHOUETTE: |
| 511 | effect->type = FIMC_REG_CIIMGEFF_FIN_SILHOUETTE; |
| 512 | break; |
| 513 | case V4L2_COLORFX_SET_CBCR: |
| 514 | effect->type = FIMC_REG_CIIMGEFF_FIN_ARBITRARY; |
| 515 | effect->pat_cb = ctx->ctrls.colorfx_cbcr->val >> 8; |
| 516 | effect->pat_cr = ctx->ctrls.colorfx_cbcr->val & 0xff; |
| 517 | break; |
| 518 | default: |
| 519 | return -EINVAL; |
| 520 | } |
| 521 | |
| 522 | return 0; |
| 523 | } |
| 524 | |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 525 | /* |
| 526 | * V4L2 controls handling |
| 527 | */ |
| 528 | #define ctrl_to_ctx(__ctrl) \ |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 529 | container_of((__ctrl)->handler, struct fimc_ctx, ctrls.handler) |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 530 | |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 531 | static int __fimc_s_ctrl(struct fimc_ctx *ctx, struct v4l2_ctrl *ctrl) |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 532 | { |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 533 | struct fimc_dev *fimc = ctx->fimc_dev; |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 534 | const struct fimc_variant *variant = fimc->variant; |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 535 | int ret = 0; |
| 536 | |
| 537 | if (ctrl->flags & V4L2_CTRL_FLAG_INACTIVE) |
| 538 | return 0; |
| 539 | |
| 540 | switch (ctrl->id) { |
| 541 | case V4L2_CID_HFLIP: |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 542 | ctx->hflip = ctrl->val; |
| 543 | break; |
| 544 | |
| 545 | case V4L2_CID_VFLIP: |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 546 | ctx->vflip = ctrl->val; |
| 547 | break; |
| 548 | |
| 549 | case V4L2_CID_ROTATE: |
Sylwester Nawrocki | 81619ce | 2013-01-30 09:54:06 -0300 | [diff] [blame] | 550 | if (fimc_capture_pending(fimc)) { |
Sylwester Nawrocki | ee7160e | 2011-08-26 14:57:06 -0300 | [diff] [blame] | 551 | ret = fimc_check_scaler_ratio(ctx, ctx->s_frame.width, |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 552 | ctx->s_frame.height, ctx->d_frame.width, |
| 553 | ctx->d_frame.height, ctrl->val); |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 554 | if (ret) |
| 555 | return -EINVAL; |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 556 | } |
| 557 | if ((ctrl->val == 90 || ctrl->val == 270) && |
| 558 | !variant->has_out_rot) |
| 559 | return -EINVAL; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 560 | |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 561 | ctx->rotation = ctrl->val; |
| 562 | break; |
| 563 | |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 564 | case V4L2_CID_ALPHA_COMPONENT: |
| 565 | ctx->d_frame.alpha = ctrl->val; |
| 566 | break; |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 567 | |
| 568 | case V4L2_CID_COLORFX: |
| 569 | ret = fimc_set_color_effect(ctx, ctrl->val); |
| 570 | if (ret) |
| 571 | return ret; |
| 572 | break; |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 573 | } |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 574 | |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 575 | ctx->state |= FIMC_PARAMS; |
| 576 | set_bit(ST_CAPT_APPLY_CFG, &fimc->state); |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 577 | return 0; |
| 578 | } |
| 579 | |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 580 | static int fimc_s_ctrl(struct v4l2_ctrl *ctrl) |
| 581 | { |
| 582 | struct fimc_ctx *ctx = ctrl_to_ctx(ctrl); |
| 583 | unsigned long flags; |
| 584 | int ret; |
| 585 | |
Sylwester Nawrocki | efb13c3 | 2012-03-19 13:11:40 -0300 | [diff] [blame] | 586 | spin_lock_irqsave(&ctx->fimc_dev->slock, flags); |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 587 | ret = __fimc_s_ctrl(ctx, ctrl); |
Sylwester Nawrocki | efb13c3 | 2012-03-19 13:11:40 -0300 | [diff] [blame] | 588 | spin_unlock_irqrestore(&ctx->fimc_dev->slock, flags); |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 589 | |
| 590 | return ret; |
| 591 | } |
| 592 | |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 593 | static const struct v4l2_ctrl_ops fimc_ctrl_ops = { |
| 594 | .s_ctrl = fimc_s_ctrl, |
| 595 | }; |
| 596 | |
| 597 | int fimc_ctrls_create(struct fimc_ctx *ctx) |
| 598 | { |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 599 | unsigned int max_alpha = fimc_get_alpha_mask(ctx->d_frame.fmt); |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 600 | struct fimc_ctrls *ctrls = &ctx->ctrls; |
| 601 | struct v4l2_ctrl_handler *handler = &ctrls->handler; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 602 | |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 603 | if (ctx->ctrls.ready) |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 604 | return 0; |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 605 | |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 606 | v4l2_ctrl_handler_init(handler, 6); |
| 607 | |
| 608 | ctrls->rotate = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops, |
Sachin Kamat | 53e5ab9 | 2012-01-10 05:46:57 -0300 | [diff] [blame] | 609 | V4L2_CID_ROTATE, 0, 270, 90, 0); |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 610 | ctrls->hflip = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops, |
Sachin Kamat | 53e5ab9 | 2012-01-10 05:46:57 -0300 | [diff] [blame] | 611 | V4L2_CID_HFLIP, 0, 1, 1, 0); |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 612 | ctrls->vflip = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops, |
Sachin Kamat | 53e5ab9 | 2012-01-10 05:46:57 -0300 | [diff] [blame] | 613 | V4L2_CID_VFLIP, 0, 1, 1, 0); |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 614 | |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 615 | if (ctx->fimc_dev->drv_data->alpha_color) |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 616 | ctrls->alpha = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops, |
| 617 | V4L2_CID_ALPHA_COMPONENT, |
| 618 | 0, max_alpha, 1, 0); |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 619 | else |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 620 | ctrls->alpha = NULL; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 621 | |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 622 | ctrls->colorfx = v4l2_ctrl_new_std_menu(handler, &fimc_ctrl_ops, |
| 623 | V4L2_CID_COLORFX, V4L2_COLORFX_SET_CBCR, |
| 624 | ~0x983f, V4L2_COLORFX_NONE); |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 625 | |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 626 | ctrls->colorfx_cbcr = v4l2_ctrl_new_std(handler, &fimc_ctrl_ops, |
| 627 | V4L2_CID_COLORFX_CBCR, 0, 0xffff, 1, 0); |
| 628 | |
| 629 | ctx->effect.type = FIMC_REG_CIIMGEFF_FIN_BYPASS; |
| 630 | |
| 631 | if (!handler->error) { |
Kamil Debski | 4c4ed22 | 2012-06-15 13:40:32 -0300 | [diff] [blame] | 632 | v4l2_ctrl_cluster(2, &ctrls->colorfx); |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 633 | ctrls->ready = true; |
| 634 | } |
| 635 | |
| 636 | return handler->error; |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | void fimc_ctrls_delete(struct fimc_ctx *ctx) |
| 640 | { |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 641 | struct fimc_ctrls *ctrls = &ctx->ctrls; |
| 642 | |
| 643 | if (ctrls->ready) { |
| 644 | v4l2_ctrl_handler_free(&ctrls->handler); |
| 645 | ctrls->ready = false; |
| 646 | ctrls->alpha = NULL; |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 647 | } |
| 648 | } |
| 649 | |
| 650 | void fimc_ctrls_activate(struct fimc_ctx *ctx, bool active) |
| 651 | { |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 652 | unsigned int has_alpha = ctx->d_frame.fmt->flags & FMT_HAS_ALPHA; |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 653 | struct fimc_ctrls *ctrls = &ctx->ctrls; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 654 | |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 655 | if (!ctrls->ready) |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 656 | return; |
| 657 | |
Sylwester Nawrocki | 8183e7a | 2012-05-25 07:04:01 -0300 | [diff] [blame] | 658 | mutex_lock(ctrls->handler.lock); |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 659 | v4l2_ctrl_activate(ctrls->rotate, active); |
| 660 | v4l2_ctrl_activate(ctrls->hflip, active); |
| 661 | v4l2_ctrl_activate(ctrls->vflip, active); |
| 662 | v4l2_ctrl_activate(ctrls->colorfx, active); |
| 663 | if (ctrls->alpha) |
| 664 | v4l2_ctrl_activate(ctrls->alpha, active && has_alpha); |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 665 | |
| 666 | if (active) { |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 667 | fimc_set_color_effect(ctx, ctrls->colorfx->cur.val); |
| 668 | ctx->rotation = ctrls->rotate->val; |
| 669 | ctx->hflip = ctrls->hflip->val; |
| 670 | ctx->vflip = ctrls->vflip->val; |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 671 | } else { |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 672 | ctx->effect.type = FIMC_REG_CIIMGEFF_FIN_BYPASS; |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 673 | ctx->rotation = 0; |
| 674 | ctx->hflip = 0; |
| 675 | ctx->vflip = 0; |
| 676 | } |
Sylwester Nawrocki | 8183e7a | 2012-05-25 07:04:01 -0300 | [diff] [blame] | 677 | mutex_unlock(ctrls->handler.lock); |
Sylwester Nawrocki | 131b6c6 | 2011-08-24 19:25:10 -0300 | [diff] [blame] | 678 | } |
| 679 | |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 680 | /* Update maximum value of the alpha color control */ |
| 681 | void fimc_alpha_ctrl_update(struct fimc_ctx *ctx) |
| 682 | { |
| 683 | struct fimc_dev *fimc = ctx->fimc_dev; |
Sylwester Nawrocki | 9448ab7 | 2012-04-02 06:41:22 -0300 | [diff] [blame] | 684 | struct v4l2_ctrl *ctrl = ctx->ctrls.alpha; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 685 | |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 686 | if (ctrl == NULL || !fimc->drv_data->alpha_color) |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 687 | return; |
| 688 | |
| 689 | v4l2_ctrl_lock(ctrl); |
| 690 | ctrl->maximum = fimc_get_alpha_mask(ctx->d_frame.fmt); |
| 691 | |
| 692 | if (ctrl->cur.val > ctrl->maximum) |
| 693 | ctrl->cur.val = ctrl->maximum; |
| 694 | |
| 695 | v4l2_ctrl_unlock(ctrl); |
| 696 | } |
| 697 | |
Sylwester Nawrocki | fa8880b | 2013-01-11 06:36:19 -0300 | [diff] [blame] | 698 | void __fimc_get_format(struct fimc_frame *frame, struct v4l2_format *f) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 699 | { |
Sylwester Nawrocki | e578588 | 2011-06-10 15:36:50 -0300 | [diff] [blame] | 700 | struct v4l2_pix_format_mplane *pixm = &f->fmt.pix_mp; |
Sylwester Nawrocki | 91707b8 | 2011-01-15 01:17:42 -0300 | [diff] [blame] | 701 | int i; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 702 | |
Sylwester Nawrocki | e578588 | 2011-06-10 15:36:50 -0300 | [diff] [blame] | 703 | pixm->width = frame->o_width; |
| 704 | pixm->height = frame->o_height; |
| 705 | pixm->field = V4L2_FIELD_NONE; |
| 706 | pixm->pixelformat = frame->fmt->fourcc; |
| 707 | pixm->colorspace = V4L2_COLORSPACE_JPEG; |
| 708 | pixm->num_planes = frame->fmt->memplanes; |
Sylwester Nawrocki | 91707b8 | 2011-01-15 01:17:42 -0300 | [diff] [blame] | 709 | |
| 710 | for (i = 0; i < pixm->num_planes; ++i) { |
Sylwester Nawrocki | fa8880b | 2013-01-11 06:36:19 -0300 | [diff] [blame] | 711 | pixm->plane_fmt[i].bytesperline = frame->bytesperline[i]; |
| 712 | pixm->plane_fmt[i].sizeimage = frame->payload[i]; |
Sylwester Nawrocki | 91707b8 | 2011-01-15 01:17:42 -0300 | [diff] [blame] | 713 | } |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 714 | } |
| 715 | |
Sylwester Nawrocki | 4db5e27 | 2011-08-26 14:51:00 -0300 | [diff] [blame] | 716 | /** |
| 717 | * fimc_adjust_mplane_format - adjust bytesperline/sizeimage for each plane |
| 718 | * @fmt: fimc pixel format description (input) |
| 719 | * @width: requested pixel width |
| 720 | * @height: requested pixel height |
| 721 | * @pix: multi-plane format to adjust |
| 722 | */ |
| 723 | void fimc_adjust_mplane_format(struct fimc_fmt *fmt, u32 width, u32 height, |
| 724 | struct v4l2_pix_format_mplane *pix) |
| 725 | { |
| 726 | u32 bytesperline = 0; |
| 727 | int i; |
| 728 | |
| 729 | pix->colorspace = V4L2_COLORSPACE_JPEG; |
| 730 | pix->field = V4L2_FIELD_NONE; |
| 731 | pix->num_planes = fmt->memplanes; |
Sylwester Nawrocki | dafb9c7 | 2011-12-01 14:02:24 -0300 | [diff] [blame] | 732 | pix->pixelformat = fmt->fourcc; |
Sylwester Nawrocki | 4db5e27 | 2011-08-26 14:51:00 -0300 | [diff] [blame] | 733 | pix->height = height; |
| 734 | pix->width = width; |
| 735 | |
| 736 | for (i = 0; i < pix->num_planes; ++i) { |
Sylwester Nawrocki | d547ab6 | 2012-05-16 15:00:26 -0300 | [diff] [blame] | 737 | struct v4l2_plane_pix_format *plane_fmt = &pix->plane_fmt[i]; |
| 738 | u32 bpl = plane_fmt->bytesperline; |
Sylwester Nawrocki | 4db5e27 | 2011-08-26 14:51:00 -0300 | [diff] [blame] | 739 | |
| 740 | if (fmt->colplanes > 1 && (bpl == 0 || bpl < pix->width)) |
| 741 | bpl = pix->width; /* Planar */ |
| 742 | |
| 743 | if (fmt->colplanes == 1 && /* Packed */ |
| 744 | (bpl == 0 || ((bpl * 8) / fmt->depth[i]) < pix->width)) |
| 745 | bpl = (pix->width * fmt->depth[0]) / 8; |
Sylwester Nawrocki | fa8880b | 2013-01-11 06:36:19 -0300 | [diff] [blame] | 746 | /* |
| 747 | * Currently bytesperline for each plane is same, except |
| 748 | * V4L2_PIX_FMT_YUV420M format. This calculation may need |
| 749 | * to be changed when other multi-planar formats are added |
| 750 | * to the fimc_formats[] array. |
| 751 | */ |
| 752 | if (i == 0) |
Sylwester Nawrocki | 4db5e27 | 2011-08-26 14:51:00 -0300 | [diff] [blame] | 753 | bytesperline = bpl; |
Sylwester Nawrocki | fa8880b | 2013-01-11 06:36:19 -0300 | [diff] [blame] | 754 | else if (i == 1 && fmt->memplanes == 3) |
| 755 | bytesperline /= 2; |
Sylwester Nawrocki | 4db5e27 | 2011-08-26 14:51:00 -0300 | [diff] [blame] | 756 | |
Sylwester Nawrocki | d547ab6 | 2012-05-16 15:00:26 -0300 | [diff] [blame] | 757 | plane_fmt->bytesperline = bytesperline; |
| 758 | plane_fmt->sizeimage = max((pix->width * pix->height * |
| 759 | fmt->depth[i]) / 8, plane_fmt->sizeimage); |
Sylwester Nawrocki | 4db5e27 | 2011-08-26 14:51:00 -0300 | [diff] [blame] | 760 | } |
| 761 | } |
| 762 | |
Sylwester Nawrocki | cf52df8 | 2011-06-13 11:09:40 -0300 | [diff] [blame] | 763 | /** |
| 764 | * fimc_find_format - lookup fimc color format by fourcc or media bus format |
| 765 | * @pixelformat: fourcc to match, ignored if null |
| 766 | * @mbus_code: media bus code to match, ignored if null |
| 767 | * @mask: the color flags to match |
| 768 | * @index: offset in the fimc_formats array, ignored if negative |
| 769 | */ |
Sylwester Nawrocki | 63746be | 2012-04-22 17:07:09 -0300 | [diff] [blame] | 770 | struct fimc_fmt *fimc_find_format(const u32 *pixelformat, const u32 *mbus_code, |
Sylwester Nawrocki | cf52df8 | 2011-06-13 11:09:40 -0300 | [diff] [blame] | 771 | unsigned int mask, int index) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 772 | { |
Sylwester Nawrocki | cf52df8 | 2011-06-13 11:09:40 -0300 | [diff] [blame] | 773 | struct fimc_fmt *fmt, *def_fmt = NULL; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 774 | unsigned int i; |
Sylwester Nawrocki | cf52df8 | 2011-06-13 11:09:40 -0300 | [diff] [blame] | 775 | int id = 0; |
| 776 | |
Sylwester Nawrocki | 63746be | 2012-04-22 17:07:09 -0300 | [diff] [blame] | 777 | if (index >= (int)ARRAY_SIZE(fimc_formats)) |
Sylwester Nawrocki | cf52df8 | 2011-06-13 11:09:40 -0300 | [diff] [blame] | 778 | return NULL; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 779 | |
| 780 | for (i = 0; i < ARRAY_SIZE(fimc_formats); ++i) { |
| 781 | fmt = &fimc_formats[i]; |
Sylwester Nawrocki | cf52df8 | 2011-06-13 11:09:40 -0300 | [diff] [blame] | 782 | if (!(fmt->flags & mask)) |
| 783 | continue; |
| 784 | if (pixelformat && fmt->fourcc == *pixelformat) |
| 785 | return fmt; |
| 786 | if (mbus_code && fmt->mbus_code == *mbus_code) |
| 787 | return fmt; |
| 788 | if (index == id) |
| 789 | def_fmt = fmt; |
| 790 | id++; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 791 | } |
Sylwester Nawrocki | cf52df8 | 2011-06-13 11:09:40 -0300 | [diff] [blame] | 792 | return def_fmt; |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 793 | } |
| 794 | |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 795 | static void fimc_clk_put(struct fimc_dev *fimc) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 796 | { |
| 797 | int i; |
Sylwester Nawrocki | 6ec0163 | 2012-03-17 18:31:33 -0300 | [diff] [blame] | 798 | for (i = 0; i < MAX_FIMC_CLOCKS; i++) { |
Sylwester Nawrocki | b71b56b | 2013-01-29 06:42:28 -0300 | [diff] [blame] | 799 | if (IS_ERR(fimc->clock[i])) |
Sylwester Nawrocki | bd7d888 | 2012-01-30 11:39:30 -0300 | [diff] [blame] | 800 | continue; |
| 801 | clk_unprepare(fimc->clock[i]); |
| 802 | clk_put(fimc->clock[i]); |
Sylwester Nawrocki | b71b56b | 2013-01-29 06:42:28 -0300 | [diff] [blame] | 803 | fimc->clock[i] = ERR_PTR(-EINVAL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 804 | } |
| 805 | } |
| 806 | |
| 807 | static int fimc_clk_get(struct fimc_dev *fimc) |
| 808 | { |
Sylwester Nawrocki | bd7d888 | 2012-01-30 11:39:30 -0300 | [diff] [blame] | 809 | int i, ret; |
| 810 | |
Sylwester Nawrocki | b71b56b | 2013-01-29 06:42:28 -0300 | [diff] [blame] | 811 | for (i = 0; i < MAX_FIMC_CLOCKS; i++) |
| 812 | fimc->clock[i] = ERR_PTR(-EINVAL); |
| 813 | |
Sylwester Nawrocki | 6ec0163 | 2012-03-17 18:31:33 -0300 | [diff] [blame] | 814 | for (i = 0; i < MAX_FIMC_CLOCKS; i++) { |
Sylwester Nawrocki | a25be18 | 2010-12-27 15:34:43 -0300 | [diff] [blame] | 815 | fimc->clock[i] = clk_get(&fimc->pdev->dev, fimc_clocks[i]); |
Sylwester Nawrocki | b71b56b | 2013-01-29 06:42:28 -0300 | [diff] [blame] | 816 | if (IS_ERR(fimc->clock[i])) { |
| 817 | ret = PTR_ERR(fimc->clock[i]); |
Sylwester Nawrocki | bd7d888 | 2012-01-30 11:39:30 -0300 | [diff] [blame] | 818 | goto err; |
Sylwester Nawrocki | b71b56b | 2013-01-29 06:42:28 -0300 | [diff] [blame] | 819 | } |
Sylwester Nawrocki | bd7d888 | 2012-01-30 11:39:30 -0300 | [diff] [blame] | 820 | ret = clk_prepare(fimc->clock[i]); |
| 821 | if (ret < 0) { |
| 822 | clk_put(fimc->clock[i]); |
Sylwester Nawrocki | b71b56b | 2013-01-29 06:42:28 -0300 | [diff] [blame] | 823 | fimc->clock[i] = ERR_PTR(-EINVAL); |
Sylwester Nawrocki | bd7d888 | 2012-01-30 11:39:30 -0300 | [diff] [blame] | 824 | goto err; |
| 825 | } |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 826 | } |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 827 | return 0; |
Sylwester Nawrocki | bd7d888 | 2012-01-30 11:39:30 -0300 | [diff] [blame] | 828 | err: |
| 829 | fimc_clk_put(fimc); |
| 830 | dev_err(&fimc->pdev->dev, "failed to get clock: %s\n", |
| 831 | fimc_clocks[i]); |
| 832 | return -ENXIO; |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 833 | } |
| 834 | |
| 835 | static int fimc_m2m_suspend(struct fimc_dev *fimc) |
| 836 | { |
| 837 | unsigned long flags; |
| 838 | int timeout; |
| 839 | |
| 840 | spin_lock_irqsave(&fimc->slock, flags); |
| 841 | if (!fimc_m2m_pending(fimc)) { |
| 842 | spin_unlock_irqrestore(&fimc->slock, flags); |
| 843 | return 0; |
| 844 | } |
| 845 | clear_bit(ST_M2M_SUSPENDED, &fimc->state); |
| 846 | set_bit(ST_M2M_SUSPENDING, &fimc->state); |
| 847 | spin_unlock_irqrestore(&fimc->slock, flags); |
| 848 | |
| 849 | timeout = wait_event_timeout(fimc->irq_queue, |
| 850 | test_bit(ST_M2M_SUSPENDED, &fimc->state), |
| 851 | FIMC_SHUTDOWN_TIMEOUT); |
| 852 | |
| 853 | clear_bit(ST_M2M_SUSPENDING, &fimc->state); |
| 854 | return timeout == 0 ? -EAGAIN : 0; |
| 855 | } |
| 856 | |
| 857 | static int fimc_m2m_resume(struct fimc_dev *fimc) |
| 858 | { |
Shaik Ameer Basha | e34a89b | 2013-02-06 01:47:10 -0300 | [diff] [blame] | 859 | struct fimc_ctx *ctx; |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 860 | unsigned long flags; |
| 861 | |
| 862 | spin_lock_irqsave(&fimc->slock, flags); |
| 863 | /* Clear for full H/W setup in first run after resume */ |
Shaik Ameer Basha | e34a89b | 2013-02-06 01:47:10 -0300 | [diff] [blame] | 864 | ctx = fimc->m2m.ctx; |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 865 | fimc->m2m.ctx = NULL; |
| 866 | spin_unlock_irqrestore(&fimc->slock, flags); |
| 867 | |
| 868 | if (test_and_clear_bit(ST_M2M_SUSPENDED, &fimc->state)) |
Shaik Ameer Basha | e34a89b | 2013-02-06 01:47:10 -0300 | [diff] [blame] | 869 | fimc_m2m_job_finish(ctx, VB2_BUF_STATE_ERROR); |
| 870 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 871 | return 0; |
| 872 | } |
| 873 | |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 874 | static const struct of_device_id fimc_of_match[]; |
| 875 | |
| 876 | static int fimc_parse_dt(struct fimc_dev *fimc, u32 *clk_freq) |
| 877 | { |
| 878 | struct device *dev = &fimc->pdev->dev; |
| 879 | struct device_node *node = dev->of_node; |
| 880 | const struct of_device_id *of_id; |
| 881 | struct fimc_variant *v; |
| 882 | struct fimc_pix_limit *lim; |
| 883 | u32 args[FIMC_PIX_LIMITS_MAX]; |
| 884 | int ret; |
| 885 | |
| 886 | if (of_property_read_bool(node, "samsung,lcd-wb")) |
| 887 | return -ENODEV; |
| 888 | |
| 889 | v = devm_kzalloc(dev, sizeof(*v) + sizeof(*lim), GFP_KERNEL); |
| 890 | if (!v) |
| 891 | return -ENOMEM; |
| 892 | |
| 893 | of_id = of_match_node(fimc_of_match, node); |
| 894 | if (!of_id) |
| 895 | return -EINVAL; |
| 896 | fimc->drv_data = of_id->data; |
| 897 | ret = of_property_read_u32_array(node, "samsung,pix-limits", |
| 898 | args, FIMC_PIX_LIMITS_MAX); |
| 899 | if (ret < 0) |
| 900 | return ret; |
| 901 | |
| 902 | lim = (struct fimc_pix_limit *)&v[1]; |
| 903 | |
| 904 | lim->scaler_en_w = args[0]; |
| 905 | lim->scaler_dis_w = args[1]; |
| 906 | lim->out_rot_en_w = args[2]; |
| 907 | lim->out_rot_dis_w = args[3]; |
| 908 | v->pix_limit = lim; |
| 909 | |
| 910 | ret = of_property_read_u32_array(node, "samsung,min-pix-sizes", |
| 911 | args, 2); |
| 912 | v->min_inp_pixsize = ret ? FIMC_DEF_MIN_SIZE : args[0]; |
| 913 | v->min_out_pixsize = ret ? FIMC_DEF_MIN_SIZE : args[1]; |
| 914 | ret = of_property_read_u32_array(node, "samsung,min-pix-alignment", |
| 915 | args, 2); |
| 916 | v->min_vsize_align = ret ? FIMC_DEF_HEIGHT_ALIGN : args[0]; |
| 917 | v->hor_offs_align = ret ? FIMC_DEF_HOR_OFFS_ALIGN : args[1]; |
| 918 | |
| 919 | ret = of_property_read_u32(node, "samsung,rotators", &args[1]); |
| 920 | v->has_inp_rot = ret ? 1 : args[1] & 0x01; |
| 921 | v->has_out_rot = ret ? 1 : args[1] & 0x10; |
| 922 | v->has_mainscaler_ext = of_property_read_bool(node, |
| 923 | "samsung,mainscaler-ext"); |
| 924 | |
| 925 | v->has_isp_wb = of_property_read_bool(node, "samsung,isp-wb"); |
| 926 | v->has_cam_if = of_property_read_bool(node, "samsung,cam-if"); |
| 927 | of_property_read_u32(node, "clock-frequency", clk_freq); |
| 928 | fimc->id = of_alias_get_id(node, "fimc"); |
| 929 | |
| 930 | fimc->variant = v; |
| 931 | return 0; |
| 932 | } |
| 933 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 934 | static int fimc_probe(struct platform_device *pdev) |
| 935 | { |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 936 | struct device *dev = &pdev->dev; |
| 937 | u32 lclk_freq = 0; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 938 | struct fimc_dev *fimc; |
| 939 | struct resource *res; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 940 | int ret = 0; |
| 941 | |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 942 | fimc = devm_kzalloc(dev, sizeof(*fimc), GFP_KERNEL); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 943 | if (!fimc) |
| 944 | return -ENOMEM; |
| 945 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 946 | fimc->pdev = pdev; |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 947 | |
| 948 | if (dev->of_node) { |
| 949 | ret = fimc_parse_dt(fimc, &lclk_freq); |
| 950 | if (ret < 0) |
| 951 | return ret; |
| 952 | } else { |
| 953 | fimc->drv_data = fimc_get_drvdata(pdev); |
| 954 | fimc->id = pdev->id; |
| 955 | } |
| 956 | if (!fimc->drv_data || fimc->id >= fimc->drv_data->num_entities || |
| 957 | fimc->id < 0) { |
Sachin Kamat | 38c602b | 2013-04-16 03:02:19 -0300 | [diff] [blame] | 958 | dev_err(dev, "Invalid driver data or device id (%d)\n", |
| 959 | fimc->id); |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 960 | return -EINVAL; |
| 961 | } |
| 962 | if (!dev->of_node) |
| 963 | fimc->variant = fimc->drv_data->variant[fimc->id]; |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 964 | |
Sylwester Nawrocki | 5f3cc44 | 2010-10-07 10:06:16 -0300 | [diff] [blame] | 965 | init_waitqueue_head(&fimc->irq_queue); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 966 | spin_lock_init(&fimc->slock); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 967 | mutex_init(&fimc->lock); |
| 968 | |
Sylwester Nawrocki | b3d8b55 | 2013-03-31 20:31:02 -0300 | [diff] [blame] | 969 | fimc->sysreg = fimc_get_sysreg_regmap(dev->of_node); |
Sylwester Nawrocki | 88fa831 | 2013-03-20 10:44:39 -0300 | [diff] [blame] | 970 | if (IS_ERR(fimc->sysreg)) |
| 971 | return PTR_ERR(fimc->sysreg); |
| 972 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 973 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 974 | fimc->regs = devm_ioremap_resource(dev, res); |
Thierry Reding | f23999e | 2013-01-21 06:09:07 -0300 | [diff] [blame] | 975 | if (IS_ERR(fimc->regs)) |
| 976 | return PTR_ERR(fimc->regs); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 977 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 978 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
Sylwester Nawrocki | 6d91a51 | 2012-01-30 11:37:59 -0300 | [diff] [blame] | 979 | if (res == NULL) { |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 980 | dev_err(dev, "Failed to get IRQ resource\n"); |
Sylwester Nawrocki | 6d91a51 | 2012-01-30 11:37:59 -0300 | [diff] [blame] | 981 | return -ENXIO; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 982 | } |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 983 | |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 984 | ret = fimc_clk_get(fimc); |
| 985 | if (ret) |
Sylwester Nawrocki | 6d91a51 | 2012-01-30 11:37:59 -0300 | [diff] [blame] | 986 | return ret; |
Sylwester Nawrocki | b71b56b | 2013-01-29 06:42:28 -0300 | [diff] [blame] | 987 | |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 988 | if (lclk_freq == 0) |
| 989 | lclk_freq = fimc->drv_data->lclk_frequency; |
| 990 | |
| 991 | ret = clk_set_rate(fimc->clock[CLK_BUS], lclk_freq); |
Sylwester Nawrocki | b71b56b | 2013-01-29 06:42:28 -0300 | [diff] [blame] | 992 | if (ret < 0) |
| 993 | return ret; |
| 994 | |
| 995 | ret = clk_enable(fimc->clock[CLK_BUS]); |
| 996 | if (ret < 0) |
| 997 | return ret; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 998 | |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 999 | ret = devm_request_irq(dev, res->start, fimc_irq_handler, |
| 1000 | 0, dev_name(dev), fimc); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1001 | if (ret) { |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1002 | dev_err(dev, "failed to install irq (%d)\n", ret); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1003 | goto err_clk; |
| 1004 | } |
| 1005 | |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1006 | ret = fimc_initialize_capture_subdev(fimc); |
| 1007 | if (ret) |
| 1008 | goto err_clk; |
| 1009 | |
| 1010 | platform_set_drvdata(pdev, fimc); |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1011 | pm_runtime_enable(dev); |
| 1012 | ret = pm_runtime_get_sync(dev); |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1013 | if (ret < 0) |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1014 | goto err_sd; |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 1015 | /* Initialize contiguous memory allocator */ |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1016 | fimc->alloc_ctx = vb2_dma_contig_init_ctx(dev); |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 1017 | if (IS_ERR(fimc->alloc_ctx)) { |
| 1018 | ret = PTR_ERR(fimc->alloc_ctx); |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1019 | goto err_pm; |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 1020 | } |
| 1021 | |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1022 | dev_dbg(dev, "FIMC.%d registered successfully\n", fimc->id); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1023 | |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1024 | pm_runtime_put(dev); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1025 | return 0; |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1026 | err_pm: |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1027 | pm_runtime_put(dev); |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1028 | err_sd: |
| 1029 | fimc_unregister_capture_subdev(fimc); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1030 | err_clk: |
Sylwester Nawrocki | b71b56b | 2013-01-29 06:42:28 -0300 | [diff] [blame] | 1031 | clk_disable(fimc->clock[CLK_BUS]); |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1032 | fimc_clk_put(fimc); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1033 | return ret; |
| 1034 | } |
| 1035 | |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1036 | static int fimc_runtime_resume(struct device *dev) |
| 1037 | { |
| 1038 | struct fimc_dev *fimc = dev_get_drvdata(dev); |
| 1039 | |
| 1040 | dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state); |
| 1041 | |
| 1042 | /* Enable clocks and perform basic initalization */ |
| 1043 | clk_enable(fimc->clock[CLK_GATE]); |
| 1044 | fimc_hw_reset(fimc); |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1045 | |
| 1046 | /* Resume the capture or mem-to-mem device */ |
| 1047 | if (fimc_capture_busy(fimc)) |
| 1048 | return fimc_capture_resume(fimc); |
Sylwester Nawrocki | f664684 | 2011-11-17 06:23:21 -0300 | [diff] [blame] | 1049 | |
| 1050 | return fimc_m2m_resume(fimc); |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1051 | } |
| 1052 | |
| 1053 | static int fimc_runtime_suspend(struct device *dev) |
| 1054 | { |
| 1055 | struct fimc_dev *fimc = dev_get_drvdata(dev); |
| 1056 | int ret = 0; |
| 1057 | |
| 1058 | if (fimc_capture_busy(fimc)) |
| 1059 | ret = fimc_capture_suspend(fimc); |
| 1060 | else |
| 1061 | ret = fimc_m2m_suspend(fimc); |
| 1062 | if (!ret) |
| 1063 | clk_disable(fimc->clock[CLK_GATE]); |
| 1064 | |
| 1065 | dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state); |
| 1066 | return ret; |
| 1067 | } |
| 1068 | |
| 1069 | #ifdef CONFIG_PM_SLEEP |
| 1070 | static int fimc_resume(struct device *dev) |
| 1071 | { |
| 1072 | struct fimc_dev *fimc = dev_get_drvdata(dev); |
| 1073 | unsigned long flags; |
| 1074 | |
| 1075 | dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state); |
| 1076 | |
| 1077 | /* Do not resume if the device was idle before system suspend */ |
| 1078 | spin_lock_irqsave(&fimc->slock, flags); |
| 1079 | if (!test_and_clear_bit(ST_LPM, &fimc->state) || |
| 1080 | (!fimc_m2m_active(fimc) && !fimc_capture_busy(fimc))) { |
| 1081 | spin_unlock_irqrestore(&fimc->slock, flags); |
| 1082 | return 0; |
| 1083 | } |
| 1084 | fimc_hw_reset(fimc); |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1085 | spin_unlock_irqrestore(&fimc->slock, flags); |
| 1086 | |
| 1087 | if (fimc_capture_busy(fimc)) |
| 1088 | return fimc_capture_resume(fimc); |
| 1089 | |
| 1090 | return fimc_m2m_resume(fimc); |
| 1091 | } |
| 1092 | |
| 1093 | static int fimc_suspend(struct device *dev) |
| 1094 | { |
| 1095 | struct fimc_dev *fimc = dev_get_drvdata(dev); |
| 1096 | |
| 1097 | dbg("fimc%d: state: 0x%lx", fimc->id, fimc->state); |
| 1098 | |
| 1099 | if (test_and_set_bit(ST_LPM, &fimc->state)) |
| 1100 | return 0; |
| 1101 | if (fimc_capture_busy(fimc)) |
| 1102 | return fimc_capture_suspend(fimc); |
| 1103 | |
| 1104 | return fimc_m2m_suspend(fimc); |
| 1105 | } |
| 1106 | #endif /* CONFIG_PM_SLEEP */ |
| 1107 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1108 | static int fimc_remove(struct platform_device *pdev) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1109 | { |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1110 | struct fimc_dev *fimc = platform_get_drvdata(pdev); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1111 | |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1112 | pm_runtime_disable(&pdev->dev); |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1113 | pm_runtime_set_suspended(&pdev->dev); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1114 | |
Sylwester Nawrocki | 693f5c4 | 2012-04-20 18:57:25 -0300 | [diff] [blame] | 1115 | fimc_unregister_capture_subdev(fimc); |
Sylwester Nawrocki | 2dab38e | 2010-12-01 10:14:59 -0300 | [diff] [blame] | 1116 | vb2_dma_contig_cleanup_ctx(fimc->alloc_ctx); |
| 1117 | |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1118 | clk_disable(fimc->clock[CLK_BUS]); |
| 1119 | fimc_clk_put(fimc); |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 1120 | |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1121 | dev_info(&pdev->dev, "driver unloaded\n"); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1122 | return 0; |
| 1123 | } |
| 1124 | |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1125 | /* Image pixel limits, similar across several FIMC HW revisions. */ |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 1126 | static const struct fimc_pix_limit s5p_pix_limit[4] = { |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1127 | [0] = { |
| 1128 | .scaler_en_w = 3264, |
| 1129 | .scaler_dis_w = 8192, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1130 | .out_rot_en_w = 1920, |
| 1131 | .out_rot_dis_w = 4224, |
| 1132 | }, |
| 1133 | [1] = { |
| 1134 | .scaler_en_w = 4224, |
| 1135 | .scaler_dis_w = 8192, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1136 | .out_rot_en_w = 1920, |
| 1137 | .out_rot_dis_w = 4224, |
| 1138 | }, |
| 1139 | [2] = { |
| 1140 | .scaler_en_w = 1920, |
| 1141 | .scaler_dis_w = 8192, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1142 | .out_rot_en_w = 1280, |
| 1143 | .out_rot_dis_w = 1920, |
| 1144 | }, |
| 1145 | }; |
| 1146 | |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 1147 | static const struct fimc_variant fimc0_variant_s5p = { |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1148 | .has_inp_rot = 1, |
| 1149 | .has_out_rot = 1, |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1150 | .has_cam_if = 1, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1151 | .min_inp_pixsize = 16, |
| 1152 | .min_out_pixsize = 16, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1153 | .hor_offs_align = 8, |
Sylwester Nawrocki | 9c63afc | 2011-05-27 13:12:23 -0300 | [diff] [blame] | 1154 | .min_vsize_align = 16, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1155 | .pix_limit = &s5p_pix_limit[0], |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1156 | }; |
| 1157 | |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 1158 | static const struct fimc_variant fimc2_variant_s5p = { |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1159 | .has_cam_if = 1, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1160 | .min_inp_pixsize = 16, |
| 1161 | .min_out_pixsize = 16, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1162 | .hor_offs_align = 8, |
Sylwester Nawrocki | 9c63afc | 2011-05-27 13:12:23 -0300 | [diff] [blame] | 1163 | .min_vsize_align = 16, |
Sylwester Nawrocki | bb7c276 | 2012-04-27 09:33:23 -0300 | [diff] [blame] | 1164 | .pix_limit = &s5p_pix_limit[1], |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1165 | }; |
| 1166 | |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 1167 | static const struct fimc_variant fimc0_variant_s5pv210 = { |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1168 | .has_inp_rot = 1, |
| 1169 | .has_out_rot = 1, |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1170 | .has_cam_if = 1, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1171 | .min_inp_pixsize = 16, |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 1172 | .min_out_pixsize = 16, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1173 | .hor_offs_align = 8, |
Sylwester Nawrocki | 9c63afc | 2011-05-27 13:12:23 -0300 | [diff] [blame] | 1174 | .min_vsize_align = 16, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1175 | .pix_limit = &s5p_pix_limit[1], |
| 1176 | }; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1177 | |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 1178 | static const struct fimc_variant fimc1_variant_s5pv210 = { |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1179 | .has_inp_rot = 1, |
| 1180 | .has_out_rot = 1, |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1181 | .has_cam_if = 1, |
Hyunwoong Kim | b241c6d | 2010-12-28 11:27:13 -0300 | [diff] [blame] | 1182 | .has_mainscaler_ext = 1, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1183 | .min_inp_pixsize = 16, |
| 1184 | .min_out_pixsize = 16, |
| 1185 | .hor_offs_align = 1, |
Sylwester Nawrocki | 9c63afc | 2011-05-27 13:12:23 -0300 | [diff] [blame] | 1186 | .min_vsize_align = 1, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1187 | .pix_limit = &s5p_pix_limit[2], |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1188 | }; |
| 1189 | |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 1190 | static const struct fimc_variant fimc2_variant_s5pv210 = { |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1191 | .has_cam_if = 1, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1192 | .min_inp_pixsize = 16, |
Sylwester Nawrocki | 548aafc | 2010-10-08 05:01:14 -0300 | [diff] [blame] | 1193 | .min_out_pixsize = 16, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1194 | .hor_offs_align = 8, |
Sylwester Nawrocki | 9c63afc | 2011-05-27 13:12:23 -0300 | [diff] [blame] | 1195 | .min_vsize_align = 16, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1196 | .pix_limit = &s5p_pix_limit[2], |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1197 | }; |
| 1198 | |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1199 | /* S5PC100 */ |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 1200 | static const struct fimc_drvdata fimc_drvdata_s5p = { |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1201 | .variant = { |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1202 | [0] = &fimc0_variant_s5p, |
| 1203 | [1] = &fimc0_variant_s5p, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1204 | [2] = &fimc2_variant_s5p, |
| 1205 | }, |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1206 | .num_entities = 3, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1207 | .lclk_frequency = 133000000UL, |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1208 | .out_buf_count = 4, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1209 | }; |
| 1210 | |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1211 | /* S5PV210, S5PC110 */ |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 1212 | static const struct fimc_drvdata fimc_drvdata_s5pv210 = { |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1213 | .variant = { |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1214 | [0] = &fimc0_variant_s5pv210, |
| 1215 | [1] = &fimc1_variant_s5pv210, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1216 | [2] = &fimc2_variant_s5pv210, |
| 1217 | }, |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1218 | .num_entities = 3, |
| 1219 | .lclk_frequency = 166000000UL, |
| 1220 | .out_buf_count = 4, |
| 1221 | .dma_pix_hoff = 1, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1222 | }; |
| 1223 | |
Sylwester Nawrocki | bb7c276 | 2012-04-27 09:33:23 -0300 | [diff] [blame] | 1224 | /* EXYNOS4210, S5PV310, S5PC210 */ |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 1225 | static const struct fimc_drvdata fimc_drvdata_exynos4210 = { |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1226 | .num_entities = 4, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1227 | .lclk_frequency = 166000000UL, |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1228 | .dma_pix_hoff = 1, |
| 1229 | .cistatus2 = 1, |
| 1230 | .alpha_color = 1, |
| 1231 | .out_buf_count = 32, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1232 | }; |
| 1233 | |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 1234 | /* EXYNOS4212, EXYNOS4412 */ |
| 1235 | static const struct fimc_drvdata fimc_drvdata_exynos4x12 = { |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1236 | .num_entities = 4, |
| 1237 | .lclk_frequency = 166000000UL, |
| 1238 | .dma_pix_hoff = 1, |
| 1239 | .cistatus2 = 1, |
| 1240 | .alpha_color = 1, |
| 1241 | .out_buf_count = 32, |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 1242 | }; |
| 1243 | |
| 1244 | static const struct platform_device_id fimc_driver_ids[] = { |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1245 | { |
| 1246 | .name = "s5p-fimc", |
| 1247 | .driver_data = (unsigned long)&fimc_drvdata_s5p, |
| 1248 | }, { |
| 1249 | .name = "s5pv210-fimc", |
| 1250 | .driver_data = (unsigned long)&fimc_drvdata_s5pv210, |
Sylwester Nawrocki | a7d5bbc | 2010-10-11 13:19:27 -0300 | [diff] [blame] | 1251 | }, { |
Sylwester Nawrocki | 25b9875 | 2011-04-08 09:08:52 -0300 | [diff] [blame] | 1252 | .name = "exynos4-fimc", |
Sylwester Nawrocki | 405f230 | 2012-08-02 10:27:46 -0300 | [diff] [blame] | 1253 | .driver_data = (unsigned long)&fimc_drvdata_exynos4210, |
| 1254 | }, { |
| 1255 | .name = "exynos4x12-fimc", |
| 1256 | .driver_data = (unsigned long)&fimc_drvdata_exynos4x12, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1257 | }, |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1258 | { }, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1259 | }; |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1260 | |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1261 | static const struct of_device_id fimc_of_match[] = { |
| 1262 | { |
| 1263 | .compatible = "samsung,s5pv210-fimc", |
| 1264 | .data = &fimc_drvdata_s5pv210, |
| 1265 | }, { |
| 1266 | .compatible = "samsung,exynos4210-fimc", |
| 1267 | .data = &fimc_drvdata_exynos4210, |
| 1268 | }, { |
| 1269 | .compatible = "samsung,exynos4212-fimc", |
| 1270 | .data = &fimc_drvdata_exynos4x12, |
| 1271 | }, |
| 1272 | { /* sentinel */ }, |
| 1273 | }; |
| 1274 | |
Sylwester Nawrocki | e9e2108 | 2011-09-02 06:25:32 -0300 | [diff] [blame] | 1275 | static const struct dev_pm_ops fimc_pm_ops = { |
| 1276 | SET_SYSTEM_SLEEP_PM_OPS(fimc_suspend, fimc_resume) |
| 1277 | SET_RUNTIME_PM_OPS(fimc_runtime_suspend, fimc_runtime_resume, NULL) |
| 1278 | }; |
| 1279 | |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1280 | static struct platform_driver fimc_driver = { |
| 1281 | .probe = fimc_probe, |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 1282 | .remove = fimc_remove, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1283 | .id_table = fimc_driver_ids, |
| 1284 | .driver = { |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1285 | .of_match_table = fimc_of_match, |
Sylwester Nawrocki | aceb59e | 2013-04-23 11:36:04 -0300 | [diff] [blame] | 1286 | .name = FIMC_DRIVER_NAME, |
Sylwester Nawrocki | e80cb1f | 2013-03-26 08:22:21 -0300 | [diff] [blame] | 1287 | .owner = THIS_MODULE, |
| 1288 | .pm = &fimc_pm_ops, |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1289 | } |
| 1290 | }; |
| 1291 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1292 | int __init fimc_register_driver(void) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1293 | { |
Sylwester Nawrocki | ecd9acb | 2012-03-21 09:58:09 -0300 | [diff] [blame] | 1294 | return platform_driver_register(&fimc_driver); |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1295 | } |
| 1296 | |
Sylwester Nawrocki | d395322 | 2011-09-01 06:01:08 -0300 | [diff] [blame] | 1297 | void __exit fimc_unregister_driver(void) |
Sylwester Nawrocki | 5fd8f73 | 2010-08-03 09:50:29 -0300 | [diff] [blame] | 1298 | { |
| 1299 | platform_driver_unregister(&fimc_driver); |
| 1300 | } |