CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/ofw

2021-08-07 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Aug  8 01:06:57 UTC 2021

Modified Files:
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c

Log Message:
If OFW_I2C_ALLOW_MISSING_COMPATIBLE_PROPERTY, ensure that clist_size
is not negative for the call to kmem_tmpbuf_alloc().


To generate a diff of this commit:
cvs rdiff -u -r1.1.6.8 -r1.1.6.9 src/sys/dev/ofw/ofw_i2c_subr.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/dev/ofw/ofw_i2c_subr.c
diff -u src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.8 src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.9
--- src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.8	Tue May 18 01:24:39 2021
+++ src/sys/dev/ofw/ofw_i2c_subr.c	Sun Aug  8 01:06:57 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.8 2021/05/18 01:24:39 thorpej Exp $	*/
+/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.9 2021/08/08 01:06:57 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.8 2021/05/18 01:24:39 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.9 2021/08/08 01:06:57 thorpej Exp $");
 
 #include 
 #include 
@@ -149,11 +149,13 @@ of_i2c_enumerate_devices(device_t dev, d
 		}
 
 		clist_size = OF_getproplen(node, "compatible");
-#ifndef OFW_I2C_ALLOW_MISSING_COMPATIBLE_PROPERTY
 		if (clist_size <= 0) {
+#ifndef OFW_I2C_ALLOW_MISSING_COMPATIBLE_PROPERTY
 			continue;
-		}
+#else
+			clist_size = 0;
 #endif
