From 6a05f063ed52ea26ce95114acfb4129df3487cb9 Mon Sep 17 00:00:00 2001 From: Jared McNeill Date: Wed, 6 Apr 2016 23:11:03 +0000 Subject: Convert Allwinner port to extres clk/hwreset/regulator APIs. Reviewed by: andrew, gonzo, Emmanuel Vadot Approved by: gonzo (mentor) Differential Revision: https://reviews.freebsd.org/D5752 --- sys/dev/iicbus/twsi/a10_twsi.c | 51 ++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 27 deletions(-) (limited to 'sys/dev/iicbus/twsi') diff --git a/sys/dev/iicbus/twsi/a10_twsi.c b/sys/dev/iicbus/twsi/a10_twsi.c index 6ee13ad59fe5..701153b1d438 100644 --- a/sys/dev/iicbus/twsi/a10_twsi.c +++ b/sys/dev/iicbus/twsi/a10_twsi.c @@ -48,8 +48,8 @@ __FBSDID("$FreeBSD$"); #include #include -#include -#include +#include +#include #include "iicbus_if.h" @@ -63,21 +63,16 @@ __FBSDID("$FreeBSD$"); #define TWI_EFR 0x1C #define TWI_LCR 0x20 -#define A10_I2C 1 -#define A31_I2C 2 - static struct ofw_compat_data compat_data[] = { - {"allwinner,sun4i-a10-i2c", A10_I2C}, - {"allwinner,sun6i-a31-i2c", A31_I2C}, + {"allwinner,sun4i-a10-i2c", 1}, + {"allwinner,sun6i-a31-i2c", 1}, {NULL, 0}, }; static int a10_twsi_probe(device_t dev) { - struct twsi_softc *sc; - sc = device_get_softc(dev); if (!ofw_bus_status_okay(dev)) return (ENXIO); @@ -92,29 +87,31 @@ static int a10_twsi_attach(device_t dev) { struct twsi_softc *sc; - int clk; + clk_t clk; + hwreset_t rst; + int error; sc = device_get_softc(dev); - /* Activate clock */ - switch (ofw_bus_search_compatible(dev, compat_data)->ocd_data) { -#if defined(SOC_ALLWINNER_A10) || defined(SOC_ALLWINNER_A20) - case A10_I2C: - clk = a10_clk_i2c_activate(device_get_unit(dev)); - break; -#endif -#if defined(SOC_ALLWINNER_A31) || defined(SOC_ALLWINNER_A31S) - case A31_I2C: - clk = a31_clk_i2c_activate(device_get_unit(dev)); - break; -#endif - default: - clk = -1; + /* De-assert reset */ + if (hwreset_get_by_ofw_idx(dev, 0, &rst) == 0) { + error = hwreset_deassert(rst); + if (error != 0) { + device_printf(dev, "could not de-assert reset\n"); + return (error); + } } - if (clk != 0) { - device_printf(dev, "could not activate i2c clock\n"); - return (ENXIO); + /* Activate clock */ + error = clk_get_by_ofw_index(dev, 0, &clk); + if (error != 0) { + device_printf(dev, "could not find clock\n"); + return (error); + } + error = clk_enable(clk); + if (error != 0) { + device_printf(dev, "could not enable clock\n"); + return (error); } sc->reg_data = TWI_DATA; -- cgit v1.2.3