1
2
3
4
5
6
7
8#include <linux/device.h>
9#include <linux/kernel.h>
10#include <linux/delay.h>
11#include <linux/slab.h>
12#include <linux/gpio.h>
13#include <linux/lcd.h>
14
15#include <linux/spi/spi.h>
16#include <linux/spi/lms283gf05.h>
17#include <linux/module.h>
18
19struct lms283gf05_state {
20 struct spi_device *spi;
21 struct lcd_device *ld;
22};
23
24struct lms283gf05_seq {
25 unsigned char reg;
26 unsigned short value;
27 unsigned char delay;
28};
29
30
31static const struct lms283gf05_seq disp_initseq[] = {
32
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
78static const struct lms283gf05_seq disp_pdwnseq[] = {
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
93static 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
103static void lms283gf05_toggle(struct spi_device *spi,
104 const struct lms283gf05_seq *seq, int sz)
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;
128 struct lms283gf05_pdata *pdata = dev_get_platdata(&spi->dev);
129
130 if (power <= FB_BLANK_NORMAL) {
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
145static struct lcd_ops lms_ops = {
146 .set_power = lms283gf05_power_set,
147 .get_power = NULL,
148};
149
150static int lms283gf05_probe(struct spi_device *spi)
151{
152 struct lms283gf05_state *st;
153 struct lms283gf05_pdata *pdata = dev_get_platdata(&spi->dev);
154 struct lcd_device *ld;
155 int ret = 0;
156
157 if (pdata != NULL) {
158 ret = devm_gpio_request_one(&spi->dev, pdata->reset_gpio,
159 GPIOF_DIR_OUT | (!pdata->reset_inverted ?
160 GPIOF_INIT_HIGH : GPIOF_INIT_LOW),
161 "LMS283GF05 RESET");
162 if (ret)
163 return ret;
164 }
165
166 st = devm_kzalloc(&spi->dev, sizeof(struct lms283gf05_state),
167 GFP_KERNEL);
168 if (st == NULL)
169 return -ENOMEM;
170
171 ld = devm_lcd_device_register(&spi->dev, "lms283gf05", &spi->dev, st,
172 &lms_ops);
173 if (IS_ERR(ld))
174 return PTR_ERR(ld);
175
176 st->spi = spi;
177 st->ld = ld;
178
179 spi_set_drvdata(spi, st);
180
181
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;
187}
188
189static struct spi_driver lms283gf05_driver = {
190 .driver = {
191 .name = "lms283gf05",
192 },
193 .probe = lms283gf05_probe,
194};
195
196module_spi_driver(lms283gf05_driver);
197
198MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
199MODULE_DESCRIPTION("LCD283GF05 LCD");
200MODULE_LICENSE("GPL v2");
201