1 /* $OpenBSD: wbsd_ebus.c,v 1.2 2021/10/24 17:05:04 mpi Exp $ */
2 /*
3 * Copyright (c) 2009 Mark Kettenis
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18 #include <sys/param.h>
19 #include <sys/device.h>
20 #include <sys/kernel.h>
21 #include <sys/proc.h>
22 #include <sys/systm.h>
23
24 #include <machine/autoconf.h>
25 #include <machine/openfirm.h>
26
27 #include <sparc64/dev/ebusreg.h>
28 #include <sparc64/dev/ebusvar.h>
29
30 #include <dev/ic/w83l518dreg.h>
31 #include <dev/ic/w83l518dvar.h>
32 #include <dev/ic/w83l518d_sdmmc.h>
33
34 int wbsd_ebus_match(struct device *, void *, void *);
35 void wbsd_ebus_attach(struct device *, struct device *, void *);
36
37 const struct cfattach wbsd_ebus_ca = {
38 sizeof(struct wb_softc), wbsd_ebus_match, wbsd_ebus_attach
39 };
40
41 struct cfdriver wbsd_cd = {
42 NULL, "wbsd", DV_DULL
43 };
44
45 int
wbsd_ebus_match(struct device * parent,void * match,void * aux)46 wbsd_ebus_match(struct device *parent, void *match, void *aux)
47 {
48 struct ebus_attach_args *ea = aux;
49
50 if (strcmp(ea->ea_name, "TAD,wb-sdcard") == 0)
51 return (1);
52
53 return (0);
54 }
55
56 void
wbsd_ebus_attach(struct device * parent,struct device * self,void * aux)57 wbsd_ebus_attach(struct device *parent, struct device *self, void *aux)
58 {
59 struct wb_softc *sc = (void *)self;
60 struct ebus_attach_args *ea = aux;
61
62 if (ebus_bus_map(ea->ea_iotag, 0,
63 EBUS_PADDR_FROM_REG(&ea->ea_regs[0]),
64 ea->ea_regs[0].size, 0, 0, &sc->wb_ioh) == 0) {
65 sc->wb_iot = ea->ea_iotag;
66 } else if (ebus_bus_map(ea->ea_memtag, 0,
67 EBUS_PADDR_FROM_REG(&ea->ea_regs[0]),
68 ea->ea_regs[0].size, 0, 0, &sc->wb_ioh) == 0) {
69 sc->wb_iot = ea->ea_memtag;
70 } else {
71 printf(": can't map register space\n");
72 return;
73 }
74
75 bus_intr_establish(sc->wb_iot, ea->ea_intrs[0], IPL_BIO, 0, wb_intr,
76 sc, self->dv_xname);
77
78 printf("\n");
79
80 sc->wb_type = WB_DEVNO_SD;
81 wb_attach(sc);
82 }
83