Module Name: src
Committed By: thorpej
Date: Sun Jan 12 17:48:42 UTC 2020
Modified Files:
src/sys/arch/arm/sunxi: sunxi_twi.c
src/sys/dev/i2c: files.i2c gttwsi_core.c gttwsireg.h gttwsivar.h
src/sys/dev/marvell: gttwsi.c
Log Message:
Clean up gttwsi's register access stuff:
- Garbage-collect the obsolete GTTWSI_ALLWINNER option; it hasn't been
needed since FDT'ization of the Allwinner support code.
- Redefine thw "TWSI_*" register definitions to clearly call out:
-> The Marvell flavor of the offsets
-> The Allwinner flavor of the offsets
...and make the regular definitions indices into a register map.
- Pass the appropriate register map from the front-end to the core.
- Remove the customer register read/write callbacks -- they are no longer
needed now that each front-end passes an appropriate register map to
the core.
To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/sys/arch/arm/sunxi/sunxi_twi.c
cvs rdiff -u -r1.107 -r1.108 src/sys/dev/i2c/files.i2c
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/i2c/gttwsi_core.c
cvs rdiff -u -r1.3 -r1.4 src/sys/dev/i2c/gttwsireg.h
cvs rdiff -u -r1.5 -r1.6 src/sys/dev/i2c/gttwsivar.h
cvs rdiff -u -r1.11 -r1.12 src/sys/dev/marvell/gttwsi.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/arch/arm/sunxi/sunxi_twi.c
diff -u src/sys/arch/arm/sunxi/sunxi_twi.c:1.10 src/sys/arch/arm/sunxi/sunxi_twi.c:1.11
--- src/sys/arch/arm/sunxi/sunxi_twi.c:1.10 Sun Jul 1 21:16:19 2018
+++ src/sys/arch/arm/sunxi/sunxi_twi.c Sun Jan 12 17:48:42 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: sunxi_twi.c,v 1.10 2018/07/01 21:16:19 jmcneill Exp $ */
+/* $NetBSD: sunxi_twi.c,v 1.11 2020/01/12 17:48:42 thorpej Exp $ */
/*-
* Copyright (c) 2017 Jared McNeill <[email protected]>
@@ -26,14 +26,9 @@
* 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.10 2018/07/01 21:16:19 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sunxi_twi.c,v 1.11 2020/01/12 17:48:42 thorpej Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -52,22 +47,14 @@ __KERNEL_RCSID(0, "$NetBSD: sunxi_twi.c,
#define TWI_CCR_CLK_M __BITS(6,3)
#define TWI_CCR_CLK_N __BITS(2,0)
-static uint8_t sunxi_twi_regmap_rd[] = {
- [TWSI_SLAVEADDR/4] = 0x00,
- [TWSI_EXTEND_SLAVEADDR/4] = 0x04,
- [TWSI_DATA/4] = 0x08,
- [TWSI_CONTROL/4] = 0x0c,
- [TWSI_STATUS/4] = 0x10,
- [TWSI_SOFTRESET/4] = 0x18,
-};
-
-static uint8_t sunxi_twi_regmap_wr[] = {
- [TWSI_SLAVEADDR/4] = 0x00,
- [TWSI_EXTEND_SLAVEADDR/4] = 0x04,
- [TWSI_DATA/4] = 0x08,
- [TWSI_CONTROL/4] = 0x0c,
- [TWSI_BAUDRATE/4] = 0x14,
- [TWSI_SOFTRESET/4] = 0x18,
+static const bus_size_t sunxi_twi_regmap[] = {
+ [TWSI_SLAVEADDR] = TWSI_ALLWINNER_SLAVEADDR,
+ [TWSI_EXTEND_SLAVEADDR] = TWSI_ALLWINNER_EXTEND_SLAVEADDR,
+ [TWSI_DATA] = TWSI_ALLWINNER_DATA,
+ [TWSI_CONTROL] = TWSI_ALLWINNER_CONTROL,
+ [TWSI_STATUS] = TWSI_ALLWINNER_STATUS,
+ [TWSI_BAUDRATE] = TWSI_ALLWINNER_BAUDRATE,
+ [TWSI_SOFTRESET] = TWSI_ALLWINNER_SOFTRESET,
};
static int sunxi_twi_match(device_t, cfdata_t, void *);
@@ -106,18 +93,6 @@ const struct fdtbus_i2c_controller_func
.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_rd[reg/4]);
-}
-
-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_wr[reg/4], val);
-}
-
static u_int
sunxi_twi_calc_rate(u_int parent_rate, u_int n, u_int m)
{
@@ -130,11 +105,12 @@ sunxi_twi_set_clock(struct gttwsi_softc
uint32_t baud;
u_int n, m, best_rate;
- baud = sunxi_twi_reg_read(sc, TWSI_BAUDRATE);
+ baud = gttwsi_read_4(sc, TWSI_BAUDRATE);
for (best_rate = 0, n = 0; n < 8; n++) {
for (m = 0; m < 16; m++) {
- const u_int tmp_rate = sunxi_twi_calc_rate(parent_rate, n, m);
+ const u_int tmp_rate =
+ sunxi_twi_calc_rate(parent_rate, n, m);
if (tmp_rate <= rate && tmp_rate > best_rate) {
best_rate = tmp_rate;
baud = __SHIFTIN(n, TWI_CCR_CLK_N) |
@@ -143,7 +119,7 @@ sunxi_twi_set_clock(struct gttwsi_softc
}
}
- sunxi_twi_reg_write(sc, TWSI_BAUDRATE, baud);
+ gttwsi_write_4(sc, TWSI_BAUDRATE, baud);
delay(10000);
}
@@ -202,9 +178,7 @@ sunxi_twi_attach(device_t parent, device
conf->iflg_rwc);
/* Attach gttwsi core */
- sc->sc_reg_read = sunxi_twi_reg_read;
- sc->sc_reg_write = sunxi_twi_reg_write;
- gttwsi_attach_subr(self, bst, bsh);
+ gttwsi_attach_subr(self, bst, bsh, sunxi_twi_regmap);
/*
* Set clock rate to 100kHz.
Index: src/sys/dev/i2c/files.i2c
diff -u src/sys/dev/i2c/files.i2c:1.107 src/sys/dev/i2c/files.i2c:1.108
--- src/sys/dev/i2c/files.i2c:1.107 Fri Jan 3 18:00:05 2020
+++ src/sys/dev/i2c/files.i2c Sun Jan 12 17:48:42 2020
@@ -1,4 +1,4 @@
-# $NetBSD: files.i2c,v 1.107 2020/01/03 18:00:05 jmcneill Exp $
+# $NetBSD: files.i2c,v 1.108 2020/01/12 17:48:42 thorpej Exp $
obsolete defflag opt_i2cbus.h I2C_SCAN
define i2cbus { }
@@ -55,7 +55,6 @@ define motoi2c
file dev/i2c/motoi2c.c motoi2c
define mvi2c
file dev/i2c/gttwsi_core.c mvi2c
-defflag opt_gttwsi.h GTTWSI_ALLWINNER
#
# I2C client devices
Index: src/sys/dev/i2c/gttwsi_core.c
diff -u src/sys/dev/i2c/gttwsi_core.c:1.11 src/sys/dev/i2c/gttwsi_core.c:1.12
--- src/sys/dev/i2c/gttwsi_core.c:1.11 Sat Jan 11 22:21:25 2020
+++ src/sys/dev/i2c/gttwsi_core.c Sun Jan 12 17:48:42 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: gttwsi_core.c,v 1.11 2020/01/11 22:21:25 thorpej Exp $ */
+/* $NetBSD: gttwsi_core.c,v 1.12 2020/01/12 17:48:42 thorpej Exp $ */
/*
* Copyright (c) 2008 Eiji Kawauchi.
* All rights reserved.
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.11 2020/01/11 22:21:25 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gttwsi_core.c,v 1.12 2020/01/12 17:48:42 thorpej Exp $");
#include "locators.h"
#include <sys/param.h>
@@ -92,45 +92,35 @@ static int gttwsi_write_byte(void *v, ui
static int gttwsi_wait(struct gttwsi_softc *, uint32_t, uint32_t,
uint32_t, int);
-static inline uint32_t
-gttwsi_default_read_4(struct gttwsi_softc *sc, uint32_t reg)
+uint32_t
+gttwsi_read_4(struct gttwsi_softc *sc, uint32_t reg)
{
- uint32_t val = bus_space_read_4(sc->sc_bust, sc->sc_bush, reg);
+ const uint32_t val = bus_space_read_4(sc->sc_bust, sc->sc_bush,
+ sc->sc_regmap[reg]);
#ifdef TWSI_DEBUG
- printf("I2C:R:%02x:%02x\n", reg, val);
+ printf("I2C:R:[%u]%02x:%02x\n", reg, sc->sc_regmap[reg], val);
#else
DELAY(TWSI_READ_DELAY);
#endif
return val;
}
-static inline void
-gttwsi_default_write_4(struct gttwsi_softc *sc, uint32_t reg, uint32_t val)
+void
+gttwsi_write_4(struct gttwsi_softc *sc, uint32_t reg, uint32_t val)
{
+
bus_space_write_4(sc->sc_bust, sc->sc_bush, reg, val);
#ifdef TWSI_DEBUG
- printf("I2C:W:%02x:%02x\n", reg, val);
+ printf("I2C:W:[%u]%02x:%02x\n", reg, sc->sc_regmap[reg], val);
#else
DELAY(TWSI_WRITE_DELAY);
#endif
- return;
-}
-
-static inline uint32_t
-gttwsi_read_4(struct gttwsi_softc *sc, uint32_t reg)
-{
- return sc->sc_reg_read(sc, reg);
-}
-
-static inline void
-gttwsi_write_4(struct gttwsi_softc *sc, uint32_t reg, uint32_t val)
-{
- return sc->sc_reg_write(sc, reg, val);
}
/* ARGSUSED */
void
-gttwsi_attach_subr(device_t self, bus_space_tag_t iot, bus_space_handle_t ioh)
+gttwsi_attach_subr(device_t self, bus_space_tag_t iot, bus_space_handle_t ioh,
+ const bus_size_t *regmap)
{
struct gttwsi_softc * const sc = device_private(self);
prop_dictionary_t cfg = device_properties(self);
@@ -141,11 +131,7 @@ gttwsi_attach_subr(device_t self, bus_sp
sc->sc_dev = self;
sc->sc_bust = iot;
sc->sc_bush = ioh;
-
- if (sc->sc_reg_read == NULL)
- sc->sc_reg_read = gttwsi_default_read_4;
- if (sc->sc_reg_write == NULL)
- sc->sc_reg_write = gttwsi_default_write_4;
+ sc->sc_regmap = regmap;
mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_BIO);
cv_init(&sc->sc_cv, device_xname(self));
@@ -166,7 +152,6 @@ gttwsi_attach_subr(device_t self, bus_sp
*/
/* reset */
gttwsi_write_4(sc, TWSI_SOFTRESET, SOFTRESET_VAL);
-
}
void
Index: src/sys/dev/i2c/gttwsireg.h
diff -u src/sys/dev/i2c/gttwsireg.h:1.3 src/sys/dev/i2c/gttwsireg.h:1.4
--- src/sys/dev/i2c/gttwsireg.h:1.3 Thu Sep 11 11:14:44 2014
+++ src/sys/dev/i2c/gttwsireg.h Sun Jan 12 17:48:42 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: gttwsireg.h,v 1.3 2014/09/11 11:14:44 jmcneill Exp $ */
+/* $NetBSD: gttwsireg.h,v 1.4 2020/01/12 17:48:42 thorpej Exp $ */
/*
* Copyright (c) 2008 Eiji Kawauchi.
@@ -27,27 +27,37 @@
#ifndef _GTTWSIREG_H_
#define _GTTWSIREG_H_
-#include "opt_gttwsi.h"
-
#define GTTWSI_SIZE 0x100
+#define GTTWSI_NREGS 7
-#if defined(GTTWSI_ALLWINNER)
-#define TWSI_SLAVEADDR 0x00
-#define TWSI_EXTEND_SLAVEADDR 0x04
-#define TWSI_DATA 0x08
-#define TWSI_CONTROL 0x0c
-#define TWSI_STATUS 0x10
-#define TWSI_BAUDRATE 0x14
-#define TWSI_SOFTRESET 0x18
-#else
-#define TWSI_SLAVEADDR 0x00
-#define TWSI_EXTEND_SLAVEADDR 0x10
-#define TWSI_DATA 0x04
-#define TWSI_CONTROL 0x08
-#define TWSI_STATUS 0x0c /* for read */
-#define TWSI_BAUDRATE 0x0c /* for write */
-#define TWSI_SOFTRESET 0x1c
-#endif
+ /* reg map indices */
+#define TWSI_SLAVEADDR 0
+#define TWSI_EXTEND_SLAVEADDR 1
+#define TWSI_DATA 2
+#define TWSI_CONTROL 3
+#define TWSI_STATUS 4
+#define TWSI_BAUDRATE 5
+#define TWSI_SOFTRESET 6
+
+ /* register offsets for Allwinner implementations */
+#define TWSI_ALLWINNER_SLAVEADDR 0x00
+#define TWSI_ALLWINNER_EXTEND_SLAVEADDR 0x04
+#define TWSI_ALLWINNER_DATA 0x08
+#define TWSI_ALLWINNER_CONTROL 0x0c
+#define TWSI_ALLWINNER_STATUS 0x10
+#define TWSI_ALLWINNER_BAUDRATE 0x14
+#define TWSI_ALLWINNER_SOFTRESET 0x18
+#define TWSI_ALLWINNER_ENH_FEAT 0x1c
+#define TWSI_ALLWINNER_LINE_CTRL 0x20
+
+ /* register offsets for Marvell implementations */
+#define TWSI_MARVELL_SLAVEADDR 0x00
+#define TWSI_MARVELL_EXTEND_SLAVEADDR 0x10
+#define TWSI_MARVELL_DATA 0x04
+#define TWSI_MARVELL_CONTROL 0x08
+#define TWSI_MARVELL_STATUS 0x0c /* for read */
+#define TWSI_MARVELL_BAUDRATE 0x0c /* for write */
+#define TWSI_MARVELL_SOFTRESET 0x1c
#define SLAVEADDR_GCE_MASK 0x01
#define SLAVEADDR_SADDR_MASK 0xfe
Index: src/sys/dev/i2c/gttwsivar.h
diff -u src/sys/dev/i2c/gttwsivar.h:1.5 src/sys/dev/i2c/gttwsivar.h:1.6
--- src/sys/dev/i2c/gttwsivar.h:1.5 Wed Dec 25 14:08:47 2019
+++ src/sys/dev/i2c/gttwsivar.h Sun Jan 12 17:48:42 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: gttwsivar.h,v 1.5 2019/12/25 14:08:47 thorpej Exp $ */
+/* $NetBSD: gttwsivar.h,v 1.6 2020/01/12 17:48:42 thorpej Exp $ */
/*
* Copyright (c) 2008 Eiji Kawauchi.
* All rights reserved.
@@ -88,15 +88,18 @@ struct gttwsi_softc {
kmutex_t sc_mtx;
kcondvar_t sc_cv;
- bool sc_iflg_rwc;
+ const bus_size_t *sc_regmap; /* GTTWSI_NREGS entries */
- uint32_t (*sc_reg_read)(struct gttwsi_softc *, uint32_t);
- void (*sc_reg_write)(struct gttwsi_softc *, uint32_t, uint32_t);
+ bool sc_iflg_rwc;
};
-void gttwsi_attach_subr(device_t, bus_space_tag_t, bus_space_handle_t);
+void gttwsi_attach_subr(device_t, bus_space_tag_t, bus_space_handle_t,
+ const bus_size_t *);
void gttwsi_config_children(device_t);
+uint32_t gttwsi_read_4(struct gttwsi_softc *, uint32_t);
+void gttwsi_write_4(struct gttwsi_softc *, uint32_t, uint32_t);
+
int gttwsi_intr(void *);
#endif /* _DEV_MARVELL_GTTSWI_VAR_H_ */
Index: src/sys/dev/marvell/gttwsi.c
diff -u src/sys/dev/marvell/gttwsi.c:1.11 src/sys/dev/marvell/gttwsi.c:1.12
--- src/sys/dev/marvell/gttwsi.c:1.11 Fri Sep 6 00:56:12 2013
+++ src/sys/dev/marvell/gttwsi.c Sun Jan 12 17:48:42 2020
@@ -1,4 +1,4 @@
-/* $NetBSD: gttwsi.c,v 1.11 2013/09/06 00:56:12 matt Exp $ */
+/* $NetBSD: gttwsi.c,v 1.12 2020/01/12 17:48:42 thorpej Exp $ */
/*
* Copyright (c) 2008 Eiji Kawauchi.
* All rights reserved.
@@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: gttwsi.c,v 1.11 2013/09/06 00:56:12 matt Exp $");
+__KERNEL_RCSID(0, "$NetBSD: gttwsi.c,v 1.12 2020/01/12 17:48:42 thorpej Exp $");
#include "locators.h"
#include <sys/param.h>
@@ -87,6 +87,16 @@ __KERNEL_RCSID(0, "$NetBSD: gttwsi.c,v 1
#include <dev/marvell/marvellvar.h>
+static const bus_size_t marvell_twsi_regmap[GTTWSI_NREGS] = {
+ [TWSI_SLAVEADDR] = TWSI_MARVELL_SLAVEADDR,
+ [TWSI_EXTEND_SLAVEADDR] = TWSI_MARVELL_EXTEND_SLAVEADDR,
+ [TWSI_DATA] = TWSI_MARVELL_DATA,
+ [TWSI_CONTROL] = TWSI_MARVELL_CONTROL,
+ [TWSI_STATUS] = TWSI_MARVELL_STATUS,
+ [TWSI_BAUDRATE] = TWSI_MARVELL_BAUDRATE,
+ [TWSI_SOFTRESET] = TWSI_MARVELL_SOFTRESET,
+};
+
static int gttwsi_match(device_t, cfdata_t, void *);
static void gttwsi_attach(device_t, device_t, void *);
@@ -124,7 +134,7 @@ gttwsi_attach(device_t parent, device_t
return;
}
- gttwsi_attach_subr(self, mva->mva_iot, ioh);
+ gttwsi_attach_subr(self, mva->mva_iot, ioh, marvell_twsi_regmap);
marvell_intr_establish(mva->mva_irq, IPL_BIO, gttwsi_intr,
device_private(self));