xref: /freebsd/sys/powerpc/mpc85xx/ds1553_reg.h (revision e32fecd0c2c3ee37c47ee100f169e7eb0282a873)
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (C) 2006-2008 Semihalf, Grzegorz Bernacki
5  * All rights reserved.
6  *
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.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE.
27  *
28  * $FreeBSD$
29  */
30 
31 #ifndef _DEV_RTC_DS1553_H_
32 #define _DEV_RTC_DS1553_H_
33 
34 /* DS1553 registers */
35 #define DS1553_NVRAM_SIZE		0x1ff0
36 #define DS1553_OFF_FLAGS		0x1ff0
37 #define DS1553_OFF_ALARM_SECONDS	0x1ff2
38 #define DS1553_OFF_ALARM_MINUTES	0x1ff3
39 #define DS1553_OFF_ALARM_HOURS		0x1ff4
40 #define DS1553_OFF_ALARM_DATE		0x1ff5
41 #define DS1553_OFF_INTERRUPTS		0x1ff6
42 #define DS1553_OFF_WATCHDOG		0x1ff7
43 #define DS1553_OFF_CONTROL		0x1ff8
44 #define DS1553_OFF_SECONDS		0x1ff9
45 #define DS1553_OFF_MINUTES		0x1ffa
46 #define DS1553_OFF_HOURS		0x1ffb
47 #define DS1553_OFF_DAYOFWEEK		0x1ffc
48 #define DS1553_OFF_DATE			0x1ffd
49 #define DS1553_OFF_MONTH		0x1ffe
50 #define DS1553_OFF_YEAR			0x1fff
51 
52 /* dayofweek register's bits */
53 #define DS1553_BIT_FREQ_TEST		0x40 /* frequency test bit */
54 
55 /* seconds register's bit */
56 #define DS1553_BIT_OSC			0x80 /* oscillator start/stop bit */
57 
58 /* control register's bits */
59 #define DS1553_BIT_WRITE		0x80 /* write */
60 #define DS1553_BIT_READ			0x40 /* read */
61 
62 /* watchdog register's bits */
63 #define DS1553_BIT_WATCHDOG		0x80 /* watchdog steering bit */
64 #define DS1553_BIT_BMB4			0x40 /* watchdog multiplier bit4 */
65 #define DS1553_BIT_BMB3			0x20 /* watchdog multiplier bit3 */
66 #define DS1553_BIT_BMB2			0x10 /* watchdog multiplier bit2 */
67 #define DS1553_BIT_BMB1			0x8  /* watchdog multiplier bit1 */
68 #define DS1553_BIT_BMB0			0x4  /* watchdog multiplier bit0 */
69 #define DS1553_BIT_RB1			0x2  /* watchdog resolution bit1 */
70 #define DS1553_BIT_RB0			0x1  /* watchdog resolution bit0 */
71 
72 /* alarm seconds/minutes/hours/date register's bit */
73 #define DS1553_BIT_AM			0x80 /* alarm mask bit */
74 
75 /* flag register's bits */
76 #define DS1553_BIT_BLF			0x10 /* battery flag */
77 #define DS1553_BIT_WF			0x80 /* watchdog flag */
78 
79 /* register's mask */
80 #define DS1553_MASK_MONTH		0x1f
81 #define DS1553_MASK_DATE		0x3f
82 #define DS1553_MASK_DAYOFWEEK		0x7
83 #define DS1553_MASK_HOUR		0x3f
84 #define DS1553_MASK_MINUTES		0x7f
85 #define DS1553_MASK_SECONDS		0x7f
86 
87 struct ds1553_softc {
88 	bus_space_tag_t		sc_bst;	/* bus space tag */
89 	bus_space_handle_t	sc_bsh;	/* bus space handle */
90 
91 	int			rid;	/* resource id */
92 	struct resource		*res;
93 	struct mtx		sc_mtx;	/* hardware mutex */
94 
95 	uint32_t		year_offset;
96 	/* read/write functions */
97 	uint8_t			(*sc_read)(device_t, bus_size_t);
98 	void			(*sc_write)(device_t, bus_size_t, uint8_t);
99 };
100 
101 /* device interface */
102 int ds1553_attach(device_t);
103 
104 /* clock interface */
105 int ds1553_gettime(device_t, struct timespec *);
106 int ds1553_settime(device_t, struct timespec *);
107 
108 #endif /* _DEV_RTC_DS1553_H_ */
109