/*-1* SPDX-License-Identifier: BSD-2-Clause2*3* Copyright (C) 2006-2008 Semihalf, Grzegorz Bernacki4* All rights reserved.5*6* Redistribution and use in source and binary forms, with or without7* modification, are permitted provided that the following conditions8* are met:9* 1. Redistributions of source code must retain the above copyright10* notice, this list of conditions and the following disclaimer.11* 2. Redistributions in binary form must reproduce the above copyright12* notice, this list of conditions and the following disclaimer in the13* documentation and/or other materials provided with the distribution.14*15* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND16* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE17* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE18* ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE19* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL20* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS21* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)22* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT23* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY24* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF25* SUCH DAMAGE.26*/2728#ifndef _DEV_RTC_DS1553_H_29#define _DEV_RTC_DS1553_H_3031/* DS1553 registers */32#define DS1553_NVRAM_SIZE 0x1ff033#define DS1553_OFF_FLAGS 0x1ff034#define DS1553_OFF_ALARM_SECONDS 0x1ff235#define DS1553_OFF_ALARM_MINUTES 0x1ff336#define DS1553_OFF_ALARM_HOURS 0x1ff437#define DS1553_OFF_ALARM_DATE 0x1ff538#define DS1553_OFF_INTERRUPTS 0x1ff639#define DS1553_OFF_WATCHDOG 0x1ff740#define DS1553_OFF_CONTROL 0x1ff841#define DS1553_OFF_SECONDS 0x1ff942#define DS1553_OFF_MINUTES 0x1ffa43#define DS1553_OFF_HOURS 0x1ffb44#define DS1553_OFF_DAYOFWEEK 0x1ffc45#define DS1553_OFF_DATE 0x1ffd46#define DS1553_OFF_MONTH 0x1ffe47#define DS1553_OFF_YEAR 0x1fff4849/* dayofweek register's bits */50#define DS1553_BIT_FREQ_TEST 0x40 /* frequency test bit */5152/* seconds register's bit */53#define DS1553_BIT_OSC 0x80 /* oscillator start/stop bit */5455/* control register's bits */56#define DS1553_BIT_WRITE 0x80 /* write */57#define DS1553_BIT_READ 0x40 /* read */5859/* watchdog register's bits */60#define DS1553_BIT_WATCHDOG 0x80 /* watchdog steering bit */61#define DS1553_BIT_BMB4 0x40 /* watchdog multiplier bit4 */62#define DS1553_BIT_BMB3 0x20 /* watchdog multiplier bit3 */63#define DS1553_BIT_BMB2 0x10 /* watchdog multiplier bit2 */64#define DS1553_BIT_BMB1 0x8 /* watchdog multiplier bit1 */65#define DS1553_BIT_BMB0 0x4 /* watchdog multiplier bit0 */66#define DS1553_BIT_RB1 0x2 /* watchdog resolution bit1 */67#define DS1553_BIT_RB0 0x1 /* watchdog resolution bit0 */6869/* alarm seconds/minutes/hours/date register's bit */70#define DS1553_BIT_AM 0x80 /* alarm mask bit */7172/* flag register's bits */73#define DS1553_BIT_BLF 0x10 /* battery flag */74#define DS1553_BIT_WF 0x80 /* watchdog flag */7576/* register's mask */77#define DS1553_MASK_MONTH 0x1f78#define DS1553_MASK_DATE 0x3f79#define DS1553_MASK_DAYOFWEEK 0x780#define DS1553_MASK_HOUR 0x3f81#define DS1553_MASK_MINUTES 0x7f82#define DS1553_MASK_SECONDS 0x7f8384struct ds1553_softc {85bus_space_tag_t sc_bst; /* bus space tag */86bus_space_handle_t sc_bsh; /* bus space handle */8788int rid; /* resource id */89struct resource *res;90struct mtx sc_mtx; /* hardware mutex */9192uint32_t year_offset;93/* read/write functions */94uint8_t (*sc_read)(device_t, bus_size_t);95void (*sc_write)(device_t, bus_size_t, uint8_t);96};9798/* device interface */99int ds1553_attach(device_t);100101/* clock interface */102int ds1553_gettime(device_t, struct timespec *);103int ds1553_settime(device_t, struct timespec *);104105#endif /* _DEV_RTC_DS1553_H_ */106107108