1 // SPDX-License-Identifier: GPL-2.0-only
3 #include <linux/amba/clcd-regs.h>
4 #include <linux/bitops.h>
5 #include <linux/device.h>
6 #include <linux/mfd/syscon.h>
7 #include <linux/module.h>
9 #include <linux/of_platform.h>
10 #include <linux/regmap.h>
11 #include <linux/vexpress.h>
13 #include "pl111_versatile.h"
14 #include "pl111_drm.h"
16 static struct regmap *versatile_syscon_map;
19 * We detect the different syscon types from the compatible strings.
33 static const struct of_device_id versatile_clcd_of_match[] = {
35 .compatible = "arm,core-module-integrator",
36 .data = (void *)INTEGRATOR_CLCD_CM,
39 .compatible = "arm,versatile-sysreg",
40 .data = (void *)VERSATILE_CLCD,
43 .compatible = "arm,realview-eb-syscon",
44 .data = (void *)REALVIEW_CLCD_EB,
47 .compatible = "arm,realview-pb1176-syscon",
48 .data = (void *)REALVIEW_CLCD_PB1176,
51 .compatible = "arm,realview-pb11mp-syscon",
52 .data = (void *)REALVIEW_CLCD_PB11MP,
55 .compatible = "arm,realview-pba8-syscon",
56 .data = (void *)REALVIEW_CLCD_PBA8,
59 .compatible = "arm,realview-pbx-syscon",
60 .data = (void *)REALVIEW_CLCD_PBX,
63 .compatible = "arm,vexpress-muxfpga",
64 .data = (void *)VEXPRESS_CLCD_V2M,
69 static const struct of_device_id impd1_clcd_of_match[] = {
71 .compatible = "arm,im-pd1-syscon",
72 .data = (void *)INTEGRATOR_IMPD1,
78 * Core module CLCD control on the Integrator/CP, bits
79 * 8 thru 19 of the CM_CONTROL register controls a bunch
82 #define INTEGRATOR_HDR_CTRL_OFFSET 0x0C
83 #define INTEGRATOR_CLCD_LCDBIASEN BIT(8)
84 #define INTEGRATOR_CLCD_LCDBIASUP BIT(9)
85 #define INTEGRATOR_CLCD_LCDBIASDN BIT(10)
86 /* Bits 11,12,13 controls the LCD or VGA bridge type */
87 #define INTEGRATOR_CLCD_LCDMUX_LCD24 BIT(11)
88 #define INTEGRATOR_CLCD_LCDMUX_SHARP (BIT(11)|BIT(12))
89 #define INTEGRATOR_CLCD_LCDMUX_VGA555 BIT(13)
90 #define INTEGRATOR_CLCD_LCDMUX_VGA24 (BIT(11)|BIT(12)|BIT(13))
91 #define INTEGRATOR_CLCD_LCD0_EN BIT(14)
92 #define INTEGRATOR_CLCD_LCD1_EN BIT(15)
93 /* R/L flip on Sharp */
94 #define INTEGRATOR_CLCD_LCD_STATIC1 BIT(16)
95 /* U/D flip on Sharp */
96 #define INTEGRATOR_CLCD_LCD_STATIC2 BIT(17)
97 /* No connection on Sharp */
98 #define INTEGRATOR_CLCD_LCD_STATIC BIT(18)
99 /* 0 = 24bit VGA, 1 = 18bit VGA */
100 #define INTEGRATOR_CLCD_LCD_N24BITEN BIT(19)
102 #define INTEGRATOR_CLCD_MASK GENMASK(19, 8)
104 static void pl111_integrator_enable(struct drm_device *drm, u32 format)
108 dev_info(drm->dev, "enable Integrator CLCD connectors\n");
110 /* FIXME: really needed? */
111 val = INTEGRATOR_CLCD_LCD_STATIC1 | INTEGRATOR_CLCD_LCD_STATIC2 |
112 INTEGRATOR_CLCD_LCD0_EN | INTEGRATOR_CLCD_LCD1_EN;
115 case DRM_FORMAT_XBGR8888:
116 case DRM_FORMAT_XRGB8888:
118 val |= INTEGRATOR_CLCD_LCDMUX_VGA24;
120 case DRM_FORMAT_XBGR1555:
121 case DRM_FORMAT_XRGB1555:
122 /* Pseudocolor, RGB555, BGR555 */
123 val |= INTEGRATOR_CLCD_LCDMUX_VGA555;
126 dev_err(drm->dev, "unhandled format on Integrator 0x%08x\n",
131 regmap_update_bits(versatile_syscon_map,
132 INTEGRATOR_HDR_CTRL_OFFSET,
133 INTEGRATOR_CLCD_MASK,
137 #define IMPD1_CTRL_OFFSET 0x18
138 #define IMPD1_CTRL_DISP_LCD (0 << 0)
139 #define IMPD1_CTRL_DISP_VGA (1 << 0)
140 #define IMPD1_CTRL_DISP_LCD1 (2 << 0)
141 #define IMPD1_CTRL_DISP_ENABLE (1 << 2)
142 #define IMPD1_CTRL_DISP_MASK (7 << 0)
144 static void pl111_impd1_enable(struct drm_device *drm, u32 format)
148 dev_info(drm->dev, "enable IM-PD1 CLCD connectors\n");
149 val = IMPD1_CTRL_DISP_VGA | IMPD1_CTRL_DISP_ENABLE;
151 regmap_update_bits(versatile_syscon_map,
153 IMPD1_CTRL_DISP_MASK,
157 static void pl111_impd1_disable(struct drm_device *drm)
159 dev_info(drm->dev, "disable IM-PD1 CLCD connectors\n");
161 regmap_update_bits(versatile_syscon_map,
163 IMPD1_CTRL_DISP_MASK,
168 * This configuration register in the Versatile and RealView
169 * family is uniformly present but appears more and more
170 * unutilized starting with the RealView series.
172 #define SYS_CLCD 0x50
173 #define SYS_CLCD_MODE_MASK (BIT(0)|BIT(1))
174 #define SYS_CLCD_MODE_888 0
175 #define SYS_CLCD_MODE_5551 BIT(0)
176 #define SYS_CLCD_MODE_565_R_LSB BIT(1)
177 #define SYS_CLCD_MODE_565_B_LSB (BIT(0)|BIT(1))
178 #define SYS_CLCD_CONNECTOR_MASK (BIT(2)|BIT(3)|BIT(4)|BIT(5))
179 #define SYS_CLCD_NLCDIOON BIT(2)
180 #define SYS_CLCD_VDDPOSSWITCH BIT(3)
181 #define SYS_CLCD_PWR3V5SWITCH BIT(4)
182 #define SYS_CLCD_VDDNEGSWITCH BIT(5)
184 static void pl111_versatile_disable(struct drm_device *drm)
186 dev_info(drm->dev, "disable Versatile CLCD connectors\n");
187 regmap_update_bits(versatile_syscon_map,
189 SYS_CLCD_CONNECTOR_MASK,
193 static void pl111_versatile_enable(struct drm_device *drm, u32 format)
197 dev_info(drm->dev, "enable Versatile CLCD connectors\n");
200 case DRM_FORMAT_ABGR8888:
201 case DRM_FORMAT_XBGR8888:
202 case DRM_FORMAT_ARGB8888:
203 case DRM_FORMAT_XRGB8888:
204 val |= SYS_CLCD_MODE_888;
206 case DRM_FORMAT_BGR565:
207 val |= SYS_CLCD_MODE_565_R_LSB;
209 case DRM_FORMAT_RGB565:
210 val |= SYS_CLCD_MODE_565_B_LSB;
212 case DRM_FORMAT_ABGR1555:
213 case DRM_FORMAT_XBGR1555:
214 case DRM_FORMAT_ARGB1555:
215 case DRM_FORMAT_XRGB1555:
216 val |= SYS_CLCD_MODE_5551;
219 dev_err(drm->dev, "unhandled format on Versatile 0x%08x\n",
225 regmap_update_bits(versatile_syscon_map,
230 /* Then enable the display */
231 regmap_update_bits(versatile_syscon_map,
233 SYS_CLCD_CONNECTOR_MASK,
234 SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH);
237 static void pl111_realview_clcd_disable(struct drm_device *drm)
239 dev_info(drm->dev, "disable RealView CLCD connectors\n");
240 regmap_update_bits(versatile_syscon_map,
242 SYS_CLCD_CONNECTOR_MASK,
246 static void pl111_realview_clcd_enable(struct drm_device *drm, u32 format)
248 dev_info(drm->dev, "enable RealView CLCD connectors\n");
249 regmap_update_bits(versatile_syscon_map,
251 SYS_CLCD_CONNECTOR_MASK,
252 SYS_CLCD_NLCDIOON | SYS_CLCD_PWR3V5SWITCH);
255 /* PL110 pixel formats for Integrator, vanilla PL110 */
256 static const u32 pl110_integrator_pixel_formats[] = {
267 /* Extended PL110 pixel formats for Integrator and Versatile */
268 static const u32 pl110_versatile_pixel_formats[] = {
273 DRM_FORMAT_BGR565, /* Uses external PLD */
274 DRM_FORMAT_RGB565, /* Uses external PLD */
281 static const u32 pl111_realview_pixel_formats[] = {
299 * The Integrator variant is a PL110 with a bunch of broken, or not
300 * yet implemented features
302 static const struct pl111_variant_data pl110_integrator = {
303 .name = "PL110 Integrator",
305 .broken_clockdivider = true,
306 .broken_vblank = true,
307 .formats = pl110_integrator_pixel_formats,
308 .nformats = ARRAY_SIZE(pl110_integrator_pixel_formats),
313 * The IM-PD1 variant is a PL110 with a bunch of broken, or not
314 * yet implemented features
316 static const struct pl111_variant_data pl110_impd1 = {
317 .name = "PL110 IM-PD1",
319 .broken_clockdivider = true,
320 .broken_vblank = true,
321 .formats = pl110_integrator_pixel_formats,
322 .nformats = ARRAY_SIZE(pl110_integrator_pixel_formats),
327 * This is the in-between PL110 variant found in the ARM Versatile,
328 * supporting RGB565/BGR565
330 static const struct pl111_variant_data pl110_versatile = {
331 .name = "PL110 Versatile",
333 .external_bgr = true,
334 .formats = pl110_versatile_pixel_formats,
335 .nformats = ARRAY_SIZE(pl110_versatile_pixel_formats),
340 * RealView PL111 variant, the only real difference from the vanilla
341 * PL111 is that we select 16bpp framebuffer by default to be able
342 * to get 1024x768 without saturating the memory bus.
344 static const struct pl111_variant_data pl111_realview = {
345 .name = "PL111 RealView",
346 .formats = pl111_realview_pixel_formats,
347 .nformats = ARRAY_SIZE(pl111_realview_pixel_formats),
352 * Versatile Express PL111 variant, again we just push the maximum
353 * BPP to 16 to be able to get 1024x768 without saturating the memory
354 * bus. The clockdivider also seems broken on the Versatile Express.
356 static const struct pl111_variant_data pl111_vexpress = {
357 .name = "PL111 Versatile Express",
358 .formats = pl111_realview_pixel_formats,
359 .nformats = ARRAY_SIZE(pl111_realview_pixel_formats),
361 .broken_clockdivider = true,
364 #define VEXPRESS_FPGAMUX_MOTHERBOARD 0x00
365 #define VEXPRESS_FPGAMUX_DAUGHTERBOARD_1 0x01
366 #define VEXPRESS_FPGAMUX_DAUGHTERBOARD_2 0x02
368 static int pl111_vexpress_clcd_init(struct device *dev, struct device_node *np,
369 struct pl111_drm_dev_private *priv)
371 struct platform_device *pdev;
372 struct device_node *root;
373 struct device_node *child;
374 struct device_node *ct_clcd = NULL;
376 bool has_coretile_clcd = false;
377 bool has_coretile_hdlcd = false;
378 bool mux_motherboard = true;
382 if (!IS_ENABLED(CONFIG_VEXPRESS_CONFIG))
386 * Check if we have a CLCD or HDLCD on the core tile by checking if a
387 * CLCD or HDLCD is available in the root of the device tree.
389 root = of_find_node_by_path("/");
393 for_each_available_child_of_node(root, child) {
394 if (of_device_is_compatible(child, "arm,pl111")) {
395 has_coretile_clcd = true;
399 if (of_device_is_compatible(child, "arm,hdlcd")) {
400 has_coretile_hdlcd = true;
409 * If there is a coretile HDLCD and it has a driver,
410 * do not mux the CLCD on the motherboard to the DVI.
412 if (has_coretile_hdlcd && IS_ENABLED(CONFIG_DRM_HDLCD))
413 mux_motherboard = false;
416 * On the Vexpress CA9 we let the CLCD on the coretile
417 * take precedence, so also in this case do not mux the
418 * motherboard to the DVI.
420 if (has_coretile_clcd)
421 mux_motherboard = false;
423 if (mux_motherboard) {
424 dev_info(dev, "DVI muxed to motherboard CLCD\n");
425 val = VEXPRESS_FPGAMUX_MOTHERBOARD;
426 } else if (ct_clcd == dev->of_node) {
428 "DVI muxed to daughterboard 1 (core tile) CLCD\n");
429 val = VEXPRESS_FPGAMUX_DAUGHTERBOARD_1;
431 dev_info(dev, "core tile graphics present\n");
432 dev_info(dev, "this device will be deactivated\n");
436 /* Call into deep Vexpress configuration API */
437 pdev = of_find_device_by_node(np);
439 dev_err(dev, "can't find the sysreg device, deferring\n");
440 return -EPROBE_DEFER;
443 map = devm_regmap_init_vexpress_config(&pdev->dev);
445 platform_device_put(pdev);
449 ret = regmap_write(map, 0, val);
450 platform_device_put(pdev);
452 dev_err(dev, "error setting DVI muxmode\n");
456 priv->variant = &pl111_vexpress;
457 dev_info(dev, "initializing Versatile Express PL111\n");
462 int pl111_versatile_init(struct device *dev, struct pl111_drm_dev_private *priv)
464 const struct of_device_id *clcd_id;
465 enum versatile_clcd versatile_clcd_type;
466 struct device_node *np;
469 np = of_find_matching_node_and_match(NULL, versatile_clcd_of_match,
472 /* Non-ARM reference designs, just bail out */
476 versatile_clcd_type = (enum versatile_clcd)clcd_id->data;
478 /* Versatile Express special handling */
479 if (versatile_clcd_type == VEXPRESS_CLCD_V2M) {
480 int ret = pl111_vexpress_clcd_init(dev, np, priv);
483 dev_err(dev, "Versatile Express init failed - %d", ret);
488 * On the Integrator, check if we should use the IM-PD1 instead,
489 * if we find it, it will take precedence. This is on the Integrator/AP
490 * which only has this option for PL110 graphics.
492 if (versatile_clcd_type == INTEGRATOR_CLCD_CM) {
493 np = of_find_matching_node_and_match(NULL, impd1_clcd_of_match,
496 versatile_clcd_type = (enum versatile_clcd)clcd_id->data;
499 map = syscon_node_to_regmap(np);
502 dev_err(dev, "no Versatile syscon regmap\n");
506 switch (versatile_clcd_type) {
507 case INTEGRATOR_CLCD_CM:
508 versatile_syscon_map = map;
509 priv->variant = &pl110_integrator;
510 priv->variant_display_enable = pl111_integrator_enable;
511 dev_info(dev, "set up callbacks for Integrator PL110\n");
513 case INTEGRATOR_IMPD1:
514 versatile_syscon_map = map;
515 priv->variant = &pl110_impd1;
516 priv->variant_display_enable = pl111_impd1_enable;
517 priv->variant_display_disable = pl111_impd1_disable;
518 dev_info(dev, "set up callbacks for IM-PD1 PL110\n");
521 versatile_syscon_map = map;
522 /* This can do RGB565 with external PLD */
523 priv->variant = &pl110_versatile;
524 priv->variant_display_enable = pl111_versatile_enable;
525 priv->variant_display_disable = pl111_versatile_disable;
527 * The Versatile has a variant halfway between PL110
528 * and PL111 where these two registers have already been
531 priv->ienb = CLCD_PL111_IENB;
532 priv->ctrl = CLCD_PL111_CNTL;
533 dev_info(dev, "set up callbacks for Versatile PL110\n");
535 case REALVIEW_CLCD_EB:
536 case REALVIEW_CLCD_PB1176:
537 case REALVIEW_CLCD_PB11MP:
538 case REALVIEW_CLCD_PBA8:
539 case REALVIEW_CLCD_PBX:
540 versatile_syscon_map = map;
541 priv->variant = &pl111_realview;
542 priv->variant_display_enable = pl111_realview_clcd_enable;
543 priv->variant_display_disable = pl111_realview_clcd_disable;
544 dev_info(dev, "set up callbacks for RealView PL111\n");
547 dev_info(dev, "unknown Versatile system controller\n");
553 EXPORT_SYMBOL_GPL(pl111_versatile_init);