public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v2 1/2] spi: mxs: Introduce spi_cs_is_valid()
@ 2012-04-23 18:30 Fabio Estevam
  2012-04-23 18:30 ` [U-Boot] [PATCH v2 2/2] spi: mxs: Allow other chip selects to work Fabio Estevam
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Fabio Estevam @ 2012-04-23 18:30 UTC (permalink / raw)
  To: u-boot

Introduce spi_cs_is_valid() for validating spi bus and chip select numbers.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Changes since v1:
- Newly introduced in v2

 drivers/spi/mxs_spi.c |   13 +++++++++++--
 1 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c
index 4e6f14e..e7237e7 100644
--- a/drivers/spi/mxs_spi.c
+++ b/drivers/spi/mxs_spi.c
@@ -51,14 +51,23 @@ void spi_init(void)
 {
 }
 
+int spi_cs_is_valid(unsigned int bus, unsigned int cs)
+{
+	/* MXS SPI: 4 ports and 3 chip selects maximum */
+	if (bus > 3 || cs > 2)
+		return 0;
+	else
+		return 1;
+}
+
 struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 				  unsigned int max_hz, unsigned int mode)
 {
 	struct mxs_spi_slave *mxs_slave;
 	uint32_t addr;
 
-	if (bus > 3) {
-		printf("MXS SPI: Max bus number is 3\n");
+	if (!spi_cs_is_valid(bus, cs)) {
+		printf("mxs_spi: invalid bus %d / chip select %d\n", bus, cs);
 		return NULL;
 	}
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v2 2/2] spi: mxs: Allow other chip selects to work
  2012-04-23 18:30 [U-Boot] [PATCH v2 1/2] spi: mxs: Introduce spi_cs_is_valid() Fabio Estevam
@ 2012-04-23 18:30 ` Fabio Estevam
  2012-04-23 21:27   ` Marek Vasut
  2012-05-09  9:53   ` Stefano Babic
  2012-04-23 21:27 ` [U-Boot] [PATCH v2 1/2] spi: mxs: Introduce spi_cs_is_valid() Marek Vasut
                   ` (2 subsequent siblings)
  3 siblings, 2 replies; 7+ messages in thread
From: Fabio Estevam @ 2012-04-23 18:30 UTC (permalink / raw)
  To: u-boot

MXS SSP controller may have up to three chip selects per port: SS0, SS1 and SS2.

Currently only SS0 is supported in the mxs_spi driver.

Allow all the three chip select to work by selecting the desired one
in bits 20 and 21 of the HW_SSP_CTRL0 register.

Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
---
Changes since v1:
- Check vor valid cs inside spi_cs_is_valid() (patch 1/2)

 drivers/spi/mxs_spi.c |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c
index e7237e7..7859536 100644
--- a/drivers/spi/mxs_spi.c
+++ b/drivers/spi/mxs_spi.c
@@ -34,6 +34,8 @@
 
 #define	MXS_SPI_MAX_TIMEOUT	1000000
 #define	MXS_SPI_PORT_OFFSET	0x2000