+		}
 		clist = kmem_tmpbuf_alloc(clist_size,
 		compat_buf, sizeof(compat_buf), KM_SLEEP);
 		if (OF_getprop(node, "compatible", clist, clist_size) <



CVS commit: [thorpej-i2c-spi-conf] src/sys

2021-08-01 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Aug  1 22:42:46 UTC 2021

Modified Files:
src/sys/altq [thorpej-i2c-spi-conf]: altq_cbq.c altq_cbq.h
altq_rmclass.c altq_rmclass.h
src/sys/arch/aarch64/aarch64 [thorpej-i2c-spi-conf]: cpu.c
src/sys/arch/aarch64/conf [thorpej-i2c-spi-conf]: files.aarch64
majors.aarch64
src/sys/arch/aarch64/include [thorpej-i2c-spi-conf]: armreg.h
src/sys/arch/acorn32/podulebus [thorpej-i2c-spi-conf]: if_ie.c
src/sys/arch/algor/conf [thorpej-i2c-spi-conf]: P4032 P5064 P6032
majors.algor
src/sys/arch/alpha/alpha [thorpej-i2c-spi-conf]: autoconf.c
core_machdep.c db_disasm.c db_instruction.h db_trace.c
dec_alphabook1.c dec_axppci_33.c dec_eb66.c dec_kn300.c
fp_complete.c genassym.cf interrupt.c lock_stubs.s locore.s
machdep.c mainbus.c patch.c pmap.c trap.c vm_machdep.c
src/sys/arch/alpha/common [thorpej-i2c-spi-conf]: bus_dma.c
sgmap_common.c sgmap_typedep.c shared_intr.c
src/sys/arch/alpha/conf [thorpej-i2c-spi-conf]: GENERIC INSTALL
majors.alpha std.alpha
src/sys/arch/alpha/include [thorpej-i2c-spi-conf]: alpha.h bus_defs.h
cpu.h fpu.h intr.h mutex.h param.h pci_machdep.h proc.h rwlock.h
src/sys/arch/alpha/isa [thorpej-i2c-spi-conf]: isapnp_machdep.c
src/sys/arch/alpha/jensenio [thorpej-i2c-spi-conf]:
jensenio_bus_intio.c jensenio_bus_io.c jensenio_bus_mem.c
jensenio_dma.c jensenio_intr.c
src/sys/arch/alpha/mcbus [thorpej-i2c-spi-conf]: mcbus.c mcmem.c
src/sys/arch/alpha/pci [thorpej-i2c-spi-conf]: apecs.c apecs_bus_io.c
apecs_bus_mem.c apecs_dma.c apecs_pci.c cia.c cia_bwx_bus_io.c
cia_bwx_bus_mem.c cia_dma.c cia_pci.c cia_swiz_bus_io.c
cia_swiz_bus_mem.c ciavar.h dwlpx.c dwlpx_bus_io.c dwlpx_bus_mem.c
dwlpx_dma.c dwlpx_pci.c irongate.c irongate_bus_io.c
irongate_bus_mem.c irongate_dma.c irongate_pci.c lca.c lca_bus_io.c
lca_bus_mem.c lca_dma.c lca_pci.c lcareg.h lcavar.h mcpcia.c
mcpcia_bus_io.c mcpcia_bus_mem.c mcpcia_dma.c mcpcia_pci.c
pci_1000.c pci_1000a.c pci_2100_a50.c pci_2100_a500.c
pci_2100_a500.h pci_550.c pci_6600.c pci_alphabook1.c
pci_axppci_33.c pci_eb164.c pci_eb64plus.c pci_eb66.c pci_kn20aa.c
pci_kn300.c pci_kn8ae.c pci_machdep.c pci_sgmap_pte32.c
pci_sgmap_pte64.c pci_up1000.c sio_pic.c sioreg.h siovar.h tsc.c
tsp_bus_io.c tsp_bus_mem.c tsp_dma.c tsp_pci.c tsreg.h tsvar.h
ttwoga.c ttwoga_bus_io.c ttwoga_bus_mem.c ttwoga_pci.c
src/sys/arch/alpha/tc [thorpej-i2c-spi-conf]: tc_bus_mem.c tc_dma.c
tc_dma_3000_500.c tc_sgmap.c
src/sys/arch/alpha/tlsb [thorpej-i2c-spi-conf]: kftxx.c tlsb.c
tlsbmem.c
src/sys/arch/amd64/conf [thorpej-i2c-spi-conf]: ALL XEN3_DOM0
majors.amd64
src/sys/arch/arm/amlogic [thorpej-i2c-spi-conf]: gxlphy.c
src/sys/arch/arm/arm [thorpej-i2c-spi-conf]: cpufunc.c
src/sys/arch/arm/arm32 [thorpej-i2c-spi-conf]: cpu.c
src/sys/arch/arm/broadcom [thorpej-i2c-spi-conf]: bcm2835_gpio.c
src/sys/arch/arm/conf [thorpej-i2c-spi-conf]: majors.arm32
src/sys/arch/arm/dts [thorpej-i2c-spi-conf]:
sun50i-a64-sopine-baseboard.dts
src/sys/arch/arm/fdt [thorpej-i2c-spi-conf]: acpi_fdt.c files.fdt
src/sys/arch/arm/imx [thorpej-i2c-spi-conf]: imx51_ccm.c imx51_ccmreg.h
src/sys/arch/arm/include [thorpej-i2c-spi-conf]: param.h
src/sys/arch/arm/ixp12x0 [thorpej-i2c-spi-conf]: ixp12x0_clk.c
src/sys/arch/arm/nvidia [thorpej-i2c-spi-conf]: tegra_cec.c
src/sys/arch/arm/omap [thorpej-i2c-spi-conf]: omap3_ehci.c
src/sys/arch/arm/rockchip [thorpej-i2c-spi-conf]: rk_anxdp.c
rk_platform.c
src/sys/arch/arm/sunxi [thorpej-i2c-spi-conf]: sunxi_platform.c
src/sys/arch/arm/xscale [thorpej-i2c-spi-conf]: ixp425_npe.c
ixp425_npereg.h
src/sys/arch/atari/pci [thorpej-i2c-spi-conf]: pci_vga.c
src/sys/arch/cats/conf [thorpej-i2c-spi-conf]: GENERIC
src/sys/arch/cesfic/cesfic [thorpej-i2c-spi-conf]: pmap_bootstrap.c
src/sys/arch/cobalt/conf [thorpej-i2c-spi-conf]: majors.cobalt
std.cobalt
src/sys/arch/cobalt/stand/boot [thorpej-i2c-spi-conf]: tlp.c
src/sys/arch/dreamcast/dev [thorpej-i2c-spi-conf]: pvr.c
src/sys/arch/emips/conf [thorpej-i2c-spi-conf]: RAMDISK
src/sys/arch/emips/ebus [thorpej-i2c-spi-conf]: ace_ebus.c flash_ebus.c
src/sys/arch/emips/stand/common [thorpej-i2c-spi-conf]: ace.c raw.c
src/sys/arch/epoc32/conf [thorpej-i2c-spi-conf]: majors.epoc32
src/sys/arch/epoc32/epoc32 [thorpej-i2c-spi-conf]: intr.c
src/sys/arch/evbarm/conf 

CVS commit: [thorpej-i2c-spi-conf] src/sys

2021-06-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu Jun 17 04:46:37 UTC 2021

Modified Files:
src/sys/arch/aarch64/aarch64 [thorpej-i2c-spi-conf]: aarch32_syscall.c
aarch64_machdep.c db_interface.c netbsd32_machdep.c pmap.c
procfs_machdep.c
src/sys/arch/aarch64/conf [thorpej-i2c-spi-conf]: Makefile.aarch64
src/sys/arch/aarch64/include [thorpej-i2c-spi-conf]: cpu.h cpufunc.h
param.h pmap.h
src/sys/arch/algor/conf [thorpej-i2c-spi-conf]: std.algor64
src/sys/arch/alpha/alpha [thorpej-i2c-spi-conf]: autoconf.c locore.s
machdep.c pmap.c vm_machdep.c
src/sys/arch/alpha/conf [thorpej-i2c-spi-conf]: GENERIC
src/sys/arch/alpha/include [thorpej-i2c-spi-conf]: alpha_cpu.h
mcontext.h param.h pci_machdep.h pmap.h
src/sys/arch/alpha/pci [thorpej-i2c-spi-conf]: tsc.c tsp_dma.c tsreg.h
tsvar.h
src/sys/arch/amd64/amd64 [thorpej-i2c-spi-conf]: db_disasm.c
src/sys/arch/amd64/conf [thorpej-i2c-spi-conf]: GENERIC
src/sys/arch/amiga/dev [thorpej-i2c-spi-conf]: amidisplaycc.c kbd.c
ms.c
src/sys/arch/amiga/stand/bootblock/elf2bb [thorpej-i2c-spi-conf]:
elf2bb.c
src/sys/arch/arm/arm32 [thorpej-i2c-spi-conf]: arm32_boot.c cpuswitch.S
src/sys/arch/arm/broadcom [thorpej-i2c-spi-conf]: bcm53xx_eth.c
src/sys/arch/arm/include [thorpej-i2c-spi-conf]: lock.h
src/sys/arch/arm/include/arm32 [thorpej-i2c-spi-conf]: param.h
src/sys/arch/arm/rockchip [thorpej-i2c-spi-conf]: rk3328_cru.c
rk3399_cru.c rk3399_iomux.c rk_cru_composite.c rk_fb.c rk_spi.c
rk_tsadc.c
src/sys/arch/arm/vfp [thorpej-i2c-spi-conf]: vfp_init.c
src/sys/arch/atari/stand/keymaps [thorpej-i2c-spi-conf]: Makefile.inc
src/sys/arch/atari/stand/keymaps/de [thorpej-i2c-spi-conf]: de-kbdmap.c
src/sys/arch/atari/stand/keymaps/fr [thorpej-i2c-spi-conf]: fr-kbdmap.c
src/sys/arch/atari/stand/keymaps/uk [thorpej-i2c-spi-conf]: uk-kbdmap.c
src/sys/arch/atari/stand/keymaps/us [thorpej-i2c-spi-conf]: us-kbdmap.c
src/sys/arch/atari/stand/libsa [thorpej-i2c-spi-conf]: diskio.c
src/sys/arch/cats/include [thorpej-i2c-spi-conf]: param.h
src/sys/arch/emips/include [thorpej-i2c-spi-conf]: types.h
src/sys/arch/epoc32/include [thorpej-i2c-spi-conf]: intr.h
src/sys/arch/evbmips/conf [thorpej-i2c-spi-conf]: MIPSSIM
src/sys/arch/evbppc/conf [thorpej-i2c-spi-conf]: DHT
src/sys/arch/hp300/conf [thorpej-i2c-spi-conf]: GENERIC INSTALL
src/sys/arch/hp300/dev [thorpej-i2c-spi-conf]: rdreg.h rdvar.h
src/sys/arch/hpcarm/include [thorpej-i2c-spi-conf]: intr.h
src/sys/arch/hpcmips/vr [thorpej-i2c-spi-conf]: vrgiu.c
src/sys/arch/hppa/include [thorpej-i2c-spi-conf]: param.h
src/sys/arch/i386/conf [thorpej-i2c-spi-conf]: GENERIC
src/sys/arch/i386/i386 [thorpej-i2c-spi-conf]: db_disasm.c
src/sys/arch/i386/include [thorpej-i2c-spi-conf]: param.h
src/sys/arch/i386/stand/boot [thorpej-i2c-spi-conf]: boot2.c
src/sys/arch/i386/stand/efiboot [thorpej-i2c-spi-conf]: boot.c
src/sys/arch/i386/stand/lib [thorpej-i2c-spi-conf]: biosdisk.c
biosdisk.h exec.c
src/sys/arch/ia64/include [thorpej-i2c-spi-conf]: param.h
src/sys/arch/landisk/stand/boot [thorpej-i2c-spi-conf]: biosdisk.c
src/sys/arch/luna68k/stand/boot [thorpej-i2c-spi-conf]: Makefile sc.c
trap.c ufs_disksubr.c version
src/sys/arch/m68k/conf [thorpej-i2c-spi-conf]: std.m68k
src/sys/arch/m68k/include [thorpej-i2c-spi-conf]: param.h
src/sys/arch/mac68k/obio [thorpej-i2c-spi-conf]: iwm_fd.c
src/sys/arch/macppc/include [thorpej-i2c-spi-conf]: param.h
src/sys/arch/macppc/stand/ofwboot [thorpej-i2c-spi-conf]: ofdev.c
src/sys/arch/mips [thorpej-i2c-spi-conf]: README.models
src/sys/arch/mips/cavium/dev [thorpej-i2c-spi-conf]: if_cnmac.c
octeon_gmx.c
src/sys/arch/mips/conf [thorpej-i2c-spi-conf]: files.mips
src/sys/arch/mips/include [thorpej-i2c-spi-conf]: cpuregs.h
db_machdep.h locore.h mips_param.h netbsd32_machdep.h types.h
src/sys/arch/mips/mips [thorpej-i2c-spi-conf]: cpu_exec.c db_disasm.c
db_interface.c fp.S locore.S mips_emul.c mips_fpu.c mips_fputrap.c
mips_machdep.c netbsd32_machdep.c
src/sys/arch/mipsco/stand [thorpej-i2c-spi-conf]: Makefile.booters
src/sys/arch/ofppc/stand/ofwboot [thorpej-i2c-spi-conf]: mbr.c rdb.c
src/sys/arch/playstation2/conf [thorpej-i2c-spi-conf]: std.playstation2
src/sys/arch/playstation2/ee [thorpej-i2c-spi-conf]: timer.c
src/sys/arch/playstation2/playstation2 [thorpej-i2c-spi-conf]:
interrupt.c
src/sys/arch/powerpc/booke/dev [thorpej-i2c-spi-conf]: pq3etsec.c
 

CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/spi

2021-05-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May 19 14:17:08 UTC 2021

Modified Files:
src/sys/dev/spi [thorpej-i2c-spi-conf]: ssdfb_spi.c

Log Message:
If we were attached via FDT, check for a "dc-gpios" property and,
if present, use the specified GPIO pin for 4-wire mode.


To generate a diff of this commit:
cvs rdiff -u -r1.5.4.1 -r1.5.4.2 src/sys/dev/spi/ssdfb_spi.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/dev/spi/ssdfb_spi.c
diff -u src/sys/dev/spi/ssdfb_spi.c:1.5.4.1 src/sys/dev/spi/ssdfb_spi.c:1.5.4.2
--- src/sys/dev/spi/ssdfb_spi.c:1.5.4.1	Wed May 19 03:46:26 2021
+++ src/sys/dev/spi/ssdfb_spi.c	Wed May 19 14:17:08 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ssdfb_spi.c,v 1.5.4.1 2021/05/19 03:46:26 thorpej Exp $ */
+/* $NetBSD: ssdfb_spi.c,v 1.5.4.2 2021/05/19 14:17:08 thorpej Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,13 +30,20 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ssdfb_spi.c,v 1.5.4.1 2021/05/19 03:46:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ssdfb_spi.c,v 1.5.4.2 2021/05/19 14:17:08 thorpej Exp $");
+
+#include "opt_fdt.h"
 
 #include 
 #include 
 #include 
 #include 
 #include 
+
+#ifdef FDT
+#include 
+#endif /* FDT */
+
 #include 
 #include 
 
@@ -49,6 +56,9 @@ struct bs_state {
 struct ssdfb_spi_softc {
 	struct ssdfb_softc	sc;
 	struct spi_handle	*sc_sh;
+#ifdef FDT
+	struct fdtbus_gpio_pin *sc_dc_gpio;
+#endif /* FDT */
 	bool			sc_3wiremode;
 };
 
@@ -86,10 +96,26 @@ ssdfb_spi_match(device_t parent, cfdata_
 	return spi_compatible_match(sa, match, compat_data);
 }
 
+#ifdef FDT
+static void
+ssdfb_spi_dc_gpio_fdt(struct ssdfb_spi_softc *sc)
+{
+	devhandle_t devhandle = device_handle(sc->sc.sc_dev);
+	int phandle = devhandle_to_of(devhandle);
+
+	sc->sc_dc_gpio = fdtbus_gpio_acquire(phandle, "dc-gpios",
+	GPIO_PIN_OUTPUT);
+	if (sc->sc_dc_gpio != NULL) {
+		sc->sc_3wiremode = false;
+	}
+}
+#endif /* FDT */
+
 static void
 ssdfb_spi_attach(device_t parent, device_t self, void *aux)
 {
 	struct ssdfb_spi_softc *sc = device_private(self);
+	devhandle_t devhandle = device_handle(self);
 	struct cfdata *cf = device_cfdata(self);
 	struct spi_attach_args *sa = aux;
 	int flags = cf->cf_flags;
@@ -98,6 +124,8 @@ ssdfb_spi_attach(device_t parent, device
 	sc->sc.sc_dev = self;
 	sc->sc_sh = sa->sa_handle;
 	sc->sc.sc_cookie = (void *)sc;
+
+	/* XXX Should get this from the device tree. */
 	if ((flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK) == SSDFB_PRODUCT_UNKNOWN)
 		flags |= SSDFB_PRODUCT_SSD1322_GENERIC;
 
@@ -118,11 +146,21 @@ ssdfb_spi_attach(device_t parent, device
 	 * the bit that determines if the lower 8 bits are command or data.
 	 *
 	 * 4 wire mode sends 8 bit sequences and requires an auxiliary GPIO
-	 * pin for the command/data bit. But in other to allocate a GPIO pin
-	 * we need to use fdt, so only support 3 wire mode in this frontend,
-	 * at least for now.
+	 * pin for the command/data bit.
+	 *
+	 * Default to 3 wire mode.  If the device tree specifies a
+	 * D/C GPIO pin, then we will use 4 wire mode.
 	 */
 	sc->sc_3wiremode = true;
+	switch (devhandle_type(devhandle)) {
+#ifdef FDT
+	case DEVHANDLE_TYPE_OF:
+		ssdfb_spi_dc_gpio_fdt(sc);
+		break;
+#endif /* FDT */
+	default:
+		break;
+	}
 
 	switch (flags & SSDFB_ATTACH_FLAG_PRODUCT_MASK) {
 	case SSDFB_PRODUCT_SSD1322_GENERIC:
@@ -265,8 +303,15 @@ ssdfb_bitstream_final(struct bs_state *s
 static void
 ssdfb_spi_4wire_set_dc(struct ssdfb_spi_softc *sc, int value)
 {
+	/* TODO: refactor this if we ever support more that just FDT. */
+
+#ifdef FDT
+	KASSERT(sc->sc_dc_gpio != NULL);
+	fdtbus_gpio_write(sc->sc_dc_gpio, value);
+#else
 	/* TODO: this should toggle an auxilliary GPIO pin */
 	panic("ssdfb_spi_4wire_set_dc");
+#endif /* FDT */
 }
 
 static int



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/spi

2021-05-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May 19 13:40:57 UTC 2021

Modified Files:
src/sys/dev/spi [thorpej-i2c-spi-conf]: mcp3k.c

Log Message:
If we were directly configured using the platform device tree, consult
the device tree for our reference voltage and make the vref sysctl read-only
in that case.  Implement this for the Device Tree bindings for this device
(the "vref-supply" property points to the regulator providing the reference
voltage).


To generate a diff of this commit:
cvs rdiff -u -r1.2.36.2 -r1.2.36.3 src/sys/dev/spi/mcp3k.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/dev/spi/mcp3k.c
diff -u src/sys/dev/spi/mcp3k.c:1.2.36.2 src/sys/dev/spi/mcp3k.c:1.2.36.3
--- src/sys/dev/spi/mcp3k.c:1.2.36.2	Wed May 19 03:46:26 2021
+++ src/sys/dev/spi/mcp3k.c	Wed May 19 13:40:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: mcp3k.c,v 1.2.36.2 2021/05/19 03:46:26 thorpej Exp $ */
+/*	$NetBSD: mcp3k.c,v 1.2.36.3 2021/05/19 13:40:56 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -45,6 +45,8 @@
  * MPC3302/3304: http://ww1.microchip.com/downloads/en/DeviceDoc/21697F.pdf
  */
 
+#include "opt_fdt.h"
+
 #include 
 #include 
 #include 
@@ -55,6 +57,10 @@
 #include 
 #include 
 
+#ifdef FDT
+#include 
+#endif /* FDT */
+
 #define M3K_MAX_SENSORS		16		/* 8 single-ended & 8 diff. */
 
 /* mcp3x0x model description */
@@ -77,6 +83,9 @@ struct mcp3kadc_softc {
 	const struct mcp3kadc_model	*sc_model;
 	uint32_t			sc_adc_max;
 	int32_tsc_vref_mv;
+#ifdef FDT
+	struct fdtbus_regulator		*sc_vref_supply;
+#endif
 
 	struct sysmon_envsys 		*sc_sme;
 	envsys_data_t 			sc_sensors[M3K_MAX_SENSORS];
@@ -247,14 +256,58 @@ mcp3kadc_match(device_t parent, cfdata_t
 	return rv;
 }
 
+#ifdef FDT
+static bool
+mcp3kadc_vref_fdt(struct mcp3kadc_softc *sc)
+{
+	devhandle_t devhandle = device_handle(sc->sc_dev);
+	int phandle = devhandle_to_of(devhandle);
+	int error;
+	u_int uvolts;
+
+	sc->sc_vref_supply = fdtbus_regulator_acquire(phandle, "vref-supply");
+	if (sc->sc_vref_supply == NULL) {
+		aprint_error_dev(sc->sc_dev,
+		"unable to acquire \"vref-supply\"\n");
+		return false;
+	}
+
+	error = fdtbus_regulator_enable(sc->sc_vref_supply);
+	if (error) {
+		aprint_error_dev(sc->sc_dev,
+		"failed to enable \"vref-supply\" (error = %d)\n",
+		error);
+		return false;
+	}
+
+	error = fdtbus_regulator_get_voltage(sc->sc_vref_supply, );
+	if (error) {
+		aprint_error_dev(sc->sc_dev,
+		"unable to get \"vref-supply\" voltage (error = %d)\n",
+		error);
+		(void) fdtbus_regulator_disable(sc->sc_vref_supply);
+		return false;
+	}
+
+	/*
+	 * Device tree property is uV, convert to mV that we use
+	 * internally.
+	 */
+	sc->sc_vref_mv = uvolts / 1000;
+	return true;
+}
+#endif /* FDT */
+
 static void
 mcp3kadc_attach(device_t parent, device_t self, void *aux)
 {
 	const struct sysctlnode *rnode, *node;
 	struct spi_attach_args *sa = aux;
 	struct mcp3kadc_softc *sc = device_private(self);
+	devhandle_t devhandle = device_handle(self);
 	const struct mcp3kadc_model *model;
 	int ch, i, error;
+	bool vref_read_only;
 
 	sc->sc_dev = self;
 	sc->sc_sh = sa->sa_handle;
@@ -277,13 +330,27 @@ mcp3kadc_attach(device_t parent, device_
 		return;
 	}
 
-	/*
-	 * XXX Get vref-supply from device tree and make the sysctl
-	 * XXX read-only in that case.
-	 */
-	/* set a default Vref in mV according to the chip's ADC resolution */
-	sc->sc_vref_mv = 1 << ((model->flags & M3K_SIGNED) ?
-	model->bits - 1 : model->bits);
+	vref_read_only = false;
+	switch (devhandle_type(devhandle)) {
+#ifdef FDT
+	case DEVHANDLE_TYPE_OF:
+		vref_read_only = mcp3kadc_vref_fdt(sc);
+		if (! vref_read_only) {
+			/* Error already displayed. */
+			return;
+		}
+		break;
+#endif /* FDT */
+	default:
+		/*
+		 * set a default Vref in mV according to the chip's ADC
+		 * resolution
+		 */
+		sc->sc_vref_mv = 1 << ((model->flags & M3K_SIGNED) ?
+		model->bits - 1 : model->bits);
+		break;
+	}
+
 
 	/* remember maximum value for this ADC - also used for masking */
 	sc->sc_adc_max = (1 << model->bits) - 1;
@@ -338,9 +405,11 @@ mcp3kadc_attach(device_t parent, device_
 	NULL, 0, NULL, 0,
 	CTL_HW, CTL_CREATE, CTL_EOL);
 
+	const int ctlflag = vref_read_only ? CTLFLAG_READONLY
+	   : CTLFLAG_READWRITE;
 	if (rnode != NULL)
 		sysctl_createv(NULL, 0, NULL, ,
-		CTLFLAG_READWRITE | CTLFLAG_OWNDESC,
+		ctlflag | CTLFLAG_OWNDESC,
 		CTLTYPE_INT, "vref",
 		SYSCTL_DESCR("ADC reference voltage"),
 		sysctl_mcp3kadc_vref, 0, (void *)sc, 0,



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/spi

2021-05-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May 19 13:23:23 UTC 2021

Modified Files:
src/sys/dev/spi [thorpej-i2c-spi-conf]: mcp23s17.c

Log Message:
Oops, fix 2 paste-o's.


To generate a diff of this commit:
cvs rdiff -u -r1.2.2.4 -r1.2.2.5 src/sys/dev/spi/mcp23s17.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/dev/spi/mcp23s17.c
diff -u src/sys/dev/spi/mcp23s17.c:1.2.2.4 src/sys/dev/spi/mcp23s17.c:1.2.2.5
--- src/sys/dev/spi/mcp23s17.c:1.2.2.4	Wed May 19 12:37:46 2021
+++ src/sys/dev/spi/mcp23s17.c	Wed May 19 13:23:23 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: mcp23s17.c,v 1.2.2.4 2021/05/19 12:37:46 thorpej Exp $ */
+/*  $NetBSD: mcp23s17.c,v 1.2.2.5 2021/05/19 13:23:23 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v 1.2.2.4 2021/05/19 12:37:46 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v 1.2.2.5 2021/05/19 13:23:23 thorpej Exp $");
 
 /* 
  * Driver for Microchip MCP23S17 GPIO
@@ -204,7 +204,7 @@ mcp23s17gpio_attach(device_t parent, dev
 /* Error alredy displayed. */
 return;
 			}
-			return;
+			break;
 #endif /* FDT */
 		default:
 			aprint_error(": unsupported device handle type\n");
@@ -212,12 +212,6 @@ mcp23s17gpio_attach(device_t parent, dev
 		}
 	}
 
-	/*
-	 * XXX Initialize sc_ha from microchip,spi-present-mask
-	 * XXX property for FDT.  Only consult cf_flags for indirect.
-	 */
-	sc->sc_ha = device_cfdata(sc->sc_dev)->cf_flags & 0x7;
-
 	aprint_naive(": GPIO\n");	
 	aprint_normal(": MCP23S17 GPIO (ha=%d)\n", sc->sc_ha);
 



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/spi

2021-05-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May 19 12:37:47 UTC 2021

Modified Files:
src/sys/dev/spi [thorpej-i2c-spi-conf]: mcp23s17.c

Log Message:
Use  instead of .


To generate a diff of this commit:
cvs rdiff -u -r1.2.2.3 -r1.2.2.4 src/sys/dev/spi/mcp23s17.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/dev/spi/mcp23s17.c
diff -u src/sys/dev/spi/mcp23s17.c:1.2.2.3 src/sys/dev/spi/mcp23s17.c:1.2.2.4
--- src/sys/dev/spi/mcp23s17.c:1.2.2.3	Wed May 19 12:35:28 2021
+++ src/sys/dev/spi/mcp23s17.c	Wed May 19 12:37:46 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: mcp23s17.c,v 1.2.2.3 2021/05/19 12:35:28 thorpej Exp $ */
+/*  $NetBSD: mcp23s17.c,v 1.2.2.4 2021/05/19 12:37:46 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v 1.2.2.3 2021/05/19 12:35:28 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v 1.2.2.4 2021/05/19 12:37:46 thorpej Exp $");
 
 /* 
  * Driver for Microchip MCP23S17 GPIO
@@ -55,7 +55,7 @@ __KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v
 #include 
 
 #ifdef FDT
-#include 
+#include 
 #endif /* FDT */
 
 /* #define MCP23S17_DEBUG */



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/spi

2021-05-19 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May 19 12:35:28 UTC 2021

Modified Files:
src/sys/dev/spi [thorpej-i2c-spi-conf]: mcp23s17.c

Log Message:
The MCP23S17 can multiplex multiple chips on the same chip select.
This driver has traditionally used cf_flags (from the kernel config
file) to get the chip address.

For direct configuration, we need to consult the platform device tree.
Add support for this, and implement for the Device Tree bindings for
this device (consulting the "microchip,spi-present-mask" property).

XXX The "microchip,spi-present-mask" property can encode for multiple
chips at the same device tree node; we do not currently support this
in the driver.


To generate a diff of this commit:
cvs rdiff -u -r1.2.2.2 -r1.2.2.3 src/sys/dev/spi/mcp23s17.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/dev/spi/mcp23s17.c
diff -u src/sys/dev/spi/mcp23s17.c:1.2.2.2 src/sys/dev/spi/mcp23s17.c:1.2.2.3
--- src/sys/dev/spi/mcp23s17.c:1.2.2.2	Wed May 19 03:46:26 2021
+++ src/sys/dev/spi/mcp23s17.c	Wed May 19 12:35:28 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: mcp23s17.c,v 1.2.2.2 2021/05/19 03:46:26 thorpej Exp $ */
+/*  $NetBSD: mcp23s17.c,v 1.2.2.3 2021/05/19 12:35:28 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v 1.2.2.2 2021/05/19 03:46:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v 1.2.2.3 2021/05/19 12:35:28 thorpej Exp $");
 
 /* 
  * Driver for Microchip MCP23S17 GPIO
@@ -39,6 +39,7 @@ __KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v
  */
 
 #include "gpio.h"
+#include "opt_fdt.h"
 
 #include 
 #include 
@@ -51,9 +52,12 @@ __KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v
 #include 
 
 #include 
-
 #include 
 
+#ifdef FDT
+#include 
+#endif /* FDT */
+
 /* #define MCP23S17_DEBUG */
 #ifdef MCP23S17_DEBUG
 int mcp23S17debug = 3;
@@ -109,6 +113,60 @@ mcp23s17gpio_match(device_t parent, cfda
 	return spi_compatible_match(sa, cf, compat_data);
 }
 
+#ifdef FDT
+static bool
+mcp23s17gpio_ha_fdt(struct mcp23s17gpio_softc *sc)
+{
+	devhandle_t devhandle = device_handle(sc->sc_dev);
+	int phandle = devhandle_to_of(devhandle);
+	uint32_t mask;
+	int count;
+
+	/*
+	 * The number of devices sharing this chip select,
+	 * along with their assigned addresses, is encoded
+	 * in the "microchip,spi-present-mask" property.
+	 *
+	 * N.B. we also check for "mcp,spi-present-mask" if
+	 * the first one isn't present (it's a deprecated
+	 * property that may be present in older device trees).
+	 */
+	if (of_getprop_uint32(phandle, "microchip,spi-present-mask",
+			  ) != 0 ||
+	of_getprop_uint32(phandle, "mcp,spi-present-mask",
+			  ) != 0) {
+		aprint_error(
+		": missing \"microchip,spi-present-mask\" property\n");
+		return false;
+	}
+
+	/*
+	 * If we ever support the mcp23s08, then only bits 0-3 are valid
+	 * on that device.
+	 */
+	if (mask == 0 || mask > __BITS(0,7)) {
+		aprint_error(
+		": invalid \"microchip,spi-present-mask\" property\n");
+		return false;
+	}
+
+	count = popcount32(mask);
+	if (count > 1) {
+		/*
+		 * XXX We only support a single chip on this chip
+		 * select for now.
+		 */
+		aprint_error(": unsupported %d-chip configuration\n", count);
+		return false;
+	}
+
+	sc->sc_ha = ffs(mask) - 1;
+	KASSERT(sc->sc_ha >= 0 && sc->sc_ha <= 7);
+
+	return true;
+}
+#endif /* FDT */
+
 static void
 mcp23s17gpio_attach(device_t parent, device_t self, void *aux)
 {
@@ -127,6 +185,34 @@ mcp23s17gpio_attach(device_t parent, dev
 	sc->sc_bank = 0;
 
 	/*
+	 * The MCP23S17 can multiplex multiple chips on the same
+	 * chip select.
+	 *
+	 * If we got here using indirect configuration, our kernel
+	 * config file directive has our address.  Otherwise, we need
+	 * to consult the device tree used for direct configuration.
+	 */
+	if (sa->sa_name == NULL) {
+		sc->sc_ha = device_cfdata(sc->sc_dev)->cf_flags & 0x7;
+	} else {
+		devhandle_t devhandle = device_handle(self);
+
+		switch (devhandle_type(devhandle)) {
+#ifdef FDT
+		case DEVHANDLE_TYPE_OF:
+			if (! mcp23s17gpio_ha_fdt(sc)) {
+/* Error alredy displayed. */
+return;
+			}
+			return;
+#endif /* FDT */
+		default:
+			aprint_error(": unsupported device handle type\n");
+			return;
+		}
+	}
+
+	/*
 	 * XXX Initialize sc_ha from microchip,spi-present-mask
 	 * XXX property for FDT.  Only consult cf_flags for indirect.
 	 */



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/spi

2021-05-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May 19 03:46:26 UTC 2021

Modified Files:
src/sys/dev/spi [thorpej-i2c-spi-conf]: m25p.c mcp23s17.c mcp3k.c
mcp48x1.c oj6sh.c ssdfb_spi.c tmp121.c

Log Message:
match/probe routines should not have side-effects; call spi_configure()
from the attach routine.


To generate a diff of this commit:
cvs rdiff -u -r1.17 -r1.17.4.1 src/sys/dev/spi/m25p.c
cvs rdiff -u -r1.2.2.1 -r1.2.2.2 src/sys/dev/spi/mcp23s17.c
cvs rdiff -u -r1.2.36.1 -r1.2.36.2 src/sys/dev/spi/mcp3k.c
cvs rdiff -u -r1.1.54.1 -r1.1.54.2 src/sys/dev/spi/mcp48x1.c
cvs rdiff -u -r1.8 -r1.8.2.1 src/sys/dev/spi/oj6sh.c
cvs rdiff -u -r1.5 -r1.5.4.1 src/sys/dev/spi/ssdfb_spi.c
cvs rdiff -u -r1.5.72.1 -r1.5.72.2 src/sys/dev/spi/tmp121.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/dev/spi/m25p.c
diff -u src/sys/dev/spi/m25p.c:1.17 src/sys/dev/spi/m25p.c:1.17.4.1
--- src/sys/dev/spi/m25p.c:1.17	Wed Jan 27 02:32:31 2021
+++ src/sys/dev/spi/m25p.c	Wed May 19 03:46:26 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: m25p.c,v 1.17 2021/01/27 02:32:31 thorpej Exp $ */
+/* $NetBSD: m25p.c,v 1.17.4.1 2021/05/19 03:46:26 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.17 2021/01/27 02:32:31 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: m25p.c,v 1.17.4.1 2021/05/19 03:46:26 thorpej Exp $");
 
 #include 
 #include 
@@ -125,17 +125,8 @@ static int
 m25p_match(device_t parent, cfdata_t cf, void *aux)
 {
 	struct spi_attach_args *sa = aux;
-	int res;
 
-	res = spi_compatible_match(sa, cf, compat_data);
-	if (!res)
-		return res;
-
-	/* configure for 20MHz, which is the max for normal reads */
-	if (spi_configure(sa->sa_handle, SPI_MODE_0, 2000))
-		res = 0;
-
-	return res;
+	return spi_compatible_match(sa, cf, compat_data);
 }
 
 static void
@@ -143,12 +134,21 @@ m25p_attach(device_t parent, device_t se
 {
 	struct m25p_softc *sc = device_private(self);
 	struct spi_attach_args *sa = aux;
+	int error;
 
 	sc->sc_sh = sa->sa_handle;
 
 	aprint_normal("\n");
 	aprint_naive("\n");
 
+	/* configure for 20MHz, which is the max for normal reads */
+	error = spi_configure(sa->sa_handle, SPI_MODE_0, 2000);
+	if (error) {
+		aprint_error_dev(self, "spi_configure failed (error = %d)\n",
+		error);
+		return;
+	}
+
 	config_interrupts(self, m25p_doattach);
 }
 

Index: src/sys/dev/spi/mcp23s17.c
diff -u src/sys/dev/spi/mcp23s17.c:1.2.2.1 src/sys/dev/spi/mcp23s17.c:1.2.2.2
--- src/sys/dev/spi/mcp23s17.c:1.2.2.1	Wed May 19 03:32:27 2021
+++ src/sys/dev/spi/mcp23s17.c	Wed May 19 03:46:26 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: mcp23s17.c,v 1.2.2.1 2021/05/19 03:32:27 thorpej Exp $ */
+/*  $NetBSD: mcp23s17.c,v 1.2.2.2 2021/05/19 03:46:26 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v 1.2.2.1 2021/05/19 03:32:27 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v 1.2.2.2 2021/05/19 03:46:26 thorpej Exp $");
 
 /* 
  * Driver for Microchip MCP23S17 GPIO
@@ -105,16 +105,8 @@ static int
 mcp23s17gpio_match(device_t parent, cfdata_t cf, void *aux)
 {
 	struct spi_attach_args *sa = aux;
-	int rv;
 
-	rv = spi_compatible_match(sa, cf, compat_data);
-	if (rv != 0) {
-		/* run at 10MHz */
-		if (spi_configure(sa->sa_handle, SPI_MODE_0, 1000))
-			return 0;
-	}
-
-	return rv;
+	return spi_compatible_match(sa, cf, compat_data);
 }
 
 static void
@@ -122,6 +114,7 @@ mcp23s17gpio_attach(device_t parent, dev
 {
 	struct mcp23s17gpio_softc *sc;
 	struct spi_attach_args *sa;
+	int error;
 #if NGPIO > 0
 	int i;
 	struct gpiobus_attach_args gba;
@@ -142,6 +135,14 @@ mcp23s17gpio_attach(device_t parent, dev
 	aprint_naive(": GPIO\n");	
 	aprint_normal(": MCP23S17 GPIO (ha=%d)\n", sc->sc_ha);
 
+	/* run at 10MHz */
+	error = spi_configure(sa->sa_handle, SPI_MODE_0, 1000);
+	if (error) {
+		aprint_error_dev(self, "spi_configure failed (error = %d)\n",
+		error);
+		return;
+	}
+
 	DPRINTF(1, ("%s: initialize (HAEN|SEQOP)\n", device_xname(sc->sc_dev)));
 
 	/* basic setup */

Index: src/sys/dev/spi/mcp3k.c
diff -u src/sys/dev/spi/mcp3k.c:1.2.36.1 src/sys/dev/spi/mcp3k.c:1.2.36.2
--- src/sys/dev/spi/mcp3k.c:1.2.36.1	Wed May 19 03:33:05 2021
+++ src/sys/dev/spi/mcp3k.c	Wed May 19 03:46:26 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: mcp3k.c,v 1.2.36.1 2021/05/19 03:33:05 thorpej Exp $ */
+/*	$NetBSD: mcp3k.c,v 1.2.36.2 2021/05/19 03:46:26 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -242,10 +242,6 @@ mcp3kadc_match(device_t parent, cfdata_t
 		if (sa->sa_clist == NULL && mcp3kadc_lookup(sa, cf) == NULL) {
 			return 0;
 		}
-
-		/* configure for 1MHz */
-		if (spi_configure(sa->sa_handle, SPI_MODE_0, 100))
-			return 0;
 	}
 
 	return rv;
@@ -258,7 +254,7 @@ 

CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/spi

2021-05-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May 19 03:34:11 UTC 2021

Modified Files:
src/sys/dev/spi [thorpej-i2c-spi-conf]: tmp121.c

Log Message:
Use spi_compatible_match().

XXX Should support the other variants of this device.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.5.72.1 src/sys/dev/spi/tmp121.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/dev/spi/tmp121.c
diff -u src/sys/dev/spi/tmp121.c:1.5 src/sys/dev/spi/tmp121.c:1.5.72.1
--- src/sys/dev/spi/tmp121.c:1.5	Mon Jun 20 17:31:37 2011
+++ src/sys/dev/spi/tmp121.c	Wed May 19 03:34:11 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tmp121.c,v 1.5 2011/06/20 17:31:37 pgoyette Exp $ */
+/* $NetBSD: tmp121.c,v 1.5.72.1 2021/05/19 03:34:11 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2006 Urbana-Champaign Independent Media Center.
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tmp121.c,v 1.5 2011/06/20 17:31:37 pgoyette Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tmp121.c,v 1.5.72.1 2021/05/19 03:34:11 thorpej Exp $");
 
 #include 
 #include 
@@ -68,16 +68,39 @@ static void	tmp121temp_refresh(struct sy
 CFATTACH_DECL_NEW(tmp121temp, sizeof(struct tmp121temp_softc),
 tmp121temp_match, tmp121temp_attach, NULL, NULL);
 
+static const struct device_compatible_entry compat_data[] = {
+	{ .compat = "ti,tmp121" },
+	{ .compat = "TMP00121" },
+
+#if 0	/* We should also add support for these: */
+	{ .compat = "ti,tmp122" },
+
+	{ .compat = "ti,lm70" },
+	{ .compat = "LM70" },
+
+	{ .compat = "ti,lm71" },
+	{ .compat = "LM71" },
+
+	{ .compat = "ti,lm74" },
+	{ .compat = "LM74" },
+#endif
+	DEVICE_COMPAT_EOL
+};
+
 static int
 tmp121temp_match(device_t parent, cfdata_t cf, void *aux)
 {
 	struct spi_attach_args *sa = aux;
+	int rv;
 
-	/* configure for 10MHz */
-	if (spi_configure(sa->sa_handle, SPI_MODE_0, 100))
-		return 0;
+	rv = spi_compatible_match(sa, cf, compat_data);
+	if (rv != 0) {
+		/* configure for 10MHz */
+		if (spi_configure(sa->sa_handle, SPI_MODE_0, 100))
+			return 0;
+	}
 
-	return 1;
+	return rv;
 }
 
 static void



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/spi

2021-05-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May 19 03:33:33 UTC 2021

Modified Files:
src/sys/dev/spi [thorpej-i2c-spi-conf]: mcp48x1.c

Log Message:
Use spi_compatible_match().


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.1.54.1 src/sys/dev/spi/mcp48x1.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/dev/spi/mcp48x1.c
diff -u src/sys/dev/spi/mcp48x1.c:1.1 src/sys/dev/spi/mcp48x1.c:1.1.54.1
--- src/sys/dev/spi/mcp48x1.c:1.1	Tue Feb 25 20:09:37 2014
+++ src/sys/dev/spi/mcp48x1.c	Wed May 19 03:33:33 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: mcp48x1.c,v 1.1 2014/02/25 20:09:37 rkujawa Exp $ */
+/*  $NetBSD: mcp48x1.c,v 1.1.54.1 2021/05/19 03:33:33 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mcp48x1.c,v 1.1 2014/02/25 20:09:37 rkujawa Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcp48x1.c,v 1.1.54.1 2021/05/19 03:33:33 thorpej Exp $");
 
 /* 
  * Driver for Microchip MCP4801/MCP4811/MCP4821 DAC. 
@@ -57,7 +57,7 @@ __KERNEL_RCSID(0, "$NetBSD: mcp48x1.c,v 
 #define MCP48X1DAC_DATA		__BITS(11,0)	/* data */
 
 struct mcp48x1dac_model {
-	const char *name;
+	u_int name;
 	uint8_t	resolution;
 	uint8_t	shift;			/* data left shift during write */
 };
@@ -66,7 +66,7 @@ struct mcp48x1dac_softc {
 	device_t sc_dev;
 	struct spi_handle *sc_sh;
 
-	struct mcp48x1dac_model *sc_dm;	/* struct describing DAC model */
+	const struct mcp48x1dac_model *sc_dm;
 
 	uint16_t sc_dac_data;
 	bool sc_dac_gain;
@@ -93,55 +93,97 @@ static int	sysctl_mcp48x1dac_gain(SYSCTL
 CFATTACH_DECL_NEW(mcp48x1dac, sizeof(struct mcp48x1dac_softc),
 mcp48x1dac_match, mcp48x1dac_attach, NULL, NULL);
 
-static struct mcp48x1dac_model mcp48x1_models[] = {
-	{
-		.name = "MCP4801",
-		.resolution = 8,
-		.shift = 4
-	},
-	{
-		.name = "MCP4811",
-		.resolution = 10,
-		.shift = 2
-	},
-	{
-		.name = "MCP4821",
-		.resolution = 12,
-		.shift = 0
-	}
+static const struct mcp48x1dac_model mcp4801 = {
+	.name = 4801,
+	.resolution = 8,
+	.shift = 4
+};
+
+static const struct mcp48x1dac_model mcp4811 = {
+	.name = 4811,
+	.resolution = 10,
+	.shift = 2
+};
+
+static const struct mcp48x1dac_model mcp4821 = {
+	.name = 4821,
+	.resolution = 12,
+	.shift = 0
+};
+
+static const struct device_compatible_entry compat_data[] = {
+	{ .compat = "microchip,mcp4801",	.data =  },
+	{ .compat = "microchip,mcp4811",	.data =  },
+	{ .compat = "microchip,mcp4821",	.data =  },
+	DEVICE_COMPAT_EOL
 };
 
+static const struct mcp48x1dac_model *
+mcp48x1dac_lookup(const struct spi_attach_args *sa, const cfdata_t cf)
+{
+	const struct device_compatible_entry *dce;
+
+	if (sa->sa_clist != NULL) {
+		dce = device_compatible_lookup_strlist(sa->sa_clist,
+		sa->sa_clist_size, compat_data);
+		if (dce == NULL) {
+			return NULL;
+		}
+		return dce->data;
+	} else {
+		const struct mcp48x1dac_model *model;
+
+		for (dce = compat_data; dce->compat != NULL; dce++) {
+			model = dce->data;
+			if (model->name == cf->cf_flags) {
+return model;
+			}
+		}
+		return NULL;
+	}
+}
 
 static int
 mcp48x1dac_match(device_t parent, cfdata_t cf, void *aux)
 {
 	struct spi_attach_args *sa = aux;
+	int rv;
 
-	/* MCP48x1 is a write-only device, so no way to detect it! */
-
-	if (spi_configure(sa->sa_handle, SPI_MODE_0, 2000))
-		return 0;
+	rv = spi_compatible_match(sa, cf, compat_data);
+	if (rv != 0) {
+		/*
+		 * If we're doing indorect config, the user must
+		 * have specified the correct model.
+		 */
+		if (sa->sa_clist == NULL && mcp48x1dac_lookup(sa, cf) == NULL) {
+			return 0;
+		}
+
+		/* configure for 20MHz */
+		if (spi_configure(sa->sa_handle, SPI_MODE_0, 2000))
+			return 0;
+	}
 
-	return 1;
+	return rv;
 }
 
 static void
 mcp48x1dac_attach(device_t parent, device_t self, void *aux)
 {
-	struct mcp48x1dac_softc *sc;
-	struct spi_attach_args *sa;
-	int cf_flags;
-
-	aprint_naive(": Digital to Analog converter\n");	
-	aprint_normal(": MCP48x1 DAC\n");
+	struct mcp48x1dac_softc *sc = device_private(self);
+	struct spi_attach_args *sa = aux;
+	const struct mcp48x1dac_model *model;
 
-	sa = aux;
-	sc = device_private(self);
 	sc->sc_dev = self;
 	sc->sc_sh = sa->sa_handle;
-	cf_flags = device_cfdata(sc->sc_dev)->cf_flags;
 
-	sc->sc_dm = _models[cf_flags]; /* flag value defines model */
+	model = mcp48x1dac_lookup(sa, device_cfdata(self));
+	KASSERT(model != NULL);
+
+	sc->sc_dm = model;
+
+	aprint_naive(": Digital to Analog converter\n");	
+	aprint_normal(": MCP%u DAC\n", model->name);
 
 	if(!mcp48x1dac_envsys_attach(sc)) {
 		aprint_error_dev(sc->sc_dev, "failed to attach envsys\n");



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/spi

2021-05-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May 19 03:33:05 UTC 2021

Modified Files:
src/sys/dev/spi [thorpej-i2c-spi-conf]: mcp3k.c

Log Message:
Use spi_compatible_match().

XXX More work to do for proper FDT integration.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.2.36.1 src/sys/dev/spi/mcp3k.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/dev/spi/mcp3k.c
diff -u src/sys/dev/spi/mcp3k.c:1.2 src/sys/dev/spi/mcp3k.c:1.2.36.1
--- src/sys/dev/spi/mcp3k.c:1.2	Sun Nov 20 12:38:04 2016
+++ src/sys/dev/spi/mcp3k.c	Wed May 19 03:33:05 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: mcp3k.c,v 1.2 2016/11/20 12:38:04 phx Exp $ */
+/*	$NetBSD: mcp3k.c,v 1.2.36.1 2021/05/19 03:33:05 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2015 The NetBSD Foundation, Inc.
@@ -72,14 +72,14 @@ struct mcp3kadc_model {
 };
 
 struct mcp3kadc_softc {
-	device_t		sc_dev;
-	struct spi_handle 	*sc_sh;
-	int			sc_model;
-	uint32_t		sc_adc_max;
-	int32_t			sc_vref_mv;
+	device_t			sc_dev;
+	struct spi_handle 		*sc_sh;
+	const struct mcp3kadc_model	*sc_model;
+	uint32_t			sc_adc_max;
+	int32_tsc_vref_mv;
 
-	struct sysmon_envsys 	*sc_sme;
-	envsys_data_t 		sc_sensors[M3K_MAX_SENSORS];
+	struct sysmon_envsys 		*sc_sme;
+	envsys_data_t 			sc_sensors[M3K_MAX_SENSORS];
 };
 
 static int	mcp3kadc_match(device_t, cfdata_t, void *);
@@ -91,124 +91,192 @@ static int	sysctl_mcp3kadc_vref(SYSCTLFN
 CFATTACH_DECL_NEW(mcp3kadc, sizeof(struct mcp3kadc_softc),
 mcp3kadc_match,  mcp3kadc_attach, NULL, NULL);
 
-static struct mcp3kadc_model mcp3k_models[] = {
-	{
-		.name = 3001,
-		.bits = 10,
-		.channels = 1,
-		.lead = 3,
-		.flags = 0
-	},
-	{
-		.name = 3002,
-		.bits = 10,
-		.channels = 2,
-		.lead = 2,
-		.flags = M3K_SGLDIFF | M3K_MSBF
-	},
-	{
-		.name = 3004,
-		.bits = 10,
-		.channels = 4,
-		.lead = 2,
-		.flags = M3K_SGLDIFF | M3K_D2D1D0
-	},
-	{
-		.name = 3008,
-		.bits = 10,
-		.channels = 8,
-		.lead = 2,
-		.flags = M3K_SGLDIFF | M3K_D2D1D0
-	},
-	{
-		.name = 3201,
-		.bits = 12,
-		.channels = 1,
-		.lead = 3,
-		.flags = 0
-	},
-	{
-		.name = 3202,
-		.bits = 12,
-		.channels = 2,
-		.lead = 2,
-		.flags = M3K_SGLDIFF | M3K_MSBF
-	},
-	{
-		.name = 3204,
-		.bits = 12,
-		.channels = 4,
-		.lead = 2,
-		.flags = M3K_SGLDIFF | M3K_D2D1D0
-	},
-	{
-		.name = 3208,
-		.bits = 12,
-		.channels = 8,
-		.lead = 2,
-		.flags = M3K_SGLDIFF | M3K_D2D1D0
-	},
-	{
-		.name = 3301,
-		.bits = 13,
-		.channels = 1,
-		.lead = 3,
-		.flags = M3K_SIGNED
-	},
-	{
-		.name = 3302,
-		.bits = 13,
-		.channels = 4,
-		.lead = 2,
-		.flags = M3K_SIGNED | M3K_SGLDIFF | M3K_D2D1D0
-	},
-	{
-		.name = 3304,
-		.bits = 13,
-		.channels = 8,
-		.lead = 2,
-		.flags = M3K_SIGNED | M3K_SGLDIFF | M3K_D2D1D0
-	},
+static const struct mcp3kadc_model mcp3001 = {
+	.name = 3001,
+	.bits = 10,
+	.channels = 1,
+	.lead = 3,
+	.flags = 0
 };
 
+static const struct mcp3kadc_model mcp3002 = {
+	.name = 3002,
+	.bits = 10,
+	.channels = 2,
+	.lead = 2,
+	.flags = M3K_SGLDIFF | M3K_MSBF
+};
+
+static const struct mcp3kadc_model mcp3004 = {
+	.name = 3004,
+	.bits = 10,
+	.channels = 4,
+	.lead = 2,
+	.flags = M3K_SGLDIFF | M3K_D2D1D0
+};
+
+static const struct mcp3kadc_model mcp3008 = {
+	.name = 3008,
+	.bits = 10,
+	.channels = 8,
+	.lead = 2,
+	.flags = M3K_SGLDIFF | M3K_D2D1D0
+};
+
+static const struct mcp3kadc_model mcp3201 = {
+	.name = 3201,
+	.bits = 12,
+	.channels = 1,
+	.lead = 3,
+	.flags = 0
+};
+
+static const struct mcp3kadc_model mcp3202 = {
+	.name = 3202,
+	.bits = 12,
+	.channels = 2,
+	.lead = 2,
+	.flags = M3K_SGLDIFF | M3K_MSBF
+};
+
+static const struct mcp3kadc_model mcp3204 = {
+	.name = 3204,
+	.bits = 12,
+	.channels = 4,
+	.lead = 2,
+	.flags = M3K_SGLDIFF | M3K_D2D1D0
+};
+
+static const struct mcp3kadc_model mcp3208 = {
+	.name = 3208,
+	.bits = 12,
+	.channels = 8,
+	.lead = 2,
+	.flags = M3K_SGLDIFF | M3K_D2D1D0
+};
+
+static const struct mcp3kadc_model mcp3301 = {
+	.name = 3301,
+	.bits = 13,
+	.channels = 1,
+	.lead = 3,
+	.flags = M3K_SIGNED
+};
+
+static const struct mcp3kadc_model mcp3302 = {
+	.name = 3302,
+	.bits = 13,
+	.channels = 4,
+	.lead = 2,
+	.flags = M3K_SIGNED | M3K_SGLDIFF | M3K_D2D1D0
+};
+
+static const struct mcp3kadc_model mcp3304 = {
+	.name = 3304,
+	.bits = 13,
+	.channels = 8,
+	.lead = 2,
+	.flags = M3K_SIGNED | M3K_SGLDIFF | M3K_D2D1D0
+};
+
+static const struct device_compatible_entry compat_data[] = {
+	{ .compat = "microchip,mcp3001",	.data =  },
+	{ .compat = "microchip,mcp3002",	.data =  },
+	{ .compat = "microchip,mcp3004",	.data =  },
+	{ .compat = "microchip,mcp3008",	.data =  },
+	{ .compat = "microchip,mcp3201",	.data =  },
+	{ .compat = "microchip,mcp3202",	.data =  },
+	{ .compat = "microchip,mcp3204",	.data =  },
+	{ .compat = "microchip,mcp3208",	.data =  },
+	{ .compat = "microchip,mcp3301",	.data =  },
+	{ .compat = "microchip,mcp3302",	.data =  },
+	{ 

CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/spi

2021-05-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May 19 03:32:27 UTC 2021

Modified Files:
src/sys/dev/spi [thorpej-i2c-spi-conf]: mcp23s17.c

Log Message:
Use spi_compatible_match().

XXX More work to do for proper FDT integration.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.2.2.1 src/sys/dev/spi/mcp23s17.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/dev/spi/mcp23s17.c
diff -u src/sys/dev/spi/mcp23s17.c:1.2 src/sys/dev/spi/mcp23s17.c:1.2.2.1
--- src/sys/dev/spi/mcp23s17.c:1.2	Sat Apr 24 23:36:59 2021
+++ src/sys/dev/spi/mcp23s17.c	Wed May 19 03:32:27 2021
@@ -1,4 +1,4 @@
-/*  $NetBSD: mcp23s17.c,v 1.2 2021/04/24 23:36:59 thorpej Exp $ */
+/*  $NetBSD: mcp23s17.c,v 1.2.2.1 2021/05/19 03:32:27 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2014 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v 1.2 2021/04/24 23:36:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: mcp23s17.c,v 1.2.2.1 2021/05/19 03:32:27 thorpej Exp $");
 
 /* 
  * Driver for Microchip MCP23S17 GPIO
@@ -87,18 +87,34 @@ static void mcp23s17gpio_gpio_pin_ct
 CFATTACH_DECL_NEW(mcp23s17gpio, sizeof(struct mcp23s17gpio_softc),
 		  mcp23s17gpio_match, mcp23s17gpio_attach, NULL, NULL);
 
+static const struct device_compatible_entry compat_data[] = {
+	{ .compat = "mcp,mcp23s17" },
+	{ .compat = "microchip,mcp23s17" },
+
+#if 0	/* We should also add support for these: */
+	{ .compat = "mcp,mcp23s08" },
+	{ .compat = "microchip,mcp23s08" },
+
+	{ .compat = "microchip,mcp23s18" },
+#endif
+
+	DEVICE_COMPAT_EOL
+};
+
 static int
 mcp23s17gpio_match(device_t parent, cfdata_t cf, void *aux)
 {
 	struct spi_attach_args *sa = aux;
+	int rv;
 
-	/* MCP23S17 has no way to detect it! */
-
-	/* run at 10MHz */
-	if (spi_configure(sa->sa_handle, SPI_MODE_0, 1000))
-		return 0;
+	rv = spi_compatible_match(sa, cf, compat_data);
+	if (rv != 0) {
+		/* run at 10MHz */
+		if (spi_configure(sa->sa_handle, SPI_MODE_0, 1000))
+			return 0;
+	}
 
-	return 1;
+	return rv;
 }
 
 static void
@@ -116,6 +132,11 @@ mcp23s17gpio_attach(device_t parent, dev
 	sc->sc_dev = self;
 	sc->sc_sh = sa->sa_handle;
 	sc->sc_bank = 0;
+
+	/*
+	 * XXX Initialize sc_ha from microchip,spi-present-mask
+	 * XXX property for FDT.  Only consult cf_flags for indirect.
+	 */
 	sc->sc_ha = device_cfdata(sc->sc_dev)->cf_flags & 0x7;
 
 	aprint_naive(": GPIO\n");	
@@ -124,7 +145,10 @@ mcp23s17gpio_attach(device_t parent, dev
 	DPRINTF(1, ("%s: initialize (HAEN|SEQOP)\n", device_xname(sc->sc_dev)));
 
 	/* basic setup */
-	mcp23s17gpio_write(sc, MCP23x17_IOCONA(sc->sc_bank), MCP23x17_IOCON_HAEN|MCP23x17_IOCON_SEQOP);
+	mcp23s17gpio_write(sc, MCP23x17_IOCONA(sc->sc_bank),
+	MCP23x17_IOCON_HAEN|MCP23x17_IOCON_SEQOP);
+
+	/* XXX Hook up to FDT GPIO. */
 
 #if NGPIO > 0
 	for (i = 0; i < MCP23x17_GPIO_NPINS; i++) {



CVS commit: [thorpej-i2c-spi-conf] src/sys

2021-05-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May 19 03:14:25 UTC 2021

Modified Files:
src/sys/arch/arm/broadcom [thorpej-i2c-spi-conf]: bcm2835_bsc_fdt.c
src/sys/arch/arm/nvidia [thorpej-i2c-spi-conf]: tegra_i2c.c
src/sys/arch/arm/rockchip [thorpej-i2c-spi-conf]: rk_i2c.c
src/sys/arch/arm/samsung [thorpej-i2c-spi-conf]: exynos_i2c.c
src/sys/arch/arm/sociox [thorpej-i2c-spi-conf]: sni_i2c.c
src/sys/arch/arm/sunxi [thorpej-i2c-spi-conf]: sunxi_rsb.c sunxi_twi.c
src/sys/arch/arm/ti [thorpej-i2c-spi-conf]: ti_iic.c
src/sys/dev/fdt [thorpej-i2c-spi-conf]: dwiic_fdt.c fdt_i2c.c fdtvar.h
src/sys/dev/i2c [thorpej-i2c-spi-conf]: motoi2c.c

Log Message:
fdtbus_attach_i2cbus() is no longer anything other than a wrapper around
config_found(); just get rid of it and make its callers look like all of
the other I2C controller drivers.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.6.4.1 src/sys/arch/arm/broadcom/bcm2835_bsc_fdt.c
cvs rdiff -u -r1.26 -r1.26.4.1 src/sys/arch/arm/nvidia/tegra_i2c.c
cvs rdiff -u -r1.10 -r1.10.4.1 src/sys/arch/arm/rockchip/rk_i2c.c
cvs rdiff -u -r1.22 -r1.22.4.1 src/sys/arch/arm/samsung/exynos_i2c.c
cvs rdiff -u -r1.11 -r1.11.2.1 src/sys/arch/arm/sociox/sni_i2c.c
cvs rdiff -u -r1.14 -r1.14.4.1 src/sys/arch/arm/sunxi/sunxi_rsb.c
cvs rdiff -u -r1.17 -r1.17.4.1 src/sys/arch/arm/sunxi/sunxi_twi.c
cvs rdiff -u -r1.13 -r1.13.4.1 src/sys/arch/arm/ti/ti_iic.c
cvs rdiff -u -r1.4 -r1.4.4.1 src/sys/dev/fdt/dwiic_fdt.c
cvs rdiff -u -r1.10.2.1 -r1.10.2.2 src/sys/dev/fdt/fdt_i2c.c
cvs rdiff -u -r1.70.2.1 -r1.70.2.2 src/sys/dev/fdt/fdtvar.h
cvs rdiff -u -r1.11.2.1 -r1.11.2.2 src/sys/dev/i2c/motoi2c.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/broadcom/bcm2835_bsc_fdt.c
diff -u src/sys/arch/arm/broadcom/bcm2835_bsc_fdt.c:1.6 src/sys/arch/arm/broadcom/bcm2835_bsc_fdt.c:1.6.4.1
--- src/sys/arch/arm/broadcom/bcm2835_bsc_fdt.c:1.6	Fri Jan 29 14:11:14 2021
+++ src/sys/arch/arm/broadcom/bcm2835_bsc_fdt.c	Wed May 19 03:14:24 2021
@@ -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.4.1 2021/05/19 03:14:24 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.4.1 2021/05/19 03:14:24 thorpej Exp $");
 
 #include 
 #include 
@@ -135,5 +135,10 @@ bsciic_fdt_attach(device_t parent, devic
 
 	fdtbus_register_i2c_controller(>sc_i2c, phandle);
 
-	fdtbus_attach_i2cbus(self, phandle, >sc_i2c, iicbus_print);
+	struct i2cbus_attach_args iba = {
+		.iba_tag = >sc_i2c,
+	};
+	config_found(self, , iicbus_print,
+	CFARG_DEVHANDLE, device_handle(self),
+	CFARG_EOL);
 }

Index: src/sys/arch/arm/nvidia/tegra_i2c.c
diff -u src/sys/arch/arm/nvidia/tegra_i2c.c:1.26 src/sys/arch/arm/nvidia/tegra_i2c.c:1.26.4.1
--- src/sys/arch/arm/nvidia/tegra_i2c.c:1.26	Wed Jan 27 03:10:19 2021
+++ src/sys/arch/arm/nvidia/tegra_i2c.c	Wed May 19 03:14:24 2021
@@ -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.4.1 2021/05/19 03:14:24 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.4.1 2021/05/19 03:14:24 thorpej Exp $");
 
 #include 
 #include 
@@ -180,7 +180,12 @@ tegra_i2c_attach(device_t parent, device
 
 	fdtbus_register_i2c_controller(>sc_ic, phandle);
 
-	fdtbus_attach_i2cbus(self, phandle, >sc_ic, iicbus_print);
+	struct i2cbus_attach_args iba = {
+		.iba_tag = >sc_ic,
+	};
+	config_found(self, , iicbus_print,
+	CFARG_DEVHANDLE, device_handle(self),
+	CFARG_EOL);
 }
 
 static void

Index: src/sys/arch/arm/rockchip/rk_i2c.c
diff -u src/sys/arch/arm/rockchip/rk_i2c.c:1.10 src/sys/arch/arm/rockchip/rk_i2c.c:1.10.4.1
--- src/sys/arch/arm/rockchip/rk_i2c.c:1.10	Wed Jan 27 03:10:19 2021
+++ src/sys/arch/arm/rockchip/rk_i2c.c	Wed May 19 03:14:24 2021
@@ -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.4.1 2021/05/19 03:14:24 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.4.1 2021/05/19 03:14:24 thorpej Exp $");
 
 #include 
 #include 
@@ -418,7 +418,12 @@ rk_i2c_attach(device_t parent, device_t 
 
 	fdtbus_register_i2c_controller(>sc_ic, phandle);
 
-	fdtbus_attach_i2cbus(self, phandle, >sc_ic, iicbus_print);
+	struct i2cbus_attach_args iba = {
+		.iba_tag = >sc_ic,
+	};
+	config_found(self, , 

CVS commit: [thorpej-i2c-spi-conf] src/sys

2021-05-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Wed May 19 02:58:26 UTC 2021

Modified Files:
src/sys/arch/arm/imx [thorpej-i2c-spi-conf]: imxspi.c
src/sys/arch/arm/rockchip [thorpej-i2c-spi-conf]: rk_spi.c
src/sys/arch/arm/sunxi [thorpej-i2c-spi-conf]: sun4i_spi.c
src/sys/dev/fdt [thorpej-i2c-spi-conf]: fdt_spi.c fdtvar.h

Log Message:
- As with i2c, just register the spi_controller directly.
- fdtbus_attach_spibus() is no longer anything other than a wrapper
  around config_found(); just get rid of it and make its callers
  look like all of the other SPI controller drivers.


To generate a diff of this commit:
cvs rdiff -u -r1.8.2.1 -r1.8.2.2 src/sys/arch/arm/imx/imxspi.c
cvs rdiff -u -r1.6 -r1.6.4.1 src/sys/arch/arm/rockchip/rk_spi.c
cvs rdiff -u -r1.7 -r1.7.4.1 src/sys/arch/arm/sunxi/sun4i_spi.c
cvs rdiff -u -r1.2.2.1 -r1.2.2.2 src/sys/dev/fdt/fdt_spi.c
cvs rdiff -u -r1.70 -r1.70.2.1 src/sys/dev/fdt/fdtvar.h

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/imx/imxspi.c
diff -u src/sys/arch/arm/imx/imxspi.c:1.8.2.1 src/sys/arch/arm/imx/imxspi.c:1.8.2.2
--- src/sys/arch/arm/imx/imxspi.c:1.8.2.1	Tue May 18 23:30:55 2021
+++ src/sys/arch/arm/imx/imxspi.c	Wed May 19 02:58:26 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: imxspi.c,v 1.8.2.1 2021/05/18 23:30:55 thorpej Exp $	*/
+/*	$NetBSD: imxspi.c,v 1.8.2.2 2021/05/19 02:58:26 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2014  Genetec Corporation.  All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: imxspi.c,v 1.8.2.1 2021/05/18 23:30:55 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: imxspi.c,v 1.8.2.2 2021/05/19 02:58:26 thorpej Exp $");
 
 #include "opt_imxspi.h"
 #include "opt_fdt.h"
@@ -86,20 +86,6 @@ int imxspi_debug = IMXSPI_DEBUG;
 #define	DPRINTFN(n,x)
 #endif
 
-#ifdef FDT
-static struct spi_controller *
-imxspi_get_controller(device_t dev)
-{
-	struct imxspi_softc * const sc = device_private(dev);
-
-	return >sc_spi;
-}
-
-static const struct fdtbus_spi_controller_func imxspi_funcs = {
-	.get_controller = imxspi_get_controller
-};
-#endif
-
 int
 imxspi_attach_common(device_t self)
 {
@@ -140,16 +126,14 @@ imxspi_attach_common(device_t self)
 #ifdef FDT
 	KASSERT(sc->sc_phandle != 0);
 
-	fdtbus_register_spi_controller(self, sc->sc_phandle, _funcs);
-	fdtbus_attach_spibus(self, sc->sc_phandle, spibus_print);
-#else
+	fdtbus_register_spi_controller(>sc_spi, sc->sc_phandle);
+#endif
 	struct spibus_attach_args sba = {
 		.sba_controller = >sc_spi,
 	};
-	config_found(sc->sc_dev, , spibus_print,
+	config_found(self, , spibus_print,
 	CFARG_DEVHANDLE, device_handle(self),
 	CFARG_EOL);
-#endif
 
 	return 0;
 }

Index: src/sys/arch/arm/rockchip/rk_spi.c
diff -u src/sys/arch/arm/rockchip/rk_spi.c:1.6 src/sys/arch/arm/rockchip/rk_spi.c:1.6.4.1
--- src/sys/arch/arm/rockchip/rk_spi.c:1.6	Wed Jan 27 03:10:19 2021
+++ src/sys/arch/arm/rockchip/rk_spi.c	Wed May 19 02:58:26 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: rk_spi.c,v 1.6 2021/01/27 03:10:19 thorpej Exp $	*/
+/*	$NetBSD: rk_spi.c,v 1.6.4.1 2021/05/19 02:58:26 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: rk_spi.c,v 1.6 2021/01/27 03:10:19 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rk_spi.c,v 1.6.4.1 2021/05/19 02:58:26 thorpej Exp $");
 
 #include 
 #include 
@@ -170,7 +170,6 @@ struct rk_spi_softc {
 #define SPIREG_WRITE(sc, reg, val) \
 bus_space_write_4((sc)->sc_bst, (sc)->sc_bsh, (reg), (val))
 
-static struct spi_controller *rk_spi_get_controller(device_t);
 static int rk_spi_match(device_t, cfdata_t, void *);
 static void rk_spi_attach(device_t, device_t, void *);
 
@@ -187,18 +186,6 @@ static int rk_spi_intr(void *);
 CFATTACH_DECL_NEW(rk_spi, sizeof(struct rk_spi_softc),
 rk_spi_match, rk_spi_attach, NULL, NULL);
 
-static const struct fdtbus_spi_controller_func rk_spi_funcs = {
-	.get_controller = rk_spi_get_controller
-};
-
-static struct spi_controller *
-rk_spi_get_controller(device_t dev)
-{
-	struct rk_spi_softc * const sc = device_private(dev);
-
-	return >sc_spi;
-}
-
 static int
 rk_spi_match(device_t parent, cfdata_t cf, void *aux)
 {
@@ -266,8 +253,14 @@ rk_spi_attach(device_t parent, device_t 
 	sc->sc_spi.sct_transfer = rk_spi_transfer;
 	sc->sc_spi.sct_nslaves = 2;
 
-	fdtbus_register_spi_controller(self, phandle, _spi_funcs);
-	(void) fdtbus_attach_spibus(self, phandle, spibus_print);
+	fdtbus_register_spi_controller(>sc_spi, phandle);
+
+	struct spibus_attach_args sba = {
+		.sba_controller = >sc_spi,
+	};
+	config_found(self, , spibus_print,
+	CFARG_DEVHANDLE, device_handle(self),
+	CFARG_EOL);
 }
 
 static int

Index: src/sys/arch/arm/sunxi/sun4i_spi.c
diff -u src/sys/arch/arm/sunxi/sun4i_spi.c:1.7 src/sys/arch/arm/sunxi/sun4i_spi.c:1.7.4.1
--- src/sys/arch/arm/sunxi/sun4i_spi.c:1.7	Wed Jan 27 03:10:20 

CVS commit: [thorpej-i2c-spi-conf] src/sys/dev

2021-05-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue May 18 23:48:16 UTC 2021

Modified Files:
src/sys/dev/fdt [thorpej-i2c-spi-conf]: fdt_spi.c
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_spi_subr.c
src/sys/dev/spi [thorpej-i2c-spi-conf]: spi.c spivar.h

Log Message:
Define a "spi-enumerate-devices" device call and use it for direct
configuration of SPI devices, rather than slinging arrays of dictionaries
around.  Implement this device call for OpenFirmware / FDT, following
the SPI bindings for Device Tree.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.2.2.1 src/sys/dev/fdt/fdt_spi.c
cvs rdiff -u -r1.1 -r1.1.6.1 src/sys/dev/ofw/ofw_spi_subr.c
cvs rdiff -u -r1.17 -r1.17.2.1 src/sys/dev/spi/spi.c
cvs rdiff -u -r1.10 -r1.10.6.1 src/sys/dev/spi/spivar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/fdt/fdt_spi.c
diff -u src/sys/dev/fdt/fdt_spi.c:1.2 src/sys/dev/fdt/fdt_spi.c:1.2.2.1
--- src/sys/dev/fdt/fdt_spi.c:1.2	Sat Apr 24 23:36:53 2021
+++ src/sys/dev/fdt/fdt_spi.c	Tue May 18 23:48:16 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_spi.c,v 1.2 2021/04/24 23:36:53 thorpej Exp $ */
+/* $NetBSD: fdt_spi.c,v 1.2.2.1 2021/05/18 23:48:16 thorpej Exp $ */
 
 /*
  * Copyright (c) 2019 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_spi.c,v 1.2 2021/04/24 23:36:53 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_spi.c,v 1.2.2.1 2021/05/18 23:48:16 thorpej Exp $");
 
 #include 
 #include 
@@ -84,33 +84,17 @@ device_t
 fdtbus_attach_spibus(device_t dev, int phandle, cfprint_t print)
 {
 	struct spi_controller *spi;
-	struct spibus_attach_args sba;
-	prop_dictionary_t devs;
-	device_t ret;
-	u_int address_cells;
-
-	devs = prop_dictionary_create();
-	if (of_getprop_uint32(phandle, "#address-cells", _cells))
-		address_cells = 1;
-	of_enter_spi_devs(devs, phandle, address_cells * 4);
 
 	spi = fdtbus_get_spi_controller(phandle);
 	KASSERT(spi != NULL);
-	memset(, 0, sizeof(sba));
-	sba.sba_controller = spi;
 
-	sba.sba_child_devices = prop_dictionary_get(devs, "spi-child-devices");
-	if (sba.sba_child_devices)
-		prop_object_retain(sba.sba_child_devices);
-	prop_object_release(devs);
-
-	ret = config_found(dev, , print,
+	struct spibus_attach_args sba = {
+		.sba_controller = spi,
+	};
+	return config_found(dev, , print,
 	CFARG_IATTR, "spibus",
+	CFARG_DEVHANDLE, device_handle(dev),
 	CFARG_EOL);
-	if (sba.sba_child_devices)
-		prop_object_release(sba.sba_child_devices);
-
-	return ret;
 }
 
 

Index: src/sys/dev/ofw/ofw_spi_subr.c
diff -u src/sys/dev/ofw/ofw_spi_subr.c:1.1 src/sys/dev/ofw/ofw_spi_subr.c:1.1.6.1
--- src/sys/dev/ofw/ofw_spi_subr.c:1.1	Thu Feb  4 20:19:09 2021
+++ src/sys/dev/ofw/ofw_spi_subr.c	Tue May 18 23:48:16 2021
@@ -1,100 +1,96 @@
-/*	$NetBSD: ofw_spi_subr.c,v 1.1 2021/02/04 20:19:09 thorpej Exp $	*/
+/*	$NetBSD: ofw_spi_subr.c,v 1.1.6.1 2021/05/18 23:48:16 thorpej Exp $	*/
 
 /*
- * Copyright 1998
- * Digital Equipment Corporation. All rights reserved.
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * All rights reserved.
  *
- * This software is furnished under license and may be used and
- * copied only in accordance with the following terms and conditions.
- * Subject to these conditions, you may download, copy, install,
- * use, modify and distribute this software in source and/or binary
- * form. No title or ownership is transferred hereby.
+ * 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.
  *
- * 1) Any source code used, modified or distributed must reproduce
- *and retain this copyright notice and list of conditions as
- *they appear in the source file.
- *
- * 2) No right is granted to use any trade name, trademark, or logo of
- *Digital Equipment Corporation. Neither the "Digital Equipment
- *Corporation" name nor any trademark or logo of Digital Equipment
- *Corporation may be used to endorse or promote products derived
- *from this software without the prior written permission of
- *Digital Equipment Corporation.
- *
- * 3) This software is provided "AS-IS" and any express or implied
- *warranties, including but not limited to, any implied warranties
- *of merchantability, fitness for a particular purpose, or
- *non-infringement are disclaimed. In no event shall DIGITAL be
- *liable for any damages whatsoever, and in particular, DIGITAL
- *shall not be liable for 

CVS commit: [thorpej-i2c-spi-conf] src/sys

2021-05-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue May 18 23:30:56 UTC 2021

Modified Files:
src/sys/arch/arm/at91 [thorpej-i2c-spi-conf]: at91spi.c
src/sys/arch/arm/broadcom [thorpej-i2c-spi-conf]: bcm2835_spi.c
src/sys/arch/arm/imx [thorpej-i2c-spi-conf]: imxspi.c
src/sys/arch/arm/sunxi [thorpej-i2c-spi-conf]: sun6i_spi.c
src/sys/arch/mips/alchemy/dev [thorpej-i2c-spi-conf]: auspi.c
src/sys/arch/mips/atheros/dev [thorpej-i2c-spi-conf]: arspi.c
src/sys/dev/marvell [thorpej-i2c-spi-conf]: mvspi.c

Log Message:
Pass the controller devhandle along to the "spi" instance.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.6.2.1 src/sys/arch/arm/at91/at91spi.c
cvs rdiff -u -r1.10 -r1.10.2.1 src/sys/arch/arm/broadcom/bcm2835_spi.c
cvs rdiff -u -r1.8 -r1.8.2.1 src/sys/arch/arm/imx/imxspi.c
cvs rdiff -u -r1.9 -r1.9.2.1 src/sys/arch/arm/sunxi/sun6i_spi.c
cvs rdiff -u -r1.10 -r1.10.2.1 src/sys/arch/mips/alchemy/dev/auspi.c
cvs rdiff -u -r1.14 -r1.14.2.1 src/sys/arch/mips/atheros/dev/arspi.c
cvs rdiff -u -r1.6 -r1.6.2.1 src/sys/dev/marvell/mvspi.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/at91/at91spi.c
diff -u src/sys/arch/arm/at91/at91spi.c:1.6 src/sys/arch/arm/at91/at91spi.c:1.6.2.1
--- src/sys/arch/arm/at91/at91spi.c:1.6	Sat Apr 24 23:36:26 2021
+++ src/sys/arch/arm/at91/at91spi.c	Tue May 18 23:30:55 2021
@@ -1,5 +1,5 @@
-/*	$Id: at91spi.c,v 1.6 2021/04/24 23:36:26 thorpej Exp $	*/
-/*	$NetBSD: at91spi.c,v 1.6 2021/04/24 23:36:26 thorpej Exp $	*/
+/*	$Id: at91spi.c,v 1.6.2.1 2021/05/18 23:30:55 thorpej Exp $	*/
+/*	$NetBSD: at91spi.c,v 1.6.2.1 2021/05/18 23:30:55 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2007 Embedtronics Oy. All rights reserved.
@@ -46,7 +46,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: at91spi.c,v 1.6 2021/04/24 23:36:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: at91spi.c,v 1.6.2.1 2021/05/18 23:30:55 thorpej Exp $");
 
 #include "locators.h"
 
@@ -105,7 +105,6 @@ at91spi_attach_common(device_t parent, d
 {
 	struct at91spi_softc *sc = device_private(self);
 	struct at91bus_attach_args *sa = aux;
-	struct spibus_attach_args sba;
 	bus_dma_segment_t segs;
 	int rsegs, err;
 
@@ -155,9 +154,6 @@ at91spi_attach_common(device_t parent, d
 		aprint_error("%s: no slaves!\n", device_xname(sc->sc_dev));
 	}
 
-	memset(, 0, sizeof(sba));
-	sba.sba_controller = >sc_spi;
-
 	/* initialize the queue */
 	SIMPLEQ_INIT(>sc_q);
 
@@ -193,7 +189,12 @@ at91spi_attach_common(device_t parent, d
 	PUTREG(sc, SPI_PDC_BASE + PDC_PTCR, PDC_PTCR_TXTEN | PDC_PTCR_RXTEN);
 
 	/* attach slave devices */
-	config_found(sc->sc_dev, , spibus_print, CFARG_EOL);
+	struct spibus_attach_args sba = {
+		.sba_controller = >sc_spi,
+	};
+	config_found(sc->sc_dev, , spibus_print,
+	CFARG_DEVHANDLE, device_handle(sc->sc_dev),
+	CFARG_EOL);
 }
 
 int

Index: src/sys/arch/arm/broadcom/bcm2835_spi.c
diff -u src/sys/arch/arm/broadcom/bcm2835_spi.c:1.10 src/sys/arch/arm/broadcom/bcm2835_spi.c:1.10.2.1
--- src/sys/arch/arm/broadcom/bcm2835_spi.c:1.10	Sat Apr 24 23:36:26 2021
+++ src/sys/arch/arm/broadcom/bcm2835_spi.c	Tue May 18 23:30:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: bcm2835_spi.c,v 1.10 2021/04/24 23:36:26 thorpej Exp $	*/
+/*	$NetBSD: bcm2835_spi.c,v 1.10.2.1 2021/05/18 23:30:55 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2012 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_spi.c,v 1.10 2021/04/24 23:36:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_spi.c,v 1.10.2.1 2021/05/18 23:30:55 thorpej Exp $");
 
 #include 
 #include 
@@ -95,7 +95,6 @@ bcmspi_attach(device_t parent, device_t 
 {
 	struct bcmspi_softc * const sc = device_private(self);
 	struct fdt_attach_args * const faa = aux;
-	struct spibus_attach_args sba;
 
 	aprint_naive("\n");
 	aprint_normal(": SPI\n");
@@ -138,10 +137,12 @@ bcmspi_attach(device_t parent, device_t 
 	sc->sc_spi.sct_transfer = bcmspi_transfer;
 	sc->sc_spi.sct_nslaves = 3;
 
-	memset(, 0, sizeof(sba));
-	sba.sba_controller = >sc_spi;
-
-	config_found(self, , spibus_print, CFARG_EOL);
+	struct spibus_attach_args sba = {
+		.sba_controller = >sc_spi,
+	};
+	config_found(self, , spibus_print,
+	CFARG_DEVHANDLE, device_handle(self),
+	CFARG_EOL);
 }
 
 static int

Index: src/sys/arch/arm/imx/imxspi.c
diff -u src/sys/arch/arm/imx/imxspi.c:1.8 src/sys/arch/arm/imx/imxspi.c:1.8.2.1
--- src/sys/arch/arm/imx/imxspi.c:1.8	Sat Apr 24 23:36:27 2021
+++ src/sys/arch/arm/imx/imxspi.c	Tue May 18 23:30:55 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: imxspi.c,v 1.8 2021/04/24 23:36:27 thorpej Exp $	*/
+/*	$NetBSD: imxspi.c,v 1.8.2.1 2021/05/18 23:30:55 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2014  Genetec Corporation.  All rights reserved.
@@ -32,7 +32,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: imxspi.c,v 1.8 2021/04/24 23:36:27 thorpej Exp $");

CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-18 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue May 18 23:26:46 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: i2c.c

Log Message:
Correct a comment.


To generate a diff of this commit:
cvs rdiff -u -r1.78.2.6 -r1.78.2.7 src/sys/dev/i2c/i2c.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/dev/i2c/i2c.c
diff -u src/sys/dev/i2c/i2c.c:1.78.2.6 src/sys/dev/i2c/i2c.c:1.78.2.7
--- src/sys/dev/i2c/i2c.c:1.78.2.6	Mon May 17 00:05:56 2021
+++ src/sys/dev/i2c/i2c.c	Tue May 18 23:26:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2c.c,v 1.78.2.6 2021/05/17 00:05:56 thorpej Exp $	*/
+/*	$NetBSD: i2c.c,v 1.78.2.7 2021/05/18 23:26:46 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78.2.6 2021/05/17 00:05:56 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78.2.7 2021/05/18 23:26:46 thorpej Exp $");
 
 #include 
 #include 
@@ -678,9 +678,8 @@ iic_attach(device_t parent, device_t sel
 		aprint_error_dev(self, "couldn't establish power handler\n");
 
 	/*
-	 * Attempt to enumerate the devices on the bus.  If
-	 * there is no enumeration method, or no devices are
-	 * found, then we will attempt indirect configuration.
+	 * Attempt to enumerate the devices on the bus.  If there is no
+	 * enumeration method, then we will attempt indirect configuration.
 	 */
 	struct i2c_enumerate_devices_args enumargs;
 	struct i2c_attach_args ia;



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/ofw

2021-05-17 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Tue May 18 01:24:39 UTC 2021

Modified Files:
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c

Log Message:
There is no code of DEC lineage in this file.


To generate a diff of this commit:
cvs rdiff -u -r1.1.6.7 -r1.1.6.8 src/sys/dev/ofw/ofw_i2c_subr.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/dev/ofw/ofw_i2c_subr.c
diff -u src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.7 src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.8
--- src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.7	Fri May 14 03:05:52 2021
+++ src/sys/dev/ofw/ofw_i2c_subr.c	Tue May 18 01:24:39 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.7 2021/05/14 03:05:52 thorpej Exp $	*/
+/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.8 2021/05/18 01:24:39 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -26,41 +26,8 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-/*
- * Copyright 1998
- * Digital Equipment Corporation. All rights reserved.
- *
- * This software is furnished under license and may be used and
- * copied only in accordance with the following terms and conditions.
- * Subject to these conditions, you may download, copy, install,
- * use, modify and distribute this software in source and/or binary
- * form. No title or ownership is transferred hereby.
- *
- * 1) Any source code used, modified or distributed must reproduce
- *and retain this copyright notice and list of conditions as
- *they appear in the source file.
- *
- * 2) No right is granted to use any trade name, trademark, or logo of
- *Digital Equipment Corporation. Neither the "Digital Equipment
- *Corporation" name nor any trademark or logo of Digital Equipment
- *Corporation may be used to endorse or promote products derived
- *from this software without the prior written permission of
- *Digital Equipment Corporation.
- *
- * 3) This software is provided "AS-IS" and any express or implied
- *warranties, including but not limited to, any implied warranties
- *of merchantability, fitness for a particular purpose, or
- *non-infringement are disclaimed. In no event shall DIGITAL be
- *liable for any damages whatsoever, and in particular, DIGITAL
- *shall not be liable for special, indirect, consequential, or
- *incidental damages or damages for lost profits, loss of
- *revenue or loss of use, whether such damages arise in contract,
- *negligence, tort, under statute, in equity, at law or otherwise,
- *even if advised of the possibility of such damage.
- */
-
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.7 2021/05/14 03:05:52 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.8 2021/05/18 01:24:39 thorpej Exp $");
 
 #include 
 #include 



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Mon May 17 00:05:56 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: i2c.c i2cvar.h

Log Message:
Remove "count" from the device enumeration callback arguments.


To generate a diff of this commit:
cvs rdiff -u -r1.78.2.5 -r1.78.2.6 src/sys/dev/i2c/i2c.c
cvs rdiff -u -r1.24.2.4 -r1.24.2.5 src/sys/dev/i2c/i2cvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/i2c/i2c.c
diff -u src/sys/dev/i2c/i2c.c:1.78.2.5 src/sys/dev/i2c/i2c.c:1.78.2.6
--- src/sys/dev/i2c/i2c.c:1.78.2.5	Sun May 16 21:04:59 2021
+++ src/sys/dev/i2c/i2c.c	Mon May 17 00:05:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2c.c,v 1.78.2.5 2021/05/16 21:04:59 thorpej Exp $	*/
+/*	$NetBSD: i2c.c,v 1.78.2.6 2021/05/17 00:05:56 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78.2.5 2021/05/16 21:04:59 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78.2.6 2021/05/17 00:05:56 thorpej Exp $");
 
 #include 
 #include 
@@ -618,8 +618,6 @@ iic_enumerate_devices_callback(device_t 
 	device_t newdev;
 	bool rv __diagused;
 
-	args->count++;
-
 	loc[IICCF_ADDR] = args->ia->ia_addr;
 
 	if (args->ia->ia_addr > I2C_MAX_ADDR) {

Index: src/sys/dev/i2c/i2cvar.h
diff -u src/sys/dev/i2c/i2cvar.h:1.24.2.4 src/sys/dev/i2c/i2cvar.h:1.24.2.5
--- src/sys/dev/i2c/i2cvar.h:1.24.2.4	Fri May 14 01:08:53 2021
+++ src/sys/dev/i2c/i2cvar.h	Mon May 17 00:05:56 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2cvar.h,v 1.24.2.4 2021/05/14 01:08:53 thorpej Exp $	*/
+/*	$NetBSD: i2cvar.h,v 1.24.2.5 2021/05/17 00:05:56 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -170,7 +170,6 @@ struct i2c_attach_args {
 struct i2c_enumerate_devices_args {
 	struct i2c_attach_args *ia;
 	bool (*callback)(device_t, struct i2c_enumerate_devices_args *);
-	unsigned int count;
 };
 
 /*



CVS commit: [thorpej-i2c-spi-conf] src/sys/arch/sparc64/sparc64

2021-05-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 16 23:45:12 UTC 2021

Modified Files:
src/sys/arch/sparc64/sparc64 [thorpej-i2c-spi-conf]: ofw_patch.c

Log Message:
- i2c_fixup_enumerate_devices(): handle getting a NULL "compatible"
  property.
- sparcle_smbus_fixup(): remove bogus place-holder compatible properties
  for the SPD entries.


To generate a diff of this commit:
cvs rdiff -u -r1.7.4.2 -r1.7.4.3 src/sys/arch/sparc64/sparc64/ofw_patch.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/sparc64/sparc64/ofw_patch.c
diff -u src/sys/arch/sparc64/sparc64/ofw_patch.c:1.7.4.2 src/sys/arch/sparc64/sparc64/ofw_patch.c:1.7.4.3
--- src/sys/arch/sparc64/sparc64/ofw_patch.c:1.7.4.2	Sat May 15 21:19:46 2021
+++ src/sys/arch/sparc64/sparc64/ofw_patch.c	Sun May 16 23:45:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_patch.c,v 1.7.4.2 2021/05/15 21:19:46 thorpej Exp $ */
+/*	$NetBSD: ofw_patch.c,v 1.7.4.3 2021/05/16 23:45:12 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020, 2021 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.7.4.2 2021/05/15 21:19:46 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.7.4.3 2021/05/16 23:45:12 thorpej Exp $");
 
 #include 
 #include 
@@ -153,7 +153,9 @@ i2c_fixup_enumerate_devices(device_t dev
 		args->ia->ia_addr = i2c_adds[i].addr;
 		args->ia->ia_name = i2c_adds[i].name;
 		args->ia->ia_clist = i2c_adds[i].compat;
-		args->ia->ia_clist_size = strlen(i2c_adds[i].compat) + 1;
+		args->ia->ia_clist_size = args->ia->ia_clist != NULL
+		? strlen(i2c_adds[i].compat) + 1
+		: 0;
 		args->ia->ia_prop = props;
 		if (fixup->i2c_phandle != 0) {
 			args->ia->ia_devhandle =
@@ -697,10 +699,8 @@ static void
 sparcle_smbus_fixup(device_t dev, void *aux)
 {
 	static const struct i2c_addition i2c_adds[] = {
-		{ .name = "dimm-spd",
-		  .compat = "netbsd,dimm-spd", .addr = 0x50 },
-		{ .name = "dimm-spd",
-		  .compat = "netbsd,dimm-spd", .addr = 0x51 },
+		{ .name = "dimm-spd",	.addr = 0x50 },
+		{ .name = "dimm-spd",	.addr = 0x51 },
 	};
 	devhandle_t devhandle = device_handle(dev);
 	KASSERT(devhandle_type(devhandle) == DEVHANDLE_TYPE_OF);



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 16 22:56:48 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: spdmem_i2c.c

Log Message:
Tweak previous to deal better with "device tree node describes empty
DIMM slot" problem.


To generate a diff of this commit:
cvs rdiff -u -r1.21.4.4 -r1.21.4.5 src/sys/dev/i2c/spdmem_i2c.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/dev/i2c/spdmem_i2c.c
diff -u src/sys/dev/i2c/spdmem_i2c.c:1.21.4.4 src/sys/dev/i2c/spdmem_i2c.c:1.21.4.5
--- src/sys/dev/i2c/spdmem_i2c.c:1.21.4.4	Sun May 16 22:53:57 2021
+++ src/sys/dev/i2c/spdmem_i2c.c	Sun May 16 22:56:47 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: spdmem_i2c.c,v 1.21.4.4 2021/05/16 22:53:57 thorpej Exp $ */
+/* $NetBSD: spdmem_i2c.c,v 1.21.4.5 2021/05/16 22:56:47 thorpej Exp $ */
 
 /*
  * Copyright (c) 2007 Nicolas Joly
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21.4.4 2021/05/16 22:53:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21.4.5 2021/05/16 22:56:47 thorpej Exp $");
 
 #include 
 #include 
@@ -243,7 +243,7 @@ spdmem_i2c_match(device_t parent, cfdata
 	sc.sc_page0 = SPDCTL_SPA0;
 	sc.sc_page1 = SPDCTL_SPA1;
 	sc.sc_base.sc_read = spdmem_i2c_read;
-	match_result = SPDMEM_HIGH_CONFIDENCE_MATCH;
+	match_result = 0;
 
  do_probe:
 	/* Check the bank and reset to the page 0 */
@@ -254,8 +254,6 @@ spdmem_i2c_match(device_t parent, cfdata
 		if (match_result < SPDMEM_HIGH_CONFIDENCE_MATCH) {
 			match_result = SPDMEM_HIGH_CONFIDENCE_MATCH;
 		}
-	} else {
-		match_result = 0;
 	}
 
 	return match_result;



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 16 22:53:57 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: spdmem_i2c.c

Log Message:
Go back to probing in the direct config case, and return a high confidence
match value if the SPD probe succeeds.  This ensures that we beat a generic
i2c serial eeprom driver if the contents looks like they contain SPD data.


To generate a diff of this commit:
cvs rdiff -u -r1.21.4.3 -r1.21.4.4 src/sys/dev/i2c/spdmem_i2c.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/dev/i2c/spdmem_i2c.c
diff -u src/sys/dev/i2c/spdmem_i2c.c:1.21.4.3 src/sys/dev/i2c/spdmem_i2c.c:1.21.4.4
--- src/sys/dev/i2c/spdmem_i2c.c:1.21.4.3	Sun May 16 15:40:20 2021
+++ src/sys/dev/i2c/spdmem_i2c.c	Sun May 16 22:53:57 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: spdmem_i2c.c,v 1.21.4.3 2021/05/16 15:40:20 thorpej Exp $ */
+/* $NetBSD: spdmem_i2c.c,v 1.21.4.4 2021/05/16 22:53:57 thorpej Exp $ */
 
 /*
  * Copyright (c) 2007 Nicolas Joly
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21.4.3 2021/05/16 15:40:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21.4.4 2021/05/16 22:53:57 thorpej Exp $");
 
 #include 
 #include 
@@ -190,6 +190,8 @@ static const struct device_compatible_en
 	DEVICE_COMPAT_EOL
 };
 
+#define	SPDMEM_HIGH_CONFIDENCE_MATCH	(I2C_MATCH_DIRECT_COMPATIBLE + 20)
+
 static bool
 spdmem_i2c_use_name_match(const struct i2c_attach_args *ia, int *match_resultp)
 {
@@ -197,7 +199,7 @@ spdmem_i2c_use_name_match(const struct i
 
 	if (name != NULL) {
 		*match_resultp = device_compatible_match(, 1, name_data)
-		? I2C_MATCH_DIRECT_COMPATIBLE
+		? SPDMEM_HIGH_CONFIDENCE_MATCH
 		: 0;
 		return true;
 	}
@@ -209,9 +211,6 @@ spdmem_i2c_use_direct_match(const struct
 			const struct device_compatible_entry *cdata,
 			int *match_resultp)
 {
-	if (iic_use_direct_match(ia, cf, cdata, match_resultp))
-		return true;
-
 	/*
 	 * Matching by name is not ideal, but some device trees only
 	 * have a name and no "compatible" property.
@@ -219,6 +218,9 @@ spdmem_i2c_use_direct_match(const struct
 	if (spdmem_i2c_use_name_match(ia, match_resultp))
 		return true;
 
+	if (iic_use_direct_match(ia, cf, cdata, match_resultp))
+		return true;
+
 	return false;
 }
 
@@ -230,7 +232,7 @@ spdmem_i2c_match(device_t parent, cfdata
 	int match_result;
 
 	if (spdmem_i2c_use_direct_match(ia, match, compat_data, _result))
-		return match_result;
+		goto do_probe;
 
 	/* Filter out by address when not using direct config. */
 	if ((ia->ia_addr & SPDMEM_I2C_ADDRMASK) != SPDMEM_I2C_ADDR)
@@ -241,14 +243,22 @@ spdmem_i2c_match(device_t parent, cfdata
 	sc.sc_page0 = SPDCTL_SPA0;
 	sc.sc_page1 = SPDCTL_SPA1;
 	sc.sc_base.sc_read = spdmem_i2c_read;
+	match_result = SPDMEM_HIGH_CONFIDENCE_MATCH;
 
+ do_probe:
 	/* Check the bank and reset to the page 0 */
 	if (spdmem_reset_page() != 0)
 		return 0;
 
-	return spdmem_common_probe(_base)
-	? I2C_MATCH_ADDRESS_AND_PROBE
-	: 0;
+	if (spdmem_common_probe(_base)) {
+		if (match_result < SPDMEM_HIGH_CONFIDENCE_MATCH) {
+			match_result = SPDMEM_HIGH_CONFIDENCE_MATCH;
+		}
+	} else {
+		match_result = 0;
+	}
+
+	return match_result;
 }
 
 static void



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 16 21:04:59 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: i2c.c

Log Message:
Check for errors from iic_acquire_bus() in iic_ioctl_exec().


To generate a diff of this commit:
cvs rdiff -u -r1.78.2.4 -r1.78.2.5 src/sys/dev/i2c/i2c.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/dev/i2c/i2c.c
diff -u src/sys/dev/i2c/i2c.c:1.78.2.4 src/sys/dev/i2c/i2c.c:1.78.2.5
--- src/sys/dev/i2c/i2c.c:1.78.2.4	Sun May 16 21:03:38 2021
+++ src/sys/dev/i2c/i2c.c	Sun May 16 21:04:59 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2c.c,v 1.78.2.4 2021/05/16 21:03:38 thorpej Exp $	*/
+/*	$NetBSD: i2c.c,v 1.78.2.5 2021/05/16 21:04:59 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78.2.4 2021/05/16 21:03:38 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78.2.5 2021/05/16 21:04:59 thorpej Exp $");
 
 #include 
 #include 
@@ -1005,7 +1005,9 @@ iic_ioctl_exec(struct iic_softc *sc, i2c
 			goto out;
 	}
 
-	iic_acquire_bus(ic, 0);
+	if ((error = iic_acquire_bus(ic, 0)) != 0) {
+		goto out;
+	}
 	error = iic_exec(ic, iie->iie_op, iie->iie_addr, cmd, iie->iie_cmdlen,
 	buf, iie->iie_buflen, 0);
 	iic_release_bus(ic, 0);



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 16 21:03:38 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: i2c.c

Log Message:
- Set D_MCLOSE in the iic_cdevsw so that we get a d_close call for
  each close so that the module ref counting works properly.
- Rearrange things a little to avoid holding the iic_mtx a long as
  previously done.


To generate a diff of this commit:
cvs rdiff -u -r1.78.2.3 -r1.78.2.4 src/sys/dev/i2c/i2c.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/dev/i2c/i2c.c
diff -u src/sys/dev/i2c/i2c.c:1.78.2.3 src/sys/dev/i2c/i2c.c:1.78.2.4
--- src/sys/dev/i2c/i2c.c:1.78.2.3	Sun May 16 04:40:08 2021
+++ src/sys/dev/i2c/i2c.c	Sun May 16 21:03:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2c.c,v 1.78.2.3 2021/05/16 04:40:08 thorpej Exp $	*/
+/*	$NetBSD: i2c.c,v 1.78.2.4 2021/05/16 21:03:38 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78.2.3 2021/05/16 04:40:08 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78.2.4 2021/05/16 21:03:38 thorpej Exp $");
 
 #include 
 #include 
@@ -115,13 +115,6 @@ static dev_type_open(iic_open);
 static dev_type_close(iic_close);
 static dev_type_ioctl(iic_ioctl);
 
-int iic_init(void);
-
-kmutex_t iic_mtx;
-int iic_refcnt;
-
-ONCE_DECL(iic_once);
-
 const struct cdevsw iic_cdevsw = {
 	.d_open = iic_open,
 	.d_close = iic_close,
@@ -134,11 +127,16 @@ const struct cdevsw iic_cdevsw = {
 	.d_mmap = nommap,
 	.d_kqfilter = nokqfilter,
 	.d_discard = nodiscard,
-	.d_flag = D_OTHER
+	.d_flag = D_OTHER | D_MCLOSE,
 };
 
 static void	iic_smbus_intr_thread(void *);
 
+static kmutex_t iic_mtx;
+static int iic_refcnt;
+static bool iic_unloading;
+static ONCE_DECL(iic_once);
+
 static struct i2c_device_link *
 iic_devslot_lookup(struct iic_softc *sc, i2c_addr_t addr)
 {
@@ -928,22 +926,43 @@ iic_use_direct_match(const struct i2c_at
 static int
 iic_open(dev_t dev, int flag, int fmt, lwp_t *l)
 {
-	struct iic_softc *sc = device_lookup_private(_cd, minor(dev));
+	struct iic_softc *sc;
 
 	mutex_enter(_mtx);
-	if (sc == NULL) {
+
+	if (iic_unloading) {
 		mutex_exit(_mtx);
 		return ENXIO;
 	}
+
+	/* Hold a refrence while we look up the softc. */
+	if (iic_refcnt == INT_MAX) {
+		mutex_exit(_mtx);
+		return EBUSY;
+	}
 	iic_refcnt++;
+
 	mutex_exit(_mtx);
 
+	sc = device_lookup_private(_cd, minor(dev));
+
+	if (sc == NULL) {
+		mutex_enter(_mtx);
+		iic_refcnt--;
+		mutex_exit(_mtx);
+		return ENXIO;
+	}
+
 	return 0;
 }
 
 static int
 iic_close(dev_t dev, int flag, int fmt, lwp_t *l)
 {
+	struct iic_softc *sc = device_lookup_private(_cd, minor(dev));;
+
+	KASSERT(iic_refcnt != 0);
+	KASSERT(sc != NULL);
 
 	mutex_enter(_mtx);
 	iic_refcnt--;
@@ -1037,7 +1056,7 @@ MODULE(MODULE_CLASS_DRIVER, iic, "i2cexe
 #include "ioconf.c"
 #endif
 
-int
+static int
 iic_init(void)
 {
 
@@ -1084,19 +1103,26 @@ iic_modcmd(modcmd_t cmd, void *opaque)
 			mutex_exit(_mtx);
 			return EBUSY;
 		}
+		iic_unloading = true;
+		mutex_exit(_mtx);
 #ifdef _MODULE
 		error = config_fini_component(cfdriver_ioconf_iic,
 		cfattach_ioconf_iic, cfdata_ioconf_iic);
 		if (error != 0) {
+			mutex_enter(_mtx);
+			iic_unloading = false;
 			mutex_exit(_mtx);
 			break;
 		}
 		error = devsw_detach(NULL, _cdevsw);
-		if (error != 0)
+		if (error != 0) {
 			config_init_component(cfdriver_ioconf_iic,
 			cfattach_ioconf_iic, cfdata_ioconf_iic);
+			mutex_enter(_mtx);
+			iic_unloading = false;
+			mutex_exit(_mtx);
+		}
 #endif
-		mutex_exit(_mtx);
 		break;
 	default:
 		error = ENOTTY;



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 16 15:40:20 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: spdmem_i2c.c

Log Message:
Check for errors from iic_acquire_bus().


To generate a diff of this commit:
cvs rdiff -u -r1.21.4.2 -r1.21.4.3 src/sys/dev/i2c/spdmem_i2c.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/dev/i2c/spdmem_i2c.c
diff -u src/sys/dev/i2c/spdmem_i2c.c:1.21.4.2 src/sys/dev/i2c/spdmem_i2c.c:1.21.4.3
--- src/sys/dev/i2c/spdmem_i2c.c:1.21.4.2	Sun May 16 15:27:12 2021
+++ src/sys/dev/i2c/spdmem_i2c.c	Sun May 16 15:40:20 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: spdmem_i2c.c,v 1.21.4.2 2021/05/16 15:27:12 thorpej Exp $ */
+/* $NetBSD: spdmem_i2c.c,v 1.21.4.3 2021/05/16 15:40:20 thorpej Exp $ */
 
 /*
  * Copyright (c) 2007 Nicolas Joly
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21.4.2 2021/05/16 15:27:12 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21.4.3 2021/05/16 15:40:20 thorpej Exp $");
 
 #include 
 #include 
@@ -107,7 +107,9 @@ spdmem_reset_page(struct spdmem_i2c_soft
 
 	reg = 0;
 
-	iic_acquire_bus(sc->sc_tag, 0);
+	if ((rv = iic_acquire_bus(sc->sc_tag, 0)) != 0) {
+		return rv;
+	}
 
 	/*
 	 * Try to read byte 0 and 2. If it failed, it's not spdmem or a device
@@ -306,7 +308,8 @@ spdmem_i2c_read(struct spdmem_softc *sof
 
 	reg = addr & 0xff;
 
-	iic_acquire_bus(sc->sc_tag, 0);
+	if ((rv = iic_acquire_bus(sc->sc_tag, 0)) != 0)
+		return rv;
 
 	if (addr & 0x100) {
 		rv = iic_exec(sc->sc_tag, I2C_OP_WRITE_WITH_STOP, sc->sc_page1,



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-16 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 16 15:27:12 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: spdmem_i2c.c

Log Message:
The last change had an unfortunate side-effect on empty DIMM slots, so
roll that back.  Instead, if we used direct config, then probe for the
module in the attach routine and report if the module is not present,
rather than assuming that it is.

Encapsulate the direct config logic for SPD into one place for clarity.


To generate a diff of this commit:
cvs rdiff -u -r1.21.4.1 -r1.21.4.2 src/sys/dev/i2c/spdmem_i2c.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/dev/i2c/spdmem_i2c.c
diff -u src/sys/dev/i2c/spdmem_i2c.c:1.21.4.1 src/sys/dev/i2c/spdmem_i2c.c:1.21.4.2
--- src/sys/dev/i2c/spdmem_i2c.c:1.21.4.1	Sun May 16 05:16:21 2021
+++ src/sys/dev/i2c/spdmem_i2c.c	Sun May 16 15:27:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: spdmem_i2c.c,v 1.21.4.1 2021/05/16 05:16:21 thorpej Exp $ */
+/* $NetBSD: spdmem_i2c.c,v 1.21.4.2 2021/05/16 15:27:12 thorpej Exp $ */
 
 /*
  * Copyright (c) 2007 Nicolas Joly
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21.4.1 2021/05/16 05:16:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21.4.2 2021/05/16 15:27:12 thorpej Exp $");
 
 #include 
 #include 
@@ -178,6 +178,48 @@ static const struct device_compatible_en
 	DEVICE_COMPAT_EOL
 };
 
+/*
+ * Some device trees don't have real "compatible" entries, so we
+ * end up having to match by name.
+ */
+static const struct device_compatible_entry name_data[] = {
+	{ .compat = "dimm-spd" },
+	{ .compat = "dimm" },
+	DEVICE_COMPAT_EOL
+};
+
+static bool
+spdmem_i2c_use_name_match(const struct i2c_attach_args *ia, int *match_resultp)
+{
+	const char *name = ia->ia_name;
+
+	if (name != NULL) {
+		*match_resultp = device_compatible_match(, 1, name_data)
+		? I2C_MATCH_DIRECT_COMPATIBLE
+		: 0;
+		return true;
+	}
+	return false;
+}
+
+static bool
+spdmem_i2c_use_direct_match(const struct i2c_attach_args *ia, const cfdata_t cf,
+			const struct device_compatible_entry *cdata,
+			int *match_resultp)
+{
+	if (iic_use_direct_match(ia, cf, cdata, match_resultp))
+		return true;
+
+	/*
+	 * Matching by name is not ideal, but some device trees only
+	 * have a name and no "compatible" property.
+	 */
+	if (spdmem_i2c_use_name_match(ia, match_resultp))
+		return true;
+
+	return false;
+}
+
 static int
 spdmem_i2c_match(device_t parent, cfdata_t match, void *aux)
 {
@@ -185,45 +227,13 @@ spdmem_i2c_match(device_t parent, cfdata
 	struct spdmem_i2c_softc sc;
 	int match_result;
 
-	/*
-	 * SPD stands for "Serial Presence Detect".  This implies that
-	 * if we're using direct configuration that we should treat
-	 * that as a *hint*... it's entirely possible that a device
-	 * tree lists locations where SPD memory can be found, not
-	 * necessarily where memory is known to be present.
-	 *
-	 * Accordingly, if we get a direct configuration match based
-	 * on compatible data or device name, we still check to see
-	 * if the device is there.
-	 */
-
-	if (iic_use_direct_match(ia, match, compat_data, _result)) {
-		if (match_result != 0) {
-			goto do_probe;
-		}
-		return 0;
-	}
+	if (spdmem_i2c_use_direct_match(ia, match, compat_data, _result))
+		return match_result;
 
-	if (ia->ia_name) {
-		/* add other names as we find more firmware variations */
-		if (strcmp(ia->ia_name, "dimm-spd") == 0 ||
-		strcmp(ia->ia_name, "dimm") == 0) {
-			match_result = I2C_MATCH_DIRECT_SPECIFIC;
-			goto do_probe;
-		}
+	/* Filter out by address when not using direct config. */
+	if ((ia->ia_addr & SPDMEM_I2C_ADDRMASK) != SPDMEM_I2C_ADDR)
 		return 0;
-	}
 
-	/* As a last resort, filter out invalid addresses. */
-	if ((ia->ia_addr & SPDMEM_I2C_ADDRMASK) == SPDMEM_I2C_ADDR) {
-		match_result = I2C_MATCH_ADDRESS_AND_PROBE;
-		goto do_probe;
-	}
-	
-	/* Not a candidate address. */
-	return 0;
-
- do_probe:
 	sc.sc_tag = ia->ia_tag;
 	sc.sc_addr = ia->ia_addr;
 	sc.sc_page0 = SPDCTL_SPA0;
@@ -234,10 +244,9 @@ spdmem_i2c_match(device_t parent, cfdata
 	if (spdmem_reset_page() != 0)
 		return 0;
 
-	if (spdmem_common_probe(_base)) {
-		return match_result;
-	}
-	return 0;
+	return spdmem_common_probe(_base)
+	? I2C_MATCH_ADDRESS_AND_PROBE
+	: 0;
 }
 
 static void
@@ -245,6 +254,7 @@ spdmem_i2c_attach(device_t parent, devic
 {
 	struct spdmem_i2c_softc *sc = device_private(self);
 	struct i2c_attach_args *ia = aux;
+	int match_result;
 
 	sc->sc_tag = ia->ia_tag;
 	sc->sc_addr = ia->ia_addr;
@@ -252,10 +262,28 @@ spdmem_i2c_attach(device_t parent, devic
 	sc->sc_page1 = SPDCTL_SPA1;
 	sc->sc_base.sc_read = spdmem_i2c_read;
 
-	if (!pmf_device_register(self, NULL, NULL))
-		aprint_error_dev(self, "couldn't establish power handler\n");
+	/*
+	 * SPD stands for "Serial Presence Detect".  If we're using
+	 * direct 

CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-15 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 16 05:16:21 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: spdmem_i2c.c

Log Message:
SPD stands for "Serial Presence Detect".  This implies that
if we're using direct configuration that we should treat
that as a *hint*... it's entirely possible that a device
tree lists locations where SPD memory can be found, not
necessarily where memory is known to be present.

Accordingly, if we get a direct configuration match based
on compatible data or device name, we still check to see
if the device is there.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.21.4.1 src/sys/dev/i2c/spdmem_i2c.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/dev/i2c/spdmem_i2c.c
diff -u src/sys/dev/i2c/spdmem_i2c.c:1.21 src/sys/dev/i2c/spdmem_i2c.c:1.21.4.1
--- src/sys/dev/i2c/spdmem_i2c.c:1.21	Wed Jan 27 02:29:48 2021
+++ src/sys/dev/i2c/spdmem_i2c.c	Sun May 16 05:16:21 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: spdmem_i2c.c,v 1.21 2021/01/27 02:29:48 thorpej Exp $ */
+/* $NetBSD: spdmem_i2c.c,v 1.21.4.1 2021/05/16 05:16:21 thorpej Exp $ */
 
 /*
  * Copyright (c) 2007 Nicolas Joly
@@ -40,7 +40,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21 2021/01/27 02:29:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: spdmem_i2c.c,v 1.21.4.1 2021/05/16 05:16:21 thorpej Exp $");
 
 #include 
 #include 
@@ -185,31 +185,45 @@ spdmem_i2c_match(device_t parent, cfdata
 	struct spdmem_i2c_softc sc;
 	int match_result;
 
-	if (iic_use_direct_match(ia, match, compat_data, _result))
-		return match_result;
-
 	/*
-	 * XXXJRT
-	 * Should do this with "compatible" strings.  There are also
-	 * other problems with this "match" routine.  Specifically, if
-	 * we are doing direct-config, we know the device is already
-	 * there aren't do need to probe.  I'll leave the logic for
-	 * now and let someone who knows better clean it later.
+	 * SPD stands for "Serial Presence Detect".  This implies that
+	 * if we're using direct configuration that we should treat
+	 * that as a *hint*... it's entirely possible that a device
+	 * tree lists locations where SPD memory can be found, not
+	 * necessarily where memory is known to be present.
+	 *
+	 * Accordingly, if we get a direct configuration match based
+	 * on compatible data or device name, we still check to see
+	 * if the device is there.
 	 */
 
+	if (iic_use_direct_match(ia, match, compat_data, _result)) {
+		if (match_result != 0) {
+			goto do_probe;
+		}
+		return 0;
+	}
+
 	if (ia->ia_name) {
 		/* add other names as we find more firmware variations */
-		if (strcmp(ia->ia_name, "dimm-spd") &&
-		strcmp(ia->ia_name, "dimm"))
-			return 0;
+		if (strcmp(ia->ia_name, "dimm-spd") == 0 ||
+		strcmp(ia->ia_name, "dimm") == 0) {
+			match_result = I2C_MATCH_DIRECT_SPECIFIC;
+			goto do_probe;
+		}
+		return 0;
 	}
 
-	/* only do this lame test when not using direct config */
-	if (ia->ia_name == NULL) {
-		if ((ia->ia_addr & SPDMEM_I2C_ADDRMASK) != SPDMEM_I2C_ADDR)
-			return 0;
+	/* As a last resort, filter out invalid addresses. */
+	if ((ia->ia_addr & SPDMEM_I2C_ADDRMASK) == SPDMEM_I2C_ADDR) {
+		match_result = I2C_MATCH_ADDRESS_AND_PROBE;
+		goto do_probe;
 	}
+	
+	/* Not a candidate address. */
+	return 0;
 
+ do_probe:
 	sc.sc_tag = ia->ia_tag;
 	sc.sc_addr = ia->ia_addr;
 	sc.sc_page0 = SPDCTL_SPA0;
@@ -221,8 +235,7 @@ spdmem_i2c_match(device_t parent, cfdata
 		return 0;
 
 	if (spdmem_common_probe(_base)) {
-		return ia->ia_name ? I2C_MATCH_DIRECT_SPECIFIC
-   : I2C_MATCH_ADDRESS_AND_PROBE;
+		return match_result;
 	}
 	return 0;
 }



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-15 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May 16 04:40:08 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: i2c.c

Log Message:
Rather than allocating 8KB (!!) of space per i2c bus for a sparsely
populated array of child devices, use a sorted list instead, optimized
a bit for the common usage pattern.


To generate a diff of this commit:
cvs rdiff -u -r1.78.2.2 -r1.78.2.3 src/sys/dev/i2c/i2c.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/dev/i2c/i2c.c
diff -u src/sys/dev/i2c/i2c.c:1.78.2.2 src/sys/dev/i2c/i2c.c:1.78.2.3
--- src/sys/dev/i2c/i2c.c:1.78.2.2	Sat May  8 11:34:38 2021
+++ src/sys/dev/i2c/i2c.c	Sun May 16 04:40:08 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2c.c,v 1.78.2.2 2021/05/08 11:34:38 thorpej Exp $	*/
+/*	$NetBSD: i2c.c,v 1.78.2.3 2021/05/16 04:40:08 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78.2.2 2021/05/08 11:34:38 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78.2.3 2021/05/16 04:40:08 thorpej Exp $");
 
 #include 
 #include 
@@ -95,10 +95,20 @@ __KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78
 #define I2C_MAX_ADDR	0x3ff	/* 10-bit address, max */
 #endif
 
+struct i2c_device_link {
+	TAILQ_ENTRY(i2c_device_link) l_list;
+	device_t		l_device;
+	i2c_addr_t		l_addr;
+};
+
+TAILQ_HEAD(i2c_devlist_head, i2c_device_link);
+
 struct iic_softc {
 	device_t sc_dev;
 	i2c_tag_t sc_tag;
-	device_t sc_devices[I2C_MAX_ADDR + 1];
+
+	kmutex_t sc_devlist_lock;
+	struct i2c_devlist_head sc_devlist;
 };
 
 static dev_type_open(iic_open);
@@ -129,6 +139,179 @@ const struct cdevsw iic_cdevsw = {
 
 static void	iic_smbus_intr_thread(void *);
 
+static struct i2c_device_link *
+iic_devslot_lookup(struct iic_softc *sc, i2c_addr_t addr)
+{
+	struct i2c_device_link *link;
+
+	KASSERT(mutex_owned(>sc_devlist_lock));
+
+	/*
+	 * A common pattern is "reserve then insert or delete", and
+	 * this is often done in increasing address order.  So check
+	 * if the last entry is the one we're looking for before we
+	 * search the list from the front.
+	 */
+	link = TAILQ_LAST(>sc_devlist, i2c_devlist_head);
+	if (link == NULL) {
+		/* List is empty. */
+		return NULL;
+	}
+	if (link->l_addr == addr) {
+		return link;
+	}
+
+	TAILQ_FOREACH(link, >sc_devlist, l_list) {
+		/*
+		 * The list is sorted, so if the current list element
+		 * has an address larger than the one we're looking
+		 * for, then it's not in the list.
+		 */
+		if (link->l_addr > addr) {
+			break;
+		}
+		if (link->l_addr == addr) {
+			return link;
+		}
+	}
+	return NULL;
+}
+
+static bool
+iic_devslot_reserve(struct iic_softc *sc, i2c_addr_t addr)
+{
+	struct i2c_device_link *link, *new_link;
+
+	new_link = kmem_zalloc(sizeof(*new_link), KM_SLEEP);
+	new_link->l_addr = addr;
+
+	mutex_enter(>sc_devlist_lock);
+
+	/* Optimize for reserving in increasing i2c address order. */
+	link = TAILQ_LAST(>sc_devlist, i2c_devlist_head);
+	if (link == NULL || link->l_addr < new_link->l_addr) {
+		TAILQ_INSERT_TAIL(>sc_devlist, new_link, l_list);
+		new_link = NULL;
+		goto done;
+	}
+	KASSERT(!TAILQ_EMPTY(>sc_devlist));
+
+	/* Sort the new entry into the list. */
+	TAILQ_FOREACH(link, >sc_devlist, l_list) {
+		if (link->l_addr < new_link->l_addr) {
+			continue;
+		}
+		if (link->l_addr == new_link->l_addr) {
+			/* Address is already reserved / in-use. */
+			goto done;
+		}
+		/*
+		 * If we get here, we know we should be inserted
+		 * before this element, because we checked to see
+		 * if we should be the last entry before entering
+		 * the loop.
+		 */
+		KASSERT(link->l_addr > new_link->l_addr);
+		TAILQ_INSERT_BEFORE(link, new_link, l_list);
+		new_link = NULL;
+		break;
+	}
+	/*
+	 * Because we checked for an empty list early, if we got
+	 * here it means we inserted before "link".
+	 */
+	KASSERT(link != NULL);
+	KASSERT(TAILQ_NEXT(new_link, l_list) == link);
+
+ done:
+	mutex_exit(>sc_devlist_lock);
+
+	if (new_link != NULL) {
+		kmem_free(new_link, sizeof(*new_link));
+		return false;
+	}
+	return true;
+}
+
+static bool
+iic_devslot_insert(struct iic_softc *sc, device_t dev, i2c_addr_t addr)
+{
+	struct i2c_device_link *link;
+	bool rv = false;
+
+	mutex_enter(>sc_devlist_lock);
+
+	link = iic_devslot_lookup(sc, addr);
+	if (link != NULL) {
+		if (link->l_device == NULL) {
+			link->l_device = dev;
+			rv = true;
+		}
+	}
+
+	mutex_exit(>sc_devlist_lock);
+
+	return rv;
+}
+
+static bool
+iic_devslot_remove(struct iic_softc *sc, device_t dev, i2c_addr_t addr)
+{
+	struct i2c_device_link *link;
+	bool rv = false;
+
+	mutex_enter(>sc_devlist_lock);
+
+	link = iic_devslot_lookup(sc, addr);
+	if (link != NULL) {
+		if (link->l_device == dev) {
+			TAILQ_REMOVE(>sc_devlist, link, l_list);
+			rv = true;
+		} else {
+			link = NULL;
+		}
+	}
+
+	mutex_exit(>sc_devlist_lock);
+
+	if (link != NULL) {
+		

CVS commit: [thorpej-i2c-spi-conf] src/sys/arch/sparc64/sparc64

2021-05-15 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May 15 21:19:46 UTC 2021

Modified Files:
src/sys/arch/sparc64/sparc64 [thorpej-i2c-spi-conf]: ofw_patch.c

Log Message:
Fix the path to the E450 envctrl DT node. Thanks, he@!


To generate a diff of this commit:
cvs rdiff -u -r1.7.4.1 -r1.7.4.2 src/sys/arch/sparc64/sparc64/ofw_patch.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/sparc64/sparc64/ofw_patch.c
diff -u src/sys/arch/sparc64/sparc64/ofw_patch.c:1.7.4.1 src/sys/arch/sparc64/sparc64/ofw_patch.c:1.7.4.2
--- src/sys/arch/sparc64/sparc64/ofw_patch.c:1.7.4.1	Sat May 15 03:22:17 2021
+++ src/sys/arch/sparc64/sparc64/ofw_patch.c	Sat May 15 21:19:46 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_patch.c,v 1.7.4.1 2021/05/15 03:22:17 thorpej Exp $ */
+/*	$NetBSD: ofw_patch.c,v 1.7.4.2 2021/05/15 21:19:46 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020, 2021 The NetBSD Foundation, Inc.
@@ -29,7 +29,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.7.4.1 2021/05/15 03:22:17 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_patch.c,v 1.7.4.2 2021/05/15 21:19:46 thorpej Exp $");
 
 #include 
 #include 
@@ -679,8 +679,7 @@ e450_envctrl_fixup(device_t dev, void *a
 }
 
 static const struct device_compatible_entry dtnode_fixup_table_e450[] = {
-	/* XXX Could make this into a special fixup, but dtnode is nicer. */
-	{ .compat = "/XXX/need/the/OFW/path",
+	{ .compat = "/pci/ebus@1/SUNW,envctrl@14,60",
 	  .data = e450_envctrl_fixup },
 
 	DEVICE_COMPAT_EOL



CVS commit: [thorpej-i2c-spi-conf] src/sys/arch/sparc64

2021-05-14 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May 15 03:22:17 UTC 2021

Modified Files:
src/sys/arch/sparc64/dev [thorpej-i2c-spi-conf]: pcf8591_envctrl.c
src/sys/arch/sparc64/sparc64 [thorpej-i2c-spi-conf]: autoconf.c
ofw_patch.c ofw_patch.h

Log Message:
- Move all of the stuff-missing-from-OFW-device-tree stuff into a
  new function sparc64_device_tree_fixup(), and call it from
  device_register().
- sparc64_device_tree_fixup() is table-driven, selecting the table
  based on the machine_model.  It can appy "dtnode" fixups (by matching
  the device's OFW path) and "special" fixups, which are especially
  useful when a property needs to be added to another device that happens
  to not be in the OFW device tree.
- Implement enumeration of missing-from-OFW-device-tree i2c devices
  by "sub-classing" the controller's device handle, intercepting the
  "i2c-enumerate-devices" device call.  We let the "super" first
  enumerate any i2c devices that are in the OFW device tree, and then
  enumerate our own additions after that is done.  i2c additions are
  provided by the machine_model fixup tables.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.19.4.1 src/sys/arch/sparc64/dev/pcf8591_envctrl.c
cvs rdiff -u -r1.228.2.1 -r1.228.2.2 src/sys/arch/sparc64/sparc64/autoconf.c
cvs rdiff -u -r1.7 -r1.7.4.1 src/sys/arch/sparc64/sparc64/ofw_patch.c
cvs rdiff -u -r1.4 -r1.4.6.1 src/sys/arch/sparc64/sparc64/ofw_patch.h

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/sparc64/dev/pcf8591_envctrl.c
diff -u src/sys/arch/sparc64/dev/pcf8591_envctrl.c:1.19 src/sys/arch/sparc64/dev/pcf8591_envctrl.c:1.19.4.1
--- src/sys/arch/sparc64/dev/pcf8591_envctrl.c:1.19	Wed Jan 27 02:20:03 2021
+++ src/sys/arch/sparc64/dev/pcf8591_envctrl.c	Sat May 15 03:22:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcf8591_envctrl.c,v 1.19 2021/01/27 02:20:03 thorpej Exp $	*/
+/*	$NetBSD: pcf8591_envctrl.c,v 1.19.4.1 2021/05/15 03:22:17 thorpej Exp $	*/
 /*	$OpenBSD: pcf8591_envctrl.c,v 1.6 2007/10/25 21:17:20 kettenis Exp $ */
 
 /*
@@ -19,7 +19,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pcf8591_envctrl.c,v 1.19 2021/01/27 02:20:03 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcf8591_envctrl.c,v 1.19.4.1 2021/05/15 03:22:17 thorpej Exp $");
 
 #include 
 #include 
@@ -125,9 +125,11 @@ ecadc_attach(device_t parent, device_t s
 	int64_t minv, warnv, crit, num, den;
 	u_int8_t junk[PCF8591_CHANNELS + 1];
 	envsys_data_t *sensor;
-	int len, error, addr, chan, node = (int)ia->ia_cookie;
+	int len, error, addr, chan, node;
 	u_int i;
 
+	node = devhandle_to_of(device_handle(self));
+
 	sc->sc_dev = self;
 	sc->sc_nchan = 0;
 	sc->sc_hastimer = 0;

Index: src/sys/arch/sparc64/sparc64/autoconf.c
diff -u src/sys/arch/sparc64/sparc64/autoconf.c:1.228.2.1 src/sys/arch/sparc64/sparc64/autoconf.c:1.228.2.2
--- src/sys/arch/sparc64/sparc64/autoconf.c:1.228.2.1	Thu May 13 00:47:28 2021
+++ src/sys/arch/sparc64/sparc64/autoconf.c	Sat May 15 03:22:17 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.228.2.1 2021/05/13 00:47:28 thorpej Exp $ */
+/*	$NetBSD: autoconf.c,v 1.228.2.2 2021/05/15 03:22:17 thorpej Exp $ */
 
 /*
  * Copyright (c) 1996
@@ -48,7 +48,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.228.2.1 2021/05/13 00:47:28 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.228.2.2 2021/05/15 03:22:17 thorpej Exp $");
 
 #include "opt_ddb.h"
 #include "opt_kgdb.h"
@@ -1005,6 +1005,9 @@ device_register(device_t dev, void *aux)
 	devhandle_t devhandle;
 	int ofnode = 0;
 
+	/* Fixup devices that have missing device tree information. */
+	sparc64_device_tree_fixup(dev, aux);
+
 	/*
 	 * If the device has a valid OpenFirmware node association,
 	 * grab it now.
@@ -1025,24 +1028,6 @@ device_register(device_t dev, void *aux)
 		 * Ignore mainbus0 itself, it certainly is not a boot
 		 * device.
 		 */
-	} else if (device_is_a(busdev, "iic")) {
-		struct i2c_attach_args *ia = aux;
-
-		if (ia->ia_name == NULL)	/* indirect config */
-			return;
-
-		ofnode = (int)ia->ia_cookie;
-		if (device_is_a(dev, "pcagpio")) {
-			if (!strcmp(machine_model, "SUNW,Sun-Fire-V240") ||
-			!strcmp(machine_model, "SUNW,Sun-Fire-V210")) {
-add_gpio_props_v210(dev, aux);
-			}
-		} 
-		if (device_is_a(dev, "pcf8574io")) {
-			if (!strcmp(machine_model, "SUNW,Ultra-250")) {
-add_gpio_props_e250(dev, aux);
-			}
-		} 
 		return;
 	} else if (device_is_a(dev, "sd") || device_is_a(dev, "cd")) {
 		struct scsipibus_attach_args *sa = aux;
@@ -1097,11 +1082,6 @@ device_register(device_t dev, void *aux)
 			dev_bi_unit_drive_match(dev, ofnode,
 			periph->periph_target + off, 0, periph->periph_lun);
 		}
-
-		if (device_is_a(busdev, "scsibus")) {
-			/* see if we're in a known SCA drivebay */
-			add_drivebay_props(dev, ofnode, aux);
-		}
 		return;
 	} else if (device_is_a(dev, "wd")) {
 		

CVS commit: [thorpej-i2c-spi-conf] src/sys

2021-05-14 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May 15 00:32:41 UTC 2021

Modified Files:
src/sys/kern [thorpej-i2c-spi-conf]: subr_device.c
src/sys/sys [thorpej-i2c-spi-conf]: device.h

Log Message:
Expose devhandle_lookup_device_call(), which can be useful when
"sub-classing" a devhandle implementation.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.7.4.1 src/sys/kern/subr_device.c
cvs rdiff -u -r1.168.2.1 -r1.168.2.2 src/sys/sys/device.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_device.c
diff -u src/sys/kern/subr_device.c:1.7 src/sys/kern/subr_device.c:1.7.4.1
--- src/sys/kern/subr_device.c:1.7	Sat Feb  6 05:33:20 2021
+++ src/sys/kern/subr_device.c	Sat May 15 00:32:40 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_device.c,v 1.7 2021/02/06 05:33:20 thorpej Exp $	*/
+/*	$NetBSD: subr_device.c,v 1.7.4.1 2021/05/15 00:32:40 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2006, 2021 The NetBSD Foundation, Inc.
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.7 2021/02/06 05:33:20 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_device.c,v 1.7.4.1 2021/05/15 00:32:40 thorpej Exp $");
 
 #include 
 #include 
@@ -72,7 +72,7 @@ devhandle_type(devhandle_t handle)
 	return handle.impl->type;
 }
 
-static device_call_t
+device_call_t
 devhandle_lookup_device_call(devhandle_t handle, const char *name,
 devhandle_t *call_handlep)
 {

Index: src/sys/sys/device.h
diff -u src/sys/sys/device.h:1.168.2.1 src/sys/sys/device.h:1.168.2.2
--- src/sys/sys/device.h:1.168.2.1	Thu May 13 00:47:33 2021
+++ src/sys/sys/device.h	Sat May 15 00:32:41 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.168.2.1 2021/05/13 00:47:33 thorpej Exp $ */
+/* $NetBSD: device.h,v 1.168.2.2 2021/05/15 00:32:41 thorpej Exp $ */
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -656,6 +656,8 @@ bool		devhandle_is_valid(devhandle_t);
 void		devhandle_invalidate(devhandle_t *);
 devhandle_type_t devhandle_type(devhandle_t);
 
+device_call_t	devhandle_lookup_device_call(devhandle_t, const char *,
+		devhandle_t *);
 void		devhandle_impl_inherit(struct devhandle_impl *,
 		const struct devhandle_impl *);
 



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/pci

2021-05-14 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May 14 22:46:37 UTC 2021

Modified Files:
src/sys/dev/pci [thorpej-i2c-spi-conf]: alipm.c

Log Message:
Pass along our devhandle to the iic bus instance.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.12.2.1 src/sys/dev/pci/alipm.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/dev/pci/alipm.c
diff -u src/sys/dev/pci/alipm.c:1.12 src/sys/dev/pci/alipm.c:1.12.2.1
--- src/sys/dev/pci/alipm.c:1.12	Sat Apr 24 23:36:57 2021
+++ src/sys/dev/pci/alipm.c	Fri May 14 22:46:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: alipm.c,v 1.12 2021/04/24 23:36:57 thorpej Exp $ */
+/*	$NetBSD: alipm.c,v 1.12.2.1 2021/05/14 22:46:36 thorpej Exp $ */
 /*	$OpenBSD: alipm.c,v 1.13 2007/05/03 12:19:01 dlg Exp $	*/
 
 /*
@@ -18,7 +18,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: alipm.c,v 1.12 2021/04/24 23:36:57 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: alipm.c,v 1.12.2.1 2021/05/14 22:46:36 thorpej Exp $");
 
 #include 
 #include 
@@ -210,7 +210,9 @@ alipm_attach(device_t parent, device_t s
 
 	memset(, 0, sizeof iba);
 	iba.iba_tag = >sc_smb_tag;
-	config_found(sc->sc_dev, , iicbus_print, CFARG_EOL);
+	config_found(sc->sc_dev, , iicbus_print,
+	CFARG_DEVHANDLE, device_handle(self),
+	CFARG_EOL);
 
 	return;
 



CVS commit: [thorpej-i2c-spi-conf] src/sys

2021-05-14 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May 14 06:53:14 UTC 2021

Modified Files:
src/sys/arch/sparc64/dev [thorpej-i2c-spi-conf]: pcfiic_ebus.c
src/sys/dev/ic [thorpej-i2c-spi-conf]: pcf8584.c pcf8584var.h

Log Message:
Update the pcfiic driver for the new i2c device enumeration scheme.
Push the multiple-channels complexity up into the ebus front-end,
as that specific to a particular Sun model of controller.  Now
the BBC-type controllers get multiple I2C bus instances attached to
them.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.7.6.1 src/sys/arch/sparc64/dev/pcfiic_ebus.c
cvs rdiff -u -r1.18 -r1.18.2.1 src/sys/dev/ic/pcf8584.c
cvs rdiff -u -r1.6 -r1.6.12.1 src/sys/dev/ic/pcf8584var.h

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/sparc64/dev/pcfiic_ebus.c
diff -u src/sys/arch/sparc64/dev/pcfiic_ebus.c:1.7 src/sys/arch/sparc64/dev/pcfiic_ebus.c:1.7.6.1
--- src/sys/arch/sparc64/dev/pcfiic_ebus.c:1.7	Fri Oct 23 15:18:10 2020
+++ src/sys/arch/sparc64/dev/pcfiic_ebus.c	Fri May 14 06:53:14 2021
@@ -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.6.1 2021/05/14 06:53:14 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.6.1 2021/05/14 06:53:14 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_ctrl_lock)) {
+			return EBUSY;
+		}
+	} else {
+		mutex_enter(>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_ctrl_lock);
+}
+
+static void
+bbc_initialize_channels(struct pcfiic_ebus_softc *esc)
+{
+	struct pcfiic_softc *sc = >esc_sc;
+	struct pcfiic_channel *ch;
+	

CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-13 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May 14 03:57:52 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: pcai2cmux.c

Log Message:
No need to device_set_handle(); it's done for us by the i2c enumeration
code.


To generate a diff of this commit:
cvs rdiff -u -r1.8.4.2 -r1.8.4.3 src/sys/dev/i2c/pcai2cmux.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/dev/i2c/pcai2cmux.c
diff -u src/sys/dev/i2c/pcai2cmux.c:1.8.4.2 src/sys/dev/i2c/pcai2cmux.c:1.8.4.3
--- src/sys/dev/i2c/pcai2cmux.c:1.8.4.2	Sun May  9 23:26:53 2021
+++ src/sys/dev/i2c/pcai2cmux.c	Fri May 14 03:57:51 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcai2cmux.c,v 1.8.4.2 2021/05/09 23:26:53 thorpej Exp $	*/
+/*	$NetBSD: pcai2cmux.c,v 1.8.4.3 2021/05/14 03:57:51 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,v 1.8.4.2 2021/05/09 23:26:53 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,v 1.8.4.3 2021/05/14 03:57:51 thorpej Exp $");
 
 /*
  * Driver for NXP PCA954x / PCA984x I2C switches and multiplexers.
@@ -334,11 +334,8 @@ pcaiicmux_attach(device_t parent, device
 {
 	struct pcaiicmux_softc * const sc = device_private(self);
 	struct i2c_attach_args * const ia = aux;
-	devhandle_t devhandle = ia->ia_devhandle;
 	int error;
 
-	device_set_handle(self, devhandle);
-
 	sc->sc_iicmux.sc_dev = self;
 	sc->sc_iicmux.sc_config = _config;
 	sc->sc_iicmux.sc_i2c_parent = ia->ia_tag;
@@ -352,6 +349,7 @@ pcaiicmux_attach(device_t parent, device
 	sc->sc_type->enable_bit ? "mux" : "switch");
 
 #if defined(I2CMUX_USE_FDT)
+	devhandle_t devhandle = device_handle(self);
 	if (devhandle_type(devhandle) == DEVHANDLE_TYPE_OF) {
 		const int phandle = devhandle_to_of(devhandle);
 		if (of_hasprop(phandle, "i2c-mux-idle-disconnect")) {



CVS commit: [thorpej-i2c-spi-conf] src/sys/arch/sparc64/dev

2021-05-13 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May 14 03:11:49 UTC 2021

Modified Files:
src/sys/arch/sparc64/dev [thorpej-i2c-spi-conf]: jbus-i2c.c

Log Message:
Adapt jbusi2c to the new i2c device enumeration scheme.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.6.2.1 src/sys/arch/sparc64/dev/jbus-i2c.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/sparc64/dev/jbus-i2c.c
diff -u src/sys/arch/sparc64/dev/jbus-i2c.c:1.6 src/sys/arch/sparc64/dev/jbus-i2c.c:1.6.2.1
--- src/sys/arch/sparc64/dev/jbus-i2c.c:1.6	Sat Apr 24 23:36:49 2021
+++ src/sys/arch/sparc64/dev/jbus-i2c.c	Fri May 14 03:11:49 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: jbus-i2c.c,v 1.6 2021/04/24 23:36:49 thorpej Exp $	*/
+/*	$NetBSD: jbus-i2c.c,v 1.6.2.1 2021/05/14 03:11:49 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2018 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: jbus-i2c.c,v 1.6 2021/04/24 23:36:49 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: jbus-i2c.c,v 1.6.2.1 2021/05/14 03:11:49 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_i2c);
 	sc->sc_i2c.ic_cookie = sc;
 	sc->sc_i2c.ic_send_start = jbusi2c_i2c_send_start;
@@ -148,37 +130,11 @@ 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(, 0, sizeof(iba));
 	iba.iba_tag = >sc_i2c;
-	config_found(sc->sc_dev, , iicbus_print, CFARG_EOL);
+	config_found(sc->sc_dev, , iicbus_print,
+	CFARG_DEVHANDLE, device_handle(self),
+	CFARG_EOL);
 }
 
 static inline void



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/ofw

2021-05-13 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May 14 03:05:52 UTC 2021

Modified Files:
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c

Log Message:
Do that again, but slightly differently: a "compatible" property is
required by the Device Tree i2c bindings, and is present on all of
the Sun i2c device nodes that are useful (the notable exception being
the i2c "idprom" nodes, which are actually duplicates of a regular
serial eeprom node).  However, Apple's older OpenFirmware implementations
are rife with i2c nodes that lack a "compatible" property.  So, define
a OFW_I2C_ALLOW_MISSING_COMPATIBLE_PROPERTY quirk, and enable it in
the __HAVE_OPENFIRMWARE_VARIANT_AAPL case.


To generate a diff of this commit:
cvs rdiff -u -r1.1.6.6 -r1.1.6.7 src/sys/dev/ofw/ofw_i2c_subr.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/dev/ofw/ofw_i2c_subr.c
diff -u src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.6 src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.7
--- src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.6	Fri May 14 02:51:43 2021
+++ src/sys/dev/ofw/ofw_i2c_subr.c	Fri May 14 03:05:52 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.6 2021/05/14 02:51:43 thorpej Exp $	*/
+/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.7 2021/05/14 03:05:52 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.6 2021/05/14 02:51:43 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.7 2021/05/14 03:05:52 thorpej Exp $");
 
 #include 
 #include 
@@ -79,6 +79,12 @@ __KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr
  */
 #define	OFW_I2C_ADDRESS_MASK	__BITS(0,7)
 #define	OFW_I2C_ADDRESS_SHIFT	1
+
+/*
+ * Some of Apple's older OpenFirmware implementations are rife with
+ * nodes lacking "compatible" properties.
+ */
+#define	OFW_I2C_ALLOW_MISSING_COMPATIBLE_PROPERTY
 #endif /* __HAVE_OPENFIRMWARE_VARIANT_AAPL */
 
 #ifdef __HAVE_OPENFIRMWARE_VARIANT_SUNW
@@ -176,6 +182,11 @@ of_i2c_enumerate_devices(device_t dev, d
 		}
 
 		clist_size = OF_getproplen(node, "compatible");
+#ifndef OFW_I2C_ALLOW_MISSING_COMPATIBLE_PROPERTY
+		if (clist_size <= 0) {
+			continue;
+		}
+#endif
 		clist = kmem_tmpbuf_alloc(clist_size,
 		compat_buf, sizeof(compat_buf), KM_SLEEP);
 		if (OF_getprop(node, "compatible", clist, clist_size) <



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/ofw

2021-05-13 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May 14 02:51:43 UTC 2021

Modified Files:
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c

Log Message:
Ooops, no, revert that.


To generate a diff of this commit:
cvs rdiff -u -r1.1.6.5 -r1.1.6.6 src/sys/dev/ofw/ofw_i2c_subr.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/dev/ofw/ofw_i2c_subr.c
diff -u src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.5 src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.6
--- src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.5	Fri May 14 02:48:43 2021
+++ src/sys/dev/ofw/ofw_i2c_subr.c	Fri May 14 02:51:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.5 2021/05/14 02:48:43 thorpej Exp $	*/
+/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.6 2021/05/14 02:51:43 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.5 2021/05/14 02:48:43 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.6 2021/05/14 02:51:43 thorpej Exp $");
 
 #include 
 #include 
@@ -176,9 +176,6 @@ of_i2c_enumerate_devices(device_t dev, d
 		}
 
 		clist_size = OF_getproplen(node, "compatible");
-		if (clist_size <= 0) {
-			continue;
-		}
 		clist = kmem_tmpbuf_alloc(clist_size,
 		compat_buf, sizeof(compat_buf), KM_SLEEP);
 		if (OF_getprop(node, "compatible", clist, clist_size) <



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/ofw

2021-05-13 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May 14 02:48:43 UTC 2021

Modified Files:
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c

Log Message:
Skip nodes without a "compatible" property.


To generate a diff of this commit:
cvs rdiff -u -r1.1.6.4 -r1.1.6.5 src/sys/dev/ofw/ofw_i2c_subr.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/dev/ofw/ofw_i2c_subr.c
diff -u src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.4 src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.5
--- src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.4	Fri May 14 01:52:36 2021
+++ src/sys/dev/ofw/ofw_i2c_subr.c	Fri May 14 02:48:43 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.4 2021/05/14 01:52:36 thorpej Exp $	*/
+/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.5 2021/05/14 02:48:43 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.4 2021/05/14 01:52:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.5 2021/05/14 02:48:43 thorpej Exp $");
 
 #include 
 #include 
@@ -176,6 +176,9 @@ of_i2c_enumerate_devices(device_t dev, d
 		}
 
 		clist_size = OF_getproplen(node, "compatible");
+		if (clist_size <= 0) {
+			continue;
+		}
 		clist = kmem_tmpbuf_alloc(clist_size,
 		compat_buf, sizeof(compat_buf), KM_SLEEP);
 		if (OF_getprop(node, "compatible", clist, clist_size) <



CVS commit: [thorpej-i2c-spi-conf] src/sys

2021-05-13 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May 14 01:52:36 UTC 2021

Modified Files:
src/sys/arch/sparc64/include [thorpej-i2c-spi-conf]: types.h
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c

Log Message:
Define __HAVE_OPENFIRMWARE_VARIANT_SUNW for sparc64 systems and handle
its OpenFirmware quirks with respect to i2c:

- "reg" property is 2 cells, the first one containing the channel the
  device is on, the second one containing the i2c device address.
- The i2c device address is shifted left 1 bit to account for the r/w
  bit on the wire.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.28.16.1 src/sys/arch/sparc64/include/types.h
cvs rdiff -u -r1.1.6.3 -r1.1.6.4 src/sys/dev/ofw/ofw_i2c_subr.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/sparc64/include/types.h
diff -u src/sys/arch/sparc64/include/types.h:1.28 src/sys/arch/sparc64/include/types.h:1.28.16.1
--- src/sys/arch/sparc64/include/types.h:1.28	Sat Apr  6 03:06:27 2019
+++ src/sys/arch/sparc64/include/types.h	Fri May 14 01:52:36 2021
@@ -1,4 +1,4 @@
-/*   $NetBSD: types.h,v 1.28 2019/04/06 03:06:27 thorpej Exp $*/
+/*   $NetBSD: types.h,v 1.28.16.1 2021/05/14 01:52:36 thorpej Exp $*/
 
 #ifndef _SPARC64_TYPES_H_
 #define	_SPARC64_TYPES_H_
@@ -11,5 +11,6 @@
 
 #define	__HAVE_COMPAT_NETBSD32
 #define	__HAVE_UCAS_FULL
+#define	__HAVE_OPENFIRMWARE_VARIANT_SUNW
 
 #endif

Index: src/sys/dev/ofw/ofw_i2c_subr.c
diff -u src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.3 src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.4
--- src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.3	Fri May 14 00:44:13 2021
+++ src/sys/dev/ofw/ofw_i2c_subr.c	Fri May 14 01:52:36 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.3 2021/05/14 00:44:13 thorpej Exp $	*/
+/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.4 2021/05/14 01:52:36 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -60,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.3 2021/05/14 00:44:13 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.4 2021/05/14 01:52:36 thorpej Exp $");
 
 #include 
 #include 
@@ -70,27 +70,80 @@ __KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr
 #include 
 #include 
 
+#ifdef __HAVE_OPENFIRMWARE_VARIANT_AAPL
+/*
+ * Apple OpenFirmware implementations have the i2c device
+ * address shifted left 1 bit to account for the r/w bit
+ * on the wire.  We also want to look at only the least-
+ * significant 8 bits of the address cell.
+ */
+#define	OFW_I2C_ADDRESS_MASK	__BITS(0,7)
+#define	OFW_I2C_ADDRESS_SHIFT	1
+#endif /* __HAVE_OPENFIRMWARE_VARIANT_AAPL */
+
+#ifdef __HAVE_OPENFIRMWARE_VARIANT_SUNW
+/*
+ * Sun OpenFirmware implementations use 2 cells for the
+ * i2c device "reg" property, the first containing the
+ * channel number, the second containing the i2c device
+ * address shifted left 1 bit to account for the r/w bit
+ * on the wire.
+ */
+#define	OFW_I2C_REG_NCELLS	2
+#define	OFW_I2C_REG_CHANNEL	0
+#define	OFW_I2C_REG_ADDRESS	1
+#define	OFW_I2C_ADDRESS_SHIFT	1
+#endif /* __HAVE_OPENFIRMWARE_VARIANT_SUNW */
+
+#ifndef OFW_I2C_REG_NCELLS
+#define	OFW_I2C_REG_NCELLS	1
+#endif
+
+#ifndef OFW_I2C_REG_ADDRESS
+#define	OFW_I2C_REG_ADDRESS	0
+#endif
+
+/* No default for OFW_I2C_REG_CHANNEL. */
+
+#ifndef OFW_I2C_ADDRESS_MASK
+#define	OFW_I2C_ADDRESS_MASK	__BITS(0,31)
+#endif
+
+#ifndef OFW_I2C_ADDRESS_SHIFT
+#define	OFW_I2C_ADDRESS_SHIFT	0
+#endif
+
 static bool
-of_i2c_get_address(int node, uint32_t *addrp)
+of_i2c_get_address(i2c_tag_t tag, int node, uint32_t *addrp)
 {
-	uint32_t reg;
-
-	if (OF_getprop(node, "reg", , sizeof(reg)) != sizeof(reg)) {
+	uint32_t reg[OFW_I2C_REG_NCELLS];
+	uint32_t addr;
+#ifdef OFW_I2C_REG_CHANNEL
+	uint32_t channel;
+#endif
+
+	if (OF_getprop(node, "reg", reg, sizeof(reg)) != sizeof(reg)) {
+		/*
+		 * "reg" property is malformed; reject the device.
+		 */
 		return false;
 	}
 
-	reg = be32toh(reg);
+	addr = be32toh(reg[OFW_I2C_REG_ADDRESS]);
+	addr = (addr & OFW_I2C_ADDRESS_MASK) >> OFW_I2C_ADDRESS_SHIFT;
 
-#ifdef __HAVE_OPENFIRMWARE_VARIANT_AAPL
+#ifdef OFW_I2C_REG_CHANNEL
 	/*
-	 * Apple OpenFirmware implementations have the i2c device
-	 * address shifted left 1 bit to account for the r/w bit
-	 * on the wire.
+	 * If the channel in the "reg" property does not match,
+	 * reject the device.
 	 */
-	reg = (reg & 0xff) >> 1;
-#endif /* __HAVE_OPENFIRMWARE_VARIANT_AAPL */
+	channel = be32toh(reg[OFW_I2C_REG_CHANNEL]);
+	if (channel != tag->ic_channel) {
+		return false;
+	}
+#endif
 
-	*addrp = reg;
+	*addrp = addr;
 	return true;
 }
 
@@ -118,7 +171,7 @@ of_i2c_enumerate_devices(device_t dev, d
 		if (OF_getprop(node, "name", name, sizeof(name)) <= 0) {
 			continue;
 		}
-		if (!of_i2c_get_address(node, )) {
+		if (!of_i2c_get_address(args->ia->ia_tag, node, )) {
 			continue;
 		}
 



CVS commit: [thorpej-i2c-spi-conf] src/sys

2021-05-13 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May 14 01:08:53 UTC 2021

Modified Files:
src/sys/arch/macppc/dev [thorpej-i2c-spi-conf]: ki2c.c smu.c
src/sys/dev/i2c [thorpej-i2c-spi-conf]: i2c_subr.c i2cmux.c i2cvar.h

Log Message:
Move the bus/channel number for multi-channel / mux controllers out of
i2cbus_attach_args and stash it in the i2c_tag_t instead.  This makes it
accessible to platform device tree code when enumerating devices.


To generate a diff of this commit:
cvs rdiff -u -r1.31.2.1 -r1.31.2.2 src/sys/arch/macppc/dev/ki2c.c
cvs rdiff -u -r1.13.2.2 -r1.13.2.3 src/sys/arch/macppc/dev/smu.c
cvs rdiff -u -r1.1.72.1 -r1.1.72.2 src/sys/dev/i2c/i2c_subr.c
cvs rdiff -u -r1.5.2.3 -r1.5.2.4 src/sys/dev/i2c/i2cmux.c
cvs rdiff -u -r1.24.2.3 -r1.24.2.4 src/sys/dev/i2c/i2cvar.h

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/macppc/dev/ki2c.c
diff -u src/sys/arch/macppc/dev/ki2c.c:1.31.2.1 src/sys/arch/macppc/dev/ki2c.c:1.31.2.2
--- src/sys/arch/macppc/dev/ki2c.c:1.31.2.1	Sat May  8 21:58:12 2021
+++ src/sys/arch/macppc/dev/ki2c.c	Fri May 14 01:08:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ki2c.c,v 1.31.2.1 2021/05/08 21:58:12 thorpej Exp $	*/
+/*	$NetBSD: ki2c.c,v 1.31.2.2 2021/05/14 01:08:53 thorpej Exp $	*/
 /*	Id: ki2c.c,v 1.7 2002/10/05 09:56:05 tsubai Exp	*/
 
 /*-
@@ -326,13 +326,13 @@ ki2c_attach(device_t parent, device_t se
 		ch = >sc_channels[i];
 
 		iic_tag_init(>ch_i2c);
+		ch->ch_i2c.ic_channel = ch->ch_channel = i;
 		ch->ch_i2c.ic_cookie = ch;
 		ch->ch_i2c.ic_acquire_bus = ki2c_i2c_acquire_bus;
 		ch->ch_i2c.ic_release_bus = ki2c_i2c_release_bus;
 		ch->ch_i2c.ic_exec = ki2c_i2c_exec;
 
 		ch->ch_ki2c = sc;
-		ch->ch_channel = i;
 	}
 
 	/*
@@ -409,11 +409,10 @@ ki2c_attach(device_t parent, device_t se
 		}
 		devhandle.impl = >sc_devhandle_impl;
 
-		locs[I2CBUSCF_BUS] = ch->ch_channel;
+		locs[I2CBUSCF_BUS] = ch->ch_i2c.ic_channel;
 
 		memset(, 0, sizeof(iba));
 		iba.iba_tag = >ch_i2c;
-		iba.iba_bus = ch->ch_channel;
 		config_found(sc->sc_dev, , iicbus_print_multi,
 		CFARG_SUBMATCH, config_stdsubmatch,
 		CFARG_LOCATORS, locs,

Index: src/sys/arch/macppc/dev/smu.c
diff -u src/sys/arch/macppc/dev/smu.c:1.13.2.2 src/sys/arch/macppc/dev/smu.c:1.13.2.3
--- src/sys/arch/macppc/dev/smu.c:1.13.2.2	Fri May 14 00:44:13 2021
+++ src/sys/arch/macppc/dev/smu.c	Fri May 14 01:08:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: smu.c,v 1.13.2.2 2021/05/14 00:44:13 thorpej Exp $	*/
+/*	$NetBSD: smu.c,v 1.13.2.3 2021/05/14 01:08:53 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2013 Phileas Fogg
@@ -476,11 +476,11 @@ smu_setup_iicbus(struct smu_softc *sc)
 
 		iic_tag_init(>i2c);
 		iicbus->i2c.ic_cookie = iicbus;
+		iicbus->i2c.ic_channel = iicbus->reg;
 		iicbus->i2c.ic_exec = smu_iicbus_exec;
 
 		memset(, 0, sizeof(iba));
 		iba.iba_tag = >i2c;
-		iba.iba_bus = iicbus->reg;
 
 		config_found(sc->sc_dev, , iicbus_print_multi,
 		CFARG_DEVHANDLE, devhandle_from_of(node),

Index: src/sys/dev/i2c/i2c_subr.c
diff -u src/sys/dev/i2c/i2c_subr.c:1.1.72.1 src/sys/dev/i2c/i2c_subr.c:1.1.72.2
--- src/sys/dev/i2c/i2c_subr.c:1.1.72.1	Sat May  8 14:23:15 2021
+++ src/sys/dev/i2c/i2c_subr.c	Fri May 14 01:08:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2c_subr.c,v 1.1.72.1 2021/05/08 14:23:15 thorpej Exp $	*/
+/*	$NetBSD: i2c_subr.c,v 1.1.72.2 2021/05/14 01:08:53 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i2c_subr.c,v 1.1.72.1 2021/05/08 14:23:15 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c_subr.c,v 1.1.72.2 2021/05/14 01:08:53 thorpej Exp $");
 
 #include 
 #include 
@@ -61,7 +61,7 @@ iicbus_print_multi(void *aux, const char
 
 	if (pnp != NULL)
 		aprint_normal("iic at %s", pnp);
-	aprint_normal(" bus %d", iba->iba_bus);
+	aprint_normal(" bus %d", iba->iba_tag->ic_channel);
 
 	return UNCONF;
 }

Index: src/sys/dev/i2c/i2cmux.c
diff -u src/sys/dev/i2c/i2cmux.c:1.5.2.3 src/sys/dev/i2c/i2cmux.c:1.5.2.4
--- src/sys/dev/i2c/i2cmux.c:1.5.2.3	Sat May  8 15:10:44 2021
+++ src/sys/dev/i2c/i2cmux.c	Fri May 14 01:08:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2cmux.c,v 1.5.2.3 2021/05/08 15:10:44 thorpej Exp $	*/
+/*	$NetBSD: i2cmux.c,v 1.5.2.4 2021/05/14 01:08:53 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1.5.2.3 2021/05/08 15:10:44 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1.5.2.4 2021/05/14 01:08:53 thorpej Exp $");
 
 #include 
 #include 
@@ -131,6 +131,7 @@ iicmux_attach_bus(struct iicmux_softc * 
 
 	iic_tag_init(>controller);
 	bus->controller.ic_cookie = bus;
+	bus->controller.ic_channel = bus->busidx;
 	bus->controller.ic_acquire_bus = iicmux_acquire_bus;
 	bus->controller.ic_release_bus = iicmux_release_bus;
 	bus->controller.ic_exec = iicmux_exec;
@@ -144,7 +145,6 @@ 

CVS commit: [thorpej-i2c-spi-conf] src/sys

2021-05-13 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Fri May 14 00:44:13 UTC 2021

Modified Files:
src/sys/arch/macppc/dev [thorpej-i2c-spi-conf]: pmu.c smu.c
src/sys/arch/macppc/include [thorpej-i2c-spi-conf]: types.h
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c openfirm.h

Log Message:
Deal with quirks / differences in OpenFirmware implementations'
interpreation of the i2c "reg" property by embedding knowledge
of those quicks directly, rather than forcing lots of drivers
to provide their own devhandle implementations.  We default to
assuming the Device Tree bindings, and tweak based on platform-
specific #ifdefs.

Start with __HAVE_OPENFIRMWARE_VARIANT_AAPL (all i2c "reg" properties
encode an address that's shifted left 1 bit to account for the R/W bit
that appears on the wire).


To generate a diff of this commit:
cvs rdiff -u -r1.37.2.1 -r1.37.2.2 src/sys/arch/macppc/dev/pmu.c
cvs rdiff -u -r1.13.2.1 -r1.13.2.2 src/sys/arch/macppc/dev/smu.c
cvs rdiff -u -r1.14 -r1.14.70.1 src/sys/arch/macppc/include/types.h
cvs rdiff -u -r1.1.6.2 -r1.1.6.3 src/sys/dev/ofw/ofw_i2c_subr.c
cvs rdiff -u -r1.47.2.1 -r1.47.2.2 src/sys/dev/ofw/openfirm.h

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/macppc/dev/pmu.c
diff -u src/sys/arch/macppc/dev/pmu.c:1.37.2.1 src/sys/arch/macppc/dev/pmu.c:1.37.2.2
--- src/sys/arch/macppc/dev/pmu.c:1.37.2.1	Sat May  8 22:39:41 2021
+++ src/sys/arch/macppc/dev/pmu.c	Fri May 14 00:44:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pmu.c,v 1.37.2.1 2021/05/08 22:39:41 thorpej Exp $ */
+/*	$NetBSD: pmu.c,v 1.37.2.2 2021/05/14 00:44:13 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2006 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pmu.c,v 1.37.2.1 2021/05/08 22:39:41 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pmu.c,v 1.37.2.2 2021/05/14 00:44:13 thorpej Exp $");
 
 #include 
 #include 
@@ -91,12 +91,6 @@ struct pmu_softc {
 	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;
@@ -242,42 +236,6 @@ static const char *has_two_smart_batteri
 	"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)
 {
@@ -382,18 +340,6 @@ pmu_attach(device_t parent, device_t sel
 			goto next;
 
 		if (strncmp(name, "pmu-i2c", 8) == 0) {
-			/*
-			 * 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_devhandle_impl,
-			devhandle.impl);
-			sc->sc_devhandle_impl.lookup_device_call =
-			pmu_devhandle_lookup_device_call;
-			devhandle.impl = >sc_devhandle_impl;
-
 			/* fill in the i2c tag */
 			iic_tag_init(>sc_i2c);
 			sc->sc_i2c.ic_cookie = sc;
@@ -403,7 +349,7 @@ pmu_attach(device_t parent, device_t sel
 			iba.iba_tag = >sc_i2c;
 			config_found(sc->sc_dev, , iicbus_print,
 			CFARG_IATTR, "i2cbus",
-			CFARG_DEVHANDLE, devhandle,
+			CFARG_DEVHANDLE, devhandle_from_of(node),
 			CFARG_EOL);
 			goto next;
 		}

Index: src/sys/arch/macppc/dev/smu.c
diff -u src/sys/arch/macppc/dev/smu.c:1.13.2.1 src/sys/arch/macppc/dev/smu.c:1.13.2.2
--- src/sys/arch/macppc/dev/smu.c:1.13.2.1	Sun May  9 21:37:04 2021
+++ src/sys/arch/macppc/dev/smu.c	Fri May 14 00:44:13 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: smu.c,v 1.13.2.1 2021/05/09 21:37:04 thorpej Exp $	*/
+/*	$NetBSD: smu.c,v 1.13.2.2 2021/05/14 00:44:13 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2013 Phileas Fogg
@@ -117,11 +117,6 @@ struct smu_softc {
 	int sc_num_fans;
 	struct smu_fan sc_fans[SMU_MAX_FANS];
 
-	/*
-	 * We provide our own i2c device enumeration method, so we
-	 * need to provide our own devhandle_impl.
-	 */
-	struct devhandle_impl sc_devhandle_impl;
 	LIST_HEAD(, smu_iicbus) sc_iic_busses;
 
 	struct todr_chip_handle 

CVS commit: [thorpej-i2c-spi-conf] src/sys/arch/macppc/dev

2021-05-12 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Thu May 13 00:59:27 UTC 2021

Modified Files:
src/sys/arch/macppc/dev [thorpej-i2c-spi-conf]: lmu.c

Log Message:
Don't use the OF phandle here.


To generate a diff of this commit:
cvs rdiff -u -r1.8.4.1 -r1.8.4.2 src/sys/arch/macppc/dev/lmu.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/macppc/dev/lmu.c
diff -u src/sys/arch/macppc/dev/lmu.c:1.8.4.1 src/sys/arch/macppc/dev/lmu.c:1.8.4.2
--- src/sys/arch/macppc/dev/lmu.c:1.8.4.1	Sun May  9 22:36:35 2021
+++ src/sys/arch/macppc/dev/lmu.c	Thu May 13 00:59:26 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lmu.c,v 1.8.4.1 2021/05/09 22:36:35 thorpej Exp $ */
+/* $NetBSD: lmu.c,v 1.8.4.2 2021/05/13 00:59:26 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020 Michael Lorenz
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lmu.c,v 1.8.4.1 2021/05/09 22:36:35 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lmu.c,v 1.8.4.2 2021/05/13 00:59:26 thorpej Exp $");
 
 #include 
 #include 
@@ -56,7 +56,6 @@ struct lmu_softc {
 	device_t	sc_dev;
 	i2c_tag_t	sc_i2c;
 	i2c_addr_t	sc_addr;
-	int		sc_node;
 
 	struct sysmon_envsys *sc_sme;
 	envsys_data_t	sc_sensors[2];
@@ -166,7 +165,6 @@ lmu_attach(device_t parent, device_t sel
 	sc->sc_dev = self;
 	sc->sc_i2c = ia->ia_tag;
 	sc->sc_addr = ia->ia_addr;
-	sc->sc_node = devhandle_to_of(device_handle(self));
 	sc->sc_last = 0;
 
 	aprint_naive("\n");



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-09 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May  9 23:26:53 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: pcai2cmux.c

Log Message:
Don't include fdtvar.h directly here.


To generate a diff of this commit:
cvs rdiff -u -r1.8.4.1 -r1.8.4.2 src/sys/dev/i2c/pcai2cmux.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/dev/i2c/pcai2cmux.c
diff -u src/sys/dev/i2c/pcai2cmux.c:1.8.4.1 src/sys/dev/i2c/pcai2cmux.c:1.8.4.2
--- src/sys/dev/i2c/pcai2cmux.c:1.8.4.1	Sat May  8 02:44:22 2021
+++ src/sys/dev/i2c/pcai2cmux.c	Sun May  9 23:26:53 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: pcai2cmux.c,v 1.8.4.1 2021/05/08 02:44:22 thorpej Exp $	*/
+/*	$NetBSD: pcai2cmux.c,v 1.8.4.2 2021/05/09 23:26:53 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,v 1.8.4.1 2021/05/08 02:44:22 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,v 1.8.4.2 2021/05/09 23:26:53 thorpej Exp $");
 
 /*
  * Driver for NXP PCA954x / PCA984x I2C switches and multiplexers.
@@ -56,7 +56,6 @@ __KERNEL_RCSID(0, "$NetBSD: pcai2cmux.c,
 #include 
 #include 
 
-#include 
 #include 
 
 /* There are a maximum of 8 busses supported. */



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-09 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May  9 23:19:10 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: i2cmuxvar.h

Log Message:
Revert most of previous -- some consumers of this file still have
ACPI-specific requirements.


To generate a diff of this commit:
cvs rdiff -u -r1.3.4.2 -r1.3.4.3 src/sys/dev/i2c/i2cmuxvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/i2c/i2cmuxvar.h
diff -u src/sys/dev/i2c/i2cmuxvar.h:1.3.4.2 src/sys/dev/i2c/i2cmuxvar.h:1.3.4.3
--- src/sys/dev/i2c/i2cmuxvar.h:1.3.4.2	Sat May  8 15:10:44 2021
+++ src/sys/dev/i2c/i2cmuxvar.h	Sun May  9 23:19:10 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2cmuxvar.h,v 1.3.4.2 2021/05/08 15:10:44 thorpej Exp $	*/
+/*	$NetBSD: i2cmuxvar.h,v 1.3.4.3 2021/05/09 23:19:10 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -36,6 +36,23 @@
 
 /* XXX This is not ideal, but... XXX */
 
+#if defined(__i386__) || defined(__amd64__) || defined(__aarch64__)
+
+#ifdef _KERNEL_OPT
+#include "acpica.h"
+
+#if NACPICA > 0
+#define	I2CMUX_USE_ACPI
+#endif
+
+#else /* ! _KERNEL_OPT */
+
+#define	I2CMUX_USE_ACPI
+
+#endif /* _KERNEL_OPT */
+
+#endif /* __i386__ || __amd64__ || __aarch64__ */
+
 #if defined(__arm__) || defined(__aarch64__)
 
 #ifdef _KERNEL_OPT
@@ -55,6 +72,10 @@
 
 /* XXX ^^^ XXX */
 
+#if defined(I2CMUX_USE_ACPI)
+#include 
+#endif
+
 #if defined(I2CMUX_USE_FDT)
 #include 
 #endif



CVS commit: [thorpej-i2c-spi-conf] src/sys/arch/macppc/dev

2021-05-09 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May  9 22:36:35 UTC 2021

Modified Files:
src/sys/arch/macppc/dev [thorpej-i2c-spi-conf]: deq.c lmu.c psoc.c
smusat.c

Log Message:
ia->ia_cookie -> devhandle_to_of(device_handle(self))


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.20.4.1 src/sys/arch/macppc/dev/deq.c
cvs rdiff -u -r1.8 -r1.8.4.1 src/sys/arch/macppc/dev/lmu.c
cvs rdiff -u -r1.6 -r1.6.4.1 src/sys/arch/macppc/dev/psoc.c
cvs rdiff -u -r1.9.4.1 -r1.9.4.2 src/sys/arch/macppc/dev/smusat.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/macppc/dev/deq.c
diff -u src/sys/arch/macppc/dev/deq.c:1.20 src/sys/arch/macppc/dev/deq.c:1.20.4.1
--- src/sys/arch/macppc/dev/deq.c:1.20	Wed Jan 27 02:17:27 2021
+++ src/sys/arch/macppc/dev/deq.c	Sun May  9 22:36:35 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: deq.c,v 1.20 2021/01/27 02:17:27 thorpej Exp $	*/
+/*	$NetBSD: deq.c,v 1.20.4.1 2021/05/09 22:36:35 thorpej Exp $	*/
 
 /*-
  * Copyright (C) 2005 Michael Lorenz
@@ -32,7 +32,7 @@
  */
  
 #include 
-__KERNEL_RCSID(0, "$NetBSD: deq.c,v 1.20 2021/01/27 02:17:27 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: deq.c,v 1.20.4.1 2021/05/09 22:36:35 thorpej Exp $");
 
 #include 
 #include 
@@ -83,7 +83,7 @@ deq_attach(device_t parent, device_t sel
 	char name[256];
 
 	sc->sc_dev = self;
-	sc->sc_node = ia->ia_cookie;
+	sc->sc_node = devhandle_to_of(device_handle(self));
 	sc->sc_parent = parent;
 	sc->sc_address = ia->ia_addr;
 	sc->sc_i2c = ia->ia_tag;

Index: src/sys/arch/macppc/dev/lmu.c
diff -u src/sys/arch/macppc/dev/lmu.c:1.8 src/sys/arch/macppc/dev/lmu.c:1.8.4.1
--- src/sys/arch/macppc/dev/lmu.c:1.8	Wed Jan 27 02:17:28 2021
+++ src/sys/arch/macppc/dev/lmu.c	Sun May  9 22:36:35 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: lmu.c,v 1.8 2021/01/27 02:17:28 thorpej Exp $ */
+/* $NetBSD: lmu.c,v 1.8.4.1 2021/05/09 22:36:35 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020 Michael Lorenz
@@ -31,7 +31,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: lmu.c,v 1.8 2021/01/27 02:17:28 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: lmu.c,v 1.8.4.1 2021/05/09 22:36:35 thorpej Exp $");
 
 #include 
 #include 
@@ -166,7 +166,7 @@ lmu_attach(device_t parent, device_t sel
 	sc->sc_dev = self;
 	sc->sc_i2c = ia->ia_tag;
 	sc->sc_addr = ia->ia_addr;
-	sc->sc_node = ia->ia_cookie;
+	sc->sc_node = devhandle_to_of(device_handle(self));
 	sc->sc_last = 0;
 
 	aprint_naive("\n");

Index: src/sys/arch/macppc/dev/psoc.c
diff -u src/sys/arch/macppc/dev/psoc.c:1.6 src/sys/arch/macppc/dev/psoc.c:1.6.4.1
--- src/sys/arch/macppc/dev/psoc.c:1.6	Wed Jan 27 02:17:28 2021
+++ src/sys/arch/macppc/dev/psoc.c	Sun May  9 22:36:35 2021
@@ -1,4 +1,4 @@
- /* $NetBSD: psoc.c,v 1.6 2021/01/27 02:17:28 thorpej Exp $ */
+ /* $NetBSD: psoc.c,v 1.6.4.1 2021/05/09 22:36:35 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2019 Michael Lorenz
@@ -42,7 +42,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: psoc.c,v 1.6 2021/01/27 02:17:28 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: psoc.c,v 1.6.4.1 2021/05/09 22:36:35 thorpej Exp $");
 
 #include 
 #include 
@@ -109,7 +109,7 @@ psoc_attach(device_t parent, device_t se
 	sc->sc_dev = self;
 	sc->sc_i2c = ia->ia_tag;
 	sc->sc_addr = ia->ia_addr;
-	sc->sc_node = ia->ia_cookie;
+	sc->sc_node = devhandle_to_of(device_handle(self));
 	sc->sc_last = 0;
 
 	aprint_naive("\n");

Index: src/sys/arch/macppc/dev/smusat.c
diff -u src/sys/arch/macppc/dev/smusat.c:1.9.4.1 src/sys/arch/macppc/dev/smusat.c:1.9.4.2
--- src/sys/arch/macppc/dev/smusat.c:1.9.4.1	Sun May  9 22:29:54 2021
+++ src/sys/arch/macppc/dev/smusat.c	Sun May  9 22:36:35 2021
@@ -135,7 +135,7 @@ smusat_attach(device_t parent, device_t 
 	int node, i, j;
 
 	sc->sc_dev = self;
-	sc->sc_node = ia->ia_cookie;
+	sc->sc_node = devhandle_to_of(device_handle(self));
 	sc->sc_addr = ia->ia_addr;
 	sc->sc_i2c = ia->ia_tag;
 



CVS commit: [thorpej-i2c-spi-conf] src/sys/arch/macppc/dev

2021-05-09 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May  9 22:29:54 UTC 2021

Modified Files:
src/sys/arch/macppc/dev [thorpej-i2c-spi-conf]: smusat.c

Log Message:
No need to include smuiicvar.h.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.9.4.1 src/sys/arch/macppc/dev/smusat.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/macppc/dev/smusat.c
diff -u src/sys/arch/macppc/dev/smusat.c:1.9 src/sys/arch/macppc/dev/smusat.c:1.9.4.1
--- src/sys/arch/macppc/dev/smusat.c:1.9	Wed Jan 27 02:17:28 2021
+++ src/sys/arch/macppc/dev/smusat.c	Sun May  9 22:29:54 2021
@@ -41,8 +41,6 @@
 #include 
 #include 
 
-#include 
-
 #include "opt_smusat.h"
 
 extern int smu_get_datablock(int, uint8_t *, size_t);



CVS commit: [thorpej-i2c-spi-conf] src/sys/arch/macppc

2021-05-09 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun May  9 21:37:04 UTC 2021

Modified Files:
src/sys/arch/macppc/conf [thorpej-i2c-spi-conf]: POWERMAC_G5
POWERMAC_G5_11_2 files.macppc
src/sys/arch/macppc/dev [thorpej-i2c-spi-conf]: smu.c
Removed Files:
src/sys/arch/macppc/dev [thorpej-i2c-spi-conf]: smuiic.c smuiicvar.h

Log Message:
Adapt the smu driver to the new i2c device enumeration method.  While
here, collapse the "smuiic" driver into the base "smu" driver; it was
superfluous given how the rest of the "smu" driver is structured.


To generate a diff of this commit:
cvs rdiff -u -r1.49 -r1.49.2.1 src/sys/arch/macppc/conf/POWERMAC_G5
cvs rdiff -u -r1.20 -r1.20.6.1 src/sys/arch/macppc/conf/POWERMAC_G5_11_2
cvs rdiff -u -r1.116 -r1.116.2.1 src/sys/arch/macppc/conf/files.macppc
cvs rdiff -u -r1.13 -r1.13.2.1 src/sys/arch/macppc/dev/smu.c
cvs rdiff -u -r1.7 -r0 src/sys/arch/macppc/dev/smuiic.c
cvs rdiff -u -r1.1 -r0 src/sys/arch/macppc/dev/smuiicvar.h

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/macppc/conf/POWERMAC_G5
diff -u src/sys/arch/macppc/conf/POWERMAC_G5:1.49 src/sys/arch/macppc/conf/POWERMAC_G5:1.49.2.1
--- src/sys/arch/macppc/conf/POWERMAC_G5:1.49	Fri Apr  2 09:27:32 2021
+++ src/sys/arch/macppc/conf/POWERMAC_G5	Sun May  9 21:37:04 2021
@@ -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: src/sys/arch/macppc/conf/POWERMAC_G5_11_2
diff -u src/sys/arch/macppc/conf/POWERMAC_G5_11_2:1.20 src/sys/arch/macppc/conf/POWERMAC_G5_11_2:1.20.6.1
--- src/sys/arch/macppc/conf/POWERMAC_G5_11_2:1.20	Tue Jul  7 02:39:59 2020
+++ src/sys/arch/macppc/conf/POWERMAC_G5_11_2	Sun May  9 21:37:04 2021
@@ -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: src/sys/arch/macppc/conf/files.macppc
diff -u src/sys/arch/macppc/conf/files.macppc:1.116 src/sys/arch/macppc/conf/files.macppc:1.116.2.1
--- src/sys/arch/macppc/conf/files.macppc:1.116	Sat Apr 24 23:36:41 2021
+++ src/sys/arch/macppc/conf/files.macppc	Sun May  9 21:37:04 2021
@@ -1,4 +1,4 @@
-#	$NetBSD: files.macppc,v 1.116 2021/04/24 23:36:41 thorpej Exp $
+#	$NetBSD: files.macppc,v 1.116.2.1 2021/05/09 21:37:04 thorpej Exp $
 #
 # macppc-specific configuration info
 
@@ -175,16 +175,11 @@ device zstty: tty
 attach zstty at zsc
 file dev/ic/z8530tty.czstty needs-flag
 
-define smu {}
-device smu: smu, obio
+device smu: i2cbus
 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: src/sys/arch/macppc/dev/smu.c
diff -u src/sys/arch/macppc/dev/smu.c:1.13 src/sys/arch/macppc/dev/smu.c:1.13.2.1
--- src/sys/arch/macppc/dev/smu.c:1.13	Sat Apr 24 23:36:41 2021
+++ src/sys/arch/macppc/dev/smu.c	Sun May  9 21:37:04 2021
@@ -1,3 +1,5 @@
+/*	$NetBSD: smu.c,v 1.13.2.1 2021/05/09 21:37:04 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,12 @@ 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];
+	/*
+	 * We provide our own i2c device enumeration method, so we
+	 * need to provide our own devhandle_impl.
+	 */
+	struct devhandle_impl sc_devhandle_impl;
+	LIST_HEAD(, smu_iicbus) sc_iic_busses;
 
 	struct todr_chip_handle sc_todr;
 
@@ -158,7 +166,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 *);
@@ -441,47 +448,98 @@ smu_setup_fans(struct smu_softc *sc)
 	}
 }
 
+static bool
+smu_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
+smu_i2c_enumerate_devices(device_t 

CVS commit: [thorpej-i2c-spi-conf] src/sys/arch/macppc/dev

2021-05-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May  8 22:39:41 UTC 2021

Modified Files:
src/sys/arch/macppc/dev [thorpej-i2c-spi-conf]: pmu.c

Log Message:
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).


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.37.2.1 src/sys/arch/macppc/dev/pmu.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/macppc/dev/pmu.c
diff -u src/sys/arch/macppc/dev/pmu.c:1.37 src/sys/arch/macppc/dev/pmu.c:1.37.2.1
--- src/sys/arch/macppc/dev/pmu.c:1.37	Sat Apr 24 23:36:41 2021
+++ src/sys/arch/macppc/dev/pmu.c	Sat May  8 22:39:41 2021
@@ -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 
-__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 
 #include 
@@ -90,6 +90,13 @@ struct pmu_softc {
 	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 @@ static const char *has_two_smart_batteri
 	"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 @@ 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,50 +382,28 @@ pmu_attach(device_t parent, device_t sel
 			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);
-
-			/* 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", , 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(, 0, sizeof(iba));
-			iba.iba_tag = >sc_i2c;
+			/*
+			 * 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_devhandle_impl,
+			devhandle.impl);
+			sc->sc_devhandle_impl.lookup_device_call =
+			pmu_devhandle_lookup_device_call;
+			devhandle.impl = >sc_devhandle_impl;
+
+			/* fill in the i2c tag */
 			iic_tag_init(>sc_i2c);
 			sc->sc_i2c.ic_cookie = sc;
 			sc->sc_i2c.ic_exec = pmu_i2c_exec;
+
+			memset(, 0, sizeof(iba));
+			iba.iba_tag = >sc_i2c;
 			config_found(sc->sc_dev, , iicbus_print,
 			CFARG_IATTR, "i2cbus",
+			CFARG_DEVHANDLE, devhandle,
 			CFARG_EOL);
 			goto next;
 		}



CVS commit: [thorpej-i2c-spi-conf] src/sys/arch/macppc/dev

2021-05-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May  8 21:58:12 UTC 2021

Modified Files:
src/sys/arch/macppc/dev [thorpej-i2c-spi-conf]: ki2c.c ki2cvar.h

Log Message:
Adapt the Keywest i2c controller driver to the new i2c device enumeration
mechanism.  We need to provide our own enumeration callback because these
controllers do not use the standard OpenFirmware bindings.

The Keywest controller supports 2 physical i2c busses on a single controller,
so we logically split it up that way now, rather than encoding the channel in
in the i2c address as was done previously.

Different systems have different I2C device tree topologies.

Some systems use a scheme like this:

/u3@0,f800/i2c@f8001000/temp-monitor@98
/u3@0,f800/i2c@f8001000/fan@15e

Here, we see the channel encoded in bit #8 of the address.

Other systems use a scheme like this:

/ht@0,f200/pci@4000,0,0/mac-io@7/i2c@18000/i2c-bus@0
/ht@0,f200/pci@4000,0,0/mac-io@7/i2c@18000/i2c-bus@0/codec@8c

/u4@0,f800/i2c@f8001000/i2c-bus@1
/u4@0,f800/i2c@f8001000/i2c-bus@1/temp-monitor@94

Here, a separate device tree node represents the channel.
Note that in BOTH cases, the I2C address of the devices are
shifted left by 1 (as it would be on the wire to leave room
for the read/write bit).


To generate a diff of this commit:
cvs rdiff -u -r1.31 -r1.31.2.1 src/sys/arch/macppc/dev/ki2c.c
cvs rdiff -u -r1.5 -r1.5.20.1 src/sys/arch/macppc/dev/ki2cvar.h

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/macppc/dev/ki2c.c
diff -u src/sys/arch/macppc/dev/ki2c.c:1.31 src/sys/arch/macppc/dev/ki2c.c:1.31.2.1
--- src/sys/arch/macppc/dev/ki2c.c:1.31	Sat Apr 24 23:36:41 2021
+++ src/sys/arch/macppc/dev/ki2c.c	Sat May  8 21:58:12 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: ki2c.c,v 1.31 2021/04/24 23:36:41 thorpej Exp $	*/
+/*	$NetBSD: ki2c.c,v 1.31.2.1 2021/05/08 21:58:12 thorpej Exp $	*/
 /*	Id: ki2c.c,v 1.7 2002/10/05 09:56:05 tsubai Exp	*/
 
 /*-
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include 
@@ -38,35 +39,220 @@
 #include "opt_ki2c.h"
 #include 
 
+#include "locators.h"
+
 #ifdef KI2C_DEBUG
 #define DPRINTF printf
 #else
 #define DPRINTF while (0) printf
 #endif
 
-int ki2c_match(device_t, cfdata_t, void *);
-void ki2c_attach(device_t, device_t, void *);
-inline uint8_t ki2c_readreg(struct ki2c_softc *, int);
-inline void ki2c_writereg(struct ki2c_softc *, int, uint8_t);
-u_int ki2c_getmode(struct ki2c_softc *);
-void ki2c_setmode(struct ki2c_softc *, u_int);
-u_int ki2c_getspeed(struct ki2c_softc *);
-void ki2c_setspeed(struct ki2c_softc *, u_int);
-int ki2c_intr(struct ki2c_softc *);
-int ki2c_poll(struct ki2c_softc *, int);
-int ki2c_start(struct ki2c_softc *, int, int, void *, int);
-int ki2c_read(struct ki2c_softc *, int, int, void *, int);
-int ki2c_write(struct ki2c_softc *, int, int, void *, int);
+static int	ki2c_match(device_t, cfdata_t, void *);
+static void	ki2c_attach(device_t, device_t, void *);
+static int	ki2c_intr(struct ki2c_softc *);
 
 /* I2C glue */
-static int ki2c_i2c_exec(void *, i2c_op_t, i2c_addr_t, const void *, size_t,
-		void *, size_t, int);
-
+static int	ki2c_i2c_exec(void *, i2c_op_t, i2c_addr_t, const void *,
+		size_t, void *, size_t, int);
+static int	ki2c_i2c_acquire_bus(void *, int);
+static void	ki2c_i2c_release_bus(void *, int);
 
 CFATTACH_DECL_NEW(ki2c, sizeof(struct ki2c_softc), ki2c_match, ki2c_attach,
 	NULL, NULL);
 
-int
+static prop_dictionary_t
+ki2c_i2c_device_props(struct ki2c_softc *sc, int node)
+{
+	prop_dictionary_t props = prop_dictionary_create();
+	uint32_t reg;
+	char descr[32], num[8];
+
+	/* We're fetching descriptions for sensors. */
+
+	for (node = OF_child(node); node != 0; node = OF_peer(node)) {
+		if (of_getprop_uint32(node, "reg", ) == -1) {
+			continue;
+		}
+		if (OF_getprop(node, "location", descr, sizeof(descr)) <= 0) {
+			continue;
+		}
+		snprintf(num, sizeof(num), "s%02x", reg);
+
+		aprint_debug_dev(sc->sc_dev,
+		"%s: sensor %s -> %s\n", __func__, num, descr);
+
+		prop_dictionary_set_string(props, num, descr);
+	}
+
+	return props;
+}
+
+static bool
+ki2c_i2c_enumerate_device(struct ki2c_softc *sc, device_t dev, int node,
+const char *name, uint32_t addr,
+struct i2c_enumerate_devices_args * const args)
+{
+	int compat_size;
+	prop_dictionary_t props;
+	char compat_buf[32];
+	char *compat;
+	bool cbrv;
+
+	compat_size = OF_getproplen(node, "compatible");
+	if (compat_size <= 0) {
+		/* some i2c device nodes don't have 'compatible' */
+		aprint_debug_dev(sc->sc_dev,
+		"no compatible property for phandle %d; using '%s'\n",
+		node, name);
+		compat = compat_buf;
+		strlcpy(compat, name, sizeof(compat));
+		compat_size = strlen(compat) + 1;
+	} else {
+		compat = kmem_tmpbuf_alloc(compat_size, compat_buf,
+		sizeof(compat_buf), KM_SLEEP);
+		

CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May  8 16:56:10 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: adadc.c fcu.c

Log Message:
ia->ia_cookie -> devhandle_to_of(device_handle(self))


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.10.4.1 src/sys/dev/i2c/adadc.c
cvs rdiff -u -r1.12 -r1.12.4.1 src/sys/dev/i2c/fcu.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/dev/i2c/adadc.c
diff -u src/sys/dev/i2c/adadc.c:1.10 src/sys/dev/i2c/adadc.c:1.10.4.1
--- src/sys/dev/i2c/adadc.c:1.10	Wed Jan 27 02:29:48 2021
+++ src/sys/dev/i2c/adadc.c	Sat May  8 16:56:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: adadc.c,v 1.10 2021/01/27 02:29:48 thorpej Exp $ */
+/* $NetBSD: adadc.c,v 1.10.4.1 2021/05/08 16:56:10 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 Michael Lorenz
@@ -34,7 +34,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: adadc.c,v 1.10 2021/01/27 02:29:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: adadc.c,v 1.10.4.1 2021/05/08 16:56:10 thorpej Exp $");
 
 #include 
 #include 
@@ -128,6 +128,7 @@ adadc_attach(device_t parent, device_t s
 	struct i2c_attach_args *ia = aux;
 	envsys_data_t *s;
 	int error, ch;
+	int phandle;
 	uint32_t eeprom[40];
 	char loc[256];
 	int which_cpu;
@@ -151,8 +152,8 @@ adadc_attach(device_t parent, device_t s
 	 * should probably just expose the temperature and four ENVSYS_INTEGERs
 	 */
 	which_cpu = 0;
-	ch = OF_child(ia->ia_cookie);
-	while (ch != 0) {
+	phandle = devhandle_to_of(device_handle(self));
+	for (ch = OF_child(phandle); ch != 0; ch = OF_peer(ch)) {
 		if (OF_getprop(ch, "location", loc, 32) > 0) {
 			int reg = 0;
 			OF_getprop(ch, "reg", , sizeof(reg));
@@ -185,7 +186,6 @@ adadc_attach(device_t parent, device_t s
 			sysmon_envsys_sensor_attach(sc->sc_sme, s);
 			sc->sc_nsensors++;
 		}
-		ch = OF_peer(ch);
 	}
 	aprint_debug_dev(self, "monitoring CPU %d\n", which_cpu);
 	error = get_cpuid(which_cpu, (uint8_t *)eeprom);

Index: src/sys/dev/i2c/fcu.c
diff -u src/sys/dev/i2c/fcu.c:1.12 src/sys/dev/i2c/fcu.c:1.12.4.1
--- src/sys/dev/i2c/fcu.c:1.12	Wed Jan 27 02:29:48 2021
+++ src/sys/dev/i2c/fcu.c	Sat May  8 16:56:10 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fcu.c,v 1.12 2021/01/27 02:29:48 thorpej Exp $ */
+/* $NetBSD: fcu.c,v 1.12.4.1 2021/05/08 16:56:10 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fcu.c,v 1.12 2021/01/27 02:29:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fcu.c,v 1.12.4.1 2021/05/08 16:56:10 thorpej Exp $");
 
 #include 
 #include 
@@ -141,6 +141,7 @@ fcu_attach(device_t parent, device_t sel
 	struct fcu_softc *sc = device_private(self);
 	struct i2c_attach_args *ia = aux;
 	int have_eeprom1 = 1;
+	int phandle;
 
 	sc->sc_dev = self;
 	sc->sc_i2c = ia->ia_tag;
@@ -185,11 +186,11 @@ fcu_attach(device_t parent, device_t sel
 	sc->sc_nfans = 0;
 
 	/* round up sensors */
+	phandle = devhandle_to_of(device_handle(self));
 	int ch;
 
 	sc->sc_nsensors = 0;
-	ch = OF_child(ia->ia_cookie);
-	while (ch != 0) {
+	for (ch = OF_child(phandle); ch != 0; ch = OF_peer(ch)) {
 		char type[32], descr[32];
 		uint32_t reg;
 
@@ -198,7 +199,7 @@ fcu_attach(device_t parent, device_t sel
 		s->state = ENVSYS_SINVALID;
 
 		if (OF_getprop(ch, "device_type", type, 32) <= 0)
-			goto next;
+			continue;
 
 		if (strcmp(type, "fan-rpm-control") == 0) {
 			s->units = ENVSYS_SFANRPM;
@@ -214,15 +215,15 @@ fcu_attach(device_t parent, device_t sel
 			s->units = ENVSYS_INDICATOR;
 		} else {
 			/* ignore other types for now */
-			goto next;
+			continue;
 		}
 
 		if (OF_getprop(ch, "reg", , sizeof(reg)) <= 0)
-			goto next;
+			continue;
 		s->private = reg;
 
 		if (OF_getprop(ch, "location", descr, 32) <= 0)
-			goto next;
+			continue;
 		strcpy(s->desc, descr);
 
 		if (s->units == ENVSYS_SFANRPM) {
@@ -304,8 +305,6 @@ fcu_attach(device_t parent, device_t sel
 		}
 		sysmon_envsys_sensor_attach(sc->sc_sme, s);
 		sc->sc_nsensors++;
-next:
-		ch = OF_peer(ch);
 	}		
 	sysmon_envsys_register(sc->sc_sme);
 



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May  8 16:46:43 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: ac100.c anxedp.c as3722.c
axp20x.c axppmic.c cwfg.c es8316ac.c fan53555.c max77620.c
pca9685.c pcf8563.c rkpmic.c sy8106a.c tcagpio.c tcakp.c tda19988.c
tps65217pmic.c twl4030.c

Log Message:
ia->ia_cookie -> devhandle_to_of(device_handle(self))


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.7.4.1 src/sys/dev/i2c/ac100.c \
src/sys/dev/i2c/tda19988.c
cvs rdiff -u -r1.6 -r1.6.4.1 src/sys/dev/i2c/anxedp.c \
src/sys/dev/i2c/pca9685.c src/sys/dev/i2c/twl4030.c
cvs rdiff -u -r1.23 -r1.23.2.1 src/sys/dev/i2c/as3722.c
cvs rdiff -u -r1.20 -r1.20.2.1 src/sys/dev/i2c/axp20x.c
cvs rdiff -u -r1.34 -r1.34.2.1 src/sys/dev/i2c/axppmic.c
cvs rdiff -u -r1.4 -r1.4.4.1 src/sys/dev/i2c/cwfg.c
cvs rdiff -u -r1.5 -r1.5.4.1 src/sys/dev/i2c/es8316ac.c
cvs rdiff -u -r1.9 -r1.9.4.1 src/sys/dev/i2c/fan53555.c
cvs rdiff -u -r1.11 -r1.11.4.1 src/sys/dev/i2c/max77620.c
cvs rdiff -u -r1.15 -r1.15.4.1 src/sys/dev/i2c/pcf8563.c
cvs rdiff -u -r1.13 -r1.13.2.1 src/sys/dev/i2c/rkpmic.c
cvs rdiff -u -r1.8 -r1.8.4.1 src/sys/dev/i2c/sy8106a.c \
src/sys/dev/i2c/tcagpio.c
cvs rdiff -u -r1.16 -r1.16.2.1 src/sys/dev/i2c/tcakp.c
cvs rdiff -u -r1.19 -r1.19.2.1 src/sys/dev/i2c/tps65217pmic.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/dev/i2c/ac100.c
diff -u src/sys/dev/i2c/ac100.c:1.7 src/sys/dev/i2c/ac100.c:1.7.4.1
--- src/sys/dev/i2c/ac100.c:1.7	Wed Jan 27 02:29:48 2021
+++ src/sys/dev/i2c/ac100.c	Sat May  8 16:46:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ac100.c,v 1.7 2021/01/27 02:29:48 thorpej Exp $ */
+/* $NetBSD: ac100.c,v 1.7.4.1 2021/05/08 16:46:43 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2014 Jared D. McNeill 
@@ -29,7 +29,7 @@
 #include "opt_fdt.h"
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ac100.c,v 1.7 2021/01/27 02:29:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ac100.c,v 1.7.4.1 2021/05/08 16:46:43 thorpej Exp $");
 
 #include 
 #include 
@@ -153,7 +153,7 @@ ac100_attach(device_t parent, device_t s
 	sc->sc_todr.cookie = sc;
 
 #ifdef FDT
-	const int phandle = ia->ia_cookie;
+	const int phandle = devhandle_to_of(device_handle(self));
 	const int rtc_phandle = of_find_firstchild_byname(phandle, "rtc");
 	if (rtc_phandle > 0)
 		fdtbus_todr_attach(self, rtc_phandle, >sc_todr);
Index: src/sys/dev/i2c/tda19988.c
diff -u src/sys/dev/i2c/tda19988.c:1.7 src/sys/dev/i2c/tda19988.c:1.7.4.1
--- src/sys/dev/i2c/tda19988.c:1.7	Wed Jan 27 02:29:48 2021
+++ src/sys/dev/i2c/tda19988.c	Sat May  8 16:46:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: tda19988.c,v 1.7 2021/01/27 02:29:48 thorpej Exp $ */
+/* $NetBSD: tda19988.c,v 1.7.4.1 2021/05/08 16:46:43 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2015 Oleksandr Tymoshenko 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: tda19988.c,v 1.7 2021/01/27 02:29:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tda19988.c,v 1.7.4.1 2021/05/08 16:46:43 thorpej Exp $");
 
 /*
 * NXP TDA19988 HDMI encoder 
@@ -904,7 +904,7 @@ tda19988_attach(device_t parent, device_
 {
 	struct tda19988_softc *sc = device_private(self);
 	struct i2c_attach_args * const ia = aux;
-	const int phandle = ia->ia_cookie;
+	const int phandle = devhandle_to_of(device_handle(self));
 
 	sc->sc_dev = self;
 	sc->sc_phandle = phandle;

Index: src/sys/dev/i2c/anxedp.c
diff -u src/sys/dev/i2c/anxedp.c:1.6 src/sys/dev/i2c/anxedp.c:1.6.4.1
--- src/sys/dev/i2c/anxedp.c:1.6	Wed Jan 27 02:29:48 2021
+++ src/sys/dev/i2c/anxedp.c	Sat May  8 16:46:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: anxedp.c,v 1.6 2021/01/27 02:29:48 thorpej Exp $ */
+/* $NetBSD: anxedp.c,v 1.6.4.1 2021/05/08 16:46:43 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2019 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: anxedp.c,v 1.6 2021/01/27 02:29:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: anxedp.c,v 1.6.4.1 2021/05/08 16:46:43 thorpej Exp $");
 
 #include 
 #include 
@@ -434,7 +434,7 @@ anxedp_attach(device_t parent, device_t 
 	sc->sc_dev = self;
 	sc->sc_i2c = ia->ia_tag;
 	sc->sc_addr = ia->ia_addr;
-	sc->sc_phandle = ia->ia_cookie;
+	sc->sc_phandle = devhandle_to_of(device_handle(self));
 
 	aprint_naive("\n");
 	aprint_normal(": eDP TX\n");
Index: src/sys/dev/i2c/pca9685.c
diff -u src/sys/dev/i2c/pca9685.c:1.6 src/sys/dev/i2c/pca9685.c:1.6.4.1
--- src/sys/dev/i2c/pca9685.c:1.6	Wed Jan 27 02:29:48 2021
+++ src/sys/dev/i2c/pca9685.c	Sat May  8 16:46:43 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: pca9685.c,v 1.6 2021/01/27 02:29:48 thorpej Exp $ */
+/* $NetBSD: pca9685.c,v 1.6.4.1 2021/05/08 16:46:43 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018, 2019 Jason R. Thorpe
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: pca9685.c,v 1.6 2021/01/27 02:29:48 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pca9685.c,v 1.6.4.1 

CVS commit: [thorpej-i2c-spi-conf] src/sys

2021-05-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May  8 15:51:31 UTC 2021

Modified Files:
src/sys/arch/macppc/dev [thorpej-i2c-spi-conf]: cuda.c
src/sys/arch/sandpoint/sandpoint [thorpej-i2c-spi-conf]: autoconf.c
src/sys/dev/acpi [thorpej-i2c-spi-conf]: acpi_i2c.c
src/sys/dev/i2c [thorpej-i2c-spi-conf]: i2cvar.h
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c

Log Message:
There are no more consumers of i2c attach args "cookie" and "cookietype",
so garbage-collect them.


To generate a diff of this commit:
cvs rdiff -u -r1.28.2.1 -r1.28.2.2 src/sys/arch/macppc/dev/cuda.c
cvs rdiff -u -r1.29.6.1 -r1.29.6.2 \
src/sys/arch/sandpoint/sandpoint/autoconf.c
cvs rdiff -u -r1.11.4.1 -r1.11.4.2 src/sys/dev/acpi/acpi_i2c.c
cvs rdiff -u -r1.24.2.2 -r1.24.2.3 src/sys/dev/i2c/i2cvar.h
cvs rdiff -u -r1.1.6.1 -r1.1.6.2 src/sys/dev/ofw/ofw_i2c_subr.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/macppc/dev/cuda.c
diff -u src/sys/arch/macppc/dev/cuda.c:1.28.2.1 src/sys/arch/macppc/dev/cuda.c:1.28.2.2
--- src/sys/arch/macppc/dev/cuda.c:1.28.2.1	Sat May  8 11:40:02 2021
+++ src/sys/arch/macppc/dev/cuda.c	Sat May  8 15:51:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cuda.c,v 1.28.2.1 2021/05/08 11:40:02 thorpej Exp $ */
+/*	$NetBSD: cuda.c,v 1.28.2.2 2021/05/08 15:51:30 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2006 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cuda.c,v 1.28.2.1 2021/05/08 11:40:02 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cuda.c,v 1.28.2.2 2021/05/08 15:51:30 thorpej Exp $");
 
 #include 
 #include 
@@ -195,8 +195,6 @@ cuda_i2c_enumerate_devices(device_t dev,
 		args->ia->ia_prop = props;
 		/* Child gets no handle. */
 		devhandle_invalidate(>ia->ia_devhandle);
-		args->ia->ia_cookie = 0;			/* XXX */
-		args->ia->ia_cookietype = I2C_COOKIE_NONE;	/* XXX */
 
 		cbrv = args->callback(dev, args);
 

Index: src/sys/arch/sandpoint/sandpoint/autoconf.c
diff -u src/sys/arch/sandpoint/sandpoint/autoconf.c:1.29.6.1 src/sys/arch/sandpoint/sandpoint/autoconf.c:1.29.6.2
--- src/sys/arch/sandpoint/sandpoint/autoconf.c:1.29.6.1	Sun Apr 25 23:19:16 2021
+++ src/sys/arch/sandpoint/sandpoint/autoconf.c	Sat May  8 15:51:30 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.29.6.1 2021/04/25 23:19:16 thorpej Exp $	*/
+/*	$NetBSD: autoconf.c,v 1.29.6.2 2021/05/08 15:51:30 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.29.6.1 2021/04/25 23:19:16 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.29.6.2 2021/05/08 15:51:30 thorpej Exp $");
 
 #include 
 #include 
@@ -190,8 +190,6 @@ sandpoint_i2c_enumerate_devices(device_t
 		args->ia->ia_prop = props;
 		/* no devhandle for child devices. */
 		devhandle_invalidate(>ia->ia_devhandle);
-		args->ia->ia_cookie = 0;			/* XXX */
-		args->ia->ia_cookietype = I2C_COOKIE_NONE;	/* XXX */
 
 		cbrv = args->callback(dev, args);
 

Index: src/sys/dev/acpi/acpi_i2c.c
diff -u src/sys/dev/acpi/acpi_i2c.c:1.11.4.1 src/sys/dev/acpi/acpi_i2c.c:1.11.4.2
--- src/sys/dev/acpi/acpi_i2c.c:1.11.4.1	Sun Apr 25 21:49:56 2021
+++ src/sys/dev/acpi/acpi_i2c.c	Sat May  8 15:51:30 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: acpi_i2c.c,v 1.11.4.1 2021/04/25 21:49:56 thorpej Exp $ */
+/* $NetBSD: acpi_i2c.c,v 1.11.4.2 2021/05/08 15:51:30 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2017, 2021 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_i2c.c,v 1.11.4.1 2021/04/25 21:49:56 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_i2c.c,v 1.11.4.2 2021/05/08 15:51:30 thorpej Exp $");
 
 #include 
 #include 
@@ -105,8 +105,6 @@ acpi_i2c_enumerate_device(device_t dev, 
 	args->ia->ia_clist_size = clist_size;
 	args->ia->ia_prop = props;
 	args->ia->ia_devhandle = devhandle_from_acpi(ad->ad_handle);
-	args->ia->ia_cookie = (uint64_t)ad->ad_handle;	/* XXX */
-	args->ia->ia_cookietype = I2C_COOKIE_ACPI;	/* XXX */
 
 	cbrv = args->callback(dev, args);
 

Index: src/sys/dev/i2c/i2cvar.h
diff -u src/sys/dev/i2c/i2cvar.h:1.24.2.2 src/sys/dev/i2c/i2cvar.h:1.24.2.3
--- src/sys/dev/i2c/i2cvar.h:1.24.2.2	Sat May  8 14:23:15 2021
+++ src/sys/dev/i2c/i2cvar.h	Sat May  8 15:51:31 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2cvar.h,v 1.24.2.2 2021/05/08 14:23:15 thorpej Exp $	*/
+/*	$NetBSD: i2cvar.h,v 1.24.2.3 2021/05/08 15:51:31 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -134,13 +134,6 @@ struct i2cbus_attach_args {
 	int iba_bus;			/* bus number (optional) */
 };
 
-/* Type of value stored in "ia_cookie" */
-enum i2c_cookie_type {
-	I2C_COOKIE_NONE,		/* Cookie is not valid */
-	I2C_COOKIE_OF,			/* Cookie is an OF node phandle */
-	I2C_COOKIE_ACPI,		/* Cookie is an ACPI handle */
-};
-
 /* Used to attach devices on the i2c bus. */
 struct 

CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May  8 15:44:12 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: ihidev.c ihidev.h

Log Message:
Rather than using the "cookie" from the i2c_attach_args, use the
device handle that's already associated with our device_t.


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.19.2.1 src/sys/dev/i2c/ihidev.c
cvs rdiff -u -r1.4 -r1.4.10.1 src/sys/dev/i2c/ihidev.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/i2c/ihidev.c
diff -u src/sys/dev/i2c/ihidev.c:1.19 src/sys/dev/i2c/ihidev.c:1.19.2.1
--- src/sys/dev/i2c/ihidev.c:1.19	Sat Apr 24 23:36:54 2021
+++ src/sys/dev/i2c/ihidev.c	Sat May  8 15:44:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ihidev.c,v 1.19 2021/04/24 23:36:54 thorpej Exp $ */
+/* $NetBSD: ihidev.c,v 1.19.2.1 2021/05/08 15:44:12 thorpej Exp $ */
 /* $OpenBSD ihidev.c,v 1.13 2017/04/08 02:57:23 deraadt Exp $ */
 
 /*-
@@ -54,7 +54,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.19 2021/04/24 23:36:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ihidev.c,v 1.19.2.1 2021/05/08 15:44:12 thorpej Exp $");
 
 #include 
 #include 
@@ -162,8 +162,7 @@ ihidev_attach(device_t parent, device_t 
 	sc->sc_addr = ia->ia_addr;
 	mutex_init(>sc_intr_lock, MUTEX_DEFAULT, IPL_VM);
 
-	sc->sc_phandle = ia->ia_cookie;
-	if (ia->ia_cookietype != I2C_COOKIE_ACPI) {
+	if (devhandle_type(device_handle(self)) != DEVHANDLE_TYPE_ACPI) {
 		aprint_error(": unsupported device tree type\n");
 		return;
 	}
@@ -651,7 +650,7 @@ static bool
 ihiddev_intr_init(struct ihidev_softc *sc)
 {
 #if NACPICA > 0
-	ACPI_HANDLE hdl = (void *)(uintptr_t)sc->sc_phandle;
+	ACPI_HANDLE hdl = devhandle_to_acpi(device_handle(sc->sc_dev));
 	struct acpi_resources res;
 	ACPI_STATUS rv;
 	char buf[100];
@@ -675,7 +674,7 @@ ihiddev_intr_init(struct ihidev_softc *s
 
 	acpi_resource_cleanup();
 
-	sc->sc_ih = acpi_intr_establish(sc->sc_dev, sc->sc_phandle, IPL_TTY,
+	sc->sc_ih = acpi_intr_establish(sc->sc_dev, (uint64_t)hdl, IPL_TTY,
 	false, ihidev_intr, sc, device_xname(sc->sc_dev));
 	if (sc->sc_ih == NULL) {
 		aprint_error_dev(sc->sc_dev, "can't establish interrupt\n");
@@ -977,7 +976,7 @@ ihidev_set_report(struct device *dev, in
 static bool
 ihidev_acpi_get_info(struct ihidev_softc *sc)
 {   
-	ACPI_HANDLE hdl = (void *)(uintptr_t)sc->sc_phandle;
+	ACPI_HANDLE hdl = devhandle_to_acpi(device_handle(sc->sc_dev));
 	ACPI_STATUS status;
 	ACPI_INTEGER val;
 

Index: src/sys/dev/i2c/ihidev.h
diff -u src/sys/dev/i2c/ihidev.h:1.4 src/sys/dev/i2c/ihidev.h:1.4.10.1
--- src/sys/dev/i2c/ihidev.h:1.4	Thu Jan  9 04:04:01 2020
+++ src/sys/dev/i2c/ihidev.h	Sat May  8 15:44:12 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: ihidev.h,v 1.4 2020/01/09 04:04:01 thorpej Exp $ */
+/* $NetBSD: ihidev.h,v 1.4.10.1 2021/05/08 15:44:12 thorpej Exp $ */
 /* $OpenBSD ihidev.h,v 1.4 2016/01/31 18:24:35 jcs Exp $ */
 
 /*-
@@ -97,7 +97,6 @@ struct ihidev_softc {
 	device_t	sc_dev;
 	i2c_tag_t	sc_tag;
 	i2c_addr_t	sc_addr;
-	uint64_t	sc_phandle;
 
 	void *		sc_ih;
 	void *		sc_sih;



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May  8 15:10:44 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: i2cmux.c i2cmuxvar.h

Log Message:
Use device_enumerate_children() to eliminate all of the ACPI-specific
code and most of the FDT-specific code from the iicmux driver.


To generate a diff of this commit:
cvs rdiff -u -r1.5.2.2 -r1.5.2.3 src/sys/dev/i2c/i2cmux.c
cvs rdiff -u -r1.3.4.1 -r1.3.4.2 src/sys/dev/i2c/i2cmuxvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/i2c/i2cmux.c
diff -u src/sys/dev/i2c/i2cmux.c:1.5.2.2 src/sys/dev/i2c/i2cmux.c:1.5.2.3
--- src/sys/dev/i2c/i2cmux.c:1.5.2.2	Sat May  8 14:23:15 2021
+++ src/sys/dev/i2c/i2cmux.c	Sat May  8 15:10:44 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2cmux.c,v 1.5.2.2 2021/05/08 14:23:15 thorpej Exp $	*/
+/*	$NetBSD: i2cmux.c,v 1.5.2.3 2021/05/08 15:10:44 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1.5.2.2 2021/05/08 14:23:15 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1.5.2.3 2021/05/08 15:10:44 thorpej Exp $");
 
 #include 
 #include 
@@ -157,98 +157,53 @@ iicmux_attach_bus(struct iicmux_softc * 
 	CFARG_EOL);
 }
 
-#if defined(I2CMUX_USE_FDT)
-static int
-iicmux_fdt_count_children(struct iicmux_softc * const sc)
+static bool
+iicmux_count_busses_callback(device_t self, devhandle_t devhandle,
+void *v __unused)
 {
-	int phandle = devhandle_to_of(sc->sc_i2c_mux_devhandle);
-	char name[32];
-	int child, count;
-
- restart:
-	for (child = OF_child(phandle), count = 0; child;
-	 child = OF_peer(child)) {
-		if (OF_getprop(child, "name", name, sizeof(name)) <= 0) {
-			continue;
+	struct iicmux_softc *sc = device_private(self);
+
+#if defined(I2CMUX_USE_FDT)
+	if (devhandle_type(devhandle) == DEVHANDLE_TYPE_OF) {
+		char name[32];
+
+		if (OF_getprop(devhandle_to_of(devhandle), "name", name,
+			   sizeof(name)) <= 0) {
+			/* Skip this DT node (shouldn't happen). */
+			return true;	/* keep enumerating */
 		}
 		if (strcmp(name, "i2c-mux") == 0) {
-			phandle = child;
-			goto restart;
+			/*
+			 * This DT node is the actual mux node; reset the
+			 * our devhandle and restart enumeration.
+			 */
+			device_set_handle(self, devhandle);
+			sc->sc_nbusses = -1;
+			return false;	/* stop enumerating */
 		}
-		count++;
 	}
+#endif /* I2CMUX_USE_FDT */
 
-	/* phandle may have changed. */
-	sc->sc_i2c_mux_devhandle = devhandle_from_of(phandle);
-	return count;
+	sc->sc_nbusses++;
+	return true;			/* keep enumerating */
 }
 
-static void
-iicmux_attach_fdt(struct iicmux_softc * const sc)
+static bool
+iicmux_attach_busses_callback(device_t self, devhandle_t devhandle, void *v)
 {
-	int phandle = devhandle_to_of(sc->sc_i2c_mux_devhandle);
-
-	sc->sc_nbusses = iicmux_fdt_count_children(sc);
-	if (sc->sc_nbusses == 0) {
-		return;
-	}
+	struct iicmux_softc *sc = device_private(self);
+	int * const idxp = v;
 
-	/* sc_i2c_mux_devhandle may have changed. */
-	phandle = devhandle_to_of(sc->sc_i2c_mux_devhandle);
+	KASSERT(*idxp < sc->sc_nbusses);
+	iicmux_attach_bus(sc, devhandle, (*idxp)++);
 
-	sc->sc_busses = kmem_zalloc(sizeof(*sc->sc_busses) * sc->sc_nbusses,
-	KM_SLEEP);
-
-	int child, idx;
-	for (child = OF_child(phandle), idx = 0; child;
-	 child = OF_peer(child), idx++) {
-		KASSERT(idx < sc->sc_nbusses);
-		iicmux_attach_bus(sc, devhandle_from_of(child), idx);
-	}
+	return true;			/* keep enumerating */
 }
-#endif /* I2CMUX_USE_FDT */
-
-#if defined(I2CMUX_USE_ACPI)
-static void
-iicmux_attach_acpi(struct iicmux_softc * const sc)
-{
-	ACPI_HANDLE hdl = devhandle_to_acpi(sc->sc_i2c_mux_devhandle);
-	struct acpi_devnode *devnode, *ad;
-	int idx;
-
-	devnode = acpi_match_node(hdl);
-	KASSERT(devnode != NULL);
-
-	/* Count child busses */
-	sc->sc_nbusses = 0;
-	SIMPLEQ_FOREACH(ad, >ad_child_head, ad_child_list) {
-		if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE ||
-		!acpi_device_present(ad->ad_handle)) {
-			continue;
-		}
-		sc->sc_nbusses++;
-	}
-
-	sc->sc_busses = kmem_zalloc(sizeof(*sc->sc_busses) * sc->sc_nbusses,
-	KM_SLEEP);
-
-	/* Attach child busses */
-	idx = 0;
-	SIMPLEQ_FOREACH(ad, >ad_child_head, ad_child_list) {
-		if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE ||
-		!acpi_device_present(ad->ad_handle)) {
-			continue;
-		}
-		iicmux_attach_bus(sc, devhandle_from_acpi(ad->ad_handle), idx);
-		idx++;
-	}
-}
-#endif /* I2CMUX_USE_ACPI */
 
 void
 iicmux_attach(struct iicmux_softc * const sc)
 {
-	devhandle_t devhandle = device_handle(sc->sc_dev);
+	int error, idx;
 
 	/*
 	 * We expect sc->sc_config and sc->sc_i2c_parent to be initialized
@@ -258,14 +213,6 @@ iicmux_attach(struct iicmux_softc * cons
 	KASSERT(sc->sc_i2c_parent != NULL);
 
 	/*
-	 * We start out assuming that the i2c bus nodes are children of
-	 * our own node.  We'll adjust later 

CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May  8 14:23:15 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: files.i2c i2c_subr.c i2cmux.c
i2cvar.h

Log Message:
- Add an optional bus number to i2cbus_attach_args, and a corresponding
  optional "bus" locator to the i2cbus interface attribute.
- Add a iicbus_print_multi() routine, which is like iicbus_print(),
  but also prints the bus number.
- Use these new features in the iicmux driver rather than winging it.


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.115.4.1 src/sys/dev/i2c/files.i2c
cvs rdiff -u -r1.1 -r1.1.72.1 src/sys/dev/i2c/i2c_subr.c
cvs rdiff -u -r1.5.2.1 -r1.5.2.2 src/sys/dev/i2c/i2cmux.c
cvs rdiff -u -r1.24.2.1 -r1.24.2.2 src/sys/dev/i2c/i2cvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/i2c/files.i2c
diff -u src/sys/dev/i2c/files.i2c:1.115 src/sys/dev/i2c/files.i2c:1.115.4.1
--- src/sys/dev/i2c/files.i2c:1.115	Mon Jan  4 22:09:35 2021
+++ src/sys/dev/i2c/files.i2c	Sat May  8 14:23:15 2021
@@ -1,7 +1,7 @@
-#	$NetBSD: files.i2c,v 1.115 2021/01/04 22:09:35 thorpej Exp $
+#	$NetBSD: files.i2c,v 1.115.4.1 2021/05/08 14:23:15 thorpej Exp $
 
 obsolete defflag	opt_i2cbus.h		I2C_SCAN
-define	i2cbus { }
+define	i2cbus { [bus = -1] }
 define	i2cexec
 
 device	iic { [addr = -1] } : i2c_bitbang

Index: src/sys/dev/i2c/i2c_subr.c
diff -u src/sys/dev/i2c/i2c_subr.c:1.1 src/sys/dev/i2c/i2c_subr.c:1.1.72.1
--- src/sys/dev/i2c/i2c_subr.c:1.1	Mon Oct  3 22:27:23 2011
+++ src/sys/dev/i2c/i2c_subr.c	Sat May  8 14:23:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2c_subr.c,v 1.1 2011/10/03 22:27:23 jmcneill Exp $	*/
+/*	$NetBSD: i2c_subr.c,v 1.1.72.1 2021/05/08 14:23:15 thorpej Exp $	*/
 
 /*
  * Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i2c_subr.c,v 1.1 2011/10/03 22:27:23 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c_subr.c,v 1.1.72.1 2021/05/08 14:23:15 thorpej Exp $");
 
 #include 
 #include 
@@ -46,9 +46,22 @@ __KERNEL_RCSID(0, "$NetBSD: i2c_subr.c,v
 int
 iicbus_print(void *aux, const char *pnp)
 {
+	/* struct i2cbus_attach_args * const iba = aux; */
 
 	if (pnp != NULL)
 		aprint_normal("iic at %s", pnp);
 
 	return UNCONF;
 }
+
+int
+iicbus_print_multi(void *aux, const char *pnp)
+{
+	struct i2cbus_attach_args * const iba = aux;
+
+	if (pnp != NULL)
+		aprint_normal("iic at %s", pnp);
+	aprint_normal(" bus %d", iba->iba_bus);
+
+	return UNCONF;
+}

Index: src/sys/dev/i2c/i2cmux.c
diff -u src/sys/dev/i2c/i2cmux.c:1.5.2.1 src/sys/dev/i2c/i2cmux.c:1.5.2.2
--- src/sys/dev/i2c/i2cmux.c:1.5.2.1	Sat May  8 02:44:22 2021
+++ src/sys/dev/i2c/i2cmux.c	Sat May  8 14:23:15 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2cmux.c,v 1.5.2.1 2021/05/08 02:44:22 thorpej Exp $	*/
+/*	$NetBSD: i2cmux.c,v 1.5.2.2 2021/05/08 14:23:15 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1.5.2.1 2021/05/08 02:44:22 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1.5.2.2 2021/05/08 14:23:15 thorpej Exp $");
 
 #include 
 #include 
@@ -40,6 +40,8 @@ __KERNEL_RCSID(0, "$NetBSD: i2cmux.c,v 1
 #include 
 #include 
 
+#include "locators.h"
+
 /*
  * i2c mux
  *
@@ -110,20 +112,6 @@ iicmux_exec(void * const v, i2c_op_t con
 
 /*/
 
-/* XXX iicbus_print() should be able to do this. */
-static int
-iicmux_print(void * const aux, const char * const pnp)
-{
-	i2c_tag_t const tag = aux;
-	struct iicmux_bus * const bus = tag->ic_cookie;
-	int rv;
-
-	rv = iicbus_print(aux, pnp);
-	aprint_normal(" bus %d", bus->busidx);
-
-	return rv;
-}
-
 static void
 iicmux_attach_bus(struct iicmux_softc * const sc, devhandle_t devhandle,
 int const busidx)
@@ -147,31 +135,26 @@ iicmux_attach_bus(struct iicmux_softc * 
 	bus->controller.ic_release_bus = iicmux_release_bus;
 	bus->controller.ic_exec = iicmux_exec;
 
-	switch (devhandle_type(devhandle)) {
 #if defined(I2CMUX_USE_FDT)
-	case DEVHANDLE_TYPE_OF:
+	if (devhandle_type(devhandle) == DEVHANDLE_TYPE_OF) {
 		fdtbus_register_i2c_controller(>controller,
 		devhandle_to_of(devhandle));
-
-		fdtbus_attach_i2cbus(sc->sc_dev, devhandle_to_of(devhandle),
-		>controller, iicmux_print);
-		break;
+	}
 #endif /* I2CMUX_USE_FDT */
 
-	case DEVHANDLE_TYPE_INVALID:
-		aprint_error_dev(sc->sc_dev, "invalid bus device handle\n");
-		return;
-
-	default: {
-		struct i2cbus_attach_args iba = {
-			.iba_tag = >controller,
-		};
-		config_found(sc->sc_dev, , iicmux_print,
-		CFARG_DEVHANDLE, devhandle,
-		CFARG_EOL);
-		break;
-	}
-	}
+	struct i2cbus_attach_args iba = {
+		.iba_tag = >controller,
+		.iba_bus = bus->busidx,
+	};
+
+	int locs[I2CBUSCF_NLOCS];
+	locs[I2CBUSCF_BUS] = bus->busidx;
+
+	config_found(sc->sc_dev, , 

CVS commit: [thorpej-i2c-spi-conf] src/sys/arch/macppc/dev

2021-05-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May  8 11:40:02 UTC 2021

Modified Files:
src/sys/arch/macppc/dev [thorpej-i2c-spi-conf]: cuda.c videopll.c

Log Message:
Children of the "cuda" i2c controller don't appear in the OF device tree,
so we need to supply our own "i2c-enumerate-devices" method.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.28.2.1 src/sys/arch/macppc/dev/cuda.c
cvs rdiff -u -r1.3 -r1.3.18.1 src/sys/arch/macppc/dev/videopll.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/macppc/dev/cuda.c
diff -u src/sys/arch/macppc/dev/cuda.c:1.28 src/sys/arch/macppc/dev/cuda.c:1.28.2.1
--- src/sys/arch/macppc/dev/cuda.c:1.28	Sat Apr 24 23:36:41 2021
+++ src/sys/arch/macppc/dev/cuda.c	Sat May  8 11:40:02 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: cuda.c,v 1.28 2021/04/24 23:36:41 thorpej Exp $ */
+/*	$NetBSD: cuda.c,v 1.28.2.1 2021/05/08 11:40:02 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2006 Michael Lorenz
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: cuda.c,v 1.28 2021/04/24 23:36:41 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: cuda.c,v 1.28.2.1 2021/05/08 11:40:02 thorpej Exp $");
 
 #include 
 #include 
@@ -72,6 +72,8 @@ typedef struct _cuda_handler {
 	void *cookie;
 } CudaHandler;
 
+#define	CUDA_MAX_I2C_DEVICES	2
+
 struct cuda_softc {
 	device_t sc_dev;
 	void *sc_ih;
@@ -81,6 +83,20 @@ struct cuda_softc {
 	struct i2c_controller sc_i2c;
 	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;
+
+	struct {
+		const char *name;
+		const char *compatible;
+		i2c_addr_t addr;
+	} sc_i2c_devices[CUDA_MAX_I2C_DEVICES];
+	int sc_ni2c_devices;
+
 	int sc_node;
 	int sc_state;
 	int sc_waiting;
@@ -147,6 +163,65 @@ static	int cuda_adb_set_handler(void *, 
 static int cuda_i2c_exec(void *, i2c_op_t, i2c_addr_t, const void *, size_t,
 		void *, size_t, int);
 
+static void
+cuda_add_i2c_device(struct cuda_softc *sc, const char *name,
+const char *compatible, i2c_addr_t addr)
+{
+	KASSERT(sc->sc_ni2c_devices < CUDA_MAX_I2C_DEVICES);
+	sc->sc_i2c_devices[sc->sc_ni2c_devices].name = name;
+	sc->sc_i2c_devices[sc->sc_ni2c_devices].compatible = compatible;
+	sc->sc_i2c_devices[sc->sc_ni2c_devices].addr = addr;
+	sc->sc_ni2c_devices++;
+}
+
+static int
+cuda_i2c_enumerate_devices(device_t dev, devhandle_t call_handle, void *v)
+{
+	struct i2c_enumerate_devices_args *args = v;
+	prop_dictionary_t props;
+	int i;
+	bool cbrv;
+
+	/* dev is the "iicbus" instance.  Cuda softc is in args. */
+	struct cuda_softc *sc = args->ia->ia_tag->ic_cookie;
+
+	for (i = 0; i < sc->sc_ni2c_devices; i++) {
+		props = prop_dictionary_create();
+
+		args->ia->ia_addr = sc->sc_i2c_devices[i].addr;
+		args->ia->ia_name = sc->sc_i2c_devices[i].name;
+		args->ia->ia_clist = sc->sc_i2c_devices[i].compatible;
+		args->ia->ia_clist_size = strlen(args->ia->ia_clist) + 1;
+		args->ia->ia_prop = props;
+		/* Child gets no handle. */
+		devhandle_invalidate(>ia->ia_devhandle);
+		args->ia->ia_cookie = 0;			/* XXX */
+		args->ia->ia_cookietype = I2C_COOKIE_NONE;	/* XXX */
+
+		cbrv = args->callback(dev, args);
+
+		prop_object_release(props);
+
+		if (!cbrv) {
+			break;	/* callback decides if we continue */
+		}
+	}
+
+	return 0;
+}
+
+static device_call_t
+cuda_devhandle_lookup_device_call(devhandle_t handle, const char *name,
+devhandle_t *call_handlep)
+{
+	if (strcmp(name, "i2c-enumerate-devices") == 0) {
+		return cuda_i2c_enumerate_devices;
+	}
+
+	/* Defer everything else to the "super". */
+	return NULL;
+}
+
 static int
 cuda_match(device_t parent, struct cfdata *cf, void *aux)
 {
@@ -172,9 +247,6 @@ cuda_attach(device_t parent, device_t se
 	struct cuda_softc *sc = device_private(self);
 	struct i2cbus_attach_args iba;
 	static struct cuda_attach_args caa;
-	prop_dictionary_t dict = device_properties(self);
-	prop_dictionary_t dev;
-	prop_array_t cfg;
 	int irq = ca->ca_intr[0];
 	int node, i, child;
 	char name[32];
@@ -252,37 +324,41 @@ cuda_attach(device_t parent, device_t se
 #if notyet
 	config_found(self, , cuda_print, CFARG_EOL);
 #endif
-	cfg = prop_array_create();
-	prop_dictionary_set(dict, "i2c-child-devices", cfg);
-	prop_object_release(cfg);
-
 	/* we don't have OF nodes for i2c devices so we have to make our own */
-
 	node = OF_finddevice("/valkyrie");
 	if (node != -1) {
-		dev = prop_dictionary_create();
-		prop_dictionary_set_string(dev, "name", "videopll");
-		prop_dictionary_set_uint32(dev, "addr", 0x50);
-		prop_array_add(cfg, dev);
-		prop_object_release(dev);
+		/* XXX a real "compatible" string would be nice... */
+		cuda_add_i2c_device(sc, "videopll",
+		"aapl,valkyrie-videopll", 0x50);
 	}
 
 	node = OF_finddevice("/perch");
 	if (node != -1) {
-		dev = 

CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-05-08 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May  8 11:34:38 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: i2c.c

Log Message:
iic_print_direct(): In the "not configured" case, parenthetically print
the first element of the compat list, if we got a compat list.


To generate a diff of this commit:
cvs rdiff -u -r1.78.2.1 -r1.78.2.2 src/sys/dev/i2c/i2c.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/dev/i2c/i2c.c
diff -u src/sys/dev/i2c/i2c.c:1.78.2.1 src/sys/dev/i2c/i2c.c:1.78.2.2
--- src/sys/dev/i2c/i2c.c:1.78.2.1	Sun Apr 25 21:45:15 2021
+++ src/sys/dev/i2c/i2c.c	Sat May  8 11:34:38 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2c.c,v 1.78.2.1 2021/04/25 21:45:15 thorpej Exp $	*/
+/*	$NetBSD: i2c.c,v 1.78.2.2 2021/05/08 11:34:38 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2021 The NetBSD Foundation, Inc.
@@ -69,7 +69,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78.2.1 2021/04/25 21:45:15 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78.2.2 2021/05/08 11:34:38 thorpej Exp $");
 
 #include 
 #include 
@@ -135,8 +135,11 @@ iic_print_direct(void *aux, const char *
 	struct i2c_attach_args *ia = aux;
 
 	if (pnp != NULL)
-		aprint_normal("%s at %s addr 0x%02x",
+		aprint_normal("%s%s%s%s at %s addr 0x%02x",
 			  ia->ia_name ? ia->ia_name : "(unknown)",
+			  ia->ia_clist ? " (" : "",
+			  ia->ia_clist ? ia->ia_clist : "",
+			  ia->ia_clist ? ")" : "",
 			  pnp, ia->ia_addr);
 	else
 		aprint_normal(" addr 0x%02x", ia->ia_addr);



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev

2021-05-07 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sat May  8 02:44:22 UTC 2021

Modified Files:
src/sys/dev/fdt [thorpej-i2c-spi-conf]: i2cmux_fdt.c
src/sys/dev/i2c [thorpej-i2c-spi-conf]: i2cmux.c i2cmuxvar.h
pcai2cmux.c

Log Message:
Update the i2c mux code for the new enumeration methods.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.10.4.1 src/sys/dev/fdt/i2cmux_fdt.c
cvs rdiff -u -r1.5 -r1.5.2.1 src/sys/dev/i2c/i2cmux.c
cvs rdiff -u -r1.3 -r1.3.4.1 src/sys/dev/i2c/i2cmuxvar.h
cvs rdiff -u -r1.8 -r1.8.4.1 src/sys/dev/i2c/pcai2cmux.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/dev/fdt/i2cmux_fdt.c
diff -u src/sys/dev/fdt/i2cmux_fdt.c:1.10 src/sys/dev/fdt/i2cmux_fdt.c:1.10.4.1
--- src/sys/dev/fdt/i2cmux_fdt.c:1.10	Wed Jan 27 03:10:21 2021
+++ src/sys/dev/fdt/i2cmux_fdt.c	Sat May  8 02:44:22 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: i2cmux_fdt.c,v 1.10 2021/01/27 03:10:21 thorpej Exp $	*/
+/*	$NetBSD: i2cmux_fdt.c,v 1.10.4.1 2021/05/08 02:44:22 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i2cmux_fdt.c,v 1.10 2021/01/27 03:10:21 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2cmux_fdt.c,v 1.10.4.1 2021/05/08 02:44:22 thorpej Exp $");
 
 #include 
 #include 
@@ -59,11 +59,12 @@ static void *
 iicmux_gpio_get_mux_info(struct iicmux_softc * const sc)
 {
 	struct mux_info_gpio *mux_data;
+	const int phandle = devhandle_to_of(device_handle(sc->sc_dev));
 	int i;
 
 	mux_data = kmem_zalloc(sizeof(*mux_data), KM_SLEEP);
 
-	mux_data->npins = fdtbus_gpio_count(sc->sc_handle, "mux-gpios");
+	mux_data->npins = fdtbus_gpio_count(phandle, "mux-gpios");
 	if (mux_data->npins == 0) {
 		aprint_error_dev(sc->sc_dev,
 		"unable to get mux-gpios property\n");
@@ -73,7 +74,7 @@ iicmux_gpio_get_mux_info(struct iicmux_s
 	mux_data->pins =
 	kmem_zalloc(sizeof(*mux_data->pins) * mux_data->npins, KM_SLEEP);
 	for (i = 0; i < mux_data->npins; i++) {
-		mux_data->pins[i] = fdtbus_gpio_acquire_index(sc->sc_handle,
+		mux_data->pins[i] = fdtbus_gpio_acquire_index(phandle,
 		"mux-gpios", i, GPIO_PIN_OUTPUT);
 		if (mux_data->pins[i] == NULL) {
 			aprint_error_dev(sc->sc_dev,
@@ -83,7 +84,7 @@ iicmux_gpio_get_mux_info(struct iicmux_s
 	}
 
 	mux_data->has_idle_value =
-	of_getprop_uint32(sc->sc_handle, "idle-state",
+	of_getprop_uint32(phandle, "idle-state",
 			  _data->idle_value) == 0;
 
 	return mux_data;
@@ -102,12 +103,13 @@ static void *
 iicmux_gpio_get_bus_info(struct iicmux_bus * const bus)
 {
 	struct iicmux_softc * const sc = bus->mux;
+	const int phandle = devhandle_to_of(bus->devhandle);
 	struct bus_info_gpio *bus_info;
 	int error;
 
 	bus_info = kmem_zalloc(sizeof(*bus_info), KM_SLEEP);
 
-	error = fdtbus_get_reg(bus->handle, 0, _info->value, NULL);
+	error = fdtbus_get_reg(phandle, 0, _info->value, NULL);
 	if (error) {
 		aprint_error_dev(sc->sc_dev,
 		"unable to get reg property for bus %d\n", bus->busidx);
@@ -172,12 +174,13 @@ struct bus_info_pinctrl {
 static void *
 iicmux_pinctrl_get_mux_info(struct iicmux_softc * const sc)
 {
+	const int phandle = devhandle_to_of(device_handle(sc->sc_dev));
 	struct mux_info_pinctrl *mux_info;
 
 	mux_info = kmem_alloc(sizeof(*mux_info), KM_SLEEP);
 
 	mux_info->has_idle_idx =
-	fdtbus_get_index(sc->sc_handle, "pinctrl-names", "idle",
+	fdtbus_get_index(phandle, "pinctrl-names", "idle",
 			 _info->idle_idx) == 0;
 
 	return mux_info;
@@ -187,12 +190,13 @@ static void *
 iicmux_pinctrl_get_bus_info(struct iicmux_bus * const bus)
 {
 	struct iicmux_softc * const sc = bus->mux;
+	const int phandle = devhandle_to_of(bus->devhandle);
 	struct bus_info_pinctrl *bus_info;
 	int error;
 
 	bus_info = kmem_alloc(sizeof(*bus_info), KM_SLEEP);
 
-	error = fdtbus_get_reg(bus->handle, 0, _info->idx, NULL);
+	error = fdtbus_get_reg(phandle, 0, _info->idx, NULL);
 	if (error) {
 		aprint_error_dev(sc->sc_dev,
 		"unable to get reg property for bus %d\n", bus->busidx);
@@ -208,9 +212,10 @@ iicmux_pinctrl_acquire_bus(struct iicmux
 int const flags __unused)
 {
 	struct iicmux_softc * const sc = bus->mux;
+	const int phandle = devhandle_to_of(device_handle(sc->sc_dev));
 	struct bus_info_pinctrl * const bus_info = bus->bus_data;
 
-	return fdtbus_pinctrl_set_config_index(sc->sc_handle, bus_info->idx);
+	return fdtbus_pinctrl_set_config_index(phandle, bus_info->idx);
 }
 
 static void
@@ -218,10 +223,11 @@ iicmux_pinctrl_release_bus(struct iicmux
 int const flags __unused)
 {
 	struct iicmux_softc * const sc = bus->mux;
+	const int phandle = devhandle_to_of(device_handle(sc->sc_dev));
 	struct mux_info_pinctrl * const mux_info = sc->sc_mux_data;
 
 	if (mux_info->has_idle_idx) {
-		(void) fdtbus_pinctrl_set_config_index(sc->sc_handle,
+		(void) fdtbus_pinctrl_set_config_index(phandle,
 		

CVS commit: [thorpej-i2c-spi-conf] src/sys/arch/sandpoint/sandpoint

2021-04-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Apr 25 23:19:16 UTC 2021

Modified Files:
src/sys/arch/sandpoint/sandpoint [thorpej-i2c-spi-conf]: autoconf.c

Log Message:
Use a private devhandle to implement i2c device enumeration on the
Sandpoint-based NAS devices.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.29.6.1 src/sys/arch/sandpoint/sandpoint/autoconf.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/sandpoint/sandpoint/autoconf.c
diff -u src/sys/arch/sandpoint/sandpoint/autoconf.c:1.29 src/sys/arch/sandpoint/sandpoint/autoconf.c:1.29.6.1
--- src/sys/arch/sandpoint/sandpoint/autoconf.c:1.29	Thu Jul  9 05:12:09 2020
+++ src/sys/arch/sandpoint/sandpoint/autoconf.c	Sun Apr 25 23:19:16 2021
@@ -1,4 +1,4 @@
-/*	$NetBSD: autoconf.c,v 1.29 2020/07/09 05:12:09 nisimura Exp $	*/
+/*	$NetBSD: autoconf.c,v 1.29.6.1 2021/04/25 23:19:16 thorpej Exp $	*/
 
 /*-
  * Copyright (c) 1990 The Regents of the University of California.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.29 2020/07/09 05:12:09 nisimura Exp $");
+__KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.29.6.1 2021/04/25 23:19:16 thorpej Exp $");
 
 #include 
 #include 
@@ -44,6 +44,7 @@ __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -57,31 +58,167 @@ static struct btinfo_net *bi_net;
 static struct btinfo_prodfamily *bi_pfam;
 static struct btinfo_model *bi_model;
 
-struct i2c_dev {
-	const char	*name;
-	unsigned	addr;
-	/* only attach when one of these bits in the model flags is set */
+struct sandpoint_i2cdev {
+	const char *	name;
+	const char *	compat;
 	uint32_t	model_mask;
+	i2c_addr_t	addr;
 };
 
-#define MAXI2CDEVS	4
-struct model_i2c {
-	const char	*family;
-	struct i2c_dev	i2c_devs[MAXI2CDEVS];
-};
-
-static struct model_i2c model_i2c_list[] = {
-	{ "dlink",	{	{ "strtc",	0x68, 0 } } },
-	{ "iomega",	{	{ "dsrtc",	0x68, 0 } } },
-	{ "kurobox",	{	{ "rs5c372rtc", 0x32, 0 } } },
-	{ "kurot4",	{	{ "rs5c372rtc", 0x32, 0 } } },
-	{ "nhnas",	{	{ "pcf8563rtc", 0x51, 0 } } },
-	{ "qnap",	{	{ "s390rtc",0x30, 0 } } },
-	{ "synology",	{	{ "rs5c372rtc", 0x32, 0 },
-{ "lmtemp",	0x48, BI_MODEL_THERMAL } } },
+static const struct sandpoint_i2cdev dlink_i2cdevs[] = {
+[0] =	{
+		.name = "strtc",
+		.compat = "st,m41t80",
+		.addr = 0x68,
+	},
+[1] =	{
+		.name = NULL
+	}
+};
+
+static const struct sandpoint_i2cdev iomega_i2cdevs[] = {
+[0] =	{
+		.name = "dsrtc",
+		.compat = "dallas,ds1307",
+		.addr = 0x68,
+	},
+[1] =	{
+		.name = NULL
+	}
+};
+
+static const struct sandpoint_i2cdev kurobox_i2cdevs[] = {
+[0] =	{
+		.name = "rs5c372rtc",
+		.compat = "ricoh,rs5c372a",
+		.addr = 0x32,
+	},
+[1] =	{
+		.name = NULL
+	}
+};
+
+static const struct sandpoint_i2cdev nhnas_i2cdevs[] = {
+[0] =	{
+		.name = "pcf8563rtc",
+		.compat = "nxp,pcf8563",
+		.addr = 0x51,
+	},
+[1] =	{
+		.name = NULL
+	}
+};
+
+static const struct sandpoint_i2cdev qnap_i2cdevs[] = {
+[0] =	{
+		.name = "s390rtc",
+		.compat = "sii,s35390a",
+		.addr = 0x30,
+	},
+[1] =	{
+		.name = NULL
+	}
+};
+
+static const struct sandpoint_i2cdev synology_i2cdevs[] = {
+[0] =	{
+		.name = "rs5c372rtc",
+		.compat = "ricoh,rs5c372a",
+		.addr = 0x32,
+	},
+[1] =	{
+		.name = "lmtemp",
+		.compat = "national,lm75",
+		.addr = 0x48,
+		.model_mask = BI_MODEL_THERMAL,
+	},
+[2] =	{
+		.name = NULL
+	}
 };
 
-static void add_i2c_child_devices(device_t, const char *);
+static const struct device_compatible_entry sandpoint_i2c_compat[] = {
+	{ .compat = "dlink",		.data = _i2cdevs },
+	{ .compat = "iomega",		.data = _i2cdevs },
+	{ .compat = "kurobox",		.data = _i2cdevs },
+	/* kurot4 has same i2c devices as kurobox */
+	{ .compat = "kurot4",		.data = _i2cdevs },
+	{ .compat = "nhnas",		.data = _i2cdevs },
+	{ .compat = "qnap",		.data = _i2cdevs },
+	{ .compat = "synology",		.data = _i2cdevs },
+	DEVICE_COMPAT_EOL
+};
+
+/*
+ * We provide a device handle implementation for i2c device enumeration.
+ */
+static int
+sandpoint_i2c_enumerate_devices(device_t dev, devhandle_t call_handle, void *v)
+{
+	struct i2c_enumerate_devices_args *args = v;
+	const struct device_compatible_entry *dce;
+	const struct sandpoint_i2cdev *i2cdev;
+	prop_dictionary_t props;
+	bool cbrv;
+
+	KASSERT(bi_pfam != NULL);
+
+	const char *fam_name = bi_pfam->name;
+	dce = device_compatible_lookup(_name, 1, sandpoint_i2c_compat);
+	if (dce == NULL) {
+		/* no i2c devices for this model. */
+		return 0;
+	}
+	i2cdev = dce->data;
+	KASSERT(i2cdev != NULL);
+
+	for (; i2cdev->name != NULL; i2cdev++) {
+		if (i2cdev->model_mask != 0) {
+			KASSERT(bi_model != NULL);
+			if ((i2cdev->model_mask & bi_model->flags) == 0) {
+/* skip this device. */
+continue;
+			}
+		}
+
+		props = prop_dictionary_create();
+
+		args->ia->ia_addr = i2cdev->addr;
+		args->ia->ia_name = i2cdev->name;
+		args->ia->ia_clist = 

CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/fdt

2021-04-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Apr 25 22:20:08 UTC 2021

Modified Files:
src/sys/dev/fdt [thorpej-i2c-spi-conf]: fdt_i2c.c

Log Message:
- Don't call of_enter_i2c_devs() -- it no longer exists.
- Pass along the provided devhandle to the i2c bus instance.

XXX fdtbus_attach_i2cbus() is now just a thin wrapper around config_found()
and should probably just go away in favor of making FDT-attached i2c
controller drivers consistent with everyone else.


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.10.2.1 src/sys/dev/fdt/fdt_i2c.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/dev/fdt/fdt_i2c.c
diff -u src/sys/dev/fdt/fdt_i2c.c:1.10 src/sys/dev/fdt/fdt_i2c.c:1.10.2.1
--- src/sys/dev/fdt/fdt_i2c.c:1.10	Sat Apr 24 23:36:53 2021
+++ src/sys/dev/fdt/fdt_i2c.c	Sun Apr 25 22:20:08 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: fdt_i2c.c,v 1.10 2021/04/24 23:36:53 thorpej Exp $ */
+/* $NetBSD: fdt_i2c.c,v 1.10.2.1 2021/04/25 22:20:08 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: fdt_i2c.c,v 1.10 2021/04/24 23:36:53 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdt_i2c.c,v 1.10.2.1 2021/04/25 22:20:08 thorpej Exp $");
 
 #include 
 #include 
@@ -102,31 +102,12 @@ device_t
 fdtbus_attach_i2cbus(device_t dev, int phandle, i2c_tag_t tag, cfprint_t print)
 {
 	struct i2cbus_attach_args iba;
-	prop_dictionary_t devs, props;
-	device_t ret;
-	u_int address_cells;
-
-	devs = prop_dictionary_create();
-	if (of_getprop_uint32(phandle, "#address-cells", _cells))
-		address_cells = 1;
-
-	of_enter_i2c_devs(devs, phandle, address_cells * 4, 0);
 
 	memset(, 0, sizeof(iba));
 	iba.iba_tag = tag;
-	iba.iba_child_devices = prop_dictionary_get(devs, "i2c-child-devices");
-	if (iba.iba_child_devices)
-		prop_object_retain(iba.iba_child_devices);
-	prop_object_release(devs);
-
-	props = device_properties(dev);
-	prop_dictionary_set_bool(props, "i2c-no-indirect-config", true);
 
-	ret = config_found(dev, , print,
+	return config_found(dev, , print,
 	CFARG_IATTR, "i2cbus",
+	CFARG_DEVHANDLE, devhandle_from_of(phandle),
 	CFARG_EOL);
-	if (iba.iba_child_devices)
-		prop_object_release(iba.iba_child_devices);
-
-	return ret;
 }



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/ofw

2021-04-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Apr 25 22:16:05 UTC 2021

Modified Files:
src/sys/dev/ofw [thorpej-i2c-spi-conf]: ofw_i2c_subr.c openfirm.h

Log Message:
Implement "i2c-enumerate-devices" for OFW / FDT.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.1.6.1 src/sys/dev/ofw/ofw_i2c_subr.c
cvs rdiff -u -r1.47 -r1.47.2.1 src/sys/dev/ofw/openfirm.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ofw/ofw_i2c_subr.c
diff -u src/sys/dev/ofw/ofw_i2c_subr.c:1.1 src/sys/dev/ofw/ofw_i2c_subr.c:1.1.6.1
--- src/sys/dev/ofw/ofw_i2c_subr.c:1.1	Thu Feb  4 20:19:09 2021
+++ src/sys/dev/ofw/ofw_i2c_subr.c	Sun Apr 25 22:16:05 2021
@@ -1,4 +1,30 @@
-/*	$NetBSD: ofw_i2c_subr.c,v 1.1 2021/02/04 20:19:09 thorpej Exp $	*/
+/*	$NetBSD: ofw_i2c_subr.c,v 1.1.6.1 2021/04/25 22:16:05 thorpej Exp $	*/
+
+/*
+ * Copyright (c) 2021 The NetBSD Foundation, Inc.
+ * 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.
+ */
 
 /*
  * Copyright 1998
@@ -34,7 +60,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1 2021/02/04 20:19:09 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr.c,v 1.1.6.1 2021/04/25 22:16:05 thorpej Exp $");
 
 #include 
 #include 
@@ -44,66 +70,81 @@ __KERNEL_RCSID(0, "$NetBSD: ofw_i2c_subr
 #include 
 
 /*
- * Iterate over the subtree of a i2c controller node.
- * Add all sub-devices into an array as part of the controller's
- * device properties.
- * This is used by the i2c bus attach code to do direct configuration.
+ * Standard routine for fetching an i2c device address, according
+ * to the standard OpenFirmware / Device Tree bindings.
  */
-void
-of_enter_i2c_devs(prop_dictionary_t props, int ofnode, size_t cell_size,
-int addr_shift)
+static bool
+of_i2c_get_address(int node, uint32_t *addrp)
+{
+	uint32_t reg;
+
+	if (of_getprop_uint32(node, "reg", ) == -1) {
+		return false;
+	}
+
+	*addrp = reg;
+	return true;
+}
+
+static int
+of_i2c_enumerate_devices(device_t dev, devhandle_t call_handle, void *v)
 {
-	int node, len;
-	char name[32];
-	uint64_t reg64;
-	uint32_t reg32;
-	uint64_t addr;
-	prop_array_t array = NULL;
-	prop_dictionary_t dev;
+	return of_i2c_enumerate_devices_ext(dev, call_handle, v,
+	of_i2c_get_address);
+}
+OF_DEVICE_CALL_REGISTER("i2c-enumerate-devices", of_i2c_enumerate_devices);
 
-	for (node = OF_child(ofnode); node; node = OF_peer(node)) {
-		if (OF_getprop(node, "name", name, sizeof(name)) <= 0)
+int
+of_i2c_enumerate_devices_ext(device_t dev, devhandle_t call_handle, void *v,
+bool (*get_address)(int, uint32_t *))
+{
+	struct i2c_enumerate_devices_args *args = v;
+	int i2c_node, node;
+	char name[32], compat_buf[32];
+	prop_dictionary_t props;
+	uint32_t addr;
+	char *clist;
+	int clist_size;
+	bool cbrv;
+
+	i2c_node = devhandle_to_of(call_handle);
+
+	for (node = OF_child(i2c_node); node != 0; node = OF_peer(node)) {
+		if (OF_getprop(node, "name", name, sizeof(name)) <= 0) {
 			continue;
-		len = OF_getproplen(node, "reg");
-		addr = 0;
-		if (cell_size == 8 && len >= sizeof(reg64)) {
-			if (OF_getprop(node, "reg", , sizeof(reg64))
-			< sizeof(reg64))
-continue;
-			addr = be64toh(reg64);
-			/*
-			 * The i2c bus number (0 or 1) is encoded in bit 33
-			 * of the register, but we encode it in bit 8 of
-			 * i2c_addr_t.
-			 */
-			if (addr & 0x1)
-addr = (addr & 0xff) | 0x100;
-		} else if (cell_size == 4 && len >= sizeof(reg32)) {
-			if (OF_getprop(node, "reg", , sizeof(reg32))
-			< sizeof(reg32))
-continue;
-			addr = be32toh(reg32);
-		} else {
+		}
+		if (!get_address(node, )) {
 		

CVS commit: [thorpej-i2c-spi-conf] src/sys

2021-04-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Apr 25 22:02:59 UTC 2021

Modified Files:
src/sys/arch/arm/broadcom [thorpej-i2c-spi-conf]: bcm2835_bsc_acpi.c
src/sys/arch/x86/pci [thorpej-i2c-spi-conf]: dwiic_pci.c
src/sys/dev/acpi [thorpej-i2c-spi-conf]: dwiic_acpi.c nxpiic_acpi.c
src/sys/dev/i2c [thorpej-i2c-spi-conf]: motoi2c.c motoi2cvar.h

Log Message:
- Don't use acpi_enter_i2c_devs() -- it no longer exists.
- Pass along our devhandle to the i2c bus instance.


To generate a diff of this commit:
cvs rdiff -u -r1.3.2.1 -r1.3.2.2 src/sys/arch/arm/broadcom/bcm2835_bsc_acpi.c
cvs rdiff -u -r1.4.2.1 -r1.4.2.2 src/sys/arch/x86/pci/dwiic_pci.c
cvs rdiff -u -r1.8.2.1 -r1.8.2.2 src/sys/dev/acpi/dwiic_acpi.c
cvs rdiff -u -r1.4.6.1 -r1.4.6.2 src/sys/dev/acpi/nxpiic_acpi.c
cvs rdiff -u -r1.11 -r1.11.2.1 src/sys/dev/i2c/motoi2c.c
cvs rdiff -u -r1.8 -r1.8.4.1 src/sys/dev/i2c/motoi2cvar.h

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/broadcom/bcm2835_bsc_acpi.c
diff -u src/sys/arch/arm/broadcom/bcm2835_bsc_acpi.c:1.3.2.1 src/sys/arch/arm/broadcom/bcm2835_bsc_acpi.c:1.3.2.2
--- src/sys/arch/arm/broadcom/bcm2835_bsc_acpi.c:1.3.2.1	Sun Apr 25 21:52:28 2021
+++ src/sys/arch/arm/broadcom/bcm2835_bsc_acpi.c	Sun Apr 25 22:02:59 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm2835_bsc_acpi.c,v 1.3.2.1 2021/04/25 21:52:28 thorpej Exp $ */
+/* $NetBSD: bcm2835_bsc_acpi.c,v 1.3.2.2 2021/04/25 22:02:59 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_bsc_acpi.c,v 1.3.2.1 2021/04/25 21:52:28 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_bsc_acpi.c,v 1.3.2.2 2021/04/25 22:02:59 thorpej Exp $");
 
 #include 
 #include 
@@ -159,8 +159,9 @@ bsciic_acpi_attach(device_t parent, devi
 
 	memset(, 0, sizeof(iba));
 	iba.iba_tag = >sc_i2c;
-	iba.iba_child_devices = acpi_enter_i2c_devs(self, aa->aa_node);
-	config_found(self, , iicbus_print, CFARG_EOL);
+	config_found(self, , iicbus_print,
+	CFARG_DEVHANDLE, device_handle(self),
+	CFARG_EOL);
 
 done:
 	acpi_resource_cleanup();

Index: src/sys/arch/x86/pci/dwiic_pci.c
diff -u src/sys/arch/x86/pci/dwiic_pci.c:1.4.2.1 src/sys/arch/x86/pci/dwiic_pci.c:1.4.2.2
--- src/sys/arch/x86/pci/dwiic_pci.c:1.4.2.1	Sun Apr 25 21:52:28 2021
+++ src/sys/arch/x86/pci/dwiic_pci.c	Sun Apr 25 22:02:59 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwiic_pci.c,v 1.4.2.1 2021/04/25 21:52:28 thorpej Exp $ */
+/* $NetBSD: dwiic_pci.c,v 1.4.2.2 2021/04/25 22:02:59 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwiic_pci.c,v 1.4.2.1 2021/04/25 21:52:28 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwiic_pci.c,v 1.4.2.2 2021/04/25 22:02:59 thorpej Exp $");
 
 #include 
 #include 
@@ -42,10 +42,6 @@ __KERNEL_RCSID(0, "$NetBSD: dwiic_pci.c,
 #include 
 #include 
 
-#include 
-#include 
-#include 
-
 #include 
 #include 
 
@@ -61,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 +159,11 @@ 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_dwiic);
 
-	config_found(self, >sc_dwiic.sc_iba, iicbus_print, CFARG_EOL);
+	config_found(self, >sc_dwiic.sc_iba, iicbus_print,
+	CFARG_DEVHANDLE, device_handle(self),
+	CFARG_EOL);
 
 	pmf_device_register(self, dwiic_suspend, dwiic_resume);
 

Index: src/sys/dev/acpi/dwiic_acpi.c
diff -u src/sys/dev/acpi/dwiic_acpi.c:1.8.2.1 src/sys/dev/acpi/dwiic_acpi.c:1.8.2.2
--- src/sys/dev/acpi/dwiic_acpi.c:1.8.2.1	Sun Apr 25 21:52:28 2021
+++ src/sys/dev/acpi/dwiic_acpi.c	Sun Apr 25 22:02:59 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwiic_acpi.c,v 1.8.2.1 2021/04/25 21:52:28 thorpej Exp $ */
+/* $NetBSD: dwiic_acpi.c,v 1.8.2.2 2021/04/25 22:02:59 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c,v 1.8.2.1 2021/04/25 21:52:28 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c,v 1.8.2.2 2021/04/25 22:02:59 thorpej Exp $");
 
 #include 
 #include 
@@ -124,11 +124,11 @@ 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_iba, iicbus_print, CFARG_EOL);
+	

CVS commit: [thorpej-i2c-spi-conf] src/sys

2021-04-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Apr 25 21:52:28 UTC 2021

Modified Files:
src/sys/arch/arm/broadcom [thorpej-i2c-spi-conf]: bcm2835_bsc_acpi.c
src/sys/arch/x86/pci [thorpej-i2c-spi-conf]: dwiic_pci.c
src/sys/dev/acpi [thorpej-i2c-spi-conf]: dwiic_acpi.c nxpiic_acpi.c

Log Message:
acpi_i2c.h is no more.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.3.2.1 src/sys/arch/arm/broadcom/bcm2835_bsc_acpi.c
cvs rdiff -u -r1.4 -r1.4.2.1 src/sys/arch/x86/pci/dwiic_pci.c
cvs rdiff -u -r1.8 -r1.8.2.1 src/sys/dev/acpi/dwiic_acpi.c
cvs rdiff -u -r1.4 -r1.4.6.1 src/sys/dev/acpi/nxpiic_acpi.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/broadcom/bcm2835_bsc_acpi.c
diff -u src/sys/arch/arm/broadcom/bcm2835_bsc_acpi.c:1.3 src/sys/arch/arm/broadcom/bcm2835_bsc_acpi.c:1.3.2.1
--- src/sys/arch/arm/broadcom/bcm2835_bsc_acpi.c:1.3	Sat Apr 24 23:36:26 2021
+++ src/sys/arch/arm/broadcom/bcm2835_bsc_acpi.c	Sun Apr 25 21:52:28 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: bcm2835_bsc_acpi.c,v 1.3 2021/04/24 23:36:26 thorpej Exp $ */
+/* $NetBSD: bcm2835_bsc_acpi.c,v 1.3.2.1 2021/04/25 21:52:28 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2020 Jared McNeill 
@@ -27,7 +27,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: bcm2835_bsc_acpi.c,v 1.3 2021/04/24 23:36:26 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: bcm2835_bsc_acpi.c,v 1.3.2.1 2021/04/25 21:52:28 thorpej Exp $");
 
 #include 
 #include 
@@ -37,7 +37,6 @@ __KERNEL_RCSID(0, "$NetBSD: bcm2835_bsc_
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 

Index: src/sys/arch/x86/pci/dwiic_pci.c
diff -u src/sys/arch/x86/pci/dwiic_pci.c:1.4 src/sys/arch/x86/pci/dwiic_pci.c:1.4.2.1
--- src/sys/arch/x86/pci/dwiic_pci.c:1.4	Sat Apr 24 23:36:51 2021
+++ src/sys/arch/x86/pci/dwiic_pci.c	Sun Apr 25 21:52:28 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwiic_pci.c,v 1.4 2021/04/24 23:36:51 thorpej Exp $ */
+/* $NetBSD: dwiic_pci.c,v 1.4.2.1 2021/04/25 21:52:28 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2017 The NetBSD Foundation, Inc.
@@ -33,7 +33,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwiic_pci.c,v 1.4 2021/04/24 23:36:51 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwiic_pci.c,v 1.4.2.1 2021/04/25 21:52:28 thorpej Exp $");
 
 #include 
 #include 
@@ -45,7 +45,6 @@ __KERNEL_RCSID(0, "$NetBSD: dwiic_pci.c,
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 

Index: src/sys/dev/acpi/dwiic_acpi.c
diff -u src/sys/dev/acpi/dwiic_acpi.c:1.8 src/sys/dev/acpi/dwiic_acpi.c:1.8.2.1
--- src/sys/dev/acpi/dwiic_acpi.c:1.8	Sat Apr 24 23:36:52 2021
+++ src/sys/dev/acpi/dwiic_acpi.c	Sun Apr 25 21:52:28 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: dwiic_acpi.c,v 1.8 2021/04/24 23:36:52 thorpej Exp $ */
+/* $NetBSD: dwiic_acpi.c,v 1.8.2.1 2021/04/25 21:52:28 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2018 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c,v 1.8 2021/04/24 23:36:52 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c,v 1.8.2.1 2021/04/25 21:52:28 thorpej Exp $");
 
 #include 
 #include 
@@ -40,7 +40,6 @@ __KERNEL_RCSID(0, "$NetBSD: dwiic_acpi.c
 #include 
 #include 
 #include 
-#include 
 
 #include 
 

Index: src/sys/dev/acpi/nxpiic_acpi.c
diff -u src/sys/dev/acpi/nxpiic_acpi.c:1.4 src/sys/dev/acpi/nxpiic_acpi.c:1.4.6.1
--- src/sys/dev/acpi/nxpiic_acpi.c:1.4	Fri Jan 29 02:26:58 2021
+++ src/sys/dev/acpi/nxpiic_acpi.c	Sun Apr 25 21:52:28 2021
@@ -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.6.1 2021/04/25 21:52:28 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.6.1 2021/04/25 21:52:28 thorpej Exp $");
 
 #include 
 #include 
@@ -40,7 +40,6 @@ __KERNEL_RCSID(0, "$NetBSD: nxpiic_acpi.
 #include 
 #include 
 #include 
-#include 
 
 #include 
 #include 



CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/acpi

2021-04-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Apr 25 21:49:56 UTC 2021

Modified Files:
src/sys/dev/acpi [thorpej-i2c-spi-conf]: acpi_i2c.c
Removed Files:
src/sys/dev/acpi [thorpej-i2c-spi-conf]: acpi_i2c.h

Log Message:
Implement "i2c-enumerate-devices" for ACPI.


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.11.4.1 src/sys/dev/acpi/acpi_i2c.c
cvs rdiff -u -r1.2 -r0 src/sys/dev/acpi/acpi_i2c.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/acpi/acpi_i2c.c
diff -u src/sys/dev/acpi/acpi_i2c.c:1.11 src/sys/dev/acpi/acpi_i2c.c:1.11.4.1
--- src/sys/dev/acpi/acpi_i2c.c:1.11	Tue Jan 26 01:23:08 2021
+++ src/sys/dev/acpi/acpi_i2c.c	Sun Apr 25 21:49:56 2021
@@ -1,11 +1,11 @@
-/* $NetBSD: acpi_i2c.c,v 1.11 2021/01/26 01:23:08 thorpej Exp $ */
+/* $NetBSD: acpi_i2c.c,v 1.11.4.1 2021/04/25 21:49:56 thorpej Exp $ */
 
 /*-
  * Copyright (c) 2017, 2021 The NetBSD Foundation, Inc.
  * All rights reserved.
  *
  * This code is derived from software contributed to The NetBSD Foundation
- * by Manuel Bouyer.
+ * by Manuel Bouyer and Jason R. Thorpe.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
@@ -30,11 +30,10 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: acpi_i2c.c,v 1.11 2021/01/26 01:23:08 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: acpi_i2c.c,v 1.11.4.1 2021/04/25 21:49:56 thorpej Exp $");
 
 #include 
 #include 
-#include 
 #include 
 
 #include 
@@ -69,15 +68,16 @@ acpi_i2c_resource_parse_callback(ACPI_RE
 	return_ACPI_STATUS(AE_OK);
 }
 
-static void
-acpi_enter_i2c_device(struct acpi_devnode *ad, prop_array_t array)
+static bool
+acpi_i2c_enumerate_device(device_t dev, struct acpi_devnode *ad,
+struct i2c_enumerate_devices_args * const args)
 {
-	prop_dictionary_t dev;
-	struct acpi_i2c_context i2cc;
-	ACPI_STATUS rv;
-	const char *name;
 	char *clist;
 	size_t clist_size;
+	prop_dictionary_t props;
+	struct acpi_i2c_context i2cc;
+	bool cbrv;
+	ACPI_STATUS rv;
 
 	memset(, 0, sizeof(i2cc));
 	rv = AcpiWalkResources(ad->ad_handle, "_CRS",
@@ -86,58 +86,61 @@ acpi_enter_i2c_device(struct acpi_devnod
 		aprint_error("ACPI: unable to get resources "
 		   "for %s: %s\n", ad->ad_name,
 		   AcpiFormatException(rv));
-		return;
+		return true;	/* keep enumerating */
 	}
 	if (i2cc.i2c_addr == 0)
-		return;
-	dev = prop_dictionary_create();
-	if (dev == NULL) {
-		aprint_error("ignoring device %s (no memory)\n",
-		ad->ad_name);
-		return;
-	}
+		return true;	/* keep enumerating */
+
 	clist = acpi_pack_compat_list(ad->ad_devinfo, _size);
 	if (clist == NULL) {
-		prop_object_release(dev);
-		aprint_error("ignoring device %s (no _HID or _CID)\n",
+		aprint_error("ACPI: ignoring device %s (no _HID or _CID)\n",
 		ad->ad_name);
-		return;
+		return true;	/* keep enumerating */
 	}
-	if ((ad->ad_devinfo->Valid & ACPI_VALID_HID) == 0)
-		name = ad->ad_name;
-	else
-		name = ad->ad_devinfo->HardwareId.String;
-	prop_dictionary_set_string(dev, "name", name);
-	prop_dictionary_set_uint32(dev, "addr", i2cc.i2c_addr);
-	prop_dictionary_set_uint64(dev, "cookie", (uintptr_t)ad->ad_handle);
-	prop_dictionary_set_uint32(dev, "cookietype", I2C_COOKIE_ACPI);
-	prop_dictionary_set_data(dev, "compatible", clist, clist_size);
+	props = prop_dictionary_create();
+
+	args->ia->ia_addr = i2cc.i2c_addr;
+	args->ia->ia_name = ad->ad_name;
+	args->ia->ia_clist = clist;
+	args->ia->ia_clist_size = clist_size;
+	args->ia->ia_prop = props;
+	args->ia->ia_devhandle = devhandle_from_acpi(ad->ad_handle);
+	args->ia->ia_cookie = (uint64_t)ad->ad_handle;	/* XXX */
+	args->ia->ia_cookietype = I2C_COOKIE_ACPI;	/* XXX */
+
+	cbrv = args->callback(dev, args);
+
+	prop_object_release(props);
 	kmem_free(clist, clist_size);
 
-	prop_array_add(array, dev);
-	prop_object_release(dev);
+	return cbrv;	/* callback decides if we keep enumerating */
 }
 
-prop_array_t
-acpi_enter_i2c_devs(device_t dev, struct acpi_devnode *devnode)
+static int
+acpi_i2c_enumerate_devices(device_t dev, devhandle_t call_handle, void *v)
 {
-	struct acpi_devnode *ad;
-	prop_array_t array = prop_array_create();
-
-	if (array == NULL)
-		return NULL;
+	struct i2c_enumerate_devices_args *args = v;
+	struct acpi_devnode *ad, *devnode;
+	ACPI_HANDLE *hdl = devhandle_to_acpi(call_handle);
+
+	devnode = acpi_match_node(hdl);
+	if (devnode == NULL) {
+		aprint_verbose_dev(dev, "%s: no devnode matching handle\n",
+		__func__);
+		return 0;
+	}
 
 	SIMPLEQ_FOREACH(ad, >ad_child_head, ad_child_list) {
 		if (ad->ad_devinfo->Type != ACPI_TYPE_DEVICE)
 			continue;
 		if (!acpi_device_present(ad->ad_handle))
 			continue;
-		acpi_enter_i2c_device(ad, array);
+		if (!acpi_i2c_enumerate_device(dev, ad, args))
+			break;
 	}
 
-	if (dev != NULL) {
-		acpi_claim_childdevs(dev, devnode);
-	}
+	acpi_claim_childdevs(dev, devnode);
 
-	

CVS commit: [thorpej-i2c-spi-conf] src/sys/dev/i2c

2021-04-25 Thread Jason R Thorpe
Module Name:src
Committed By:   thorpej
Date:   Sun Apr 25 21:45:16 UTC 2021

Modified Files:
src/sys/dev/i2c [thorpej-i2c-spi-conf]: i2c.c i2cvar.h

Log Message:
Stop using a prop_array of child device data to perform direct
configuration of i2c devices.  Instead, introduce and use a new
device call "i2c-enumerate-devices" that can be implemented by
devhandle providers that have I2C bindings.  This device call
gathers up the data into i2c_attach_args and invoked a callback
(back to the i2c layer) to attach the device.  The I2C controller
device supplies its devhandle (or the appropriate devhandle for
the I2C bus) when attaching the i2c bus instance using CFARG_DEVHANDLE.


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.78.2.1 src/sys/dev/i2c/i2c.c
cvs rdiff -u -r1.24 -r1.24.2.1 src/sys/dev/i2c/i2cvar.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/i2c/i2c.c
diff -u src/sys/dev/i2c/i2c.c:1.78 src/sys/dev/i2c/i2c.c:1.78.2.1
--- src/sys/dev/i2c/i2c.c:1.78	Sat Apr 24 23:36:54 2021
+++ src/sys/dev/i2c/i2c.c	Sun Apr 25 21:45:15 2021
@@ -1,4 +1,33 @@
-/*	$NetBSD: i2c.c,v 1.78 2021/04/24 23:36:54 thorpej Exp $	*/
+/*	$NetBSD: i2c.c,v 1.78.2.1 2021/04/25 21:45:15 thorpej 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) 2003 Wasabi Systems, Inc.
@@ -40,7 +69,7 @@
 #endif
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78 2021/04/24 23:36:54 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.78.2.1 2021/04/25 21:45:15 thorpej Exp $");
 
 #include 
 #include 
@@ -99,8 +128,6 @@ const struct cdevsw iic_cdevsw = {
 };
 
 static void	iic_smbus_intr_thread(void *);
-static void	iic_fill_compat(struct i2c_attach_args*, const char*,
-			size_t, char **);
 
 static int
 iic_print_direct(void *aux, const char *pnp)
@@ -287,8 +314,8 @@ iic_search(device_t parent, cfdata_t cf,
 	ia.ia_tag = sc->sc_tag;
 
 	ia.ia_name = NULL;
-	ia.ia_ncompat = 0;
-	ia.ia_compat = NULL;
+	ia.ia_clist = NULL;
+	ia.ia_clist_size = 0;
 	ia.ia_prop = NULL;
 
 	if (cf->cf_loc[IICCF_ADDR] == IICCF_ADDR_DEFAULT) {
@@ -387,6 +414,34 @@ iic_rescan(device_t self, const char *if
 	return 0;
 }
 
+static bool
+iic_enumerate_devices_callback(device_t self,
+struct i2c_enumerate_devices_args *args)
+{
+	struct iic_softc *sc = device_private(self);
+	int loc[IICCF_NLOCS] = { 0 };
+
+	args->count++;
+
+	loc[IICCF_ADDR] = args->ia->ia_addr;
+
+	if (args->ia->ia_addr > I2C_MAX_ADDR) {
+		aprint_error_dev(self,
+		"WARNING: ignoring bad device address @ 0x%02x\n",
+		args->ia->ia_addr);
+		return true;			/* keep enumerating */
+	}
+	if (sc->sc_devices[args->ia->ia_addr] == NULL) {
+		sc->sc_devices[args->ia->ia_addr] =
+		config_found(self, args->ia, iic_print_direct,
+			/* CFARG_SUBMATCH, config_stdsubmatch, XXX */
+			CFARG_LOCATORS, loc,
+			CFARG_DEVHANDLE, args->ia->ia_devhandle,
+			CFARG_EOL);
+	}
+	return true;/* keep enumerating */
+}
+
 static int
 iic_match(device_t parent, cfdata_t cf, void *aux)
 {
@@ -399,18 +454,15 @@ iic_attach(device_t parent, device_t sel
 {
 	struct iic_softc *sc = device_private(self);
 	struct i2cbus_attach_args *iba = aux;
-	prop_array_t child_devices;
-	prop_dictionary_t props;
-	char *buf;
 	i2c_tag_t ic;
 	int rv;
-	bool no_indirect_config = false;
 
 	aprint_naive("\n");
 	aprint_normal(": I2C bus\n");
 
 	sc->sc_dev = self;
 	sc->sc_tag = iba->iba_tag;
+
 	ic = sc->sc_tag;