Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2012 Samsung Electronics Co.Ltd |
| 3 | * Authors: |
| 4 | * Eunchul Kim <chulspro.kim@samsung.com> |
| 5 | * Jinyoung Jeon <jy0.jeon@samsung.com> |
| 6 | * Sangmin Lee <lsmin.lee@samsung.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify it |
| 9 | * under the terms of the GNU General Public License as published by the |
| 10 | * Free Software Foundation; either version 2 of the License, or (at your |
| 11 | * option) any later version. |
| 12 | * |
| 13 | */ |
| 14 | #include <linux/kernel.h> |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 15 | #include <linux/component.h> |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
| 17 | #include <linux/clk.h> |
| 18 | #include <linux/pm_runtime.h> |
Seung-Woo Kim | aeefb36 | 2015-11-30 14:53:18 +0100 | [diff] [blame] | 19 | #include <linux/mfd/syscon.h> |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 20 | #include <linux/of_device.h> |
Seung-Woo Kim | aeefb36 | 2015-11-30 14:53:18 +0100 | [diff] [blame] | 21 | #include <linux/regmap.h> |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 22 | |
| 23 | #include <drm/drmP.h> |
| 24 | #include <drm/exynos_drm.h> |
| 25 | #include "regs-gsc.h" |
Mark Brown | e30655d | 2013-08-13 00:46:40 +0100 | [diff] [blame] | 26 | #include "exynos_drm_drv.h" |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 27 | #include "exynos_drm_ipp.h" |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 28 | |
| 29 | /* |
Eunchul Kim | 6fe891f | 2012-12-22 17:49:26 +0900 | [diff] [blame] | 30 | * GSC stands for General SCaler and |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 31 | * supports image scaler/rotator and input/output DMA operations. |
| 32 | * input DMA reads image data from the memory. |
| 33 | * output DMA writes image data to memory. |
| 34 | * GSC supports image rotation and image effect functions. |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 35 | */ |
| 36 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 37 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 38 | #define GSC_MAX_CLOCKS 8 |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 39 | #define GSC_MAX_SRC 4 |
| 40 | #define GSC_MAX_DST 16 |
| 41 | #define GSC_RESET_TIMEOUT 50 |
| 42 | #define GSC_BUF_STOP 1 |
| 43 | #define GSC_BUF_START 2 |
| 44 | #define GSC_REG_SZ 16 |
| 45 | #define GSC_WIDTH_ITU_709 1280 |
| 46 | #define GSC_SC_UP_MAX_RATIO 65536 |
| 47 | #define GSC_SC_DOWN_RATIO_7_8 74898 |
| 48 | #define GSC_SC_DOWN_RATIO_6_8 87381 |
| 49 | #define GSC_SC_DOWN_RATIO_5_8 104857 |
| 50 | #define GSC_SC_DOWN_RATIO_4_8 131072 |
| 51 | #define GSC_SC_DOWN_RATIO_3_8 174762 |
| 52 | #define GSC_SC_DOWN_RATIO_2_8 262144 |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 53 | #define GSC_CROP_MAX 8192 |
| 54 | #define GSC_CROP_MIN 32 |
| 55 | #define GSC_SCALE_MAX 4224 |
| 56 | #define GSC_SCALE_MIN 32 |
| 57 | #define GSC_COEF_RATIO 7 |
| 58 | #define GSC_COEF_PHASE 9 |
| 59 | #define GSC_COEF_ATTR 16 |
| 60 | #define GSC_COEF_H_8T 8 |
| 61 | #define GSC_COEF_V_4T 4 |
| 62 | #define GSC_COEF_DEPTH 3 |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 63 | #define GSC_AUTOSUSPEND_DELAY 2000 |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 64 | |
| 65 | #define get_gsc_context(dev) platform_get_drvdata(to_platform_device(dev)) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 66 | #define gsc_read(offset) readl(ctx->regs + (offset)) |
| 67 | #define gsc_write(cfg, offset) writel(cfg, ctx->regs + (offset)) |
| 68 | |
| 69 | /* |
| 70 | * A structure of scaler. |
| 71 | * |
| 72 | * @range: narrow, wide. |
| 73 | * @pre_shfactor: pre sclaer shift factor. |
| 74 | * @pre_hratio: horizontal ratio of the prescaler. |
| 75 | * @pre_vratio: vertical ratio of the prescaler. |
| 76 | * @main_hratio: the main scaler's horizontal ratio. |
| 77 | * @main_vratio: the main scaler's vertical ratio. |
| 78 | */ |
| 79 | struct gsc_scaler { |
| 80 | bool range; |
| 81 | u32 pre_shfactor; |
| 82 | u32 pre_hratio; |
| 83 | u32 pre_vratio; |
| 84 | unsigned long main_hratio; |
| 85 | unsigned long main_vratio; |
| 86 | }; |
| 87 | |
| 88 | /* |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 89 | * A structure of gsc context. |
| 90 | * |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 91 | * @regs_res: register resources. |
| 92 | * @regs: memory mapped io registers. |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 93 | * @gsc_clk: gsc gate clock. |
| 94 | * @sc: scaler infomations. |
| 95 | * @id: gsc id. |
| 96 | * @irq: irq number. |
| 97 | * @rotation: supports rotation of src. |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 98 | */ |
| 99 | struct gsc_context { |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 100 | struct exynos_drm_ipp ipp; |
| 101 | struct drm_device *drm_dev; |
| 102 | struct device *dev; |
| 103 | struct exynos_drm_ipp_task *task; |
| 104 | struct exynos_drm_ipp_formats *formats; |
| 105 | unsigned int num_formats; |
| 106 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 107 | struct resource *regs_res; |
| 108 | void __iomem *regs; |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 109 | const char **clk_names; |
| 110 | struct clk *clocks[GSC_MAX_CLOCKS]; |
| 111 | int num_clocks; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 112 | struct gsc_scaler sc; |
| 113 | int id; |
| 114 | int irq; |
| 115 | bool rotation; |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 116 | }; |
| 117 | |
| 118 | /** |
| 119 | * struct gsc_driverdata - per device type driver data for init time. |
| 120 | * |
| 121 | * @limits: picture size limits array |
| 122 | * @clk_names: names of clocks needed by this variant |
| 123 | * @num_clocks: the number of clocks needed by this variant |
| 124 | */ |
| 125 | struct gsc_driverdata { |
| 126 | const struct drm_exynos_ipp_limit *limits; |
| 127 | int num_limits; |
| 128 | const char *clk_names[GSC_MAX_CLOCKS]; |
| 129 | int num_clocks; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 130 | }; |
| 131 | |
| 132 | /* 8-tap Filter Coefficient */ |
| 133 | static const int h_coef_8t[GSC_COEF_RATIO][GSC_COEF_ATTR][GSC_COEF_H_8T] = { |
| 134 | { /* Ratio <= 65536 (~8:8) */ |
| 135 | { 0, 0, 0, 128, 0, 0, 0, 0 }, |
| 136 | { -1, 2, -6, 127, 7, -2, 1, 0 }, |
| 137 | { -1, 4, -12, 125, 16, -5, 1, 0 }, |
| 138 | { -1, 5, -15, 120, 25, -8, 2, 0 }, |
| 139 | { -1, 6, -18, 114, 35, -10, 3, -1 }, |
| 140 | { -1, 6, -20, 107, 46, -13, 4, -1 }, |
| 141 | { -2, 7, -21, 99, 57, -16, 5, -1 }, |
| 142 | { -1, 6, -20, 89, 68, -18, 5, -1 }, |
| 143 | { -1, 6, -20, 79, 79, -20, 6, -1 }, |
| 144 | { -1, 5, -18, 68, 89, -20, 6, -1 }, |
| 145 | { -1, 5, -16, 57, 99, -21, 7, -2 }, |
| 146 | { -1, 4, -13, 46, 107, -20, 6, -1 }, |
| 147 | { -1, 3, -10, 35, 114, -18, 6, -1 }, |
| 148 | { 0, 2, -8, 25, 120, -15, 5, -1 }, |
| 149 | { 0, 1, -5, 16, 125, -12, 4, -1 }, |
| 150 | { 0, 1, -2, 7, 127, -6, 2, -1 } |
| 151 | }, { /* 65536 < Ratio <= 74898 (~8:7) */ |
| 152 | { 3, -8, 14, 111, 13, -8, 3, 0 }, |
| 153 | { 2, -6, 7, 112, 21, -10, 3, -1 }, |
| 154 | { 2, -4, 1, 110, 28, -12, 4, -1 }, |
| 155 | { 1, -2, -3, 106, 36, -13, 4, -1 }, |
| 156 | { 1, -1, -7, 103, 44, -15, 4, -1 }, |
| 157 | { 1, 1, -11, 97, 53, -16, 4, -1 }, |
| 158 | { 0, 2, -13, 91, 61, -16, 4, -1 }, |
| 159 | { 0, 3, -15, 85, 69, -17, 4, -1 }, |
| 160 | { 0, 3, -16, 77, 77, -16, 3, 0 }, |
| 161 | { -1, 4, -17, 69, 85, -15, 3, 0 }, |
| 162 | { -1, 4, -16, 61, 91, -13, 2, 0 }, |
| 163 | { -1, 4, -16, 53, 97, -11, 1, 1 }, |
| 164 | { -1, 4, -15, 44, 103, -7, -1, 1 }, |
| 165 | { -1, 4, -13, 36, 106, -3, -2, 1 }, |
| 166 | { -1, 4, -12, 28, 110, 1, -4, 2 }, |
| 167 | { -1, 3, -10, 21, 112, 7, -6, 2 } |
| 168 | }, { /* 74898 < Ratio <= 87381 (~8:6) */ |
| 169 | { 2, -11, 25, 96, 25, -11, 2, 0 }, |
| 170 | { 2, -10, 19, 96, 31, -12, 2, 0 }, |
| 171 | { 2, -9, 14, 94, 37, -12, 2, 0 }, |
| 172 | { 2, -8, 10, 92, 43, -12, 1, 0 }, |
| 173 | { 2, -7, 5, 90, 49, -12, 1, 0 }, |
| 174 | { 2, -5, 1, 86, 55, -12, 0, 1 }, |
| 175 | { 2, -4, -2, 82, 61, -11, -1, 1 }, |
| 176 | { 1, -3, -5, 77, 67, -9, -1, 1 }, |
| 177 | { 1, -2, -7, 72, 72, -7, -2, 1 }, |
| 178 | { 1, -1, -9, 67, 77, -5, -3, 1 }, |
| 179 | { 1, -1, -11, 61, 82, -2, -4, 2 }, |
| 180 | { 1, 0, -12, 55, 86, 1, -5, 2 }, |
| 181 | { 0, 1, -12, 49, 90, 5, -7, 2 }, |
| 182 | { 0, 1, -12, 43, 92, 10, -8, 2 }, |
| 183 | { 0, 2, -12, 37, 94, 14, -9, 2 }, |
| 184 | { 0, 2, -12, 31, 96, 19, -10, 2 } |
| 185 | }, { /* 87381 < Ratio <= 104857 (~8:5) */ |
| 186 | { -1, -8, 33, 80, 33, -8, -1, 0 }, |
| 187 | { -1, -8, 28, 80, 37, -7, -2, 1 }, |
| 188 | { 0, -8, 24, 79, 41, -7, -2, 1 }, |
| 189 | { 0, -8, 20, 78, 46, -6, -3, 1 }, |
| 190 | { 0, -8, 16, 76, 50, -4, -3, 1 }, |
| 191 | { 0, -7, 13, 74, 54, -3, -4, 1 }, |
| 192 | { 1, -7, 10, 71, 58, -1, -5, 1 }, |
| 193 | { 1, -6, 6, 68, 62, 1, -5, 1 }, |
| 194 | { 1, -6, 4, 65, 65, 4, -6, 1 }, |
| 195 | { 1, -5, 1, 62, 68, 6, -6, 1 }, |
| 196 | { 1, -5, -1, 58, 71, 10, -7, 1 }, |
| 197 | { 1, -4, -3, 54, 74, 13, -7, 0 }, |
| 198 | { 1, -3, -4, 50, 76, 16, -8, 0 }, |
| 199 | { 1, -3, -6, 46, 78, 20, -8, 0 }, |
| 200 | { 1, -2, -7, 41, 79, 24, -8, 0 }, |
| 201 | { 1, -2, -7, 37, 80, 28, -8, -1 } |
| 202 | }, { /* 104857 < Ratio <= 131072 (~8:4) */ |
| 203 | { -3, 0, 35, 64, 35, 0, -3, 0 }, |
| 204 | { -3, -1, 32, 64, 38, 1, -3, 0 }, |
| 205 | { -2, -2, 29, 63, 41, 2, -3, 0 }, |
| 206 | { -2, -3, 27, 63, 43, 4, -4, 0 }, |
| 207 | { -2, -3, 24, 61, 46, 6, -4, 0 }, |
| 208 | { -2, -3, 21, 60, 49, 7, -4, 0 }, |
| 209 | { -1, -4, 19, 59, 51, 9, -4, -1 }, |
| 210 | { -1, -4, 16, 57, 53, 12, -4, -1 }, |
| 211 | { -1, -4, 14, 55, 55, 14, -4, -1 }, |
| 212 | { -1, -4, 12, 53, 57, 16, -4, -1 }, |
| 213 | { -1, -4, 9, 51, 59, 19, -4, -1 }, |
| 214 | { 0, -4, 7, 49, 60, 21, -3, -2 }, |
| 215 | { 0, -4, 6, 46, 61, 24, -3, -2 }, |
| 216 | { 0, -4, 4, 43, 63, 27, -3, -2 }, |
| 217 | { 0, -3, 2, 41, 63, 29, -2, -2 }, |
| 218 | { 0, -3, 1, 38, 64, 32, -1, -3 } |
| 219 | }, { /* 131072 < Ratio <= 174762 (~8:3) */ |
| 220 | { -1, 8, 33, 48, 33, 8, -1, 0 }, |
| 221 | { -1, 7, 31, 49, 35, 9, -1, -1 }, |
| 222 | { -1, 6, 30, 49, 36, 10, -1, -1 }, |
| 223 | { -1, 5, 28, 48, 38, 12, -1, -1 }, |
| 224 | { -1, 4, 26, 48, 39, 13, 0, -1 }, |
| 225 | { -1, 3, 24, 47, 41, 15, 0, -1 }, |
| 226 | { -1, 2, 23, 47, 42, 16, 0, -1 }, |
| 227 | { -1, 2, 21, 45, 43, 18, 1, -1 }, |
| 228 | { -1, 1, 19, 45, 45, 19, 1, -1 }, |
| 229 | { -1, 1, 18, 43, 45, 21, 2, -1 }, |
| 230 | { -1, 0, 16, 42, 47, 23, 2, -1 }, |
| 231 | { -1, 0, 15, 41, 47, 24, 3, -1 }, |
| 232 | { -1, 0, 13, 39, 48, 26, 4, -1 }, |
| 233 | { -1, -1, 12, 38, 48, 28, 5, -1 }, |
| 234 | { -1, -1, 10, 36, 49, 30, 6, -1 }, |
| 235 | { -1, -1, 9, 35, 49, 31, 7, -1 } |
| 236 | }, { /* 174762 < Ratio <= 262144 (~8:2) */ |
| 237 | { 2, 13, 30, 38, 30, 13, 2, 0 }, |
| 238 | { 2, 12, 29, 38, 30, 14, 3, 0 }, |
| 239 | { 2, 11, 28, 38, 31, 15, 3, 0 }, |
| 240 | { 2, 10, 26, 38, 32, 16, 4, 0 }, |
| 241 | { 1, 10, 26, 37, 33, 17, 4, 0 }, |
| 242 | { 1, 9, 24, 37, 34, 18, 5, 0 }, |
| 243 | { 1, 8, 24, 37, 34, 19, 5, 0 }, |
| 244 | { 1, 7, 22, 36, 35, 20, 6, 1 }, |
| 245 | { 1, 6, 21, 36, 36, 21, 6, 1 }, |
| 246 | { 1, 6, 20, 35, 36, 22, 7, 1 }, |
| 247 | { 0, 5, 19, 34, 37, 24, 8, 1 }, |
| 248 | { 0, 5, 18, 34, 37, 24, 9, 1 }, |
| 249 | { 0, 4, 17, 33, 37, 26, 10, 1 }, |
| 250 | { 0, 4, 16, 32, 38, 26, 10, 2 }, |
| 251 | { 0, 3, 15, 31, 38, 28, 11, 2 }, |
| 252 | { 0, 3, 14, 30, 38, 29, 12, 2 } |
| 253 | } |
| 254 | }; |
| 255 | |
| 256 | /* 4-tap Filter Coefficient */ |
| 257 | static const int v_coef_4t[GSC_COEF_RATIO][GSC_COEF_ATTR][GSC_COEF_V_4T] = { |
| 258 | { /* Ratio <= 65536 (~8:8) */ |
| 259 | { 0, 128, 0, 0 }, |
| 260 | { -4, 127, 5, 0 }, |
| 261 | { -6, 124, 11, -1 }, |
| 262 | { -8, 118, 19, -1 }, |
| 263 | { -8, 111, 27, -2 }, |
| 264 | { -8, 102, 37, -3 }, |
| 265 | { -8, 92, 48, -4 }, |
| 266 | { -7, 81, 59, -5 }, |
| 267 | { -6, 70, 70, -6 }, |
| 268 | { -5, 59, 81, -7 }, |
| 269 | { -4, 48, 92, -8 }, |
| 270 | { -3, 37, 102, -8 }, |
| 271 | { -2, 27, 111, -8 }, |
| 272 | { -1, 19, 118, -8 }, |
| 273 | { -1, 11, 124, -6 }, |
| 274 | { 0, 5, 127, -4 } |
| 275 | }, { /* 65536 < Ratio <= 74898 (~8:7) */ |
| 276 | { 8, 112, 8, 0 }, |
| 277 | { 4, 111, 14, -1 }, |
| 278 | { 1, 109, 20, -2 }, |
| 279 | { -2, 105, 27, -2 }, |
| 280 | { -3, 100, 34, -3 }, |
| 281 | { -5, 93, 43, -3 }, |
| 282 | { -5, 86, 51, -4 }, |
| 283 | { -5, 77, 60, -4 }, |
| 284 | { -5, 69, 69, -5 }, |
| 285 | { -4, 60, 77, -5 }, |
| 286 | { -4, 51, 86, -5 }, |
| 287 | { -3, 43, 93, -5 }, |
| 288 | { -3, 34, 100, -3 }, |
| 289 | { -2, 27, 105, -2 }, |
| 290 | { -2, 20, 109, 1 }, |
| 291 | { -1, 14, 111, 4 } |
| 292 | }, { /* 74898 < Ratio <= 87381 (~8:6) */ |
| 293 | { 16, 96, 16, 0 }, |
| 294 | { 12, 97, 21, -2 }, |
| 295 | { 8, 96, 26, -2 }, |
| 296 | { 5, 93, 32, -2 }, |
| 297 | { 2, 89, 39, -2 }, |
| 298 | { 0, 84, 46, -2 }, |
| 299 | { -1, 79, 53, -3 }, |
| 300 | { -2, 73, 59, -2 }, |
| 301 | { -2, 66, 66, -2 }, |
| 302 | { -2, 59, 73, -2 }, |
| 303 | { -3, 53, 79, -1 }, |
| 304 | { -2, 46, 84, 0 }, |
| 305 | { -2, 39, 89, 2 }, |
| 306 | { -2, 32, 93, 5 }, |
| 307 | { -2, 26, 96, 8 }, |
| 308 | { -2, 21, 97, 12 } |
| 309 | }, { /* 87381 < Ratio <= 104857 (~8:5) */ |
| 310 | { 22, 84, 22, 0 }, |
| 311 | { 18, 85, 26, -1 }, |
| 312 | { 14, 84, 31, -1 }, |
| 313 | { 11, 82, 36, -1 }, |
| 314 | { 8, 79, 42, -1 }, |
| 315 | { 6, 76, 47, -1 }, |
| 316 | { 4, 72, 52, 0 }, |
| 317 | { 2, 68, 58, 0 }, |
| 318 | { 1, 63, 63, 1 }, |
| 319 | { 0, 58, 68, 2 }, |
| 320 | { 0, 52, 72, 4 }, |
| 321 | { -1, 47, 76, 6 }, |
| 322 | { -1, 42, 79, 8 }, |
| 323 | { -1, 36, 82, 11 }, |
| 324 | { -1, 31, 84, 14 }, |
| 325 | { -1, 26, 85, 18 } |
| 326 | }, { /* 104857 < Ratio <= 131072 (~8:4) */ |
| 327 | { 26, 76, 26, 0 }, |
| 328 | { 22, 76, 30, 0 }, |
| 329 | { 19, 75, 34, 0 }, |
| 330 | { 16, 73, 38, 1 }, |
| 331 | { 13, 71, 43, 1 }, |
| 332 | { 10, 69, 47, 2 }, |
| 333 | { 8, 66, 51, 3 }, |
| 334 | { 6, 63, 55, 4 }, |
| 335 | { 5, 59, 59, 5 }, |
| 336 | { 4, 55, 63, 6 }, |
| 337 | { 3, 51, 66, 8 }, |
| 338 | { 2, 47, 69, 10 }, |
| 339 | { 1, 43, 71, 13 }, |
| 340 | { 1, 38, 73, 16 }, |
| 341 | { 0, 34, 75, 19 }, |
| 342 | { 0, 30, 76, 22 } |
| 343 | }, { /* 131072 < Ratio <= 174762 (~8:3) */ |
| 344 | { 29, 70, 29, 0 }, |
| 345 | { 26, 68, 32, 2 }, |
| 346 | { 23, 67, 36, 2 }, |
| 347 | { 20, 66, 39, 3 }, |
| 348 | { 17, 65, 43, 3 }, |
| 349 | { 15, 63, 46, 4 }, |
| 350 | { 12, 61, 50, 5 }, |
| 351 | { 10, 58, 53, 7 }, |
| 352 | { 8, 56, 56, 8 }, |
| 353 | { 7, 53, 58, 10 }, |
| 354 | { 5, 50, 61, 12 }, |
| 355 | { 4, 46, 63, 15 }, |
| 356 | { 3, 43, 65, 17 }, |
| 357 | { 3, 39, 66, 20 }, |
| 358 | { 2, 36, 67, 23 }, |
| 359 | { 2, 32, 68, 26 } |
| 360 | }, { /* 174762 < Ratio <= 262144 (~8:2) */ |
| 361 | { 32, 64, 32, 0 }, |
| 362 | { 28, 63, 34, 3 }, |
| 363 | { 25, 62, 37, 4 }, |
| 364 | { 22, 62, 40, 4 }, |
| 365 | { 19, 61, 43, 5 }, |
| 366 | { 17, 59, 46, 6 }, |
| 367 | { 15, 58, 48, 7 }, |
| 368 | { 13, 55, 51, 9 }, |
| 369 | { 11, 53, 53, 11 }, |
| 370 | { 9, 51, 55, 13 }, |
| 371 | { 7, 48, 58, 15 }, |
| 372 | { 6, 46, 59, 17 }, |
| 373 | { 5, 43, 61, 19 }, |
| 374 | { 4, 40, 62, 22 }, |
| 375 | { 4, 37, 62, 25 }, |
| 376 | { 3, 34, 63, 28 } |
| 377 | } |
| 378 | }; |
| 379 | |
| 380 | static int gsc_sw_reset(struct gsc_context *ctx) |
| 381 | { |
| 382 | u32 cfg; |
| 383 | int count = GSC_RESET_TIMEOUT; |
| 384 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 385 | /* s/w reset */ |
| 386 | cfg = (GSC_SW_RESET_SRESET); |
| 387 | gsc_write(cfg, GSC_SW_RESET); |
| 388 | |
| 389 | /* wait s/w reset complete */ |
| 390 | while (count--) { |
| 391 | cfg = gsc_read(GSC_SW_RESET); |
| 392 | if (!cfg) |
| 393 | break; |
| 394 | usleep_range(1000, 2000); |
| 395 | } |
| 396 | |
| 397 | if (cfg) { |
Inki Dae | 6f83d20 | 2019-04-15 14:24:36 +0900 | [diff] [blame^] | 398 | DRM_DEV_ERROR(ctx->dev, "failed to reset gsc h/w.\n"); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 399 | return -EBUSY; |
| 400 | } |
| 401 | |
| 402 | /* reset sequence */ |
| 403 | cfg = gsc_read(GSC_IN_BASE_ADDR_Y_MASK); |
| 404 | cfg |= (GSC_IN_BASE_ADDR_MASK | |
| 405 | GSC_IN_BASE_ADDR_PINGPONG(0)); |
| 406 | gsc_write(cfg, GSC_IN_BASE_ADDR_Y_MASK); |
| 407 | gsc_write(cfg, GSC_IN_BASE_ADDR_CB_MASK); |
| 408 | gsc_write(cfg, GSC_IN_BASE_ADDR_CR_MASK); |
| 409 | |
| 410 | cfg = gsc_read(GSC_OUT_BASE_ADDR_Y_MASK); |
| 411 | cfg |= (GSC_OUT_BASE_ADDR_MASK | |
| 412 | GSC_OUT_BASE_ADDR_PINGPONG(0)); |
| 413 | gsc_write(cfg, GSC_OUT_BASE_ADDR_Y_MASK); |
| 414 | gsc_write(cfg, GSC_OUT_BASE_ADDR_CB_MASK); |
| 415 | gsc_write(cfg, GSC_OUT_BASE_ADDR_CR_MASK); |
| 416 | |
| 417 | return 0; |
| 418 | } |
| 419 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 420 | static void gsc_handle_irq(struct gsc_context *ctx, bool enable, |
| 421 | bool overflow, bool done) |
| 422 | { |
| 423 | u32 cfg; |
| 424 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 425 | DRM_DEBUG_KMS("enable[%d]overflow[%d]level[%d]\n", |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 426 | enable, overflow, done); |
| 427 | |
| 428 | cfg = gsc_read(GSC_IRQ); |
| 429 | cfg |= (GSC_IRQ_OR_MASK | GSC_IRQ_FRMDONE_MASK); |
| 430 | |
| 431 | if (enable) |
| 432 | cfg |= GSC_IRQ_ENABLE; |
| 433 | else |
| 434 | cfg &= ~GSC_IRQ_ENABLE; |
| 435 | |
| 436 | if (overflow) |
| 437 | cfg &= ~GSC_IRQ_OR_MASK; |
| 438 | else |
| 439 | cfg |= GSC_IRQ_OR_MASK; |
| 440 | |
| 441 | if (done) |
| 442 | cfg &= ~GSC_IRQ_FRMDONE_MASK; |
| 443 | else |
| 444 | cfg |= GSC_IRQ_FRMDONE_MASK; |
| 445 | |
| 446 | gsc_write(cfg, GSC_IRQ); |
| 447 | } |
| 448 | |
| 449 | |
Marek Szyprowski | d25a40a | 2018-08-10 15:29:01 +0200 | [diff] [blame] | 450 | static void gsc_src_set_fmt(struct gsc_context *ctx, u32 fmt, bool tiled) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 451 | { |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 452 | u32 cfg; |
| 453 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 454 | DRM_DEBUG_KMS("fmt[0x%x]\n", fmt); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 455 | |
| 456 | cfg = gsc_read(GSC_IN_CON); |
| 457 | cfg &= ~(GSC_IN_RGB_TYPE_MASK | GSC_IN_YUV422_1P_ORDER_MASK | |
| 458 | GSC_IN_CHROMA_ORDER_MASK | GSC_IN_FORMAT_MASK | |
| 459 | GSC_IN_TILE_TYPE_MASK | GSC_IN_TILE_MODE | |
| 460 | GSC_IN_CHROM_STRIDE_SEL_MASK | GSC_IN_RB_SWAP_MASK); |
| 461 | |
| 462 | switch (fmt) { |
| 463 | case DRM_FORMAT_RGB565: |
| 464 | cfg |= GSC_IN_RGB565; |
| 465 | break; |
| 466 | case DRM_FORMAT_XRGB8888: |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 467 | case DRM_FORMAT_ARGB8888: |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 468 | cfg |= GSC_IN_XRGB8888; |
| 469 | break; |
| 470 | case DRM_FORMAT_BGRX8888: |
| 471 | cfg |= (GSC_IN_XRGB8888 | GSC_IN_RB_SWAP); |
| 472 | break; |
| 473 | case DRM_FORMAT_YUYV: |
| 474 | cfg |= (GSC_IN_YUV422_1P | |
| 475 | GSC_IN_YUV422_1P_ORDER_LSB_Y | |
| 476 | GSC_IN_CHROMA_ORDER_CBCR); |
| 477 | break; |
| 478 | case DRM_FORMAT_YVYU: |
| 479 | cfg |= (GSC_IN_YUV422_1P | |
| 480 | GSC_IN_YUV422_1P_ORDER_LSB_Y | |
| 481 | GSC_IN_CHROMA_ORDER_CRCB); |
| 482 | break; |
| 483 | case DRM_FORMAT_UYVY: |
| 484 | cfg |= (GSC_IN_YUV422_1P | |
| 485 | GSC_IN_YUV422_1P_OEDER_LSB_C | |
| 486 | GSC_IN_CHROMA_ORDER_CBCR); |
| 487 | break; |
| 488 | case DRM_FORMAT_VYUY: |
| 489 | cfg |= (GSC_IN_YUV422_1P | |
| 490 | GSC_IN_YUV422_1P_OEDER_LSB_C | |
| 491 | GSC_IN_CHROMA_ORDER_CRCB); |
| 492 | break; |
| 493 | case DRM_FORMAT_NV21: |
Marek Szyprowski | dd209ef | 2018-06-07 13:06:13 +0200 | [diff] [blame] | 494 | cfg |= (GSC_IN_CHROMA_ORDER_CRCB | GSC_IN_YUV420_2P); |
| 495 | break; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 496 | case DRM_FORMAT_NV61: |
Marek Szyprowski | dd209ef | 2018-06-07 13:06:13 +0200 | [diff] [blame] | 497 | cfg |= (GSC_IN_CHROMA_ORDER_CRCB | GSC_IN_YUV422_2P); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 498 | break; |
| 499 | case DRM_FORMAT_YUV422: |
| 500 | cfg |= GSC_IN_YUV422_3P; |
| 501 | break; |
| 502 | case DRM_FORMAT_YUV420: |
Marek Szyprowski | dd209ef | 2018-06-07 13:06:13 +0200 | [diff] [blame] | 503 | cfg |= (GSC_IN_CHROMA_ORDER_CBCR | GSC_IN_YUV420_3P); |
| 504 | break; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 505 | case DRM_FORMAT_YVU420: |
Marek Szyprowski | dd209ef | 2018-06-07 13:06:13 +0200 | [diff] [blame] | 506 | cfg |= (GSC_IN_CHROMA_ORDER_CRCB | GSC_IN_YUV420_3P); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 507 | break; |
| 508 | case DRM_FORMAT_NV12: |
Marek Szyprowski | dd209ef | 2018-06-07 13:06:13 +0200 | [diff] [blame] | 509 | cfg |= (GSC_IN_CHROMA_ORDER_CBCR | GSC_IN_YUV420_2P); |
| 510 | break; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 511 | case DRM_FORMAT_NV16: |
Marek Szyprowski | dd209ef | 2018-06-07 13:06:13 +0200 | [diff] [blame] | 512 | cfg |= (GSC_IN_CHROMA_ORDER_CBCR | GSC_IN_YUV422_2P); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 513 | break; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 514 | } |
| 515 | |
Marek Szyprowski | d25a40a | 2018-08-10 15:29:01 +0200 | [diff] [blame] | 516 | if (tiled) |
| 517 | cfg |= (GSC_IN_TILE_C_16x8 | GSC_IN_TILE_MODE); |
| 518 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 519 | gsc_write(cfg, GSC_IN_CON); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 520 | } |
| 521 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 522 | static void gsc_src_set_transf(struct gsc_context *ctx, unsigned int rotation) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 523 | { |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 524 | unsigned int degree = rotation & DRM_MODE_ROTATE_MASK; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 525 | u32 cfg; |
| 526 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 527 | cfg = gsc_read(GSC_IN_CON); |
| 528 | cfg &= ~GSC_IN_ROT_MASK; |
| 529 | |
| 530 | switch (degree) { |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 531 | case DRM_MODE_ROTATE_0: |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 532 | if (rotation & DRM_MODE_REFLECT_X) |
Marek Szyprowski | 4cc11a5 | 2018-06-07 13:06:12 +0200 | [diff] [blame] | 533 | cfg |= GSC_IN_ROT_XFLIP; |
| 534 | if (rotation & DRM_MODE_REFLECT_Y) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 535 | cfg |= GSC_IN_ROT_YFLIP; |
| 536 | break; |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 537 | case DRM_MODE_ROTATE_90: |
| 538 | cfg |= GSC_IN_ROT_90; |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 539 | if (rotation & DRM_MODE_REFLECT_X) |
Marek Szyprowski | 4cc11a5 | 2018-06-07 13:06:12 +0200 | [diff] [blame] | 540 | cfg |= GSC_IN_ROT_XFLIP; |
| 541 | if (rotation & DRM_MODE_REFLECT_Y) |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 542 | cfg |= GSC_IN_ROT_YFLIP; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 543 | break; |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 544 | case DRM_MODE_ROTATE_180: |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 545 | cfg |= GSC_IN_ROT_180; |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 546 | if (rotation & DRM_MODE_REFLECT_X) |
Marek Szyprowski | 4cc11a5 | 2018-06-07 13:06:12 +0200 | [diff] [blame] | 547 | cfg &= ~GSC_IN_ROT_XFLIP; |
| 548 | if (rotation & DRM_MODE_REFLECT_Y) |
Hyungwon Hwang | 5149705 | 2015-07-01 19:09:25 +0900 | [diff] [blame] | 549 | cfg &= ~GSC_IN_ROT_YFLIP; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 550 | break; |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 551 | case DRM_MODE_ROTATE_270: |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 552 | cfg |= GSC_IN_ROT_270; |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 553 | if (rotation & DRM_MODE_REFLECT_X) |
Marek Szyprowski | 4cc11a5 | 2018-06-07 13:06:12 +0200 | [diff] [blame] | 554 | cfg &= ~GSC_IN_ROT_XFLIP; |
| 555 | if (rotation & DRM_MODE_REFLECT_Y) |
Hyungwon Hwang | 5149705 | 2015-07-01 19:09:25 +0900 | [diff] [blame] | 556 | cfg &= ~GSC_IN_ROT_YFLIP; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 557 | break; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 558 | } |
| 559 | |
| 560 | gsc_write(cfg, GSC_IN_CON); |
| 561 | |
Hyungwon Hwang | 988a473 | 2015-07-01 19:09:24 +0900 | [diff] [blame] | 562 | ctx->rotation = (cfg & GSC_IN_ROT_90) ? 1 : 0; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 563 | } |
| 564 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 565 | static void gsc_src_set_size(struct gsc_context *ctx, |
| 566 | struct exynos_drm_ipp_buffer *buf) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 567 | { |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 568 | struct gsc_scaler *sc = &ctx->sc; |
| 569 | u32 cfg; |
| 570 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 571 | /* pixel offset */ |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 572 | cfg = (GSC_SRCIMG_OFFSET_X(buf->rect.x) | |
| 573 | GSC_SRCIMG_OFFSET_Y(buf->rect.y)); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 574 | gsc_write(cfg, GSC_SRCIMG_OFFSET); |
| 575 | |
| 576 | /* cropped size */ |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 577 | cfg = (GSC_CROPPED_WIDTH(buf->rect.w) | |
| 578 | GSC_CROPPED_HEIGHT(buf->rect.h)); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 579 | gsc_write(cfg, GSC_CROPPED_SIZE); |
| 580 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 581 | /* original size */ |
| 582 | cfg = gsc_read(GSC_SRCIMG_SIZE); |
| 583 | cfg &= ~(GSC_SRCIMG_HEIGHT_MASK | |
| 584 | GSC_SRCIMG_WIDTH_MASK); |
| 585 | |
Marek Szyprowski | 4958a1c | 2018-06-07 13:06:10 +0200 | [diff] [blame] | 586 | cfg |= (GSC_SRCIMG_WIDTH(buf->buf.pitch[0] / buf->format->cpp[0]) | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 587 | GSC_SRCIMG_HEIGHT(buf->buf.height)); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 588 | |
| 589 | gsc_write(cfg, GSC_SRCIMG_SIZE); |
| 590 | |
| 591 | cfg = gsc_read(GSC_IN_CON); |
| 592 | cfg &= ~GSC_IN_RGB_TYPE_MASK; |
| 593 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 594 | if (buf->rect.w >= GSC_WIDTH_ITU_709) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 595 | if (sc->range) |
| 596 | cfg |= GSC_IN_RGB_HD_WIDE; |
| 597 | else |
| 598 | cfg |= GSC_IN_RGB_HD_NARROW; |
| 599 | else |
| 600 | if (sc->range) |
| 601 | cfg |= GSC_IN_RGB_SD_WIDE; |
| 602 | else |
| 603 | cfg |= GSC_IN_RGB_SD_NARROW; |
| 604 | |
| 605 | gsc_write(cfg, GSC_IN_CON); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 606 | } |
| 607 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 608 | static void gsc_src_set_buf_seq(struct gsc_context *ctx, u32 buf_id, |
| 609 | bool enqueue) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 610 | { |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 611 | bool masked = !enqueue; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 612 | u32 cfg; |
| 613 | u32 mask = 0x00000001 << buf_id; |
| 614 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 615 | /* mask register set */ |
| 616 | cfg = gsc_read(GSC_IN_BASE_ADDR_Y_MASK); |
| 617 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 618 | /* sequence id */ |
| 619 | cfg &= ~mask; |
| 620 | cfg |= masked << buf_id; |
| 621 | gsc_write(cfg, GSC_IN_BASE_ADDR_Y_MASK); |
| 622 | gsc_write(cfg, GSC_IN_BASE_ADDR_CB_MASK); |
| 623 | gsc_write(cfg, GSC_IN_BASE_ADDR_CR_MASK); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 624 | } |
| 625 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 626 | static void gsc_src_set_addr(struct gsc_context *ctx, u32 buf_id, |
| 627 | struct exynos_drm_ipp_buffer *buf) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 628 | { |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 629 | /* address register set */ |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 630 | gsc_write(buf->dma_addr[0], GSC_IN_BASE_ADDR_Y(buf_id)); |
| 631 | gsc_write(buf->dma_addr[1], GSC_IN_BASE_ADDR_CB(buf_id)); |
| 632 | gsc_write(buf->dma_addr[2], GSC_IN_BASE_ADDR_CR(buf_id)); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 633 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 634 | gsc_src_set_buf_seq(ctx, buf_id, true); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 635 | } |
| 636 | |
Marek Szyprowski | d25a40a | 2018-08-10 15:29:01 +0200 | [diff] [blame] | 637 | static void gsc_dst_set_fmt(struct gsc_context *ctx, u32 fmt, bool tiled) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 638 | { |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 639 | u32 cfg; |
| 640 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 641 | DRM_DEBUG_KMS("fmt[0x%x]\n", fmt); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 642 | |
| 643 | cfg = gsc_read(GSC_OUT_CON); |
| 644 | cfg &= ~(GSC_OUT_RGB_TYPE_MASK | GSC_OUT_YUV422_1P_ORDER_MASK | |
| 645 | GSC_OUT_CHROMA_ORDER_MASK | GSC_OUT_FORMAT_MASK | |
| 646 | GSC_OUT_CHROM_STRIDE_SEL_MASK | GSC_OUT_RB_SWAP_MASK | |
| 647 | GSC_OUT_GLOBAL_ALPHA_MASK); |
| 648 | |
| 649 | switch (fmt) { |
| 650 | case DRM_FORMAT_RGB565: |
| 651 | cfg |= GSC_OUT_RGB565; |
| 652 | break; |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 653 | case DRM_FORMAT_ARGB8888: |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 654 | case DRM_FORMAT_XRGB8888: |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 655 | cfg |= (GSC_OUT_XRGB8888 | GSC_OUT_GLOBAL_ALPHA(0xff)); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 656 | break; |
| 657 | case DRM_FORMAT_BGRX8888: |
| 658 | cfg |= (GSC_OUT_XRGB8888 | GSC_OUT_RB_SWAP); |
| 659 | break; |
| 660 | case DRM_FORMAT_YUYV: |
| 661 | cfg |= (GSC_OUT_YUV422_1P | |
| 662 | GSC_OUT_YUV422_1P_ORDER_LSB_Y | |
| 663 | GSC_OUT_CHROMA_ORDER_CBCR); |
| 664 | break; |
| 665 | case DRM_FORMAT_YVYU: |
| 666 | cfg |= (GSC_OUT_YUV422_1P | |
| 667 | GSC_OUT_YUV422_1P_ORDER_LSB_Y | |
| 668 | GSC_OUT_CHROMA_ORDER_CRCB); |
| 669 | break; |
| 670 | case DRM_FORMAT_UYVY: |
| 671 | cfg |= (GSC_OUT_YUV422_1P | |
| 672 | GSC_OUT_YUV422_1P_OEDER_LSB_C | |
| 673 | GSC_OUT_CHROMA_ORDER_CBCR); |
| 674 | break; |
| 675 | case DRM_FORMAT_VYUY: |
| 676 | cfg |= (GSC_OUT_YUV422_1P | |
| 677 | GSC_OUT_YUV422_1P_OEDER_LSB_C | |
| 678 | GSC_OUT_CHROMA_ORDER_CRCB); |
| 679 | break; |
| 680 | case DRM_FORMAT_NV21: |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 681 | cfg |= (GSC_OUT_CHROMA_ORDER_CRCB | GSC_OUT_YUV420_2P); |
| 682 | break; |
Marek Szyprowski | dd209ef | 2018-06-07 13:06:13 +0200 | [diff] [blame] | 683 | case DRM_FORMAT_NV61: |
| 684 | cfg |= (GSC_OUT_CHROMA_ORDER_CRCB | GSC_OUT_YUV422_2P); |
| 685 | break; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 686 | case DRM_FORMAT_YUV422: |
Marek Szyprowski | dd209ef | 2018-06-07 13:06:13 +0200 | [diff] [blame] | 687 | cfg |= GSC_OUT_YUV422_3P; |
| 688 | break; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 689 | case DRM_FORMAT_YUV420: |
Marek Szyprowski | dd209ef | 2018-06-07 13:06:13 +0200 | [diff] [blame] | 690 | cfg |= (GSC_OUT_CHROMA_ORDER_CBCR | GSC_OUT_YUV420_3P); |
| 691 | break; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 692 | case DRM_FORMAT_YVU420: |
Marek Szyprowski | dd209ef | 2018-06-07 13:06:13 +0200 | [diff] [blame] | 693 | cfg |= (GSC_OUT_CHROMA_ORDER_CRCB | GSC_OUT_YUV420_3P); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 694 | break; |
| 695 | case DRM_FORMAT_NV12: |
Marek Szyprowski | dd209ef | 2018-06-07 13:06:13 +0200 | [diff] [blame] | 696 | cfg |= (GSC_OUT_CHROMA_ORDER_CBCR | GSC_OUT_YUV420_2P); |
| 697 | break; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 698 | case DRM_FORMAT_NV16: |
Marek Szyprowski | dd209ef | 2018-06-07 13:06:13 +0200 | [diff] [blame] | 699 | cfg |= (GSC_OUT_CHROMA_ORDER_CBCR | GSC_OUT_YUV422_2P); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 700 | break; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 701 | } |
| 702 | |
Marek Szyprowski | d25a40a | 2018-08-10 15:29:01 +0200 | [diff] [blame] | 703 | if (tiled) |
| 704 | cfg |= (GSC_IN_TILE_C_16x8 | GSC_OUT_TILE_MODE); |
| 705 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 706 | gsc_write(cfg, GSC_OUT_CON); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 707 | } |
| 708 | |
Inki Dae | 6f83d20 | 2019-04-15 14:24:36 +0900 | [diff] [blame^] | 709 | static int gsc_get_ratio_shift(struct gsc_context *ctx, u32 src, u32 dst, |
| 710 | u32 *ratio) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 711 | { |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 712 | DRM_DEBUG_KMS("src[%d]dst[%d]\n", src, dst); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 713 | |
| 714 | if (src >= dst * 8) { |
Inki Dae | 6f83d20 | 2019-04-15 14:24:36 +0900 | [diff] [blame^] | 715 | DRM_DEV_ERROR(ctx->dev, "failed to make ratio and shift.\n"); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 716 | return -EINVAL; |
| 717 | } else if (src >= dst * 4) |
| 718 | *ratio = 4; |
| 719 | else if (src >= dst * 2) |
| 720 | *ratio = 2; |
| 721 | else |
| 722 | *ratio = 1; |
| 723 | |
| 724 | return 0; |
| 725 | } |
| 726 | |
| 727 | static void gsc_get_prescaler_shfactor(u32 hratio, u32 vratio, u32 *shfactor) |
| 728 | { |
| 729 | if (hratio == 4 && vratio == 4) |
| 730 | *shfactor = 4; |
| 731 | else if ((hratio == 4 && vratio == 2) || |
| 732 | (hratio == 2 && vratio == 4)) |
| 733 | *shfactor = 3; |
| 734 | else if ((hratio == 4 && vratio == 1) || |
| 735 | (hratio == 1 && vratio == 4) || |
| 736 | (hratio == 2 && vratio == 2)) |
| 737 | *shfactor = 2; |
| 738 | else if (hratio == 1 && vratio == 1) |
| 739 | *shfactor = 0; |
| 740 | else |
| 741 | *shfactor = 1; |
| 742 | } |
| 743 | |
| 744 | static int gsc_set_prescaler(struct gsc_context *ctx, struct gsc_scaler *sc, |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 745 | struct drm_exynos_ipp_task_rect *src, |
| 746 | struct drm_exynos_ipp_task_rect *dst) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 747 | { |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 748 | u32 cfg; |
| 749 | u32 src_w, src_h, dst_w, dst_h; |
| 750 | int ret = 0; |
| 751 | |
| 752 | src_w = src->w; |
| 753 | src_h = src->h; |
| 754 | |
| 755 | if (ctx->rotation) { |
| 756 | dst_w = dst->h; |
| 757 | dst_h = dst->w; |
| 758 | } else { |
| 759 | dst_w = dst->w; |
| 760 | dst_h = dst->h; |
| 761 | } |
| 762 | |
Inki Dae | 6f83d20 | 2019-04-15 14:24:36 +0900 | [diff] [blame^] | 763 | ret = gsc_get_ratio_shift(ctx, src_w, dst_w, &sc->pre_hratio); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 764 | if (ret) { |
Inki Dae | 6f83d20 | 2019-04-15 14:24:36 +0900 | [diff] [blame^] | 765 | DRM_DEV_ERROR(ctx->dev, "failed to get ratio horizontal.\n"); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 766 | return ret; |
| 767 | } |
| 768 | |
Inki Dae | 6f83d20 | 2019-04-15 14:24:36 +0900 | [diff] [blame^] | 769 | ret = gsc_get_ratio_shift(ctx, src_h, dst_h, &sc->pre_vratio); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 770 | if (ret) { |
Inki Dae | 6f83d20 | 2019-04-15 14:24:36 +0900 | [diff] [blame^] | 771 | DRM_DEV_ERROR(ctx->dev, "failed to get ratio vertical.\n"); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 772 | return ret; |
| 773 | } |
| 774 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 775 | DRM_DEBUG_KMS("pre_hratio[%d]pre_vratio[%d]\n", |
| 776 | sc->pre_hratio, sc->pre_vratio); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 777 | |
| 778 | sc->main_hratio = (src_w << 16) / dst_w; |
| 779 | sc->main_vratio = (src_h << 16) / dst_h; |
| 780 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 781 | DRM_DEBUG_KMS("main_hratio[%ld]main_vratio[%ld]\n", |
| 782 | sc->main_hratio, sc->main_vratio); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 783 | |
| 784 | gsc_get_prescaler_shfactor(sc->pre_hratio, sc->pre_vratio, |
| 785 | &sc->pre_shfactor); |
| 786 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 787 | DRM_DEBUG_KMS("pre_shfactor[%d]\n", sc->pre_shfactor); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 788 | |
| 789 | cfg = (GSC_PRESC_SHFACTOR(sc->pre_shfactor) | |
| 790 | GSC_PRESC_H_RATIO(sc->pre_hratio) | |
| 791 | GSC_PRESC_V_RATIO(sc->pre_vratio)); |
| 792 | gsc_write(cfg, GSC_PRE_SCALE_RATIO); |
| 793 | |
| 794 | return ret; |
| 795 | } |
| 796 | |
| 797 | static void gsc_set_h_coef(struct gsc_context *ctx, unsigned long main_hratio) |
| 798 | { |
| 799 | int i, j, k, sc_ratio; |
| 800 | |
| 801 | if (main_hratio <= GSC_SC_UP_MAX_RATIO) |
| 802 | sc_ratio = 0; |
| 803 | else if (main_hratio <= GSC_SC_DOWN_RATIO_7_8) |
| 804 | sc_ratio = 1; |
| 805 | else if (main_hratio <= GSC_SC_DOWN_RATIO_6_8) |
| 806 | sc_ratio = 2; |
| 807 | else if (main_hratio <= GSC_SC_DOWN_RATIO_5_8) |
| 808 | sc_ratio = 3; |
| 809 | else if (main_hratio <= GSC_SC_DOWN_RATIO_4_8) |
| 810 | sc_ratio = 4; |
| 811 | else if (main_hratio <= GSC_SC_DOWN_RATIO_3_8) |
| 812 | sc_ratio = 5; |
| 813 | else |
| 814 | sc_ratio = 6; |
| 815 | |
| 816 | for (i = 0; i < GSC_COEF_PHASE; i++) |
| 817 | for (j = 0; j < GSC_COEF_H_8T; j++) |
| 818 | for (k = 0; k < GSC_COEF_DEPTH; k++) |
| 819 | gsc_write(h_coef_8t[sc_ratio][i][j], |
| 820 | GSC_HCOEF(i, j, k)); |
| 821 | } |
| 822 | |
| 823 | static void gsc_set_v_coef(struct gsc_context *ctx, unsigned long main_vratio) |
| 824 | { |
| 825 | int i, j, k, sc_ratio; |
| 826 | |
| 827 | if (main_vratio <= GSC_SC_UP_MAX_RATIO) |
| 828 | sc_ratio = 0; |
| 829 | else if (main_vratio <= GSC_SC_DOWN_RATIO_7_8) |
| 830 | sc_ratio = 1; |
| 831 | else if (main_vratio <= GSC_SC_DOWN_RATIO_6_8) |
| 832 | sc_ratio = 2; |
| 833 | else if (main_vratio <= GSC_SC_DOWN_RATIO_5_8) |
| 834 | sc_ratio = 3; |
| 835 | else if (main_vratio <= GSC_SC_DOWN_RATIO_4_8) |
| 836 | sc_ratio = 4; |
| 837 | else if (main_vratio <= GSC_SC_DOWN_RATIO_3_8) |
| 838 | sc_ratio = 5; |
| 839 | else |
| 840 | sc_ratio = 6; |
| 841 | |
| 842 | for (i = 0; i < GSC_COEF_PHASE; i++) |
| 843 | for (j = 0; j < GSC_COEF_V_4T; j++) |
| 844 | for (k = 0; k < GSC_COEF_DEPTH; k++) |
| 845 | gsc_write(v_coef_4t[sc_ratio][i][j], |
| 846 | GSC_VCOEF(i, j, k)); |
| 847 | } |
| 848 | |
| 849 | static void gsc_set_scaler(struct gsc_context *ctx, struct gsc_scaler *sc) |
| 850 | { |
| 851 | u32 cfg; |
| 852 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 853 | DRM_DEBUG_KMS("main_hratio[%ld]main_vratio[%ld]\n", |
| 854 | sc->main_hratio, sc->main_vratio); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 855 | |
| 856 | gsc_set_h_coef(ctx, sc->main_hratio); |
| 857 | cfg = GSC_MAIN_H_RATIO_VALUE(sc->main_hratio); |
| 858 | gsc_write(cfg, GSC_MAIN_H_RATIO); |
| 859 | |
| 860 | gsc_set_v_coef(ctx, sc->main_vratio); |
| 861 | cfg = GSC_MAIN_V_RATIO_VALUE(sc->main_vratio); |
| 862 | gsc_write(cfg, GSC_MAIN_V_RATIO); |
| 863 | } |
| 864 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 865 | static void gsc_dst_set_size(struct gsc_context *ctx, |
| 866 | struct exynos_drm_ipp_buffer *buf) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 867 | { |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 868 | struct gsc_scaler *sc = &ctx->sc; |
| 869 | u32 cfg; |
| 870 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 871 | /* pixel offset */ |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 872 | cfg = (GSC_DSTIMG_OFFSET_X(buf->rect.x) | |
| 873 | GSC_DSTIMG_OFFSET_Y(buf->rect.y)); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 874 | gsc_write(cfg, GSC_DSTIMG_OFFSET); |
| 875 | |
| 876 | /* scaled size */ |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 877 | if (ctx->rotation) |
| 878 | cfg = (GSC_SCALED_WIDTH(buf->rect.h) | |
| 879 | GSC_SCALED_HEIGHT(buf->rect.w)); |
| 880 | else |
| 881 | cfg = (GSC_SCALED_WIDTH(buf->rect.w) | |
| 882 | GSC_SCALED_HEIGHT(buf->rect.h)); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 883 | gsc_write(cfg, GSC_SCALED_SIZE); |
| 884 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 885 | /* original size */ |
| 886 | cfg = gsc_read(GSC_DSTIMG_SIZE); |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 887 | cfg &= ~(GSC_DSTIMG_HEIGHT_MASK | GSC_DSTIMG_WIDTH_MASK); |
Marek Szyprowski | 4958a1c | 2018-06-07 13:06:10 +0200 | [diff] [blame] | 888 | cfg |= GSC_DSTIMG_WIDTH(buf->buf.pitch[0] / buf->format->cpp[0]) | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 889 | GSC_DSTIMG_HEIGHT(buf->buf.height); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 890 | gsc_write(cfg, GSC_DSTIMG_SIZE); |
| 891 | |
| 892 | cfg = gsc_read(GSC_OUT_CON); |
| 893 | cfg &= ~GSC_OUT_RGB_TYPE_MASK; |
| 894 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 895 | if (buf->rect.w >= GSC_WIDTH_ITU_709) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 896 | if (sc->range) |
| 897 | cfg |= GSC_OUT_RGB_HD_WIDE; |
| 898 | else |
| 899 | cfg |= GSC_OUT_RGB_HD_NARROW; |
| 900 | else |
| 901 | if (sc->range) |
| 902 | cfg |= GSC_OUT_RGB_SD_WIDE; |
| 903 | else |
| 904 | cfg |= GSC_OUT_RGB_SD_NARROW; |
| 905 | |
| 906 | gsc_write(cfg, GSC_OUT_CON); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 907 | } |
| 908 | |
| 909 | static int gsc_dst_get_buf_seq(struct gsc_context *ctx) |
| 910 | { |
| 911 | u32 cfg, i, buf_num = GSC_REG_SZ; |
| 912 | u32 mask = 0x00000001; |
| 913 | |
| 914 | cfg = gsc_read(GSC_OUT_BASE_ADDR_Y_MASK); |
| 915 | |
| 916 | for (i = 0; i < GSC_REG_SZ; i++) |
| 917 | if (cfg & (mask << i)) |
| 918 | buf_num--; |
| 919 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 920 | DRM_DEBUG_KMS("buf_num[%d]\n", buf_num); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 921 | |
| 922 | return buf_num; |
| 923 | } |
| 924 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 925 | static void gsc_dst_set_buf_seq(struct gsc_context *ctx, u32 buf_id, |
| 926 | bool enqueue) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 927 | { |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 928 | bool masked = !enqueue; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 929 | u32 cfg; |
| 930 | u32 mask = 0x00000001 << buf_id; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 931 | |
| 932 | /* mask register set */ |
| 933 | cfg = gsc_read(GSC_OUT_BASE_ADDR_Y_MASK); |
| 934 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 935 | /* sequence id */ |
| 936 | cfg &= ~mask; |
| 937 | cfg |= masked << buf_id; |
| 938 | gsc_write(cfg, GSC_OUT_BASE_ADDR_Y_MASK); |
| 939 | gsc_write(cfg, GSC_OUT_BASE_ADDR_CB_MASK); |
| 940 | gsc_write(cfg, GSC_OUT_BASE_ADDR_CR_MASK); |
| 941 | |
| 942 | /* interrupt enable */ |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 943 | if (enqueue && gsc_dst_get_buf_seq(ctx) >= GSC_BUF_START) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 944 | gsc_handle_irq(ctx, true, false, true); |
| 945 | |
| 946 | /* interrupt disable */ |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 947 | if (!enqueue && gsc_dst_get_buf_seq(ctx) <= GSC_BUF_STOP) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 948 | gsc_handle_irq(ctx, false, false, true); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 949 | } |
| 950 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 951 | static void gsc_dst_set_addr(struct gsc_context *ctx, |
| 952 | u32 buf_id, struct exynos_drm_ipp_buffer *buf) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 953 | { |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 954 | /* address register set */ |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 955 | gsc_write(buf->dma_addr[0], GSC_OUT_BASE_ADDR_Y(buf_id)); |
| 956 | gsc_write(buf->dma_addr[1], GSC_OUT_BASE_ADDR_CB(buf_id)); |
| 957 | gsc_write(buf->dma_addr[2], GSC_OUT_BASE_ADDR_CR(buf_id)); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 958 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 959 | gsc_dst_set_buf_seq(ctx, buf_id, true); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 960 | } |
| 961 | |
| 962 | static int gsc_get_src_buf_index(struct gsc_context *ctx) |
| 963 | { |
| 964 | u32 cfg, curr_index, i; |
| 965 | u32 buf_id = GSC_MAX_SRC; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 966 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 967 | DRM_DEBUG_KMS("gsc id[%d]\n", ctx->id); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 968 | |
| 969 | cfg = gsc_read(GSC_IN_BASE_ADDR_Y_MASK); |
| 970 | curr_index = GSC_IN_CURR_GET_INDEX(cfg); |
| 971 | |
| 972 | for (i = curr_index; i < GSC_MAX_SRC; i++) { |
| 973 | if (!((cfg >> i) & 0x1)) { |
| 974 | buf_id = i; |
| 975 | break; |
| 976 | } |
| 977 | } |
| 978 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 979 | DRM_DEBUG_KMS("cfg[0x%x]curr_index[%d]buf_id[%d]\n", cfg, |
| 980 | curr_index, buf_id); |
| 981 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 982 | if (buf_id == GSC_MAX_SRC) { |
Inki Dae | 6f83d20 | 2019-04-15 14:24:36 +0900 | [diff] [blame^] | 983 | DRM_DEV_ERROR(ctx->dev, "failed to get in buffer index.\n"); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 984 | return -EINVAL; |
| 985 | } |
| 986 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 987 | gsc_src_set_buf_seq(ctx, buf_id, false); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 988 | |
| 989 | return buf_id; |
| 990 | } |
| 991 | |
| 992 | static int gsc_get_dst_buf_index(struct gsc_context *ctx) |
| 993 | { |
| 994 | u32 cfg, curr_index, i; |
| 995 | u32 buf_id = GSC_MAX_DST; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 996 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 997 | DRM_DEBUG_KMS("gsc id[%d]\n", ctx->id); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 998 | |
| 999 | cfg = gsc_read(GSC_OUT_BASE_ADDR_Y_MASK); |
| 1000 | curr_index = GSC_OUT_CURR_GET_INDEX(cfg); |
| 1001 | |
| 1002 | for (i = curr_index; i < GSC_MAX_DST; i++) { |
| 1003 | if (!((cfg >> i) & 0x1)) { |
| 1004 | buf_id = i; |
| 1005 | break; |
| 1006 | } |
| 1007 | } |
| 1008 | |
| 1009 | if (buf_id == GSC_MAX_DST) { |
Inki Dae | 6f83d20 | 2019-04-15 14:24:36 +0900 | [diff] [blame^] | 1010 | DRM_DEV_ERROR(ctx->dev, "failed to get out buffer index.\n"); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1011 | return -EINVAL; |
| 1012 | } |
| 1013 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1014 | gsc_dst_set_buf_seq(ctx, buf_id, false); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1015 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1016 | DRM_DEBUG_KMS("cfg[0x%x]curr_index[%d]buf_id[%d]\n", cfg, |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1017 | curr_index, buf_id); |
| 1018 | |
| 1019 | return buf_id; |
| 1020 | } |
| 1021 | |
| 1022 | static irqreturn_t gsc_irq_handler(int irq, void *dev_id) |
| 1023 | { |
| 1024 | struct gsc_context *ctx = dev_id; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1025 | u32 status; |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1026 | int err = 0; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1027 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1028 | DRM_DEBUG_KMS("gsc id[%d]\n", ctx->id); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1029 | |
| 1030 | status = gsc_read(GSC_IRQ); |
| 1031 | if (status & GSC_IRQ_STATUS_OR_IRQ) { |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1032 | dev_err(ctx->dev, "occurred overflow at %d, status 0x%x.\n", |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1033 | ctx->id, status); |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1034 | err = -EINVAL; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1035 | } |
| 1036 | |
| 1037 | if (status & GSC_IRQ_STATUS_OR_FRM_DONE) { |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1038 | int src_buf_id, dst_buf_id; |
| 1039 | |
| 1040 | dev_dbg(ctx->dev, "occurred frame done at %d, status 0x%x.\n", |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1041 | ctx->id, status); |
| 1042 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1043 | src_buf_id = gsc_get_src_buf_index(ctx); |
| 1044 | dst_buf_id = gsc_get_dst_buf_index(ctx); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1045 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1046 | DRM_DEBUG_KMS("buf_id_src[%d]buf_id_dst[%d]\n", src_buf_id, |
| 1047 | dst_buf_id); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1048 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1049 | if (src_buf_id < 0 || dst_buf_id < 0) |
| 1050 | err = -EINVAL; |
| 1051 | } |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1052 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1053 | if (ctx->task) { |
| 1054 | struct exynos_drm_ipp_task *task = ctx->task; |
| 1055 | |
| 1056 | ctx->task = NULL; |
| 1057 | pm_runtime_mark_last_busy(ctx->dev); |
| 1058 | pm_runtime_put_autosuspend(ctx->dev); |
| 1059 | exynos_drm_ipp_task_done(task, err); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1060 | } |
| 1061 | |
| 1062 | return IRQ_HANDLED; |
| 1063 | } |
| 1064 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1065 | static int gsc_reset(struct gsc_context *ctx) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1066 | { |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1067 | struct gsc_scaler *sc = &ctx->sc; |
| 1068 | int ret; |
| 1069 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1070 | /* reset h/w block */ |
| 1071 | ret = gsc_sw_reset(ctx); |
| 1072 | if (ret < 0) { |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1073 | dev_err(ctx->dev, "failed to reset hardware.\n"); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1074 | return ret; |
| 1075 | } |
| 1076 | |
| 1077 | /* scaler setting */ |
| 1078 | memset(&ctx->sc, 0x0, sizeof(ctx->sc)); |
| 1079 | sc->range = true; |
| 1080 | |
| 1081 | return 0; |
| 1082 | } |
| 1083 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1084 | static void gsc_start(struct gsc_context *ctx) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1085 | { |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1086 | u32 cfg; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1087 | |
| 1088 | gsc_handle_irq(ctx, true, false, true); |
| 1089 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1090 | /* enable one shot */ |
| 1091 | cfg = gsc_read(GSC_ENABLE); |
| 1092 | cfg &= ~(GSC_ENABLE_ON_CLEAR_MASK | |
| 1093 | GSC_ENABLE_CLK_GATE_MODE_MASK); |
| 1094 | cfg |= GSC_ENABLE_ON_CLEAR_ONESHOT; |
| 1095 | gsc_write(cfg, GSC_ENABLE); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1096 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1097 | /* src dma memory */ |
| 1098 | cfg = gsc_read(GSC_IN_CON); |
| 1099 | cfg &= ~(GSC_IN_PATH_MASK | GSC_IN_LOCAL_SEL_MASK); |
| 1100 | cfg |= GSC_IN_PATH_MEMORY; |
| 1101 | gsc_write(cfg, GSC_IN_CON); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1102 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1103 | /* dst dma memory */ |
| 1104 | cfg = gsc_read(GSC_OUT_CON); |
| 1105 | cfg |= GSC_OUT_PATH_MEMORY; |
| 1106 | gsc_write(cfg, GSC_OUT_CON); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1107 | |
| 1108 | gsc_set_scaler(ctx, &ctx->sc); |
| 1109 | |
| 1110 | cfg = gsc_read(GSC_ENABLE); |
| 1111 | cfg |= GSC_ENABLE_ON; |
| 1112 | gsc_write(cfg, GSC_ENABLE); |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1113 | } |
| 1114 | |
| 1115 | static int gsc_commit(struct exynos_drm_ipp *ipp, |
| 1116 | struct exynos_drm_ipp_task *task) |
| 1117 | { |
| 1118 | struct gsc_context *ctx = container_of(ipp, struct gsc_context, ipp); |
| 1119 | int ret; |
| 1120 | |
| 1121 | pm_runtime_get_sync(ctx->dev); |
| 1122 | ctx->task = task; |
| 1123 | |
| 1124 | ret = gsc_reset(ctx); |
| 1125 | if (ret) { |
| 1126 | pm_runtime_put_autosuspend(ctx->dev); |
| 1127 | ctx->task = NULL; |
| 1128 | return ret; |
| 1129 | } |
| 1130 | |
Marek Szyprowski | d25a40a | 2018-08-10 15:29:01 +0200 | [diff] [blame] | 1131 | gsc_src_set_fmt(ctx, task->src.buf.fourcc, task->src.buf.modifier); |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1132 | gsc_src_set_transf(ctx, task->transform.rotation); |
| 1133 | gsc_src_set_size(ctx, &task->src); |
| 1134 | gsc_src_set_addr(ctx, 0, &task->src); |
Marek Szyprowski | d25a40a | 2018-08-10 15:29:01 +0200 | [diff] [blame] | 1135 | gsc_dst_set_fmt(ctx, task->dst.buf.fourcc, task->dst.buf.modifier); |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1136 | gsc_dst_set_size(ctx, &task->dst); |
| 1137 | gsc_dst_set_addr(ctx, 0, &task->dst); |
| 1138 | gsc_set_prescaler(ctx, &ctx->sc, &task->src.rect, &task->dst.rect); |
| 1139 | gsc_start(ctx); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1140 | |
| 1141 | return 0; |
| 1142 | } |
| 1143 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1144 | static void gsc_abort(struct exynos_drm_ipp *ipp, |
| 1145 | struct exynos_drm_ipp_task *task) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1146 | { |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1147 | struct gsc_context *ctx = |
| 1148 | container_of(ipp, struct gsc_context, ipp); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1149 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1150 | gsc_reset(ctx); |
| 1151 | if (ctx->task) { |
| 1152 | struct exynos_drm_ipp_task *task = ctx->task; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1153 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1154 | ctx->task = NULL; |
| 1155 | pm_runtime_mark_last_busy(ctx->dev); |
| 1156 | pm_runtime_put_autosuspend(ctx->dev); |
| 1157 | exynos_drm_ipp_task_done(task, -EIO); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1158 | } |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1159 | } |
| 1160 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1161 | static struct exynos_drm_ipp_funcs ipp_funcs = { |
| 1162 | .commit = gsc_commit, |
| 1163 | .abort = gsc_abort, |
| 1164 | }; |
| 1165 | |
| 1166 | static int gsc_bind(struct device *dev, struct device *master, void *data) |
| 1167 | { |
| 1168 | struct gsc_context *ctx = dev_get_drvdata(dev); |
| 1169 | struct drm_device *drm_dev = data; |
| 1170 | struct exynos_drm_ipp *ipp = &ctx->ipp; |
| 1171 | |
| 1172 | ctx->drm_dev = drm_dev; |
Andrzej Hajda | 29cbf24 | 2018-10-12 12:53:41 +0200 | [diff] [blame] | 1173 | exynos_drm_register_dma(drm_dev, dev); |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1174 | |
| 1175 | exynos_drm_ipp_register(drm_dev, ipp, &ipp_funcs, |
| 1176 | DRM_EXYNOS_IPP_CAP_CROP | DRM_EXYNOS_IPP_CAP_ROTATE | |
| 1177 | DRM_EXYNOS_IPP_CAP_SCALE | DRM_EXYNOS_IPP_CAP_CONVERT, |
| 1178 | ctx->formats, ctx->num_formats, "gsc"); |
| 1179 | |
| 1180 | dev_info(dev, "The exynos gscaler has been probed successfully\n"); |
| 1181 | |
| 1182 | return 0; |
| 1183 | } |
| 1184 | |
| 1185 | static void gsc_unbind(struct device *dev, struct device *master, |
| 1186 | void *data) |
| 1187 | { |
| 1188 | struct gsc_context *ctx = dev_get_drvdata(dev); |
| 1189 | struct drm_device *drm_dev = data; |
| 1190 | struct exynos_drm_ipp *ipp = &ctx->ipp; |
| 1191 | |
| 1192 | exynos_drm_ipp_unregister(drm_dev, ipp); |
Andrzej Hajda | 2375569 | 2018-10-12 12:53:43 +0200 | [diff] [blame] | 1193 | exynos_drm_unregister_dma(drm_dev, dev); |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1194 | } |
| 1195 | |
| 1196 | static const struct component_ops gsc_component_ops = { |
| 1197 | .bind = gsc_bind, |
| 1198 | .unbind = gsc_unbind, |
| 1199 | }; |
| 1200 | |
| 1201 | static const unsigned int gsc_formats[] = { |
| 1202 | DRM_FORMAT_ARGB8888, |
| 1203 | DRM_FORMAT_XRGB8888, DRM_FORMAT_RGB565, DRM_FORMAT_BGRX8888, |
| 1204 | DRM_FORMAT_NV12, DRM_FORMAT_NV16, DRM_FORMAT_NV21, DRM_FORMAT_NV61, |
| 1205 | DRM_FORMAT_UYVY, DRM_FORMAT_VYUY, DRM_FORMAT_YUYV, DRM_FORMAT_YVYU, |
| 1206 | DRM_FORMAT_YUV420, DRM_FORMAT_YVU420, DRM_FORMAT_YUV422, |
| 1207 | }; |
| 1208 | |
Marek Szyprowski | d25a40a | 2018-08-10 15:29:01 +0200 | [diff] [blame] | 1209 | static const unsigned int gsc_tiled_formats[] = { |
| 1210 | DRM_FORMAT_NV12, DRM_FORMAT_NV21, |
| 1211 | }; |
| 1212 | |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 1213 | static int gsc_probe(struct platform_device *pdev) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1214 | { |
| 1215 | struct device *dev = &pdev->dev; |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1216 | struct gsc_driverdata *driver_data; |
| 1217 | struct exynos_drm_ipp_formats *formats; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1218 | struct gsc_context *ctx; |
| 1219 | struct resource *res; |
Marek Szyprowski | d25a40a | 2018-08-10 15:29:01 +0200 | [diff] [blame] | 1220 | int num_formats, ret, i, j; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1221 | |
| 1222 | ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL); |
| 1223 | if (!ctx) |
| 1224 | return -ENOMEM; |
| 1225 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1226 | driver_data = (struct gsc_driverdata *)of_device_get_match_data(dev); |
| 1227 | ctx->dev = dev; |
| 1228 | ctx->num_clocks = driver_data->num_clocks; |
| 1229 | ctx->clk_names = driver_data->clk_names; |
| 1230 | |
Marek Szyprowski | d25a40a | 2018-08-10 15:29:01 +0200 | [diff] [blame] | 1231 | /* construct formats/limits array */ |
| 1232 | num_formats = ARRAY_SIZE(gsc_formats) + ARRAY_SIZE(gsc_tiled_formats); |
| 1233 | formats = devm_kcalloc(dev, num_formats, sizeof(*formats), GFP_KERNEL); |
| 1234 | if (!formats) |
| 1235 | return -ENOMEM; |
| 1236 | |
| 1237 | /* linear formats */ |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1238 | for (i = 0; i < ARRAY_SIZE(gsc_formats); i++) { |
| 1239 | formats[i].fourcc = gsc_formats[i]; |
| 1240 | formats[i].type = DRM_EXYNOS_IPP_FORMAT_SOURCE | |
| 1241 | DRM_EXYNOS_IPP_FORMAT_DESTINATION; |
| 1242 | formats[i].limits = driver_data->limits; |
| 1243 | formats[i].num_limits = driver_data->num_limits; |
Seung-Woo Kim | aeefb36 | 2015-11-30 14:53:18 +0100 | [diff] [blame] | 1244 | } |
Marek Szyprowski | d25a40a | 2018-08-10 15:29:01 +0200 | [diff] [blame] | 1245 | |
| 1246 | /* tiled formats */ |
| 1247 | for (j = i, i = 0; i < ARRAY_SIZE(gsc_tiled_formats); j++, i++) { |
| 1248 | formats[j].fourcc = gsc_tiled_formats[i]; |
| 1249 | formats[j].modifier = DRM_FORMAT_MOD_SAMSUNG_16_16_TILE; |
| 1250 | formats[j].type = DRM_EXYNOS_IPP_FORMAT_SOURCE | |
| 1251 | DRM_EXYNOS_IPP_FORMAT_DESTINATION; |
| 1252 | formats[j].limits = driver_data->limits; |
| 1253 | formats[j].num_limits = driver_data->num_limits; |
| 1254 | } |
| 1255 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1256 | ctx->formats = formats; |
Marek Szyprowski | d25a40a | 2018-08-10 15:29:01 +0200 | [diff] [blame] | 1257 | ctx->num_formats = num_formats; |
Seung-Woo Kim | aeefb36 | 2015-11-30 14:53:18 +0100 | [diff] [blame] | 1258 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1259 | /* clock control */ |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1260 | for (i = 0; i < ctx->num_clocks; i++) { |
| 1261 | ctx->clocks[i] = devm_clk_get(dev, ctx->clk_names[i]); |
| 1262 | if (IS_ERR(ctx->clocks[i])) { |
| 1263 | dev_err(dev, "failed to get clock: %s\n", |
| 1264 | ctx->clk_names[i]); |
| 1265 | return PTR_ERR(ctx->clocks[i]); |
| 1266 | } |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1267 | } |
| 1268 | |
| 1269 | /* resource memory */ |
| 1270 | ctx->regs_res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Thierry Reding | d4ed602 | 2013-01-21 11:09:02 +0100 | [diff] [blame] | 1271 | ctx->regs = devm_ioremap_resource(dev, ctx->regs_res); |
| 1272 | if (IS_ERR(ctx->regs)) |
| 1273 | return PTR_ERR(ctx->regs); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1274 | |
| 1275 | /* resource irq */ |
| 1276 | res = platform_get_resource(pdev, IORESOURCE_IRQ, 0); |
| 1277 | if (!res) { |
| 1278 | dev_err(dev, "failed to request irq resource.\n"); |
Sachin Kamat | 5cbd419 | 2012-12-24 14:03:51 +0530 | [diff] [blame] | 1279 | return -ENOENT; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | ctx->irq = res->start; |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1283 | ret = devm_request_irq(dev, ctx->irq, gsc_irq_handler, 0, |
| 1284 | dev_name(dev), ctx); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1285 | if (ret < 0) { |
| 1286 | dev_err(dev, "failed to request irq.\n"); |
Sachin Kamat | 5cbd419 | 2012-12-24 14:03:51 +0530 | [diff] [blame] | 1287 | return ret; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | /* context initailization */ |
| 1291 | ctx->id = pdev->id; |
| 1292 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1293 | platform_set_drvdata(pdev, ctx); |
| 1294 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1295 | pm_runtime_use_autosuspend(dev); |
| 1296 | pm_runtime_set_autosuspend_delay(dev, GSC_AUTOSUSPEND_DELAY); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1297 | pm_runtime_enable(dev); |
| 1298 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1299 | ret = component_add(dev, &gsc_component_ops); |
| 1300 | if (ret) |
| 1301 | goto err_pm_dis; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1302 | |
Seung-Woo Kim | d873ab9 | 2013-05-22 21:14:14 +0900 | [diff] [blame] | 1303 | dev_info(dev, "drm gsc registered successfully.\n"); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1304 | |
| 1305 | return 0; |
| 1306 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1307 | err_pm_dis: |
| 1308 | pm_runtime_dont_use_autosuspend(dev); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1309 | pm_runtime_disable(dev); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1310 | return ret; |
| 1311 | } |
| 1312 | |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 1313 | static int gsc_remove(struct platform_device *pdev) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1314 | { |
| 1315 | struct device *dev = &pdev->dev; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1316 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1317 | pm_runtime_dont_use_autosuspend(dev); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1318 | pm_runtime_disable(dev); |
| 1319 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1320 | return 0; |
| 1321 | } |
| 1322 | |
Arnd Bergmann | 4158dbe | 2016-09-18 22:51:38 +0900 | [diff] [blame] | 1323 | static int __maybe_unused gsc_runtime_suspend(struct device *dev) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1324 | { |
| 1325 | struct gsc_context *ctx = get_gsc_context(dev); |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1326 | int i; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1327 | |
YoungJun Cho | cbc4c33 | 2013-06-12 10:44:40 +0900 | [diff] [blame] | 1328 | DRM_DEBUG_KMS("id[%d]\n", ctx->id); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1329 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1330 | for (i = ctx->num_clocks - 1; i >= 0; i--) |
| 1331 | clk_disable_unprepare(ctx->clocks[i]); |
| 1332 | |
| 1333 | return 0; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1334 | } |
| 1335 | |
Arnd Bergmann | 4158dbe | 2016-09-18 22:51:38 +0900 | [diff] [blame] | 1336 | static int __maybe_unused gsc_runtime_resume(struct device *dev) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1337 | { |
| 1338 | struct gsc_context *ctx = get_gsc_context(dev); |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1339 | int i, ret; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1340 | |
YoungJun Cho | bca34c9 | 2013-06-12 10:40:52 +0900 | [diff] [blame] | 1341 | DRM_DEBUG_KMS("id[%d]\n", ctx->id); |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1342 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1343 | for (i = 0; i < ctx->num_clocks; i++) { |
| 1344 | ret = clk_prepare_enable(ctx->clocks[i]); |
| 1345 | if (ret) { |
| 1346 | while (--i > 0) |
| 1347 | clk_disable_unprepare(ctx->clocks[i]); |
| 1348 | return ret; |
| 1349 | } |
| 1350 | } |
| 1351 | return 0; |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1352 | } |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1353 | |
| 1354 | static const struct dev_pm_ops gsc_pm_ops = { |
Marek Szyprowski | 83bd7b2 | 2016-08-31 14:55:55 +0200 | [diff] [blame] | 1355 | SET_SYSTEM_SLEEP_PM_OPS(pm_runtime_force_suspend, |
| 1356 | pm_runtime_force_resume) |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1357 | SET_RUNTIME_PM_OPS(gsc_runtime_suspend, gsc_runtime_resume, NULL) |
| 1358 | }; |
| 1359 | |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1360 | static const struct drm_exynos_ipp_limit gsc_5250_limits[] = { |
| 1361 | { IPP_SIZE_LIMIT(BUFFER, .h = { 32, 4800, 8 }, .v = { 16, 3344, 8 }) }, |
| 1362 | { IPP_SIZE_LIMIT(AREA, .h = { 16, 4800, 2 }, .v = { 8, 3344, 2 }) }, |
| 1363 | { IPP_SIZE_LIMIT(ROTATED, .h = { 32, 2048 }, .v = { 16, 2048 }) }, |
| 1364 | { IPP_SCALE_LIMIT(.h = { (1 << 16) / 16, (1 << 16) * 8 }, |
| 1365 | .v = { (1 << 16) / 16, (1 << 16) * 8 }) }, |
| 1366 | }; |
| 1367 | |
| 1368 | static const struct drm_exynos_ipp_limit gsc_5420_limits[] = { |
| 1369 | { IPP_SIZE_LIMIT(BUFFER, .h = { 32, 4800, 8 }, .v = { 16, 3344, 8 }) }, |
| 1370 | { IPP_SIZE_LIMIT(AREA, .h = { 16, 4800, 2 }, .v = { 8, 3344, 2 }) }, |
| 1371 | { IPP_SIZE_LIMIT(ROTATED, .h = { 16, 2016 }, .v = { 8, 2016 }) }, |
| 1372 | { IPP_SCALE_LIMIT(.h = { (1 << 16) / 16, (1 << 16) * 8 }, |
| 1373 | .v = { (1 << 16) / 16, (1 << 16) * 8 }) }, |
| 1374 | }; |
| 1375 | |
| 1376 | static const struct drm_exynos_ipp_limit gsc_5433_limits[] = { |
Marek Szyprowski | 28b6763 | 2018-06-07 13:06:11 +0200 | [diff] [blame] | 1377 | { IPP_SIZE_LIMIT(BUFFER, .h = { 32, 8191, 16 }, .v = { 16, 8191, 2 }) }, |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1378 | { IPP_SIZE_LIMIT(AREA, .h = { 16, 4800, 1 }, .v = { 8, 3344, 1 }) }, |
| 1379 | { IPP_SIZE_LIMIT(ROTATED, .h = { 32, 2047 }, .v = { 8, 8191 }) }, |
| 1380 | { IPP_SCALE_LIMIT(.h = { (1 << 16) / 16, (1 << 16) * 8 }, |
| 1381 | .v = { (1 << 16) / 16, (1 << 16) * 8 }) }, |
| 1382 | }; |
| 1383 | |
| 1384 | static struct gsc_driverdata gsc_exynos5250_drvdata = { |
| 1385 | .clk_names = {"gscl"}, |
| 1386 | .num_clocks = 1, |
| 1387 | .limits = gsc_5250_limits, |
| 1388 | .num_limits = ARRAY_SIZE(gsc_5250_limits), |
| 1389 | }; |
| 1390 | |
| 1391 | static struct gsc_driverdata gsc_exynos5420_drvdata = { |
| 1392 | .clk_names = {"gscl"}, |
| 1393 | .num_clocks = 1, |
| 1394 | .limits = gsc_5420_limits, |
| 1395 | .num_limits = ARRAY_SIZE(gsc_5420_limits), |
| 1396 | }; |
| 1397 | |
| 1398 | static struct gsc_driverdata gsc_exynos5433_drvdata = { |
| 1399 | .clk_names = {"pclk", "aclk", "aclk_xiu", "aclk_gsclbend"}, |
| 1400 | .num_clocks = 4, |
| 1401 | .limits = gsc_5433_limits, |
| 1402 | .num_limits = ARRAY_SIZE(gsc_5433_limits), |
| 1403 | }; |
| 1404 | |
Seung-Woo Kim | aeefb36 | 2015-11-30 14:53:18 +0100 | [diff] [blame] | 1405 | static const struct of_device_id exynos_drm_gsc_of_match[] = { |
Marek Szyprowski | 8b7d3ec | 2018-05-09 10:59:24 +0200 | [diff] [blame] | 1406 | { |
| 1407 | .compatible = "samsung,exynos5-gsc", |
| 1408 | .data = &gsc_exynos5250_drvdata, |
| 1409 | }, { |
| 1410 | .compatible = "samsung,exynos5250-gsc", |
| 1411 | .data = &gsc_exynos5250_drvdata, |
| 1412 | }, { |
| 1413 | .compatible = "samsung,exynos5420-gsc", |
| 1414 | .data = &gsc_exynos5420_drvdata, |
| 1415 | }, { |
| 1416 | .compatible = "samsung,exynos5433-gsc", |
| 1417 | .data = &gsc_exynos5433_drvdata, |
| 1418 | }, { |
| 1419 | }, |
Seung-Woo Kim | aeefb36 | 2015-11-30 14:53:18 +0100 | [diff] [blame] | 1420 | }; |
| 1421 | MODULE_DEVICE_TABLE(of, exynos_drm_gsc_of_match); |
| 1422 | |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1423 | struct platform_driver gsc_driver = { |
| 1424 | .probe = gsc_probe, |
Greg Kroah-Hartman | 56550d9 | 2012-12-21 15:09:25 -0800 | [diff] [blame] | 1425 | .remove = gsc_remove, |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1426 | .driver = { |
| 1427 | .name = "exynos-drm-gsc", |
| 1428 | .owner = THIS_MODULE, |
| 1429 | .pm = &gsc_pm_ops, |
Seung-Woo Kim | aeefb36 | 2015-11-30 14:53:18 +0100 | [diff] [blame] | 1430 | .of_match_table = of_match_ptr(exynos_drm_gsc_of_match), |
Eunchul Kim | f264638 | 2012-12-14 17:58:57 +0900 | [diff] [blame] | 1431 | }, |
| 1432 | }; |