+#define MXS_SSP_CHIPSELECT_MASK		0x00300000
+#define MXS_SSP_CHIPSELECT_SHIFT	20
 
 struct mxs_spi_slave {
 	struct spi_slave	slave;
@@ -65,6 +67,8 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 {
 	struct mxs_spi_slave *mxs_slave;
 	uint32_t addr;
+	struct mx28_ssp_regs *ssp_regs;
+	int reg;
 
 	if (!spi_cs_is_valid(bus, cs)) {
 		printf("mxs_spi: invalid bus %d / chip select %d\n", bus, cs);
@@ -82,7 +86,13 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	mxs_slave->max_khz = max_hz / 1000;
 	mxs_slave->mode = mode;
 	mxs_slave->regs = (struct mx28_ssp_regs *)addr;
+	ssp_regs = mxs_slave->regs;
 
+	reg = readl(&ssp_regs->hw_ssp_ctrl0);
+	reg &= ~(MXS_SSP_CHIPSELECT_MASK);
+	reg |= cs << MXS_SSP_CHIPSELECT_SHIFT;
+
+	writel(reg, &ssp_regs->hw_ssp_ctrl0);
 	return &mxs_slave->slave;
 }
 
-- 
1.7.1

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v2 1/2] spi: mxs: Introduce spi_cs_is_valid()
  2012-04-23 18:30 [U-Boot] [PATCH v2 1/2] spi: mxs: Introduce spi_cs_is_valid() Fabio Estevam
  2012-04-23 18:30 ` [U-Boot] [PATCH v2 2/2] spi: mxs: Allow other chip selects to work Fabio Estevam
@ 2012-04-23 21:27 ` Marek Vasut
  2012-04-23 21:51 ` Mike Frysinger
  2012-05-09  9:53 ` Stefano Babic
  3 siblings, 0 replies; 7+ messages in thread
From: Marek Vasut @ 2012-04-23 21:27 UTC (permalink / raw)
  To: u-boot

Dear Fabio Estevam,

> Introduce spi_cs_is_valid() for validating spi bus and chip select numbers.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

Acked-by: Marek Vasut <marex@denx.de>
> ---
> Changes since v1:
> - Newly introduced in v2
> 
>  drivers/spi/mxs_spi.c |   13 +++++++++++--
>  1 files changed, 11 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c
> index 4e6f14e..e7237e7 100644
> --- a/drivers/spi/mxs_spi.c
> +++ b/drivers/spi/mxs_spi.c
> @@ -51,14 +51,23 @@ void spi_init(void)
>  {
>  }
> 
> +int spi_cs_is_valid(unsigned int bus, unsigned int cs)
> +{
> +	/* MXS SPI: 4 ports and 3 chip selects maximum */
> +	if (bus > 3 || cs > 2)
> +		return 0;
> +	else
> +		return 1;
> +}
> +
>  struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
>  				  unsigned int max_hz, unsigned int mode)
>  {
>  	struct mxs_spi_slave *mxs_slave;
>  	uint32_t addr;
> 
> -	if (bus > 3) {
> -		printf("MXS SPI: Max bus number is 3\n");
> +	if (!spi_cs_is_valid(bus, cs)) {
> +		printf("mxs_spi: invalid bus %d / chip select %d\n", bus, cs);
>  		return NULL;
>  	}

Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v2 2/2] spi: mxs: Allow other chip selects to work
  2012-04-23 18:30 ` [U-Boot] [PATCH v2 2/2] spi: mxs: Allow other chip selects to work Fabio Estevam
@ 2012-04-23 21:27   ` Marek Vasut
  2012-05-09  9:53   ` Stefano Babic
  1 sibling, 0 replies; 7+ messages in thread
From: Marek Vasut @ 2012-04-23 21:27 UTC (permalink / raw)
  To: u-boot

Dear Fabio Estevam,

> MXS SSP controller may have up to three chip selects per port: SS0, SS1 and
> SS2.
> 
> Currently only SS0 is supported in the mxs_spi driver.
> 
> Allow all the three chip select to work by selecting the desired one
> in bits 20 and 21 of the HW_SSP_CTRL0 register.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>

Acked-by: Marek Vasut <marex@denx.de>
> ---
> Changes since v1:
> - Check vor valid cs inside spi_cs_is_valid() (patch 1/2)
> 
>  drivers/spi/mxs_spi.c |   10 ++++++++++
>  1 files changed, 10 insertions(+), 0 deletions(-)
> 
> diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c
> index e7237e7..7859536 100644
> --- a/drivers/spi/mxs_spi.c
> +++ b/drivers/spi/mxs_spi.c
> @@ -34,6 +34,8 @@
> 
>  #define	MXS_SPI_MAX_TIMEOUT	1000000
>  #define	MXS_SPI_PORT_OFFSET	0x2000
> +#define MXS_SSP_CHIPSELECT_MASK		0x00300000
> +#define MXS_SSP_CHIPSELECT_SHIFT	20
> 
>  struct mxs_spi_slave {
>  	struct spi_slave	slave;
> @@ -65,6 +67,8 @@ struct spi_slave *spi_setup_slave(unsigned int bus,
> unsigned int cs, {
>  	struct mxs_spi_slave *mxs_slave;
>  	uint32_t addr;
> +	struct mx28_ssp_regs *ssp_regs;
> +	int reg;
> 
>  	if (!spi_cs_is_valid(bus, cs)) {
>  		printf("mxs_spi: invalid bus %d / chip select %d\n", bus, cs);
> @@ -82,7 +86,13 @@ struct spi_slave *spi_setup_slave(unsigned int bus,
> unsigned int cs, mxs_slave->max_khz = max_hz / 1000;
>  	mxs_slave->mode = mode;
>  	mxs_slave->regs = (struct mx28_ssp_regs *)addr;
> +	ssp_regs = mxs_slave->regs;
> 
> +	reg = readl(&ssp_regs->hw_ssp_ctrl0);
> +	reg &= ~(MXS_SSP_CHIPSELECT_MASK);
> +	reg |= cs << MXS_SSP_CHIPSELECT_SHIFT;
> +
> +	writel(reg, &ssp_regs->hw_ssp_ctrl0);
>  	return &mxs_slave->slave;
>  }

Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v2 1/2] spi: mxs: Introduce spi_cs_is_valid()
  2012-04-23 18:30 [U-Boot] [PATCH v2 1/2] spi: mxs: Introduce spi_cs_is_valid() Fabio Estevam
  2012-04-23 18:30 ` [U-Boot] [PATCH v2 2/2] spi: mxs: Allow other chip selects to work Fabio Estevam
  2012-04-23 21:27 ` [U-Boot] [PATCH v2 1/2] spi: mxs: Introduce spi_cs_is_valid() Marek Vasut
@ 2012-04-23 21:51 ` Mike Frysinger
  2012-05-09  9:53 ` Stefano Babic
  3 siblings, 0 replies; 7+ messages in thread
From: Mike Frysinger @ 2012-04-23 21:51 UTC (permalink / raw)
  To: u-boot

On Monday 23 April 2012 14:30:49 Fabio Estevam wrote:
> Introduce spi_cs_is_valid() for validating spi bus and chip select numbers.

Acked-by: Mike Frysinger <vapier@gentoo.org>
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20120423/15a143ee/attachment.pgp>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v2 2/2] spi: mxs: Allow other chip selects to work
  2012-04-23 18:30 ` [U-Boot] [PATCH v2 2/2] spi: mxs: Allow other chip selects to work Fabio Estevam
  2012-04-23 21:27   ` Marek Vasut
@ 2012-05-09  9:53   ` Stefano Babic
  1 sibling, 0 replies; 7+ messages in thread
From: Stefano Babic @ 2012-05-09  9:53 UTC (permalink / raw)
  To: u-boot

On 23/04/2012 20:30, Fabio Estevam wrote:
> MXS SSP controller may have up to three chip selects per port: SS0, SS1 and SS2.
> 
> Currently only SS0 is supported in the mxs_spi driver.
> 
> Allow all the three chip select to work by selecting the desired one
> in bits 20 and 21 of the HW_SSP_CTRL0 register.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
> ---

Applied to u-boot-imx, thanks.

Best regards,
Stefano Babic


-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [U-Boot] [PATCH v2 1/2] spi: mxs: Introduce spi_cs_is_valid()
  2012-04-23 18:30 [U-Boot] [PATCH v2 1/2] spi: mxs: Introduce spi_cs_is_valid() Fabio Estevam
                   ` (2 preceding siblings ...)
  2012-04-23 21:51 ` Mike Frysinger
@ 2012-05-09  9:53 ` Stefano Babic
  3 siblings, 0 replies; 7+ messages in thread
From: Stefano Babic @ 2012-05-09  9:53 UTC (permalink / raw)
  To: u-boot

On 23/04/2012 20:30, Fabio Estevam wrote:
> Introduce spi_cs_is_valid() for validating spi bus and chip select numbers.
> 
> Signed-off-by: Fabio Estevam <fabio.estevam@freescale.com>
> ---

Applied to u-boot-imx, thanks.

Best regards,
Stefano Babic

-- 
=====================================================================
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-53 Fax: +49-8142-66989-80 Email: sbabic at denx.de
=====================================================================

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2012-05-09  9:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-04-23 18:30 [U-Boot] [PATCH v2 1/2] spi: mxs: Introduce spi_cs_is_valid() Fabio Estevam
2012-04-23 18:30 ` [U-Boot] [PATCH v2 2/2] spi: mxs: Allow other chip selects to work Fabio Estevam
2012-04-23 21:27   ` Marek Vasut
2012-05-09  9:53   ` Stefano Babic
2012-04-23 21:27 ` [U-Boot] [PATCH v2 1/2] spi: mxs: Introduce spi_cs_is_valid() Marek Vasut
2012-04-23 21:51 ` Mike Frysinger
2012-05-09  9:53 ` Stefano Babic

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox