Deleted Added
full compact
s35390a.c (330897) s35390a.c (331503)
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD AND BSD-2-Clause-NetBSD
3 *
4 * Copyright (c) 2012 Yusuke Tanaka
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

--- 41 unchanged lines hidden (view full) ---

50 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54 * POSSIBILITY OF SUCH DAMAGE.
55 */
56
57#include <sys/cdefs.h>
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD AND BSD-2-Clause-NetBSD
3 *
4 * Copyright (c) 2012 Yusuke Tanaka
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

--- 41 unchanged lines hidden (view full) ---

50 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
51 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
52 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
53 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
54 * POSSIBILITY OF SUCH DAMAGE.
55 */
56
57#include <sys/cdefs.h>
58__FBSDID("$FreeBSD: stable/11/sys/dev/iicbus/s35390a.c 330897 2018-03-14 03:19:51Z eadler $");
58__FBSDID("$FreeBSD: stable/11/sys/dev/iicbus/s35390a.c 331503 2018-03-24 23:01:10Z ian $");
59
60/*
61 * Driver for Seiko Instruments S-35390A Real-time Clock
62 */
63
64#include "opt_platform.h"
65
66#include <sys/param.h>

--- 225 unchanged lines hidden (view full) ---

292 clock_unregister(dev);
293 return (0);
294}
295
296static int
297s390rtc_gettime(device_t dev, struct timespec *ts)
298{
299 uint8_t bcd[S390_RT1_NBYTES];
59
60/*
61 * Driver for Seiko Instruments S-35390A Real-time Clock
62 */
63
64#include "opt_platform.h"
65
66#include <sys/param.h>

--- 225 unchanged lines hidden (view full) ---

292 clock_unregister(dev);
293 return (0);
294}
295
296static int
297s390rtc_gettime(device_t dev, struct timespec *ts)
298{
299 uint8_t bcd[S390_RT1_NBYTES];
300 struct clocktime ct;
300 struct bcd_clocktime bct;
301 int error;
302
303 error = s390rtc_read(dev, S390_REALTIME1, bcd, S390_RT1_NBYTES);
304 if (error) {
305 device_printf(dev, "%s: cannot read realtime1 register\n",
306 __func__);
307 return (error);
308 }
309
310 /*
311 * Convert the register values into something useable.
312 */
301 int error;
302
303 error = s390rtc_read(dev, S390_REALTIME1, bcd, S390_RT1_NBYTES);
304 if (error) {
305 device_printf(dev, "%s: cannot read realtime1 register\n",
306 __func__);
307 return (error);
308 }
309
310 /*
311 * Convert the register values into something useable.
312 */
313 ct.nsec = 0;
314 ct.sec = FROMBCD(bcd[S390_RT1_SECOND]);
315 ct.min = FROMBCD(bcd[S390_RT1_MINUTE]);
316 ct.hour = FROMBCD(bcd[S390_RT1_HOUR] & 0x3f);
317 ct.day = FROMBCD(bcd[S390_RT1_DAY]);
318 ct.dow = bcd[S390_RT1_WDAY] & 0x07;
319 ct.mon = FROMBCD(bcd[S390_RT1_MONTH]);
320 ct.year = FROMBCD(bcd[S390_RT1_YEAR]) + 2000;
313 bct.nsec = 0;
314 bct.sec = bcd[S390_RT1_SECOND];
315 bct.min = bcd[S390_RT1_MINUTE];
316 bct.hour = bcd[S390_RT1_HOUR] & 0x3f;
317 bct.day = bcd[S390_RT1_DAY];
318 bct.dow = bcd[S390_RT1_WDAY] & 0x07;
319 bct.mon = bcd[S390_RT1_MONTH];
320 bct.year = bcd[S390_RT1_YEAR];
321
321
322 return (clock_ct_to_ts(&ct, ts));
322 clock_dbgprint_bcd(dev, CLOCK_DBG_READ, &bct);
323 return (clock_bcd_to_ts(&bct, ts, false));
323}
324
325static int
326s390rtc_settime(device_t dev, struct timespec *ts)
327{
328 uint8_t bcd[S390_RT1_NBYTES];
324}
325
326static int
327s390rtc_settime(device_t dev, struct timespec *ts)
328{
329 uint8_t bcd[S390_RT1_NBYTES];
329 struct clocktime ct;
330 struct bcd_clocktime bct;
330
331
331 clock_ts_to_ct(ts, &ct);
332 clock_ts_to_bcd(ts, &bct, false);
333 clock_dbgprint_bcd(dev, CLOCK_DBG_WRITE, &bct);
332
333 /*
334 * Convert our time representation into something the S-xx390
335 * can understand.
336 */
334
335 /*
336 * Convert our time representation into something the S-xx390
337 * can understand.
338 */
337 bcd[S390_RT1_SECOND] = TOBCD(ct.sec);
338 bcd[S390_RT1_MINUTE] = TOBCD(ct.min);
339 bcd[S390_RT1_HOUR] = TOBCD(ct.hour);
340 bcd[S390_RT1_DAY] = TOBCD(ct.day);
341 bcd[S390_RT1_WDAY] = ct.dow;
342 bcd[S390_RT1_MONTH] = TOBCD(ct.mon);
343 bcd[S390_RT1_YEAR] = TOBCD(ct.year % 100);
339 bcd[S390_RT1_SECOND] = bct.sec;
340 bcd[S390_RT1_MINUTE] = bct.min;
341 bcd[S390_RT1_HOUR] = bct.hour;
342 bcd[S390_RT1_DAY] = bct.day;
343 bcd[S390_RT1_WDAY] = bct.dow;
344 bcd[S390_RT1_MONTH] = bct.mon;
345 bcd[S390_RT1_YEAR] = bct.year & 0xff;
344
345 return (s390rtc_write(dev, S390_REALTIME1, bcd, S390_RT1_NBYTES));
346}
347
348static device_method_t s390rtc_methods[] = {
349 DEVMETHOD(device_probe, s390rtc_probe),
350 DEVMETHOD(device_attach, s390rtc_attach),
351 DEVMETHOD(device_detach, s390rtc_detach),

--- 17 unchanged lines hidden ---
346
347 return (s390rtc_write(dev, S390_REALTIME1, bcd, S390_RT1_NBYTES));
348}
349
350static device_method_t s390rtc_methods[] = {
351 DEVMETHOD(device_probe, s390rtc_probe),
352 DEVMETHOD(device_attach, s390rtc_attach),
353 DEVMETHOD(device_detach, s390rtc_detach),

--- 17 unchanged lines hidden ---