tx39clock.c revision 1.1 1 1.1 uch /* $NetBSD: tx39clock.c,v 1.1 1999/11/20 19:56:33 uch Exp $ */
2 1.1 uch
3 1.1 uch /*
4 1.1 uch * Copyright (c) 1999, by UCHIYAMA Yasushi
5 1.1 uch * All rights reserved.
6 1.1 uch *
7 1.1 uch * Redistribution and use in source and binary forms, with or without
8 1.1 uch * modification, are permitted provided that the following conditions
9 1.1 uch * are met:
10 1.1 uch * 1. Redistributions of source code must retain the above copyright
11 1.1 uch * notice, this list of conditions and the following disclaimer.
12 1.1 uch * 2. The name of the developer may NOT be used to endorse or promote products
13 1.1 uch * derived from this software without specific prior written permission.
14 1.1 uch *
15 1.1 uch * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 1.1 uch * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 1.1 uch * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 1.1 uch * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 1.1 uch * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 1.1 uch * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 1.1 uch * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 uch * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 1.1 uch * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 1.1 uch * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 1.1 uch * SUCH DAMAGE.
26 1.1 uch *
27 1.1 uch */
28 1.1 uch #include "opt_tx39_debug.h"
29 1.1 uch
30 1.1 uch #include <sys/param.h>
31 1.1 uch #include <sys/systm.h>
32 1.1 uch #include <sys/device.h>
33 1.1 uch
34 1.1 uch #include <machine/bus.h>
35 1.1 uch #include <machine/clock_machdep.h>
36 1.1 uch #include <machine/cpu.h>
37 1.1 uch
38 1.1 uch #include <hpcmips/tx/tx39var.h>
39 1.1 uch #include <hpcmips/tx/tx39icureg.h> /* XXX */
40 1.1 uch #include <hpcmips/tx/tx39clockreg.h>
41 1.1 uch #include <hpcmips/tx/tx39timerreg.h>
42 1.1 uch #include <dev/dec/clockvar.h>
43 1.1 uch
44 1.1 uch #define ISSETPRINT(r, m) __is_set_print(r, TX39_CLOCK_EN##m##CLK, #m)
45 1.1 uch
46 1.1 uch void clock_init __P((struct device*));
47 1.1 uch void clock_get __P((struct device*, time_t, struct clocktime*));
48 1.1 uch void clock_set __P((struct device*, struct clocktime*));
49 1.1 uch
50 1.1 uch static const struct clockfns clockfns = {
51 1.1 uch clock_init, clock_get, clock_set,
52 1.1 uch };
53 1.1 uch
54 1.1 uch int tx39clock_match __P((struct device*, struct cfdata*, void*));
55 1.1 uch void tx39clock_attach __P((struct device*, struct device*, void*));
56 1.1 uch void tx39clock_dump __P((tx_chipset_tag_t));
57 1.1 uch
58 1.1 uch void tx39timer_freeze __P((tx_chipset_tag_t));
59 1.1 uch void tx39timer_rtcreset __P((tx_chipset_tag_t));
60 1.1 uch
61 1.1 uch struct tx39clock_softc {
62 1.1 uch struct device sc_dev;
63 1.1 uch tx_chipset_tag_t sc_tc;
64 1.1 uch };
65 1.1 uch
66 1.1 uch struct cfattach tx39clock_ca = {
67 1.1 uch sizeof(struct tx39clock_softc), tx39clock_match, tx39clock_attach
68 1.1 uch };
69 1.1 uch
70 1.1 uch int
71 1.1 uch tx39clock_match(parent, cf, aux)
72 1.1 uch struct device *parent;
73 1.1 uch struct cfdata *cf;
74 1.1 uch void *aux;
75 1.1 uch {
76 1.1 uch return 2; /* 1st attach group of txsim */
77 1.1 uch }
78 1.1 uch
79 1.1 uch void
80 1.1 uch tx39clock_attach(parent, self, aux)
81 1.1 uch struct device *parent;
82 1.1 uch struct device *self;
83 1.1 uch void *aux;
84 1.1 uch {
85 1.1 uch struct txsim_attach_args *ta = aux;
86 1.1 uch struct tx39clock_softc *sc = (void*)self;
87 1.1 uch tx_chipset_tag_t tc;
88 1.1 uch txreg_t reg;
89 1.1 uch
90 1.1 uch tc = sc->sc_tc = ta->ta_tc;
91 1.1 uch
92 1.1 uch
93 1.1 uch /*
94 1.1 uch * Enable periodic timer
95 1.1 uch * but interrupt don't arise yet. see clock_init().
96 1.1 uch */
97 1.1 uch reg = tx_conf_read(tc, TX39_TIMERCONTROL_REG);
98 1.1 uch reg |= TX39_TIMERCONTROL_ENPERTIMER;
99 1.1 uch tx_conf_write(tc, TX39_TIMERCONTROL_REG, reg);
100 1.1 uch
101 1.1 uch /* Set counter */
102 1.1 uch #if 0
103 1.1 uch {
104 1.1 uch int cnt = 0xffff; /* XXX the most slower. */
105 1.1 uch reg = tx_conf_read(tc, TX39_TIMERPERIODIC_REG);
106 1.1 uch reg = TX39_TIMERPERIODIC_PERVAL_SET(reg, cnt);
107 1.1 uch tx_conf_write(tc, TX39_TIMERPERIODIC_REG, reg);
108 1.1 uch }
109 1.1 uch #endif
110 1.1 uch clockattach(self, &clockfns);
111 1.1 uch
112 1.1 uch tx39clock_dump(tc);
113 1.1 uch }
114 1.1 uch
115 1.1 uch /*
116 1.1 uch * RTC and ALARM
117 1.1 uch * RTCINT ... INTR5 bit 31 (roll over)
118 1.1 uch * ALARMINT ... INTR5 bit 30
119 1.1 uch * PERINT ... INTR5 bit 29
120 1.1 uch */
121 1.1 uch void
122 1.1 uch tx39timer_freeze(tc)
123 1.1 uch tx_chipset_tag_t tc;
124 1.1 uch {
125 1.1 uch txreg_t reg;
126 1.1 uch
127 1.1 uch reg = tx_conf_read(tc, TX39_TIMERCONTROL_REG);
128 1.1 uch /* Freeze RTC */
129 1.1 uch reg |= TX39_TIMERCONTROL_FREEZEPRE; /* Upper 8bit */
130 1.1 uch reg |= TX39_TIMERCONTROL_FREEZERTC; /* Lower 32bit */
131 1.1 uch /* Freeze periodic timer */
132 1.1 uch reg |= TX39_TIMERCONTROL_FREEZETIMER;
133 1.1 uch reg &= ~TX39_TIMERCONTROL_ENPERTIMER;
134 1.1 uch tx_conf_write(tc, TX39_TIMERCONTROL_REG, reg);
135 1.1 uch }
136 1.1 uch
137 1.1 uch void
138 1.1 uch tx39timer_rtcreset(tc)
139 1.1 uch tx_chipset_tag_t tc;
140 1.1 uch {
141 1.1 uch txreg_t reg;
142 1.1 uch
143 1.1 uch reg = tx_conf_read(tc, TX39_TIMERCONTROL_REG);
144 1.1 uch /* Reset counter and stop */
145 1.1 uch reg |= TX39_TIMERCONTROL_RTCCLR;
146 1.1 uch tx_conf_write(tc, TX39_TIMERCONTROL_REG, reg);
147 1.1 uch /* Count again */
148 1.1 uch reg &= ~TX39_TIMERCONTROL_RTCCLR;
149 1.1 uch tx_conf_write(tc, TX39_TIMERCONTROL_REG, reg);
150 1.1 uch }
151 1.1 uch
152 1.1 uch void
153 1.1 uch clock_init(dev)
154 1.1 uch struct device *dev;
155 1.1 uch {
156 1.1 uch tx_chipset_tag_t tc;
157 1.1 uch txreg_t reg;
158 1.1 uch
159 1.1 uch tc = tx_conf_get_tag();
160 1.1 uch /* Enable periodic timer */
161 1.1 uch reg = tx_conf_read(tc, TX39_INTRENABLE6_REG);
162 1.1 uch reg |= TX39_INTRPRI13_TIMER_PERIODIC_BIT;
163 1.1 uch tx_conf_write(tc, TX39_INTRENABLE6_REG, reg);
164 1.1 uch
165 1.1 uch }
166 1.1 uch
167 1.1 uch void
168 1.1 uch clock_get(dev, base, ct)
169 1.1 uch struct device *dev;
170 1.1 uch time_t base;
171 1.1 uch struct clocktime *ct;
172 1.1 uch {
173 1.1 uch tx_chipset_tag_t tc;
174 1.1 uch txreg_t reghi, reglo, oreghi, oreglo;
175 1.1 uch int i;
176 1.1 uch
177 1.1 uch tc = tx_conf_get_tag();
178 1.1 uch i = 10;
179 1.1 uch do {
180 1.1 uch reghi = tx_conf_read(tc, TX39_TIMERRTCHI_REG);
181 1.1 uch reglo = tx_conf_read(tc, TX39_TIMERRTCLO_REG);
182 1.1 uch oreghi = tx_conf_read(tc, TX39_TIMERRTCHI_REG);
183 1.1 uch oreglo = tx_conf_read(tc, TX39_TIMERRTCLO_REG);
184 1.1 uch } while ((reghi != oreghi || reglo != oreglo) && (--i > 0));
185 1.1 uch if (i < 0) {
186 1.1 uch panic("RTC timer read error.\n");
187 1.1 uch }
188 1.1 uch /* XXX not coded yet */
189 1.1 uch }
190 1.1 uch
191 1.1 uch void
192 1.1 uch clock_set(dev, ct)
193 1.1 uch struct device *dev;
194 1.1 uch struct clocktime *ct;
195 1.1 uch {
196 1.1 uch /* XXX not coded yet */
197 1.1 uch }
198 1.1 uch
199 1.1 uch void
200 1.1 uch tx39clock_dump(tc)
201 1.1 uch tx_chipset_tag_t tc;
202 1.1 uch {
203 1.1 uch txreg_t reg;
204 1.1 uch
205 1.1 uch reg = tx_conf_read(tc, TX39_CLOCKCTRL_REG);
206 1.1 uch printf(" ");
207 1.1 uch ISSETPRINT(reg, CHIM);
208 1.1 uch #ifdef TX391X
209 1.1 uch ISSETPRINT(reg, VID);
210 1.1 uch ISSETPRINT(reg, MBUS);
211 1.1 uch #endif /* TX391X */
212 1.1 uch #ifdef TX392X
213 1.1 uch ISSETPRINT(reg, IRDA);
214 1.1 uch #endif /* TX392X */
215 1.1 uch ISSETPRINT(reg, SPI);
216 1.1 uch ISSETPRINT(reg, TIMER);
217 1.1 uch ISSETPRINT(reg, FASTTIMER);
218 1.1 uch #ifdef TX392X
219 1.1 uch ISSETPRINT(reg, C48MOUT);
220 1.1 uch #endif /* TX392X */
221 1.1 uch ISSETPRINT(reg, SIBM);
222 1.1 uch ISSETPRINT(reg, CSER);
223 1.1 uch ISSETPRINT(reg, IR);
224 1.1 uch ISSETPRINT(reg, UARTA);
225 1.1 uch ISSETPRINT(reg, UARTB);
226 1.1 uch printf("\n");
227 1.1 uch }
228 1.1 uch
229 1.1 uch
230 1.1 uch
231 1.1 uch
232