2018-10-10 17:12:50

by Lubomir Rintel

[permalink] [raw]
Subject: [PATCH 0/11] spi: pxa2xx: add DT and slave mode support

Hi.

This patchset adds devicetree and slave mode support to pxa2xx SPI
controller. The objective is that it will be able to support the
OLPC XO 1.75 embedded controller that is a SPI master talking to a
MMP2 SOC. The EC driver will be submitted in a separate patch set
shortly.

These patches have been submitted previously, but not applied:

[PATCH v2 01/11] dt-bindings: spi/spi-pxa2xx: add PXA2xx SSP SPI
[PATCH v2 02/11] PCI: Provide pci_match_id() with CONFIG_PCI=n
[PATCH 03/11] spi: pxa2xx: Use an enum for type
[PATCH 04/11] spi: pxa2xx: Add devicetree support
[PATCH v2 05/11] DT: marvell,mmp2: Add SSP1 and SSP3

These are new:

[PATCH 06/11] dt-bindings: spi/spi-pxa2xx: Add spi-slave property
[PATCH 07/11] spi: Deal with slaves that return from transfer_one()
[PATCH 08/11] spi: pxa2xx: Add slave mode support
[PATCH 09/11] dt-bindings: spi/spi-pxa2xx: Add ready GPIO signal
[PATCH 10/11] spi: pxa2xx: Add ready signal
[PATCH 11/11] spi: pxa2xx: Deal with the leftover garbage in TXFIFO

Verified on a OLPC XO 1.75 machine.

Thank you,
Lubo



2018-10-10 17:10:55

by Lubomir Rintel

[permalink] [raw]
Subject: [PATCH v2 01/11] dt-bindings: spi/spi-pxa2xx: add PXA2xx SSP SPI Controller

This is the SPI controller found on Marvel MMP2 and perhaps more
platforms.

Reviewed-by: Rob Herring <[email protected]>
Signed-off-by: Lubomir Rintel <[email protected]>

---
Changes since v1:
- s/ssp@d4035000/spi@d4035000/

.../devicetree/bindings/spi/spi-pxa2xx.txt | 24 +++++++++++++++++++
1 file changed, 24 insertions(+)
create mode 100644 Documentation/devicetree/bindings/spi/spi-pxa2xx.txt

diff --git a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
new file mode 100644
index 000000000000..0335a9bd2e8a
--- /dev/null
+++ b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
@@ -0,0 +1,24 @@
+PXA2xx SSP SPI Controller
+
+Required properties:
+- compatible: Must be "marvell,mmp2-ssp".
+- reg: Offset and length of the device's register set.
+- interrupts: Should be the interrupt number.
+- clocks: Should contain a single entry describing the clock input.
+- #address-cells: Number of cells required to define a chip select address.
+- #size-cells: Should be zero.
+
+Optional properties:
+- cs-gpios: list of GPIO chip selects. See the SPI bus bindings,
+ Documentation/devicetree/bindings/spi/spi-bus.txt
+
+Child nodes represent devices on the SPI bus
+ See ../spi/spi-bus.txt
+
+Example:
+ ssp1: spi@d4035000 {
+ compatible = "marvell,mmp2-ssp";
+ reg = <0xd4035000 0x1000>;
+ clocks = <&soc_clocks MMP2_CLK_SSP0>;
+ interrupts = <0>;
+ };
--
2.19.0


2018-10-10 17:10:58

by Lubomir Rintel

[permalink] [raw]
Subject: [PATCH 05/11] DT: marvell,mmp2: Add SSP1 and SSP3

There seem to be SSP2, SSP4 and perhaps SSP5 too, but Marvel keeps their
base addresses secret.

The SSP1 and SSP3 addresses were taken from OLPC 1.75, OpenFirmware and
kernel respectively.

Signed-off-by: Lubomir Rintel <[email protected]>

---
Changes since v1:
- Dropped the aliases

arch/arm/boot/dts/mmp2.dtsi | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/arch/arm/boot/dts/mmp2.dtsi b/arch/arm/boot/dts/mmp2.dtsi
index 766bbb8495b6..c16531f4d4c7 100644
--- a/arch/arm/boot/dts/mmp2.dtsi
+++ b/arch/arm/boot/dts/mmp2.dtsi
@@ -239,6 +239,22 @@
resets = <&soc_clocks MMP2_CLK_RTC>;
status = "disabled";
};
+
+ ssp1: ssp@d4035000 {
+ compatible = "marvell,mmp2-ssp";
+ reg = <0xd4035000 0x1000>;
+ clocks = <&soc_clocks MMP2_CLK_SSP0>;
+ interrupts = <0>;
+ status = "disabled";
+ };
+
+ ssp3: ssp@d4037000 {
+ compatible = "marvell,mmp2-ssp";
+ reg = <0xd4037000 0x1000>;
+ clocks = <&soc_clocks MMP2_CLK_SSP2>;
+ interrupts = <20>;
+ status = "disabled";
+ };
};

soc_clocks: clocks{
--
2.19.0


2018-10-10 17:11:06

by Lubomir Rintel

[permalink] [raw]
Subject: [PATCH 03/11] spi: pxa2xx: Use an enum for type

That seems to be the correct type.

Signed-off-by: Lubomir Rintel <[email protected]>
---
drivers/spi/spi-pxa2xx.c | 6 +++---
include/linux/pxa2xx_ssp.h | 2 +-
2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index 14f4ea59caff..f674541675bb 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -1429,7 +1429,7 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev)
struct resource *res;
const struct acpi_device_id *adev_id = NULL;
const struct pci_device_id *pcidev_id = NULL;
- int type;
+ enum pxa_ssp_type type;

adev = ACPI_COMPANION(&pdev->dev);

@@ -1443,9 +1443,9 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev)
return NULL;

if (adev_id)
- type = (int)adev_id->driver_data;
+ type = (enum pxa_ssp_type)adev_id->driver_data;
else if (pcidev_id)
- type = (int)pcidev_id->driver_data;
+ type = (enum pxa_ssp_type)pcidev_id->driver_data;
else
return NULL;

