1 /* $NetBSD: rs5c313_landisk.c,v 1.3 2008/03/27 02:15:29 uwe Exp $ */
4 * Copyright (c) 2002 The NetBSD Foundation, Inc.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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>
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)
76 rs5c313_landisk_match(device_t parent
, cfdata_t cf
, void *aux
)
78 static int matched
= 0;
89 rs5c313_landisk_attach(device_t parent
, device_t self
, void *aux
)
91 struct rs5c313_softc
*sc
= device_private(self
);
94 sc
->sc_ops
= &rs5c313_landisk_ops
;
100 rtc_begin(struct rs5c313_softc
*sc
)
103 SHREG_SCSPTR
= SCSPTR_SPB1IO
| SCSPTR_SPB1DT
104 | SCSPTR_SPB0IO
| SCSPTR_SPB0DT
;
113 rtc_ce(struct rs5c313_softc
*sc
, int onoff
)
117 _reg_write_1(LANDISK_PWRMNG
, PWRMNG_RTC_CE
);
119 _reg_write_1(LANDISK_PWRMNG
, 0);
125 * SCLK pin is connnected to SPB0DT.
126 * SPB0DT is always in output mode, we set SPB0IO in rtc_begin.
129 rtc_clk(struct rs5c313_softc
*sc
, int onoff
)
131 uint8_t r
= SHREG_SCSPTR
;
142 * SIO pin is connected to SPB1DT.
143 * SPB1DT is output when SPB1IO is set.
146 rtc_dir(struct rs5c313_softc
*sc
, int output
)
148 uint8_t r
= SHREG_SCSPTR
;
159 * Read bit from SPB1DT pin.
162 rtc_read(struct rs5c313_softc
*sc
)
168 bit
= (SHREG_SCSPTR
& SCSPTR_SPB1DT
) ? 1 : 0;
179 * Write bit via SPB1DT pin.
182 rtc_write(struct rs5c313_softc
*sc
, int bit
)
184 uint8_t r
= SHREG_SCSPTR
;