Index: arch/arm/broadcom/bcm2835_bsc_acpi.c =================================================================== RCS file: /cvsroot/src/sys/arch/arm/broadcom/bcm2835_bsc_acpi.c,v retrieving revision 1.4 retrieving revision 1.4.2.1 diff -u -p -r1.4 -r1.4.2.1 --- arch/arm/broadcom/bcm2835_bsc_acpi.c 7 Aug 2021 16:18:43 -0000 1.4 +++ arch/arm/broadcom/bcm2835_bsc_acpi.c 9 Aug 2021 00:30:06 -0000 1.4.2.1 @@ -1,4 +1,4 @@ -/* $NetBSD: bcm2835_bsc_acpi.c,v 1.4 2021/08/07 16:18:43 thorpej Exp $ */ +/* $NetBSD: bcm2835_bsc_acpi.c,v 1.4.2.1 2021/08/09 00:30:06 thorpej Exp $ */ /*- * Copyright (c) 2020 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bcm2835_bsc_acpi.c,v 1.4 2021/08/07 16:18:43 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bcm2835_bsc_acpi.c,v 1.4.2.1 2021/08/09 00:30:06 thorpej Exp $"); #include #include @@ -37,7 +37,6 @@ __KERNEL_RCSID(0, "$NetBSD: bcm2835_bsc_ #include #include #include -#include #include #include @@ -160,8 +159,8 @@ bsciic_acpi_attach(device_t parent, devi memset(&iba, 0, sizeof(iba)); iba.iba_tag = &sc->sc_i2c; - iba.iba_child_devices = acpi_enter_i2c_devs(self, aa->aa_node); - config_found(self, &iba, iicbus_print, CFARGS_NONE); + config_found(self, &iba, iicbus_print, + CFARGS(.devhandle = device_handle(self))); done: acpi_resource_cleanup(&res); Index: arch/arm/broadcom/bcm2835_bsc_fdt.c =================================================================== RCS file: /cvsroot/src/sys/arch/arm/broadcom/bcm2835_bsc_fdt.c,v retrieving revision 1.6 retrieving revision 1.6.14.1 diff -u -p -r1.6 -r1.6.14.1 --- arch/arm/broadcom/bcm2835_bsc_fdt.c 29 Jan 2021 14:11:14 -0000 1.6 +++ arch/arm/broadcom/bcm2835_bsc_fdt.c 9 Aug 2021 00:30:06 -0000 1.6.14.1 @@ -1,4 +1,4 @@ -/* $NetBSD: bcm2835_bsc_fdt.c,v 1.6 2021/01/29 14:11:14 skrll Exp $ */ +/* $NetBSD: bcm2835_bsc_fdt.c,v 1.6.14.1 2021/08/09 00:30:06 thorpej Exp $ */ /* * Copyright (c) 2019 Jason R. Thorpe @@ -28,7 +28,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: bcm2835_bsc_fdt.c,v 1.6 2021/01/29 14:11:14 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: bcm2835_bsc_fdt.c,v 1.6.14.1 2021/08/09 00:30:06 thorpej Exp $"); #include #include @@ -135,5 +135,9 @@ bsciic_fdt_attach(device_t parent, devic fdtbus_register_i2c_controller(&sc->sc_i2c, phandle); - fdtbus_attach_i2cbus(self, phandle, &sc->sc_i2c, iicbus_print); + struct i2cbus_attach_args iba = { + .iba_tag = &sc->sc_i2c, + }; + config_found(self, &iba, iicbus_print, + CFARGS(.devhandle = device_handle(self))); } Index: arch/arm/nvidia/tegra_i2c.c =================================================================== RCS file: /cvsroot/src/sys/arch/arm/nvidia/tegra_i2c.c,v retrieving revision 1.26 retrieving revision 1.26.14.1 diff -u -p -r1.26 -r1.26.14.1 --- arch/arm/nvidia/tegra_i2c.c 27 Jan 2021 03:10:19 -0000 1.26 +++ arch/arm/nvidia/tegra_i2c.c 9 Aug 2021 00:30:07 -0000 1.26.14.1 @@ -1,4 +1,4 @@ -/* $NetBSD: tegra_i2c.c,v 1.26 2021/01/27 03:10:19 thorpej Exp $ */ +/* $NetBSD: tegra_i2c.c,v 1.26.14.1 2021/08/09 00:30:07 thorpej Exp $ */ /*- * Copyright (c) 2015 Jared D. McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: tegra_i2c.c,v 1.26 2021/01/27 03:10:19 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: tegra_i2c.c,v 1.26.14.1 2021/08/09 00:30:07 thorpej Exp $"); #include #include @@ -180,7 +180,11 @@ tegra_i2c_attach(device_t parent, device fdtbus_register_i2c_controller(&sc->sc_ic, phandle); - fdtbus_attach_i2cbus(self, phandle, &sc->sc_ic, iicbus_print); + struct i2cbus_attach_args iba = { + .iba_tag = &sc->sc_ic, + }; + config_found(self, &iba, iicbus_print, + CFARGS(.devhandle = device_handle(self))); } static void Index: arch/arm/rockchip/rk_i2c.c =================================================================== RCS file: /cvsroot/src/sys/arch/arm/rockchip/rk_i2c.c,v retrieving revision 1.10 retrieving revision 1.10.14.1 diff -u -p -r1.10 -r1.10.14.1 --- arch/arm/rockchip/rk_i2c.c 27 Jan 2021 03:10:19 -0000 1.10 +++ arch/arm/rockchip/rk_i2c.c 9 Aug 2021 00:30:07 -0000 1.10.14.1 @@ -1,4 +1,4 @@ -/* $NetBSD: rk_i2c.c,v 1.10 2021/01/27 03:10:19 thorpej Exp $ */ +/* $NetBSD: rk_i2c.c,v 1.10.14.1 2021/08/09 00:30:07 thorpej Exp $ */ /*- * Copyright (c) 2018 Jared McNeill @@ -28,7 +28,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: rk_i2c.c,v 1.10 2021/01/27 03:10:19 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: rk_i2c.c,v 1.10.14.1 2021/08/09 00:30:07 thorpej Exp $"); #include #include @@ -418,7 +418,11 @@ rk_i2c_attach(device_t parent, device_t fdtbus_register_i2c_controller(&sc->sc_ic, phandle); - fdtbus_attach_i2cbus(self, phandle, &sc->sc_ic, iicbus_print); + struct i2cbus_attach_args iba = { + .iba_tag = &sc->sc_ic, + }; + config_found(self, &iba, iicbus_print, + CFARGS(.devhandle = device_handle(self))); } CFATTACH_DECL_NEW(rk_i2c, sizeof(struct rk_i2c_softc), Index: arch/arm/samsung/exynos_i2c.c =================================================================== RCS file: /cvsroot/src/sys/arch/arm/samsung/exynos_i2c.c,v retrieving revision 1.22 retrieving revision 1.22.14.1 diff -u -p -r1.22 -r1.22.14.1 --- arch/arm/samsung/exynos_i2c.c 14 Mar 2021 08:16:57 -0000 1.22 +++ arch/arm/samsung/exynos_i2c.c 9 Aug 2021 00:30:07 -0000 1.22.14.1 @@ -1,4 +1,4 @@ -/* $NetBSD: exynos_i2c.c,v 1.22 2021/03/14 08:16:57 skrll Exp $ */ +/* $NetBSD: exynos_i2c.c,v 1.22.14.1 2021/08/09 00:30:07 thorpej Exp $ */ /* * Copyright (c) 2015 Jared D. McNeill @@ -31,7 +31,7 @@ #include "opt_arm_debug.h" #include -__KERNEL_RCSID(0, "$NetBSD: exynos_i2c.c,v 1.22 2021/03/14 08:16:57 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: exynos_i2c.c,v 1.22.14.1 2021/08/09 00:30:07 thorpej Exp $"); #include #include @@ -178,7 +178,11 @@ exynos_i2c_attach(device_t parent, devic fdtbus_register_i2c_controller(&sc->sc_ic, phandle); - fdtbus_attach_i2cbus(self, phandle, &sc->sc_ic, iicbus_print); + struct i2cbus_attach_args iba = { + .iba_tag = &sc->sc_ic, + }; + config_found(self, &iba, iicbus_print, + CFARGS(.devhandle = device_handle(self))); } static int Index: arch/arm/sociox/sni_i2c.c =================================================================== RCS file: /cvsroot/src/sys/arch/arm/sociox/sni_i2c.c,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -u -p -r1.12 -r1.12.2.1 --- arch/arm/sociox/sni_i2c.c 7 Aug 2021 16:18:45 -0000 1.12 +++ arch/arm/sociox/sni_i2c.c 9 Aug 2021 00:30:07 -0000 1.12.2.1 @@ -1,4 +1,4 @@ -/* $NetBSD: sni_i2c.c,v 1.12 2021/08/07 16:18:45 thorpej Exp $ */ +/* $NetBSD: sni_i2c.c,v 1.12.2.1 2021/08/09 00:30:07 thorpej Exp $ */ /*- * Copyright (c) 2020 The NetBSD Foundation, Inc. @@ -34,7 +34,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sni_i2c.c,v 1.12 2021/08/07 16:18:45 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sni_i2c.c,v 1.12.2.1 2021/08/09 00:30:07 thorpej Exp $"); #include #include @@ -148,7 +148,11 @@ sniiic_fdt_attach(device_t parent, devic fdtbus_register_i2c_controller(&sc->sc_ic, phandle); #if 0 - fdtbus_attach_i2cbus(self, phandle, &sc->sc_ic, iicbus_print); + struct i2cbus_attach_args iba = { + .iba_tag = &sc->sc_i2c, + }; + config_found(self, &iba, iicbus_print, + CFARGS(.devhandle = device_handle(self))); #endif return; fail: Index: arch/arm/sunxi/sunxi_rsb.c =================================================================== RCS file: /cvsroot/src/sys/arch/arm/sunxi/sunxi_rsb.c,v retrieving revision 1.14 retrieving revision 1.14.14.1 diff -u -p -r1.14 -r1.14.14.1 --- arch/arm/sunxi/sunxi_rsb.c 27 Jan 2021 03:10:20 -0000 1.14 +++ arch/arm/sunxi/sunxi_rsb.c 9 Aug 2021 00:30:07 -0000 1.14.14.1 @@ -1,4 +1,4 @@ -/* $NetBSD: sunxi_rsb.c,v 1.14 2021/01/27 03:10:20 thorpej Exp $ */ +/* $NetBSD: sunxi_rsb.c,v 1.14.14.1 2021/08/09 00:30:07 thorpej Exp $ */ /*- * Copyright (c) 2014-2017 Jared McNeill @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: sunxi_rsb.c,v 1.14 2021/01/27 03:10:20 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sunxi_rsb.c,v 1.14.14.1 2021/08/09 00:30:07 thorpej Exp $"); #include #include @@ -184,7 +184,11 @@ sunxi_rsb_attach(device_t parent, device fdtbus_register_i2c_controller(&sc->sc_ic, phandle); - fdtbus_attach_i2cbus(self, phandle, &sc->sc_ic, iicbus_print); + struct i2cbus_attach_args iba = { + .iba_tag = &sc->sc_ic, + }; + config_found(self, &iba, iicbus_print, + CFARGS(.devhandle = device_handle(self))); } static int Index: arch/arm/sunxi/sunxi_twi.c =================================================================== RCS file: /cvsroot/src/sys/arch/arm/sunxi/sunxi_twi.c,v retrieving revision 1.17 retrieving revision 1.17.14.1 diff -u -p -r1.17 -r1.17.14.1 --- arch/arm/sunxi/sunxi_twi.c 27 Jan 2021 03:10:20 -0000 1.17 +++ arch/arm/sunxi/sunxi_twi.c 9 Aug 2021 00:30:07 -0000 1.17.14.1 @@ -1,4 +1,4 @@ -/* $NetBSD: sunxi_twi.c,v 1.17 2021/01/27 03:10:20 thorpej Exp $ */ +/* $NetBSD: sunxi_twi.c,v 1.17.14.1 2021/08/09 00:30:07 thorpej Exp $ */ /*- * Copyright (c) 2017 Jared McNeill @@ -28,7 +28,7 @@ #include -__KERNEL_RCSID(0, "$NetBSD: sunxi_twi.c,v 1.17 2021/01/27 03:10:20 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: sunxi_twi.c,v 1.17.14.1 2021/08/09 00:30:07 thorpej Exp $"); #include #include @@ -185,5 +185,9 @@ sunxi_twi_attach(device_t parent, device fdtbus_register_i2c_controller(&sc->sc_i2c, phandle); - fdtbus_attach_i2cbus(self, phandle, &sc->sc_i2c, iicbus_print); + struct i2cbus_attach_args iba = { + .iba_tag = &sc->sc_i2c, + }; + config_found(self, &iba, iicbus_print, + CFARGS(.devhandle = device_handle(self))); } Index: arch/arm/ti/ti_iic.c =================================================================== RCS file: /cvsroot/src/sys/arch/arm/ti/ti_iic.c,v retrieving revision 1.13 retrieving revision 1.13.14.1 diff -u -p -r1.13 -r1.13.14.1 --- arch/arm/ti/ti_iic.c 27 Jan 2021 03:10:20 -0000 1.13 +++ arch/arm/ti/ti_iic.c 9 Aug 2021 00:30:07 -0000 1.13.14.1 @@ -1,4 +1,4 @@ -/* $NetBSD: ti_iic.c,v 1.13 2021/01/27 03:10:20 thorpej Exp $ */ +/* $NetBSD: ti_iic.c,v 1.13.14.1 2021/08/09 00:30:07 thorpej Exp $ */ /* * Copyright (c) 2013 Manuel Bouyer. All rights reserved. @@ -50,7 +50,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: ti_iic.c,v 1.13 2021/01/27 03:10:20 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: ti_iic.c,v 1.13.14.1 2021/08/09 00:30:07 thorpej Exp $"); #include #include @@ -298,7 +298,11 @@ ti_iic_attach(device_t parent, device_t fdtbus_register_i2c_controller(&sc->sc_ic, phandle); - fdtbus_attach_i2cbus(self, phandle, &sc->sc_ic, iicbus_print); + struct i2cbus_attach_args iba = { + .iba_tag = &sc->sc_ic, + }; + config_found(self, &iba, iicbus_print, + CFARGS(.devhandle = device_handle(self))); } static int Index: arch/macppc/conf/POWERMAC_G5 =================================================================== RCS file: /cvsroot/src/sys/arch/macppc/conf/POWERMAC_G5,v retrieving revision 1.49 retrieving revision 1.49.12.1 diff -u -p -r1.49 -r1.49.12.1 --- arch/macppc/conf/POWERMAC_G5 2 Apr 2021 09:27:32 -0000 1.49 +++ arch/macppc/conf/POWERMAC_G5 9 Aug 2021 00:30:08 -0000 1.49.12.1 @@ -131,8 +131,7 @@ ibmcpc* at mainbus? uninorth* at mainbus? smu* at mainbus? #options SMU_DEBUG -smuiic* at smu? -iic* at smuiic? +iic* at smu? pci* at ibmcpc? bus ? Index: arch/macppc/conf/POWERMAC_G5_11_2 =================================================================== RCS file: /cvsroot/src/sys/arch/macppc/conf/POWERMAC_G5_11_2,v retrieving revision 1.20 retrieving revision 1.20.16.1 diff -u -p -r1.20 -r1.20.16.1 --- arch/macppc/conf/POWERMAC_G5_11_2 7 Jul 2020 02:39:59 -0000 1.20 +++ arch/macppc/conf/POWERMAC_G5_11_2 9 Aug 2021 00:30:08 -0000 1.20.16.1 @@ -117,8 +117,7 @@ ki2c* at uni_n? # Keywest I2C smu* at mainbus? #options SMU_DEBUG -smuiic* at smu? -iic* at smuiic? +iic* at smu? pci* at ibmcpc? bus ? pci* at uninorth? bus ? Index: arch/macppc/conf/files.macppc =================================================================== RCS file: /cvsroot/src/sys/arch/macppc/conf/files.macppc,v retrieving revision 1.121 retrieving revision 1.121.6.1 diff -u -p -r1.121 -r1.121.6.1 --- arch/macppc/conf/files.macppc 27 Jul 2021 23:38:42 -0000 1.121 +++ arch/macppc/conf/files.macppc 9 Aug 2021 00:30:08 -0000 1.121.6.1 @@ -1,4 +1,4 @@ -# $NetBSD: files.macppc,v 1.121 2021/07/27 23:38:42 macallan Exp $ +# $NetBSD: files.macppc,v 1.121.6.1 2021/08/09 00:30:08 thorpej Exp $ # # macppc-specific configuration info @@ -180,15 +180,11 @@ define fancontrol file arch/macppc/dev/fancontrol.c fancontrol defflag opt_fancontrol.h FANCONTROL_DEBUG -device smu { } : fancontrol +device smu: i2cbus, fancontrol attach smu at mainbus file arch/macppc/dev/smu.c smu needs-flag defflag opt_smu.h SMU_DEBUG -device smuiic: i2cbus -attach smuiic at smu -file arch/macppc/dev/smuiic.c smuiic - device smusat attach smusat at iic file arch/macppc/dev/smusat.c smusat Index: arch/macppc/dev/pmu.c =================================================================== RCS file: /cvsroot/src/sys/arch/macppc/dev/pmu.c,v retrieving revision 1.39 retrieving revision 1.39.2.1 diff -u -p -r1.39 -r1.39.2.1 --- arch/macppc/dev/pmu.c 7 Aug 2021 16:18:58 -0000 1.39 +++ arch/macppc/dev/pmu.c 9 Aug 2021 00:30:08 -0000 1.39.2.1 @@ -1,4 +1,4 @@ -/* $NetBSD: pmu.c,v 1.39 2021/08/07 16:18:58 thorpej Exp $ */ +/* $NetBSD: pmu.c,v 1.39.2.1 2021/08/09 00:30:08 thorpej Exp $ */ /*- * Copyright (c) 2006 Michael Lorenz @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pmu.c,v 1.39 2021/08/07 16:18:58 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pmu.c,v 1.39.2.1 2021/08/09 00:30:08 thorpej Exp $"); #include #include @@ -90,6 +90,7 @@ struct pmu_softc { struct sysmon_pswitch sc_powerbutton; bus_space_tag_t sc_memt; bus_space_handle_t sc_memh; + uint32_t sc_flags; #define PMU_HAS_BACKLIGHT_CONTROL 1 int sc_node; @@ -267,7 +268,6 @@ pmu_attach(device_t parent, device_t sel 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,64 +340,16 @@ pmu_attach(device_t parent, device_t sel goto next; if (strncmp(name, "pmu-i2c", 8) == 0) { - int devs, sensors; - 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); - - /* 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); - sensors = OF_child(devs); - while (sensors != 0) { - int reg; - char loc[64]; - char pname[8]; - if (OF_getprop(sensors, "reg", ®, 4) != 4) - goto nope; - if (OF_getprop(sensors, "location", loc, 63) <= 0) - goto nope; - snprintf(pname, 7, "s%02x", reg); - prop_dictionary_set_string(dev, pname, loc); - nope: - sensors = OF_peer(sensors); - } - 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, - CFARGS(.iattr = "i2cbus")); + CFARGS(.iattr = "i2cbus", + .devhandle = devhandle_from_of(node))); goto next; } if (strncmp(name, "adb", 4) == 0) { Index: arch/macppc/dev/smu.c =================================================================== RCS file: /cvsroot/src/sys/arch/macppc/dev/smu.c,v retrieving revision 1.14 retrieving revision 1.14.2.1 diff -u -p -r1.14 -r1.14.2.1 --- arch/macppc/dev/smu.c 7 Aug 2021 16:18:58 -0000 1.14 +++ arch/macppc/dev/smu.c 9 Aug 2021 00:30:08 -0000 1.14.2.1 @@ -1,3 +1,5 @@ +/* $NetBSD: smu.c,v 1.14.2.1 2021/08/09 00:30:08 thorpej Exp $ */ + /*- * Copyright (c) 2013 Phileas Fogg * All rights reserved. @@ -30,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -72,14 +75,15 @@ struct smu_fan { }; struct smu_iicbus { - struct smu_softc* sc; + struct smu_softc *sc; int reg; struct i2c_controller i2c; + + LIST_ENTRY(smu_iicbus) buslist; }; #define SMU_MAX_FANS 8 -#define SMU_MAX_IICBUS 3 #define SMU_MAX_SME_SENSORS (SMU_MAX_FANS + 8) struct smu_zone { @@ -113,8 +117,7 @@ struct smu_softc { int sc_num_fans; struct smu_fan sc_fans[SMU_MAX_FANS]; - int sc_num_iicbus; - struct smu_iicbus sc_iicbus[SMU_MAX_IICBUS]; + LIST_HEAD(, smu_iicbus) sc_iic_busses; struct todr_chip_handle sc_todr; @@ -158,7 +161,6 @@ static int smu_setup_doorbell(struct smu static void smu_setup_fans(struct smu_softc *); static void smu_setup_iicbus(struct smu_softc *); static void smu_setup_sme(struct smu_softc *); -static int smu_iicbus_print(void *, const char *); static void smu_sme_refresh(struct sysmon_envsys *, envsys_data_t *); static int smu_do_cmd(struct smu_softc *, struct smu_cmd *, int); static int smu_dbell_gpio_intr(void *); @@ -445,42 +447,43 @@ static void smu_setup_iicbus(struct smu_softc *sc) { struct smu_iicbus *iicbus; - struct i2c_controller *i2c; - struct smu_iicbus_confargs ca; + struct i2cbus_attach_args iba; int node; char name[32]; node = of_getnode_byname(sc->sc_node, "smu-i2c-control"); - if (node == 0) node = sc->sc_node; - for (node = OF_child(node); - (node != 0) && (sc->sc_num_iicbus < SMU_MAX_IICBUS); - node = OF_peer(node)) { + if (node == 0) + node = sc->sc_node; + + for (node = OF_child(node); node != 0; node = OF_peer(node)) { + memset(name, 0, sizeof(name)); OF_getprop(node, "name", name, sizeof(name)); - if ((strcmp(name, "i2c-bus") != 0) && - (strcmp(name, "i2c") != 0)) + if (strcmp(name, "i2c-bus") != 0 && strcmp(name, "i2c") != 0) continue; - iicbus = &sc->sc_iicbus[sc->sc_num_iicbus]; + iicbus = kmem_zalloc(sizeof(*iicbus), KM_SLEEP); iicbus->sc = sc; - i2c = &iicbus->i2c; - if (OF_getprop(node, "reg", &iicbus->reg, sizeof(iicbus->reg)) <= 0) + if (OF_getprop(node, "reg", &iicbus->reg, + sizeof(iicbus->reg)) <= 0) { + kmem_free(iicbus, sizeof(*iicbus)); continue; + } + LIST_INSERT_HEAD(&sc->sc_iic_busses, iicbus, buslist); DPRINTF("iicbus: reg %x\n", iicbus->reg); - iic_tag_init(i2c); - i2c->ic_cookie = iicbus; - i2c->ic_exec = smu_iicbus_exec; - - ca.ca_name = name; - ca.ca_node = node; - ca.ca_tag = i2c; - config_found(sc->sc_dev, &ca, smu_iicbus_print, - CFARGS(.devhandle = devhandle_from_of(node))); + iic_tag_init(&iicbus->i2c); + iicbus->i2c.ic_cookie = iicbus; + iicbus->i2c.ic_channel = iicbus->reg; + iicbus->i2c.ic_exec = smu_iicbus_exec; + + memset(&iba, 0, sizeof(iba)); + iba.iba_tag = &iicbus->i2c; - sc->sc_num_iicbus++; + config_found(sc->sc_dev, &iba, iicbus_print_multi, + CFARGS(.devhandle = devhandle_from_of(node))); } } @@ -539,17 +542,6 @@ next: } } -static int -smu_iicbus_print(void *aux, const char *smu) -{ - struct smu_iicbus_confargs *ca = aux; - - if (smu) - aprint_normal("%s at %s", ca->ca_name, smu); - - return UNCONF; -} - static void smu_sme_refresh(struct sysmon_envsys *sme, envsys_data_t *edata) { Index: arch/macppc/dev/smuiic.c =================================================================== RCS file: arch/macppc/dev/smuiic.c diff -N arch/macppc/dev/smuiic.c --- arch/macppc/dev/smuiic.c 7 Aug 2021 16:18:58 -0000 1.8 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,135 +0,0 @@ -/* $NetBSD: smuiic.c,v 1.8 2021/08/07 16:18:58 thorpej Exp $ */ - -/*- - * Copyright (c) 2013 Phileas Fogg - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include -#include - -struct smuiic_softc { - device_t sc_dev; - int sc_node; - struct i2c_controller *sc_i2c; -}; - -static int smuiic_match(device_t, struct cfdata *, void *); -static void smuiic_attach(device_t, device_t, void *); - -CFATTACH_DECL_NEW(smuiic, sizeof(struct smuiic_softc), - smuiic_match, smuiic_attach, NULL, NULL); - -static int -smuiic_match(device_t parent, struct cfdata *cf, void *aux) -{ - struct smu_iicbus_confargs *ca = aux; - - if (strcmp(ca->ca_name, "i2c-bus") == 0) - return 5; - if (strcmp(ca->ca_name, "i2c") == 0) - return 5; - - return 0; -} - -static void -smuiic_attach(device_t parent, device_t self, void *aux) -{ - struct smu_iicbus_confargs *ca = aux; - struct smuiic_softc *sc = device_private(self); - struct i2cbus_attach_args iba; - prop_dictionary_t dict = device_properties(self); - int devs, devc; - uint32_t addr; - char compat[256]; - prop_array_t cfg; - prop_dictionary_t dev; - prop_data_t data; - char name[32], descr[32], num[8]; - - sc->sc_dev = self; - sc->sc_node = ca->ca_node; - sc->sc_i2c = ca->ca_tag; - printf("\n"); - - cfg = prop_array_create(); - prop_dictionary_set(dict, "i2c-child-devices", cfg); - prop_object_release(cfg); - - /* look for i2c devices */ - devs = OF_child(sc->sc_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; - 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); - devc = OF_child(devs); - while (devc != 0) { - int reg; - if (OF_getprop(devc, "reg", ®, 4) < 4) goto nope; - if (OF_getprop(devc, "location", descr, 32) <= 0) - goto nope; - printf("found '%s' at %02x\n", descr, reg); - snprintf(num, 7, "s%02x", reg); - prop_dictionary_set_string(dev, num, descr); - nope: - devc = OF_peer(devc); - } - 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; - - config_found(sc->sc_dev, &iba, iicbus_print, CFARGS_NONE); -} Index: arch/macppc/dev/smuiicvar.h =================================================================== RCS file: arch/macppc/dev/smuiicvar.h diff -N arch/macppc/dev/smuiicvar.h --- arch/macppc/dev/smuiicvar.h 6 Jun 2017 15:58:17 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,38 +0,0 @@ -/*- - * Copyright (c) 2013 Phileas Fogg - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS - * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED - * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR - * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS - * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -#include - -struct smuiic_confargs { - char *ca_name; - int ca_node; - i2c_addr_t ca_addr; - i2c_tag_t ca_tag; -}; Index: arch/sparc64/dev/jbus-i2c.c =================================================================== RCS file: /cvsroot/src/sys/arch/sparc64/dev/jbus-i2c.c,v retrieving revision 1.7 retrieving revision 1.7.2.1 diff -u -p -r1.7 -r1.7.2.1 --- arch/sparc64/dev/jbus-i2c.c 7 Aug 2021 16:19:05 -0000 1.7 +++ arch/sparc64/dev/jbus-i2c.c 9 Aug 2021 00:30:08 -0000 1.7.2.1 @@ -1,4 +1,4 @@ -/* $NetBSD: jbus-i2c.c,v 1.7 2021/08/07 16:19:05 thorpej Exp $ */ +/* $NetBSD: jbus-i2c.c,v 1.7.2.1 2021/08/09 00:30:08 thorpej Exp $ */ /* * Copyright (c) 2018 Michael Lorenz @@ -27,7 +27,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: jbus-i2c.c,v 1.7 2021/08/07 16:19:05 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: jbus-i2c.c,v 1.7.2.1 2021/08/09 00:30:08 thorpej Exp $"); #include #include @@ -79,11 +79,8 @@ struct jbusi2c_softc { struct i2c_controller sc_i2c; bus_space_tag_t sc_bustag; bus_space_handle_t sc_regh; - int sc_node; }; -static void jbusi2c_setup_i2c(struct jbusi2c_softc *); - CFATTACH_DECL_NEW(jbusi2c, sizeof(struct jbusi2c_softc), jbusi2c_match, jbusi2c_attach, NULL, NULL); @@ -112,11 +109,11 @@ jbusi2c_attach(device_t parent, device_t { struct jbusi2c_softc *sc = device_private(self); struct mainbus_attach_args *ma = aux; + struct i2cbus_attach_args iba; aprint_normal(": addr %" PRIx64 "\n", ma->ma_reg[0].ur_paddr); sc->sc_dev = self; - sc->sc_node = ma->ma_node; sc->sc_bustag = ma->ma_bustag; if (bus_space_map(sc->sc_bustag, ma->ma_reg[0].ur_paddr, 16, 0, @@ -125,21 +122,6 @@ jbusi2c_attach(device_t parent, device_t return; } - jbusi2c_setup_i2c(sc); -} - - - -static void -jbusi2c_setup_i2c(struct jbusi2c_softc *sc) -{ - struct i2cbus_attach_args iba; - prop_array_t cfg; - prop_dictionary_t dev; - prop_dictionary_t dict = device_properties(sc->sc_dev); - int devs, regs[2], addr; - char name[64], compat[256]; - iic_tag_init(&sc->sc_i2c); sc->sc_i2c.ic_cookie = sc; sc->sc_i2c.ic_send_start = jbusi2c_i2c_send_start; @@ -148,37 +130,10 @@ jbusi2c_setup_i2c(struct jbusi2c_softc * sc->sc_i2c.ic_read_byte = jbusi2c_i2c_read_byte; sc->sc_i2c.ic_write_byte = jbusi2c_i2c_write_byte; - /* round up i2c devices */ - devs = OF_child(sc->sc_node); - cfg = prop_array_create(); - prop_dictionary_set(dict, "i2c-child-devices", cfg); - prop_object_release(cfg); - while (devs != 0) { - if (OF_getprop(devs, "name", name, 256) <= 0) - goto skip; - memset(compat, 0, sizeof(compat)); - if (OF_getprop(devs, "compatible", - compat, 255) <= 0) - goto skip; - if (OF_getprop(devs, "reg", regs, 8) <= 0) - goto skip; - if (regs[0] != 0) goto skip; - addr = (regs[1] & 0xff) >> 1; - DPRINTF("-> %s@%d,%x\n", name, regs[0], addr); - dev = prop_dictionary_create(); - prop_dictionary_set_string(dev, "name", name); - prop_dictionary_set_data(dev, "compatible", compat, - strlen(compat)+1); - 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; - config_found(sc->sc_dev, &iba, iicbus_print, CFARGS_NONE); + config_found(sc->sc_dev, &iba, iicbus_print, + CFARGS(.devhandle = device_handle(self))); } static inline void Index: arch/sparc64/dev/pcfiic_ebus.c =================================================================== RCS file: /cvsroot/src/sys/arch/sparc64/dev/pcfiic_ebus.c,v retrieving revision 1.7 retrieving revision 1.7.16.1 diff -u -p -r1.7 -r1.7.16.1 --- arch/sparc64/dev/pcfiic_ebus.c 23 Oct 2020 15:18:10 -0000 1.7 +++ arch/sparc64/dev/pcfiic_ebus.c 9 Aug 2021 00:30:08 -0000 1.7.16.1 @@ -1,7 +1,36 @@ -/* $NetBSD: pcfiic_ebus.c,v 1.7 2020/10/23 15:18:10 jdc Exp $ */ +/* $NetBSD: pcfiic_ebus.c,v 1.7.16.1 2021/08/09 00:30:08 thorpej Exp $ */ /* $OpenBSD: pcfiic_ebus.c,v 1.13 2008/06/08 03:07:40 deraadt Exp $ */ /* + * Copyright (c) 2021 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* * Copyright (c) 2006 David Gwynne * * Permission to use, copy, modify, and distribute this software for any @@ -18,7 +47,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: pcfiic_ebus.c,v 1.7 2020/10/23 15:18:10 jdc Exp $"); +__KERNEL_RCSID(0, "$NetBSD: pcfiic_ebus.c,v 1.7.16.1 2021/08/09 00:30:08 thorpej Exp $"); /* * Device specific driver for the EBus i2c devices found on some sun4u @@ -30,7 +59,8 @@ __KERNEL_RCSID(0, "$NetBSD: pcfiic_ebus. #include #include #include -#include +#include +#include #include #include @@ -44,20 +74,119 @@ __KERNEL_RCSID(0, "$NetBSD: pcfiic_ebus. #include #include -int pcfiic_ebus_match(device_t, struct cfdata *, void *); -void pcfiic_ebus_attach(device_t, device_t, void *); - struct pcfiic_ebus_softc { struct pcfiic_softc esc_sc; - int esc_node; + kmutex_t esc_ctrl_lock; + bus_space_handle_t esc_ioh; /* for channel selection */ + void *esc_ih; }; -CFATTACH_DECL_NEW(pcfiic, sizeof(struct pcfiic_ebus_softc), - pcfiic_ebus_match, pcfiic_ebus_attach, NULL, NULL); +static void +bbc_select_channel(struct pcfiic_ebus_softc *esc, uint8_t channel) +{ + bus_space_write_1(esc->esc_sc.sc_iot, esc->esc_ioh, 0, channel); + bus_space_barrier(esc->esc_sc.sc_iot, esc->esc_ioh, 0, 1, + BUS_SPACE_BARRIER_WRITE); +} + +static int +bbc_acquire_bus(void *v, int flags) +{ + struct pcfiic_channel *ch = v; + struct pcfiic_ebus_softc *esc = container_of(ch->ch_sc, + struct pcfiic_ebus_softc, esc_sc); + + if (flags & I2C_F_POLL) { + if (! mutex_tryenter(&esc->esc_ctrl_lock)) { + return EBUSY; + } + } else { + mutex_enter(&esc->esc_ctrl_lock); + } + + bbc_select_channel(esc, (uint8_t)ch->ch_channel); + return 0; +} + +static void +bbc_release_bus(void *v, int flags) +{ + struct pcfiic_channel *ch = v; + struct pcfiic_ebus_softc *esc = container_of(ch->ch_sc, + struct pcfiic_ebus_softc, esc_sc); -int + mutex_exit(&esc->esc_ctrl_lock); +} + +static void +bbc_initialize_channels(struct pcfiic_ebus_softc *esc) +{ + struct pcfiic_softc *sc = &esc->esc_sc; + struct pcfiic_channel *ch; + devhandle_t devhandle = device_handle(sc->sc_dev); + unsigned int busmap = 0; + int node = devhandle_to_of(devhandle); + uint32_t reg[2]; + uint32_t channel; + int i, nchannels; + + /* + * Two physical I2C busses share a single controller. The + * devices are not distinct, so it's not easy to treat it + * it as a mux. + * + * The locking order is: + * + * iic bus mutex -> ctrl_lock + * + * ctrl_lock is taken in bbc_acquire_bus. + */ + mutex_init(&esc->esc_ctrl_lock, MUTEX_DEFAULT, IPL_NONE); + sc->sc_acquire_bus = bbc_acquire_bus; + sc->sc_release_bus = bbc_release_bus; + + /* + * The Sun device tree has all devices, no matter the + * channel, as direct children of this node. Figure + * out which channel numbers are listed, count them, + * and then populate the channel structures. + */ + for (node = OF_child(node); node != 0; node = OF_peer(node)) { + if (OF_getprop(node, "reg", reg, sizeof(reg)) != sizeof(reg)) { + continue; + } + + /* Channel is in the first cell. */ + channel = be32toh(reg[0]); + KASSERT(channel < 32); + + busmap |= __BIT(channel); + } + + nchannels = popcount(busmap); + if (nchannels == 0) { + /* No child devices. */ + return; + } + + ch = kmem_alloc(nchannels * sizeof(*ch), KM_SLEEP); + for (i = 0; i < nchannels; i++) { + channel = ffs(busmap); + KASSERT(channel != 0); + channel--; /* ffs() returns 0 if no bits set. */ + busmap &= ~__BIT(channel); + + ch[i].ch_channel = channel; + ch[i].ch_devhandle = devhandle; + } + + sc->sc_channels = ch; + sc->sc_nchannels = nchannels; +} + +static int pcfiic_ebus_match(device_t parent, struct cfdata *match, void *aux) { struct ebus_attach_args *ea = aux; @@ -82,15 +211,15 @@ pcfiic_ebus_match(device_t parent, struc return (0); } -void +static void pcfiic_ebus_attach(device_t parent, device_t self, void *aux) { struct pcfiic_ebus_softc *esc = device_private(self); struct pcfiic_softc *sc = &esc->esc_sc; struct ebus_attach_args *ea = aux; char compat[32]; - u_int64_t addr; - u_int8_t clock = PCF8584_CLK_12 | PCF8584_SCL_90; + uint32_t addr[2]; + uint8_t clock = PCF8584_CLK_12 | PCF8584_SCL_90; int swapregs = 0; if (ea->ea_nreg < 1 || ea->ea_nreg > 2) { @@ -121,15 +250,15 @@ pcfiic_ebus_attach(device_t parent, devi } if (OF_getprop(ea->ea_node, "own-address", &addr, sizeof(addr)) == -1) { - addr = 0xaa; - } else if (addr == 0x00 || addr > 0xff) { + addr[0] = 0; + addr[1] = 0x55 << 1; + } else if (addr[1] == 0x00 || addr[1] > 0xff) { printf(": invalid address on I2C bus"); return; } - if (bus_space_map(ea->ea_bustag, - EBUS_ADDR_FROM_REG(&ea->ea_reg[0]), - ea->ea_reg[0].size, 0, &sc->sc_ioh) == 0) { + if (bus_space_map(ea->ea_bustag, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]), + ea->ea_reg[0].size, 0, &sc->sc_ioh) == 0) { sc->sc_iot = ea->ea_bustag; } else { printf(": can't map register space\n"); @@ -140,14 +269,14 @@ pcfiic_ebus_attach(device_t parent, devi /* * Second register only occurs on BBC-based machines, * and is likely not prom mapped - */ - if (bus_space_map(sc->sc_iot, EBUS_ADDR_FROM_REG(&ea->ea_reg[1]), - ea->ea_reg[1].size, 0, &sc->sc_ioh2) != 0) { + */ + if (bus_space_map(sc->sc_iot, + EBUS_ADDR_FROM_REG(&ea->ea_reg[1]), + ea->ea_reg[1].size, 0, &esc->esc_ioh) != 0) { printf(": can't map 2nd register space\n"); return; } - sc->sc_master = 1; - printf(": iic mux present"); + bbc_initialize_channels(esc); } if (ea->ea_nintr >= 1) @@ -156,9 +285,11 @@ pcfiic_ebus_attach(device_t parent, devi else esc->esc_ih = NULL; - if (esc->esc_ih == NULL) sc->sc_poll = 1; - pcfiic_attach(sc, (i2c_addr_t)(addr >> 1), clock, swapregs); + pcfiic_attach(sc, (i2c_addr_t)(addr[1] >> 1), clock, swapregs); } + +CFATTACH_DECL_NEW(pcfiic, sizeof(struct pcfiic_ebus_softc), + pcfiic_ebus_match, pcfiic_ebus_attach, NULL, NULL); Index: arch/x86/pci/dwiic_pci.c =================================================================== RCS file: /cvsroot/src/sys/arch/x86/pci/dwiic_pci.c,v retrieving revision 1.6 retrieving revision 1.6.2.1 diff -u -p -r1.6 -r1.6.2.1 --- arch/x86/pci/dwiic_pci.c 7 Aug 2021 16:19:07 -0000 1.6 +++ arch/x86/pci/dwiic_pci.c 9 Aug 2021 00:30:09 -0000 1.6.2.1 @@ -1,4 +1,4 @@ -/* $NetBSD: dwiic_pci.c,v 1.6 2021/08/07 16:19:07 thorpej Exp $ */ +/* $NetBSD: dwiic_pci.c,v 1.6.2.1 2021/08/09 00:30:09 thorpej Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dwiic_pci.c,v 1.6 2021/08/07 16:19:07 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dwiic_pci.c,v 1.6.2.1 2021/08/09 00:30:09 thorpej Exp $"); #include #include @@ -42,11 +42,6 @@ __KERNEL_RCSID(0, "$NetBSD: dwiic_pci.c, #include #include -#include -#include -#include -#include - #include #include @@ -62,7 +57,6 @@ struct pci_dwiic_softc { struct dwiic_softc sc_dwiic; pci_chipset_tag_t sc_pc; pcitag_t sc_ptag; - struct acpi_devnode *sc_acpinode; }; static uint32_t @@ -164,19 +158,10 @@ pci_dwiic_attach(device_t parent, device lpss_write(sc, LPSS_REMAP_HI, pci_conf_read(sc->sc_pc, sc->sc_ptag, PCI_BAR0 + 0x4)); - sc->sc_acpinode = acpi_pcidev_find(0 /*XXX segment*/, - pa->pa_bus, pa->pa_device, pa->pa_function); - - if (sc->sc_acpinode) { - sc->sc_dwiic.sc_iba.iba_child_devices = - acpi_enter_i2c_devs(NULL, sc->sc_acpinode); - } else { - aprint_verbose_dev(self, "no matching ACPI node\n"); - } - dwiic_attach(&sc->sc_dwiic); - config_found(self, &sc->sc_dwiic.sc_iba, iicbus_print, CFARGS_NONE); + config_found(self, &sc->sc_dwiic.sc_iba, iicbus_print, + CFARGS(.devhandle = device_handle(self))); pmf_device_register(self, dwiic_suspend, dwiic_resume); Index: dev/acpi/dwiic_acpi.c =================================================================== RCS file: /cvsroot/src/sys/dev/acpi/dwiic_acpi.c,v retrieving revision 1.9 retrieving revision 1.9.2.1 diff -u -p -r1.9 -r1.9.2.1 --- dev/acpi/dwiic_acpi.c 7 Aug 2021 16:19:09 -0000 1.9 +++ dev/acpi/dwiic_acpi.c 9 Aug 2021 00:30:09 -0000 1.9.2.1 @@ -1,4 +1,4 @@ -/* $NetBSD: dwiic_acpi.c,v 1.9 2021/08/07 16:19:09 thorpej Exp $ */ +/* $NetBSD: dwiic_acpi.c,v 1.9.2.1 2021/08/09 00:30:09 thorpej Exp $ */ /*- * Copyright (c) 2018 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c,v 1.9 2021/08/07 16:19:09 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c,v 1.9.2.1 2021/08/09 00:30:09 thorpej Exp $"); #include #include @@ -40,7 +40,6 @@ __KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c #include #include #include -#include #include @@ -125,11 +124,10 @@ dwiic_acpi_attach(device_t parent, devic dwiic_acpi_configure(sc, aa->aa_node->ad_handle); - sc->sc_iba.iba_child_devices = acpi_enter_i2c_devs(self, aa->aa_node); - dwiic_attach(sc); - config_found(self, &sc->sc_iba, iicbus_print, CFARGS_NONE); + config_found(self, &sc->sc_iba, iicbus_print, + CFARGS(.devhandle = device_handle(self))); pmf_device_register(self, dwiic_suspend, dwiic_resume); Index: dev/acpi/nxpiic_acpi.c =================================================================== RCS file: /cvsroot/src/sys/dev/acpi/nxpiic_acpi.c,v retrieving revision 1.4 retrieving revision 1.4.16.1 diff -u -p -r1.4 -r1.4.16.1 --- dev/acpi/nxpiic_acpi.c 29 Jan 2021 02:26:58 -0000 1.4 +++ dev/acpi/nxpiic_acpi.c 9 Aug 2021 00:30:09 -0000 1.4.16.1 @@ -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.4.16.1 2021/08/09 00:30:09 thorpej Exp $ */ /*- * Copyright (c) 2021 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__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.4.16.1 2021/08/09 00:30:09 thorpej Exp $"); #include #include @@ -40,7 +40,6 @@ __KERNEL_RCSID(0, "$NetBSD: nxpiic_acpi. #include #include #include -#include #include #include @@ -148,7 +147,6 @@ nxpiic_acpi_attach(device_t parent, devi 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); motoi2c_attach_common(self, msc, &settings); Index: dev/fdt/dwiic_fdt.c =================================================================== RCS file: /cvsroot/src/sys/dev/fdt/dwiic_fdt.c,v retrieving revision 1.4 retrieving revision 1.4.14.1 diff -u -p -r1.4 -r1.4.14.1 --- dev/fdt/dwiic_fdt.c 27 Jan 2021 03:10:21 -0000 1.4 +++ dev/fdt/dwiic_fdt.c 9 Aug 2021 00:30:09 -0000 1.4.14.1 @@ -1,4 +1,4 @@ -/* $NetBSD: dwiic_fdt.c,v 1.4 2021/01/27 03:10:21 thorpej Exp $ */ +/* $NetBSD: dwiic_fdt.c,v 1.4.14.1 2021/08/09 00:30:09 thorpej Exp $ */ /*- * Copyright (c) 2017 The NetBSD Foundation, Inc. @@ -33,7 +33,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: dwiic_fdt.c,v 1.4 2021/01/27 03:10:21 thorpej Exp $"); +__KERNEL_RCSID(0, "$NetBSD: dwiic_fdt.c,v 1.4.14.1 2021/08/09 00:30:09 thorpej Exp $"); #include #include @@ -111,7 +111,11 @@ dwiic_fdt_attach(device_t parent, device fdtbus_register_i2c_controller(&sc->sc_dwiic.sc_i2c_tag, phandle); - fdtbus_attach_i2cbus(self, phandle, &sc->sc_dwiic.sc_i2c_tag, iicbus_print); + struct i2cbus_attach_args iba = { + .iba_tag = &sc->sc_dwiic.sc_i2c_tag, + }; + config_found(self, &iba, iicbus_print, + CFARGS(.devhandle = device_handle(self))); out: return; Index: dev/i2c/motoi2c.c =================================================================== RCS file: /cvsroot/src/sys/dev/i2c/motoi2c.c,v retrieving revision 1.12 retrieving revision 1.12.2.1 diff -u -p -r1.12 -r1.12.2.1 --- dev/i2c/motoi2c.c 7 Aug 2021 16:19:11 -0000 1.12 +++ dev/i2c/motoi2c.c 9 Aug 2021 00:30:09 -0000 1.12.2.1 @@ -1,4 +1,4 @@ -/* $NetBSD: motoi2c.c,v 1.12 2021/08/07 16:19:11 thorpej Exp $ */ +/* $NetBSD: motoi2c.c,v 1.12.2.1 2021/08/09 00:30:09 thorpej Exp $ */ /*- * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc. @@ -30,7 +30,7 @@ */ #include -__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.12.2.1 2021/08/09 00:30:09 thorpej Exp $"); #if defined(__arm__) || defined(__aarch64__) #include "opt_fdt.h" @@ -107,7 +107,6 @@ motoi2c_attach_common(device_t self, str sc->sc_iowr = motoi2c_iowr1; memset(&iba, 0, sizeof(iba)); iba.iba_tag = &sc->sc_i2c; - iba.iba_child_devices = sc->sc_child_devices; if ((sc->sc_flags & MOTOI2C_F_ENABLE_INV) != 0) { sc->sc_enable_mask = 0; @@ -130,12 +129,11 @@ motoi2c_attach_common(device_t self, str #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, - iicbus_print); - } else + } #endif config_found(self, &iba, iicbus_print, - CFARGS(.iattr = "i2cbus")); + CFARGS(.iattr = "i2cbus", + .devhandle = device_handle(self))); } static int Index: dev/i2c/motoi2cvar.h =================================================================== RCS file: /cvsroot/src/sys/dev/i2c/motoi2cvar.h,v retrieving revision 1.8 retrieving revision 1.8.14.1 diff -u -p -r1.8 -r1.8.14.1 --- dev/i2c/motoi2cvar.h 25 Jan 2021 12:08:47 -0000 1.8 +++ dev/i2c/motoi2cvar.h 9 Aug 2021 00:30:09 -0000 1.8.14.1 @@ -1,4 +1,4 @@ -/* $NetBSD: motoi2cvar.h,v 1.8 2021/01/25 12:08:47 jmcneill Exp $ */ +/* $NetBSD: motoi2cvar.h,v 1.8.14.1 2021/08/09 00:30:09 thorpej Exp $ */ /*- * Copyright (c) 2007, 2010 The NetBSD Foundation, Inc. @@ -51,7 +51,6 @@ struct motoi2c_softc { motoi2c_iord_t sc_iord; motoi2c_iowr_t sc_iowr; int sc_phandle; - prop_array_t sc_child_devices; int sc_flags; #define MOTOI2C_F_ENABLE_INV __BIT(0) #define MOTOI2C_F_STATUS_W1C __BIT(1) Index: dev/ic/pcf8584.c =================================================================== RCS file: /cvsroot/src/sys/dev/ic/pcf8584.c,v retrieving revision 1.19 retrieving revision 1.19.2.1 diff -u -p -r1.19 -r1.19.2.1 --- dev/ic/pcf8584.c 7 Aug 2021 16:19:12 -0000 1.19 +++ dev/ic/pcf8584.c 9 Aug 2021 01:29:52 -0000 1.19.2.1 @@ -1,7 +1,36 @@ -/* $NetBSD: pcf8584.c,v 1.19 2021/08/07 16:19:12 thorpej Exp $ */ +/* $NetBSD: pcf8584.c,v 1.19.2.1 2021/08/09 01:29:52 thorpej Exp $ */ /* $OpenBSD: pcf8584.c,v 1.9 2007/10/20 18:46:21 kettenis Exp $ */ /* + * Copyright (c) 2021 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* * Copyright (c) 2006 David Gwynne * * Permission to use, copy, modify, and distribute this software for any @@ -20,7 +49,7 @@ #include #include #include -#include +#include #include #include #include @@ -30,6 +59,8 @@ #include #include +#include "locators.h" + /* Internal registers */ #define PCF8584_S0 0x00 #define PCF8584_S1 0x01 @@ -37,8 +68,6 @@ #define PCF8584_S3 0x03 void pcfiic_init(struct pcfiic_softc *); -int pcfiic_i2c_acquire_bus(void *, int); -void pcfiic_i2c_release_bus(void *, int); int pcfiic_i2c_exec(void *, i2c_op_t, i2c_addr_t, const void *, size_t, void *, size_t, int); @@ -49,7 +78,6 @@ int pcfiic_recv(struct pcfiic_softc *, u_int8_t pcfiic_read(struct pcfiic_softc *, bus_size_t); void pcfiic_write(struct pcfiic_softc *, bus_size_t, u_int8_t); -void pcfiic_choose_bus(struct pcfiic_softc *, u_int8_t); int pcfiic_wait_BBN(struct pcfiic_softc *); int pcfiic_wait_pin(struct pcfiic_softc *, volatile u_int8_t *); @@ -71,10 +99,12 @@ pcfiic_init(struct pcfiic_softc *sc) } void -pcfiic_attach(struct pcfiic_softc *sc, i2c_addr_t addr, u_int8_t clock, +pcfiic_attach(struct pcfiic_softc *sc, i2c_addr_t addr, uint8_t clock, int swapregs) { - struct i2cbus_attach_args iba; + struct i2cbus_attach_args iba; + struct pcfiic_channel *ch; + int i; if (swapregs) { sc->sc_regmap[PCF8584_S1] = PCF8584_S0; @@ -90,16 +120,39 @@ pcfiic_attach(struct pcfiic_softc *sc, i printf("\n"); - if (sc->sc_master) - pcfiic_choose_bus(sc, 0); + if (sc->sc_channels == NULL) { + KASSERT(sc->sc_nchannels == 0); + ch = kmem_alloc(sizeof(*sc->sc_channels), KM_SLEEP); + ch->ch_channel = 0; + ch->ch_devhandle = device_handle(sc->sc_dev); - iic_tag_init(&sc->sc_i2c); - sc->sc_i2c.ic_cookie = sc; - sc->sc_i2c.ic_exec = pcfiic_i2c_exec; - - bzero(&iba, sizeof(iba)); - iba.iba_tag = &sc->sc_i2c; - config_found(sc->sc_dev, &iba, iicbus_print, CFARGS_NONE); + sc->sc_channels = ch; + sc->sc_nchannels = 1; + } else { + KASSERT(sc->sc_nchannels != 0); + } + + for (i = 0; i < sc->sc_nchannels; i++) { + int locs[I2CBUSCF_NLOCS]; + + ch = &sc->sc_channels[i]; + ch->ch_sc = sc; + iic_tag_init(&ch->ch_i2c); + ch->ch_i2c.ic_cookie = ch; + ch->ch_i2c.ic_exec = pcfiic_i2c_exec; + ch->ch_i2c.ic_acquire_bus = sc->sc_acquire_bus; + ch->ch_i2c.ic_release_bus = sc->sc_release_bus; + + locs[I2CBUSCF_BUS] = ch->ch_i2c.ic_channel; + + memset(&iba, 0, sizeof(iba)); + iba.iba_tag = &ch->ch_i2c; + config_found(sc->sc_dev, &iba, + sc->sc_nchannels == 1 ? iicbus_print : iicbus_print_multi, + CFARGS(.submatch = config_stdsubmatch, + .locators = locs, + .devhandle = ch->ch_devhandle)); + } } int @@ -123,9 +176,6 @@ pcfiic_i2c_exec(void *arg, i2c_op_t op, if (sc->sc_poll) flags |= I2C_F_POLL; - if (sc->sc_master) - pcfiic_choose_bus(sc, addr >> 7); - /* * If we are writing, write address, cmdbuf, buf. * If we are reading, write address, cmdbuf, then read address, buf. @@ -224,14 +274,6 @@ pcfiic_write(struct pcfiic_softc *sc, bu (void)bus_space_read_1(sc->sc_iot, sc->sc_ioh, PCF8584_S1); } -void -pcfiic_choose_bus(struct pcfiic_softc *sc, u_int8_t bus) -{ - bus_space_write_1(sc->sc_iot, sc->sc_ioh2, 0, bus); - bus_space_barrier(sc->sc_iot, sc->sc_ioh2, 0, 1, - BUS_SPACE_BARRIER_WRITE); -} - int pcfiic_wait_BBN(struct pcfiic_softc *sc) { Index: dev/ic/pcf8584var.h =================================================================== RCS file: /cvsroot/src/sys/dev/ic/pcf8584var.h,v retrieving revision 1.6 retrieving revision 1.6.22.1 diff -u -p -r1.6 -r1.6.22.1 --- dev/ic/pcf8584var.h 22 Dec 2019 23:23:32 -0000 1.6 +++ dev/ic/pcf8584var.h 9 Aug 2021 01:29:52 -0000 1.6.22.1 @@ -1,4 +1,4 @@ -/* $NetBSD: pcf8584var.h,v 1.6 2019/12/22 23:23:32 thorpej Exp $ */ +/* $NetBSD: pcf8584var.h,v 1.6.22.1 2021/08/09 01:29:52 thorpej Exp $ */ /* $OpenBSD: pcf8584var.h,v 1.5 2007/10/20 18:46:21 kettenis Exp $ */ /* @@ -17,21 +17,41 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifndef _DEV_IC_PCF8584VAR_H_ +#define _DEV_IC_PCF8584VAR_H_ + +struct pcfiic_channel { + struct i2c_controller ch_i2c; + struct pcfiic_softc *ch_sc; + devhandle_t ch_devhandle; + int ch_channel; +}; + struct pcfiic_softc { device_t sc_dev; bus_space_tag_t sc_iot; bus_space_handle_t sc_ioh; - bus_space_handle_t sc_ioh2; - int sc_master; - u_int8_t sc_addr; - u_int8_t sc_clock; - u_int8_t sc_regmap[2]; + uint8_t sc_addr; + uint8_t sc_clock; + uint8_t sc_regmap[2]; int sc_poll; - struct i2c_controller sc_i2c; + /* + * Some Sun clones of the this i2c controller support + * multiple channels. The specific attachment will + * initialize these fields for controllers that support + * this. If not, the core driver will assume a single + * channel. + */ + struct pcfiic_channel *sc_channels; + int sc_nchannels; + int (*sc_acquire_bus)(void *, int); + void (*sc_release_bus)(void *, int); }; -void pcfiic_attach(struct pcfiic_softc *, i2c_addr_t, u_int8_t, int); +void pcfiic_attach(struct pcfiic_softc *, i2c_addr_t, uint8_t, int); int pcfiic_intr(void *); + +#endif /* _DEV_IC_PCF8584VAR_H_ */