From 1c905260e41c1f5363a354130174d3cb03e27889 Mon Sep 17 00:00:00 2001 From: Martin Ayotte Date: Fri, 13 Jan 2017 17:49:38 -0500 Subject: [PATCH] add SPI-NOR in OPiZero DT and fix H3 SPI FIFO in spi-sun6i SPI --- .../add-opi-zero-dts-with-wireless.patch | 31 ++++++- .../add_missing_SPI_for-H3_v4.9.x.patch | 89 ++++++++++++++++++- 2 files changed, 117 insertions(+), 3 deletions(-) diff --git a/patch/kernel/sun8i-dev/add-opi-zero-dts-with-wireless.patch b/patch/kernel/sun8i-dev/add-opi-zero-dts-with-wireless.patch index 408e41523d..7194f28376 100644 --- a/patch/kernel/sun8i-dev/add-opi-zero-dts-with-wireless.patch +++ b/patch/kernel/sun8i-dev/add-opi-zero-dts-with-wireless.patch @@ -15,7 +15,7 @@ new file mode 100644 index 00000000..d262a251 --- /dev/null +++ b/arch/arm/boot/dts/sun8i-h2plus-orangepi-zero.dts -@@ -0,0 +1,60 @@ +@@ -0,0 +1,88 @@ + +#include "sun8i-h3-orangepi-one.dts" + @@ -76,3 +76,32 @@ index 00000000..d262a251 + }; +}; + ++&spi0 { ++ status = "okay"; ++ spi-flash@0 { ++ #address-cells = <1>; ++ #size-cells = <0>; ++ compatible = "jedec,spi-nor"; ++ reg = <0>; /* Chip select 0 */ ++ spi-max-frequency = <10000000>; ++ status = "okay"; ++ partitions { ++ compatible = "fixed-partitions"; ++ #address-cells = <1>; ++ #size-cells = <1>; ++ partition@0 { ++ label = "uboot"; ++ reg = <0x0 0x100000>; ++ }; ++ partition@100000 { ++ label = "env"; ++ reg = <0x100000 0x100000>; ++ }; ++ partition@200000 { ++ label = "data"; ++ reg = <0x200000 0x200000>; ++ }; ++ }; ++ }; ++}; ++ \ No newline at end of file diff --git a/patch/kernel/sun8i-dev/add_missing_SPI_for-H3_v4.9.x.patch b/patch/kernel/sun8i-dev/add_missing_SPI_for-H3_v4.9.x.patch index c555afce5c..07f045304e 100644 --- a/patch/kernel/sun8i-dev/add_missing_SPI_for-H3_v4.9.x.patch +++ b/patch/kernel/sun8i-dev/add_missing_SPI_for-H3_v4.9.x.patch @@ -54,7 +54,7 @@ index cc2a8b4..70b2607 100644 }; + spi0: spi@01c68000 { -+ compatible = "allwinner,sun6i-a31-spi"; ++ compatible = "allwinner,sun8i-h3-spi"; + reg = <0x01c68000 0x1000>; + interrupts = ; + pinctrl-names = "default"; @@ -70,7 +70,7 @@ index cc2a8b4..70b2607 100644 + }; + + spi1: spi@01c69000 { -+ compatible = "allwinner,sun6i-a31-spi"; ++ compatible = "allwinner,sun8i-h3-spi"; + reg = <0x01c69000 0x1000>; + interrupts = ; + pinctrl-names = "default"; @@ -88,3 +88,88 @@ index cc2a8b4..70b2607 100644 emac: ethernet@1c30000 { compatible = "allwinner,sun8i-h3-emac"; syscon = <&syscon>; +diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c +index 9918a57..e311483 100644 +--- a/drivers/spi/spi-sun6i.c ++++ b/drivers/spi/spi-sun6i.c +@@ -17,6 +17,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -24,6 +25,7 @@ + #include + + #define SUN6I_FIFO_DEPTH 128 ++#define SUN8I_FIFO_DEPTH 64 + + #define SUN6I_GBL_CTL_REG 0x04 + #define SUN6I_GBL_CTL_BUS_ENABLE BIT(0) +@@ -90,6 +92,7 @@ struct sun6i_spi { + const u8 *tx_buf; + u8 *rx_buf; + int len; ++ unsigned long fifo_depth; + }; + + static inline u32 sun6i_spi_read(struct sun6i_spi *sspi, u32 reg) +@@ -155,7 +158,9 @@ static void sun6i_spi_set_cs(struct spi_device *spi, bool enable) + + static size_t sun6i_spi_max_transfer_size(struct spi_device *spi) + { +- return SUN6I_FIFO_DEPTH - 1; ++ struct sun6i_spi *sspi = spi_master_get_devdata(spi->master); ++ ++ return sspi->fifo_depth - 1; + } + + static int sun6i_spi_transfer_one(struct spi_master *master, +@@ -170,7 +175,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master, + u32 reg; + + /* We don't support transfer larger than the FIFO */ +- if (tfr->len > SUN6I_FIFO_DEPTH) ++ if (tfr->len > sspi->fifo_depth) + return -EINVAL; + + reinit_completion(&sspi->done); +@@ -265,7 +270,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master, + SUN6I_BURST_CTL_CNT_STC(tx_len)); + + /* Fill the TX FIFO */ +- sun6i_spi_fill_fifo(sspi, SUN6I_FIFO_DEPTH); ++ sun6i_spi_fill_fifo(sspi, sspi->fifo_depth); + + /* Enable the interrupts */ + sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, SUN6I_INT_CTL_TC); +@@ -288,7 +293,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master, + goto out; + } + +- sun6i_spi_drain_fifo(sspi, SUN6I_FIFO_DEPTH); ++ sun6i_spi_drain_fifo(sspi, sspi->fifo_depth); + + out: + sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, 0); +@@ -398,6 +403,8 @@ static int sun6i_spi_probe(struct platform_device *pdev) + } + + sspi->master = master; ++ sspi->fifo_depth = (unsigned long)of_device_get_match_data(&pdev->dev); ++ + master->max_speed_hz = 100 * 1000 * 1000; + master->min_speed_hz = 3 * 1000; + master->set_cs = sun6i_spi_set_cs; +@@ -470,7 +477,8 @@ static int sun6i_spi_remove(struct platform_device *pdev) + } + + static const struct of_device_id sun6i_spi_match[] = { +- { .compatible = "allwinner,sun6i-a31-spi", }, ++ { .compatible = "allwinner,sun6i-a31-spi", .data = (void *)SUN6I_FIFO_DEPTH }, ++ { .compatible = "allwinner,sun8i-h3-spi", .data = (void *)SUN8I_FIFO_DEPTH }, + {} + }; + MODULE_DEVICE_TABLE(of, sun6i_spi_match);