[email protected] writes:

> From: Thomas Koeller <[email protected]>
>
> Change the SPI setup code to allow use of all SPI units. Also,
> move some resource assignments (DMA channels, interrupts)
> to the board code, where they belong. These really should not
> be hard-coded in dm365.c.
>
> Signed-off-by: Thomas Koeller <[email protected]>

Looks like a good reorg and cleanup.  I like the generalizing, Thanks.
Some specific comments below, but first some general comments:

Please run your patches through scripts/checkpatch.pl and fix the
errors warnings there.

Also, when fixing up dm365, could you do the same for dm355?  If you
don't have a dm355, others here can help test.  

With your cleanups, we can probably combine the dm355 and dm365 code
into common code.

> ---
>  arch/arm/mach-davinci/board-dm365-evm.c           |   37 +++-
>  arch/arm/mach-davinci/board_dm365_evm_resources.h |   17 ++
>  arch/arm/mach-davinci/dm365.c                     |  278 
> +++++++++++++++++----
>  arch/arm/mach-davinci/include/mach/dm365.h        |   16 +-
>  4 files changed, 293 insertions(+), 55 deletions(-)
>  create mode 100644 arch/arm/mach-davinci/board_dm365_evm_resources.h
>
> diff --git a/arch/arm/mach-davinci/board-dm365-evm.c 
> b/arch/arm/mach-davinci/board-dm365-evm.c
> index ab3b0e2..6797d3e 100644
> --- a/arch/arm/mach-davinci/board-dm365-evm.c
> +++ b/arch/arm/mach-davinci/board-dm365-evm.c
> @@ -49,6 +49,8 @@
>  #include <media/tvp7002.h>
>  #include <media/davinci/videohd.h>
>  
> +#include "board_dm365_evm_resources.h"
> +
>  
>  
>  /* have_imager() - Check if we have support for imager interface */
> @@ -832,16 +834,39 @@ static struct spi_eeprom at25640 = {
>       .flags          = EE_ADDR2,
>  };
>  
> -static struct spi_board_info dm365_evm_spi_info[] __initconst = {
> -     {
> +static const struct spi_board_info
> +     dm365_evm_spi_info_at25 __initconst = {

This line doesn't need to wrap.

Also, should keep this as an array for ease of adding others later and
also so you can use ARRAY_SIZE() for ninfo during the call to _init()

>               .modalias       = "at25",
>               .platform_data  = &at25640,
>               .max_speed_hz   = 20 * 1000 * 1000,     /* at 3v3 */
>               .bus_num        = 0,
>               .chip_select    = 0,
>               .mode           = SPI_MODE_0,
> -     },
> -};
> +     };
> +
> +static struct dm365_spi_unit_desc
> +     dm365_evm_spi_udesc_at25 = {

line doesn't need to wrap

> +             .spi_hwunit     = 0,
> +             .chipsel        = BIT(0),
> +             .irq            = IRQ_SPI0,

Here, just use the already defined IRQ_DM365_SPIINT0_0 instead of
having an extra #define.

> +             .dma_tx_chan    = DMA_CHAN_SPI0_TX,
> +             .dma_rx_chan    = DMA_CHAN_SPI0_RX,
> +             .dma_evtq       = DMA_EVQ_SPI0,

Here, just use EVENTQ_3.

> +             .pdata          = {
> +                     .version        = SPI_VERSION_1,
> +                     .num_chipselect = 2,
> +                     .clk_internal   = 1,
> +                     .cs_hold        = 1,
> +                     .intr_level     = 0,
> +                     .poll_mode      = 1,    /* 0 -> interrupt mode 1-> 
> polling mode */
> +                     .use_dma        = 1,    /* when 1, value in poll_mode 
> is ignored */
> +                     .c2tdelay       = 0,
> +                     .t2cdelay       = 0
> +             }
> +     };
> +
> +
> +
>  
>  static __init void dm365_evm_init(void)
>  {
> @@ -861,8 +886,8 @@ static __init void dm365_evm_init(void)
>       dm365_init_rtc();
>       dm365_init_ks(&dm365evm_ks_data);
>  
> -     dm365_init_spi0(BIT(0), dm365_evm_spi_info,
> -                     ARRAY_SIZE(dm365_evm_spi_info));
> +     dm365_init_spi(&dm365_evm_spi_udesc_at25, 1, &dm365_evm_spi_info_at25);

as mentioned above, switch the info struct back to an array and switch
back to using ARRAY_SIZE() here instead of '1'.

> +     return;
>  }
>  
>  static __init void dm365_evm_irq_init(void)
> diff --git a/arch/arm/mach-davinci/board_dm365_evm_resources.h 
> b/arch/arm/mach-davinci/board_dm365_evm_resources.h
> new file mode 100644
> index 0000000..d9cfc6b
> --- /dev/null
> +++ b/arch/arm/mach-davinci/board_dm365_evm_resources.h
> @@ -0,0 +1,17 @@
> +#ifndef _DAVINCI_EVM_RESOURCES_H
> +#define _DAVINCI_EVM_RESOURCES_H
> +
> +#include <mach/irqs.h>
> +#include <mach/edma.h>
> +
> +/* IRQs */
> +#define IRQ_SPI0             IRQ_DM365_SPIINT0_0

This can be dropped, and IRQ_DM365_SPIINT0_0 used directly.

> +/* DMA channels */
> +#define DMA_CHAN_SPI0_TX     16
> +#define DMA_CHAN_SPI0_RX     17

These are SoC common, should be in <soc>.h

> +/* DMA event queues */
> +#define DMA_EVQ_SPI0         EVENTQ_3

