j720ssp.c revision 1.24.2.1 1 /* $NetBSD: j720ssp.c,v 1.24.2.1 2006/06/21 14:51:44 yamt Exp $ */
2
3 /*-
4 * Copyright (c) 2001, 2006 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by IWAMOTO Toshihiro.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 /* Jornada 720 SSP port. */
40
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: j720ssp.c,v 1.24.2.1 2006/06/21 14:51:44 yamt Exp $");
43
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/device.h>
47
48 #include <arm/sa11x0/sa11x0_var.h>
49 #include <arm/sa11x0/sa11x0_gpioreg.h>
50 #include <arm/sa11x0/sa11x0_ppcreg.h>
51 #include <arm/sa11x0/sa11x0_sspreg.h>
52
53 #include <hpcarm/dev/j720sspvar.h>
54
55 #ifdef DEBUG
56 #define DPRINTF(arg) printf arg
57 #else
58 #define DPRINTF(arg) /* nothing */
59 #endif
60
61 static int j720ssp_match(struct device *, struct cfdata *, void *);
62 static void j720ssp_attach(struct device *, struct device *, void *);
63 static int j720ssp_search(struct device *, struct cfdata *,
64 const int *, void *);
65 static int j720ssp_print(void *, const char *);
66
67 CFATTACH_DECL(j720ssp, sizeof(struct j720ssp_softc),
68 j720ssp_match, j720ssp_attach, NULL, NULL);
69
70
71 static int
72 j720ssp_match(struct device *parent, struct cfdata *cf, void *aux)
73 {
74
75 if (strcmp(cf->cf_name, "j720ssp") != 0)
76 return 0;
77
78 return 1;
79 }
80
81 static void
82 j720ssp_attach(struct device *parent, struct device *self, void *aux)
83 {
84 struct j720ssp_softc *sc = (void *)self;
85 struct sa11x0_softc *psc = (void *)parent;
86 struct sa11x0_attach_args *sa = aux;
87
88 sc->sc_iot = psc->sc_iot;
89 sc->sc_gpioh = psc->sc_gpioh;
90 sc->sc_parent = psc;
91
92 if (bus_space_map(sc->sc_iot, sa->sa_addr, sa->sa_size, 0,
93 &sc->sc_ssph)) {
94 printf(": unable to map SSP registers\n");
95 return;
96 }
97
98 printf("\n");
99
100 config_search_ia(j720ssp_search, self, "j720ssp", NULL);
101 }
102
103 static int
104 j720ssp_search(struct device *parent, struct cfdata *cf,
105 const int *ldesc, void *aux)
106 {
107
108 if (config_match(parent, cf, NULL) > 0)
109 config_attach(parent, cf, NULL, j720ssp_print);
110
111 return 0;
112 }
113
114 static int
115 j720ssp_print(void *aux, const char *pnp)
116 {
117
118 return pnp ? QUIET : UNCONF;
119 }
120
121 int
122 j720ssp_readwrite(struct j720ssp_softc *sc, int drainfifo, int in,
123 int *out, int wait)
124 {
125 int timeout;
126
127 while (!(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_TNF))
128 continue;
129
130 timeout = 400000;
131 while (bus_space_read_4(sc->sc_iot, sc->sc_gpioh, SAGPIO_PLR) & 0x400)
132 if (--timeout == 0) {
133 DPRINTF(("j720ssp_readwrite: timeout 0\n"));
134 return -1;
135 }
136 if (drainfifo) {
137 while (bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) &
138 SR_RNE)
139 bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
140 delay(wait);
141 }
142
143 bus_space_write_4(sc->sc_iot, sc->sc_ssph, SASSP_DR, in);
144
145 delay(wait);
146 timeout = 100000;
147 while (!(bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_SR) & SR_RNE))
148 if (--timeout == 0) {
149 DPRINTF(("j720ssp_readwrite: timeout 1\n"));
150 return -1;
151 }
152
153 *out = bus_space_read_4(sc->sc_iot, sc->sc_ssph, SASSP_DR);
154
155 return 0;
156 }
157