]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/arm/lpc/ssd1289.c
Merge ACPICA 20180105.
[FreeBSD/FreeBSD.git] / sys / arm / lpc / ssd1289.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 2011 Jakub Wojciech Klama <jceel@FreeBSD.org>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  */
29
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/bio.h>
36 #include <sys/bus.h>
37 #include <sys/conf.h>
38 #include <sys/endian.h>
39 #include <sys/kernel.h>
40 #include <sys/kthread.h>
41 #include <sys/lock.h>
42 #include <sys/malloc.h>
43 #include <sys/module.h>
44 #include <sys/mutex.h>
45 #include <sys/queue.h>
46 #include <sys/resource.h>
47 #include <sys/rman.h>
48 #include <sys/time.h>
49 #include <sys/timetc.h>
50 #include <sys/watchdog.h>
51
52 #include <dev/spibus/spi.h>
53
54 #include <dev/ofw/ofw_bus.h>
55 #include <dev/ofw/ofw_bus_subr.h>
56
57 #include <arm/lpc/lpcreg.h>
58 #include <arm/lpc/lpcvar.h>
59
60 #include "spibus_if.h"
61
62 struct ssd1289_softc
63 {
64         device_t                ss_dev;
65 };
66
67 static int ssd1289_probe(device_t);
68 static int ssd1289_attach(device_t);
69
70 static __inline void ssd1289_set_dc(struct ssd1289_softc *, int);
71 static __inline void ssd1289_spi_send(struct ssd1289_softc *, uint8_t *, int);
72 static void ssd1289_write_reg(struct ssd1289_softc *, uint16_t, uint16_t);
73
74 static struct ssd1289_softc *ssd1289_sc = NULL;
75
76 void ssd1289_configure(void);
77
78 static int
79 ssd1289_probe(device_t dev)
80 {
81 #if 0
82         if (!ofw_bus_is_compatible(dev, "ssd1289"))
83                 return (ENXIO);
84 #endif
85
86         device_set_desc(dev, "Solomon Systech SSD1289 LCD controller");
87         return (BUS_PROBE_DEFAULT);
88 }
89
90 static int
91 ssd1289_attach(device_t dev)
92 {
93         struct ssd1289_softc *sc = device_get_softc(dev);
94
95         sc->ss_dev = dev;
96         ssd1289_sc = sc;
97
98         return (0);
99 }
100
101 void
102 ssd1289_configure(void)
103 {
104         struct ssd1289_softc *sc = ssd1289_sc;
105
106         /* XXX will be replaced with commented code */
107         ssd1289_write_reg(sc,0x00,0x0001);
108         DELAY(20);
109
110         ssd1289_write_reg(sc,0x03,0xA2A4);
111         ssd1289_write_reg(sc,0x0C,0x0004);
112         ssd1289_write_reg(sc,0x0D,0x0308);
113         ssd1289_write_reg(sc,0x0E,0x3000);
114         DELAY(50);
115
116         ssd1289_write_reg(sc,0x1E,0x00AF);
117         ssd1289_write_reg(sc,0x01,0x2B3F);
118         ssd1289_write_reg(sc,0x02,0x0600);
119         ssd1289_write_reg(sc,0x10,0x0000);
120         ssd1289_write_reg(sc,0x07,0x0233);
121         ssd1289_write_reg(sc,0x0B,0x0039);
122         ssd1289_write_reg(sc,0x0F,0x0000);
123         DELAY(50);
124
125         ssd1289_write_reg(sc,0x30,0x0707);
126         ssd1289_write_reg(sc,0x31,0x0204);
127         ssd1289_write_reg(sc,0x32,0x0204);
128         ssd1289_write_reg(sc,0x33,0x0502);
129         ssd1289_write_reg(sc,0x34,0x0507);
130         ssd1289_write_reg(sc,0x35,0x0204);
131         ssd1289_write_reg(sc,0x36,0x0204);
132         ssd1289_write_reg(sc,0x37,0x0502);
133         ssd1289_write_reg(sc,0x3A,0x0302);
134         ssd1289_write_reg(sc,0x3B,0x0302);
135
136         ssd1289_write_reg(sc,0x23,0x0000);
137         ssd1289_write_reg(sc,0x24,0x0000);
138
139         ssd1289_write_reg(sc,0x48,0x0000);
140         ssd1289_write_reg(sc,0x49,0x013F);
141         ssd1289_write_reg(sc,0x4A,0x0000);
142         ssd1289_write_reg(sc,0x4B,0x0000);
143
144         ssd1289_write_reg(sc,0x41,0x0000);
145         ssd1289_write_reg(sc,0x42,0x0000);
146
147         ssd1289_write_reg(sc,0x44,0xEF00);
148         ssd1289_write_reg(sc,0x45,0x0000);
149         ssd1289_write_reg(sc,0x46,0x013F);
150         DELAY(50);
151
152         ssd1289_write_reg(sc,0x44,0xEF00);
153         ssd1289_write_reg(sc,0x45,0x0000);
154         ssd1289_write_reg(sc,0x4E,0x0000);
155         ssd1289_write_reg(sc,0x4F,0x0000);
156         ssd1289_write_reg(sc,0x46,0x013F);
157 }
158
159 static __inline void
160 ssd1289_spi_send(struct ssd1289_softc *sc, uint8_t *data, int len)
161 {
162         struct spi_command cmd;
163         uint8_t buffer[8];
164         cmd.tx_cmd = data;
165         cmd.tx_cmd_sz = len;
166         cmd.rx_cmd = buffer;
167         cmd.rx_cmd_sz = len;
168         cmd.tx_data_sz = 0;
169         cmd.rx_data_sz = 0;
170         SPIBUS_TRANSFER(device_get_parent(sc->ss_dev), sc->ss_dev, &cmd);
171 }
172
173 static __inline void
174 ssd1289_set_dc(struct ssd1289_softc *sc, int value)
175 {
176         lpc_gpio_set_state(sc->ss_dev, SSD1289_DC_PIN, value);
177 }
178
179 static void
180 ssd1289_write_reg(struct ssd1289_softc *sc, uint16_t addr, uint16_t value)
181 {
182         uint8_t buffer[2];
183
184         ssd1289_set_dc(sc, 0);
185         buffer[0] = 0x00;
186         buffer[1] = addr & 0xff;
187         ssd1289_spi_send(sc, buffer, 2);
188
189         ssd1289_set_dc(sc, 1);
190         buffer[0] = (value >> 8) & 0xff;
191         buffer[1] = value & 0xff;
192         ssd1289_spi_send(sc, buffer, 2);
193 }
194
195 static device_method_t ssd1289_methods[] = {
196         /* Device interface */
197         DEVMETHOD(device_probe,         ssd1289_probe),
198         DEVMETHOD(device_attach,        ssd1289_attach),
199
200         { 0, 0 }
201 };
202
203 static devclass_t ssd1289_devclass;
204
205 static driver_t ssd1289_driver = {
206         "ssd1289",
207         ssd1289_methods,
208         sizeof(struct ssd1289_softc),
209 };
210
211 DRIVER_MODULE(ssd1289, spibus, ssd1289_driver, ssd1289_devclass, 0, 0);