diff --git a/include/linux/pxa2xx_ssp.h b/include/linux/pxa2xx_ssp.h
index 13b4244d44c1..262e1f318836 100644
--- a/include/linux/pxa2xx_ssp.h
+++ b/include/linux/pxa2xx_ssp.h
@@ -217,7 +217,7 @@ struct ssp_device {

const char *label;
int port_id;
- int type;
+ enum pxa_ssp_type type;
int use_count;
int irq;

--
2.19.0


2018-10-10 17:11:21

by Lubomir Rintel

[permalink] [raw]
Subject: [PATCH 09/11] dt-bindings: spi/spi-pxa2xx: Add ready GPIO signal

This this is used to let the SPI master know that our FIFO is filled and
we're ready to service a transfer. Only useful in slave mode.

A signal like this is used by an embedded controller on a OLPC XO 1.75
machine, that happens to be a SPI master.

Signed-off-by: Lubomir Rintel <[email protected]>
---
Documentation/devicetree/bindings/spi/spi-pxa2xx.txt | 2 ++
1 file changed, 2 insertions(+)

diff --git a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
index 89b2832283e3..681a82b40e6f 100644
--- a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
+++ b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
@@ -12,6 +12,8 @@ Optional properties:
- cs-gpios: list of GPIO chip selects. See the SPI bus bindings,
Documentation/devicetree/bindings/spi/spi-bus.txt
- spi-slave: Empty property indicating the SPI controller is used in slave mode.
+- ready-gpio: GPIO used to signal a SPI master that the FIFO is filled
+ and we're ready to service a transfer. Only useful in slave mode.

Child nodes represent devices on the SPI bus
See ../spi/spi-bus.txt
--
2.19.0


2018-10-10 17:11:22

by Lubomir Rintel

[permalink] [raw]
Subject: [PATCH 10/11] spi: pxa2xx: Add ready signal

Strobe a GPIO line when the slave TX FIFO is filled. This is how the
Embedded Controller on an OLPC XO-1.75 machine, that happens to be a SPI
master, learns that it can initiate a transaction.

Signed-off-by: Lubomir Rintel <[email protected]>
---
drivers/spi/spi-pxa2xx.c | 12 ++++++++++++
drivers/spi/spi-pxa2xx.h | 3 +++
2 files changed, 15 insertions(+)

diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index 3848842d68fd..a3b4b12c1077 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -1079,6 +1079,9 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master,
if (spi_controller_is_slave(master)) {
while (drv_data->write(drv_data))
;
+ gpiod_set_value(drv_data->gpiod_ready, 1);
+ udelay(1);
+ gpiod_set_value(drv_data->gpiod_ready, 0);
}

/*
@@ -1784,6 +1787,15 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
}
}

+ if (platform_info->is_slave) {
+ drv_data->gpiod_ready = devm_gpiod_get_optional(dev,
+ "ready", GPIOD_OUT_LOW);
+ if (IS_ERR(drv_data->gpiod_ready)) {
+ status = (int)PTR_ERR(drv_data->gpiod_ready);
+ goto out_error_clock_enabled;
+ }
+ }
+
pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
pm_runtime_use_autosuspend(&pdev->dev);
pm_runtime_set_active(&pdev->dev);
diff --git a/drivers/spi/spi-pxa2xx.h b/drivers/spi/spi-pxa2xx.h
index 513c53aaeab2..4e324da66ef7 100644
--- a/drivers/spi/spi-pxa2xx.h
+++ b/drivers/spi/spi-pxa2xx.h
@@ -64,6 +64,9 @@ struct driver_data {

/* GPIOs for chip selects */
struct gpio_desc **cs_gpiods;
+
+ /* Optional slave FIFO ready signal */
+ struct gpio_desc *gpiod_ready;
};

struct chip_data {
--
2.19.0


2018-10-10 17:11:25

by Lubomir Rintel

[permalink] [raw]
Subject: [PATCH 11/11] spi: pxa2xx: Deal with the leftover garbage in TXFIFO

There doesn't seem to be a way to empty TXFIFO on MMP2. The datasheet is
super-secret and the method described in Armada 16x manual won't work:

"The TXFIFO and RXFIFO are cleared to 0b0 when the SSPx port is reset or
disabled (by writing a 0b0 to the <Synchronous Serial Port Enable> field
in the SSP Control Register 0)."

# devmem 0xd4037008 # read SSSR
0x0000F204
# devmem 0xd4037000 32 0x80 # SSE off in SSCR0
# devmem 0xd4037000 32 0x87 # SSE on
# devmem 0xd4037008
0x0000F204
^ TXFIFO level is still 2. Sigh.

The OLPC 1.75 boot firmware leaves two bytes in the TXFIFO. Those are
basically throwaway bytes used in response to the messages from the EC.
The OLPC kernel copes with this by power-cycling the hardware. Perhaps
the firmware should do this instead.

Other than that, there's not much we can do other than complain loudly
until the garbage gets drained and discard the actual data... For the
OLPC EC this will work just fine and pushing more data to TXFIFO would
break further transactions.

Signed-off-by: Lubomir Rintel <[email protected]>
---
drivers/spi/spi-pxa2xx.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)

diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index a3b4b12c1077..2662b99d4439 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -1076,6 +1076,20 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master,
pxa2xx_spi_write(drv_data, SSTO, chip->timeout);
}

+ if (drv_data->ssp_type == MMP2_SSP) {
+ u8 tx_level = (pxa2xx_spi_read(drv_data, SSSR)
+ & SSSR_TFL_MASK) >> 8;
+
+ if (tx_level) {
+ /* On MMP2, flipping SSE doesn't to empty TXFIFO. */
+ dev_warn(&spi->dev, "%d bytes of garbage in TXFIFO!\n",
+ tx_level);
+ if (tx_level > transfer->len)
+ tx_level = transfer->len;
+ drv_data->tx += tx_level;
+ }
+ }
+
if (spi_controller_is_slave(master)) {
while (drv_data->write(drv_data))
;
--
2.19.0


2018-10-10 17:11:33

by Lubomir Rintel

[permalink] [raw]
Subject: [PATCH 08/11] spi: pxa2xx: Add slave mode support

Tested on an OLPC XO-1.75 machine, where the Embedded Controller happens
to be a SPI master.

Signed-off-by: Lubomir Rintel <[email protected]>
---
drivers/spi/spi-pxa2xx.c | 81 +++++++++++++++++++++++++++++++---
include/linux/spi/pxa2xx_spi.h | 1 +
2 files changed, 75 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index 58554c765a87..3848842d68fd 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -626,6 +626,11 @@ static irqreturn_t interrupt_transfer(struct driver_data *drv_data)
return IRQ_HANDLED;
}

+ if (irq_status & SSSR_TUR) {
+ int_error_stop(drv_data, "interrupt_transfer: fifo underrun");
+ return IRQ_HANDLED;
+ }
+
if (irq_status & SSSR_TINT) {
pxa2xx_spi_write(drv_data, SSSR, SSSR_TINT);
if (drv_data->read(drv_data)) {
@@ -1071,6 +1076,11 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master,
pxa2xx_spi_write(drv_data, SSTO, chip->timeout);
}

+ if (spi_controller_is_slave(master)) {
+ while (drv_data->write(drv_data))
+ ;
+ }
+
/*
* Release the data by enabling service requests and interrupts,
* without changing any mode bits
@@ -1080,6 +1090,27 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master,
return 1;
}

+static int pxa2xx_spi_slave_abort(struct spi_master *master)
+{
+ struct driver_data *drv_data = spi_controller_get_devdata(master);
+
+ /* Stop and reset SSP */
+ write_SSSR_CS(drv_data, drv_data->clear_sr);
+ reset_sccr1(drv_data);
+ if (!pxa25x_ssp_comp(drv_data))
+ pxa2xx_spi_write(drv_data, SSTO, 0);
+ pxa2xx_spi_flush(drv_data);
+ pxa2xx_spi_write(drv_data, SSCR0,
+ pxa2xx_spi_read(drv_data, SSCR0) & ~SSCR0_SSE);
+
+ dev_dbg(&drv_data->pdev->dev, "transfer aborted\n");
+
+ drv_data->master->cur_msg->status = -EINTR;
+ spi_finalize_current_transfer(drv_data->master);
+
+ return 0;
+}
+
static void pxa2xx_spi_handle_err(struct spi_controller *master,
struct spi_message *msg)
{
@@ -1207,9 +1238,14 @@ static int setup(struct spi_device *spi)
rx_thres = config->rx_threshold;
break;
default:
- tx_thres = TX_THRESH_DFLT;
tx_hi_thres = 0;
- rx_thres = RX_THRESH_DFLT;
+ if (spi_controller_is_slave(drv_data->master)) {
+ tx_thres = 1;
+ rx_thres = 2;
+ } else {
+ tx_thres = TX_THRESH_DFLT;
+ rx_thres = RX_THRESH_DFLT;
+ }
break;
}

