obio_lpchc.c revision 1.2.10.2 1 1.2.10.2 yamt /* $NetBSD: obio_lpchc.c,v 1.2.10.2 2009/05/04 08:10:42 yamt Exp $ */
2 1.2.10.2 yamt
3 1.2.10.2 yamt /*
4 1.2.10.2 yamt * obio attachment for GEMINI LPC Host Controller
5 1.2.10.2 yamt */
6 1.2.10.2 yamt #include "opt_gemini.h"
7 1.2.10.2 yamt #include "locators.h"
8 1.2.10.2 yamt
9 1.2.10.2 yamt #include <sys/cdefs.h>
10 1.2.10.2 yamt __KERNEL_RCSID(0, "$NetBSD: obio_lpchc.c,v 1.2.10.2 2009/05/04 08:10:42 yamt Exp $");
11 1.2.10.2 yamt
12 1.2.10.2 yamt #include <sys/param.h>
13 1.2.10.2 yamt #include <sys/callout.h>
14 1.2.10.2 yamt #include <sys/cdefs.h>
15 1.2.10.2 yamt #include <sys/device.h>
16 1.2.10.2 yamt #include <sys/kernel.h>
17 1.2.10.2 yamt #include <sys/systm.h>
18 1.2.10.2 yamt
19 1.2.10.2 yamt #include <machine/param.h>
20 1.2.10.2 yamt #include <machine/bus.h>
21 1.2.10.2 yamt
22 1.2.10.2 yamt #include <arm/gemini/gemini_obiovar.h>
23 1.2.10.2 yamt #include <arm/gemini/gemini_lpcvar.h>
24 1.2.10.2 yamt #include <arm/gemini/gemini_lpchcvar.h>
25 1.2.10.2 yamt #include <arm/gemini/gemini_reg.h>
26 1.2.10.2 yamt
27 1.2.10.2 yamt static int gemini_lpchc_match(struct device *, struct cfdata *, void *);
28 1.2.10.2 yamt static void gemini_lpchc_attach(struct device *, struct device *, void *);
29 1.2.10.2 yamt static int gemini_lpchc_print(void *, const char *);
30 1.2.10.2 yamt
31 1.2.10.2 yamt CFATTACH_DECL_NEW(obio_lpchc, sizeof(struct gemini_lpchc_softc),
32 1.2.10.2 yamt gemini_lpchc_match, gemini_lpchc_attach, NULL, NULL);
33 1.2.10.2 yamt
34 1.2.10.2 yamt
35 1.2.10.2 yamt static int
36 1.2.10.2 yamt gemini_lpchc_match(struct device *parent, struct cfdata *cf, void *aux)
37 1.2.10.2 yamt {
38 1.2.10.2 yamt struct obio_attach_args *obio = aux;
39 1.2.10.2 yamt
40 1.2.10.2 yamt if (obio->obio_addr == OBIOCF_ADDR_DEFAULT)
41 1.2.10.2 yamt panic("geminilpchc must have addr specified in config.");
42 1.2.10.2 yamt
43 1.2.10.2 yamt if (obio->obio_addr == GEMINI_LPCHC_BASE)
44 1.2.10.2 yamt return 1;
45 1.2.10.2 yamt
46 1.2.10.2 yamt return 0;
47 1.2.10.2 yamt }
48 1.2.10.2 yamt
49 1.2.10.2 yamt static void
50 1.2.10.2 yamt gemini_lpchc_attach(struct device *parent, struct device *self, void *aux)
51 1.2.10.2 yamt {
52 1.2.10.2 yamt gemini_lpchc_softc_t *sc = device_private(self);
53 1.2.10.2 yamt struct obio_attach_args *obio = aux;
54 1.2.10.2 yamt struct gemini_lpchc_attach_args lpchc;
55 1.2.10.2 yamt uint32_t r;
56 1.2.10.2 yamt void *ih=NULL;
57 1.2.10.2 yamt
58 1.2.10.2 yamt sc->sc_dev = self;
59 1.2.10.2 yamt sc->sc_addr = obio->obio_addr;
60 1.2.10.2 yamt sc->sc_size = (obio->obio_size == OBIOCF_SIZE_DEFAULT)
61 1.2.10.2 yamt ? GEMINI_LPCHC_SIZE : obio->obio_size;
62 1.2.10.2 yamt
63 1.2.10.2 yamt sc->sc_iot = obio->obio_iot;
64 1.2.10.2 yamt
65 1.2.10.2 yamt if (bus_space_map(sc->sc_iot, sc->sc_addr, sc->sc_size, 0, &sc->sc_ioh))
66 1.2.10.2 yamt panic("%s: Cannot map registers", device_xname(self));
67 1.2.10.2 yamt
68 1.2.10.2 yamt r = bus_space_read_4(sc->sc_iot, sc->sc_ioh, GEMINI_LPCHC_ID);
69 1.2.10.2 yamt aprint_normal("\n%s: device %d, rev %#x ",
70 1.2.10.2 yamt device_xname(self), _LPCHC_ID_DEVICE(r), _LPCHC_ID_REV(r));
71 1.2.10.2 yamt
72 1.2.10.2 yamt
73 1.2.10.2 yamt sc->sc_intr = obio->obio_intr;
74 1.2.10.2 yamt if (obio->obio_intr != OBIOCF_INTR_DEFAULT) {
75 1.2.10.2 yamt ih = intr_establish(obio->obio_intr, IPL_SERIAL,
76 1.2.10.2 yamt IST_LEVEL_HIGH, gemini_lpchc_intr, sc);
77 1.2.10.2 yamt if (ih == NULL)
78 1.2.10.2 yamt panic("%s: cannot register intr %d",
79 1.2.10.2 yamt device_xname(self), obio->obio_intr);
80 1.2.10.2 yamt }
81 1.2.10.2 yamt sc->sc_ih = ih;
82 1.2.10.2 yamt
83 1.2.10.2 yamt gemini_lpchc_init(sc);
84 1.2.10.2 yamt
85 1.2.10.2 yamt aprint_normal("\n");
86 1.2.10.2 yamt aprint_naive("\n");
87 1.2.10.2 yamt
88 1.2.10.2 yamt lpchc.lpchc_iot = obio->obio_iot;
89 1.2.10.2 yamt lpchc.lpchc_addr = GEMINI_LPCIO_BASE; /* XXX sc_addr+offset */
90 1.2.10.2 yamt lpchc.lpchc_size = LPCCF_SIZE_DEFAULT; /* XXX placeholder */
91 1.2.10.2 yamt lpchc.lpchc_tag = sc;
92 1.2.10.2 yamt
93 1.2.10.2 yamt (void)config_found_ia(sc->sc_dev, "lpcbus", &lpchc, gemini_lpchc_print);
94 1.2.10.2 yamt }
95 1.2.10.2 yamt
96 1.2.10.2 yamt int
97 1.2.10.2 yamt gemini_lpchc_print(void *aux, const char *name)
98 1.2.10.2 yamt {
99 1.2.10.2 yamt struct gemini_lpchc_attach_args *lpchc = aux;
100 1.2.10.2 yamt
101 1.2.10.2 yamt if (lpchc->lpchc_addr != LPCCF_ADDR_DEFAULT)
102 1.2.10.2 yamt aprint_normal(" addr %#lx", lpchc->lpchc_addr);
103 1.2.10.2 yamt
104 1.2.10.2 yamt return UNCONF;
105 1.2.10.2 yamt }
106