* [PATCH 1/2] spi: mvebu: add LSB support
@ 2016-12-08 10:52 Uwe Kleine-König
2016-12-08 10:52 ` [PATCH 2/2] spi: mvebu: improve error reporting Uwe Kleine-König
2016-12-12 5:45 ` [PATCH 1/2] spi: mvebu: add LSB support Sascha Hauer
0 siblings, 2 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2016-12-08 10:52 UTC (permalink / raw)
To: barebox
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/spi/mvebu_spi.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/mvebu_spi.c b/drivers/spi/mvebu_spi.c
index 6921cb8cd7db..c5d8732e4f84 100644
--- a/drivers/spi/mvebu_spi.c
+++ b/drivers/spi/mvebu_spi.c
@@ -31,8 +31,13 @@
#define IF_READ_READY BIT(1)
#define IF_CS_ENABLE BIT(0)
#define SPI_IF_CONFIG 0x04
+
+#define IF_RXLSBF BIT(14)
+#define IF_TXLSBF BIT(13)
+
#define IF_CLK_DIV(x) ((x) << 11)
#define IF_CLK_DIV_MASK (0x7 << 11)
+
#define IF_FAST_READ BIT(10)
#define IF_ADDRESS_LEN_4BYTE (3 << 8)
#define IF_ADDRESS_LEN_3BYTE (2 << 8)
@@ -192,6 +197,8 @@ static int dove_spi_set_baudrate(struct mvebu_spi *p, u32 speed)
static int mvebu_spi_set_mode(struct mvebu_spi *p, u8 mode)
{
+ u32 val;
+
/*
* From public datasheets of Orion SoCs, it is unclear
* if the SPI controller supports setting CPOL/CPHA.
@@ -202,12 +209,19 @@ static int mvebu_spi_set_mode(struct mvebu_spi *p, u8 mode)
* other mode than SPI_MODE0.
*/
- if ((mode & (SPI_CPOL|SPI_CPHA)) == SPI_MODE_0)
- return 0;
+ if ((mode & (SPI_CPOL|SPI_CPHA)) != SPI_MODE_0) {
+ pr_err("%s: unsupported SPI mode %02x\n", __func__, mode);
+ return -EINVAL;
+ }
- pr_err("%s: unsupported SPI mode %02x\n", __func__, mode);
+ val = readl(p->base + SPI_IF_CONFIG);
+ if (mode & SPI_LSB_FIRST)
+ val |= IF_RXLSBF | IF_TXLSBF;
+ else
+ val &= ~(IF_RXLSBF | IF_TXLSBF);
+ writel(val, p->base + SPI_IF_CONFIG);
- return -EINVAL;
+ return 0;
}
static int mvebu_spi_setup(struct spi_device *spi)
@@ -293,6 +307,12 @@ static int mvebu_spi_transfer(struct spi_device *spi, struct spi_message *msg)
int ret;
struct mvebu_spi *priv = priv_from_spi_device(spi);
+ ret = mvebu_spi_set_mode(priv, spi->mode);
+ if (ret) {
+ dev_err(&spi->dev, "Failed to set mode (0x%x)\n", (unsigned)spi->mode);
+ return ret;
+ }
+
ret = mvebu_spi_set_cs(priv, spi->chip_select, spi->mode, true);
if (ret)
return ret;
--
2.10.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 2/2] spi: mvebu: improve error reporting
2016-12-08 10:52 [PATCH 1/2] spi: mvebu: add LSB support Uwe Kleine-König
@ 2016-12-08 10:52 ` Uwe Kleine-König
2016-12-12 5:45 ` [PATCH 1/2] spi: mvebu: add LSB support Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Uwe Kleine-König @ 2016-12-08 10:52 UTC (permalink / raw)
To: barebox
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/spi/mvebu_spi.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)
diff --git a/drivers/spi/mvebu_spi.c b/drivers/spi/mvebu_spi.c
index c5d8732e4f84..14ab39603cbb 100644
--- a/drivers/spi/mvebu_spi.c
+++ b/drivers/spi/mvebu_spi.c
@@ -264,13 +264,19 @@ static int mvebu_spi_do_transfer(struct spi_device *spi,
if (t->bits_per_word)
ret = mvebu_spi_set_transfer_size(priv, spi->bits_per_word);
- if (ret)
+ if (ret) {
+ dev_err(&spi->dev, "Failed to set transfer size (bpw = %u)\n",
+ (unsigned)spi->bits_per_word);
return ret;
+ }
if (t->speed_hz)
ret = priv->set_baudrate(priv, t->speed_hz);
- if (ret)
+ if (ret) {
+ dev_err(&spi->dev, "Failed to set baudrate to %u Hz\n",
+ (unsigned)t->speed_hz);
return ret;
+ }
inc = (priv->data16) ? 2 : 1;
for (n = 0; n < t->len; n += inc) {
@@ -314,8 +320,10 @@ static int mvebu_spi_transfer(struct spi_device *spi, struct spi_message *msg)
}
ret = mvebu_spi_set_cs(priv, spi->chip_select, spi->mode, true);
- if (ret)
+ if (ret) {
+ dev_err(&spi->dev, "Failed to set chip select\n");
return ret;
+ }
msg->actual_length = 0;
--
2.10.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 1/2] spi: mvebu: add LSB support
2016-12-08 10:52 [PATCH 1/2] spi: mvebu: add LSB support Uwe Kleine-König
2016-12-08 10:52 ` [PATCH 2/2] spi: mvebu: improve error reporting Uwe Kleine-König
@ 2016-12-12 5:45 ` Sascha Hauer
1 sibling, 0 replies; 3+ messages in thread
From: Sascha Hauer @ 2016-12-12 5:45 UTC (permalink / raw)
To: Uwe Kleine-König; +Cc: barebox
On Thu, Dec 08, 2016 at 11:52:25AM +0100, Uwe Kleine-König wrote:
> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
> ---
> drivers/spi/mvebu_spi.c | 28 ++++++++++++++++++++++++----
> 1 file changed, 24 insertions(+), 4 deletions(-)
Applied, thanks
Sascha
>
> diff --git a/drivers/spi/mvebu_spi.c b/drivers/spi/mvebu_spi.c
> index 6921cb8cd7db..c5d8732e4f84 100644
> --- a/drivers/spi/mvebu_spi.c
> +++ b/drivers/spi/mvebu_spi.c
> @@ -31,8 +31,13 @@
> #define IF_READ_READY BIT(1)
> #define IF_CS_ENABLE BIT(0)
> #define SPI_IF_CONFIG 0x04
> +
> +#define IF_RXLSBF BIT(14)
> +#define IF_TXLSBF BIT(13)
> +
> #define IF_CLK_DIV(x) ((x) << 11)
> #define IF_CLK_DIV_MASK (0x7 << 11)
> +
> #define IF_FAST_READ BIT(10)
> #define IF_ADDRESS_LEN_4BYTE (3 << 8)
> #define IF_ADDRESS_LEN_3BYTE (2 << 8)
> @@ -192,6 +197,8 @@ static int dove_spi_set_baudrate(struct mvebu_spi *p, u32 speed)
>
> static int mvebu_spi_set_mode(struct mvebu_spi *p, u8 mode)
> {
> + u32 val;
> +
> /*
> * From public datasheets of Orion SoCs, it is unclear
> * if the SPI controller supports setting CPOL/CPHA.
> @@ -202,12 +209,19 @@ static int mvebu_spi_set_mode(struct mvebu_spi *p, u8 mode)
> * other mode than SPI_MODE0.
> */
>
> - if ((mode & (SPI_CPOL|SPI_CPHA)) == SPI_MODE_0)
> - return 0;
> + if ((mode & (SPI_CPOL|SPI_CPHA)) != SPI_MODE_0) {
> + pr_err("%s: unsupported SPI mode %02x\n", __func__, mode);
> + return -EINVAL;
> + }
>
> - pr_err("%s: unsupported SPI mode %02x\n", __func__, mode);
> + val = readl(p->base + SPI_IF_CONFIG);
> + if (mode & SPI_LSB_FIRST)
> + val |= IF_RXLSBF | IF_TXLSBF;
> + else
> + val &= ~(IF_RXLSBF | IF_TXLSBF);
> + writel(val, p->base + SPI_IF_CONFIG);
>
> - return -EINVAL;
> + return 0;
> }
>
> static int mvebu_spi_setup(struct spi_device *spi)
> @@ -293,6 +307,12 @@ static int mvebu_spi_transfer(struct spi_device *spi, struct spi_message *msg)
> int ret;
> struct mvebu_spi *priv = priv_from_spi_device(spi);
>
> + ret = mvebu_spi_set_mode(priv, spi->mode);
> + if (ret) {
> + dev_err(&spi->dev, "Failed to set mode (0x%x)\n", (unsigned)spi->mode);
> + return ret;
> + }
> +
> ret = mvebu_spi_set_cs(priv, spi->chip_select, spi->mode, true);
> if (ret)
> return ret;
> --
> 2.10.2
>
>
> _______________________________________________
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2016-12-12 5:46 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-08 10:52 [PATCH 1/2] spi: mvebu: add LSB support Uwe Kleine-König
2016-12-08 10:52 ` [PATCH 2/2] spi: mvebu: improve error reporting Uwe Kleine-König
2016-12-12 5:45 ` [PATCH 1/2] spi: mvebu: add LSB support Sascha Hauer
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox