Skip to contentSkip to conversation

Microchip soft ip corePWM driver

PATCH Superseded Conor Dooley 1 participant 6 messages Jul 8, 2022

Subsystems (4)

v4 of 18 Superseded Latest is v18 →

lore
Share & tools
lore

Conor Dooley

author maintainer
#0 lore raw

v4 cover Microchip soft ip corePWM driver

Hey Uwe, all,

Added some extra patches so I have a cover letter this time. You pointed out that I was overriding npwmcells in the driver and I realised that the dt & binding were not correct so I have added two simple patches to deal with that. The dts patch I will take in my tree once the binding is applied.

For the maintainers entry, I mentioned before that I have several changes in-flight for it. We are late(ish) in the cycle so I doubt you'll be applying this for v5.20, but in the off chance you do - I would be happy to send it (with your Ack) alongside an i2c addition that is "deferred".

In your review of v3, you had a lot of comments about the period and duty cycle calculations, so I have had another run at them. I converted the period calculation to "search" from the bottom up for the suitable prescale value. The duty cycle calculation has been fixed - the problem was exactly what I suspected in my replies to your review. I had to block the use of a 0xFF period_steps register value (which I think should be covered by the updated comment and limitation #2).

Beyond that, I have rebased on -next and converted to the devm_ stuff in probe that was recently added & dropped remove() - as requested. I added locking to protect the period racing, changed the #defines and switched to returning -EINVAL when the period is locked to a value greater than that requested.

Thanks,
Conor.

Conor Dooley (4):
dt-bindings: pwm: fix microchip corePWM's pwm-cells
riscv: dts: fix the icicle's #pwm-cells
pwm: add microchip soft ip corePWM driver
MAINTAINERS: add pwm to PolarFire SoC entry

 .../bindings/pwm/microchip,corepwm.yaml       |   4 +-
 MAINTAINERS                                   |   1 +
 .../dts/microchip/mpfs-icicle-kit-fabric.dtsi |   2 +-
 .../dts/microchip/mpfs-tysom-m-fabric.dtsi    |  18 +
 .../riscv/boot/dts/microchip/mpfs-tysom-m.dts | 185 +++++++++
 drivers/pwm/Kconfig                           |  10 +
 drivers/pwm/Makefile                          |   1 +
 drivers/pwm/pwm-microchip-core.c              | 355 ++++++++++++++++++
 8 files changed, 574 insertions(+), 2 deletions(-)
 create mode 100644 arch/riscv/boot/dts/microchip/mpfs-tysom-m-fabric.dtsi
 create mode 100644 arch/riscv/boot/dts/microchip/mpfs-tysom-m.dts
 create mode 100644 drivers/pwm/pwm-microchip-core.c

base-commit: 088b9c375534d905a4d337c78db3b3bfbb52c4a0

Signature · 1 line
2.36.1
author maintainer
#1 lore raw

PATCH v4 1/4 dt-bindings: pwm: fix microchip corePWM's pwm-cells

corePWM is capable of inverted operation but the binding requires \#pwm-cells of 2. Expand the binding to support setting the polarity.

Fixes df77f7735786 ("dt-bindings: pwm: add microchip corepwm binding")
---
 Documentation/devicetree/bindings/pwm/microchip,corepwm.yaml | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/pwm/microchip,corepwm.yaml +3 -1
index a7fae1772a81..cd8e9a8907f8 100644
@@ -30,7 +30,9 @@ properties:
     maxItems: 1
 
   "#pwm-cells":
-    const: 2
+    enum: [2, 3]
+    description:
+      The only flag supported by the controller is PWM_POLARITY_INVERTED.
 
   microchip,sync-update-mask:
     description: |
Signature · 1 line
2.36.1
author maintainer
#2 lore raw

PATCH v4 2/4 riscv: dts: fix the icicle's #pwm-cells

In reply to Conor Dooley

\#pwm-cells for the Icicle kit's fabric PWM was incorrectly set to 2 & blindly overridden by the (out of tree) driver anyway. The core can support inverted operation, so update the entry to correctly report its capabilities.

Fixes 72560c6559b8 ("riscv: dts: microchip: add fpga fabric section to icicle kit")
---
 .../dts/microchip/mpfs-icicle-kit-fabric.dtsi |   2 +-
 .../dts/microchip/mpfs-tysom-m-fabric.dtsi    |  18 ++
 .../riscv/boot/dts/microchip/mpfs-tysom-m.dts | 185 ++++++++++++++++++
 3 files changed, 204 insertions(+), 1 deletion(-)
 create mode 100644 arch/riscv/boot/dts/microchip/mpfs-tysom-m-fabric.dtsi
 create mode 100644 arch/riscv/boot/dts/microchip/mpfs-tysom-m.dts
arch/riscv/boot/dts/microchip/mpfs-icicle-kit-fabric.dtsi +1 -1
index 0d28858b83f2..e09a13aef268 100644
@@ -8,7 +8,7 @@ core_pwm0: pwm@41000000 {
 		compatible = "microchip,corepwm-rtl-v4";
 		reg = <0x0 0x41000000 0x0 0xF0>;
 		microchip,sync-update-mask = /bits/ 32 <0>;
-		#pwm-cells = <2>;
+		#pwm-cells = <3>;
 		clocks = <&fabric_clk3>;
 		status = "disabled";
 	};
arch/riscv/boot/dts/microchip/mpfs-tysom-m-fabric.dtsi new file +18 -0
new file mode 100644
index 000000000000..98f642e83ad4
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/* Copyright (c) 2022 Microchip Technology Inc */
+
+// #include "dt-bindings/mailbox/miv-ihc.h"
+
+/ {
+	fabric_clk3: fabric-clk3 {
+		compatible = "fixed-clock";
+		#clock-cells = <0>;
+		clock-frequency = <62500000>;
+	};
+
+	fabric_clk1: fabric-clk1 {
+		compatible = "fixed-clock";
+		#clock-cells = <0>;
+		clock-frequency = <125000000>;
+	};
+};
arch/riscv/boot/dts/microchip/mpfs-tysom-m.dts new file +185 -0

185 lines not on this page · raw message

Signature · 1 line
2.36.1
author maintainer
#3 lore raw

Re: [PATCH v4 2/4] riscv: dts: fix the icicle's #pwm-cells

Quoted 7 lines · Conor Dooley

\#pwm-cells for the Icicle kit's fabric PWM was incorrectly set to 2 & blindly overridden by the (out of tree) driver anyway. The core can support inverted operation, so update the entry to correctly report its capabilities.

Fixes 72560c6559b8 ("riscv: dts: microchip: add fpga fabric section to icicle kit")

Gah, I messed this patch up... I'll resend.

Quoted 236 lines
---
  .../dts/microchip/mpfs-icicle-kit-fabric.dtsi |   2 +-
  .../dts/microchip/mpfs-tysom-m-fabric.dtsi    |  18 ++
  .../riscv/boot/dts/microchip/mpfs-tysom-m.dts | 185 ++++++++++++++++++
  3 files changed, 204 insertions(+), 1 deletion(-)

create mode 100644 arch/riscv/boot/dts/microchip/mpfs-tysom-m-fabric.dtsi create mode 100644 arch/riscv/boot/dts/microchip/mpfs-tysom-m.dts

arch/riscv/boot/dts/microchip/mpfs-icicle-kit-fabric.dtsi +1 -1
index 0d28858b83f2..e09a13aef268 100644
@@ -8,7 +8,7 @@ core_pwm0: pwm@41000000 {
  		compatible = "microchip,corepwm-rtl-v4";
  		reg = <0x0 0x41000000 0x0 0xF0>;
  		microchip,sync-update-mask = /bits/ 32 <0>;
-		#pwm-cells = <2>;
+		#pwm-cells = <3>;
  		clocks = <&fabric_clk3>;
  		status = "disabled";
  	};
arch/riscv/boot/dts/microchip/mpfs-tysom-m-fabric.dtsi new file +18 -0
new file mode 100644
index 000000000000..98f642e83ad4
@@ -0,0 +1,18 @@
+// SPDX-License-Identifier: (GPL-2.0 OR MIT)
+/* Copyright (c) 2022 Microchip Technology Inc */
+
+// #include "dt-bindings/mailbox/miv-ihc.h"
+
+/ {
+	fabric_clk3: fabric-clk3 {
+		compatible = "fixed-clock";
+		#clock-cells = <0>;
+		clock-frequency = <62500000>;
+	};
+
+	fabric_clk1: fabric-clk1 {
+		compatible = "fixed-clock";
+		#clock-cells = <0>;
+		clock-frequency = <125000000>;
+	};
+};
arch/riscv/boot/dts/microchip/mpfs-tysom-m.dts new file +185 -0
new file mode 100644
index 000000000000..0b664c591255
@@ -0,0 +1,185 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Original all-in-one devicetree:
+ * Copyright (C) 2020-2022 - Aldec
+ * Rewritten to use includes:
+ * Copyright (C) 2022 - Conor Dooley <[email protected]>
+ */
+
+/dts-v1/;
+
+#include "mpfs.dtsi"
+#include "mpfs-tysom-m-fabric.dtsi"
+
+/* Clock frequency (in Hz) of the rtcclk */
+#define MTIMER_FREQ		1000000
+
+/ {
+	model = "Aldec TySOM-M-MPFS250T";
+	compatible = "aldec,tysom-m-mpfs250t", "microchip,mpfs";
+
+	aliases {
+		ethernet0 = &mac0;
+		ethernet1 = &mac1;
+		serial0 = &mmuart0;
+		serial1 = &mmuart1;
+		serial2 = &mmuart2;
+		serial3 = &mmuart3;
+		serial4 = &mmuart4;
+		gpio0 = &gpio0;
+		gpio1 = &gpio2;
+	};
+
+	chosen {
+		stdout-path = "serial1:115200n8";
+	};
+
+	cpus {
+		timebase-frequency = <MTIMER_FREQ>;
+	};
+
+	ddrc_cache_lo: memory@80000000 {
+		device_type = "memory";
+		reg = <0x0 0x80000000 0x0 0x2e000000>;
+		status = "okay";
+	};
+
+	ddrc_cache_hi: memory@1000000000 {
+		device_type = "memory";
+		reg = <0x10 0x00000000 0x0 0x40000000>;
+		status = "okay";
+	};
+
+	soc {
+	};
+
+	leds {
+		compatible = "gpio-leds";
+		status = "okay";
+
+		led0 {
+			gpios = <&gpio1 23 1>;
+			default-state = "on";
+			linux,default-trigger = "heartbeat";
+		};
+	};
+};
+
+&i2c0 {
+	status = "okay";
+};
+
+&i2c1 {
+	status = "okay";
+	ina219: ina219@45 {
+		status = "okay";
+		compatible = "ti,ina219";
+		reg = <0x45>;
+		shunt-resistor = <0x7d0>;
+	};
+};
+
+&gpio1 {
+	interrupts = <27 28 29 30 31 32 33 47 35 36 37 38 39 40 41 42 43 44 45 46 34 48 49 50>;
+	status = "okay";
+};
+
+&mac0 {
+	status = "okay";
+	phy-mode = "gmii";
+	phy-handle = <&phy0>;
+
+};
+
+&mac1 {
+	status = "okay";
+	phy-mode = "gmii";
+	phy-handle = <&phy1>;
+	phy1: ethernet-phy@1 {
+		reg = <1>;
+		ti,fifo-depth = <0x01>;
+	};
+	phy0: ethernet-phy@0 {
+		reg = <0>;
+		ti,fifo-depth = <0x01>;
+	};
+};
+
+&mbox {
+	status = "okay";
+};
+
+&mmc {
+	max-frequency = <200000000>;
+	cap-mmc-highspeed;
+	cap-sd-highspeed;
+	no-1-8-v;
+	disable-wp;
+	status = "okay";
+};
+
+&mmuart1 {
+	status = "okay";
+};
+
+&mmuart2 {
+	status = "okay";
+};
+
+&mmuart3 {
+	status = "okay";
+};
+
+&mmuart4 {
+	status = "okay";
+};
+
+&refclk {
+	clock-frequency = <125000000>;
+};
+
+&rtc {
+	status = "okay";
+};
+
+&spi0 {
+	status = "okay";
+};
+
+&spi1 {
+	status = "okay";
+	pseFlash@0 {
+		#address-cells = <1>;
+		#size-cells = <1>;
+		compatible = "n25q128a11", "jedec,spi-nor";
+		status = "okay";
+		reg = <0x0>;
+		spi-max-frequency = <10000000>;
+
+		partition@test-0 { /* test purposes */
+			label = "qspi-test-0";
+			reg = <0x00000000 0x00800000>;
+		};
+		partition@test-1 { /* test purposes */
+			label = "qspi-test-1";
+			reg = <0x00800000 0x00800000>;
+		};
+		partition@test-2 { /* test purposes */
+			label = "qspi-test-2";
+			reg = <0x01000000 0x00800000>;
+		};
+		partition@test-3 { /* test purposes */
+			label = "qspi-test-3";
+			reg = <0x01800000 0x00800000>;
+		};
+	};
+};
+
+&syscontroller {
+	status = "okay";
+};
+
+&usb {
+	status = "okay";
+	dr_mode = "host";
+};
author maintainer
#4 lore raw

PATCH v4 3/4 pwm: add microchip soft ip corePWM driver

In reply to Conor Dooley

Add a driver that supports the Microchip FPGA "soft" PWM IP core.

---
 drivers/pwm/Kconfig              |  10 +
 drivers/pwm/Makefile             |   1 +
 drivers/pwm/pwm-microchip-core.c | 355 +++++++++++++++++++++++++++++++
 3 files changed, 366 insertions(+)
 create mode 100644 drivers/pwm/pwm-microchip-core.c
drivers/pwm/Kconfig +10 -0
index 904de8d61828..007ea5750e73 100644
@@ -383,6 +383,16 @@ config PWM_MEDIATEK
 	  To compile this driver as a module, choose M here: the module
 	  will be called pwm-mediatek.
 
+config PWM_MICROCHIP_CORE
+	tristate "Microchip corePWM PWM support"
+	depends on SOC_MICROCHIP_POLARFIRE || COMPILE_TEST
+	depends on HAS_IOMEM && OF
+	help
+	  PWM driver for Microchip FPGA soft IP core.
+
+	  To compile this driver as a module, choose M here: the module
+	  will be called pwm-microchip-core.
+
 config PWM_MXS
 	tristate "Freescale MXS PWM support"
 	depends on ARCH_MXS || COMPILE_TEST
drivers/pwm/Makefile +1 -0
index 5c08bdb817b4..43feb7cfc66a 100644
@@ -33,6 +33,7 @@ obj-$(CONFIG_PWM_LPSS_PCI)	+= pwm-lpss-pci.o
 obj-$(CONFIG_PWM_LPSS_PLATFORM)	+= pwm-lpss-platform.o
 obj-$(CONFIG_PWM_MESON)		+= pwm-meson.o
 obj-$(CONFIG_PWM_MEDIATEK)	+= pwm-mediatek.o
+obj-$(CONFIG_PWM_MICROCHIP_CORE)	+= pwm-microchip-core.o
 obj-$(CONFIG_PWM_MTK_DISP)	+= pwm-mtk-disp.o
 obj-$(CONFIG_PWM_MXS)		+= pwm-mxs.o
 obj-$(CONFIG_PWM_NTXEC)		+= pwm-ntxec.o
drivers/pwm/pwm-microchip-core.c new file +355 -0

355 lines not on this page · raw message

Signature · 1 line
2.36.1
author maintainer
#5 lore raw

PATCH v4 4/4 MAINTAINERS: add pwm to PolarFire SoC entry

In reply to Conor Dooley

Add the newly introduced pwm driver to the existing PolarFire SoC entry.

---
 MAINTAINERS | 1 +
 1 file changed, 1 insertion(+)
MAINTAINERS +1 -0
index d64d79eb36a2..f023ae8442ab 100644
@@ -17429,6 +17429,7 @@ L:	[email protected]
 S:	Supported
 F:	arch/riscv/boot/dts/microchip/
 F:	drivers/mailbox/mailbox-mpfs.c
+F:	drivers/pwm/pwm-microchip-core.c
 F:	drivers/rtc/rtc-mpfs.c
 F:	drivers/soc/microchip/
 F:	drivers/spi/spi-microchip-core.c
Signature · 1 line
2.36.1