spi.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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 "padmux.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. /* Nominally this is LOOPBACK_DISABLED, but this is our dummy chip! */
  32. .lbm = LOOPBACK_ENABLED,
  33. /*
  34. * available POLLING_TRANSFER and INTERRUPT_TRANSFER,
  35. * DMA_TRANSFER does not work
  36. */
  37. .com_mode = INTERRUPT_TRANSFER,
  38. .iface = SSP_INTERFACE_MOTOROLA_SPI,
  39. /* We can only act as master but SSP_SLAVE is possible in theory */
  40. .hierarchy = SSP_MASTER,
  41. /* 0 = drive TX even as slave, 1 = do not drive TX as slave */
  42. .slave_tx_disable = 0,
  43. /* LSB first */
  44. .endian_tx = SSP_TX_LSB,
  45. .endian_rx = SSP_RX_LSB,
  46. .data_size = SSP_DATA_BITS_8, /* used to be 12 in some default */
  47. .rx_lev_trig = SSP_RX_1_OR_MORE_ELEM,
  48. .tx_lev_trig = SSP_TX_1_OR_MORE_EMPTY_LOC,
  49. .clk_phase = SSP_CLK_SECOND_EDGE,
  50. .clk_pol = SSP_CLK_POL_IDLE_LOW,
  51. .ctrl_len = SSP_BITS_12,
  52. .wait_state = SSP_MWIRE_WAIT_ZERO,
  53. .duplex = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX,
  54. /*
  55. * This is where you insert a call to a function to enable CS
  56. * (usually GPIO) for a certain chip.
  57. */
  58. .cs_control = select_dummy_chip,
  59. };
  60. #endif
  61. static struct spi_board_info u300_spi_devices[] = {
  62. #ifdef CONFIG_MACH_U300_SPIDUMMY
  63. {
  64. /* A dummy chip used for loopback tests */
  65. .modalias = "spi-dummy",
  66. /* Really dummy, pass in additional chip config here */
  67. .platform_data = NULL,
  68. /* This defines how the controller shall handle the device */
  69. .controller_data = &dummy_chip_info,
  70. /* .irq - no external IRQ routed from this device */
  71. .max_speed_hz = 1000000,
  72. .bus_num = 0, /* Only one bus on this chip */
  73. .chip_select = 0,
  74. /* Means SPI_CS_HIGH, change if e.g low CS */
  75. .mode = 0,
  76. },
  77. #endif
  78. };
  79. static struct pl022_ssp_controller ssp_platform_data = {
  80. /* If you have several SPI buses this varies, we have only bus 0 */
  81. .bus_id = 0,
  82. /* Set this to 1 when we think we got DMA working */
  83. .enable_dma = 0,
  84. /*
  85. * On the APP CPU GPIO 4, 5 and 6 are connected as generic
  86. * chip selects for SPI. (Same on U330, U335 and U365.)
  87. * TODO: make sure the GPIO driver can select these properly
  88. * and do padmuxing accordingly too.
  89. */
  90. .num_chipselect = 3,
  91. };
  92. void __init u300_spi_init(struct amba_device *adev)
  93. {
  94. struct pmx *pmx;
  95. adev->dev.platform_data = &ssp_platform_data;
  96. /*
  97. * Setup padmuxing for SPI. Since this must always be
  98. * compiled into the kernel, pmx is never released.
  99. */
  100. pmx = pmx_get(&adev->dev, U300_APP_PMX_SPI_SETTING);
  101. if (IS_ERR(pmx))
  102. dev_warn(&adev->dev, "Could not get padmux handle\n");
  103. else {
  104. int ret;
  105. ret = pmx_activate(&adev->dev, pmx);
  106. if (IS_ERR_VALUE(ret))
  107. dev_warn(&adev->dev, "Could not activate padmuxing\n");
  108. }
  109. }
  110. void __init u300_spi_register_board_devices(void)
  111. {
  112. /* Register any SPI devices */
  113. spi_register_board_info(u300_spi_devices, ARRAY_SIZE(u300_spi_devices));
  114. }