@@ -1253,6 +1289,12 @@ static int setup(struct spi_device *spi)
if (chip_info->enable_loopback)
chip->cr1 = SSCR1_LBM;
}
+ if (spi_controller_is_slave(drv_data->master)) {
+ chip->cr1 |= SSCR1_SCFR;
+ chip->cr1 |= SSCR1_SCLKDIR;
+ chip->cr1 |= SSCR1_SFRMDIR;
+ chip->cr1 |= SSCR1_SPH;
+ }

chip->lpss_rx_threshold = SSIRF_RxThresh(rx_thres);
chip->lpss_tx_threshold = SSITF_TxLoThresh(tx_thres)
@@ -1492,6 +1534,13 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev)
}
#endif

+#if CONFIG_OF
+ if (of_id) {
+ pdata->is_slave = of_property_read_bool(pdev->dev.of_node,
+ "spi-slave");
+ }
+#endif
+
ssp->clk = devm_clk_get(&pdev->dev, NULL);
ssp->irq = platform_get_irq(pdev, 0);
ssp->type = type;
@@ -1557,7 +1606,11 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
return -ENODEV;
}

- master = spi_alloc_master(dev, sizeof(struct driver_data));
+ if (platform_info->is_slave)
+ master = spi_alloc_slave(dev, sizeof(struct driver_data));
+ else
+ master = spi_alloc_master(dev, sizeof(struct driver_data));
+
if (!master) {
dev_err(&pdev->dev, "cannot alloc spi_master\n");
pxa_ssp_free(ssp);
@@ -1579,6 +1632,7 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
master->setup = setup;
master->set_cs = pxa2xx_spi_set_cs;
master->transfer_one = pxa2xx_spi_transfer_one;
+ master->slave_abort = pxa2xx_spi_slave_abort;
master->handle_err = pxa2xx_spi_handle_err;
master->unprepare_transfer_hardware = pxa2xx_spi_unprepare_transfer;
master->fw_translate_cs = pxa2xx_spi_fw_translate_cs;
@@ -1608,7 +1662,8 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
drv_data->int_cr1 = SSCR1_TIE | SSCR1_RIE | SSCR1_TINTE;
drv_data->dma_cr1 = DEFAULT_DMA_CR1;
drv_data->clear_sr = SSSR_ROR | SSSR_TINT;
- drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS | SSSR_ROR;
+ drv_data->mask_sr = SSSR_TINT | SSSR_RFS | SSSR_TFS
+ | SSSR_ROR | SSSR_TUR;
}

status = request_irq(ssp->irq, ssp_int, IRQF_SHARED, dev_name(dev),
@@ -1656,10 +1711,22 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
pxa2xx_spi_write(drv_data, SSCR0, tmp);
break;
default:
- tmp = SSCR1_RxTresh(RX_THRESH_DFLT) |
- SSCR1_TxTresh(TX_THRESH_DFLT);
+
+ if (spi_controller_is_slave(master)) {
+ tmp = SSCR1_SCFR |
+ SSCR1_SCLKDIR |
+ SSCR1_SFRMDIR |
+ SSCR1_RxTresh(2) |
+ SSCR1_TxTresh(1) |
+ SSCR1_SPH;
+ } else {
+ tmp = SSCR1_RxTresh(RX_THRESH_DFLT) |
+ SSCR1_TxTresh(TX_THRESH_DFLT);
+ }
pxa2xx_spi_write(drv_data, SSCR1, tmp);
- tmp = SSCR0_SCR(2) | SSCR0_Motorola | SSCR0_DataSize(8);
+ tmp = SSCR0_Motorola | SSCR0_DataSize(8);
+ if (!spi_controller_is_slave(master))
+ tmp |= SSCR0_SCR(2);
pxa2xx_spi_write(drv_data, SSCR0, tmp);
break;
}
diff --git a/include/linux/spi/pxa2xx_spi.h b/include/linux/spi/pxa2xx_spi.h
index 9ec4c147abbc..b0674e330ef6 100644
--- a/include/linux/spi/pxa2xx_spi.h
+++ b/include/linux/spi/pxa2xx_spi.h
@@ -25,6 +25,7 @@ struct dma_chan;
struct pxa2xx_spi_master {
u16 num_chipselect;
u8 enable_dma;
+ bool is_slave;

/* DMA engine specific config */
bool (*dma_filter)(struct dma_chan *chan, void *param);
--
2.19.0


2018-10-10 17:11:50

by Lubomir Rintel

[permalink] [raw]
Subject: [PATCH 04/11] spi: pxa2xx: Add devicetree support

The MMP2 platform, that uses device tree, has this controller. Let's add
devicetree alongside platform & PCI.

Signed-off-by: Lubomir Rintel <[email protected]>
---
drivers/spi/spi-pxa2xx.c | 73 +++++++++++++++++++++++---------------
include/linux/pxa2xx_ssp.h | 1 +
2 files changed, 45 insertions(+), 29 deletions(-)

diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
index f674541675bb..58554c765a87 100644
--- a/drivers/spi/spi-pxa2xx.c
+++ b/drivers/spi/spi-pxa2xx.c
@@ -33,6 +33,7 @@
#include <linux/clk.h>
#include <linux/pm_runtime.h>
#include <linux/acpi.h>
+#include <linux/of_device.h>

#include "spi-pxa2xx.h"

@@ -1333,9 +1334,6 @@ static void cleanup(struct spi_device *spi)
kfree(chip);
}

-#ifdef CONFIG_PCI
-#ifdef CONFIG_ACPI
-
static const struct acpi_device_id pxa2xx_spi_acpi_match[] = {
{ "INT33C0", LPSS_LPT_SSP },
{ "INT33C1", LPSS_LPT_SSP },
@@ -1347,23 +1345,6 @@ static const struct acpi_device_id pxa2xx_spi_acpi_match[] = {
};
MODULE_DEVICE_TABLE(acpi, pxa2xx_spi_acpi_match);

-static int pxa2xx_spi_get_port_id(struct acpi_device *adev)
-{
- unsigned int devid;
- int port_id = -1;
-
- if (adev && adev->pnp.unique_id &&
- !kstrtouint(adev->pnp.unique_id, 0, &devid))
- port_id = devid;
- return port_id;
-}
-#else /* !CONFIG_ACPI */
-static int pxa2xx_spi_get_port_id(struct acpi_device *adev)
-{
- return -1;
-}
-#endif
-
/*
* PCI IDs of compound devices that integrate both host controller and private
* integrated DMA engine. Please note these are not used in module
@@ -1410,6 +1391,37 @@ static const struct pci_device_id pxa2xx_spi_pci_compound_match[] = {
{ },
};

+static const struct of_device_id pxa2xx_spi_of_match[] = {
+ { .compatible = "marvell,mmp2-ssp", .data = (void *)MMP2_SSP },
+ {},
+};
+MODULE_DEVICE_TABLE(of, pxa2xx_spi_of_match);
+
+#ifdef CONFIG_ACPI
+
+static int pxa2xx_spi_get_port_id(struct acpi_device *adev)
+{
+ unsigned int devid;
+ int port_id = -1;
+
+ if (adev && adev->pnp.unique_id &&
+ !kstrtouint(adev->pnp.unique_id, 0, &devid))
+ port_id = devid;
+ return port_id;
+}
+
+#else /* !CONFIG_ACPI */
+
+static int pxa2xx_spi_get_port_id(struct acpi_device *adev)
+{
+ return -1;
+}
+
+#endif /* CONFIG_ACPI */
+
+
+#ifdef CONFIG_PCI
+
static bool pxa2xx_spi_idma_filter(struct dma_chan *chan, void *param)
{
struct device *dev = param;
@@ -1420,6 +1432,8 @@ static bool pxa2xx_spi_idma_filter(struct dma_chan *chan, void *param)
return true;
}

+#endif /* CONFIG_PCI */
+
static struct pxa2xx_spi_master *
pxa2xx_spi_init_pdata(struct platform_device *pdev)
{
@@ -1429,11 +1443,15 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev)
struct resource *res;
const struct acpi_device_id *adev_id = NULL;
const struct pci_device_id *pcidev_id = NULL;
+ const struct of_device_id *of_id = NULL;
enum pxa_ssp_type type;

adev = ACPI_COMPANION(&pdev->dev);

- if (dev_is_pci(pdev->dev.parent))
+ if (pdev->dev.of_node)
+ of_id = of_match_device(pdev->dev.driver->of_match_table,
+ &pdev->dev);
+ else if (dev_is_pci(pdev->dev.parent))
pcidev_id = pci_match_id(pxa2xx_spi_pci_compound_match,
to_pci_dev(pdev->dev.parent));
else if (adev)
@@ -1446,6 +1464,8 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev)
type = (enum pxa_ssp_type)adev_id->driver_data;
else if (pcidev_id)
type = (enum pxa_ssp_type)pcidev_id->driver_data;
+ else if (of_id)
+ type = (enum pxa_ssp_type)of_id->data;
else
return NULL;

