2 * Copyright (c) 2011 Jakub Wojciech Klama <jceel@FreeBSD.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 #include <sys/cdefs.h>
29 __FBSDID("$FreeBSD$");
31 #include <sys/param.h>
32 #include <sys/systm.h>
36 #include <sys/endian.h>
37 #include <sys/kernel.h>
38 #include <sys/kthread.h>
40 #include <sys/malloc.h>
41 #include <sys/module.h>
42 #include <sys/mutex.h>
43 #include <sys/queue.h>
44 #include <sys/resource.h>
47 #include <sys/timetc.h>
48 #include <sys/watchdog.h>
50 #include <dev/spibus/spi.h>
52 #include <dev/ofw/ofw_bus.h>
53 #include <dev/ofw/ofw_bus_subr.h>
55 #include <arm/lpc/lpcreg.h>
56 #include <arm/lpc/lpcvar.h>
58 #include "spibus_if.h"
65 static int ssd1289_probe(device_t);
66 static int ssd1289_attach(device_t);
68 static __inline void ssd1289_set_dc(struct ssd1289_softc *, int);
69 static __inline void ssd1289_spi_send(struct ssd1289_softc *, uint8_t *, int);
70 static void ssd1289_write_reg(struct ssd1289_softc *, uint16_t, uint16_t);
72 static struct ssd1289_softc *ssd1289_sc = NULL;
74 void ssd1289_configure(void);
77 ssd1289_probe(device_t dev)
80 if (!ofw_bus_is_compatible(dev, "ssd1289"))
84 device_set_desc(dev, "Solomon Systech SSD1289 LCD controller");
85 return (BUS_PROBE_DEFAULT);
89 ssd1289_attach(device_t dev)
91 struct ssd1289_softc *sc = device_get_softc(dev);
100 ssd1289_configure(void)
102 struct ssd1289_softc *sc = ssd1289_sc;
104 /* XXX will be replaced with commented code */
105 ssd1289_write_reg(sc,0x00,0x0001);
108 ssd1289_write_reg(sc,0x03,0xA2A4);
109 ssd1289_write_reg(sc,0x0C,0x0004);
110 ssd1289_write_reg(sc,0x0D,0x0308);
111 ssd1289_write_reg(sc,0x0E,0x3000);
114 ssd1289_write_reg(sc,0x1E,0x00AF);
115 ssd1289_write_reg(sc,0x01,0x2B3F);
116 ssd1289_write_reg(sc,0x02,0x0600);
117 ssd1289_write_reg(sc,0x10,0x0000);
118 ssd1289_write_reg(sc,0x07,0x0233);
119 ssd1289_write_reg(sc,0x0B,0x0039);
120 ssd1289_write_reg(sc,0x0F,0x0000);
123 ssd1289_write_reg(sc,0x30,0x0707);
124 ssd1289_write_reg(sc,0x31,0x0204);
125 ssd1289_write_reg(sc,0x32,0x0204);
126 ssd1289_write_reg(sc,0x33,0x0502);
127 ssd1289_write_reg(sc,0x34,0x0507);
128 ssd1289_write_reg(sc,0x35,0x0204);
129 ssd1289_write_reg(sc,0x36,0x0204);
130 ssd1289_write_reg(sc,0x37,0x0502);
131 ssd1289_write_reg(sc,0x3A,0x0302);
132 ssd1289_write_reg(sc,0x3B,0x0302);
134 ssd1289_write_reg(sc,0x23,0x0000);
135 ssd1289_write_reg(sc,0x24,0x0000);
137 ssd1289_write_reg(sc,0x48,0x0000);
138 ssd1289_write_reg(sc,0x49,0x013F);
139 ssd1289_write_reg(sc,0x4A,0x0000);
140 ssd1289_write_reg(sc,0x4B,0x0000);
142 ssd1289_write_reg(sc,0x41,0x0000);
143 ssd1289_write_reg(sc,0x42,0x0000);
145 ssd1289_write_reg(sc,0x44,0xEF00);
146 ssd1289_write_reg(sc,0x45,0x0000);
147 ssd1289_write_reg(sc,0x46,0x013F);
150 ssd1289_write_reg(sc,0x44,0xEF00);
151 ssd1289_write_reg(sc,0x45,0x0000);
152 ssd1289_write_reg(sc,0x4E,0x0000);
153 ssd1289_write_reg(sc,0x4F,0x0000);
154 ssd1289_write_reg(sc,0x46,0x013F);
158 ssd1289_spi_send(struct ssd1289_softc *sc, uint8_t *data, int len)
160 struct spi_command cmd;
168 SPIBUS_TRANSFER(device_get_parent(sc->ss_dev), sc->ss_dev, &cmd);
172 ssd1289_set_dc(struct ssd1289_softc *sc, int value)
174 lpc_gpio_set_state(sc->ss_dev, SSD1289_DC_PIN, value);
178 ssd1289_write_reg(struct ssd1289_softc *sc, uint16_t addr, uint16_t value)
182 ssd1289_set_dc(sc, 0);
184 buffer[1] = addr & 0xff;
185 ssd1289_spi_send(sc, buffer, 2);
187 ssd1289_set_dc(sc, 1);
188 buffer[0] = (value >> 8) & 0xff;
189 buffer[1] = value & 0xff;
190 ssd1289_spi_send(sc, buffer, 2);
193 static device_method_t ssd1289_methods[] = {
194 /* Device interface */
195 DEVMETHOD(device_probe, ssd1289_probe),
196 DEVMETHOD(device_attach, ssd1289_attach),
201 static devclass_t ssd1289_devclass;
203 static driver_t ssd1289_driver = {
206 sizeof(struct ssd1289_softc),
209 DRIVER_MODULE(ssd1289, spibus, ssd1289_driver, ssd1289_devclass, 0, 0);