From c1762c82da9178fd3dbb9673d7b4a6a76a5da816 Mon Sep 17 00:00:00 2001 From: patrick Date: Thu, 11 Mar 2021 09:15:25 +0000 Subject: [PATCH] Make sure to skip attaching disabled I2C devices. This can happen on hardware which include a common parent block in their device trees and only enable the components that were actually implemented, as seen on e.g. the NanoPi R4S. --- sys/dev/fdt/amliic.c | 9 +++++++-- sys/dev/fdt/bcm2835_bsc.c | 9 +++++++-- sys/dev/fdt/imxiic_fdt.c | 9 +++++++-- sys/dev/fdt/mviic.c | 9 +++++++-- sys/dev/fdt/sxitwi.c | 9 +++++++-- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/sys/dev/fdt/amliic.c b/sys/dev/fdt/amliic.c index 275cac4528b..83535b0da52 100644 --- a/sys/dev/fdt/amliic.c +++ b/sys/dev/fdt/amliic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: amliic.c,v 1.2 2020/12/18 22:13:06 kettenis Exp $ */ +/* $OpenBSD: amliic.c,v 1.3 2021/03/11 09:15:25 patrick Exp $ */ /* * Copyright (c) 2019 Mark Kettenis * @@ -269,12 +269,13 @@ amliic_bus_scan(struct device *self, struct i2cbus_attach_args *iba, void *arg) { int iba_node = *(int *)arg; struct i2c_attach_args ia; - char name[32]; + char name[32], status[32]; uint32_t reg[1]; int node; for (node = OF_child(iba_node); node; node = OF_peer(node)) { memset(name, 0, sizeof(name)); + memset(status, 0, sizeof(status)); memset(reg, 0, sizeof(reg)); if (OF_getprop(node, "compatible", name, sizeof(name)) == -1) @@ -282,6 +283,10 @@ amliic_bus_scan(struct device *self, struct i2cbus_attach_args *iba, void *arg) if (name[0] == '\0') continue; + if (OF_getprop(node, "status", status, sizeof(status)) > 0 && + strcmp(status, "disabled") == 0) + continue; + if (OF_getprop(node, "reg", ®, sizeof(reg)) != sizeof(reg)) continue; diff --git a/sys/dev/fdt/bcm2835_bsc.c b/sys/dev/fdt/bcm2835_bsc.c index 9f8f16db86f..017d5078264 100644 --- a/sys/dev/fdt/bcm2835_bsc.c +++ b/sys/dev/fdt/bcm2835_bsc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bcm2835_bsc.c,v 1.1 2020/04/25 22:28:12 kettenis Exp $ */ +/* $OpenBSD: bcm2835_bsc.c,v 1.2 2021/03/11 09:15:25 patrick Exp $ */ /* * Copyright (c) 2020 Mark Kettenis * @@ -273,12 +273,13 @@ bcmbsc_bus_scan(struct device *self, struct i2cbus_attach_args *iba, void *arg) { int iba_node = *(int *)arg; struct i2c_attach_args ia; - char name[32]; + char name[32], status[32]; uint32_t reg[1]; int node; for (node = OF_child(iba_node); node; node = OF_peer(node)) { memset(name, 0, sizeof(name)); + memset(status, 0, sizeof(status)); memset(reg, 0, sizeof(reg)); if (OF_getprop(node, "compatible", name, sizeof(name)) == -1) @@ -286,6 +287,10 @@ bcmbsc_bus_scan(struct device *self, struct i2cbus_attach_args *iba, void *arg) if (name[0] == '\0') continue; + if (OF_getprop(node, "status", status, sizeof(status)) > 0 && + strcmp(status, "disabled") == 0) + continue; + if (OF_getprop(node, "reg", ®, sizeof(reg)) != sizeof(reg)) continue; diff --git a/sys/dev/fdt/imxiic_fdt.c b/sys/dev/fdt/imxiic_fdt.c index ab60de38511..f6d21ffe604 100644 --- a/sys/dev/fdt/imxiic_fdt.c +++ b/sys/dev/fdt/imxiic_fdt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: imxiic_fdt.c,v 1.1 2020/11/17 14:30:13 patrick Exp $ */ +/* $OpenBSD: imxiic_fdt.c,v 1.2 2021/03/11 09:15:25 patrick Exp $ */ /* * Copyright (c) 2013 Patrick Wildt * @@ -120,12 +120,13 @@ imxiic_fdt_bus_scan(struct device *self, struct i2cbus_attach_args *iba, void *a int iba_node = *(int *)aux; extern int iic_print(void *, const char *); struct i2c_attach_args ia; - char name[32]; + char name[32], status[32]; uint32_t reg[1]; int node; for (node = OF_child(iba_node); node; node = OF_peer(node)) { memset(name, 0, sizeof(name)); + memset(status, 0, sizeof(status)); memset(reg, 0, sizeof(reg)); if (OF_getprop(node, "compatible", name, sizeof(name)) == -1) @@ -133,6 +134,10 @@ imxiic_fdt_bus_scan(struct device *self, struct i2cbus_attach_args *iba, void *a if (name[0] == '\0') continue; + if (OF_getprop(node, "status", status, sizeof(status)) > 0 && + strcmp(status, "disabled") == 0) + continue; + if (OF_getprop(node, "reg", ®, sizeof(reg)) != sizeof(reg)) continue; diff --git a/sys/dev/fdt/mviic.c b/sys/dev/fdt/mviic.c index 7eb41855555..0581f697887 100644 --- a/sys/dev/fdt/mviic.c +++ b/sys/dev/fdt/mviic.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mviic.c,v 1.2 2019/09/07 13:27:40 patrick Exp $ */ +/* $OpenBSD: mviic.c,v 1.3 2021/03/11 09:15:25 patrick Exp $ */ /* * Copyright (c) 2019 Patrick Wildt * @@ -314,12 +314,13 @@ mviic_bus_scan(struct device *self, struct i2cbus_attach_args *iba, void *aux) int iba_node = *(int *)aux; extern int iic_print(void *, const char *); struct i2c_attach_args ia; - char name[32]; + char name[32], status[32]; uint32_t reg[1]; int node; for (node = OF_child(iba_node); node; node = OF_peer(node)) { memset(name, 0, sizeof(name)); + memset(status, 0, sizeof(status)); memset(reg, 0, sizeof(reg)); if (OF_getprop(node, "compatible", name, sizeof(name)) == -1) @@ -327,6 +328,10 @@ mviic_bus_scan(struct device *self, struct i2cbus_attach_args *iba, void *aux) if (name[0] == '\0') continue; + if (OF_getprop(node, "status", status, sizeof(status)) > 0 && + strcmp(status, "disabled") == 0) + continue; + if (OF_getprop(node, "reg", ®, sizeof(reg)) != sizeof(reg)) continue; diff --git a/sys/dev/fdt/sxitwi.c b/sys/dev/fdt/sxitwi.c index 112afa3431f..a7b872b5010 100644 --- a/sys/dev/fdt/sxitwi.c +++ b/sys/dev/fdt/sxitwi.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sxitwi.c,v 1.12 2020/10/08 20:57:52 patrick Exp $ */ +/* $OpenBSD: sxitwi.c,v 1.13 2021/03/11 09:15:25 patrick Exp $ */ /* $NetBSD: gttwsi_core.c,v 1.2 2014/11/23 13:37:27 jmcneill Exp $ */ /* * Copyright (c) 2008 Eiji Kawauchi. @@ -304,12 +304,13 @@ sxitwi_bus_scan(struct device *self, struct i2cbus_attach_args *iba, void *arg) { int iba_node = *(int *)arg; struct i2c_attach_args ia; - char name[32]; + char name[32], status[32]; uint32_t reg[1]; int node; for (node = OF_child(iba_node); node; node = OF_peer(node)) { memset(name, 0, sizeof(name)); + memset(status, 0, sizeof(status)); memset(reg, 0, sizeof(reg)); if (OF_getprop(node, "compatible", name, sizeof(name)) == -1) @@ -317,6 +318,10 @@ sxitwi_bus_scan(struct device *self, struct i2cbus_attach_args *iba, void *arg) if (name[0] == '\0') continue; + if (OF_getprop(node, "status", status, sizeof(status)) > 0 && + strcmp(status, "disabled") == 0) + continue; + if (OF_getprop(node, "reg", ®, sizeof(reg)) != sizeof(reg)) continue; -- 2.20.1