]>
Commit | Line | Data |
---|---|---|
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> |
5036cc41 MV |
12 | #include <linux/gpio.h> |
13 | #include <linux/lcd.h> | |
14 | ||
15 | #include <linux/spi/spi.h> | |
16 | #include <linux/spi/lms283gf05.h> | |
355b200b | 17 | #include <linux/module.h> |
5036cc41 MV |
18 | |
19 | struct lms283gf05_state { | |
20 | struct spi_device *spi; | |
21 | struct lcd_device *ld; | |
22 | }; | |
23 | ||
24 | struct 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 | 31 | static 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 | 78 | static 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 | ||
93 | static void lms283gf05_reset(unsigned long gpio, bool inverted) | |
94 | { | |
95 | gpio_set_value(gpio, !inverted); | |
96 | mdelay(100); | |
97 | gpio_set_value(gpio, inverted); | |
98 | mdelay(20); | |
99 | gpio_set_value(gpio, !inverted); | |
100 | mdelay(20); | |
101 | } | |
102 | ||
103 | static 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 | ||
124 | static 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; | |
c512794c | 128 | struct lms283gf05_pdata *pdata = dev_get_platdata(&spi->dev); |
5036cc41 | 129 | |
6bde9082 | 130 | if (power <= FB_BLANK_NORMAL) { |
5036cc41 MV |
131 | if (pdata) |
132 | lms283gf05_reset(pdata->reset_gpio, | |
133 | pdata->reset_inverted); | |
134 | lms283gf05_toggle(spi, disp_initseq, ARRAY_SIZE(disp_initseq)); | |
135 | } else { | |
136 | lms283gf05_toggle(spi, disp_pdwnseq, ARRAY_SIZE(disp_pdwnseq)); | |
137 | if (pdata) | |
138 | gpio_set_value(pdata->reset_gpio, | |
139 | pdata->reset_inverted); | |
140 | } | |
141 | ||
142 | return 0; | |
143 | } | |
144 | ||
145 | static struct lcd_ops lms_ops = { | |
146 | .set_power = lms283gf05_power_set, | |
147 | .get_power = NULL, | |
148 | }; | |
149 | ||
1b9e450d | 150 | static int lms283gf05_probe(struct spi_device *spi) |
5036cc41 MV |
151 | { |
152 | struct lms283gf05_state *st; | |
c512794c | 153 | struct lms283gf05_pdata *pdata = dev_get_platdata(&spi->dev); |
5036cc41 MV |
154 | struct lcd_device *ld; |
155 | int ret = 0; | |
156 | ||
157 | if (pdata != NULL) { | |
5a5a0743 | 158 | ret = devm_gpio_request_one(&spi->dev, pdata->reset_gpio, |
1eddd977 JH |
159 | GPIOF_DIR_OUT | (!pdata->reset_inverted ? |
160 | GPIOF_INIT_HIGH : GPIOF_INIT_LOW), | |
30f644fd | 161 | "LMS283GF05 RESET"); |
5036cc41 | 162 | if (ret) |
04e961fb | 163 | return ret; |
5036cc41 MV |
164 | } |
165 | ||
26f2b35c JH |
166 | st = devm_kzalloc(&spi->dev, sizeof(struct lms283gf05_state), |
167 | GFP_KERNEL); | |
e1094f9f | 168 | if (st == NULL) |
04e961fb | 169 | return -ENOMEM; |
5036cc41 | 170 | |
0a1c55d0 JH |
171 | ld = devm_lcd_device_register(&spi->dev, "lms283gf05", &spi->dev, st, |
172 | &lms_ops); | |
04e961fb JH |
173 | if (IS_ERR(ld)) |
174 | return PTR_ERR(ld); | |
5036cc41 MV |
175 | |
176 | st->spi = spi; | |
177 | st->ld = ld; | |
178 | ||
b936fab0 | 179 | spi_set_drvdata(spi, st); |
5036cc41 MV |
180 | |
181 | /* kick in the LCD */ | |
182 | if (pdata) | |
183 | lms283gf05_reset(pdata->reset_gpio, pdata->reset_inverted); | |
184 | lms283gf05_toggle(spi, disp_initseq, ARRAY_SIZE(disp_initseq)); | |
185 | ||
186 | return 0; | |
5036cc41 MV |
187 | } |
188 | ||
5036cc41 MV |
189 | static struct spi_driver lms283gf05_driver = { |
190 | .driver = { | |
191 | .name = "lms283gf05", | |
5036cc41 MV |
192 | }, |
193 | .probe = lms283gf05_probe, | |
5036cc41 MV |
194 | }; |
195 | ||
462dd838 | 196 | module_spi_driver(lms283gf05_driver); |
5036cc41 MV |
197 | |
198 | MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>"); | |
199 | MODULE_DESCRIPTION("LCD283GF05 LCD"); | |
200 | MODULE_LICENSE("GPL v2"); |