* [RFC net-next v2 0/6] ptp: ocp: Add R4006 and V9 I2C peripheral support
@ 2026-08-03 20:50 Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 1/6] dt-bindings: leds: Add IS32FL3207 controller Ahmad Byagowi
` (5 more replies)
0 siblings, 6 replies; 8+ messages in thread
From: Ahmad Byagowi @ 2026-08-03 20:50 UTC (permalink / raw)
To: linux-leds, devicetree, linux-i2c, netdev
Cc: Lee Jones, Pavel Machek, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Andi Shyti, Peter Rosin, Nam Tran, Vadim Fedorenko,
Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Kees Cook, Gustavo A. R. Silva,
linux-hardening, linux-kernel
R4006 and Time Card V9 place an I2C mux behind the FPGA XIIC
controller. The current ptp_ocp driver exposes the root adapter but does
not describe the peripherals behind the mux.
This series adds the generic infrastructure and board profiles needed
for existing subsystem drivers to bind to those peripherals:
1. A binding for the Lumissil IS32FL3207 18-channel LED controller.
2. An IS32FL3207 LED class driver with individual and multicolor LED
support and per-output current limits.
3. Software-node propagation from an I2C mux to its channel adapters.
4. Validation of the fixed-width EEPROM board identifier.
5. An R4006 profile for its sensors and GNSS/SMA LEDs.
6. A Time Card V9 profile for its BME280, BNO055, GNSS1, GNSS2, and
four SMA LEDs.
Profile selection is deliberately fail-closed. PCI IDs are shared by
multiple PCB revisions, so only a validated EEPROM board identifier may
select a topology. Erased, malformed, and unknown identifiers leave the
downstream devices unconfigured. R4006 identifiers are matched by their
R4006 prefix, while Time Card V9 requires the exact "TIMECARD-V9"
identifier.
The R4006 BNO08x is intentionally not instantiated because no upstream
driver exists for it. LED status policy remains in userspace; this
series exposes standard multicolor LED class devices.
The EEPROM validation patch fixes a pre-existing out-of-bounds string
read and carries Fixes and stable trailers. It is included because safe
board identification is a prerequisite for the profiles. That patch can
travel separately through the net tree if preferred.
Validation performed:
- dt_binding_check, including YAML lint and example compilation
- x86-64 and arm64 W=1 builds of the modified driver objects
- strict checkpatch and git diff --check
- R4006 addresses and LED routing exercised with the downstream
implementation
- Time Card V9 BME280, BNO055, mux, and LED-controller addresses
verified directly on hardware
The complete upstream series has not yet been boot-tested on an R4006.
The V9 test card has an erased EEPROM and was intentionally left
unchanged, so automatic V9 profile selection was not exercised. Its LED
controller responded, but the outputs reported open-load status on that
board, so physical LED illumination could not be validated. The test
distribution also lacked the BME280 and BNO055 modules.
Questions for this RFC:
- Should IS32FL3207 remain a standalone multicolor driver, or be
integrated into the existing is31fl32xx driver?
- Is assigning software-node channel children in the generic I2C mux
core the preferred representation for PCI-card mux topologies?
- Should net-next carry the complete series after DT, LED, and I2C
review, or should the prerequisite patches travel separately?
Changes since RFC v1:
- Correct the documented PWM resolution and support standard LED
startup and retained-shutdown state properties.
- Use a named I2C ID initializer and fix MAINTAINERS ordering.
- Move EEPROM validation into a separate prerequisite fix.
- Select profiles only from validated EEPROM identifiers.
- Rework the R4006 implementation into reusable board profiles.
- Bound asynchronous retries and serialize topology population with
controller and mux driver bind/unbind.
- Avoid repeated managed allocations during retry.
- Add the Time Card V9 profile, including the second GNSS LED.
- Leave the I2C mux software-node propagation patch unchanged.
RFC v1:
https://lore.kernel.org/r/cover.1785684064.git.ahmadexp@gmail.com/
Ahmad Byagowi (6):
dt-bindings: leds: Add IS32FL3207 controller
leds: rgb: Add IS32FL3207 controller driver
i2c: mux: Propagate software nodes to channel adapters
ptp: ocp: Validate EEPROM board IDs
ptp: ocp: Add R4006 I2C peripheral topology
ptp: ocp: Add Time Card V9 I2C peripheral topology
.../bindings/leds/issi,is32fl3207.yaml | 208 +++++
MAINTAINERS | 7 +
drivers/i2c/i2c-mux.c | 55 ++
drivers/leds/rgb/Kconfig | 11 +
drivers/leds/rgb/Makefile | 1 +
drivers/leds/rgb/leds-is32fl3207.c | 580 ++++++++++++
drivers/ptp/ptp_ocp.c | 871 +++++++++++++++++-
7 files changed, 1687 insertions(+), 46 deletions(-)
create mode 100644 Documentation/devicetree/bindings/leds/issi,is32fl3207.yaml
create mode 100644 drivers/leds/rgb/leds-is32fl3207.c
base-commit: 69963a0678a347d57c4ac8b16939dba216eb95ce
--
2.50.1 (Apple Git-155)
^ permalink raw reply [flat|nested] 8+ messages in thread
* [RFC net-next v2 1/6] dt-bindings: leds: Add IS32FL3207 controller
2026-08-03 20:50 [RFC net-next v2 0/6] ptp: ocp: Add R4006 and V9 I2C peripheral support Ahmad Byagowi
@ 2026-08-03 20:50 ` Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 2/6] leds: rgb: Add IS32FL3207 controller driver Ahmad Byagowi
` (4 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Ahmad Byagowi @ 2026-08-03 20:50 UTC (permalink / raw)
To: linux-leds, devicetree, linux-i2c, netdev
Cc: Lee Jones, Pavel Machek, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Andi Shyti, Peter Rosin, Nam Tran, Vadim Fedorenko,
Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Kees Cook, Gustavo A. R. Silva,
linux-hardening, linux-kernel
The IS32FL3207 is an 18-channel constant-current LED controller
with per-output PWM and current scaling.
Describe I2C addressing, power and shutdown controls, RISET, and
individual or multicolor output groupings. Require board current limits
for each output.
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
.../bindings/leds/issi,is32fl3207.yaml | 208 ++++++++++++++++++
MAINTAINERS | 6 +
2 files changed, 214 insertions(+)
create mode 100644 Documentation/devicetree/bindings/leds/issi,is32fl3207.yaml
diff --git a/Documentation/devicetree/bindings/leds/issi,is32fl3207.yaml b/Documentation/devicetree/bindings/leds/issi,is32fl3207.yaml
new file mode 100644
index 000000000..ffb305e9a
--- /dev/null
+++ b/Documentation/devicetree/bindings/leds/issi,is32fl3207.yaml
@@ -0,0 +1,208 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/leds/issi,is32fl3207.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Lumissil IS32FL3207 18-channel LED controller
+
+maintainers:
+ - Ahmad Byagowi <ahmadexp@gmail.com>
+
+description: |
+ The IS32FL3207 is an I2C LED controller with 18 individually controlled
+ constant-current outputs. Each output has 8-bit current scaling. PWM
+ brightness control uses the controller's default 8-bit, 62 kHz mode.
+ Outputs may be exposed as individual LEDs or grouped as multicolor LEDs.
+
+ The data sheet is available at:
+ https://www.lumissil.com/assets/pdf/core/IS32FL3207_DS.pdf
+
+properties:
+ compatible:
+ const: issi,is32fl3207
+
+ reg:
+ enum: [0x34, 0x35, 0x36, 0x37]
+
+ vcc-supply:
+ description: Regulator providing power to the VCC pin.
+
+ enable-gpios:
+ maxItems: 1
+ description: GPIO connected to SDB, asserted to enable the controller.
+
+ issi,riset-ohms:
+ minimum: 2000
+ maximum: 76500000
+ description: |
+ Resistance in ohms of the external RISET resistor. The resistor sets the
+ maximum output current according to IOUT(MAX) = 76.5 / RISET amperes.
+
+ "#address-cells":
+ const: 1
+
+ "#size-cells":
+ const: 0
+
+patternProperties:
+ "^led@[0-9a-f]+$":
+ type: object
+ $ref: common.yaml#
+ unevaluatedProperties: false
+
+ properties:
+ reg:
+ minimum: 0
+ maximum: 17
+ description: LED output number.
+
+ led-max-microamp:
+ minimum: 1
+ maximum: 38250
+
+ color:
+ not:
+ enum: [8, 9]
+
+ max-brightness:
+ minimum: 1
+ maximum: 255
+
+ default-state:
+ description:
+ The controller is reset during initialization, so an existing state
+ cannot be preserved.
+ enum: ["on", "off"]
+
+ default-brightness:
+ maximum: 255
+
+ required:
+ - reg
+ - led-max-microamp
+
+ "^multi-led@[0-9a-f]+$":
+ type: object
+ $ref: leds-class-multicolor.yaml#
+ unevaluatedProperties: false
+
+ properties:
+ reg:
+ minimum: 0
+ maximum: 17
+ description: Lowest-numbered LED output used by the group.
+
+ "#address-cells":
+ const: 1
+
+ "#size-cells":
+ const: 0
+
+ max-brightness:
+ minimum: 1
+ maximum: 255
+
+ default-state:
+ description:
+ The controller is reset during initialization, so an existing state
+ cannot be preserved.
+ enum: ["on", "off"]
+
+ default-brightness:
+ maximum: 255
+
+ patternProperties:
+ "^led@[0-9a-f]+$":
+ type: object
+ $ref: common.yaml#
+ unevaluatedProperties: false
+
+ properties:
+ reg:
+ minimum: 0
+ maximum: 17
+ description: LED output number.
+
+ led-max-microamp:
+ minimum: 1
+ maximum: 38250
+
+ color:
+ not:
+ enum: [8, 9]
+
+ max-brightness: false
+
+ default-state: false
+
+ default-brightness: false
+
+ retain-state-shutdown: false
+
+ required:
+ - reg
+ - color
+ - led-max-microamp
+
+ required:
+ - reg
+ - "#address-cells"
+ - "#size-cells"
+
+required:
+ - compatible
+ - reg
+ - issi,riset-ohms
+ - "#address-cells"
+ - "#size-cells"
+
+additionalProperties: false
+
+examples:
+ - |
+ #include <dt-bindings/gpio/gpio.h>
+ #include <dt-bindings/leds/common.h>
+
+ i2c {
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ led-controller@34 {
+ compatible = "issi,is32fl3207";
+ reg = <0x34>;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ vcc-supply = <&led_3v3>;
+ enable-gpios = <&gpio0 4 GPIO_ACTIVE_HIGH>;
+ issi,riset-ohms = <4700>;
+
+ multi-led@0 {
+ reg = <0>;
+ color = <LED_COLOR_ID_RGB>;
+ function = LED_FUNCTION_STATUS;
+ #address-cells = <1>;
+ #size-cells = <0>;
+
+ led@0 {
+ reg = <0>;
+ color = <LED_COLOR_ID_RED>;
+ led-max-microamp = <8100>;
+ };
+
+ led@1 {
+ reg = <1>;
+ color = <LED_COLOR_ID_GREEN>;
+ led-max-microamp = <8100>;
+ };
+
+ led@2 {
+ reg = <2>;
+ color = <LED_COLOR_ID_BLUE>;
+ led-max-microamp = <8100>;
+ };
+ };
+ };
+ };
+...
diff --git a/MAINTAINERS b/MAINTAINERS
index 932ea1db0..744296f1c 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13828,6 +13828,12 @@ S: Maintained
F: Documentation/filesystems/isofs.rst
F: fs/isofs/
+ISSI IS32FL3207 LED DRIVER
+M: Ahmad Byagowi <ahmadexp@gmail.com>
+L: linux-leds@vger.kernel.org
+S: Maintained
+F: Documentation/devicetree/bindings/leds/issi,is32fl3207.yaml
+
IT87 HARDWARE MONITORING DRIVER
M: Jean Delvare <jdelvare@suse.com>
L: linux-hwmon@vger.kernel.org
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [RFC net-next v2 2/6] leds: rgb: Add IS32FL3207 controller driver
2026-08-03 20:50 [RFC net-next v2 0/6] ptp: ocp: Add R4006 and V9 I2C peripheral support Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 1/6] dt-bindings: leds: Add IS32FL3207 controller Ahmad Byagowi
@ 2026-08-03 20:50 ` Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 3/6] i2c: mux: Propagate software nodes to channel adapters Ahmad Byagowi
` (3 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Ahmad Byagowi @ 2026-08-03 20:50 UTC (permalink / raw)
To: linux-leds, devicetree, linux-i2c, netdev
Cc: Lee Jones, Pavel Machek, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Andi Shyti, Peter Rosin, Nam Tran, Vadim Fedorenko,
Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Kees Cook, Gustavo A. R. Silva,
linux-hardening, linux-kernel
Add a generic I2C driver for the Lumissil IS32FL3207 18-channel
LED controller.
Expose individual and multicolor LEDs through the LED class. Use the
default 8-bit 62 kHz PWM mode, derive output current from RISET, and
enforce each output current limit with the scaling registers. Honor
initial brightness and retained shutdown state. Handle an optional
supply and enable GPIO, and serialize controller-wide update latches.
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
MAINTAINERS | 1 +
drivers/leds/rgb/Kconfig | 11 +
drivers/leds/rgb/Makefile | 1 +
drivers/leds/rgb/leds-is32fl3207.c | 580 +++++++++++++++++++++++++++++
4 files changed, 593 insertions(+)
create mode 100644 drivers/leds/rgb/leds-is32fl3207.c
diff --git a/MAINTAINERS b/MAINTAINERS
index 744296f1c..8f2386fd5 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -13833,6 +13833,7 @@ M: Ahmad Byagowi <ahmadexp@gmail.com>
L: linux-leds@vger.kernel.org
S: Maintained
F: Documentation/devicetree/bindings/leds/issi,is32fl3207.yaml
+F: drivers/leds/rgb/leds-is32fl3207.c
IT87 HARDWARE MONITORING DRIVER
M: Jean Delvare <jdelvare@suse.com>
diff --git a/drivers/leds/rgb/Kconfig b/drivers/leds/rgb/Kconfig
index 6e9ab5f60..c896be131 100644
--- a/drivers/leds/rgb/Kconfig
+++ b/drivers/leds/rgb/Kconfig
@@ -14,6 +14,17 @@ config LEDS_GROUP_MULTICOLOR
To compile this driver as a module, choose M here: the module
will be called leds-group-multicolor.
+config LEDS_IS32FL3207
+ tristate "LED support for ISSI IS32FL3207"
+ depends on I2C
+ select REGMAP_I2C
+ help
+ Say Y here to include support for the Lumissil IS32FL3207
+ 18-channel I2C LED controller.
+
+ To compile this driver as a module, choose M here: the module will
+ be called leds-is32fl3207.
+
config LEDS_KTD202X
tristate "LED support for KTD202x Chips"
depends on I2C
diff --git a/drivers/leds/rgb/Makefile b/drivers/leds/rgb/Makefile
index cc0f2df66..228923e8b 100644
--- a/drivers/leds/rgb/Makefile
+++ b/drivers/leds/rgb/Makefile
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0
obj-$(CONFIG_LEDS_GROUP_MULTICOLOR) += leds-group-multicolor.o
+obj-$(CONFIG_LEDS_IS32FL3207) += leds-is32fl3207.o
obj-$(CONFIG_LEDS_KTD202X) += leds-ktd202x.o
obj-$(CONFIG_LEDS_LP5812) += leds-lp5812.o
obj-$(CONFIG_LEDS_LP5860_CORE) += leds-lp5860-core.o
diff --git a/drivers/leds/rgb/leds-is32fl3207.c b/drivers/leds/rgb/leds-is32fl3207.c
new file mode 100644
index 000000000..08843da96
--- /dev/null
+++ b/drivers/leds/rgb/leds-is32fl3207.c
@@ -0,0 +1,580 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ISSI IS32FL3207 LED controller driver
+ *
+ * Copyright 2026 Ahmad Byagowi
+ */
+
+#include <linux/bitmap.h>
+#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
+#include <linux/i2c.h>
+#include <linux/led-class-multicolor.h>
+#include <linux/math64.h>
+#include <linux/module.h>
+#include <linux/mutex.h>
+#include <linux/property.h>
+#include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
+#include <linux/string.h>
+
+#include <dt-bindings/leds/common.h>
+
+#define IS32FL3207_NUM_CHANNELS 18
+#define IS32FL3207_MAX_BRIGHTNESS 255
+
+#define IS32FL3207_REG_CONTROL 0x00
+#define IS32FL3207_REG_PWM_LOW(channel) (0x01 + 2 * (channel))
+#define IS32FL3207_REG_PWM_UPDATE 0x49
+#define IS32FL3207_REG_SCALING(channel) (0x4a + (channel))
+#define IS32FL3207_REG_GLOBAL_CURRENT 0x6e
+#define IS32FL3207_REG_RESET 0x7f
+
+#define IS32FL3207_CONTROL_ENABLE BIT(0)
+#define IS32FL3207_GLOBAL_CURRENT_MAX 0xff
+
+/* IOUT(MAX) in microamperes = 76,500,000 / RISET in ohms. */
+#define IS32FL3207_CURRENT_NUMERATOR 76500000ULL
+
+struct is32fl3207;
+
+struct is32fl3207_led {
+ struct is32fl3207 *chip;
+ struct led_classdev *led_cdev;
+ union {
+ struct led_classdev cdev;
+ struct led_classdev_mc mcdev;
+ };
+ unsigned int channel;
+};
+
+struct is32fl3207 {
+ struct device *dev;
+ struct regmap *regmap;
+ struct gpio_desc *enable_gpio;
+ struct mutex lock; /* Serializes controller register updates. */
+ unsigned long channels[BITS_TO_LONGS(IS32FL3207_NUM_CHANNELS)];
+ u32 output_max_microamp;
+ unsigned int num_leds;
+ struct is32fl3207_led leds[] __counted_by(num_leds);
+};
+
+static int is32fl3207_parse_led_properties(struct is32fl3207 *chip,
+ struct fwnode_handle *fwnode,
+ unsigned int *max_brightness,
+ unsigned int *brightness)
+{
+ enum led_default_state default_state;
+ u32 value;
+ int ret;
+
+ *max_brightness = IS32FL3207_MAX_BRIGHTNESS;
+ if (fwnode_property_present(fwnode, "max-brightness")) {
+ ret = fwnode_property_read_u32(fwnode, "max-brightness", &value);
+ if (ret)
+ return dev_err_probe(chip->dev, ret,
+ "failed to read maximum brightness for %pfw\n",
+ fwnode);
+ if (!value || value > IS32FL3207_MAX_BRIGHTNESS)
+ return dev_err_probe(chip->dev, -EINVAL,
+ "invalid maximum brightness %u for %pfw\n",
+ value, fwnode);
+
+ *max_brightness = value;
+ }
+
+ value = *max_brightness;
+ if (fwnode_property_present(fwnode, "default-brightness")) {
+ ret = fwnode_property_read_u32(fwnode, "default-brightness",
+ &value);
+ if (ret)
+ return dev_err_probe(chip->dev, ret,
+ "failed to read default brightness for %pfw\n",
+ fwnode);
+ if (value > *max_brightness)
+ return dev_err_probe(chip->dev, -EINVAL,
+ "invalid default brightness %u for %pfw\n",
+ value, fwnode);
+ }
+
+ default_state = led_init_default_state_get(fwnode);
+ if (default_state == LEDS_DEFSTATE_KEEP)
+ return dev_err_probe(chip->dev, -EINVAL,
+ "default state keep is not supported for %pfw\n",
+ fwnode);
+
+ *brightness = default_state == LEDS_DEFSTATE_ON ? value : LED_OFF;
+ return 0;
+}
+
+static int is32fl3207_validate_component(struct is32fl3207 *chip,
+ struct fwnode_handle *fwnode)
+{
+ static const char * const unsupported[] = {
+ "default-brightness",
+ "default-state",
+ "max-brightness",
+ "retain-state-shutdown",
+ };
+ unsigned int i;
+
+ for (i = 0; i < ARRAY_SIZE(unsupported); i++)
+ if (fwnode_property_present(fwnode, unsupported[i]))
+ return dev_err_probe(chip->dev, -EINVAL,
+ "%s is not supported for component %pfw\n",
+ unsupported[i], fwnode);
+
+ return 0;
+}
+
+static int is32fl3207_write_channels(struct is32fl3207 *chip,
+ const struct mc_subled *subleds,
+ unsigned int num_channels)
+{
+ unsigned int i;
+ int ret;
+
+ guard(mutex)(&chip->lock);
+
+ for (i = 0; i < num_channels; i++) {
+ ret = regmap_write(chip->regmap,
+ IS32FL3207_REG_PWM_LOW(subleds[i].channel),
+ subleds[i].brightness);
+ if (ret)
+ return ret;
+ }
+
+ return regmap_write(chip->regmap, IS32FL3207_REG_PWM_UPDATE, 0);
+}
+
+static int is32fl3207_brightness_set(struct led_classdev *cdev,
+ enum led_brightness brightness)
+{
+ struct is32fl3207_led *led = container_of(cdev, struct is32fl3207_led,
+ cdev);
+ struct mc_subled subled = {
+ .brightness = brightness,
+ .channel = led->channel,
+ };
+
+ return is32fl3207_write_channels(led->chip, &subled, 1);
+}
+
+static int is32fl3207_mc_brightness_set(struct led_classdev *cdev,
+ enum led_brightness brightness)
+{
+ struct led_classdev_mc *mcdev = lcdev_to_mccdev(cdev);
+ struct is32fl3207_led *led = container_of(mcdev, struct is32fl3207_led,
+ mcdev);
+
+ led_mc_calc_color_components(mcdev, brightness);
+
+ return is32fl3207_write_channels(led->chip, mcdev->subled_info,
+ mcdev->num_colors);
+}
+
+static int is32fl3207_configure_channel(struct is32fl3207 *chip,
+ struct fwnode_handle *fwnode,
+ unsigned int *channel)
+{
+ u64 scaling;
+ u32 max_microamp;
+ u32 reg;
+ int ret;
+
+ ret = fwnode_property_read_u32(fwnode, "reg", ®);
+ if (ret)
+ return dev_err_probe(chip->dev, ret,
+ "failed to read channel for %pfw\n", fwnode);
+
+ if (reg >= IS32FL3207_NUM_CHANNELS)
+ return dev_err_probe(chip->dev, -EINVAL,
+ "channel %u is out of range\n", reg);
+
+ if (test_bit(reg, chip->channels))
+ return dev_err_probe(chip->dev, -EINVAL,
+ "channel %u is used more than once\n", reg);
+
+ ret = fwnode_property_read_u32(fwnode, "led-max-microamp",
+ &max_microamp);
+ if (ret)
+ return dev_err_probe(chip->dev, ret,
+ "failed to read current limit for channel %u\n",
+ reg);
+
+ if (!max_microamp || max_microamp > chip->output_max_microamp)
+ return dev_err_probe(chip->dev, -EINVAL,
+ "invalid current limit %u uA for channel %u\n",
+ max_microamp, reg);
+
+ /* GCC is fixed at 0xff, so use each output's scaling register. */
+ scaling = div_u64((u64)max_microamp * 256 * 256,
+ (u64)chip->output_max_microamp *
+ IS32FL3207_GLOBAL_CURRENT_MAX);
+ if (!scaling)
+ return dev_err_probe(chip->dev, -EINVAL,
+ "current limit %u uA is below channel %u resolution\n",
+ max_microamp, reg);
+
+ scaling = min_t(u64, scaling, 0xff);
+ ret = regmap_write(chip->regmap, IS32FL3207_REG_SCALING(reg),
+ (unsigned int)scaling);
+ if (ret)
+ return ret;
+
+ set_bit(reg, chip->channels);
+ *channel = reg;
+
+ return 0;
+}
+
+static int is32fl3207_register_single(struct is32fl3207 *chip,
+ struct fwnode_handle *fwnode,
+ struct is32fl3207_led *led)
+{
+ struct led_init_data init_data = {
+ .devicename = dev_name(chip->dev),
+ .devname_mandatory = true,
+ .fwnode = fwnode,
+ };
+ unsigned int max_brightness;
+ unsigned int brightness;
+ u32 color;
+ int ret;
+
+ ret = is32fl3207_parse_led_properties(chip, fwnode,
+ &max_brightness, &brightness);
+ if (ret)
+ return ret;
+
+ if (fwnode_property_present(fwnode, "color")) {
+ ret = fwnode_property_read_u32(fwnode, "color", &color);
+ if (ret)
+ return dev_err_probe(chip->dev, ret,
+ "failed to read color for %pfw\n",
+ fwnode);
+ if (color >= LED_COLOR_ID_MAX || color == LED_COLOR_ID_MULTI ||
+ color == LED_COLOR_ID_RGB)
+ return dev_err_probe(chip->dev, -EINVAL,
+ "invalid single LED color %u\n", color);
+ }
+
+ ret = is32fl3207_configure_channel(chip, fwnode, &led->channel);
+ if (ret)
+ return ret;
+ led->chip = chip;
+ led->led_cdev = &led->cdev;
+ led->cdev.brightness = brightness;
+ led->cdev.max_brightness = max_brightness;
+ led->cdev.brightness_set_blocking = is32fl3207_brightness_set;
+
+ ret = is32fl3207_brightness_set(&led->cdev, brightness);
+ if (ret)
+ return ret;
+
+ return devm_led_classdev_register_ext(chip->dev, &led->cdev, &init_data);
+}
+
+static int is32fl3207_register_multicolor(struct is32fl3207 *chip,
+ struct fwnode_handle *fwnode,
+ struct is32fl3207_led *led)
+{
+ struct led_init_data init_data = {
+ .devicename = dev_name(chip->dev),
+ .devname_mandatory = true,
+ .fwnode = fwnode,
+ };
+ struct mc_subled *subleds;
+ DECLARE_BITMAP(color_map, LED_COLOR_ID_MAX);
+ unsigned int max_brightness;
+ unsigned int brightness;
+ unsigned int count;
+ unsigned int i = 0;
+ u32 group_color;
+ u32 group_reg;
+ unsigned int first_channel = IS32FL3207_NUM_CHANNELS;
+ int ret;
+
+ ret = is32fl3207_parse_led_properties(chip, fwnode,
+ &max_brightness, &brightness);
+ if (ret)
+ return ret;
+
+ ret = fwnode_property_read_u32(fwnode, "color", &group_color);
+ if (ret)
+ return dev_err_probe(chip->dev, ret,
+ "failed to read color for %pfw\n", fwnode);
+
+ if (group_color != LED_COLOR_ID_RGB &&
+ group_color != LED_COLOR_ID_MULTI)
+ return dev_err_probe(chip->dev, -EINVAL,
+ "invalid multicolor LED color %u\n", group_color);
+
+ ret = fwnode_property_read_u32(fwnode, "reg", &group_reg);
+ if (ret)
+ return dev_err_probe(chip->dev, ret,
+ "failed to read group index for %pfw\n", fwnode);
+
+ count = fwnode_get_child_node_count(fwnode);
+ if (!count || count > LED_COLOR_ID_MAX)
+ return dev_err_probe(chip->dev, -EINVAL,
+ "invalid component count %u for %pfw\n",
+ count, fwnode);
+
+ subleds = devm_kcalloc(chip->dev, count, sizeof(*subleds), GFP_KERNEL);
+ if (!subleds)
+ return -ENOMEM;
+ bitmap_zero(color_map, LED_COLOR_ID_MAX);
+
+ fwnode_for_each_child_node_scoped(fwnode, child) {
+ u32 color;
+
+ ret = is32fl3207_validate_component(chip, child);
+ if (ret)
+ return ret;
+
+ ret = fwnode_property_read_u32(child, "color", &color);
+ if (ret)
+ return dev_err_probe(chip->dev, ret,
+ "failed to read color for %pfw\n",
+ child);
+
+ if (color >= LED_COLOR_ID_MAX || color == LED_COLOR_ID_MULTI ||
+ color == LED_COLOR_ID_RGB)
+ return dev_err_probe(chip->dev, -EINVAL,
+ "invalid component color %u\n", color);
+ if (test_and_set_bit(color, color_map))
+ return dev_err_probe(chip->dev, -EINVAL,
+ "component color %u is used more than once\n",
+ color);
+
+ ret = is32fl3207_configure_channel(chip, child,
+ &subleds[i].channel);
+ if (ret)
+ return ret;
+
+ subleds[i].color_index = color;
+ subleds[i].intensity = max_brightness;
+ subleds[i].max_intensity = 0;
+ first_channel = min(first_channel, subleds[i].channel);
+ i++;
+ }
+
+ if (group_reg != first_channel)
+ return dev_err_probe(chip->dev, -EINVAL,
+ "group index %u does not match first channel %u\n",
+ group_reg, first_channel);
+
+ led->chip = chip;
+ led->led_cdev = &led->mcdev.led_cdev;
+ led->mcdev.num_colors = count;
+ led->mcdev.subled_info = subleds;
+ led->mcdev.led_cdev.brightness = brightness;
+ led->mcdev.led_cdev.max_brightness = max_brightness;
+ led->mcdev.led_cdev.brightness_set_blocking =
+ is32fl3207_mc_brightness_set;
+
+ led_mc_calc_color_components(&led->mcdev, brightness);
+
+ ret = is32fl3207_write_channels(chip, subleds, count);
+ if (ret)
+ return ret;
+
+ return devm_led_classdev_multicolor_register_ext(chip->dev, &led->mcdev,
+ &init_data);
+}
+
+static int is32fl3207_hw_init(struct is32fl3207 *chip)
+{
+ u8 scaling[IS32FL3207_NUM_CHANNELS];
+ u8 pwm[2 * IS32FL3207_NUM_CHANNELS] = { };
+ int ret;
+
+ ret = regmap_write(chip->regmap, IS32FL3207_REG_CONTROL,
+ IS32FL3207_CONTROL_ENABLE);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(chip->regmap, IS32FL3207_REG_RESET, 0);
+ if (ret)
+ return ret;
+ usleep_range(200, 300);
+
+ ret = regmap_write(chip->regmap, IS32FL3207_REG_CONTROL,
+ IS32FL3207_CONTROL_ENABLE);
+ if (ret)
+ return ret;
+
+ ret = regmap_write(chip->regmap, IS32FL3207_REG_GLOBAL_CURRENT,
+ IS32FL3207_GLOBAL_CURRENT_MAX);
+ if (ret)
+ return ret;
+
+ memset(scaling, 0xff, sizeof(scaling));
+ ret = regmap_bulk_write(chip->regmap, IS32FL3207_REG_SCALING(0),
+ scaling, sizeof(scaling));
+ if (ret)
+ return ret;
+
+ ret = regmap_bulk_write(chip->regmap, IS32FL3207_REG_PWM_LOW(0), pwm,
+ sizeof(pwm));
+ if (ret)
+ return ret;
+
+ return regmap_write(chip->regmap, IS32FL3207_REG_PWM_UPDATE, 0);
+}
+
+static void is32fl3207_disable(void *data)
+{
+ struct is32fl3207 *chip = data;
+
+ guard(mutex)(&chip->lock);
+ regmap_write(chip->regmap, IS32FL3207_REG_CONTROL, 0);
+ if (chip->enable_gpio)
+ gpiod_set_value_cansleep(chip->enable_gpio, 0);
+}
+
+static const struct regmap_config is32fl3207_regmap_config = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = IS32FL3207_REG_RESET,
+};
+
+static int is32fl3207_probe(struct i2c_client *client)
+{
+ struct device *dev = &client->dev;
+ struct is32fl3207 *chip;
+ unsigned int count;
+ unsigned int i = 0;
+ u32 riset_ohms;
+ int ret;
+
+ count = device_get_child_node_count(dev);
+ if (!count || count > IS32FL3207_NUM_CHANNELS)
+ return dev_err_probe(dev, -EINVAL,
+ "invalid LED count %u\n", count);
+
+ chip = devm_kzalloc(dev, struct_size(chip, leds, count), GFP_KERNEL);
+ if (!chip)
+ return -ENOMEM;
+
+ chip->dev = dev;
+ chip->num_leds = count;
+ i2c_set_clientdata(client, chip);
+
+ ret = device_property_read_u32(dev, "issi,riset-ohms", &riset_ohms);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to read RISET value\n");
+
+ if (riset_ohms < 2000)
+ return dev_err_probe(dev, -EINVAL,
+ "RISET value %u is below 2000 ohms\n",
+ riset_ohms);
+
+ chip->output_max_microamp = div_u64(IS32FL3207_CURRENT_NUMERATOR,
+ riset_ohms);
+ if (!chip->output_max_microamp)
+ return dev_err_probe(dev, -EINVAL,
+ "RISET value %u is too large\n", riset_ohms);
+
+ ret = devm_regulator_get_enable_optional(dev, "vcc");
+ if (ret && ret != -ENODEV)
+ return dev_err_probe(dev, ret, "failed to enable VCC regulator\n");
+
+ chip->enable_gpio = devm_gpiod_get_optional(dev, "enable",
+ GPIOD_OUT_HIGH);
+ if (IS_ERR(chip->enable_gpio))
+ return dev_err_probe(dev, PTR_ERR(chip->enable_gpio),
+ "failed to get enable GPIO\n");
+
+ if (chip->enable_gpio)
+ usleep_range(1000, 2000);
+
+ chip->regmap = devm_regmap_init_i2c(client, &is32fl3207_regmap_config);
+ if (IS_ERR(chip->regmap))
+ return dev_err_probe(dev, PTR_ERR(chip->regmap),
+ "failed to allocate register map\n");
+
+ ret = devm_mutex_init(dev, &chip->lock);
+ if (ret)
+ return ret;
+
+ ret = devm_add_action_or_reset(dev, is32fl3207_disable, chip);
+ if (ret)
+ return ret;
+
+ ret = is32fl3207_hw_init(chip);
+ if (ret)
+ return dev_err_probe(dev, ret, "failed to initialize controller\n");
+
+ device_for_each_child_node_scoped(dev, child) {
+ struct is32fl3207_led *led = &chip->leds[i];
+
+ if (fwnode_get_child_node_count(child))
+ ret = is32fl3207_register_multicolor(chip, child, led);
+ else
+ ret = is32fl3207_register_single(chip, child, led);
+ if (ret)
+ return ret;
+
+ i++;
+ }
+
+ return 0;
+}
+
+static void is32fl3207_shutdown(struct i2c_client *client)
+{
+ struct is32fl3207 *chip = i2c_get_clientdata(client);
+ bool retain_state = false;
+ unsigned int i;
+
+ for (i = 0; i < chip->num_leds; i++)
+ if (chip->leds[i].led_cdev->flags & LED_RETAIN_AT_SHUTDOWN) {
+ retain_state = true;
+ break;
+ }
+
+ if (!retain_state) {
+ is32fl3207_disable(chip);
+ return;
+ }
+
+ for (i = 0; i < chip->num_leds; i++) {
+ struct led_classdev *cdev = chip->leds[i].led_cdev;
+
+ if (cdev->flags & LED_RETAIN_AT_SHUTDOWN)
+ continue;
+ if (cdev->flags & LED_MULTI_COLOR)
+ is32fl3207_mc_brightness_set(cdev, LED_OFF);
+ else
+ is32fl3207_brightness_set(cdev, LED_OFF);
+ }
+}
+
+static const struct of_device_id is32fl3207_of_match[] = {
+ { .compatible = "issi,is32fl3207" },
+ { }
+};
+MODULE_DEVICE_TABLE(of, is32fl3207_of_match);
+
+static const struct i2c_device_id is32fl3207_id[] = {
+ { .name = "is32fl3207" },
+ { }
+};
+MODULE_DEVICE_TABLE(i2c, is32fl3207_id);
+
+static struct i2c_driver is32fl3207_driver = {
+ .driver = {
+ .name = "is32fl3207",
+ .of_match_table = is32fl3207_of_match,
+ },
+ .probe = is32fl3207_probe,
+ .shutdown = is32fl3207_shutdown,
+ .id_table = is32fl3207_id,
+};
+module_i2c_driver(is32fl3207_driver);
+
+MODULE_AUTHOR("Ahmad Byagowi <ahmadexp@gmail.com>");
+MODULE_DESCRIPTION("Lumissil IS32FL3207 LED controller driver");
+MODULE_LICENSE("GPL");
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [RFC net-next v2 3/6] i2c: mux: Propagate software nodes to channel adapters
2026-08-03 20:50 [RFC net-next v2 0/6] ptp: ocp: Add R4006 and V9 I2C peripheral support Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 1/6] dt-bindings: leds: Add IS32FL3207 controller Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 2/6] leds: rgb: Add IS32FL3207 controller driver Ahmad Byagowi
@ 2026-08-03 20:50 ` Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 4/6] ptp: ocp: Validate EEPROM board IDs Ahmad Byagowi
` (2 subsequent siblings)
5 siblings, 0 replies; 8+ messages in thread
From: Ahmad Byagowi @ 2026-08-03 20:50 UTC (permalink / raw)
To: linux-leds, devicetree, linux-i2c, netdev
Cc: Lee Jones, Pavel Machek, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Andi Shyti, Peter Rosin, Nam Tran, Vadim Fedorenko,
Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Kees Cook, Gustavo A. R. Silva,
linux-hardening, linux-kernel
Device Tree channel nodes are associated with the adapters created by
i2c-mux, but equivalent software-node descriptions are not.
Find the software-node child whose reg value matches the channel and
assign it to the new adapter. Keep a reference for the adapter lifetime
so downstream clients can find the channel by firmware node.
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
drivers/i2c/i2c-mux.c | 55 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 55 insertions(+)
diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
index 681a201c2..1e587ea4e 100644
--- a/drivers/i2c/i2c-mux.c
+++ b/drivers/i2c/i2c-mux.c
@@ -25,6 +25,7 @@
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of.h>
+#include <linux/property.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
@@ -264,6 +265,49 @@ static const struct i2c_lock_operations i2c_parent_lock_ops = {
.unlock_bus = i2c_parent_unlock_bus,
};
+static struct fwnode_handle *
+i2c_mux_get_channel_swnode(struct i2c_mux_core *muxc, u32 chan_id)
+{
+ struct fwnode_handle *dev_node = dev_fwnode(muxc->dev);
+ struct fwnode_handle *mux_node, *child = NULL;
+ u32 reg;
+
+ if (!is_software_node(dev_node))
+ return NULL;
+
+ if (muxc->arbitrator)
+ mux_node = fwnode_get_named_child_node(dev_node, "i2c-arb");
+ else if (muxc->gate)
+ mux_node = fwnode_get_named_child_node(dev_node, "i2c-gate");
+ else
+ mux_node = fwnode_get_named_child_node(dev_node, "i2c-mux");
+
+ if (mux_node) {
+ /* A "reg" property indicates an old-style firmware entry. */
+ if (!fwnode_property_read_u32(mux_node, "reg", ®)) {
+ fwnode_handle_put(mux_node);
+ mux_node = NULL;
+ }
+ }
+
+ if (!mux_node)
+ mux_node = fwnode_handle_get(dev_node);
+ else if (muxc->arbitrator || muxc->gate)
+ child = fwnode_handle_get(mux_node);
+
+ if (!child) {
+ fwnode_for_each_child_node(mux_node, child) {
+ if (fwnode_property_read_u32(child, "reg", ®))
+ continue;
+ if (chan_id == reg)
+ break;
+ }
+ }
+
+ fwnode_handle_put(mux_node);
+ return child;
+}
+
int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
u32 force_nr, u32 chan_id)
{
@@ -364,6 +408,12 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
priv->adap.dev.of_node = child;
of_node_put(mux_node);
+ } else {
+ struct fwnode_handle *fwnode;
+
+ fwnode = i2c_mux_get_channel_swnode(muxc, chan_id);
+ if (fwnode)
+ device_set_node(&priv->adap.dev, fwnode);
}
/*
@@ -408,6 +458,8 @@ int i2c_mux_add_adapter(struct i2c_mux_core *muxc,
return 0;
err_free_priv:
+ if (is_software_node(dev_fwnode(&priv->adap.dev)))
+ fwnode_handle_put(dev_fwnode(&priv->adap.dev));
kfree(priv);
return ret;
}
@@ -420,6 +472,7 @@ void i2c_mux_del_adapters(struct i2c_mux_core *muxc)
while (muxc->num_adapters) {
struct i2c_adapter *adap = muxc->adapter[--muxc->num_adapters];
struct i2c_mux_priv *priv = adap->algo_data;
+ struct fwnode_handle *fwnode = dev_fwnode(&adap->dev);
struct device_node *np = adap->dev.of_node;
muxc->adapter[muxc->num_adapters] = NULL;
@@ -430,6 +483,8 @@ void i2c_mux_del_adapters(struct i2c_mux_core *muxc)
sysfs_remove_link(&priv->adap.dev.kobj, "mux_device");
i2c_del_adapter(adap);
+ if (is_software_node(fwnode))
+ fwnode_handle_put(fwnode);
of_node_put(np);
kfree(priv);
}
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [RFC net-next v2 4/6] ptp: ocp: Validate EEPROM board IDs
2026-08-03 20:50 [RFC net-next v2 0/6] ptp: ocp: Add R4006 and V9 I2C peripheral support Ahmad Byagowi
` (2 preceding siblings ...)
2026-08-03 20:50 ` [RFC net-next v2 3/6] i2c: mux: Propagate software nodes to channel adapters Ahmad Byagowi
@ 2026-08-03 20:50 ` Ahmad Byagowi
2026-08-04 13:55 ` Vadim Fedorenko
2026-08-03 20:50 ` [RFC net-next v2 5/6] ptp: ocp: Add R4006 I2C peripheral topology Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 6/6] ptp: ocp: Add Time Card V9 " Ahmad Byagowi
5 siblings, 1 reply; 8+ messages in thread
From: Ahmad Byagowi @ 2026-08-03 20:50 UTC (permalink / raw)
To: linux-leds, devicetree, linux-i2c, netdev
Cc: Lee Jones, Pavel Machek, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Andi Shyti, Peter Rosin, Nam Tran, Vadim Fedorenko,
Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Kees Cook, Gustavo A. R. Silva,
linux-hardening, linux-kernel, stable
The EEPROM board ID is a fixed 13-byte field. It is stored without room
for a terminator and passed to devlink as a C string. An erased EEPROM
therefore exposes 0xff bytes and can make devlink read beyond the field
while formatting board.id.
Reserve a trailing byte, classify erased and malformed contents, and
publish board.id only when the field contains printable text with valid
padding. Continue reporting the serial number when the board ID is
absent.
Fixes: 0cfcdd1ebcfe1a9b262f6ad8419580720dc843c4 ("ptp: ocp: add nvmem interface for accessing eeprom")
Cc: stable@vger.kernel.org
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
drivers/ptp/ptp_ocp.c | 69 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 66 insertions(+), 3 deletions(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 35e911f1a..cec936bd1 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -347,6 +347,13 @@ struct ptp_ocp_serial_port {
#define OCP_SIGNAL_NUM 4
#define OCP_FREQ_NUM 4
+enum ptp_ocp_board_id_state {
+ OCP_BOARD_ID_UNREAD,
+ OCP_BOARD_ID_VALID,
+ OCP_BOARD_ID_ERASED,
+ OCP_BOARD_ID_INVALID,
+};
+
enum {
PORT_GNSS,
PORT_GNSS2,
@@ -401,8 +408,9 @@ struct ptp_ocp {
bool fw_loader;
u8 fw_tag;
u16 fw_version;
- u8 board_id[OCP_BOARD_ID_LEN];
+ char board_id[OCP_BOARD_ID_LEN + 1];
u8 serial[OCP_SERIAL_LEN];
+ enum ptp_ocp_board_id_state board_id_state;
bool has_eeprom_data;
u32 pps_req_map;
int flash_start;
@@ -472,18 +480,23 @@ struct ptp_ocp_eeprom_map {
.len = sizeof_field(struct ptp_ocp, member), \
.bp_offset = offsetof(struct ptp_ocp, member)
+#define EEPROM_ENTRY_LEN(addr, member, entry_len) \
+ .off = addr, \
+ .len = entry_len, \
+ .bp_offset = offsetof(struct ptp_ocp, member)
+
#define BP_MAP_ENTRY_ADDR(bp, map) ({ \
(void *)((uintptr_t)(bp) + (map)->bp_offset); \
})
static struct ptp_ocp_eeprom_map fb_eeprom_map[] = {
- { EEPROM_ENTRY(0x43, board_id) },
+ { EEPROM_ENTRY_LEN(0x43, board_id, OCP_BOARD_ID_LEN) },
{ EEPROM_ENTRY(0x00, serial), .tag = "mac" },
{ }
};
static struct ptp_ocp_eeprom_map art_eeprom_map[] = {
- { EEPROM_ENTRY(0x200 + 0x43, board_id) },
+ { EEPROM_ENTRY_LEN(0x200 + 0x43, board_id, OCP_BOARD_ID_LEN) },
{ EEPROM_ENTRY(0x200 + 0x63, serial) },
{ }
};
@@ -1969,6 +1982,52 @@ ptp_ocp_nvmem_device_put(struct nvmem_device **nvmemp)
*nvmemp = NULL;
}
+static enum ptp_ocp_board_id_state
+ptp_ocp_classify_board_id(char *board_id)
+{
+ bool all_zero = true;
+ bool all_ones = true;
+ bool terminated = false;
+ unsigned int i;
+
+ board_id[OCP_BOARD_ID_LEN] = '\0';
+ for (i = 0; i < OCP_BOARD_ID_LEN; i++) {
+ u8 value = board_id[i];
+
+ all_zero &= value == 0;
+ all_ones &= value == 0xff;
+ }
+
+ if (all_zero || all_ones) {
+ board_id[0] = '\0';
+ return OCP_BOARD_ID_ERASED;
+ }
+
+ for (i = 0; i < OCP_BOARD_ID_LEN; i++) {
+ u8 value = board_id[i];
+
+ if (terminated) {
+ if (value)
+ goto invalid;
+ continue;
+ }
+
+ if (!value) {
+ terminated = true;
+ continue;
+ }
+ if (value < 0x20 || value > 0x7e)
+ goto invalid;
+ }
+
+ if (board_id[0])
+ return OCP_BOARD_ID_VALID;
+
+invalid:
+ board_id[0] = '\0';
+ return OCP_BOARD_ID_INVALID;
+}
+
static void
ptp_ocp_read_eeprom(struct ptp_ocp *bp)
{
@@ -2001,6 +2060,7 @@ ptp_ocp_read_eeprom(struct ptp_ocp *bp)
goto fail;
}
+ bp->board_id_state = ptp_ocp_classify_board_id(bp->board_id);
bp->has_eeprom_data = true;
out:
@@ -2177,6 +2237,9 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
if (err)
return err;
+ if (bp->board_id_state != OCP_BOARD_ID_VALID)
+ return 0;
+
err = devlink_info_version_fixed_put(req,
DEVLINK_INFO_VERSION_GENERIC_BOARD_ID,
bp->board_id);
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [RFC net-next v2 5/6] ptp: ocp: Add R4006 I2C peripheral topology
2026-08-03 20:50 [RFC net-next v2 0/6] ptp: ocp: Add R4006 and V9 I2C peripheral support Ahmad Byagowi
` (3 preceding siblings ...)
2026-08-03 20:50 ` [RFC net-next v2 4/6] ptp: ocp: Validate EEPROM board IDs Ahmad Byagowi
@ 2026-08-03 20:50 ` Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 6/6] ptp: ocp: Add Time Card V9 " Ahmad Byagowi
5 siblings, 0 replies; 8+ messages in thread
From: Ahmad Byagowi @ 2026-08-03 20:50 UTC (permalink / raw)
To: linux-leds, devicetree, linux-i2c, netdev
Cc: Lee Jones, Pavel Machek, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Andi Shyti, Peter Rosin, Nam Tran, Vadim Fedorenko,
Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Kees Cook, Gustavo A. R. Silva,
linux-hardening, linux-kernel
R4006 cards place a PCA9546 mux behind the FPGA I2C controller. The mux
exposes three LM75B temperature sensors, an SHT3x humidity sensor, an
ICP10100 pressure sensor, and an IS32FL3207 controller for the GNSS and
SMA LEDs.
Describe the per-card topology with software nodes and instantiate
standard I2C clients after their adapters appear. Use a reusable board
profile selected only when the validated EEPROM ID begins with "R4006".
PCI IDs are shared by multiple PCB revisions and cannot safely select
LED wiring.
Leave the channel containing the BNO08x empty because no upstream driver
exists. Retry asynchronous population with a bounded budget. Serialize
population against controller and mux driver bind/unbind, remove the mux
when the root adapter disappears, and support adapter reappearance. Limit
the existing i2c sysfs link to the root adapter.
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
drivers/ptp/ptp_ocp.c | 736 +++++++++++++++++++++++++++++++++++++++---
1 file changed, 693 insertions(+), 43 deletions(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index cec936bd1..70ba47096 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -21,10 +21,14 @@
#include <net/devlink.h>
#include <linux/i2c.h>
#include <linux/mtd/mtd.h>
+#include <linux/mutex.h>
#include <linux/nvmem-consumer.h>
+#include <linux/property.h>
#include <linux/crc16.h>
#include <linux/dpll.h>
+#include <dt-bindings/leds/common.h>
+
#define PCI_DEVICE_ID_META_TIMECARD 0x0400
#define PCI_VENDOR_ID_CELESTICA 0x18d4
@@ -347,6 +351,17 @@ struct ptp_ocp_serial_port {
#define OCP_SIGNAL_NUM 4
#define OCP_FREQ_NUM 4
+#define OCP_I2C_MUX_CHANNELS 4
+#define OCP_I2C_MAX_SENSOR_COUNT 5
+#define OCP_I2C_MAX_LED_COUNT 5
+#define OCP_I2C_MAX_LED_COMPONENT_COUNT (3 * OCP_I2C_MAX_LED_COUNT)
+#define OCP_I2C_MUX_NAME_LEN 32
+#define OCP_I2C_RETRY_MAX 10
+#define OCP_I2C_MAX_NODE_COUNT (1 + OCP_I2C_MUX_CHANNELS + \
+ OCP_I2C_MAX_SENSOR_COUNT + 1 + \
+ OCP_I2C_MAX_LED_COUNT + \
+ OCP_I2C_MAX_LED_COMPONENT_COUNT)
+
enum ptp_ocp_board_id_state {
OCP_BOARD_ID_UNREAD,
OCP_BOARD_ID_VALID,
@@ -354,6 +369,51 @@ enum ptp_ocp_board_id_state {
OCP_BOARD_ID_INVALID,
};
+struct ptp_ocp_i2c_device {
+ const char *node_name;
+ const char *compatible;
+ const char *type;
+ u8 channel;
+ u8 address;
+};
+
+struct ptp_ocp_led {
+ const char *node_name;
+ const char *function;
+ u8 function_enumerator;
+ bool has_function_enumerator;
+ u8 channel[3];
+};
+
+struct ptp_ocp_i2c_profile {
+ const char *name;
+ const struct ptp_ocp_i2c_device *sensors;
+ unsigned int sensor_count;
+ const struct ptp_ocp_led *leds;
+ unsigned int led_count;
+ const char *led_node_name;
+ u8 led_address;
+};
+
+struct ptp_ocp_i2c_topology {
+ char mux_name[OCP_I2C_MUX_NAME_LEN];
+ struct software_node mux_node;
+ struct property_entry mux_props[6];
+ struct software_node channel_nodes[OCP_I2C_MUX_CHANNELS];
+ struct property_entry channel_props[OCP_I2C_MUX_CHANNELS][4];
+ struct software_node sensor_nodes[OCP_I2C_MAX_SENSOR_COUNT];
+ struct property_entry sensor_props[OCP_I2C_MAX_SENSOR_COUNT][3];
+ struct software_node led_node;
+ struct property_entry led_props[6];
+ struct software_node led_nodes[OCP_I2C_MAX_LED_COUNT];
+ struct property_entry led_group_props[OCP_I2C_MAX_LED_COUNT][7];
+ struct software_node component_nodes[OCP_I2C_MAX_LED_COMPONENT_COUNT];
+ struct property_entry component_props[OCP_I2C_MAX_LED_COMPONENT_COUNT][4];
+ const struct software_node *node_group[OCP_I2C_MAX_NODE_COUNT + 1];
+ const struct ptp_ocp_i2c_profile *profile;
+ bool registered;
+};
+
enum {
PORT_GNSS,
PORT_GNSS2,
@@ -410,6 +470,7 @@ struct ptp_ocp {
u16 fw_version;
char board_id[OCP_BOARD_ID_LEN + 1];
u8 serial[OCP_SERIAL_LEN];
+ struct mutex eeprom_lock; /* Serializes EEPROM discovery. */
enum ptp_ocp_board_id_state board_id_state;
bool has_eeprom_data;
u32 pps_req_map;
@@ -422,6 +483,14 @@ struct ptp_ocp {
const struct ocp_sma_op *sma_op;
struct dpll_device *dpll;
dpll_tracker tracker;
+ const struct ptp_ocp_i2c_profile *i2c_profile;
+ struct ptp_ocp_i2c_topology *i2c_topology;
+ struct delayed_work i2c_work;
+ struct notifier_block i2c_notifier;
+ atomic_t i2c_retry_count;
+ bool i2c_root_present;
+ bool i2c_resources_ready;
+ bool i2c_notifier_registered;
int signals_nr;
int freq_in_nr;
};
@@ -452,6 +521,8 @@ static int ptp_ocp_signal_from_perout(struct ptp_ocp *bp, int gen,
struct ptp_perout_request *req);
static int ptp_ocp_signal_enable(void *priv, u32 req, bool enable);
static int ptp_ocp_sma_store(struct ptp_ocp *bp, const char *buf, int sma_nr);
+static int ptp_ocp_i2c_notifier_call(struct notifier_block *nb,
+ unsigned long action, void *data);
static int ptp_ocp_art_board_init(struct ptp_ocp *bp, struct ocp_resource *r);
@@ -501,6 +572,65 @@ static struct ptp_ocp_eeprom_map art_eeprom_map[] = {
{ }
};
+/* Channel 3's BNO08x at 0x4a has no upstream Linux driver, so omit it. */
+static const struct ptp_ocp_i2c_device ptp_ocp_r4006_sensors[] = {
+ { "temperature@48", "national,lm75b", "lm75b", 0, 0x48 },
+ { "temperature@49", "national,lm75b", "lm75b", 0, 0x49 },
+ { "temperature@4a", "national,lm75b", "lm75b", 0, 0x4a },
+ { "humidity@44", "sensirion,sht3x", "sht3x", 1, 0x44 },
+ { "pressure@63", "invensense,icp10100", "icp10100", 2, 0x63 },
+};
+
+static const struct ptp_ocp_led ptp_ocp_r4006_leds[] = {
+ {
+ .node_name = "multi-led@c",
+ .function = LED_FUNCTION_STATUS,
+ .channel = { 13, 12, 14 },
+ },
+ {
+ .node_name = "multi-led@6",
+ .function = LED_FUNCTION_INDICATOR,
+ .function_enumerator = 1,
+ .has_function_enumerator = true,
+ .channel = { 7, 6, 8 },
+ },
+ {
+ .node_name = "multi-led@9",
+ .function = LED_FUNCTION_INDICATOR,
+ .function_enumerator = 2,
+ .has_function_enumerator = true,
+ .channel = { 10, 9, 11 },
+ },
+ {
+ .node_name = "multi-led@0",
+ .function = LED_FUNCTION_INDICATOR,
+ .function_enumerator = 3,
+ .has_function_enumerator = true,
+ .channel = { 1, 0, 2 },
+ },
+ {
+ .node_name = "multi-led@3",
+ .function = LED_FUNCTION_INDICATOR,
+ .function_enumerator = 4,
+ .has_function_enumerator = true,
+ .channel = { 4, 3, 5 },
+ },
+};
+
+static_assert(ARRAY_SIZE(ptp_ocp_r4006_sensors) <=
+ OCP_I2C_MAX_SENSOR_COUNT);
+static_assert(ARRAY_SIZE(ptp_ocp_r4006_leds) <= OCP_I2C_MAX_LED_COUNT);
+
+static const struct ptp_ocp_i2c_profile ptp_ocp_r4006_profile = {
+ .name = "r4006",
+ .sensors = ptp_ocp_r4006_sensors,
+ .sensor_count = ARRAY_SIZE(ptp_ocp_r4006_sensors),
+ .leds = ptp_ocp_r4006_leds,
+ .led_count = ARRAY_SIZE(ptp_ocp_r4006_leds),
+ .led_node_name = "led-controller@34",
+ .led_address = 0x34,
+};
+
#define bp_assign_entry(bp, res, val) ({ \
uintptr_t addr = (uintptr_t)(bp) + (res)->bp_offset; \
*(typeof(val) *)addr = val; \
@@ -1961,8 +2091,8 @@ ptp_ocp_nvmem_match(struct device *dev, const void *data)
return 0;
while ((dev = dev->parent))
- if (dev->driver && !strcmp(dev->driver->name, KBUILD_MODNAME))
- return info->bp == dev_get_drvdata(dev);
+ if (dev == &info->bp->pdev->dev)
+ return 1;
return 0;
}
@@ -1982,6 +2112,12 @@ ptp_ocp_nvmem_device_put(struct nvmem_device **nvmemp)
*nvmemp = NULL;
}
+static bool
+ptp_ocp_has_eeprom_data(struct ptp_ocp *bp)
+{
+ return smp_load_acquire(&bp->has_eeprom_data);
+}
+
static enum ptp_ocp_board_id_state
ptp_ocp_classify_board_id(char *board_id)
{
@@ -2036,11 +2172,11 @@ ptp_ocp_read_eeprom(struct ptp_ocp *bp)
const void *tag;
int ret;
- if (!bp->i2c_ctrl)
- return;
-
tag = NULL;
nvmem = NULL;
+ mutex_lock(&bp->eeprom_lock);
+ if (!bp->i2c_ctrl || ptp_ocp_has_eeprom_data(bp))
+ goto out;
for (map = bp->eeprom_map; map->len; map++) {
if (map->tag != tag) {
@@ -2061,10 +2197,13 @@ ptp_ocp_read_eeprom(struct ptp_ocp *bp)
}
bp->board_id_state = ptp_ocp_classify_board_id(bp->board_id);
- bp->has_eeprom_data = true;
+
+ /* Publish the EEPROM fields before readers observe valid data. */
+ smp_store_release(&bp->has_eeprom_data, true);
out:
ptp_ocp_nvmem_device_put(&nvmem);
+ mutex_unlock(&bp->eeprom_lock);
return;
fail:
@@ -2072,6 +2211,467 @@ ptp_ocp_read_eeprom(struct ptp_ocp *bp)
goto out;
}
+static int
+ptp_ocp_i2c_adapter_match(struct device *dev, const void *data)
+{
+ return !!i2c_verify_adapter(dev);
+}
+
+static struct i2c_adapter *
+ptp_ocp_i2c_root_adapter(struct ptp_ocp *bp)
+{
+ struct i2c_adapter *adapter;
+ struct device *dev;
+
+ if (!bp->i2c_ctrl)
+ return NULL;
+
+ dev = device_find_child(&bp->i2c_ctrl->dev, NULL,
+ ptp_ocp_i2c_adapter_match);
+ if (!dev)
+ return NULL;
+
+ adapter = i2c_verify_adapter(dev);
+ if (!adapter || !try_module_get(adapter->owner)) {
+ put_device(dev);
+ return NULL;
+ }
+
+ /* The device reference from device_find_child() is owned by the caller. */
+ return adapter;
+}
+
+static const struct ptp_ocp_i2c_profile *
+ptp_ocp_i2c_select_profile(struct ptp_ocp *bp)
+{
+ /* PCI IDs identify FPGA images, not a unique PCB revision. */
+ if (!((bp->pdev->vendor == PCI_VENDOR_ID_META &&
+ bp->pdev->device == PCI_DEVICE_ID_META_TIMECARD) ||
+ (bp->pdev->vendor == PCI_VENDOR_ID_CELESTICA &&
+ bp->pdev->device == PCI_DEVICE_ID_CELESTICA_TIMECARD)))
+ return NULL;
+
+ if (!ptp_ocp_has_eeprom_data(bp))
+ return NULL;
+ if (bp->board_id_state != OCP_BOARD_ID_VALID)
+ return NULL;
+
+ if (!strncmp(bp->board_id, "R4006", 5))
+ return &ptp_ocp_r4006_profile;
+
+ return NULL;
+}
+
+static int
+ptp_ocp_i2c_init_nodes(struct ptp_ocp *bp)
+{
+ static const char * const channel_names[] = {
+ "i2c@0", "i2c@1", "i2c@2", "i2c@3",
+ };
+ static const char * const output_names[] = {
+ "led@0", "led@1", "led@2", "led@3", "led@4", "led@5",
+ "led@6", "led@7", "led@8", "led@9", "led@a", "led@b",
+ "led@c", "led@d", "led@e", "led@f", "led@10", "led@11",
+ };
+ static const u32 colors[] = {
+ LED_COLOR_ID_RED, LED_COLOR_ID_GREEN, LED_COLOR_ID_BLUE,
+ };
+ const struct ptp_ocp_i2c_profile *profile = bp->i2c_profile;
+ struct device *dev = &bp->pdev->dev;
+ struct ptp_ocp_i2c_topology *topology;
+ unsigned int component = 0;
+ unsigned int node = 0;
+ unsigned int expected_nodes;
+ unsigned int i, j, prop;
+ int ret;
+
+ if (!profile)
+ return -EINVAL;
+ if (bp->i2c_topology && bp->i2c_topology->registered)
+ return 0;
+ if (bp->i2c_topology) {
+ topology = bp->i2c_topology;
+ goto register_nodes;
+ }
+ if (WARN_ON(profile->sensor_count > OCP_I2C_MAX_SENSOR_COUNT ||
+ profile->led_count > OCP_I2C_MAX_LED_COUNT))
+ return -EINVAL;
+
+ topology = devm_kzalloc(dev, sizeof(*topology), GFP_KERNEL);
+ if (!topology)
+ return -ENOMEM;
+
+ topology->profile = profile;
+ snprintf(topology->mux_name, sizeof(topology->mux_name),
+ "ocp%d-%s-mux", bp->id, profile->name);
+ topology->mux_node.name = topology->mux_name;
+ topology->mux_node.properties = topology->mux_props;
+ topology->mux_props[0] =
+ PROPERTY_ENTRY_STRING("compatible", "nxp,pca9546");
+ topology->mux_props[1] = PROPERTY_ENTRY_U32("reg", 0x70);
+ topology->mux_props[2] =
+ PROPERTY_ENTRY_BOOL("i2c-mux-idle-disconnect");
+ topology->mux_props[3] = PROPERTY_ENTRY_U32("#address-cells", 1);
+ topology->mux_props[4] = PROPERTY_ENTRY_U32("#size-cells", 0);
+ topology->node_group[node++] = &topology->mux_node;
+
+ for (i = 0; i < OCP_I2C_MUX_CHANNELS; i++) {
+ topology->channel_nodes[i].name = channel_names[i];
+ topology->channel_nodes[i].parent = &topology->mux_node;
+ topology->channel_nodes[i].properties = topology->channel_props[i];
+ topology->channel_props[i][0] = PROPERTY_ENTRY_U32("reg", i);
+ topology->channel_props[i][1] =
+ PROPERTY_ENTRY_U32("#address-cells", 1);
+ topology->channel_props[i][2] =
+ PROPERTY_ENTRY_U32("#size-cells", 0);
+ topology->node_group[node++] = &topology->channel_nodes[i];
+ }
+
+ for (i = 0; i < profile->sensor_count; i++) {
+ const struct ptp_ocp_i2c_device *sensor;
+
+ sensor = &profile->sensors[i];
+ topology->sensor_nodes[i].name = sensor->node_name;
+ topology->sensor_nodes[i].parent =
+ &topology->channel_nodes[sensor->channel];
+ topology->sensor_nodes[i].properties = topology->sensor_props[i];
+ topology->sensor_props[i][0] =
+ PROPERTY_ENTRY_STRING("compatible", sensor->compatible);
+ topology->sensor_props[i][1] =
+ PROPERTY_ENTRY_U32("reg", sensor->address);
+ topology->node_group[node++] = &topology->sensor_nodes[i];
+ }
+
+ topology->led_node.name = profile->led_node_name;
+ topology->led_node.parent = &topology->channel_nodes[1];
+ topology->led_node.properties = topology->led_props;
+ topology->led_props[0] =
+ PROPERTY_ENTRY_STRING("compatible", "issi,is32fl3207");
+ topology->led_props[1] =
+ PROPERTY_ENTRY_U32("reg", profile->led_address);
+ topology->led_props[2] =
+ PROPERTY_ENTRY_U32("issi,riset-ohms", 4700);
+ topology->led_props[3] = PROPERTY_ENTRY_U32("#address-cells", 1);
+ topology->led_props[4] = PROPERTY_ENTRY_U32("#size-cells", 0);
+ topology->node_group[node++] = &topology->led_node;
+
+ for (i = 0; i < profile->led_count; i++) {
+ const struct ptp_ocp_led *led = &profile->leds[i];
+ u32 group_reg;
+
+ group_reg = min3(led->channel[0], led->channel[1],
+ led->channel[2]);
+ topology->led_nodes[i].name = led->node_name;
+ topology->led_nodes[i].parent = &topology->led_node;
+ topology->led_nodes[i].properties =
+ topology->led_group_props[i];
+ prop = 0;
+ topology->led_group_props[i][prop++] =
+ PROPERTY_ENTRY_U32("reg", group_reg);
+ topology->led_group_props[i][prop++] =
+ PROPERTY_ENTRY_U32("color", LED_COLOR_ID_RGB);
+ topology->led_group_props[i][prop++] =
+ PROPERTY_ENTRY_STRING("function", led->function);
+ if (led->has_function_enumerator)
+ topology->led_group_props[i][prop++] =
+ PROPERTY_ENTRY_U32("function-enumerator",
+ led->function_enumerator);
+ topology->led_group_props[i][prop++] =
+ PROPERTY_ENTRY_U32("#address-cells", 1);
+ topology->led_group_props[i][prop] =
+ PROPERTY_ENTRY_U32("#size-cells", 0);
+ topology->node_group[node++] = &topology->led_nodes[i];
+
+ for (j = 0; j < ARRAY_SIZE(led->channel); j++, component++) {
+ u8 channel = led->channel[j];
+
+ topology->component_nodes[component].name =
+ output_names[channel];
+ topology->component_nodes[component].parent =
+ &topology->led_nodes[i];
+ topology->component_nodes[component].properties =
+ topology->component_props[component];
+ topology->component_props[component][0] =
+ PROPERTY_ENTRY_U32("reg", channel);
+ topology->component_props[component][1] =
+ PROPERTY_ENTRY_U32("color", colors[j]);
+ topology->component_props[component][2] =
+ PROPERTY_ENTRY_U32("led-max-microamp", 8150);
+ topology->node_group[node++] =
+ &topology->component_nodes[component];
+ }
+ }
+
+ expected_nodes = 1 + OCP_I2C_MUX_CHANNELS + profile->sensor_count + 1 +
+ profile->led_count + 3 * profile->led_count;
+ if (WARN_ON(node != expected_nodes)) {
+ devm_kfree(dev, topology);
+ return -EINVAL;
+ }
+
+ bp->i2c_topology = topology;
+
+register_nodes:
+ ret = software_node_register_node_group(topology->node_group);
+ if (ret)
+ return dev_err_probe(dev, ret,
+ "failed to register %s firmware nodes\n",
+ profile->name);
+
+ topology->registered = true;
+ return 0;
+}
+
+static int
+ptp_ocp_i2c_add_device(struct ptp_ocp *bp, struct i2c_adapter *adapter,
+ const struct software_node *node, const char *type,
+ u16 address)
+{
+ struct fwnode_handle *fwnode = software_node_fwnode(node);
+ struct i2c_board_info info = { };
+ struct i2c_client *client;
+
+ client = i2c_find_device_by_fwnode(fwnode);
+ if (client) {
+ put_device(&client->dev);
+ return 0;
+ }
+
+ strscpy(info.type, type, sizeof(info.type));
+ info.addr = address;
+ info.fwnode = fwnode;
+ client = i2c_new_client_device(adapter, &info);
+ if (IS_ERR(client))
+ return dev_err_probe(&bp->pdev->dev, PTR_ERR(client),
+ "failed to add %s at %d-00%02x\n",
+ type, i2c_adapter_id(adapter), address);
+
+ return 0;
+}
+
+static int
+ptp_ocp_i2c_populate_channel(struct ptp_ocp *bp, unsigned int channel)
+{
+ struct ptp_ocp_i2c_topology *topology = bp->i2c_topology;
+ const struct ptp_ocp_i2c_profile *profile = topology->profile;
+ const struct software_node *node;
+ struct fwnode_handle *fwnode;
+ struct i2c_adapter *adapter;
+ unsigned int i;
+ int err, ret = 0;
+
+ fwnode = software_node_fwnode(&topology->channel_nodes[channel]);
+ adapter = i2c_get_adapter_by_fwnode(fwnode);
+ if (!adapter)
+ return -EAGAIN;
+
+ for (i = 0; i < profile->sensor_count; i++) {
+ const struct ptp_ocp_i2c_device *sensor;
+
+ sensor = &profile->sensors[i];
+ if (sensor->channel != channel)
+ continue;
+
+ node = &topology->sensor_nodes[i];
+ err = ptp_ocp_i2c_add_device(bp, adapter, node, sensor->type,
+ sensor->address);
+ if (err && !ret)
+ ret = err;
+ }
+
+ if (channel == 1) {
+ err = ptp_ocp_i2c_add_device(bp, adapter, &topology->led_node,
+ "is32fl3207",
+ profile->led_address);
+ if (err && !ret)
+ ret = err;
+ }
+
+ i2c_put_adapter(adapter);
+ return ret;
+}
+
+static void
+ptp_ocp_i2c_remove_mux(struct ptp_ocp *bp)
+{
+ struct fwnode_handle *fwnode;
+ struct i2c_client *client;
+
+ if (!bp->i2c_topology || !bp->i2c_topology->registered)
+ return;
+
+ fwnode = software_node_fwnode(&bp->i2c_topology->mux_node);
+ client = i2c_find_device_by_fwnode(fwnode);
+ if (!client)
+ return;
+
+ i2c_unregister_device(client);
+ put_device(&client->dev);
+}
+
+static void
+ptp_ocp_i2c_kick(struct ptp_ocp *bp)
+{
+ if (!READ_ONCE(bp->i2c_resources_ready))
+ return;
+ if (!READ_ONCE(bp->i2c_root_present))
+ return;
+
+ atomic_set(&bp->i2c_retry_count, 0);
+ mod_delayed_work(system_wq, &bp->i2c_work, 1);
+}
+
+static void
+ptp_ocp_i2c_retry(struct ptp_ocp *bp)
+{
+ if (!READ_ONCE(bp->i2c_resources_ready))
+ return;
+ if (!READ_ONCE(bp->i2c_root_present))
+ return;
+ if (atomic_inc_return(&bp->i2c_retry_count) > OCP_I2C_RETRY_MAX)
+ return;
+
+ mod_delayed_work(system_wq, &bp->i2c_work, HZ);
+}
+
+static void
+ptp_ocp_i2c_populate_topology(struct ptp_ocp *bp,
+ struct platform_device *i2c_ctrl,
+ bool *retry)
+{
+ const struct software_node *node;
+ struct i2c_adapter *adapter;
+ struct fwnode_handle *fwnode;
+ struct i2c_client *mux;
+ unsigned int channel;
+ int ret;
+
+ if (!READ_ONCE(bp->i2c_root_present)) {
+ ptp_ocp_i2c_remove_mux(bp);
+ return;
+ }
+ if (!device_is_registered(&i2c_ctrl->dev) ||
+ !device_is_bound(&i2c_ctrl->dev)) {
+ *retry = true;
+ return;
+ }
+ if (!bp->eeprom_map)
+ return;
+
+ adapter = ptp_ocp_i2c_root_adapter(bp);
+ if (!adapter) {
+ *retry = true;
+ return;
+ }
+
+ if (!ptp_ocp_has_eeprom_data(bp))
+ ptp_ocp_read_eeprom(bp);
+ if (!ptp_ocp_has_eeprom_data(bp)) {
+ *retry = true;
+ goto out_put_adapter;
+ }
+ if (!bp->i2c_profile)
+ bp->i2c_profile = ptp_ocp_i2c_select_profile(bp);
+ if (!bp->i2c_profile)
+ goto out_put_adapter;
+
+ ret = ptp_ocp_i2c_init_nodes(bp);
+ if (ret) {
+ *retry = true;
+ goto out_put_adapter;
+ }
+
+ node = &bp->i2c_topology->mux_node;
+ ret = ptp_ocp_i2c_add_device(bp, adapter, node, "pca9546", 0x70);
+ if (ret) {
+ *retry = true;
+ goto out_put_adapter;
+ }
+
+ fwnode = software_node_fwnode(&bp->i2c_topology->mux_node);
+ mux = i2c_find_device_by_fwnode(fwnode);
+ if (!mux) {
+ *retry = true;
+ goto out_put_adapter;
+ }
+
+ device_lock(&mux->dev);
+ if (!device_is_registered(&mux->dev) || !device_is_bound(&mux->dev)) {
+ *retry = true;
+ goto out_unlock_mux;
+ }
+
+ for (channel = 0; channel < OCP_I2C_MUX_CHANNELS; channel++) {
+ ret = ptp_ocp_i2c_populate_channel(bp, channel);
+ if (ret)
+ *retry = true;
+ }
+
+out_unlock_mux:
+ device_unlock(&mux->dev);
+ put_device(&mux->dev);
+out_put_adapter:
+ i2c_put_adapter(adapter);
+}
+
+static void
+ptp_ocp_i2c_work(struct work_struct *work)
+{
+ struct ptp_ocp *bp = container_of(work, struct ptp_ocp, i2c_work.work);
+ struct platform_device *i2c_ctrl;
+ bool retry = false;
+
+ /* Pair with resource publication after registration. */
+ if (!smp_load_acquire(&bp->i2c_resources_ready))
+ return;
+
+ i2c_ctrl = bp->i2c_ctrl;
+ if (!i2c_ctrl) {
+ ptp_ocp_i2c_retry(bp);
+ return;
+ }
+
+ device_lock(&i2c_ctrl->dev);
+ ptp_ocp_i2c_populate_topology(bp, i2c_ctrl, &retry);
+ device_unlock(&i2c_ctrl->dev);
+
+ if (retry)
+ ptp_ocp_i2c_retry(bp);
+ else
+ atomic_set(&bp->i2c_retry_count, 0);
+}
+
+static void
+ptp_ocp_i2c_unregister(struct ptp_ocp *bp)
+{
+ struct device *i2c_ctrl_dev = NULL;
+
+ WRITE_ONCE(bp->i2c_resources_ready, false);
+ WRITE_ONCE(bp->i2c_root_present, false);
+ disable_delayed_work_sync(&bp->i2c_work);
+ if (bp->i2c_ctrl) {
+ i2c_ctrl_dev = &bp->i2c_ctrl->dev;
+ device_lock(i2c_ctrl_dev);
+ }
+ if (!bp->i2c_topology) {
+ bp->i2c_profile = NULL;
+ goto out_unlock;
+ }
+
+ if (bp->i2c_topology->registered) {
+ ptp_ocp_i2c_remove_mux(bp);
+ software_node_unregister_node_group(bp->i2c_topology->node_group);
+ bp->i2c_topology->registered = false;
+ }
+
+ bp->i2c_topology = NULL;
+ bp->i2c_profile = NULL;
+
+out_unlock:
+ if (i2c_ctrl_dev)
+ device_unlock(i2c_ctrl_dev);
+}
+
static struct device *
ptp_ocp_find_flash(struct ptp_ocp *bp)
{
@@ -2226,9 +2826,9 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
if (err)
return err;
- if (!bp->has_eeprom_data) {
+ if (!ptp_ocp_has_eeprom_data(bp)) {
ptp_ocp_read_eeprom(bp);
- if (!bp->has_eeprom_data)
+ if (!ptp_ocp_has_eeprom_data(bp))
return 0;
}
@@ -3819,7 +4419,7 @@ serialnum_show(struct device *dev, struct device_attribute *attr, char *buf)
{
struct ptp_ocp *bp = dev_get_drvdata(dev);
- if (!bp->has_eeprom_data)
+ if (!ptp_ocp_has_eeprom_data(bp))
ptp_ocp_read_eeprom(bp);
return sysfs_emit(buf, "%pM\n", bp->serial);
@@ -4790,6 +5390,7 @@ ptp_ocp_device_init(struct ptp_ocp *bp, struct pci_dev *pdev)
bp->ptp_info = ptp_ocp_clock_info;
spin_lock_init(&bp->lock);
+ mutex_init(&bp->eeprom_lock);
for (i = 0; i < __PORT_COUNT; i++)
bp->port[i].line = -1;
@@ -4928,6 +5529,11 @@ ptp_ocp_detach(struct ptp_ocp *bp)
{
int i;
+ if (bp->i2c_notifier_registered) {
+ bus_unregister_notifier(&i2c_bus_type, &bp->i2c_notifier);
+ bp->i2c_notifier_registered = false;
+ }
+ ptp_ocp_i2c_unregister(bp);
ptp_ocp_debugfs_remove_device(bp);
ptp_ocp_detach_sysfs(bp);
ptp_ocp_attr_group_del(bp);
@@ -5142,6 +5748,8 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
goto out_disable;
INIT_DELAYED_WORK(&bp->sync_work, ptp_ocp_sync_work);
+ INIT_DELAYED_WORK(&bp->i2c_work, ptp_ocp_i2c_work);
+ atomic_set(&bp->i2c_retry_count, 0);
/* compat mode.
* Older FPGA firmware only returns 2 irq's.
@@ -5156,9 +5764,20 @@ ptp_ocp_probe(struct pci_dev *pdev, const struct pci_device_id *id)
bp->n_irqs = err;
pci_set_master(pdev);
+ bp->i2c_notifier.notifier_call = ptp_ocp_i2c_notifier_call;
+ err = bus_register_notifier(&i2c_bus_type, &bp->i2c_notifier);
+ if (err) {
+ dev_err(&pdev->dev, "failed to register I2C notifier: %d\n", err);
+ goto out;
+ }
+ bp->i2c_notifier_registered = true;
+
err = ptp_ocp_register_resources(bp, id->driver_data);
if (err)
goto out;
+ /* Publish all board resources before I2C topology work can run. */
+ smp_store_release(&bp->i2c_resources_ready, true);
+ ptp_ocp_i2c_kick(bp);
bp->ptp = ptp_clock_register(&bp->ptp_info, &pdev->dev);
if (IS_ERR(bp->ptp)) {
@@ -5252,46 +5871,85 @@ static struct pci_driver ptp_ocp_driver = {
.shutdown = ptp_ocp_remove,
};
+static bool
+ptp_ocp_i2c_is_child(struct ptp_ocp *bp, struct device *child)
+{
+ struct device *dev = child;
+
+ while (dev) {
+ if (dev == &bp->pdev->dev)
+ return true;
+ dev = dev->parent;
+ }
+
+ return false;
+}
+
+static bool
+ptp_ocp_i2c_is_root(struct ptp_ocp *bp, struct i2c_adapter *adapter)
+{
+ struct device *parent = adapter->dev.parent;
+
+ if (!parent)
+ return false;
+ if (bp->i2c_ctrl && parent == &bp->i2c_ctrl->dev)
+ return true;
+
+ /* The adapter can notify before ptp_ocp_register_i2c() stores it. */
+ return parent->parent == &bp->pdev->dev;
+}
+
static int
ptp_ocp_i2c_notifier_call(struct notifier_block *nb,
unsigned long action, void *data)
{
- struct device *dev, *child = data;
- struct ptp_ocp *bp;
- bool add;
+ struct i2c_adapter *adapter;
+ struct i2c_client *client;
+ struct device *child = data;
+ struct ptp_ocp *bp = container_of(nb, struct ptp_ocp, i2c_notifier);
+
+ if (!ptp_ocp_i2c_is_child(bp, child))
+ return 0;
switch (action) {
case BUS_NOTIFY_ADD_DEVICE:
- case BUS_NOTIFY_DEL_DEVICE:
- add = action == BUS_NOTIFY_ADD_DEVICE;
- break;
- default:
+ adapter = i2c_verify_adapter(child);
+ if (!adapter)
+ return 0;
+ if (ptp_ocp_i2c_is_root(bp, adapter)) {
+ WRITE_ONCE(bp->i2c_root_present, true);
+ ptp_ocp_symlink(bp, child, "i2c");
+ }
+ ptp_ocp_i2c_kick(bp);
return 0;
- }
- if (!i2c_verify_adapter(child))
+ case BUS_NOTIFY_DEL_DEVICE:
+ adapter = i2c_verify_adapter(child);
+ if (!adapter)
+ return 0;
+ if (ptp_ocp_i2c_is_root(bp, adapter)) {
+ WRITE_ONCE(bp->i2c_root_present, false);
+ sysfs_remove_link(&bp->dev.kobj, "i2c");
+ mod_delayed_work(system_wq, &bp->i2c_work, 0);
+ }
return 0;
- dev = child;
- while ((dev = dev->parent))
- if (dev->driver && !strcmp(dev->driver->name, KBUILD_MODNAME))
- goto found;
- return 0;
+ case BUS_NOTIFY_BOUND_DRIVER:
+ client = i2c_verify_client(child);
+ if (!client || client->addr != 0x50)
+ return 0;
+ if (!ptp_ocp_i2c_is_root(bp, client->adapter))
+ return 0;
+ ptp_ocp_i2c_kick(bp);
+ return 0;
-found:
- bp = dev_get_drvdata(dev);
- if (add)
- ptp_ocp_symlink(bp, child, "i2c");
- else
- sysfs_remove_link(&bp->dev.kobj, "i2c");
+ default:
+ return 0;
+ }
return 0;
}
-static struct notifier_block ptp_ocp_i2c_notifier = {
- .notifier_call = ptp_ocp_i2c_notifier_call,
-};
-
static int __init
ptp_ocp_init(void)
{
@@ -5305,21 +5963,14 @@ ptp_ocp_init(void)
if (err)
goto out;
- what = "i2c notifier";
- err = bus_register_notifier(&i2c_bus_type, &ptp_ocp_i2c_notifier);
- if (err)
- goto out_notifier;
-
what = "ptp_ocp driver";
err = pci_register_driver(&ptp_ocp_driver);
if (err)
- goto out_register;
+ goto out_class;
return 0;
-out_register:
- bus_unregister_notifier(&i2c_bus_type, &ptp_ocp_i2c_notifier);
-out_notifier:
+out_class:
class_unregister(&timecard_class);
out:
ptp_ocp_debugfs_fini();
@@ -5330,7 +5981,6 @@ ptp_ocp_init(void)
static void __exit
ptp_ocp_fini(void)
{
- bus_unregister_notifier(&i2c_bus_type, &ptp_ocp_i2c_notifier);
pci_unregister_driver(&ptp_ocp_driver);
class_unregister(&timecard_class);
ptp_ocp_debugfs_fini();
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* [RFC net-next v2 6/6] ptp: ocp: Add Time Card V9 I2C peripheral topology
2026-08-03 20:50 [RFC net-next v2 0/6] ptp: ocp: Add R4006 and V9 I2C peripheral support Ahmad Byagowi
` (4 preceding siblings ...)
2026-08-03 20:50 ` [RFC net-next v2 5/6] ptp: ocp: Add R4006 I2C peripheral topology Ahmad Byagowi
@ 2026-08-03 20:50 ` Ahmad Byagowi
5 siblings, 0 replies; 8+ messages in thread
From: Ahmad Byagowi @ 2026-08-03 20:50 UTC (permalink / raw)
To: linux-leds, devicetree, linux-i2c, netdev
Cc: Lee Jones, Pavel Machek, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Andi Shyti, Peter Rosin, Nam Tran, Vadim Fedorenko,
Richard Cochran, Andrew Lunn, David S. Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Kees Cook, Gustavo A. R. Silva,
linux-hardening, linux-kernel
Time Card V9 places a BME280 at 0x76, a BNO055 at 0x29, and an
IS32FL3207 at 0x37 on PCA9546 channel 1.
Describe GNSS1 and GNSS2 as RGB LEDs on outputs 0 through 5 and SMA1
through SMA4 on outputs 6 through 17. Select this profile only for the
exact EEPROM ID "TIMECARD-V9".
Earlier Time Card revisions expose the same I2C device population with
different LED routing, so probing cannot distinguish them safely. Leave
erased, malformed, and unknown board IDs unconfigured.
Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
---
drivers/ptp/ptp_ocp.c | 68 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 67 insertions(+), 1 deletion(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 70ba47096..c8c28d792 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -353,7 +353,7 @@ struct ptp_ocp_serial_port {
#define OCP_I2C_MUX_CHANNELS 4
#define OCP_I2C_MAX_SENSOR_COUNT 5
-#define OCP_I2C_MAX_LED_COUNT 5
+#define OCP_I2C_MAX_LED_COUNT 6
#define OCP_I2C_MAX_LED_COMPONENT_COUNT (3 * OCP_I2C_MAX_LED_COUNT)
#define OCP_I2C_MUX_NAME_LEN 32
#define OCP_I2C_RETRY_MAX 10
@@ -617,9 +617,61 @@ static const struct ptp_ocp_led ptp_ocp_r4006_leds[] = {
},
};
+static const struct ptp_ocp_i2c_device ptp_ocp_v9_sensors[] = {
+ { "pressure@76", "bosch,bme280", "bme280", 1, 0x76 },
+ { "imu@29", "bosch,bno055", "bno055", 1, 0x29 },
+};
+
+static const struct ptp_ocp_led ptp_ocp_v9_leds[] = {
+ {
+ .node_name = "multi-led@0",
+ .function = LED_FUNCTION_STATUS,
+ .function_enumerator = 1,
+ .has_function_enumerator = true,
+ .channel = { 0, 1, 2 },
+ },
+ {
+ .node_name = "multi-led@3",
+ .function = LED_FUNCTION_STATUS,
+ .function_enumerator = 2,
+ .has_function_enumerator = true,
+ .channel = { 3, 4, 5 },
+ },
+ {
+ .node_name = "multi-led@6",
+ .function = LED_FUNCTION_INDICATOR,
+ .function_enumerator = 1,
+ .has_function_enumerator = true,
+ .channel = { 6, 7, 8 },
+ },
+ {
+ .node_name = "multi-led@9",
+ .function = LED_FUNCTION_INDICATOR,
+ .function_enumerator = 2,
+ .has_function_enumerator = true,
+ .channel = { 9, 10, 11 },
+ },
+ {
+ .node_name = "multi-led@c",
+ .function = LED_FUNCTION_INDICATOR,
+ .function_enumerator = 3,
+ .has_function_enumerator = true,
+ .channel = { 12, 13, 14 },
+ },
+ {
+ .node_name = "multi-led@f",
+ .function = LED_FUNCTION_INDICATOR,
+ .function_enumerator = 4,
+ .has_function_enumerator = true,
+ .channel = { 15, 16, 17 },
+ },
+};
+
static_assert(ARRAY_SIZE(ptp_ocp_r4006_sensors) <=
OCP_I2C_MAX_SENSOR_COUNT);
static_assert(ARRAY_SIZE(ptp_ocp_r4006_leds) <= OCP_I2C_MAX_LED_COUNT);
+static_assert(ARRAY_SIZE(ptp_ocp_v9_sensors) <= OCP_I2C_MAX_SENSOR_COUNT);
+static_assert(ARRAY_SIZE(ptp_ocp_v9_leds) <= OCP_I2C_MAX_LED_COUNT);
static const struct ptp_ocp_i2c_profile ptp_ocp_r4006_profile = {
.name = "r4006",
@@ -631,6 +683,16 @@ static const struct ptp_ocp_i2c_profile ptp_ocp_r4006_profile = {
.led_address = 0x34,
};
+static const struct ptp_ocp_i2c_profile ptp_ocp_v9_profile = {
+ .name = "v9",
+ .sensors = ptp_ocp_v9_sensors,
+ .sensor_count = ARRAY_SIZE(ptp_ocp_v9_sensors),
+ .leds = ptp_ocp_v9_leds,
+ .led_count = ARRAY_SIZE(ptp_ocp_v9_leds),
+ .led_node_name = "led-controller@37",
+ .led_address = 0x37,
+};
+
#define bp_assign_entry(bp, res, val) ({ \
uintptr_t addr = (uintptr_t)(bp) + (res)->bp_offset; \
*(typeof(val) *)addr = val; \
@@ -2259,6 +2321,10 @@ ptp_ocp_i2c_select_profile(struct ptp_ocp *bp)
if (!strncmp(bp->board_id, "R4006", 5))
return &ptp_ocp_r4006_profile;
+ /* Older revisions share V9's I2C devices but not its LED wiring. */
+ if (!strcmp(bp->board_id, "TIMECARD-V9"))
+ return &ptp_ocp_v9_profile;
+
return NULL;
}
--
2.50.1 (Apple Git-155)
^ permalink raw reply related [flat|nested] 8+ messages in thread
* Re: [RFC net-next v2 4/6] ptp: ocp: Validate EEPROM board IDs
2026-08-03 20:50 ` [RFC net-next v2 4/6] ptp: ocp: Validate EEPROM board IDs Ahmad Byagowi
@ 2026-08-04 13:55 ` Vadim Fedorenko
0 siblings, 0 replies; 8+ messages in thread
From: Vadim Fedorenko @ 2026-08-04 13:55 UTC (permalink / raw)
To: Ahmad Byagowi, linux-leds, devicetree, linux-i2c, netdev
Cc: Lee Jones, Pavel Machek, Rob Herring, Krzysztof Kozlowski,
Conor Dooley, Andi Shyti, Peter Rosin, Nam Tran, Richard Cochran,
Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
Paolo Abeni, Kees Cook, Gustavo A. R. Silva, linux-hardening,
linux-kernel, stable
On 03/08/2026 21:50, Ahmad Byagowi wrote:
> The EEPROM board ID is a fixed 13-byte field. It is stored without room
> for a terminator and passed to devlink as a C string. An erased EEPROM
> therefore exposes 0xff bytes and can make devlink read beyond the field
> while formatting board.id.
>
> Reserve a trailing byte, classify erased and malformed contents, and
> publish board.id only when the field contains printable text with valid
> padding. Continue reporting the serial number when the board ID is
> absent.
>
> Fixes: 0cfcdd1ebcfe1a9b262f6ad8419580720dc843c4 ("ptp: ocp: add nvmem interface for accessing eeprom")
use short format of hash to provide commit to fix:
Fixes: 0cfcdd1ebcfe ("ptp: ocp: add nvmem interface for accessing eeprom")
And as this is a fix, it has to go to net rather than net-next
> Cc: stable@vger.kernel.org
> Signed-off-by: Ahmad Byagowi <ahmadexp@gmail.com>
> ---
> drivers/ptp/ptp_ocp.c | 69 +++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 66 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index 35e911f1a..cec936bd1 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -347,6 +347,13 @@ struct ptp_ocp_serial_port {
> #define OCP_SIGNAL_NUM 4
> #define OCP_FREQ_NUM 4
>
> +enum ptp_ocp_board_id_state {
> + OCP_BOARD_ID_UNREAD,
> + OCP_BOARD_ID_VALID,
> + OCP_BOARD_ID_ERASED,
> + OCP_BOARD_ID_INVALID,
> +};
> +
> enum {
> PORT_GNSS,
> PORT_GNSS2,
> @@ -401,8 +408,9 @@ struct ptp_ocp {
> bool fw_loader;
> u8 fw_tag;
> u16 fw_version;
> - u8 board_id[OCP_BOARD_ID_LEN];
> + char board_id[OCP_BOARD_ID_LEN + 1];
> u8 serial[OCP_SERIAL_LEN];
> + enum ptp_ocp_board_id_state board_id_state;
> bool has_eeprom_data;
> u32 pps_req_map;
> int flash_start;
> @@ -472,18 +480,23 @@ struct ptp_ocp_eeprom_map {
> .len = sizeof_field(struct ptp_ocp, member), \
> .bp_offset = offsetof(struct ptp_ocp, member)
>
> +#define EEPROM_ENTRY_LEN(addr, member, entry_len) \
> + .off = addr, \
> + .len = entry_len, \
> + .bp_offset = offsetof(struct ptp_ocp, member)
> +
> #define BP_MAP_ENTRY_ADDR(bp, map) ({ \
> (void *)((uintptr_t)(bp) + (map)->bp_offset); \
> })
>
> static struct ptp_ocp_eeprom_map fb_eeprom_map[] = {
> - { EEPROM_ENTRY(0x43, board_id) },
> + { EEPROM_ENTRY_LEN(0x43, board_id, OCP_BOARD_ID_LEN) },
> { EEPROM_ENTRY(0x00, serial), .tag = "mac" },
> { }
> };
>
> static struct ptp_ocp_eeprom_map art_eeprom_map[] = {
> - { EEPROM_ENTRY(0x200 + 0x43, board_id) },
> + { EEPROM_ENTRY_LEN(0x200 + 0x43, board_id, OCP_BOARD_ID_LEN) },
> { EEPROM_ENTRY(0x200 + 0x63, serial) },
> { }
> };
> @@ -1969,6 +1982,52 @@ ptp_ocp_nvmem_device_put(struct nvmem_device **nvmemp)
> *nvmemp = NULL;
> }
>
> +static enum ptp_ocp_board_id_state
> +ptp_ocp_classify_board_id(char *board_id)
> +{
> + bool all_zero = true;
> + bool all_ones = true;
> + bool terminated = false;
> + unsigned int i;
> +
> + board_id[OCP_BOARD_ID_LEN] = '\0';
> + for (i = 0; i < OCP_BOARD_ID_LEN; i++) {
> + u8 value = board_id[i];
> +
> + all_zero &= value == 0;
> + all_ones &= value == 0xff;
> + }
> +
> + if (all_zero || all_ones) {
> + board_id[0] = '\0';
> + return OCP_BOARD_ID_ERASED;
> + }
> +
> + for (i = 0; i < OCP_BOARD_ID_LEN; i++) {
> + u8 value = board_id[i];
> +
> + if (terminated) {
> + if (value)
> + goto invalid;
> + continue;
> + }
> +
> + if (!value) {
> + terminated = true;
> + continue;
> + }
> + if (value < 0x20 || value > 0x7e)
> + goto invalid;
> + }
> +
> + if (board_id[0])
> + return OCP_BOARD_ID_VALID;
> +
> +invalid:
> + board_id[0] = '\0';
> + return OCP_BOARD_ID_INVALID;
> +}
> +
> static void
> ptp_ocp_read_eeprom(struct ptp_ocp *bp)
> {
> @@ -2001,6 +2060,7 @@ ptp_ocp_read_eeprom(struct ptp_ocp *bp)
> goto fail;
> }
>
> + bp->board_id_state = ptp_ocp_classify_board_id(bp->board_id);
> bp->has_eeprom_data = true;
>
> out:
> @@ -2177,6 +2237,9 @@ ptp_ocp_devlink_info_get(struct devlink *devlink, struct devlink_info_req *req,
> if (err)
> return err;
>
> + if (bp->board_id_state != OCP_BOARD_ID_VALID)
> + return 0;
> +
why don't simply
snprintf(buf, OCP_BOARD_ID_LEN + 1, "%s", bp->board_id); ?
buf is already used in the function, let's reuse it
> err = devlink_info_version_fixed_put(req,
> DEVLINK_INFO_VERSION_GENERIC_BOARD_ID,
> bp->board_id);
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2026-08-04 13:55 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-08-03 20:50 [RFC net-next v2 0/6] ptp: ocp: Add R4006 and V9 I2C peripheral support Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 1/6] dt-bindings: leds: Add IS32FL3207 controller Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 2/6] leds: rgb: Add IS32FL3207 controller driver Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 3/6] i2c: mux: Propagate software nodes to channel adapters Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 4/6] ptp: ocp: Validate EEPROM board IDs Ahmad Byagowi
2026-08-04 13:55 ` Vadim Fedorenko
2026-08-03 20:50 ` [RFC net-next v2 5/6] ptp: ocp: Add R4006 I2C peripheral topology Ahmad Byagowi
2026-08-03 20:50 ` [RFC net-next v2 6/6] ptp: ocp: Add Time Card V9 " Ahmad Byagowi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox