pq3sdhc.c revision 1.2 1 1.2 matt /* $NetBSD: pq3sdhc.c,v 1.2 2011/01/18 01:02:53 matt Exp $ */
2 1.2 matt /*-
3 1.2 matt * Copyright (c) 2011 The NetBSD Foundation, Inc.
4 1.2 matt * All rights reserved.
5 1.2 matt *
6 1.2 matt * This code is derived from software contributed to The NetBSD Foundation
7 1.2 matt * by Matt Thomas of 3am Software Foundry.
8 1.2 matt *
9 1.2 matt * Redistribution and use in source and binary forms, with or without
10 1.2 matt * modification, are permitted provided that the following conditions
11 1.2 matt * are met:
12 1.2 matt * 1. Redistributions of source code must retain the above copyright
13 1.2 matt * notice, this list of conditions and the following disclaimer.
14 1.2 matt * 2. Redistributions in binary form must reproduce the above copyright
15 1.2 matt * notice, this list of conditions and the following disclaimer in the
16 1.2 matt * documentation and/or other materials provided with the distribution.
17 1.2 matt *
18 1.2 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 1.2 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 1.2 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 1.2 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 1.2 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 1.2 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 1.2 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 1.2 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 1.2 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 1.2 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 1.2 matt * POSSIBILITY OF SUCH DAMAGE.
29 1.2 matt */
30 1.2 matt
31 1.2 matt #include <sys/cdefs.h>
32 1.2 matt __KERNEL_RCSID(0, "$NetBSD: pq3sdhc.c,v 1.2 2011/01/18 01:02:53 matt Exp $");
33 1.2 matt
34 1.2 matt #include <sys/param.h>
35 1.2 matt #include <sys/systm.h>
36 1.2 matt #include <sys/device.h>
37 1.2 matt #include <sys/kernel.h>
38 1.2 matt #include <sys/proc.h>
39 1.2 matt #include <sys/queue.h>
40 1.2 matt
41 1.2 matt #include <sys/bus.h>
42 1.2 matt
43 1.2 matt #include <powerpc/booke/cpuvar.h>
44 1.2 matt #include <powerpc/booke/e500var.h>
45 1.2 matt #include <powerpc/booke/e500reg.h>
46 1.2 matt
47 1.2 matt #include <dev/sdmmc/sdhcreg.h>
48 1.2 matt #include <dev/sdmmc/sdhcvar.h>
49 1.2 matt
50 1.2 matt static int pq3sdhc_match(device_t, cfdata_t, void *);
51 1.2 matt static void pq3sdhc_attach(device_t, device_t, void *);
52 1.2 matt
53 1.2 matt struct pq3sdhc_softc {
54 1.2 matt struct sdhc_softc sc;
55 1.2 matt bus_space_tag_t sc_bst;
56 1.2 matt bus_space_handle_t sc_bsh;
57 1.2 matt struct sdhc_host *sc_hosts[1];
58 1.2 matt void *sc_ih; /* interrupt vectoring */
59 1.2 matt };
60 1.2 matt
61 1.2 matt CFATTACH_DECL_NEW(pq3sdhc, sizeof(struct pq3sdhc_softc),
62 1.2 matt pq3sdhc_match, pq3sdhc_attach, NULL, NULL);
63 1.2 matt
64 1.2 matt static int
65 1.2 matt pq3sdhc_match(device_t parent, cfdata_t cf, void *aux)
66 1.2 matt {
67 1.2 matt
68 1.2 matt if (!e500_cpunode_submatch(parent, cf, cf->cf_name, aux))
69 1.2 matt return 0;
70 1.2 matt
71 1.2 matt return 1;
72 1.2 matt }
73 1.2 matt
74 1.2 matt static void
75 1.2 matt pq3sdhc_attach(device_t parent, device_t self, void *aux)
76 1.2 matt {
77 1.2 matt struct cpunode_softc * const psc = device_private(parent);
78 1.2 matt struct pq3sdhc_softc * const sc = device_private(self);
79 1.2 matt struct cpunode_attach_args * const cna = aux;
80 1.2 matt struct cpunode_locators * const cnl = &cna->cna_locs;
81 1.2 matt int error;
82 1.2 matt
83 1.2 matt psc->sc_children |= cna->cna_childmask;
84 1.2 matt sc->sc.sc_dmat = cna->cna_dmat;
85 1.2 matt sc->sc.sc_dev = self;
86 1.2 matt //sc->sc.sc_flags |= SDHC_FLAG_USE_DMA;
87 1.2 matt sc->sc.sc_host = sc->sc_hosts;
88 1.2 matt sc->sc_bst = cna->cna_memt;
89 1.2 matt
90 1.2 matt error = bus_space_map(sc->sc_bst, cnl->cnl_addr, cnl->cnl_size, 0,
91 1.2 matt &sc->sc_bsh);
92 1.2 matt if (error) {
93 1.2 matt aprint_error_dev(self,
94 1.2 matt "can't map registers for %s: %d\n", cnl->cnl_name, error);
95 1.2 matt return;
96 1.2 matt }
97 1.2 matt
98 1.2 matt aprint_naive(": SDHC controller\n");
99 1.2 matt aprint_normal(": SDHC controller\n");
100 1.2 matt
101 1.2 matt sc->sc_ih = intr_establish(cnl->cnl_intrs[0], IPL_VM, IST_ONCHIP,
102 1.2 matt sdhc_intr, &sc->sc);
103 1.2 matt if (sc->sc_ih == NULL) {
104 1.2 matt aprint_error_dev(self, "failed to establish interrupt %d\n",
105 1.2 matt cnl->cnl_intrs[0]);
106 1.2 matt goto fail;
107 1.2 matt }
108 1.2 matt aprint_normal_dev(self, "interrupting on irq %d\n",
109 1.2 matt cnl->cnl_intrs[0]);
110 1.2 matt
111 1.2 matt error = sdhc_host_found(&sc->sc, sc->sc_bst, sc->sc_bsh, cnl->cnl_size);
112 1.2 matt if (error != 0) {
113 1.2 matt aprint_error_dev(self, "couldn't initialize host, error=%d\n",
114 1.2 matt error);
115 1.2 matt goto fail;
116 1.2 matt }
117 1.2 matt return;
118 1.2 matt
119 1.2 matt fail:
120 1.2 matt if (sc->sc_ih) {
121 1.2 matt intr_disestablish(sc->sc_ih);
122 1.2 matt sc->sc_ih = NULL;
123 1.2 matt }
124 1.2 matt bus_space_unmap(sc->sc_bst, sc->sc_bsh, cnl->cnl_size);
125 1.2 matt }
126