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