summaryrefslogtreecommitdiff
path: root/sys/dev/i2c
diff options
context:
space:
mode:
authorjmcneill <jmcneill@NetBSD.org>2019-05-27 21:11:13 +0000
committerjmcneill <jmcneill@NetBSD.org>2019-05-27 21:11:13 +0000
commit5d409af357bb3f9c8ee9dc56d9c0f235544ec902 (patch)
tree0a7ee674bfdf0e8e7024b249b9a237b4240fe615 /sys/dev/i2c
parenta443938f6b96f27ae84968042c10b37902ee290d (diff)
FDT-ize AC100 driver
Diffstat (limited to 'sys/dev/i2c')
-rw-r--r--sys/dev/i2c/ac100.c33
1 files changed, 30 insertions, 3 deletions
diff --git a/sys/dev/i2c/ac100.c b/sys/dev/i2c/ac100.c
index f7280940dd4..6540273a7de 100644
--- a/sys/dev/i2c/ac100.c
+++ b/sys/dev/i2c/ac100.c
@@ -1,4 +1,4 @@
-/* $NetBSD: ac100.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $ */
+/* $NetBSD: ac100.c,v 1.3 2019/05/27 21:11:13 jmcneill Exp $ */
/*-
* Copyright (c) 2014 Jared D. McNeill <jmcneill@invisible.ca>
@@ -26,8 +26,10 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
+#include "opt_fdt.h"
+
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ac100.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ac100.c,v 1.3 2019/05/27 21:11:13 jmcneill Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -41,6 +43,10 @@ __KERNEL_RCSID(0, "$NetBSD: ac100.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $");
#include <dev/i2c/i2cvar.h>
+#ifdef FDT
+#include <dev/fdt/fdtvar.h>
+#endif
+
#define AC100_CHIP_AUDIO_RST_REG 0x00
#define AC100_PLL_CTRL1_REG 0x02
#define AC100_PLL_CTRL2_REG 0x03
@@ -86,6 +92,11 @@ __KERNEL_RCSID(0, "$NetBSD: ac100.c,v 1.2 2018/06/16 21:22:13 thorpej Exp $");
#define AC100_RTC_UPD_TRIG_WRITE __BIT(15)
+static const struct device_compatible_entry compat_data[] = {
+ { "x-powers,ac100", 0 },
+ { NULL, 0 }
+};
+
struct ac100_softc {
device_t sc_dev;
i2c_tag_t sc_i2c;
@@ -109,7 +120,15 @@ CFATTACH_DECL_NEW(ac100ic, sizeof(struct ac100_softc),
static int
ac100_match(device_t parent, cfdata_t match, void *aux)
{
- return I2C_MATCH_ADDRESS_ONLY; /* XXX */
+ struct i2c_attach_args *ia = aux;
+ int match_result;
+
+ if (iic_use_direct_match(ia, match, compat_data, &match_result))
+ return match_result;
+
+ /* This device is direct-config only. */
+
+ return 0;
}
static void
@@ -132,7 +151,15 @@ ac100_attach(device_t parent, device_t self, void *aux)
sc->sc_todr.todr_gettime_ymdhms = ac100_rtc_gettime;
sc->sc_todr.todr_settime_ymdhms = ac100_rtc_settime;
sc->sc_todr.cookie = sc;
+
+#ifdef FDT
+ const int phandle = ia->ia_cookie;
+ const int rtc_phandle = of_find_firstchild_byname(phandle, "rtc");
+ if (rtc_phandle > 0)
+ fdtbus_todr_attach(self, rtc_phandle, &sc->sc_todr);
+#else
todr_attach(&sc->sc_todr);
+#endif
}
static int