dev-spi.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. /* linux/arch/arm/mach-s5pv210/dev-spi.c
  2. *
  3. * Copyright (C) 2010 Samsung Electronics Co. Ltd.
  4. * Jaswinder Singh <jassi.brar@samsung.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/platform_device.h>
  11. #include <linux/dma-mapping.h>
  12. #include <linux/gpio.h>
  13. #include <mach/dma.h>
  14. #include <mach/map.h>
  15. #include <mach/irqs.h>
  16. #include <mach/spi-clocks.h>
  17. #include <plat/s3c64xx-spi.h>
  18. #include <plat/gpio-cfg.h>
  19. static char *spi_src_clks[] = {
  20. [S5PV210_SPI_SRCCLK_PCLK] = "pclk",
  21. [S5PV210_SPI_SRCCLK_SCLK] = "sclk_spi",
  22. };
  23. /* SPI Controller platform_devices */
  24. /* Since we emulate multi-cs capability, we do not touch the CS.
  25. * The emulated CS is toggled by board specific mechanism, as it can
  26. * be either some immediate GPIO or some signal out of some other
  27. * chip in between ... or some yet another way.
  28. * We simply do not assume anything about CS.
  29. */
  30. static int s5pv210_spi_cfg_gpio(struct platform_device *pdev)
  31. {
  32. unsigned int base;
  33. switch (pdev->id) {
  34. case 0:
  35. base = S5PV210_GPB(0);
  36. break;
  37. case 1:
  38. base = S5PV210_GPB(4);
  39. break;
  40. default:
  41. dev_err(&pdev->dev, "Invalid SPI Controller number!");
  42. return -EINVAL;
  43. }
  44. s3c_gpio_cfgall_range(base, 3,
  45. S3C_GPIO_SFN(2), S3C_GPIO_PULL_UP);
  46. return 0;
  47. }
  48. static struct resource s5pv210_spi0_resource[] = {
  49. [0] = {
  50. .start = S5PV210_PA_SPI0,
  51. .end = S5PV210_PA_SPI0 + 0x100 - 1,
  52. .flags = IORESOURCE_MEM,
  53. },
  54. [1] = {
  55. .start = DMACH_SPI0_TX,
  56. .end = DMACH_SPI0_TX,
  57. .flags = IORESOURCE_DMA,
  58. },
  59. [2] = {
  60. .start = DMACH_SPI0_RX,
  61. .end = DMACH_SPI0_RX,
  62. .flags = IORESOURCE_DMA,
  63. },
  64. [3] = {
  65. .start = IRQ_SPI0,
  66. .end = IRQ_SPI0,
  67. .flags = IORESOURCE_IRQ,
  68. },
  69. };
  70. static struct s3c64xx_spi_info s5pv210_spi0_pdata = {
  71. .cfg_gpio = s5pv210_spi_cfg_gpio,
  72. .fifo_lvl_mask = 0x1ff,
  73. .rx_lvl_offset = 15,
  74. .high_speed = 1,
  75. };
  76. static u64 spi_dmamask = DMA_BIT_MASK(32);
  77. struct platform_device s5pv210_device_spi0 = {
  78. .name = "s3c64xx-spi",
  79. .id = 0,
  80. .num_resources = ARRAY_SIZE(s5pv210_spi0_resource),
  81. .resource = s5pv210_spi0_resource,
  82. .dev = {
  83. .dma_mask = &spi_dmamask,
  84. .coherent_dma_mask = DMA_BIT_MASK(32),
  85. .platform_data = &s5pv210_spi0_pdata,
  86. },
  87. };
  88. static struct resource s5pv210_spi1_resource[] = {
  89. [0] = {
  90. .start = S5PV210_PA_SPI1,
  91. .end = S5PV210_PA_SPI1 + 0x100 - 1,
  92. .flags = IORESOURCE_MEM,
  93. },
  94. [1] = {
  95. .start = DMACH_SPI1_TX,
  96. .end = DMACH_SPI1_TX,
  97. .flags = IORESOURCE_DMA,
  98. },
  99. [2] = {
  100. .start = DMACH_SPI1_RX,
  101. .end = DMACH_SPI1_RX,
  102. .flags = IORESOURCE_DMA,
  103. },
  104. [3] = {
  105. .start = IRQ_SPI1,
  106. .end = IRQ_SPI1,
  107. .flags = IORESOURCE_IRQ,
  108. },
  109. };
  110. static struct s3c64xx_spi_info s5pv210_spi1_pdata = {
  111. .cfg_gpio = s5pv210_spi_cfg_gpio,
  112. .fifo_lvl_mask = 0x7f,
  113. .rx_lvl_offset = 15,
  114. .high_speed = 1,
  115. };
  116. struct platform_device s5pv210_device_spi1 = {
  117. .name = "s3c64xx-spi",
  118. .id = 1,
  119. .num_resources = ARRAY_SIZE(s5pv210_spi1_resource),
  120. .resource = s5pv210_spi1_resource,
  121. .dev = {
  122. .dma_mask = &spi_dmamask,
  123. .coherent_dma_mask = DMA_BIT_MASK(32),
  124. .platform_data = &s5pv210_spi1_pdata,
  125. },
  126. };
  127. void __init s5pv210_spi_set_info(int cntrlr, int src_clk_nr, int num_cs)
  128. {
  129. struct s3c64xx_spi_info *pd;
  130. /* Reject invalid configuration */
  131. if (!num_cs || src_clk_nr < 0
  132. || src_clk_nr > S5PV210_SPI_SRCCLK_SCLK) {
  133. printk(KERN_ERR "%s: Invalid SPI configuration\n", __func__);
  134. return;
  135. }
  136. switch (cntrlr) {
  137. case 0:
  138. pd = &s5pv210_spi0_pdata;
  139. break;
  140. case 1:
  141. pd = &s5pv210_spi1_pdata;
  142. break;
  143. default:
  144. printk(KERN_ERR "%s: Invalid SPI controller(%d)\n",
  145. __func__, cntrlr);
  146. return;
  147. }
  148. pd->num_cs = num_cs;
  149. pd->src_clk_nr = src_clk_nr;
  150. pd->src_clk_name = spi_src_clks[src_clk_nr];
  151. }