summaryrefslogtreecommitdiffstats
path: root/sys/arm/lpc/ssd1289.c
blob: cdbd49008bdb38024ec3ecb51e8c3c2329e7ebbe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*-
 * Copyright (c) 2011 Jakub Wojciech Klama <jceel@FreeBSD.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 *
 */

#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/bio.h>
#include <sys/bus.h>
#include <sys/conf.h>
#include <sys/endian.h>
#include <sys/kernel.h>
#include <sys/kthread.h>
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/module.h>
#include <sys/mutex.h>
#include <sys/queue.h>
#include <sys/resource.h>
#include <sys/rman.h>
#include <sys/time.h>
#include <sys/timetc.h>
#include <sys/watchdog.h>

#include <dev/spibus/spi.h>

#include <dev/ofw/ofw_bus.h>
#include <dev/ofw/ofw_bus_subr.h>

#include <arm/lpc/lpcreg.h>
#include <arm/lpc/lpcvar.h>

#include "spibus_if.h"

struct ssd1289_softc
{
	device_t		ss_dev;
};

static int ssd1289_probe(device_t);
static int ssd1289_attach(device_t);

static __inline void ssd1289_set_dc(struct ssd1289_softc *, int);
static __inline void ssd1289_spi_send(struct ssd1289_softc *, uint8_t *, int);
static void ssd1289_write_reg(struct ssd1289_softc *, uint16_t, uint16_t);

static struct ssd1289_softc *ssd1289_sc = NULL;

void ssd1289_configure(void);

static int
ssd1289_probe(device_t dev)
{
#if 0
	if (!ofw_bus_is_compatible(dev, "ssd1289"))
		return (ENXIO);
#endif

	device_set_desc(dev, "Solomon Systech SSD1289 LCD controller");
	return (BUS_PROBE_DEFAULT);
}

static int
ssd1289_attach(device_t dev)
{
	struct ssd1289_softc *sc = device_get_softc(dev);

	sc->ss_dev = dev;
	ssd1289_sc = sc;

	return (0);
}

void
ssd1289_configure(void)
{
	struct ssd1289_softc *sc = ssd1289_sc;

	/* XXX will be replaced with commented code */
        ssd1289_write_reg(sc,0x00,0x0001);
        DELAY(20);

        ssd1289_write_reg(sc,0x03,0xA2A4);
        ssd1289_write_reg(sc,0x0C,0x0004);
        ssd1289_write_reg(sc,0x0D,0x0308);
        ssd1289_write_reg(sc,0x0E,0x3000);
        DELAY(50);

        ssd1289_write_reg(sc,0x1E,0x00AF);
        ssd1289_write_reg(sc,0x01,0x2B3F);
        ssd1289_write_reg(sc,0x02,0x0600);
        ssd1289_write_reg(sc,0x10,0x0000);
        ssd1289_write_reg(sc,0x07,0x0233);
        ssd1289_write_reg(sc,0x0B,0x0039);
        ssd1289_write_reg(sc,0x0F,0x0000);
        DELAY(50);

        ssd1289_write_reg(sc,0x30,0x0707);
        ssd1289_write_reg(sc,0x31,0x0204);
        ssd1289_write_reg(sc,0x32,0x0204);
        ssd1289_write_reg(sc,0x33,0x0502);
        ssd1289_write_reg(sc,0x34,0x0507);
        ssd1289_write_reg(sc,0x35,0x0204);
        ssd1289_write_reg(sc,0x36,0x0204);
        ssd1289_write_reg(sc,0x37,0x0502);
        ssd1289_write_reg(sc,0x3A,0x0302);
        ssd1289_write_reg(sc,0x3B,0x0302);

        ssd1289_write_reg(sc,0x23,0x0000);
        ssd1289_write_reg(sc,0x24,0x0000);

        ssd1289_write_reg(sc,0x48,0x0000);
        ssd1289_write_reg(sc,0x49,0x013F);
        ssd1289_write_reg(sc,0x4A,0x0000);
        ssd1289_write_reg(sc,0x4B,0x0000);

        ssd1289_write_reg(sc,0x41,0x0000);
        ssd1289_write_reg(sc,0x42,0x0000);

        ssd1289_write_reg(sc,0x44,0xEF00);
        ssd1289_write_reg(sc,0x45,0x0000);
        ssd1289_write_reg(sc,0x46,0x013F);
        DELAY(50);

        ssd1289_write_reg(sc,0x44,0xEF00);
        ssd1289_write_reg(sc,0x45,0x0000);
        ssd1289_write_reg(sc,0x4E,0x0000);
        ssd1289_write_reg(sc,0x4F,0x0000);
        ssd1289_write_reg(sc,0x46,0x013F);
}

static __inline void
ssd1289_spi_send(struct ssd1289_softc *sc, uint8_t *data, int len)
{
	struct spi_command cmd;
	uint8_t buffer[8];
	cmd.tx_cmd = data;
	cmd.tx_cmd_sz = len;
	cmd.rx_cmd = buffer;
	cmd.rx_cmd_sz = len;
	cmd.tx_data_sz = 0;
	cmd.rx_data_sz = 0;
	SPIBUS_TRANSFER(device_get_parent(sc->ss_dev), sc->ss_dev, &cmd);
}

static __inline void
ssd1289_set_dc(struct ssd1289_softc *sc, int value)
{
	lpc_gpio_set_state(sc->ss_dev, SSD1289_DC_PIN, value);
}

static void
ssd1289_write_reg(struct ssd1289_softc *sc, uint16_t addr, uint16_t value)
{
	uint8_t buffer[2];

	ssd1289_set_dc(sc, 0);
	buffer[0] = 0x00;
	buffer[1] = addr & 0xff;
	ssd1289_spi_send(sc, buffer, 2);

	ssd1289_set_dc(sc, 1);
	buffer[0] = (value >> 8) & 0xff;
	buffer[1] = value & 0xff;
	ssd1289_spi_send(sc, buffer, 2);
}

static device_method_t ssd1289_methods[] = {
	/* Device interface */
	DEVMETHOD(device_probe,		ssd1289_probe),
	DEVMETHOD(device_attach,	ssd1289_attach),

	{ 0, 0 }
};

static devclass_t ssd1289_devclass;

static driver_t ssd1289_driver = {
	"ssd1289",
	ssd1289_methods,
	sizeof(struct ssd1289_softc),
};

DRIVER_MODULE(ssd1289, spibus, ssd1289_driver, ssd1289_devclass, 0, 0);
OpenPOWER on IntegriCloud