mxs: mmc: spi: dma: Better wrap the MXS differences

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>
master
Marek Vasut 11 years ago committed by Stefano Babic
parent 5c2f444c9b
commit 3430e0bd2a
  1. 3
      arch/arm/cpu/arm926ejs/mxs/clock.c
  2. 19
      arch/arm/include/asm/arch-mxs/dma.h
  3. 26
      arch/arm/include/asm/arch-mxs/regs-ssp.h
  4. 20
      drivers/mmc/mxsmmc.c
  5. 4
      drivers/spi/mxs_spi.c

@ -289,7 +289,8 @@ static uint32_t mxs_get_sspclk(enum mxs_sspclock ssp)
void mxs_set_ssp_busclock(unsigned int bus, uint32_t freq)
{
struct mxs_ssp_regs *ssp_regs;
const uint32_t sspclk = mxs_get_sspclk(bus);
const enum mxs_sspclock clk = mxs_ssp_clock_by_bus(bus);
const uint32_t sspclk = mxs_get_sspclk(clk);
uint32_t reg;
uint32_t divide, rate, tgtclk;

@ -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.

@ -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) {

@ -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;

@ -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;

Loading…
Cancel
Save