summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorthorpej <thorpej@NetBSD.org>2022-07-22 23:43:23 +0000
committerthorpej <thorpej@NetBSD.org>2022-07-22 23:43:23 +0000
commitd69f4c5741d4010327cb074798ea17e2ce60ec69 (patch)
tree6d0c01ff6561e63c41ae807917c26282d7e4c5ab /sys/dev
parentfbabdee57216afcdae45181fff1ea0bf08e85365 (diff)
Normalize how motoi2c controllers are attached.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/acpi/nxpiic_acpi.c30
-rw-r--r--sys/dev/i2c/motoi2c.c40
-rw-r--r--sys/dev/i2c/motoi2cvar.h6
3 files changed, 36 insertions, 40 deletions
diff --git a/sys/dev/acpi/nxpiic_acpi.c b/sys/dev/acpi/nxpiic_acpi.c
index 17998349559..b3eea14bddd 100644
--- a/sys/dev/acpi/nxpiic_acpi.c
+++ b/sys/dev/acpi/nxpiic_acpi.c
@@ -1,4 +1,4 @@
-/* $NetBSD: nxpiic_acpi.c,v 1.4 2021/01/29 02:26:58 thorpej Exp $ */
+/* $NetBSD: nxpiic_acpi.c,v 1.5 2022/07/22 23:43:23 thorpej Exp $ */
/*-
* Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: nxpiic_acpi.c,v 1.4 2021/01/29 02:26:58 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: nxpiic_acpi.c,v 1.5 2022/07/22 23:43:23 thorpej Exp $");
#include <sys/param.h>
#include <sys/bus.h>
@@ -68,18 +68,13 @@ static const struct clk_div {
{ 3840, 0x3f }, { 4096, 0x7B }, { 5120, 0x7d }, { 6144, 0x7e },
};
-struct nxpiic_softc {
- device_t sc_dev;
- struct motoi2c_softc sc_motoi2c;
-};
-
static int nxpiic_acpi_match(device_t, cfdata_t, void *);
static void nxpiic_acpi_attach(device_t, device_t, void *);
static uint8_t nxpiic_acpi_iord(struct motoi2c_softc *, bus_size_t);
static void nxpiic_acpi_iowr(struct motoi2c_softc *, bus_size_t, uint8_t);
-CFATTACH_DECL_NEW(nxpiic_acpi, sizeof(struct nxpiic_softc),
+CFATTACH_DECL_NEW(nxpiic_acpi, sizeof(struct motoi2c_softc),
nxpiic_acpi_match, nxpiic_acpi_attach, NULL, NULL);
static const struct device_compatible_entry compat_data[] = {
@@ -98,8 +93,7 @@ nxpiic_acpi_match(device_t parent, cfdata_t cf, void *aux)
static void
nxpiic_acpi_attach(device_t parent, device_t self, void *aux)
{
- struct nxpiic_softc * const sc = device_private(self);
- struct motoi2c_softc * const msc = &sc->sc_motoi2c;
+ struct motoi2c_softc * const sc = device_private(self);
struct motoi2c_settings settings;
struct acpi_attach_args *aa = aux;
struct acpi_resources res;
@@ -109,7 +103,7 @@ nxpiic_acpi_attach(device_t parent, device_t self, void *aux)
int error, n;
sc->sc_dev = self;
- msc->sc_iot = aa->aa_memt;
+ sc->sc_iot = aa->aa_memt;
rv = acpi_resource_parse(sc->sc_dev, aa->aa_node->ad_handle, "_CRS",
&res, &acpi_resource_parse_ops_default);
@@ -130,8 +124,8 @@ nxpiic_acpi_attach(device_t parent, device_t self, void *aux)
}
aprint_debug_dev(self, "bus clock %u Hz\n", (u_int)clock_freq);
- error = bus_space_map(msc->sc_iot, mem->ar_base, mem->ar_length, 0,
- &msc->sc_ioh);
+ error = bus_space_map(sc->sc_iot, mem->ar_base, mem->ar_length, 0,
+ &sc->sc_ioh);
if (error) {
aprint_error_dev(self, "couldn't map registers\n");
return;
@@ -145,12 +139,12 @@ nxpiic_acpi_attach(device_t parent, device_t self, void *aux)
}
settings.i2c_fdr = nxpiic_clk_div[n].ibc;
- msc->sc_flags |= MOTOI2C_F_ENABLE_INV | MOTOI2C_F_STATUS_W1C;
- msc->sc_iord = nxpiic_acpi_iord;
- msc->sc_iowr = nxpiic_acpi_iowr;
- msc->sc_child_devices = acpi_enter_i2c_devs(self, aa->aa_node);
+ sc->sc_flags |= MOTOI2C_F_ENABLE_INV | MOTOI2C_F_STATUS_W1C;
+ sc->sc_iord = nxpiic_acpi_iord;
+ sc->sc_iowr = nxpiic_acpi_iowr;
+ sc->sc_child_devices = acpi_enter_i2c_devs(self, aa->aa_node);
- motoi2c_attach_common(self, msc, &settings);
+ motoi2c_attach(sc, &settings);
done:
acpi_resource_cleanup(&res);
diff --git a/sys/dev/i2c/motoi2c.c b/sys/dev/i2c/motoi2c.c
index 078399bb7f4..582016124a3 100644
--- a/sys/dev/i2c/motoi2c.c
+++ b/sys/dev/i2c/motoi2c.c
@@ -1,4 +1,4 @@
-/* $NetBSD: motoi2c.c,v 1.12 2021/08/07 16:19:11 thorpej Exp $ */
+/* $NetBSD: motoi2c.c,v 1.13 2022/07/22 23:43:23 thorpej Exp $ */
/*-
* Copyright (c) 2007, 2010 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.12 2021/08/07 16:19:11 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: motoi2c.c,v 1.13 2022/07/22 23:43:23 thorpej Exp $");
#if defined(__arm__) || defined(__aarch64__)
#include "opt_fdt.h"
@@ -62,6 +62,7 @@ static int motoi2c_acquire_bus(void *, int);
static void motoi2c_release_bus(void *, int);
static int motoi2c_exec(void *, i2c_op_t, i2c_addr_t, const void *, size_t,
void *, size_t, int);
+static void motoi2c_clear_status(struct motoi2c_softc *, uint8_t);
static int motoi2c_busy_wait(struct motoi2c_softc *, uint8_t);
static const struct motoi2c_settings motoi2c_default_settings = {
@@ -88,23 +89,26 @@ motoi2c_iowr1(struct motoi2c_softc *sc, bus_size_t off, uint8_t data)
}
void
-motoi2c_attach_common(device_t self, struct motoi2c_softc *sc,
- const struct motoi2c_settings *i2c)
+motoi2c_attach(struct motoi2c_softc *sc,
+ const struct motoi2c_settings *settings)
{
struct i2cbus_attach_args iba;
- if (i2c == NULL)
- i2c = &motoi2c_default_settings;
+ if (settings == NULL) {
+ sc->sc_settings = motoi2c_default_settings;
+ } else {
+ sc->sc_settings = *settings;
+ }
+ if (sc->sc_iord == NULL)
+ sc->sc_iord = motoi2c_iord1;
+ if (sc->sc_iowr == NULL)
+ sc->sc_iowr = motoi2c_iowr1;
iic_tag_init(&sc->sc_i2c);
sc->sc_i2c.ic_cookie = sc;
sc->sc_i2c.ic_acquire_bus = motoi2c_acquire_bus;
sc->sc_i2c.ic_release_bus = motoi2c_release_bus;
sc->sc_i2c.ic_exec = motoi2c_exec;
- if (sc->sc_iord == NULL)
- sc->sc_iord = motoi2c_iord1;
- if (sc->sc_iowr == NULL)
- sc->sc_iowr = motoi2c_iowr1;
memset(&iba, 0, sizeof(iba));
iba.iba_tag = &sc->sc_i2c;
iba.iba_child_devices = sc->sc_child_devices;
@@ -118,23 +122,19 @@ motoi2c_attach_common(device_t self, struct motoi2c_softc *sc,
}
I2C_WRITE(I2CCR, sc->sc_disable_mask); /* reset before config */
- I2C_WRITE(I2CDFSRR, i2c->i2c_dfsrr); /* sampling units */
- I2C_WRITE(I2CFDR, i2c->i2c_fdr); /* divider 3072 (0x31) */
- I2C_WRITE(I2CADR, i2c->i2c_adr); /* our slave address is 0x7f */
- if ((sc->sc_flags & MOTOI2C_F_STATUS_W1C) != 0) {
- I2C_WRITE(I2CSR, I2C_READ(I2CSR)); /* clear status flags */
- } else {
- I2C_WRITE(I2CSR, 0); /* clear status flags */
- }
+ I2C_WRITE(I2CDFSRR, sc->sc_settings.i2c_dfsrr); /* sampling units */
+ I2C_WRITE(I2CFDR, sc->sc_settings.i2c_fdr); /* divider 3072 */
+ I2C_WRITE(I2CADR, sc->sc_settings.i2c_adr); /* our slave address */
+ motoi2c_clear_status(sc, I2C_READ(I2CSR));
#ifdef FDT
if (sc->sc_phandle != 0) {
fdtbus_register_i2c_controller(&sc->sc_i2c, sc->sc_phandle);
- fdtbus_attach_i2cbus(self, sc->sc_phandle, &sc->sc_i2c,
+ fdtbus_attach_i2cbus(sc->sc_dev, sc->sc_phandle, &sc->sc_i2c,
iicbus_print);
} else
#endif
- config_found(self, &iba, iicbus_print,
+ config_found(sc->sc_dev, &iba, iicbus_print,
CFARGS(.iattr = "i2cbus"));
}
diff --git a/sys/dev/i2c/motoi2cvar.h b/sys/dev/i2c/motoi2cvar.h
index 642bc04130c..e6d60d290fa 100644
--- a/sys/dev/i2c/motoi2cvar.h
+++ b/sys/dev/i2c/motoi2cvar.h
@@ -1,4 +1,4 @@
-/* $NetBSD: motoi2cvar.h,v 1.8 2021/01/25 12:08:47 jmcneill Exp $ */
+/* $NetBSD: motoi2cvar.h,v 1.9 2022/07/22 23:43:23 thorpej Exp $ */
/*-
* Copyright (c) 2007, 2010 The NetBSD Foundation, Inc.
@@ -45,6 +45,7 @@ struct motoi2c_settings {
};
struct motoi2c_softc {
+ device_t sc_dev;
bus_space_tag_t sc_iot;
bus_space_handle_t sc_ioh;
struct i2c_controller sc_i2c;
@@ -52,6 +53,7 @@ struct motoi2c_softc {
motoi2c_iowr_t sc_iowr;
int sc_phandle;
prop_array_t sc_child_devices;
+ struct motoi2c_settings sc_settings;
int sc_flags;
#define MOTOI2C_F_ENABLE_INV __BIT(0)
#define MOTOI2C_F_STATUS_W1C __BIT(1)
@@ -64,7 +66,7 @@ struct motoi2c_softc {
#define MOTOI2C_DFSRR_DEFAULT 0x10
#ifdef _KERNEL
-void motoi2c_attach_common(device_t, struct motoi2c_softc *,
+void motoi2c_attach(struct motoi2c_softc *,
const struct motoi2c_settings *);
int motoi2c_intr(void *);
#endif