From 8dadd7448455b1784c435b71b705dd347ec16110 Mon Sep 17 00:00:00 2001 From: kettenis Date: Fri, 5 Aug 2016 21:29:23 +0000 Subject: [PATCH] Dynamically attach sxirtc(4); another board_id check bites the dust. --- sys/arch/armv7/conf/GENERIC | 4 ++-- sys/arch/armv7/conf/RAMDISK | 4 ++-- sys/arch/armv7/sunxi/files.sunxi | 4 ++-- sys/arch/armv7/sunxi/sxirtc.c | 33 ++++++++++++++++++++++++-------- 4 files changed, 31 insertions(+), 14 deletions(-) diff --git a/sys/arch/armv7/conf/GENERIC b/sys/arch/armv7/conf/GENERIC index dd03c1911ab..41ca54fbef0 100644 --- a/sys/arch/armv7/conf/GENERIC +++ b/sys/arch/armv7/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.34 2016/08/05 20:38:17 kettenis Exp $ +# $OpenBSD: GENERIC,v 1.35 2016/08/05 21:29:23 kettenis Exp $ # # For further information on compiling OpenBSD kernels, see the config(8) # man page. @@ -91,7 +91,7 @@ gpio* at sxipio? sxiccmu* at sunxi? # Clock Control Module/Unit sxitimer* at sunxi? sxidog* at sunxi? # watchdog timer -sxirtc* at sunxi? # Real Time Clock +sxirtc* at fdt? # Real Time Clock sxiuart* at fdt? # onboard UARTs sxie* at fdt? sxiahci* at fdt? # AHCI/SATA diff --git a/sys/arch/armv7/conf/RAMDISK b/sys/arch/armv7/conf/RAMDISK index f88d65bc7f9..a4a3cf8351f 100644 --- a/sys/arch/armv7/conf/RAMDISK +++ b/sys/arch/armv7/conf/RAMDISK @@ -1,4 +1,4 @@ -# $OpenBSD: RAMDISK,v 1.31 2016/08/05 20:38:17 kettenis Exp $ +# $OpenBSD: RAMDISK,v 1.32 2016/08/05 21:29:23 kettenis Exp $ machine armv7 arm @@ -90,7 +90,7 @@ gpio* at sxipio? sxiccmu* at sunxi? # Clock Control Module/Unit sxitimer* at sunxi? sxidog* at sunxi? # watchdog timer -sxirtc* at sunxi? # Real Time Clock +sxirtc* at fdt? # Real Time Clock sxiuart* at fdt? # onboard UARTs sxie* at fdt? sxiahci* at fdt? # AHCI/SATA diff --git a/sys/arch/armv7/sunxi/files.sunxi b/sys/arch/armv7/sunxi/files.sunxi index d18eec743f3..fc6417affcf 100644 --- a/sys/arch/armv7/sunxi/files.sunxi +++ b/sys/arch/armv7/sunxi/files.sunxi @@ -1,4 +1,4 @@ -# $OpenBSD: files.sunxi,v 1.8 2016/08/05 20:38:17 kettenis Exp $ +# $OpenBSD: files.sunxi,v 1.9 2016/08/05 21:29:23 kettenis Exp $ define sunxi {} device sunxi: sunxi @@ -29,7 +29,7 @@ attach sxidog at sunxi file arch/armv7/sunxi/sxidog.c sxidog device sxirtc -attach sxirtc at sunxi +attach sxirtc at fdt file arch/armv7/sunxi/sxirtc.c sxirtc device sxiahci: scsi, atascsi diff --git a/sys/arch/armv7/sunxi/sxirtc.c b/sys/arch/armv7/sunxi/sxirtc.c index a274b668b5b..0e0fe8dbe0e 100644 --- a/sys/arch/armv7/sunxi/sxirtc.c +++ b/sys/arch/armv7/sunxi/sxirtc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sxirtc.c,v 1.6 2016/02/01 23:36:57 jsg Exp $ */ +/* $OpenBSD: sxirtc.c,v 1.7 2016/08/05 21:29:23 kettenis Exp $ */ /* * Copyright (c) 2008 Mark Kettenis * Copyright (c) 2013 Artturi Alm @@ -24,10 +24,14 @@ #include #include +#include #include #include +#include +#include + #define SXIRTC_YYMMDD 0x04 #define SXIRTC_HHMMSS 0x08 @@ -48,10 +52,11 @@ struct sxirtc_softc { uint32_t leap_shift; }; +int sxirtc_match(struct device *, void *, void *); void sxirtc_attach(struct device *, struct device *, void *); struct cfattach sxirtc_ca = { - sizeof(struct device), NULL, sxirtc_attach + sizeof(struct device), sxirtc_match, sxirtc_attach }; struct cfdriver sxirtc_cd = { @@ -61,23 +66,35 @@ struct cfdriver sxirtc_cd = { int sxirtc_gettime(todr_chip_handle_t, struct timeval *); int sxirtc_settime(todr_chip_handle_t, struct timeval *); +int +sxirtc_match(struct device *parent, void *match, void *aux) +{ + struct fdt_attach_args *faa = aux; + + return (OF_is_compatible(faa->fa_node, "allwinner,sun4i-a10-rtc") || + OF_is_compatible(faa->fa_node, "allwinner,sun7i-a20-rtc")); +} + void -sxirtc_attach(struct device *parent, struct device *self, void *args) +sxirtc_attach(struct device *parent, struct device *self, void *aux) { struct sxirtc_softc *sc = (struct sxirtc_softc *)self; - struct armv7_attach_args *aa = args; + struct fdt_attach_args *faa = aux; todr_chip_handle_t handle; + if (faa->fa_nreg < 1) + return; + handle = malloc(sizeof(struct todr_chip_handle), M_DEVBUF, M_NOWAIT); if (handle == NULL) panic("sxirtc_attach: couldn't allocate todr_handle"); - sc->sc_iot = aa->aa_iot; - if (bus_space_map(sc->sc_iot, aa->aa_dev->mem[0].addr, - aa->aa_dev->mem[0].size, 0, &sc->sc_ioh)) + sc->sc_iot = faa->fa_iot; + if (bus_space_map(sc->sc_iot, faa->fa_reg[0].addr, + faa->fa_reg[0].size, 0, &sc->sc_ioh)) panic("sxirtc_attach: bus_space_map failed!"); - if (board_id == BOARD_ID_SUN7I_A20) { + if (OF_is_compatible(faa->fa_node, "allwinner,sun7i-a20-rtc")) { sc->base_year = 1970; sc->year_mask = 0xff; sc->leap_shift = 24; -- 2.20.1