1 // SPDX-License-Identifier: GPL-2.0
3 * Panel driver for the ARM Versatile family reference designs from
7 * Linus Walleij <linus.wallei@linaro.org>
9 * On the Versatile AB, these panels come mounted on daughterboards
10 * named "IB1" or "IB2" (Interface Board 1 & 2 respectively.) They
11 * are documented in ARM DUI 0225D Appendix C and D. These daughter
12 * boards support TFT display panels.
14 * - The IB1 is a passive board where the display connector defines a
15 * few wires for encoding the display type for autodetection,
16 * suitable display settings can then be looked up from this setting.
17 * The magic bits can be read out from the system controller.
19 * - The IB2 is a more complex board intended for GSM phone development
20 * with some logic and a control register, which needs to be accessed
21 * and the board display needs to be turned on explicitly.
23 * On the Versatile PB, a special CLCD adaptor board is available
24 * supporting the same displays as the Versatile AB, plus one more
29 #include <drm/drm_panel.h>
31 #include <linux/bitops.h>
32 #include <linux/init.h>
33 #include <linux/kernel.h>
34 #include <linux/mfd/syscon.h>
35 #include <linux/module.h>
36 #include <linux/platform_device.h>
37 #include <linux/regmap.h>
39 #include <video/of_videomode.h>
40 #include <video/videomode.h>
43 * This configuration register in the Versatile and RealView
44 * family is uniformly present but appears more and more
45 * unutilized starting with the RealView series.
49 /* The Versatile can detect the connected panel type */
50 #define SYS_CLCD_CLCDID_MASK (BIT(8)|BIT(9)|BIT(10)|BIT(11)|BIT(12))
51 #define SYS_CLCD_ID_SANYO_3_8 (0x00 << 8)
52 #define SYS_CLCD_ID_SHARP_8_4 (0x01 << 8)
53 #define SYS_CLCD_ID_EPSON_2_2 (0x02 << 8)
54 #define SYS_CLCD_ID_SANYO_2_5 (0x07 << 8)
55 #define SYS_CLCD_ID_VGA (0x1f << 8)
57 /* IB2 control register for the Versatile daughterboard */
59 #define IB2_CTRL_LCD_SD BIT(1) /* 1 = shut down LCD */
60 #define IB2_CTRL_LCD_BL_ON BIT(0)
61 #define IB2_CTRL_LCD_MASK (BIT(0)|BIT(1))
64 * struct versatile_panel_type - lookup struct for the supported panels
66 struct versatile_panel_type
{
68 * @name: the name of this panel
72 * @magic: the magic value from the detection register
76 * @mode: the DRM display mode for this panel
78 struct drm_display_mode mode
;
80 * @bus_flags: the DRM bus flags for this panel e.g. inverted clock
84 * @width_mm: the panel width in mm
88 * @height_mm: the panel height in mm
92 * @ib2: the panel may be connected on an IB2 daughterboard
98 * struct versatile_panel - state container for the Versatile panels
100 struct versatile_panel
{
102 * @dev: the container device
106 * @panel: the DRM panel instance for this device
108 struct drm_panel panel
;
110 * @panel_type: the Versatile panel type as detected
112 const struct versatile_panel_type
*panel_type
;
114 * @map: map to the parent syscon where the main register reside
118 * @ib2_map: map to the IB2 syscon, if applicable
120 struct regmap
*ib2_map
;
123 static const struct versatile_panel_type versatile_panels
[] = {
125 * Sanyo TM38QV67A02A - 3.8 inch QVGA (320x240) Color TFT
126 * found on the Versatile AB IB1 connector or the Versatile
127 * PB adaptor board connector.
130 .name
= "Sanyo TM38QV67A02A",
131 .magic
= SYS_CLCD_ID_SANYO_3_8
,
137 .hsync_start
= 320 + 6,
138 .hsync_end
= 320 + 6 + 6,
139 .htotal
= 320 + 6 + 6 + 6,
141 .vsync_start
= 240 + 5,
142 .vsync_end
= 240 + 5 + 6,
143 .vtotal
= 240 + 5 + 6 + 5,
145 .flags
= DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
,
149 * Sharp LQ084V1DG21 640x480 VGA Color TFT module
150 * found on the Versatile AB IB1 connector or the Versatile
151 * PB adaptor board connector.
154 .name
= "Sharp LQ084V1DG21",
155 .magic
= SYS_CLCD_ID_SHARP_8_4
,
161 .hsync_start
= 640 + 24,
162 .hsync_end
= 640 + 24 + 96,
163 .htotal
= 640 + 24 + 96 + 24,
165 .vsync_start
= 480 + 11,
166 .vsync_end
= 480 + 11 + 2,
167 .vtotal
= 480 + 11 + 2 + 32,
169 .flags
= DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
,
173 * Epson L2F50113T00 - 2.2 inch QCIF 176x220 Color TFT
174 * found on the Versatile PB adaptor board connector.
177 .name
= "Epson L2F50113T00",
178 .magic
= SYS_CLCD_ID_EPSON_2_2
,
184 .hsync_start
= 176 + 2,
185 .hsync_end
= 176 + 2 + 3,
186 .htotal
= 176 + 2 + 3 + 3,
188 .vsync_start
= 220 + 0,
189 .vsync_end
= 220 + 0 + 2,
190 .vtotal
= 220 + 0 + 2 + 1,
192 .flags
= DRM_MODE_FLAG_PHSYNC
| DRM_MODE_FLAG_PVSYNC
,
194 .bus_flags
= DRM_BUS_FLAG_PIXDATA_NEGEDGE
,
197 * Sanyo ALR252RGT 240x320 portrait display found on the
198 * Versatile AB IB2 daughterboard for GSM prototyping.
201 .name
= "Sanyo ALR252RGT",
202 .magic
= SYS_CLCD_ID_SANYO_2_5
,
208 .hsync_start
= 240 + 10,
209 .hsync_end
= 240 + 10 + 10,
210 .htotal
= 240 + 10 + 10 + 20,
212 .vsync_start
= 320 + 2,
213 .vsync_end
= 320 + 2 + 2,
214 .vtotal
= 320 + 2 + 2 + 2,
216 .flags
= DRM_MODE_FLAG_NHSYNC
| DRM_MODE_FLAG_NVSYNC
,
218 .bus_flags
= DRM_BUS_FLAG_PIXDATA_NEGEDGE
,
223 static inline struct versatile_panel
*
224 to_versatile_panel(struct drm_panel
*panel
)
226 return container_of(panel
, struct versatile_panel
, panel
);
229 static int versatile_panel_disable(struct drm_panel
*panel
)
231 struct versatile_panel
*vpanel
= to_versatile_panel(panel
);
233 /* If we're on an IB2 daughterboard, turn off display */
234 if (vpanel
->ib2_map
) {
235 dev_dbg(vpanel
->dev
, "disable IB2 display\n");
236 regmap_update_bits(vpanel
->ib2_map
,
245 static int versatile_panel_enable(struct drm_panel
*panel
)
247 struct versatile_panel
*vpanel
= to_versatile_panel(panel
);
249 /* If we're on an IB2 daughterboard, turn on display */
250 if (vpanel
->ib2_map
) {
251 dev_dbg(vpanel
->dev
, "enable IB2 display\n");
252 regmap_update_bits(vpanel
->ib2_map
,
261 static int versatile_panel_get_modes(struct drm_panel
*panel
)
263 struct drm_connector
*connector
= panel
->connector
;
264 struct versatile_panel
*vpanel
= to_versatile_panel(panel
);
265 struct drm_display_mode
*mode
;
267 strncpy(connector
->display_info
.name
, vpanel
->panel_type
->name
,
268 DRM_DISPLAY_INFO_LEN
);
269 connector
->display_info
.width_mm
= vpanel
->panel_type
->width_mm
;
270 connector
->display_info
.height_mm
= vpanel
->panel_type
->height_mm
;
271 connector
->display_info
.bus_flags
= vpanel
->panel_type
->bus_flags
;
273 mode
= drm_mode_duplicate(panel
->drm
, &vpanel
->panel_type
->mode
);
274 drm_mode_set_name(mode
);
275 mode
->type
= DRM_MODE_TYPE_DRIVER
| DRM_MODE_TYPE_PREFERRED
;
277 mode
->width_mm
= vpanel
->panel_type
->width_mm
;
278 mode
->height_mm
= vpanel
->panel_type
->height_mm
;
279 drm_mode_probed_add(connector
, mode
);
284 static const struct drm_panel_funcs versatile_panel_drm_funcs
= {
285 .disable
= versatile_panel_disable
,
286 .enable
= versatile_panel_enable
,
287 .get_modes
= versatile_panel_get_modes
,
290 static int versatile_panel_probe(struct platform_device
*pdev
)
292 struct device
*dev
= &pdev
->dev
;
293 struct versatile_panel
*vpanel
;
294 struct device
*parent
;
300 parent
= dev
->parent
;
302 dev_err(dev
, "no parent for versatile panel\n");
305 map
= syscon_node_to_regmap(parent
->of_node
);
307 dev_err(dev
, "no regmap for versatile panel parent\n");
311 vpanel
= devm_kzalloc(dev
, sizeof(*vpanel
), GFP_KERNEL
);
315 ret
= regmap_read(map
, SYS_CLCD
, &val
);
317 dev_err(dev
, "cannot access syscon regs\n");
321 val
&= SYS_CLCD_CLCDID_MASK
;
323 for (i
= 0; i
< ARRAY_SIZE(versatile_panels
); i
++) {
324 const struct versatile_panel_type
*pt
;
326 pt
= &versatile_panels
[i
];
327 if (pt
->magic
== val
) {
328 vpanel
->panel_type
= pt
;
333 /* No panel detected or VGA, let's leave this show */
334 if (i
== ARRAY_SIZE(versatile_panels
)) {
335 dev_info(dev
, "no panel detected\n");
339 dev_info(dev
, "detected: %s\n", vpanel
->panel_type
->name
);
343 /* Check if the panel is mounted on an IB2 daughterboard */
344 if (vpanel
->panel_type
->ib2
) {
345 vpanel
->ib2_map
= syscon_regmap_lookup_by_compatible(
346 "arm,versatile-ib2-syscon");
347 if (IS_ERR(vpanel
->ib2_map
))
348 vpanel
->ib2_map
= NULL
;
350 dev_info(dev
, "panel mounted on IB2 daughterboard\n");
353 drm_panel_init(&vpanel
->panel
);
354 vpanel
->panel
.dev
= dev
;
355 vpanel
->panel
.funcs
= &versatile_panel_drm_funcs
;
357 return drm_panel_add(&vpanel
->panel
);
360 static const struct of_device_id versatile_panel_match
[] = {
361 { .compatible
= "arm,versatile-tft-panel", },
364 MODULE_DEVICE_TABLE(of
, versatile_panel_match
);
366 static struct platform_driver versatile_panel_driver
= {
367 .probe
= versatile_panel_probe
,
369 .name
= "versatile-tft-panel",
370 .of_match_table
= versatile_panel_match
,
373 module_platform_driver(versatile_panel_driver
);
375 MODULE_AUTHOR("Linus Walleij <linus.walleij@linaro.org>");
376 MODULE_DESCRIPTION("ARM Versatile panel driver");
377 MODULE_LICENSE("GPL v2");