Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/thorpej-i2c-spi-conf]: src/sys/arch/macppc/dev Adapt the pmu driver to t...
details: https://anonhg.NetBSD.org/src/rev/6d984d0141f1
branches: thorpej-i2c-spi-conf
changeset: 983206:6d984d0141f1
user: thorpej <thorpej%NetBSD.org@localhost>
date: Sat May 08 22:39:41 2021 +0000
description:
Adapt the pmu driver to the new i2c device enumeration mechanism. This
follows the OpenFirmware bindings for the most part, but has the i2c
addresses of children shifted left one bit as it would appear on the
wire (for the r/w bit).
diffstat:
sys/arch/macppc/dev/pmu.c | 102 +++++++++++++++++++++++++++------------------
1 files changed, 61 insertions(+), 41 deletions(-)
diffs (150 lines):
diff -r 5fbb787f4198 -r 6d984d0141f1 sys/arch/macppc/dev/pmu.c
--- a/sys/arch/macppc/dev/pmu.c Sat May 08 21:58:12 2021 +0000
+++ b/sys/arch/macppc/dev/pmu.c Sat May 08 22:39:41 2021 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: pmu.c,v 1.37 2021/04/24 23:36:41 thorpej Exp $ */
+/* $NetBSD: pmu.c,v 1.37.2.1 2021/05/08 22:39:41 thorpej Exp $ */
/*-
* Copyright (c) 2006 Michael Lorenz
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pmu.c,v 1.37 2021/04/24 23:36:41 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmu.c,v 1.37.2.1 2021/05/08 22:39:41 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -90,6 +90,13 @@
struct sysmon_pswitch sc_powerbutton;
bus_space_tag_t sc_memt;
bus_space_handle_t sc_memh;
+
+ /*
+ * We provide our own i2c device enumeration method, so we
+ * need to provide our own devhandle_impl.
+ */
+ struct devhandle_impl sc_devhandle_impl;
+
uint32_t sc_flags;
#define PMU_HAS_BACKLIGHT_CONTROL 1
int sc_node;
@@ -235,6 +242,42 @@
"PowerBook1,1",
NULL };
+static bool
+pmu_i2c_get_address(int node, uint32_t *addrp)
+{
+ uint32_t reg;
+
+ if (of_getprop_uint32(node, "reg", ®) == -1) {
+ return false;
+ }
+
+ *addrp = (reg & 0xff) >> 1;
+ return true;
+}
+
+static int
+pmu_i2c_enumerate_devices(device_t dev, devhandle_t call_handle, void *v)
+{
+ /*
+ * This follows the OpenFirmware I2C binding for the most
+ * part, but has the address shifted left for the READ bit.
+ */
+ return of_i2c_enumerate_devices_ext(dev, call_handle, v,
+ pmu_i2c_get_address);
+}
+
+static device_call_t
+pmu_devhandle_lookup_device_call(devhandle_t handle, const char *name,
+ devhandle_t *call_handlep)
+{
+ if (strcmp(name, "i2c-enumerate-devices") == 0) {
+ return pmu_i2c_enumerate_devices;
+ }
+
+ /* Defer everything else to the "super". */
+ return NULL;
+}
+
static int
pmu_match(device_t parent, cfdata_t cf, void *aux)
{
@@ -267,7 +310,6 @@
uint8_t cmd[2] = {2, 0};
uint8_t resp[16];
char name[256], model[32];
- prop_dictionary_t dict = device_properties(self);
extint_node = of_getnode_byname(OF_parent(ca->ca_node), "extint-gpio1");
if (extint_node) {
@@ -340,50 +382,28 @@
goto next;
if (strncmp(name, "pmu-i2c", 8) == 0) {
- int devs;
- uint32_t addr;
- char compat[256];
- prop_array_t cfg;
- prop_dictionary_t dev;
- prop_data_t data;
-
- aprint_normal_dev(self, "initializing IIC bus\n");
-
- cfg = prop_array_create();
- prop_dictionary_set(dict, "i2c-child-devices", cfg);
- prop_object_release(cfg);
+ /*
+ * Give the OFW node to the i2c bus instance,
+ * but provide our own devhandle_impl, because
+ * we have our own device enumeration method.
+ */
+ devhandle_t devhandle = devhandle_from_of(node);
+ devhandle_impl_inherit(&sc->sc_devhandle_impl,
+ devhandle.impl);
+ sc->sc_devhandle_impl.lookup_device_call =
+ pmu_devhandle_lookup_device_call;
+ devhandle.impl = &sc->sc_devhandle_impl;
- /* look for i2c devices */
- devs = OF_child(node);
- while (devs != 0) {
- if (OF_getprop(devs, "name", name, 256) <= 0)
- goto skip;
- if (OF_getprop(devs, "compatible",
- compat, 256) <= 0)
- goto skip;
- if (OF_getprop(devs, "reg", &addr, 4) <= 0)
- goto skip;
- addr = (addr & 0xff) >> 1;
- DPRINTF("-> %s@%x\n", name, addr);
- dev = prop_dictionary_create();
- prop_dictionary_set_string(dev, "name", name);
- data = prop_data_create_copy(compat, strlen(compat)+1);
- prop_dictionary_set(dev, "compatible", data);
- prop_object_release(data);
- prop_dictionary_set_uint32(dev, "addr", addr);
- prop_dictionary_set_uint64(dev, "cookie", devs);
- prop_array_add(cfg, dev);
- prop_object_release(dev);
- skip:
- devs = OF_peer(devs);
- }
- memset(&iba, 0, sizeof(iba));
- iba.iba_tag = &sc->sc_i2c;
+ /* fill in the i2c tag */
iic_tag_init(&sc->sc_i2c);
sc->sc_i2c.ic_cookie = sc;
sc->sc_i2c.ic_exec = pmu_i2c_exec;
+
+ memset(&iba, 0, sizeof(iba));
+ iba.iba_tag = &sc->sc_i2c;
config_found(sc->sc_dev, &iba, iicbus_print,
CFARG_IATTR, "i2cbus",
+ CFARG_DEVHANDLE, devhandle,
CFARG_EOL);
goto next;
}
Home |
Main Index |
Thread Index |
Old Index