This can be dropped, and EVNETQ_3 used directly.

> +#endif /* _DAVINCI_EVM_RESOURCES_H */

I think it's best to just drop this file and these #defines altogether
and just use the values directly in the board files.  It will make the
board files a bit more readable and avoid a level of indirection.

> diff --git a/arch/arm/mach-davinci/dm365.c b/arch/arm/mach-davinci/dm365.c
> index ed6c9c7..023d708 100644
> --- a/arch/arm/mach-davinci/dm365.c
> +++ b/arch/arm/mach-davinci/dm365.c
> @@ -616,72 +616,256 @@ EVT_CFG(DM365, EVT3_ASP_RX,         1,     1,    0,    
>  false)
>  #endif
>  };
>  
> -static u64 dm365_spi0_dma_mask = DMA_BIT_MASK(32);
> +static u64 dm365_spi_dma_mask = DMA_BIT_MASK(32);
>  
> -static struct davinci_spi_platform_data dm365_spi0_pdata = {
> -     .version        = SPI_VERSION_1,
> -     .num_chipselect = 2,
> -     .clk_internal   = 1,
> -     .cs_hold        = 1,
> -     .intr_level     = 0,
> -     .poll_mode      = 1,    /* 0 -> interrupt mode 1-> polling mode */
> -     .use_dma        = 1,    /* when 1, value in poll_mode is ignored */
> -     .c2tdelay       = 0,
> -     .t2cdelay       = 0,
> +enum dm365_spi_resource_index {
> +     spirsrc_iomem,
> +     spirsrc_irq,
> +     spirsrc_rxdma,
> +     spirsrc_txdma,
> +     spirsrc_evqdma
>  };
>
> -static struct resource dm365_spi0_resources[] = {
> +
> +static struct resource dm365_spi_resources[spirsrc_evqdma + 1][5] = {
>       {
> -             .start = 0x01c66000,
> -             .end   = 0x01c667ff,
> -             .flags = IORESOURCE_MEM,
> +             [spirsrc_iomem] = {
> +                     .start  = 0x01c66000,
> +                     .end    = 0x01c667ff,
> +                     .flags  = IORESOURCE_MEM,
> +             },
> +             [spirsrc_irq] = {
> +                     .flags  = IORESOURCE_IRQ,
> +             },
> +             [spirsrc_rxdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_RX_CHAN,
> +             },
> +             [spirsrc_txdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_TX_CHAN,
> +             },
> +             [spirsrc_evqdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_EVENT_Q,
> +             }
>       },
>       {
> -             .start = IRQ_DM365_SPIINT0_0,
> -             .flags = IORESOURCE_IRQ,
> +             [spirsrc_iomem] = {
> +                     .start  = 0x01c66800,
> +                     .end    = 0x01c66fff,
> +                     .flags  = IORESOURCE_MEM,
> +             },
> +             [spirsrc_irq] = {
> +                     .flags  = IORESOURCE_IRQ,
> +             },
> +             [spirsrc_rxdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_RX_CHAN,
> +             },
> +             [spirsrc_txdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_TX_CHAN,
> +             },
> +             [spirsrc_evqdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_EVENT_Q,
> +             }
>       },
>       {
> -             .start = 17,
> -             .flags = IORESOURCE_DMA | IORESOURCE_DMA_RX_CHAN,
> +             [spirsrc_iomem] = {
> +                     .start  = 0x01c67800,
> +                     .end    = 0x01c67fff,
> +                     .flags  = IORESOURCE_MEM,
> +             },
> +             [spirsrc_irq] = {
> +                     .flags  = IORESOURCE_IRQ,
> +             },
> +             [spirsrc_rxdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_RX_CHAN,
> +             },
> +             [spirsrc_txdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_TX_CHAN,
> +             },
> +             [spirsrc_evqdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_EVENT_Q,
> +             }
>       },
>       {
> -             .start = 16,
> -             .flags = IORESOURCE_DMA | IORESOURCE_DMA_TX_CHAN,
> +             [spirsrc_iomem] = {
> +                     .start  = 0x01c68000,
> +                     .end    = 0x01c687ff,
> +                     .flags  = IORESOURCE_MEM,
> +             },
> +             [spirsrc_irq] = {
> +                     .flags  = IORESOURCE_IRQ,
> +             },
> +             [spirsrc_rxdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_RX_CHAN,
> +             },
> +             [spirsrc_txdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_TX_CHAN,
> +             },
> +             [spirsrc_evqdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_EVENT_Q,
> +             }
>       },
>       {
> -             .start = EVENTQ_3,
> -             .flags = IORESOURCE_DMA | IORESOURCE_DMA_EVENT_Q,
> +             [spirsrc_iomem] = {
> +                     .start  = 0x01c23000,
> +                     .end    = 0x01c237ff,
> +                     .flags  = IORESOURCE_MEM,
> +             },
> +             [spirsrc_irq] = {
> +                     .flags  = IORESOURCE_IRQ,
> +             },
> +             [spirsrc_rxdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_RX_CHAN,
> +             },
> +             [spirsrc_txdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_TX_CHAN,
> +             },
> +             [spirsrc_evqdma] = {
> +                     .flags  = IORESOURCE_DMA | IORESOURCE_DMA_EVENT_Q,
> +             }
> +     }
> +};

Since most boards will not be using all of the above, Rather than
statically allocate the IRQ and DMA resources, why not allocate them
on demand during _init_spi()?

[...]

Kevin

_______________________________________________
Davinci-linux-open-source mailing list
[email protected]
http://linux.davincidsp.com/mailman/listinfo/davinci-linux-open-source

Reply via email to