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 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 47 | void ipu_srm_dp_sync_update(struct ipu_soc *ipu) |
| 48 | { |
| 49 | u32 val; |
| 50 | |
| 51 | val = ipu_cm_read(ipu, IPU_SRM_PRI2); |
| 52 | val |= 0x8; |
| 53 | ipu_cm_write(ipu, val, IPU_SRM_PRI2); |
| 54 | } |
| 55 | EXPORT_SYMBOL_GPL(ipu_srm_dp_sync_update); |
| 56 | |
Philipp Zabel | 7cb1779 | 2013-10-10 16:18:38 +0200 | [diff] [blame] | 57 | enum ipu_color_space ipu_drm_fourcc_to_colorspace(u32 drm_fourcc) |
| 58 | { |
| 59 | switch (drm_fourcc) { |
| 60 | case DRM_FORMAT_RGB565: |
| 61 | case DRM_FORMAT_BGR565: |
| 62 | case DRM_FORMAT_RGB888: |
| 63 | case DRM_FORMAT_BGR888: |
| 64 | case DRM_FORMAT_XRGB8888: |
| 65 | case DRM_FORMAT_XBGR8888: |
| 66 | case DRM_FORMAT_RGBX8888: |
| 67 | case DRM_FORMAT_BGRX8888: |
| 68 | case DRM_FORMAT_ARGB8888: |
| 69 | case DRM_FORMAT_ABGR8888: |
| 70 | case DRM_FORMAT_RGBA8888: |
| 71 | case DRM_FORMAT_BGRA8888: |
| 72 | return IPUV3_COLORSPACE_RGB; |
| 73 | case DRM_FORMAT_YUYV: |
| 74 | case DRM_FORMAT_UYVY: |
| 75 | case DRM_FORMAT_YUV420: |
| 76 | case DRM_FORMAT_YVU420: |
| 77 | return IPUV3_COLORSPACE_YUV; |
| 78 | default: |
| 79 | return IPUV3_COLORSPACE_UNKNOWN; |
| 80 | } |
| 81 | } |
| 82 | EXPORT_SYMBOL_GPL(ipu_drm_fourcc_to_colorspace); |
| 83 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 84 | enum ipu_color_space ipu_pixelformat_to_colorspace(u32 pixelformat) |
| 85 | { |
| 86 | switch (pixelformat) { |
| 87 | case V4L2_PIX_FMT_YUV420: |
Philipp Zabel | d3e4e61 | 2012-11-12 16:29:00 +0100 | [diff] [blame] | 88 | case V4L2_PIX_FMT_YVU420: |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 89 | case V4L2_PIX_FMT_UYVY: |
Michael Olbrich | c096ae1 | 2012-11-12 16:28:59 +0100 | [diff] [blame] | 90 | case V4L2_PIX_FMT_YUYV: |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 91 | return IPUV3_COLORSPACE_YUV; |
| 92 | case V4L2_PIX_FMT_RGB32: |
| 93 | case V4L2_PIX_FMT_BGR32: |
| 94 | case V4L2_PIX_FMT_RGB24: |
| 95 | case V4L2_PIX_FMT_BGR24: |
| 96 | case V4L2_PIX_FMT_RGB565: |
| 97 | return IPUV3_COLORSPACE_RGB; |
| 98 | default: |
| 99 | return IPUV3_COLORSPACE_UNKNOWN; |
| 100 | } |
| 101 | } |
| 102 | EXPORT_SYMBOL_GPL(ipu_pixelformat_to_colorspace); |
| 103 | |
Steve Longerbeam | ae0e970 | 2014-06-25 18:05:36 -0700 | [diff] [blame] | 104 | enum ipu_color_space ipu_mbus_code_to_colorspace(u32 mbus_code) |
| 105 | { |
| 106 | switch (mbus_code & 0xf000) { |
| 107 | case 0x1000: |
| 108 | return IPUV3_COLORSPACE_RGB; |
| 109 | case 0x2000: |
| 110 | return IPUV3_COLORSPACE_YUV; |
| 111 | default: |
| 112 | return IPUV3_COLORSPACE_UNKNOWN; |
| 113 | } |
| 114 | } |
| 115 | EXPORT_SYMBOL_GPL(ipu_mbus_code_to_colorspace); |
| 116 | |
Steve Longerbeam | f835f38 | 2014-06-25 18:05:37 -0700 | [diff] [blame^] | 117 | int ipu_degrees_to_rot_mode(enum ipu_rotate_mode *mode, int degrees, |
| 118 | bool hflip, bool vflip) |
| 119 | { |
| 120 | u32 r90, vf, hf; |
| 121 | |
| 122 | switch (degrees) { |
| 123 | case 0: |
| 124 | vf = hf = r90 = 0; |
| 125 | break; |
| 126 | case 90: |
| 127 | vf = hf = 0; |
| 128 | r90 = 1; |
| 129 | break; |
| 130 | case 180: |
| 131 | vf = hf = 1; |
| 132 | r90 = 0; |
| 133 | break; |
| 134 | case 270: |
| 135 | vf = hf = r90 = 1; |
| 136 | break; |
| 137 | default: |
| 138 | return -EINVAL; |
| 139 | } |
| 140 | |
| 141 | hf ^= (u32)hflip; |
| 142 | vf ^= (u32)vflip; |
| 143 | |
| 144 | *mode = (enum ipu_rotate_mode)((r90 << 2) | (hf << 1) | vf); |
| 145 | return 0; |
| 146 | } |
| 147 | EXPORT_SYMBOL_GPL(ipu_degrees_to_rot_mode); |
| 148 | |
| 149 | int ipu_rot_mode_to_degrees(int *degrees, enum ipu_rotate_mode mode, |
| 150 | bool hflip, bool vflip) |
| 151 | { |
| 152 | u32 r90, vf, hf; |
| 153 | |
| 154 | r90 = ((u32)mode >> 2) & 0x1; |
| 155 | hf = ((u32)mode >> 1) & 0x1; |
| 156 | vf = ((u32)mode >> 0) & 0x1; |
| 157 | hf ^= (u32)hflip; |
| 158 | vf ^= (u32)vflip; |
| 159 | |
| 160 | switch ((enum ipu_rotate_mode)((r90 << 2) | (hf << 1) | vf)) { |
| 161 | case IPU_ROTATE_NONE: |
| 162 | *degrees = 0; |
| 163 | break; |
| 164 | case IPU_ROTATE_90_RIGHT: |
| 165 | *degrees = 90; |
| 166 | break; |
| 167 | case IPU_ROTATE_180: |
| 168 | *degrees = 180; |
| 169 | break; |
| 170 | case IPU_ROTATE_90_LEFT: |
| 171 | *degrees = 270; |
| 172 | break; |
| 173 | default: |
| 174 | return -EINVAL; |
| 175 | } |
| 176 | |
| 177 | return 0; |
| 178 | } |
| 179 | EXPORT_SYMBOL_GPL(ipu_rot_mode_to_degrees); |
| 180 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 181 | struct ipuv3_channel *ipu_idmac_get(struct ipu_soc *ipu, unsigned num) |
| 182 | { |
| 183 | struct ipuv3_channel *channel; |
| 184 | |
| 185 | dev_dbg(ipu->dev, "%s %d\n", __func__, num); |
| 186 | |
| 187 | if (num > 63) |
| 188 | return ERR_PTR(-ENODEV); |
| 189 | |
| 190 | mutex_lock(&ipu->channel_lock); |
| 191 | |
| 192 | channel = &ipu->channel[num]; |
| 193 | |
| 194 | if (channel->busy) { |
| 195 | channel = ERR_PTR(-EBUSY); |
| 196 | goto out; |
| 197 | } |
| 198 | |
Valentina Manea | 89bc5be | 2013-10-25 11:52:20 +0300 | [diff] [blame] | 199 | channel->busy = true; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 200 | channel->num = num; |
| 201 | |
| 202 | out: |
| 203 | mutex_unlock(&ipu->channel_lock); |
| 204 | |
| 205 | return channel; |
| 206 | } |
| 207 | EXPORT_SYMBOL_GPL(ipu_idmac_get); |
| 208 | |
| 209 | void ipu_idmac_put(struct ipuv3_channel *channel) |
| 210 | { |
| 211 | struct ipu_soc *ipu = channel->ipu; |
| 212 | |
| 213 | dev_dbg(ipu->dev, "%s %d\n", __func__, channel->num); |
| 214 | |
| 215 | mutex_lock(&ipu->channel_lock); |
| 216 | |
Valentina Manea | 89bc5be | 2013-10-25 11:52:20 +0300 | [diff] [blame] | 217 | channel->busy = false; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 218 | |
| 219 | mutex_unlock(&ipu->channel_lock); |
| 220 | } |
| 221 | EXPORT_SYMBOL_GPL(ipu_idmac_put); |
| 222 | |
| 223 | #define idma_mask(ch) (1 << (ch & 0x1f)) |
| 224 | |
| 225 | void ipu_idmac_set_double_buffer(struct ipuv3_channel *channel, |
| 226 | bool doublebuffer) |
| 227 | { |
| 228 | struct ipu_soc *ipu = channel->ipu; |
| 229 | unsigned long flags; |
| 230 | u32 reg; |
| 231 | |
| 232 | spin_lock_irqsave(&ipu->lock, flags); |
| 233 | |
| 234 | reg = ipu_cm_read(ipu, IPU_CHA_DB_MODE_SEL(channel->num)); |
| 235 | if (doublebuffer) |
| 236 | reg |= idma_mask(channel->num); |
| 237 | else |
| 238 | reg &= ~idma_mask(channel->num); |
| 239 | ipu_cm_write(ipu, reg, IPU_CHA_DB_MODE_SEL(channel->num)); |
| 240 | |
| 241 | spin_unlock_irqrestore(&ipu->lock, flags); |
| 242 | } |
| 243 | EXPORT_SYMBOL_GPL(ipu_idmac_set_double_buffer); |
| 244 | |
| 245 | int ipu_module_enable(struct ipu_soc *ipu, u32 mask) |
| 246 | { |
| 247 | unsigned long lock_flags; |
| 248 | u32 val; |
| 249 | |
| 250 | spin_lock_irqsave(&ipu->lock, lock_flags); |
| 251 | |
| 252 | val = ipu_cm_read(ipu, IPU_DISP_GEN); |
| 253 | |
| 254 | if (mask & IPU_CONF_DI0_EN) |
| 255 | val |= IPU_DI0_COUNTER_RELEASE; |
| 256 | if (mask & IPU_CONF_DI1_EN) |
| 257 | val |= IPU_DI1_COUNTER_RELEASE; |
| 258 | |
| 259 | ipu_cm_write(ipu, val, IPU_DISP_GEN); |
| 260 | |
| 261 | val = ipu_cm_read(ipu, IPU_CONF); |
| 262 | val |= mask; |
| 263 | ipu_cm_write(ipu, val, IPU_CONF); |
| 264 | |
| 265 | spin_unlock_irqrestore(&ipu->lock, lock_flags); |
| 266 | |
| 267 | return 0; |
| 268 | } |
| 269 | EXPORT_SYMBOL_GPL(ipu_module_enable); |
| 270 | |
| 271 | int ipu_module_disable(struct ipu_soc *ipu, u32 mask) |
| 272 | { |
| 273 | unsigned long lock_flags; |
| 274 | u32 val; |
| 275 | |
| 276 | spin_lock_irqsave(&ipu->lock, lock_flags); |
| 277 | |
| 278 | val = ipu_cm_read(ipu, IPU_CONF); |
| 279 | val &= ~mask; |
| 280 | ipu_cm_write(ipu, val, IPU_CONF); |
| 281 | |
| 282 | val = ipu_cm_read(ipu, IPU_DISP_GEN); |
| 283 | |
| 284 | if (mask & IPU_CONF_DI0_EN) |
| 285 | val &= ~IPU_DI0_COUNTER_RELEASE; |
| 286 | if (mask & IPU_CONF_DI1_EN) |
| 287 | val &= ~IPU_DI1_COUNTER_RELEASE; |
| 288 | |
| 289 | ipu_cm_write(ipu, val, IPU_DISP_GEN); |
| 290 | |
| 291 | spin_unlock_irqrestore(&ipu->lock, lock_flags); |
| 292 | |
| 293 | return 0; |
| 294 | } |
| 295 | EXPORT_SYMBOL_GPL(ipu_module_disable); |
| 296 | |
Philipp Zabel | e904609 | 2012-05-16 17:28:29 +0200 | [diff] [blame] | 297 | int ipu_idmac_get_current_buffer(struct ipuv3_channel *channel) |
| 298 | { |
| 299 | struct ipu_soc *ipu = channel->ipu; |
| 300 | unsigned int chno = channel->num; |
| 301 | |
| 302 | return (ipu_cm_read(ipu, IPU_CHA_CUR_BUF(chno)) & idma_mask(chno)) ? 1 : 0; |
| 303 | } |
| 304 | EXPORT_SYMBOL_GPL(ipu_idmac_get_current_buffer); |
| 305 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 306 | void ipu_idmac_select_buffer(struct ipuv3_channel *channel, u32 buf_num) |
| 307 | { |
| 308 | struct ipu_soc *ipu = channel->ipu; |
| 309 | unsigned int chno = channel->num; |
| 310 | unsigned long flags; |
| 311 | |
| 312 | spin_lock_irqsave(&ipu->lock, flags); |
| 313 | |
| 314 | /* Mark buffer as ready. */ |
| 315 | if (buf_num == 0) |
| 316 | ipu_cm_write(ipu, idma_mask(chno), IPU_CHA_BUF0_RDY(chno)); |
| 317 | else |
| 318 | ipu_cm_write(ipu, idma_mask(chno), IPU_CHA_BUF1_RDY(chno)); |
| 319 | |
| 320 | spin_unlock_irqrestore(&ipu->lock, flags); |
| 321 | } |
| 322 | EXPORT_SYMBOL_GPL(ipu_idmac_select_buffer); |
| 323 | |
| 324 | int ipu_idmac_enable_channel(struct ipuv3_channel *channel) |
| 325 | { |
| 326 | struct ipu_soc *ipu = channel->ipu; |
| 327 | u32 val; |
| 328 | unsigned long flags; |
| 329 | |
| 330 | spin_lock_irqsave(&ipu->lock, flags); |
| 331 | |
| 332 | val = ipu_idmac_read(ipu, IDMAC_CHA_EN(channel->num)); |
| 333 | val |= idma_mask(channel->num); |
| 334 | ipu_idmac_write(ipu, val, IDMAC_CHA_EN(channel->num)); |
| 335 | |
| 336 | spin_unlock_irqrestore(&ipu->lock, flags); |
| 337 | |
| 338 | return 0; |
| 339 | } |
| 340 | EXPORT_SYMBOL_GPL(ipu_idmac_enable_channel); |
| 341 | |
Philipp Zabel | 1707550 | 2014-04-14 23:53:17 +0200 | [diff] [blame] | 342 | bool ipu_idmac_channel_busy(struct ipu_soc *ipu, unsigned int chno) |
| 343 | { |
| 344 | return (ipu_idmac_read(ipu, IDMAC_CHA_BUSY(chno)) & idma_mask(chno)); |
| 345 | } |
| 346 | EXPORT_SYMBOL_GPL(ipu_idmac_channel_busy); |
| 347 | |
Sascha Hauer | fb822a3 | 2013-10-10 16:18:41 +0200 | [diff] [blame] | 348 | int ipu_idmac_wait_busy(struct ipuv3_channel *channel, int ms) |
| 349 | { |
| 350 | struct ipu_soc *ipu = channel->ipu; |
| 351 | unsigned long timeout; |
| 352 | |
| 353 | timeout = jiffies + msecs_to_jiffies(ms); |
| 354 | while (ipu_idmac_read(ipu, IDMAC_CHA_BUSY(channel->num)) & |
| 355 | idma_mask(channel->num)) { |
| 356 | if (time_after(jiffies, timeout)) |
| 357 | return -ETIMEDOUT; |
| 358 | cpu_relax(); |
| 359 | } |
| 360 | |
| 361 | return 0; |
| 362 | } |
| 363 | EXPORT_SYMBOL_GPL(ipu_idmac_wait_busy); |
| 364 | |
Philipp Zabel | 1707550 | 2014-04-14 23:53:17 +0200 | [diff] [blame] | 365 | int ipu_wait_interrupt(struct ipu_soc *ipu, int irq, int ms) |
| 366 | { |
| 367 | unsigned long timeout; |
| 368 | |
| 369 | timeout = jiffies + msecs_to_jiffies(ms); |
| 370 | ipu_cm_write(ipu, BIT(irq % 32), IPU_INT_STAT(irq / 32)); |
| 371 | while (!(ipu_cm_read(ipu, IPU_INT_STAT(irq / 32) & BIT(irq % 32)))) { |
| 372 | if (time_after(jiffies, timeout)) |
| 373 | return -ETIMEDOUT; |
| 374 | cpu_relax(); |
| 375 | } |
| 376 | |
| 377 | return 0; |
| 378 | } |
| 379 | EXPORT_SYMBOL_GPL(ipu_wait_interrupt); |
| 380 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 381 | int ipu_idmac_disable_channel(struct ipuv3_channel *channel) |
| 382 | { |
| 383 | struct ipu_soc *ipu = channel->ipu; |
| 384 | u32 val; |
| 385 | unsigned long flags; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 386 | |
| 387 | spin_lock_irqsave(&ipu->lock, flags); |
| 388 | |
| 389 | /* Disable DMA channel(s) */ |
| 390 | val = ipu_idmac_read(ipu, IDMAC_CHA_EN(channel->num)); |
| 391 | val &= ~idma_mask(channel->num); |
| 392 | ipu_idmac_write(ipu, val, IDMAC_CHA_EN(channel->num)); |
| 393 | |
| 394 | /* Set channel buffers NOT to be ready */ |
| 395 | ipu_cm_write(ipu, 0xf0000000, IPU_GPR); /* write one to clear */ |
| 396 | |
| 397 | if (ipu_cm_read(ipu, IPU_CHA_BUF0_RDY(channel->num)) & |
| 398 | idma_mask(channel->num)) { |
| 399 | ipu_cm_write(ipu, idma_mask(channel->num), |
| 400 | IPU_CHA_BUF0_RDY(channel->num)); |
| 401 | } |
| 402 | |
| 403 | if (ipu_cm_read(ipu, IPU_CHA_BUF1_RDY(channel->num)) & |
| 404 | idma_mask(channel->num)) { |
| 405 | ipu_cm_write(ipu, idma_mask(channel->num), |
| 406 | IPU_CHA_BUF1_RDY(channel->num)); |
| 407 | } |
| 408 | |
| 409 | ipu_cm_write(ipu, 0x0, IPU_GPR); /* write one to set */ |
| 410 | |
| 411 | /* Reset the double buffer */ |
| 412 | val = ipu_cm_read(ipu, IPU_CHA_DB_MODE_SEL(channel->num)); |
| 413 | val &= ~idma_mask(channel->num); |
| 414 | ipu_cm_write(ipu, val, IPU_CHA_DB_MODE_SEL(channel->num)); |
| 415 | |
| 416 | spin_unlock_irqrestore(&ipu->lock, flags); |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | EXPORT_SYMBOL_GPL(ipu_idmac_disable_channel); |
| 421 | |
Philipp Zabel | 6c64155 | 2013-03-28 17:35:21 +0100 | [diff] [blame] | 422 | static int ipu_memory_reset(struct ipu_soc *ipu) |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 423 | { |
| 424 | unsigned long timeout; |
| 425 | |
| 426 | ipu_cm_write(ipu, 0x807FFFFF, IPU_MEM_RST); |
| 427 | |
| 428 | timeout = jiffies + msecs_to_jiffies(1000); |
| 429 | while (ipu_cm_read(ipu, IPU_MEM_RST) & 0x80000000) { |
| 430 | if (time_after(jiffies, timeout)) |
| 431 | return -ETIME; |
| 432 | cpu_relax(); |
| 433 | } |
| 434 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 435 | return 0; |
| 436 | } |
| 437 | |
Steve Longerbeam | ba07975 | 2014-06-25 18:05:30 -0700 | [diff] [blame] | 438 | /* |
| 439 | * Set the source mux for the given CSI. Selects either parallel or |
| 440 | * MIPI CSI2 sources. |
| 441 | */ |
| 442 | void ipu_set_csi_src_mux(struct ipu_soc *ipu, int csi_id, bool mipi_csi2) |
| 443 | { |
| 444 | unsigned long flags; |
| 445 | u32 val, mask; |
| 446 | |
| 447 | mask = (csi_id == 1) ? IPU_CONF_CSI1_DATA_SOURCE : |
| 448 | IPU_CONF_CSI0_DATA_SOURCE; |
| 449 | |
| 450 | spin_lock_irqsave(&ipu->lock, flags); |
| 451 | |
| 452 | val = ipu_cm_read(ipu, IPU_CONF); |
| 453 | if (mipi_csi2) |
| 454 | val |= mask; |
| 455 | else |
| 456 | val &= ~mask; |
| 457 | ipu_cm_write(ipu, val, IPU_CONF); |
| 458 | |
| 459 | spin_unlock_irqrestore(&ipu->lock, flags); |
| 460 | } |
| 461 | EXPORT_SYMBOL_GPL(ipu_set_csi_src_mux); |
| 462 | |
| 463 | /* |
| 464 | * Set the source mux for the IC. Selects either CSI[01] or the VDI. |
| 465 | */ |
| 466 | void ipu_set_ic_src_mux(struct ipu_soc *ipu, int csi_id, bool vdi) |
| 467 | { |
| 468 | unsigned long flags; |
| 469 | u32 val; |
| 470 | |
| 471 | spin_lock_irqsave(&ipu->lock, flags); |
| 472 | |
| 473 | val = ipu_cm_read(ipu, IPU_CONF); |
| 474 | if (vdi) { |
| 475 | val |= IPU_CONF_IC_INPUT; |
| 476 | } else { |
| 477 | val &= ~IPU_CONF_IC_INPUT; |
| 478 | if (csi_id == 1) |
| 479 | val |= IPU_CONF_CSI_SEL; |
| 480 | else |
| 481 | val &= ~IPU_CONF_CSI_SEL; |
| 482 | } |
| 483 | ipu_cm_write(ipu, val, IPU_CONF); |
| 484 | |
| 485 | spin_unlock_irqrestore(&ipu->lock, flags); |
| 486 | } |
| 487 | EXPORT_SYMBOL_GPL(ipu_set_ic_src_mux); |
| 488 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 489 | struct ipu_devtype { |
| 490 | const char *name; |
| 491 | unsigned long cm_ofs; |
| 492 | unsigned long cpmem_ofs; |
| 493 | unsigned long srm_ofs; |
| 494 | unsigned long tpm_ofs; |
Steve Longerbeam | 2ffd48f | 2014-08-19 10:52:40 -0700 | [diff] [blame] | 495 | unsigned long csi0_ofs; |
| 496 | unsigned long csi1_ofs; |
Steve Longerbeam | 1aa8ea0 | 2014-08-11 13:04:50 +0200 | [diff] [blame] | 497 | unsigned long ic_ofs; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 498 | unsigned long disp0_ofs; |
| 499 | unsigned long disp1_ofs; |
| 500 | unsigned long dc_tmpl_ofs; |
| 501 | unsigned long vdi_ofs; |
| 502 | enum ipuv3_type type; |
| 503 | }; |
| 504 | |
| 505 | static struct ipu_devtype ipu_type_imx51 = { |
| 506 | .name = "IPUv3EX", |
| 507 | .cm_ofs = 0x1e000000, |
| 508 | .cpmem_ofs = 0x1f000000, |
| 509 | .srm_ofs = 0x1f040000, |
| 510 | .tpm_ofs = 0x1f060000, |
Steve Longerbeam | 2ffd48f | 2014-08-19 10:52:40 -0700 | [diff] [blame] | 511 | .csi0_ofs = 0x1f030000, |
| 512 | .csi1_ofs = 0x1f038000, |
Steve Longerbeam | 1aa8ea0 | 2014-08-11 13:04:50 +0200 | [diff] [blame] | 513 | .ic_ofs = 0x1f020000, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 514 | .disp0_ofs = 0x1e040000, |
| 515 | .disp1_ofs = 0x1e048000, |
| 516 | .dc_tmpl_ofs = 0x1f080000, |
| 517 | .vdi_ofs = 0x1e068000, |
| 518 | .type = IPUV3EX, |
| 519 | }; |
| 520 | |
| 521 | static struct ipu_devtype ipu_type_imx53 = { |
| 522 | .name = "IPUv3M", |
| 523 | .cm_ofs = 0x06000000, |
| 524 | .cpmem_ofs = 0x07000000, |
| 525 | .srm_ofs = 0x07040000, |
| 526 | .tpm_ofs = 0x07060000, |
Steve Longerbeam | 2ffd48f | 2014-08-19 10:52:40 -0700 | [diff] [blame] | 527 | .csi0_ofs = 0x07030000, |
| 528 | .csi1_ofs = 0x07038000, |
Steve Longerbeam | 1aa8ea0 | 2014-08-11 13:04:50 +0200 | [diff] [blame] | 529 | .ic_ofs = 0x07020000, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 530 | .disp0_ofs = 0x06040000, |
| 531 | .disp1_ofs = 0x06048000, |
| 532 | .dc_tmpl_ofs = 0x07080000, |
| 533 | .vdi_ofs = 0x06068000, |
| 534 | .type = IPUV3M, |
| 535 | }; |
| 536 | |
| 537 | static struct ipu_devtype ipu_type_imx6q = { |
| 538 | .name = "IPUv3H", |
| 539 | .cm_ofs = 0x00200000, |
| 540 | .cpmem_ofs = 0x00300000, |
| 541 | .srm_ofs = 0x00340000, |
| 542 | .tpm_ofs = 0x00360000, |
Steve Longerbeam | 2ffd48f | 2014-08-19 10:52:40 -0700 | [diff] [blame] | 543 | .csi0_ofs = 0x00230000, |
| 544 | .csi1_ofs = 0x00238000, |
Steve Longerbeam | 1aa8ea0 | 2014-08-11 13:04:50 +0200 | [diff] [blame] | 545 | .ic_ofs = 0x00220000, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 546 | .disp0_ofs = 0x00240000, |
| 547 | .disp1_ofs = 0x00248000, |
| 548 | .dc_tmpl_ofs = 0x00380000, |
| 549 | .vdi_ofs = 0x00268000, |
| 550 | .type = IPUV3H, |
| 551 | }; |
| 552 | |
| 553 | static const struct of_device_id imx_ipu_dt_ids[] = { |
| 554 | { .compatible = "fsl,imx51-ipu", .data = &ipu_type_imx51, }, |
| 555 | { .compatible = "fsl,imx53-ipu", .data = &ipu_type_imx53, }, |
| 556 | { .compatible = "fsl,imx6q-ipu", .data = &ipu_type_imx6q, }, |
| 557 | { /* sentinel */ } |
| 558 | }; |
| 559 | MODULE_DEVICE_TABLE(of, imx_ipu_dt_ids); |
| 560 | |
| 561 | static int ipu_submodules_init(struct ipu_soc *ipu, |
| 562 | struct platform_device *pdev, unsigned long ipu_base, |
| 563 | struct clk *ipu_clk) |
| 564 | { |
| 565 | char *unit; |
| 566 | int ret; |
| 567 | struct device *dev = &pdev->dev; |
| 568 | const struct ipu_devtype *devtype = ipu->devtype; |
| 569 | |
Steve Longerbeam | 7d2691d | 2014-06-25 18:05:47 -0700 | [diff] [blame] | 570 | ret = ipu_cpmem_init(ipu, dev, ipu_base + devtype->cpmem_ofs); |
| 571 | if (ret) { |
| 572 | unit = "cpmem"; |
| 573 | goto err_cpmem; |
| 574 | } |
| 575 | |
Steve Longerbeam | 2ffd48f | 2014-08-19 10:52:40 -0700 | [diff] [blame] | 576 | ret = ipu_csi_init(ipu, dev, 0, ipu_base + devtype->csi0_ofs, |
| 577 | IPU_CONF_CSI0_EN, ipu_clk); |
| 578 | if (ret) { |
| 579 | unit = "csi0"; |
| 580 | goto err_csi_0; |
| 581 | } |
| 582 | |
| 583 | ret = ipu_csi_init(ipu, dev, 1, ipu_base + devtype->csi1_ofs, |
| 584 | IPU_CONF_CSI1_EN, ipu_clk); |
| 585 | if (ret) { |
| 586 | unit = "csi1"; |
| 587 | goto err_csi_1; |
| 588 | } |
| 589 | |
Steve Longerbeam | 1aa8ea0 | 2014-08-11 13:04:50 +0200 | [diff] [blame] | 590 | ret = ipu_ic_init(ipu, dev, |
| 591 | ipu_base + devtype->ic_ofs, |
| 592 | ipu_base + devtype->tpm_ofs); |
| 593 | if (ret) { |
| 594 | unit = "ic"; |
| 595 | goto err_ic; |
| 596 | } |
| 597 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 598 | ret = ipu_di_init(ipu, dev, 0, ipu_base + devtype->disp0_ofs, |
Steve Longerbeam | 1aa8ea0 | 2014-08-11 13:04:50 +0200 | [diff] [blame] | 599 | IPU_CONF_DI0_EN, ipu_clk); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 600 | if (ret) { |
| 601 | unit = "di0"; |
| 602 | goto err_di_0; |
| 603 | } |
| 604 | |
| 605 | ret = ipu_di_init(ipu, dev, 1, ipu_base + devtype->disp1_ofs, |
| 606 | IPU_CONF_DI1_EN, ipu_clk); |
| 607 | if (ret) { |
| 608 | unit = "di1"; |
| 609 | goto err_di_1; |
| 610 | } |
| 611 | |
| 612 | ret = ipu_dc_init(ipu, dev, ipu_base + devtype->cm_ofs + |
| 613 | IPU_CM_DC_REG_OFS, ipu_base + devtype->dc_tmpl_ofs); |
| 614 | if (ret) { |
| 615 | unit = "dc_template"; |
| 616 | goto err_dc; |
| 617 | } |
| 618 | |
| 619 | ret = ipu_dmfc_init(ipu, dev, ipu_base + |
| 620 | devtype->cm_ofs + IPU_CM_DMFC_REG_OFS, ipu_clk); |
| 621 | if (ret) { |
| 622 | unit = "dmfc"; |
| 623 | goto err_dmfc; |
| 624 | } |
| 625 | |
| 626 | ret = ipu_dp_init(ipu, dev, ipu_base + devtype->srm_ofs); |
| 627 | if (ret) { |
| 628 | unit = "dp"; |
| 629 | goto err_dp; |
| 630 | } |
| 631 | |
Philipp Zabel | 35de925 | 2012-05-09 16:59:01 +0200 | [diff] [blame] | 632 | ret = ipu_smfc_init(ipu, dev, ipu_base + |
| 633 | devtype->cm_ofs + IPU_CM_SMFC_REG_OFS); |
| 634 | if (ret) { |
| 635 | unit = "smfc"; |
| 636 | goto err_smfc; |
| 637 | } |
| 638 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 639 | return 0; |
| 640 | |
Philipp Zabel | 35de925 | 2012-05-09 16:59:01 +0200 | [diff] [blame] | 641 | err_smfc: |
| 642 | ipu_dp_exit(ipu); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 643 | err_dp: |
| 644 | ipu_dmfc_exit(ipu); |
| 645 | err_dmfc: |
| 646 | ipu_dc_exit(ipu); |
| 647 | err_dc: |
| 648 | ipu_di_exit(ipu, 1); |
| 649 | err_di_1: |
| 650 | ipu_di_exit(ipu, 0); |
| 651 | err_di_0: |
Steve Longerbeam | 1aa8ea0 | 2014-08-11 13:04:50 +0200 | [diff] [blame] | 652 | ipu_ic_exit(ipu); |
| 653 | err_ic: |
Steve Longerbeam | 2ffd48f | 2014-08-19 10:52:40 -0700 | [diff] [blame] | 654 | ipu_csi_exit(ipu, 1); |
| 655 | err_csi_1: |
| 656 | ipu_csi_exit(ipu, 0); |
| 657 | err_csi_0: |
Steve Longerbeam | 7d2691d | 2014-06-25 18:05:47 -0700 | [diff] [blame] | 658 | ipu_cpmem_exit(ipu); |
| 659 | err_cpmem: |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 660 | dev_err(&pdev->dev, "init %s failed with %d\n", unit, ret); |
| 661 | return ret; |
| 662 | } |
| 663 | |
| 664 | static void ipu_irq_handle(struct ipu_soc *ipu, const int *regs, int num_regs) |
| 665 | { |
| 666 | unsigned long status; |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 667 | int i, bit, irq; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 668 | |
| 669 | for (i = 0; i < num_regs; i++) { |
| 670 | |
| 671 | status = ipu_cm_read(ipu, IPU_INT_STAT(regs[i])); |
| 672 | status &= ipu_cm_read(ipu, IPU_INT_CTRL(regs[i])); |
| 673 | |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 674 | for_each_set_bit(bit, &status, 32) { |
Antoine Schweitzer-Chaput | 838201a | 2014-04-18 23:20:06 +0200 | [diff] [blame] | 675 | irq = irq_linear_revmap(ipu->domain, |
| 676 | regs[i] * 32 + bit); |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 677 | if (irq) |
| 678 | generic_handle_irq(irq); |
| 679 | } |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 680 | } |
| 681 | } |
| 682 | |
| 683 | static void ipu_irq_handler(unsigned int irq, struct irq_desc *desc) |
| 684 | { |
| 685 | struct ipu_soc *ipu = irq_desc_get_handler_data(desc); |
| 686 | const int int_reg[] = { 0, 1, 2, 3, 10, 11, 12, 13, 14}; |
| 687 | struct irq_chip *chip = irq_get_chip(irq); |
| 688 | |
| 689 | chained_irq_enter(chip, desc); |
| 690 | |
| 691 | ipu_irq_handle(ipu, int_reg, ARRAY_SIZE(int_reg)); |
| 692 | |
| 693 | chained_irq_exit(chip, desc); |
| 694 | } |
| 695 | |
| 696 | static void ipu_err_irq_handler(unsigned int irq, struct irq_desc *desc) |
| 697 | { |
| 698 | struct ipu_soc *ipu = irq_desc_get_handler_data(desc); |
| 699 | const int int_reg[] = { 4, 5, 8, 9}; |
| 700 | struct irq_chip *chip = irq_get_chip(irq); |
| 701 | |
| 702 | chained_irq_enter(chip, desc); |
| 703 | |
| 704 | ipu_irq_handle(ipu, int_reg, ARRAY_SIZE(int_reg)); |
| 705 | |
| 706 | chained_irq_exit(chip, desc); |
| 707 | } |
| 708 | |
Philipp Zabel | 861a50c | 2014-04-14 23:53:16 +0200 | [diff] [blame] | 709 | int ipu_map_irq(struct ipu_soc *ipu, int irq) |
| 710 | { |
| 711 | int virq; |
| 712 | |
| 713 | virq = irq_linear_revmap(ipu->domain, irq); |
| 714 | if (!virq) |
| 715 | virq = irq_create_mapping(ipu->domain, irq); |
| 716 | |
| 717 | return virq; |
| 718 | } |
| 719 | EXPORT_SYMBOL_GPL(ipu_map_irq); |
| 720 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 721 | int ipu_idmac_channel_irq(struct ipu_soc *ipu, struct ipuv3_channel *channel, |
| 722 | enum ipu_channel_irq irq_type) |
| 723 | { |
Philipp Zabel | 861a50c | 2014-04-14 23:53:16 +0200 | [diff] [blame] | 724 | return ipu_map_irq(ipu, irq_type + channel->num); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 725 | } |
| 726 | EXPORT_SYMBOL_GPL(ipu_idmac_channel_irq); |
| 727 | |
| 728 | static void ipu_submodules_exit(struct ipu_soc *ipu) |
| 729 | { |
Philipp Zabel | 35de925 | 2012-05-09 16:59:01 +0200 | [diff] [blame] | 730 | ipu_smfc_exit(ipu); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 731 | ipu_dp_exit(ipu); |
| 732 | ipu_dmfc_exit(ipu); |
| 733 | ipu_dc_exit(ipu); |
| 734 | ipu_di_exit(ipu, 1); |
| 735 | ipu_di_exit(ipu, 0); |
Steve Longerbeam | 1aa8ea0 | 2014-08-11 13:04:50 +0200 | [diff] [blame] | 736 | ipu_ic_exit(ipu); |
Steve Longerbeam | 2ffd48f | 2014-08-19 10:52:40 -0700 | [diff] [blame] | 737 | ipu_csi_exit(ipu, 1); |
| 738 | ipu_csi_exit(ipu, 0); |
Steve Longerbeam | 7d2691d | 2014-06-25 18:05:47 -0700 | [diff] [blame] | 739 | ipu_cpmem_exit(ipu); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | static int platform_remove_devices_fn(struct device *dev, void *unused) |
| 743 | { |
| 744 | struct platform_device *pdev = to_platform_device(dev); |
| 745 | |
| 746 | platform_device_unregister(pdev); |
| 747 | |
| 748 | return 0; |
| 749 | } |
| 750 | |
| 751 | static void platform_device_unregister_children(struct platform_device *pdev) |
| 752 | { |
| 753 | device_for_each_child(&pdev->dev, NULL, platform_remove_devices_fn); |
| 754 | } |
| 755 | |
| 756 | struct ipu_platform_reg { |
| 757 | struct ipu_client_platformdata pdata; |
| 758 | const char *name; |
Philipp Zabel | d6ca8ca | 2012-05-23 17:08:19 +0200 | [diff] [blame] | 759 | int reg_offset; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 760 | }; |
| 761 | |
| 762 | static const struct ipu_platform_reg client_reg[] = { |
| 763 | { |
| 764 | .pdata = { |
| 765 | .di = 0, |
| 766 | .dc = 5, |
| 767 | .dp = IPU_DP_FLOW_SYNC_BG, |
| 768 | .dma[0] = IPUV3_CHANNEL_MEM_BG_SYNC, |
Philipp Zabel | b8d181e | 2013-10-10 16:18:45 +0200 | [diff] [blame] | 769 | .dma[1] = IPUV3_CHANNEL_MEM_FG_SYNC, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 770 | }, |
| 771 | .name = "imx-ipuv3-crtc", |
| 772 | }, { |
| 773 | .pdata = { |
| 774 | .di = 1, |
| 775 | .dc = 1, |
| 776 | .dp = -EINVAL, |
| 777 | .dma[0] = IPUV3_CHANNEL_MEM_DC_SYNC, |
| 778 | .dma[1] = -EINVAL, |
| 779 | }, |
| 780 | .name = "imx-ipuv3-crtc", |
Philipp Zabel | d6ca8ca | 2012-05-23 17:08:19 +0200 | [diff] [blame] | 781 | }, { |
| 782 | .pdata = { |
| 783 | .csi = 0, |
| 784 | .dma[0] = IPUV3_CHANNEL_CSI0, |
| 785 | .dma[1] = -EINVAL, |
| 786 | }, |
| 787 | .reg_offset = IPU_CM_CSI0_REG_OFS, |
| 788 | .name = "imx-ipuv3-camera", |
| 789 | }, { |
| 790 | .pdata = { |
| 791 | .csi = 1, |
| 792 | .dma[0] = IPUV3_CHANNEL_CSI1, |
| 793 | .dma[1] = -EINVAL, |
| 794 | }, |
| 795 | .reg_offset = IPU_CM_CSI1_REG_OFS, |
| 796 | .name = "imx-ipuv3-camera", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 797 | }, |
| 798 | }; |
| 799 | |
Russell King | 4ae078d | 2013-12-16 11:34:25 +0000 | [diff] [blame] | 800 | static DEFINE_MUTEX(ipu_client_id_mutex); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 801 | static int ipu_client_id; |
| 802 | |
Philipp Zabel | d6ca8ca | 2012-05-23 17:08:19 +0200 | [diff] [blame] | 803 | static int ipu_add_client_devices(struct ipu_soc *ipu, unsigned long ipu_base) |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 804 | { |
Russell King | 4ae078d | 2013-12-16 11:34:25 +0000 | [diff] [blame] | 805 | struct device *dev = ipu->dev; |
| 806 | unsigned i; |
| 807 | int id, ret; |
| 808 | |
| 809 | mutex_lock(&ipu_client_id_mutex); |
| 810 | id = ipu_client_id; |
| 811 | ipu_client_id += ARRAY_SIZE(client_reg); |
| 812 | mutex_unlock(&ipu_client_id_mutex); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 813 | |
| 814 | for (i = 0; i < ARRAY_SIZE(client_reg); i++) { |
| 815 | const struct ipu_platform_reg *reg = &client_reg[i]; |
Russell King | 4ae078d | 2013-12-16 11:34:25 +0000 | [diff] [blame] | 816 | struct platform_device *pdev; |
Philipp Zabel | d6ca8ca | 2012-05-23 17:08:19 +0200 | [diff] [blame] | 817 | struct resource res; |
Russell King | 4ae078d | 2013-12-16 11:34:25 +0000 | [diff] [blame] | 818 | |
Philipp Zabel | d6ca8ca | 2012-05-23 17:08:19 +0200 | [diff] [blame] | 819 | if (reg->reg_offset) { |
| 820 | memset(&res, 0, sizeof(res)); |
| 821 | res.flags = IORESOURCE_MEM; |
| 822 | res.start = ipu_base + ipu->devtype->cm_ofs + reg->reg_offset; |
| 823 | res.end = res.start + PAGE_SIZE - 1; |
| 824 | pdev = platform_device_register_resndata(dev, reg->name, |
| 825 | id++, &res, 1, ®->pdata, sizeof(reg->pdata)); |
| 826 | } else { |
| 827 | pdev = platform_device_register_data(dev, reg->name, |
| 828 | id++, ®->pdata, sizeof(reg->pdata)); |
| 829 | } |
Russell King | 4ae078d | 2013-12-16 11:34:25 +0000 | [diff] [blame] | 830 | |
| 831 | if (IS_ERR(pdev)) |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 832 | goto err_register; |
| 833 | } |
| 834 | |
| 835 | return 0; |
| 836 | |
| 837 | err_register: |
Russell King | 4ae078d | 2013-12-16 11:34:25 +0000 | [diff] [blame] | 838 | platform_device_unregister_children(to_platform_device(dev)); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 839 | |
| 840 | return ret; |
| 841 | } |
| 842 | |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 843 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 844 | static int ipu_irq_init(struct ipu_soc *ipu) |
| 845 | { |
Philipp Zabel | 379cdec | 2013-06-21 14:52:17 +0200 | [diff] [blame] | 846 | struct irq_chip_generic *gc; |
| 847 | struct irq_chip_type *ct; |
Philipp Zabel | 37f85b26 | 2013-06-21 14:52:18 +0200 | [diff] [blame] | 848 | unsigned long unused[IPU_NUM_IRQS / 32] = { |
| 849 | 0x400100d0, 0xffe000fd, |
| 850 | 0x400100d0, 0xffe000fd, |
| 851 | 0x400100d0, 0xffe000fd, |
| 852 | 0x4077ffff, 0xffe7e1fd, |
| 853 | 0x23fffffe, 0x8880fff0, |
| 854 | 0xf98fe7d0, 0xfff81fff, |
| 855 | 0x400100d0, 0xffe000fd, |
| 856 | 0x00000000, |
| 857 | }; |
Philipp Zabel | 379cdec | 2013-06-21 14:52:17 +0200 | [diff] [blame] | 858 | int ret, i; |
| 859 | |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 860 | 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] | 861 | &irq_generic_chip_ops, ipu); |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 862 | if (!ipu->domain) { |
| 863 | dev_err(ipu->dev, "failed to add irq domain\n"); |
| 864 | return -ENODEV; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 865 | } |
| 866 | |
Philipp Zabel | 379cdec | 2013-06-21 14:52:17 +0200 | [diff] [blame] | 867 | ret = irq_alloc_domain_generic_chips(ipu->domain, 32, 1, "IPU", |
Antoine Schweitzer-Chaput | 838201a | 2014-04-18 23:20:06 +0200 | [diff] [blame] | 868 | handle_level_irq, 0, |
| 869 | IRQF_VALID, 0); |
Philipp Zabel | 379cdec | 2013-06-21 14:52:17 +0200 | [diff] [blame] | 870 | if (ret < 0) { |
| 871 | dev_err(ipu->dev, "failed to alloc generic irq chips\n"); |
| 872 | irq_domain_remove(ipu->domain); |
| 873 | return ret; |
| 874 | } |
| 875 | |
| 876 | for (i = 0; i < IPU_NUM_IRQS; i += 32) { |
| 877 | gc = irq_get_domain_generic_chip(ipu->domain, i); |
| 878 | gc->reg_base = ipu->cm_reg; |
Philipp Zabel | 37f85b26 | 2013-06-21 14:52:18 +0200 | [diff] [blame] | 879 | gc->unused = unused[i / 32]; |
Philipp Zabel | 379cdec | 2013-06-21 14:52:17 +0200 | [diff] [blame] | 880 | ct = gc->chip_types; |
| 881 | ct->chip.irq_ack = irq_gc_ack_set_bit; |
| 882 | ct->chip.irq_mask = irq_gc_mask_clr_bit; |
| 883 | ct->chip.irq_unmask = irq_gc_mask_set_bit; |
| 884 | ct->regs.ack = IPU_INT_STAT(i / 32); |
| 885 | ct->regs.mask = IPU_INT_CTRL(i / 32); |
| 886 | } |
| 887 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 888 | irq_set_chained_handler(ipu->irq_sync, ipu_irq_handler); |
| 889 | irq_set_handler_data(ipu->irq_sync, ipu); |
| 890 | irq_set_chained_handler(ipu->irq_err, ipu_err_irq_handler); |
| 891 | irq_set_handler_data(ipu->irq_err, ipu); |
| 892 | |
| 893 | return 0; |
| 894 | } |
| 895 | |
| 896 | static void ipu_irq_exit(struct ipu_soc *ipu) |
| 897 | { |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 898 | int i, irq; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 899 | |
| 900 | irq_set_chained_handler(ipu->irq_err, NULL); |
| 901 | irq_set_handler_data(ipu->irq_err, NULL); |
| 902 | irq_set_chained_handler(ipu->irq_sync, NULL); |
| 903 | irq_set_handler_data(ipu->irq_sync, NULL); |
| 904 | |
Philipp Zabel | 379cdec | 2013-06-21 14:52:17 +0200 | [diff] [blame] | 905 | /* TODO: remove irq_domain_generic_chips */ |
| 906 | |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 907 | for (i = 0; i < IPU_NUM_IRQS; i++) { |
| 908 | irq = irq_linear_revmap(ipu->domain, i); |
| 909 | if (irq) |
| 910 | irq_dispose_mapping(irq); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 911 | } |
| 912 | |
Philipp Zabel | b728766 | 2013-06-21 10:27:39 +0200 | [diff] [blame] | 913 | irq_domain_remove(ipu->domain); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 914 | } |
| 915 | |
Bill Pemberton | c4aabf8 | 2012-11-19 13:22:11 -0500 | [diff] [blame] | 916 | static int ipu_probe(struct platform_device *pdev) |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 917 | { |
| 918 | const struct of_device_id *of_id = |
| 919 | of_match_device(imx_ipu_dt_ids, &pdev->dev); |
| 920 | struct ipu_soc *ipu; |
| 921 | struct resource *res; |
| 922 | unsigned long ipu_base; |
| 923 | int i, ret, irq_sync, irq_err; |
| 924 | const struct ipu_devtype *devtype; |
| 925 | |
| 926 | devtype = of_id->data; |
| 927 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 928 | irq_sync = platform_get_irq(pdev, 0); |
| 929 | irq_err = platform_get_irq(pdev, 1); |
| 930 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
| 931 | |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 932 | dev_dbg(&pdev->dev, "irq_sync: %d irq_err: %d\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 933 | irq_sync, irq_err); |
| 934 | |
| 935 | if (!res || irq_sync < 0 || irq_err < 0) |
| 936 | return -ENODEV; |
| 937 | |
| 938 | ipu_base = res->start; |
| 939 | |
| 940 | ipu = devm_kzalloc(&pdev->dev, sizeof(*ipu), GFP_KERNEL); |
| 941 | if (!ipu) |
| 942 | return -ENODEV; |
| 943 | |
| 944 | for (i = 0; i < 64; i++) |
| 945 | ipu->channel[i].ipu = ipu; |
| 946 | ipu->devtype = devtype; |
| 947 | ipu->ipu_type = devtype->type; |
| 948 | |
| 949 | spin_lock_init(&ipu->lock); |
| 950 | mutex_init(&ipu->channel_lock); |
| 951 | |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 952 | dev_dbg(&pdev->dev, "cm_reg: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 953 | ipu_base + devtype->cm_ofs); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 954 | dev_dbg(&pdev->dev, "idmac: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 955 | ipu_base + devtype->cm_ofs + IPU_CM_IDMAC_REG_OFS); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 956 | dev_dbg(&pdev->dev, "cpmem: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 957 | ipu_base + devtype->cpmem_ofs); |
Steve Longerbeam | 2ffd48f | 2014-08-19 10:52:40 -0700 | [diff] [blame] | 958 | dev_dbg(&pdev->dev, "csi0: 0x%08lx\n", |
| 959 | ipu_base + devtype->csi0_ofs); |
| 960 | dev_dbg(&pdev->dev, "csi1: 0x%08lx\n", |
| 961 | ipu_base + devtype->csi1_ofs); |
Steve Longerbeam | 1aa8ea0 | 2014-08-11 13:04:50 +0200 | [diff] [blame] | 962 | dev_dbg(&pdev->dev, "ic: 0x%08lx\n", |
| 963 | ipu_base + devtype->ic_ofs); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 964 | dev_dbg(&pdev->dev, "disp0: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 965 | ipu_base + devtype->disp0_ofs); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 966 | dev_dbg(&pdev->dev, "disp1: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 967 | ipu_base + devtype->disp1_ofs); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 968 | dev_dbg(&pdev->dev, "srm: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 969 | ipu_base + devtype->srm_ofs); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 970 | dev_dbg(&pdev->dev, "tpm: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 971 | ipu_base + devtype->tpm_ofs); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 972 | dev_dbg(&pdev->dev, "dc: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 973 | ipu_base + devtype->cm_ofs + IPU_CM_DC_REG_OFS); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 974 | dev_dbg(&pdev->dev, "ic: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 975 | ipu_base + devtype->cm_ofs + IPU_CM_IC_REG_OFS); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 976 | dev_dbg(&pdev->dev, "dmfc: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 977 | ipu_base + devtype->cm_ofs + IPU_CM_DMFC_REG_OFS); |
Fabio Estevam | fd563db | 2012-10-24 21:36:46 -0200 | [diff] [blame] | 978 | dev_dbg(&pdev->dev, "vdi: 0x%08lx\n", |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 979 | ipu_base + devtype->vdi_ofs); |
| 980 | |
| 981 | ipu->cm_reg = devm_ioremap(&pdev->dev, |
| 982 | ipu_base + devtype->cm_ofs, PAGE_SIZE); |
| 983 | ipu->idmac_reg = devm_ioremap(&pdev->dev, |
| 984 | ipu_base + devtype->cm_ofs + IPU_CM_IDMAC_REG_OFS, |
| 985 | PAGE_SIZE); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 986 | |
Steve Longerbeam | 7d2691d | 2014-06-25 18:05:47 -0700 | [diff] [blame] | 987 | if (!ipu->cm_reg || !ipu->idmac_reg) |
Fabio Estevam | be798b2 | 2013-07-20 18:22:09 -0300 | [diff] [blame] | 988 | return -ENOMEM; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 989 | |
| 990 | ipu->clk = devm_clk_get(&pdev->dev, "bus"); |
| 991 | if (IS_ERR(ipu->clk)) { |
| 992 | ret = PTR_ERR(ipu->clk); |
| 993 | dev_err(&pdev->dev, "clk_get failed with %d", ret); |
Fabio Estevam | be798b2 | 2013-07-20 18:22:09 -0300 | [diff] [blame] | 994 | return ret; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | platform_set_drvdata(pdev, ipu); |
| 998 | |
Fabio Estevam | 62645a2 | 2013-07-20 18:22:10 -0300 | [diff] [blame] | 999 | ret = clk_prepare_enable(ipu->clk); |
| 1000 | if (ret) { |
| 1001 | dev_err(&pdev->dev, "clk_prepare_enable failed: %d\n", ret); |
| 1002 | return ret; |
| 1003 | } |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1004 | |
| 1005 | ipu->dev = &pdev->dev; |
| 1006 | ipu->irq_sync = irq_sync; |
| 1007 | ipu->irq_err = irq_err; |
| 1008 | |
| 1009 | ret = ipu_irq_init(ipu); |
| 1010 | if (ret) |
| 1011 | goto out_failed_irq; |
| 1012 | |
Philipp Zabel | 6c64155 | 2013-03-28 17:35:21 +0100 | [diff] [blame] | 1013 | ret = device_reset(&pdev->dev); |
| 1014 | if (ret) { |
| 1015 | dev_err(&pdev->dev, "failed to reset: %d\n", ret); |
| 1016 | goto out_failed_reset; |
| 1017 | } |
| 1018 | ret = ipu_memory_reset(ipu); |
Lothar Waßmann | 4d27b2c | 2012-12-25 15:58:37 +0100 | [diff] [blame] | 1019 | if (ret) |
| 1020 | goto out_failed_reset; |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1021 | |
| 1022 | /* Set MCU_T to divide MCU access window into 2 */ |
| 1023 | ipu_cm_write(ipu, 0x00400000L | (IPU_MCU_T_DEFAULT << 18), |
| 1024 | IPU_DISP_GEN); |
| 1025 | |
| 1026 | ret = ipu_submodules_init(ipu, pdev, ipu_base, ipu->clk); |
| 1027 | if (ret) |
| 1028 | goto failed_submodules_init; |
| 1029 | |
Philipp Zabel | d6ca8ca | 2012-05-23 17:08:19 +0200 | [diff] [blame] | 1030 | ret = ipu_add_client_devices(ipu, ipu_base); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1031 | if (ret) { |
| 1032 | dev_err(&pdev->dev, "adding client devices failed with %d\n", |
| 1033 | ret); |
| 1034 | goto failed_add_clients; |
| 1035 | } |
| 1036 | |
Fabio Estevam | 9c2c438 | 2012-10-24 21:36:47 -0200 | [diff] [blame] | 1037 | dev_info(&pdev->dev, "%s probed\n", devtype->name); |
| 1038 | |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1039 | return 0; |
| 1040 | |
| 1041 | failed_add_clients: |
| 1042 | ipu_submodules_exit(ipu); |
| 1043 | failed_submodules_init: |
Lothar Waßmann | 4d27b2c | 2012-12-25 15:58:37 +0100 | [diff] [blame] | 1044 | out_failed_reset: |
Philipp Zabel | 6c64155 | 2013-03-28 17:35:21 +0100 | [diff] [blame] | 1045 | ipu_irq_exit(ipu); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1046 | out_failed_irq: |
| 1047 | clk_disable_unprepare(ipu->clk); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1048 | return ret; |
| 1049 | } |
| 1050 | |
Bill Pemberton | 8aa1be4 | 2012-11-19 13:26:38 -0500 | [diff] [blame] | 1051 | static int ipu_remove(struct platform_device *pdev) |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1052 | { |
| 1053 | struct ipu_soc *ipu = platform_get_drvdata(pdev); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1054 | |
| 1055 | platform_device_unregister_children(pdev); |
| 1056 | ipu_submodules_exit(ipu); |
| 1057 | ipu_irq_exit(ipu); |
| 1058 | |
| 1059 | clk_disable_unprepare(ipu->clk); |
| 1060 | |
| 1061 | return 0; |
| 1062 | } |
| 1063 | |
| 1064 | static struct platform_driver imx_ipu_driver = { |
| 1065 | .driver = { |
| 1066 | .name = "imx-ipuv3", |
| 1067 | .of_match_table = imx_ipu_dt_ids, |
| 1068 | }, |
| 1069 | .probe = ipu_probe, |
Bill Pemberton | 99c28f1 | 2012-11-19 13:20:51 -0500 | [diff] [blame] | 1070 | .remove = ipu_remove, |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1071 | }; |
| 1072 | |
| 1073 | module_platform_driver(imx_ipu_driver); |
| 1074 | |
Fabio Estevam | 10f2268 | 2013-07-20 18:22:11 -0300 | [diff] [blame] | 1075 | MODULE_ALIAS("platform:imx-ipuv3"); |
Sascha Hauer | aecfbdb | 2012-09-21 10:07:49 +0200 | [diff] [blame] | 1076 | MODULE_DESCRIPTION("i.MX IPU v3 driver"); |
| 1077 | MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); |
| 1078 | MODULE_LICENSE("GPL"); |