Patchwork [U-Boot] mxs: mmc: spi: dma: Better wrap the MXS differences

login
register
mail settings
Submitter Marek Vasut
Date Feb. 2, 2013, 5:55 a.m.
Message ID <1359784533-20614-1-git-send-email-marex@denx.de>
Download mbox | patch
Permalink /patch/217638/
State Superseded
Delegated to: Stefano Babic
Headers show

Comments

Marek Vasut - Feb. 2, 2013, 5:55 a.m.
This patch streamlines the differences between the MX23 and MX28 by
implementing a few helper functions to handle different DMA channel
mapping, different clock domain for SSP block and fixes a few minor
bugs.

First of all, the DMA channel mapping is now fixed in dma.h by defining
the actual channel map for both MX23 and MX28. Thus, MX23 now does no
longer use MX28 channel map which was wrong. Also, there is a fix for
MX28 DMA channel map, where the last four channels were incorrect.

Next, because correct DMA channel map is in place, the mxs_dma_init_channel()
call now bases the channel ID starting from SSP port #0. This removes the
need for DMA channel offset being added and cleans up the code. For the
same reason, the SSP0 offset can now be used in mxs_dma_desc_append(), thus
no need to adjust dma channel number in the driver either.

Lastly, the SSP clock ID is now retrieved by calling mxs_ssp_clock_by_bus()
which handles the fact that MX23 has shared SSP clock for both ports, while
MX28 has per-port SSP clock.

Finally, the mxs_ssp_bus_id_valid() pulls out two implementations of the
same functionality from MMC and SPI driver into common code.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Fabio Estevam <fabio.estevam@freescale.com>
Cc: Otavio Salvador <otavio@ossystems.com.br>
Cc: Stefano Babic <sbabic@denx.de>
---
 arch/arm/include/asm/arch-mxs/dma.h      |   19 ++++++++++++++++++-
 arch/arm/include/asm/arch-mxs/regs-ssp.h |   26 ++++++++++++++++++++++++++
 drivers/mmc/mxsmmc.c                     |   20 ++++----------------
 drivers/spi/mxs_spi.c                    |    4 ++--
 4 files changed, 50 insertions(+), 19 deletions(-)

NOTE: COMPILE TESTED ONLY!!! I need someone to actually test this stuff.
Stefano Babic - Feb. 23, 2013, 11:50 a.m.
On 02/02/2013 06:55, Marek Vasut wrote:
> This patch streamlines the differences between the MX23 and MX28 by
> implementing a few helper functions to handle different DMA channel
> mapping, different clock domain for SSP block and fixes a few minor
> bugs.
> 
> First of all, the DMA channel mapping is now fixed in dma.h by defining
> the actual channel map for both MX23 and MX28. Thus, MX23 now does no
> longer use MX28 channel map which was wrong. Also, there is a fix for
> MX28 DMA channel map, where the last four channels were incorrect.
> 
> Next, because correct DMA channel map is in place, the mxs_dma_init_channel()
> call now bases the channel ID starting from SSP port #0. This removes the
> need for DMA channel offset being added and cleans up the code. For the
> same reason, the SSP0 offset can now be used in mxs_dma_desc_append(), thus
> no need to adjust dma channel number in the driver either.
> 
> Lastly, the SSP clock ID is now retrieved by calling mxs_ssp_clock_by_bus()
> which handles the fact that MX23 has shared SSP clock for both ports, while
> MX28 has per-port SSP clock.
> 
> Finally, the mxs_ssp_bus_id_valid() pulls out two implementations of the
> same functionality from MMC and SPI driver into common code.
> 
> Signed-off-by: Marek Vasut <marex@denx.de>
> Cc: Fabio Estevam <fabio.estevam@freescale.com>
> Cc: Otavio Salvador <otavio@ossystems.com.br>
> Cc: Stefano Babic <sbabic@denx.de>
> ---
>  arch/arm/include/asm/arch-mxs/dma.h      |   19 ++++++++++++++++++-
>  arch/arm/include/asm/arch-mxs/regs-ssp.h |   26 ++++++++++++++++++++++++++
>  drivers/mmc/mxsmmc.c                     |   20 ++++----------------
>  drivers/spi/mxs_spi.c                    |    4 ++--
>  4 files changed, 50 insertions(+), 19 deletions(-)
> 
> NOTE: COMPILE TESTED ONLY!!! I need someone to actually test this stuff.

Hi all,

I am thinking about how to proceed with this. Is there any plan to test
it ? It would prefer that it runs at least once else merging it now
without any test and fix later.

Regards,
Stefano
Marek Vasut - Feb. 23, 2013, 12:18 p.m.
Dear Stefano Babic,

