| @@ -1,892 +1,901 @@ | | | @@ -1,892 +1,901 @@ |
1 | /* $NetBSD: omapfb.c,v 1.13 2013/01/17 01:10:52 macallan Exp $ */ | | 1 | /* $NetBSD: omapfb.c,v 1.14 2013/01/21 14:17:39 macallan Exp $ */ |
2 | | | 2 | |
3 | /* | | 3 | /* |
4 | * Copyright (c) 2010 Michael Lorenz | | 4 | * Copyright (c) 2010 Michael Lorenz |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
15 | * | | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | | 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | | 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | | 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | | 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | | 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ | | 26 | */ |
27 | | | 27 | |
28 | /* | | 28 | /* |
29 | * A console driver for OMAP 3530's built-in video controller | | 29 | * A console driver for OMAP 3530's built-in video controller |
30 | * tested on beagleboard only so far | | 30 | * tested on beagleboard only so far |
31 | */ | | 31 | */ |
32 | | | 32 | |
33 | #include <sys/cdefs.h> | | 33 | #include <sys/cdefs.h> |
34 | __KERNEL_RCSID(0, "$NetBSD: omapfb.c,v 1.13 2013/01/17 01:10:52 macallan Exp $"); | | 34 | __KERNEL_RCSID(0, "$NetBSD: omapfb.c,v 1.14 2013/01/21 14:17:39 macallan Exp $"); |
35 | | | 35 | |
36 | #include <sys/param.h> | | 36 | #include <sys/param.h> |
37 | #include <sys/systm.h> | | 37 | #include <sys/systm.h> |
38 | #include <sys/kernel.h> | | 38 | #include <sys/kernel.h> |
39 | #include <sys/device.h> | | 39 | #include <sys/device.h> |
40 | #include <sys/malloc.h> | | 40 | #include <sys/malloc.h> |
41 | #include <sys/lwp.h> | | 41 | #include <sys/lwp.h> |
42 | #include <sys/kauth.h> | | 42 | #include <sys/kauth.h> |
43 | | | 43 | |
44 | #include <uvm/uvm_extern.h> | | 44 | #include <uvm/uvm_extern.h> |
45 | | | 45 | |
46 | #include <dev/videomode/videomode.h> | | 46 | #include <dev/videomode/videomode.h> |
47 | | | 47 | |
48 | #include <sys/bus.h> | | 48 | #include <sys/bus.h> |
49 | #include <arm/omap/omapfbreg.h> | | 49 | #include <arm/omap/omapfbreg.h> |
50 | #include <arm/omap/omap2_obiovar.h> | | 50 | #include <arm/omap/omap2_obiovar.h> |
51 | #include <arm/omap/omap2_obioreg.h> | | 51 | #include <arm/omap/omap2_obioreg.h> |
52 | #include <arm/omap/omap3_sdmareg.h> | | 52 | #include <arm/omap/omap3_sdmareg.h> |
53 | #include <arm/omap/omap3_sdmavar.h> | | 53 | #include <arm/omap/omap3_sdmavar.h> |
54 | | | 54 | |
55 | #include <dev/wscons/wsdisplayvar.h> | | 55 | #include <dev/wscons/wsdisplayvar.h> |
56 | #include <dev/wscons/wsconsio.h> | | 56 | #include <dev/wscons/wsconsio.h> |
57 | #include <dev/wsfont/wsfont.h> | | 57 | #include <dev/wsfont/wsfont.h> |
58 | #include <dev/rasops/rasops.h> | | 58 | #include <dev/rasops/rasops.h> |
59 | #include <dev/wscons/wsdisplay_vconsvar.h> | | 59 | #include <dev/wscons/wsdisplay_vconsvar.h> |
60 | | | 60 | |
61 | #include <dev/videomode/edidvar.h> | | 61 | #include <dev/videomode/edidvar.h> |
62 | | | 62 | |
63 | #include "omapdma.h" | | 63 | #include "omapdma.h" |
64 | | | 64 | |
65 | struct omapfb_softc { | | 65 | struct omapfb_softc { |
66 | device_t sc_dev; | | 66 | device_t sc_dev; |
67 | | | 67 | |
68 | bus_space_tag_t sc_iot; | | 68 | bus_space_tag_t sc_iot; |
69 | bus_dma_tag_t sc_dmat; | | 69 | bus_dma_tag_t sc_dmat; |
70 | bus_space_handle_t sc_regh; | | 70 | bus_space_handle_t sc_regh; |
71 | bus_dmamap_t sc_dmamap; | | 71 | bus_dmamap_t sc_dmamap; |
72 | bus_dma_segment_t sc_dmamem[1]; | | 72 | bus_dma_segment_t sc_dmamem[1]; |
73 | size_t sc_vramsize; | | 73 | size_t sc_vramsize; |
74 | | | 74 | |
75 | int sc_width, sc_height, sc_depth, sc_stride; | | 75 | int sc_width, sc_height, sc_depth, sc_stride; |
76 | int sc_locked; | | 76 | int sc_locked; |
77 | void *sc_fbaddr, *sc_vramaddr; | | 77 | void *sc_fbaddr, *sc_vramaddr; |
78 | bus_addr_t sc_fbhwaddr; | | 78 | bus_addr_t sc_fbhwaddr; |
79 | uint32_t *sc_clut; | | 79 | uint32_t *sc_clut; |
80 | struct vcons_screen sc_console_screen; | | 80 | struct vcons_screen sc_console_screen; |
81 | struct wsscreen_descr sc_defaultscreen_descr; | | 81 | struct wsscreen_descr sc_defaultscreen_descr; |
82 | const struct wsscreen_descr *sc_screens[1]; | | 82 | const struct wsscreen_descr *sc_screens[1]; |
83 | struct wsscreen_list sc_screenlist; | | 83 | struct wsscreen_list sc_screenlist; |
84 | struct vcons_data vd; | | 84 | struct vcons_data vd; |
85 | int sc_mode; | | 85 | int sc_mode; |
86 | uint8_t sc_cmap_red[256], sc_cmap_green[256], sc_cmap_blue[256]; | | 86 | uint8_t sc_cmap_red[256], sc_cmap_green[256], sc_cmap_blue[256]; |
87 | void (*sc_putchar)(void *, int, int, u_int, long); | | 87 | void (*sc_putchar)(void *, int, int, u_int, long); |
88 | | | 88 | |
89 | uint8_t sc_edid_data[1024]; | | 89 | uint8_t sc_edid_data[1024]; |
90 | size_t sc_edid_size; | | 90 | size_t sc_edid_size; |
91 | }; | | 91 | }; |
92 | | | 92 | |
93 | static int omapfb_match(device_t, cfdata_t, void *); | | 93 | static int omapfb_match(device_t, cfdata_t, void *); |
94 | static void omapfb_attach(device_t, device_t, void *); | | 94 | static void omapfb_attach(device_t, device_t, void *); |
95 | | | 95 | |
96 | CFATTACH_DECL_NEW(omapfb, sizeof(struct omapfb_softc), | | 96 | CFATTACH_DECL_NEW(omapfb, sizeof(struct omapfb_softc), |
97 | omapfb_match, omapfb_attach, NULL, NULL); | | 97 | omapfb_match, omapfb_attach, NULL, NULL); |
98 | | | 98 | |
99 | static int omapfb_ioctl(void *, void *, u_long, void *, int, | | 99 | static int omapfb_ioctl(void *, void *, u_long, void *, int, |
100 | struct lwp *); | | 100 | struct lwp *); |
101 | static paddr_t omapfb_mmap(void *, void *, off_t, int); | | 101 | static paddr_t omapfb_mmap(void *, void *, off_t, int); |
102 | static void omapfb_init_screen(void *, struct vcons_screen *, int, long *); | | 102 | static void omapfb_init_screen(void *, struct vcons_screen *, int, long *); |
103 | | | 103 | |
104 | static int omapfb_putcmap(struct omapfb_softc *, struct wsdisplay_cmap *); | | 104 | static int omapfb_putcmap(struct omapfb_softc *, struct wsdisplay_cmap *); |
105 | static int omapfb_getcmap(struct omapfb_softc *, struct wsdisplay_cmap *); | | 105 | static int omapfb_getcmap(struct omapfb_softc *, struct wsdisplay_cmap *); |
106 | static void omapfb_restore_palette(struct omapfb_softc *); | | 106 | static void omapfb_restore_palette(struct omapfb_softc *); |
107 | static void omapfb_putpalreg(struct omapfb_softc *, int, uint8_t, | | 107 | static void omapfb_putpalreg(struct omapfb_softc *, int, uint8_t, |
108 | uint8_t, uint8_t); | | 108 | uint8_t, uint8_t); |
109 | | | 109 | |
110 | #if NOMAPDMA > 0 | | 110 | #if NOMAPDMA > 0 |
111 | static void omapfb_init(struct omapfb_softc *); | | 111 | static void omapfb_init(struct omapfb_softc *); |
112 | static void omapfb_wait_idle(struct omapfb_softc *); | | 112 | static void omapfb_wait_idle(struct omapfb_softc *); |
113 | static void omapfb_rectfill(struct omapfb_softc *, int, int, int, int, | | 113 | static void omapfb_rectfill(struct omapfb_softc *, int, int, int, int, |
114 | uint32_t); | | 114 | uint32_t); |
115 | static void omapfb_bitblt(struct omapfb_softc *, int, int, int, int, int, | | 115 | static void omapfb_bitblt(struct omapfb_softc *, int, int, int, int, int, |
116 | int, int); | | 116 | int, int); |
117 | | | 117 | |
118 | static void omapfb_cursor(void *, int, int, int); | | 118 | static void omapfb_cursor(void *, int, int, int); |
119 | static void omapfb_putchar(void *, int, int, u_int, long); | | 119 | static void omapfb_putchar(void *, int, int, u_int, long); |
120 | static void omapfb_copycols(void *, int, int, int, int); | | 120 | static void omapfb_copycols(void *, int, int, int, int); |
121 | static void omapfb_erasecols(void *, int, int, int, long); | | 121 | static void omapfb_erasecols(void *, int, int, int, long); |
122 | static void omapfb_copyrows(void *, int, int, int); | | 122 | static void omapfb_copyrows(void *, int, int, int); |
123 | static void omapfb_eraserows(void *, int, int, long); | | 123 | static void omapfb_eraserows(void *, int, int, long); |
124 | #endif /* NOMAPDMA > 0 */ | | 124 | #endif /* NOMAPDMA > 0 */ |
125 | | | 125 | |
126 | struct wsdisplay_accessops omapfb_accessops = { | | 126 | struct wsdisplay_accessops omapfb_accessops = { |
127 | omapfb_ioctl, | | 127 | omapfb_ioctl, |
128 | omapfb_mmap, | | 128 | omapfb_mmap, |
129 | NULL, /* alloc_screen */ | | 129 | NULL, /* alloc_screen */ |
130 | NULL, /* free_screen */ | | 130 | NULL, /* free_screen */ |
131 | NULL, /* show_screen */ | | 131 | NULL, /* show_screen */ |
132 | NULL, /* load_font */ | | 132 | NULL, /* load_font */ |
133 | NULL, /* pollc */ | | 133 | NULL, /* pollc */ |
134 | NULL /* scroll */ | | 134 | NULL /* scroll */ |
135 | }; | | 135 | }; |
136 | | | 136 | |
137 | uint32_t venc_mode_ntsc[] = { | | 137 | uint32_t venc_mode_ntsc[] = { |
138 | 0x00000000, 0x00000001, 0x00008040, 0x00000359, | | 138 | 0x00000000, 0x00000001, 0x00008040, 0x00000359, |
139 | 0x0000020c, 0x00000000, 0x043f2631, 0x00000000, | | 139 | 0x0000020c, 0x00000000, 0x043f2631, 0x00000000, |
140 | 0x00000102, 0x0000016c, 0x0000012f, 0x00000043, | | 140 | 0x00000102, 0x0000016c, 0x0000012f, 0x00000043, |
141 | 0x00000038, 0x00000007, 0x00000001, 0x00000038, | | 141 | 0x00000038, 0x00000007, 0x00000001, 0x00000038, |
142 | 0x21f07c1f, 0x00000000, 0x01310011, 0x0000f003, | | 142 | 0x21f07c1f, 0x00000000, 0x01310011, 0x0000f003, |
143 | 0x00000000, 0x069300f4, 0x0016020c, 0x00060107, | | 143 | 0x00000000, 0x069300f4, 0x0016020c, 0x00060107, |
144 | 0x008e0350, 0x000f0359, 0x01a00000, 0x020701a0, | | 144 | 0x008e0350, 0x000f0359, 0x01a00000, 0x020701a0, |
145 | 0x01ac0024, 0x020d01ac, 0x00000006, 0x03480078, | | 145 | 0x01ac0024, 0x020d01ac, 0x00000006, 0x03480078, |
146 | 0x02060024, 0x0001008a, 0x01ac0106, 0x01060006, | | 146 | 0x02060024, 0x0001008a, 0x01ac0106, 0x01060006, |
147 | 0x00140001, 0x00010001, 0x00f90000, 0x0000000d, | | 147 | 0x00140001, 0x00010001, 0x00f90000, 0x0000000d, |
148 | 0x00000000}; | | 148 | 0x00000000}; |
149 | | | 149 | |
150 | extern const u_char rasops_cmap[768]; | | 150 | extern const u_char rasops_cmap[768]; |
151 | | | 151 | |
152 | static int | | 152 | static int |
153 | omapfb_match(device_t parent, cfdata_t match, void *aux) | | 153 | omapfb_match(device_t parent, cfdata_t match, void *aux) |
154 | { | | 154 | { |
155 | struct obio_attach_args *obio = aux; | | 155 | struct obio_attach_args *obio = aux; |
156 | | | 156 | |
157 | if ((obio->obio_addr == -1) || (obio->obio_size == 0)) | | 157 | if ((obio->obio_addr == -1) || (obio->obio_size == 0)) |
158 | return 0; | | 158 | return 0; |
159 | return 1; | | 159 | return 1; |
160 | } | | 160 | } |
161 | | | 161 | |
162 | static void | | 162 | static void |
163 | omapfb_attach(device_t parent, device_t self, void *aux) | | 163 | omapfb_attach(device_t parent, device_t self, void *aux) |
164 | { | | 164 | { |
165 | struct omapfb_softc *sc = device_private(self); | | 165 | struct omapfb_softc *sc = device_private(self); |
166 | struct obio_attach_args *obio = aux; | | 166 | struct obio_attach_args *obio = aux; |
167 | struct rasops_info *ri; | | 167 | struct rasops_info *ri; |
168 | struct wsemuldisplaydev_attach_args aa; | | 168 | struct wsemuldisplaydev_attach_args aa; |
169 | prop_dictionary_t dict; | | 169 | prop_dictionary_t dict; |
170 | prop_data_t edid_data; | | 170 | prop_data_t edid_data; |
171 | unsigned long defattr; | | 171 | unsigned long defattr; |
172 | bool is_console = false; | | 172 | bool is_console = false; |
173 | uint32_t sz, reg; | | 173 | uint32_t sz, reg; |
174 | int segs, i, j, adr; | | 174 | int segs, i, j, adr; |
175 | | | 175 | |
176 | sc->sc_iot = obio->obio_iot; | | 176 | sc->sc_iot = obio->obio_iot; |
177 | sc->sc_dev = self; | | 177 | sc->sc_dev = self; |
178 | sc->sc_dmat = obio->obio_dmat; | | 178 | sc->sc_dmat = obio->obio_dmat; |
179 | | | 179 | |
180 | printf(": OMAP onboard video\n"); | | 180 | printf(": OMAP onboard video\n"); |
181 | if (bus_space_map(obio->obio_iot, obio->obio_addr, obio->obio_size, 0, | | 181 | if (bus_space_map(obio->obio_iot, obio->obio_addr, obio->obio_size, 0, |
182 | &sc->sc_regh)) { | | 182 | &sc->sc_regh)) { |
183 | aprint_error(": couldn't map register space\n"); | | 183 | aprint_error(": couldn't map register space\n"); |
184 | return; | | 184 | return; |
185 | } | | 185 | } |
186 | | | 186 | |
187 | /* | | 187 | /* |
188 | * XXX | | 188 | * XXX |
189 | * different u-boot versions initialize the graphics controller in | | 189 | * different u-boot versions initialize the graphics controller in |
190 | * different ways, so we look for the display resolution in a few | | 190 | * different ways, so we look for the display resolution in a few |
191 | * different places... | | 191 | * different places... |
192 | */ | | 192 | */ |
193 | sz = bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_SIZE); | | 193 | sz = bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_SIZE); |
194 | if (sz == 0) { | | 194 | if (sz == 0) { |
195 | sz = bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_SIZE_LCD); | | 195 | sz = bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_SIZE_LCD); |
196 | } | | 196 | } |
197 | if (sz == 0) { | | 197 | if (sz == 0) { |
198 | sz = bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_SIZE_DIG); | | 198 | sz = bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_SIZE_DIG); |
199 | } | | 199 | } |
200 | | | 200 | |
201 | /* ... and make sure it ends up where we need it */ | | 201 | /* ... and make sure it ends up where we need it */ |
202 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_SIZE, sz); | | 202 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_SIZE, sz); |
203 | | | 203 | |
204 | sc->sc_width = (sz & 0xfff) + 1; | | 204 | sc->sc_width = (sz & 0xfff) + 1; |
205 | sc->sc_height = ((sz & 0x0fff0000 ) >> 16) + 1; | | 205 | sc->sc_height = ((sz & 0x0fff0000 ) >> 16) + 1; |
206 | sc->sc_depth = 16; | | 206 | sc->sc_depth = 16; |
207 | sc->sc_stride = sc->sc_width << 1; | | 207 | sc->sc_stride = sc->sc_width << 1; |
208 | | | 208 | |
209 | if (sc->sc_width == 1 || sc->sc_height == 1) { | | 209 | if (sc->sc_width == 1 || sc->sc_height == 1) { |
210 | aprint_error_dev(self, "bogus display size, not attaching\n"); | | 210 | aprint_error_dev(self, "bogus display size, not attaching\n"); |
211 | return; | | 211 | return; |
212 | } | | 212 | } |
213 | | | 213 | |
214 | printf("%s: firmware set up %d x %d\n", device_xname(self), | | 214 | printf("%s: firmware set up %d x %d\n", device_xname(self), |
215 | sc->sc_width, sc->sc_height); | | 215 | sc->sc_width, sc->sc_height); |
216 | #if 0 | | 216 | #if 0 |
217 | printf("DSS revision: %08x\n", | | 217 | printf("DSS revision: %08x\n", |
218 | bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DSS_REVISION)); | | 218 | bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DSS_REVISION)); |
219 | #endif | | 219 | #endif |
220 | dict = device_properties(self); | | 220 | dict = device_properties(self); |
221 | prop_dictionary_get_bool(dict, "is_console", &is_console); | | 221 | prop_dictionary_get_bool(dict, "is_console", &is_console); |
222 | edid_data = prop_dictionary_get(dict, "EDID"); | | 222 | edid_data = prop_dictionary_get(dict, "EDID"); |
223 | | | 223 | |
224 | if (edid_data != NULL) { | | 224 | if (edid_data != NULL) { |
225 | struct edid_info ei; | | 225 | struct edid_info ei; |
226 | | | 226 | |
227 | sc->sc_edid_size = min(prop_data_size(edid_data), 1024); | | 227 | sc->sc_edid_size = min(prop_data_size(edid_data), 1024); |
228 | memset(sc->sc_edid_data, 0, sizeof(sc->sc_edid_data)); | | 228 | memset(sc->sc_edid_data, 0, sizeof(sc->sc_edid_data)); |
229 | memcpy(sc->sc_edid_data, prop_data_data_nocopy(edid_data), | | 229 | memcpy(sc->sc_edid_data, prop_data_data_nocopy(edid_data), |
230 | sc->sc_edid_size); | | 230 | sc->sc_edid_size); |
231 | | | 231 | |
232 | edid_parse(sc->sc_edid_data, &ei); | | 232 | edid_parse(sc->sc_edid_data, &ei); |
233 | edid_print(&ei); | | 233 | edid_print(&ei); |
234 | } | | 234 | } |
235 | | | 235 | |
236 | if (!is_console) | | 236 | if (!is_console) |
237 | return; | | 237 | return; |
238 | | | 238 | |
239 | /* setup video DMA */ | | 239 | /* setup video DMA */ |
240 | sc->sc_vramsize = (12 << 20) + 0x1000; /* 12MB + CLUT */ | | 240 | sc->sc_vramsize = (12 << 20) + 0x1000; /* 12MB + CLUT */ |
241 | | | 241 | |
242 | if (bus_dmamem_alloc(sc->sc_dmat, sc->sc_vramsize, 0, 0, | | 242 | if (bus_dmamem_alloc(sc->sc_dmat, sc->sc_vramsize, 0, 0, |
243 | sc->sc_dmamem, 1, &segs, BUS_DMA_NOWAIT) != 0) { | | 243 | sc->sc_dmamem, 1, &segs, BUS_DMA_NOWAIT) != 0) { |
244 | panic("boo!\n"); | | 244 | panic("boo!\n"); |
245 | aprint_error_dev(sc->sc_dev, | | 245 | aprint_error_dev(sc->sc_dev, |
246 | "failed to allocate video memory\n"); | | 246 | "failed to allocate video memory\n"); |
247 | return; | | 247 | return; |
248 | } | | 248 | } |
249 | | | 249 | |
250 | if (bus_dmamem_map(sc->sc_dmat, sc->sc_dmamem, 1, sc->sc_vramsize, | | 250 | if (bus_dmamem_map(sc->sc_dmat, sc->sc_dmamem, 1, sc->sc_vramsize, |
251 | &sc->sc_vramaddr, BUS_DMA_NOWAIT | BUS_DMA_COHERENT) != 0) { | | 251 | &sc->sc_vramaddr, BUS_DMA_NOWAIT | BUS_DMA_COHERENT) != 0) { |
252 | aprint_error_dev(sc->sc_dev, "failed to map video RAM\n"); | | 252 | aprint_error_dev(sc->sc_dev, "failed to map video RAM\n"); |
253 | return; | | 253 | return; |
254 | } | | 254 | } |
255 | sc->sc_fbaddr = (uint8_t *)sc->sc_vramaddr + 0x1000; | | 255 | sc->sc_fbaddr = (uint8_t *)sc->sc_vramaddr + 0x1000; |
256 | sc->sc_clut = sc->sc_vramaddr; | | 256 | sc->sc_clut = sc->sc_vramaddr; |
257 | | | 257 | |
258 | if (bus_dmamap_create(sc->sc_dmat, sc->sc_vramsize, 1, sc->sc_vramsize, | | 258 | if (bus_dmamap_create(sc->sc_dmat, sc->sc_vramsize, 1, sc->sc_vramsize, |
259 | 0, BUS_DMA_NOWAIT, &sc->sc_dmamap) != 0) { | | 259 | 0, BUS_DMA_NOWAIT, &sc->sc_dmamap) != 0) { |
260 | aprint_error_dev(sc->sc_dev, "failed to create DMA map\n"); | | 260 | aprint_error_dev(sc->sc_dev, "failed to create DMA map\n"); |
261 | return; | | 261 | return; |
262 | } | | 262 | } |
263 | | | 263 | |
264 | if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmamap, sc->sc_vramaddr, | | 264 | if (bus_dmamap_load(sc->sc_dmat, sc->sc_dmamap, sc->sc_vramaddr, |
265 | sc->sc_vramsize, NULL, BUS_DMA_NOWAIT) != 0) { | | 265 | sc->sc_vramsize, NULL, BUS_DMA_NOWAIT) != 0) { |
266 | aprint_error_dev(sc->sc_dev, "failed to load DMA map\n"); | | 266 | aprint_error_dev(sc->sc_dev, "failed to load DMA map\n"); |
267 | return; | | 267 | return; |
268 | } | | 268 | } |
269 | | | 269 | |
270 | if (sc->sc_depth == 8) { | | 270 | if (sc->sc_depth == 8) { |
271 | j = 0; | | 271 | j = 0; |
272 | for (i = 0; i < 256; i++) { | | 272 | for (i = 0; i < 256; i++) { |
273 | sc->sc_cmap_red[i] = rasops_cmap[j]; | | 273 | sc->sc_cmap_red[i] = rasops_cmap[j]; |
274 | sc->sc_cmap_green[i] = rasops_cmap[j + 1]; | | 274 | sc->sc_cmap_green[i] = rasops_cmap[j + 1]; |
275 | sc->sc_cmap_blue[i] = rasops_cmap[j + 2]; | | 275 | sc->sc_cmap_blue[i] = rasops_cmap[j + 2]; |
276 | j += 3; | | 276 | j += 3; |
277 | } | | 277 | } |
278 | } else { | | 278 | } else { |
279 | for (i = 0; i < 256; i++) { | | 279 | for (i = 0; i < 256; i++) { |
280 | sc->sc_cmap_red[i] = i; | | 280 | sc->sc_cmap_red[i] = i; |
281 | sc->sc_cmap_green[i] = i; | | 281 | sc->sc_cmap_green[i] = i; |
282 | sc->sc_cmap_blue[i] = i; | | 282 | sc->sc_cmap_blue[i] = i; |
283 | } | | 283 | } |
284 | } | | 284 | } |
285 | omapfb_restore_palette(sc); | | 285 | omapfb_restore_palette(sc); |
286 | | | 286 | |
287 | /* now that we have video memory, stick it to the video controller */ | | 287 | /* now that we have video memory, stick it to the video controller */ |
288 | | | 288 | |
289 | reg = bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_SYSCONFIG); | | 289 | reg = bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_SYSCONFIG); |
290 | reg &= ~(OMAP_DISPC_SYSC_STANDBY_MASK | OMAP_DISPC_SYSC_IDLE_MASK); | | 290 | reg &= ~(OMAP_DISPC_SYSC_STANDBY_MASK | OMAP_DISPC_SYSC_IDLE_MASK); |
291 | reg |= OMAP_DISPC_SYSC_SMART_STANDBY | OMAP_DISPC_SYSC_SMART_IDLE | | | 291 | reg |= OMAP_DISPC_SYSC_SMART_STANDBY | OMAP_DISPC_SYSC_SMART_IDLE | |
292 | OMAP_DISPC_SYSC_WAKEUP_ENABLE | OMAP_SYSCONF_AUTOIDLE; | | 292 | OMAP_DISPC_SYSC_WAKEUP_ENABLE | OMAP_SYSCONF_AUTOIDLE; |
293 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_SYSCONFIG, reg); | | 293 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_SYSCONFIG, reg); |
294 | | | 294 | |
295 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DSS_SYSCONFIG, | | 295 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DSS_SYSCONFIG, |
296 | OMAP_SYSCONF_AUTOIDLE); | | 296 | OMAP_SYSCONF_AUTOIDLE); |
297 | reg = bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_CONFIG); | | 297 | reg = bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_CONFIG); |
298 | reg = 0x8; | | 298 | reg = 0x8; |
299 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_CONFIG, reg); | | 299 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_CONFIG, reg); |
300 | | | 300 | |
301 | sc->sc_fbhwaddr = sc->sc_dmamem->ds_addr + 0x1000; | | 301 | sc->sc_fbhwaddr = sc->sc_dmamem->ds_addr + 0x1000; |
302 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_BASE_0, | | 302 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_BASE_0, |
303 | sc->sc_fbhwaddr); | | 303 | sc->sc_fbhwaddr); |
304 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_TABLE_BASE, | | 304 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_TABLE_BASE, |
305 | sc->sc_dmamem->ds_addr); | | 305 | sc->sc_dmamem->ds_addr); |
306 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_POSITION, | | 306 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_POSITION, |
307 | 0); | | 307 | 0); |
308 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_PRELOAD, 0x60); | | 308 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_PRELOAD, 0x60); |
309 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_ATTRIBUTES, | | 309 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_ATTRIBUTES, |
310 | OMAP_DISPC_ATTR_ENABLE | | | 310 | OMAP_DISPC_ATTR_ENABLE | |
311 | OMAP_DISPC_ATTR_BURST_16x32 | | | 311 | OMAP_DISPC_ATTR_BURST_16x32 | |
312 | /*OMAP_DISPC_ATTR_8BIT*/OMAP_DISPC_ATTR_RGB16 | | 312 | /*OMAP_DISPC_ATTR_8BIT*/OMAP_DISPC_ATTR_RGB16 |
313 | | OMAP_DISPC_ATTR_REPLICATION); | | 313 | | OMAP_DISPC_ATTR_REPLICATION); |
314 | #if 0 | | 314 | #if 0 |
315 | printf("dss_control: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DSS_CONTROL)); | | 315 | printf("dss_control: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DSS_CONTROL)); |
316 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DSS_CONTROL, | | 316 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DSS_CONTROL, |
317 | /*OMAP_DSSCTRL_DISPC_CLK_SWITCH |*/ | | 317 | /*OMAP_DSSCTRL_DISPC_CLK_SWITCH |*/ |
318 | OMAP_DSSCTRL_CLOCK_MODE | | | 318 | OMAP_DSSCTRL_CLOCK_MODE | |
319 | OMAP_DSSCTRL_VENC_CLOCK_4X | | | 319 | OMAP_DSSCTRL_VENC_CLOCK_4X | |
320 | OMAP_DSSCTRL_DAC_DEMEN); | | 320 | OMAP_DSSCTRL_DAC_DEMEN); |
321 | #endif | | 321 | #endif |
322 | | | 322 | |
323 | /* VENC to NTSC mode */ | | 323 | /* VENC to NTSC mode */ |
324 | adr = OMAPFB_VENC_F_CONTROL; | | 324 | adr = OMAPFB_VENC_F_CONTROL; |
325 | #if 0 | | 325 | #if 0 |
326 | for (i = 0; i < __arraycount(venc_mode_ntsc); i++) { | | 326 | for (i = 0; i < __arraycount(venc_mode_ntsc); i++) { |
327 | bus_space_write_4(sc->sc_iot, sc->sc_regh, adr, | | 327 | bus_space_write_4(sc->sc_iot, sc->sc_regh, adr, |
328 | venc_mode_ntsc[i]); | | 328 | venc_mode_ntsc[i]); |
329 | adr += 4; | | 329 | adr += 4; |
330 | } | | 330 | } |
331 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_VENC_F_CONTROL, | | 331 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_VENC_F_CONTROL, |
332 | venc_mode_ntsc[0]); | | 332 | venc_mode_ntsc[0]); |
333 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_VENC_SYNC_CTRL, | | 333 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_VENC_SYNC_CTRL, |
334 | venc_mode_ntsc[2]); | | 334 | venc_mode_ntsc[2]); |
335 | | | 335 | |
336 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_DEFAULT_COLOR_1, | | 336 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_DEFAULT_COLOR_1, |
337 | 0x00ff0000); | | 337 | 0x00ff0000); |
338 | #endif | | 338 | #endif |
339 | | | 339 | |
340 | /* now we make sure the video output is actually running */ | | 340 | /* now we make sure the video output is actually running */ |
341 | reg = bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_CONTROL); | | 341 | reg = bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_CONTROL); |
342 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_CONTROL, | | 342 | bus_space_write_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_CONTROL, |
343 | reg | OMAP_DISPC_CTRL_GO_LCD | OMAP_DISPC_CTRL_GO_DIGITAL); | | 343 | reg | OMAP_DISPC_CTRL_GO_LCD | OMAP_DISPC_CTRL_GO_DIGITAL); |
344 | | | 344 | |
345 | #ifdef OMAPFB_DEBUG | | 345 | #ifdef OMAPFB_DEBUG |
346 | printf("attr: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_ATTRIBUTES)); | | 346 | printf("attr: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_ATTRIBUTES)); |
347 | printf("preload: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_PRELOAD)); | | 347 | printf("preload: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_PRELOAD)); |
348 | printf("config: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_CONFIG)); | | 348 | printf("config: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_CONFIG)); |
349 | printf("control: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_CONTROL)); | | 349 | printf("control: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_CONTROL)); |
350 | printf("dss_control: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DSS_CONTROL)); | | 350 | printf("dss_control: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DSS_CONTROL)); |
351 | printf("threshold: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_FIFO_THRESH)); | | 351 | printf("threshold: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_FIFO_THRESH)); |
352 | printf("GFX size: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_SIZE)); | | 352 | printf("GFX size: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_SIZE)); |
353 | printf("row inc: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_ROW_INC)); | | 353 | printf("row inc: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_ROW_INC)); |
354 | printf("pixel inc: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_PIXEL_INC)); | | 354 | printf("pixel inc: %08x\n", bus_space_read_4(sc->sc_iot, sc->sc_regh, OMAPFB_DISPC_GFX_PIXEL_INC)); |
355 | #endif | | 355 | #endif |
356 | | | 356 | |
357 | sc->sc_defaultscreen_descr = (struct wsscreen_descr){ | | 357 | sc->sc_defaultscreen_descr = (struct wsscreen_descr){ |
358 | "default", | | 358 | "default", |
359 | 0, 0, | | 359 | 0, 0, |
360 | NULL, | | 360 | NULL, |
361 | 8, 16, | | 361 | 8, 16, |
362 | WSSCREEN_WSCOLORS | WSSCREEN_HILIT, | | 362 | WSSCREEN_WSCOLORS | WSSCREEN_HILIT, |
363 | NULL | | 363 | NULL |
364 | }; | | 364 | }; |
365 | sc->sc_screens[0] = &sc->sc_defaultscreen_descr; | | 365 | sc->sc_screens[0] = &sc->sc_defaultscreen_descr; |
366 | sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens}; | | 366 | sc->sc_screenlist = (struct wsscreen_list){1, sc->sc_screens}; |
367 | sc->sc_mode = WSDISPLAYIO_MODE_EMUL; | | 367 | sc->sc_mode = WSDISPLAYIO_MODE_EMUL; |
368 | sc->sc_locked = 0; | | 368 | sc->sc_locked = 0; |
369 | | | 369 | |
370 | vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr, | | 370 | vcons_init(&sc->vd, sc, &sc->sc_defaultscreen_descr, |
371 | &omapfb_accessops); | | 371 | &omapfb_accessops); |
372 | sc->vd.init_screen = omapfb_init_screen; | | 372 | sc->vd.init_screen = omapfb_init_screen; |
373 | | | 373 | |
374 | /* init engine here */ | | 374 | /* init engine here */ |
375 | #if NOMAPDMA > 0 | | 375 | #if NOMAPDMA > 0 |
376 | omapfb_init(sc); | | 376 | omapfb_init(sc); |
377 | #endif | | 377 | #endif |
378 | | | 378 | |
379 | ri = &sc->sc_console_screen.scr_ri; | | 379 | ri = &sc->sc_console_screen.scr_ri; |
380 | | | 380 | |
381 | if (is_console) { | | 381 | if (is_console) { |
382 | vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1, | | 382 | vcons_init_screen(&sc->vd, &sc->sc_console_screen, 1, |
383 | &defattr); | | 383 | &defattr); |
384 | sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC; | | 384 | sc->sc_console_screen.scr_flags |= VCONS_SCREEN_IS_STATIC; |
385 | | | 385 | |
386 | #if NOMAPDMA > 0 | | 386 | #if NOMAPDMA > 0 |
387 | omapfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height, | | 387 | omapfb_rectfill(sc, 0, 0, sc->sc_width, sc->sc_height, |
388 | ri->ri_devcmap[(defattr >> 16) & 0xff]); | | 388 | ri->ri_devcmap[(defattr >> 16) & 0xff]); |
389 | #endif | | 389 | #endif |
390 | sc->sc_defaultscreen_descr.textops = &ri->ri_ops; | | 390 | sc->sc_defaultscreen_descr.textops = &ri->ri_ops; |
391 | sc->sc_defaultscreen_descr.capabilities = ri->ri_caps; | | 391 | sc->sc_defaultscreen_descr.capabilities = ri->ri_caps; |
392 | sc->sc_defaultscreen_descr.nrows = ri->ri_rows; | | 392 | sc->sc_defaultscreen_descr.nrows = ri->ri_rows; |
393 | sc->sc_defaultscreen_descr.ncols = ri->ri_cols; | | 393 | sc->sc_defaultscreen_descr.ncols = ri->ri_cols; |
394 | wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0, | | 394 | wsdisplay_cnattach(&sc->sc_defaultscreen_descr, ri, 0, 0, |
395 | defattr); | | 395 | defattr); |
396 | vcons_replay_msgbuf(&sc->sc_console_screen); | | 396 | vcons_replay_msgbuf(&sc->sc_console_screen); |
397 | } else { | | 397 | } else { |
398 | /* | | 398 | /* |
399 | * since we're not the console we can postpone the rest | | 399 | * since we're not the console we can postpone the rest |
400 | * until someone actually allocates a screen for us | | 400 | * until someone actually allocates a screen for us |
401 | */ | | 401 | */ |
402 | (*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr); | | 402 | (*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr); |
403 | } | | 403 | } |
404 | | | 404 | |
405 | aa.console = is_console; | | 405 | aa.console = is_console; |
406 | aa.scrdata = &sc->sc_screenlist; | | 406 | aa.scrdata = &sc->sc_screenlist; |
407 | aa.accessops = &omapfb_accessops; | | 407 | aa.accessops = &omapfb_accessops; |
408 | aa.accesscookie = &sc->vd; | | 408 | aa.accesscookie = &sc->vd; |
409 | | | 409 | |
410 | config_found(sc->sc_dev, &aa, wsemuldisplaydevprint); | | 410 | config_found(sc->sc_dev, &aa, wsemuldisplaydevprint); |
411 | #ifdef OMAPFB_DEBUG | | 411 | #ifdef OMAPFB_DEBUG |
412 | #if NOMAPDMA > 0 | | 412 | #if NOMAPDMA > 0 |
413 | omapfb_rectfill(sc, 100, 100, 100, 100, 0xe000); | | 413 | omapfb_rectfill(sc, 100, 100, 100, 100, 0xe000); |
414 | omapfb_rectfill(sc, 100, 200, 100, 100, 0x01f8); | | 414 | omapfb_rectfill(sc, 100, 200, 100, 100, 0x01f8); |
415 | omapfb_rectfill(sc, 200, 100, 100, 100, 0x01f8); | | 415 | omapfb_rectfill(sc, 200, 100, 100, 100, 0x01f8); |
416 | omapfb_rectfill(sc, 200, 200, 100, 100, 0xe000); | | 416 | omapfb_rectfill(sc, 200, 200, 100, 100, 0xe000); |
417 | omapfb_bitblt(sc, 100, 100, 400, 100, 200, 200, 0); | | 417 | omapfb_bitblt(sc, 100, 100, 400, 100, 200, 200, 0); |
418 | /* let's see if we can draw something */ | | 418 | /* let's see if we can draw something */ |
419 | printf("OMAPDMAC_CDAC: %08x\n", omapdma_read_ch_reg(0, OMAPDMAC_CDAC)); | | 419 | printf("OMAPDMAC_CDAC: %08x\n", omapdma_read_ch_reg(0, OMAPDMAC_CDAC)); |
420 | printf("OMAPDMAC_CSR: %08x\n", omapdma_read_ch_reg(0, OMAPDMAC_CSR)); | | 420 | printf("OMAPDMAC_CSR: %08x\n", omapdma_read_ch_reg(0, OMAPDMAC_CSR)); |
421 | printf("OMAPDMAC_CCR: %08x\n", omapdma_read_ch_reg(0, OMAPDMAC_CCR)); | | 421 | printf("OMAPDMAC_CCR: %08x\n", omapdma_read_ch_reg(0, OMAPDMAC_CCR)); |
422 | #endif | | 422 | #endif |
423 | #endif | | 423 | #endif |
424 | } | | 424 | } |
425 | | | 425 | |
426 | static int | | 426 | static int |
427 | omapfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, | | 427 | omapfb_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, |
428 | struct lwp *l) | | 428 | struct lwp *l) |
429 | { | | 429 | { |
430 | struct vcons_data *vd = v; | | 430 | struct vcons_data *vd = v; |
431 | struct omapfb_softc *sc = vd->cookie; | | 431 | struct omapfb_softc *sc = vd->cookie; |
432 | struct wsdisplay_fbinfo *wdf; | | 432 | struct wsdisplay_fbinfo *wdf; |
433 | struct vcons_screen *ms = vd->active; | | 433 | struct vcons_screen *ms = vd->active; |
434 | | | 434 | |
435 | switch (cmd) { | | 435 | switch (cmd) { |
436 | | | 436 | |
437 | case WSDISPLAYIO_GTYPE: | | 437 | case WSDISPLAYIO_GTYPE: |
438 | *(u_int *)data = WSDISPLAY_TYPE_PCIMISC; | | 438 | *(u_int *)data = WSDISPLAY_TYPE_OMAP3; |
439 | return 0; | | 439 | return 0; |
440 | | | 440 | |
| | | 441 | case WSDISPLAYIO_GET_BUSID: |
| | | 442 | { |
| | | 443 | struct wsdisplayio_bus_id *busid; |
| | | 444 | |
| | | 445 | busid = data; |
| | | 446 | busid->bus_type = WSDISPLAYIO_BUS_SOC; |
| | | 447 | return 0; |
| | | 448 | } |
| | | 449 | |
441 | case WSDISPLAYIO_GINFO: | | 450 | case WSDISPLAYIO_GINFO: |
442 | if (ms == NULL) | | 451 | if (ms == NULL) |
443 | return ENODEV; | | 452 | return ENODEV; |
444 | wdf = (void *)data; | | 453 | wdf = (void *)data; |
445 | wdf->height = ms->scr_ri.ri_height; | | 454 | wdf->height = ms->scr_ri.ri_height; |
446 | wdf->width = ms->scr_ri.ri_width; | | 455 | wdf->width = ms->scr_ri.ri_width; |
447 | wdf->depth = ms->scr_ri.ri_depth; | | 456 | wdf->depth = ms->scr_ri.ri_depth; |
448 | wdf->cmsize = 256; | | 457 | wdf->cmsize = 256; |
449 | return 0; | | 458 | return 0; |
450 | | | 459 | |
451 | case WSDISPLAYIO_GETCMAP: | | 460 | case WSDISPLAYIO_GETCMAP: |
452 | return omapfb_getcmap(sc, | | 461 | return omapfb_getcmap(sc, |
453 | (struct wsdisplay_cmap *)data); | | 462 | (struct wsdisplay_cmap *)data); |
454 | | | 463 | |
455 | case WSDISPLAYIO_PUTCMAP: | | 464 | case WSDISPLAYIO_PUTCMAP: |
456 | return omapfb_putcmap(sc, | | 465 | return omapfb_putcmap(sc, |
457 | (struct wsdisplay_cmap *)data); | | 466 | (struct wsdisplay_cmap *)data); |
458 | | | 467 | |
459 | case WSDISPLAYIO_LINEBYTES: | | 468 | case WSDISPLAYIO_LINEBYTES: |
460 | *(u_int *)data = sc->sc_stride; | | 469 | *(u_int *)data = sc->sc_stride; |
461 | return 0; | | 470 | return 0; |
462 | | | 471 | |
463 | case WSDISPLAYIO_SMODE: | | 472 | case WSDISPLAYIO_SMODE: |
464 | { | | 473 | { |
465 | int new_mode = *(int*)data; | | 474 | int new_mode = *(int*)data; |
466 | | | 475 | |
467 | /* notify the bus backend */ | | 476 | /* notify the bus backend */ |
468 | if (new_mode != sc->sc_mode) { | | 477 | if (new_mode != sc->sc_mode) { |
469 | sc->sc_mode = new_mode; | | 478 | sc->sc_mode = new_mode; |
470 | if(new_mode == WSDISPLAYIO_MODE_EMUL) { | | 479 | if(new_mode == WSDISPLAYIO_MODE_EMUL) { |
471 | vcons_redraw_screen(ms); | | 480 | vcons_redraw_screen(ms); |
472 | } | | 481 | } |
473 | } | | 482 | } |
474 | } | | 483 | } |
475 | return 0; | | 484 | return 0; |
476 | } | | 485 | } |
477 | return EPASSTHROUGH; | | 486 | return EPASSTHROUGH; |
478 | } | | 487 | } |
479 | | | 488 | |
480 | static paddr_t | | 489 | static paddr_t |
481 | omapfb_mmap(void *v, void *vs, off_t offset, int prot) | | 490 | omapfb_mmap(void *v, void *vs, off_t offset, int prot) |
482 | { | | 491 | { |
483 | paddr_t pa = -1; | | 492 | paddr_t pa = -1; |
484 | struct vcons_data *vd = v; | | 493 | struct vcons_data *vd = v; |
485 | struct omapfb_softc *sc = vd->cookie; | | 494 | struct omapfb_softc *sc = vd->cookie; |
486 | | | 495 | |
487 | /* 'regular' framebuffer mmap()ing */ | | 496 | /* 'regular' framebuffer mmap()ing */ |
488 | if (offset < (12 << 20)) { | | 497 | if (offset < (12 << 20)) { |
489 | pa = bus_dmamem_mmap(sc->sc_dmat, sc->sc_dmamem, 1, | | 498 | pa = bus_dmamem_mmap(sc->sc_dmat, sc->sc_dmamem, 1, |
490 | offset + 0x1000, prot, BUS_DMA_COHERENT); | | 499 | offset + 0x1000, prot, BUS_DMA_COHERENT); |
491 | return pa; | | 500 | return pa; |
492 | } | | 501 | } |
493 | return pa; | | 502 | return pa; |
494 | } | | 503 | } |
495 | | | 504 | |
496 | static void | | 505 | static void |
497 | omapfb_init_screen(void *cookie, struct vcons_screen *scr, | | 506 | omapfb_init_screen(void *cookie, struct vcons_screen *scr, |
498 | int existing, long *defattr) | | 507 | int existing, long *defattr) |
499 | { | | 508 | { |
500 | struct omapfb_softc *sc = cookie; | | 509 | struct omapfb_softc *sc = cookie; |
501 | struct rasops_info *ri = &scr->scr_ri; | | 510 | struct rasops_info *ri = &scr->scr_ri; |
502 | | | 511 | |
503 | ri->ri_depth = sc->sc_depth; | | 512 | ri->ri_depth = sc->sc_depth; |
504 | ri->ri_width = sc->sc_width; | | 513 | ri->ri_width = sc->sc_width; |
505 | ri->ri_height = sc->sc_height; | | 514 | ri->ri_height = sc->sc_height; |
506 | ri->ri_stride = sc->sc_stride; | | 515 | ri->ri_stride = sc->sc_stride; |
507 | ri->ri_flg = RI_CENTER | RI_FULLCLEAR; | | 516 | ri->ri_flg = RI_CENTER | RI_FULLCLEAR; |
508 | | | 517 | |
509 | ri->ri_bits = (char *)sc->sc_fbaddr; | | 518 | ri->ri_bits = (char *)sc->sc_fbaddr; |
510 | | | 519 | |
511 | #if NOMAPDMA < 1 | | 520 | #if NOMAPDMA < 1 |
512 | scr->scr_flags |= VCONS_DONT_READ; | | 521 | scr->scr_flags |= VCONS_DONT_READ; |
513 | #endif | | 522 | #endif |
514 | | | 523 | |
515 | if (existing) { | | 524 | if (existing) { |
516 | ri->ri_flg |= RI_CLEAR; | | 525 | ri->ri_flg |= RI_CLEAR; |
517 | } | | 526 | } |
518 | | | 527 | |
519 | rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8); | | 528 | rasops_init(ri, sc->sc_height / 8, sc->sc_width / 8); |
520 | ri->ri_caps = WSSCREEN_WSCOLORS; | | 529 | ri->ri_caps = WSSCREEN_WSCOLORS; |
521 | | | 530 | |
522 | rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight, | | 531 | rasops_reconfig(ri, sc->sc_height / ri->ri_font->fontheight, |
523 | sc->sc_width / ri->ri_font->fontwidth); | | 532 | sc->sc_width / ri->ri_font->fontwidth); |
524 | | | 533 | |
525 | ri->ri_hw = scr; | | 534 | ri->ri_hw = scr; |
526 | | | 535 | |
527 | #if NOMAPDMA > 0 | | 536 | #if NOMAPDMA > 0 |
528 | ri->ri_ops.copyrows = omapfb_copyrows; | | 537 | ri->ri_ops.copyrows = omapfb_copyrows; |
529 | ri->ri_ops.copycols = omapfb_copycols; | | 538 | ri->ri_ops.copycols = omapfb_copycols; |
530 | ri->ri_ops.eraserows = omapfb_eraserows; | | 539 | ri->ri_ops.eraserows = omapfb_eraserows; |
531 | ri->ri_ops.erasecols = omapfb_erasecols; | | 540 | ri->ri_ops.erasecols = omapfb_erasecols; |
532 | ri->ri_ops.cursor = omapfb_cursor; | | 541 | ri->ri_ops.cursor = omapfb_cursor; |
533 | sc->sc_putchar = ri->ri_ops.putchar; | | 542 | sc->sc_putchar = ri->ri_ops.putchar; |
534 | ri->ri_ops.putchar = omapfb_putchar; | | 543 | ri->ri_ops.putchar = omapfb_putchar; |
535 | #endif | | 544 | #endif |
536 | } | | 545 | } |
537 | | | 546 | |
538 | static int | | 547 | static int |
539 | omapfb_putcmap(struct omapfb_softc *sc, struct wsdisplay_cmap *cm) | | 548 | omapfb_putcmap(struct omapfb_softc *sc, struct wsdisplay_cmap *cm) |
540 | { | | 549 | { |
541 | u_char *r, *g, *b; | | 550 | u_char *r, *g, *b; |
542 | u_int index = cm->index; | | 551 | u_int index = cm->index; |
543 | u_int count = cm->count; | | 552 | u_int count = cm->count; |
544 | int i, error; | | 553 | int i, error; |
545 | u_char rbuf[256], gbuf[256], bbuf[256]; | | 554 | u_char rbuf[256], gbuf[256], bbuf[256]; |
546 | | | 555 | |
547 | if (cm->index >= 256 || cm->count > 256 || | | 556 | if (cm->index >= 256 || cm->count > 256 || |
548 | (cm->index + cm->count) > 256) | | 557 | (cm->index + cm->count) > 256) |
549 | return EINVAL; | | 558 | return EINVAL; |
550 | error = copyin(cm->red, &rbuf[index], count); | | 559 | error = copyin(cm->red, &rbuf[index], count); |
551 | if (error) | | 560 | if (error) |
552 | return error; | | 561 | return error; |
553 | error = copyin(cm->green, &gbuf[index], count); | | 562 | error = copyin(cm->green, &gbuf[index], count); |
554 | if (error) | | 563 | if (error) |
555 | return error; | | 564 | return error; |
556 | error = copyin(cm->blue, &bbuf[index], count); | | 565 | error = copyin(cm->blue, &bbuf[index], count); |
557 | if (error) | | 566 | if (error) |
558 | return error; | | 567 | return error; |
559 | | | 568 | |
560 | memcpy(&sc->sc_cmap_red[index], &rbuf[index], count); | | 569 | memcpy(&sc->sc_cmap_red[index], &rbuf[index], count); |
561 | memcpy(&sc->sc_cmap_green[index], &gbuf[index], count); | | 570 | memcpy(&sc->sc_cmap_green[index], &gbuf[index], count); |
562 | memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count); | | 571 | memcpy(&sc->sc_cmap_blue[index], &bbuf[index], count); |
563 | | | 572 | |
564 | r = &sc->sc_cmap_red[index]; | | 573 | r = &sc->sc_cmap_red[index]; |
565 | g = &sc->sc_cmap_green[index]; | | 574 | g = &sc->sc_cmap_green[index]; |
566 | b = &sc->sc_cmap_blue[index]; | | 575 | b = &sc->sc_cmap_blue[index]; |
567 | | | 576 | |
568 | for (i = 0; i < count; i++) { | | 577 | for (i = 0; i < count; i++) { |
569 | omapfb_putpalreg(sc, index, *r, *g, *b); | | 578 | omapfb_putpalreg(sc, index, *r, *g, *b); |
570 | index++; | | 579 | index++; |
571 | r++, g++, b++; | | 580 | r++, g++, b++; |
572 | } | | 581 | } |
573 | return 0; | | 582 | return 0; |
574 | } | | 583 | } |
575 | | | 584 | |
576 | static int | | 585 | static int |
577 | omapfb_getcmap(struct omapfb_softc *sc, struct wsdisplay_cmap *cm) | | 586 | omapfb_getcmap(struct omapfb_softc *sc, struct wsdisplay_cmap *cm) |
578 | { | | 587 | { |
579 | u_int index = cm->index; | | 588 | u_int index = cm->index; |
580 | u_int count = cm->count; | | 589 | u_int count = cm->count; |
581 | int error; | | 590 | int error; |
582 | | | 591 | |
583 | if (index >= 255 || count > 256 || index + count > 256) | | 592 | if (index >= 255 || count > 256 || index + count > 256) |
584 | return EINVAL; | | 593 | return EINVAL; |
585 | | | 594 | |
586 | error = copyout(&sc->sc_cmap_red[index], cm->red, count); | | 595 | error = copyout(&sc->sc_cmap_red[index], cm->red, count); |
587 | if (error) | | 596 | if (error) |
588 | return error; | | 597 | return error; |
589 | error = copyout(&sc->sc_cmap_green[index], cm->green, count); | | 598 | error = copyout(&sc->sc_cmap_green[index], cm->green, count); |
590 | if (error) | | 599 | if (error) |
591 | return error; | | 600 | return error; |
592 | error = copyout(&sc->sc_cmap_blue[index], cm->blue, count); | | 601 | error = copyout(&sc->sc_cmap_blue[index], cm->blue, count); |
593 | if (error) | | 602 | if (error) |
594 | return error; | | 603 | return error; |
595 | | | 604 | |
596 | return 0; | | 605 | return 0; |
597 | } | | 606 | } |
598 | | | 607 | |
599 | static void | | 608 | static void |
600 | omapfb_restore_palette(struct omapfb_softc *sc) | | 609 | omapfb_restore_palette(struct omapfb_softc *sc) |
601 | { | | 610 | { |
602 | int i; | | 611 | int i; |
603 | | | 612 | |
604 | for (i = 0; i < 256; i++) { | | 613 | for (i = 0; i < 256; i++) { |
605 | omapfb_putpalreg(sc, i, sc->sc_cmap_red[i], | | 614 | omapfb_putpalreg(sc, i, sc->sc_cmap_red[i], |
606 | sc->sc_cmap_green[i], sc->sc_cmap_blue[i]); | | 615 | sc->sc_cmap_green[i], sc->sc_cmap_blue[i]); |
607 | } | | 616 | } |
608 | } | | 617 | } |
609 | | | 618 | |
610 | static void | | 619 | static void |
611 | omapfb_putpalreg(struct omapfb_softc *sc, int idx, uint8_t r, uint8_t g, | | 620 | omapfb_putpalreg(struct omapfb_softc *sc, int idx, uint8_t r, uint8_t g, |
612 | uint8_t b) | | 621 | uint8_t b) |
613 | { | | 622 | { |
614 | uint32_t reg; | | 623 | uint32_t reg; |
615 | | | 624 | |
616 | if ((idx < 0) || (idx > 255)) | | 625 | if ((idx < 0) || (idx > 255)) |
617 | return; | | 626 | return; |
618 | /* whack the DAC */ | | 627 | /* whack the DAC */ |
619 | reg = (r << 16) | (g << 8) | b; | | 628 | reg = (r << 16) | (g << 8) | b; |
620 | sc->sc_clut[idx] = reg; | | 629 | sc->sc_clut[idx] = reg; |
621 | | | 630 | |
622 | } | | 631 | } |
623 | | | 632 | |
624 | #if NOMAPDMA > 0 | | 633 | #if NOMAPDMA > 0 |
625 | static void | | 634 | static void |
626 | omapfb_init(struct omapfb_softc *sc) | | 635 | omapfb_init(struct omapfb_softc *sc) |
627 | { | | 636 | { |
628 | omapdma_write_ch_reg(0, OMAPDMAC_CLNK_CTRL, 0); | | 637 | omapdma_write_ch_reg(0, OMAPDMAC_CLNK_CTRL, 0); |
629 | omapdma_write_ch_reg(0, OMAPDMAC_CICRI, 0); | | 638 | omapdma_write_ch_reg(0, OMAPDMAC_CICRI, 0); |
630 | omapdma_write_ch_reg(0, OMAPDMAC_CSDPI, | | 639 | omapdma_write_ch_reg(0, OMAPDMAC_CSDPI, |
631 | CSDPI_SRC_BURST_64 | CSDPI_DST_BURST_64 | | | 640 | CSDPI_SRC_BURST_64 | CSDPI_DST_BURST_64 | |
632 | CSDPI_WRITE_POSTED | CSDPI_DATA_TYPE_16); | | 641 | CSDPI_WRITE_POSTED | CSDPI_DATA_TYPE_16); |
633 | } | | 642 | } |
634 | | | 643 | |
635 | static void | | 644 | static void |
636 | omapfb_wait_idle(struct omapfb_softc *sc) | | 645 | omapfb_wait_idle(struct omapfb_softc *sc) |
637 | { | | 646 | { |
638 | while ((omapdma_read_ch_reg(0, OMAPDMAC_CCR) & CCR_WR_ACTIVE) != 0); | | 647 | while ((omapdma_read_ch_reg(0, OMAPDMAC_CCR) & CCR_WR_ACTIVE) != 0); |
639 | } | | 648 | } |
640 | | | 649 | |
641 | static void | | 650 | static void |
642 | omapfb_rectfill(struct omapfb_softc *sc, int x, int y, int wi, int he, | | 651 | omapfb_rectfill(struct omapfb_softc *sc, int x, int y, int wi, int he, |
643 | uint32_t colour) | | 652 | uint32_t colour) |
644 | { | | 653 | { |
645 | int bpp = sc->sc_depth >> 3; /* bytes per pixel */ | | 654 | int bpp = sc->sc_depth >> 3; /* bytes per pixel */ |
646 | int width_in_bytes = wi * bpp; | | 655 | int width_in_bytes = wi * bpp; |
647 | uint32_t daddr; | | 656 | uint32_t daddr; |
648 | | | 657 | |
649 | daddr = sc->sc_fbhwaddr + sc->sc_stride * y + x * bpp; | | 658 | daddr = sc->sc_fbhwaddr + sc->sc_stride * y + x * bpp; |
650 | omapfb_wait_idle(sc); | | 659 | omapfb_wait_idle(sc); |
651 | | | 660 | |
652 | /* | | 661 | /* |
653 | * stupid hardware | | 662 | * stupid hardware |
654 | * in 32bit mode the DMA controller always writes 0 into the upper byte, so we | | 663 | * in 32bit mode the DMA controller always writes 0 into the upper byte, so we |
655 | * can use this mode only if we actually want that | | 664 | * can use this mode only if we actually want that |
656 | */ | | 665 | */ |
657 | if (((colour & 0xff00) == 0) && | | 666 | if (((colour & 0xff00) == 0) && |
658 | (((daddr | width_in_bytes) & 3) == 0)) { | | 667 | (((daddr | width_in_bytes) & 3) == 0)) { |
659 | /* | | 668 | /* |
660 | * everything is properly aligned so we can copy stuff in | | 669 | * everything is properly aligned so we can copy stuff in |
661 | * 32bit chunks instead of pixel by pixel | | 670 | * 32bit chunks instead of pixel by pixel |
662 | */ | | 671 | */ |
663 | wi = wi >> 1; | | 672 | wi = wi >> 1; |
664 | | | 673 | |
665 | /* just in case */ | | 674 | /* just in case */ |
666 | colour |= colour << 16; | | 675 | colour |= colour << 16; |
667 | | | 676 | |
668 | omapdma_write_ch_reg(0, OMAPDMAC_CSDPI, | | 677 | omapdma_write_ch_reg(0, OMAPDMAC_CSDPI, |
669 | CSDPI_SRC_BURST_64 | CSDPI_DST_BURST_64 | | | 678 | CSDPI_SRC_BURST_64 | CSDPI_DST_BURST_64 | |
670 | CSDPI_DST_PACKED | CSDPI_WRITE_POSTED_EXCEPT_LAST | | | 679 | CSDPI_DST_PACKED | CSDPI_WRITE_POSTED_EXCEPT_LAST | |
671 | CSDPI_DATA_TYPE_32); | | 680 | CSDPI_DATA_TYPE_32); |
672 | } else { | | 681 | } else { |
673 | omapdma_write_ch_reg(0, OMAPDMAC_CSDPI, | | 682 | omapdma_write_ch_reg(0, OMAPDMAC_CSDPI, |
674 | CSDPI_SRC_BURST_64 | CSDPI_DST_BURST_64 | | | 683 | CSDPI_SRC_BURST_64 | CSDPI_DST_BURST_64 | |
675 | CSDPI_DST_PACKED | CSDPI_WRITE_POSTED_EXCEPT_LAST | | | 684 | CSDPI_DST_PACKED | CSDPI_WRITE_POSTED_EXCEPT_LAST | |
676 | CSDPI_DATA_TYPE_16); | | 685 | CSDPI_DATA_TYPE_16); |
677 | } | | 686 | } |
678 | | | 687 | |
679 | omapdma_write_ch_reg(0, OMAPDMAC_CEN, wi); | | 688 | omapdma_write_ch_reg(0, OMAPDMAC_CEN, wi); |
680 | omapdma_write_ch_reg(0, OMAPDMAC_CFN, he); | | 689 | omapdma_write_ch_reg(0, OMAPDMAC_CFN, he); |
681 | omapdma_write_ch_reg(0, OMAPDMAC_CDSA, daddr); | | 690 | omapdma_write_ch_reg(0, OMAPDMAC_CDSA, daddr); |
682 | omapdma_write_ch_reg(0, OMAPDMAC_CCR, | | 691 | omapdma_write_ch_reg(0, OMAPDMAC_CCR, |
683 | CCR_CONST_FILL_ENABLE | CCR_DST_AMODE_DOUBLE_INDEX | | | 692 | CCR_CONST_FILL_ENABLE | CCR_DST_AMODE_DOUBLE_INDEX | |
684 | CCR_SRC_AMODE_CONST_ADDR); | | 693 | CCR_SRC_AMODE_CONST_ADDR); |
685 | omapdma_write_ch_reg(0, OMAPDMAC_CDEI, 1); | | 694 | omapdma_write_ch_reg(0, OMAPDMAC_CDEI, 1); |
686 | omapdma_write_ch_reg(0, OMAPDMAC_CDFI, (sc->sc_stride - width_in_bytes) + 1); | | 695 | omapdma_write_ch_reg(0, OMAPDMAC_CDFI, (sc->sc_stride - width_in_bytes) + 1); |
687 | omapdma_write_ch_reg(0, OMAPDMAC_COLOR, colour); | | 696 | omapdma_write_ch_reg(0, OMAPDMAC_COLOR, colour); |
688 | omapdma_write_ch_reg(0, OMAPDMAC_CCR, | | 697 | omapdma_write_ch_reg(0, OMAPDMAC_CCR, |
689 | CCR_CONST_FILL_ENABLE | CCR_DST_AMODE_DOUBLE_INDEX | | | 698 | CCR_CONST_FILL_ENABLE | CCR_DST_AMODE_DOUBLE_INDEX | |
690 | CCR_SRC_AMODE_CONST_ADDR | CCR_ENABLE); | | 699 | CCR_SRC_AMODE_CONST_ADDR | CCR_ENABLE); |
691 | } | | 700 | } |
692 | | | 701 | |
693 | static void | | 702 | static void |
694 | omapfb_bitblt(struct omapfb_softc *sc, int xs, int ys, int xd, int yd, | | 703 | omapfb_bitblt(struct omapfb_softc *sc, int xs, int ys, int xd, int yd, |
695 | int wi, int he, int rop) | | 704 | int wi, int he, int rop) |
696 | { | | 705 | { |
697 | int bpp = sc->sc_depth >> 3; /* bytes per pixel */ | | 706 | int bpp = sc->sc_depth >> 3; /* bytes per pixel */ |
698 | int width_in_bytes = wi * bpp; | | 707 | int width_in_bytes = wi * bpp; |
699 | | | 708 | |
700 | int hstep, vstep; | | 709 | int hstep, vstep; |
701 | uint32_t saddr, daddr; | | 710 | uint32_t saddr, daddr; |
702 | | | 711 | |
703 | /* | | 712 | /* |
704 | * TODO: | | 713 | * TODO: |
705 | * - use 32bit transfers if we're properly aligned | | 714 | * - use 32bit transfers if we're properly aligned |
706 | */ | | 715 | */ |
707 | saddr = sc->sc_fbhwaddr + sc->sc_stride * ys + xs * bpp; | | 716 | saddr = sc->sc_fbhwaddr + sc->sc_stride * ys + xs * bpp; |
708 | daddr = sc->sc_fbhwaddr + sc->sc_stride * yd + xd * bpp; | | 717 | daddr = sc->sc_fbhwaddr + sc->sc_stride * yd + xd * bpp; |
709 | | | 718 | |
710 | if (ys < yd) { | | 719 | if (ys < yd) { |
711 | /* need to go vertically backwards */ | | 720 | /* need to go vertically backwards */ |
712 | vstep = 1 - (sc->sc_stride + width_in_bytes); | | 721 | vstep = 1 - (sc->sc_stride + width_in_bytes); |
713 | saddr += sc->sc_stride * (he - 1); | | 722 | saddr += sc->sc_stride * (he - 1); |
714 | daddr += sc->sc_stride * (he - 1); | | 723 | daddr += sc->sc_stride * (he - 1); |
715 | } else | | 724 | } else |
716 | vstep = (sc->sc_stride - width_in_bytes) + 1; | | 725 | vstep = (sc->sc_stride - width_in_bytes) + 1; |
717 | if ((xs < xd) && (ys == yd)) { | | 726 | if ((xs < xd) && (ys == yd)) { |
718 | /* | | 727 | /* |
719 | * need to go horizontally backwards, only needed if source | | 728 | * need to go horizontally backwards, only needed if source |
720 | * and destination pixels are on the same line | | 729 | * and destination pixels are on the same line |
721 | */ | | 730 | */ |
722 | hstep = 1 - (sc->sc_depth >> 2); | | 731 | hstep = 1 - (sc->sc_depth >> 2); |
723 | vstep = sc->sc_stride + bpp * (wi - 1) + 1; | | 732 | vstep = sc->sc_stride + bpp * (wi - 1) + 1; |
724 | saddr += bpp * (wi - 1); | | 733 | saddr += bpp * (wi - 1); |
725 | daddr += bpp * (wi - 1); | | 734 | daddr += bpp * (wi - 1); |
726 | } else | | 735 | } else |
727 | hstep = 1; | | 736 | hstep = 1; |
728 | | | 737 | |
729 | omapfb_wait_idle(sc); | | 738 | omapfb_wait_idle(sc); |
730 | if (((saddr | daddr | width_in_bytes) & 3) == 0) { | | 739 | if (((saddr | daddr | width_in_bytes) & 3) == 0) { |
731 | /* | | 740 | /* |
732 | * everything is properly aligned so we can copy stuff in | | 741 | * everything is properly aligned so we can copy stuff in |
733 | * 32bit chunks instead of pixel by pixel | | 742 | * 32bit chunks instead of pixel by pixel |
734 | */ | | 743 | */ |
735 | wi = wi >> 1; | | 744 | wi = wi >> 1; |
736 | omapdma_write_ch_reg(0, OMAPDMAC_CSDPI, | | 745 | omapdma_write_ch_reg(0, OMAPDMAC_CSDPI, |
737 | CSDPI_SRC_BURST_64 | CSDPI_DST_BURST_64 | | | 746 | CSDPI_SRC_BURST_64 | CSDPI_DST_BURST_64 | |
738 | CSDPI_DST_PACKED | CSDPI_WRITE_POSTED_EXCEPT_LAST | | | 747 | CSDPI_DST_PACKED | CSDPI_WRITE_POSTED_EXCEPT_LAST | |
739 | CSDPI_DATA_TYPE_32); | | 748 | CSDPI_DATA_TYPE_32); |
740 | } else { | | 749 | } else { |
741 | omapdma_write_ch_reg(0, OMAPDMAC_CSDPI, | | 750 | omapdma_write_ch_reg(0, OMAPDMAC_CSDPI, |
742 | CSDPI_SRC_BURST_64 | CSDPI_DST_BURST_64 | | | 751 | CSDPI_SRC_BURST_64 | CSDPI_DST_BURST_64 | |
743 | CSDPI_DST_PACKED | CSDPI_WRITE_POSTED_EXCEPT_LAST | | | 752 | CSDPI_DST_PACKED | CSDPI_WRITE_POSTED_EXCEPT_LAST | |
744 | CSDPI_DATA_TYPE_16); | | 753 | CSDPI_DATA_TYPE_16); |
745 | } | | 754 | } |
746 | | | 755 | |
747 | omapdma_write_ch_reg(0, OMAPDMAC_CEN, wi); | | 756 | omapdma_write_ch_reg(0, OMAPDMAC_CEN, wi); |
748 | omapdma_write_ch_reg(0, OMAPDMAC_CFN, he); | | 757 | omapdma_write_ch_reg(0, OMAPDMAC_CFN, he); |
749 | omapdma_write_ch_reg(0, OMAPDMAC_CSSA, saddr); | | 758 | omapdma_write_ch_reg(0, OMAPDMAC_CSSA, saddr); |
750 | omapdma_write_ch_reg(0, OMAPDMAC_CDSA, daddr); | | 759 | omapdma_write_ch_reg(0, OMAPDMAC_CDSA, daddr); |
751 | omapdma_write_ch_reg(0, OMAPDMAC_CCR, | | 760 | omapdma_write_ch_reg(0, OMAPDMAC_CCR, |
752 | CCR_DST_AMODE_DOUBLE_INDEX | | | 761 | CCR_DST_AMODE_DOUBLE_INDEX | |
753 | CCR_SRC_AMODE_DOUBLE_INDEX); | | 762 | CCR_SRC_AMODE_DOUBLE_INDEX); |
754 | omapdma_write_ch_reg(0, OMAPDMAC_CSEI, hstep); | | 763 | omapdma_write_ch_reg(0, OMAPDMAC_CSEI, hstep); |
755 | omapdma_write_ch_reg(0, OMAPDMAC_CSFI, vstep); | | 764 | omapdma_write_ch_reg(0, OMAPDMAC_CSFI, vstep); |
756 | omapdma_write_ch_reg(0, OMAPDMAC_CDEI, hstep); | | 765 | omapdma_write_ch_reg(0, OMAPDMAC_CDEI, hstep); |
757 | omapdma_write_ch_reg(0, OMAPDMAC_CDFI, vstep); | | 766 | omapdma_write_ch_reg(0, OMAPDMAC_CDFI, vstep); |
758 | omapdma_write_ch_reg(0, OMAPDMAC_CCR, | | 767 | omapdma_write_ch_reg(0, OMAPDMAC_CCR, |
759 | CCR_DST_AMODE_DOUBLE_INDEX | | | 768 | CCR_DST_AMODE_DOUBLE_INDEX | |
760 | CCR_SRC_AMODE_DOUBLE_INDEX | CCR_ENABLE); | | 769 | CCR_SRC_AMODE_DOUBLE_INDEX | CCR_ENABLE); |
761 | } | | 770 | } |
762 | | | 771 | |
763 | static void | | 772 | static void |
764 | omapfb_cursor(void *cookie, int on, int row, int col) | | 773 | omapfb_cursor(void *cookie, int on, int row, int col) |
765 | { | | 774 | { |
766 | struct rasops_info *ri = cookie; | | 775 | struct rasops_info *ri = cookie; |
767 | struct vcons_screen *scr = ri->ri_hw; | | 776 | struct vcons_screen *scr = ri->ri_hw; |
768 | struct omapfb_softc *sc = scr->scr_cookie; | | 777 | struct omapfb_softc *sc = scr->scr_cookie; |
769 | int wi, he, pos; | | 778 | int wi, he, pos; |
770 | | | 779 | |
771 | wi = ri->ri_font->fontwidth; | | 780 | wi = ri->ri_font->fontwidth; |
772 | he = ri->ri_font->fontheight; | | 781 | he = ri->ri_font->fontheight; |
773 | pos = col + row * ri->ri_cols; | | 782 | pos = col + row * ri->ri_cols; |
774 | #ifdef WSDISPLAY_SCROLLSUPPORT | | 783 | #ifdef WSDISPLAY_SCROLLSUPPORT |
775 | pos += scr->scr_offset_to_zero; | | 784 | pos += scr->scr_offset_to_zero; |
776 | #endif | | 785 | #endif |
777 | if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) { | | 786 | if (sc->sc_mode == WSDISPLAYIO_MODE_EMUL) { |
778 | if (ri->ri_flg & RI_CURSOR) { | | 787 | if (ri->ri_flg & RI_CURSOR) { |
779 | omapfb_putchar(cookie, row, col, scr->scr_chars[pos], | | 788 | omapfb_putchar(cookie, row, col, scr->scr_chars[pos], |
780 | scr->scr_attrs[pos]); | | 789 | scr->scr_attrs[pos]); |
781 | ri->ri_flg &= ~RI_CURSOR; | | 790 | ri->ri_flg &= ~RI_CURSOR; |
782 | } | | 791 | } |
783 | ri->ri_crow = row; | | 792 | ri->ri_crow = row; |
784 | ri->ri_ccol = col; | | 793 | ri->ri_ccol = col; |
785 | if (on) { | | 794 | if (on) { |
786 | omapfb_putchar(cookie, row, col, scr->scr_chars[pos], | | 795 | omapfb_putchar(cookie, row, col, scr->scr_chars[pos], |
787 | scr->scr_attrs[pos] ^ 0x0f0f0000); | | 796 | scr->scr_attrs[pos] ^ 0x0f0f0000); |
788 | ri->ri_flg |= RI_CURSOR; | | 797 | ri->ri_flg |= RI_CURSOR; |
789 | } | | 798 | } |
790 | } else { | | 799 | } else { |
791 | scr->scr_ri.ri_crow = row; | | 800 | scr->scr_ri.ri_crow = row; |
792 | scr->scr_ri.ri_ccol = col; | | 801 | scr->scr_ri.ri_ccol = col; |
793 | scr->scr_ri.ri_flg &= ~RI_CURSOR; | | 802 | scr->scr_ri.ri_flg &= ~RI_CURSOR; |
794 | } | | 803 | } |
795 | } | | 804 | } |
796 | | | 805 | |
797 | static void | | 806 | static void |
798 | omapfb_putchar(void *cookie, int row, int col, u_int c, long attr) | | 807 | omapfb_putchar(void *cookie, int row, int col, u_int c, long attr) |
799 | { | | 808 | { |
800 | struct rasops_info *ri = cookie; | | 809 | struct rasops_info *ri = cookie; |
801 | struct vcons_screen *scr = ri->ri_hw; | | 810 | struct vcons_screen *scr = ri->ri_hw; |
802 | struct omapfb_softc *sc = scr->scr_cookie; | | 811 | struct omapfb_softc *sc = scr->scr_cookie; |
803 | | | 812 | |
804 | if (c == 0x20) { | | 813 | if (c == 0x20) { |
805 | uint32_t fg, bg, ul; | | 814 | uint32_t fg, bg, ul; |
806 | rasops_unpack_attr(attr, &fg, &bg, &ul); | | 815 | rasops_unpack_attr(attr, &fg, &bg, &ul); |
807 | omapfb_rectfill(sc, | | 816 | omapfb_rectfill(sc, |
808 | ri->ri_xorigin + ri->ri_font->fontwidth * col, | | 817 | ri->ri_xorigin + ri->ri_font->fontwidth * col, |
809 | ri->ri_yorigin + ri->ri_font->fontheight * row, | | 818 | ri->ri_yorigin + ri->ri_font->fontheight * row, |
810 | ri->ri_font->fontwidth, | | 819 | ri->ri_font->fontwidth, |
811 | ri->ri_font->fontheight, | | 820 | ri->ri_font->fontheight, |
812 | ri->ri_devcmap[bg]); | | 821 | ri->ri_devcmap[bg]); |
813 | return; | | 822 | return; |
814 | } | | 823 | } |
815 | omapfb_wait_idle(sc); | | 824 | omapfb_wait_idle(sc); |
816 | sc->sc_putchar(cookie, row, col, c, attr); | | 825 | sc->sc_putchar(cookie, row, col, c, attr); |
817 | } | | 826 | } |
818 | | | 827 | |
819 | static void | | 828 | static void |
820 | omapfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols) | | 829 | omapfb_copycols(void *cookie, int row, int srccol, int dstcol, int ncols) |
821 | { | | 830 | { |
822 | struct rasops_info *ri = cookie; | | 831 | struct rasops_info *ri = cookie; |
823 | struct vcons_screen *scr = ri->ri_hw; | | 832 | struct vcons_screen *scr = ri->ri_hw; |
824 | struct omapfb_softc *sc = scr->scr_cookie; | | 833 | struct omapfb_softc *sc = scr->scr_cookie; |
825 | int32_t xs, xd, y, width, height; | | 834 | int32_t xs, xd, y, width, height; |
826 | | | 835 | |
827 | if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) { | | 836 | if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) { |
828 | xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol; | | 837 | xs = ri->ri_xorigin + ri->ri_font->fontwidth * srccol; |
829 | xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol; | | 838 | xd = ri->ri_xorigin + ri->ri_font->fontwidth * dstcol; |
830 | y = ri->ri_yorigin + ri->ri_font->fontheight * row; | | 839 | y = ri->ri_yorigin + ri->ri_font->fontheight * row; |
831 | width = ri->ri_font->fontwidth * ncols; | | 840 | width = ri->ri_font->fontwidth * ncols; |
832 | height = ri->ri_font->fontheight; | | 841 | height = ri->ri_font->fontheight; |
833 | omapfb_bitblt(sc, xs, y, xd, y, width, height, 12); | | 842 | omapfb_bitblt(sc, xs, y, xd, y, width, height, 12); |
834 | } | | 843 | } |
835 | } | | 844 | } |
836 | | | 845 | |
837 | static void | | 846 | static void |
838 | omapfb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr) | | 847 | omapfb_erasecols(void *cookie, int row, int startcol, int ncols, long fillattr) |
839 | { | | 848 | { |
840 | struct rasops_info *ri = cookie; | | 849 | struct rasops_info *ri = cookie; |
841 | struct vcons_screen *scr = ri->ri_hw; | | 850 | struct vcons_screen *scr = ri->ri_hw; |
842 | struct omapfb_softc *sc = scr->scr_cookie; | | 851 | struct omapfb_softc *sc = scr->scr_cookie; |
843 | int32_t x, y, width, height, fg, bg, ul; | | 852 | int32_t x, y, width, height, fg, bg, ul; |
844 | | | 853 | |
845 | if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) { | | 854 | if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) { |
846 | x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol; | | 855 | x = ri->ri_xorigin + ri->ri_font->fontwidth * startcol; |
847 | y = ri->ri_yorigin + ri->ri_font->fontheight * row; | | 856 | y = ri->ri_yorigin + ri->ri_font->fontheight * row; |
848 | width = ri->ri_font->fontwidth * ncols; | | 857 | width = ri->ri_font->fontwidth * ncols; |
849 | height = ri->ri_font->fontheight; | | 858 | height = ri->ri_font->fontheight; |
850 | rasops_unpack_attr(fillattr, &fg, &bg, &ul); | | 859 | rasops_unpack_attr(fillattr, &fg, &bg, &ul); |
851 | | | 860 | |
852 | omapfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]); | | 861 | omapfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]); |
853 | } | | 862 | } |
854 | } | | 863 | } |
855 | | | 864 | |
856 | static void | | 865 | static void |
857 | omapfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows) | | 866 | omapfb_copyrows(void *cookie, int srcrow, int dstrow, int nrows) |
858 | { | | 867 | { |
859 | struct rasops_info *ri = cookie; | | 868 | struct rasops_info *ri = cookie; |
860 | struct vcons_screen *scr = ri->ri_hw; | | 869 | struct vcons_screen *scr = ri->ri_hw; |
861 | struct omapfb_softc *sc = scr->scr_cookie; | | 870 | struct omapfb_softc *sc = scr->scr_cookie; |
862 | int32_t x, ys, yd, width, height; | | 871 | int32_t x, ys, yd, width, height; |
863 | | | 872 | |
864 | if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) { | | 873 | if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) { |
865 | x = ri->ri_xorigin; | | 874 | x = ri->ri_xorigin; |
866 | ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow; | | 875 | ys = ri->ri_yorigin + ri->ri_font->fontheight * srcrow; |
867 | yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow; | | 876 | yd = ri->ri_yorigin + ri->ri_font->fontheight * dstrow; |
868 | width = ri->ri_emuwidth; | | 877 | width = ri->ri_emuwidth; |
869 | height = ri->ri_font->fontheight * nrows; | | 878 | height = ri->ri_font->fontheight * nrows; |
870 | omapfb_bitblt(sc, x, ys, x, yd, width, height, 12); | | 879 | omapfb_bitblt(sc, x, ys, x, yd, width, height, 12); |
871 | } | | 880 | } |
872 | } | | 881 | } |
873 | | | 882 | |
874 | static void | | 883 | static void |
875 | omapfb_eraserows(void *cookie, int row, int nrows, long fillattr) | | 884 | omapfb_eraserows(void *cookie, int row, int nrows, long fillattr) |
876 | { | | 885 | { |
877 | struct rasops_info *ri = cookie; | | 886 | struct rasops_info *ri = cookie; |
878 | struct vcons_screen *scr = ri->ri_hw; | | 887 | struct vcons_screen *scr = ri->ri_hw; |
879 | struct omapfb_softc *sc = scr->scr_cookie; | | 888 | struct omapfb_softc *sc = scr->scr_cookie; |
880 | int32_t x, y, width, height, fg, bg, ul; | | 889 | int32_t x, y, width, height, fg, bg, ul; |
881 | | | 890 | |
882 | if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) { | | 891 | if ((sc->sc_locked == 0) && (sc->sc_mode == WSDISPLAYIO_MODE_EMUL)) { |
883 | x = ri->ri_xorigin; | | 892 | x = ri->ri_xorigin; |
884 | y = ri->ri_yorigin + ri->ri_font->fontheight * row; | | 893 | y = ri->ri_yorigin + ri->ri_font->fontheight * row; |
885 | width = ri->ri_emuwidth; | | 894 | width = ri->ri_emuwidth; |
886 | height = ri->ri_font->fontheight * nrows; | | 895 | height = ri->ri_font->fontheight * nrows; |
887 | rasops_unpack_attr(fillattr, &fg, &bg, &ul); | | 896 | rasops_unpack_attr(fillattr, &fg, &bg, &ul); |
888 | | | 897 | |
889 | omapfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]); | | 898 | omapfb_rectfill(sc, x, y, width, height, ri->ri_devcmap[bg]); |
890 | } | | 899 | } |
891 | } | | 900 | } |
892 | #endif /* NOMAPDMA > 0 */ | | 901 | #endif /* NOMAPDMA > 0 */ |