aupsc.c revision 1.1 1 /* $NetBSD: aupsc.c,v 1.1 2006/02/24 14:34:31 shige Exp $ */
2
3 /*-
4 * Copyright (c) 2006 Shigeyuki Fukushima.
5 * All rights reserved.
6 *
7 * Written by Shigeyuki Fukushima.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above
15 * copyright notice, this list of conditions and the following
16 * disclaimer in the documentation and/or other materials provided
17 * with the distribution.
18 * 3. The name of the author may not be used to endorse or promote
19 * products derived from this software without specific prior
20 * written permission.
21 *
22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
23 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
24 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
26 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
28 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
31 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: aupsc.c,v 1.1 2006/02/24 14:34:31 shige Exp $");
37
38 #include "locators.h"
39
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/device.h>
43 #include <sys/errno.h>
44
45 #include <machine/bus.h>
46 #include <machine/cpu.h>
47
48 #include <mips/alchemy/include/aubusvar.h>
49 #include <mips/alchemy/include/aureg.h>
50 #include <mips/alchemy/dev/aupscreg.h>
51 #include <mips/alchemy/dev/aupscvar.h>
52
53 struct aupsc_softc {
54 struct device sc_dev;
55 bus_space_tag_t sc_bust;
56 bus_space_handle_t sc_bush;
57 int sc_pscsel;
58 };
59
60 const struct aupsc_proto {
61 const char *name;
62 } aupsc_protos [] = {
63 #if 0
64 { "auaudio" },
65 { "aui2s" },
66 { "ausmbus" },
67 { "auspi" },
68 #endif
69 { NULL }
70 };
71
72 static int aupsc_match(struct device *, struct cfdata *, void *);
73 static void aupsc_attach(struct device *, struct device *, void *);
74 static int aupsc_submatch(struct device *parent, struct cfdata *cf,
75 const int *ldesc, void *aux);
76 static int aupsc_print(void *aux, const char *pnp);
77
78 CFATTACH_DECL(aupsc, sizeof(struct aupsc_softc),
79 aupsc_match, aupsc_attach, NULL, NULL);
80
81 static int
82 aupsc_match(struct device *parent, struct cfdata *cf, void *aux)
83 {
84 struct aubus_attach_args *aa = (struct aubus_attach_args *)aux;
85
86 if (strcmp(aa->aa_name, cf->cf_name) != 0)
87 return 0;
88
89 return 1;
90 }
91
92 static void
93 aupsc_attach(struct device *parent, struct device *self, void *aux)
94 {
95 int i;
96 uint32_t rv;
97 struct aupsc_softc *sc = (struct aupsc_softc *)self;
98 struct aubus_attach_args *aa = (struct aubus_attach_args *)aux;
99 struct aupsc_attach_args pa;
100
101 sc->sc_bust = aa->aa_st;
102 if (bus_space_map(sc->sc_bust, aa->aa_addr,
103 AUPSC_SIZE, 0, &sc->sc_bush) != 0) {
104 aprint_normal(": unable to map device registers\n");
105 return;
106 }
107
108 /* Initialize PSC_SEL register */
109 sc->sc_pscsel = AUPSC_SEL_DISABLE;
110 rv = bus_space_read_4(sc->sc_bust, sc->sc_bush, AUPSC_SEL);
111 bus_space_write_4(sc->sc_bust, sc->sc_bush,
112 AUPSC_SEL, (rv & AUPSC_SEL_PS(AUPSC_SEL_DISABLE)));
113
114 aprint_normal(": Alchemy PSC\n");
115
116 for (i = 0 ; aupsc_protos[i].name != NULL ; i++) {
117 pa.aupsc_name = aupsc_protos[i].name;
118 pa.aupsc_bust = sc->sc_bust;
119 pa.aupsc_bush = sc->sc_bush;
120
121 (void) config_found_sm_loc(self, "aupsc", NULL,
122 &pa, aupsc_print, aupsc_submatch);
123 }
124 }
125
126 static int
127 aupsc_submatch(struct device *parent, struct cfdata *cf,
128 const int *ldesc, void *aux)
129 {
130
131 return config_match(parent, cf, aux);
132 }
133
134 static int
135 aupsc_print(void *aux, const char *pnp)
136 {
137 struct aupsc_attach_args *pa = aux;
138
139 if (pnp)
140 aprint_normal("%s at %s", pa->aupsc_name, pnp);
141
142 return UNCONF;
143 }
144