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

Miquel Raynal miquel.raynal at bootlin.com
Mon Feb 1 10:02:47 EST 2021


Hi,

zhengxunli <zhengxunli at mxic.com.tw> wrote on Fri, 29 Jan 2021 16:13:38
+0800:

> 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

Binding and driver changes should be in two separate commits.

> @@ -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.

I don't think this property should be part of the controller binding.
It is a per device property and is already parsed by the core (see
of_spi_parse_dt() in spi.c).

> +
>  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 */

As said before, there are two limitations to take into account:
1- your controller maximum speed
2- your flash maximum speed

(1) I don't think this needs to be exported through the DT, the driver
    knows his own limitations and enforces them.

(2) Should be either advertised by the DT through the spi-max-frequency
    property or advertised somehow by the vendor driver (macronix.c).

> +
>  	mxic_spi_hw_init(mxic);
>  
>  	ret = spi_register_master(master);

Thanks,
Miquèl



More information about the linux-mtd mailing list