1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Based on drivers/video/omap/lcd_inn1510.c
5 * LCD panel support for the Amstrad E3 (Delta) videophone.
7 * Copyright (C) 2006 Jonathan McDowell <noodles@earth.li>
10 #include <linux/module.h>
11 #include <linux/platform_device.h>
13 #include <linux/delay.h>
14 #include <linux/gpio/consumer.h>
15 #include <linux/lcd.h>
17 #include <linux/soc/ti/omap1-io.h>
21 #define AMS_DELTA_DEFAULT_CONTRAST 112
23 #define AMS_DELTA_MAX_CONTRAST 0x00FF
24 #define AMS_DELTA_LCD_POWER 0x0100
27 /* LCD class device section */
29 static int ams_delta_lcd
;
30 static struct gpio_desc
*gpiod_vblen
;
31 static struct gpio_desc
*gpiod_ndisp
;
33 static int ams_delta_lcd_set_power(struct lcd_device
*dev
, int power
)
35 if (power
== LCD_POWER_ON
) {
36 if (!(ams_delta_lcd
& AMS_DELTA_LCD_POWER
)) {
37 omap_writeb(ams_delta_lcd
& AMS_DELTA_MAX_CONTRAST
,
39 omap_writeb(1, OMAP_PWL_CLK_ENABLE
);
40 ams_delta_lcd
|= AMS_DELTA_LCD_POWER
;
43 if (ams_delta_lcd
& AMS_DELTA_LCD_POWER
) {
44 omap_writeb(0, OMAP_PWL_ENABLE
);
45 omap_writeb(0, OMAP_PWL_CLK_ENABLE
);
46 ams_delta_lcd
&= ~AMS_DELTA_LCD_POWER
;
52 static int ams_delta_lcd_set_contrast(struct lcd_device
*dev
, int value
)
54 if ((value
>= 0) && (value
<= AMS_DELTA_MAX_CONTRAST
)) {
55 omap_writeb(value
, OMAP_PWL_ENABLE
);
56 ams_delta_lcd
&= ~AMS_DELTA_MAX_CONTRAST
;
57 ams_delta_lcd
|= value
;
62 #ifdef CONFIG_LCD_CLASS_DEVICE
63 static int ams_delta_lcd_get_power(struct lcd_device
*dev
)
65 if (ams_delta_lcd
& AMS_DELTA_LCD_POWER
)
71 static int ams_delta_lcd_get_contrast(struct lcd_device
*dev
)
73 if (!(ams_delta_lcd
& AMS_DELTA_LCD_POWER
))
76 return ams_delta_lcd
& AMS_DELTA_MAX_CONTRAST
;
79 static const struct lcd_ops ams_delta_lcd_ops
= {
80 .get_power
= ams_delta_lcd_get_power
,
81 .set_power
= ams_delta_lcd_set_power
,
82 .get_contrast
= ams_delta_lcd_get_contrast
,
83 .set_contrast
= ams_delta_lcd_set_contrast
,
88 /* omapfb panel section */
90 static int ams_delta_panel_enable(struct lcd_panel
*panel
)
92 gpiod_set_value(gpiod_ndisp
, 1);
93 gpiod_set_value(gpiod_vblen
, 1);
97 static void ams_delta_panel_disable(struct lcd_panel
*panel
)
99 gpiod_set_value(gpiod_vblen
, 0);
100 gpiod_set_value(gpiod_ndisp
, 0);
103 static struct lcd_panel ams_delta_panel
= {
121 .enable
= ams_delta_panel_enable
,
122 .disable
= ams_delta_panel_disable
,
126 /* platform driver section */
128 static int ams_delta_panel_probe(struct platform_device
*pdev
)
130 struct lcd_device
*lcd_device
= NULL
;
132 gpiod_vblen
= devm_gpiod_get(&pdev
->dev
, "vblen", GPIOD_OUT_LOW
);
133 if (IS_ERR(gpiod_vblen
))
134 return dev_err_probe(&pdev
->dev
, PTR_ERR(gpiod_vblen
),
135 "VBLEN GPIO request failed\n");
137 gpiod_ndisp
= devm_gpiod_get(&pdev
->dev
, "ndisp", GPIOD_OUT_LOW
);
138 if (IS_ERR(gpiod_ndisp
))
139 return dev_err_probe(&pdev
->dev
, PTR_ERR(gpiod_ndisp
),
140 "NDISP GPIO request failed\n");
142 #ifdef CONFIG_LCD_CLASS_DEVICE
143 lcd_device
= lcd_device_register("omapfb", &pdev
->dev
, NULL
,
146 if (IS_ERR(lcd_device
)) {
147 int ret
= PTR_ERR(lcd_device
);
149 dev_err(&pdev
->dev
, "failed to register device\n");
153 platform_set_drvdata(pdev
, lcd_device
);
154 lcd_device
->props
.max_contrast
= AMS_DELTA_MAX_CONTRAST
;
157 ams_delta_lcd_set_contrast(lcd_device
, AMS_DELTA_DEFAULT_CONTRAST
);
158 ams_delta_lcd_set_power(lcd_device
, LCD_POWER_ON
);
160 omapfb_register_panel(&ams_delta_panel
);
164 static struct platform_driver ams_delta_panel_driver
= {
165 .probe
= ams_delta_panel_probe
,
167 .name
= "lcd_ams_delta",
171 module_platform_driver(ams_delta_panel_driver
);
173 MODULE_AUTHOR("Jonathan McDowell <noodles@earth.li>");
174 MODULE_DESCRIPTION("LCD panel support for the Amstrad E3 (Delta) videophone");
175 MODULE_LICENSE("GPL");