2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
4 * Copyright (c) 2011 Jakub Wojciech Klama <jceel@FreeBSD.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/systm.h>
38 #include <sys/endian.h>
39 #include <sys/kernel.h>
40 #include <sys/kthread.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>
49 #include <sys/timetc.h>
50 #include <sys/watchdog.h>
52 #include <dev/spibus/spi.h>
54 #include <dev/ofw/ofw_bus.h>
55 #include <dev/ofw/ofw_bus_subr.h>
57 #include <arm/lpc/lpcreg.h>
58 #include <arm/lpc/lpcvar.h>
60 #include "spibus_if.h"
67 static int ssd1289_probe(device_t);
68 static int ssd1289_attach(device_t);
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);
74 static struct ssd1289_softc *ssd1289_sc = NULL;
76 void ssd1289_configure(void);
79 ssd1289_probe(device_t dev)
82 if (!ofw_bus_is_compatible(dev, "ssd1289"))
86 device_set_desc(dev, "Solomon Systech SSD1289 LCD controller");
87 return (BUS_PROBE_DEFAULT);
91 ssd1289_attach(device_t dev)
93 struct ssd1289_softc *sc = device_get_softc(dev);
102 ssd1289_configure(void)
104 struct ssd1289_softc *sc = ssd1289_sc;
106 /* XXX will be replaced with commented code */
107 ssd1289_write_reg(sc,0x00,0x0001);
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);
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);
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);
136 ssd1289_write_reg(sc,0x23,0x0000);
137 ssd1289_write_reg(sc,0x24,0x0000);
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);
144 ssd1289_write_reg(sc,0x41,0x0000);
145 ssd1289_write_reg(sc,0x42,0x0000);
147 ssd1289_write_reg(sc,0x44,0xEF00);
148 ssd1289_write_reg(sc,0x45,0x0000);
149 ssd1289_write_reg(sc,0x46,0x013F);
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);
160 ssd1289_spi_send(struct ssd1289_softc *sc, uint8_t *data, int len)
162 struct spi_command cmd;
170 SPIBUS_TRANSFER(device_get_parent(sc->ss_dev), sc->ss_dev, &cmd);
174 ssd1289_set_dc(struct ssd1289_softc *sc, int value)
176 lpc_gpio_set_state(sc->ss_dev, SSD1289_DC_PIN, value);
180 ssd1289_write_reg(struct ssd1289_softc *sc, uint16_t addr, uint16_t value)
184 ssd1289_set_dc(sc, 0);
186 buffer[1] = addr & 0xff;
187 ssd1289_spi_send(sc, buffer, 2);
189 ssd1289_set_dc(sc, 1);
190 buffer[0] = (value >> 8) & 0xff;
191 buffer[1] = value & 0xff;
192 ssd1289_spi_send(sc, buffer, 2);
195 static device_method_t ssd1289_methods[] = {
196 /* Device interface */
197 DEVMETHOD(device_probe, ssd1289_probe),
198 DEVMETHOD(device_attach, ssd1289_attach),
203 static devclass_t ssd1289_devclass;
205 static driver_t ssd1289_driver = {
208 sizeof(struct ssd1289_softc),
211 DRIVER_MODULE(ssd1289, spibus, ssd1289_driver, ssd1289_devclass, 0, 0);