Expand PMF_FN_* macros.
[netbsd-mini2440.git] / sys / arch / arm / sa11x0 / sa1111.c
bloba3149473cfdb795433adfe4dda27b76fe24420e6
1 /* $NetBSD: sa1111.c,v 1.22 2008/04/28 20:23:14 martin Exp $ */
3 /*-
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by IWAMOTO Toshihiro.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 * TODO:
34 * - introduce bus abstraction to support SA-1101
37 #include <sys/cdefs.h>
38 __KERNEL_RCSID(0, "$NetBSD: sa1111.c,v 1.22 2008/04/28 20:23:14 martin Exp $");
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/types.h>
43 #include <sys/conf.h>
44 #include <sys/device.h>
45 #include <sys/kernel.h>
46 #include <sys/malloc.h>
47 #include <sys/uio.h>
49 #include <machine/bus.h>
50 #include <machine/intr.h>
52 #include <arm/sa11x0/sa11x0_reg.h>
53 #include <arm/sa11x0/sa11x0_var.h>
54 #include <arm/sa11x0/sa11x0_gpioreg.h>
55 #include <arm/sa11x0/sa1111_reg.h>
56 #include <arm/sa11x0/sa1111_var.h>
58 #include "locators.h"
60 static int sa1111_print(void *, const char *);
62 static void sacc_intr_calculatemasks(struct sacc_softc *);
63 static void sacc_intr_setpolarity(sacc_chipset_tag_t *, int , int);
65 #ifdef INTR_DEBUG
66 #define DPRINTF(arg) printf arg
67 #else
68 #define DPRINTF(arg)
69 #endif
71 int
72 sacc_probe(device_t parent, cfdata_t match, void *aux)
74 struct sa11x0_attach_args *sa = aux;
75 bus_space_handle_t ioh;
76 uint32_t skid;
78 if (bus_space_map(sa->sa_iot, sa->sa_addr, sa->sa_size, 0, &ioh))
79 return 0;
81 skid = bus_space_read_4(sa->sa_iot, ioh, SACCSBI_SKID);
82 bus_space_unmap(sa->sa_iot, ioh, sa->sa_size);
84 if ((skid & 0xffffff00) != 0x690cc200)
85 return 0;
87 return 1;
91 int
92 sa1111_search(device_t parent, cfdata_t cf, const int *ldesc,
93 void *aux)
95 struct sa1111_attach_args aa;
97 aa.sa_addr = cf->cf_loc[SACCCF_ADDR];
98 aa.sa_size = cf->cf_loc[SACCCF_SIZE];
99 aa.sa_intr = cf->cf_loc[SACCCF_INTR];
100 #if 0
101 aa.sa_membase = cf->cf_loc[SACCCF_MEMBASE];
102 aa.sa_memsize = cf->cf_loc[SACCCF_MEMSIZE];
103 #endif
105 if (config_match(parent, cf, &aa) > 0)
106 config_attach(parent, cf, &aa, sa1111_print);
108 return 0;
111 static int
112 sa1111_print(void *aux, const char *name)
115 return UNCONF;
119 void *
120 sacc_intr_establish(sacc_chipset_tag_t *ic, int irq, int type, int level,
121 int (*ih_fun)(void *), void *ih_arg)
123 int s;
124 struct sacc_softc *sc = (struct sacc_softc *)ic;
125 struct sacc_intrhand **p, *ih;
127 /* no point in sleeping unless someone can free memory. */
128 ih = malloc(sizeof *ih, M_DEVBUF, cold ? M_NOWAIT : M_WAITOK);
129 if (ih == NULL)
130 panic("sacc_intr_establish: can't malloc handler info");
132 if (irq < 0 || irq > SACCIC_LEN ||
133 !(type == IST_EDGE_RAISE || type == IST_EDGE_FALL))
134 panic("sacc_intr_establish: bogus irq or type");
136 if (sc->sc_intrhand[irq] == NULL) {
137 sacc_intr_setpolarity(ic, irq, type);
138 sc->sc_intrtype[irq] = type;
139 } else if (sc->sc_intrtype[irq] != type)
140 /* XXX we should be able to share raising and
141 * falling edge intrs */
142 panic("sacc_intr_establish: type must be unique");
144 /* install intr handler */
145 /* map interrupt level to appropriate softinterrupt level */
146 level = SOFTINT_SERIAL;
147 ih->ih_soft = softint_establish(level, (void (*)(void *)) ih_fun,
148 ih_arg);
149 ih->ih_irq = irq;
150 ih->ih_next = NULL;
152 s = splhigh();
153 for (p = &sc->sc_intrhand[irq]; *p; p = &(*p)->ih_next)
154 continue;
156 *p = ih;
158 sacc_intr_calculatemasks(sc);
159 splx(s);
161 return ih;
164 void
165 sacc_intr_disestablish(sacc_chipset_tag_t *ic, void *arg)
167 int irq, s;
168 struct sacc_softc *sc = (struct sacc_softc *)ic;
169 struct sacc_intrhand *ih, **p;
171 ih = (struct sacc_intrhand *)arg;
172 irq = ih->ih_irq;
174 #ifdef DIAGNOSTIC
175 if (irq < 0 || irq > SACCIC_LEN)
176 panic("sacc_intr_disestablish: bogus irq");
177 #endif
179 s = splhigh();
181 for (p = &sc->sc_intrhand[irq];; p = &(*p)->ih_next) {
182 if (*p == NULL)
183 panic("sacc_intr_disestablish: handler not registered");
184 if (*p == ih)
185 break;
187 *p = (*p)->ih_next;
189 sacc_intr_calculatemasks(sc);
190 splx(s);
192 free(ih, M_DEVBUF);
195 static void
196 sacc_intr_setpolarity(sacc_chipset_tag_t *ic, int irq, int type)
198 struct sacc_softc *sc = (struct sacc_softc *)ic;
199 int s;
200 uint32_t pol, mask;
201 int addr;
203 if (irq >= 32) {
204 addr = SACCIC_INTPOL1;
205 irq -= 32;
206 } else
207 addr = SACCIC_INTPOL0;
209 mask = (1 << irq);
211 s = splhigh();
212 pol = bus_space_read_4(sc->sc_iot, sc->sc_ioh, addr);
213 if (type == IST_EDGE_RAISE)
214 pol &= ~mask;
215 else
216 pol |= mask;
217 bus_space_write_4(sc->sc_iot, sc->sc_ioh, addr, pol);
218 splx(s);
221 static void
222 sacc_intr_calculatemasks(struct sacc_softc *sc)
224 int irq;
226 sc->sc_imask.lo = 0;
227 sc->sc_imask.hi = 0;
228 for (irq = 0; irq < 32; irq++)
229 if (sc->sc_intrhand[irq])
230 sc->sc_imask.lo |= (1 << irq);
231 for (irq = 0; irq < SACCIC_LEN - 32; irq++)
232 if (sc->sc_intrhand[irq + 32])
233 sc->sc_imask.hi |= (1 << irq);
236 /* XXX this should not be done here */
237 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTEN0,
238 sc->sc_imask.lo);
239 bus_space_write_4(sc->sc_iot, sc->sc_ioh, SACCIC_INTEN1,
240 sc->sc_imask.hi);
241 DPRINTF(("sacc_intr_calculatemasks: %x %x\n", sc->sc_imask.lo,
242 sc->sc_imask.hi));