Add support for the LTC4266 PSE Controller
Subsystems (4)
cover Add support for the LTC4266 PSE Controller
Hello,
This RFC series is intended as a starting point for adding support for the LTC4266, an older PSE (IEEE 802.3at+) chipset from Linear Technology.
This chip has four individually controllable ports, each with its own detection, classification and current-limiting abilities. Currently, this series integrates with the PSE controller core and supports enable/disable, current and voltage reporting, classification results and will power up a valid IEEE 802.3at or IEEE802.3af powered device.
It also (poorly) supports the power-limiting functionality in the PSE core. The complexity here is that the LTC4266 only supports limiting the current, and so deriving a "current limit" from this power limit while staying compliant with the IEEE 802.3at/af specifications is tricky. I'm curious if folks have a better idea than the linear approximation I've used here.
It is RFC because I want to clarify some confusion I have around the system-level flow for a port's power allocation. It's very likely I've missed something, but it appears as though the port needs to be delivering power in order to set the power limit on the port.
Thanks for your time,
Kyle
Kyle Swenson (2):
dt-bindings: net: pse-pd: Describe the LTC4266 PSE chipset
net: pse-pd: Add LTC4266 PSE controller driver
.../bindings/net/pse-pd/lltc,ltc4266.yaml | 146 +++ drivers/net/pse-pd/Kconfig | 10 + drivers/net/pse-pd/Makefile | 1 + drivers/net/pse-pd/ltc4266.c | 919 ++++++++++++++++++ 4 files changed, 1076 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml create mode 100644 drivers/net/pse-pd/ltc4266.c
Signature · 1 line
2.47.0
RFC PATCH 1/2 dt-bindings: net: pse-pd: Describe the LTC4266 PSE chipset
Add the LTC4266 PSE controller from Linear Technology to the device-tree bindings.
--- .../bindings/net/pse-pd/lltc,ltc4266.yaml | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +146 -0
@@ -0,0 +1,146 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/pse-pd/lltc,ltc4266.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LTC LTC4266 Power Sourcing Equipment controller + +maintainers: + - Kyle Swenson <[email protected]> + +allOf: + - $ref: pse-controller.yaml# + +properties: + compatible: + enum: + - lltc,ltc4266 + + reg: + maxItems: 1 + + '#pse-cells': + const: 1 + + reset-gpios: + maxItems: 1 + + channels: + + description: This parameter describes the mapping between the logical ports + on the PSE controller and the physical ports. + + type: object + + additionalProperties: false + + properties: + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + + + patternProperties: + '^channel@[0-3]$': + type: object + additionalProperties: false + + properties: + reg: + maxItems: 1 + + sense-resistor-micro-ohms: + description: Sense resistor connected to the channel's MOSFET, used + for current measurement for overcurrent detection. + enum: [250000, 500000] + + required: + - reg + + required: + - "#address-cells" + - "#size-cells" + +unevaluatedProperties: false + +required: + - compatible + - reg + +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-pse@2f { + compatible = "lltc,ltc4266"; + status = "okay"; + + reg = <0x2f>; + + channels { + #address-cells = <1>; + #size-cells = <0>; + + phys0: channel@0 { + reg = <0>; + }; + + phys1: channel@1 { + reg = <1>; + }; + + phys2: channel@2 { + reg = <2>; + }; + + phys3: channel@3 { + reg = <3>; + }; + }; + pse-pis { + #address-cells = <1>; + #size-cells = <0>; + + pse_pi0: pse-pi@0 { + reg = <0>; + #pse-cells = <0>; + pairset-names = "alternative-a"; + pairsets = <&phys0>; + polarity-supported = "MDI"; + vpwr-supply = <&vreg_pse_1>; + }; + + pse_pi1: pse-pi@1 { + reg = <1>; + #pse-cells = <0>; + pairset-names = "alternative-a"; + pairsets = <&phys1>; + polarity-supported = "MDI"; + vpwr-supply = <&vreg_pse_2>; + }; + + pse_pi2: pse-pi@2 { + reg = <2>; + #pse-cells = <0>; + pairset-names = "alternative-a"; + pairsets = <&phys2>; + polarity-supported = "MDI"; + vpwr-supply = <&vreg_pse_3>; + }; + + pse_pi3: pse-pi@3 { + reg = <3>; + #pse-cells = <0>; + pairset-names = "alternative-a"; + pairsets = <&phys3>; + polarity-supported = "MDI"; + vpwr-supply = <&vreg_pse_4>; + }; + }; + }; + };
Signature · 1 line
2.47.0
Re: [RFC PATCH net-next 1/2] dt-bindings: net: pse-pd: Describe the LTC4266 PSE chipset
Quoted 9 lines · Kyle Swenson
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +9
-0+allOf: + - $ref: pse-controller.yaml# + +properties: + compatible: + enum: + - lltc,ltc4266 + + reg:
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 30
Quoted 10 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +10
-0+ maxItems: 1 + + '#pse-cells': + const: 1 + + reset-gpios: + maxItems: 1 + + channels: +
Drop blank line
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 32
Quoted 2 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +2
-0+ description: This parameter describes the mapping between the logical ports + on the PSE controller and the physical ports.
Move description after additionalProperties, so entire block is together.
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 35
Quoted 4 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +3
-0+ + type: object +
Drop blank line
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 45
Quoted 10 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +10
-0+ additionalProperties: false + + properties: + "#address-cells": + const: 1 + + "#size-cells": + const: 0 + +
Only one blank line
Quoted 9 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +9
-0+ patternProperties: + '^channel@[0-3]$': + type: object + additionalProperties: false + + properties: + reg: + maxItems: 1 +
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 64
Quoted 10 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +10
-0+ sense-resistor-micro-ohms: + description: Sense resistor connected to the channel's MOSFET, used + for current measurement for overcurrent detection. + enum: [250000, 500000] + + required: + - reg + + required: + - "#address-cells"
Keep consistent quotes, either ' or "
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 67
Quoted 3 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +3
-0+ - "#size-cells" + +unevaluatedProperties: false
This goes after required block
Quoted 4 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +4
-0+ +required: + - compatible + - reg
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 81
Quoted 10 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +10
-0+ +examples: + - | + i2c { + #address-cells = <1>; + #size-cells = <0>; + + ethernet-pse@2f { + compatible = "lltc,ltc4266"; + status = "okay";
Drop
Quoted 1 line
+
Drop blank line
Quoted 12 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +12
-0+ reg = <0x2f>; + + channels { + #address-cells = <1>; + #size-cells = <0>; + + phys0: channel@0 { + reg = <0>; + }; + + phys1: channel@1 { + reg = <1>;
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml line 104
Quoted 10 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +10
-0+ }; + + phys2: channel@2 { + reg = <2>; + }; + + phys3: channel@3 { + reg = <3>; + }; + };
Blank line... you really folllow entirely different style :/
Best regards,
Krzysztof
Kory Maincent
maintainerRe: [RFC PATCH net-next 1/2] dt-bindings: net: pse-pd: Describe the LTC4266 PSE chipset
In reply to Kyle SwensonQuoted 2 lines · Kyle Swenson
Add the LTC4266 PSE controller from Linear Technology to the device-tree bindings.
Hello Kyle,
Nice to see your patch!
Your Sign-off-by tag is missing on all your patches.
Quoted 43 lines
--- .../bindings/net/pse-pd/lltc,ltc4266.yaml | 146 ++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml(quoted diff) +0
-0
b/Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yamlnew file mode 100644 index 000000000000..874447ab6c84Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +31
-0@@ -0,0 +1,146 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/net/pse-pd/lltc,ltc4266.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: LTC LTC4266 Power Sourcing Equipment controller + +maintainers: + - Kyle Swenson <[email protected]> + +allOf: + - $ref: pse-controller.yaml# + +properties: + compatible: + enum: + - lltc,ltc4266 + + reg: + maxItems: 1 + + '#pse-cells': + const: 1 + + reset-gpios: + maxItems: 1 + + channels: + + description: This parameter describes the mapping between the logical
Quoted 2 lines
ports
+ on the PSE controller and the physical ports.
The channels parameter is not describing the mapping but only the channels list. I also have to change the tps23881 binding doc similarly. We discussed about this here
https://lore.kernel.org/netdev/20250517003525.2f6a5005@kmaincent-XPS-13-7390/
Regards,
Signature · 3 lines
Köry Maincent, Bootlin Embedded Linux and kernel engineering https://bootlin.com
Re: [RFC PATCH net-next 1/2] dt-bindings: net: pse-pd: Describe the LTC4266 PSE chipset
Quoted 6 lines · Kory Maincent
Le Tue, 3 Jun 2025 23:04:37 +0000,
Kyle Swenson <[email protected]> a écrit :Hello Kyle,
Nice to see your patch!
Thanks! A bit later than I had intended but late is better than never I guess.
Quoted 2 lines
Your Sign-off-by tag is missing on all your patches.
My mistake. I had intended to add that but evidently didn't.
Quoted 10 lines
Quoted 5 lines
Documentation/devicetree/bindings/net/pse-pd/lltc,ltc4266.yaml new file +3
-0+ channels: + + description: This parameter describes the mapping between the logicalports
+ on the PSE controller and the physical ports.The channels parameter is not describing the mapping but only the channels list. I also have to change the tps23881 binding doc similarly. We discussed about this here
https://lore.kernel.org/netdev/20250517003525.2f6a5005@kmaincent-XPS-13-7390/
Oh, thanks for the link. I'll fix this (and all the other issues in the binding) in v2.
Thanks,
Kyle
RFC PATCH 2/2 net: pse-pd: Add LTC4266 PSE controller driver
In reply to Kyle SwensonAdd a new driver for the Linear Technology LTC4266 I2C Power Sourcing Equipment controller. This driver integrates with the current PSE controller core, implementing IEEE802.3af and IEEE802.3at PSE standards.
--- drivers/net/pse-pd/Kconfig | 10 + drivers/net/pse-pd/Makefile | 1 + drivers/net/pse-pd/ltc4266.c | 919 +++++++++++++++++++++++++++++++++++ 3 files changed, 930 insertions(+) create mode 100644 drivers/net/pse-pd/ltc4266.c
drivers/net/pse-pd/Kconfig +10 -0
@@ -18,10 +18,20 @@ config PSE_REGULATOR help This module provides support for simple regulator based Ethernet Power Sourcing Equipment without automatic classification support. For example for basic implementation of PoDL (802.3bu) specification. +config PSE_LTC4266 + tristate "LTC4266 PSE controller" + depends on I2C + help + This module provides support the LTC4266 regulator based Ethernet + Power Sourcing Equipment. + + To compile this driver as a module, choose M here: the + module will be called ltc4266. + config PSE_PD692X0 tristate "PD692X0 PSE controller" depends on I2C select FW_LOADER select FW_UPLOAD
drivers/net/pse-pd/Makefile +1 -0
@@ -1,8 +1,9 @@ # SPDX-License-Identifier: GPL-2.0-only # Makefile for Linux PSE drivers obj-$(CONFIG_PSE_CONTROLLER) += pse_core.o +obj-$(CONFIG_PSE_LTC4266) += ltc4266.o obj-$(CONFIG_PSE_REGULATOR) += pse_regulator.o obj-$(CONFIG_PSE_PD692X0) += pd692x0.o obj-$(CONFIG_PSE_TPS23881) += tps23881.o
drivers/net/pse-pd/ltc4266.c new file +919 -0
919 lines not on this page · raw message
Signature · 1 line
2.47.0
Oleksij Rempel
maintainerRe: [RFC PATCH net-next 2/2] net: pse-pd: Add LTC4266 PSE controller driver
Hi Kyle,
thank you for your work!
Are there any way to get manual with register description? I would like to make a deeper review :)
Quoted 118 lines · Kyle Swenson
Add a new driver for the Linear Technology LTC4266 I2C Power Sourcing Equipment controller. This driver integrates with the current PSE controller core, implementing IEEE802.3af and IEEE802.3at PSE standards.
--- drivers/net/pse-pd/Kconfig | 10 + drivers/net/pse-pd/Makefile | 1 + drivers/net/pse-pd/ltc4266.c | 919 +++++++++++++++++++++++++++++++++++ 3 files changed, 930 insertions(+) create mode 100644 drivers/net/pse-pd/ltc4266.cdrivers/net/pse-pd/Kconfig +10
-0@@ -18,10 +18,20 @@ config PSE_REGULATOR help This module provides support for simple regulator based Ethernet Power Sourcing Equipment without automatic classification support. For example for basic implementation of PoDL (802.3bu) specification. +config PSE_LTC4266 + tristate "LTC4266 PSE controller" + depends on I2C + help + This module provides support the LTC4266 regulator based Ethernet + Power Sourcing Equipment. + + To compile this driver as a module, choose M here: the + module will be called ltc4266. + config PSE_PD692X0 tristate "PD692X0 PSE controller" depends on I2C select FW_LOADER select FW_UPLOADdrivers/net/pse-pd/Makefile +1
-0@@ -1,8 +1,9 @@ # SPDX-License-Identifier: GPL-2.0-only # Makefile for Linux PSE drivers obj-$(CONFIG_PSE_CONTROLLER) += pse_core.o +obj-$(CONFIG_PSE_LTC4266) += ltc4266.o obj-$(CONFIG_PSE_REGULATOR) += pse_regulator.o obj-$(CONFIG_PSE_PD692X0) += pd692x0.o obj-$(CONFIG_PSE_TPS23881) += tps23881.odrivers/net/pse-pd/ltc4266.c new file +63
-0@@ -0,0 +1,919 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* Driver for Linear LTC4266 PoE PSE Controller +* +* Original work: +* Copyright 2019 Cradlepoint Technology, Inc. +* Cradlepoint Technology, Inc. <[email protected]> +* +* Re-written in 2025: +* Copyright 2025 Ericsson Software Technology +* Kyle Swenson <[email protected]> +* +*/ + +#include <linux/bitfield.h> +#include <linux/bits.h> +#include <linux/delay.h> +#include <linux/device.h> +#include <linux/errno.h> +#include <linux/ethtool.h> +#include <linux/gpio.h> +#include <linux/i2c.h> +#include <linux/interrupt.h> +#include <linux/kernel.h> +#include <linux/math.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/pse-pd/pse.h> +#include <linux/slab.h> +#include <linux/workqueue.h> + +#define LTC4266_REG_ID 0x1B +#define LTC4266_ID 0x64 + +#define TWO_BIT_WORD_OFFSET (_v, _pid) ((_v) << ((_pid) * 2)) +#define TWO_BIT_WORD_MASK (_pid) TWO_BIT_WORD_OFFSET(0x03, (_pid)) + +#define LTC4266_IPLSB_REG (_p) (0x30 | ((_p) << 2)) +#define LTC4266_VPLSB_REG (_p) (LTC4266_IPLSB_REG(_p) + 2) + +#define LTC4266_RSTPB_INTCLR BIT(7) +#define LTC4266_RSTPB_PINCLR BIT(6) +#define LTC4266_RSTPB_RSTALL BIT(5) + +/* Register definitions */ +#define LTC4266_REG_INTSTAT 0x00 +#define LTC4266_REG_INTMASK 0x01 +#define LTC4266_REG_PWREVN_COR 0x03 +#define LTC4266_REG_DETEVN_COR 0x05 +#define LTC4266_REG_FLTEVN_COR 0x07 +#define LTC4266_REG_TSEVN_COR 0x09 +#define LTC4266_REG_SUPEVN_COR 0x0B +#define LTC4266_REG_STAT (n) (0x0C + (n)) +#define LTC4266_REG_STATPWR 0x10 +#define LTC4266_REG_OPMD 0x12 +#define LTC4266_REG_DISENA 0x13/* Disconnect detect enable */ +#define LTC4266_REG_MCONF 0x17 +#define LTC4266_REG_DETPB 0x18 +#define LTC4266_REG_PWRPB 0x19 +#define LTC4266_REG_RSTPB 0x1A +#define LTC4266_REG_HPEN 0x44 +#define LTC4266_REG_HPMD (_p) (0x46 + (5 * (_p))) +#define LTC4266_REG_ILIM (_p) (LTC4266_REG_HPMD(_p) + 2)
drivers/net/pse-pd/ltc4266.c line 73
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+#define LTC4266_REG_TLIM12 0x1E +#define LTC4266_REG_TLIM34 0x1F + +/* Register field definitions */ +#define LTC4266_HPMD_PONGEN 0x01 + +/* For LTC4266_REG_TLIM* */ +#define LTC4266_TLIM_VALUE 0x01 + +/* LTC4266_REG_HPEN, enable "High Power" mode (i.e. Type 2, 25.4W PDs) */
Type 2 Class 4? Probably not, datasheet claims:
"Supports Proprietary Power Levels Above 25W"
Quoted 4 lines
drivers/net/pse-pd/ltc4266.c new file +4
-0+#define LTC4266_HPEN (_p) BIT(_p) + +/* LTC4266_REG_MCONF */ +#define LTC4266_MCONF_INTERRUPT_ENABLE BIT(7)
drivers/net/pse-pd/ltc4266.c line 87
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+ +/* LTC4266_REG_STATPWR */ +#define LTC4266_STATPWR_PG (_p) BIT((_p) + 4) +#define LTC4266_STATPWR_PE (_p) BIT(_p) +#define LTC4266_PORT_CLASS (_stat) FIELD_GET(GENMASK(6, 4), (_stat)) + +#define LTC4266_REG_ICUT_HP (_p) (LTC4266_REG_HPMD(_p) + 1) + +/* if R_sense = 0.25 Ohm, this should be set otherwise 0 */ +#define LTC4266_ICUT_RSENSE BIT(7)
LTC4266_ICUT_RSENSE_025_OHM
drivers/net/pse-pd/ltc4266.c line 94
Quoted 7 lines
drivers/net/pse-pd/ltc4266.c new file +7
-0+/* if set, halve the range and double the precision */ +#define LTC4266_ICUT_RANGE BIT(6) + +#define LTC4266_ILIM_AF_RSENSE_025 0x80 +#define LTC4266_ILIM_AF_RSENSE_050 0x00 +#define LTC4266_ILIM_AT_RSENSE_025 0xC0 +#define LTC4266_ILIM_AT_RSENSE_050 0x40
Consider renaming constants AF/AT mentions.
Replace _AF_ with _TYPE1_ (e.g., LTC4266_ILIM_TYPE1_RSENSE_025) Replace _AT_ with _TYPE2_ (e.g., LTC4266_ILIM_TYPE2_RSENSE_025)
The terms "Type 1" and "Type 2" are how the official IEEE 802.3 standard refers to the PoE capabilities and power levels that were introduced by the 802.3af and 802.3at amendments, respectively. Using "Type1" and "Type2" in your code will make it clearer and more aligned with the current, consolidated IEEE terminology, which is helpful since direct access to the original "af" and "at" amendment documents can be challenging for the open-source community.
Do you have access to this amendments?
Quoted 16 lines
drivers/net/pse-pd/ltc4266.c new file +16
-0+/* LTC4266_REG_INTSTAT and LTC4266_REG_INTMASK */ +#define LTC4266_INT_SUPPLY BIT(7) +#define LTC4266_INT_TSTART BIT(6) +#define LTC4266_INT_TCUT BIT(5) +#define LTC4266_INT_CLASS BIT(4) +#define LTC4266_INT_DET BIT(3) +#define LTC4266_INT_DIS BIT(2) +#define LTC4266_INT_PWRGD BIT(1) +#define LTC4266_INT_PWRENA BIT(0) + +#define LTC4266_MAX_PORTS 4 + +/* Maximum and minimum power limits for a single port */ +#define LTC4266_PW_LIMIT_MAX 25400 +#define LTC4266_PW_LIMIT_MIN 1 +
drivers/net/pse-pd/ltc4266.c line 121
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+enum { +READ_CURRENT =0 , +READ_VOLTAGE =2 +}; + +enum { +LTC4266_OPMD_SHUTDOWN =0 , +LTC4266_OPMD_MANUAL , +LTC4266_OPMD_SEMI , +LTC4266_OPMD_AUTO
Please add explanations to this port modes
Quoted 7 lines
drivers/net/pse-pd/ltc4266.c new file +7
-0+}; + +/* Map LTC4266 Classification result to PD class */ +static int ltc4266_class_map[] = { +0 ,/* Treat as class 3 */ +1 , +2 ,
drivers/net/pse-pd/ltc4266.c line 138
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+3 , +4 , + -EINVAL , +3 ,/* Treat as class 3 */ + -ERANGE +}; + +/* Convert a class 0-4 to icut register value */ +static int ltc4266_class_to_icut[] = { + 375,
missing comment, index 0 is class 3.
drivers/net/pse-pd/ltc4266.c line 143
Quoted 5 lines
drivers/net/pse-pd/ltc4266.c new file +5
-0+112 , +206 , +375 , + 638 +};
May be we should have a generic function in the framework providing conversion from class to min/max Icut and Ilim, otherwise it makes additional work validation this values.
Quoted 15 lines
drivers/net/pse-pd/ltc4266.c new file +15
-0+ +enum sense_resistor { +LTC4266_RSENSE_500 ,/* Rsense 0.5 Ohm */ +LTC4266_RSENSE_250 /* Rsense 0.25 Ohm */ +}; + +struct ltc4266_port { +enum sense_resistor rsense; +struct device_node *node; +int current_limit; +}; + +struct ltc4266 { +struct i2c_client *client; +struct mutex lock;/* Protect Read-Modify-Write Sequences */
drivers/net/pse-pd/ltc4266.c line 168
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+struct ltc4266_port *ports[LTC4266_MAX_PORTS ]; +struct device *dev; +struct device_node *np; +struct pse_controller_dev pcdev; +}; + +/* Read-modify-write sequence with value and mask. Mask is expected to be +* shifted to the correct spot. +*/ +static int ltc4266_write_reg (struct ltc4266 *ltc4266,u8 reg,u8 value,u8 mask)
If it is Read-modify-write type of function, it would be better to name it ltc4266_rmw_reg(). Or use regmap instead, you will get some extra
functionality: register dump over sysfs interface, range validation, caching if enabled, locking, etc.
Quoted 32 lines
drivers/net/pse-pd/ltc4266.c new file +32
-0+{ +int ret; +u8 new; + +mutex_lock (<c4266->lock); + ret =i2c_smbus_read_byte_data (ltc4266->client, reg); +if (ret <0 ) { +dev_warn (ltc4266->dev,"Failed to read register 0x%02x, err=%d\n" , reg, ret); +mutex_unlock (<c4266->lock); +return ret; + } + new = (u8 )ret; + new &= ~mask; + new |= value & mask; + ret =i2c_smbus_write_byte_data (ltc4266->client, reg, new); +mutex_unlock (<c4266->lock); + +return ret; +} + +static int ltc4266_read_iv (struct ltc4266 *ltc4266,int port,u8 iv) +{ +int lsb; +int msb; +int result; +int lsb_reg; +u64 ivbits =0 ; + +if (iv ==READ_CURRENT ) + lsb_reg =LTC4266_IPLSB_REG (port); +else if (iv ==READ_VOLTAGE ) + lsb_reg =LTC4266_VPLSB_REG (port);
drivers/net/pse-pd/ltc4266.c line 210
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+else +return -EINVAL ; + + result =i2c_smbus_read_byte_data (ltc4266->client,LTC4266_REG_STATPWR ); +if (result <0 ) +return result; + +/* LTC4266 IV readings are only valid if the port is powered. */ +if (!(result <C4266_STATPWR_PG (port))) +return -EINVAL ;
We have two states:
- admin enabled: admin enabled state
- delivering power: PSE is actually delivering power
Please use this words to clarify what is actually happening.
drivers/net/pse-pd/ltc4266.c line 216
Quoted 5 lines
drivers/net/pse-pd/ltc4266.c new file +5
-0+/* LTC4266 expects the MSB register to be read immediately following the LSB +* register, so we need to ensure other parts aren't reading other registers in +* this chip while we read the current/voltage regulators. +*/ +mutex_lock (<c4266->lock);
please use guard* variants for locking.
Quoted 35 lines
drivers/net/pse-pd/ltc4266.c new file +34
-0+ + lsb =i2c_smbus_read_byte_data (ltc4266->client, lsb_reg); + msb =i2c_smbus_read_byte_data (ltc4266->client, lsb_reg +1 ); + +mutex_unlock (<c4266->lock); + +if (lsb <0 ) +return lsb; + +if (msb <0 ) +return msb; + + ivbits =0 ; + ivbits |= ((u8 )msb) <<8 | ((u8 )lsb); + +if (iv ==READ_CURRENT ) +if (ltc4266->ports[port]->rsense ==LTC4266_RSENSE_250 )/* 122.07 uA/LSB */ + result =DIV_ROUND_CLOSEST_ULL ((ivbits *122070 ),1000 ); +else /* 61.035 uA/LSB */ + result =DIV_ROUND_CLOSEST_ULL ((ivbits *61035 ),1000 ); +else /* 5.835 mV/LSB == 5835 uV/LSB */ + result = ivbits *5835 ; + +return result; +} +i +static int ltc4266_port_set_ilim(struct ltc4266 *ltc4266, int port, int class) +{ +if (class >4 || class <0 ) +return -EINVAL ; + +/* We want to set 425 mA for class 3 and lower; 850 mA otherwise for IEEE compliance */ +if (class <4 ) { +/* Write 0x80 for 0.25 Ohm sense otherwise 0 */
drivers/net/pse-pd/ltc4266.c line 260
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+if (ltc4266->ports[port]->rsense ==LTC4266_RSENSE_250 ) +return i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_ILIM (port),LTC4266_ILIM_AF_RSENSE_025 ); +return i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_ILIM (port),LTC4266_ILIM_AF_RSENSE_050 ); + } + +/* Class == 4 */ +if (ltc4266->ports[port]->rsense ==LTC4266_RSENSE_250 ) +return i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_ILIM (port),LTC4266_ILIM_AT_RSENSE_025 ); +/* Class == 4 and the sense resistor is 0.5 */ +return i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_ILIM (port),LTC4266_ILIM_AT_RSENSE_050 );
May be something like this:
/*
* ltc4266_port_set_ilim - Set the active current limit (ILIM) for a port.
* @ltc4266: Pointer to the LTC4266 device structure.
* @port: The port number (0-3).
* @class: The detected PD class (0-4).
*
* This function configures the ILIM register (0x48, 0x4D, 0x52, 0x57)
* of the LTC4266. The ILIM value determines the threshold at which the
* PSE actively limits current to the PD. The chosen values are based on
* IEEE Std 802.3-2022 requirements and typical operational values for the
* LTC4266 controller.
*
* IEEE Std 802.3-2022, Table 33-11 specifies ILIM parameter ranges:
* - For Type 1 PSE operation (typically PD Classes 0-3):
* The minimum ILIM is 0.400A. This driver uses 425mA. This value fits
* within typical Type 1 ILIM specifications (e.g., 0.400A min to
* around 0.440A-0.500A max for the programmed steady-state limit).
*
* - For Type 2 PSE operation (typically PD Class 4):
* The minimum ILIM is 1.14 * ICable (or ~1.05 * IPort_max from other
* interpretations, e.g., ~0.630A to ~0.684A). This driver uses 850mA.
* This value meets the minimum requirement and is a supported operational
* current limit for high power modes in the LTC4266.
*
* The overall PSE current output must not exceed the time-dependent PSE
* upperbound template, IPSEUT(t), described in IEEE Std 802.3-2022,
* Equation (33-6). The programmed ILIM values (425mA/850mA) serve as the
* long-term current limit (Ilimmin segment of IPSEUT(t)) and are well
* within the higher short-term current allowances of that template (e.g., 1.75A). *
* The specific register values written depend on the sense resistor
* (0.25 Ohm or 0.50 Ohm) as detailed in the LTC4266 datasheet (Table 5). *
* Returns: ...
*/
static int ltc4266_port_set_ilim(struct ltc4266 *ltc4266, int port, int class)
{
u8 ilim_reg_val;
if (class > 4 || class < 0)
return -EINVAL;
if (class < 4) {
/* PD Class is 0, 1, 2, or 3 (Type 1 PSE operation).
* Set ILIM to 425mA.
*/
if (ltc4266->ports[port]->rsense == LTC4266_RSENSE_250) {
/* Using 0.25 Ohm sense resistor. */
ilim_reg_val = LTC4266_ILIM_TYPE1_RSENSE_025;
} else {
/* Using 0.50 Ohm sense resistor. */
ilim_reg_val = LTC4266_ILIM_TYPE1_RSENSE_050;
}
} else {
/* PD Class is 4 (Type 2 PSE operation).
* Set ILIM to 850mA.
*/
if (ltc4266->ports[port]->rsense == LTC4266_RSENSE_250) {
/* Using 0.25 Ohm sense resistor. */
ilim_reg_val = LTC4266_ILIM_TYPE2_RSENSE_025;
} else {
/* Using 0.50 Ohm sense resistor. */
ilim_reg_val = LTC4266_ILIM_TYPE2_RSENSE_050;
}
}
/* Write the determined ILIM value to the appropriate port's ILIM register.
* The LTC4266_REG_ILIM(port) macro resolves to the correct register
* address for the given port (e.g., 0x48 for port 0, 0x4D for port 1, etc.).
*/
return i2c_smbus_write_byte_data(ltc4266->client, LTC4266_REG_ILIM(port), ilim_reg_val);
}drivers/net/pse-pd/ltc4266.c line 267
Quoted 5 lines
drivers/net/pse-pd/ltc4266.c new file +5
-0+static int ltc4266_port_set_icut (struct ltc4266 *ltc4266,int port,int icut) +{ +u8 val; + +if (icut >850 )
It looks like board specific limit:
From the LTC4266 datasheet:
"Non-standard applications that provide more current
than the 850mA IEEE maximum may require heat sinking and other MOSFET design considerations."
drivers/net/pse-pd/ltc4266.c line 270
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+return -ERANGE ; + + val = (u8)(DIV_ROUND_CLOSEST ((icut *1000 ),18750 ) &0x3F );
I assume 18750 micro Amp, per step in the register value and 0x3f is the max mask for the bit field. In this case this register supports0x3f * 18750 / 1000 = 1181mA
Please use defines to make it readable.
Quoted 7 lines
drivers/net/pse-pd/ltc4266.c new file +7
-0+ +if (ltc4266->ports[port]->rsense ==LTC4266_RSENSE_250 ) + val |=LTC4266_ICUT_RSENSE |LTC4266_ICUT_RANGE ; + +return i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_ICUT_HP (port), val); +} +
drivers/net/pse-pd/ltc4266.c line 287
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+static int ltc4266_port_mode (struct ltc4266 *ltc4266,int port,u8 opmd) +{ +if (opmd >=LTC4266_OPMD_AUTO ) +return -EINVAL ; + +return ltc4266_write_reg (ltc4266,LTC4266_REG_OPMD ,TWO_BIT_WORD_OFFSET (opmd, port), +TWO_BIT_WORD_MASK (port)); +} + +static int ltc4266_port_powered (struct ltc4266 *ltc4266,int port)
delivering or enabled?
Quoted 11 lines
drivers/net/pse-pd/ltc4266.c new file +11
-0+{ +int result =i2c_smbus_read_byte_data (ltc4266->client,LTC4266_REG_STATPWR ); + +if (result <0 ) +return result; + +return !!((result <C4266_STATPWR_PG (port)) && (result <C4266_STATPWR_PE (port))); +} + +static int ltc4266_port_init (struct ltc4266 *ltc4266,int port) +{
drivers/net/pse-pd/ltc4266.c line 308
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+int ret; +u8 tlim_reg; +u8 tlim_mask; + +/* Reset the port */ + ret =i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_RSTPB ,BIT (port)); +if (ret <0 ) +return ret; + + ret =ltc4266_port_mode (ltc4266, port,LTC4266_OPMD_SEMI );
Should we have disabled mode before all current limits configured?
drivers/net/pse-pd/ltc4266.c line 312
Quoted 4 lines
drivers/net/pse-pd/ltc4266.c new file +4
-0+if (ret <0 ) +return ret; + +/* Enable high power mode on the port (802.3at+) */
802.3at+? "Proprietary Power Levels Above 25W"?. Here we will need a discussion how to reflect a Proprietary Power levels in the UAPI.
drivers/net/pse-pd/ltc4266.c line 318
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+ ret =ltc4266_write_reg (ltc4266,LTC4266_REG_HPEN , +LTC4266_HPEN (port),LTC4266_HPEN (port)); +if (ret <0 ) +return ret; + +/* Enable Ping-Pong Classification */
This is probably "2-event classification" described in Clause 33 of the IEEE Std 802.3-2022.
Quoted 25 lines
drivers/net/pse-pd/ltc4266.c new file +25
-0+ ret =ltc4266_write_reg (ltc4266,LTC4266_REG_HPMD (port), +LTC4266_HPMD_PONGEN ,LTC4266_HPMD_PONGEN ); +if (ret <0 ) +return ret; + +if (ltc4266->ports[port]->rsense ==LTC4266_RSENSE_250 ) + ret =ltc4266_write_reg (ltc4266,LTC4266_REG_ICUT_HP (port), +LTC4266_ICUT_RSENSE ,LTC4266_ICUT_RSENSE ); +else + ret =ltc4266_write_reg (ltc4266,LTC4266_REG_ICUT_HP (port), +0 ,LTC4266_ICUT_RSENSE ); + +if (ret <0 ) +return ret; + +if (port <=1 ) + tlim_reg =LTC4266_REG_TLIM12 ; +else + tlim_reg =LTC4266_REG_TLIM34 ; + +if (port &BIT (0 )) + tlim_mask =GENMASK (7 ,4 ); +else + tlim_mask =GENMASK (3 ,0 ); +
drivers/net/pse-pd/ltc4266.c line 353
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+ ret =ltc4266_write_reg (ltc4266, tlim_reg,LTC4266_TLIM_VALUE , tlim_mask); +if (ret <0 ) +return ret; + +/* Enable disconnect detect. */ + ret =ltc4266_write_reg (ltc4266,LTC4266_REG_DISENA ,BIT (port),BIT (port)); +if (ret <0 ) +return ret; + +/* Enable detection (low nibble), classification (high nibble) on the port */
This seems to correspond to ETHTOOL_C33_PSE_ADMIN_STATE_ENABLED
Quoted 32 lines
drivers/net/pse-pd/ltc4266.c new file +32
-0+ ret =i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_DETPB , +BIT (port +4 ) |BIT (port)); + +if (ret <0 ) +return ret; + +dev_dbg (ltc4266->dev,"Port %d has been initialized\n" , port); +return 0 ; +} + +static int ltc4266_get_opmode (struct ltc4266 *ltc4266,int port) +{ +int ret; + + ret =i2c_smbus_read_byte_data (ltc4266->client,LTC4266_REG_OPMD ); +if (ret <0 ) +return ret; + +switch (port) { +case 0 : +return FIELD_GET (GENMASK (1 ,0 ), ret); +case 1 : +return FIELD_GET (GENMASK (3 ,2 ), ret); +case 2 : +return FIELD_GET (GENMASK (5 ,4 ), ret); +case 3 : +return FIELD_GET (GENMASK (7 ,6 ), ret); + } +return -EINVAL ; +} + +static int ltc4266_pi_is_enabled (struct pse_controller_dev *pcdev,int id)
drivers/net/pse-pd/ltc4266.c line 395
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+{ +int ret; + struct ltc4266 *ltc4266 = container_of(pcdev, struct ltc4266, pcdev); + + ret =ltc4266_get_opmode (ltc4266, id); +if (ret <0 ) +return ret; + +if (ret ==LTC4266_OPMD_SEMI ) +return 1 ;/* If a port is in OPMODE SEMI, we'll just assume admin has it enabled */
From HW perspective, every mode except of LTC4266_OPMD_SHUTDOWN can be seen as admin state enabled. LTC4266_OPMD_MANUAL - is forced mode controlling power delivery manually.
I need to make stop here, i'll try to review the rest later.
Regards,
Oleksij
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
Re: [RFC PATCH net-next 2/2] net: pse-pd: Add LTC4266 PSE controller driver
Quoted 6 lines · Oleksij Rempel
Hi Kyle,
thank you for your work!
Are there any way to get manual with register description? I would like to make a deeper review :)
Yes, but unfortunately I think you'll need to make an account on the Analog Devices website and go through the "Request Software" process for what they call the "Software Interface" datasheet.
Quoted 4 lines · Kyle Swenson
Quoted 3 lines
Add a new driver for the Linear Technology LTC4266 I2C Power Sourcing Equipment controller. This driver integrates with the current PSE controller core, implementing IEEE802.3af and IEEE802.3at PSE standards.
[snip]
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c line 73
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+#define LTC4266_TLIM_VALUE 0x01 + +/* LTC4266_REG_HPEN, enable "High Power" mode (i.e. Type 2, 25.4W PDs) */ Type 2 Class 4? Probably not, datasheet claims:
"Supports Proprietary Power Levels Above 25W"
Yes, Type 2 in this context means a Class 4 device. I think the comment in the datasheet is referring to the "4-Point PD detection circuitry" but it's a little unclear. That said, I've no intent in supporting these proprietary power levels unless they're the same as what's described in the IEEE spec.
Quoted 8 lines
Quoted 8 lines
drivers/net/pse-pd/ltc4266.c new file +8
-0+#define LTC4266_HPEN (_p) BIT(_p) + +/* LTC4266_REG_MCONF */ +#define LTC4266_MCONF_INTERRUPT_ENABLE BIT(7) + +/* LTC4266_REG_STATPWR */ +#define LTC4266_STATPWR_PG (_p) BIT((_p) + 4) +#define LTC4266_STATPWR_PE (_p) BIT(_p)
Quoted 8 lines
drivers/net/pse-pd/ltc4266.c line 87
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+#define LTC4266_PORT_CLASS (_stat) FIELD_GET(GENMASK(6, 4), (_stat)) + +#define LTC4266_REG_ICUT_HP (_p) (LTC4266_REG_HPMD(_p) + 1) + +/* if R_sense = 0.25 Ohm, this should be set otherwise 0 */ +#define LTC4266_ICUT_RSENSE BIT(7)
LTC4266_ICUT_RSENSE_025_OHM
Ack. I'll also fix up the indentation that's (now) obviously misaligned.
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c line 94
Quoted 7 lines
drivers/net/pse-pd/ltc4266.c new file +7
-0+/* if set, halve the range and double the precision */ +#define LTC4266_ICUT_RANGE BIT(6) + +#define LTC4266_ILIM_AF_RSENSE_025 0x80 +#define LTC4266_ILIM_AF_RSENSE_050 0x00 +#define LTC4266_ILIM_AT_RSENSE_025 0xC0 +#define LTC4266_ILIM_AT_RSENSE_050 0x40Consider renaming constants AF/AT mentions.
Quoted 2 lines
Replace _AF_ with _TYPE1_ (e.g.,
LTC4266_ILIM_TYPE1_RSENSE_025) Replace _AT_ with _TYPE2_ (e.g.,LTC4266_ILIM_TYPE2_RSENSE_025)
Sounds good, will do.
Quoted 6 lines
The terms "Type 1" and "Type 2" are how the official IEEE 802.3 standard refers to the PoE capabilities and power levels that were introduced by the 802.3af and 802.3at amendments, respectively. Using "Type1" and "Type2" in your code will make it clearer and more aligned with the current, consolidated IEEE terminology, which is helpful since direct access to the original "af" and "at" amendment documents can be challenging for the open-source community.
Ah, makes sense. I'll change AF/AT related bits to Type 1 and Type 2.
Quoted 1 line
Do you have access to this amendments?
I don't have them currently, but I'll ask around my organization and see if I can get access.
Quoted 20 lines
Quoted 20 lines
drivers/net/pse-pd/ltc4266.c new file +20
-0+/* LTC4266_REG_INTSTAT and LTC4266_REG_INTMASK */ +#define LTC4266_INT_SUPPLY BIT(7) +#define LTC4266_INT_TSTART BIT(6) +#define LTC4266_INT_TCUT BIT(5) +#define LTC4266_INT_CLASS BIT(4) +#define LTC4266_INT_DET BIT(3) +#define LTC4266_INT_DIS BIT(2) +#define LTC4266_INT_PWRGD BIT(1) +#define LTC4266_INT_PWRENA BIT(0) + +#define LTC4266_MAX_PORTS 4 + +/* Maximum and minimum power limits for a single port */ +#define LTC4266_PW_LIMIT_MAX 25400 +#define LTC4266_PW_LIMIT_MIN 1 + +enum { +READ_CURRENT =0 , +READ_VOLTAGE =2 +};
Quoted 8 lines
drivers/net/pse-pd/ltc4266.c line 121
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+ +enum { +LTC4266_OPMD_SHUTDOWN =0 , +LTC4266_OPMD_MANUAL , +LTC4266_OPMD_SEMI , +LTC4266_OPMD_AUTO Please add explanations to this port modes
Will do, I see now the confusion this has caused. Sorry for that.
Quoted 11 lines
Quoted 11 lines
drivers/net/pse-pd/ltc4266.c new file +11
-0+}; + +/* Map LTC4266 Classification result to PD class */ +static int ltc4266_class_map[] = { +0 ,/* Treat as class 3 */ +1 , +2 , +3 , +4 , + -EINVAL , +3 ,/* Treat as class 3 */
Quoted 8 lines
drivers/net/pse-pd/ltc4266.c line 138
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+ -ERANGE +}; + +/* Convert a class 0-4 to icut register value */ +static int ltc4266_class_to_icut[] = { +375 ,missing comment, index 0 is class 3.
Ack.
Quoted 9 lines
drivers/net/pse-pd/ltc4266.c line 143
Quoted 5 lines
drivers/net/pse-pd/ltc4266.c new file +5
-0+112 , +206 , +375 , + 638 +};May be we should have a generic function in the framework providing conversion from class to min/max Icut and Ilim, otherwise it makes additional work validation this values.
Sure, I'm open to something like this, even more so if other PSE chipsets use a current limit instead of a power limit.
Quoted 22 lines
Quoted 22 lines
drivers/net/pse-pd/ltc4266.c new file +22
-0+ +enum sense_resistor { +LTC4266_RSENSE_500 ,/* Rsense 0.5 Ohm */ +LTC4266_RSENSE_250 /* Rsense 0.25 Ohm */ +}; + +struct ltc4266_port { +enum sense_resistor rsense; +struct device_node *node; +int current_limit; +}; + +struct ltc4266 { +struct i2c_client *client; +struct mutex lock;/* Protect Read-Modify-Write Sequences */ +struct ltc4266_port *ports[LTC4266_MAX_PORTS ]; +struct device *dev; +struct device_node *np; +struct pse_controller_dev pcdev; +}; + +/* Read-modify-write sequence with value and mask. Mask is expected to be
Quoted 8 lines
Quoted 3 lines
+ * shifted to the correct spot.
+ */
+static intltc4266_write_reg(struct ltc4266 *ltc4266, u8 reg, u8 value, u8 mask)If it is Read-modify-write type of function, it would be better to name it
ltc4266_rmw_reg(). Or use regmap instead, you will get some extra
functionality: register dump over sysfs interface, range validation, caching if enabled, locking, etc.
Oh, good call- I'll use regmap.
Quoted 47 lines
Quoted 32 lines
drivers/net/pse-pd/ltc4266.c new file +32
-0+{ +int ret; +u8 new; + +mutex_lock (<c4266->lock); + ret =i2c_smbus_read_byte_data (ltc4266->client, reg); +if (ret <0 ) { +dev_warn (ltc4266->dev,"Failed to read register 0x%02x, err=%d\n" , reg, ret); +mutex_unlock (<c4266->lock); +return ret; + } + new = (u8 )ret; + new &= ~mask; + new |= value & mask; + ret =i2c_smbus_write_byte_data (ltc4266->client, reg, new); +mutex_unlock (<c4266->lock); + +return ret; +} + +static int ltc4266_read_iv (struct ltc4266 *ltc4266,int port,u8 iv) +{ +int lsb; +int msb; +int result; +int lsb_reg; +u64 ivbits =0 ; + +if (iv ==READ_CURRENT ) + lsb_reg =LTC4266_IPLSB_REG (port); +else if (iv ==READ_VOLTAGE ) + lsb_reg =LTC4266_VPLSB_REG (port);drivers/net/pse-pd/ltc4266.c line 210
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+else +return -EINVAL ; + + result =i2c_smbus_read_byte_data (ltc4266->client,LTC4266_REG_STATPWR ); +if (result <0 ) +return result; + +/* LTC4266 IV readings are only valid if the port is powered. */ +if (!(result <C4266_STATPWR_PG (port))) +return -EINVAL ;We have two states:
- admin enabled: admin enabled state
- delivering power: PSE is actually delivering power
Quoted 1 line
Please use this words to clarify what is actually happening.
Will do.
Quoted 7 lines
drivers/net/pse-pd/ltc4266.c line 216
Quoted 5 lines
drivers/net/pse-pd/ltc4266.c new file +5
-0+/* LTC4266 expects the MSB register to be read immediately following the LSB +* register, so we need to ensure other parts aren't reading other registers in +* this chip while we read the current/voltage regulators. +*/ +mutex_lock (<c4266->lock);please use guard* variants for locking.
Ack.
Quoted 111 lines
Quoted 35 lines
drivers/net/pse-pd/ltc4266.c new file +33
-0+ + lsb =i2c_smbus_read_byte_data (ltc4266->client, lsb_reg); + msb =i2c_smbus_read_byte_data (ltc4266->client, lsb_reg +1 ); + +mutex_unlock (<c4266->lock); + +if (lsb <0 ) +return lsb; + +if (msb <0 ) +return msb; + + ivbits =0 ; + ivbits |= ((u8 )msb) <<8 | ((u8 )lsb); + +if (iv ==READ_CURRENT ) +if (ltc4266->ports[port]->rsense ==LTC4266_RSENSE_250 )/* 122.07 uA/LSB */ + result =DIV_ROUND_CLOSEST_ULL ((ivbits *122070 ),1000 ); +else /* 61.035 uA/LSB */ + result =DIV_ROUND_CLOSEST_ULL ((ivbits *61035 ),1000 ); +else /* 5.835 mV/LSB == 5835 uV/LSB */ + result = ivbits *5835 ; + +return result; +} +static int ltc4266_port_set_ilim (struct ltc4266 *ltc4266,int port,int class) +{ +if (class >4 || class <0 ) +return -EINVAL ; + +/* We want to set 425 mA for class 3 and lower; 850 mA otherwise for IEEE compliance */ +if (class <4 ) { +/* Write 0x80 for 0.25 Ohm sense otherwise 0 */ drivers/net/pse-pd/ltc4266.c line 260
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c new file +10
-0+if (ltc4266->ports[port]->rsense ==LTC4266_RSENSE_250 ) +return i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_ILIM (port),LTC4266_ILIM_AF_RSENSE_025 ); +return i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_ILIM (port),LTC4266_ILIM_AF_RSENSE_050 ); + } + +/* Class == 4 */ +if (ltc4266->ports[port]->rsense ==LTC4266_RSENSE_250 ) +return i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_ILIM (port),LTC4266_ILIM_AT_RSENSE_025 ); +/* Class == 4 and the sense resistor is 0.5 */ +return i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_ILIM (port),LTC4266_ILIM_AT_RSENSE_050 );May be something like this:
/*
*ltc4266_port_set_ilim- Set the active current limit (ILIM) for a port.
* @ltc4266: Pointer to the LTC4266 device structure.
* @port: The port number (0-3).
* @class: The detected PD class (0-4).
*
* This function configures the ILIM register (0x48,0x4D,0x52,0x57)
* of the LTC4266. The ILIM value determines the threshold at which the
* PSE actively limits current to the PD. The chosen values are based on
* IEEE Std 802.3-2022 requirements and typical operational values for the
* LTC4266 controller.
*
* IEEE Std 802.3-2022, Table 33-11 specifies ILIM parameter ranges:
* - For Type 1 PSE operation (typically PD Classes 0-3):
* The minimum ILIM is 0.400A. This driver uses 425mA. This value fits
* within typical Type 1 ILIM specifications (e.g., 0.400A min to
* around 0.440A-0.500A max for the programmed steady-state limit).
*
* - For Type 2 PSE operation (typically PD Class 4):
* The minimum ILIM is 1.14 * ICable (or ~1.05 *IPort_maxfrom other
* interpretations, e.g., ~0.630A to ~0.684A). This driver uses 850mA.
* This value meets the minimum requirement and is a supported operational
* current limit for high power modes in the LTC4266.
*
* The overall PSE current output must not exceed the time-dependent PSE
* upperbound template, IPSEUT(t), described in IEEE Std 802.3-2022,
* Equation (33-6). The programmed ILIM values (425mA/850mA) serve as the
* long-term current limit (Ilimmin segment of IPSEUT(t)) and are well
* within the higher short-term current allowances of that template (e.g., 1.75A). *
* The specific register values written depend on the sense resistor
* (0.25 Ohm or 0.50 Ohm) as detailed in the LTC4266 datasheet (Table 5). *
* Returns: ...
*/
static intltc4266_port_set_ilim(struct ltc4266 *ltc4266, int port, int class){ u8 ilim_reg_val; if (class > 4 || class < 0) return -EINVAL; if (class < 4) { /* PD Class is 0, 1, 2, or 3 (Type 1 PSE operation). * Set ILIM to 425mA. */ if (ltc4266->ports[port]->rsense == LTC4266_RSENSE_250) { /* Using 0.25 Ohm sense resistor. */ ilim_reg_val = LTC4266_ILIM_TYPE1_RSENSE_025; } else { /* Using 0.50 Ohm sense resistor. */ ilim_reg_val = LTC4266_ILIM_TYPE1_RSENSE_050; } } else { /* PD Class is 4 (Type 2 PSE operation). * Set ILIM to 850mA. */ if (ltc4266->ports[port]->rsense == LTC4266_RSENSE_250) { /* Using 0.25 Ohm sense resistor. */ ilim_reg_val = LTC4266_ILIM_TYPE2_RSENSE_025; } else { /* Using 0.50 Ohm sense resistor. */ ilim_reg_val = LTC4266_ILIM_TYPE2_RSENSE_050; }
Quoted 8 lines
} /* Write the determined ILIM value to the appropriate port's ILIM register. * The LTC4266_REG_ILIM(port) macro resolves to the correct register * address for the given port (e.g., 0x48 for port 0, 0x4D for port 1, etc.). */ return i2c_smbus_write_byte_data(ltc4266->client, LTC4266_REG_ILIM(port), ilim_reg_val); }
Wow, that is much more clear. Thanks so much, I'll change accordingly.
Quoted 11 lines
drivers/net/pse-pd/ltc4266.c line 267
Quoted 5 lines
drivers/net/pse-pd/ltc4266.c new file +5
-0+static int ltc4266_port_set_icut (struct ltc4266 *ltc4266,int port,int icut) +{ +u8 val; + +if (icut >850 )It looks like board specific limit:
From the LTC4266 datasheet:
"Non-standard applications that provide more current
than the 850mA IEEE maximum may require heat sinking and other MOSFET design considerations."
Yes, it is board specific but also sounded to me like above 850mA would violate the spec.
Quoted 9 lines
drivers/net/pse-pd/ltc4266.c line 270
Quoted 3 lines
drivers/net/pse-pd/ltc4266.c new file +3
-0+return -ERANGE ; + + val = (u8)(DIV_ROUND_CLOSEST ((icut *1000 ),18750 ) &0x3F );I assume 18750 micro Amp, per step in the register value and
0x3fis the max mask for the bit field. In this case this register supports0x3f* 18750 / 1000 = 1181mAPlease use defines to make it readable.
Will do. I'll do this for all the other current/voltage conversions as well.
Quoted 11 lines
Quoted 11 lines
drivers/net/pse-pd/ltc4266.c new file +11
-0+ +if (ltc4266->ports[port]->rsense ==LTC4266_RSENSE_250 ) + val |=LTC4266_ICUT_RSENSE |LTC4266_ICUT_RANGE ; + +return i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_ICUT_HP (port), val); +} + +static int ltc4266_port_mode (struct ltc4266 *ltc4266,int port,u8 opmd) +{ +if (opmd >=LTC4266_OPMD_AUTO ) +return -EINVAL ;
Quoted 8 lines
drivers/net/pse-pd/ltc4266.c line 287
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+ +return ltc4266_write_reg (ltc4266,LTC4266_REG_OPMD ,TWO_BIT_WORD_OFFSET (opmd, port), +TWO_BIT_WORD_MASK (port)); +} + +static int ltc4266_port_powered (struct ltc4266 *ltc4266,int port)delivering or enabled?
Delivering. I'll change this per your earlier comment.
Quoted 15 lines
Quoted 15 lines
drivers/net/pse-pd/ltc4266.c new file +15
-0+{ +int result =i2c_smbus_read_byte_data (ltc4266->client,LTC4266_REG_STATPWR ); + +if (result <0 ) +return result; + +return !!((result <C4266_STATPWR_PG (port)) && (result <C4266_STATPWR_PE (port))); +} + +static int ltc4266_port_init (struct ltc4266 *ltc4266,int port) +{ +int ret; +u8 tlim_reg; +u8 tlim_mask; +
Quoted 8 lines
drivers/net/pse-pd/ltc4266.c line 308
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+/* Reset the port */ + ret =i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_RSTPB ,BIT (port)); +if (ret <0 ) +return ret; + + ret =ltc4266_port_mode (ltc4266, port,LTC4266_OPMD_SEMI );Should we have disabled mode before all current limits configured?
Well, OPMD_SEMI means "Semi-Automatic" mode, which will detect and classify connected PDs but not power them until instructed to do so by software.
Quoted 7 lines
drivers/net/pse-pd/ltc4266.c line 312
Quoted 4 lines
drivers/net/pse-pd/ltc4266.c new file +4
-0+if (ret <0 ) +return ret; + +/* Enable high power mode on the port (802.3at+) */ 802.3at+? "Proprietary Power Levels Above 25W"?. Here we will need a discussion how to reflect a Proprietary Power levels in the UAPI.
I don't know there is value in this discussion because a) I don't know what the datasheet is referring to about these "Proprietary Power Levels" and b) I'm not really interested in adding support for any proprietary power levels because I can't test them. The LTC4266 can power Type 1 and Type 2 PDs. There is a support for high-capacitance devices (seen in really old Cisco IP Phones), but this support I left (or intended to) disabled because I can't test that, either.
Quoted 10 lines
drivers/net/pse-pd/ltc4266.c line 318
Quoted 7 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+ ret =ltc4266_write_reg (ltc4266,LTC4266_REG_HPEN , +LTC4266_HPEN (port),LTC4266_HPEN (port)); +if (ret <0 ) +return ret; + +/* Enable Ping-Pong Classification */ This is probably "2-event classification" described in Clause 33 of the IEEE Std 802.3-2022.
Yes, this is exactly that.
Quoted 30 lines
Quoted 30 lines
drivers/net/pse-pd/ltc4266.c new file +29
-0+ ret =ltc4266_write_reg (ltc4266,LTC4266_REG_HPMD (port), +LTC4266_HPMD_PONGEN ,LTC4266_HPMD_PONGEN ); +if (ret <0 ) +return ret; + +if (ltc4266->ports[port]->rsense ==LTC4266_RSENSE_250 ) + ret =ltc4266_write_reg (ltc4266,LTC4266_REG_ICUT_HP (port), +LTC4266_ICUT_RSENSE ,LTC4266_ICUT_RSENSE ); +else + ret =ltc4266_write_reg (ltc4266,LTC4266_REG_ICUT_HP (port), +0 ,LTC4266_ICUT_RSENSE ); + +if (ret <0 ) +return ret; + +if (port <=1 ) + tlim_reg =LTC4266_REG_TLIM12 ; +else + tlim_reg =LTC4266_REG_TLIM34 ; + +if (port &BIT (0 )) + tlim_mask =GENMASK (7 ,4 ); +else + tlim_mask =GENMASK (3 ,0 ); + + ret =ltc4266_write_reg (ltc4266, tlim_reg,LTC4266_TLIM_VALUE , tlim_mask); +if (ret <0 ) +return ret; +
Quoted 8 lines
drivers/net/pse-pd/ltc4266.c line 353
Quoted 6 lines
drivers/net/pse-pd/ltc4266.c new file +6
-0+/* Enable disconnect detect. */ + ret =ltc4266_write_reg (ltc4266,LTC4266_REG_DISENA ,BIT (port),BIT (port)); +if (ret <0 ) +return ret; + +/* Enable detection (low nibble), classification (high nibble) on the port */ This seems to correspond to
ETHTOOL_C33_PSE_ADMIN_STATE_ENABLED
Yes, the combination of OPMD_SEMI, PD Detection enabled and PD classification enabled corresponds to ADMIN_STATE_ENABLED.
Quoted 39 lines
Quoted 39 lines
drivers/net/pse-pd/ltc4266.c new file +38
-0+ ret =i2c_smbus_write_byte_data (ltc4266->client,LTC4266_REG_DETPB , +BIT (port +4 ) |BIT (port)); + +if (ret <0 ) +return ret; + +dev_dbg (ltc4266->dev,"Port %d has been initialized\n" , port); +return 0 ; +} + +static int ltc4266_get_opmode (struct ltc4266 *ltc4266,int port) +{ +int ret; + + ret =i2c_smbus_read_byte_data (ltc4266->client,LTC4266_REG_OPMD ); +if (ret <0 ) +return ret; + +switch (port) { +case 0 : +return FIELD_GET (GENMASK (1 ,0 ), ret); +case 1 : +return FIELD_GET (GENMASK (3 ,2 ), ret); +case 2 : +return FIELD_GET (GENMASK (5 ,4 ), ret); +case 3 : +return FIELD_GET (GENMASK (7 ,6 ), ret); + } +return -EINVAL ; +} + +static int ltc4266_pi_is_enabled (struct pse_controller_dev *pcdev,int id) +{ +int ret; + struct ltc4266 *ltc4266 = container_of(pcdev, struct ltc4266, pcdev); + + ret =ltc4266_get_opmode (ltc4266, id); +if (ret <0 )
Quoted 8 lines
drivers/net/pse-pd/ltc4266.c line 395
Quoted 4 lines
drivers/net/pse-pd/ltc4266.c new file +4
-0+return ret; + +if (ret ==LTC4266_OPMD_SEMI ) +return 1 ;/* If a port is in OPMODE SEMI, we'll just assume admin has it enabled */ From HW perspective, every mode except of
LTC4266_OPMD_SHUTDOWNcan be seen as admin state enabled.LTC4266_OPMD_MANUAL- is forced mode controlling power delivery manually.
In V2, I'll add a lot more information in comments and such that describe these modes a little better, but until then:
OPMD_SHUTDOWN means that port is off and will not run any detection or classification cycles regardless of other configuration.
OPMD_MANUAL means the port will run a single detect cycle after the corresponding bit is set; additionally, it will run a single classification cycle after that bit is set. The problem with OPMD_MANUAL is that there is no state enforcement in hardware, meaning software could instruct the PSE to apply power to a port that doesn't have a valid PD attached, and will apply power regardless of the result (if any) from detection/classification. Frankly, OPMD_MANUAL scares me and I see supporting it as only adding risk with no value.
OPMD_SEMI means the chip will detect and classify PDs on enabled ports and will wait until software sets the corresponding bit to power on the port and (critically) only will power on a port with a valid detection and classification result.
OPMD_AUTO requires the chip be powered on with the "auto" pin high, and will automatically detect, classify, and power any valid PD. I don't have a board with this configuration so I've not included that support. It's a little unclear to me what is possible to configure from software when the chip is in this mode.
Quoted 2 lines
I need to make stop here, i'll try to review the rest later.
Thanks so much for the amazing review thus far, I think I've got more than enough to adjust for a V2.
Quoted 2 lines
Regards,
Oleksij
Thanks again,
Kyle