Merge tag 'soc-ep93xx-dt-6.12' of git://git.kernel.org/pub/scm/linux/kernel/git/soc/soc
[linux-2.6-block.git] / drivers / video / backlight / lms283gf05.c
CommitLineData
d2912cb1 1// SPDX-License-Identifier: GPL-2.0-only
5036cc41
MV
2/*
3 * lms283gf05.c -- support for Samsung LMS283GF05 LCD
4 *
5 * Copyright (c) 2009 Marek Vasut <marek.vasut@gmail.com>
5036cc41
MV
6 */
7
8#include <linux/device.h>
9#include <linux/kernel.h>
10#include <linux/delay.h>
5a0e3ad6 11#include <linux/slab.h>
93cc26fa 12#include <linux/gpio/consumer.h>
5036cc41
MV
13#include <linux/lcd.h>
14
15#include <linux/spi/spi.h>
355b200b 16#include <linux/module.h>
5036cc41
MV
17
18struct lms283gf05_state {
19 struct spi_device *spi;
20 struct lcd_device *ld;
93cc26fa 21 struct gpio_desc *reset;
5036cc41
MV
22};
23
24struct lms283gf05_seq {
25 unsigned char reg;
26 unsigned short value;
27 unsigned char delay;
28};
29
30/* Magic sequences supplied by manufacturer, for details refer to datasheet */
c22e61b3 31static const struct lms283gf05_seq disp_initseq[] = {
5036cc41
MV
32 /* REG, VALUE, DELAY */
33 { 0x07, 0x0000, 0 },
34 { 0x13, 0x0000, 10 },
35
36 { 0x11, 0x3004, 0 },
37 { 0x14, 0x200F, 0 },
38 { 0x10, 0x1a20, 0 },
39 { 0x13, 0x0040, 50 },
40
41 { 0x13, 0x0060, 0 },
42 { 0x13, 0x0070, 200 },
43
44 { 0x01, 0x0127, 0 },
45 { 0x02, 0x0700, 0 },
46 { 0x03, 0x1030, 0 },
47 { 0x08, 0x0208, 0 },
48 { 0x0B, 0x0620, 0 },
49 { 0x0C, 0x0110, 0 },
50 { 0x30, 0x0120, 0 },
51 { 0x31, 0x0127, 0 },
52 { 0x32, 0x0000, 0 },
53 { 0x33, 0x0503, 0 },
54 { 0x34, 0x0727, 0 },
55 { 0x35, 0x0124, 0 },
56 { 0x36, 0x0706, 0 },
57 { 0x37, 0x0701, 0 },
58 { 0x38, 0x0F00, 0 },
59 { 0x39, 0x0F00, 0 },
60 { 0x40, 0x0000, 0 },
61 { 0x41, 0x0000, 0 },
62 { 0x42, 0x013f, 0 },
63 { 0x43, 0x0000, 0 },
64 { 0x44, 0x013f, 0 },
65 { 0x45, 0x0000, 0 },
66 { 0x46, 0xef00, 0 },
67 { 0x47, 0x013f, 0 },
68 { 0x48, 0x0000, 0 },
69 { 0x07, 0x0015, 30 },
70
71 { 0x07, 0x0017, 0 },
72
73 { 0x20, 0x0000, 0 },
74 { 0x21, 0x0000, 0 },
75 { 0x22, 0x0000, 0 }
76};
77
c22e61b3 78static const struct lms283gf05_seq disp_pdwnseq[] = {
5036cc41
MV
79 { 0x07, 0x0016, 30 },
80
81 { 0x07, 0x0004, 0 },
82 { 0x10, 0x0220, 20 },
83
84 { 0x13, 0x0060, 50 },
85
86 { 0x13, 0x0040, 50 },
87
88 { 0x13, 0x0000, 0 },
89 { 0x10, 0x0000, 0 }
90};
91
92
93cc26fa 93static void lms283gf05_reset(struct gpio_desc *gpiod)
5036cc41 94{
93cc26fa 95 gpiod_set_value(gpiod, 0); /* De-asserted */
5036cc41 96 mdelay(100);
93cc26fa 97 gpiod_set_value(gpiod, 1); /* Asserted */
5036cc41 98 mdelay(20);
93cc26fa 99 gpiod_set_value(gpiod, 0); /* De-asserted */
5036cc41
MV
100 mdelay(20);
101}
102
103static void lms283gf05_toggle(struct spi_device *spi,
c22e61b3 104 const struct lms283gf05_seq *seq, int sz)
5036cc41
MV
105{
106 char buf[3];
107 int i;
108
109 for (i = 0; i < sz; i++) {
110 buf[0] = 0x74;
111 buf[1] = 0x00;
112 buf[2] = seq[i].reg;
113 spi_write(spi, buf, 3);
114
115 buf[0] = 0x76;
116 buf[1] = seq[i].value >> 8;
117 buf[2] = seq[i].value & 0xff;
118 spi_write(spi, buf, 3);
119
120 mdelay(seq[i].delay);
121 }
122}
123
124static int lms283gf05_power_set(struct lcd_device *ld, int power)
125{
126 struct lms283gf05_state *st = lcd_get_data(ld);
127 struct spi_device *spi = st->spi;
5036cc41 128
6bde9082 129 if (power <= FB_BLANK_NORMAL) {
93cc26fa
LW
130 if (st->reset)
131 lms283gf05_reset(st->reset);
5036cc41
MV
132 lms283gf05_toggle(spi, disp_initseq, ARRAY_SIZE(disp_initseq));
133 } else {
134 lms283gf05_toggle(spi, disp_pdwnseq, ARRAY_SIZE(disp_pdwnseq));
93cc26fa
LW
135 if (st->reset)
136 gpiod_set_value(st->reset, 1); /* Asserted */
5036cc41
MV
137 }
138
139 return 0;
140}
141
7ae6431a 142static const struct lcd_ops lms_ops = {
5036cc41
MV
143 .set_power = lms283gf05_power_set,
144 .get_power = NULL,
145};
146
1b9e450d 147static int lms283gf05_probe(struct spi_device *spi)
5036cc41
MV
148{
149 struct lms283gf05_state *st;
5036cc41 150 struct lcd_device *ld;
5036cc41 151
26f2b35c
JH
152 st = devm_kzalloc(&spi->dev, sizeof(struct lms283gf05_state),
153 GFP_KERNEL);
e1094f9f 154 if (st == NULL)
04e961fb 155 return -ENOMEM;
5036cc41 156
93cc26fa
LW
157 st->reset = gpiod_get_optional(&spi->dev, "reset", GPIOD_OUT_LOW);
158 if (IS_ERR(st->reset))
159 return PTR_ERR(st->reset);
160 gpiod_set_consumer_name(st->reset, "LMS283GF05 RESET");
161
0a1c55d0
JH
162 ld = devm_lcd_device_register(&spi->dev, "lms283gf05", &spi->dev, st,
163 &lms_ops);
04e961fb
JH
164 if (IS_ERR(ld))
165 return PTR_ERR(ld);
5036cc41
MV
166
167 st->spi = spi;
168 st->ld = ld;
169
b936fab0 170 spi_set_drvdata(spi, st);
5036cc41
MV
171
172 /* kick in the LCD */
93cc26fa
LW
173 if (st->reset)
174 lms283gf05_reset(st->reset);
5036cc41
MV
175 lms283gf05_toggle(spi, disp_initseq, ARRAY_SIZE(disp_initseq));
176
177 return 0;
5036cc41
MV
178}
179
5036cc41
MV
180static struct spi_driver lms283gf05_driver = {
181 .driver = {
182 .name = "lms283gf05",
5036cc41
MV
183 },
184 .probe = lms283gf05_probe,
5036cc41
MV
185};
186
462dd838 187module_spi_driver(lms283gf05_driver);
5036cc41
MV
188
189MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
190MODULE_DESCRIPTION("LCD283GF05 LCD");
191MODULE_LICENSE("GPL v2");