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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
|
/* $OpenBSD: moko_lcd.c,v 1.1 2009/07/14 14:09:05 drahn Exp $ */
/* $NetBSD: smdk2410_lcd.c,v 1.4 2008/06/11 23:24:43 cegger Exp $ */
/*
* Copyright (c) 2004 Genetec Corporation. All rights reserved.
* Written by Hiroyuki Bessho for Genetec Corporation.
*
* 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.
* 3. The name of Genetec Corporation may not be used to endorse or
* promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``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 GENETEC CORPORATION
* 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.
*
*/
/*
* LCD driver for Samsung SMDK2410.
*
* Controlling LCD is almost completely done through S3C2410's
* integrated LCD controller. Codes for it is arm/s3c2xx0/s3c24x0_lcd.c.
*
* Codes in this file provide the platform's LCD panel information.
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/conf.h>
#include <sys/event.h>
#include <sys/uio.h>
#include <sys/malloc.h>
#include <dev/cons.h>
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsdisplayvar.h>
#include <dev/wscons/wscons_callbacks.h>
#include <machine/bus.h>
#include <arm/s3c2xx0/s3c24x0var.h>
#include <arm/s3c2xx0/s3c24x0reg.h>
#include <arm/s3c2xx0/s3c2410reg.h>
#include <arm/s3c2xx0/s3c24x0_lcd.h>
#include "wsdisplay.h"
int lcd_match(struct device *, void *, void *);
void lcd_attach(struct device *, struct device *, void *);
#ifdef LCD_DEBUG
void draw_test_pattern(struct s3c24x0_lcd_softc *,
struct s3c24x0_lcd_screen *scr);
#endif
#if NWSDISPLAY > 0
/*
* Screen geometries.
*
* S3C24x0's LCD controller can have virtual screens that are bigger
* than actual LCD panel. (XXX: wscons can't manage such screens for now)
*/
struct s3c24x0_wsscreen_descr lcd_bpp16_std =
{
{
"std",
},
16 /* bits per pixel */
};
static const struct wsscreen_descr *lcd_scr_descr[] = {
&lcd_bpp16_std.c,
};
#define N_SCR_DESCR (sizeof lcd_scr_descr / sizeof lcd_scr_descr[0])
const struct wsscreen_list lcd_screen_list = {
N_SCR_DESCR,
lcd_scr_descr
};
void lcd_burner(void *v, u_int on, u_int flags);
const struct wsdisplay_accessops lcd_accessops = {
s3c24x0_lcd_ioctl,
s3c24x0_lcd_mmap,
s3c24x0_lcd_alloc_screen,
s3c24x0_lcd_free_screen,
s3c24x0_lcd_show_screen,
NULL, /* load_font */
NULL, /* scrollback */
NULL, /* getchar */
lcd_burner
};
#else /* NWSDISPLAY */
/*
* Interface to LCD framebuffer without wscons
*/
extern struct cfdriver lcd_cd;
dev_type_open(lcdopen);
dev_type_close(lcdclose);
dev_type_ioctl(lcdioctl);
dev_type_mmap(lcdmmap);
const struct cdevsw lcd_cdevsw = {
lcdopen, lcdclose, noread, nowrite, lcdioctl,
nostop, notty, nopoll, lcdmmap, nokqfilter, D_TTY
};
#endif /* NWSDISPLAY */
struct cfattach lcd_ssio_ca = {
sizeof (struct s3c24x0_lcd_softc), lcd_match, lcd_attach
};
struct cfdriver lcd_cd = {
NULL, "lcd", DV_DULL
};
int
lcd_match(struct device *parent, void *v, void *aux)
{
struct s3c2xx0_attach_args *sa = aux;
extern uint32_t hardware_type;
if ((hardware_type & 0xff00) != 0x0100)
return 0; /* NOT GTA01 */
if (sa->sa_addr == 0)
sa->sa_addr = S3C2410_LCDC_BASE;
return 1;
}
static struct s3c24x0_lcd_panel_info moko_glass =
{
480, /* Width */
640, /* Height */
66500000/2, /*XXX *//* pixel clock = 10MHz */
#define _(field, val) (((val)-1) << (field##_SHIFT))
LCDCON1_PNRMODE_TFT|LCDCON1_BPPMODE_TFT16,
/* LCDCON2: vertical timings */
/* _(LCDCON2_VBPD, 2) |
_(LCDCON2_VFPD, 3) |
_(LCDCON2_LINEVAL, 320) |
_(LCDCON2_VPSW, 2) */ 0x19fc3c1,
/* LCDCON3: horizontal timings */
/* _(LCDCON3_HBPD, 7) |
_(LCDCON3_HFPD, 3) */ 0x39df67,
/* LCDCON4: horizontaol pulse width */
_(LCDCON4_HPSW, 8),
/* LCDCON5: signal polarities */
LCDCON5_FRM565 | LCDCON5_INVVCLK| LCDCON5_INVVLINE | LCDCON5_INVVFRAME |
LCDCON5_PWREN | LCDCON5_HWSWP,
/* LPCSEL register */
LPCSEL_MODE_SEL,
#undef _
};
void
lcd_attach(struct device *parent, struct device *self, void *aux)
{
struct s3c24x0_lcd_softc *sc = (struct s3c24x0_lcd_softc *)self;
bus_space_tag_t iot = s3c2xx0_softc->sc_iot;
bus_space_handle_t gpio_ioh = s3c2xx0_softc->sc_gpio_ioh;
#if NWSDISPLAY > 0
struct wsemuldisplaydev_attach_args aa;
#else
struct s3c24x0_lcd_screen *screen;
#endif
printf( "\n" );
/* setup GPIO ports for LCD */
/* XXX: some LCD panels may not need all VD signals */
gpio_ioh = s3c2xx0_softc->sc_gpio_ioh;
bus_space_write_4(iot, gpio_ioh, GPIO_PCUP, ~0);
bus_space_write_4(iot, gpio_ioh, GPIO_PCCON, 0xaaaaaaaa);
bus_space_write_4(iot, gpio_ioh, GPIO_PDUP, ~0);
bus_space_write_4(iot, gpio_ioh, GPIO_PDCON, 0xaaaaaaaa);
s3c24x0_lcd_attach_sub(sc, aux, &moko_glass);
#if NWSDISPLAY > 0
aa.console = 0;
aa.scrdata = &lcd_screen_list;
aa.accessops = &lcd_accessops;
aa.accesscookie = sc;
aa.defaultscreens = 0; /* default */
(void) config_found(self, &aa, wsemuldisplaydevprint);
#else
screen = s3c24x0_lcd_new_screen(sc, 240, 320, 16);
if( screen ){
sc->active = screen;
s3c24x0_lcd_start_dma(sc, screen);
s3c24x0_lcd_power(sc, 1);
}
#endif /* NWSDISPLAY */
}
#if NWSDISPLAY == 0
int
lcdopen( dev_t dev, int oflags, int devtype, struct proc *p )
{
return 0;
}
int
lcdclose( dev_t dev, int fflag, int devtype, struct proc *p )
{
return 0;
}
paddr_t
lcdmmap( dev_t dev, off_t offset, int size )
{
struct s3c24x0_lcd_softc *sc =
device_lookup_private(&lcd_cd, minor(dev));
struct s3c24x0_lcd_screen *scr = sc->active;
return bus_dmamem_mmap(sc->dma_tag, scr->segs, scr->nsegs,
offset, 0, BUS_DMA_WAITOK|BUS_DMA_COHERENT);
}
int
lcdioctl( dev_t dev, u_long cmd, void *data,
int fflag, struct lwp *l )
{
return EOPNOTSUPP;
}
#endif /* NWSDISPLAY>0 */
void
lcd_burner(void *v, u_int on, u_int flags)
{
#if 0
lcd_set_brightness(on ? lcd_get_brightness() : 0);
#endif
}
#ifdef LCD_DEBUG
static void
draw_test_pattern_16(struct s3c24x0_lcd_softc *sc,
struct s3c24x0_lcd_screen *scr)
{
int x, y;
uint16_t color, *line;
char *buf = (char *)(scr->buf_va);
#define rgb(r,g,b) (((r)<<11) | ((g)<<5) | (b))
for (y=0; y < sc->panel_info->panel_height; ++y) {
line = (uint16_t *)(buf + scr->stride * y);
for (x=0; x < sc->panel_info->panel_width; ++x) {
switch (((x/30) + (y/10)) % 8) {
default:
case 0: color = rgb(0x00, 0x00, 0x00); break;
case 1: color = rgb(0x00, 0x00, 0x1f); break;
case 2: color = rgb(0x00, 0x3f, 0x00); break;
case 3: color = rgb(0x00, 0x3f, 0x1f); break;
case 4: color = rgb(0x1f, 0x00, 0x00); break;
case 5: color = rgb(0x1f, 0x00, 0x1f); break;
case 6: color = rgb(0x1f, 0x3f, 0x00); break;
case 7: color = rgb(0x1f, 0x3f, 0x1f); break;
}
line[x] = color;
}
}
for (x=0; x < MIN(sc->panel_info->panel_height,
sc->panel_info->panel_width); ++x) {
line = (uint16_t *)(buf + scr->stride * x);
line[x] = rgb(0x1f, 0x3f, 0x1f);
}
}
static void
draw_test_pattern_8(struct s3c24x0_lcd_softc *sc,
struct s3c24x0_lcd_screen *scr)
{
int x, y;
uint8_t *line;
char *buf = (char *)(scr->buf_va);
for (y=0; y < sc->panel_info->panel_height; ++y) {
line = (uint8_t *)(buf + scr->stride * y);
for (x=0; x < sc->panel_info->panel_width; ++x) {
line[x] = (((x/15) + (y/20)) % 16);
}
}
for (x=0; x < MIN(sc->panel_info->panel_height,
sc->panel_info->panel_width); ++x) {
line = (uint8_t *)(buf + scr->stride * x);
line[x] = 7;
}
}
void
draw_test_pattern(struct s3c24x0_lcd_softc *sc, struct s3c24x0_lcd_screen *scr)
{
switch (scr->depth) {
case 16:
draw_test_pattern_16(sc, scr);
break;
case 8:
draw_test_pattern_8(sc, scr);
break;
}
}
#endif /* LCD_DEBUG */
|