ep93xx_spi 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. Cirrus EP93xx SPI controller driver HOWTO
  2. =========================================
  3. ep93xx_spi driver brings SPI master support for EP93xx SPI controller. Chip
  4. selects are implemented with GPIO lines.
  5. NOTE: If possible, don't use SFRMOUT (SFRM1) signal as a chip select. It will
  6. not work correctly (it cannot be controlled by software). Use GPIO lines
  7. instead.
  8. Sample configuration
  9. ====================
  10. Typically driver configuration is done in platform board files (the files under
  11. arch/arm/mach-ep93xx/*.c). In this example we configure MMC over SPI through
  12. this driver on TS-7260 board. You can adapt the code to suit your needs.
  13. This example uses EGPIO9 as SD/MMC card chip select (this is wired in DIO1
  14. header on the board).
  15. You need to select CONFIG_MMC_SPI to use mmc_spi driver.
  16. arch/arm/mach-ep93xx/ts72xx.c:
  17. ...
  18. #include <linux/gpio.h>
  19. #include <linux/spi/spi.h>
  20. #include <linux/platform_data/spi-ep93xx.h>
  21. /* this is our GPIO line used for chip select */
  22. #define MMC_CHIP_SELECT_GPIO EP93XX_GPIO_LINE_EGPIO9
  23. static int ts72xx_mmc_spi_setup(struct spi_device *spi)
  24. {
  25. int err;
  26. err = gpio_request(MMC_CHIP_SELECT_GPIO, spi->modalias);
  27. if (err)
  28. return err;
  29. gpio_direction_output(MMC_CHIP_SELECT_GPIO, 1);
  30. return 0;
  31. }
  32. static void ts72xx_mmc_spi_cleanup(struct spi_device *spi)
  33. {
  34. gpio_set_value(MMC_CHIP_SELECT_GPIO, 1);
  35. gpio_direction_input(MMC_CHIP_SELECT_GPIO);
  36. gpio_free(MMC_CHIP_SELECT_GPIO);
  37. }
  38. static void ts72xx_mmc_spi_cs_control(struct spi_device *spi, int value)
  39. {
  40. gpio_set_value(MMC_CHIP_SELECT_GPIO, value);
  41. }
  42. static struct ep93xx_spi_chip_ops ts72xx_mmc_spi_ops = {
  43. .setup = ts72xx_mmc_spi_setup,
  44. .cleanup = ts72xx_mmc_spi_cleanup,
  45. .cs_control = ts72xx_mmc_spi_cs_control,
  46. };
  47. static struct spi_board_info ts72xx_spi_devices[] __initdata = {
  48. {
  49. .modalias = "mmc_spi",
  50. .controller_data = &ts72xx_mmc_spi_ops,
  51. /*
  52. * We use 10 MHz even though the maximum is 7.4 MHz. The driver
  53. * will limit it automatically to max. frequency.
  54. */
  55. .max_speed_hz = 10 * 1000 * 1000,
  56. .bus_num = 0,
  57. .chip_select = 0,
  58. .mode = SPI_MODE_0,
  59. },
  60. };
  61. static struct ep93xx_spi_info ts72xx_spi_info = {
  62. .num_chipselect = ARRAY_SIZE(ts72xx_spi_devices),
  63. };
  64. static void __init ts72xx_init_machine(void)
  65. {
  66. ...
  67. ep93xx_register_spi(&ts72xx_spi_info, ts72xx_spi_devices,
  68. ARRAY_SIZE(ts72xx_spi_devices));
  69. }
  70. The driver can use DMA for the transfers also. In this case ts72xx_spi_info
  71. becomes:
  72. static struct ep93xx_spi_info ts72xx_spi_info = {
  73. .num_chipselect = ARRAY_SIZE(ts72xx_spi_devices),
  74. .use_dma = true;
  75. };
  76. Note that CONFIG_EP93XX_DMA should be enabled as well.
  77. Thanks to
  78. =========
  79. Martin Guy, H. Hartley Sweeten and others who helped me during development of
  80. the driver. Simplemachines.it donated me a Sim.One board which I used testing
  81. the driver on EP9307.