tft_ll.c revision 1.1.6.2 1 1.1.6.2 ad /* $NetBSD: tft_ll.c,v 1.1.6.2 2007/01/12 01:00:47 ad Exp $ */
2 1.1.6.2 ad
3 1.1.6.2 ad /*
4 1.1.6.2 ad * Copyright (c) 2006 Jachym Holecek
5 1.1.6.2 ad * All rights reserved.
6 1.1.6.2 ad *
7 1.1.6.2 ad * Written for DFC Design, s.r.o.
8 1.1.6.2 ad *
9 1.1.6.2 ad * Redistribution and use in source and binary forms, with or without
10 1.1.6.2 ad * modification, are permitted provided that the following conditions
11 1.1.6.2 ad * are met:
12 1.1.6.2 ad *
13 1.1.6.2 ad * 1. Redistributions of source code must retain the above copyright
14 1.1.6.2 ad * notice, this list of conditions and the following disclaimer.
15 1.1.6.2 ad *
16 1.1.6.2 ad * 2. Redistributions in binary form must reproduce the above copyright
17 1.1.6.2 ad * notice, this list of conditions and the following disclaimer in the
18 1.1.6.2 ad * documentation and/or other materials provided with the distribution.
19 1.1.6.2 ad *
20 1.1.6.2 ad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 1.1.6.2 ad * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 1.1.6.2 ad * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 1.1.6.2 ad * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 1.1.6.2 ad * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 1.1.6.2 ad * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 1.1.6.2 ad * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 1.1.6.2 ad * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 1.1.6.2 ad * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 1.1.6.2 ad * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 1.1.6.2 ad */
31 1.1.6.2 ad
32 1.1.6.2 ad #include <sys/cdefs.h>
33 1.1.6.2 ad __KERNEL_RCSID(0, "$NetBSD: tft_ll.c,v 1.1.6.2 2007/01/12 01:00:47 ad Exp $");
34 1.1.6.2 ad
35 1.1.6.2 ad #include <sys/param.h>
36 1.1.6.2 ad #include <sys/systm.h>
37 1.1.6.2 ad #include <sys/mbuf.h>
38 1.1.6.2 ad #include <sys/kernel.h>
39 1.1.6.2 ad #include <sys/socket.h>
40 1.1.6.2 ad #include <sys/ioctl.h>
41 1.1.6.2 ad #include <sys/device.h>
42 1.1.6.2 ad #include <sys/queue.h>
43 1.1.6.2 ad
44 1.1.6.2 ad #include <uvm/uvm_extern.h>
45 1.1.6.2 ad
46 1.1.6.2 ad #include <machine/bus.h>
47 1.1.6.2 ad
48 1.1.6.2 ad /* XXX needed? */
49 1.1.6.2 ad #include <dev/wscons/wsdisplayvar.h>
50 1.1.6.2 ad #include <dev/wscons/wsconsio.h>
51 1.1.6.2 ad #include <dev/rasops/rasops.h>
52 1.1.6.2 ad #include <dev/wscons/wsdisplay_vconsvar.h>
53 1.1.6.2 ad
54 1.1.6.2 ad #include <evbppc/virtex/dev/xcvbusvar.h>
55 1.1.6.2 ad #include <evbppc/virtex/dev/cdmacreg.h>
56 1.1.6.2 ad #include <evbppc/virtex/dev/tftreg.h>
57 1.1.6.2 ad #include <evbppc/virtex/dev/tftvar.h>
58 1.1.6.2 ad
59 1.1.6.2 ad
60 1.1.6.2 ad struct ll_tft_control {
61 1.1.6.2 ad struct cdmac_descr cd_dsc;
62 1.1.6.2 ad u_char cd_img[];
63 1.1.6.2 ad } __packed;
64 1.1.6.2 ad
65 1.1.6.2 ad struct ll_tft_softc {
66 1.1.6.2 ad struct tft_softc lsc_sc;
67 1.1.6.2 ad
68 1.1.6.2 ad bus_space_tag_t lsc_dma_iot;
69 1.1.6.2 ad bus_space_handle_t lsc_dma_ioh;
70 1.1.6.2 ad
71 1.1.6.2 ad bus_dma_tag_t lsc_dmat;
72 1.1.6.2 ad bus_dmamap_t lsc_dmap;
73 1.1.6.2 ad
74 1.1.6.2 ad struct ll_tft_control *lsc_cd;
75 1.1.6.2 ad bus_dma_segment_t lsc_seg;
76 1.1.6.2 ad };
77 1.1.6.2 ad
78 1.1.6.2 ad static void ll_tft_attach(struct device *, struct device *, void *);
79 1.1.6.2 ad static paddr_t ll_tft_mmap(void *, void *, off_t, int);
80 1.1.6.2 ad static void ll_tft_shutdown(void *);
81 1.1.6.2 ad
82 1.1.6.2 ad CFATTACH_DECL(ll_tft, sizeof(struct ll_tft_softc),
83 1.1.6.2 ad xcvbus_child_match, ll_tft_attach, NULL, NULL);
84 1.1.6.2 ad
85 1.1.6.2 ad
86 1.1.6.2 ad static struct wsdisplay_accessops ll_tft_accessops = {
87 1.1.6.2 ad .mmap = ll_tft_mmap,
88 1.1.6.2 ad };
89 1.1.6.2 ad
90 1.1.6.2 ad
91 1.1.6.2 ad static void
92 1.1.6.2 ad ll_tft_attach(struct device *parent, struct device *self, void *aux)
93 1.1.6.2 ad {
94 1.1.6.2 ad struct xcvbus_attach_args *vaa = aux;
95 1.1.6.2 ad struct ll_dmac *tx = vaa->vaa_tx_dmac;
96 1.1.6.2 ad struct ll_tft_softc *lsc = (struct ll_tft_softc *)self;
97 1.1.6.2 ad struct tft_softc *sc = &lsc->lsc_sc;
98 1.1.6.2 ad int nseg, error;
99 1.1.6.2 ad
100 1.1.6.2 ad KASSERT(tx);
101 1.1.6.2 ad
102 1.1.6.2 ad lsc->lsc_dma_iot = tx->dmac_iot;
103 1.1.6.2 ad lsc->lsc_dmat = vaa->vaa_dmat;
104 1.1.6.2 ad sc->sc_iot = vaa->vaa_iot;
105 1.1.6.2 ad
106 1.1.6.2 ad printf(": LL_TFT\n");
107 1.1.6.2 ad
108 1.1.6.2 ad if ((error = bus_space_map(sc->sc_iot, vaa->vaa_addr, TFT_SIZE,
109 1.1.6.2 ad 0, &sc->sc_ioh)) != 0) {
110 1.1.6.2 ad printf("%s: could not map device registers\n",
111 1.1.6.2 ad device_xname(self));
112 1.1.6.2 ad goto fail_0;
113 1.1.6.2 ad }
114 1.1.6.2 ad if ((error = bus_space_map(lsc->lsc_dma_iot, tx->dmac_ctrl_addr,
115 1.1.6.2 ad CDMAC_CTRL_SIZE, 0, &lsc->lsc_dma_ioh)) != 0) {
116 1.1.6.2 ad printf("%s: could not map dmac registers\n",
117 1.1.6.2 ad device_xname(self));
118 1.1.6.2 ad goto fail_1;
119 1.1.6.2 ad }
120 1.1.6.2 ad
121 1.1.6.2 ad /* Fill in resolution, depth, size. */
122 1.1.6.2 ad tft_mode(&sc->sc_dev);
123 1.1.6.2 ad
124 1.1.6.2 ad /* Allocate and map framebuffer control data. */
125 1.1.6.2 ad if ((error = bus_dmamem_alloc(lsc->lsc_dmat,
126 1.1.6.2 ad sizeof(struct ll_tft_control) + sc->sc_size, 8, 0,
127 1.1.6.2 ad &lsc->lsc_seg, 1, &nseg, 0)) != 0) {
128 1.1.6.2 ad printf("%s: could not allocate framebuffer\n",
129 1.1.6.2 ad device_xname(self));
130 1.1.6.2 ad goto fail_2;
131 1.1.6.2 ad }
132 1.1.6.2 ad if ((error = bus_dmamem_map(lsc->lsc_dmat, &lsc->lsc_seg, nseg,
133 1.1.6.2 ad sizeof(struct ll_tft_control) + sc->sc_size,
134 1.1.6.2 ad (caddr_t *)&lsc->lsc_cd, BUS_DMA_COHERENT)) != 0) {
135 1.1.6.2 ad printf("%s: could not map framebuffer\n",
136 1.1.6.2 ad device_xname(self));
137 1.1.6.2 ad goto fail_3;
138 1.1.6.2 ad }
139 1.1.6.2 ad if ((error = bus_dmamap_create(lsc->lsc_dmat,
140 1.1.6.2 ad sizeof(struct ll_tft_control) + sc->sc_size, 1,
141 1.1.6.2 ad sizeof(struct ll_tft_control) + sc->sc_size, 0, 0,
142 1.1.6.2 ad &lsc->lsc_dmap)) != 0) {
143 1.1.6.2 ad printf("%s: could not create framebuffer DMA map\n",
144 1.1.6.2 ad device_xname(self));
145 1.1.6.2 ad goto fail_4;
146 1.1.6.2 ad }
147 1.1.6.2 ad if ((error = bus_dmamap_load(lsc->lsc_dmat, lsc->lsc_dmap, lsc->lsc_cd,
148 1.1.6.2 ad sizeof(struct ll_tft_control) + sc->sc_size, NULL, 0)) != 0) {
149 1.1.6.2 ad printf("%s: could not load framebuffer DMA map\n",
150 1.1.6.2 ad device_xname(self));
151 1.1.6.2 ad goto fail_5;
152 1.1.6.2 ad }
153 1.1.6.2 ad
154 1.1.6.2 ad /* Clear screen, setup descriptor. */
155 1.1.6.2 ad memset(lsc->lsc_cd, 0x00, sizeof(struct ll_tft_control));
156 1.1.6.2 ad sc->sc_image = lsc->lsc_cd->cd_img;
157 1.1.6.2 ad
158 1.1.6.2 ad lsc->lsc_cd->cd_dsc.desc_next = lsc->lsc_dmap->dm_segs[0].ds_addr;
159 1.1.6.2 ad lsc->lsc_cd->cd_dsc.desc_addr = lsc->lsc_dmap->dm_segs[0].ds_addr +
160 1.1.6.2 ad offsetof(struct ll_tft_control, cd_img);
161 1.1.6.2 ad lsc->lsc_cd->cd_dsc.desc_size = sc->sc_size;
162 1.1.6.2 ad lsc->lsc_cd->cd_dsc.desc_stat = CDMAC_STAT_SOP;
163 1.1.6.2 ad
164 1.1.6.2 ad bus_dmamap_sync(lsc->lsc_dmat, lsc->lsc_dmap, 0,
165 1.1.6.2 ad sizeof(struct ll_tft_control) + sc->sc_size,
166 1.1.6.2 ad BUS_DMASYNC_PREREAD | BUS_DMASYNC_PREWRITE);
167 1.1.6.2 ad
168 1.1.6.2 ad sc->sc_sdhook = shutdownhook_establish(ll_tft_shutdown, sc);
169 1.1.6.2 ad if (sc->sc_sdhook == NULL)
170 1.1.6.2 ad printf("%s: WARNING: unable to establish shutdown hook\n",
171 1.1.6.2 ad device_xname(self));
172 1.1.6.2 ad
173 1.1.6.2 ad tft_attach(self, &ll_tft_accessops);
174 1.1.6.2 ad
175 1.1.6.2 ad printf("%s: video memory pa 0x%08x\n", device_xname(self),
176 1.1.6.2 ad (uint32_t)lsc->lsc_cd->cd_dsc.desc_addr);
177 1.1.6.2 ad
178 1.1.6.2 ad /* Timing sensitive... */
179 1.1.6.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, TFT_CTRL, CTRL_RESET);
180 1.1.6.2 ad bus_space_write_4(sc->sc_iot, sc->sc_ioh, TFT_CTRL, CTRL_ENABLE);
181 1.1.6.2 ad bus_space_write_4(lsc->lsc_dma_iot, lsc->lsc_dma_ioh, CDMAC_CURDESC,
182 1.1.6.2 ad lsc->lsc_dmap->dm_segs[0].ds_addr);
183 1.1.6.2 ad
184 1.1.6.2 ad return ;
185 1.1.6.2 ad
186 1.1.6.2 ad fail_5:
187 1.1.6.2 ad bus_dmamap_destroy(lsc->lsc_dmat, lsc->lsc_dmap);
188 1.1.6.2 ad fail_4:
189 1.1.6.2 ad bus_dmamem_unmap(lsc->lsc_dmat, (caddr_t)lsc->lsc_cd,
190 1.1.6.2 ad sizeof(struct ll_tft_control) + sc->sc_size);
191 1.1.6.2 ad fail_3:
192 1.1.6.2 ad bus_dmamem_free(lsc->lsc_dmat, &lsc->lsc_seg, nseg);
193 1.1.6.2 ad fail_2:
194 1.1.6.2 ad bus_space_unmap(lsc->lsc_dma_iot, lsc->lsc_dma_ioh, CDMAC_CTRL_SIZE);
195 1.1.6.2 ad fail_1:
196 1.1.6.2 ad bus_space_unmap(sc->sc_iot, sc->sc_ioh, TFT_SIZE);
197 1.1.6.2 ad fail_0:
198 1.1.6.2 ad printf("%s: error %d\n", device_xname(self), error);
199 1.1.6.2 ad }
200 1.1.6.2 ad
201 1.1.6.2 ad static paddr_t
202 1.1.6.2 ad ll_tft_mmap(void *arg, void *scr, off_t offs, int prot)
203 1.1.6.2 ad {
204 1.1.6.2 ad struct ll_tft_softc *lsc = arg;
205 1.1.6.2 ad paddr_t pa;
206 1.1.6.2 ad
207 1.1.6.2 ad if (offs < lsc->lsc_sc.sc_size) {
208 1.1.6.2 ad pa = bus_dmamem_mmap(lsc->lsc_dmat, &lsc->lsc_seg, 1,
209 1.1.6.2 ad offs + offsetof(struct ll_tft_control, cd_img),
210 1.1.6.2 ad prot, BUS_DMA_WAITOK | BUS_DMA_COHERENT);
211 1.1.6.2 ad
212 1.1.6.2 ad return (pa);
213 1.1.6.2 ad }
214 1.1.6.2 ad
215 1.1.6.2 ad return (-1);
216 1.1.6.2 ad }
217 1.1.6.2 ad
218 1.1.6.2 ad static void
219 1.1.6.2 ad ll_tft_shutdown(void *arg)
220 1.1.6.2 ad {
221 1.1.6.2 ad struct ll_tft_softc *lsc = arg;
222 1.1.6.2 ad
223 1.1.6.2 ad bus_space_write_4(lsc->lsc_dma_iot, lsc->lsc_dma_ioh, 0,
224 1.1.6.2 ad CDMAC_STAT_RESET);
225 1.1.6.2 ad
226 1.1.6.2 ad tft_shutdown(&lsc->lsc_sc);
227 1.1.6.2 ad }
228