summaryrefslogtreecommitdiff
path: root/sys/arch/armv7/exynos/exdisplay.c
blob: ae52cdacfc4c9cfc8a2cb0b1f3e255895287ef4c (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
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
/* $OpenBSD: exdisplay.c,v 1.7 2021/10/24 17:52:27 mpi Exp $ */
/*
 * Copyright (c) 2013 Patrick Wildt <patrick@blueri.se>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#include <sys/param.h>
#include <sys/systm.h>
#include <sys/queue.h>
#include <sys/malloc.h>
#include <sys/device.h>
#include <sys/evcount.h>
#include <sys/socket.h>
#include <sys/timeout.h>

#include <dev/cons.h>
#include <dev/wscons/wsconsio.h>
#include <dev/wscons/wsdisplayvar.h>
#include <dev/wscons/wscons_callbacks.h>
#include <dev/wsfont/wsfont.h>
#include <dev/rasops/rasops.h>

#include <machine/intr.h>
#include <machine/bus.h>
#if NFDT > 0
#include <machine/fdt.h>
#endif
#include <armv7/armv7/armv7var.h>

/* registers */

struct exdisplay_softc {
	struct device		 sc_dev;
	bus_space_tag_t		 sc_iot;
	bus_space_handle_t	 sc_ioh;
	struct rasops_info	*ro;
};

int exdisplay_match(struct device *parent, void *v, void *aux);
void exdisplay_attach(struct device *parent, struct device *self, void *args);
int exdisplay_cnattach(bus_space_tag_t iot, bus_addr_t iobase, size_t size);
void exdisplay_setup_rasops(struct rasops_info *rinfo, struct wsscreen_descr *descr);

const struct cfattach	exdisplay_ca = {
	sizeof (struct exdisplay_softc), NULL, exdisplay_attach
};
const struct cfattach	exdisplay_fdt_ca = {
	sizeof (struct exdisplay_softc), exdisplay_match, exdisplay_attach
};

struct cfdriver exdisplay_cd = {
	NULL, "exdisplay", DV_DULL
};

int exdisplay_wsioctl(void *, u_long, caddr_t, int, struct proc *);
paddr_t exdisplay_wsmmap(void *, off_t, int);
int exdisplay_alloc_screen(void *, const struct wsscreen_descr *,
    void **, int *, int *, uint32_t *);
void exdisplay_free_screen(void *, void *);
int exdisplay_show_screen(void *, void *, int,
    void (*)(void *, int, int), void *);
void exdisplay_doswitch(void *, void *);
int exdisplay_load_font(void *, void *, struct wsdisplay_font *);
int exdisplay_list_font(void *, struct wsdisplay_font *);
int exdisplay_getchar(void *, int, int, struct wsdisplay_charcell *);
void exdisplay_burner(void *, u_int, u_int);

struct rasops_info exdisplay_ri;
struct wsscreen_descr exdisplay_stdscreen = {
	"std"
};

const struct wsscreen_descr *exdisplay_scrlist[] = {
	&exdisplay_stdscreen,
};

struct wsscreen_list exdisplay_screenlist = {
	nitems(exdisplay_scrlist), exdisplay_scrlist
};

struct wsdisplay_accessops exdisplay_accessops = {
	.ioctl = exdisplay_wsioctl,
	.mmap = exdisplay_wsmmap,
	.alloc_screen = exdisplay_alloc_screen,
	.free_screen = exdisplay_free_screen,
	.show_screen = exdisplay_show_screen,
	.getchar = exdisplay_getchar,
	.load_font = exdisplay_load_font,
	.list_font = exdisplay_list_font,
	.burn_screen = exdisplay_burner
};

int
exdisplay_match(struct device *parent, void *v, void *aux)
{
#if NFDT > 0
	struct armv7_attach_args *aa = aux;

	if (fdt_node_compatible("samsung,exynos5250-fimd", aa->aa_node))
		return 1;
#endif

	return 0;
}

void
exdisplay_attach(struct device *parent, struct device *self, void *args)
{
	struct armv7_attach_args *aa = args;
	struct exdisplay_softc *sc = (struct exdisplay_softc *) self;
	struct wsemuldisplaydev_attach_args waa;
	struct rasops_info *ri = &exdisplay_ri;
	struct armv7mem mem;

	sc->sc_iot = aa->aa_iot;
#if NFDT > 0
	if (aa->aa_node) {
		struct fdt_reg reg;
		if (fdt_get_reg(aa->aa_node, 0, &reg))
			panic("%s: could not extract memory data from FDT",
			    __func__);
		mem.addr = reg.addr;
		mem.size = reg.size;
	} else
#endif
	{
		mem.addr = aa->aa_dev->mem[0].addr;
		mem.size = aa->aa_dev->mem[0].size;
	}

	if (bus_space_map(sc->sc_iot, mem.addr, mem.size, 0, &sc->sc_ioh))
		panic("%s: bus_space_map failed!", __func__);

	printf("\n");

#if notyet
	/* FIXME: Set up framebuffer instead of re-using. */
	if (!fdt_find_compatible("simple-framebuffer")) {
		uint32_t defattr;

		ri->ri_bits = (u_char *)sc->sc_fbioh;
		exdisplay_setup_rasops(ri, &exdisplay_stdscreen);

		ri->ri_ops.pack_attr(ri->ri_active, 0, 0, 0, &defattr);
		wsdisplay_cnattach(&exdisplay_stdscreen, ri->ri_active,
		    0, 0, defattr);
	}
#endif

	sc->ro = ri;

	waa.console = 1;
	waa.scrdata = &exdisplay_screenlist;
	waa.accessops = &exdisplay_accessops;
	waa.accesscookie = sc;
	waa.defaultscreens = 0;

	printf("%s: %dx%d\n", sc->sc_dev.dv_xname, ri->ri_width, ri->ri_height);

	config_found(self, &waa, wsemuldisplaydevprint);
}

int
exdisplay_cnattach(bus_space_tag_t iot, bus_addr_t iobase, size_t size)
{
	struct wsscreen_descr *descr = &exdisplay_stdscreen;
	struct rasops_info *ri = &exdisplay_ri;
	uint32_t defattr;

	if (bus_space_map(iot, iobase, size, 0, (bus_space_handle_t *)&ri->ri_bits))
		return ENOMEM;

	exdisplay_setup_rasops(ri, descr);

	/* assumes 16 bpp */
	ri->ri_ops.pack_attr(ri, 0, 0, 0, &defattr);

	wsdisplay_cnattach(descr, ri, ri->ri_ccol, ri->ri_crow, defattr);

	return 0;
}

void
exdisplay_setup_rasops(struct rasops_info *rinfo, struct wsscreen_descr *descr)
{
	rinfo->ri_flg = RI_CLEAR;
	rinfo->ri_depth = 16;
	rinfo->ri_width = 1366;
	rinfo->ri_height = 768;
	rinfo->ri_stride = rinfo->ri_width * rinfo->ri_depth / 8;

	/* swap B and R */
	if (rinfo->ri_depth == 16) {
		rinfo->ri_rnum = 5;
		rinfo->ri_rpos = 11;
		rinfo->ri_gnum = 6;
		rinfo->ri_gpos = 5;
		rinfo->ri_bnum = 5;
		rinfo->ri_bpos = 0;
	}

	wsfont_init();
	rinfo->ri_wsfcookie = wsfont_find(NULL, 8, 0, 0);
	wsfont_lock(rinfo->ri_wsfcookie, &rinfo->ri_font,
	    WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R);

	/* get rasops to compute screen size the first time */
	rasops_init(rinfo, 200, 200);

	descr->nrows = rinfo->ri_rows;
	descr->ncols = rinfo->ri_cols;
	descr->capabilities = rinfo->ri_caps;
	descr->textops = &rinfo->ri_ops;
}

int
exdisplay_wsioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
{
	return (-1);
}

paddr_t
exdisplay_wsmmap(void *v, off_t off, int prot)
{
	return (-1);
}

int
exdisplay_alloc_screen(void *v, const struct wsscreen_descr *type,
    void **cookiep, int *curxp, int *curyp, uint32_t *attrp)
{
	struct exdisplay_softc *sc = v;
	struct rasops_info *ri = sc->ro;

	return rasops_alloc_screen(ri, cookiep, curxp, curyp, attrp);
}

void
exdisplay_free_screen(void *v, void *cookie)
{
	struct exdisplay_softc *sc = v;
	struct rasops_info *ri = sc->ro;

	return rasops_free_screen(ri, cookie);
}

int
exdisplay_show_screen(void *v, void *cookie, int waitok,
    void (*cb)(void *, int, int), void *cbarg)
{
	return (0);
}

void
exdisplay_doswitch(void *v, void *dummy)
{
}

int
exdisplay_getchar(void *v, int row, int col, struct wsdisplay_charcell *cell)
{
	struct exdisplay_softc *sc = v;
	struct rasops_info *ri = sc->ro;

	return rasops_getchar(ri, row, col, cell);
}

int
exdisplay_load_font(void *v, void *cookie, struct wsdisplay_font *font)
{
	struct exdisplay_softc *sc = v;
	struct rasops_info *ri = sc->ro;

	return rasops_load_font(ri, cookie, font);
}

int
exdisplay_list_font(void *v, struct wsdisplay_font *font)
{
	struct exdisplay_softc *sc = v;
	struct rasops_info *ri = sc->ro;

	return rasops_list_font(ri, font);
}

void
exdisplay_burner(void *v, u_int on, u_int flags)
{
}