blob: 287226311413c7036cecb02e973e6109d0b26548 [file] [log] [blame]
Sascha Hauerf326f792012-09-21 10:07:50 +02001/*
2 * i.MX IPUv3 Graphics driver
3 *
4 * Copyright (C) 2011 Sascha Hauer, Pengutronix
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Sascha Hauerf326f792012-09-21 10:07:50 +020014 */
Russell King17b50012013-11-03 11:23:34 +000015#include <linux/component.h>
Sascha Hauerf326f792012-09-21 10:07:50 +020016#include <linux/module.h>
17#include <linux/export.h>
18#include <linux/device.h>
19#include <linux/platform_device.h>
20#include <drm/drmP.h>
Sascha Hauerf326f792012-09-21 10:07:50 +020021#include <drm/drm_crtc_helper.h>
22#include <linux/fb.h>
23#include <linux/clk.h>
Philipp Zabelb8d181e2013-10-10 16:18:45 +020024#include <linux/errno.h>
Sascha Hauerf326f792012-09-21 10:07:50 +020025#include <drm/drm_gem_cma_helper.h>
26#include <drm/drm_fb_cma_helper.h>
27
Philipp Zabel39b90042013-09-30 16:13:39 +020028#include <video/imx-ipu-v3.h>
Sascha Hauerf326f792012-09-21 10:07:50 +020029#include "imx-drm.h"
Philipp Zabelb8d181e2013-10-10 16:18:45 +020030#include "ipuv3-plane.h"
Sascha Hauerf326f792012-09-21 10:07:50 +020031
32#define DRIVER_DESC "i.MX IPUv3 Graphics"
33
Sascha Hauerf326f792012-09-21 10:07:50 +020034struct ipu_crtc {
Sascha Hauerf326f792012-09-21 10:07:50 +020035 struct device *dev;
36 struct drm_crtc base;
37 struct imx_drm_crtc *imx_crtc;
Philipp Zabelb8d181e2013-10-10 16:18:45 +020038
39 /* plane[0] is the full plane, plane[1] is the partial plane */
40 struct ipu_plane *plane[2];
41
Sascha Hauerf326f792012-09-21 10:07:50 +020042 struct ipu_dc *dc;
Sascha Hauerf326f792012-09-21 10:07:50 +020043 struct ipu_di *di;
44 int enabled;
Sascha Hauerf326f792012-09-21 10:07:50 +020045 struct drm_pending_vblank_event *page_flip_event;
46 struct drm_framebuffer *newfb;
47 int irq;
Philipp Zabel2872c802015-02-02 17:25:59 +010048 u32 bus_format;
Philipp Zabel2ea42602013-04-08 18:04:35 +020049 int di_hsync_pin;
50 int di_vsync_pin;
Sascha Hauerf326f792012-09-21 10:07:50 +020051};
52
53#define to_ipu_crtc(x) container_of(x, struct ipu_crtc, base)
54
Sascha Hauerf326f792012-09-21 10:07:50 +020055static void ipu_fb_enable(struct ipu_crtc *ipu_crtc)
56{
Philipp Zabel1e6d4862014-04-14 23:53:23 +020057 struct ipu_soc *ipu = dev_get_drvdata(ipu_crtc->dev->parent);
58
Sascha Hauerf326f792012-09-21 10:07:50 +020059 if (ipu_crtc->enabled)
60 return;
61
Philipp Zabel1e6d4862014-04-14 23:53:23 +020062 ipu_dc_enable(ipu);
Philipp Zabelb8d181e2013-10-10 16:18:45 +020063 ipu_plane_enable(ipu_crtc->plane[0]);
Philipp Zabelc115edb2014-04-14 23:53:22 +020064 /* Start DC channel and DI after IDMAC */
65 ipu_dc_enable_channel(ipu_crtc->dc);
66 ipu_di_enable(ipu_crtc->di);
Lucas Stach6c8b66e2015-11-03 12:02:17 +010067 drm_crtc_vblank_on(&ipu_crtc->base);
Sascha Hauerf326f792012-09-21 10:07:50 +020068
69 ipu_crtc->enabled = 1;
70}
71
72static void ipu_fb_disable(struct ipu_crtc *ipu_crtc)
73{
Philipp Zabel1e6d4862014-04-14 23:53:23 +020074 struct ipu_soc *ipu = dev_get_drvdata(ipu_crtc->dev->parent);
75
Sascha Hauerf326f792012-09-21 10:07:50 +020076 if (!ipu_crtc->enabled)
77 return;
78
Philipp Zabelc115edb2014-04-14 23:53:22 +020079 /* Stop DC channel and DI before IDMAC */
Sascha Hauerf326f792012-09-21 10:07:50 +020080 ipu_dc_disable_channel(ipu_crtc->dc);
Sascha Hauerf326f792012-09-21 10:07:50 +020081 ipu_di_disable(ipu_crtc->di);
Philipp Zabelc115edb2014-04-14 23:53:22 +020082 ipu_plane_disable(ipu_crtc->plane[0]);
Philipp Zabel1e6d4862014-04-14 23:53:23 +020083 ipu_dc_disable(ipu);
Lucas Stach6c8b66e2015-11-03 12:02:17 +010084 drm_crtc_vblank_off(&ipu_crtc->base);
Sascha Hauerf326f792012-09-21 10:07:50 +020085
86 ipu_crtc->enabled = 0;
87}
88
89static void ipu_crtc_dpms(struct drm_crtc *crtc, int mode)
90{
91 struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc);
92
Philipp Zabela8e4e232012-11-12 16:29:01 +010093 dev_dbg(ipu_crtc->dev, "%s mode: %d\n", __func__, mode);
Sascha Hauerf326f792012-09-21 10:07:50 +020094
95 switch (mode) {
96 case DRM_MODE_DPMS_ON:
97 ipu_fb_enable(ipu_crtc);
98 break;
99 case DRM_MODE_DPMS_STANDBY:
100 case DRM_MODE_DPMS_SUSPEND:
101 case DRM_MODE_DPMS_OFF:
102 ipu_fb_disable(ipu_crtc);
103 break;
104 }
105}
106
107static int ipu_page_flip(struct drm_crtc *crtc,
108 struct drm_framebuffer *fb,
Keith Packarded8d1972013-07-22 18:49:58 -0700109 struct drm_pending_vblank_event *event,
110 uint32_t page_flip_flags)
Sascha Hauerf326f792012-09-21 10:07:50 +0200111{
112 struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc);
113 int ret;
114
115 if (ipu_crtc->newfb)
116 return -EBUSY;
117
118 ret = imx_drm_crtc_vblank_get(ipu_crtc->imx_crtc);
119 if (ret) {
120 dev_dbg(ipu_crtc->dev, "failed to acquire vblank counter\n");
121 list_del(&event->base.link);
122
123 return ret;
124 }
125
126 ipu_crtc->newfb = fb;
127 ipu_crtc->page_flip_event = event;
Matt Roperf4510a22014-04-01 15:22:40 -0700128 crtc->primary->fb = fb;
Sascha Hauerf326f792012-09-21 10:07:50 +0200129
130 return 0;
131}
132
133static const struct drm_crtc_funcs ipu_crtc_funcs = {
134 .set_config = drm_crtc_helper_set_config,
135 .destroy = drm_crtc_cleanup,
136 .page_flip = ipu_page_flip,
137};
138
Sascha Hauerf326f792012-09-21 10:07:50 +0200139static int ipu_crtc_mode_set(struct drm_crtc *crtc,
140 struct drm_display_mode *orig_mode,
141 struct drm_display_mode *mode,
142 int x, int y,
143 struct drm_framebuffer *old_fb)
144{
Russell Kingd50141d2014-12-21 15:58:19 +0000145 struct drm_device *dev = crtc->dev;
146 struct drm_encoder *encoder;
Sascha Hauerf326f792012-09-21 10:07:50 +0200147 struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc);
Sascha Hauerf326f792012-09-21 10:07:50 +0200148 struct ipu_di_signal_cfg sig_cfg = {};
Russell Kingd50141d2014-12-21 15:58:19 +0000149 unsigned long encoder_types = 0;
Russell Kingd50141d2014-12-21 15:58:19 +0000150 int ret;
Sascha Hauerf326f792012-09-21 10:07:50 +0200151
152 dev_dbg(ipu_crtc->dev, "%s: mode->hdisplay: %d\n", __func__,
153 mode->hdisplay);
154 dev_dbg(ipu_crtc->dev, "%s: mode->vdisplay: %d\n", __func__,
155 mode->vdisplay);
156
Russell Kingd50141d2014-12-21 15:58:19 +0000157 list_for_each_entry(encoder, &dev->mode_config.encoder_list, head)
158 if (encoder->crtc == crtc)
159 encoder_types |= BIT(encoder->encoder_type);
160
161 dev_dbg(ipu_crtc->dev, "%s: attached to encoder types 0x%lx\n",
162 __func__, encoder_types);
163
164 /*
Philipp Zabele0d155c2014-07-11 17:28:45 +0200165 * If we have DAC or LDB, then we need the IPU DI clock to be
166 * the same as the LDB DI clock. For TVDAC, derive the IPU DI
167 * clock from 27 MHz TVE_DI clock, but allow to divide it.
Russell Kingd50141d2014-12-21 15:58:19 +0000168 */
169 if (encoder_types & (BIT(DRM_MODE_ENCODER_DAC) |
Russell Kingd50141d2014-12-21 15:58:19 +0000170 BIT(DRM_MODE_ENCODER_LVDS)))
171 sig_cfg.clkflags = IPU_DI_CLKMODE_SYNC | IPU_DI_CLKMODE_EXT;
Philipp Zabele0d155c2014-07-11 17:28:45 +0200172 else if (encoder_types & BIT(DRM_MODE_ENCODER_TVDAC))
173 sig_cfg.clkflags = IPU_DI_CLKMODE_EXT;
Russell Kingd50141d2014-12-21 15:58:19 +0000174 else
175 sig_cfg.clkflags = 0;
176
Sascha Hauerf326f792012-09-21 10:07:50 +0200177 sig_cfg.enable_pol = 1;
Denis Carikli85de9d12014-04-07 14:44:43 +0200178 sig_cfg.clk_pol = 0;
Philipp Zabel2872c802015-02-02 17:25:59 +0100179 sig_cfg.bus_format = ipu_crtc->bus_format;
Sascha Hauerf326f792012-09-21 10:07:50 +0200180 sig_cfg.v_to_h_sync = 0;
Philipp Zabel2ea42602013-04-08 18:04:35 +0200181 sig_cfg.hsync_pin = ipu_crtc->di_hsync_pin;
182 sig_cfg.vsync_pin = ipu_crtc->di_vsync_pin;
183
Steve Longerbeamb6835a72014-12-18 18:00:25 -0800184 drm_display_mode_to_videomode(mode, &sig_cfg.mode);
185
186 ret = ipu_dc_init_sync(ipu_crtc->dc, ipu_crtc->di,
187 mode->flags & DRM_MODE_FLAG_INTERLACE,
Philipp Zabel2872c802015-02-02 17:25:59 +0100188 ipu_crtc->bus_format, mode->hdisplay);
Sascha Hauerf326f792012-09-21 10:07:50 +0200189 if (ret) {
190 dev_err(ipu_crtc->dev,
191 "initializing display controller failed with %d\n",
192 ret);
193 return ret;
194 }
195
196 ret = ipu_di_init_sync_panel(ipu_crtc->di, &sig_cfg);
197 if (ret) {
198 dev_err(ipu_crtc->dev,
199 "initializing panel failed with %d\n", ret);
200 return ret;
201 }
202
Yannis Damigos30e94a52014-08-19 18:26:46 +0300203 return ipu_plane_mode_set(ipu_crtc->plane[0], crtc, mode,
204 crtc->primary->fb,
Philipp Zabelb8d181e2013-10-10 16:18:45 +0200205 0, 0, mode->hdisplay, mode->vdisplay,
Philipp Zabeldd7fa6d2014-07-11 18:02:06 +0200206 x, y, mode->hdisplay, mode->vdisplay,
207 mode->flags & DRM_MODE_FLAG_INTERLACE);
Sascha Hauerf326f792012-09-21 10:07:50 +0200208}
209
210static void ipu_crtc_handle_pageflip(struct ipu_crtc *ipu_crtc)
211{
Sascha Hauerf326f792012-09-21 10:07:50 +0200212 unsigned long flags;
213 struct drm_device *drm = ipu_crtc->base.dev;
214
215 spin_lock_irqsave(&drm->event_lock, flags);
Rob Clark0eca56f2012-10-08 19:50:46 +0000216 if (ipu_crtc->page_flip_event)
Russell King69d21fc2015-11-25 10:25:39 +0000217 drm_crtc_send_vblank_event(&ipu_crtc->base,
218 ipu_crtc->page_flip_event);
Sascha Hauerf326f792012-09-21 10:07:50 +0200219 ipu_crtc->page_flip_event = NULL;
Sascha Hauerf326f792012-09-21 10:07:50 +0200220 imx_drm_crtc_vblank_put(ipu_crtc->imx_crtc);
Sascha Hauerf326f792012-09-21 10:07:50 +0200221 spin_unlock_irqrestore(&drm->event_lock, flags);
222}
223
224static irqreturn_t ipu_irq_handler(int irq, void *dev_id)
225{
226 struct ipu_crtc *ipu_crtc = dev_id;
227
228 imx_drm_handle_vblank(ipu_crtc->imx_crtc);
229
230 if (ipu_crtc->newfb) {
Yannis Damigos30e94a52014-08-19 18:26:46 +0300231 struct ipu_plane *plane = ipu_crtc->plane[0];
232
Sascha Hauerf326f792012-09-21 10:07:50 +0200233 ipu_crtc->newfb = NULL;
Yannis Damigos30e94a52014-08-19 18:26:46 +0300234 ipu_plane_set_base(plane, ipu_crtc->base.primary->fb,
235 plane->x, plane->y);
Sascha Hauerf326f792012-09-21 10:07:50 +0200236 ipu_crtc_handle_pageflip(ipu_crtc);
237 }
238
239 return IRQ_HANDLED;
240}
241
242static bool ipu_crtc_mode_fixup(struct drm_crtc *crtc,
243 const struct drm_display_mode *mode,
244 struct drm_display_mode *adjusted_mode)
245{
Steve Longerbeam0c460a52014-12-18 18:00:23 -0800246 struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc);
247 struct videomode vm;
248 int ret;
249
250 drm_display_mode_to_videomode(adjusted_mode, &vm);
251
252 ret = ipu_di_adjust_videomode(ipu_crtc->di, &vm);
253 if (ret)
254 return false;
255
256 drm_display_mode_from_videomode(&vm, adjusted_mode);
257
Sascha Hauerf326f792012-09-21 10:07:50 +0200258 return true;
259}
260
261static void ipu_crtc_prepare(struct drm_crtc *crtc)
262{
263 struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc);
264
265 ipu_fb_disable(ipu_crtc);
266}
267
268static void ipu_crtc_commit(struct drm_crtc *crtc)
269{
270 struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc);
271
272 ipu_fb_enable(ipu_crtc);
273}
274
Ville Syrjälä7ae847d2015-12-15 12:21:09 +0100275static const struct drm_crtc_helper_funcs ipu_helper_funcs = {
Sascha Hauerf326f792012-09-21 10:07:50 +0200276 .dpms = ipu_crtc_dpms,
277 .mode_fixup = ipu_crtc_mode_fixup,
278 .mode_set = ipu_crtc_mode_set,
279 .prepare = ipu_crtc_prepare,
280 .commit = ipu_crtc_commit,
Sascha Hauerf326f792012-09-21 10:07:50 +0200281};
282
283static int ipu_enable_vblank(struct drm_crtc *crtc)
284{
Sascha Hauerf326f792012-09-21 10:07:50 +0200285 return 0;
286}
287
288static void ipu_disable_vblank(struct drm_crtc *crtc)
289{
290 struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc);
291
Sascha Hauer6ee4d7f2013-10-10 16:18:44 +0200292 ipu_crtc->page_flip_event = NULL;
293 ipu_crtc->newfb = NULL;
Sascha Hauerf326f792012-09-21 10:07:50 +0200294}
295
Russell Kingd50141d2014-12-21 15:58:19 +0000296static int ipu_set_interface_pix_fmt(struct drm_crtc *crtc,
Philipp Zabel2872c802015-02-02 17:25:59 +0100297 u32 bus_format, int hsync_pin, int vsync_pin)
Sascha Hauerf326f792012-09-21 10:07:50 +0200298{
299 struct ipu_crtc *ipu_crtc = to_ipu_crtc(crtc);
300
Philipp Zabel2872c802015-02-02 17:25:59 +0100301 ipu_crtc->bus_format = bus_format;
Philipp Zabel2ea42602013-04-08 18:04:35 +0200302 ipu_crtc->di_hsync_pin = hsync_pin;
303 ipu_crtc->di_vsync_pin = vsync_pin;
Sascha Hauerf326f792012-09-21 10:07:50 +0200304
Sascha Hauerf326f792012-09-21 10:07:50 +0200305 return 0;
306}
307
308static const struct imx_drm_crtc_helper_funcs ipu_crtc_helper_funcs = {
309 .enable_vblank = ipu_enable_vblank,
310 .disable_vblank = ipu_disable_vblank,
311 .set_interface_pix_fmt = ipu_set_interface_pix_fmt,
312 .crtc_funcs = &ipu_crtc_funcs,
313 .crtc_helper_funcs = &ipu_helper_funcs,
314};
315
316static void ipu_put_resources(struct ipu_crtc *ipu_crtc)
317{
Philipp Zabelb8d181e2013-10-10 16:18:45 +0200318 if (!IS_ERR_OR_NULL(ipu_crtc->dc))
319 ipu_dc_put(ipu_crtc->dc);
Sascha Hauerf326f792012-09-21 10:07:50 +0200320 if (!IS_ERR_OR_NULL(ipu_crtc->di))
321 ipu_di_put(ipu_crtc->di);
322}
323
324static int ipu_get_resources(struct ipu_crtc *ipu_crtc,
325 struct ipu_client_platformdata *pdata)
326{
327 struct ipu_soc *ipu = dev_get_drvdata(ipu_crtc->dev->parent);
328 int ret;
329
Sascha Hauerf326f792012-09-21 10:07:50 +0200330 ipu_crtc->dc = ipu_dc_get(ipu, pdata->dc);
331 if (IS_ERR(ipu_crtc->dc)) {
332 ret = PTR_ERR(ipu_crtc->dc);
333 goto err_out;
334 }
335
Sascha Hauerf326f792012-09-21 10:07:50 +0200336 ipu_crtc->di = ipu_di_get(ipu, pdata->di);
337 if (IS_ERR(ipu_crtc->di)) {
338 ret = PTR_ERR(ipu_crtc->di);
339 goto err_out;
340 }
341
Sascha Hauerf326f792012-09-21 10:07:50 +0200342 return 0;
343err_out:
344 ipu_put_resources(ipu_crtc);
345
346 return ret;
347}
348
349static int ipu_crtc_init(struct ipu_crtc *ipu_crtc,
Russell King32266b42013-11-03 12:26:23 +0000350 struct ipu_client_platformdata *pdata, struct drm_device *drm)
Sascha Hauerf326f792012-09-21 10:07:50 +0200351{
Philipp Zabel47b1be52013-02-20 10:57:01 +0800352 struct ipu_soc *ipu = dev_get_drvdata(ipu_crtc->dev->parent);
Philipp Zabelb8d181e2013-10-10 16:18:45 +0200353 int dp = -EINVAL;
Sascha Hauerf326f792012-09-21 10:07:50 +0200354 int ret;
355
356 ret = ipu_get_resources(ipu_crtc, pdata);
357 if (ret) {
358 dev_err(ipu_crtc->dev, "getting resources failed with %d.\n",
359 ret);
360 return ret;
361 }
362
Philipp Zabel43895592015-11-06 11:08:02 +0100363 if (pdata->dp >= 0)
364 dp = IPU_DP_FLOW_SYNC_BG;
365 ipu_crtc->plane[0] = ipu_plane_init(drm, ipu, pdata->dma[0], dp, 0,
366 DRM_PLANE_TYPE_PRIMARY);
Liu Yinga7ed3c22015-11-06 22:42:45 +0800367 if (IS_ERR(ipu_crtc->plane[0])) {
368 ret = PTR_ERR(ipu_crtc->plane[0]);
369 goto err_put_resources;
370 }
Philipp Zabel43895592015-11-06 11:08:02 +0100371
Philipp Zabel655b43c2014-03-05 10:20:52 +0100372 ret = imx_drm_add_crtc(drm, &ipu_crtc->base, &ipu_crtc->imx_crtc,
Philipp Zabel43895592015-11-06 11:08:02 +0100373 &ipu_crtc->plane[0]->base, &ipu_crtc_helper_funcs,
374 ipu_crtc->dev->of_node);
Sascha Hauerf326f792012-09-21 10:07:50 +0200375 if (ret) {
376 dev_err(ipu_crtc->dev, "adding crtc failed with %d.\n", ret);
377 goto err_put_resources;
378 }
379
Philipp Zabelb8d181e2013-10-10 16:18:45 +0200380 ret = ipu_plane_get_resources(ipu_crtc->plane[0]);
381 if (ret) {
382 dev_err(ipu_crtc->dev, "getting plane 0 resources failed with %d.\n",
383 ret);
384 goto err_remove_crtc;
385 }
386
387 /* If this crtc is using the DP, add an overlay plane */
388 if (pdata->dp >= 0 && pdata->dma[1] > 0) {
Philipp Zabel43895592015-11-06 11:08:02 +0100389 ipu_crtc->plane[1] = ipu_plane_init(drm, ipu, pdata->dma[1],
390 IPU_DP_FLOW_SYNC_FG,
391 drm_crtc_mask(&ipu_crtc->base),
392 DRM_PLANE_TYPE_OVERLAY);
Philipp Zabelb8d181e2013-10-10 16:18:45 +0200393 if (IS_ERR(ipu_crtc->plane[1]))
394 ipu_crtc->plane[1] = NULL;
395 }
396
397 ipu_crtc->irq = ipu_plane_irq(ipu_crtc->plane[0]);
Philipp Zabel47b1be52013-02-20 10:57:01 +0800398 ret = devm_request_irq(ipu_crtc->dev, ipu_crtc->irq, ipu_irq_handler, 0,
399 "imx_drm", ipu_crtc);
400 if (ret < 0) {
401 dev_err(ipu_crtc->dev, "irq request failed with %d.\n", ret);
Philipp Zabelb8d181e2013-10-10 16:18:45 +0200402 goto err_put_plane_res;
Philipp Zabel47b1be52013-02-20 10:57:01 +0800403 }
404
Sascha Hauerf326f792012-09-21 10:07:50 +0200405 return 0;
406
Philipp Zabelb8d181e2013-10-10 16:18:45 +0200407err_put_plane_res:
408 ipu_plane_put_resources(ipu_crtc->plane[0]);
409err_remove_crtc:
410 imx_drm_remove_crtc(ipu_crtc->imx_crtc);
Sascha Hauerf326f792012-09-21 10:07:50 +0200411err_put_resources:
412 ipu_put_resources(ipu_crtc);
413
414 return ret;
415}
416
Russell King17b50012013-11-03 11:23:34 +0000417static int ipu_drm_bind(struct device *dev, struct device *master, void *data)
Sascha Hauerf326f792012-09-21 10:07:50 +0200418{
Russell King17b50012013-11-03 11:23:34 +0000419 struct ipu_client_platformdata *pdata = dev->platform_data;
Russell King32266b42013-11-03 12:26:23 +0000420 struct drm_device *drm = data;
Sascha Hauerf326f792012-09-21 10:07:50 +0200421 struct ipu_crtc *ipu_crtc;
422 int ret;
423
Russell King17b50012013-11-03 11:23:34 +0000424 ipu_crtc = devm_kzalloc(dev, sizeof(*ipu_crtc), GFP_KERNEL);
425 if (!ipu_crtc)
426 return -ENOMEM;
427
428 ipu_crtc->dev = dev;
429
Russell King32266b42013-11-03 12:26:23 +0000430 ret = ipu_crtc_init(ipu_crtc, pdata, drm);
Russell King17b50012013-11-03 11:23:34 +0000431 if (ret)
432 return ret;
433
434 dev_set_drvdata(dev, ipu_crtc);
435
436 return 0;
437}
438
439static void ipu_drm_unbind(struct device *dev, struct device *master,
440 void *data)
441{
442 struct ipu_crtc *ipu_crtc = dev_get_drvdata(dev);
443
444 imx_drm_remove_crtc(ipu_crtc->imx_crtc);
445
446 ipu_plane_put_resources(ipu_crtc->plane[0]);
447 ipu_put_resources(ipu_crtc);
448}
449
450static const struct component_ops ipu_crtc_ops = {
451 .bind = ipu_drm_bind,
452 .unbind = ipu_drm_unbind,
453};
454
455static int ipu_drm_probe(struct platform_device *pdev)
456{
Philipp Zabel655b43c2014-03-05 10:20:52 +0100457 struct device *dev = &pdev->dev;
Russell King17b50012013-11-03 11:23:34 +0000458 int ret;
459
Philipp Zabel655b43c2014-03-05 10:20:52 +0100460 if (!dev->platform_data)
Sascha Hauerf326f792012-09-21 10:07:50 +0200461 return -EINVAL;
462
Philipp Zabel655b43c2014-03-05 10:20:52 +0100463 ret = dma_set_coherent_mask(dev, DMA_BIT_MASK(32));
Russell King4cdbb4f2013-06-10 16:56:16 +0100464 if (ret)
465 return ret;
Sascha Hauerf326f792012-09-21 10:07:50 +0200466
Philipp Zabel655b43c2014-03-05 10:20:52 +0100467 return component_add(dev, &ipu_crtc_ops);
Sascha Hauerf326f792012-09-21 10:07:50 +0200468}
469
Bill Pemberton8aa1be42012-11-19 13:26:38 -0500470static int ipu_drm_remove(struct platform_device *pdev)
Sascha Hauerf326f792012-09-21 10:07:50 +0200471{
Russell King17b50012013-11-03 11:23:34 +0000472 component_del(&pdev->dev, &ipu_crtc_ops);
Sascha Hauerf326f792012-09-21 10:07:50 +0200473 return 0;
474}
475
476static struct platform_driver ipu_drm_driver = {
477 .driver = {
478 .name = "imx-ipuv3-crtc",
479 },
480 .probe = ipu_drm_probe,
Bill Pemberton99c28f12012-11-19 13:20:51 -0500481 .remove = ipu_drm_remove,
Sascha Hauerf326f792012-09-21 10:07:50 +0200482};
483module_platform_driver(ipu_drm_driver);
484
485MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
486MODULE_DESCRIPTION(DRIVER_DESC);
487MODULE_LICENSE("GPL");
Fabio Estevamce9c1ce2013-08-18 21:40:06 -0300488MODULE_ALIAS("platform:imx-ipuv3-crtc");