tft.c revision 1.2.72.1 1 /* $NetBSD: tft.c,v 1.2.72.1 2011/06/06 09:05:33 jruoho Exp $ */
2
3 /*
4 * Copyright (c) 2006 Jachym Holecek
5 * All rights reserved.
6 *
7 * Written for DFC Design, s.r.o.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 *
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 *
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: tft.c,v 1.2.72.1 2011/06/06 09:05:33 jruoho Exp $");
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/mbuf.h>
38 #include <sys/kernel.h>
39 #include <sys/socket.h>
40 #include <sys/ioctl.h>
41 #include <sys/device.h>
42 #include <sys/queue.h>
43
44 #include <uvm/uvm_extern.h>
45
46 #include <machine/bus.h>
47
48 #include <dev/wscons/wsdisplayvar.h>
49 #include <dev/wscons/wsconsio.h>
50 #include <dev/wsfont/wsfont.h>
51 #include <dev/rasops/rasops.h>
52 #include <dev/splash/splash.h>
53 #include <dev/wscons/wsdisplay_vconsvar.h>
54
55 #include <evbppc/virtex/dev/tftreg.h>
56 #include <evbppc/virtex/dev/tftvar.h>
57
58
59 /* Template. */
60 static struct wsscreen_descr tft_screen = {
61 .name = "fb",
62 .fontwidth = 8,
63 .fontheight = 16,
64 .capabilities = (WSSCREEN_WSCOLORS | WSSCREEN_HILIT |
65 WSSCREEN_UNDERLINE | WSSCREEN_REVERSE),
66 };
67
68 static void tft_init_screen(void *, struct vcons_screen *, int, long *);
69
70
71 void
72 tft_attach(device_t self, struct wsdisplay_accessops *accessops)
73 {
74 struct wsemuldisplaydev_attach_args waa;
75 struct tft_softc *sc = device_private(self);
76 struct rasops_info *ri;
77 long defattr;
78
79 KASSERT(accessops->mmap);
80
81 if (accessops->ioctl == NULL)
82 accessops->ioctl = tft_ioctl;
83
84 printf("%s: %ux%ux%ub\n", device_xname(self), sc->sc_width,
85 sc->sc_height, sc->sc_bpp);
86 printf("%s: video memory va %p size %uB stride %uB\n",
87 device_xname(self), sc->sc_image, sc->sc_size, sc->sc_stride);
88
89 memset(sc->sc_image, 0xf0, sc->sc_size);
90
91 /* Setup descr template, make up list. */
92 sc->sc_ws_descr_storage[0] = tft_screen; /* struct copy */
93 sc->sc_ws_descr = sc->sc_ws_descr_storage;
94 sc->sc_ws_scrlist.nscreens = 1;
95 sc->sc_ws_scrlist.screens =
96 (const struct wsscreen_descr **)&sc->sc_ws_descr;
97
98 vcons_init(&sc->sc_vc_data, self, sc->sc_ws_descr, accessops);
99
100 sc->sc_vc_screen.scr_flags |= VCONS_SCREEN_IS_STATIC;
101 sc->sc_vc_data.init_screen = tft_init_screen;
102 sc->sc_vc_data.cookie = sc;
103
104 vcons_init_screen(&sc->sc_vc_data, &sc->sc_vc_screen, 1, &defattr);
105
106 /* Patch descr. */
107 ri = &sc->sc_vc_screen.scr_ri;
108 sc->sc_ws_descr->textops = &ri->ri_ops;
109 sc->sc_ws_descr->capabilities = ri->ri_caps;
110 sc->sc_ws_descr->nrows = ri->ri_rows;
111 sc->sc_ws_descr->ncols = ri->ri_cols;
112
113 #ifdef SPLASHSCREEN
114 sc->sc_sp_info.si_depth = ri->ri_depth;
115 sc->sc_sp_info.si_bits = ri->ri_bits;
116 sc->sc_sp_info.si_hwbits = ri->ri_hwbits;
117 sc->sc_sp_info.si_width = ri->ri_width;
118 sc->sc_sp_info.si_height = ri->ri_height;
119 sc->sc_sp_info.si_stride = ri->ri_stride;
120 sc->sc_sp_info.si_fillrect = NULL;
121
122 if (splash_render(&sc->sc_sp_info, SPLASH_F_CENTER|SPLASH_F_FILL) == 0)
123 SCREEN_DISABLE_DRAWING(&sc->sc_vc_screen);
124 #endif
125
126 if (sc->sc_sdhook == NULL) {
127 sc->sc_sdhook = shutdownhook_establish(tft_shutdown, self);
128 if (sc->sc_sdhook == NULL)
129 printf("%s: WARNING: unable to establish shutdown "
130 "hook\n", device_xname(self));
131 }
132
133 waa.console = 0; /* XXX */
134 waa.scrdata = &sc->sc_ws_scrlist;
135 waa.accessops = accessops;
136 waa.accesscookie = &sc->sc_vc_data;
137
138 config_found(self, &waa, wsemuldisplaydevprint);
139 }
140
141 static void
142 tft_init_screen(void *cookie, struct vcons_screen *scr, int existing,
143 long *defattr)
144 {
145 struct tft_softc *sc = cookie;
146 struct rasops_info *ri = &scr->scr_ri;
147
148 /* initialize font subsystem */
149 wsfont_init();
150
151 ri->ri_depth = sc->sc_bpp;
152 ri->ri_width = sc->sc_width;
153 ri->ri_height = sc->sc_height;
154 ri->ri_stride = sc->sc_stride;
155 ri->ri_flg = /*RI_CENTER |*/ RI_CLEAR;
156 ri->ri_bits = (void *)sc->sc_image;
157 ri->ri_caps = WSSCREEN_WSCOLORS;
158
159 ri->ri_rnum = 8;
160 ri->ri_gnum = 8;
161 ri->ri_bnum = 8;
162 ri->ri_rpos = 16;
163 ri->ri_gpos = 8;
164 ri->ri_bpos = 0;
165
166 rasops_init(ri, ri->ri_height / 16, ri->ri_width / 8);
167
168 /* we'd override rasops methods now if we had acceleration */
169 }
170
171 void
172 tft_shutdown(void *arg)
173 {
174 struct tft_softc *sc = arg;
175
176 bus_space_write_4(sc->sc_iot, sc->sc_ioh, TFT_CTRL, CTRL_RESET);
177 }
178
179 int
180 tft_mode(device_t dev)
181 {
182 struct tft_softc *sc = device_private(dev);
183 prop_number_t pn;
184
185 /* Defaults for tft core generics. */
186 sc->sc_width = 640;
187 sc->sc_height = 480;
188 sc->sc_stride = 1024 * 4;
189 sc->sc_bpp = 32; /* 24bit colour, not packed */
190
191 /* We can make all these mandatory if it becomes practical... */
192 pn = prop_dictionary_get(device_properties(dev), "x-resolution");
193 if (pn != NULL)
194 sc->sc_width = (u_int)prop_number_integer_value(pn);
195
196 pn = prop_dictionary_get(device_properties(dev), "y-resolution");
197 if (pn != NULL)
198 sc->sc_height = (u_int)prop_number_integer_value(pn);
199
200 pn = prop_dictionary_get(device_properties(dev), "stride-bytes");
201 if (pn != NULL)
202 sc->sc_stride = (u_int)prop_number_integer_value(pn);
203
204 pn = prop_dictionary_get(device_properties(dev), "bits-per-pixel");
205 if (pn != NULL)
206 sc->sc_bpp = (u_int)prop_number_integer_value(pn);
207
208 sc->sc_size = sc->sc_stride * sc->sc_height;
209 return (0);
210 }
211
212 int
213 tft_ioctl(void *arg, void *scr, u_long cmd, void *data, int flag,
214 struct lwp *l)
215 {
216 struct vcons_data *vd = arg;
217 struct tft_softc *sc = vd->cookie;
218 struct wsdisplay_fbinfo *info;
219
220 switch (cmd) {
221 case WSDISPLAYIO_GTYPE:
222 *(u_int *)data = WSDISPLAY_TYPE_XILFB;
223 return (0);
224
225 case WSDISPLAYIO_GINFO:
226 info = (struct wsdisplay_fbinfo *)data;
227
228 info->height = sc->sc_height;
229 info->width = sc->sc_width;
230 info->depth = sc->sc_bpp;
231 info->cmsize = 0;
232
233 return (0);
234 case WSDISPLAYIO_LINEBYTES:
235 *(u_int *)data = sc->sc_stride;
236
237 return (0);
238 }
239
240 return (EPASSTHROUGH);
241 }
242