@@ -1464,11 +1484,13 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev)
if (IS_ERR(ssp->mmio_base))
return NULL;

+#ifdef CONFIG_PCI
if (pcidev_id) {
pdata->tx_param = pdev->dev.parent;
pdata->rx_param = pdev->dev.parent;
pdata->dma_filter = pxa2xx_spi_idma_filter;
}
+#endif

ssp->clk = devm_clk_get(&pdev->dev, NULL);
ssp->irq = platform_get_irq(pdev, 0);
@@ -1482,14 +1504,6 @@ pxa2xx_spi_init_pdata(struct platform_device *pdev)
return pdata;
}

-#else /* !CONFIG_PCI */
-static inline struct pxa2xx_spi_master *
-pxa2xx_spi_init_pdata(struct platform_device *pdev)
-{
- return NULL;
-}
-#endif
-
static int pxa2xx_spi_fw_translate_cs(struct spi_controller *master,
unsigned int cs)
{
@@ -1848,6 +1862,7 @@ static struct platform_driver driver = {
.name = "pxa2xx-spi",
.pm = &pxa2xx_spi_pm_ops,
.acpi_match_table = ACPI_PTR(pxa2xx_spi_acpi_match),
+ .of_match_table = of_match_ptr(pxa2xx_spi_of_match),
},
.probe = pxa2xx_spi_probe,
.remove = pxa2xx_spi_remove,
diff --git a/include/linux/pxa2xx_ssp.h b/include/linux/pxa2xx_ssp.h
index 262e1f318836..979087e021f3 100644
--- a/include/linux/pxa2xx_ssp.h
+++ b/include/linux/pxa2xx_ssp.h
@@ -196,6 +196,7 @@ enum pxa_ssp_type {
PXA27x_SSP,
PXA3xx_SSP,
PXA168_SSP,
+ MMP2_SSP,
PXA910_SSP,
CE4100_SSP,
QUARK_X1000_SSP,
--
2.19.0


2018-10-10 17:11:54

by Lubomir Rintel

[permalink] [raw]
Subject: [PATCH 07/11] spi: Deal with slaves that return from transfer_one() unfinished

Some drivers, such as spi-pxa2xx return from the transfer_one callback
immediately, idicating that the transfer will be finished asynchronously.

Normally, spi_transfer_one_message() synchronously waits for the
transfer to finish with wait_for_completion_timeout(). For slaves, we
don't want the transaction to time out as it can complete in a long time
in future. Use wait_for_completion_interruptible() instead.

Signed-off-by: Lubomir Rintel <[email protected]>
---
drivers/spi/spi.c | 64 +++++++++++++++++++++++++++++++----------------
1 file changed, 42 insertions(+), 22 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 9da0bc5a036c..079214a31d2c 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -993,6 +993,44 @@ static int spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
return __spi_map_msg(ctlr, msg);
}

+static int spi_transfer_wait(struct spi_controller *ctlr,
+ struct spi_message *msg,
+ struct spi_transfer *xfer)
+{
+ struct spi_statistics *statm = &ctlr->statistics;
+ struct spi_statistics *stats = &msg->spi->statistics;
+ unsigned long long ms = 1;
+
+ if (spi_controller_is_slave(ctlr)) {
+ if (wait_for_completion_interruptible(&ctlr->xfer_completion)) {
+ dev_dbg(&msg->spi->dev, "SPI transfer interrupted\n");
+ return -EINTR;
+ }
+ } else {
+ ms = 8LL * 1000LL * xfer->len;
+ do_div(ms, xfer->speed_hz);
+ ms += ms + 200; /* some tolerance */
+
+ if (ms > UINT_MAX)
+ ms = UINT_MAX;
+
+ ms = wait_for_completion_timeout(&ctlr->xfer_completion,
+ msecs_to_jiffies(ms));
+
+ if (ms == 0) {
+ SPI_STATISTICS_INCREMENT_FIELD(statm,
+ timedout);
+ SPI_STATISTICS_INCREMENT_FIELD(stats,
+ timedout);
+ dev_err(&msg->spi->dev,
+ "SPI transfer timed out\n");
+ msg->status = -ETIMEDOUT;
+ }
+ }
+
+ return 0;
+}
+
/*
* spi_transfer_one_message - Default implementation of transfer_one_message()
*
@@ -1006,7 +1044,6 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
struct spi_transfer *xfer;
bool keep_cs = false;
int ret = 0;
- unsigned long long ms = 1;
struct spi_statistics *statm = &ctlr->statistics;
struct spi_statistics *stats = &msg->spi->statistics;

@@ -1035,28 +1072,11 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
goto out;
}

- if (ret > 0) {
- ret = 0;
- ms = 8LL * 1000LL * xfer->len;
- do_div(ms, xfer->speed_hz);
- ms += ms + 200; /* some tolerance */
-
- if (ms > UINT_MAX)
- ms = UINT_MAX;
+ if (ret > 0)
+ ret = spi_transfer_wait(ctlr, msg, xfer);

- ms = wait_for_completion_timeout(&ctlr->xfer_completion,
- msecs_to_jiffies(ms));
- }
-
- if (ms == 0) {
- SPI_STATISTICS_INCREMENT_FIELD(statm,
- timedout);
- SPI_STATISTICS_INCREMENT_FIELD(stats,
- timedout);
- dev_err(&msg->spi->dev,
- "SPI transfer timed out\n");
- msg->status = -ETIMEDOUT;
- }
+ if (ret < 0)
+ return ret;
} else {
if (xfer->len)
dev_err(&msg->spi->dev,
--
2.19.0


2018-10-10 17:12:52

by Lubomir Rintel

[permalink] [raw]
Subject: [PATCH v2 02/11] PCI: Provide pci_match_id() with CONFIG_PCI=n

This spares drivers from #ifdef-ing on CONFIG_PCI if the driver can be
optionally built on machines without PCI bus.

Consistent with acpi_driver_match_device() and similar.

Acked-by: Bjorn Helgaas <[email protected]>
Signed-off-by: Lubomir Rintel <[email protected]>

---
Changes since v1:
- Capitalization in the commit message

include/linux/pci.h | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/include/linux/pci.h b/include/linux/pci.h
index 6925828f9f25..2c4755032475 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -1705,6 +1705,10 @@ static inline int pci_irqd_intx_xlate(struct irq_domain *d,
unsigned long *out_hwirq,
unsigned int *out_type)
{ return -EINVAL; }
+
+static inline const struct pci_device_id *pci_match_id(const struct pci_device_id *ids,
+ struct pci_dev *dev)
+{ return NULL; }
#endif /* CONFIG_PCI */

/* Include architecture-dependent settings and functions */
--
2.19.0


2018-10-10 17:13:20

by Lubomir Rintel

[permalink] [raw]
Subject: [PATCH 06/11] dt-bindings: spi/spi-pxa2xx: Add spi-slave property

This is used to indicate that the chip attached to this controller is a SPI
master.

Signed-off-by: Lubomir Rintel <[email protected]>
---
Documentation/devicetree/bindings/spi/spi-pxa2xx.txt | 1 +
1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
index 0335a9bd2e8a..89b2832283e3 100644
--- a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
+++ b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
@@ -11,6 +11,7 @@ Required properties:
Optional properties:
- cs-gpios: list of GPIO chip selects. See the SPI bus bindings,
Documentation/devicetree/bindings/spi/spi-bus.txt
+- spi-slave: Empty property indicating the SPI controller is used in slave mode.

Child nodes represent devices on the SPI bus
See ../spi/spi-bus.txt
--
2.19.0


2018-10-11 08:10:42

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 07/11] spi: Deal with slaves that return from transfer_one() unfinished

Hi Lubomir,

On Wed, Oct 10, 2018 at 7:10 PM Lubomir Rintel <[email protected]> wrote:
> Some drivers, such as spi-pxa2xx return from the transfer_one callback
> immediately, idicating that the transfer will be finished asynchronously.
>
> Normally, spi_transfer_one_message() synchronously waits for the
> transfer to finish with wait_for_completion_timeout(). For slaves, we
> don't want the transaction to time out as it can complete in a long time
> in future. Use wait_for_completion_interruptible() instead.
>
> Signed-off-by: Lubomir Rintel <[email protected]>

Thanks for your patch!

> --- a/drivers/spi/spi.c
> +++ b/drivers/spi/spi.c
> @@ -993,6 +993,44 @@ static int spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
> return __spi_map_msg(ctlr, msg);
> }
>
> +static int spi_transfer_wait(struct spi_controller *ctlr,
> + struct spi_message *msg,
> + struct spi_transfer *xfer)
> +{
> + struct spi_statistics *statm = &ctlr->statistics;
> + struct spi_statistics *stats = &msg->spi->statistics;
> + unsigned long long ms = 1;
> +
> + if (spi_controller_is_slave(ctlr)) {
> + if (wait_for_completion_interruptible(&ctlr->xfer_completion)) {
> + dev_dbg(&msg->spi->dev, "SPI transfer interrupted\n");
> + return -EINTR;

Why not setting msg->status = -EINTR here, but returning an error? ...

> + }
> + } else {
> + ms = 8LL * 1000LL * xfer->len;
> + do_div(ms, xfer->speed_hz);
> + ms += ms + 200; /* some tolerance */
> +
> + if (ms > UINT_MAX)
> + ms = UINT_MAX;
> +
> + ms = wait_for_completion_timeout(&ctlr->xfer_completion,
> + msecs_to_jiffies(ms));
> +
> + if (ms == 0) {
> + SPI_STATISTICS_INCREMENT_FIELD(statm,
> + timedout);
> + SPI_STATISTICS_INCREMENT_FIELD(stats,
> + timedout);
> + dev_err(&msg->spi->dev,
> + "SPI transfer timed out\n");
> + msg->status = -ETIMEDOUT;
> + }
> + }
> +
> + return 0;
> +}
> +
> /*
> * spi_transfer_one_message - Default implementation of transfer_one_message()
> *
> @@ -1006,7 +1044,6 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
> struct spi_transfer *xfer;
> bool keep_cs = false;
> int ret = 0;
> - unsigned long long ms = 1;
> struct spi_statistics *statm = &ctlr->statistics;
> struct spi_statistics *stats = &msg->spi->statistics;
>
> @@ -1035,28 +1072,11 @@ static int spi_transfer_one_message(struct spi_controller *ctlr,
> goto out;
> }
>
> - if (ret > 0) {
> - ret = 0;
> - ms = 8LL * 1000LL * xfer->len;
> - do_div(ms, xfer->speed_hz);
> - ms += ms + 200; /* some tolerance */
> -
> - if (ms > UINT_MAX)
> - ms = UINT_MAX;
> + if (ret > 0)
> + ret = spi_transfer_wait(ctlr, msg, xfer);
>
> - ms = wait_for_completion_timeout(&ctlr->xfer_completion,
> - msecs_to_jiffies(ms));
> - }
> -
> - if (ms == 0) {
> - SPI_STATISTICS_INCREMENT_FIELD(statm,
> - timedout);
> - SPI_STATISTICS_INCREMENT_FIELD(stats,
> - timedout);
> - dev_err(&msg->spi->dev,
> - "SPI transfer timed out\n");
> - msg->status = -ETIMEDOUT;
> - }
> + if (ret < 0)
> + return ret;

