1 // SPDX-License-Identifier: GPL-2.0-only
2 #include <linux/amba/clcd-regs.h>
3 #include <linux/device.h>
5 #include <linux/of_platform.h>
6 #include <linux/regmap.h>
7 #include <linux/mfd/syscon.h>
8 #include <linux/bitops.h>
9 #include <linux/module.h>
11 #include "pl111_versatile.h"
12 #include "pl111_vexpress.h"
13 #include "pl111_drm.h"
15 static struct regmap *versatile_syscon_map;
18 * We detect the different syscon types from the compatible strings.
31 static const struct of_device_id versatile_clcd_of_match[] = {
33 .compatible = "arm,core-module-integrator",
34 .data = (void *)INTEGRATOR_CLCD_CM,
37 .compatible = "arm,versatile-sysreg",
38 .data = (void *)VERSATILE_CLCD,
41 .compatible = "arm,realview-eb-syscon",
42 .data = (void *)REALVIEW_CLCD_EB,
45 .compatible = "arm,realview-pb1176-syscon",
46 .data = (void *)REALVIEW_CLCD_PB1176,
49 .compatible = "arm,realview-pb11mp-syscon",
50 .data = (void *)REALVIEW_CLCD_PB11MP,
53 .compatible = "arm,realview-pba8-syscon",
54 .data = (void *)REALVIEW_CLCD_PBA8,
57 .compatible = "arm,realview-pbx-syscon",
58 .data = (void *)REALVIEW_CLCD_PBX,
61 .compatible = "arm,vexpress-muxfpga",
62 .data = (void *)VEXPRESS_CLCD_V2M,
68 * Core module CLCD control on the Integrator/CP, bits
69 * 8 thru 19 of the CM_CONTROL register controls a bunch
72 #define INTEGRATOR_HDR_CTRL_OFFSET 0x0C
73 #define INTEGRATOR_CLCD_LCDBIASEN BIT(8)
74 #define INTEGRATOR_CLCD_LCDBIASUP BIT(9)
75 #define INTEGRATOR_CLCD_LCDBIASDN BIT(10)
76 /* Bits 11,12,13 controls the LCD or VGA bridge type */
77 #define INTEGRATOR_CLCD_LCDMUX_LCD24 BIT(11)
78 #define INTEGRATOR_CLCD_LCDMUX_SHARP (BIT(11)|BIT(12))
79 #define INTEGRATOR_CLCD_LCDMUX_VGA555 BIT(13)
80 #define INTEGRATOR_CLCD_LCDMUX_VGA24 (BIT(11)|BIT(12)|BIT(13))
81 #define INTEGRATOR_CLCD_LCD0_EN BIT(14)
82 #define INTEGRATOR_CLCD_LCD1_EN BIT(15)
83 /* R/L flip on Sharp */
84 #define INTEGRATOR_CLCD_LCD_STATIC1 BIT(16)
85 /* U/D flip on Sharp */
86 #define INTEGRATOR_CLCD_LCD_STATIC2 BIT(17)
87 /* No connection on Sharp */
88 #define INTEGRATOR_CLCD_LCD_STATIC BIT(18)
89 /* 0 = 24bit VGA, 1 = 18bit VGA */
90 #define INTEGRATOR_CLCD_LCD_N24BITEN BIT(19)
92 #define INTEGRATOR_CLCD_MASK GENMASK(19, 8)
94 static void pl111_integrator_enable(struct drm_device *drm, u32 format)
98 dev_info(drm->dev, "enable Integrator CLCD connectors\n");
100 /* FIXME: really needed? */
101 val = INTEGRATOR_CLCD_LCD_STATIC1 | INTEGRATOR_CLCD_LCD_STATIC2 |
102 INTEGRATOR_CLCD_LCD0_EN | INTEGRATOR_CLCD_LCD1_EN;
105 case DRM_FORMAT_XBGR8888:
106 case DRM_FORMAT_XRGB8888:
108 val |= INTEGRATOR_CLCD_LCDMUX_VGA24;
110 case DRM_FORMAT_XBGR1555:
111 case DRM_FORMAT_XRGB1555:
112 /* Pseudocolor, RGB555, BGR555 */
113 val |= INTEGRATOR_CLCD_LCDMUX_VGA555;
116 dev_err(drm->dev, "unhandled format on Integrator 0x%08x\n",
121 regmap_update_bits(versatile_syscon_map,
122 INTEGRATOR_HDR_CTRL_OFFSET,
123 INTEGRATOR_CLCD_MASK,
128 * This configuration register in the Versatile and RealView
129 * family is uniformly present but appears more and more
130 * unutilized starting with the RealView series.
132 #define SYS_CLCD 0x50
133 #define SYS_CLCD_MODE_MASK (BIT(0)|BIT(1))
134 #define SYS_CLCD_MODE_888 0
135 #define SYS_CLCD_MODE_5551 BIT(0)
136 #define SYS_CLCD_MODE_565_R_LSB BIT(1)
137 #define SYS_CLCD_MODE_565_B_LSB (BIT(0)|BIT(1))
138 #define SYS_CLCD_CONNECTOR_MASK (BIT(2)|BIT(3)|BIT(4)|BIT(5))
139 #define SYS_CLCD_NLCDIOON BIT(2)
140 #define SYS_CLCD_VDDPOSSWITCH BIT(3)
141 #define SYS_CLCD_PWR3V5SWITCH BIT(4)
142 #define SYS_CLCD_VDDNEGSWITCH BIT(5)
144 static void pl111_versatile_disable(struct drm_device *drm)
146 dev_info(drm->dev, "disable Versatile CLCD connectors\n");
147 regmap_update_bits(versatile_syscon_map,
149 SYS_CLCD_CONNECTOR_MASK,
153 static void pl111_versatile_enable(struct drm_device *drm, u32 format)
157 dev_info(drm->dev, "enable Versatile CLCD connectors\n");
160 case DRM_FORMAT_ABGR8888:
161 case DRM_FORMAT_XBGR8888:
162 case DRM_FORMAT_ARGB8888:
163 case DRM_FORMAT_XRGB8888:
164 val |= SYS_CLCD_MODE_888;
166 case DRM_FORMAT_BGR565:
167 val |= SYS_CLCD_MODE_565_R_LSB;
169 case DRM_FORMAT_RGB565:
170 val |= SYS_CLCD_MODE_565_B_LSB;
172 case DRM_FORMAT_ABGR1555:
173 case DRM_FORMAT_XBGR1555:
174 case DRM_FORMAT_ARGB1555:
175 case DRM_FORMAT_XRGB1555:
176 val |= SYS_CLCD_MODE_5551;
179 dev_err(drm->dev, "unhandled format on Versatile 0x%08x\n",
185 regmap_update_bits(versatile_syscon_map,
190 /* Then enable the display */
191 regmap_update_bits(versatile_syscon_map,
193 SYS_CLCD_CONNECTOR_MASK,
194 SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH);
197 static void pl111_realview_clcd_disable(struct drm_device *drm)
199 dev_info(drm->dev, "disable RealView CLCD connectors\n");
200 regmap_update_bits(versatile_syscon_map,
202 SYS_CLCD_CONNECTOR_MASK,
206 static void pl111_realview_clcd_enable(struct drm_device *drm, u32 format)
208 dev_info(drm->dev, "enable RealView CLCD connectors\n");
209 regmap_update_bits(versatile_syscon_map,
211 SYS_CLCD_CONNECTOR_MASK,
212 SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH);
215 /* PL110 pixel formats for Integrator, vanilla PL110 */
216 static const u32 pl110_integrator_pixel_formats[] = {
227 /* Extended PL110 pixel formats for Integrator and Versatile */
228 static const u32 pl110_versatile_pixel_formats[] = {
233 DRM_FORMAT_BGR565, /* Uses external PLD */
234 DRM_FORMAT_RGB565, /* Uses external PLD */
241 static const u32 pl111_realview_pixel_formats[] = {
259 * The Integrator variant is a PL110 with a bunch of broken, or not
260 * yet implemented features
262 static const struct pl111_variant_data pl110_integrator = {
263 .name = "PL110 Integrator",
265 .broken_clockdivider = true,
266 .broken_vblank = true,
267 .formats = pl110_integrator_pixel_formats,
268 .nformats = ARRAY_SIZE(pl110_integrator_pixel_formats),
273 * This is the in-between PL110 variant found in the ARM Versatile,
274 * supporting RGB565/BGR565
276 static const struct pl111_variant_data pl110_versatile = {
277 .name = "PL110 Versatile",
279 .external_bgr = true,
280 .formats = pl110_versatile_pixel_formats,
281 .nformats = ARRAY_SIZE(pl110_versatile_pixel_formats),
286 * RealView PL111 variant, the only real difference from the vanilla
287 * PL111 is that we select 16bpp framebuffer by default to be able
288 * to get 1024x768 without saturating the memory bus.
290 static const struct pl111_variant_data pl111_realview = {
291 .name = "PL111 RealView",
292 .formats = pl111_realview_pixel_formats,
293 .nformats = ARRAY_SIZE(pl111_realview_pixel_formats),
298 * Versatile Express PL111 variant, again we just push the maximum
299 * BPP to 16 to be able to get 1024x768 without saturating the memory
300 * bus. The clockdivider also seems broken on the Versatile Express.
302 static const struct pl111_variant_data pl111_vexpress = {
303 .name = "PL111 Versatile Express",
304 .formats = pl111_realview_pixel_formats,
305 .nformats = ARRAY_SIZE(pl111_realview_pixel_formats),
307 .broken_clockdivider = true,
310 int pl111_versatile_init(struct device *dev, struct pl111_drm_dev_private *priv)
312 const struct of_device_id *clcd_id;
313 enum versatile_clcd versatile_clcd_type;
314 struct device_node *np;
318 np = of_find_matching_node_and_match(NULL, versatile_clcd_of_match,
321 /* Non-ARM reference designs, just bail out */
324 versatile_clcd_type = (enum versatile_clcd)clcd_id->data;
326 /* Versatile Express special handling */
327 if (versatile_clcd_type == VEXPRESS_CLCD_V2M) {
328 struct platform_device *pdev;
330 /* Registers a driver for the muxfpga */
331 ret = vexpress_muxfpga_init();
333 dev_err(dev, "unable to initialize muxfpga driver\n");
338 /* Call into deep Vexpress configuration API */
339 pdev = of_find_device_by_node(np);
341 dev_err(dev, "can't find the sysreg device, deferring\n");
343 return -EPROBE_DEFER;
345 map = dev_get_drvdata(&pdev->dev);
347 dev_err(dev, "sysreg has not yet probed\n");
348 platform_device_put(pdev);
350 return -EPROBE_DEFER;
353 map = syscon_node_to_regmap(np);
358 dev_err(dev, "no Versatile syscon regmap\n");
362 switch (versatile_clcd_type) {
363 case INTEGRATOR_CLCD_CM:
364 versatile_syscon_map = map;
365 priv->variant = &pl110_integrator;
366 priv->variant_display_enable = pl111_integrator_enable;
367 dev_info(dev, "set up callbacks for Integrator PL110\n");
370 versatile_syscon_map = map;
371 /* This can do RGB565 with external PLD */
372 priv->variant = &pl110_versatile;
373 priv->variant_display_enable = pl111_versatile_enable;
374 priv->variant_display_disable = pl111_versatile_disable;
376 * The Versatile has a variant halfway between PL110
377 * and PL111 where these two registers have already been
380 priv->ienb = CLCD_PL111_IENB;
381 priv->ctrl = CLCD_PL111_CNTL;
382 dev_info(dev, "set up callbacks for Versatile PL110\n");
384 case REALVIEW_CLCD_EB:
385 case REALVIEW_CLCD_PB1176:
386 case REALVIEW_CLCD_PB11MP:
387 case REALVIEW_CLCD_PBA8:
388 case REALVIEW_CLCD_PBX:
389 versatile_syscon_map = map;
390 priv->variant = &pl111_realview;
391 priv->variant_display_enable = pl111_realview_clcd_enable;
392 priv->variant_display_disable = pl111_realview_clcd_disable;
393 dev_info(dev, "set up callbacks for RealView PL111\n");
395 case VEXPRESS_CLCD_V2M:
396 priv->variant = &pl111_vexpress;
397 dev_info(dev, "initializing Versatile Express PL111\n");
398 ret = pl111_vexpress_clcd_init(dev, priv, map);
403 dev_info(dev, "unknown Versatile system controller\n");
409 EXPORT_SYMBOL_GPL(pl111_versatile_init);