vrdmaau.c revision 1.4 1 1.1 takemura /*
2 1.1 takemura * Copyright (c) 2001 HAMAJIMA Katsuomi. All rights reserved.
3 1.1 takemura *
4 1.1 takemura * Redistribution and use in source and binary forms, with or without
5 1.1 takemura * modification, are permitted provided that the following conditions
6 1.1 takemura * are met:
7 1.1 takemura * 1. Redistributions of source code must retain the above copyright
8 1.1 takemura * notice, this list of conditions and the following disclaimer.
9 1.1 takemura * 2. Redistributions in binary form must reproduce the above copyright
10 1.1 takemura * notice, this list of conditions and the following disclaimer in the
11 1.1 takemura * documentation and/or other materials provided with the distribution.
12 1.1 takemura *
13 1.1 takemura * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 1.1 takemura * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 1.1 takemura * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 1.1 takemura * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 1.1 takemura * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 1.1 takemura * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 1.1 takemura * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 1.1 takemura * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 1.1 takemura * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 1.1 takemura * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23 1.1 takemura * SUCH DAMAGE.
24 1.1 takemura */
25 1.1 takemura
26 1.4 lukem #include <sys/cdefs.h>
27 1.4 lukem __KERNEL_RCSID(0, "$NetBSD: vrdmaau.c,v 1.4 2003/07/15 02:29:35 lukem Exp $");
28 1.4 lukem
29 1.1 takemura #include <sys/param.h>
30 1.1 takemura #include <sys/systm.h>
31 1.1 takemura #include <sys/device.h>
32 1.1 takemura
33 1.1 takemura #include <machine/bus.h>
34 1.1 takemura
35 1.1 takemura #include <hpcmips/vr/vripif.h>
36 1.1 takemura #include <hpcmips/vr/dmaaureg.h>
37 1.1 takemura
38 1.1 takemura #ifdef VRDMAAU_DEBUG
39 1.1 takemura int vrdmaau_debug = VRDMAAU_DEBUG;
40 1.1 takemura #define DPRINTFN(n,x) if (vrdmaau_debug>(n)) printf x;
41 1.1 takemura #else
42 1.1 takemura #define DPRINTFN(n,x)
43 1.1 takemura #endif
44 1.1 takemura
45 1.1 takemura struct vrdmaau_softc {
46 1.1 takemura struct device sc_dev;
47 1.1 takemura bus_space_tag_t sc_iot;
48 1.1 takemura bus_space_handle_t sc_ioh;
49 1.1 takemura struct vrdmaau_chipset_tag sc_chipset;
50 1.1 takemura };
51 1.1 takemura
52 1.1 takemura int vrdmaau_match(struct device *, struct cfdata *, void *);
53 1.1 takemura void vrdmaau_attach(struct device *, struct device *, void *);
54 1.1 takemura
55 1.3 thorpej CFATTACH_DECL(vrdmaau, sizeof(struct vrdmaau_softc),
56 1.3 thorpej vrdmaau_match, vrdmaau_attach, NULL, NULL);
57 1.1 takemura
58 1.1 takemura int vrdmaau_set_aiuin(vrdmaau_chipset_tag_t, void *);
59 1.1 takemura int vrdmaau_set_aiuout(vrdmaau_chipset_tag_t, void *);
60 1.1 takemura int vrdmaau_set_fir(vrdmaau_chipset_tag_t, void *);
61 1.1 takemura static int vrdmaau_phy_addr(struct vrdmaau_softc *, void *, u_int32_t *);
62 1.1 takemura
63 1.1 takemura int
64 1.1 takemura vrdmaau_match(struct device *parent, struct cfdata *cf, void *aux)
65 1.1 takemura {
66 1.1 takemura return 2; /* 1st attach group of vrip */
67 1.1 takemura }
68 1.1 takemura
69 1.1 takemura void
70 1.1 takemura vrdmaau_attach(struct device *parent, struct device *self, void *aux)
71 1.1 takemura {
72 1.1 takemura struct vrip_attach_args *va = aux;
73 1.1 takemura struct vrdmaau_softc *sc = (void*)self;
74 1.1 takemura
75 1.1 takemura sc->sc_iot = va->va_iot;
76 1.1 takemura sc->sc_chipset.ac_sc = sc;
77 1.1 takemura sc->sc_chipset.ac_set_aiuin = vrdmaau_set_aiuin;
78 1.1 takemura sc->sc_chipset.ac_set_aiuout = vrdmaau_set_aiuout;
79 1.1 takemura sc->sc_chipset.ac_set_fir = vrdmaau_set_fir;
80 1.1 takemura
81 1.1 takemura if (bus_space_map(sc->sc_iot, va->va_addr, va->va_size,
82 1.1 takemura 0 /* no flags */, &sc->sc_ioh)) {
83 1.1 takemura printf(": can't map i/o space\n");
84 1.1 takemura return;
85 1.1 takemura }
86 1.1 takemura printf("\n");
87 1.1 takemura vrip_register_dmaau(va->va_vc, &sc->sc_chipset);
88 1.1 takemura }
89 1.1 takemura
90 1.1 takemura int
91 1.1 takemura vrdmaau_set_aiuin(vrdmaau_chipset_tag_t ac, void *addr)
92 1.1 takemura {
93 1.1 takemura struct vrdmaau_softc *sc = ac->ac_sc;
94 1.1 takemura u_int32_t phy;
95 1.1 takemura int err;
96 1.1 takemura
97 1.1 takemura DPRINTFN(1, ("vrdmaau_set_aiuin: address %p\n", addr));
98 1.1 takemura
99 1.1 takemura if ((err = vrdmaau_phy_addr(sc, addr, &phy)))
100 1.1 takemura return err;
101 1.1 takemura
102 1.1 takemura bus_space_write_2(sc->sc_iot, sc->sc_ioh, AIUIBAH_REG_W, phy >> 16);
103 1.1 takemura bus_space_write_2(sc->sc_iot, sc->sc_ioh, AIUIBAL_REG_W, phy & 0xffff);
104 1.1 takemura return 0;
105 1.1 takemura }
106 1.1 takemura
107 1.1 takemura int
108 1.1 takemura vrdmaau_set_aiuout(vrdmaau_chipset_tag_t ac, void *addr)
109 1.1 takemura {
110 1.1 takemura struct vrdmaau_softc *sc = ac->ac_sc;
111 1.1 takemura u_int32_t phy;
112 1.1 takemura int err;
113 1.1 takemura
114 1.1 takemura DPRINTFN(1, ("vrdmaau_set_aiuout: address %p\n", addr));
115 1.1 takemura
116 1.1 takemura if ((err = vrdmaau_phy_addr(sc, addr, &phy)))
117 1.1 takemura return err;
118 1.1 takemura
119 1.1 takemura bus_space_write_2(sc->sc_iot, sc->sc_ioh, AIUOBAH_REG_W, phy >> 16);
120 1.1 takemura bus_space_write_2(sc->sc_iot, sc->sc_ioh, AIUOBAL_REG_W, phy & 0xffff);
121 1.1 takemura return 0;
122 1.1 takemura }
123 1.1 takemura
124 1.1 takemura int
125 1.1 takemura vrdmaau_set_fir(vrdmaau_chipset_tag_t ac, void *addr)
126 1.1 takemura {
127 1.1 takemura struct vrdmaau_softc *sc = ac->ac_sc;
128 1.1 takemura u_int32_t phy;
129 1.1 takemura int err;
130 1.1 takemura
131 1.1 takemura DPRINTFN(1, ("vrdmaau_set_fir: address %p\n", addr));
132 1.1 takemura
133 1.1 takemura if ((err = vrdmaau_phy_addr(sc, addr, &phy)))
134 1.1 takemura return err;
135 1.1 takemura
136 1.1 takemura bus_space_write_2(sc->sc_iot, sc->sc_ioh, FIRBAH_REG_W, phy >> 16);
137 1.1 takemura bus_space_write_2(sc->sc_iot, sc->sc_ioh, FIRBAL_REG_W, phy & 0xffff);
138 1.1 takemura return 0;
139 1.1 takemura }
140 1.1 takemura
141 1.1 takemura static int
142 1.1 takemura vrdmaau_phy_addr(struct vrdmaau_softc *sc, void *addr, u_int32_t *phy)
143 1.1 takemura {
144 1.1 takemura DPRINTFN(1, ("vrdmaau_phy_addr\n"));
145 1.1 takemura
146 1.1 takemura if (addr >= (void *)MIPS_KSEG0_START &&
147 1.1 takemura addr < (void *)MIPS_KSEG1_START)
148 1.1 takemura *phy = MIPS_KSEG0_TO_PHYS(addr);
149 1.1 takemura else if (addr >= (void *)MIPS_KSEG1_START &&
150 1.1 takemura addr < (void *)MIPS_KSEG2_START)
151 1.1 takemura *phy = MIPS_KSEG1_TO_PHYS(addr);
152 1.1 takemura else {
153 1.1 takemura DPRINTFN(0, ("vrdmaau_map_addr: invalid address %p\n", addr));
154 1.1 takemura return EFAULT;
155 1.1 takemura }
156 1.1 takemura
157 1.1 takemura #ifdef DIAGNOSTIC
158 1.1 takemura if ((*phy & (VRDMAAU_ALIGNMENT - 1)) ||
159 1.1 takemura *phy >= VRDMAAU_BOUNCE_THRESHOLD ) {
160 1.1 takemura printf("%s: vrdmaau_phy_addr: invalid address %p\n",
161 1.1 takemura sc->sc_dev.dv_xname, addr);
162 1.1 takemura return EINVAL;
163 1.1 takemura }
164 1.1 takemura #endif
165 1.1 takemura return 0;
166 1.1 takemura }
167