Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch sunxi_twi: provide custom read/write reg callbacks ...



details:   https://anonhg.NetBSD.org/src/rev/06af6a1667a6
branches:  trunk
changeset: 827471:06af6a1667a6
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sun Oct 29 15:00:00 2017 +0000

description:
sunxi_twi: provide custom read/write reg callbacks and remove the
GTTWSI_ALLWINNER option from the kernel config

diffstat:

 sys/arch/arm/sunxi/sunxi_twi.c |  35 +++++++++++++++++++++++++++++++++--
 sys/arch/evbarm/conf/SUNXI     |   3 +--
 2 files changed, 34 insertions(+), 4 deletions(-)

diffs (97 lines):

diff -r 166a250d7933 -r 06af6a1667a6 sys/arch/arm/sunxi/sunxi_twi.c
--- a/sys/arch/arm/sunxi/sunxi_twi.c    Sun Oct 29 14:59:05 2017 +0000
+++ b/sys/arch/arm/sunxi/sunxi_twi.c    Sun Oct 29 15:00:00 2017 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_twi.c,v 1.5 2017/10/07 20:17:38 jmcneill Exp $ */
+/* $NetBSD: sunxi_twi.c,v 1.6 2017/10/29 15:00:00 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2017 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -26,9 +26,14 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
+#include "opt_gttwsi.h"
+#ifdef GTTWSI_ALLWINNER
+# error Do not define GTTWSI_ALLWINNER when using this driver
+#endif
+
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: sunxi_twi.c,v 1.5 2017/10/07 20:17:38 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_twi.c,v 1.6 2017/10/29 15:00:00 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/bus.h>
@@ -39,6 +44,7 @@
 
 #include <dev/i2c/i2cvar.h>
 #include <dev/i2c/gttwsivar.h>
+#include <dev/i2c/gttwsireg.h>
 
 #include <dev/fdt/fdtvar.h>
 
@@ -46,6 +52,16 @@
 #define         TWI_CCR_CLK_M  __BITS(6,3)
 #define         TWI_CCR_CLK_N  __BITS(2,0)
 
+static uint8_t sunxi_twi_regmap[] = {
+       [TWSI_SLAVEADDR]        = 0x00,
+       [TWSI_EXTEND_SLAVEADDR] = 0x04,
+       [TWSI_DATA]             = 0x08,
+       [TWSI_CONTROL]          = 0x0c,
+       [TWSI_STATUS]           = 0x10,
+       [TWSI_BAUDRATE]         = 0x14,
+       [TWSI_SOFTRESET]        = 0x18,
+};
+
 static int sunxi_twi_match(device_t, cfdata_t, void *);
 static void sunxi_twi_attach(device_t, device_t, void *);
 
@@ -82,6 +98,18 @@
        .get_tag = sunxi_twi_get_tag,
 };
 
+static uint32_t
+sunxi_twi_reg_read(struct gttwsi_softc *sc, uint32_t reg)
+{
+       return bus_space_read_4(sc->sc_bust, sc->sc_bush, sunxi_twi_regmap[reg]);
+}
+
+static void
+sunxi_twi_reg_write(struct gttwsi_softc *sc, uint32_t reg, uint32_t val)
+{
+       bus_space_write_4(sc->sc_bust, sc->sc_bush, sunxi_twi_regmap[reg], val);
+}
+
 static int
 sunxi_twi_match(device_t parent, cfdata_t cf, void *aux)
 {
@@ -149,6 +177,9 @@
                             __SHIFTIN(m, TWI_CCR_CLK_M); 
        bus_space_write_4(bst, bsh, TWI_CCR_REG, ccr);
 
+       sc->sc_reg_read = sunxi_twi_reg_read;
+       sc->sc_reg_write = sunxi_twi_reg_write;
+
        gttwsi_attach_subr(self, bst, bsh);
 
        ih = fdtbus_intr_establish(phandle, 0, IPL_VM, 0, gttwsi_intr, sc);
diff -r 166a250d7933 -r 06af6a1667a6 sys/arch/evbarm/conf/SUNXI
--- a/sys/arch/evbarm/conf/SUNXI        Sun Oct 29 14:59:05 2017 +0000
+++ b/sys/arch/evbarm/conf/SUNXI        Sun Oct 29 15:00:00 2017 +0000
@@ -1,5 +1,5 @@
 #
-#      $NetBSD: SUNXI,v 1.48 2017/10/29 14:07:11 jmcneill Exp $
+#      $NetBSD: SUNXI,v 1.49 2017/10/29 15:00:00 jmcneill Exp $
 #
 #      Allwinner sunxi family
 #
@@ -170,7 +170,6 @@
 
 # I2C
 sunxitwi*      at fdt?                 # TWI
-options        GTTWSI_ALLWINNER        # XXX this should be a driver flag
 sunxirsb*      at fdt?                 # P2WI/RSB
 iic*           at i2cbus?
 tcakp*         at iic?                 # TI TCA8418 Keypad Scan IC



Home | Main Index | Thread Index | Old Index