> On 02/02/2013 06:55, Marek Vasut wrote:
> > This patch streamlines the differences between the MX23 and MX28 by
> > implementing a few helper functions to handle different DMA channel
> > mapping, different clock domain for SSP block and fixes a few minor
> > bugs.
> > 
> > First of all, the DMA channel mapping is now fixed in dma.h by defining
> > the actual channel map for both MX23 and MX28. Thus, MX23 now does no
> > longer use MX28 channel map which was wrong. Also, there is a fix for
> > MX28 DMA channel map, where the last four channels were incorrect.
> > 
> > Next, because correct DMA channel map is in place, the
> > mxs_dma_init_channel() call now bases the channel ID starting from SSP
> > port #0. This removes the need for DMA channel offset being added and
> > cleans up the code. For the same reason, the SSP0 offset can now be used
> > in mxs_dma_desc_append(), thus no need to adjust dma channel number in
> > the driver either.
> > 
> > Lastly, the SSP clock ID is now retrieved by calling
> > mxs_ssp_clock_by_bus() which handles the fact that MX23 has shared SSP
> > clock for both ports, while MX28 has per-port SSP clock.
> > 
> > Finally, the mxs_ssp_bus_id_valid() pulls out two implementations of the
> > same functionality from MMC and SPI driver into common code.
> > 
> > Signed-off-by: Marek Vasut <marex@denx.de>
> > Cc: Fabio Estevam <fabio.estevam@freescale.com>
> > Cc: Otavio Salvador <otavio@ossystems.com.br>
> > Cc: Stefano Babic <sbabic@denx.de>
> > ---
> > 
> >  arch/arm/include/asm/arch-mxs/dma.h      |   19 ++++++++++++++++++-
> >  arch/arm/include/asm/arch-mxs/regs-ssp.h |   26
> >  ++++++++++++++++++++++++++ drivers/mmc/mxsmmc.c                     |  
> >  20 ++++---------------- drivers/spi/mxs_spi.c                    |    4
> >  ++--
> >  4 files changed, 50 insertions(+), 19 deletions(-)
> > 
> > NOTE: COMPILE TESTED ONLY!!! I need someone to actually test this stuff.
> 
> Hi all,
> 
> I am thinking about how to proceed with this. Is there any plan to test
> it ? It would prefer that it runs at least once else merging it now
> without any test and fix later.

This needs more work, NAK so far.

Best regards,
Marek Vasut

Patch

diff --git a/arch/arm/include/asm/arch-mxs/dma.h b/arch/arm/include/asm/arch-mxs/dma.h
index a0a0ea5..1ac8696 100644
--- a/arch/arm/include/asm/arch-mxs/dma.h
+++ b/arch/arm/include/asm/arch-mxs/dma.h
@@ -40,6 +40,19 @@ 
 /*
  * MXS DMA channels
  */
