blob: 773a2fc8fed4da4f511e023c405d2ba98a8a8cf5 [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 Longerbeam4cea9402014-06-25 18:05:38 -0700104bool ipu_pixelformat_is_planar(u32 pixelformat)
105{
106 switch (pixelformat) {
107 case V4L2_PIX_FMT_YUV420:
108 case V4L2_PIX_FMT_YVU420:
109 return true;
110 }
111
112 return false;
113}
114EXPORT_SYMBOL_GPL(ipu_pixelformat_is_planar);
115
Steve Longerbeamae0e9702014-06-25 18:05:36 -0700116enum ipu_color_space ipu_mbus_code_to_colorspace(u32 mbus_code)
117{
118 switch (mbus_code & 0xf000) {
119 case 0x1000:
120 return IPUV3_COLORSPACE_RGB;
121 case 0x2000:
122 return IPUV3_COLORSPACE_YUV;
123 default:
124 return IPUV3_COLORSPACE_UNKNOWN;
125 }
126}
127EXPORT_SYMBOL_GPL(ipu_mbus_code_to_colorspace);
128
Steve Longerbeamf835f382014-06-25 18:05:37 -0700129int ipu_degrees_to_rot_mode(enum ipu_rotate_mode *mode, int degrees,
130 bool hflip, bool vflip)
131{
132 u32 r90, vf, hf;
133
134 switch (degrees) {
135 case 0:
136 vf = hf = r90 = 0;
137 break;
138 case 90:
139 vf = hf = 0;
140 r90 = 1;
141 break;
142 case 180:
143 vf = hf = 1;
144 r90 = 0;
145 break;
146 case 270:
147 vf = hf = r90 = 1;
148 break;
149 default:
150 return -EINVAL;
151 }
152
153 hf ^= (u32)hflip;
154 vf ^= (u32)vflip;
155
156 *mode = (enum ipu_rotate_mode)((r90 << 2) | (hf << 1) | vf);
157 return 0;
158}
159EXPORT_SYMBOL_GPL(ipu_degrees_to_rot_mode);
160
161int ipu_rot_mode_to_degrees(int *degrees, enum ipu_rotate_mode mode,
162 bool hflip, bool vflip)
163{
164 u32 r90, vf, hf;
165
166 r90 = ((u32)mode >> 2) & 0x1;
167 hf = ((u32)mode >> 1) & 0x1;
168 vf = ((u32)mode >> 0) & 0x1;
169 hf ^= (u32)hflip;
170 vf ^= (u32)vflip;
171
172 switch ((enum ipu_rotate_mode)((r90 << 2) | (hf << 1) | vf)) {
173 case IPU_ROTATE_NONE:
174 *degrees = 0;
175 break;
176 case IPU_ROTATE_90_RIGHT:
177 *degrees = 90;
178 break;
179 case IPU_ROTATE_180:
180 *degrees = 180;
181 break;
182 case IPU_ROTATE_90_LEFT:
183 *degrees = 270;
184 break;
185 default:
186 return -EINVAL;
187 }
188
189 return 0;
190}
191EXPORT_SYMBOL_GPL(ipu_rot_mode_to_degrees);
192
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200193struct ipuv3_channel *ipu_idmac_get(struct ipu_soc *ipu, unsigned num)
194{
195 struct ipuv3_channel *channel;
196
197 dev_dbg(ipu->dev, "%s %d\n", __func__, num);
198
199 if (num > 63)
200 return ERR_PTR(-ENODEV);
201
202 mutex_lock(&ipu->channel_lock);
203
204 channel = &ipu->channel[num];
205
206 if (channel->busy) {
207 channel = ERR_PTR(-EBUSY);
208 goto out;
209 }
210
Valentina Manea89bc5be2013-10-25 11:52:20 +0300211 channel->busy = true;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200212 channel->num = num;
213
214out:
215 mutex_unlock(&ipu->channel_lock);
216
217 return channel;
218}
219EXPORT_SYMBOL_GPL(ipu_idmac_get);
220
221void ipu_idmac_put(struct ipuv3_channel *channel)
222{
223 struct ipu_soc *ipu = channel->ipu;
224
225 dev_dbg(ipu->dev, "%s %d\n", __func__, channel->num);
226
227 mutex_lock(&ipu->channel_lock);
228
Valentina Manea89bc5be2013-10-25 11:52:20 +0300229 channel->busy = false;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200230
231 mutex_unlock(&ipu->channel_lock);
232}
233EXPORT_SYMBOL_GPL(ipu_idmac_put);
234
Steve Longerbeamaa52f572014-06-25 18:05:40 -0700235#define idma_mask(ch) (1 << ((ch) & 0x1f))
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200236
237void ipu_idmac_set_double_buffer(struct ipuv3_channel *channel,
238 bool doublebuffer)
239{
240 struct ipu_soc *ipu = channel->ipu;
241 unsigned long flags;
242 u32 reg;
243
244 spin_lock_irqsave(&ipu->lock, flags);
245
246 reg = ipu_cm_read(ipu, IPU_CHA_DB_MODE_SEL(channel->num));
247 if (doublebuffer)
248 reg |= idma_mask(channel->num);
249 else
250 reg &= ~idma_mask(channel->num);
251 ipu_cm_write(ipu, reg, IPU_CHA_DB_MODE_SEL(channel->num));
252
253 spin_unlock_irqrestore(&ipu->lock, flags);
254}
255EXPORT_SYMBOL_GPL(ipu_idmac_set_double_buffer);
256
257int ipu_module_enable(struct ipu_soc *ipu, u32 mask)
258{
259 unsigned long lock_flags;
260 u32 val;
261
262 spin_lock_irqsave(&ipu->lock, lock_flags);
263
264 val = ipu_cm_read(ipu, IPU_DISP_GEN);
265
266 if (mask & IPU_CONF_DI0_EN)
267 val |= IPU_DI0_COUNTER_RELEASE;
268 if (mask & IPU_CONF_DI1_EN)
269 val |= IPU_DI1_COUNTER_RELEASE;
270
271 ipu_cm_write(ipu, val, IPU_DISP_GEN);
272
273 val = ipu_cm_read(ipu, IPU_CONF);
274 val |= mask;
275 ipu_cm_write(ipu, val, IPU_CONF);
276
277 spin_unlock_irqrestore(&ipu->lock, lock_flags);
278
279 return 0;
280}
281EXPORT_SYMBOL_GPL(ipu_module_enable);
282
283int ipu_module_disable(struct ipu_soc *ipu, u32 mask)
284{
285 unsigned long lock_flags;
286 u32 val;
287
288 spin_lock_irqsave(&ipu->lock, lock_flags);
289
290 val = ipu_cm_read(ipu, IPU_CONF);
291 val &= ~mask;
292 ipu_cm_write(ipu, val, IPU_CONF);
293
294 val = ipu_cm_read(ipu, IPU_DISP_GEN);
295
296 if (mask & IPU_CONF_DI0_EN)
297 val &= ~IPU_DI0_COUNTER_RELEASE;
298 if (mask & IPU_CONF_DI1_EN)
299 val &= ~IPU_DI1_COUNTER_RELEASE;
300
301 ipu_cm_write(ipu, val, IPU_DISP_GEN);
302
303 spin_unlock_irqrestore(&ipu->lock, lock_flags);
304
305 return 0;
306}
307EXPORT_SYMBOL_GPL(ipu_module_disable);
308
Philipp Zabele9046092012-05-16 17:28:29 +0200309int ipu_idmac_get_current_buffer(struct ipuv3_channel *channel)
310{
311 struct ipu_soc *ipu = channel->ipu;
312 unsigned int chno = channel->num;
313
314 return (ipu_cm_read(ipu, IPU_CHA_CUR_BUF(chno)) & idma_mask(chno)) ? 1 : 0;
315}
316EXPORT_SYMBOL_GPL(ipu_idmac_get_current_buffer);
317
Steve Longerbeamaa52f572014-06-25 18:05:40 -0700318bool ipu_idmac_buffer_is_ready(struct ipuv3_channel *channel, u32 buf_num)
319{
320 struct ipu_soc *ipu = channel->ipu;
321 unsigned long flags;
322 u32 reg = 0;
323
324 spin_lock_irqsave(&ipu->lock, flags);
325 switch (buf_num) {
326 case 0:
327 reg = ipu_cm_read(ipu, IPU_CHA_BUF0_RDY(channel->num));
328 break;
329 case 1:
330 reg = ipu_cm_read(ipu, IPU_CHA_BUF1_RDY(channel->num));
331 break;
332 case 2:
333 reg = ipu_cm_read(ipu, IPU_CHA_BUF2_RDY(channel->num));
334 break;
335 }
336 spin_unlock_irqrestore(&ipu->lock, flags);
337
338 return ((reg & idma_mask(channel->num)) != 0);
339}
340EXPORT_SYMBOL_GPL(ipu_idmac_buffer_is_ready);
341
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200342void ipu_idmac_select_buffer(struct ipuv3_channel *channel, u32 buf_num)
343{
344 struct ipu_soc *ipu = channel->ipu;
345 unsigned int chno = channel->num;
346 unsigned long flags;
347
348 spin_lock_irqsave(&ipu->lock, flags);
349
350 /* Mark buffer as ready. */
351 if (buf_num == 0)
352 ipu_cm_write(ipu, idma_mask(chno), IPU_CHA_BUF0_RDY(chno));
353 else
354 ipu_cm_write(ipu, idma_mask(chno), IPU_CHA_BUF1_RDY(chno));
355
356 spin_unlock_irqrestore(&ipu->lock, flags);
357}
358EXPORT_SYMBOL_GPL(ipu_idmac_select_buffer);
359
Steve Longerbeambce6f082014-06-25 18:05:41 -0700360void ipu_idmac_clear_buffer(struct ipuv3_channel *channel, u32 buf_num)
361{
362 struct ipu_soc *ipu = channel->ipu;
363 unsigned int chno = channel->num;
364 unsigned long flags;
365
366 spin_lock_irqsave(&ipu->lock, flags);
367
368 ipu_cm_write(ipu, 0xF0300000, IPU_GPR); /* write one to clear */
369 switch (buf_num) {
370 case 0:
371 ipu_cm_write(ipu, idma_mask(chno), IPU_CHA_BUF0_RDY(chno));
372 break;
373 case 1:
374 ipu_cm_write(ipu, idma_mask(chno), IPU_CHA_BUF1_RDY(chno));
375 break;
376 case 2:
377 ipu_cm_write(ipu, idma_mask(chno), IPU_CHA_BUF2_RDY(chno));
378 break;
379 default:
380 break;
381 }
382 ipu_cm_write(ipu, 0x0, IPU_GPR); /* write one to set */
383
384 spin_unlock_irqrestore(&ipu->lock, flags);
385}
386EXPORT_SYMBOL_GPL(ipu_idmac_clear_buffer);
387
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200388int ipu_idmac_enable_channel(struct ipuv3_channel *channel)
389{
390 struct ipu_soc *ipu = channel->ipu;
391 u32 val;
392 unsigned long flags;
393
394 spin_lock_irqsave(&ipu->lock, flags);
395
396 val = ipu_idmac_read(ipu, IDMAC_CHA_EN(channel->num));
397 val |= idma_mask(channel->num);
398 ipu_idmac_write(ipu, val, IDMAC_CHA_EN(channel->num));
399
400 spin_unlock_irqrestore(&ipu->lock, flags);
401
402 return 0;
403}
404EXPORT_SYMBOL_GPL(ipu_idmac_enable_channel);
405
Philipp Zabel17075502014-04-14 23:53:17 +0200406bool ipu_idmac_channel_busy(struct ipu_soc *ipu, unsigned int chno)
407{
408 return (ipu_idmac_read(ipu, IDMAC_CHA_BUSY(chno)) & idma_mask(chno));
409}
410EXPORT_SYMBOL_GPL(ipu_idmac_channel_busy);
411
Sascha Hauerfb822a32013-10-10 16:18:41 +0200412int ipu_idmac_wait_busy(struct ipuv3_channel *channel, int ms)
413{
414 struct ipu_soc *ipu = channel->ipu;
415 unsigned long timeout;
416
417 timeout = jiffies + msecs_to_jiffies(ms);
418 while (ipu_idmac_read(ipu, IDMAC_CHA_BUSY(channel->num)) &
419 idma_mask(channel->num)) {
420 if (time_after(jiffies, timeout))
421 return -ETIMEDOUT;
422 cpu_relax();
423 }
424
425 return 0;
426}
427EXPORT_SYMBOL_GPL(ipu_idmac_wait_busy);
428
Philipp Zabel17075502014-04-14 23:53:17 +0200429int ipu_wait_interrupt(struct ipu_soc *ipu, int irq, int ms)
430{
431 unsigned long timeout;
432
433 timeout = jiffies + msecs_to_jiffies(ms);
434 ipu_cm_write(ipu, BIT(irq % 32), IPU_INT_STAT(irq / 32));
435 while (!(ipu_cm_read(ipu, IPU_INT_STAT(irq / 32) & BIT(irq % 32)))) {
436 if (time_after(jiffies, timeout))
437 return -ETIMEDOUT;
438 cpu_relax();
439 }
440
441 return 0;
442}
443EXPORT_SYMBOL_GPL(ipu_wait_interrupt);
444
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200445int ipu_idmac_disable_channel(struct ipuv3_channel *channel)
446{
447 struct ipu_soc *ipu = channel->ipu;
448 u32 val;
449 unsigned long flags;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200450
451 spin_lock_irqsave(&ipu->lock, flags);
452
453 /* Disable DMA channel(s) */
454 val = ipu_idmac_read(ipu, IDMAC_CHA_EN(channel->num));
455 val &= ~idma_mask(channel->num);
456 ipu_idmac_write(ipu, val, IDMAC_CHA_EN(channel->num));
457
458 /* Set channel buffers NOT to be ready */
459 ipu_cm_write(ipu, 0xf0000000, IPU_GPR); /* write one to clear */
460
461 if (ipu_cm_read(ipu, IPU_CHA_BUF0_RDY(channel->num)) &
462 idma_mask(channel->num)) {
463 ipu_cm_write(ipu, idma_mask(channel->num),
464 IPU_CHA_BUF0_RDY(channel->num));
465 }
466
467 if (ipu_cm_read(ipu, IPU_CHA_BUF1_RDY(channel->num)) &
468 idma_mask(channel->num)) {
469 ipu_cm_write(ipu, idma_mask(channel->num),
470 IPU_CHA_BUF1_RDY(channel->num));
471 }
472
473 ipu_cm_write(ipu, 0x0, IPU_GPR); /* write one to set */
474
475 /* Reset the double buffer */
476 val = ipu_cm_read(ipu, IPU_CHA_DB_MODE_SEL(channel->num));
477 val &= ~idma_mask(channel->num);
478 ipu_cm_write(ipu, val, IPU_CHA_DB_MODE_SEL(channel->num));
479
480 spin_unlock_irqrestore(&ipu->lock, flags);
481
482 return 0;
483}
484EXPORT_SYMBOL_GPL(ipu_idmac_disable_channel);
485
Philipp Zabel6c641552013-03-28 17:35:21 +0100486static int ipu_memory_reset(struct ipu_soc *ipu)
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200487{
488 unsigned long timeout;
489
490 ipu_cm_write(ipu, 0x807FFFFF, IPU_MEM_RST);
491
492 timeout = jiffies + msecs_to_jiffies(1000);
493 while (ipu_cm_read(ipu, IPU_MEM_RST) & 0x80000000) {
494 if (time_after(jiffies, timeout))
495 return -ETIME;
496 cpu_relax();
497 }
498
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200499 return 0;
500}
501
Steve Longerbeamba079752014-06-25 18:05:30 -0700502/*
503 * Set the source mux for the given CSI. Selects either parallel or
504 * MIPI CSI2 sources.
505 */
506void ipu_set_csi_src_mux(struct ipu_soc *ipu, int csi_id, bool mipi_csi2)
507{
508 unsigned long flags;
509 u32 val, mask;
510
511 mask = (csi_id == 1) ? IPU_CONF_CSI1_DATA_SOURCE :
512 IPU_CONF_CSI0_DATA_SOURCE;
513
514 spin_lock_irqsave(&ipu->lock, flags);
515
516 val = ipu_cm_read(ipu, IPU_CONF);
517 if (mipi_csi2)
518 val |= mask;
519 else
520 val &= ~mask;
521 ipu_cm_write(ipu, val, IPU_CONF);
522
523 spin_unlock_irqrestore(&ipu->lock, flags);
524}
525EXPORT_SYMBOL_GPL(ipu_set_csi_src_mux);
526
527/*
528 * Set the source mux for the IC. Selects either CSI[01] or the VDI.
529 */
530void ipu_set_ic_src_mux(struct ipu_soc *ipu, int csi_id, bool vdi)
531{
532 unsigned long flags;
533 u32 val;
534
535 spin_lock_irqsave(&ipu->lock, flags);
536
537 val = ipu_cm_read(ipu, IPU_CONF);
538 if (vdi) {
539 val |= IPU_CONF_IC_INPUT;
540 } else {
541 val &= ~IPU_CONF_IC_INPUT;
542 if (csi_id == 1)
543 val |= IPU_CONF_CSI_SEL;
544 else
545 val &= ~IPU_CONF_CSI_SEL;
546 }
547 ipu_cm_write(ipu, val, IPU_CONF);
548
549 spin_unlock_irqrestore(&ipu->lock, flags);
550}
551EXPORT_SYMBOL_GPL(ipu_set_ic_src_mux);
552
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200553struct ipu_devtype {
554 const char *name;
555 unsigned long cm_ofs;
556 unsigned long cpmem_ofs;
557 unsigned long srm_ofs;
558 unsigned long tpm_ofs;
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700559 unsigned long csi0_ofs;
560 unsigned long csi1_ofs;
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200561 unsigned long ic_ofs;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200562 unsigned long disp0_ofs;
563 unsigned long disp1_ofs;
564 unsigned long dc_tmpl_ofs;
565 unsigned long vdi_ofs;
566 enum ipuv3_type type;
567};
568
569static struct ipu_devtype ipu_type_imx51 = {
570 .name = "IPUv3EX",
571 .cm_ofs = 0x1e000000,
572 .cpmem_ofs = 0x1f000000,
573 .srm_ofs = 0x1f040000,
574 .tpm_ofs = 0x1f060000,
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700575 .csi0_ofs = 0x1f030000,
576 .csi1_ofs = 0x1f038000,
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200577 .ic_ofs = 0x1f020000,
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200578 .disp0_ofs = 0x1e040000,
579 .disp1_ofs = 0x1e048000,
580 .dc_tmpl_ofs = 0x1f080000,
581 .vdi_ofs = 0x1e068000,
582 .type = IPUV3EX,
583};
584
585static struct ipu_devtype ipu_type_imx53 = {
586 .name = "IPUv3M",
587 .cm_ofs = 0x06000000,
588 .cpmem_ofs = 0x07000000,
589 .srm_ofs = 0x07040000,
590 .tpm_ofs = 0x07060000,
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700591 .csi0_ofs = 0x07030000,
592 .csi1_ofs = 0x07038000,
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200593 .ic_ofs = 0x07020000,
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200594 .disp0_ofs = 0x06040000,
595 .disp1_ofs = 0x06048000,
596 .dc_tmpl_ofs = 0x07080000,
597 .vdi_ofs = 0x06068000,
598 .type = IPUV3M,
599};
600
601static struct ipu_devtype ipu_type_imx6q = {
602 .name = "IPUv3H",
603 .cm_ofs = 0x00200000,
604 .cpmem_ofs = 0x00300000,
605 .srm_ofs = 0x00340000,
606 .tpm_ofs = 0x00360000,
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700607 .csi0_ofs = 0x00230000,
608 .csi1_ofs = 0x00238000,
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200609 .ic_ofs = 0x00220000,
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200610 .disp0_ofs = 0x00240000,
611 .disp1_ofs = 0x00248000,
612 .dc_tmpl_ofs = 0x00380000,
613 .vdi_ofs = 0x00268000,
614 .type = IPUV3H,
615};
616
617static const struct of_device_id imx_ipu_dt_ids[] = {
618 { .compatible = "fsl,imx51-ipu", .data = &ipu_type_imx51, },
619 { .compatible = "fsl,imx53-ipu", .data = &ipu_type_imx53, },
620 { .compatible = "fsl,imx6q-ipu", .data = &ipu_type_imx6q, },
621 { /* sentinel */ }
622};
623MODULE_DEVICE_TABLE(of, imx_ipu_dt_ids);
624
625static int ipu_submodules_init(struct ipu_soc *ipu,
626 struct platform_device *pdev, unsigned long ipu_base,
627 struct clk *ipu_clk)
628{
629 char *unit;
630 int ret;
631 struct device *dev = &pdev->dev;
632 const struct ipu_devtype *devtype = ipu->devtype;
633
Steve Longerbeam7d2691d2014-06-25 18:05:47 -0700634 ret = ipu_cpmem_init(ipu, dev, ipu_base + devtype->cpmem_ofs);
635 if (ret) {
636 unit = "cpmem";
637 goto err_cpmem;
638 }
639
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700640 ret = ipu_csi_init(ipu, dev, 0, ipu_base + devtype->csi0_ofs,
641 IPU_CONF_CSI0_EN, ipu_clk);
642 if (ret) {
643 unit = "csi0";
644 goto err_csi_0;
645 }
646
647 ret = ipu_csi_init(ipu, dev, 1, ipu_base + devtype->csi1_ofs,
648 IPU_CONF_CSI1_EN, ipu_clk);
649 if (ret) {
650 unit = "csi1";
651 goto err_csi_1;
652 }
653
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200654 ret = ipu_ic_init(ipu, dev,
655 ipu_base + devtype->ic_ofs,
656 ipu_base + devtype->tpm_ofs);
657 if (ret) {
658 unit = "ic";
659 goto err_ic;
660 }
661
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200662 ret = ipu_di_init(ipu, dev, 0, ipu_base + devtype->disp0_ofs,
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200663 IPU_CONF_DI0_EN, ipu_clk);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200664 if (ret) {
665 unit = "di0";
666 goto err_di_0;
667 }
668
669 ret = ipu_di_init(ipu, dev, 1, ipu_base + devtype->disp1_ofs,
670 IPU_CONF_DI1_EN, ipu_clk);
671 if (ret) {
672 unit = "di1";
673 goto err_di_1;
674 }
675
676 ret = ipu_dc_init(ipu, dev, ipu_base + devtype->cm_ofs +
677 IPU_CM_DC_REG_OFS, ipu_base + devtype->dc_tmpl_ofs);
678 if (ret) {
679 unit = "dc_template";
680 goto err_dc;
681 }
682
683 ret = ipu_dmfc_init(ipu, dev, ipu_base +
684 devtype->cm_ofs + IPU_CM_DMFC_REG_OFS, ipu_clk);
685 if (ret) {
686 unit = "dmfc";
687 goto err_dmfc;
688 }
689
690 ret = ipu_dp_init(ipu, dev, ipu_base + devtype->srm_ofs);
691 if (ret) {
692 unit = "dp";
693 goto err_dp;
694 }
695
Philipp Zabel35de9252012-05-09 16:59:01 +0200696 ret = ipu_smfc_init(ipu, dev, ipu_base +
697 devtype->cm_ofs + IPU_CM_SMFC_REG_OFS);
698 if (ret) {
699 unit = "smfc";
700 goto err_smfc;
701 }
702
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200703 return 0;
704
Philipp Zabel35de9252012-05-09 16:59:01 +0200705err_smfc:
706 ipu_dp_exit(ipu);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200707err_dp:
708 ipu_dmfc_exit(ipu);
709err_dmfc:
710 ipu_dc_exit(ipu);
711err_dc:
712 ipu_di_exit(ipu, 1);
713err_di_1:
714 ipu_di_exit(ipu, 0);
715err_di_0:
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200716 ipu_ic_exit(ipu);
717err_ic:
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700718 ipu_csi_exit(ipu, 1);
719err_csi_1:
720 ipu_csi_exit(ipu, 0);
721err_csi_0:
Steve Longerbeam7d2691d2014-06-25 18:05:47 -0700722 ipu_cpmem_exit(ipu);
723err_cpmem:
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200724 dev_err(&pdev->dev, "init %s failed with %d\n", unit, ret);
725 return ret;
726}
727
728static void ipu_irq_handle(struct ipu_soc *ipu, const int *regs, int num_regs)
729{
730 unsigned long status;
Philipp Zabelb7287662013-06-21 10:27:39 +0200731 int i, bit, irq;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200732
733 for (i = 0; i < num_regs; i++) {
734
735 status = ipu_cm_read(ipu, IPU_INT_STAT(regs[i]));
736 status &= ipu_cm_read(ipu, IPU_INT_CTRL(regs[i]));
737
Philipp Zabelb7287662013-06-21 10:27:39 +0200738 for_each_set_bit(bit, &status, 32) {
Antoine Schweitzer-Chaput838201a2014-04-18 23:20:06 +0200739 irq = irq_linear_revmap(ipu->domain,
740 regs[i] * 32 + bit);
Philipp Zabelb7287662013-06-21 10:27:39 +0200741 if (irq)
742 generic_handle_irq(irq);
743 }
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200744 }
745}
746
747static void ipu_irq_handler(unsigned int irq, struct irq_desc *desc)
748{
749 struct ipu_soc *ipu = irq_desc_get_handler_data(desc);
750 const int int_reg[] = { 0, 1, 2, 3, 10, 11, 12, 13, 14};
751 struct irq_chip *chip = irq_get_chip(irq);
752
753 chained_irq_enter(chip, desc);
754
755 ipu_irq_handle(ipu, int_reg, ARRAY_SIZE(int_reg));
756
757 chained_irq_exit(chip, desc);
758}
759
760static void ipu_err_irq_handler(unsigned int irq, struct irq_desc *desc)
761{
762 struct ipu_soc *ipu = irq_desc_get_handler_data(desc);
763 const int int_reg[] = { 4, 5, 8, 9};
764 struct irq_chip *chip = irq_get_chip(irq);
765
766 chained_irq_enter(chip, desc);
767
768 ipu_irq_handle(ipu, int_reg, ARRAY_SIZE(int_reg));
769
770 chained_irq_exit(chip, desc);
771}
772
Philipp Zabel861a50c2014-04-14 23:53:16 +0200773int ipu_map_irq(struct ipu_soc *ipu, int irq)
774{
775 int virq;
776
777 virq = irq_linear_revmap(ipu->domain, irq);
778 if (!virq)
779 virq = irq_create_mapping(ipu->domain, irq);
780
781 return virq;
782}
783EXPORT_SYMBOL_GPL(ipu_map_irq);
784
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200785int ipu_idmac_channel_irq(struct ipu_soc *ipu, struct ipuv3_channel *channel,
786 enum ipu_channel_irq irq_type)
787{
Philipp Zabel861a50c2014-04-14 23:53:16 +0200788 return ipu_map_irq(ipu, irq_type + channel->num);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200789}
790EXPORT_SYMBOL_GPL(ipu_idmac_channel_irq);
791
792static void ipu_submodules_exit(struct ipu_soc *ipu)
793{
Philipp Zabel35de9252012-05-09 16:59:01 +0200794 ipu_smfc_exit(ipu);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200795 ipu_dp_exit(ipu);
796 ipu_dmfc_exit(ipu);
797 ipu_dc_exit(ipu);
798 ipu_di_exit(ipu, 1);
799 ipu_di_exit(ipu, 0);
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +0200800 ipu_ic_exit(ipu);
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -0700801 ipu_csi_exit(ipu, 1);
802 ipu_csi_exit(ipu, 0);
Steve Longerbeam7d2691d2014-06-25 18:05:47 -0700803 ipu_cpmem_exit(ipu);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200804}
805
806static int platform_remove_devices_fn(struct device *dev, void *unused)
807{
808 struct platform_device *pdev = to_platform_device(dev);
809
810 platform_device_unregister(pdev);
811
812 return 0;
813}
814
815static void platform_device_unregister_children(struct platform_device *pdev)
816{
817 device_for_each_child(&pdev->dev, NULL, platform_remove_devices_fn);
818}
819
820struct ipu_platform_reg {
821 struct ipu_client_platformdata pdata;
822 const char *name;
Philipp Zabeld6ca8ca2012-05-23 17:08:19 +0200823 int reg_offset;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200824};
825
826static const struct ipu_platform_reg client_reg[] = {
827 {
828 .pdata = {
829 .di = 0,
830 .dc = 5,
831 .dp = IPU_DP_FLOW_SYNC_BG,
832 .dma[0] = IPUV3_CHANNEL_MEM_BG_SYNC,
Philipp Zabelb8d181e2013-10-10 16:18:45 +0200833 .dma[1] = IPUV3_CHANNEL_MEM_FG_SYNC,
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200834 },
835 .name = "imx-ipuv3-crtc",
836 }, {
837 .pdata = {
838 .di = 1,
839 .dc = 1,
840 .dp = -EINVAL,
841 .dma[0] = IPUV3_CHANNEL_MEM_DC_SYNC,
842 .dma[1] = -EINVAL,
843 },
844 .name = "imx-ipuv3-crtc",
Philipp Zabeld6ca8ca2012-05-23 17:08:19 +0200845 }, {
846 .pdata = {
847 .csi = 0,
848 .dma[0] = IPUV3_CHANNEL_CSI0,
849 .dma[1] = -EINVAL,
850 },
851 .reg_offset = IPU_CM_CSI0_REG_OFS,
852 .name = "imx-ipuv3-camera",
853 }, {
854 .pdata = {
855 .csi = 1,
856 .dma[0] = IPUV3_CHANNEL_CSI1,
857 .dma[1] = -EINVAL,
858 },
859 .reg_offset = IPU_CM_CSI1_REG_OFS,
860 .name = "imx-ipuv3-camera",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200861 },
862};
863
Russell King4ae078d2013-12-16 11:34:25 +0000864static DEFINE_MUTEX(ipu_client_id_mutex);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200865static int ipu_client_id;
866
Philipp Zabeld6ca8ca2012-05-23 17:08:19 +0200867static int ipu_add_client_devices(struct ipu_soc *ipu, unsigned long ipu_base)
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200868{
Russell King4ae078d2013-12-16 11:34:25 +0000869 struct device *dev = ipu->dev;
870 unsigned i;
871 int id, ret;
872
873 mutex_lock(&ipu_client_id_mutex);
874 id = ipu_client_id;
875 ipu_client_id += ARRAY_SIZE(client_reg);
876 mutex_unlock(&ipu_client_id_mutex);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200877
878 for (i = 0; i < ARRAY_SIZE(client_reg); i++) {
879 const struct ipu_platform_reg *reg = &client_reg[i];
Russell King4ae078d2013-12-16 11:34:25 +0000880 struct platform_device *pdev;
Philipp Zabeld6ca8ca2012-05-23 17:08:19 +0200881 struct resource res;
Russell King4ae078d2013-12-16 11:34:25 +0000882
Philipp Zabeld6ca8ca2012-05-23 17:08:19 +0200883 if (reg->reg_offset) {
884 memset(&res, 0, sizeof(res));
885 res.flags = IORESOURCE_MEM;
886 res.start = ipu_base + ipu->devtype->cm_ofs + reg->reg_offset;
887 res.end = res.start + PAGE_SIZE - 1;
888 pdev = platform_device_register_resndata(dev, reg->name,
889 id++, &res, 1, &reg->pdata, sizeof(reg->pdata));
890 } else {
891 pdev = platform_device_register_data(dev, reg->name,
892 id++, &reg->pdata, sizeof(reg->pdata));
893 }
Russell King4ae078d2013-12-16 11:34:25 +0000894
895 if (IS_ERR(pdev))
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200896 goto err_register;
897 }
898
899 return 0;
900
901err_register:
Russell King4ae078d2013-12-16 11:34:25 +0000902 platform_device_unregister_children(to_platform_device(dev));
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200903
904 return ret;
905}
906
Philipp Zabelb7287662013-06-21 10:27:39 +0200907
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200908static int ipu_irq_init(struct ipu_soc *ipu)
909{
Philipp Zabel379cdec2013-06-21 14:52:17 +0200910 struct irq_chip_generic *gc;
911 struct irq_chip_type *ct;
Philipp Zabel37f85b262013-06-21 14:52:18 +0200912 unsigned long unused[IPU_NUM_IRQS / 32] = {
913 0x400100d0, 0xffe000fd,
914 0x400100d0, 0xffe000fd,
915 0x400100d0, 0xffe000fd,
916 0x4077ffff, 0xffe7e1fd,
917 0x23fffffe, 0x8880fff0,
918 0xf98fe7d0, 0xfff81fff,
919 0x400100d0, 0xffe000fd,
920 0x00000000,
921 };
Philipp Zabel379cdec2013-06-21 14:52:17 +0200922 int ret, i;
923
Philipp Zabelb7287662013-06-21 10:27:39 +0200924 ipu->domain = irq_domain_add_linear(ipu->dev->of_node, IPU_NUM_IRQS,
Philipp Zabel379cdec2013-06-21 14:52:17 +0200925 &irq_generic_chip_ops, ipu);
Philipp Zabelb7287662013-06-21 10:27:39 +0200926 if (!ipu->domain) {
927 dev_err(ipu->dev, "failed to add irq domain\n");
928 return -ENODEV;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200929 }
930
Philipp Zabel379cdec2013-06-21 14:52:17 +0200931 ret = irq_alloc_domain_generic_chips(ipu->domain, 32, 1, "IPU",
Antoine Schweitzer-Chaput838201a2014-04-18 23:20:06 +0200932 handle_level_irq, 0,
933 IRQF_VALID, 0);
Philipp Zabel379cdec2013-06-21 14:52:17 +0200934 if (ret < 0) {
935 dev_err(ipu->dev, "failed to alloc generic irq chips\n");
936 irq_domain_remove(ipu->domain);
937 return ret;
938 }
939
940 for (i = 0; i < IPU_NUM_IRQS; i += 32) {
941 gc = irq_get_domain_generic_chip(ipu->domain, i);
942 gc->reg_base = ipu->cm_reg;
Philipp Zabel37f85b262013-06-21 14:52:18 +0200943 gc->unused = unused[i / 32];
Philipp Zabel379cdec2013-06-21 14:52:17 +0200944 ct = gc->chip_types;
945 ct->chip.irq_ack = irq_gc_ack_set_bit;
946 ct->chip.irq_mask = irq_gc_mask_clr_bit;
947 ct->chip.irq_unmask = irq_gc_mask_set_bit;
948 ct->regs.ack = IPU_INT_STAT(i / 32);
949 ct->regs.mask = IPU_INT_CTRL(i / 32);
950 }
951
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200952 irq_set_chained_handler(ipu->irq_sync, ipu_irq_handler);
953 irq_set_handler_data(ipu->irq_sync, ipu);
954 irq_set_chained_handler(ipu->irq_err, ipu_err_irq_handler);
955 irq_set_handler_data(ipu->irq_err, ipu);
956
957 return 0;
958}
959
960static void ipu_irq_exit(struct ipu_soc *ipu)
961{
Philipp Zabelb7287662013-06-21 10:27:39 +0200962 int i, irq;
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200963
964 irq_set_chained_handler(ipu->irq_err, NULL);
965 irq_set_handler_data(ipu->irq_err, NULL);
966 irq_set_chained_handler(ipu->irq_sync, NULL);
967 irq_set_handler_data(ipu->irq_sync, NULL);
968
Philipp Zabel379cdec2013-06-21 14:52:17 +0200969 /* TODO: remove irq_domain_generic_chips */
970
Philipp Zabelb7287662013-06-21 10:27:39 +0200971 for (i = 0; i < IPU_NUM_IRQS; i++) {
972 irq = irq_linear_revmap(ipu->domain, i);
973 if (irq)
974 irq_dispose_mapping(irq);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200975 }
976
Philipp Zabelb7287662013-06-21 10:27:39 +0200977 irq_domain_remove(ipu->domain);
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200978}
979
Bill Pembertonc4aabf82012-11-19 13:22:11 -0500980static int ipu_probe(struct platform_device *pdev)
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200981{
982 const struct of_device_id *of_id =
983 of_match_device(imx_ipu_dt_ids, &pdev->dev);
984 struct ipu_soc *ipu;
985 struct resource *res;
986 unsigned long ipu_base;
987 int i, ret, irq_sync, irq_err;
988 const struct ipu_devtype *devtype;
989
990 devtype = of_id->data;
991
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200992 irq_sync = platform_get_irq(pdev, 0);
993 irq_err = platform_get_irq(pdev, 1);
994 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
995
Fabio Estevamfd563db2012-10-24 21:36:46 -0200996 dev_dbg(&pdev->dev, "irq_sync: %d irq_err: %d\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +0200997 irq_sync, irq_err);
998
999 if (!res || irq_sync < 0 || irq_err < 0)
1000 return -ENODEV;
1001
1002 ipu_base = res->start;
1003
1004 ipu = devm_kzalloc(&pdev->dev, sizeof(*ipu), GFP_KERNEL);
1005 if (!ipu)
1006 return -ENODEV;
1007
1008 for (i = 0; i < 64; i++)
1009 ipu->channel[i].ipu = ipu;
1010 ipu->devtype = devtype;
1011 ipu->ipu_type = devtype->type;
1012
1013 spin_lock_init(&ipu->lock);
1014 mutex_init(&ipu->channel_lock);
1015
Fabio Estevamfd563db2012-10-24 21:36:46 -02001016 dev_dbg(&pdev->dev, "cm_reg: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001017 ipu_base + devtype->cm_ofs);
Fabio Estevamfd563db2012-10-24 21:36:46 -02001018 dev_dbg(&pdev->dev, "idmac: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001019 ipu_base + devtype->cm_ofs + IPU_CM_IDMAC_REG_OFS);
Fabio Estevamfd563db2012-10-24 21:36:46 -02001020 dev_dbg(&pdev->dev, "cpmem: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001021 ipu_base + devtype->cpmem_ofs);
Steve Longerbeam2ffd48f2014-08-19 10:52:40 -07001022 dev_dbg(&pdev->dev, "csi0: 0x%08lx\n",
1023 ipu_base + devtype->csi0_ofs);
1024 dev_dbg(&pdev->dev, "csi1: 0x%08lx\n",
1025 ipu_base + devtype->csi1_ofs);
Steve Longerbeam1aa8ea02014-08-11 13:04:50 +02001026 dev_dbg(&pdev->dev, "ic: 0x%08lx\n",
1027 ipu_base + devtype->ic_ofs);
Fabio Estevamfd563db2012-10-24 21:36:46 -02001028 dev_dbg(&pdev->dev, "disp0: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001029 ipu_base + devtype->disp0_ofs);
Fabio Estevamfd563db2012-10-24 21:36:46 -02001030 dev_dbg(&pdev->dev, "disp1: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001031 ipu_base + devtype->disp1_ofs);
Fabio Estevamfd563db2012-10-24 21:36:46 -02001032 dev_dbg(&pdev->dev, "srm: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001033 ipu_base + devtype->srm_ofs);
Fabio Estevamfd563db2012-10-24 21:36:46 -02001034 dev_dbg(&pdev->dev, "tpm: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001035 ipu_base + devtype->tpm_ofs);
Fabio Estevamfd563db2012-10-24 21:36:46 -02001036 dev_dbg(&pdev->dev, "dc: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001037 ipu_base + devtype->cm_ofs + IPU_CM_DC_REG_OFS);
Fabio Estevamfd563db2012-10-24 21:36:46 -02001038 dev_dbg(&pdev->dev, "ic: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001039 ipu_base + devtype->cm_ofs + IPU_CM_IC_REG_OFS);
Fabio Estevamfd563db2012-10-24 21:36:46 -02001040 dev_dbg(&pdev->dev, "dmfc: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001041 ipu_base + devtype->cm_ofs + IPU_CM_DMFC_REG_OFS);
Fabio Estevamfd563db2012-10-24 21:36:46 -02001042 dev_dbg(&pdev->dev, "vdi: 0x%08lx\n",
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001043 ipu_base + devtype->vdi_ofs);
1044
1045 ipu->cm_reg = devm_ioremap(&pdev->dev,
1046 ipu_base + devtype->cm_ofs, PAGE_SIZE);
1047 ipu->idmac_reg = devm_ioremap(&pdev->dev,
1048 ipu_base + devtype->cm_ofs + IPU_CM_IDMAC_REG_OFS,
1049 PAGE_SIZE);
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001050
Steve Longerbeam7d2691d2014-06-25 18:05:47 -07001051 if (!ipu->cm_reg || !ipu->idmac_reg)
Fabio Estevambe798b22013-07-20 18:22:09 -03001052 return -ENOMEM;
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001053
1054 ipu->clk = devm_clk_get(&pdev->dev, "bus");
1055 if (IS_ERR(ipu->clk)) {
1056 ret = PTR_ERR(ipu->clk);
1057 dev_err(&pdev->dev, "clk_get failed with %d", ret);
Fabio Estevambe798b22013-07-20 18:22:09 -03001058 return ret;
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001059 }
1060
1061 platform_set_drvdata(pdev, ipu);
1062
Fabio Estevam62645a22013-07-20 18:22:10 -03001063 ret = clk_prepare_enable(ipu->clk);
1064 if (ret) {
1065 dev_err(&pdev->dev, "clk_prepare_enable failed: %d\n", ret);
1066 return ret;
1067 }
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001068
1069 ipu->dev = &pdev->dev;
1070 ipu->irq_sync = irq_sync;
1071 ipu->irq_err = irq_err;
1072
1073 ret = ipu_irq_init(ipu);
1074 if (ret)
1075 goto out_failed_irq;
1076
Philipp Zabel6c641552013-03-28 17:35:21 +01001077 ret = device_reset(&pdev->dev);
1078 if (ret) {
1079 dev_err(&pdev->dev, "failed to reset: %d\n", ret);
1080 goto out_failed_reset;
1081 }
1082 ret = ipu_memory_reset(ipu);
Lothar Waßmann4d27b2c2012-12-25 15:58:37 +01001083 if (ret)
1084 goto out_failed_reset;
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001085
1086 /* Set MCU_T to divide MCU access window into 2 */
1087 ipu_cm_write(ipu, 0x00400000L | (IPU_MCU_T_DEFAULT << 18),
1088 IPU_DISP_GEN);
1089
1090 ret = ipu_submodules_init(ipu, pdev, ipu_base, ipu->clk);
1091 if (ret)
1092 goto failed_submodules_init;
1093
Philipp Zabeld6ca8ca2012-05-23 17:08:19 +02001094 ret = ipu_add_client_devices(ipu, ipu_base);
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001095 if (ret) {
1096 dev_err(&pdev->dev, "adding client devices failed with %d\n",
1097 ret);
1098 goto failed_add_clients;
1099 }
1100
Fabio Estevam9c2c438c2012-10-24 21:36:47 -02001101 dev_info(&pdev->dev, "%s probed\n", devtype->name);
1102
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001103 return 0;
1104
1105failed_add_clients:
1106 ipu_submodules_exit(ipu);
1107failed_submodules_init:
Lothar Waßmann4d27b2c2012-12-25 15:58:37 +01001108out_failed_reset:
Philipp Zabel6c641552013-03-28 17:35:21 +01001109 ipu_irq_exit(ipu);
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001110out_failed_irq:
1111 clk_disable_unprepare(ipu->clk);
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001112 return ret;
1113}
1114
Bill Pemberton8aa1be42012-11-19 13:26:38 -05001115static int ipu_remove(struct platform_device *pdev)
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001116{
1117 struct ipu_soc *ipu = platform_get_drvdata(pdev);
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001118
1119 platform_device_unregister_children(pdev);
1120 ipu_submodules_exit(ipu);
1121 ipu_irq_exit(ipu);
1122
1123 clk_disable_unprepare(ipu->clk);
1124
1125 return 0;
1126}
1127
1128static struct platform_driver imx_ipu_driver = {
1129 .driver = {
1130 .name = "imx-ipuv3",
1131 .of_match_table = imx_ipu_dt_ids,
1132 },
1133 .probe = ipu_probe,
Bill Pemberton99c28f12012-11-19 13:20:51 -05001134 .remove = ipu_remove,
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001135};
1136
1137module_platform_driver(imx_ipu_driver);
1138
Fabio Estevam10f22682013-07-20 18:22:11 -03001139MODULE_ALIAS("platform:imx-ipuv3");
Sascha Haueraecfbdb2012-09-21 10:07:49 +02001140MODULE_DESCRIPTION("i.MX IPU v3 driver");
1141MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
1142MODULE_LICENSE("GPL");