... which will return here, skipping all finalization and cleanup below?

> } else {
> if (xfer->len)
> dev_err(&msg->spi->dev,

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2018-10-11 08:11:23

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 09/11] dt-bindings: spi/spi-pxa2xx: Add ready GPIO signal

Hi Lubomir,

On Wed, Oct 10, 2018 at 7:10 PM Lubomir Rintel <[email protected]> wrote:
> This this is used to let the SPI master know that our FIFO is filled and
> we're ready to service a transfer. Only useful in slave mode.
>
> A signal like this is used by an embedded controller on a OLPC XO 1.75
> machine, that happens to be a SPI master.
>
> Signed-off-by: Lubomir Rintel <[email protected]>

Thanks for your patch!

> --- a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
> +++ b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
> @@ -12,6 +12,8 @@ Optional properties:
> - cs-gpios: list of GPIO chip selects. See the SPI bus bindings,
> Documentation/devicetree/bindings/spi/spi-bus.txt
> - spi-slave: Empty property indicating the SPI controller is used in slave mode.
> +- ready-gpio: GPIO used to signal a SPI master that the FIFO is filled

ready-gpios

Documentation/devicetree/bindings/gpio/gpio.txt:
"GPIO properties named "[<name>-]gpio" are valid and old
bindings use it, but are only supported for compatibility reasons
and should not
be used for newer bindings since it has been deprecated."

> + and we're ready to service a transfer. Only useful in slave mode.
>
> Child nodes represent devices on the SPI bus
> See ../spi/spi-bus.txt

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2018-10-11 08:11:39

by Geert Uytterhoeven

[permalink] [raw]
Subject: Re: [PATCH 10/11] spi: pxa2xx: Add ready signal

Hi Lubomir,

On Wed, Oct 10, 2018 at 7:10 PM Lubomir Rintel <[email protected]> wrote:
> Strobe a GPIO line when the slave TX FIFO is filled. This is how the
> Embedded Controller on an OLPC XO-1.75 machine, that happens to be a SPI
> master, learns that it can initiate a transaction.
>
> Signed-off-by: Lubomir Rintel <[email protected]>

Thanks for your patch!

I'm repeating my comments on the RFC below:

> --- a/drivers/spi/spi-pxa2xx.c
> +++ b/drivers/spi/spi-pxa2xx.c
> @@ -1079,6 +1079,9 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master,
> if (spi_controller_is_slave(master)) {
> while (drv_data->write(drv_data))
> ;
> + gpiod_set_value(drv_data->gpiod_ready, 1);
> + udelay(1);
> + gpiod_set_value(drv_data->gpiod_ready, 0);

While gpiod_set_value() handles the case of no GPIO fine, I think it's
better to explicitly check for that, so you can avoid spinning for 1 µs if
the GPIO is not present.

> }
>
> /*
> @@ -1784,6 +1787,15 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
> }
> }
>
> + if (platform_info->is_slave) {
> + drv_data->gpiod_ready = devm_gpiod_get_optional(dev,
> + "ready", GPIOD_OUT_LOW);
> + if (IS_ERR(drv_data->gpiod_ready)) {
> + status = (int)PTR_ERR(drv_data->gpiod_ready);

The cast to int is not needed.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

2018-10-11 14:28:18

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v2 01/11] dt-bindings: spi/spi-pxa2xx: add PXA2xx SSP SPI Controller

On Wed, Oct 10, 2018 at 07:09:26PM +0200, Lubomir Rintel wrote:
> This is the SPI controller found on Marvel MMP2 and perhaps more
> platforms.

*Way* more.

Please use subject lines matching the style for the subsystem. This
makes it easier for people to identify relevant patches.


Attachments:
(No filename) (292.00 B)
signature.asc (499.00 B)
Download all attachments

2018-10-11 16:15:38

by Lubomir Rintel

[permalink] [raw]
Subject: Re: [PATCH 10/11] spi: pxa2xx: Add ready signal

On Thu, 2018-10-11 at 09:28 +0200, Geert Uytterhoeven wrote:
> Hi Lubomir,
>
> On Wed, Oct 10, 2018 at 7:10 PM Lubomir Rintel <[email protected]>
> wrote:
> > Strobe a GPIO line when the slave TX FIFO is filled. This is how
> > the
> > Embedded Controller on an OLPC XO-1.75 machine, that happens to be
> > a SPI
> > master, learns that it can initiate a transaction.
> >
> > Signed-off-by: Lubomir Rintel <[email protected]>
>
> Thanks for your patch!
>
> I'm repeating my comments on the RFC below:

Ah, sorry for not addressing those; it somehow slipped through my
fingers. I'll wait a while to collect more feedback before sending v2
and then I'll include fixes for those.

Thanks for the review.

Lubo


2018-10-11 19:35:36

by Lubomir Rintel

[permalink] [raw]
Subject: Re: [PATCH v2 01/11] dt-bindings: spi/spi-pxa2xx: add PXA2xx SSP SPI Controller

On Thu, 2018-10-11 at 15:27 +0100, Mark Brown wrote:
> On Wed, Oct 10, 2018 at 07:09:26PM +0200, Lubomir Rintel wrote:
> > This is the SPI controller found on Marvel MMP2 and perhaps more
> > platforms.
>
> *Way* more.
>
> Please use subject lines matching the style for the subsystem. This
> makes it easier for people to identify relevant patches.

Thanks for the response.

I'm a little confused here. Why I chose this subject line is because I
did this:

git log --no-merges Documentation/devicetree/bindings/

to figure out what's the typical subject for the DT binding changes.

I also believed that's the right way to get Rob Herring's and Mark
Rutland's attention. Do the device tree binding documentation typically
go in with the associated drivers, or via their tree ("OPEN FIRMWARE
AND FLATTENED DEVICE TREE BINDINGS" in MAINTIANERS)?

Lubo


2018-10-12 17:02:21

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v2 01/11] dt-bindings: spi/spi-pxa2xx: add PXA2xx SSP SPI Controller

On Thu, Oct 11, 2018 at 07:59:15PM +0200, Lubomir Rintel wrote:
> On Thu, 2018-10-11 at 15:27 +0100, Mark Brown wrote:

> > Please use subject lines matching the style for the subsystem. This
> > makes it easier for people to identify relevant patches.

> Thanks for the response.

> I'm a little confused here. Why I chose this subject line is because I
> did this:

> git log --no-merges Documentation/devicetree/bindings/

Try Documentation/devicetree/bindings/spi instead :)

> to figure out what's the typical subject for the DT binding changes.

> I also believed that's the right way to get Rob Herring's and Mark
> Rutland's attention. Do the device tree binding documentation typically

There *is* some debate for the DT bindings unfortunately.

> go in with the associated drivers, or via their tree ("OPEN FIRMWARE
> AND FLATTENED DEVICE TREE BINDINGS" in MAINTIANERS)?

They usually go in with the drivers. This one isn't so bad since it
does mention SPI, it's a worse problem when that's not present at all.


Attachments:
(No filename) (1.03 kB)
signature.asc (499.00 B)
Download all attachments

2018-10-17 19:33:01

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH v2 01/11] dt-bindings: spi/spi-pxa2xx: add PXA2xx SSP SPI Controller

On Fri, Oct 12, 2018 at 07:00:02PM +0200, Mark Brown wrote:
> On Thu, Oct 11, 2018 at 07:59:15PM +0200, Lubomir Rintel wrote:
> > On Thu, 2018-10-11 at 15:27 +0100, Mark Brown wrote:
>
> > > Please use subject lines matching the style for the subsystem. This
> > > makes it easier for people to identify relevant patches.
>
> > Thanks for the response.
>
> > I'm a little confused here. Why I chose this subject line is because I
> > did this:
>
> > git log --no-merges Documentation/devicetree/bindings/
>
> Try Documentation/devicetree/bindings/spi instead :)

Just so you know, pretty much everything else except SPI, regulators,
and ASoC follows 'dt-bindings: <binding dir>:' these days.

I don't really care so much about the difference, but it is tribal
knowledge that submitters have to learn.

Really, this could all be solved with tooling using MAINTAINERS and
get_maintainers.pl, but limping around in checkpatch.pl occasionally is
enough perl for me.

> > to figure out what's the typical subject for the DT binding changes.
>
> > I also believed that's the right way to get Rob Herring's and Mark
> > Rutland's attention.

All that matters is CC'ing the DT list really. And Mark R is pretty much
AWOL. Reviewing bindings in front of your own will get yours reviewed
faster. :)

> Do the device tree binding documentation typically
>
> There *is* some debate for the DT bindings unfortunately.
>
> > go in with the associated drivers, or via their tree ("OPEN FIRMWARE
> > AND FLATTENED DEVICE TREE BINDINGS" in MAINTIANERS)?
>
> They usually go in with the drivers. This one isn't so bad since it
> does mention SPI, it's a worse problem when that's not present at all.

Right.

I generally only take single patches not in a series with dts or driver
changes and when/if the subsystem maintainer doesn't pick them up. Or
any standalone fixes I'll take.

Rob

2018-10-17 19:34:38

by Rob Herring

[permalink] [raw]
Subject: Re: [PATCH 06/11] dt-bindings: spi/spi-pxa2xx: Add spi-slave property

On Wed, Oct 10, 2018 at 07:09:31PM +0200, Lubomir Rintel wrote:
> This is used to indicate that the chip attached to this controller is a SPI
> master.
>
> Signed-off-by: Lubomir Rintel <[email protected]>
> ---
> Documentation/devicetree/bindings/spi/spi-pxa2xx.txt | 1 +
> 1 file changed, 1 insertion(+)

This could be rolled into patch 1. Either way,

Reviewed-by: Rob Herring <[email protected]>

2018-10-29 05:44:02

by James Cameron

[permalink] [raw]
Subject: Re: [PATCH 05/11] DT: marvell,mmp2: Add SSP1 and SSP3

On Wed, Oct 10, 2018 at 07:09:30PM +0200, Lubomir Rintel wrote:
> There seem to be SSP2, SSP4 and perhaps SSP5 too, but Marvel keeps their
> base addresses secret.
>
> The SSP1 and SSP3 addresses were taken from OLPC 1.75, OpenFirmware and
> kernel respectively.

Sorry for the delay. Love your work! From my notes, SSP2 is
0xd4036000, and SSP4 is 0xd4039000. Can be probed by hand in
OpenFirmware or CForth once clocks are on.

--
James Cameron
http://quozl.netrek.org/

2018-11-04 12:14:59

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH 07/11] spi: Deal with slaves that return from transfer_one() unfinished

On Wed 2018-10-10 19:09:32, Lubomir Rintel wrote:
> Some drivers, such as spi-pxa2xx return from the transfer_one callback
> immediately, idicating that the transfer will be finished asynchronously.
>
> Normally, spi_transfer_one_message() synchronously waits for the
> transfer to finish with wait_for_completion_timeout(). For slaves, we
> don't want the transaction to time out as it can complete in a long time
> in future. Use wait_for_completion_interruptible() instead.
>
> Signed-off-by: Lubomir Rintel <[email protected]>

Acked-by: Pavel Machek <[email protected]>

> @@ -993,6 +993,44 @@ static int spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
> return __spi_map_msg(ctlr, msg);
> }
>
> +static int spi_transfer_wait(struct spi_controller *ctlr,
> + struct spi_message *msg,
> + struct spi_transfer *xfer)
> +{
> + struct spi_statistics *statm = &ctlr->statistics;
> + struct spi_statistics *stats = &msg->spi->statistics;
> + unsigned long long ms = 1;
> +
> + if (spi_controller_is_slave(ctlr)) {
> + if (wait_for_completion_interruptible(&ctlr->xfer_completion)) {
> + dev_dbg(&msg->spi->dev, "SPI transfer interrupted\n");
> + return -EINTR;
> + }

Do "return 0" here, and you can get rid of the else branch.

> + } else {
> + ms = 8LL * 1000LL * xfer->len;
> + do_div(ms, xfer->speed_hz);
> + ms += ms + 200; /* some tolerance */
> +
> + if (ms > UINT_MAX)
> + ms = UINT_MAX;
> +
> + ms = wait_for_completion_timeout(&ctlr->xfer_completion,
> + msecs_to_jiffies(ms));
> +
> + if (ms == 0) {
> + SPI_STATISTICS_INCREMENT_FIELD(statm,
> + timedout);
> + SPI_STATISTICS_INCREMENT_FIELD(stats,
> + timedout);
> + dev_err(&msg->spi->dev,
> + "SPI transfer timed out\n");
> + msg->status = -ETIMEDOUT;
> + }
> + }
> +
> + return 0;
> +}
> +
> /*
> * spi_transfer_one_message - Default implementation of transfer_one_message()
> *

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (2.09 kB)
signature.asc (188.00 B)
Digital signature
Download all attachments

2018-11-04 12:32:00

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH v2 01/11] dt-bindings: spi/spi-pxa2xx: add PXA2xx SSP SPI Controller

On Wed 2018-10-10 19:09:26, Lubomir Rintel wrote:
> This is the SPI controller found on Marvel MMP2 and perhaps more
> platforms.
>
> Reviewed-by: Rob Herring <[email protected]>
> Signed-off-by: Lubomir Rintel <[email protected]>

Acked-by: Pavel Machek <[email protected]>

Rob, do you want to apply this?

Pavel

> @@ -0,0 +1,24 @@
> +PXA2xx SSP SPI Controller
> +
> +Required properties:
> +- compatible: Must be "marvell,mmp2-ssp".
> +- reg: Offset and length of the device's register set.
> +- interrupts: Should be the interrupt number.
> +- clocks: Should contain a single entry describing the clock input.
> +- #address-cells: Number of cells required to define a chip select address.
> +- #size-cells: Should be zero.
> +
> +Optional properties:
> +- cs-gpios: list of GPIO chip selects. See the SPI bus bindings,
> + Documentation/devicetree/bindings/spi/spi-bus.txt
> +
> +Child nodes represent devices on the SPI bus
> + See ../spi/spi-bus.txt
> +
> +Example:
> + ssp1: spi@d4035000 {
> + compatible = "marvell,mmp2-ssp";
> + reg = <0xd4035000 0x1000>;
> + clocks = <&soc_clocks MMP2_CLK_SSP0>;
> + interrupts = <0>;
> + };

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (1.29 kB)
signature.asc (188.00 B)
Digital signature
Download all attachments

2018-11-04 12:32:58

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH v2 02/11] PCI: Provide pci_match_id() with CONFIG_PCI=n

On Wed 2018-10-10 19:09:27, Lubomir Rintel wrote:
> This spares drivers from #ifdef-ing on CONFIG_PCI if the driver can be
> optionally built on machines without PCI bus.
>
> Consistent with acpi_driver_match_device() and similar.
>
> Acked-by: Bjorn Helgaas <[email protected]>
> Signed-off-by: Lubomir Rintel <[email protected]>

Acked-by: Pavel Machek <[email protected]>
Pavel

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (538.00 B)
signature.asc (188.00 B)
Digital signature
Download all attachments

2018-11-04 12:33:00

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH 03/11] spi: pxa2xx: Use an enum for type

On Wed 2018-10-10 19:09:28, Lubomir Rintel wrote:
> That seems to be the correct type.
>
> Signed-off-by: Lubomir Rintel <[email protected]>

Acked-by: Pavel Machek <[email protected]>

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (325.00 B)
signature.asc (188.00 B)
Digital signature
Download all attachments

2018-11-04 12:34:09

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH 04/11] spi: pxa2xx: Add devicetree support

On Wed 2018-10-10 19:09:29, Lubomir Rintel wrote:
> The MMP2 platform, that uses device tree, has this controller. Let's add
> devicetree alongside platform & PCI.
>
> Signed-off-by: Lubomir Rintel <[email protected]>

Acked-by: Pavel Machek <[email protected]>


--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (405.00 B)
signature.asc (188.00 B)
Digital signature
Download all attachments

2018-11-04 12:34:54

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH 05/11] DT: marvell,mmp2: Add SSP1 and SSP3

On Wed 2018-10-10 19:09:30, Lubomir Rintel wrote:
> There seem to be SSP2, SSP4 and perhaps SSP5 too, but Marvel keeps their
> base addresses secret.
>
> The SSP1 and SSP3 addresses were taken from OLPC 1.75, OpenFirmware and
> kernel respectively.
>
> Signed-off-by: Lubomir Rintel <[email protected]>

Acked-by: Pavel Machek <[email protected]>

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (492.00 B)
signature.asc (188.00 B)
Digital signature
Download all attachments

2018-11-04 12:35:15

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH 06/11] dt-bindings: spi/spi-pxa2xx: Add spi-slave property

On Wed 2018-10-10 19:09:31, Lubomir Rintel wrote:
> This is used to indicate that the chip attached to this controller is a SPI
> master.
>
> Signed-off-by: Lubomir Rintel <[email protected]>
> Reviewed-by: Rob Herring <[email protected]>

Acked-by: Pavel Machek <[email protected]>

Rob, can you apply this?
Pavel

> ---
> Documentation/devicetree/bindings/spi/spi-pxa2xx.txt | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
> index 0335a9bd2e8a..89b2832283e3 100644
> --- a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
> +++ b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
> @@ -11,6 +11,7 @@ Required properties:
> Optional properties:
> - cs-gpios: list of GPIO chip selects. See the SPI bus bindings,
> Documentation/devicetree/bindings/spi/spi-bus.txt
> +- spi-slave: Empty property indicating the SPI controller is used in slave mode.
>
> Child nodes represent devices on the SPI bus
> See ../spi/spi-bus.txt

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (1.20 kB)
signature.asc (188.00 B)
Digital signature
Download all attachments

2018-11-04 13:53:25

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH 08/11] spi: pxa2xx: Add slave mode support

On Wed 2018-10-10 19:09:33, Lubomir Rintel wrote:
> Tested on an OLPC XO-1.75 machine, where the Embedded Controller happens
> to be a SPI master.
>
> Signed-off-by: Lubomir Rintel <[email protected]>

Acked-by: Pavel Machek <[email protected]>


--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (388.00 B)
signature.asc (188.00 B)
Digital signature
Download all attachments

2018-11-04 13:53:25

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH 11/11] spi: pxa2xx: Deal with the leftover garbage in TXFIFO

On Wed 2018-10-10 19:09:36, Lubomir Rintel wrote:
> There doesn't seem to be a way to empty TXFIFO on MMP2. The datasheet is
> super-secret and the method described in Armada 16x manual won't work:
>
> "The TXFIFO and RXFIFO are cleared to 0b0 when the SSPx port is reset or
> disabled (by writing a 0b0 to the <Synchronous Serial Port Enable> field
> in the SSP Control Register 0)."
>
> # devmem 0xd4037008 # read SSSR
> 0x0000F204
> # devmem 0xd4037000 32 0x80 # SSE off in SSCR0
> # devmem 0xd4037000 32 0x87 # SSE on
> # devmem 0xd4037008
> 0x0000F204
> ^ TXFIFO level is still 2. Sigh.
>
> The OLPC 1.75 boot firmware leaves two bytes in the TXFIFO. Those are
> basically throwaway bytes used in response to the messages from the EC.
> The OLPC kernel copes with this by power-cycling the hardware. Perhaps
> the firmware should do this instead.
>
> Other than that, there's not much we can do other than complain loudly
> until the garbage gets drained and discard the actual data... For the
> OLPC EC this will work just fine and pushing more data to TXFIFO would
> break further transactions.
>
> Signed-off-by: Lubomir Rintel <[email protected]>

Acked-by: Pavel Machek <[email protected]>

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (1.38 kB)
signature.asc (188.00 B)
Digital signature
Download all attachments

2018-11-04 13:53:25

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH 09/11] dt-bindings: spi/spi-pxa2xx: Add ready GPIO signal

On Wed 2018-10-10 19:09:34, Lubomir Rintel wrote:
> This this is used to let the SPI master know that our FIFO is filled and
> we're ready to service a transfer. Only useful in slave mode.
>
> A signal like this is used by an embedded controller on a OLPC XO 1.75
> machine, that happens to be a SPI master.
>
> Signed-off-by: Lubomir Rintel <[email protected]>

Acked-by: Pavel Machek <[email protected]>

> ---
> Documentation/devicetree/bindings/spi/spi-pxa2xx.txt | 2 ++
> 1 file changed, 2 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
> index 89b2832283e3..681a82b40e6f 100644
> --- a/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
> +++ b/Documentation/devicetree/bindings/spi/spi-pxa2xx.txt
> @@ -12,6 +12,8 @@ Optional properties:
> - cs-gpios: list of GPIO chip selects. See the SPI bus bindings,
> Documentation/devicetree/bindings/spi/spi-bus.txt
> - spi-slave: Empty property indicating the SPI controller is used in slave mode.
> +- ready-gpio: GPIO used to signal a SPI master that the FIFO is filled
> + and we're ready to service a transfer. Only useful in slave mode.
>
> Child nodes represent devices on the SPI bus
> See ../spi/spi-bus.txt

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (1.40 kB)
signature.asc (188.00 B)
Digital signature
Download all attachments

2018-11-04 13:53:25

by Pavel Machek

[permalink] [raw]
Subject: Re: [PATCH 10/11] spi: pxa2xx: Add ready signal

On Wed 2018-10-10 19:09:35, Lubomir Rintel wrote:
> Strobe a GPIO line when the slave TX FIFO is filled. This is how the
> Embedded Controller on an OLPC XO-1.75 machine, that happens to be a SPI
> master, learns that it can initiate a transaction.
>
> Signed-off-by: Lubomir Rintel <[email protected]>

Acked-by: Pavel Machek <[email protected]>

> ---
> drivers/spi/spi-pxa2xx.c | 12 ++++++++++++
> drivers/spi/spi-pxa2xx.h | 3 +++
> 2 files changed, 15 insertions(+)
>
> diff --git a/drivers/spi/spi-pxa2xx.c b/drivers/spi/spi-pxa2xx.c
> index 3848842d68fd..a3b4b12c1077 100644
> --- a/drivers/spi/spi-pxa2xx.c
> +++ b/drivers/spi/spi-pxa2xx.c
> @@ -1079,6 +1079,9 @@ static int pxa2xx_spi_transfer_one(struct spi_controller *master,
> if (spi_controller_is_slave(master)) {
> while (drv_data->write(drv_data))
> ;
> + gpiod_set_value(drv_data->gpiod_ready, 1);
> + udelay(1);
> + gpiod_set_value(drv_data->gpiod_ready, 0);
> }
>
> /*
> @@ -1784,6 +1787,15 @@ static int pxa2xx_spi_probe(struct platform_device *pdev)
> }
> }
>
> + if (platform_info->is_slave) {
> + drv_data->gpiod_ready = devm_gpiod_get_optional(dev,
> + "ready", GPIOD_OUT_LOW);
> + if (IS_ERR(drv_data->gpiod_ready)) {
> + status = (int)PTR_ERR(drv_data->gpiod_ready);
> + goto out_error_clock_enabled;
> + }
> + }
> +
> pm_runtime_set_autosuspend_delay(&pdev->dev, 50);
> pm_runtime_use_autosuspend(&pdev->dev);
> pm_runtime_set_active(&pdev->dev);
> diff --git a/drivers/spi/spi-pxa2xx.h b/drivers/spi/spi-pxa2xx.h
> index 513c53aaeab2..4e324da66ef7 100644
> --- a/drivers/spi/spi-pxa2xx.h
> +++ b/drivers/spi/spi-pxa2xx.h
> @@ -64,6 +64,9 @@ struct driver_data {
>
> /* GPIOs for chip selects */
> struct gpio_desc **cs_gpiods;
> +
> + /* Optional slave FIFO ready signal */
> + struct gpio_desc *gpiod_ready;
> };
>
> struct chip_data {

--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html


Attachments:
(No filename) (2.02 kB)
signature.asc (188.00 B)
Digital signature
Download all attachments