1 // SPDX-License-Identifier: GPL-2.0-only
3 * l4f00242t03.c -- support for Epson L4F00242T03 LCD
5 * Copyright 2007-2009 Freescale Semiconductor, Inc. All Rights Reserved.
7 * Copyright (c) 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
8 * Inspired by Marek Vasut work in l4f00242t03.c
11 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
13 #include <linux/device.h>
14 #include <linux/kernel.h>
15 #include <linux/delay.h>
16 #include <linux/module.h>
17 #include <linux/gpio/consumer.h>
18 #include <linux/lcd.h>
19 #include <linux/slab.h>
20 #include <linux/regulator/consumer.h>
21 #include <linux/spi/spi.h>
23 struct l4f00242t03_priv
{
24 struct spi_device
*spi
;
25 struct lcd_device
*ld
;
27 struct regulator
*io_reg
;
28 struct regulator
*core_reg
;
29 struct gpio_desc
*reset
;
30 struct gpio_desc
*enable
;
33 static void l4f00242t03_reset(struct gpio_desc
*gpiod
)
35 pr_debug("l4f00242t03_reset.\n");
36 gpiod_set_value(gpiod
, 1);
38 gpiod_set_value(gpiod
, 0);
39 mdelay(10); /* tRES >= 100us */
40 gpiod_set_value(gpiod
, 1);
44 #define param(x) ((x) | 0x100)
46 static void l4f00242t03_lcd_init(struct spi_device
*spi
)
48 struct l4f00242t03_priv
*priv
= spi_get_drvdata(spi
);
49 const u16 cmd
[] = { 0x36, param(0), 0x3A, param(0x60) };
52 dev_dbg(&spi
->dev
, "initializing LCD\n");
54 ret
= regulator_set_voltage(priv
->io_reg
, 1800000, 1800000);
56 dev_err(&spi
->dev
, "failed to set the IO regulator voltage.\n");
59 ret
= regulator_enable(priv
->io_reg
);
61 dev_err(&spi
->dev
, "failed to enable the IO regulator.\n");
65 ret
= regulator_set_voltage(priv
->core_reg
, 2800000, 2800000);
67 dev_err(&spi
->dev
, "failed to set the core regulator voltage.\n");
68 regulator_disable(priv
->io_reg
);
71 ret
= regulator_enable(priv
->core_reg
);
73 dev_err(&spi
->dev
, "failed to enable the core regulator.\n");
74 regulator_disable(priv
->io_reg
);
78 l4f00242t03_reset(priv
->reset
);
80 gpiod_set_value(priv
->enable
, 1);
82 spi_write(spi
, (const u8
*)cmd
, ARRAY_SIZE(cmd
) * sizeof(u16
));
85 static void l4f00242t03_lcd_powerdown(struct spi_device
*spi
)
87 struct l4f00242t03_priv
*priv
= spi_get_drvdata(spi
);
89 dev_dbg(&spi
->dev
, "Powering down LCD\n");
91 gpiod_set_value(priv
->enable
, 0);
93 regulator_disable(priv
->io_reg
);
94 regulator_disable(priv
->core_reg
);
97 static int l4f00242t03_lcd_power_get(struct lcd_device
*ld
)
99 struct l4f00242t03_priv
*priv
= lcd_get_data(ld
);
101 return priv
->lcd_state
;
104 static int l4f00242t03_lcd_power_set(struct lcd_device
*ld
, int power
)
106 struct l4f00242t03_priv
*priv
= lcd_get_data(ld
);
107 struct spi_device
*spi
= priv
->spi
;
109 const u16 slpout
= 0x11;
110 const u16 dison
= 0x29;
112 const u16 slpin
= 0x10;
113 const u16 disoff
= 0x28;
115 if (power
<= LCD_POWER_REDUCED
) {
116 if (priv
->lcd_state
<= LCD_POWER_REDUCED
) {
117 /* Do nothing, the LCD is running */
118 } else if (priv
->lcd_state
< LCD_POWER_OFF
) {
119 dev_dbg(&spi
->dev
, "Resuming LCD\n");
121 spi_write(spi
, (const u8
*)&slpout
, sizeof(u16
));
123 spi_write(spi
, (const u8
*)&dison
, sizeof(u16
));
125 /* priv->lcd_state == LCD_POWER_OFF */
126 l4f00242t03_lcd_init(spi
);
127 priv
->lcd_state
= LCD_POWER_REDUCED_VSYNC_SUSPEND
;
128 l4f00242t03_lcd_power_set(priv
->ld
, power
);
130 } else if (power
< LCD_POWER_OFF
) {
131 if (priv
->lcd_state
<= LCD_POWER_REDUCED
) {
132 /* Send the display in standby */
133 dev_dbg(&spi
->dev
, "Standby the LCD\n");
135 spi_write(spi
, (const u8
*)&disoff
, sizeof(u16
));
137 spi_write(spi
, (const u8
*)&slpin
, sizeof(u16
));
138 } else if (priv
->lcd_state
< LCD_POWER_OFF
) {
139 /* Do nothing, the LCD is already in standby */
141 /* priv->lcd_state == LCD_POWER_OFF */
142 l4f00242t03_lcd_init(spi
);
143 priv
->lcd_state
= LCD_POWER_ON
;
144 l4f00242t03_lcd_power_set(ld
, power
);
147 /* power == LCD_POWER_OFF */
148 if (priv
->lcd_state
!= LCD_POWER_OFF
) {
149 /* Clear the screen before shutting down */
150 spi_write(spi
, (const u8
*)&disoff
, sizeof(u16
));
152 l4f00242t03_lcd_powerdown(spi
);
156 priv
->lcd_state
= power
;
161 static const struct lcd_ops l4f_ops
= {
162 .set_power
= l4f00242t03_lcd_power_set
,
163 .get_power
= l4f00242t03_lcd_power_get
,
166 static int l4f00242t03_probe(struct spi_device
*spi
)
168 struct l4f00242t03_priv
*priv
;
171 priv
= devm_kzalloc(&spi
->dev
, sizeof(struct l4f00242t03_priv
),
176 spi_set_drvdata(spi
, priv
);
177 spi
->bits_per_word
= 9;
178 ret
= spi_setup(spi
);
180 return dev_err_probe(&spi
->dev
, ret
, "Unable to setup spi.\n");
184 priv
->reset
= devm_gpiod_get(&spi
->dev
, "reset", GPIOD_OUT_HIGH
);
185 if (IS_ERR(priv
->reset
))
186 return dev_err_probe(&spi
->dev
, PTR_ERR(priv
->reset
),
187 "Unable to get the lcd l4f00242t03 reset gpio.\n");
188 gpiod_set_consumer_name(priv
->reset
, "lcd l4f00242t03 reset");
190 priv
->enable
= devm_gpiod_get(&spi
->dev
, "enable", GPIOD_OUT_LOW
);
191 if (IS_ERR(priv
->enable
))
192 return dev_err_probe(&spi
->dev
, PTR_ERR(priv
->enable
),
193 "Unable to get the lcd l4f00242t03 data en gpio.\n");
194 gpiod_set_consumer_name(priv
->enable
, "lcd l4f00242t03 data enable");
196 priv
->io_reg
= devm_regulator_get(&spi
->dev
, "vdd");
197 if (IS_ERR(priv
->io_reg
))
198 return dev_err_probe(&spi
->dev
, PTR_ERR(priv
->io_reg
),
199 "%s: Unable to get the IO regulator\n",
202 priv
->core_reg
= devm_regulator_get(&spi
->dev
, "vcore");
203 if (IS_ERR(priv
->core_reg
))
204 return dev_err_probe(&spi
->dev
, PTR_ERR(priv
->core_reg
),
205 "%s: Unable to get the core regulator\n",
208 priv
->ld
= devm_lcd_device_register(&spi
->dev
, "l4f00242t03", &spi
->dev
,
210 if (IS_ERR(priv
->ld
))
211 return PTR_ERR(priv
->ld
);
214 l4f00242t03_lcd_init(spi
);
215 priv
->lcd_state
= LCD_POWER_REDUCED_VSYNC_SUSPEND
;
216 l4f00242t03_lcd_power_set(priv
->ld
, LCD_POWER_ON
);
218 dev_info(&spi
->dev
, "Epson l4f00242t03 lcd probed.\n");
223 static void l4f00242t03_remove(struct spi_device
*spi
)
225 struct l4f00242t03_priv
*priv
= spi_get_drvdata(spi
);
227 l4f00242t03_lcd_power_set(priv
->ld
, LCD_POWER_OFF
);
230 static void l4f00242t03_shutdown(struct spi_device
*spi
)
232 struct l4f00242t03_priv
*priv
= spi_get_drvdata(spi
);
235 l4f00242t03_lcd_power_set(priv
->ld
, LCD_POWER_OFF
);
239 static struct spi_driver l4f00242t03_driver
= {
241 .name
= "l4f00242t03",
243 .probe
= l4f00242t03_probe
,
244 .remove
= l4f00242t03_remove
,
245 .shutdown
= l4f00242t03_shutdown
,
248 module_spi_driver(l4f00242t03_driver
);
250 MODULE_AUTHOR("Alberto Panizzo <maramaopercheseimorto@gmail.com>");
251 MODULE_DESCRIPTION("EPSON L4F00242T03 LCD");
252 MODULE_LICENSE("GPL v2");