+#if defined(CONFIG_MX23)
+enum {
+	MXS_DMA_CHANNEL_AHB_APBH_LCDIF = 0,
+	MXS_DMA_CHANNEL_AHB_APBH_SSP0,
+	MXS_DMA_CHANNEL_AHB_APBH_SSP1,
+	MXS_DMA_CHANNEL_AHB_APBH_RESERVED0,
+	MXS_DMA_CHANNEL_AHB_APBH_GPMI0,
+	MXS_DMA_CHANNEL_AHB_APBH_GPMI1,
+	MXS_DMA_CHANNEL_AHB_APBH_GPMI2,
+	MXS_DMA_CHANNEL_AHB_APBH_GPMI3,
+	MXS_MAX_DMA_CHANNELS,
+};
+#elif defined(CONFIG_MX28)
 enum {
 	MXS_DMA_CHANNEL_AHB_APBH_SSP0 = 0,
 	MXS_DMA_CHANNEL_AHB_APBH_SSP1,
@@ -53,9 +66,13 @@  enum {
 	MXS_DMA_CHANNEL_AHB_APBH_GPMI5,
 	MXS_DMA_CHANNEL_AHB_APBH_GPMI6,
 	MXS_DMA_CHANNEL_AHB_APBH_GPMI7,
-	MXS_DMA_CHANNEL_AHB_APBH_SSP,
+	MXS_DMA_CHANNEL_AHB_APBH_HSADC,
+	MXS_DMA_CHANNEL_AHB_APBH_LCDIF,
+	MXS_DMA_CHANNEL_AHB_APBH_RESERVED0,
+	MXS_DMA_CHANNEL_AHB_APBH_RESERVED1,
 	MXS_MAX_DMA_CHANNELS,
 };
+#endif
 
 /*
  * MXS DMA hardware command.
diff --git a/arch/arm/include/asm/arch-mxs/regs-ssp.h b/arch/arm/include/asm/arch-mxs/regs-ssp.h
index 9b30f56..5920f9b 100644
--- a/arch/arm/include/asm/arch-mxs/regs-ssp.h
+++ b/arch/arm/include/asm/arch-mxs/regs-ssp.h
@@ -74,6 +74,32 @@  struct mxs_ssp_regs {
 };
 #endif
 
+static inline int mxs_ssp_bus_id_valid(int bus)
+{
+#if defined(CONFIG_MX23)
+	const unsigned int mxs_ssp_chan_count = 2;
+#elif defined(CONFIG_MX28)
+	const unsigned int mxs_ssp_chan_count = 4;
+#endif
+
+	if (bus >= mxs_ssp_chan_count)
+		return 0;
+
+	if (bus < 0)
+		return 0;
+
+	return 1;
+}
+
+static inline int mxs_ssp_clock_by_bus(unsigned int clock)
+{
+#if defined(CONFIG_MX23)
+	return 0;
+#elif defined(CONFIG_MX28)
+	return clock;
+#endif
+}
+
 static inline struct mxs_ssp_regs *mxs_ssp_regs_by_bus(unsigned int port)
 {
 	switch (port) {
diff --git a/drivers/mmc/mxsmmc.c b/drivers/mmc/mxsmmc.c
index ae0f378..939d549 100644
--- a/drivers/mmc/mxsmmc.c
+++ b/drivers/mmc/mxsmmc.c
@@ -53,12 +53,6 @@  struct mxsmmc_priv {
 	struct mxs_dma_desc	*desc;
 };
 
-#if defined(CONFIG_MX23)
-static const unsigned int mxsmmc_id_offset = 1;
-#elif defined(CONFIG_MX28)
-static const unsigned int mxsmmc_id_offset = 0;
-#endif
-
 #define	MXSMMC_MAX_TIMEOUT	10000
 #define MXSMMC_SMALL_TRANSFER	512
 
@@ -137,7 +131,7 @@  static int mxsmmc_send_cmd_dma(struct mxsmmc_priv *priv, struct mmc_data *data)
 	priv->desc->cmd.data |= MXS_DMA_DESC_IRQ | MXS_DMA_DESC_DEC_SEM |
 				(data_count << MXS_DMA_DESC_BYTES_OFFSET);
 
-	dmach = MXS_DMA_CHANNEL_AHB_APBH_SSP0 + priv->id + mxsmmc_id_offset;
+	dmach = MXS_DMA_CHANNEL_AHB_APBH_SSP0 + priv->id;
 	mxs_dma_desc_append(dmach, priv->desc);
 	if (mxs_dma_go(dmach)) {
 		bounce_buffer_stop(&bbstate);
@@ -390,15 +384,9 @@  int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int))
 	struct mmc *mmc = NULL;
 	struct mxsmmc_priv *priv = NULL;
 	int ret;
-#if defined(CONFIG_MX23)
-	const unsigned int mxsmmc_max_id = 2;
-	const unsigned int mxsmmc_clk_id = 0;
-#elif defined(CONFIG_MX28)
-	const unsigned int mxsmmc_max_id = 4;
-	const unsigned int mxsmmc_clk_id = id;
-#endif
+	const unsigned int mxsmmc_clk_id = mxs_ssp_clock_by_bus(id);
 
-	if (id >= mxsmmc_max_id)
+	if (mxs_ssp_bus_id_valid(id))
 		return -ENODEV;
 
 	mmc = malloc(sizeof(struct mmc));
@@ -418,7 +406,7 @@  int mxsmmc_initialize(bd_t *bis, int id, int (*wp)(int), int (*cd)(int))
 		return -ENOMEM;
 	}
 
-	ret = mxs_dma_init_channel(id + mxsmmc_id_offset);
+	ret = mxs_dma_init_channel(MXS_DMA_CHANNEL_AHB_APBH_SSP0 + id);
 	if (ret)
 		return ret;
 
diff --git a/drivers/spi/mxs_spi.c b/drivers/spi/mxs_spi.c
index bb865b7..5f2fd18 100644
--- a/drivers/spi/mxs_spi.c
+++ b/drivers/spi/mxs_spi.c
@@ -70,7 +70,7 @@  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)
+	if (mxs_ssp_bus_id_valid(bus) || cs > 2)
 		return 0;
 	else
 		return 1;
@@ -92,7 +92,7 @@  struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	if (!mxs_slave)
 		return NULL;
 
-	if (mxs_dma_init_channel(bus))
+	if (mxs_dma_init_channel(MXS_DMA_CHANNEL_AHB_APBH_SSP0 + bus))
 		goto err_init;
 
 	mxs_slave->slave.bus = bus;