Linux Audio

Check our new training course

Loading...
v6.8
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * (C) COPYRIGHT 2012-2013 ARM Limited. All rights reserved.
  4 *
  5 * Parts of this file were based on sources as follows:
  6 *
  7 * Copyright (c) 2006-2008 Intel Corporation
  8 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
  9 * Copyright (C) 2011 Texas Instruments
 10 */
 11
 12/**
 13 * DOC: ARM PrimeCell PL110 and PL111 CLCD Driver
 14 *
 15 * The PL110/PL111 is a simple LCD controller that can support TFT
 16 * and STN displays. This driver exposes a standard KMS interface
 17 * for them.
 
 
 
 
 
 
 
 18 *
 19 * The driver currently doesn't expose the cursor.  The DRM API for
 20 * cursors requires support for 64x64 ARGB8888 cursor images, while
 21 * the hardware can only support 64x64 monochrome with masking
 22 * cursors.  While one could imagine trying to hack something together
 23 * to look at the ARGB8888 and program reasonable in monochrome, we
 24 * just don't expose the cursor at all instead, and leave cursor
 25 * support to the application software cursor layer.
 26 *
 27 * TODO:
 28 *
 29 * - Fix race between setting plane base address and getting IRQ for
 30 *   vsync firing the pageflip completion.
 31 *
 
 
 
 32 * - Read back hardware state at boot to skip reprogramming the
 33 *   hardware when doing a no-op modeset.
 34 *
 35 * - Use the CLKSEL bit to support switching between the two external
 36 *   clock parents.
 37 */
 38
 39#include <linux/amba/bus.h>
 40#include <linux/dma-buf.h>
 41#include <linux/module.h>
 42#include <linux/of.h>
 43#include <linux/of_graph.h>
 44#include <linux/of_reserved_mem.h>
 45#include <linux/shmem_fs.h>
 46#include <linux/slab.h>
 
 47
 48#include <drm/drm_atomic_helper.h>
 49#include <drm/drm_bridge.h>
 50#include <drm/drm_drv.h>
 51#include <drm/drm_fbdev_dma.h>
 52#include <drm/drm_fourcc.h>
 53#include <drm/drm_gem_dma_helper.h>
 54#include <drm/drm_gem_framebuffer_helper.h>
 55#include <drm/drm_of.h>
 56#include <drm/drm_panel.h>
 57#include <drm/drm_probe_helper.h>
 58#include <drm/drm_vblank.h>
 59
 60#include "pl111_drm.h"
 61#include "pl111_versatile.h"
 62#include "pl111_nomadik.h"
 63
 64#define DRIVER_DESC      "DRM module for PL111"
 65
 66static const struct drm_mode_config_funcs mode_config_funcs = {
 67	.fb_create = drm_gem_fb_create,
 68	.atomic_check = drm_atomic_helper_check,
 69	.atomic_commit = drm_atomic_helper_commit,
 70};
 71
 72static int pl111_modeset_init(struct drm_device *dev)
 73{
 74	struct drm_mode_config *mode_config;
 75	struct pl111_drm_dev_private *priv = dev->dev_private;
 76	struct device_node *np = dev->dev->of_node;
 77	struct device_node *remote;
 78	struct drm_panel *panel = NULL;
 79	struct drm_bridge *bridge = NULL;
 80	bool defer = false;
 81	int ret;
 82	int i;
 83
 84	ret = drmm_mode_config_init(dev);
 85	if (ret)
 86		return ret;
 87
 88	mode_config = &dev->mode_config;
 89	mode_config->funcs = &mode_config_funcs;
 90	mode_config->min_width = 1;
 91	mode_config->max_width = 1024;
 92	mode_config->min_height = 1;
 93	mode_config->max_height = 768;
 94
 95	i = 0;
 96	for_each_endpoint_of_node(np, remote) {
 97		struct drm_panel *tmp_panel;
 98		struct drm_bridge *tmp_bridge;
 99
100		dev_dbg(dev->dev, "checking endpoint %d\n", i);
101
102		ret = drm_of_find_panel_or_bridge(dev->dev->of_node,
103						  0, i,
104						  &tmp_panel,
105						  &tmp_bridge);
106		if (ret) {
107			if (ret == -EPROBE_DEFER) {
108				/*
109				 * Something deferred, but that is often just
110				 * another way of saying -ENODEV, but let's
111				 * cast a vote for later deferral.
112				 */
113				defer = true;
114			} else if (ret != -ENODEV) {
115				/* Continue, maybe something else is working */
116				dev_err(dev->dev,
117					"endpoint %d returns %d\n", i, ret);
118			}
119		}
120
121		if (tmp_panel) {
122			dev_info(dev->dev,
123				 "found panel on endpoint %d\n", i);
124			panel = tmp_panel;
125		}
126		if (tmp_bridge) {
127			dev_info(dev->dev,
128				 "found bridge on endpoint %d\n", i);
129			bridge = tmp_bridge;
130		}
131
132		i++;
133	}
134
135	/*
136	 * If we can't find neither panel nor bridge on any of the
137	 * endpoints, and any of them retured -EPROBE_DEFER, then
138	 * let's defer this driver too.
139	 */
140	if ((!panel && !bridge) && defer)
141		return -EPROBE_DEFER;
142
143	if (panel) {
144		bridge = drm_panel_bridge_add_typed(panel,
145						    DRM_MODE_CONNECTOR_Unknown);
146		if (IS_ERR(bridge)) {
147			ret = PTR_ERR(bridge);
148			goto finish;
149		}
150	} else if (bridge) {
151		dev_info(dev->dev, "Using non-panel bridge\n");
152	} else {
153		dev_err(dev->dev, "No bridge, exiting\n");
154		return -ENODEV;
155	}
156
157	priv->bridge = bridge;
158	if (panel) {
159		priv->panel = panel;
160		priv->connector = drm_panel_bridge_connector(bridge);
161	}
162
163	ret = pl111_display_init(dev);
164	if (ret != 0) {
165		dev_err(dev->dev, "Failed to init display\n");
166		goto out_bridge;
167	}
168
169	ret = drm_simple_display_pipe_attach_bridge(&priv->pipe,
170						    bridge);
171	if (ret)
172		return ret;
173
174	if (!priv->variant->broken_vblank) {
175		ret = drm_vblank_init(dev, 1);
176		if (ret != 0) {
177			dev_err(dev->dev, "Failed to init vblank\n");
178			goto out_bridge;
179		}
180	}
181
182	drm_mode_config_reset(dev);
183
184	drm_kms_helper_poll_init(dev);
185
186	goto finish;
187
188out_bridge:
189	if (panel)
190		drm_panel_bridge_remove(bridge);
191finish:
192	return ret;
193}
194
195static struct drm_gem_object *
196pl111_gem_import_sg_table(struct drm_device *dev,
197			  struct dma_buf_attachment *attach,
198			  struct sg_table *sgt)
199{
200	struct pl111_drm_dev_private *priv = dev->dev_private;
201
202	/*
203	 * When using device-specific reserved memory we can't import
204	 * DMA buffers: those are passed by reference in any global
205	 * memory and we can only handle a specific range of memory.
206	 */
207	if (priv->use_device_memory)
208		return ERR_PTR(-EINVAL);
209
210	return drm_gem_dma_prime_import_sg_table(dev, attach, sgt);
211}
212
213DEFINE_DRM_GEM_DMA_FOPS(drm_fops);
214
215static const struct drm_driver pl111_drm_driver = {
216	.driver_features =
217		DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
218	.ioctls = NULL,
219	.fops = &drm_fops,
220	.name = "pl111",
221	.desc = DRIVER_DESC,
222	.date = "20170317",
223	.major = 1,
224	.minor = 0,
225	.patchlevel = 0,
226	.dumb_create = drm_gem_dma_dumb_create,
 
 
 
 
227	.gem_prime_import_sg_table = pl111_gem_import_sg_table,
 
 
 
228
229#if defined(CONFIG_DEBUG_FS)
230	.debugfs_init = pl111_debugfs_init,
231#endif
232};
233
234static int pl111_amba_probe(struct amba_device *amba_dev,
235			    const struct amba_id *id)
236{
237	struct device *dev = &amba_dev->dev;
238	struct pl111_drm_dev_private *priv;
239	const struct pl111_variant_data *variant = id->data;
240	struct drm_device *drm;
241	int ret;
242
243	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
244	if (!priv)
245		return -ENOMEM;
246
247	drm = drm_dev_alloc(&pl111_drm_driver, dev);
248	if (IS_ERR(drm))
249		return PTR_ERR(drm);
250	amba_set_drvdata(amba_dev, drm);
251	priv->drm = drm;
252	drm->dev_private = priv;
253	priv->variant = variant;
254
255	ret = of_reserved_mem_device_init(dev);
256	if (!ret) {
257		dev_info(dev, "using device-specific reserved memory\n");
258		priv->use_device_memory = true;
259	}
260
261	if (of_property_read_u32(dev->of_node, "max-memory-bandwidth",
262				 &priv->memory_bw)) {
263		dev_info(dev, "no max memory bandwidth specified, assume unlimited\n");
264		priv->memory_bw = 0;
265	}
266
267	/* The two main variants swap this register */
268	if (variant->is_pl110 || variant->is_lcdc) {
269		priv->ienb = CLCD_PL110_IENB;
270		priv->ctrl = CLCD_PL110_CNTL;
271	} else {
272		priv->ienb = CLCD_PL111_IENB;
273		priv->ctrl = CLCD_PL111_CNTL;
274	}
275
276	priv->regs = devm_ioremap_resource(dev, &amba_dev->res);
277	if (IS_ERR(priv->regs)) {
278		dev_err(dev, "%s failed mmio\n", __func__);
279		ret = PTR_ERR(priv->regs);
280		goto dev_put;
281	}
282
283	/* This may override some variant settings */
284	ret = pl111_versatile_init(dev, priv);
285	if (ret)
286		goto dev_put;
287
288	pl111_nomadik_init(dev);
289
290	/* turn off interrupts before requesting the irq */
291	writel(0, priv->regs + priv->ienb);
292
293	ret = devm_request_irq(dev, amba_dev->irq[0], pl111_irq, 0,
294			       variant->name, priv);
295	if (ret != 0) {
296		dev_err(dev, "%s failed irq %d\n", __func__, ret);
297		return ret;
298	}
299
300	ret = pl111_modeset_init(drm);
301	if (ret != 0)
302		goto dev_put;
303
304	ret = drm_dev_register(drm, 0);
305	if (ret < 0)
306		goto dev_put;
307
308	drm_fbdev_dma_setup(drm, priv->variant->fb_depth);
309
310	return 0;
311
312dev_put:
313	drm_dev_put(drm);
314	of_reserved_mem_device_release(dev);
315
316	return ret;
317}
318
319static void pl111_amba_remove(struct amba_device *amba_dev)
320{
321	struct device *dev = &amba_dev->dev;
322	struct drm_device *drm = amba_get_drvdata(amba_dev);
323	struct pl111_drm_dev_private *priv = drm->dev_private;
324
325	drm_dev_unregister(drm);
326	drm_atomic_helper_shutdown(drm);
327	if (priv->panel)
328		drm_panel_bridge_remove(priv->bridge);
329	drm_dev_put(drm);
330	of_reserved_mem_device_release(dev);
331}
332
333static void pl111_amba_shutdown(struct amba_device *amba_dev)
334{
335	drm_atomic_helper_shutdown(amba_get_drvdata(amba_dev));
336}
337
338/*
339 * This early variant lacks the 565 and 444 pixel formats.
340 */
341static const u32 pl110_pixel_formats[] = {
342	DRM_FORMAT_ABGR8888,
343	DRM_FORMAT_XBGR8888,
344	DRM_FORMAT_ARGB8888,
345	DRM_FORMAT_XRGB8888,
346	DRM_FORMAT_ABGR1555,
347	DRM_FORMAT_XBGR1555,
348	DRM_FORMAT_ARGB1555,
349	DRM_FORMAT_XRGB1555,
350};
351
352static const struct pl111_variant_data pl110_variant = {
353	.name = "PL110",
354	.is_pl110 = true,
355	.formats = pl110_pixel_formats,
356	.nformats = ARRAY_SIZE(pl110_pixel_formats),
357	.fb_depth = 16,
358};
359
360/* RealView, Versatile Express etc use this modern variant */
361static const u32 pl111_pixel_formats[] = {
362	DRM_FORMAT_ABGR8888,
363	DRM_FORMAT_XBGR8888,
364	DRM_FORMAT_ARGB8888,
365	DRM_FORMAT_XRGB8888,
366	DRM_FORMAT_BGR565,
367	DRM_FORMAT_RGB565,
368	DRM_FORMAT_ABGR1555,
369	DRM_FORMAT_XBGR1555,
370	DRM_FORMAT_ARGB1555,
371	DRM_FORMAT_XRGB1555,
372	DRM_FORMAT_ABGR4444,
373	DRM_FORMAT_XBGR4444,
374	DRM_FORMAT_ARGB4444,
375	DRM_FORMAT_XRGB4444,
376};
377
378static const struct pl111_variant_data pl111_variant = {
379	.name = "PL111",
380	.formats = pl111_pixel_formats,
381	.nformats = ARRAY_SIZE(pl111_pixel_formats),
382	.fb_depth = 32,
383};
384
385static const u32 pl110_nomadik_pixel_formats[] = {
386	DRM_FORMAT_RGB888,
387	DRM_FORMAT_BGR888,
388	DRM_FORMAT_ABGR8888,
389	DRM_FORMAT_XBGR8888,
390	DRM_FORMAT_ARGB8888,
391	DRM_FORMAT_XRGB8888,
392	DRM_FORMAT_BGR565,
393	DRM_FORMAT_RGB565,
394	DRM_FORMAT_ABGR1555,
395	DRM_FORMAT_XBGR1555,
396	DRM_FORMAT_ARGB1555,
397	DRM_FORMAT_XRGB1555,
398	DRM_FORMAT_ABGR4444,
399	DRM_FORMAT_XBGR4444,
400	DRM_FORMAT_ARGB4444,
401	DRM_FORMAT_XRGB4444,
402};
403
404static const struct pl111_variant_data pl110_nomadik_variant = {
405	.name = "LCDC (PL110 Nomadik)",
406	.formats = pl110_nomadik_pixel_formats,
407	.nformats = ARRAY_SIZE(pl110_nomadik_pixel_formats),
408	.is_lcdc = true,
409	.st_bitmux_control = true,
410	.broken_vblank = true,
411	.fb_depth = 16,
412};
413
414static const struct amba_id pl111_id_table[] = {
415	{
416		.id = 0x00041110,
417		.mask = 0x000fffff,
418		.data = (void *)&pl110_variant,
419	},
420	{
421		.id = 0x00180110,
422		.mask = 0x00fffffe,
423		.data = (void *)&pl110_nomadik_variant,
424	},
425	{
426		.id = 0x00041111,
427		.mask = 0x000fffff,
428		.data = (void *)&pl111_variant,
429	},
430	{0, 0},
431};
432MODULE_DEVICE_TABLE(amba, pl111_id_table);
433
434static struct amba_driver pl111_amba_driver __maybe_unused = {
435	.drv = {
436		.name = "drm-clcd-pl111",
437	},
438	.probe = pl111_amba_probe,
439	.remove = pl111_amba_remove,
440	.shutdown = pl111_amba_shutdown,
441	.id_table = pl111_id_table,
442};
443
444#ifdef CONFIG_ARM_AMBA
445module_amba_driver(pl111_amba_driver);
446#endif
447
448MODULE_DESCRIPTION(DRIVER_DESC);
449MODULE_AUTHOR("ARM Ltd.");
450MODULE_LICENSE("GPL");
v5.9
  1// SPDX-License-Identifier: GPL-2.0-only
  2/*
  3 * (C) COPYRIGHT 2012-2013 ARM Limited. All rights reserved.
  4 *
  5 * Parts of this file were based on sources as follows:
  6 *
  7 * Copyright (c) 2006-2008 Intel Corporation
  8 * Copyright (c) 2007 Dave Airlie <airlied@linux.ie>
  9 * Copyright (C) 2011 Texas Instruments
 10 */
 11
 12/**
 13 * DOC: ARM PrimeCell PL111 CLCD Driver
 14 *
 15 * The PL111 is a simple LCD controller that can support TFT and STN
 16 * displays.  This driver exposes a standard KMS interface for them.
 17 *
 18 * This driver uses the same Device Tree binding as the fbdev CLCD
 19 * driver.  While the fbdev driver supports panels that may be
 20 * connected to the CLCD internally to the CLCD driver, in DRM the
 21 * panels get split out to drivers/gpu/drm/panels/.  This means that,
 22 * in converting from using fbdev to using DRM, you also need to write
 23 * a panel driver (which may be as simple as an entry in
 24 * panel-simple.c).
 25 *
 26 * The driver currently doesn't expose the cursor.  The DRM API for
 27 * cursors requires support for 64x64 ARGB8888 cursor images, while
 28 * the hardware can only support 64x64 monochrome with masking
 29 * cursors.  While one could imagine trying to hack something together
 30 * to look at the ARGB8888 and program reasonable in monochrome, we
 31 * just don't expose the cursor at all instead, and leave cursor
 32 * support to the X11 software cursor layer.
 33 *
 34 * TODO:
 35 *
 36 * - Fix race between setting plane base address and getting IRQ for
 37 *   vsync firing the pageflip completion.
 38 *
 39 * - Use the "max-memory-bandwidth" DT property to filter the
 40 *   supported formats.
 41 *
 42 * - Read back hardware state at boot to skip reprogramming the
 43 *   hardware when doing a no-op modeset.
 44 *
 45 * - Use the CLKSEL bit to support switching between the two external
 46 *   clock parents.
 47 */
 48
 49#include <linux/amba/bus.h>
 50#include <linux/dma-buf.h>
 51#include <linux/module.h>
 52#include <linux/of.h>
 53#include <linux/of_graph.h>
 54#include <linux/of_reserved_mem.h>
 55#include <linux/shmem_fs.h>
 56#include <linux/slab.h>
 57#include <linux/version.h>
 58
 59#include <drm/drm_atomic_helper.h>
 60#include <drm/drm_bridge.h>
 61#include <drm/drm_drv.h>
 62#include <drm/drm_fb_cma_helper.h>
 63#include <drm/drm_fb_helper.h>
 64#include <drm/drm_gem_cma_helper.h>
 65#include <drm/drm_gem_framebuffer_helper.h>
 66#include <drm/drm_of.h>
 67#include <drm/drm_panel.h>
 68#include <drm/drm_probe_helper.h>
 69#include <drm/drm_vblank.h>
 70
 71#include "pl111_drm.h"
 72#include "pl111_versatile.h"
 73#include "pl111_nomadik.h"
 74
 75#define DRIVER_DESC      "DRM module for PL111"
 76
 77static const struct drm_mode_config_funcs mode_config_funcs = {
 78	.fb_create = drm_gem_fb_create,
 79	.atomic_check = drm_atomic_helper_check,
 80	.atomic_commit = drm_atomic_helper_commit,
 81};
 82
 83static int pl111_modeset_init(struct drm_device *dev)
 84{
 85	struct drm_mode_config *mode_config;
 86	struct pl111_drm_dev_private *priv = dev->dev_private;
 87	struct device_node *np = dev->dev->of_node;
 88	struct device_node *remote;
 89	struct drm_panel *panel = NULL;
 90	struct drm_bridge *bridge = NULL;
 91	bool defer = false;
 92	int ret;
 93	int i;
 94
 95	ret = drmm_mode_config_init(dev);
 96	if (ret)
 97		return ret;
 98
 99	mode_config = &dev->mode_config;
100	mode_config->funcs = &mode_config_funcs;
101	mode_config->min_width = 1;
102	mode_config->max_width = 1024;
103	mode_config->min_height = 1;
104	mode_config->max_height = 768;
105
106	i = 0;
107	for_each_endpoint_of_node(np, remote) {
108		struct drm_panel *tmp_panel;
109		struct drm_bridge *tmp_bridge;
110
111		dev_dbg(dev->dev, "checking endpoint %d\n", i);
112
113		ret = drm_of_find_panel_or_bridge(dev->dev->of_node,
114						  0, i,
115						  &tmp_panel,
116						  &tmp_bridge);
117		if (ret) {
118			if (ret == -EPROBE_DEFER) {
119				/*
120				 * Something deferred, but that is often just
121				 * another way of saying -ENODEV, but let's
122				 * cast a vote for later deferral.
123				 */
124				defer = true;
125			} else if (ret != -ENODEV) {
126				/* Continue, maybe something else is working */
127				dev_err(dev->dev,
128					"endpoint %d returns %d\n", i, ret);
129			}
130		}
131
132		if (tmp_panel) {
133			dev_info(dev->dev,
134				 "found panel on endpoint %d\n", i);
135			panel = tmp_panel;
136		}
137		if (tmp_bridge) {
138			dev_info(dev->dev,
139				 "found bridge on endpoint %d\n", i);
140			bridge = tmp_bridge;
141		}
142
143		i++;
144	}
145
146	/*
147	 * If we can't find neither panel nor bridge on any of the
148	 * endpoints, and any of them retured -EPROBE_DEFER, then
149	 * let's defer this driver too.
150	 */
151	if ((!panel && !bridge) && defer)
152		return -EPROBE_DEFER;
153
154	if (panel) {
155		bridge = drm_panel_bridge_add_typed(panel,
156						    DRM_MODE_CONNECTOR_Unknown);
157		if (IS_ERR(bridge)) {
158			ret = PTR_ERR(bridge);
159			goto finish;
160		}
161	} else if (bridge) {
162		dev_info(dev->dev, "Using non-panel bridge\n");
163	} else {
164		dev_err(dev->dev, "No bridge, exiting\n");
165		return -ENODEV;
166	}
167
168	priv->bridge = bridge;
169	if (panel) {
170		priv->panel = panel;
171		priv->connector = drm_panel_bridge_connector(bridge);
172	}
173
174	ret = pl111_display_init(dev);
175	if (ret != 0) {
176		dev_err(dev->dev, "Failed to init display\n");
177		goto out_bridge;
178	}
179
180	ret = drm_simple_display_pipe_attach_bridge(&priv->pipe,
181						    bridge);
182	if (ret)
183		return ret;
184
185	if (!priv->variant->broken_vblank) {
186		ret = drm_vblank_init(dev, 1);
187		if (ret != 0) {
188			dev_err(dev->dev, "Failed to init vblank\n");
189			goto out_bridge;
190		}
191	}
192
193	drm_mode_config_reset(dev);
194
195	drm_kms_helper_poll_init(dev);
196
197	goto finish;
198
199out_bridge:
200	if (panel)
201		drm_panel_bridge_remove(bridge);
202finish:
203	return ret;
204}
205
206static struct drm_gem_object *
207pl111_gem_import_sg_table(struct drm_device *dev,
208			  struct dma_buf_attachment *attach,
209			  struct sg_table *sgt)
210{
211	struct pl111_drm_dev_private *priv = dev->dev_private;
212
213	/*
214	 * When using device-specific reserved memory we can't import
215	 * DMA buffers: those are passed by reference in any global
216	 * memory and we can only handle a specific range of memory.
217	 */
218	if (priv->use_device_memory)
219		return ERR_PTR(-EINVAL);
220
221	return drm_gem_cma_prime_import_sg_table(dev, attach, sgt);
222}
223
224DEFINE_DRM_GEM_CMA_FOPS(drm_fops);
225
226static struct drm_driver pl111_drm_driver = {
227	.driver_features =
228		DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
229	.ioctls = NULL,
230	.fops = &drm_fops,
231	.name = "pl111",
232	.desc = DRIVER_DESC,
233	.date = "20170317",
234	.major = 1,
235	.minor = 0,
236	.patchlevel = 0,
237	.dumb_create = drm_gem_cma_dumb_create,
238	.gem_free_object_unlocked = drm_gem_cma_free_object,
239	.gem_vm_ops = &drm_gem_cma_vm_ops,
240	.prime_handle_to_fd = drm_gem_prime_handle_to_fd,
241	.prime_fd_to_handle = drm_gem_prime_fd_to_handle,
242	.gem_prime_import_sg_table = pl111_gem_import_sg_table,
243	.gem_prime_get_sg_table	= drm_gem_cma_prime_get_sg_table,
244	.gem_prime_mmap = drm_gem_cma_prime_mmap,
245	.gem_prime_vmap = drm_gem_cma_prime_vmap,
246
247#if defined(CONFIG_DEBUG_FS)
248	.debugfs_init = pl111_debugfs_init,
249#endif
250};
251
252static int pl111_amba_probe(struct amba_device *amba_dev,
253			    const struct amba_id *id)
254{
255	struct device *dev = &amba_dev->dev;
256	struct pl111_drm_dev_private *priv;
257	const struct pl111_variant_data *variant = id->data;
258	struct drm_device *drm;
259	int ret;
260
261	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
262	if (!priv)
263		return -ENOMEM;
264
265	drm = drm_dev_alloc(&pl111_drm_driver, dev);
266	if (IS_ERR(drm))
267		return PTR_ERR(drm);
268	amba_set_drvdata(amba_dev, drm);
269	priv->drm = drm;
270	drm->dev_private = priv;
271	priv->variant = variant;
272
273	ret = of_reserved_mem_device_init(dev);
274	if (!ret) {
275		dev_info(dev, "using device-specific reserved memory\n");
276		priv->use_device_memory = true;
277	}
278
279	if (of_property_read_u32(dev->of_node, "max-memory-bandwidth",
280				 &priv->memory_bw)) {
281		dev_info(dev, "no max memory bandwidth specified, assume unlimited\n");
282		priv->memory_bw = 0;
283	}
284
285	/* The two main variants swap this register */
286	if (variant->is_pl110 || variant->is_lcdc) {
287		priv->ienb = CLCD_PL110_IENB;
288		priv->ctrl = CLCD_PL110_CNTL;
289	} else {
290		priv->ienb = CLCD_PL111_IENB;
291		priv->ctrl = CLCD_PL111_CNTL;
292	}
293
294	priv->regs = devm_ioremap_resource(dev, &amba_dev->res);
295	if (IS_ERR(priv->regs)) {
296		dev_err(dev, "%s failed mmio\n", __func__);
297		ret = PTR_ERR(priv->regs);
298		goto dev_put;
299	}
300
301	/* This may override some variant settings */
302	ret = pl111_versatile_init(dev, priv);
303	if (ret)
304		goto dev_put;
305
306	pl111_nomadik_init(dev);
307
308	/* turn off interrupts before requesting the irq */
309	writel(0, priv->regs + priv->ienb);
310
311	ret = devm_request_irq(dev, amba_dev->irq[0], pl111_irq, 0,
312			       variant->name, priv);
313	if (ret != 0) {
314		dev_err(dev, "%s failed irq %d\n", __func__, ret);
315		return ret;
316	}
317
318	ret = pl111_modeset_init(drm);
319	if (ret != 0)
320		goto dev_put;
321
322	ret = drm_dev_register(drm, 0);
323	if (ret < 0)
324		goto dev_put;
325
326	drm_fbdev_generic_setup(drm, priv->variant->fb_bpp);
327
328	return 0;
329
330dev_put:
331	drm_dev_put(drm);
332	of_reserved_mem_device_release(dev);
333
334	return ret;
335}
336
337static int pl111_amba_remove(struct amba_device *amba_dev)
338{
339	struct device *dev = &amba_dev->dev;
340	struct drm_device *drm = amba_get_drvdata(amba_dev);
341	struct pl111_drm_dev_private *priv = drm->dev_private;
342
343	drm_dev_unregister(drm);
 
344	if (priv->panel)
345		drm_panel_bridge_remove(priv->bridge);
346	drm_dev_put(drm);
347	of_reserved_mem_device_release(dev);
 
348
349	return 0;
 
 
350}
351
352/*
353 * This early variant lacks the 565 and 444 pixel formats.
354 */
355static const u32 pl110_pixel_formats[] = {
356	DRM_FORMAT_ABGR8888,
357	DRM_FORMAT_XBGR8888,
358	DRM_FORMAT_ARGB8888,
359	DRM_FORMAT_XRGB8888,
360	DRM_FORMAT_ABGR1555,
361	DRM_FORMAT_XBGR1555,
362	DRM_FORMAT_ARGB1555,
363	DRM_FORMAT_XRGB1555,
364};
365
366static const struct pl111_variant_data pl110_variant = {
367	.name = "PL110",
368	.is_pl110 = true,
369	.formats = pl110_pixel_formats,
370	.nformats = ARRAY_SIZE(pl110_pixel_formats),
371	.fb_bpp = 16,
372};
373
374/* RealView, Versatile Express etc use this modern variant */
375static const u32 pl111_pixel_formats[] = {
376	DRM_FORMAT_ABGR8888,
377	DRM_FORMAT_XBGR8888,
378	DRM_FORMAT_ARGB8888,
379	DRM_FORMAT_XRGB8888,
380	DRM_FORMAT_BGR565,
381	DRM_FORMAT_RGB565,
382	DRM_FORMAT_ABGR1555,
383	DRM_FORMAT_XBGR1555,
384	DRM_FORMAT_ARGB1555,
385	DRM_FORMAT_XRGB1555,
386	DRM_FORMAT_ABGR4444,
387	DRM_FORMAT_XBGR4444,
388	DRM_FORMAT_ARGB4444,
389	DRM_FORMAT_XRGB4444,
390};
391
392static const struct pl111_variant_data pl111_variant = {
393	.name = "PL111",
394	.formats = pl111_pixel_formats,
395	.nformats = ARRAY_SIZE(pl111_pixel_formats),
396	.fb_bpp = 32,
397};
398
399static const u32 pl110_nomadik_pixel_formats[] = {
400	DRM_FORMAT_RGB888,
401	DRM_FORMAT_BGR888,
402	DRM_FORMAT_ABGR8888,
403	DRM_FORMAT_XBGR8888,
404	DRM_FORMAT_ARGB8888,
405	DRM_FORMAT_XRGB8888,
406	DRM_FORMAT_BGR565,
407	DRM_FORMAT_RGB565,
408	DRM_FORMAT_ABGR1555,
409	DRM_FORMAT_XBGR1555,
410	DRM_FORMAT_ARGB1555,
411	DRM_FORMAT_XRGB1555,
412	DRM_FORMAT_ABGR4444,
413	DRM_FORMAT_XBGR4444,
414	DRM_FORMAT_ARGB4444,
415	DRM_FORMAT_XRGB4444,
416};
417
418static const struct pl111_variant_data pl110_nomadik_variant = {
419	.name = "LCDC (PL110 Nomadik)",
420	.formats = pl110_nomadik_pixel_formats,
421	.nformats = ARRAY_SIZE(pl110_nomadik_pixel_formats),
422	.is_lcdc = true,
423	.st_bitmux_control = true,
424	.broken_vblank = true,
425	.fb_bpp = 16,
426};
427
428static const struct amba_id pl111_id_table[] = {
429	{
430		.id = 0x00041110,
431		.mask = 0x000fffff,
432		.data = (void *)&pl110_variant,
433	},
434	{
435		.id = 0x00180110,
436		.mask = 0x00fffffe,
437		.data = (void *)&pl110_nomadik_variant,
438	},
439	{
440		.id = 0x00041111,
441		.mask = 0x000fffff,
442		.data = (void *)&pl111_variant,
443	},
444	{0, 0},
445};
446MODULE_DEVICE_TABLE(amba, pl111_id_table);
447
448static struct amba_driver pl111_amba_driver __maybe_unused = {
449	.drv = {
450		.name = "drm-clcd-pl111",
451	},
452	.probe = pl111_amba_probe,
453	.remove = pl111_amba_remove,
 
454	.id_table = pl111_id_table,
455};
456
457#ifdef CONFIG_ARM_AMBA
458module_amba_driver(pl111_amba_driver);
459#endif
460
461MODULE_DESCRIPTION(DRIVER_DESC);
462MODULE_AUTHOR("ARM Ltd.");
463MODULE_LICENSE("GPL");