ssdfb.c revision 1.13 1 1.13 thorpej /* $NetBSD: ssdfb.c,v 1.13 2021/04/24 23:36:55 thorpej Exp $ */
2 1.1 tnn
3 1.1 tnn /*
4 1.1 tnn * Copyright (c) 2019 The NetBSD Foundation, Inc.
5 1.1 tnn * All rights reserved.
6 1.1 tnn *
7 1.1 tnn * This code is derived from software contributed to The NetBSD Foundation
8 1.1 tnn * by Tobias Nygren.
9 1.1 tnn *
10 1.1 tnn * Redistribution and use in source and binary forms, with or without
11 1.1 tnn * modification, are permitted provided that the following conditions
12 1.1 tnn * are met:
13 1.1 tnn * 1. Redistributions of source code must retain the above copyright
14 1.1 tnn * notice, this list of conditions and the following disclaimer.
15 1.1 tnn * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 tnn * notice, this list of conditions and the following disclaimer in the
17 1.1 tnn * documentation and/or other materials provided with the distribution.
18 1.1 tnn *
19 1.1 tnn * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 tnn * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 tnn * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 tnn * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 tnn * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 tnn * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 tnn * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 tnn * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 tnn * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 tnn * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 tnn * POSSIBILITY OF SUCH DAMAGE.
30 1.1 tnn */
31 1.1 tnn
32 1.1 tnn #include <sys/cdefs.h>
33 1.13 thorpej __KERNEL_RCSID(0, "$NetBSD: ssdfb.c,v 1.13 2021/04/24 23:36:55 thorpej Exp $");
34 1.1 tnn
35 1.1 tnn #include "opt_ddb.h"
36 1.1 tnn
37 1.1 tnn #include <sys/param.h>
38 1.1 tnn #include <sys/kernel.h>
39 1.3 tnn #include <sys/conf.h>
40 1.1 tnn #include <sys/condvar.h>
41 1.1 tnn #include <sys/kmem.h>
42 1.1 tnn #include <sys/kthread.h>
43 1.12 riastrad
44 1.12 riastrad #include <uvm/uvm_device.h>
45 1.12 riastrad #include <uvm/uvm_extern.h>
46 1.12 riastrad
47 1.1 tnn #include <dev/wscons/wsdisplayvar.h>
48 1.1 tnn #include <dev/rasops/rasops.h>
49 1.1 tnn #include <dev/ic/ssdfbvar.h>
50 1.1 tnn
51 1.1 tnn #if defined(DDB)
52 1.1 tnn #include <machine/db_machdep.h>
53 1.1 tnn #include <ddb/db_extern.h>
54 1.1 tnn #endif
55 1.1 tnn
56 1.1 tnn /* userland interface */
57 1.1 tnn static int ssdfb_ioctl(void *, void *, u_long, void *, int, struct lwp *);
58 1.1 tnn static paddr_t ssdfb_mmap(void *, void *, off_t, int);
59 1.1 tnn
60 1.1 tnn /* wscons screen management */
61 1.1 tnn static int ssdfb_alloc_screen(void *, const struct wsscreen_descr *,
62 1.1 tnn void **, int *, int *, long *);
63 1.1 tnn static void ssdfb_free_screen(void *, void *);
64 1.1 tnn static int ssdfb_show_screen(void *, void *, int,
65 1.1 tnn void (*cb) (void *, int, int), void *);
66 1.1 tnn
67 1.1 tnn /* rasops hooks */
68 1.1 tnn static void ssdfb_putchar(void *, int, int, u_int, long);
69 1.1 tnn static void ssdfb_copycols(void *, int, int, int, int);
70 1.1 tnn static void ssdfb_erasecols(void *, int, int, int, long);
71 1.1 tnn static void ssdfb_copyrows(void *, int, int, int);
72 1.1 tnn static void ssdfb_eraserows(void *, int, int, long);
73 1.1 tnn static void ssdfb_cursor(void *, int, int, int);
74 1.1 tnn
75 1.1 tnn /* hardware interface */
76 1.8 tnn static int ssdfb_init_ssd1306(struct ssdfb_softc *);
77 1.9 tnn static int ssdfb_init_ssd1322(struct ssdfb_softc *);
78 1.1 tnn static int ssdfb_set_contrast(struct ssdfb_softc *, uint8_t, bool);
79 1.1 tnn static int ssdfb_set_display_on(struct ssdfb_softc *, bool, bool);
80 1.1 tnn static int ssdfb_set_mode(struct ssdfb_softc *, u_int);
81 1.1 tnn
82 1.1 tnn /* frame buffer damage tracking and synchronization */
83 1.3 tnn static void ssdfb_udv_attach(struct ssdfb_softc *sc);
84 1.1 tnn static bool ssdfb_is_modified(struct ssdfb_softc *sc);
85 1.1 tnn static bool ssdfb_clear_modify(struct ssdfb_softc *sc);
86 1.1 tnn static void ssdfb_damage(struct ssdfb_softc *);
87 1.1 tnn static void ssdfb_thread(void *);
88 1.1 tnn static void ssdfb_set_usepoll(struct ssdfb_softc *, bool);
89 1.1 tnn static int ssdfb_sync(struct ssdfb_softc *, bool);
90 1.9 tnn static int ssdfb_sync_ssd1306(struct ssdfb_softc *, bool);
91 1.9 tnn static int ssdfb_sync_ssd1322(struct ssdfb_softc *, bool);
92 1.9 tnn static uint64_t ssdfb_transpose_block(uint8_t *, size_t);
93 1.1 tnn
94 1.1 tnn /* misc helpers */
95 1.1 tnn static const struct ssdfb_product *
96 1.1 tnn ssdfb_lookup_product(ssdfb_product_id_t);
97 1.1 tnn static int ssdfb_pick_font(int *, struct wsdisplay_font **);
98 1.1 tnn static void ssdfb_clear_screen(struct ssdfb_softc *);
99 1.1 tnn #if defined(DDB)
100 1.1 tnn static void ssdfb_ddb_trap_callback(int);
101 1.1 tnn #endif
102 1.1 tnn
103 1.1 tnn static const char *ssdfb_controller_names[] = {
104 1.1 tnn [SSDFB_CONTROLLER_UNKNOWN] = "unknown",
105 1.1 tnn [SSDFB_CONTROLLER_SSD1306] = "Solomon Systech SSD1306",
106 1.8 tnn [SSDFB_CONTROLLER_SH1106] = "Sino Wealth SH1106",
107 1.8 tnn [SSDFB_CONTROLLER_SSD1322] = "Solomon Systech SSD1322"
108 1.1 tnn };
109 1.1 tnn
110 1.1 tnn /*
111 1.1 tnn * Display module assemblies supported by this driver.
112 1.1 tnn */
113 1.1 tnn static const struct ssdfb_product ssdfb_products[] = {
114 1.1 tnn {
115 1.1 tnn .p_product_id = SSDFB_PRODUCT_SSD1306_GENERIC,
116 1.1 tnn .p_controller_id = SSDFB_CONTROLLER_SSD1306,
117 1.1 tnn .p_name = "generic",
118 1.1 tnn .p_width = 128,
119 1.1 tnn .p_height = 64,
120 1.9 tnn .p_bits_per_pixel = 1,
121 1.1 tnn .p_panel_shift = 0,
122 1.1 tnn .p_fosc = 0x8,
123 1.1 tnn .p_fosc_div = 0,
124 1.1 tnn .p_precharge = 0x1,
125 1.1 tnn .p_discharge = 0xf,
126 1.1 tnn .p_compin_cfg = SSDFB_COM_PINS_A1_MASK
127 1.1 tnn | SSDFB_COM_PINS_ALTERNATIVE_MASK,
128 1.1 tnn .p_vcomh_deselect_level = SSD1306_VCOMH_DESELECT_LEVEL_0_77_VCC,
129 1.1 tnn .p_default_contrast = 0x7f,
130 1.1 tnn .p_multiplex_ratio = 0x3f,
131 1.9 tnn .p_init = ssdfb_init_ssd1306,
132 1.9 tnn .p_sync = ssdfb_sync_ssd1306
133 1.1 tnn },
134 1.1 tnn {
135 1.1 tnn .p_product_id = SSDFB_PRODUCT_SH1106_GENERIC,
136 1.1 tnn .p_controller_id = SSDFB_CONTROLLER_SH1106,
137 1.1 tnn .p_name = "generic",
138 1.1 tnn .p_width = 128,
139 1.1 tnn .p_height = 64,
140 1.9 tnn .p_bits_per_pixel = 1,
141 1.1 tnn .p_panel_shift = 2,
142 1.1 tnn .p_fosc = 0x5,
143 1.1 tnn .p_fosc_div = 0,
144 1.1 tnn .p_precharge = 0x2,
145 1.1 tnn .p_discharge = 0x2,
146 1.1 tnn .p_compin_cfg = SSDFB_COM_PINS_A1_MASK
147 1.1 tnn | SSDFB_COM_PINS_ALTERNATIVE_MASK,
148 1.1 tnn .p_vcomh_deselect_level = SH1106_VCOMH_DESELECT_LEVEL_DEFAULT,
149 1.1 tnn .p_default_contrast = 0x80,
150 1.1 tnn .p_multiplex_ratio = 0x3f,
151 1.9 tnn .p_init = ssdfb_init_ssd1306,
152 1.9 tnn .p_sync = ssdfb_sync_ssd1306
153 1.1 tnn },
154 1.1 tnn {
155 1.1 tnn .p_product_id = SSDFB_PRODUCT_ADAFRUIT_938,
156 1.1 tnn .p_controller_id = SSDFB_CONTROLLER_SSD1306,
157 1.1 tnn .p_name = "Adafruit Industries, LLC product 938",
158 1.1 tnn .p_width = 128,
159 1.1 tnn .p_height = 64,
160 1.9 tnn .p_bits_per_pixel = 1,
161 1.1 tnn .p_panel_shift = 0,
162 1.1 tnn .p_fosc = 0x8,
163 1.1 tnn .p_fosc_div = 0,
164 1.1 tnn .p_precharge = 0x1,
165 1.1 tnn .p_discharge = 0xf,
166 1.1 tnn .p_compin_cfg = 0x12,
167 1.1 tnn .p_vcomh_deselect_level = 0x40,
168 1.1 tnn .p_default_contrast = 0x8f,
169 1.1 tnn .p_multiplex_ratio = 0x3f,
170 1.9 tnn .p_init = ssdfb_init_ssd1306,
171 1.9 tnn .p_sync = ssdfb_sync_ssd1306
172 1.1 tnn },
173 1.1 tnn {
174 1.1 tnn .p_product_id = SSDFB_PRODUCT_ADAFRUIT_931,
175 1.1 tnn .p_controller_id = SSDFB_CONTROLLER_SSD1306,
176 1.1 tnn .p_name = "Adafruit Industries, LLC product 931",
177 1.1 tnn .p_width = 128,
178 1.1 tnn .p_height = 32,
179 1.9 tnn .p_bits_per_pixel = 1,
180 1.1 tnn .p_panel_shift = 0,
181 1.1 tnn .p_fosc = 0x8,
182 1.1 tnn .p_fosc_div = 0,
183 1.1 tnn .p_precharge = 0x1,
184 1.1 tnn .p_discharge = 0xf,
185 1.1 tnn .p_compin_cfg = 0x2,
186 1.1 tnn .p_vcomh_deselect_level = 0x40,
187 1.1 tnn .p_default_contrast = 0x8f,
188 1.1 tnn .p_multiplex_ratio = 0x1f,
189 1.9 tnn .p_init = ssdfb_init_ssd1306,
190 1.9 tnn .p_sync = ssdfb_sync_ssd1306
191 1.9 tnn },
192 1.9 tnn {
193 1.9 tnn .p_product_id = SSDFB_PRODUCT_SSD1322_GENERIC,
194 1.9 tnn .p_controller_id = SSDFB_CONTROLLER_SSD1322,
195 1.9 tnn .p_name = "generic",
196 1.9 tnn .p_width = 256,
197 1.9 tnn .p_height = 64,
198 1.9 tnn .p_bits_per_pixel = 4,
199 1.9 tnn .p_panel_shift = 28,
200 1.9 tnn .p_vcomh_deselect_level = SSD1322_DEFAULT_VCOMH,
201 1.9 tnn .p_fosc = SSD1322_DEFAULT_FREQUENCY,
202 1.9 tnn .p_fosc_div = SSD1322_DEFAULT_DIVIDER,
203 1.9 tnn .p_default_contrast = SSD1322_DEFAULT_CONTRAST_CURRENT,
204 1.9 tnn .p_multiplex_ratio = 0x3f,
205 1.9 tnn .p_init = ssdfb_init_ssd1322,
206 1.9 tnn .p_sync = ssdfb_sync_ssd1322
207 1.1 tnn }
208 1.1 tnn };
209 1.1 tnn
210 1.1 tnn static const struct wsdisplay_accessops ssdfb_accessops = {
211 1.1 tnn .ioctl = ssdfb_ioctl,
212 1.1 tnn .mmap = ssdfb_mmap,
213 1.1 tnn .alloc_screen = ssdfb_alloc_screen,
214 1.1 tnn .free_screen = ssdfb_free_screen,
215 1.1 tnn .show_screen = ssdfb_show_screen
216 1.1 tnn };
217 1.1 tnn
218 1.1 tnn #define SSDFB_CMD1(c) do { cmd[0] = (c); error = sc->sc_cmd(sc->sc_cookie, cmd, 1, usepoll); } while(0)
219 1.1 tnn #define SSDFB_CMD2(c, a) do { cmd[0] = (c); cmd[1] = (a); error = sc->sc_cmd(sc->sc_cookie, cmd, 2, usepoll); } while(0)
220 1.9 tnn #define SSDFB_CMD3(c, a, b) do { cmd[0] = (c); cmd[1] = (a); cmd[2] = (b); error = sc->sc_cmd(sc->sc_cookie, cmd, 3, usepoll); } while(0)
221 1.1 tnn
222 1.1 tnn void
223 1.1 tnn ssdfb_attach(struct ssdfb_softc *sc, int flags)
224 1.1 tnn {
225 1.1 tnn struct wsemuldisplaydev_attach_args aa;
226 1.1 tnn struct rasops_info *ri = &sc->sc_ri;
227 1.1 tnn int error = 0;
228 1.1 tnn long defattr;
229 1.1 tnn const struct ssdfb_product *p;
230 1.9 tnn int kt_flags;
231 1.1 tnn
232 1.1 tnn p = ssdfb_lookup_product(flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK);
233 1.1 tnn if (p == NULL) {
234 1.1 tnn aprint_error(": unknown display assembly\n");
235 1.1 tnn return;
236 1.1 tnn }
237 1.1 tnn sc->sc_p = p;
238 1.1 tnn
239 1.1 tnn aprint_naive("\n");
240 1.1 tnn aprint_normal(": %s (%s)\n",
241 1.1 tnn ssdfb_controller_names[p->p_controller_id],
242 1.1 tnn p->p_name);
243 1.1 tnn
244 1.1 tnn sc->sc_mode = WSDISPLAYIO_MODE_EMUL;
245 1.1 tnn sc->sc_is_console = flags & SSDFB_ATTACH_FLAG_CONSOLE ? true : false;
246 1.1 tnn sc->sc_inverse = flags & SSDFB_ATTACH_FLAG_INVERSE ? true : false;
247 1.1 tnn sc->sc_upsidedown = flags & SSDFB_ATTACH_FLAG_UPSIDEDOWN ? true : false;
248 1.1 tnn sc->sc_backoff = 1;
249 1.1 tnn sc->sc_contrast = sc->sc_p->p_default_contrast;
250 1.9 tnn sc->sc_gddram_len = sc->sc_p->p_width * sc->sc_p->p_height
251 1.9 tnn * sc->sc_p->p_bits_per_pixel / 8;
252 1.1 tnn sc->sc_gddram = kmem_alloc(sc->sc_gddram_len, KM_SLEEP);
253 1.1 tnn if (sc->sc_gddram == NULL)
254 1.1 tnn goto out;
255 1.1 tnn
256 1.1 tnn aprint_normal_dev(sc->sc_dev, "%dx%d%s\n", sc->sc_p->p_width,
257 1.1 tnn sc->sc_p->p_height, sc->sc_is_console ? ", console" : "");
258 1.1 tnn
259 1.1 tnn /*
260 1.1 tnn * Initialize rasops. The native depth is 1-bit monochrome and we
261 1.1 tnn * support this in text emul mode via rasops1. But modern Xorg
262 1.1 tnn * userland has many rendering glitches when running with 1-bit depth
263 1.1 tnn * so to better support this use case we instead declare ourselves as
264 1.1 tnn * an 8-bit display with a two entry constant color map.
265 1.1 tnn */
266 1.1 tnn error = ssdfb_pick_font(&sc->sc_fontcookie, &sc->sc_font);
267 1.1 tnn if (error) {
268 1.1 tnn aprint_error_dev(sc->sc_dev, "no font\n");
269 1.1 tnn goto out;
270 1.1 tnn }
271 1.9 tnn #ifdef SSDFB_USE_NATIVE_DEPTH
272 1.9 tnn ri->ri_depth = sc->sc_p->p_bits_per_pixel;
273 1.9 tnn #else
274 1.1 tnn ri->ri_depth = 8;
275 1.9 tnn #endif
276 1.1 tnn ri->ri_font = sc->sc_font;
277 1.1 tnn ri->ri_width = sc->sc_p->p_width;
278 1.1 tnn ri->ri_height = sc->sc_p->p_height;
279 1.1 tnn ri->ri_stride = ri->ri_width * ri->ri_depth / 8;
280 1.1 tnn ri->ri_hw = sc;
281 1.9 tnn ri->ri_flg = RI_FULLCLEAR | RI_FORCEMONO;
282 1.1 tnn sc->sc_ri_bits_len = round_page(ri->ri_stride * ri->ri_height);
283 1.1 tnn ri->ri_bits = (u_char *)uvm_km_alloc(kernel_map, sc->sc_ri_bits_len,
284 1.1 tnn 0, UVM_KMF_WIRED);
285 1.1 tnn if (ri->ri_bits == NULL)
286 1.1 tnn goto out;
287 1.1 tnn
288 1.1 tnn error = rasops_init(ri,
289 1.1 tnn sc->sc_p->p_height / sc->sc_font->fontheight,
290 1.1 tnn sc->sc_p->p_width / sc->sc_font->fontwidth);
291 1.1 tnn if (error)
292 1.1 tnn goto out;
293 1.1 tnn
294 1.1 tnn ri->ri_caps &= ~WSSCREEN_WSCOLORS;
295 1.1 tnn
296 1.1 tnn /*
297 1.1 tnn * Save original emul ops & insert our damage notification hooks.
298 1.1 tnn */
299 1.1 tnn sc->sc_orig_riops = ri->ri_ops;
300 1.1 tnn ri->ri_ops.putchar = ssdfb_putchar;
301 1.1 tnn ri->ri_ops.copycols = ssdfb_copycols;
302 1.1 tnn ri->ri_ops.erasecols = ssdfb_erasecols;
303 1.1 tnn ri->ri_ops.copyrows = ssdfb_copyrows;
304 1.1 tnn ri->ri_ops.eraserows = ssdfb_eraserows;
305 1.1 tnn ri->ri_ops.cursor = ssdfb_cursor;
306 1.1 tnn
307 1.1 tnn /*
308 1.1 tnn * Set up the screen.
309 1.1 tnn */
310 1.1 tnn sc->sc_screen_descr = (struct wsscreen_descr){
311 1.1 tnn .name = "default",
312 1.1 tnn .ncols = ri->ri_cols,
313 1.1 tnn .nrows = ri->ri_rows,
314 1.1 tnn .textops = &ri->ri_ops,
315 1.1 tnn .fontwidth = ri->ri_font->fontwidth,
316 1.1 tnn .fontheight = ri->ri_font->fontheight,
317 1.1 tnn .capabilities = ri->ri_caps
318 1.1 tnn };
319 1.1 tnn sc->sc_screens[0] = &sc->sc_screen_descr;
320 1.1 tnn sc->sc_screenlist = (struct wsscreen_list){
321 1.1 tnn .nscreens = 1,
322 1.1 tnn .screens = sc->sc_screens
323 1.1 tnn };
324 1.1 tnn
325 1.1 tnn /*
326 1.1 tnn * Initialize hardware.
327 1.1 tnn */
328 1.8 tnn error = p->p_init(sc);
329 1.1 tnn if (error)
330 1.1 tnn goto out;
331 1.1 tnn
332 1.1 tnn if (sc->sc_is_console)
333 1.1 tnn ssdfb_set_usepoll(sc, true);
334 1.1 tnn
335 1.10 tnn mutex_init(&sc->sc_cond_mtx, MUTEX_DEFAULT,
336 1.10 tnn ISSET(flags, SSDFB_ATTACH_FLAG_MPSAFE) ? IPL_SCHED : IPL_BIO);
337 1.1 tnn cv_init(&sc->sc_cond, "ssdfb");
338 1.9 tnn kt_flags = KTHREAD_MUSTJOIN;
339 1.9 tnn /* XXX spi(4) is not MPSAFE yet. */
340 1.9 tnn if (ISSET(flags, SSDFB_ATTACH_FLAG_MPSAFE))
341 1.9 tnn kt_flags |= KTHREAD_MPSAFE;
342 1.9 tnn error = kthread_create(PRI_SOFTCLOCK, kt_flags, NULL, ssdfb_thread, sc,
343 1.9 tnn &sc->sc_thread, "%s", device_xname(sc->sc_dev));
344 1.1 tnn if (error) {
345 1.1 tnn cv_destroy(&sc->sc_cond);
346 1.1 tnn mutex_destroy(&sc->sc_cond_mtx);
347 1.1 tnn goto out;
348 1.1 tnn }
349 1.1 tnn
350 1.1 tnn /*
351 1.1 tnn * Attach wsdisplay.
352 1.1 tnn */
353 1.1 tnn if (sc->sc_is_console) {
354 1.1 tnn (*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
355 1.1 tnn wsdisplay_cnattach(&sc->sc_screen_descr, ri, 0, 0, defattr);
356 1.1 tnn #if defined(DDB)
357 1.1 tnn db_trap_callback = ssdfb_ddb_trap_callback;
358 1.1 tnn #endif
359 1.1 tnn }
360 1.1 tnn aa = (struct wsemuldisplaydev_attach_args){
361 1.1 tnn .console = sc->sc_is_console,
362 1.1 tnn .scrdata = &sc->sc_screenlist,
363 1.1 tnn .accessops = &ssdfb_accessops,
364 1.1 tnn .accesscookie = sc
365 1.1 tnn };
366 1.1 tnn sc->sc_wsdisplay =
367 1.13 thorpej config_found(sc->sc_dev, &aa, wsemuldisplaydevprint, CFARG_EOL);
368 1.1 tnn
369 1.1 tnn return;
370 1.1 tnn out:
371 1.1 tnn aprint_error_dev(sc->sc_dev, "attach failed: %d\n", error);
372 1.1 tnn if (sc->sc_gddram != NULL)
373 1.1 tnn kmem_free(sc->sc_gddram, sc->sc_gddram_len);
374 1.1 tnn if (ri->ri_bits != NULL)
375 1.1 tnn uvm_km_free(kernel_map, (vaddr_t)ri->ri_bits, sc->sc_ri_bits_len,
376 1.1 tnn UVM_KMF_WIRED);
377 1.1 tnn if (sc->sc_fontcookie > 0)
378 1.1 tnn (void) wsfont_unlock(sc->sc_fontcookie);
379 1.1 tnn }
380 1.1 tnn
381 1.1 tnn int
382 1.1 tnn ssdfb_detach(struct ssdfb_softc *sc)
383 1.1 tnn {
384 1.1 tnn mutex_enter(&sc->sc_cond_mtx);
385 1.1 tnn sc->sc_detaching = true;
386 1.1 tnn cv_broadcast(&sc->sc_cond);
387 1.1 tnn mutex_exit(&sc->sc_cond_mtx);
388 1.1 tnn kthread_join(sc->sc_thread);
389 1.1 tnn
390 1.3 tnn if (sc->sc_uobj != NULL) {
391 1.11 ad rw_enter(sc->sc_uobj->vmobjlock, RW_WRITER);
392 1.3 tnn sc->sc_uobj->uo_refs--;
393 1.11 ad rw_exit(sc->sc_uobj->vmobjlock);
394 1.3 tnn }
395 1.1 tnn config_detach(sc->sc_wsdisplay, DETACH_FORCE);
396 1.1 tnn
397 1.1 tnn cv_destroy(&sc->sc_cond);
398 1.1 tnn mutex_destroy(&sc->sc_cond_mtx);
399 1.1 tnn uvm_km_free(kernel_map, (vaddr_t)sc->sc_ri.ri_bits, sc->sc_ri_bits_len,
400 1.1 tnn UVM_KMF_WIRED);
401 1.1 tnn kmem_free(sc->sc_gddram, sc->sc_gddram_len);
402 1.1 tnn (void) wsfont_unlock(sc->sc_fontcookie);
403 1.1 tnn return 0;
404 1.1 tnn }
405 1.1 tnn
406 1.1 tnn static int
407 1.1 tnn ssdfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
408 1.1 tnn {
409 1.1 tnn struct ssdfb_softc *sc = v;
410 1.1 tnn struct wsdisplay_param *wdp;
411 1.1 tnn struct wsdisplay_cmap *wc;
412 1.9 tnn u_char cmap[16];
413 1.9 tnn int cmaplen = 1 << sc->sc_p->p_bits_per_pixel;
414 1.9 tnn int i;
415 1.9 tnn struct wsdisplayio_fbinfo *fbi;
416 1.1 tnn int error;
417 1.1 tnn
418 1.1 tnn switch (cmd) {
419 1.1 tnn case WSDISPLAYIO_GTYPE:
420 1.1 tnn *(u_int *)data = WSDISPLAY_TYPE_SSDFB;
421 1.1 tnn return 0;
422 1.1 tnn case WSDISPLAYIO_GINFO:
423 1.1 tnn *(struct wsdisplay_fbinfo *)data = (struct wsdisplay_fbinfo){
424 1.1 tnn .width = sc->sc_ri.ri_width,
425 1.1 tnn .height = sc->sc_ri.ri_height,
426 1.1 tnn .depth = sc->sc_ri.ri_depth,
427 1.9 tnn .cmsize = cmaplen
428 1.1 tnn };
429 1.1 tnn return 0;
430 1.1 tnn case WSDISPLAYIO_GET_FBINFO:
431 1.9 tnn fbi = (struct wsdisplayio_fbinfo *)data;
432 1.9 tnn error = wsdisplayio_get_fbinfo(&sc->sc_ri, fbi);
433 1.9 tnn fbi->fbi_subtype.fbi_cmapinfo.cmap_entries = cmaplen;
434 1.9 tnn /* fbi->fbi_pixeltype = WSFB_GREYSCALE */;
435 1.9 tnn return error;
436 1.1 tnn case WSDISPLAYIO_LINEBYTES:
437 1.1 tnn *(u_int *)data = sc->sc_ri.ri_stride;
438 1.1 tnn return 0;
439 1.1 tnn case WSDISPLAYIO_GETPARAM:
440 1.1 tnn wdp = (struct wsdisplay_param *)data;
441 1.1 tnn if (wdp->param != WSDISPLAYIO_PARAM_CONTRAST)
442 1.1 tnn return EINVAL;
443 1.1 tnn wdp->min = 0;
444 1.1 tnn wdp->max = 0xff;
445 1.1 tnn wdp->curval = sc->sc_contrast;
446 1.1 tnn return 0;
447 1.1 tnn case WSDISPLAYIO_SETPARAM:
448 1.1 tnn wdp = (struct wsdisplay_param *)data;
449 1.1 tnn if (wdp->param != WSDISPLAYIO_PARAM_CONTRAST)
450 1.1 tnn return EINVAL;
451 1.1 tnn if (wdp->curval < 0 || wdp->curval > 0xff)
452 1.1 tnn return EINVAL;
453 1.1 tnn return ssdfb_set_contrast(sc, wdp->curval, sc->sc_usepoll);
454 1.1 tnn case WSDISPLAYIO_GMODE:
455 1.1 tnn *(u_int *)data = sc->sc_mode;
456 1.1 tnn return 0;
457 1.1 tnn case WSDISPLAYIO_SMODE:
458 1.1 tnn return ssdfb_set_mode(sc, *(u_int *)data);
459 1.1 tnn case WSDISPLAYIO_GVIDEO:
460 1.1 tnn *(u_int *)data = sc->sc_display_on
461 1.1 tnn ? WSDISPLAYIO_VIDEO_ON
462 1.1 tnn : WSDISPLAYIO_VIDEO_OFF;
463 1.1 tnn return 0;
464 1.1 tnn case WSDISPLAYIO_SVIDEO:
465 1.1 tnn switch (*(u_int *)data) {
466 1.1 tnn case WSDISPLAYIO_VIDEO_ON:
467 1.1 tnn case WSDISPLAYIO_VIDEO_OFF:
468 1.1 tnn break;
469 1.1 tnn default:
470 1.1 tnn return EINVAL;
471 1.1 tnn }
472 1.1 tnn return ssdfb_set_display_on(sc,
473 1.1 tnn *(u_int *)data == WSDISPLAYIO_VIDEO_ON ? true : false,
474 1.1 tnn sc->sc_usepoll);
475 1.1 tnn #if 0 /* don't let userland mess with polling yet */
476 1.1 tnn case WSDISPLAYIO_SET_POLLING:
477 1.1 tnn switch (*(u_int *)data) {
478 1.1 tnn case 0:
479 1.1 tnn case 1:
480 1.1 tnn break;
481 1.1 tnn default:
482 1.1 tnn return EINVAL;
483 1.1 tnn }
484 1.1 tnn mutex_enter(&sc->sc_cond_mtx);
485 1.1 tnn ssdfb_set_usepoll(sc, *(u_int *)data ? true : false);
486 1.1 tnn cv_broadcast(&sc->sc_cond);
487 1.1 tnn mutex_exit(&sc->sc_cond_mtx);
488 1.1 tnn return 0;
489 1.1 tnn #endif
490 1.1 tnn case WSDISPLAYIO_GETCMAP:
491 1.1 tnn wc = (struct wsdisplay_cmap *)data;
492 1.9 tnn if (wc->index >= cmaplen ||
493 1.9 tnn wc->count > cmaplen - wc->index)
494 1.1 tnn return EINVAL;
495 1.9 tnn for(i = 0; i < cmaplen; i++) {
496 1.9 tnn cmap[i] = 255 * i / (cmaplen - 1);
497 1.9 tnn }
498 1.1 tnn error = copyout(&cmap[wc->index], wc->red, wc->count);
499 1.1 tnn if (error)
500 1.1 tnn return error;
501 1.1 tnn error = copyout(&cmap[wc->index], wc->green, wc->count);
502 1.1 tnn if (error)
503 1.1 tnn return error;
504 1.1 tnn error = copyout(&cmap[wc->index], wc->blue, wc->count);
505 1.1 tnn return error;
506 1.1 tnn case WSDISPLAYIO_PUTCMAP:
507 1.1 tnn return ENODEV;
508 1.1 tnn }
509 1.1 tnn
510 1.1 tnn return EPASSTHROUGH;
511 1.1 tnn }
512 1.1 tnn
513 1.1 tnn static paddr_t
514 1.1 tnn ssdfb_mmap(void *v, void *vs, off_t off, int prot)
515 1.1 tnn {
516 1.1 tnn struct ssdfb_softc *sc = (struct ssdfb_softc *)v;
517 1.1 tnn struct rasops_info *ri = &sc->sc_ri;
518 1.1 tnn vaddr_t va_base = (vaddr_t)ri->ri_bits;
519 1.1 tnn paddr_t pa;
520 1.1 tnn
521 1.1 tnn if (off < 0 || off >= sc->sc_ri_bits_len || (off & PAGE_MASK) != 0)
522 1.1 tnn return -1;
523 1.1 tnn
524 1.1 tnn if (!pmap_extract(pmap_kernel(), va_base + off, &pa))
525 1.1 tnn return -1;
526 1.1 tnn
527 1.1 tnn return atop(pa);
528 1.1 tnn }
529 1.1 tnn
530 1.1 tnn static int
531 1.1 tnn ssdfb_alloc_screen(void *v, const struct wsscreen_descr *descr, void **cookiep,
532 1.1 tnn int *curxp, int *curyp, long *attrp)
533 1.1 tnn {
534 1.1 tnn struct ssdfb_softc *sc = v;
535 1.1 tnn struct rasops_info *ri = &sc->sc_ri;
536 1.1 tnn
537 1.1 tnn if (sc->sc_nscreens > 0)
538 1.1 tnn return ENOMEM;
539 1.1 tnn
540 1.1 tnn ri->ri_ops.allocattr(ri, 0, 0, 0, attrp);
541 1.1 tnn *cookiep = &sc->sc_ri;
542 1.1 tnn *curxp = 0;
543 1.1 tnn *curyp = 0;
544 1.1 tnn sc->sc_nscreens++;
545 1.1 tnn
546 1.1 tnn return 0;
547 1.1 tnn }
548 1.1 tnn
549 1.1 tnn static void
550 1.1 tnn ssdfb_free_screen(void *v, void *cookie)
551 1.1 tnn {
552 1.1 tnn struct ssdfb_softc *sc = v;
553 1.1 tnn
554 1.1 tnn if (sc->sc_is_console)
555 1.1 tnn panic("ssdfb_free_screen: is console");
556 1.1 tnn
557 1.1 tnn sc->sc_nscreens--;
558 1.1 tnn }
559 1.1 tnn
560 1.1 tnn static int
561 1.1 tnn ssdfb_show_screen(void *v, void *cookie, int waitok,
562 1.1 tnn void (*cb) (void *, int, int), void *cb_arg)
563 1.1 tnn {
564 1.1 tnn return 0;
565 1.1 tnn }
566 1.1 tnn
567 1.1 tnn static void
568 1.1 tnn ssdfb_putchar(void *cookie, int row, int col, u_int c, long attr)
569 1.1 tnn {
570 1.1 tnn struct rasops_info *ri = (struct rasops_info *)cookie;
571 1.1 tnn struct ssdfb_softc *sc = ri->ri_hw;
572 1.1 tnn
573 1.1 tnn sc->sc_orig_riops.putchar(cookie, row, col, c, attr);
574 1.1 tnn ssdfb_damage(sc);
575 1.1 tnn }
576 1.1 tnn
577 1.1 tnn static void
578 1.1 tnn ssdfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols)
579 1.1 tnn {
580 1.1 tnn struct rasops_info *ri = (struct rasops_info *)cookie;
581 1.1 tnn struct ssdfb_softc *sc = ri->ri_hw;
582 1.1 tnn
583 1.1 tnn sc->sc_orig_riops.copycols(cookie, row, srccol, dstcol, ncols);
584 1.1 tnn ssdfb_damage(sc);
585 1.1 tnn }
586 1.1 tnn
587 1.1 tnn static void
588 1.1 tnn ssdfb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr)
589 1.1 tnn {
590 1.1 tnn struct rasops_info *ri = (struct rasops_info *)cookie;
591 1.1 tnn struct ssdfb_softc *sc = ri->ri_hw;
592 1.1 tnn
593 1.1 tnn sc->sc_orig_riops.erasecols(cookie, row, startcol, ncols, fillattr);
594 1.1 tnn ssdfb_damage(sc);
595 1.1 tnn }
596 1.1 tnn
597 1.1 tnn static void
598 1.1 tnn ssdfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows)
599 1.1 tnn {
600 1.1 tnn struct rasops_info *ri = (struct rasops_info *)cookie;
601 1.1 tnn struct ssdfb_softc *sc = ri->ri_hw;
602 1.1 tnn
603 1.1 tnn sc->sc_orig_riops.copyrows(cookie, srcrow, dstrow, nrows);
604 1.1 tnn ssdfb_damage(sc);
605 1.1 tnn }
606 1.1 tnn
607 1.1 tnn static void
608 1.1 tnn ssdfb_eraserows(void *cookie, int row, int nrows, long fillattr)
609 1.1 tnn {
610 1.1 tnn struct rasops_info *ri = (struct rasops_info *)cookie;
611 1.1 tnn struct ssdfb_softc *sc = ri->ri_hw;
612 1.1 tnn
613 1.1 tnn sc->sc_orig_riops.eraserows(cookie, row, nrows, fillattr);
614 1.1 tnn ssdfb_damage(sc);
615 1.1 tnn }
616 1.1 tnn
617 1.1 tnn static void
618 1.1 tnn ssdfb_cursor(void *cookie, int on, int row, int col)
619 1.1 tnn {
620 1.1 tnn struct rasops_info *ri = (struct rasops_info *)cookie;
621 1.1 tnn struct ssdfb_softc *sc = ri->ri_hw;
622 1.1 tnn
623 1.1 tnn sc->sc_orig_riops.cursor(cookie, on, row, col);
624 1.1 tnn ssdfb_damage(sc);
625 1.1 tnn }
626 1.1 tnn
627 1.1 tnn static int
628 1.8 tnn ssdfb_init_ssd1306(struct ssdfb_softc *sc)
629 1.1 tnn {
630 1.1 tnn int error;
631 1.3 tnn uint8_t cmd[2];
632 1.1 tnn bool usepoll = true;
633 1.1 tnn
634 1.1 tnn /*
635 1.1 tnn * Enter sleep.
636 1.1 tnn */
637 1.1 tnn SSDFB_CMD1(SSDFB_CMD_SET_DISPLAY_OFF);
638 1.1 tnn if (error)
639 1.1 tnn return error;
640 1.1 tnn SSDFB_CMD1(SSDFB_CMD_DEACTIVATE_SCROLL);
641 1.1 tnn if (error)
642 1.1 tnn return error;
643 1.1 tnn SSDFB_CMD1(SSDFB_CMD_ENTIRE_DISPLAY_OFF);
644 1.1 tnn if (error)
645 1.1 tnn return error;
646 1.1 tnn
647 1.1 tnn /*
648 1.1 tnn * Configure physical display panel layout.
649 1.1 tnn */
650 1.1 tnn SSDFB_CMD2(SSDFB_CMD_SET_MULTIPLEX_RATIO, sc->sc_p->p_multiplex_ratio);
651 1.1 tnn if (error)
652 1.1 tnn return error;
653 1.1 tnn SSDFB_CMD2(SSDFB_CMD_SET_DISPLAY_OFFSET, 0);
654 1.1 tnn if (error)
655 1.1 tnn return error;
656 1.1 tnn SSDFB_CMD1(SSDFB_CMD_SET_DISPLAY_START_LINE_BASE + 0x00);
657 1.1 tnn if (error)
658 1.1 tnn return error;
659 1.1 tnn SSDFB_CMD2(SSDFB_CMD_SET_COM_PINS_HARDWARE_CFG, sc->sc_p->p_compin_cfg);
660 1.1 tnn if (error)
661 1.1 tnn return error;
662 1.1 tnn if (sc->sc_upsidedown) {
663 1.1 tnn SSDFB_CMD1(SSDFB_CMD_SET_SEGMENT_REMAP_REVERSE);
664 1.1 tnn if (error)
665 1.1 tnn return error;
666 1.1 tnn SSDFB_CMD1(SSDFB_CMD_SET_COM_OUTPUT_DIRECTION_REMAP);
667 1.1 tnn if (error)
668 1.1 tnn return error;
669 1.1 tnn } else {
670 1.1 tnn SSDFB_CMD1(SSDFB_CMD_SET_SEGMENT_REMAP_NORMAL);
671 1.1 tnn if (error)
672 1.1 tnn return error;
673 1.1 tnn SSDFB_CMD1(SSDFB_CMD_SET_COM_OUTPUT_DIRECTION_NORMAL);
674 1.1 tnn if (error)
675 1.1 tnn return error;
676 1.1 tnn }
677 1.1 tnn SSDFB_CMD1(SSDFB_CMD_SET_NORMAL_DISPLAY + (uint8_t)sc->sc_inverse);
678 1.1 tnn if (error)
679 1.1 tnn return error;
680 1.1 tnn
681 1.1 tnn /*
682 1.1 tnn * Configure timing characteristics.
683 1.1 tnn */
684 1.1 tnn SSDFB_CMD2(SSDFB_CMD_SET_DISPLAY_CLOCK_RATIO,
685 1.7 tnn __SHIFTIN(sc->sc_p->p_fosc, SSDFB_DISPLAY_CLOCK_OSCILLATOR_MASK) |
686 1.7 tnn __SHIFTIN(sc->sc_p->p_fosc_div, SSDFB_DISPLAY_CLOCK_DIVIDER_MASK));
687 1.1 tnn if (error)
688 1.1 tnn return error;
689 1.1 tnn SSDFB_CMD2(SSDFB_CMD_SET_CONTRAST_CONTROL, sc->sc_contrast);
690 1.1 tnn if (error)
691 1.1 tnn return error;
692 1.1 tnn SSDFB_CMD2(SSDFB_CMD_SET_PRECHARGE_PERIOD,
693 1.7 tnn __SHIFTIN(sc->sc_p->p_precharge, SSDFB_PRECHARGE_MASK) |
694 1.7 tnn __SHIFTIN(sc->sc_p->p_discharge, SSDFB_DISCHARGE_MASK));
695 1.1 tnn if (error)
696 1.1 tnn return error;
697 1.1 tnn SSDFB_CMD2(SSDFB_CMD_SET_VCOMH_DESELECT_LEVEL,
698 1.1 tnn sc->sc_p->p_vcomh_deselect_level);
699 1.1 tnn if (error)
700 1.1 tnn return error;
701 1.1 tnn
702 1.1 tnn /*
703 1.9 tnn * Start charge pumps.
704 1.1 tnn */
705 1.1 tnn if (sc->sc_p->p_controller_id == SSDFB_CONTROLLER_SH1106) {
706 1.9 tnn SSDFB_CMD1(SH1106_CMD_SET_CHARGE_PUMP_7V4);
707 1.9 tnn if (error)
708 1.9 tnn return error;
709 1.1 tnn SSDFB_CMD2(SH1106_CMD_SET_DC_DC, SH1106_DC_DC_ON);
710 1.1 tnn if (error)
711 1.1 tnn return error;
712 1.9 tnn } else {
713 1.9 tnn SSDFB_CMD2(SSD1306_CMD_SET_CHARGE_PUMP,
714 1.9 tnn SSD1306_CHARGE_PUMP_ENABLE);
715 1.9 tnn if (error)
716 1.9 tnn return error;
717 1.1 tnn }
718 1.1 tnn
719 1.1 tnn ssdfb_clear_screen(sc);
720 1.9 tnn error = sc->sc_p->p_sync(sc, usepoll);
721 1.9 tnn if (error)
722 1.9 tnn return error;
723 1.9 tnn error = ssdfb_set_display_on(sc, true, usepoll);
724 1.9 tnn
725 1.9 tnn return error;
726 1.9 tnn }
727 1.9 tnn
728 1.9 tnn static int
729 1.9 tnn ssdfb_init_ssd1322(struct ssdfb_softc *sc)
730 1.9 tnn {
731 1.9 tnn int error;
732 1.9 tnn uint8_t cmd[3];
733 1.9 tnn bool usepoll = true;
734 1.9 tnn uint8_t remap;
735 1.9 tnn uint8_t dualcom;
736 1.9 tnn
737 1.9 tnn /*
738 1.9 tnn * Enter sleep.
739 1.9 tnn */
740 1.9 tnn SSDFB_CMD2(SSD1322_CMD_SET_COMMAND_LOCK, SSD1322_COMMAND_UNLOCK_MAGIC);
741 1.9 tnn if (error)
742 1.9 tnn return error;
743 1.9 tnn SSDFB_CMD1(SSD1322_CMD_SET_SLEEP_MODE_ON);
744 1.9 tnn if (error)
745 1.9 tnn return error;
746 1.9 tnn
747 1.9 tnn /*
748 1.9 tnn * Start charge pumps.
749 1.9 tnn */
750 1.9 tnn SSDFB_CMD2(SSD1322_CMD_FUNCTION_SELECTION,
751 1.9 tnn SSD1322_FUNCTION_SELECTION_INTERNAL_VDD);
752 1.9 tnn if (error)
753 1.9 tnn return error;
754 1.9 tnn SSDFB_CMD2(SSD1322_CMD_SET_VCOMH, sc->sc_p->p_vcomh_deselect_level);
755 1.9 tnn if (error)
756 1.9 tnn return error;
757 1.9 tnn SSDFB_CMD2(SSD1322_CMD_SET_PRE_CHARGE_VOLTAGE_LEVEL,
758 1.9 tnn SSD1322_DEFAULT_PRE_CHARGE_VOLTAGE_LEVEL);
759 1.9 tnn if (error)
760 1.9 tnn return error;
761 1.9 tnn SSDFB_CMD2(SSD1322_CMD_SET_GPIO,
762 1.9 tnn SSD1322_GPIO0_DISABLED | SSD1322_GPIO1_DISABLED);
763 1.9 tnn if (error)
764 1.9 tnn return error;
765 1.9 tnn
766 1.9 tnn /*
767 1.9 tnn * Configure timing characteristics.
768 1.9 tnn */
769 1.9 tnn SSDFB_CMD2(SSD1322_CMD_SET_FRONT_CLOCK_DIVIDER,
770 1.9 tnn __SHIFTIN(sc->sc_p->p_fosc, SSD1322_FREQUENCY_MASK) |
771 1.9 tnn __SHIFTIN(sc->sc_p->p_fosc_div, SSD1322_DIVIDER_MASK));
772 1.9 tnn if (error)
773 1.9 tnn return error;
774 1.9 tnn SSDFB_CMD2(SSD1322_CMD_SET_PHASE_LENGTH,
775 1.9 tnn __SHIFTIN(SSD1322_DEFAULT_PHASE_2,
776 1.9 tnn SSD1322_PHASE_LENGTH_PHASE_2_MASK) |
777 1.9 tnn __SHIFTIN(SSD1322_DEFAULT_PHASE_1,
778 1.9 tnn SSD1322_PHASE_LENGTH_PHASE_1_MASK));
779 1.9 tnn if (error)
780 1.9 tnn return error;
781 1.9 tnn SSDFB_CMD2(SSD1322_CMD_SET_SECOND_PRECHARGE_PERIOD,
782 1.9 tnn SSD1322_DEFAULT_SECOND_PRECHARGE);
783 1.9 tnn if (error)
784 1.9 tnn return error;
785 1.9 tnn
786 1.9 tnn /*
787 1.9 tnn * Configure physical display panel layout.
788 1.9 tnn */
789 1.9 tnn SSDFB_CMD2(SSD1322_CMD_SET_MUX_RATIO, sc->sc_p->p_multiplex_ratio);
790 1.9 tnn if (error)
791 1.9 tnn return error;
792 1.9 tnn if (sc->sc_upsidedown)
793 1.9 tnn remap = 0x10;
794 1.9 tnn else
795 1.9 tnn remap = 0x2;
796 1.9 tnn dualcom = 0x1;
797 1.9 tnn if (sc->sc_p->p_multiplex_ratio <= 63)
798 1.9 tnn dualcom |= 0x10;
799 1.9 tnn SSDFB_CMD3(SSD1322_CMD_SET_REMAP_AND_DUAL_COM_LINE_MODE, remap, dualcom);
800 1.9 tnn if (error)
801 1.9 tnn return error;
802 1.9 tnn
803 1.9 tnn /*
804 1.9 tnn * Contrast settings.
805 1.9 tnn */
806 1.9 tnn SSDFB_CMD1(SSD1322_CMD_SET_DEFAULT_GRAY_SCALE_TABLE);
807 1.9 tnn if (error)
808 1.9 tnn return error;
809 1.9 tnn SSDFB_CMD3(SSD1322_CMD_DISPLAY_ENHANCEMENT_A,
810 1.9 tnn SSD1322_DISPLAY_ENHANCEMENT_A_MAGIC1,
811 1.9 tnn SSD1322_DISPLAY_ENHANCEMENT_A_MAGIC2);
812 1.9 tnn if (error)
813 1.9 tnn return error;
814 1.9 tnn SSDFB_CMD3(SSD1322_CMD_DISPLAY_ENHANCEMENT_B,
815 1.9 tnn SSD1322_DISPLAY_ENHANCEMENT_B_MAGIC1,
816 1.9 tnn SSD1322_DISPLAY_ENHANCEMENT_B_MAGIC2);
817 1.9 tnn if (error)
818 1.9 tnn return error;
819 1.9 tnn SSDFB_CMD2(SSD1322_CMD_SET_CONTRAST_CURRENT,
820 1.9 tnn sc->sc_contrast);
821 1.9 tnn if (error)
822 1.9 tnn return error;
823 1.9 tnn SSDFB_CMD2(SSD1322_CMD_MASTER_CONTRAST_CURRENT_CONTROL,
824 1.9 tnn SSD1322_DEFAULT_MASTER_CONTRAST_CURRENT_CONTROL);
825 1.9 tnn if (error)
826 1.9 tnn return error;
827 1.9 tnn
828 1.9 tnn /*
829 1.9 tnn * Reset display engine state.
830 1.9 tnn */
831 1.9 tnn SSDFB_CMD2(SSD1322_CMD_SET_DISPLAY_OFFSET, 0x00);
832 1.9 tnn if (error)
833 1.9 tnn return error;
834 1.9 tnn SSDFB_CMD2(SSD1322_CMD_SET_DISPLAY_START_LINE, 0x00);
835 1.9 tnn if (error)
836 1.9 tnn return error;
837 1.9 tnn SSDFB_CMD1(SSD1322_CMD_NORMAL_DISPLAY + (uint8_t)sc->sc_inverse);
838 1.9 tnn if (error)
839 1.9 tnn return error;
840 1.9 tnn SSDFB_CMD1(SSD1322_CMD_EXIT_PARTIAL_DISPLAY);
841 1.9 tnn if (error)
842 1.9 tnn return error;
843 1.9 tnn
844 1.9 tnn ssdfb_clear_screen(sc);
845 1.1 tnn error = ssdfb_sync(sc, usepoll);
846 1.1 tnn if (error)
847 1.1 tnn return error;
848 1.9 tnn
849 1.1 tnn error = ssdfb_set_display_on(sc, true, usepoll);
850 1.1 tnn
851 1.1 tnn return error;
852 1.1 tnn }
853 1.1 tnn
854 1.1 tnn static int
855 1.1 tnn ssdfb_set_contrast(struct ssdfb_softc *sc, uint8_t value, bool usepoll)
856 1.1 tnn {
857 1.1 tnn uint8_t cmd[2];
858 1.1 tnn
859 1.9 tnn switch (sc->sc_p->p_controller_id) {
860 1.9 tnn case SSDFB_CONTROLLER_SSD1322:
861 1.9 tnn cmd[0] = SSD1322_CMD_SET_CONTRAST_CURRENT;
862 1.9 tnn break;
863 1.9 tnn default:
864 1.9 tnn cmd[0] = SSDFB_CMD_SET_CONTRAST_CONTROL;
865 1.9 tnn }
866 1.9 tnn cmd[1] = sc->sc_contrast = value;
867 1.1 tnn
868 1.9 tnn return sc->sc_cmd(sc->sc_cookie, cmd, sizeof(cmd), usepoll);
869 1.1 tnn }
870 1.1 tnn
871 1.1 tnn static int
872 1.1 tnn ssdfb_set_display_on(struct ssdfb_softc *sc, bool value, bool usepoll)
873 1.1 tnn {
874 1.1 tnn uint8_t cmd[1];
875 1.1 tnn int error;
876 1.1 tnn sc->sc_display_on = value;
877 1.1 tnn
878 1.1 tnn SSDFB_CMD1(value ? SSDFB_CMD_SET_DISPLAY_ON : SSDFB_CMD_SET_DISPLAY_OFF);
879 1.1 tnn
880 1.1 tnn return error;
881 1.1 tnn }
882 1.1 tnn
883 1.1 tnn static int
884 1.1 tnn ssdfb_set_mode(struct ssdfb_softc *sc, u_int mode)
885 1.1 tnn {
886 1.1 tnn switch (mode) {
887 1.1 tnn case WSDISPLAYIO_MODE_EMUL:
888 1.1 tnn case WSDISPLAYIO_MODE_DUMBFB:
889 1.1 tnn break;
890 1.1 tnn default:
891 1.1 tnn return EINVAL;
892 1.1 tnn }
893 1.1 tnn if (mode == sc->sc_mode)
894 1.1 tnn return 0;
895 1.1 tnn mutex_enter(&sc->sc_cond_mtx);
896 1.1 tnn sc->sc_mode = mode;
897 1.1 tnn cv_broadcast(&sc->sc_cond);
898 1.1 tnn mutex_exit(&sc->sc_cond_mtx);
899 1.1 tnn ssdfb_clear_screen(sc);
900 1.1 tnn ssdfb_damage(sc);
901 1.1 tnn
902 1.1 tnn return 0;
903 1.1 tnn }
904 1.1 tnn
905 1.1 tnn static void
906 1.1 tnn ssdfb_damage(struct ssdfb_softc *sc)
907 1.1 tnn {
908 1.1 tnn int s;
909 1.1 tnn
910 1.1 tnn if (sc->sc_usepoll) {
911 1.1 tnn (void) ssdfb_sync(sc, true);
912 1.1 tnn } else {
913 1.1 tnn /*
914 1.1 tnn * kernel code isn't permitted to call us via kprintf at
915 1.1 tnn * splhigh. In case misbehaving code calls us anyway we can't
916 1.1 tnn * safely take the mutex so we skip the damage notification.
917 1.1 tnn */
918 1.1 tnn if (sc->sc_is_console) {
919 1.1 tnn s = splhigh();
920 1.1 tnn splx(s);
921 1.1 tnn if (s == IPL_HIGH)
922 1.1 tnn return;
923 1.1 tnn }
924 1.1 tnn mutex_enter(&sc->sc_cond_mtx);
925 1.1 tnn sc->sc_modified = true;
926 1.1 tnn cv_broadcast(&sc->sc_cond);
927 1.1 tnn mutex_exit(&sc->sc_cond_mtx);
928 1.1 tnn }
929 1.1 tnn }
930 1.1 tnn
931 1.3 tnn static void
932 1.3 tnn ssdfb_udv_attach(struct ssdfb_softc *sc)
933 1.3 tnn {
934 1.3 tnn extern const struct cdevsw wsdisplay_cdevsw;
935 1.3 tnn dev_t dev;
936 1.3 tnn #define WSDISPLAYMINOR(unit, screen) (((unit) << 8) | (screen))
937 1.3 tnn dev = makedev(cdevsw_lookup_major(&wsdisplay_cdevsw),
938 1.3 tnn WSDISPLAYMINOR(device_unit(sc->sc_wsdisplay), 0));
939 1.3 tnn sc->sc_uobj = udv_attach(dev, VM_PROT_READ|VM_PROT_WRITE, 0,
940 1.3 tnn sc->sc_ri_bits_len);
941 1.3 tnn }
942 1.3 tnn
943 1.1 tnn static bool
944 1.1 tnn ssdfb_is_modified(struct ssdfb_softc *sc)
945 1.1 tnn {
946 1.1 tnn vaddr_t va, va_end;
947 1.1 tnn
948 1.1 tnn if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)
949 1.1 tnn return sc->sc_modified;
950 1.1 tnn
951 1.3 tnn if (sc->sc_uobj == NULL)
952 1.3 tnn return false;
953 1.3 tnn
954 1.1 tnn va = (vaddr_t)sc->sc_ri.ri_bits;
955 1.1 tnn va_end = va + sc->sc_ri_bits_len;
956 1.1 tnn while (va < va_end) {
957 1.1 tnn if (pmap_is_modified(uvm_pageratop(va)))
958 1.1 tnn return true;
959 1.1 tnn va += PAGE_SIZE;
960 1.1 tnn }
961 1.1 tnn
962 1.1 tnn return false;
963 1.1 tnn }
964 1.1 tnn
965 1.1 tnn static bool
966 1.1 tnn ssdfb_clear_modify(struct ssdfb_softc *sc)
967 1.1 tnn {
968 1.1 tnn vaddr_t va, va_end;
969 1.1 tnn bool ret;
970 1.1 tnn
971 1.1 tnn if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) {
972 1.9 tnn mutex_enter(&sc->sc_cond_mtx);
973 1.1 tnn ret = sc->sc_modified;
974 1.1 tnn sc->sc_modified = false;
975 1.9 tnn mutex_exit(&sc->sc_cond_mtx);
976 1.1 tnn return ret;
977 1.1 tnn }
978 1.1 tnn
979 1.3 tnn if (sc->sc_uobj == NULL)
980 1.3 tnn return false;
981 1.3 tnn
982 1.1 tnn va = (vaddr_t)sc->sc_ri.ri_bits;
983 1.1 tnn va_end = va + sc->sc_ri_bits_len;
984 1.1 tnn ret = false;
985 1.1 tnn while (va < va_end) {
986 1.1 tnn if (pmap_clear_modify(uvm_pageratop(va)))
987 1.1 tnn ret = true;
988 1.1 tnn va += PAGE_SIZE;
989 1.1 tnn }
990 1.1 tnn
991 1.1 tnn return ret;
992 1.1 tnn }
993 1.1 tnn
994 1.1 tnn static void
995 1.2 tnn ssdfb_thread(void *arg)
996 1.2 tnn {
997 1.1 tnn struct ssdfb_softc *sc = (struct ssdfb_softc *)arg;
998 1.1 tnn int error;
999 1.1 tnn
1000 1.1 tnn mutex_enter(&sc->sc_cond_mtx);
1001 1.1 tnn
1002 1.1 tnn if (sc->sc_usepoll)
1003 1.1 tnn ssdfb_set_usepoll(sc, false);
1004 1.1 tnn
1005 1.1 tnn while(!sc->sc_detaching) {
1006 1.3 tnn if (sc->sc_mode == WSDISPLAYIO_MODE_DUMBFB &&
1007 1.3 tnn sc->sc_uobj == NULL) {
1008 1.3 tnn mutex_exit(&sc->sc_cond_mtx);
1009 1.3 tnn ssdfb_udv_attach(sc);
1010 1.3 tnn mutex_enter(&sc->sc_cond_mtx);
1011 1.3 tnn }
1012 1.1 tnn if (!ssdfb_is_modified(sc)) {
1013 1.1 tnn if (cv_timedwait(&sc->sc_cond, &sc->sc_cond_mtx,
1014 1.1 tnn sc->sc_mode == WSDISPLAYIO_MODE_EMUL
1015 1.1 tnn ? 0 : sc->sc_backoff) == EWOULDBLOCK
1016 1.1 tnn && sc->sc_backoff < mstohz(200)) {
1017 1.1 tnn sc->sc_backoff <<= 1;
1018 1.1 tnn }
1019 1.1 tnn continue;
1020 1.1 tnn }
1021 1.1 tnn sc->sc_backoff = 1;
1022 1.9 tnn mutex_exit(&sc->sc_cond_mtx);
1023 1.1 tnn (void) ssdfb_clear_modify(sc);
1024 1.9 tnn if (!sc->sc_usepoll) {
1025 1.9 tnn error = ssdfb_sync(sc, false);
1026 1.9 tnn if (error)
1027 1.9 tnn device_printf(sc->sc_dev,
1028 1.9 tnn "ssdfb_sync: error %d\n",
1029 1.9 tnn error);
1030 1.9 tnn }
1031 1.1 tnn mutex_enter(&sc->sc_cond_mtx);
1032 1.1 tnn }
1033 1.1 tnn
1034 1.1 tnn mutex_exit(&sc->sc_cond_mtx);
1035 1.6 tnn kthread_exit(0);
1036 1.1 tnn }
1037 1.1 tnn
1038 1.1 tnn static void
1039 1.2 tnn ssdfb_set_usepoll(struct ssdfb_softc *sc, bool enable)
1040 1.2 tnn {
1041 1.1 tnn sc->sc_usepoll = enable;
1042 1.1 tnn }
1043 1.1 tnn
1044 1.1 tnn static int
1045 1.2 tnn ssdfb_sync(struct ssdfb_softc *sc, bool usepoll)
1046 1.2 tnn {
1047 1.9 tnn return sc->sc_p->p_sync(sc, usepoll);
1048 1.9 tnn }
1049 1.9 tnn
1050 1.9 tnn static int
1051 1.9 tnn ssdfb_sync_ssd1306(struct ssdfb_softc *sc, bool usepoll)
1052 1.9 tnn {
1053 1.1 tnn struct rasops_info *ri = &sc->sc_ri;
1054 1.1 tnn int block_size = 8;
1055 1.1 tnn int ri_block_stride = ri->ri_stride * block_size;
1056 1.1 tnn int height_in_blocks = sc->sc_p->p_height / block_size;
1057 1.1 tnn int width_in_blocks = sc->sc_p->p_width / block_size;
1058 1.1 tnn int ri_block_step = block_size * ri->ri_depth / 8;
1059 1.1 tnn int x, y;
1060 1.1 tnn union ssdfb_block *blockp;
1061 1.1 tnn uint64_t raw_block;
1062 1.1 tnn uint8_t *src;
1063 1.1 tnn int x1, x2, y1, y2;
1064 1.1 tnn
1065 1.1 tnn /*
1066 1.1 tnn * Transfer rasops bitmap into gddram shadow buffer while keeping track
1067 1.1 tnn * of the bounding box of the dirty region we scribbled over.
1068 1.1 tnn */
1069 1.1 tnn x1 = width_in_blocks;
1070 1.1 tnn x2 = -1;
1071 1.1 tnn y1 = height_in_blocks;
1072 1.1 tnn y2 = -1;
1073 1.1 tnn for (y = 0; y < height_in_blocks; y++) {
1074 1.9 tnn src = &ri->ri_bits[y * ri_block_stride];
1075 1.1 tnn blockp = &sc->sc_gddram[y * width_in_blocks];
1076 1.1 tnn for (x = 0; x < width_in_blocks; x++) {
1077 1.9 tnn raw_block = ssdfb_transpose_block(src, ri->ri_stride);
1078 1.1 tnn if (raw_block != blockp->raw) {
1079 1.1 tnn blockp->raw = raw_block;
1080 1.1 tnn if (x1 > x)
1081 1.1 tnn x1 = x;
1082 1.1 tnn if (x2 < x)
1083 1.1 tnn x2 = x;
1084 1.1 tnn if (y1 > y)
1085 1.1 tnn y1 = y;
1086 1.1 tnn if (y2 < y)
1087 1.1 tnn y2 = y;
1088 1.1 tnn }
1089 1.1 tnn src += ri_block_step;
1090 1.1 tnn blockp++;
1091 1.1 tnn }
1092 1.1 tnn }
1093 1.1 tnn if (x2 != -1)
1094 1.1 tnn return sc->sc_transfer_rect(sc->sc_cookie,
1095 1.1 tnn x1 * block_size + sc->sc_p->p_panel_shift,
1096 1.1 tnn (x2 + 1) * block_size - 1 + sc->sc_p->p_panel_shift,
1097 1.1 tnn y1,
1098 1.1 tnn y2,
1099 1.1 tnn &sc->sc_gddram[y1 * width_in_blocks + x1].col[0],
1100 1.1 tnn sc->sc_p->p_width,
1101 1.1 tnn usepoll);
1102 1.1 tnn
1103 1.1 tnn return 0;
1104 1.1 tnn }
1105 1.1 tnn
1106 1.9 tnn static int
1107 1.9 tnn ssdfb_sync_ssd1322(struct ssdfb_softc *sc, bool usepoll)
1108 1.9 tnn {
1109 1.9 tnn struct rasops_info *ri = &sc->sc_ri;
1110 1.9 tnn int block_size_w = 4;
1111 1.9 tnn int width = sc->sc_p->p_width;
1112 1.9 tnn int height = sc->sc_p->p_height;
1113 1.9 tnn int width_in_blocks = width / block_size_w;
1114 1.9 tnn int x, y;
1115 1.9 tnn uint16_t *blockp;
1116 1.9 tnn uint16_t raw_block;
1117 1.9 tnn uint16_t *src;
1118 1.9 tnn uint32_t *src32;
1119 1.9 tnn int x1, x2, y1, y2;
1120 1.9 tnn
1121 1.9 tnn /*
1122 1.9 tnn * Transfer rasops bitmap into gddram shadow buffer while keeping track
1123 1.9 tnn * of the bounding box of the dirty region we scribbled over.
1124 1.9 tnn */
1125 1.9 tnn x1 = sc->sc_p->p_width;
1126 1.9 tnn x2 = -1;
1127 1.9 tnn y1 = sc->sc_p->p_height;
1128 1.9 tnn y2 = -1;
1129 1.9 tnn blockp = (uint16_t*)sc->sc_gddram;
1130 1.9 tnn for (y = 0; y < height; y++) {
1131 1.9 tnn src = (uint16_t*)&ri->ri_bits[y * ri->ri_stride];
1132 1.9 tnn src32 = (uint32_t*)src;
1133 1.9 tnn for (x = 0; x < width_in_blocks; x++) {
1134 1.9 tnn #if _BYTE_ORDER == _LITTLE_ENDIAN
1135 1.9 tnn # ifdef SSDFB_USE_NATIVE_DEPTH
1136 1.9 tnn raw_block =
1137 1.9 tnn ((*src << 12) & 0xf000) |
1138 1.9 tnn ((*src << 4) & 0x0f00) |
1139 1.9 tnn ((*src >> 4) & 0x00f0) |
1140 1.9 tnn ((*src >> 12) & 0x000f);
1141 1.9 tnn src++;
1142 1.9 tnn # else
1143 1.9 tnn raw_block =
1144 1.9 tnn ((*src32 << 8) & 0x0f00) |
1145 1.9 tnn ((*src32 << 4) & 0xf000) |
1146 1.9 tnn ((*src32 >> 16) & 0x000f) |
1147 1.9 tnn ((*src32 >> 20) & 0x00f0);
1148 1.9 tnn # endif
1149 1.9 tnn src32++;
1150 1.9 tnn #else
1151 1.9 tnn # error please add big endian host support here
1152 1.9 tnn #endif
1153 1.9 tnn if (raw_block != *blockp) {
1154 1.9 tnn *blockp = raw_block;
1155 1.9 tnn if (x1 > x)
1156 1.9 tnn x1 = x;
1157 1.9 tnn if (x2 < x)
1158 1.9 tnn x2 = x;
1159 1.9 tnn if (y1 > y)
1160 1.9 tnn y1 = y;
1161 1.9 tnn if (y2 < y)
1162 1.9 tnn y2 = y;
1163 1.9 tnn }
1164 1.9 tnn blockp++;
1165 1.9 tnn }
1166 1.9 tnn }
1167 1.9 tnn
1168 1.9 tnn blockp = (uint16_t*)sc->sc_gddram;
1169 1.9 tnn if (x2 != -1)
1170 1.9 tnn return sc->sc_transfer_rect(sc->sc_cookie,
1171 1.9 tnn x1 + sc->sc_p->p_panel_shift,
1172 1.9 tnn x2 + sc->sc_p->p_panel_shift,
1173 1.9 tnn y1,
1174 1.9 tnn y2,
1175 1.9 tnn (uint8_t*)&blockp[y1 * width_in_blocks + x1],
1176 1.9 tnn width * sc->sc_p->p_bits_per_pixel / 8,
1177 1.9 tnn usepoll);
1178 1.9 tnn return 0;
1179 1.9 tnn }
1180 1.9 tnn
1181 1.1 tnn static uint64_t
1182 1.9 tnn ssdfb_transpose_block(uint8_t *src, size_t src_stride)
1183 1.1 tnn {
1184 1.1 tnn uint64_t x = 0;
1185 1.9 tnn #ifdef SSDFB_USE_NATIVE_DEPTH
1186 1.1 tnn uint64_t t;
1187 1.1 tnn int i;
1188 1.1 tnn
1189 1.1 tnn /*
1190 1.1 tnn * collect the 8x8 block.
1191 1.1 tnn */
1192 1.1 tnn for (i = 0; i < 8; i++) {
1193 1.1 tnn x >>= 8;
1194 1.1 tnn x |= (uint64_t)src[i * src_stride] << 56;
1195 1.1 tnn }
1196 1.1 tnn
1197 1.1 tnn /*
1198 1.1 tnn * Transpose it into gddram layout.
1199 1.1 tnn * Post-transpose bswap is the same as pre-transpose bit order reversal.
1200 1.1 tnn * We do this to match rasops1 bit order.
1201 1.1 tnn */
1202 1.1 tnn t = (x ^ (x >> 28)) & 0x00000000F0F0F0F0ULL;
1203 1.1 tnn x = x ^ t ^ (t << 28);
1204 1.1 tnn t = (x ^ (x >> 14)) & 0x0000CCCC0000CCCCULL;
1205 1.1 tnn x = x ^ t ^ (t << 14);
1206 1.1 tnn t = (x ^ (x >> 7)) & 0x00AA00AA00AA00AAULL;
1207 1.1 tnn x = x ^ t ^ (t << 7);
1208 1.1 tnn x = bswap64(x);
1209 1.9 tnn #else
1210 1.1 tnn int m, n;
1211 1.1 tnn
1212 1.1 tnn for (m = 0; m < 8; m++) {
1213 1.1 tnn for (n = 0; n < 8; n++) {
1214 1.1 tnn x >>= 1;
1215 1.1 tnn x |= src[n * src_stride + m] ? (1ULL << 63) : 0;
1216 1.1 tnn }
1217 1.1 tnn }
1218 1.9 tnn #endif
1219 1.1 tnn return htole64(x);
1220 1.1 tnn }
1221 1.1 tnn
1222 1.1 tnn static const struct ssdfb_product *
1223 1.2 tnn ssdfb_lookup_product(ssdfb_product_id_t id)
1224 1.2 tnn {
1225 1.1 tnn int i;
1226 1.1 tnn
1227 1.1 tnn for (i = 0; i < __arraycount(ssdfb_products); i++) {
1228 1.1 tnn if (ssdfb_products[i].p_product_id == id)
1229 1.1 tnn return &ssdfb_products[i];
1230 1.1 tnn }
1231 1.1 tnn
1232 1.1 tnn return NULL;
1233 1.1 tnn }
1234 1.1 tnn
1235 1.1 tnn static int
1236 1.2 tnn ssdfb_pick_font(int *cookiep, struct wsdisplay_font **fontp)
1237 1.2 tnn {
1238 1.1 tnn int error;
1239 1.1 tnn int c;
1240 1.1 tnn struct wsdisplay_font *f;
1241 1.1 tnn int i;
1242 1.1 tnn uint8_t d[4][2] = {{5, 8}, {8, 8}, {8, 10} ,{8, 16}};
1243 1.1 tnn
1244 1.1 tnn /*
1245 1.4 tnn * Try to find fonts in order of increasing size.
1246 1.1 tnn */
1247 1.1 tnn wsfont_init();
1248 1.1 tnn for(i = 0; i < __arraycount(d); i++) {
1249 1.1 tnn c = wsfont_find(NULL, d[i][0], d[i][1], 0,
1250 1.1 tnn WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R,
1251 1.1 tnn WSFONT_FIND_BITMAP);
1252 1.1 tnn if (c > 0)
1253 1.1 tnn break;
1254 1.1 tnn }
1255 1.1 tnn if (c <= 0)
1256 1.1 tnn return ENOENT;
1257 1.1 tnn error = wsfont_lock(c, &f);
1258 1.1 tnn if (error)
1259 1.1 tnn return error;
1260 1.1 tnn *cookiep = c;
1261 1.1 tnn *fontp = f;
1262 1.1 tnn
1263 1.1 tnn return 0;
1264 1.1 tnn }
1265 1.1 tnn
1266 1.1 tnn static void
1267 1.1 tnn ssdfb_clear_screen(struct ssdfb_softc *sc)
1268 1.1 tnn {
1269 1.1 tnn struct rasops_info *ri = &sc->sc_ri;
1270 1.1 tnn
1271 1.1 tnn memset(sc->sc_gddram, 0xff, sc->sc_gddram_len);
1272 1.1 tnn memset(ri->ri_bits, 0, sc->sc_ri_bits_len);
1273 1.1 tnn }
1274 1.1 tnn
1275 1.1 tnn #if defined(DDB)
1276 1.1 tnn static void
1277 1.1 tnn ssdfb_ddb_trap_callback(int enable)
1278 1.1 tnn {
1279 1.1 tnn extern struct cfdriver ssdfb_cd;
1280 1.1 tnn struct ssdfb_softc *sc;
1281 1.1 tnn int i;
1282 1.1 tnn
1283 1.1 tnn for (i = 0; i < ssdfb_cd.cd_ndevs; i++) {
1284 1.1 tnn sc = device_lookup_private(&ssdfb_cd, i);
1285 1.1 tnn if (sc != NULL && sc->sc_is_console) {
1286 1.1 tnn ssdfb_set_usepoll(sc, (bool)enable);
1287 1.1 tnn }
1288 1.1 tnn }
1289 1.1 tnn }
1290 1.1 tnn #endif
1291