No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / landisk / dev / rs5c313_landisk.c
blobdd99d88ec7f66c4119dc65be77cb0dd56dc47d38
1 /* $NetBSD: rs5c313_landisk.c,v 1.3 2008/03/27 02:15:29 uwe Exp $ */
3 /*-
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: rs5c313_landisk.c,v 1.3 2008/03/27 02:15:29 uwe Exp $");
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/device.h>
35 #include <sys/kernel.h>
37 #include <dev/clock_subr.h>
38 #include <dev/ic/rs5c313var.h>
40 #include <sh3/devreg.h>
41 #include <sh3/scireg.h>
43 #include <landisk/landisk/landiskreg.h>
46 /* autoconf glue */
47 static int rs5c313_landisk_match(device_t, cfdata_t, void *);
48 static void rs5c313_landisk_attach(device_t, device_t, void *);
50 CFATTACH_DECL_NEW(rs5c313_landisk, sizeof(struct rs5c313_softc),
51 rs5c313_landisk_match, rs5c313_landisk_attach, NULL, NULL);
54 /* chip access methods */
55 static void rtc_begin(struct rs5c313_softc *);
56 static void rtc_ce(struct rs5c313_softc *, int);
57 static void rtc_dir(struct rs5c313_softc *, int);
58 static void rtc_clk(struct rs5c313_softc *, int);
59 static int rtc_read(struct rs5c313_softc *);
60 static void rtc_write(struct rs5c313_softc *, int);
62 static struct rs5c313_ops rs5c313_landisk_ops = {
63 .rs5c313_op_begin = rtc_begin,
64 .rs5c313_op_ce = rtc_ce,
65 .rs5c313_op_clk = rtc_clk,
66 .rs5c313_op_dir = rtc_dir,
67 .rs5c313_op_read = rtc_read,
68 .rs5c313_op_write = rtc_write,
71 #define ndelay(x) delay(x)
75 static int
76 rs5c313_landisk_match(device_t parent, cfdata_t cf, void *aux)
78 static int matched = 0;
80 if (matched)
81 return 0;
83 matched = 1;
84 return 1;
88 static void
89 rs5c313_landisk_attach(device_t parent, device_t self, void *aux)
91 struct rs5c313_softc *sc = device_private(self);
93 sc->sc_dev = self;
94 sc->sc_ops = &rs5c313_landisk_ops;
95 rs5c313_attach(sc);
99 static void
100 rtc_begin(struct rs5c313_softc *sc)
103 SHREG_SCSPTR = SCSPTR_SPB1IO | SCSPTR_SPB1DT
104 | SCSPTR_SPB0IO | SCSPTR_SPB0DT;
105 ndelay(100);
110 * CE pin
112 static void
113 rtc_ce(struct rs5c313_softc *sc, int onoff)
116 if (onoff)
117 _reg_write_1(LANDISK_PWRMNG, PWRMNG_RTC_CE);
118 else
119 _reg_write_1(LANDISK_PWRMNG, 0);
120 ndelay(600);
125 * SCLK pin is connnected to SPB0DT.
126 * SPB0DT is always in output mode, we set SPB0IO in rtc_begin.
128 static void
129 rtc_clk(struct rs5c313_softc *sc, int onoff)
131 uint8_t r = SHREG_SCSPTR;
133 if (onoff)
134 r |= SCSPTR_SPB0DT;
135 else
136 r &= ~SCSPTR_SPB0DT;
137 SHREG_SCSPTR = r;
142 * SIO pin is connected to SPB1DT.
143 * SPB1DT is output when SPB1IO is set.
145 static void
146 rtc_dir(struct rs5c313_softc *sc, int output)
148 uint8_t r = SHREG_SCSPTR;
150 if (output)
151 r |= SCSPTR_SPB1IO;
152 else
153 r &= ~SCSPTR_SPB1IO;
154 SHREG_SCSPTR = r;
159 * Read bit from SPB1DT pin.
161 static int
162 rtc_read(struct rs5c313_softc *sc)
164 int bit;
166 ndelay(300);
168 bit = (SHREG_SCSPTR & SCSPTR_SPB1DT) ? 1 : 0;
170 rtc_clk(sc, 0);
171 ndelay(300);
172 rtc_clk(sc, 1);
174 return bit;
179 * Write bit via SPB1DT pin.
181 static void
182 rtc_write(struct rs5c313_softc *sc, int bit)
184 uint8_t r = SHREG_SCSPTR;
186 if (bit)
187 r |= SCSPTR_SPB1DT;
188 else
189 r &= ~SCSPTR_SPB1DT;
190 SHREG_SCSPTR = r;
192 ndelay(300);
194 rtc_clk(sc, 0);
195 ndelay(300);
196 rtc_clk(sc, 1);