1 /* $NetBSD: j720ssp.c,v 1.31 2008/04/28 20:23:21 martin Exp $ */
4 * Copyright (c) 2001, 2006 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by IWAMOTO Toshihiro.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 /* Jornada 720 SSP port. */
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: j720ssp.c,v 1.31 2008/04/28 20:23:21 martin Exp $");
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
41 #include <arm/sa11x0/sa11x0_var.h>
42 #include <arm/sa11x0/sa11x0_gpioreg.h>
43 #include <arm/sa11x0/sa11x0_ppcreg.h>
44 #include <arm/sa11x0/sa11x0_sspreg.h>
46 #include <hpcarm/dev/j720sspvar.h>
49 #define DPRINTF(arg) aprint_normal arg
51 #define DPRINTF(arg) /* nothing */
54 #define BIT_INVERT(x) \
56 (x) = ((((x) & 0xf0) >> 4) | (((x) & 0x0f) << 4)); \
57 (x) = ((((x) & 0xcc) >> 2) | (((x) & 0x33) << 2)); \
58 (x) = ((((x) & 0xaa) >> 1) | (((x) & 0x55) << 1)); \
61 static int j720ssp_match(device_t
, cfdata_t
, void *);
62 static void j720ssp_attach(device_t
, device_t
, void *);
63 static int j720ssp_search(device_t
, cfdata_t
, const int *, void *);
64 static int j720ssp_print(void *, const char *);
66 CFATTACH_DECL_NEW(j720ssp
, sizeof(struct j720ssp_softc
),
67 j720ssp_match
, j720ssp_attach
, NULL
, NULL
);
71 j720ssp_match(device_t parent
, cfdata_t cf
, void *aux
)
74 if (strcmp(cf
->cf_name
, "j720ssp") != 0)
81 j720ssp_attach(device_t parent
, device_t self
, void *aux
)
83 struct j720ssp_softc
*sc
= device_private(self
);
84 struct sa11x0_softc
*psc
= device_private(parent
);
85 struct sa11x0_attach_args
*sa
= aux
;
88 sc
->sc_iot
= psc
->sc_iot
;
89 sc
->sc_gpioh
= psc
->sc_gpioh
;
92 if (bus_space_map(sc
->sc_iot
, sa
->sa_addr
, sa
->sa_size
, 0,
94 aprint_normal(": unable to map SSP registers\n");
100 config_search_ia(j720ssp_search
, self
, "j720ssp", NULL
);
104 j720ssp_search(device_t parent
, cfdata_t cf
, const int *ldesc
, void *aux
)
107 if (config_match(parent
, cf
, NULL
) > 0)
108 config_attach(parent
, cf
, NULL
, j720ssp_print
);
114 j720ssp_print(void *aux
, const char *pnp
)
117 return pnp
? QUIET
: UNCONF
;
121 j720ssp_readwrite(struct j720ssp_softc
*sc
, int drainfifo
, int in
,
126 while (!(bus_space_read_4(sc
->sc_iot
, sc
->sc_ssph
, SASSP_SR
) & SR_TNF
))
130 while (bus_space_read_4(sc
->sc_iot
, sc
->sc_gpioh
, SAGPIO_PLR
) & 0x400)
131 if (--timeout
== 0) {
132 DPRINTF(("j720ssp_readwrite: timeout 0\n"));
136 while (bus_space_read_4(sc
->sc_iot
, sc
->sc_ssph
, SASSP_SR
) &
138 bus_space_read_4(sc
->sc_iot
, sc
->sc_ssph
, SASSP_DR
);
143 bus_space_write_4(sc
->sc_iot
, sc
->sc_ssph
, SASSP_DR
, in
<< 8);
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"));
153 *out
= bus_space_read_4(sc
->sc_iot
, sc
->sc_ssph
, SASSP_DR
);