Add i.MX7ULP EVK PWM backlight support
Subsystems (4)
v11 cover Add i.MX7ULP EVK PWM backlight support
i.MX7ULP EVK board has MIPI-DSI display, its backlight is supplied by TPM PWM module, this patch set enables i.MX7ULP TPM PWM driver support and also add backlight support for MIPI-DSI display.
Changes since V10:
- ONLY change the pwm driver patch.
Anson Huang (5):
dt-bindings: pwm: Add i.MX TPM PWM binding
pwm: Add i.MX TPM PWM driver support
ARM: imx_v6_v7_defconfig: Add TPM PWM support by default
ARM: dts: imx7ulp: Add tpm pwm support
ARM: dts: imx7ulp-evk: Add backlight support
.../devicetree/bindings/pwm/imx-tpm-pwm.txt | 22 + arch/arm/boot/dts/imx7ulp-evk.dts | 21 + arch/arm/boot/dts/imx7ulp.dtsi | 10 + arch/arm/configs/imx_v6_v7_defconfig | 1 + drivers/pwm/Kconfig | 11 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-imx-tpm.c | 442 +++++++++++++++++++++ 7 files changed, 508 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/imx-tpm-pwm.txt create mode 100644 drivers/pwm/pwm-imx-tpm.c
Signature · 1 line
2.7.4
PATCH v11 1/5 dt-bindings: pwm: Add i.MX TPM PWM binding
Add i.MX TPM(Low Power Timer/Pulse Width Modulation Module) PWM binding.
---
No changes.
--- .../devicetree/bindings/pwm/imx-tpm-pwm.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/imx-tpm-pwm.txt
Documentation/devicetree/bindings/pwm/imx-tpm-pwm.txt new file +22 -0
@@ -0,0 +1,22 @@ +Freescale i.MX TPM PWM controller + +Required properties: +- compatible : Should be "fsl,imx7ulp-pwm". +- reg: Physical base address and length of the controller's registers. +- #pwm-cells: Should be 3. See pwm.txt in this directory for a description of the cells format. +- clocks : The clock provided by the SoC to drive the PWM. +- interrupts: The interrupt for the PWM controller. + +Note: The TPM counter and period counter are shared between multiple channels, so all channels +should use same period setting. + +Example: + +tpm4: pwm@40250000 { + compatible = "fsl,imx7ulp-pwm"; + reg = <0x40250000 0x1000>; + assigned-clocks = <&pcc2 IMX7ULP_CLK_LPTPM4>; + assigned-clock-parents = <&scg1 IMX7ULP_CLK_SOSC_BUS_CLK>; + clocks = <&pcc2 IMX7ULP_CLK_LPTPM4>; + #pwm-cells = <3>; +};
Signature · 1 line
2.7.4
PATCH v11 2/5 pwm: Add i.MX TPM PWM driver support
In reply to Anson Huangi.MX7ULP has TPM(Low Power Timer/Pulse Width Modulation Module) inside, it can support multiple PWM channels, all the channels share same counter and period setting, but each channel can configure its duty and polarity independently.
There are several TPM modules in i.MX7ULP, the number of channels in TPM modules are different, it can be read from each TPM module's PARAM register.
---
Changes since V10:
- remove channel private data which is ONLY for storing polarity, just read it from HW register;
- improve pwm_imx_tpm_round_state() and pwm_imx_tpm_apply_hw() parameters sequence;
- improve comments for polarity setting;
- refuse polarity change if PWM is active.
--- drivers/pwm/Kconfig | 11 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-imx-tpm.c | 442 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 454 insertions(+) create mode 100644 drivers/pwm/pwm-imx-tpm.c
drivers/pwm/Kconfig +11 -0
@@ -210,6 +210,17 @@ config PWM_IMX27 To compile this driver as a module, choose M here: the module will be called pwm-imx27. +config PWM_IMX_TPM + tristate "i.MX TPM PWM support" + depends on ARCH_MXC || COMPILE_TEST + depends on HAVE_CLK && HAS_IOMEM + help + Generic PWM framework driver for i.MX7ULP TPM module, TPM's full + name is Low Power Timer/Pulse Width Modulation Module. + + To compile this driver as a module, choose M here: the module + will be called pwm-imx-tpm. + config PWM_JZ4740 tristate "Ingenic JZ47xx PWM support" depends on MACH_INGENIC
drivers/pwm/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-$(CONFIG_PWM_HIBVT) += pwm-hibvt.o obj-$(CONFIG_PWM_IMG) += pwm-img.o obj-$(CONFIG_PWM_IMX1) += pwm-imx1.o obj-$(CONFIG_PWM_IMX27) += pwm-imx27.o +obj-$(CONFIG_PWM_IMX_TPM) += pwm-imx-tpm.o obj-$(CONFIG_PWM_JZ4740) += pwm-jz4740.o obj-$(CONFIG_PWM_LP3943) += pwm-lp3943.o obj-$(CONFIG_PWM_LPC18XX_SCT) += pwm-lpc18xx-sct.o
drivers/pwm/pwm-imx-tpm.c new file +442 -0
442 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v11 3/5 ARM: imx_v6_v7_defconfig: Add TPM PWM support by default
In reply to Anson HuangSelect CONFIG_PWM_IMX_TPM by default to support i.MX7ULP TPM PWM.
---
No changes.
--- arch/arm/configs/imx_v6_v7_defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm/configs/imx_v6_v7_defconfig +1 -0
@@ -401,6 +401,7 @@ CONFIG_MPL3115=y CONFIG_PWM=y CONFIG_PWM_FSL_FTM=y CONFIG_PWM_IMX27=y +CONFIG_PWM_IMX_TPM=y CONFIG_NVMEM_IMX_OCOTP=y CONFIG_NVMEM_VF610_OCOTP=y CONFIG_TEE=y
Signature · 1 line
2.7.4
PATCH v11 4/5 ARM: dts: imx7ulp: Add tpm pwm support
In reply to Anson HuangAdd i.MX7ULP EVK board PWM support.
---
No changes.
--- arch/arm/boot/dts/imx7ulp.dtsi | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/arm/boot/dts/imx7ulp.dtsi +10 -0
@@ -124,6 +124,16 @@ status = "disabled"; }; + tpm4: pwm@40250000 { + compatible = "fsl,imx7ulp-pwm"; + reg = <0x40250000 0x1000>; + assigned-clocks = <&pcc2 IMX7ULP_CLK_LPTPM4>; + assigned-clock-parents = <&scg1 IMX7ULP_CLK_SOSC_BUS_CLK>; + clocks = <&pcc2 IMX7ULP_CLK_LPTPM4>; + #pwm-cells = <3>; + status = "disabled"; + }; + tpm5: tpm@40260000 { compatible = "fsl,imx7ulp-tpm"; reg = <0x40260000 0x1000>;
Signature · 1 line
2.7.4
PATCH v11 5/5 ARM: dts: imx7ulp-evk: Add backlight support
In reply to Anson HuangThis patch adds i.MX7ULP EVK board MIPI-DSI backlight support.
---
No changes.
--- arch/arm/boot/dts/imx7ulp-evk.dts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
arch/arm/boot/dts/imx7ulp-evk.dts +21 -0
@@ -8,6 +8,7 @@ /dts-v1/; #include "imx7ulp.dtsi" +#include <dt-bindings/pwm/pwm.h> / { model = "NXP i.MX7ULP EVK";
@@ -22,6 +23,14 @@ reg = <0x60000000 0x40000000>; }; + backlight { + compatible = "pwm-backlight"; + pwms = <&tpm4 1 50000 0>; + brightness-levels = <0 20 25 30 35 40 100>; + default-brightness-level = <6>; + status = "okay"; + }; + reg_vsd_3v3: regulator-vsd-3v3 { compatible = "regulator-fixed"; regulator-name = "VSD_3V3";
@@ -40,6 +49,12 @@ status = "okay"; }; +&tpm4 { + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_pwm0>; + status = "okay"; +}; + &usdhc0 { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_usdhc0>;
@@ -57,6 +72,12 @@ bias-pull-up; }; + pinctrl_pwm0: pwm0grp { + fsl,pins = < + IMX7ULP_PAD_PTF2__TPM4_CH1 0x2 + >; + }; + pinctrl_usdhc0: usdhc0grp { fsl,pins = < IMX7ULP_PAD_PTD1__SDHC0_CMD 0x43
Signature · 1 line
2.7.4
Fabio Estevam
reviewerRe: [PATCH V11 5/5] ARM: dts: imx7ulp-evk: Add backlight support
Quoted 2 lines · Anson Huang
#include "
imx7ulp.dtsi"
+#include <dt-bindings/pwm/pwm.h>
This inclusion is not needed here as PWM_POLARITY_INVERTED is not used in this dts.
RE: [EXT] Re: [PATCH V11 5/5] ARM: dts: imx7ulp-evk: Add backlight support
Hi, Fabio
Best Regards!
Anson Huang
Quoted 20 lines
-----Original Message-----
From: Fabio Estevam [mailto:[email protected]]
Sent: 2019年4月10日 10:03
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Leonard Crestez <[email protected]>; Robin Gong <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; [email protected]; dl-linux-imx <[email protected]>
Subject: [EXT] Re: [PATCH V11 5/5] ARM: dts: imx7ulp-evk: Add backlight supportWARNING: This email was created outside of NXP. DO NOT CLICK links or attachments unless you recognize the sender and know the content is safe.
Quoted 8 lines
Quoted 2 lines · Anson Huang
#include "
imx7ulp.dtsi"
+#include <dt-bindings/pwm/pwm.h>This inclusion is not needed here as
PWM_POLARITY_INVERTEDis not used in this dts.
Thanks for reminder, I will remove it later.
Anson.
Gentle ping...
Quoted 41 lines
-----Original Message-----
From: Anson Huang
Sent: Wednesday, April 10, 2019 9:47 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Leonard Crestez <[email protected]>; Robin Gong <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: [PATCH V11 0/5] Add i.MX7ULP EVK PWM backlight supporti.MX7ULP EVK board has MIPI-DSI display, its backlight is supplied by TPM PWM module, this patch set enables i.MX7ULP TPM PWM driver support and also add backlight support for MIPI-DSI display.
Changes since V10:
- ONLY change the pwm driver patch.Anson Huang (5):
dt-bindings: pwm: Add i.MX TPM PWM binding
pwm: Add i.MX TPM PWM driver support
ARM:imx_v6_v7_defconfig: Add TPM PWM support by default
ARM: dts: imx7ulp: Add tpm pwm support
ARM: dts: imx7ulp-evk: Add backlight support.../devicetree/bindings/pwm/imx-tpm-pwm.txt | 22 + arch/arm/boot/dts/imx7ulp-evk.dts | 21 + arch/arm/boot/dts/imx7ulp.dtsi | 10 + arch/arm/configs/imx_v6_v7_defconfig | 1 + drivers/pwm/Kconfig | 11 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-imx-tpm.c | 442 +++++++++++++++++++++ 7 files changed, 508 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/imx-tpm- pwm.txt create mode 100644 drivers/pwm/pwm-imx-tpm.c--
2.7.4
Ping...
Quoted 59 lines
-----Original Message-----
From: Anson Huang
Sent: Wednesday, April 24, 2019 10:59 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Leonard Crestez <[email protected]>; Robin Gong <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: RE: [PATCH V11 0/5] Add i.MX7ULP EVK PWM backlight supportGentle ping...
Quoted 14 lines
-----Original Message-----
From: Anson Huang
Sent: Wednesday, April 10, 2019 9:47 AM
To: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Leonard Crestez <[email protected]>; Robin Gong <[email protected]>; [email protected]; linux- [email protected]; [email protected]; linux-arm- [email protected]; [email protected]
Cc: dl-linux-imx <[email protected]>
Subject: [PATCH V11 0/5] Add i.MX7ULP EVK PWM backlight supportQuoted 2 lines
i.MX7ULP EVK board has MIPI-DSI display, its backlight is supplied by TPM PWM module, this patch set enables i.MX7ULP TPM PWM driver
support
Quoted 12 lines
and also add backlight support for MIPI-DSI display.
Changes since V10:
- ONLY change the pwm driver patch.Anson Huang (5):
dt-bindings: pwm: Add i.MX TPM PWM binding
pwm: Add i.MX TPM PWM driver support
ARM:imx_v6_v7_defconfig: Add TPM PWM support by default
ARM: dts: imx7ulp: Add tpm pwm support
ARM: dts: imx7ulp-evk: Add backlight supportQuoted 7 lines
.../devicetree/bindings/pwm/imx-tpm-pwm.txt | 22 + arch/arm/boot/dts/imx7ulp-evk.dts | 21 + arch/arm/boot/dts/imx7ulp.dtsi | 10 + arch/arm/configs/imx_v6_v7_defconfig | 1 + drivers/pwm/Kconfig | 11 + drivers/pwm/Makefile | 1 + drivers/pwm/pwm-imx-tpm.c | 442+++++++++++++++++++++
Quoted 7 lines
7 files changed, 508 insertions(+) create mode 100644 Documentation/devicetree/bindings/pwm/imx-tpm- pwm.txt create mode 100644 drivers/pwm/pwm-imx-tpm.c--
2.7.4
Re: [PATCH V11 2/5] pwm: Add i.MX TPM PWM driver support
In reply to Anson HuangHello,
Quoted 134 lines · Anson Huang
i.MX7ULP has TPM(Low Power Timer/Pulse Width Modulation Module) inside, it can support multiple PWM channels, all the channels share same counter and period setting, but each channel can configure its duty and polarity independently.
There are several TPM modules in i.MX7ULP, the number of channels in TPM modules are different, it can be read from each TPM module's PARAM register.
Signed-off-by Anson Huang <[email protected]>---
Changes since V10:
- remove channel private data which is ONLY for storing polarity, just read it from HW register;
- improvepwm_imx_tpm_round_state()andpwm_imx_tpm_apply_hw()parameters sequence;
- improve comments for polarity setting;
- refuse polarity change if PWM is active.--- drivers/pwm/Kconfig | 11 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-imx-tpm.c | 442 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 454 insertions(+) create mode 100644 drivers/pwm/pwm-imx-tpm.cdrivers/pwm/Kconfig +11
-0@@ -210,6 +210,17 @@ config PWM_IMX27 To compile this driver as a module, choose M here: the module will be called pwm-imx27. +config PWM_IMX_TPM + tristate "i.MX TPM PWM support" + depends on ARCH_MXC || COMPILE_TEST + depends on HAVE_CLK && HAS_IOMEM + help + Generic PWM framework driver for i.MX7ULP TPM module, TPM's full + name is Low Power Timer/Pulse Width Modulation Module. + + To compile this driver as a module, choose M here: the module + will be called pwm-imx-tpm. + config PWM_JZ4740 tristate "Ingenic JZ47xx PWM support" depends on MACH_INGENICdrivers/pwm/Makefile +1
-0@@ -19,6 +19,7 @@ obj-$(CONFIG_PWM_HIBVT) += pwm-hibvt.o obj-$(CONFIG_PWM_IMG) += pwm-img.o obj-$(CONFIG_PWM_IMX1) += pwm-imx1.o obj-$(CONFIG_PWM_IMX27) += pwm-imx27.o +obj-$(CONFIG_PWM_IMX_TPM) += pwm-imx-tpm.o obj-$(CONFIG_PWM_JZ4740) += pwm-jz4740.o obj-$(CONFIG_PWM_LP3943) += pwm-lp3943.o obj-$(CONFIG_PWM_LPC18XX_SCT) += pwm-lpc18xx-sct.odrivers/pwm/pwm-imx-tpm.c new file +71
-0@@ -0,0 +1,442 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018-2019 NXP. +* +* Limitations: +* - The TPM counter and period counter are shared between +* multiple channels, so all channels should use same period +* settings. +* - Changes to polarity cannot be latched at the time of the +* next period start. +* - Changing period and duty cycle together isn't atomic, +* with the wrong timing it might happen that a period is +* produced with old duty cycle but new period settings. +*/ + +#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/clk.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/log2.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/platform_device.h> +#include <linux/pwm.h> +#include <linux/slab.h> + +#define PWM_IMX_TPM_PARAM 0x4 +#define PWM_IMX_TPM_GLOBAL 0x8 +#define PWM_IMX_TPM_SC 0x10 +#define PWM_IMX_TPM_CNT 0x14 +#define PWM_IMX_TPM_MOD 0x18 +#define PWM_IMX_TPM_CnSC (n) (0x20 + (n) * 0x8) +#define PWM_IMX_TPM_CnV (n) (0x24 + (n) * 0x8) + +#define PWM_IMX_TPM_PARAM_CHAN GENMASK(7, 0) + +#define PWM_IMX_TPM_SC_PS GENMASK(2, 0) +#define PWM_IMX_TPM_SC_CMOD GENMASK(4, 3) +#define PWM_IMX_TPM_SC_CMOD_INC_EVERY_CLK FIELD_PREP(PWM_IMX_TPM_SC_CMOD, 1) +#define PWM_IMX_TPM_SC_CPWMS BIT(5) + +#define PWM_IMX_TPM_CnSC_CHF BIT(7) +#define PWM_IMX_TPM_CnSC_MSB BIT(5) +#define PWM_IMX_TPM_CnSC_MSA BIT(4) + +/* +* The reference manual describes this field as two separate bits. The +* semantic of the two bits isn't orthogonal though, so they are treated +* together as a 2-bit field here. +*/ +#define PWM_IMX_TPM_CnSC_ELS GENMASK(3, 2) +#define PWM_IMX_TPM_CnSC_ELS_INVERSED FIELD_PREP(PWM_IMX_TPM_CnSC_ELS, 1) +#define PWM_IMX_TPM_CnSC_ELS_NORMAL FIELD_PREP(PWM_IMX_TPM_CnSC_ELS, 2) + + +#define PWM_IMX_TPM_MOD_WIDTH 16 +#define PWM_IMX_TPM_MOD_MOD GENMASK(PWM_IMX_TPM_MOD_WIDTH - 1, 0) + +struct imx_tpm_pwm_chip { +struct pwm_chip chip; +struct clk *clk; +void __iomem *base; +struct mutex lock; +u32 user_count; +u32 enable_count; +u32 real_period; +}; + +struct imx_tpm_pwm_param {
drivers/pwm/pwm-imx-tpm.c line 81
Quoted 10 lines
drivers/pwm/pwm-imx-tpm.c new file +10
-0+u8 prescale; +u32 mod; +u32 val; +}; + +static inline struct imx_tpm_pwm_chip *to_imx_tpm_pwm_chip (struct pwm_chip *chip) +{ + return container_of(chip, struct imx_tpm_pwm_chip, chip); +} +
Maybe add a comment here describing the purpose of this function. Something like:
/*
* This function determines for a given pwm_state *state that a consumer
* might request the pwm_state *realstate that eventually is implemented
* by the hardware and the necessary register values (in *p) to achive
* this.
*/
I didn't revalidate all the maths in this driver but assume they are still right from the previous rounds. If you add the comment I suggested above, feel free to also add
Quoted 9 lines
drivers/pwm/pwm-imx-tpm.c new file +9
-0+static int pwm_imx_tpm_round_state (struct pwm_chip *chip, +struct imx_tpm_pwm_param *p, +struct pwm_state *real_state, +struct pwm_state *state) +{ +struct imx_tpm_pwm_chip *tpm =to_imx_tpm_pwm_chip (chip); +u32 rate, prescale, period_count, clock_unit; +u64 tmp; +
drivers/pwm/pwm-imx-tpm.c line 100
Quoted 10 lines
drivers/pwm/pwm-imx-tpm.c new file +10
-0+ rate =clk_get_rate (tpm->clk); + tmp = (u64 )state->period * rate; + clock_unit =DIV_ROUND_CLOSEST_ULL (tmp,NSEC_PER_SEC ); +if (clock_unit <=PWM_IMX_TPM_MOD_MOD ) + prescale =0 ; +else + prescale =ilog2 (clock_unit) +1 -PWM_IMX_TPM_MOD_WIDTH ; + +if ((!FIELD_FIT (PWM_IMX_TPM_SC_PS , prescale))) +return -ERANGE ;
It's a bit sad that my ideas for the core concerning a round_rate callback don't go down particularly well on Thierry's side.
With the way I suggested we'd continue with prescale = 7 in this case.
As of now there is no rule which kind of deviation to accept and which not. :-| (Nothing this patch can change of course.)
Best regards
Uwe
Signature · 2 lines
Pengutronix e.K. | Uwe Kleine-König | Industrial Linux Solutions | http://www.pengutronix.de/ |
RE: [PATCH V11 2/5] pwm: Add i.MX TPM PWM driver support
Hi, Uwe
Quoted 182 lines
-----Original Message-----
From: Uwe Kleine-König [mailto:[email protected]]
Sent: Thursday, May 9, 2019 3:20 PM
To: Anson Huang <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Leonard Crestez <[email protected]>; Robin Gong <[email protected]>; [email protected]; [email protected]; [email protected]; linux- [email protected]; dl-linux-imx <[email protected]>
Subject: Re: [PATCH V11 2/5] pwm: Add i.MX TPM PWM driver supportHello,
Quoted 5 lines · Anson Huang
i.MX7ULP has TPM(Low Power Timer/Pulse Width Modulation Module) inside, it can support multiple PWM channels, all the channels share same counter and period setting, but each channel can configure its duty and polarity independently.
Quoted 8 lines
There are several TPM modules in i.MX7ULP, the number of channels in TPM modules are different, it can be read from each TPM module's PARAM register.
Signed-off-by Anson Huang <[email protected]>---
Changes since V10:
- remove channel private data which is ONLY for storing polarity, justread it from HW register;
Quoted 1 line
- improve
pwm_imx_tpm_round_state()and
pwm_imx_tpm_apply_hw()parameters sequence;Quoted 15 lines
- improve comments for polarity setting;
- refuse polarity change if PWM is active.--- drivers/pwm/Kconfig | 11 ++ drivers/pwm/Makefile | 1 + drivers/pwm/pwm-imx-tpm.c | 442 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 454 insertions(+) create mode 100644 drivers/pwm/pwm-imx-tpm.cdrivers/pwm/Kconfig index renamed from drivers/pwm/Kconfig +0
-0c054bd1..1311b540 100644
drivers/pwm/Kconfig config PWM_IMX27 · line 218
Quoted 9 lines
drivers/pwm/Kconfig +6
-0@@ -210,6 +210,17 @@ config PWM_IMX27 To compile this driver as a module, choose M here: the module will be called pwm-imx27. +config PWM_IMX_TPM + tristate "i.MX TPM PWM support" + depends on ARCH_MXC || COMPILE_TEST + depends on HAVE_CLK && HAS_IOMEM + help + Generic PWM framework driver for i.MX7ULP TPM module, TPM'sfull
drivers/pwm/Makefile obj-$(CONFIG_PWM_HIBVT) += pwm-
Quoted 13 lines
drivers/pwm/Kconfig +5
-0+ name is Low Power Timer/Pulse Width Modulation Module. + + To compile this driver as a module, choose M here: the module + will be called pwm-imx-tpm. + config PWM_JZ4740 tristate "Ingenic JZ47xx PWM support" depends on MACH_INGENICdrivers/pwm/Makefile index renamed from drivers/pwm/Makefile +0
-0448825e..c368599 100644
drivers/pwm/Makefile +0
-0@@ -19,6 +19,7 @@ obj-$(CONFIG_PWM_HIBVT) += pwm-hibvt.o
drivers/pwm/pwm-imx-tpm.c
Quoted 8 lines
drivers/pwm/Makefile +1
-0obj-$(CONFIG_PWM_IMG) += pwm-img.o obj-$(CONFIG_PWM_IMX1) += pwm-imx1.o obj-$(CONFIG_PWM_IMX27) += pwm-imx27.o +obj-$(CONFIG_PWM_IMX_TPM) += pwm-imx-tpm.o obj-$(CONFIG_PWM_JZ4740) += pwm-jz4740.o obj-$(CONFIG_PWM_LP3943) += pwm-lp3943.o obj-$(CONFIG_PWM_LPC18XX_SCT) += pwm-lpc18xx-sct.odrivers/pwm/pwm-imx-tpm.c +0
-0new
Quoted 31 lines
file mode 100644 index 0000000..9349f4f
drivers/pwm/pwm-imx-tpm.c new file +27
-0@@ -0,0 +1,442 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Copyright 2018-2019 NXP. +* +* Limitations: +* - The TPM counter and period counter are shared between +* multiple channels, so all channels should use same period +* settings. +* - Changes to polarity cannot be latched at the time of the +* next period start. +* - Changing period and duty cycle together isn't atomic, +* with the wrong timing it might happen that a period is +* produced with old duty cycle but new period settings. +*/ + +#include <linux/bitfield.h> +#include <linux/bitops.h> +#include <linux/clk.h> +#include <linux/err.h> +#include <linux/io.h> +#include <linux/log2.h> +#include <linux/module.h> +#include <linux/of.h> +#include <linux/of_address.h> +#include <linux/platform_device.h> +#include <linux/pwm.h> +#include <linux/slab.h> drivers/pwm/pwm-imx-tpm.c line 37
Quoted 10 lines
drivers/pwm/pwm-imx-tpm.c new file +10
-0+ +#define PWM_IMX_TPM_PARAM 0x4 +#define PWM_IMX_TPM_GLOBAL 0x8 +#define PWM_IMX_TPM_SC 0x10 +#define PWM_IMX_TPM_CNT 0x14 +#define PWM_IMX_TPM_MOD 0x18 +#define PWM_IMX_TPM_CnSC (n) (0x20 + (n) * 0x8) +#define PWM_IMX_TPM_CnV (n) (0x24 + (n) * 0x8) + +#define PWM_IMX_TPM_PARAM_CHAN GENMASK(7,0)
drivers/pwm/pwm-imx-tpm.c
Quoted 4 lines
drivers/pwm/pwm-imx-tpm.c new file +4
-0+ +#define PWM_IMX_TPM_SC_PS GENMASK(2, 0) +#define PWM_IMX_TPM_SC_CMOD GENMASK(4, 3) +#define PWM_IMX_TPM_SC_CMOD_INC_EVERY_CLK FIELD_PREP(PWM_IMX_TPM_SC_CMOD, 1)Quoted 5 lines
drivers/pwm/pwm-imx-tpm.c new file +5
-0+#define PWM_IMX_TPM_SC_CPWMS BIT(5) + +#define PWM_IMX_TPM_CnSC_CHF BIT(7) +#define PWM_IMX_TPM_CnSC_MSB BIT(5) +#define PWM_IMX_TPM_CnSC_MSA BIT(4)drivers/pwm/pwm-imx-tpm.c
Quoted 10 lines
drivers/pwm/pwm-imx-tpm.c new file +10
-0+ +/* +* The reference manual describes this field as two separate bits. +The +* semantic of the two bits isn't orthogonal though, so they are +treated +* together as a 2-bit field here. +*/ +#define PWM_IMX_TPM_CnSC_ELS GENMASK(3, 2) +#define PWM_IMX_TPM_CnSC_ELS_INVERSEDFIELD_PREP(PWM_IMX_TPM_CnSC_ELS, 1)drivers/pwm/pwm-imx-tpm.c line 57
Quoted 1 line
drivers/pwm/pwm-imx-tpm.c new file +1
-0+#define PWM_IMX_TPM_CnSC_ELS_NORMALFIELD_PREP(PWM_IMX_TPM_CnSC_ELS, 2)drivers/pwm/pwm-imx-tpm.c
Quoted 4 lines
drivers/pwm/pwm-imx-tpm.c new file +4
-0+ + +#define PWM_IMX_TPM_MOD_WIDTH 16 +#define PWM_IMX_TPM_MOD_MOD GENMASK(PWM_IMX_TPM_MOD_WIDTH - 1, 0)Quoted 11 lines
drivers/pwm/pwm-imx-tpm.c new file +11
-0+ +struct imx_tpm_pwm_chip { +struct pwm_chip chip; +struct clk *clk; +void __iomem *base; +struct mutex lock; +u32 user_count; +u32 enable_count; +u32 real_period; +}; +drivers/pwm/pwm-imx-tpm.c line 81
Quoted 10 lines
drivers/pwm/pwm-imx-tpm.c new file +10
-0+struct imx_tpm_pwm_param { +u8 prescale; +u32 mod; +u32 val; +}; + +static inline struct imx_tpm_pwm_chip *to_imx_tpm_pwm_chip (struct +pwm_chip *chip) { + return container_of(chip, struct imx_tpm_pwm_chip, chip); } +Maybe add a comment here describing the purpose of this function. Something like:
/*
* This function determines for a givenpwm_state*state that a consumer
* might request thepwm_state*realstate that eventually is implemented
* by the hardware and the necessary register values (in *p) to achive
* this.
*/
Quoted 6 lines
I didn't revalidate all the maths in this driver but assume they are still right from the previous rounds. If you add the comment I suggested above, feel free to also add
Reviewed-by Uwe Kleine-König <[email protected]>
OK, I will add this comment in V12, thanks!
Quoted 24 lines
Quoted 6 lines
drivers/pwm/pwm-imx-tpm.c new file +6
-0+static int pwm_imx_tpm_round_state (struct pwm_chip *chip, +struct imx_tpm_pwm_param *p, +struct pwm_state *real_state, +struct pwm_state *state) +{ +struct imx_tpm_pwm_chip *tpm =to_imx_tpm_pwm_chip (chip);drivers/pwm/pwm-imx-tpm.c
Quoted 10 lines
drivers/pwm/pwm-imx-tpm.c new file +10
-0+u32 rate, prescale, period_count, clock_unit; +u64 tmp; + + rate =clk_get_rate (tpm->clk); + tmp = (u64 )state->period * rate; + clock_unit =DIV_ROUND_CLOSEST_ULL (tmp,NSEC_PER_SEC ); +if (clock_unit <=PWM_IMX_TPM_MOD_MOD ) + prescale =0 ; +else + prescale = ilog2(clock_unit) + 1 -
PWM_IMX_TPM_MOD_WIDTH;drivers/pwm/pwm-imx-tpm.c line 100
Quoted 3 lines
drivers/pwm/pwm-imx-tpm.c new file +3
-0+ +if ((!FIELD_FIT (PWM_IMX_TPM_SC_PS , prescale))) +return -ERANGE ;It's a bit sad that my ideas for the core concerning a
round_ratecallback don't go down particularly well on Thierry's side.
Quoted 5 lines
With the way I suggested we'd continue with prescale = 7 in this case.
As of now there is no rule which kind of deviation to accept and which not. :- | (Nothing this patch can change of course.)
Thanks,
Anson.
Quoted 11 lines
Best regards
Uwe--
Pengutronix e.K. | Uwe Kleine-König |
Industrial Linux Solutions |
https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.p
engutronix.de%2F&data=02%7C01%7Canson.huang%40nxp.com%7C87 2ade014b314f5edf6d08d6d44ed41e%7C686ea1d3bc2b4c6fa92cd99c5c30163 5%7C0%7C0%7C636929832363393461&sdata=QTSwOn0288HYlBCus%2 FSlw9BDljPqMJ1WJD2KbEiJhuM%3D&reserved=0 |