spi.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * arch/arm/mach-u300/spi.c
  3. *
  4. * Copyright (C) 2009 ST-Ericsson AB
  5. * License terms: GNU General Public License (GPL) version 2
  6. *
  7. * Author: Linus Walleij <linus.walleij@stericsson.com>
  8. */
  9. #include <linux/device.h>
  10. #include <linux/amba/bus.h>
  11. #include <linux/spi/spi.h>
  12. #include <linux/amba/pl022.h>
  13. #include <linux/platform_data/dma-coh901318.h>
  14. #include <linux/err.h>
  15. /*
  16. * The following is for the actual devices on the SSP/SPI bus
  17. */
  18. #ifdef CONFIG_MACH_U300_SPIDUMMY
  19. static void select_dummy_chip(u32 chipselect)
  20. {
  21. pr_debug("CORE: %s called with CS=0x%x (%s)\n",
  22. __func__,
  23. chipselect,
  24. chipselect ? "unselect chip" : "select chip");
  25. /*
  26. * Here you would write the chip select value to the GPIO pins if
  27. * this was a real chip (but this is a loopback dummy).
  28. */
  29. }
  30. struct pl022_config_chip dummy_chip_info = {
  31. /* available POLLING_TRANSFER, INTERRUPT_TRANSFER, DMA_TRANSFER */
  32. .com_mode = DMA_TRANSFER,
  33. .iface = SSP_INTERFACE_MOTOROLA_SPI,
  34. /* We can only act as master but SSP_SLAVE is possible in theory */
  35. .hierarchy = SSP_MASTER,
  36. /* 0 = drive TX even as slave, 1 = do not drive TX as slave */
  37. .slave_tx_disable = 0,
  38. .rx_lev_trig = SSP_RX_4_OR_MORE_ELEM,
  39. .tx_lev_trig = SSP_TX_4_OR_MORE_EMPTY_LOC,
  40. .ctrl_len = SSP_BITS_12,
  41. .wait_state = SSP_MWIRE_WAIT_ZERO,
  42. .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX,
  43. /*
  44. * This is where you insert a call to a function to enable CS
  45. * (usually GPIO) for a certain chip.
  46. */
  47. .cs_control = select_dummy_chip,
  48. };
  49. #endif
  50. static struct spi_board_info u300_spi_devices[] = {
  51. #ifdef CONFIG_MACH_U300_SPIDUMMY
  52. {
  53. /* A dummy chip used for loopback tests */
  54. .modalias = "spi-dummy",
  55. /* Really dummy, pass in additional chip config here */
  56. .platform_data = NULL,
  57. /* This defines how the controller shall handle the device */
  58. .controller_data = &dummy_chip_info,
  59. /* .irq - no external IRQ routed from this device */
  60. .max_speed_hz = 1000000,
  61. .bus_num = 0, /* Only one bus on this chip */
  62. .chip_select = 0,
  63. /* Means SPI_CS_HIGH, change if e.g low CS */
  64. .mode = SPI_MODE_1 | SPI_LOOP,
  65. },
  66. #endif
  67. };
  68. static struct pl022_ssp_controller ssp_platform_data = {
  69. /* If you have several SPI buses this varies, we have only bus 0 */
  70. .bus_id = 0,
  71. /*
  72. * On the APP CPU GPIO 4, 5 and 6 are connected as generic
  73. * chip selects for SPI. (Same on U330, U335 and U365.)
  74. * TODO: make sure the GPIO driver can select these properly
  75. * and do padmuxing accordingly too.
  76. */
  77. .num_chipselect = 3,
  78. #ifdef CONFIG_COH901318
  79. .enable_dma = 1,
  80. .dma_filter = coh901318_filter_id,
  81. .dma_rx_param = (void *) U300_DMA_SPI_RX,
  82. .dma_tx_param = (void *) U300_DMA_SPI_TX,
  83. #else
  84. .enable_dma = 0,
  85. #endif
  86. };
  87. void __init u300_spi_init(struct amba_device *adev)
  88. {
  89. adev->dev.platform_data = &ssp_platform_data;
  90. }
  91. void __init u300_spi_register_board_devices(void)
  92. {
  93. /* Register any SPI devices */
  94. spi_register_board_info(u300_spi_devices, ARRAY_SIZE(u300_spi_devices));
  95. }