spi.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/err.h>
  14. #include <mach/coh901318.h>
  15. #include <mach/dma_channels.h>
  16. #include "padmux.h"
  17. /*
  18. * The following is for the actual devices on the SSP/SPI bus
  19. */
  20. #ifdef CONFIG_MACH_U300_SPIDUMMY
  21. static void select_dummy_chip(u32 chipselect)
  22. {
  23. pr_debug("CORE: %s called with CS=0x%x (%s)\n",
  24. __func__,
  25. chipselect,
  26. chipselect ? "unselect chip" : "select chip");
  27. /*
  28. * Here you would write the chip select value to the GPIO pins if
  29. * this was a real chip (but this is a loopback dummy).
  30. */
  31. }
  32. struct pl022_config_chip dummy_chip_info = {
  33. /* available POLLING_TRANSFER, INTERRUPT_TRANSFER, DMA_TRANSFER */
  34. .com_mode = DMA_TRANSFER,
  35. .iface = SSP_INTERFACE_MOTOROLA_SPI,
  36. /* We can only act as master but SSP_SLAVE is possible in theory */
  37. .hierarchy = SSP_MASTER,
  38. /* 0 = drive TX even as slave, 1 = do not drive TX as slave */
  39. .slave_tx_disable = 0,
  40. .rx_lev_trig = SSP_RX_1_OR_MORE_ELEM,
  41. .tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC,
  42. .ctrl_len = SSP_BITS_12,
  43. .wait_state = SSP_MWIRE_WAIT_ZERO,
  44. .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX,
  45. /*
  46. * This is where you insert a call to a function to enable CS
  47. * (usually GPIO) for a certain chip.
  48. */
  49. .cs_control = select_dummy_chip,
  50. };
  51. #endif
  52. static struct spi_board_info u300_spi_devices[] = {
  53. #ifdef CONFIG_MACH_U300_SPIDUMMY
  54. {
  55. /* A dummy chip used for loopback tests */
  56. .modalias = "spi-dummy",
  57. /* Really dummy, pass in additional chip config here */
  58. .platform_data = NULL,
  59. /* This defines how the controller shall handle the device */
  60. .controller_data = &dummy_chip_info,
  61. /* .irq - no external IRQ routed from this device */
  62. .max_speed_hz = 1000000,
  63. .bus_num = 0, /* Only one bus on this chip */
  64. .chip_select = 0,
  65. /* Means SPI_CS_HIGH, change if e.g low CS */
  66. .mode = SPI_MODE_1 | SPI_LOOP,
  67. },
  68. #endif
  69. };
  70. static struct pl022_ssp_controller ssp_platform_data = {
  71. /* If you have several SPI buses this varies, we have only bus 0 */
  72. .bus_id = 0,
  73. /*
  74. * On the APP CPU GPIO 4, 5 and 6 are connected as generic
  75. * chip selects for SPI. (Same on U330, U335 and U365.)
  76. * TODO: make sure the GPIO driver can select these properly
  77. * and do padmuxing accordingly too.
  78. */
  79. .num_chipselect = 3,
  80. #ifdef CONFIG_COH901318
  81. .enable_dma = 1,
  82. .dma_filter = coh901318_filter_id,
  83. .dma_rx_param = (void *) U300_DMA_SPI_RX,
  84. .dma_tx_param = (void *) U300_DMA_SPI_TX,
  85. #else
  86. .enable_dma = 0,
  87. #endif
  88. };
  89. void __init u300_spi_init(struct amba_device *adev)
  90. {
  91. struct pmx *pmx;
  92. adev->dev.platform_data = &ssp_platform_data;
  93. /*
  94. * Setup padmuxing for SPI. Since this must always be
  95. * compiled into the kernel, pmx is never released.
  96. */
  97. pmx = pmx_get(&adev->dev, U300_APP_PMX_SPI_SETTING);
  98. if (IS_ERR(pmx))
  99. dev_warn(&adev->dev, "Could not get padmux handle\n");
  100. else {
  101. int ret;
  102. ret = pmx_activate(&adev->dev, pmx);
  103. if (IS_ERR_VALUE(ret))
  104. dev_warn(&adev->dev, "Could not activate padmuxing\n");
  105. }
  106. }
  107. void __init u300_spi_register_board_devices(void)
  108. {
  109. /* Register any SPI devices */
  110. spi_register_board_info(u300_spi_devices, ARRAY_SIZE(u300_spi_devices));
  111. }