[PATCH 3/3] spi: mxic: add maximum speed of spi host

zhengxunli zhengxunli at mxic.com.tw
Fri Jan 29 03:13:38 EST 2021


Add the maximum speed of the host to avoid over-speed
operation of the device.

Signed-off-by: zhengxunli <zhengxunli at mxic.com.tw>
---
 Documentation/devicetree/bindings/spi/spi-mxic.txt | 4 ++++
 drivers/spi/spi-mxic.c                             | 7 +++++++
 2 files changed, 11 insertions(+)

diff --git a/Documentation/devicetree/bindings/spi/spi-mxic.txt b/Documentation/devicetree/bindings/spi/spi-mxic.txt
index 529f2da..ff6937c 100644
--- a/Documentation/devicetree/bindings/spi/spi-mxic.txt
+++ b/Documentation/devicetree/bindings/spi/spi-mxic.txt
@@ -13,6 +13,9 @@ Required properties:
 - clocks: should contain 3 entries for the "ps_clk", "send_clk" and
 	  "send_dly_clk" clocks
 
+Recommended properties:
+- spi-max-frequency: Maximum SPI clocking speed of the device in Hz.
+
 Example:
 
 	spi at 43c30000 {
@@ -21,6 +24,7 @@ Example:
 		reg-names = "regs", "dirmap";
 		clocks = <&clkwizard 0>, <&clkwizard 1>, <&clkc 18>;
 		clock-names = "send_clk", "send_dly_clk", "ps_clk";
+		spi-max-frequency = <200000000>;
 		#address-cells = <1>;
 		#size-cells = <0>;
 
diff --git a/drivers/spi/spi-mxic.c b/drivers/spi/spi-mxic.c
index 821328a..7786d33 100644
--- a/drivers/spi/spi-mxic.c
+++ b/drivers/spi/spi-mxic.c
@@ -12,6 +12,7 @@
 #include <linux/io.h>
 #include <linux/iopoll.h>
 #include <linux/module.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
 #include <linux/spi/spi.h>
@@ -536,7 +537,9 @@ static int mxic_spi_probe(struct platform_device *pdev)
 {
 	struct spi_master *master;
 	struct resource *res;
+	struct device_node *np = pdev->dev.of_node;
 	struct mxic_spi *mxic;
+	u32 max_freq;
 	int ret;
 
 	master = devm_spi_alloc_master(&pdev->dev, sizeof(struct mxic_spi));
@@ -580,6 +583,10 @@ static int mxic_spi_probe(struct platform_device *pdev)
 			SPI_RX_QUAD | SPI_TX_QUAD |
 			SPI_RX_OCTAL | SPI_TX_OCTAL;
 
+	if (of_property_read_u32(np, "spi-max-frequency",
+				 &master->max_speed_hz))
+		master->max_speed_hz = 25000000; /* 25MHz */
+
 	mxic_spi_hw_init(mxic);
 
 	ret = spi_register_master(master);
-- 
1.9.1




More information about the linux-mtd mailing list