mkclock_ap.c revision 1.2.4.4 1 1.2.4.4 skrll /* $NetBSD: mkclock_ap.c,v 1.2.4.4 2004/09/21 13:19:32 skrll Exp $ */
2 1.2.4.2 skrll
3 1.2.4.2 skrll /*-
4 1.2.4.2 skrll * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.2.4.2 skrll * All rights reserved.
6 1.2.4.2 skrll *
7 1.2.4.2 skrll * This code is derived from software contributed to The NetBSD Foundation
8 1.2.4.2 skrll * by Jason R. Thorpe.
9 1.2.4.2 skrll *
10 1.2.4.2 skrll * Redistribution and use in source and binary forms, with or without
11 1.2.4.2 skrll * modification, are permitted provided that the following conditions
12 1.2.4.2 skrll * are met:
13 1.2.4.2 skrll * 1. Redistributions of source code must retain the above copyright
14 1.2.4.2 skrll * notice, this list of conditions and the following disclaimer.
15 1.2.4.2 skrll * 2. Redistributions in binary form must reproduce the above copyright
16 1.2.4.2 skrll * notice, this list of conditions and the following disclaimer in the
17 1.2.4.2 skrll * documentation and/or other materials provided with the distribution.
18 1.2.4.2 skrll * 3. All advertising materials mentioning features or use of this software
19 1.2.4.2 skrll * must display the following acknowledgement:
20 1.2.4.2 skrll * This product includes software developed by the NetBSD
21 1.2.4.2 skrll * Foundation, Inc. and its contributors.
22 1.2.4.2 skrll * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2.4.2 skrll * contributors may be used to endorse or promote products derived
24 1.2.4.2 skrll * from this software without specific prior written permission.
25 1.2.4.2 skrll *
26 1.2.4.2 skrll * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2.4.2 skrll * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2.4.2 skrll * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2.4.2 skrll * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2.4.2 skrll * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2.4.2 skrll * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2.4.2 skrll * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2.4.2 skrll * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2.4.2 skrll * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2.4.2 skrll * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2.4.2 skrll * POSSIBILITY OF SUCH DAMAGE.
37 1.2.4.2 skrll */
38 1.2.4.2 skrll
39 1.2.4.2 skrll #include <sys/cdefs.h>
40 1.2.4.4 skrll __KERNEL_RCSID(0, "$NetBSD: mkclock_ap.c,v 1.2.4.4 2004/09/21 13:19:32 skrll Exp $");
41 1.2.4.2 skrll
42 1.2.4.2 skrll #include <sys/param.h>
43 1.2.4.2 skrll #include <sys/kernel.h>
44 1.2.4.2 skrll #include <sys/systm.h>
45 1.2.4.2 skrll #include <sys/device.h>
46 1.2.4.2 skrll
47 1.2.4.2 skrll #include <machine/cpu.h>
48 1.2.4.2 skrll #include <machine/bus.h>
49 1.2.4.2 skrll
50 1.2.4.2 skrll #include <dev/clock_subr.h>
51 1.2.4.2 skrll #include <dev/ic/mk48txxreg.h>
52 1.2.4.2 skrll #include <dev/ic/mk48txxvar.h>
53 1.2.4.2 skrll
54 1.2.4.2 skrll #include <newsmips/apbus/apbusvar.h>
55 1.2.4.2 skrll
56 1.2.4.2 skrll #define MKCLOCK_AP_STRIDE 2
57 1.2.4.2 skrll #define MKCLOCK_AP_OFFSET \
58 1.2.4.2 skrll ((MK48T02_CLKOFF + MK48TXX_ICSR) << MKCLOCK_AP_STRIDE)
59 1.2.4.2 skrll
60 1.2.4.2 skrll int mkclock_ap_match(struct device *, struct cfdata *, void *);
61 1.2.4.2 skrll void mkclock_ap_attach(struct device *, struct device *, void *);
62 1.2.4.2 skrll static u_int8_t mkclock_ap_nvrd(struct mk48txx_softc *, int);
63 1.2.4.2 skrll static void mkclock_ap_nvwr(struct mk48txx_softc *, int, u_int8_t);
64 1.2.4.2 skrll
65 1.2.4.2 skrll CFATTACH_DECL(mkclock_ap, sizeof(struct mk48txx_softc),
66 1.2.4.2 skrll mkclock_ap_match, mkclock_ap_attach, NULL, NULL);
67 1.2.4.2 skrll
68 1.2.4.2 skrll extern struct cfdriver mkclock_cd;
69 1.2.4.2 skrll
70 1.2.4.2 skrll int
71 1.2.4.2 skrll mkclock_ap_match(parent, cf, aux)
72 1.2.4.2 skrll struct device *parent;
73 1.2.4.2 skrll struct cfdata *cf;
74 1.2.4.2 skrll void *aux;
75 1.2.4.2 skrll {
76 1.2.4.2 skrll struct apbus_attach_args *apa = aux;
77 1.2.4.2 skrll
78 1.2.4.2 skrll if (strcmp("clock", apa->apa_name) != 0)
79 1.2.4.2 skrll return 0;
80 1.2.4.2 skrll
81 1.2.4.2 skrll return 1;
82 1.2.4.2 skrll }
83 1.2.4.2 skrll
84 1.2.4.2 skrll void
85 1.2.4.2 skrll mkclock_ap_attach(parent, self, aux)
86 1.2.4.2 skrll struct device *parent, *self;
87 1.2.4.2 skrll void *aux;
88 1.2.4.2 skrll {
89 1.2.4.2 skrll struct mk48txx_softc *sc = (void *)self;
90 1.2.4.2 skrll struct apbus_attach_args *apa = aux;
91 1.2.4.2 skrll
92 1.2.4.2 skrll printf(" slot%d addr 0x%lx", apa->apa_slotno, apa->apa_hwbase);
93 1.2.4.2 skrll if (bus_space_map(sc->sc_bst, apa->apa_hwbase - MKCLOCK_AP_OFFSET,
94 1.2.4.2 skrll MK48T02_CLKSZ, 0, &sc->sc_bsh) != 0)
95 1.2.4.2 skrll printf("can't map device space\n");
96 1.2.4.2 skrll
97 1.2.4.2 skrll sc->sc_model = "mk48t02";
98 1.2.4.2 skrll sc->sc_year0 = 1900;
99 1.2.4.2 skrll sc->sc_nvrd = mkclock_ap_nvrd;
100 1.2.4.2 skrll sc->sc_nvwr = mkclock_ap_nvwr;
101 1.2.4.2 skrll
102 1.2.4.2 skrll mk48txx_attach(sc);
103 1.2.4.2 skrll
104 1.2.4.2 skrll printf("\n");
105 1.2.4.2 skrll
106 1.2.4.2 skrll todr_attach(&sc->sc_handle);
107 1.2.4.2 skrll }
108 1.2.4.2 skrll
109 1.2.4.2 skrll static u_int8_t
110 1.2.4.2 skrll mkclock_ap_nvrd(sc, off)
111 1.2.4.2 skrll struct mk48txx_softc *sc;
112 1.2.4.2 skrll int off;
113 1.2.4.2 skrll {
114 1.2.4.2 skrll u_int8_t rv;
115 1.2.4.2 skrll
116 1.2.4.2 skrll rv = bus_space_read_4(sc->sc_bst, sc->sc_bsh, off << MKCLOCK_AP_STRIDE);
117 1.2.4.2 skrll return rv;
118 1.2.4.2 skrll }
119 1.2.4.2 skrll
120 1.2.4.2 skrll static void
121 1.2.4.2 skrll mkclock_ap_nvwr(sc, off, v)
122 1.2.4.2 skrll struct mk48txx_softc *sc;
123 1.2.4.2 skrll int off;
124 1.2.4.2 skrll u_int8_t v;
125 1.2.4.2 skrll {
126 1.2.4.2 skrll
127 1.2.4.2 skrll bus_space_write_4(sc->sc_bst, sc->sc_bsh, off << MKCLOCK_AP_STRIDE, v);
128 1.2.4.2 skrll }
129