pwm: add support for NXPs high-side switch MC33XS2410
Subsystems (2)
cover pwm: add support for NXPs high-side switch MC33XS2410
The MC33XS2410 is a four channel high-side switch. Featuring advanced monitoring and control function, the device is operational from 3.0 V to 60 V. The device is controlled by SPI port for configuration.
Dimitri Fedrau (3):
dt-bindings: pwm: add support for MC33XS2410
pwm: add support for NXPs high-side switch MC33XS2410
pwm: mc33xs2410: add support for direct inputs
.../bindings/pwm/nxp,mc33xs2410.yaml | 105 +++++ drivers/pwm/Kconfig | 12 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-mc33xs2410.c | 418 ++++++++++++++++++ 4 files changed, 536 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml create mode 100644 drivers/pwm/pwm-mc33xs2410.c
Signature · 1 line
2.39.2
PATCH 1/3 dt-bindings: pwm: add support for MC33XS2410
Adding documentation for MC33XS2410 pwm driver.
--- .../bindings/pwm/nxp,mc33xs2410.yaml | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +105 -0
@@ -0,0 +1,105 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pwm/nxp,mc33xs2410.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MC33XS2410 PWM driver + +maintainers: + - Dimitri Fedrau <[email protected]> + +allOf: + - $ref: pwm.yaml# + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +properties: + compatible: + const: nxp,mc33xs2410 + + reg: + maxItems: 1 + + spi-max-frequency: + maximum: 10000000 + + spi-cpha: true + + spi-cs-setup-delay-ns: + minimum: 100 + default: 100 + + spi-cs-hold-delay-ns: + minimum: 10 + default: 10 + + spi-cs-inactive-delay-ns: + minimum: 300 + default: 300 + + reset-gpios: + description: + GPIO connected to the active low reset pin. + maxItems: 1 + + "#pwm-cells": + const: 3 + + pwms: + description: + Direct inputs(di0-3) are used to directly turn-on or turn-off the + outputs. The external PWM clock can be used if the internal clock + doesn't meet timing requirements. + maxItems: 5 + + pwm-names: + items: + - const: di0 + - const: di1 + - const: di2 + - const: di3 + - const: ext_clk + + vdd-supply: + description: + Logic supply voltage + + vspi-supply: + description: + Supply voltage for SPI + + vpwr-supply: + description: + Power switch supply + + interrupts: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false + +examples: + - | + #include <dt-bindings/gpio/gpio.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + pwm@0 { + compatible = "nxp,mc33xs2410"; + reg = <0x0>; + spi-max-frequency = <4000000>; + spi-cpha; + spi-cs-setup-delay-ns = <100>; + spi-cs-hold-delay-ns = <10>; + spi-cs-inactive-delay-ns = <300>; + reset-gpios = <&gpio3 22 GPIO_ACTIVE_LOW>; + #pwm-cells = <3>; + vdd-supply = <®_3v3>; + vspi-supply = <®_3v3>; + vpwr-supply = <®_24v0>; + }; + };
Signature · 1 line
2.39.2
PATCH 2/3 pwm: add support for NXPs high-side switch MC33XS2410
In reply to Dimitri FedrauThe MC33XS2410 is a four channel high-side switch. Featuring advanced monitoring and control function, the device is operational from 3.0 V to 60 V. The device is controlled by SPI port for configuration.
--- drivers/pwm/Kconfig | 12 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-mc33xs2410.c | 324 +++++++++++++++++++++++++++++++++++ 3 files changed, 337 insertions(+) create mode 100644 drivers/pwm/pwm-mc33xs2410.c
drivers/pwm/Kconfig +12 -0
@@ -384,6 +384,18 @@ config PWM_LPSS_PLATFORM To compile this driver as a module, choose M here: the module will be called pwm-lpss-platform. +config PWM_MC33XS2410 + tristate "MC33XS2410 PWM support" + depends on OF + depends on SPI + help + NXP MC33XS2410 high-side switch driver. The MC33XS2410 is a four + channel high-side switch. The device is operational from 3.0 V + to 60 V. The device is controlled by SPI port for configuration. + + To compile this driver as a module, choose M here: the module + will be called pwm-mc33xs2410. + config PWM_MESON tristate "Amlogic Meson PWM driver" depends on ARCH_MESON || COMPILE_TEST
drivers/pwm/Makefile +1 -0
@@ -34,6 +34,7 @@ obj-$(CONFIG_PWM_LPC32XX) += pwm-lpc32xx.o obj-$(CONFIG_PWM_LPSS) += pwm-lpss.o obj-$(CONFIG_PWM_LPSS_PCI) += pwm-lpss-pci.o obj-$(CONFIG_PWM_LPSS_PLATFORM) += pwm-lpss-platform.o +obj-$(CONFIG_PWM_MC33XS2410) += pwm-mc33xs2410.o obj-$(CONFIG_PWM_MESON) += pwm-meson.o obj-$(CONFIG_PWM_MEDIATEK) += pwm-mediatek.o obj-$(CONFIG_PWM_MICROCHIP_CORE) += pwm-microchip-core.o
drivers/pwm/pwm-mc33xs2410.c new file +324 -0
324 lines not on this page · raw message
Signature · 1 line
2.39.2
PATCH 3/3 pwm: mc33xs2410: add support for direct inputs
In reply to Dimitri FedrauAdd support for direct inputs, which are used to directly turn-on or turn-off the outputs. Direct inputs have the advantage over the SPI controlled outputs that they aren't limited to the frequency steps. Frequency resolution depends on the input signal, range is still from 0.5Hz to 2.048kHz.
--- drivers/pwm/pwm-mc33xs2410.c | 116 +++++++++++++++++++++++++++++++---- 1 file changed, 105 insertions(+), 11 deletions(-)
drivers/pwm/pwm-mc33xs2410.c +105 -11
@@ -18,7 +18,10 @@#define MC33XS2410_GLB_CTRL_MODE_MASK GENMASK(7, 6)#define MC33XS2410_GLB_CTRL_NORMAL_MODE BIT(6)#define MC33XS2410_GLB_CTRL_SAFE_MODE BIT(7) +#define MC33XS2410_GLB_CTRL_CMOS_LEVEL BIT(0)#define MC33XS2410_OUT1_4_CTRL 0x02 +#define MC33XS2410_IN_CTRL1 0x03 +#define MC33XS2410_IN_CTRL1_IN_EN (x) BIT(x)#define MC33XS2410_PWM_CTRL1 0x05#define MC33XS2410_PWM_CTRL1_POL_INV (x) BIT(x)#define MC33XS2410_PWM_CTRL3 0x07
@@ -45,6 +48,7 @@struct mc33xs2410_pwm {struct pwm_chip chip;struct spi_device *spi; +struct pwm_device *di[4 ];struct mutex lock; };
@@ -154,20 +158,15 @@ static u8 mc33xs2410_pwm_get_freq(const struct pwm_state *state)return (ret |FIELD_PREP (MC33XS2410_PWM_FREQ_STEP_MASK , step)); } -static int mc33xs2410_pwm_apply (struct pwm_chip *chip,struct pwm_device *pwm, -const struct pwm_state *state) +static int mc33xs2410_pwm_apply_spi (struct pwm_chip *chip, +struct pwm_device *pwm, +const struct pwm_state *state) {struct mc33xs2410_pwm *mc33xs2410 =mc33xs2410_pwm_from_chip (chip);struct spi_device *spi = mc33xs2410->spi;u8 mask, val;int ret; -if (state->period > mc33xs2410_period[STEP_05HZ ][MC33XS2410_PERIOD_MAX ]) -return -EINVAL ; - -if (state->period < mc33xs2410_period[STEP_32HZ ][MC33XS2410_PERIOD_MIN ]) -return -EINVAL ; -guard (mutex)(&mc33xs2410->lock); mask =MC33XS2410_PWM_CTRL1_POL_INV (pwm->hwpwm); val = (state->polarity ==PWM_POLARITY_INVERSED ) ? mask :0 ;
@@ -190,9 +189,38 @@ static int mc33xs2410_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm,return mc33xs2410_modify_reg (spi,MC33XS2410_PWM_CTRL3 , mask, val); } -static int mc33xs2410_pwm_get_state (struct pwm_chip *chip, -struct pwm_device *pwm, -struct pwm_state *state) +static int mc33xs2410_pwm_apply_direct_inputs (struct pwm_chip *chip, +struct pwm_device *pwm, +const struct pwm_state *state) +{ +struct mc33xs2410_pwm *mc33xs2410 =mc33xs2410_pwm_from_chip (chip); +struct pwm_device *di = mc33xs2410->di[pwm->hwpwm]; + +guard (mutex)(&mc33xs2410->lock); + +return pwm_apply_state (di, state); +} + +static int mc33xs2410_pwm_apply (struct pwm_chip *chip,struct pwm_device *pwm, +const struct pwm_state *state) +{ +struct mc33xs2410_pwm *mc33xs2410 =mc33xs2410_pwm_from_chip (chip); + +if (state->period > mc33xs2410_period[STEP_05HZ ][MC33XS2410_PERIOD_MAX ]) +return -EINVAL ; + +if (state->period < mc33xs2410_period[STEP_32HZ ][MC33XS2410_PERIOD_MIN ]) +return -EINVAL ; + +if (mc33xs2410->di[pwm->hwpwm]) +return mc33xs2410_pwm_apply_direct_inputs (chip, pwm, state); +else +return mc33xs2410_pwm_apply_spi (chip, pwm, state); +} + +static int mc33xs2410_pwm_get_state_spi (struct pwm_chip *chip, +struct pwm_device *pwm, +struct pwm_state *state) {struct mc33xs2410_pwm *mc33xs2410 =mc33xs2410_pwm_from_chip (chip);struct spi_device *spi = mc33xs2410->spi;
@@ -236,6 +264,28 @@ static int mc33xs2410_pwm_get_state(struct pwm_chip *chip,return 0 ; } +static int mc33xs2410_pwm_get_state_direct_inputs (struct pwm_chip *chip, +struct pwm_device *pwm, +struct pwm_state *state) +{ +struct mc33xs2410_pwm *mc33xs2410 =mc33xs2410_pwm_from_chip (chip); + +pwm_get_state (mc33xs2410->di[pwm->hwpwm], state); +return 0 ; +} + +static int mc33xs2410_pwm_get_state (struct pwm_chip *chip, +struct pwm_device *pwm, +struct pwm_state *state) +{ +struct mc33xs2410_pwm *mc33xs2410 =mc33xs2410_pwm_from_chip (chip); + +if (mc33xs2410->di[pwm->hwpwm]) +return mc33xs2410_pwm_get_state_direct_inputs (chip, pwm, state); +else +return mc33xs2410_pwm_get_state_spi (chip, pwm, state); +} +static const struct pwm_ops mc33xs2410_pwm_ops = { .apply = mc33xs2410_pwm_apply, .get_state = mc33xs2410_pwm_get_state,
@@ -257,6 +307,45 @@ static int mc33xs2410_reset(struct device *dev)return 0 ; } +static int mc33xs2410_direct_inputs_probe (struct mc33xs2410_pwm *mc33xs2410) +{ +struct device *dev = &mc33xs2410->spi->dev; +u16 di_en =0 ; +char buf[4 ]; +int ret, ch; + +for (ch =0 ; ch <4 ; ch++) { +sprintf (buf,"di%d" , ch); + mc33xs2410->di[ch] =devm_pwm_get (dev, buf); + ret =PTR_ERR_OR_ZERO (mc33xs2410->di[ch]); +switch (ret) { +case 0 : + di_en |=MC33XS2410_IN_CTRL1_IN_EN (ch); +break ; +case -ENODATA : + mc33xs2410->di[ch] =NULL ; +break ; +case -EPROBE_DEFER : +return ret; +default : +dev_err (dev,"Failed to request %s: %d\n" , buf, ret); +return ret; + } + } + +if (!di_en) +return 0 ; + +/* CMOS input logic level */ + ret =mc33xs2410_modify_reg (mc33xs2410->spi,MC33XS2410_GLB_CTRL , +MC33XS2410_GLB_CTRL_CMOS_LEVEL , +MC33XS2410_GLB_CTRL_CMOS_LEVEL ); +if (ret <0 ) +return ret; + +return mc33xs2410_write_reg (mc33xs2410->spi,MC33XS2410_IN_CTRL1 , di_en); +} +static int mc33xs2410_probe (struct spi_device *spi) {struct mc33xs2410_pwm *mc33xs2410;
@@ -290,6 +379,11 @@ static int mc33xs2410_probe(struct spi_device *spi)return dev_err_probe (dev, ret,"Failed to transition to normal mode\n" ); +/* Enable direct inputs */ + ret =mc33xs2410_direct_inputs_probe (mc33xs2410); +if (ret) +return ret; + ret =devm_pwmchip_add (dev, &mc33xs2410->chip);if (ret <0 )return dev_err_probe (dev, ret,"Failed to add pwm chip\n" );
Signature · 1 line
2.39.2
Re: [PATCH 1/3] dt-bindings: pwm: add support for MC33XS2410
In reply to Dimitri FedrauQuoted 1 line · Dimitri Fedrau
Adding documentation for MC33XS2410 pwm driver.
Driver as Linux driver? If so, please rephrase to describe hardware.
Quoted 13 lines
Signed-off-by Dimitri Fedrau <[email protected]>--- .../bindings/pwm/nxp,mc33xs2410.yaml | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yamlDocumentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +0
-0
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml line 7
Quoted 7 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +7
-0@@ -0,0 +1,105 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pwm/nxp,mc33xs2410.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MC33XS2410 PWM driver
Driver as Linux driver? If so, please rephrase to describe hardware.
Quoted 35 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +35
-0+ +maintainers: + - Dimitri Fedrau <[email protected]> + +allOf: + - $ref: pwm.yaml# + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +properties: + compatible: + const: nxp,mc33xs2410 + + reg: + maxItems: 1 + + spi-max-frequency: + maximum: 10000000 + + spi-cpha: true + + spi-cs-setup-delay-ns: + minimum: 100 + default: 100 + + spi-cs-hold-delay-ns: + minimum: 10 + default: 10 + + spi-cs-inactive-delay-ns: + minimum: 300 + default: 300 + + reset-gpios: + description: + GPIO connected to the active low reset pin.
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml line 52
Quoted 10 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +10
-0+ maxItems: 1 + + "#pwm-cells": + const: 3 + + pwms: + description: + Direct inputs(di0-3) are used to directly turn-on or turn-off the + outputs. The external PWM clock can be used if the internal clock + doesn't meet timing requirements.
pwm is input for pwm?
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml line 61
Quoted 9 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +9
-0+ maxItems: 5 + + pwm-names: + items: + - const: di0 + - const: di1 + - const: di2 + - const: di3 + - const: ext_clk
Aren't these clocks?
Quoted 11 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +11
-0+ + vdd-supply: + description: + Logic supply voltage + + vspi-supply: + description: + Supply voltage for SPI + + vpwr-supply: + description:
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml line 82
Quoted 10 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +10
-0+ Power switch supply + + interrupts: + maxItems: 1 + +required: + - compatible + - reg + +additionalProperties: false
Instead:
unevaluatedProperties: false
Quoted 8 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +8
-0+ +examples: + - | + #include <dt-bindings/gpio/gpio.h> + spi { + #address-cells = <1>; + #size-cells = <0>; +
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml line 100
Quoted 10 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +10
-0+ pwm@0 { + compatible = "nxp,mc33xs2410"; + reg = <0x0>; + spi-max-frequency = <4000000>; + spi-cpha; + spi-cs-setup-delay-ns = <100>; + spi-cs-hold-delay-ns = <10>; + spi-cs-inactive-delay-ns = <300>; + reset-gpios = <&gpio3 22 GPIO_ACTIVE_LOW>; + #pwm-cells = <3>;
Make example complete, so provide all properties, like interrupts, pwms and whatever you have in the binding.
Best regards,
Krzysztof
Re: [PATCH 1/3] dt-bindings: pwm: add support for MC33XS2410
Am Wed, Feb 28, 2024 at 02:59:48PM +0100 schrieb Krzysztof Kozlowski:
Quoted 5 lines · Dimitri Fedrau
Quoted 1 line
Adding documentation for MC33XS2410 pwm driver.
Driver as Linux driver? If so, please rephrase to describe hardware.
Will fix it.
Quoted 7 lines
Quoted 7 lines
Signed-off-by Dimitri Fedrau <[email protected]>--- .../bindings/pwm/nxp,mc33xs2410.yaml | 105 ++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml
Quoted 16 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml line 7
Quoted 13 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +7
-0@@ -0,0 +1,105 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/pwm/nxp,mc33xs2410.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MC33XS2410 PWM driverDriver as Linux driver? If so, please rephrase to describe hardware.
Will fix it.
Quoted 39 lines
Quoted 39 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +39
-0+ +maintainers: + - Dimitri Fedrau <[email protected]> + +allOf: + - $ref: pwm.yaml# + - $ref: /schemas/spi/spi-peripheral-props.yaml# + +properties: + compatible: + const: nxp,mc33xs2410 + + reg: + maxItems: 1 + + spi-max-frequency: + maximum: 10000000 + + spi-cpha: true + + spi-cs-setup-delay-ns: + minimum: 100 + default: 100 + + spi-cs-hold-delay-ns: + minimum: 10 + default: 10 + + spi-cs-inactive-delay-ns: + minimum: 300 + default: 300 + + reset-gpios: + description: + GPIO connected to the active low reset pin. + maxItems: 1 + + "#pwm-cells": + const: 3
Quoted 9 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml line 52
Quoted 6 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +6
-0+ + pwms: + description: + Direct inputs(di0-3) are used to directly turn-on or turn-off the + outputs. The external PWM clock can be used if the internal clock + doesn't meet timing requirements.pwm is input for pwm?
Yes.
Quoted 10 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml line 61
Quoted 9 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +9
-0+ maxItems: 5 + + pwm-names: + items: + - const: di0 + - const: di1 + - const: di2 + - const: di3 + - const: ext_clk
Quoted 2 lines
Aren't these clocks?
di0-3 are PWM input signals which are translated to output voltage "vpwr". ext_clk is described as PWM clock in the datasheet. Didn't used it, just mentioned it here for completeness.
Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +16
-0+ + vdd-supply: + description: + Logic supply voltage + + vspi-supply: + description: + Supply voltage for SPI + + vpwr-supply: + description: + Power switch supply + + interrupts: + maxItems: 1 +
Quoted 9 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml line 82
Quoted 5 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +5
-0+required: + - compatible + - reg + +additionalProperties: falseInstead:
unevaluatedProperties: false
Will fix it.
Quoted 13 lines
Quoted 13 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +13
-0+ +examples: + - | + #include <dt-bindings/gpio/gpio.h> + spi { + #address-cells = <1>; + #size-cells = <0>; + + pwm@0 { + compatible = "nxp,mc33xs2410"; + reg = <0x0>; + spi-max-frequency = <4000000>; + spi-cpha;
Quoted 9 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml line 100
Quoted 5 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +5
-0+ spi-cs-setup-delay-ns = <100>; + spi-cs-hold-delay-ns = <10>; + spi-cs-inactive-delay-ns = <300>; + reset-gpios = <&gpio3 22 GPIO_ACTIVE_LOW>; + #pwm-cells = <3>;Make example complete, so provide all properties, like interrupts, pwms and whatever you have in the binding.
I could make the binding complete, but I haven't used all properties nor does the driver supports them.
Quoted 3 lines
Best regards,
Krzysztof
Best regards,
Dimitri
Re: [PATCH 1/3] dt-bindings: pwm: add support for MC33XS2410
Quoted 10 lines · Dimitri Fedrau
Quoted 10 lines
Quoted 9 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +9
-0+ maxItems: 5 + + pwm-names: + items: + - const: di0 + - const: di1 + - const: di2 + - const: di3 + - const: ext_clk
Quoted 5 lines
Quoted 2 lines
Aren't these clocks?
di0-3 are PWM input signals which are translated to output voltage "vpwr".
ext_clkis described as PWM clock in the datasheet. Didn't used it, just mentioned it here for completeness.
Then it looks more like a clock, so clocks: property.
Quoted 5 lines
Quoted 5 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml line 66
Quoted 5 lines
Documentation/devicetree/bindings/pwm/nxp,mc33xs2410.yaml new file +5
-0+ + vdd-supply: + description: + Logic supply voltage +
Best regards,
Krzysztof