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