Linux Audio

Check our new training course

Loading...
v6.13.7
  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_client_setup.h>
 51#include <drm/drm_drv.h>
 52#include <drm/drm_fbdev_dma.h>
 53#include <drm/drm_fourcc.h>
 54#include <drm/drm_gem_dma_helper.h>
 55#include <drm/drm_gem_framebuffer_helper.h>
 56#include <drm/drm_of.h>
 57#include <drm/drm_panel.h>
 58#include <drm/drm_probe_helper.h>
 59#include <drm/drm_vblank.h>
 60
 61#include "pl111_drm.h"
 62#include "pl111_versatile.h"
 63#include "pl111_nomadik.h"
 64
 65#define DRIVER_DESC      "DRM module for PL111"
 66
 67static const struct drm_mode_config_funcs mode_config_funcs = {
 68	.fb_create = drm_gem_fb_create,
 69	.atomic_check = drm_atomic_helper_check,
 70	.atomic_commit = drm_atomic_helper_commit,
 71};
 72
 73static int pl111_modeset_init(struct drm_device *dev)
 74{
 75	struct drm_mode_config *mode_config;
 76	struct pl111_drm_dev_private *priv = dev->dev_private;
 77	struct device_node *np = dev->dev->of_node;
 78	struct device_node *remote;
 79	struct drm_panel *panel = NULL;
 80	struct drm_bridge *bridge = NULL;
 81	bool defer = false;
 82	int ret;
 83	int i;
 84
 85	ret = drmm_mode_config_init(dev);
 86	if (ret)
 87		return ret;
 88
 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;
 95
 96	i = 0;
 97	for_each_endpoint_of_node(np, remote) {
 98		struct drm_panel *tmp_panel;
 99		struct drm_bridge *tmp_bridge;
100
101		dev_dbg(dev->dev, "checking endpoint %d\n", i);
102
103		ret = drm_of_find_panel_or_bridge(dev->dev->of_node,
104						  0, i,
105						  &tmp_panel,
106						  &tmp_bridge);
107		if (ret) {
108			if (ret == -EPROBE_DEFER) {
109				/*
110				 * Something deferred, but that is often just
111				 * another way of saying -ENODEV, but let's
112				 * cast a vote for later deferral.
113				 */
114				defer = true;
115			} else if (ret != -ENODEV) {
116				/* Continue, maybe something else is working */
117				dev_err(dev->dev,
118					"endpoint %d returns %d\n", i, ret);
119			}
120		}
121
122		if (tmp_panel) {
123			dev_info(dev->dev,
124				 "found panel on endpoint %d\n", i);
125			panel = tmp_panel;
126		}
127		if (tmp_bridge) {
128			dev_info(dev->dev,
129				 "found bridge on endpoint %d\n", i);
130			bridge = tmp_bridge;
131		}
132
133		i++;
134	}
135
136	/*
137	 * If we can't find neither panel nor bridge on any of the
138	 * endpoints, and any of them retured -EPROBE_DEFER, then
139	 * let's defer this driver too.
140	 */
141	if ((!panel && !bridge) && defer)
142		return -EPROBE_DEFER;
143
144	if (panel) {
145		bridge = drm_panel_bridge_add_typed(panel,
146						    DRM_MODE_CONNECTOR_Unknown);
147		if (IS_ERR(bridge)) {
148			ret = PTR_ERR(bridge);
149			goto finish;
150		}
151	} else if (bridge) {
152		dev_info(dev->dev, "Using non-panel bridge\n");
153	} else {
154		dev_err(dev->dev, "No bridge, exiting\n");
155		return -ENODEV;
156	}
157
158	priv->bridge = bridge;
159	if (panel) {
160		priv->panel = panel;
161		priv->connector = drm_panel_bridge_connector(bridge);
162	}
163
164	ret = pl111_display_init(dev);
165	if (ret != 0) {
166		dev_err(dev->dev, "Failed to init display\n");
167		goto out_bridge;
168	}
169
170	ret = drm_simple_display_pipe_attach_bridge(&priv->pipe,
171						    bridge);
172	if (ret)
173		return ret;
174
175	if (!priv->variant->broken_vblank) {
176		ret = drm_vblank_init(dev, 1);
177		if (ret != 0) {
178			dev_err(dev->dev, "Failed to init vblank\n");
179			goto out_bridge;
180		}
181	}
182
183	drm_mode_config_reset(dev);
184
185	drm_kms_helper_poll_init(dev);
186
187	goto finish;
188
189out_bridge:
190	if (panel)
191		drm_panel_bridge_remove(bridge);
 
 
192finish:
193	return ret;
194}
195
196static struct drm_gem_object *
197pl111_gem_import_sg_table(struct drm_device *dev,
198			  struct dma_buf_attachment *attach,
199			  struct sg_table *sgt)
200{
201	struct pl111_drm_dev_private *priv = dev->dev_private;
202
203	/*
204	 * When using device-specific reserved memory we can't import
205	 * DMA buffers: those are passed by reference in any global
206	 * memory and we can only handle a specific range of memory.
207	 */
208	if (priv->use_device_memory)
209		return ERR_PTR(-EINVAL);
210
211	return drm_gem_dma_prime_import_sg_table(dev, attach, sgt);
212}
213
214DEFINE_DRM_GEM_DMA_FOPS(drm_fops);
215
216static const struct drm_driver pl111_drm_driver = {
217	.driver_features =
218		DRIVER_MODESET | DRIVER_GEM | DRIVER_ATOMIC,
219	.ioctls = NULL,
220	.fops = &drm_fops,
221	.name = "pl111",
222	.desc = DRIVER_DESC,
223	.date = "20170317",
224	.major = 1,
225	.minor = 0,
226	.patchlevel = 0,
227	.dumb_create = drm_gem_dma_dumb_create,
 
 
 
 
228	.gem_prime_import_sg_table = pl111_gem_import_sg_table,
229	DRM_FBDEV_DMA_DRIVER_OPS,
 
 
230
231#if defined(CONFIG_DEBUG_FS)
232	.debugfs_init = pl111_debugfs_init,
233#endif
234};
235
236static int pl111_amba_probe(struct amba_device *amba_dev,
237			    const struct amba_id *id)
238{
239	struct device *dev = &amba_dev->dev;
240	struct pl111_drm_dev_private *priv;
241	const struct pl111_variant_data *variant = id->data;
242	struct drm_device *drm;
243	int ret;
244
245	priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
246	if (!priv)
247		return -ENOMEM;
248
249	drm = drm_dev_alloc(&pl111_drm_driver, dev);
250	if (IS_ERR(drm))
251		return PTR_ERR(drm);
252	amba_set_drvdata(amba_dev, drm);
253	priv->drm = drm;
254	drm->dev_private = priv;
255	priv->variant = variant;
256
257	ret = of_reserved_mem_device_init(dev);
258	if (!ret) {
259		dev_info(dev, "using device-specific reserved memory\n");
260		priv->use_device_memory = true;
261	}
262
263	if (of_property_read_u32(dev->of_node, "max-memory-bandwidth",
264				 &priv->memory_bw)) {
265		dev_info(dev, "no max memory bandwidth specified, assume unlimited\n");
266		priv->memory_bw = 0;
267	}
268
269	/* The two main variants swap this register */
270	if (variant->is_pl110 || variant->is_lcdc) {
271		priv->ienb = CLCD_PL110_IENB;
272		priv->ctrl = CLCD_PL110_CNTL;
273	} else {
274		priv->ienb = CLCD_PL111_IENB;
275		priv->ctrl = CLCD_PL111_CNTL;
276	}
277
278	priv->regs = devm_ioremap_resource(dev, &amba_dev->res);
279	if (IS_ERR(priv->regs)) {
280		dev_err(dev, "%s failed mmio\n", __func__);
281		ret = PTR_ERR(priv->regs);
282		goto dev_put;
283	}
284
285	/* This may override some variant settings */
286	ret = pl111_versatile_init(dev, priv);
287	if (ret)
288		goto dev_put;
289
290	pl111_nomadik_init(dev);
291
292	/* turn off interrupts before requesting the irq */
293	writel(0, priv->regs + priv->ienb);
294
295	ret = devm_request_irq(dev, amba_dev->irq[0], pl111_irq, 0,
296			       variant->name, priv);
297	if (ret != 0) {
298		dev_err(dev, "%s failed irq %d\n", __func__, ret);
299		return ret;
300	}
301
302	ret = pl111_modeset_init(drm);
303	if (ret != 0)
304		goto dev_put;
305
306	ret = drm_dev_register(drm, 0);
307	if (ret < 0)
308		goto dev_put;
309
310	drm_client_setup_with_color_mode(drm, priv->variant->fb_depth);
311
312	return 0;
313
314dev_put:
315	drm_dev_put(drm);
316	of_reserved_mem_device_release(dev);
317
318	return ret;
319}
320
321static void pl111_amba_remove(struct amba_device *amba_dev)
322{
323	struct device *dev = &amba_dev->dev;
324	struct drm_device *drm = amba_get_drvdata(amba_dev);
325	struct pl111_drm_dev_private *priv = drm->dev_private;
326
327	drm_dev_unregister(drm);
328	drm_atomic_helper_shutdown(drm);
329	if (priv->panel)
330		drm_panel_bridge_remove(priv->bridge);
 
331	drm_dev_put(drm);
332	of_reserved_mem_device_release(dev);
333}
334
335static void pl111_amba_shutdown(struct amba_device *amba_dev)
336{
337	drm_atomic_helper_shutdown(amba_get_drvdata(amba_dev));
338}
339
340/*
341 * This early variant lacks the 565 and 444 pixel formats.
342 */
343static const u32 pl110_pixel_formats[] = {
344	DRM_FORMAT_ABGR8888,
345	DRM_FORMAT_XBGR8888,
346	DRM_FORMAT_ARGB8888,
347	DRM_FORMAT_XRGB8888,
348	DRM_FORMAT_ABGR1555,
349	DRM_FORMAT_XBGR1555,
350	DRM_FORMAT_ARGB1555,
351	DRM_FORMAT_XRGB1555,
352};
353
354static const struct pl111_variant_data pl110_variant = {
355	.name = "PL110",
356	.is_pl110 = true,
357	.formats = pl110_pixel_formats,
358	.nformats = ARRAY_SIZE(pl110_pixel_formats),
359	.fb_depth = 16,
360};
361
362/* RealView, Versatile Express etc use this modern variant */
363static const u32 pl111_pixel_formats[] = {
364	DRM_FORMAT_ABGR8888,
365	DRM_FORMAT_XBGR8888,
366	DRM_FORMAT_ARGB8888,
367	DRM_FORMAT_XRGB8888,
368	DRM_FORMAT_BGR565,
369	DRM_FORMAT_RGB565,
370	DRM_FORMAT_ABGR1555,
371	DRM_FORMAT_XBGR1555,
372	DRM_FORMAT_ARGB1555,
373	DRM_FORMAT_XRGB1555,
374	DRM_FORMAT_ABGR4444,
375	DRM_FORMAT_XBGR4444,
376	DRM_FORMAT_ARGB4444,
377	DRM_FORMAT_XRGB4444,
378};
379
380static const struct pl111_variant_data pl111_variant = {
381	.name = "PL111",
382	.formats = pl111_pixel_formats,
383	.nformats = ARRAY_SIZE(pl111_pixel_formats),
384	.fb_depth = 32,
385};
386
387static const u32 pl110_nomadik_pixel_formats[] = {
388	DRM_FORMAT_RGB888,
389	DRM_FORMAT_BGR888,
390	DRM_FORMAT_ABGR8888,
391	DRM_FORMAT_XBGR8888,
392	DRM_FORMAT_ARGB8888,
393	DRM_FORMAT_XRGB8888,
394	DRM_FORMAT_BGR565,
395	DRM_FORMAT_RGB565,
396	DRM_FORMAT_ABGR1555,
397	DRM_FORMAT_XBGR1555,
398	DRM_FORMAT_ARGB1555,
399	DRM_FORMAT_XRGB1555,
400	DRM_FORMAT_ABGR4444,
401	DRM_FORMAT_XBGR4444,
402	DRM_FORMAT_ARGB4444,
403	DRM_FORMAT_XRGB4444,
404};
405
406static const struct pl111_variant_data pl110_nomadik_variant = {
407	.name = "LCDC (PL110 Nomadik)",
408	.formats = pl110_nomadik_pixel_formats,
409	.nformats = ARRAY_SIZE(pl110_nomadik_pixel_formats),
410	.is_lcdc = true,
411	.st_bitmux_control = true,
412	.broken_vblank = true,
413	.fb_depth = 16,
414};
415
416static const struct amba_id pl111_id_table[] = {
417	{
418		.id = 0x00041110,
419		.mask = 0x000fffff,
420		.data = (void *)&pl110_variant,
421	},
422	{
423		.id = 0x00180110,
424		.mask = 0x00fffffe,
425		.data = (void *)&pl110_nomadik_variant,
426	},
427	{
428		.id = 0x00041111,
429		.mask = 0x000fffff,
430		.data = (void *)&pl111_variant,
431	},
432	{0, 0},
433};
434MODULE_DEVICE_TABLE(amba, pl111_id_table);
435
436static struct amba_driver pl111_amba_driver __maybe_unused = {
437	.drv = {
438		.name = "drm-clcd-pl111",
439	},
440	.probe = pl111_amba_probe,
441	.remove = pl111_amba_remove,
442	.shutdown = pl111_amba_shutdown,
443	.id_table = pl111_id_table,
444};
445
446#ifdef CONFIG_ARM_AMBA
447module_amba_driver(pl111_amba_driver);
448#endif
449
450MODULE_DESCRIPTION(DRIVER_DESC);
451MODULE_AUTHOR("ARM Ltd.");
452MODULE_LICENSE("GPL");
v5.4
  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/amba/clcd-regs.h>
 51#include <linux/dma-buf.h>
 52#include <linux/module.h>
 53#include <linux/of.h>
 54#include <linux/of_graph.h>
 55#include <linux/of_reserved_mem.h>
 56#include <linux/shmem_fs.h>
 57#include <linux/slab.h>
 58#include <linux/version.h>
 59
 60#include <drm/drm_atomic_helper.h>
 61#include <drm/drm_bridge.h>
 
 62#include <drm/drm_drv.h>
 63#include <drm/drm_fb_cma_helper.h>
 64#include <drm/drm_fb_helper.h>
 65#include <drm/drm_gem_cma_helper.h>
 66#include <drm/drm_gem_framebuffer_helper.h>
 67#include <drm/drm_of.h>
 68#include <drm/drm_panel.h>
 69#include <drm/drm_probe_helper.h>
 70#include <drm/drm_vblank.h>
 71
 72#include "pl111_drm.h"
 73#include "pl111_versatile.h"
 74#include "pl111_nomadik.h"
 75
 76#define DRIVER_DESC      "DRM module for PL111"
 77
 78static const struct drm_mode_config_funcs mode_config_funcs = {
 79	.fb_create = drm_gem_fb_create,
 80	.atomic_check = drm_atomic_helper_check,
 81	.atomic_commit = drm_atomic_helper_commit,
 82};
 83
 84static int pl111_modeset_init(struct drm_device *dev)
 85{
 86	struct drm_mode_config *mode_config;
 87	struct pl111_drm_dev_private *priv = dev->dev_private;
 88	struct device_node *np = dev->dev->of_node;
 89	struct device_node *remote;
 90	struct drm_panel *panel = NULL;
 91	struct drm_bridge *bridge = NULL;
 92	bool defer = false;
 93	int ret = 0;
 94	int i;
 95
 96	drm_mode_config_init(dev);
 
 
 
 97	mode_config = &dev->mode_config;
 98	mode_config->funcs = &mode_config_funcs;
 99	mode_config->min_width = 1;
100	mode_config->max_width = 1024;
101	mode_config->min_height = 1;
102	mode_config->max_height = 768;
103
104	i = 0;
105	for_each_endpoint_of_node(np, remote) {
106		struct drm_panel *tmp_panel;
107		struct drm_bridge *tmp_bridge;
108
109		dev_dbg(dev->dev, "checking endpoint %d\n", i);
110
111		ret = drm_of_find_panel_or_bridge(dev->dev->of_node,
112						  0, i,
113						  &tmp_panel,
114						  &tmp_bridge);
115		if (ret) {
116			if (ret == -EPROBE_DEFER) {
117				/*
118				 * Something deferred, but that is often just
119				 * another way of saying -ENODEV, but let's
120				 * cast a vote for later deferral.
121				 */
122				defer = true;
123			} else if (ret != -ENODEV) {
124				/* Continue, maybe something else is working */
125				dev_err(dev->dev,
126					"endpoint %d returns %d\n", i, ret);
127			}
128		}
129
130		if (tmp_panel) {
131			dev_info(dev->dev,
132				 "found panel on endpoint %d\n", i);
133			panel = tmp_panel;
134		}
135		if (tmp_bridge) {
136			dev_info(dev->dev,
137				 "found bridge on endpoint %d\n", i);
138			bridge = tmp_bridge;
139		}
140
141		i++;
142	}
143
144	/*
145	 * If we can't find neither panel nor bridge on any of the
146	 * endpoints, and any of them retured -EPROBE_DEFER, then
147	 * let's defer this driver too.
148	 */
149	if ((!panel && !bridge) && defer)
150		return -EPROBE_DEFER;
151
152	if (panel) {
153		bridge = drm_panel_bridge_add(panel,
154					      DRM_MODE_CONNECTOR_Unknown);
155		if (IS_ERR(bridge)) {
156			ret = PTR_ERR(bridge);
157			goto out_config;
158		}
159	} else if (bridge) {
160		dev_info(dev->dev, "Using non-panel bridge\n");
161	} else {
162		dev_err(dev->dev, "No bridge, exiting\n");
163		return -ENODEV;
164	}
165
166	priv->bridge = bridge;
167	if (panel) {
168		priv->panel = panel;
169		priv->connector = panel->connector;
170	}
171
172	ret = pl111_display_init(dev);
173	if (ret != 0) {
174		dev_err(dev->dev, "Failed to init display\n");
175		goto out_bridge;
176	}
177
178	ret = drm_simple_display_pipe_attach_bridge(&priv->pipe,
179						    bridge);
180	if (ret)
181		return ret;
182
183	if (!priv->variant->broken_vblank) {
184		ret = drm_vblank_init(dev, 1);
185		if (ret != 0) {
186			dev_err(dev->dev, "Failed to init vblank\n");
187			goto out_bridge;
188		}
189	}
190
191	drm_mode_config_reset(dev);
192
193	drm_kms_helper_poll_init(dev);
194
195	goto finish;
196
197out_bridge:
198	if (panel)
199		drm_panel_bridge_remove(bridge);
200out_config:
201	drm_mode_config_cleanup(dev);
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_mode_config_cleanup(drm);
347	drm_dev_put(drm);
348	of_reserved_mem_device_release(dev);
 
349
350	return 0;
 
 
351}
352
353/*
354 * This early variant lacks the 565 and 444 pixel formats.
355 */
356static const u32 pl110_pixel_formats[] = {
357	DRM_FORMAT_ABGR8888,
358	DRM_FORMAT_XBGR8888,
359	DRM_FORMAT_ARGB8888,
360	DRM_FORMAT_XRGB8888,
361	DRM_FORMAT_ABGR1555,
362	DRM_FORMAT_XBGR1555,
363	DRM_FORMAT_ARGB1555,
364	DRM_FORMAT_XRGB1555,
365};
366
367static const struct pl111_variant_data pl110_variant = {
368	.name = "PL110",
369	.is_pl110 = true,
370	.formats = pl110_pixel_formats,
371	.nformats = ARRAY_SIZE(pl110_pixel_formats),
372	.fb_bpp = 16,
373};
374
375/* RealView, Versatile Express etc use this modern variant */
376static const u32 pl111_pixel_formats[] = {
377	DRM_FORMAT_ABGR8888,
378	DRM_FORMAT_XBGR8888,
379	DRM_FORMAT_ARGB8888,
380	DRM_FORMAT_XRGB8888,
381	DRM_FORMAT_BGR565,
382	DRM_FORMAT_RGB565,
383	DRM_FORMAT_ABGR1555,
384	DRM_FORMAT_XBGR1555,
385	DRM_FORMAT_ARGB1555,
386	DRM_FORMAT_XRGB1555,
387	DRM_FORMAT_ABGR4444,
388	DRM_FORMAT_XBGR4444,
389	DRM_FORMAT_ARGB4444,
390	DRM_FORMAT_XRGB4444,
391};
392
393static const struct pl111_variant_data pl111_variant = {
394	.name = "PL111",
395	.formats = pl111_pixel_formats,
396	.nformats = ARRAY_SIZE(pl111_pixel_formats),
397	.fb_bpp = 32,
398};
399
400static const u32 pl110_nomadik_pixel_formats[] = {
401	DRM_FORMAT_RGB888,
402	DRM_FORMAT_BGR888,
403	DRM_FORMAT_ABGR8888,
404	DRM_FORMAT_XBGR8888,
405	DRM_FORMAT_ARGB8888,
406	DRM_FORMAT_XRGB8888,
407	DRM_FORMAT_BGR565,
408	DRM_FORMAT_RGB565,
409	DRM_FORMAT_ABGR1555,
410	DRM_FORMAT_XBGR1555,
411	DRM_FORMAT_ARGB1555,
412	DRM_FORMAT_XRGB1555,
413	DRM_FORMAT_ABGR4444,
414	DRM_FORMAT_XBGR4444,
415	DRM_FORMAT_ARGB4444,
416	DRM_FORMAT_XRGB4444,
417};
418
419static const struct pl111_variant_data pl110_nomadik_variant = {
420	.name = "LCDC (PL110 Nomadik)",
421	.formats = pl110_nomadik_pixel_formats,
422	.nformats = ARRAY_SIZE(pl110_nomadik_pixel_formats),
423	.is_lcdc = true,
424	.st_bitmux_control = true,
425	.broken_vblank = true,
426	.fb_bpp = 16,
427};
428
429static const struct amba_id pl111_id_table[] = {
430	{
431		.id = 0x00041110,
432		.mask = 0x000fffff,
433		.data = (void *)&pl110_variant,
434	},
435	{
436		.id = 0x00180110,
437		.mask = 0x00fffffe,
438		.data = (void *)&pl110_nomadik_variant,
439	},
440	{
441		.id = 0x00041111,
442		.mask = 0x000fffff,
443		.data = (void *)&pl111_variant,
444	},
445	{0, 0},
446};
 
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");