Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2010 Sascha Hauer <s.hauer@pengutronix.de> |
| 3 | * Copyright (C) 2005-2009 Freescale Semiconductor, Inc. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License as published by the |
| 7 | * Free Software Foundation; either version 2 of the License, or (at your |
| 8 | * option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY |
| 12 | * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 13 | * for more details. |
| 14 | */ |
| 15 | #include <linux/module.h> |
| 16 | #include <linux/export.h> |
| 17 | #include <linux/types.h> |
Philipp Zabel | 6c64155 | 2013-03-28 17:35:21 +0100 | [diff] [blame] | 18 | #include <linux/reset.h> |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 19 | #include <linux/platform_device.h> |
| 20 | #include <linux/err.h> |
| 21 | #include <linux/spinlock.h> |
| 22 | #include <linux/delay.h> |
| 23 | #include <linux/interrupt.h> |
| 24 | #include <linux/io.h> |
| 25 | #include <linux/clk.h> |
| 26 | #include <linux/list.h> |
| 27 | #include <linux/irq.h> |
Catalin Marinas | de88cbb | 2013-01-18 15:31:37 +0000 | [diff] [blame] | 28 | #include <linux/irqchip/chained_irq.h> |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 29 | #include <linux/irqdomain.h> |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 30 | #include <linux/of_device.h> |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 31 | |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 32 | #include <drm/drm_fourcc.h> |
| 33 | |
Philipp Zabel | 39b9004 | 2013-09-30 16:13:39 +0200 | [diff] [blame] | 34 | #include <video/imx-ipu-v3.h> |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 35 | #include "ipu-prv.h" |
| 36 | |
| 37 | static inline u32 ipu_cm_read(struct ipu_soc *ipu, unsigned offset) |
| 38 | { |
| 39 | return readl(ipu->cm_reg + offset); |
| 40 | } |
| 41 | |
| 42 | static inline void ipu_cm_write(struct ipu_soc *ipu, u32 value, unsigned offset) |
| 43 | { |
| 44 | writel(value, ipu->cm_reg + offset); |
| 45 | } |
| 46 | |
| 47 | static inline u32 ipu_idmac_read(struct ipu_soc *ipu, unsigned offset) |
| 48 | { |
| 49 | return readl(ipu->idmac_reg + offset); |
| 50 | } |
| 51 | |
| 52 | static inline void ipu_idmac_write(struct ipu_soc *ipu, u32 value, |
| 53 | unsigned offset) |
| 54 | { |
| 55 | writel(value, ipu->idmac_reg + offset); |
| 56 | } |
| 57 | |
| 58 | void ipu_srm_dp_sync_update(struct ipu_soc *ipu) |
| 59 | { |
| 60 | u32 val; |
| 61 | |
| 62 | val = ipu_cm_read(ipu, IPU_SRM_PRI2); |
| 63 | val |= 0x8; |
| 64 | ipu_cm_write(ipu, val, IPU_SRM_PRI2); |
| 65 | } |
| 66 | EXPORT_SYMBOL_GPL(ipu_srm_dp_sync_update); |
| 67 | |
| 68 | struct ipu_ch_param __iomem *ipu_get_cpmem(struct ipuv3_channel *channel) |
| 69 | { |
| 70 | struct ipu_soc *ipu = channel->ipu; |
| 71 | |
| 72 | return ipu->cpmem_base + channel->num; |
| 73 | } |
| 74 | EXPORT_SYMBOL_GPL(ipu_get_cpmem); |
| 75 | |
| 76 | void ipu_cpmem_set_high_priority(struct ipuv3_channel *channel) |
| 77 | { |
| 78 | struct ipu_soc *ipu = channel->ipu; |
| 79 | struct ipu_ch_param __iomem *p = ipu_get_cpmem(channel); |
| 80 | u32 val; |
| 81 | |
| 82 | if (ipu->ipu_type == IPUV3EX) |
| 83 | ipu_ch_param_write_field(p, IPU_FIELD_ID, 1); |
| 84 | |
| 85 | val = ipu_idmac_read(ipu, IDMAC_CHA_PRI(channel->num)); |
| 86 | val |= 1 << (channel->num % 32); |
| 87 | ipu_idmac_write(ipu, val, IDMAC_CHA_PRI(channel->num)); |
| 88 | }; |
| 89 | EXPORT_SYMBOL_GPL(ipu_cpmem_set_high_priority); |
| 90 | |
| 91 | void ipu_ch_param_write_field(struct ipu_ch_param __iomem *base, u32 wbs, u32 v) |
| 92 | { |
| 93 | u32 bit = (wbs >> 8) % 160; |
| 94 | u32 size = wbs & 0xff; |
| 95 | u32 word = (wbs >> 8) / 160; |
| 96 | u32 i = bit / 32; |
| 97 | u32 ofs = bit % 32; |
| 98 | u32 mask = (1 << size) - 1; |
| 99 | u32 val; |
| 100 | |
| 101 | pr_debug("%s %d %d %d\n", __func__, word, bit , size); |
| 102 | |
| 103 | val = readl(&base->word[word].data[i]); |
| 104 | val &= ~(mask << ofs); |
| 105 | val |= v << ofs; |
| 106 | writel(val, &base->word[word].data[i]); |
| 107 | |
| 108 | if ((bit + size - 1) / 32 > i) { |
| 109 | val = readl(&base->word[word].data[i + 1]); |
| 110 | val &= ~(mask >> (ofs ? (32 - ofs) : 0)); |
| 111 | val |= v >> (ofs ? (32 - ofs) : 0); |
| 112 | writel(val, &base->word[word].data[i + 1]); |
| 113 | } |
| 114 | } |
| 115 | EXPORT_SYMBOL_GPL(ipu_ch_param_write_field); |
| 116 | |
| 117 | u32 ipu_ch_param_read_field(struct ipu_ch_param __iomem *base, u32 wbs) |
| 118 | { |
| 119 | u32 bit = (wbs >> 8) % 160; |
| 120 | u32 size = wbs & 0xff; |
| 121 | u32 word = (wbs >> 8) / 160; |
| 122 | u32 i = bit / 32; |
| 123 | u32 ofs = bit % 32; |
| 124 | u32 mask = (1 << size) - 1; |
| 125 | u32 val = 0; |
| 126 | |
| 127 | pr_debug("%s %d %d %d\n", __func__, word, bit , size); |
| 128 | |
| 129 | val = (readl(&base->word[word].data[i]) >> ofs) & mask; |
| 130 | |
| 131 | if ((bit + size - 1) / 32 > i) { |
| 132 | u32 tmp; |
| 133 | tmp = readl(&base->word[word].data[i + 1]); |
| 134 | tmp &= mask >> (ofs ? (32 - ofs) : 0); |
| 135 | val |= tmp << (ofs ? (32 - ofs) : 0); |
| 136 | } |
| 137 | |
| 138 | return val; |
| 139 | } |
| 140 | EXPORT_SYMBOL_GPL(ipu_ch_param_read_field); |
| 141 | |
| 142 | int ipu_cpmem_set_format_rgb(struct ipu_ch_param __iomem *p, |
Philipp Zabel | e56af86 | 2013-10-10 16:18:37 +0200 | [diff] [blame] | 143 | const struct ipu_rgb *rgb) |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 144 | { |
| 145 | int bpp = 0, npb = 0, ro, go, bo, to; |
| 146 | |
| 147 | ro = rgb->bits_per_pixel - rgb->red.length - rgb->red.offset; |
| 148 | go = rgb->bits_per_pixel - rgb->green.length - rgb->green.offset; |
| 149 | bo = rgb->bits_per_pixel - rgb->blue.length - rgb->blue.offset; |
| 150 | to = rgb->bits_per_pixel - rgb->transp.length - rgb->transp.offset; |
| 151 | |
| 152 | ipu_ch_param_write_field(p, IPU_FIELD_WID0, rgb->red.length - 1); |
| 153 | ipu_ch_param_write_field(p, IPU_FIELD_OFS0, ro); |
| 154 | ipu_ch_param_write_field(p, IPU_FIELD_WID1, rgb->green.length - 1); |
| 155 | ipu_ch_param_write_field(p, IPU_FIELD_OFS1, go); |
| 156 | ipu_ch_param_write_field(p, IPU_FIELD_WID2, rgb->blue.length - 1); |
| 157 | ipu_ch_param_write_field(p, IPU_FIELD_OFS2, bo); |
| 158 | |
| 159 | if (rgb->transp.length) { |
| 160 | ipu_ch_param_write_field(p, IPU_FIELD_WID3, |
| 161 | rgb->transp.length - 1); |
| 162 | ipu_ch_param_write_field(p, IPU_FIELD_OFS3, to); |
| 163 | } else { |
| 164 | ipu_ch_param_write_field(p, IPU_FIELD_WID3, 7); |
| 165 | ipu_ch_param_write_field(p, IPU_FIELD_OFS3, |
| 166 | rgb->bits_per_pixel); |
| 167 | } |
| 168 | |
| 169 | switch (rgb->bits_per_pixel) { |
| 170 | case 32: |
| 171 | bpp = 0; |
| 172 | npb = 15; |
| 173 | break; |
| 174 | case 24: |
| 175 | bpp = 1; |
| 176 | npb = 19; |
| 177 | break; |
| 178 | case 16: |
| 179 | bpp = 3; |
| 180 | npb = 31; |
| 181 | break; |
| 182 | case 8: |
| 183 | bpp = 5; |
| 184 | npb = 63; |
| 185 | break; |
| 186 | default: |
| 187 | return -EINVAL; |
| 188 | } |
| 189 | ipu_ch_param_write_field(p, IPU_FIELD_BPP, bpp); |
| 190 | ipu_ch_param_write_field(p, IPU_FIELD_NPB, npb); |
| 191 | ipu_ch_param_write_field(p, IPU_FIELD_PFS, 7); /* rgb mode */ |
| 192 | |
| 193 | return 0; |
| 194 | } |
| 195 | EXPORT_SYMBOL_GPL(ipu_cpmem_set_format_rgb); |
| 196 | |
| 197 | int ipu_cpmem_set_format_passthrough(struct ipu_ch_param __iomem *p, |
| 198 | int width) |
| 199 | { |
| 200 | int bpp = 0, npb = 0; |
| 201 | |
| 202 | switch (width) { |
| 203 | case 32: |
| 204 | bpp = 0; |
| 205 | npb = 15; |
| 206 | break; |
| 207 | case 24: |
| 208 | bpp = 1; |
| 209 | npb = 19; |
| 210 | break; |
| 211 | case 16: |
| 212 | bpp = 3; |
| 213 | npb = 31; |
| 214 | break; |
| 215 | case 8: |
| 216 | bpp = 5; |
| 217 | npb = 63; |
| 218 | break; |
| 219 | default: |
| 220 | return -EINVAL; |
| 221 | } |
| 222 | |
| 223 | ipu_ch_param_write_field(p, IPU_FIELD_BPP, bpp); |
| 224 | ipu_ch_param_write_field(p, IPU_FIELD_NPB, npb); |
| 225 | ipu_ch_param_write_field(p, IPU_FIELD_PFS, 6); /* raw mode */ |
| 226 | |
| 227 | return 0; |
| 228 | } |
| 229 | EXPORT_SYMBOL_GPL(ipu_cpmem_set_format_passthrough); |
| 230 | |
Fabio Estevam | 6cadd88 | 2013-03-23 19:43:32 -0300 | [diff] [blame] | 231 | void ipu_cpmem_set_yuv_interleaved(struct ipu_ch_param __iomem *p, |
| 232 | u32 pixel_format) |
Philipp Zabel | 0125f21 | 2012-11-12 16:29:02 +0100 | [diff] [blame] | 233 | { |
| 234 | switch (pixel_format) { |
| 235 | case V4L2_PIX_FMT_UYVY: |
| 236 | ipu_ch_param_write_field(p, IPU_FIELD_BPP, 3); /* bits/pixel */ |
| 237 | ipu_ch_param_write_field(p, IPU_FIELD_PFS, 0xA); /* pix format */ |
| 238 | ipu_ch_param_write_field(p, IPU_FIELD_NPB, 31); /* burst size */ |
| 239 | break; |
| 240 | case V4L2_PIX_FMT_YUYV: |
| 241 | ipu_ch_param_write_field(p, IPU_FIELD_BPP, 3); /* bits/pixel */ |
| 242 | ipu_ch_param_write_field(p, IPU_FIELD_PFS, 0x8); /* pix format */ |
| 243 | ipu_ch_param_write_field(p, IPU_FIELD_NPB, 31); /* burst size */ |
| 244 | break; |
| 245 | } |
| 246 | } |
| 247 | EXPORT_SYMBOL_GPL(ipu_cpmem_set_yuv_interleaved); |
| 248 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 249 | void ipu_cpmem_set_yuv_planar_full(struct ipu_ch_param __iomem *p, |
| 250 | u32 pixel_format, int stride, int u_offset, int v_offset) |
| 251 | { |
| 252 | switch (pixel_format) { |
| 253 | case V4L2_PIX_FMT_YUV420: |
| 254 | ipu_ch_param_write_field(p, IPU_FIELD_SLUV, (stride / 2) - 1); |
| 255 | ipu_ch_param_write_field(p, IPU_FIELD_UBO, u_offset / 8); |
| 256 | ipu_ch_param_write_field(p, IPU_FIELD_VBO, v_offset / 8); |
| 257 | break; |
Philipp Zabel | d3e4e61 | 2012-11-12 16:29:00 +0100 | [diff] [blame] | 258 | case V4L2_PIX_FMT_YVU420: |
| 259 | ipu_ch_param_write_field(p, IPU_FIELD_SLUV, (stride / 2) - 1); |
| 260 | ipu_ch_param_write_field(p, IPU_FIELD_UBO, v_offset / 8); |
| 261 | ipu_ch_param_write_field(p, IPU_FIELD_VBO, u_offset / 8); |
| 262 | break; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 263 | } |
| 264 | } |
| 265 | EXPORT_SYMBOL_GPL(ipu_cpmem_set_yuv_planar_full); |
| 266 | |
| 267 | void ipu_cpmem_set_yuv_planar(struct ipu_ch_param __iomem *p, u32 pixel_format, |
| 268 | int stride, int height) |
| 269 | { |
| 270 | int u_offset, v_offset; |
| 271 | int uv_stride = 0; |
| 272 | |
| 273 | switch (pixel_format) { |
| 274 | case V4L2_PIX_FMT_YUV420: |
Philipp Zabel | d3e4e61 | 2012-11-12 16:29:00 +0100 | [diff] [blame] | 275 | case V4L2_PIX_FMT_YVU420: |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 276 | uv_stride = stride / 2; |
| 277 | u_offset = stride * height; |
| 278 | v_offset = u_offset + (uv_stride * height / 2); |
Philipp Zabel | d3e4e61 | 2012-11-12 16:29:00 +0100 | [diff] [blame] | 279 | ipu_cpmem_set_yuv_planar_full(p, pixel_format, stride, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 280 | u_offset, v_offset); |
| 281 | break; |
| 282 | } |
| 283 | } |
| 284 | EXPORT_SYMBOL_GPL(ipu_cpmem_set_yuv_planar); |
| 285 | |
Philipp Zabel | e56af86 | 2013-10-10 16:18:37 +0200 | [diff] [blame] | 286 | static const struct ipu_rgb def_rgb_32 = { |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 287 | .red = { .offset = 16, .length = 8, }, |
| 288 | .green = { .offset = 8, .length = 8, }, |
| 289 | .blue = { .offset = 0, .length = 8, }, |
| 290 | .transp = { .offset = 24, .length = 8, }, |
| 291 | .bits_per_pixel = 32, |
| 292 | }; |
| 293 | |
Philipp Zabel | e56af86 | 2013-10-10 16:18:37 +0200 | [diff] [blame] | 294 | static const struct ipu_rgb def_bgr_32 = { |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 295 | .red = { .offset = 0, .length = 8, }, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 296 | .green = { .offset = 8, .length = 8, }, |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 297 | .blue = { .offset = 16, .length = 8, }, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 298 | .transp = { .offset = 24, .length = 8, }, |
| 299 | .bits_per_pixel = 32, |
| 300 | }; |
| 301 | |
Philipp Zabel | e56af86 | 2013-10-10 16:18:37 +0200 | [diff] [blame] | 302 | static const struct ipu_rgb def_rgb_24 = { |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 303 | .red = { .offset = 16, .length = 8, }, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 304 | .green = { .offset = 8, .length = 8, }, |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 305 | .blue = { .offset = 0, .length = 8, }, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 306 | .transp = { .offset = 0, .length = 0, }, |
| 307 | .bits_per_pixel = 24, |
| 308 | }; |
| 309 | |
Philipp Zabel | e56af86 | 2013-10-10 16:18:37 +0200 | [diff] [blame] | 310 | static const struct ipu_rgb def_bgr_24 = { |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 311 | .red = { .offset = 0, .length = 8, }, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 312 | .green = { .offset = 8, .length = 8, }, |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 313 | .blue = { .offset = 16, .length = 8, }, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 314 | .transp = { .offset = 0, .length = 0, }, |
| 315 | .bits_per_pixel = 24, |
| 316 | }; |
| 317 | |
Philipp Zabel | e56af86 | 2013-10-10 16:18:37 +0200 | [diff] [blame] | 318 | static const struct ipu_rgb def_rgb_16 = { |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 319 | .red = { .offset = 11, .length = 5, }, |
| 320 | .green = { .offset = 5, .length = 6, }, |
| 321 | .blue = { .offset = 0, .length = 5, }, |
| 322 | .transp = { .offset = 0, .length = 0, }, |
| 323 | .bits_per_pixel = 16, |
| 324 | }; |
| 325 | |
Philipp Zabel | 38fc7b3 | 2013-10-10 16:18:39 +0200 | [diff] [blame] | 326 | static const struct ipu_rgb def_bgr_16 = { |
| 327 | .red = { .offset = 0, .length = 5, }, |
| 328 | .green = { .offset = 5, .length = 6, }, |
| 329 | .blue = { .offset = 11, .length = 5, }, |
| 330 | .transp = { .offset = 0, .length = 0, }, |
| 331 | .bits_per_pixel = 16, |
| 332 | }; |
| 333 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 334 | #define Y_OFFSET(pix, x, y) ((x) + pix->width * (y)) |
| 335 | #define U_OFFSET(pix, x, y) ((pix->width * pix->height) + \ |
| 336 | (pix->width * (y) / 4) + (x) / 2) |
| 337 | #define V_OFFSET(pix, x, y) ((pix->width * pix->height) + \ |
| 338 | (pix->width * pix->height / 4) + \ |
| 339 | (pix->width * (y) / 4) + (x) / 2) |
| 340 | |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 341 | int ipu_cpmem_set_fmt(struct ipu_ch_param __iomem *cpmem, u32 drm_fourcc) |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 342 | { |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 343 | switch (drm_fourcc) { |
| 344 | case DRM_FORMAT_YUV420: |
| 345 | case DRM_FORMAT_YVU420: |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 346 | /* pix format */ |
| 347 | ipu_ch_param_write_field(cpmem, IPU_FIELD_PFS, 2); |
| 348 | /* burst size */ |
| 349 | ipu_ch_param_write_field(cpmem, IPU_FIELD_NPB, 63); |
| 350 | break; |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 351 | case DRM_FORMAT_UYVY: |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 352 | /* bits/pixel */ |
| 353 | ipu_ch_param_write_field(cpmem, IPU_FIELD_BPP, 3); |
| 354 | /* pix format */ |
| 355 | ipu_ch_param_write_field(cpmem, IPU_FIELD_PFS, 0xA); |
| 356 | /* burst size */ |
| 357 | ipu_ch_param_write_field(cpmem, IPU_FIELD_NPB, 31); |
| 358 | break; |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 359 | case DRM_FORMAT_YUYV: |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 360 | /* bits/pixel */ |
| 361 | ipu_ch_param_write_field(cpmem, IPU_FIELD_BPP, 3); |
| 362 | /* pix format */ |
| 363 | ipu_ch_param_write_field(cpmem, IPU_FIELD_PFS, 0x8); |
| 364 | /* burst size */ |
| 365 | ipu_ch_param_write_field(cpmem, IPU_FIELD_NPB, 31); |
| 366 | break; |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 367 | case DRM_FORMAT_ABGR8888: |
| 368 | case DRM_FORMAT_XBGR8888: |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 369 | ipu_cpmem_set_format_rgb(cpmem, &def_bgr_32); |
| 370 | break; |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 371 | case DRM_FORMAT_ARGB8888: |
| 372 | case DRM_FORMAT_XRGB8888: |
| 373 | ipu_cpmem_set_format_rgb(cpmem, &def_rgb_32); |
| 374 | break; |
| 375 | case DRM_FORMAT_BGR888: |
| 376 | ipu_cpmem_set_format_rgb(cpmem, &def_bgr_24); |
| 377 | break; |
| 378 | case DRM_FORMAT_RGB888: |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 379 | ipu_cpmem_set_format_rgb(cpmem, &def_rgb_24); |
| 380 | break; |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 381 | case DRM_FORMAT_RGB565: |
| 382 | ipu_cpmem_set_format_rgb(cpmem, &def_rgb_16); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 383 | break; |
Philipp Zabel | 38fc7b3 | 2013-10-10 16:18:39 +0200 | [diff] [blame] | 384 | case DRM_FORMAT_BGR565: |
| 385 | ipu_cpmem_set_format_rgb(cpmem, &def_bgr_16); |
| 386 | break; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 387 | default: |
| 388 | return -EINVAL; |
| 389 | } |
| 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | EXPORT_SYMBOL_GPL(ipu_cpmem_set_fmt); |
| 394 | |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 395 | /* |
| 396 | * The V4L2 spec defines packed RGB formats in memory byte order, which from |
| 397 | * point of view of the IPU corresponds to little-endian words with the first |
| 398 | * component in the least significant bits. |
| 399 | * The DRM pixel formats and IPU internal representation are ordered the other |
| 400 | * way around, with the first named component ordered at the most significant |
| 401 | * bits. Further, V4L2 formats are not well defined: |
| 402 | * http://linuxtv.org/downloads/v4l-dvb-apis/packed-rgb.html |
| 403 | * We choose the interpretation which matches GStreamer behavior. |
| 404 | */ |
| 405 | static int v4l2_pix_fmt_to_drm_fourcc(u32 pixelformat) |
| 406 | { |
| 407 | switch (pixelformat) { |
| 408 | case V4L2_PIX_FMT_RGB565: |
| 409 | /* |
| 410 | * Here we choose the 'corrected' interpretation of RGBP, a |
| 411 | * little-endian 16-bit word with the red component at the most |
| 412 | * significant bits: |
| 413 | * g[2:0]b[4:0] r[4:0]g[5:3] <=> [16:0] R:G:B |
| 414 | */ |
| 415 | return DRM_FORMAT_RGB565; |
| 416 | case V4L2_PIX_FMT_BGR24: |
| 417 | /* B G R <=> [24:0] R:G:B */ |
| 418 | return DRM_FORMAT_RGB888; |
| 419 | case V4L2_PIX_FMT_RGB24: |
| 420 | /* R G B <=> [24:0] B:G:R */ |
| 421 | return DRM_FORMAT_BGR888; |
| 422 | case V4L2_PIX_FMT_BGR32: |
| 423 | /* B G R A <=> [32:0] A:B:G:R */ |
| 424 | return DRM_FORMAT_XRGB8888; |
| 425 | case V4L2_PIX_FMT_RGB32: |
| 426 | /* R G B A <=> [32:0] A:B:G:R */ |
| 427 | return DRM_FORMAT_XBGR8888; |
| 428 | case V4L2_PIX_FMT_UYVY: |
| 429 | return DRM_FORMAT_UYVY; |
| 430 | case V4L2_PIX_FMT_YUYV: |
| 431 | return DRM_FORMAT_YUYV; |
| 432 | case V4L2_PIX_FMT_YUV420: |
| 433 | return DRM_FORMAT_YUV420; |
| 434 | case V4L2_PIX_FMT_YVU420: |
| 435 | return DRM_FORMAT_YVU420; |
| 436 | } |
| 437 | |
| 438 | return -EINVAL; |
| 439 | } |
| 440 | |
| 441 | enum ipu_color_space ipu_drm_fourcc_to_colorspace(u32 drm_fourcc) |
| 442 | { |
| 443 | switch (drm_fourcc) { |
| 444 | case DRM_FORMAT_RGB565: |
| 445 | case DRM_FORMAT_BGR565: |
| 446 | case DRM_FORMAT_RGB888: |
| 447 | case DRM_FORMAT_BGR888: |
| 448 | case DRM_FORMAT_XRGB8888: |
| 449 | case DRM_FORMAT_XBGR8888: |
| 450 | case DRM_FORMAT_RGBX8888: |
| 451 | case DRM_FORMAT_BGRX8888: |
| 452 | case DRM_FORMAT_ARGB8888: |
| 453 | case DRM_FORMAT_ABGR8888: |
| 454 | case DRM_FORMAT_RGBA8888: |
| 455 | case DRM_FORMAT_BGRA8888: |
| 456 | return IPUV3_COLORSPACE_RGB; |
| 457 | case DRM_FORMAT_YUYV: |
| 458 | case DRM_FORMAT_UYVY: |
| 459 | case DRM_FORMAT_YUV420: |
| 460 | case DRM_FORMAT_YVU420: |
| 461 | return IPUV3_COLORSPACE_YUV; |
| 462 | default: |
| 463 | return IPUV3_COLORSPACE_UNKNOWN; |
| 464 | } |
| 465 | } |
| 466 | EXPORT_SYMBOL_GPL(ipu_drm_fourcc_to_colorspace); |
| 467 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 468 | int ipu_cpmem_set_image(struct ipu_ch_param __iomem *cpmem, |
| 469 | struct ipu_image *image) |
| 470 | { |
| 471 | struct v4l2_pix_format *pix = &image->pix; |
| 472 | int y_offset, u_offset, v_offset; |
| 473 | |
| 474 | pr_debug("%s: resolution: %dx%d stride: %d\n", |
| 475 | __func__, pix->width, pix->height, |
| 476 | pix->bytesperline); |
| 477 | |
| 478 | ipu_cpmem_set_resolution(cpmem, image->rect.width, |
| 479 | image->rect.height); |
| 480 | ipu_cpmem_set_stride(cpmem, pix->bytesperline); |
| 481 | |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 482 | ipu_cpmem_set_fmt(cpmem, v4l2_pix_fmt_to_drm_fourcc(pix->pixelformat)); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 483 | |
| 484 | switch (pix->pixelformat) { |
| 485 | case V4L2_PIX_FMT_YUV420: |
Philipp Zabel | d3e4e61 | 2012-11-12 16:29:00 +0100 | [diff] [blame] | 486 | case V4L2_PIX_FMT_YVU420: |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 487 | y_offset = Y_OFFSET(pix, image->rect.left, image->rect.top); |
| 488 | u_offset = U_OFFSET(pix, image->rect.left, |
| 489 | image->rect.top) - y_offset; |
| 490 | v_offset = V_OFFSET(pix, image->rect.left, |
| 491 | image->rect.top) - y_offset; |
| 492 | |
| 493 | ipu_cpmem_set_yuv_planar_full(cpmem, pix->pixelformat, |
| 494 | pix->bytesperline, u_offset, v_offset); |
| 495 | ipu_cpmem_set_buffer(cpmem, 0, image->phys + y_offset); |
| 496 | break; |
| 497 | case V4L2_PIX_FMT_UYVY: |
Michael Olbrich | c096ae1 | 2012-11-12 16:28:59 +0100 | [diff] [blame] | 498 | case V4L2_PIX_FMT_YUYV: |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 499 | ipu_cpmem_set_buffer(cpmem, 0, image->phys + |
| 500 | image->rect.left * 2 + |
| 501 | image->rect.top * image->pix.bytesperline); |
| 502 | break; |
| 503 | case V4L2_PIX_FMT_RGB32: |
| 504 | case V4L2_PIX_FMT_BGR32: |
| 505 | ipu_cpmem_set_buffer(cpmem, 0, image->phys + |
| 506 | image->rect.left * 4 + |
| 507 | image->rect.top * image->pix.bytesperline); |
| 508 | break; |
| 509 | case V4L2_PIX_FMT_RGB565: |
| 510 | ipu_cpmem_set_buffer(cpmem, 0, image->phys + |
| 511 | image->rect.left * 2 + |
| 512 | image->rect.top * image->pix.bytesperline); |
| 513 | break; |
| 514 | case V4L2_PIX_FMT_RGB24: |
| 515 | case V4L2_PIX_FMT_BGR24: |
| 516 | ipu_cpmem_set_buffer(cpmem, 0, image->phys + |
| 517 | image->rect.left * 3 + |
| 518 | image->rect.top * image->pix.bytesperline); |
| 519 | break; |
| 520 | default: |
| 521 | return -EINVAL; |
| 522 | } |
| 523 | |
| 524 | return 0; |
| 525 | } |
| 526 | EXPORT_SYMBOL_GPL(ipu_cpmem_set_image); |
| 527 | |
| 528 | enum ipu_color_space ipu_pixelformat_to_colorspace(u32 pixelformat) |
| 529 | { |
| 530 | switch (pixelformat) { |
| 531 | case V4L2_PIX_FMT_YUV420: |
Philipp Zabel | d3e4e61 | 2012-11-12 16:29:00 +0100 | [diff] [blame] | 532 | case V4L2_PIX_FMT_YVU420: |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 533 | case V4L2_PIX_FMT_UYVY: |
Michael Olbrich | c096ae1 | 2012-11-12 16:28:59 +0100 | [diff] [blame] | 534 | case V4L2_PIX_FMT_YUYV: |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 535 | return IPUV3_COLORSPACE_YUV; |
| 536 | case V4L2_PIX_FMT_RGB32: |
| 537 | case V4L2_PIX_FMT_BGR32: |
| 538 | case V4L2_PIX_FMT_RGB24: |
| 539 | case V4L2_PIX_FMT_BGR24: |
| 540 | case V4L2_PIX_FMT_RGB565: |
| 541 | return IPUV3_COLORSPACE_RGB; |
| 542 | default: |
| 543 | return IPUV3_COLORSPACE_UNKNOWN; |
| 544 | } |
| 545 | } |
| 546 | EXPORT_SYMBOL_GPL(ipu_pixelformat_to_colorspace); |
| 547 | |
| 548 | struct ipuv3_channel *ipu_idmac_get(struct ipu_soc *ipu, unsigned num) |
| 549 | { |
| 550 | struct ipuv3_channel *channel; |
| 551 | |
| 552 | dev_dbg(ipu->dev, "%s %d\n", __func__, num); |
| 553 | |
| 554 | if (num > 63) |
| 555 | return ERR_PTR(-ENODEV); |
| 556 | |
| 557 | mutex_lock(&ipu->channel_lock); |
| 558 | |
| 559 | channel = &ipu->channel[num]; |
| 560 | |
| 561 | if (channel->busy) { |
| 562 | channel = ERR_PTR(-EBUSY); |
| 563 | goto out; |
| 564 | } |
| 565 | |
Valentina Manea | 89bc5be | 2013-10-25 11:52:20 +0300 | [diff] [blame] | 566 | channel->busy = true; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 567 | channel->num = num; |
| 568 | |
| 569 | out: |
| 570 | mutex_unlock(&ipu->channel_lock); |
| 571 | |
| 572 | return channel; |
| 573 | } |
| 574 | EXPORT_SYMBOL_GPL(ipu_idmac_get); |
| 575 | |
| 576 | void ipu_idmac_put(struct ipuv3_channel *channel) |
| 577 | { |
| 578 | struct ipu_soc *ipu = channel->ipu; |
| 579 | |
| 580 | dev_dbg(ipu->dev, "%s %d\n", __func__, channel->num); |
| 581 | |
| 582 | mutex_lock(&ipu->channel_lock); |
| 583 | |
Valentina Manea | 89bc5be | 2013-10-25 11:52:20 +0300 | [diff] [blame] | 584 | channel->busy = false; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 585 | |
| 586 | mutex_unlock(&ipu->channel_lock); |
| 587 | } |
| 588 | EXPORT_SYMBOL_GPL(ipu_idmac_put); |
| 589 | |
| 590 | #define idma_mask(ch) (1 << (ch & 0x1f)) |
| 591 | |
| 592 | void ipu_idmac_set_double_buffer(struct ipuv3_channel *channel, |
| 593 | bool doublebuffer) |
| 594 | { |
| 595 | struct ipu_soc *ipu = channel->ipu; |
| 596 | unsigned long flags; |
| 597 | u32 reg; |
| 598 | |
| 599 | spin_lock_irqsave(&ipu->lock, flags); |
| 600 | |
| 601 | reg = ipu_cm_read(ipu, IPU_CHA_DB_MODE_SEL(channel->num)); |
| 602 | if (doublebuffer) |
| 603 | reg |= idma_mask(channel->num); |
| 604 | else |
| 605 | reg &= ~idma_mask(channel->num); |
| 606 | ipu_cm_write(ipu, reg, IPU_CHA_DB_MODE_SEL(channel->num)); |
| 607 | |
| 608 | spin_unlock_irqrestore(&ipu->lock, flags); |
| 609 | } |
| 610 | EXPORT_SYMBOL_GPL(ipu_idmac_set_double_buffer); |
| 611 | |
| 612 | int ipu_module_enable(struct ipu_soc *ipu, u32 mask) |
| 613 | { |
| 614 | unsigned long lock_flags; |
| 615 | u32 val; |
| 616 | |
| 617 | spin_lock_irqsave(&ipu->lock, lock_flags); |
| 618 | |
| 619 | val = ipu_cm_read(ipu, IPU_DISP_GEN); |
| 620 | |
| 621 | if (mask & IPU_CONF_DI0_EN) |
| 622 | val |= IPU_DI0_COUNTER_RELEASE; |
| 623 | if (mask & IPU_CONF_DI1_EN) |
| 624 | val |= IPU_DI1_COUNTER_RELEASE; |
| 625 | |
| 626 | ipu_cm_write(ipu, val, IPU_DISP_GEN); |
| 627 | |
| 628 | val = ipu_cm_read(ipu, IPU_CONF); |
| 629 | val |= mask; |
| 630 | ipu_cm_write(ipu, val, IPU_CONF); |
| 631 | |
| 632 | spin_unlock_irqrestore(&ipu->lock, lock_flags); |
| 633 | |
| 634 | return 0; |
| 635 | } |
| 636 | EXPORT_SYMBOL_GPL(ipu_module_enable); |
| 637 | |
| 638 | int ipu_module_disable(struct ipu_soc *ipu, u32 mask) |
| 639 | { |
| 640 | unsigned long lock_flags; |
| 641 | u32 val; |
| 642 | |
| 643 | spin_lock_irqsave(&ipu->lock, lock_flags); |
| 644 | |
| 645 | val = ipu_cm_read(ipu, IPU_CONF); |
| 646 | val &= ~mask; |
| 647 | ipu_cm_write(ipu, val, IPU_CONF); |
| 648 | |
| 649 | val = ipu_cm_read(ipu, IPU_DISP_GEN); |
| 650 | |
| 651 | if (mask & IPU_CONF_DI0_EN) |
| 652 | val &= ~IPU_DI0_COUNTER_RELEASE; |
| 653 | if (mask & IPU_CONF_DI1_EN) |
| 654 | val &= ~IPU_DI1_COUNTER_RELEASE; |
| 655 | |
| 656 | ipu_cm_write(ipu, val, IPU_DISP_GEN); |
| 657 | |
| 658 | spin_unlock_irqrestore(&ipu->lock, lock_flags); |
| 659 | |
| 660 | return 0; |
| 661 | } |
| 662 | EXPORT_SYMBOL_GPL(ipu_module_disable); |
| 663 | |
Philipp Zabel | 3f5a8a9 | 2012-05-22 17:08:48 +0200 | [diff] [blame^] | 664 | int ipu_csi_enable(struct ipu_soc *ipu, int csi) |
| 665 | { |
| 666 | return ipu_module_enable(ipu, csi ? IPU_CONF_CSI1_EN : IPU_CONF_CSI0_EN); |
| 667 | } |
| 668 | EXPORT_SYMBOL_GPL(ipu_csi_enable); |
| 669 | |
| 670 | int ipu_csi_disable(struct ipu_soc *ipu, int csi) |
| 671 | { |
| 672 | return ipu_module_disable(ipu, csi ? IPU_CONF_CSI1_EN : IPU_CONF_CSI0_EN); |
| 673 | } |
| 674 | EXPORT_SYMBOL_GPL(ipu_csi_disable); |
| 675 | |
| 676 | int ipu_smfc_enable(struct ipu_soc *ipu) |
| 677 | { |
| 678 | return ipu_module_enable(ipu, IPU_CONF_SMFC_EN); |
| 679 | } |
| 680 | EXPORT_SYMBOL_GPL(ipu_smfc_enable); |
| 681 | |
| 682 | int ipu_smfc_disable(struct ipu_soc *ipu) |
| 683 | { |
| 684 | return ipu_module_disable(ipu, IPU_CONF_SMFC_EN); |
| 685 | } |
| 686 | EXPORT_SYMBOL_GPL(ipu_smfc_disable); |
| 687 | |
Philipp Zabel | e904609 | 2012-05-16 17:28:29 +0200 | [diff] [blame] | 688 | int ipu_idmac_get_current_buffer(struct ipuv3_channel *channel) |
| 689 | { |
| 690 | struct ipu_soc *ipu = channel->ipu; |
| 691 | unsigned int chno = channel->num; |
| 692 | |
| 693 | return (ipu_cm_read(ipu, IPU_CHA_CUR_BUF(chno)) & idma_mask(chno)) ? 1 : 0; |
| 694 | } |
| 695 | EXPORT_SYMBOL_GPL(ipu_idmac_get_current_buffer); |
| 696 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 697 | void ipu_idmac_select_buffer(struct ipuv3_channel *channel, u32 buf_num) |
| 698 | { |
| 699 | struct ipu_soc *ipu = channel->ipu; |
| 700 | unsigned int chno = channel->num; |
| 701 | unsigned long flags; |
| 702 | |
| 703 | spin_lock_irqsave(&ipu->lock, flags); |
| 704 | |
| 705 | /* Mark buffer as ready. */ |
| 706 | if (buf_num == 0) |
| 707 | ipu_cm_write(ipu, idma_mask(chno), IPU_CHA_BUF0_RDY(chno)); |
| 708 | else |
| 709 | ipu_cm_write(ipu, idma_mask(chno), IPU_CHA_BUF1_RDY(chno)); |
| 710 | |
| 711 | spin_unlock_irqrestore(&ipu->lock, flags); |
| 712 | } |
| 713 | EXPORT_SYMBOL_GPL(ipu_idmac_select_buffer); |
| 714 | |
| 715 | int ipu_idmac_enable_channel(struct ipuv3_channel *channel) |
| 716 | { |
| 717 | struct ipu_soc *ipu = channel->ipu; |
| 718 | u32 val; |
| 719 | unsigned long flags; |
| 720 | |
| 721 | spin_lock_irqsave(&ipu->lock, flags); |
| 722 | |
| 723 | val = ipu_idmac_read(ipu, IDMAC_CHA_EN(channel->num)); |
| 724 | val |= idma_mask(channel->num); |
| 725 | ipu_idmac_write(ipu, val, IDMAC_CHA_EN(channel->num)); |
| 726 | |
| 727 | spin_unlock_irqrestore(&ipu->lock, flags); |
| 728 | |
| 729 | return 0; |
| 730 | } |
| 731 | EXPORT_SYMBOL_GPL(ipu_idmac_enable_channel); |
| 732 | |
Sascha Hauer | fb822a3 | 2013-10-10 16:18:41 +0200 | [diff] [blame] | 733 | int ipu_idmac_wait_busy(struct ipuv3_channel *channel, int ms) |
| 734 | { |
| 735 | struct ipu_soc *ipu = channel->ipu; |
| 736 | unsigned long timeout; |
| 737 | |
| 738 | timeout = jiffies + msecs_to_jiffies(ms); |
| 739 | while (ipu_idmac_read(ipu, IDMAC_CHA_BUSY(channel->num)) & |
| 740 | idma_mask(channel->num)) { |
| 741 | if (time_after(jiffies, timeout)) |
| 742 | return -ETIMEDOUT; |
| 743 | cpu_relax(); |
| 744 | } |
| 745 | |
| 746 | return 0; |
| 747 | } |
| 748 | EXPORT_SYMBOL_GPL(ipu_idmac_wait_busy); |
| 749 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 750 | int ipu_idmac_disable_channel(struct ipuv3_channel *channel) |
| 751 | { |
| 752 | struct ipu_soc *ipu = channel->ipu; |
| 753 | u32 val; |
| 754 | unsigned long flags; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 755 | |
| 756 | spin_lock_irqsave(&ipu->lock, flags); |
| 757 | |
| 758 | /* Disable DMA channel(s) */ |
| 759 | val = ipu_idmac_read(ipu, IDMAC_CHA_EN(channel->num)); |
| 760 | val &= ~idma_mask(channel->num); |
| 761 | ipu_idmac_write(ipu, val, IDMAC_CHA_EN(channel->num)); |
| 762 | |
| 763 | /* Set channel buffers NOT to be ready */ |
| 764 | ipu_cm_write(ipu, 0xf0000000, IPU_GPR); /* write one to clear */ |
| 765 | |
| 766 | if (ipu_cm_read(ipu, IPU_CHA_BUF0_RDY(channel->num)) & |
| 767 | idma_mask(channel->num)) { |
| 768 | ipu_cm_write(ipu, idma_mask(channel->num), |
| 769 | IPU_CHA_BUF0_RDY(channel->num)); |
| 770 | } |
| 771 | |
| 772 | if (ipu_cm_read(ipu, IPU_CHA_BUF1_RDY(channel->num)) & |
| 773 | idma_mask(channel->num)) { |
| 774 | ipu_cm_write(ipu, idma_mask(channel->num), |
| 775 | IPU_CHA_BUF1_RDY(channel->num)); |
| 776 | } |
| 777 | |
| 778 | ipu_cm_write(ipu, 0x0, IPU_GPR); /* write one to set */ |
| 779 | |
| 780 | /* Reset the double buffer */ |
| 781 | val = ipu_cm_read(ipu, IPU_CHA_DB_MODE_SEL(channel->num)); |
| 782 | val &= ~idma_mask(channel->num); |
| 783 | ipu_cm_write(ipu, val, IPU_CHA_DB_MODE_SEL(channel->num)); |
| 784 | |
| 785 | spin_unlock_irqrestore(&ipu->lock, flags); |
| 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | EXPORT_SYMBOL_GPL(ipu_idmac_disable_channel); |
| 790 | |
Philipp Zabel | 6c64155 | 2013-03-28 17:35:21 +0100 | [diff] [blame] | 791 | static int ipu_memory_reset(struct ipu_soc *ipu) |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 792 | { |
| 793 | unsigned long timeout; |
| 794 | |
| 795 | ipu_cm_write(ipu, 0x807FFFFF, IPU_MEM_RST); |
| 796 | |
| 797 | timeout = jiffies + msecs_to_jiffies(1000); |
| 798 | while (ipu_cm_read(ipu, IPU_MEM_RST) & 0x80000000) { |
| 799 | if (time_after(jiffies, timeout)) |
| 800 | return -ETIME; |
| 801 | cpu_relax(); |
| 802 | } |
| 803 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 804 | return 0; |
| 805 | } |
| 806 | |
| 807 | struct ipu_devtype { |
| 808 | const char *name; |
| 809 | unsigned long cm_ofs; |
| 810 | unsigned long cpmem_ofs; |
| 811 | unsigned long srm_ofs; |
| 812 | unsigned long tpm_ofs; |
| 813 | unsigned long disp0_ofs; |
| 814 | unsigned long disp1_ofs; |
| 815 | unsigned long dc_tmpl_ofs; |
| 816 | unsigned long vdi_ofs; |
| 817 | enum ipuv3_type type; |
| 818 | }; |
| 819 | |
| 820 | static struct ipu_devtype ipu_type_imx51 = { |
| 821 | .name = "IPUv3EX", |
| 822 | .cm_ofs = 0x1e000000, |
| 823 | .cpmem_ofs = 0x1f000000, |
| 824 | .srm_ofs = 0x1f040000, |
| 825 | .tpm_ofs = 0x1f060000, |
| 826 | .disp0_ofs = 0x1e040000, |
| 827 | .disp1_ofs = 0x1e048000, |
| 828 | .dc_tmpl_ofs = 0x1f080000, |
| 829 | .vdi_ofs = 0x1e068000, |
| 830 | .type = IPUV3EX, |
| 831 | }; |
| 832 | |
| 833 | static struct ipu_devtype ipu_type_imx53 = { |
| 834 | .name = "IPUv3M", |
| 835 | .cm_ofs = 0x06000000, |
| 836 | .cpmem_ofs = 0x07000000, |
| 837 | .srm_ofs = 0x07040000, |
| 838 | .tpm_ofs = 0x07060000, |
| 839 | .disp0_ofs = 0x06040000, |
| 840 | .disp1_ofs = 0x06048000, |
| 841 | .dc_tmpl_ofs = 0x07080000, |
| 842 | .vdi_ofs = 0x06068000, |
| 843 | .type = IPUV3M, |
| 844 | }; |
| 845 | |
| 846 | static struct ipu_devtype ipu_type_imx6q = { |
| 847 | .name = "IPUv3H", |
| 848 | .cm_ofs = 0x00200000, |
| 849 | .cpmem_ofs = 0x00300000, |
| 850 | .srm_ofs = 0x00340000, |
| 851 | .tpm_ofs = 0x00360000, |
| 852 | .disp0_ofs = 0x00240000, |
| 853 | .disp1_ofs = 0x00248000, |
| 854 | .dc_tmpl_ofs = 0x00380000, |
| 855 | .vdi_ofs = 0x00268000, |
| 856 | .type = IPUV3H, |
| 857 | }; |
| 858 | |
| 859 | static const struct of_device_id imx_ipu_dt_ids[] = { |
| 860 | { .compatible = "fsl,imx51-ipu", .data = &ipu_type_imx51, }, |
| 861 | { .compatible = "fsl,imx53-ipu", .data = &ipu_type_imx53, }, |
| 862 | { .compatible = "fsl,imx6q-ipu", .data = &ipu_type_imx6q, }, |
| 863 | { /* sentinel */ } |
| 864 | }; |
| 865 | MODULE_DEVICE_TABLE(of, imx_ipu_dt_ids); |
| 866 | |
| 867 | static int ipu_submodules_init(struct ipu_soc *ipu, |
| 868 | struct platform_device *pdev, unsigned long ipu_base, |
| 869 | struct clk *ipu_clk) |
| 870 | { |
| 871 | char *unit; |
| 872 | int ret; |
| 873 | struct device *dev = &pdev->dev; |
| 874 | const struct ipu_devtype *devtype = ipu->devtype; |
| 875 | |
| 876 | ret = ipu_di_init(ipu, dev, 0, ipu_base + devtype->disp0_ofs, |
| 877 | IPU_CONF_DI0_EN, ipu_clk); |
| 878 | if (ret) { |
| 879 | unit = "di0"; |
| 880 | goto err_di_0; |
| 881 | } |
| 882 | |
| 883 | ret = ipu_di_init(ipu, dev, 1, ipu_base + devtype->disp1_ofs, |
| 884 | IPU_CONF_DI1_EN, ipu_clk); |
| 885 | if (ret) { |
| 886 | unit = "di1"; |
| 887 | goto err_di_1; |
| 888 | } |
| 889 | |
| 890 | ret = ipu_dc_init(ipu, dev, ipu_base + devtype->cm_ofs + |
| 891 | IPU_CM_DC_REG_OFS, ipu_base + devtype->dc_tmpl_ofs); |
| 892 | if (ret) { |
| 893 | unit = "dc_template"; |
| 894 | goto err_dc; |
| 895 | } |
| 896 | |
| 897 | ret = ipu_dmfc_init(ipu, dev, ipu_base + |
| 898 | devtype->cm_ofs + IPU_CM_DMFC_REG_OFS, ipu_clk); |
| 899 | if (ret) { |
| 900 | unit = "dmfc"; |
| 901 | goto err_dmfc; |
| 902 | } |
| 903 | |
| 904 | ret = ipu_dp_init(ipu, dev, ipu_base + devtype->srm_ofs); |
| 905 | if (ret) { |
| 906 | unit = "dp"; |
| 907 | goto err_dp; |
| 908 | } |
| 909 | |
Philipp Zabel | 35de925 | 2012-05-09 16:59:01 +0200 | [diff] [blame] | 910 | ret = ipu_smfc_init(ipu, dev, ipu_base + |
| 911 | devtype->cm_ofs + IPU_CM_SMFC_REG_OFS); |
| 912 | if (ret) { |
| 913 | unit = "smfc"; |
| 914 | goto err_smfc; |
| 915 | } |
| 916 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 917 | return 0; |
| 918 | |
Philipp Zabel | 35de925 | 2012-05-09 16:59:01 +0200 | [diff] [blame] | 919 | err_smfc: |
| 920 | ipu_dp_exit(ipu); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 921 | err_dp: |
| 922 | ipu_dmfc_exit(ipu); |
| 923 | err_dmfc: |
| 924 | ipu_dc_exit(ipu); |
| 925 | err_dc: |
| 926 | ipu_di_exit(ipu, 1); |
| 927 | err_di_1: |
| 928 | ipu_di_exit(ipu, 0); |
| 929 | err_di_0: |
| 930 | dev_err(&pdev->dev, "init %s failed with %d\n", unit, ret); |
| 931 | return ret; |
| 932 | } |
| 933 | |
| 934 | static void ipu_irq_handle(struct ipu_soc *ipu, const int *regs, int num_regs) |
| 935 | { |
| 936 | unsigned long status; |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 937 | int i, bit, irq; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 938 | |
| 939 | for (i = 0; i < num_regs; i++) { |
| 940 | |
| 941 | status = ipu_cm_read(ipu, IPU_INT_STAT(regs[i])); |
| 942 | status &= ipu_cm_read(ipu, IPU_INT_CTRL(regs[i])); |
| 943 | |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 944 | for_each_set_bit(bit, &status, 32) { |
| 945 | irq = irq_linear_revmap(ipu->domain, regs[i] * 32 + bit); |
| 946 | if (irq) |
| 947 | generic_handle_irq(irq); |
| 948 | } |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 949 | } |
| 950 | } |
| 951 | |
| 952 | static void ipu_irq_handler(unsigned int irq, struct irq_desc *desc) |
| 953 | { |
| 954 | struct ipu_soc *ipu = irq_desc_get_handler_data(desc); |
| 955 | const int int_reg[] = { 0, 1, 2, 3, 10, 11, 12, 13, 14}; |
| 956 | struct irq_chip *chip = irq_get_chip(irq); |
| 957 | |
| 958 | chained_irq_enter(chip, desc); |
| 959 | |
| 960 | ipu_irq_handle(ipu, int_reg, ARRAY_SIZE(int_reg)); |
| 961 | |
| 962 | chained_irq_exit(chip, desc); |
| 963 | } |
| 964 | |
| 965 | static void ipu_err_irq_handler(unsigned int irq, struct irq_desc *desc) |
| 966 | { |
| 967 | struct ipu_soc *ipu = irq_desc_get_handler_data(desc); |
| 968 | const int int_reg[] = { 4, 5, 8, 9}; |
| 969 | struct irq_chip *chip = irq_get_chip(irq); |
| 970 | |
| 971 | chained_irq_enter(chip, desc); |
| 972 | |
| 973 | ipu_irq_handle(ipu, int_reg, ARRAY_SIZE(int_reg)); |
| 974 | |
| 975 | chained_irq_exit(chip, desc); |
| 976 | } |
| 977 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 978 | int ipu_idmac_channel_irq(struct ipu_soc *ipu, struct ipuv3_channel *channel, |
| 979 | enum ipu_channel_irq irq_type) |
| 980 | { |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 981 | int irq = irq_linear_revmap(ipu->domain, irq_type + channel->num); |
| 982 | |
| 983 | if (!irq) |
| 984 | irq = irq_create_mapping(ipu->domain, irq_type + channel->num); |
| 985 | |
| 986 | return irq; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 987 | } |
| 988 | EXPORT_SYMBOL_GPL(ipu_idmac_channel_irq); |
| 989 | |
| 990 | static void ipu_submodules_exit(struct ipu_soc *ipu) |
| 991 | { |
Philipp Zabel | 35de925 | 2012-05-09 16:59:01 +0200 | [diff] [blame] | 992 | ipu_smfc_exit(ipu); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 993 | ipu_dp_exit(ipu); |
| 994 | ipu_dmfc_exit(ipu); |
| 995 | ipu_dc_exit(ipu); |
| 996 | ipu_di_exit(ipu, 1); |
| 997 | ipu_di_exit(ipu, 0); |
| 998 | } |
| 999 | |
| 1000 | static int platform_remove_devices_fn(struct device *dev, void *unused) |
| 1001 | { |
| 1002 | struct platform_device *pdev = to_platform_device(dev); |
| 1003 | |
| 1004 | platform_device_unregister(pdev); |
| 1005 | |
| 1006 | return 0; |
| 1007 | } |
| 1008 | |
| 1009 | static void platform_device_unregister_children(struct platform_device *pdev) |
| 1010 | { |
| 1011 | device_for_each_child(&pdev->dev, NULL, platform_remove_devices_fn); |
| 1012 | } |
| 1013 | |
| 1014 | struct ipu_platform_reg { |
| 1015 | struct ipu_client_platformdata pdata; |
| 1016 | const char *name; |
| 1017 | }; |
| 1018 | |
| 1019 | static const struct ipu_platform_reg client_reg[] = { |
| 1020 | { |
| 1021 | .pdata = { |
| 1022 | .di = 0, |
| 1023 | .dc = 5, |
| 1024 | .dp = IPU_DP_FLOW_SYNC_BG, |
| 1025 | .dma[0] = IPUV3_CHANNEL_MEM_BG_SYNC, |
Philipp Zabel | b8d181e | 2013-10-10 16:18:45 +0200 | [diff] [blame] | 1026 | .dma[1] = IPUV3_CHANNEL_MEM_FG_SYNC, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1027 | }, |
| 1028 | .name = "imx-ipuv3-crtc", |
| 1029 | }, { |
| 1030 | .pdata = { |
| 1031 | .di = 1, |
| 1032 | .dc = 1, |
| 1033 | .dp = -EINVAL, |
| 1034 | .dma[0] = IPUV3_CHANNEL_MEM_DC_SYNC, |
| 1035 | .dma[1] = -EINVAL, |
| 1036 | }, |
| 1037 | .name = "imx-ipuv3-crtc", |
| 1038 | }, |
| 1039 | }; |
| 1040 | |
Russell King | 4ae078d | 2013-12-16 11:34:25 +0000 | [diff] [blame] | 1041 | static DEFINE_MUTEX(ipu_client_id_mutex); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1042 | static int ipu_client_id; |
| 1043 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1044 | static int ipu_add_client_devices(struct ipu_soc *ipu) |
| 1045 | { |
Russell King | 4ae078d | 2013-12-16 11:34:25 +0000 | [diff] [blame] | 1046 | struct device *dev = ipu->dev; |
| 1047 | unsigned i; |
| 1048 | int id, ret; |
| 1049 | |
| 1050 | mutex_lock(&ipu_client_id_mutex); |
| 1051 | id = ipu_client_id; |
| 1052 | ipu_client_id += ARRAY_SIZE(client_reg); |
| 1053 | mutex_unlock(&ipu_client_id_mutex); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1054 | |
| 1055 | for (i = 0; i < ARRAY_SIZE(client_reg); i++) { |
| 1056 | const struct ipu_platform_reg *reg = &client_reg[i]; |
Russell King | 4ae078d | 2013-12-16 11:34:25 +0000 | [diff] [blame] | 1057 | struct platform_device *pdev; |
| 1058 | |
| 1059 | pdev = platform_device_register_data(dev, reg->name, |
| 1060 | id++, ®->pdata, sizeof(reg->pdata)); |
| 1061 | |
| 1062 | if (IS_ERR(pdev)) |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1063 | goto err_register; |
| 1064 | } |
| 1065 | |
| 1066 | return 0; |
| 1067 | |
| 1068 | err_register: |
Russell King | 4ae078d | 2013-12-16 11:34:25 +0000 | [diff] [blame] | 1069 | platform_device_unregister_children(to_platform_device(dev)); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1070 | |
| 1071 | return ret; |
| 1072 | } |
| 1073 | |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 1074 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1075 | static int ipu_irq_init(struct ipu_soc *ipu) |
| 1076 | { |
Philipp Zabel | 379cdec | 2013-06-21 14:52:17 +0200 | [diff] [blame] | 1077 | struct irq_chip_generic *gc; |
| 1078 | struct irq_chip_type *ct; |
Philipp Zabel | 37f85b26 | 2013-06-21 14:52:18 +0200 | [diff] [blame] | 1079 | unsigned long unused[IPU_NUM_IRQS / 32] = { |
| 1080 | 0x400100d0, 0xffe000fd, |
| 1081 | 0x400100d0, 0xffe000fd, |
| 1082 | 0x400100d0, 0xffe000fd, |
| 1083 | 0x4077ffff, 0xffe7e1fd, |
| 1084 | 0x23fffffe, 0x8880fff0, |
| 1085 | 0xf98fe7d0, 0xfff81fff, |
| 1086 | 0x400100d0, 0xffe000fd, |
| 1087 | 0x00000000, |
| 1088 | }; |
Philipp Zabel | 379cdec | 2013-06-21 14:52:17 +0200 | [diff] [blame] | 1089 | int ret, i; |
| 1090 | |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 1091 | ipu->domain = irq_domain_add_linear(ipu->dev->of_node, IPU_NUM_IRQS, |
Philipp Zabel | 379cdec | 2013-06-21 14:52:17 +0200 | [diff] [blame] | 1092 | &irq_generic_chip_ops, ipu); |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 1093 | if (!ipu->domain) { |
| 1094 | dev_err(ipu->dev, "failed to add irq domain\n"); |
| 1095 | return -ENODEV; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1096 | } |
| 1097 | |
Philipp Zabel | 379cdec | 2013-06-21 14:52:17 +0200 | [diff] [blame] | 1098 | ret = irq_alloc_domain_generic_chips(ipu->domain, 32, 1, "IPU", |
| 1099 | handle_level_irq, 0, IRQF_VALID, 0); |
| 1100 | if (ret < 0) { |
| 1101 | dev_err(ipu->dev, "failed to alloc generic irq chips\n"); |
| 1102 | irq_domain_remove(ipu->domain); |
| 1103 | return ret; |
| 1104 | } |
| 1105 | |
| 1106 | for (i = 0; i < IPU_NUM_IRQS; i += 32) { |
| 1107 | gc = irq_get_domain_generic_chip(ipu->domain, i); |
| 1108 | gc->reg_base = ipu->cm_reg; |
Philipp Zabel | 37f85b26 | 2013-06-21 14:52:18 +0200 | [diff] [blame] | 1109 | gc->unused = unused[i / 32]; |
Philipp Zabel | 379cdec | 2013-06-21 14:52:17 +0200 | [diff] [blame] | 1110 | ct = gc->chip_types; |
| 1111 | ct->chip.irq_ack = irq_gc_ack_set_bit; |
| 1112 | ct->chip.irq_mask = irq_gc_mask_clr_bit; |
| 1113 | ct->chip.irq_unmask = irq_gc_mask_set_bit; |
| 1114 | ct->regs.ack = IPU_INT_STAT(i / 32); |
| 1115 | ct->regs.mask = IPU_INT_CTRL(i / 32); |
| 1116 | } |
| 1117 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1118 | irq_set_chained_handler(ipu->irq_sync, ipu_irq_handler); |
| 1119 | irq_set_handler_data(ipu->irq_sync, ipu); |
| 1120 | irq_set_chained_handler(ipu->irq_err, ipu_err_irq_handler); |
| 1121 | irq_set_handler_data(ipu->irq_err, ipu); |
| 1122 | |
| 1123 | return 0; |
| 1124 | } |
| 1125 | |
| 1126 | static void ipu_irq_exit(struct ipu_soc *ipu) |
| 1127 | { |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 1128 | int i, irq; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1129 | |
| 1130 | irq_set_chained_handler(ipu->irq_err, NULL); |
| 1131 | irq_set_handler_data(ipu->irq_err, NULL); |
| 1132 | irq_set_chained_handler(ipu->irq_sync, NULL); |
| 1133 | irq_set_handler_data(ipu->irq_sync, NULL); |
| 1134 | |
Philipp Zabel | 379cdec | 2013-06-21 14:52:17 +0200 | [diff] [blame] | 1135 | /* TODO: remove irq_domain_generic_chips */ |
| 1136 | |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 1137 | for (i = 0; i < IPU_NUM_IRQS; i++) { |
| 1138 | irq = irq_linear_revmap(ipu->domain, i); |
| 1139 | if (irq) |
| 1140 | irq_dispose_mapping(irq); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1141 | } |
| 1142 | |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 1143 | irq_domain_remove(ipu->domain); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1144 | } |
| 1145 | |
Bill Pemberton | c4aabf8 | 2012-11-19 13:22:11 -0500 | [diff] [blame] | 1146 | static int ipu_probe(struct platform_device *pdev) |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1147 | { |
| 1148 | const struct of_device_id *of_id = |
| 1149 | of_match_device(imx_ipu_dt_ids, &pdev->dev); |
| 1150 | struct ipu_soc *ipu; |
| 1151 | struct resource *res; |
| 1152 | unsigned long ipu_base; |
| 1153 | int i, ret, irq_sync, irq_err; |
| 1154 | const struct ipu_devtype *devtype; |
| 1155 | |
| 1156 | devtype = of_id->data; |
| 1157 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1158 | irq_sync = platform_get_irq(pdev, 0); |
| 1159 | irq_err = platform_get_irq(pdev, 1); |
| 1160 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 1161 | |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 1162 | dev_dbg(&pdev->dev, "irq_sync: %d irq_err: %d\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1163 | irq_sync, irq_err); |
| 1164 | |
| 1165 | if (!res || irq_sync < 0 || irq_err < 0) |
| 1166 | return -ENODEV; |
| 1167 | |
| 1168 | ipu_base = res->start; |
| 1169 | |
| 1170 | ipu = devm_kzalloc(&pdev->dev, sizeof(*ipu), GFP_KERNEL); |
| 1171 | if (!ipu) |
| 1172 | return -ENODEV; |
| 1173 | |
| 1174 | for (i = 0; i < 64; i++) |
| 1175 | ipu->channel[i].ipu = ipu; |
| 1176 | ipu->devtype = devtype; |
| 1177 | ipu->ipu_type = devtype->type; |
| 1178 | |
| 1179 | spin_lock_init(&ipu->lock); |
| 1180 | mutex_init(&ipu->channel_lock); |
| 1181 | |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 1182 | dev_dbg(&pdev->dev, "cm_reg: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1183 | ipu_base + devtype->cm_ofs); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 1184 | dev_dbg(&pdev->dev, "idmac: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1185 | ipu_base + devtype->cm_ofs + IPU_CM_IDMAC_REG_OFS); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 1186 | dev_dbg(&pdev->dev, "cpmem: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1187 | ipu_base + devtype->cpmem_ofs); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 1188 | dev_dbg(&pdev->dev, "disp0: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1189 | ipu_base + devtype->disp0_ofs); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 1190 | dev_dbg(&pdev->dev, "disp1: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1191 | ipu_base + devtype->disp1_ofs); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 1192 | dev_dbg(&pdev->dev, "srm: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1193 | ipu_base + devtype->srm_ofs); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 1194 | dev_dbg(&pdev->dev, "tpm: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1195 | ipu_base + devtype->tpm_ofs); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 1196 | dev_dbg(&pdev->dev, "dc: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1197 | ipu_base + devtype->cm_ofs + IPU_CM_DC_REG_OFS); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 1198 | dev_dbg(&pdev->dev, "ic: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1199 | ipu_base + devtype->cm_ofs + IPU_CM_IC_REG_OFS); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 1200 | dev_dbg(&pdev->dev, "dmfc: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1201 | ipu_base + devtype->cm_ofs + IPU_CM_DMFC_REG_OFS); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 1202 | dev_dbg(&pdev->dev, "vdi: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1203 | ipu_base + devtype->vdi_ofs); |
| 1204 | |
| 1205 | ipu->cm_reg = devm_ioremap(&pdev->dev, |
| 1206 | ipu_base + devtype->cm_ofs, PAGE_SIZE); |
| 1207 | ipu->idmac_reg = devm_ioremap(&pdev->dev, |
| 1208 | ipu_base + devtype->cm_ofs + IPU_CM_IDMAC_REG_OFS, |
| 1209 | PAGE_SIZE); |
| 1210 | ipu->cpmem_base = devm_ioremap(&pdev->dev, |
| 1211 | ipu_base + devtype->cpmem_ofs, PAGE_SIZE); |
| 1212 | |
Fabio Estevam | be798b2 | 2013-07-20 18:22:09 -0300 | [diff] [blame] | 1213 | if (!ipu->cm_reg || !ipu->idmac_reg || !ipu->cpmem_base) |
| 1214 | return -ENOMEM; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1215 | |
| 1216 | ipu->clk = devm_clk_get(&pdev->dev, "bus"); |
| 1217 | if (IS_ERR(ipu->clk)) { |
| 1218 | ret = PTR_ERR(ipu->clk); |
| 1219 | dev_err(&pdev->dev, "clk_get failed with %d", ret); |
Fabio Estevam | be798b2 | 2013-07-20 18:22:09 -0300 | [diff] [blame] | 1220 | return ret; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | platform_set_drvdata(pdev, ipu); |
| 1224 | |
Fabio Estevam | 62645a2 | 2013-07-20 18:22:10 -0300 | [diff] [blame] | 1225 | ret = clk_prepare_enable(ipu->clk); |
| 1226 | if (ret) { |
| 1227 | dev_err(&pdev->dev, "clk_prepare_enable failed: %d\n", ret); |
| 1228 | return ret; |
| 1229 | } |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1230 | |
| 1231 | ipu->dev = &pdev->dev; |
| 1232 | ipu->irq_sync = irq_sync; |
| 1233 | ipu->irq_err = irq_err; |
| 1234 | |
| 1235 | ret = ipu_irq_init(ipu); |
| 1236 | if (ret) |
| 1237 | goto out_failed_irq; |
| 1238 | |
Philipp Zabel | 6c64155 | 2013-03-28 17:35:21 +0100 | [diff] [blame] | 1239 | ret = device_reset(&pdev->dev); |
| 1240 | if (ret) { |
| 1241 | dev_err(&pdev->dev, "failed to reset: %d\n", ret); |
| 1242 | goto out_failed_reset; |
| 1243 | } |
| 1244 | ret = ipu_memory_reset(ipu); |
Lothar Waßmann | 4d27b2c | 2012-12-25 15:58:37 +0100 | [diff] [blame] | 1245 | if (ret) |
| 1246 | goto out_failed_reset; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1247 | |
| 1248 | /* Set MCU_T to divide MCU access window into 2 */ |
| 1249 | ipu_cm_write(ipu, 0x00400000L | (IPU_MCU_T_DEFAULT << 18), |
| 1250 | IPU_DISP_GEN); |
| 1251 | |
| 1252 | ret = ipu_submodules_init(ipu, pdev, ipu_base, ipu->clk); |
| 1253 | if (ret) |
| 1254 | goto failed_submodules_init; |
| 1255 | |
| 1256 | ret = ipu_add_client_devices(ipu); |
| 1257 | if (ret) { |
| 1258 | dev_err(&pdev->dev, "adding client devices failed with %d\n", |
| 1259 | ret); |
| 1260 | goto failed_add_clients; |
| 1261 | } |
| 1262 | |
Fabio Estevam | 9c2c438c | 2012-10-24 21:36:47 -0200 | [diff] [blame] | 1263 | dev_info(&pdev->dev, "%s probed\n", devtype->name); |
| 1264 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1265 | return 0; |
| 1266 | |
| 1267 | failed_add_clients: |
| 1268 | ipu_submodules_exit(ipu); |
| 1269 | failed_submodules_init: |
Lothar Waßmann | 4d27b2c | 2012-12-25 15:58:37 +0100 | [diff] [blame] | 1270 | out_failed_reset: |
Philipp Zabel | 6c64155 | 2013-03-28 17:35:21 +0100 | [diff] [blame] | 1271 | ipu_irq_exit(ipu); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1272 | out_failed_irq: |
| 1273 | clk_disable_unprepare(ipu->clk); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1274 | return ret; |
| 1275 | } |
| 1276 | |
Bill Pemberton | 8aa1be4 | 2012-11-19 13:26:38 -0500 | [diff] [blame] | 1277 | static int ipu_remove(struct platform_device *pdev) |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1278 | { |
| 1279 | struct ipu_soc *ipu = platform_get_drvdata(pdev); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1280 | |
| 1281 | platform_device_unregister_children(pdev); |
| 1282 | ipu_submodules_exit(ipu); |
| 1283 | ipu_irq_exit(ipu); |
| 1284 | |
| 1285 | clk_disable_unprepare(ipu->clk); |
| 1286 | |
| 1287 | return 0; |
| 1288 | } |
| 1289 | |
| 1290 | static struct platform_driver imx_ipu_driver = { |
| 1291 | .driver = { |
| 1292 | .name = "imx-ipuv3", |
| 1293 | .of_match_table = imx_ipu_dt_ids, |
| 1294 | }, |
| 1295 | .probe = ipu_probe, |
Bill Pemberton | 99c28f1 | 2012-11-19 13:20:51 -0500 | [diff] [blame] | 1296 | .remove = ipu_remove, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1297 | }; |
| 1298 | |
| 1299 | module_platform_driver(imx_ipu_driver); |
| 1300 | |
Fabio Estevam | 10f2268 | 2013-07-20 18:22:11 -0300 | [diff] [blame] | 1301 | MODULE_ALIAS("platform:imx-ipuv3"); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1302 | MODULE_DESCRIPTION("i.MX IPU v3 driver"); |
| 1303 | MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); |
| 1304 | MODULE_LICENSE("GPL"); |