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