blob: a1d42eed5d060aa15da55c6aee16fe7a48cf78f8 [file] [log] [blame]
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001/*
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 Zabel6c641552013-03-28 17:35:21 +010018#include <linux/reset.h>
Sascha Haueraecfbdb2012-09-21 10:07:49 +020019#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 Marinasde88cbb2013-01-18 15:31:37 +000028#include <linux/irqchip/chained_irq.h>
Philipp Zabelb7287662013-06-21 10:27:39 +020029#include <linux/irqdomain.h>
Sascha Haueraecfbdb2012-09-21 10:07:49 +020030#include <linux/of_device.h>
Sascha Haueraecfbdb2012-09-21 10:07:49 +020031
Philipp Zabel7cb17792013-10-10 16:18:38 +020032#include <drm/drm_fourcc.h>
33
Philipp Zabel39b90042013-09-30 16:13:39 +020034#include <video/imx-ipu-v3.h>
Sascha Haueraecfbdb2012-09-21 10:07:49 +020035#include "ipu-prv.h"
36
37static inline u32 ipu_cm_read(struct ipu_soc *ipu, unsigned offset)
38{
39 return readl(ipu->cm_reg + offset);
40}
41
42static inline void ipu_cm_write(struct ipu_soc *ipu, u32 value, unsigned offset)
43{
44 writel(value, ipu->cm_reg + offset);
45}
46
Sascha Haueraecfbdb2012-09-21 10:07:49 +020047void 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}
55EXPORT_SYMBOL_GPL(ipu_srm_dp_sync_update);
56
Philipp Zabel7cb17792013-10-10 16:18:38 +020057enum 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}
82EXPORT_SYMBOL_GPL(ipu_drm_fourcc_to_colorspace);
83
Sascha Haueraecfbdb2012-09-21 10:07:49 +020084enum ipu_color_space ipu_pixelformat_to_colorspace(u32 pixelformat)
85{
86 switch (pixelformat) {
87 case V4L2_PIX_FMT_YUV420:
Philipp Zabeld3e4e612012-11-12 16:29:00 +010088 case V4L2_PIX_FMT_YVU420:
Sascha Haueraecfbdb2012-09-21 10:07:49 +020089 case V4L2_PIX_FMT_UYVY:
Michael Olbrichc096ae12012-11-12 16:28:59 +010090 case V4L2_PIX_FMT_YUYV:
Sascha Haueraecfbdb2012-09-21 10:07:49 +020091 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}
102EXPORT_SYMBOL_GPL(ipu_pixelformat_to_colorspace);
103
Steve Longerbeamae0e9702014-06-25 18:05:36 -0700104enum 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}
115EXPORT_SYMBOL_GPL(ipu_mbus_code_to_colorspace);
116
Steve Longerbeamf835f382014-06-25 18:05:37 -0700117int 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}
147EXPORT_SYMBOL_GPL(ipu_degrees_to_rot_mode);
148
149int 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}
179EXPORT_SYMBOL_GPL(ipu_rot_mode_to_degrees);
180
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200181struct 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 Manea89bc5be2013-10-25 11:52:20 +0300199 channel->busy = true;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200200 channel->num = num;
201
202out:
203 mutex_unlock(&ipu->channel_lock);
204
205 return channel;
206}
207EXPORT_SYMBOL_GPL(ipu_idmac_get);
208
209void 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 Manea89bc5be2013-10-25 11:52:20 +0300217 channel->busy = false;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200218
219 mutex_unlock(&ipu->channel_lock);
220}
221EXPORT_SYMBOL_GPL(ipu_idmac_put);
222
223#define idma_mask(ch) (1 << (ch & 0x1f))
224
225void 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}
243EXPORT_SYMBOL_GPL(ipu_idmac_set_double_buffer);
244
245int 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}
269EXPORT_SYMBOL_GPL(ipu_module_enable);
270
271int 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}
295EXPORT_SYMBOL_GPL(ipu_module_disable);
296
Philipp Zabele9046092012-05-16 17:28:29 +0200297int 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}
304EXPORT_SYMBOL_GPL(ipu_idmac_get_current_buffer);
305
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200306void 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}
322EXPORT_SYMBOL_GPL(ipu_idmac_select_buffer);
323
324int 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}
340EXPORT_SYMBOL_GPL(ipu_idmac_enable_channel);
341
Philipp Zabel17075502014-04-14 23:53:17 +0200342bool 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}
346EXPORT_SYMBOL_GPL(ipu_idmac_channel_busy);
347
Sascha Hauerfb822a32013-10-10 16:18:41 +0200348int 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}
363EXPORT_SYMBOL_GPL(ipu_idmac_wait_busy);
364
Philipp Zabel17075502014-04-14 23:53:17 +0200365int 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}
379EXPORT_SYMBOL_GPL(ipu_wait_interrupt);
380
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200381int ipu_idmac_disable_channel(struct ipuv3_channel *channel)
382{
383 struct ipu_soc *ipu = channel->ipu;
384 u32 val;
385 unsigned long flags;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200386
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}
420EXPORT_SYMBOL_GPL(ipu_idmac_disable_channel);
421
Philipp Zabel6c641552013-03-28 17:35:21 +0100422static int ipu_memory_reset(struct ipu_soc *ipu)
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200423{
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 Haueraecfbdb2012-09-21 10:07:49 +0200435 return 0;
436}
437
Steve Longerbeamba079752014-06-25 18:05:30 -0700438/*
439 * Set the source mux for the given CSI. Selects either parallel or
440 * MIPI CSI2 sources.
441 */
442void 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}
461EXPORT_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 */
466void 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}
487EXPORT_SYMBOL_GPL(ipu_set_ic_src_mux);
488
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200489struct 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 Longerbeam2ffd48f2014-08-19 10:52:40 -0700495 unsigned long csi0_ofs;
496 unsigned long csi1_ofs;
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200497 unsigned long ic_ofs;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200498 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
505static 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 Longerbeam2ffd48f2014-08-19 10:52:40 -0700511 .csi0_ofs = 0x1f030000,
512 .csi1_ofs = 0x1f038000,
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200513 .ic_ofs = 0x1f020000,
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200514 .disp0_ofs = 0x1e040000,
515 .disp1_ofs = 0x1e048000,
516 .dc_tmpl_ofs = 0x1f080000,
517 .vdi_ofs = 0x1e068000,
518 .type = IPUV3EX,
519};
520
521static 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 Longerbeam2ffd48f2014-08-19 10:52:40 -0700527 .csi0_ofs = 0x07030000,
528 .csi1_ofs = 0x07038000,
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200529 .ic_ofs = 0x07020000,
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200530 .disp0_ofs = 0x06040000,
531 .disp1_ofs = 0x06048000,
532 .dc_tmpl_ofs = 0x07080000,
533 .vdi_ofs = 0x06068000,
534 .type = IPUV3M,
535};
536
537static 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 Longerbeam2ffd48f2014-08-19 10:52:40 -0700543 .csi0_ofs = 0x00230000,
544 .csi1_ofs = 0x00238000,
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200545 .ic_ofs = 0x00220000,
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200546 .disp0_ofs = 0x00240000,
547 .disp1_ofs = 0x00248000,
548 .dc_tmpl_ofs = 0x00380000,
549 .vdi_ofs = 0x00268000,
550 .type = IPUV3H,
551};
552
553static 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};
559MODULE_DEVICE_TABLE(of, imx_ipu_dt_ids);
560
561static 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 Longerbeam7d2691d2014-06-25 18:05:47 -0700570 ret = ipu_cpmem_init(ipu, dev, ipu_base + devtype->cpmem_ofs);
571 if (ret) {
572 unit = "cpmem";
573 goto err_cpmem;
574 }
575
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700576 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 Longerbeam1aa8ea02014-08-11 13:04:50 +0200590 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 Haueraecfbdb2012-09-21 10:07:49 +0200598 ret = ipu_di_init(ipu, dev, 0, ipu_base + devtype->disp0_ofs,
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200599 IPU_CONF_DI0_EN, ipu_clk);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200600 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 Zabel35de9252012-05-09 16:59:01 +0200632 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 Haueraecfbdb2012-09-21 10:07:49 +0200639 return 0;
640
Philipp Zabel35de9252012-05-09 16:59:01 +0200641err_smfc:
642 ipu_dp_exit(ipu);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200643err_dp:
644 ipu_dmfc_exit(ipu);
645err_dmfc:
646 ipu_dc_exit(ipu);
647err_dc:
648 ipu_di_exit(ipu, 1);
649err_di_1:
650 ipu_di_exit(ipu, 0);
651err_di_0:
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200652 ipu_ic_exit(ipu);
653err_ic:
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700654 ipu_csi_exit(ipu, 1);
655err_csi_1:
656 ipu_csi_exit(ipu, 0);
657err_csi_0:
Steve Longerbeam7d2691d2014-06-25 18:05:47 -0700658 ipu_cpmem_exit(ipu);
659err_cpmem:
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200660 dev_err(&pdev->dev, "init %s failed with %d\n", unit, ret);
661 return ret;
662}
663
664static void ipu_irq_handle(struct ipu_soc *ipu, const int *regs, int num_regs)
665{
666 unsigned long status;
Philipp Zabelb7287662013-06-21 10:27:39 +0200667 int i, bit, irq;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200668
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 Zabelb7287662013-06-21 10:27:39 +0200674 for_each_set_bit(bit, &status, 32) {
Antoine Schweitzer-Chaput838201a2014-04-18 23:20:06 +0200675 irq = irq_linear_revmap(ipu->domain,
676 regs[i] * 32 + bit);
Philipp Zabelb7287662013-06-21 10:27:39 +0200677 if (irq)
678 generic_handle_irq(irq);
679 }
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200680 }
681}
682
683static 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
696static 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 Zabel861a50c2014-04-14 23:53:16 +0200709int 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}
719EXPORT_SYMBOL_GPL(ipu_map_irq);
720
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200721int ipu_idmac_channel_irq(struct ipu_soc *ipu, struct ipuv3_channel *channel,
722 enum ipu_channel_irq irq_type)
723{
Philipp Zabel861a50c2014-04-14 23:53:16 +0200724 return ipu_map_irq(ipu, irq_type + channel->num);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200725}
726EXPORT_SYMBOL_GPL(ipu_idmac_channel_irq);
727
728static void ipu_submodules_exit(struct ipu_soc *ipu)
729{
Philipp Zabel35de9252012-05-09 16:59:01 +0200730 ipu_smfc_exit(ipu);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200731 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 Longerbeam1aa8ea02014-08-11 13:04:50 +0200736 ipu_ic_exit(ipu);
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700737 ipu_csi_exit(ipu, 1);
738 ipu_csi_exit(ipu, 0);
Steve Longerbeam7d2691d2014-06-25 18:05:47 -0700739 ipu_cpmem_exit(ipu);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200740}
741
742static 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
751static void platform_device_unregister_children(struct platform_device *pdev)
752{
753 device_for_each_child(&pdev->dev, NULL, platform_remove_devices_fn);
754}
755
756struct ipu_platform_reg {
757 struct ipu_client_platformdata pdata;
758 const char *name;
Philipp Zabeld6ca8ca2012-05-23 17:08:19 +0200759 int reg_offset;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200760};
761
762static 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 Zabelb8d181e2013-10-10 16:18:45 +0200769 .dma[1] = IPUV3_CHANNEL_MEM_FG_SYNC,
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200770 },
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 Zabeld6ca8ca2012-05-23 17:08:19 +0200781 }, {
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 Haueraecfbdb2012-09-21 10:07:49 +0200797 },
798};
799
Russell King4ae078d2013-12-16 11:34:25 +0000800static DEFINE_MUTEX(ipu_client_id_mutex);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200801static int ipu_client_id;
802
Philipp Zabeld6ca8ca2012-05-23 17:08:19 +0200803static int ipu_add_client_devices(struct ipu_soc *ipu, unsigned long ipu_base)
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200804{
Russell King4ae078d2013-12-16 11:34:25 +0000805 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 Haueraecfbdb2012-09-21 10:07:49 +0200813
814 for (i = 0; i < ARRAY_SIZE(client_reg); i++) {
815 const struct ipu_platform_reg *reg = &client_reg[i];
Russell King4ae078d2013-12-16 11:34:25 +0000816 struct platform_device *pdev;
Philipp Zabeld6ca8ca2012-05-23 17:08:19 +0200817 struct resource res;
Russell King4ae078d2013-12-16 11:34:25 +0000818
Philipp Zabeld6ca8ca2012-05-23 17:08:19 +0200819 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, &reg->pdata, sizeof(reg->pdata));
826 } else {
827 pdev = platform_device_register_data(dev, reg->name,
828 id++, &reg->pdata, sizeof(reg->pdata));
829 }
Russell King4ae078d2013-12-16 11:34:25 +0000830
831 if (IS_ERR(pdev))
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200832 goto err_register;
833 }
834
835 return 0;
836
837err_register:
Russell King4ae078d2013-12-16 11:34:25 +0000838 platform_device_unregister_children(to_platform_device(dev));
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200839
840 return ret;
841}
842
Philipp Zabelb7287662013-06-21 10:27:39 +0200843
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200844static int ipu_irq_init(struct ipu_soc *ipu)
845{
Philipp Zabel379cdec2013-06-21 14:52:17 +0200846 struct irq_chip_generic *gc;
847 struct irq_chip_type *ct;
Philipp Zabel37f85b262013-06-21 14:52:18 +0200848 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 Zabel379cdec2013-06-21 14:52:17 +0200858 int ret, i;
859
Philipp Zabelb7287662013-06-21 10:27:39 +0200860 ipu->domain = irq_domain_add_linear(ipu->dev->of_node, IPU_NUM_IRQS,
Philipp Zabel379cdec2013-06-21 14:52:17 +0200861 &irq_generic_chip_ops, ipu);
Philipp Zabelb7287662013-06-21 10:27:39 +0200862 if (!ipu->domain) {
863 dev_err(ipu->dev, "failed to add irq domain\n");
864 return -ENODEV;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200865 }
866
Philipp Zabel379cdec2013-06-21 14:52:17 +0200867 ret = irq_alloc_domain_generic_chips(ipu->domain, 32, 1, "IPU",
Antoine Schweitzer-Chaput838201a2014-04-18 23:20:06 +0200868 handle_level_irq, 0,
869 IRQF_VALID, 0);
Philipp Zabel379cdec2013-06-21 14:52:17 +0200870 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 Zabel37f85b262013-06-21 14:52:18 +0200879 gc->unused = unused[i / 32];
Philipp Zabel379cdec2013-06-21 14:52:17 +0200880 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 Haueraecfbdb2012-09-21 10:07:49 +0200888 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
896static void ipu_irq_exit(struct ipu_soc *ipu)
897{
Philipp Zabelb7287662013-06-21 10:27:39 +0200898 int i, irq;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200899
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 Zabel379cdec2013-06-21 14:52:17 +0200905 /* TODO: remove irq_domain_generic_chips */
906
Philipp Zabelb7287662013-06-21 10:27:39 +0200907 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 Haueraecfbdb2012-09-21 10:07:49 +0200911 }
912
Philipp Zabelb7287662013-06-21 10:27:39 +0200913 irq_domain_remove(ipu->domain);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200914}
915
Bill Pembertonc4aabf82012-11-19 13:22:11 -0500916static int ipu_probe(struct platform_device *pdev)
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200917{
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 Haueraecfbdb2012-09-21 10:07:49 +0200928 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 Estevamfd563db2012-10-24 21:36:46 -0200932 dev_dbg(&pdev->dev, "irq_sync: %d irq_err: %d\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200933 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 Estevamfd563db2012-10-24 21:36:46 -0200952 dev_dbg(&pdev->dev, "cm_reg: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200953 ipu_base + devtype->cm_ofs);
Fabio Estevamfd563db2012-10-24 21:36:46 -0200954 dev_dbg(&pdev->dev, "idmac: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200955 ipu_base + devtype->cm_ofs + IPU_CM_IDMAC_REG_OFS);
Fabio Estevamfd563db2012-10-24 21:36:46 -0200956 dev_dbg(&pdev->dev, "cpmem: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200957 ipu_base + devtype->cpmem_ofs);
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700958 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 Longerbeam1aa8ea02014-08-11 13:04:50 +0200962 dev_dbg(&pdev->dev, "ic: 0x%08lx\n",
963 ipu_base + devtype->ic_ofs);
Fabio Estevamfd563db2012-10-24 21:36:46 -0200964 dev_dbg(&pdev->dev, "disp0: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200965 ipu_base + devtype->disp0_ofs);
Fabio Estevamfd563db2012-10-24 21:36:46 -0200966 dev_dbg(&pdev->dev, "disp1: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200967 ipu_base + devtype->disp1_ofs);
Fabio Estevamfd563db2012-10-24 21:36:46 -0200968 dev_dbg(&pdev->dev, "srm: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200969 ipu_base + devtype->srm_ofs);
Fabio Estevamfd563db2012-10-24 21:36:46 -0200970 dev_dbg(&pdev->dev, "tpm: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200971 ipu_base + devtype->tpm_ofs);
Fabio Estevamfd563db2012-10-24 21:36:46 -0200972 dev_dbg(&pdev->dev, "dc: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200973 ipu_base + devtype->cm_ofs + IPU_CM_DC_REG_OFS);
Fabio Estevamfd563db2012-10-24 21:36:46 -0200974 dev_dbg(&pdev->dev, "ic: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200975 ipu_base + devtype->cm_ofs + IPU_CM_IC_REG_OFS);
Fabio Estevamfd563db2012-10-24 21:36:46 -0200976 dev_dbg(&pdev->dev, "dmfc: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200977 ipu_base + devtype->cm_ofs + IPU_CM_DMFC_REG_OFS);
Fabio Estevamfd563db2012-10-24 21:36:46 -0200978 dev_dbg(&pdev->dev, "vdi: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200979 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 Haueraecfbdb2012-09-21 10:07:49 +0200986
Steve Longerbeam7d2691d2014-06-25 18:05:47 -0700987 if (!ipu->cm_reg || !ipu->idmac_reg)
Fabio Estevambe798b22013-07-20 18:22:09 -0300988 return -ENOMEM;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200989
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 Estevambe798b22013-07-20 18:22:09 -0300994 return ret;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200995 }
996
997 platform_set_drvdata(pdev, ipu);
998
Fabio Estevam62645a22013-07-20 18:22:10 -0300999 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 Haueraecfbdb2012-09-21 10:07:49 +02001004
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 Zabel6c641552013-03-28 17:35:21 +01001013 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ßmann4d27b2c2012-12-25 15:58:37 +01001019 if (ret)
1020 goto out_failed_reset;
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001021
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 Zabeld6ca8ca2012-05-23 17:08:19 +02001030 ret = ipu_add_client_devices(ipu, ipu_base);
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001031 if (ret) {
1032 dev_err(&pdev->dev, "adding client devices failed with %d\n",
1033 ret);
1034 goto failed_add_clients;
1035 }
1036
Fabio Estevam9c2c4382012-10-24 21:36:47 -02001037 dev_info(&pdev->dev, "%s probed\n", devtype->name);
1038
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001039 return 0;
1040
1041failed_add_clients:
1042 ipu_submodules_exit(ipu);
1043failed_submodules_init:
Lothar Waßmann4d27b2c2012-12-25 15:58:37 +01001044out_failed_reset:
Philipp Zabel6c641552013-03-28 17:35:21 +01001045 ipu_irq_exit(ipu);
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001046out_failed_irq:
1047 clk_disable_unprepare(ipu->clk);
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001048 return ret;
1049}
1050
Bill Pemberton8aa1be42012-11-19 13:26:38 -05001051static int ipu_remove(struct platform_device *pdev)
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001052{
1053 struct ipu_soc *ipu = platform_get_drvdata(pdev);
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001054
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
1064static 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 Pemberton99c28f12012-11-19 13:20:51 -05001070 .remove = ipu_remove,
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001071};
1072
1073module_platform_driver(imx_ipu_driver);
1074
Fabio Estevam10f22682013-07-20 18:22:11 -03001075MODULE_ALIAS("platform:imx-ipuv3");
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001076MODULE_DESCRIPTION("i.MX IPU v3 driver");
1077MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
1078MODULE_LICENSE("GPL");