2 * (C) COPYRIGHT 2012-2013 ARM Limited. All rights reserved.
4 * Parts of this file were based on sources as follows:
6 * Copyright (c) 2006-2008 Intel Corporation
7 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
8 * Copyright (C) 2011 Texas Instruments
10 * This program is free software and is provided to you under the terms of the
11 * GNU General Public License version 2 as published by the Free Software
12 * Foundation, and any use by you of this program is subject to the terms of
18 * DOC: ARM PrimeCell PL111 CLCD Driver
20 * The PL111 is a simple LCD controller that can support TFT and STN
21 * displays. This driver exposes a standard KMS interface for them.
23 * This driver uses the same Device Tree binding as the fbdev CLCD
24 * driver. While the fbdev driver supports panels that may be
25 * connected to the CLCD internally to the CLCD driver, in DRM the
26 * panels get split out to drivers/gpu/drm/panels/. This means that,
27 * in converting from using fbdev to using DRM, you also need to write
28 * a panel driver (which may be as simple as an entry in
31 * The driver currently doesn't expose the cursor. The DRM API for
32 * cursors requires support for 64x64 ARGB8888 cursor images, while
33 * the hardware can only support 64x64 monochrome with masking
34 * cursors. While one could imagine trying to hack something together
35 * to look at the ARGB8888 and program reasonable in monochrome, we
36 * just don't expose the cursor at all instead, and leave cursor
37 * support to the X11 software cursor layer.
41 * - Fix race between setting plane base address and getting IRQ for
42 * vsync firing the pageflip completion.
44 * - Expose the correct set of formats we can support based on the
45 * "arm,pl11x,tft-r0g0b0-pads" DT property.
47 * - Use the "max-memory-bandwidth" DT property to filter the
50 * - Read back hardware state at boot to skip reprogramming the
51 * hardware when doing a no-op modeset.
53 * - Use the CLKSEL bit to support switching between the two external
57 #include <linux/amba/bus.h>
58 #include <linux/amba/clcd-regs.h>
59 #include <linux/version.h>
60 #include <linux/shmem_fs.h>
61 #include <linux/dma-buf.h>
62 #include <linux/module.h>
63 #include <linux/slab.h>
66 #include <drm/drm_atomic_helper.h>
67 #include <drm/drm_crtc_helper.h>
68 #include <drm/drm_gem_cma_helper.h>
69 #include <drm/drm_gem_framebuffer_helper.h>
70 #include <drm/drm_fb_cma_helper.h>
72 #include "pl111_drm.h"
74 #define DRIVER_DESC "DRM module for PL111"
76 static const struct drm_mode_config_funcs mode_config_funcs = {
77 .fb_create = drm_gem_fb_create,
78 .atomic_check = drm_atomic_helper_check,
79 .atomic_commit = drm_atomic_helper_commit,
82 static int pl111_modeset_init(struct drm_device *dev)
84 struct drm_mode_config *mode_config;
85 struct pl111_drm_dev_private *priv = dev->dev_private;
88 drm_mode_config_init(dev);
89 mode_config = &dev->mode_config;
90 mode_config->funcs = &mode_config_funcs;
91 mode_config->min_width = 1;
92 mode_config->max_width = 1024;
93 mode_config->min_height = 1;
94 mode_config->max_height = 768;
96 ret = pl111_connector_init(dev);
98 dev_err(dev->dev, "Failed to create pl111_drm_connector\n");
102 /* Don't actually attach if we didn't find a drm_panel
103 * attached to us. This will allow a kernel to include both
104 * the fbdev pl111 driver and this one, and choose between
105 * them based on which subsystem has support for the panel.
107 if (!priv->connector.panel) {
109 "Disabling due to lack of DRM panel device.\n");
114 ret = pl111_display_init(dev);
116 dev_err(dev->dev, "Failed to init display\n");
120 ret = drm_vblank_init(dev, 1);
122 dev_err(dev->dev, "Failed to init vblank\n");
126 drm_mode_config_reset(dev);
128 priv->fbdev = drm_fbdev_cma_init(dev, 32,
129 dev->mode_config.num_connector);
131 drm_kms_helper_poll_init(dev);
136 drm_mode_config_cleanup(dev);
141 DEFINE_DRM_GEM_CMA_FOPS(drm_fops);
143 static void pl111_lastclose(struct drm_device *dev)
145 struct pl111_drm_dev_private *priv = dev->dev_private;
147 drm_fbdev_cma_restore_mode(priv->fbdev);
150 static struct drm_driver pl111_drm_driver = {
152 DRIVER_MODESET | DRIVER_GEM | DRIVER_PRIME | DRIVER_ATOMIC,
153 .lastclose = pl111_lastclose,
162 .dumb_create = drm_gem_cma_dumb_create,
163 .gem_free_object_unlocked = drm_gem_cma_free_object,
164 .gem_vm_ops = &drm_gem_cma_vm_ops,
166 .enable_vblank = pl111_enable_vblank,
167 .disable_vblank = pl111_disable_vblank,
169 .prime_handle_to_fd = drm_gem_prime_handle_to_fd,
170 .prime_fd_to_handle = drm_gem_prime_fd_to_handle,
171 .gem_prime_import = drm_gem_prime_import,
172 .gem_prime_import_sg_table = drm_gem_cma_prime_import_sg_table,
173 .gem_prime_export = drm_gem_prime_export,
174 .gem_prime_get_sg_table = drm_gem_cma_prime_get_sg_table,
176 #if defined(CONFIG_DEBUG_FS)
177 .debugfs_init = pl111_debugfs_init,
181 static int pl111_amba_probe(struct amba_device *amba_dev,
182 const struct amba_id *id)
184 struct device *dev = &amba_dev->dev;
185 struct pl111_drm_dev_private *priv;
186 struct drm_device *drm;
189 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
193 drm = drm_dev_alloc(&pl111_drm_driver, dev);
196 amba_set_drvdata(amba_dev, drm);
198 drm->dev_private = priv;
200 priv->regs = devm_ioremap_resource(dev, &amba_dev->res);
201 if (IS_ERR(priv->regs)) {
202 dev_err(dev, "%s failed mmio\n", __func__);
203 return PTR_ERR(priv->regs);
206 /* turn off interrupts before requesting the irq */
207 writel(0, priv->regs + CLCD_PL111_IENB);
209 ret = devm_request_irq(dev, amba_dev->irq[0], pl111_irq, 0,
212 dev_err(dev, "%s failed irq %d\n", __func__, ret);
216 ret = pl111_modeset_init(drm);
220 ret = drm_dev_register(drm, 0);
231 static int pl111_amba_remove(struct amba_device *amba_dev)
233 struct drm_device *drm = amba_get_drvdata(amba_dev);
234 struct pl111_drm_dev_private *priv = drm->dev_private;
236 drm_dev_unregister(drm);
238 drm_fbdev_cma_fini(priv->fbdev);
239 drm_mode_config_cleanup(drm);
245 static struct amba_id pl111_id_table[] = {
253 static struct amba_driver pl111_amba_driver __maybe_unused = {
255 .name = "drm-clcd-pl111",
257 .probe = pl111_amba_probe,
258 .remove = pl111_amba_remove,
259 .id_table = pl111_id_table,
262 #ifdef CONFIG_ARM_AMBA
263 module_amba_driver(pl111_amba_driver);
266 MODULE_DESCRIPTION(DRIVER_DESC);
267 MODULE_AUTHOR("ARM Ltd.");
268 MODULE_LICENSE("GPL");