dev-spi.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. /* linux/arch/arm/mach-s5p64x0/dev-spi.c
  2. *
  3. * Copyright (c) 2010 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * Copyright (C) 2010 Samsung Electronics Co. Ltd.
  7. * Jaswinder Singh <jassi.brar@samsung.com>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/platform_device.h>
  14. #include <linux/dma-mapping.h>
  15. #include <linux/gpio.h>
  16. #include <mach/dma.h>
  17. #include <mach/map.h>
  18. #include <mach/irqs.h>
  19. #include <mach/regs-clock.h>
  20. #include <mach/spi-clocks.h>
  21. #include <plat/cpu.h>
  22. #include <plat/s3c64xx-spi.h>
  23. #include <plat/gpio-cfg.h>
  24. static char *s5p64x0_spi_src_clks[] = {
  25. [S5P64X0_SPI_SRCCLK_PCLK] = "pclk",
  26. [S5P64X0_SPI_SRCCLK_SCLK] = "sclk_spi",
  27. };
  28. /* SPI Controller platform_devices */
  29. /* Since we emulate multi-cs capability, we do not touch the CS.
  30. * The emulated CS is toggled by board specific mechanism, as it can
  31. * be either some immediate GPIO or some signal out of some other
  32. * chip in between ... or some yet another way.
  33. * We simply do not assume anything about CS.
  34. */
  35. static int s5p6440_spi_cfg_gpio(struct platform_device *pdev)
  36. {
  37. unsigned int base;
  38. switch (pdev->id) {
  39. case 0:
  40. base = S5P6440_GPC(0);
  41. break;
  42. case 1:
  43. base = S5P6440_GPC(4);
  44. break;
  45. default:
  46. dev_err(&pdev->dev, "Invalid SPI Controller number!");
  47. return -EINVAL;
  48. }
  49. s3c_gpio_cfgall_range(base, 3,
  50. S3C_GPIO_SFN(2), S3C_GPIO_PULL_UP);
  51. return 0;
  52. }
  53. static int s5p6450_spi_cfg_gpio(struct platform_device *pdev)
  54. {
  55. unsigned int base;
  56. switch (pdev->id) {
  57. case 0:
  58. base = S5P6450_GPC(0);
  59. break;
  60. case 1:
  61. base = S5P6450_GPC(4);
  62. break;
  63. default:
  64. dev_err(&pdev->dev, "Invalid SPI Controller number!");
  65. return -EINVAL;
  66. }
  67. s3c_gpio_cfgall_range(base, 3,
  68. S3C_GPIO_SFN(2), S3C_GPIO_PULL_UP);
  69. return 0;
  70. }
  71. static struct resource s5p64x0_spi0_resource[] = {
  72. [0] = {
  73. .start = S5P64X0_PA_SPI0,
  74. .end = S5P64X0_PA_SPI0 + 0x100 - 1,
  75. .flags = IORESOURCE_MEM,
  76. },
  77. [1] = {
  78. .start = DMACH_SPI0_TX,
  79. .end = DMACH_SPI0_TX,
  80. .flags = IORESOURCE_DMA,
  81. },
  82. [2] = {
  83. .start = DMACH_SPI0_RX,
  84. .end = DMACH_SPI0_RX,
  85. .flags = IORESOURCE_DMA,
  86. },
  87. [3] = {
  88. .start = IRQ_SPI0,
  89. .end = IRQ_SPI0,
  90. .flags = IORESOURCE_IRQ,
  91. },
  92. };
  93. static struct s3c64xx_spi_info s5p6440_spi0_pdata = {
  94. .cfg_gpio = s5p6440_spi_cfg_gpio,
  95. .fifo_lvl_mask = 0x1ff,
  96. .rx_lvl_offset = 15,
  97. .tx_st_done = 25,
  98. };
  99. static struct s3c64xx_spi_info s5p6450_spi0_pdata = {
  100. .cfg_gpio = s5p6450_spi_cfg_gpio,
  101. .fifo_lvl_mask = 0x1ff,
  102. .rx_lvl_offset = 15,
  103. .tx_st_done = 25,
  104. };
  105. static u64 spi_dmamask = DMA_BIT_MASK(32);
  106. struct platform_device s5p64x0_device_spi0 = {
  107. .name = "s3c64xx-spi",
  108. .id = 0,
  109. .num_resources = ARRAY_SIZE(s5p64x0_spi0_resource),
  110. .resource = s5p64x0_spi0_resource,
  111. .dev = {
  112. .dma_mask = &spi_dmamask,
  113. .coherent_dma_mask = DMA_BIT_MASK(32),
  114. },
  115. };
  116. static struct resource s5p64x0_spi1_resource[] = {
  117. [0] = {
  118. .start = S5P64X0_PA_SPI1,
  119. .end = S5P64X0_PA_SPI1 + 0x100 - 1,
  120. .flags = IORESOURCE_MEM,
  121. },
  122. [1] = {
  123. .start = DMACH_SPI1_TX,
  124. .end = DMACH_SPI1_TX,
  125. .flags = IORESOURCE_DMA,
  126. },
  127. [2] = {
  128. .start = DMACH_SPI1_RX,
  129. .end = DMACH_SPI1_RX,
  130. .flags = IORESOURCE_DMA,
  131. },
  132. [3] = {
  133. .start = IRQ_SPI1,
  134. .end = IRQ_SPI1,
  135. .flags = IORESOURCE_IRQ,
  136. },
  137. };
  138. static struct s3c64xx_spi_info s5p6440_spi1_pdata = {
  139. .cfg_gpio = s5p6440_spi_cfg_gpio,
  140. .fifo_lvl_mask = 0x7f,
  141. .rx_lvl_offset = 15,
  142. .tx_st_done = 25,
  143. };
  144. static struct s3c64xx_spi_info s5p6450_spi1_pdata = {
  145. .cfg_gpio = s5p6450_spi_cfg_gpio,
  146. .fifo_lvl_mask = 0x7f,
  147. .rx_lvl_offset = 15,
  148. .tx_st_done = 25,
  149. };
  150. struct platform_device s5p64x0_device_spi1 = {
  151. .name = "s3c64xx-spi",
  152. .id = 1,
  153. .num_resources = ARRAY_SIZE(s5p64x0_spi1_resource),
  154. .resource = s5p64x0_spi1_resource,
  155. .dev = {
  156. .dma_mask = &spi_dmamask,
  157. .coherent_dma_mask = DMA_BIT_MASK(32),
  158. },
  159. };
  160. void __init s5p64x0_spi_set_info(int cntrlr, int src_clk_nr, int num_cs)
  161. {
  162. struct s3c64xx_spi_info *pd;
  163. /* Reject invalid configuration */
  164. if (!num_cs || src_clk_nr < 0
  165. || src_clk_nr > S5P64X0_SPI_SRCCLK_SCLK) {
  166. printk(KERN_ERR "%s: Invalid SPI configuration\n", __func__);
  167. return;
  168. }
  169. switch (cntrlr) {
  170. case 0:
  171. if (soc_is_s5p6450())
  172. pd = &s5p6450_spi0_pdata;
  173. else
  174. pd = &s5p6440_spi0_pdata;
  175. s5p64x0_device_spi0.dev.platform_data = pd;
  176. break;
  177. case 1:
  178. if (soc_is_s5p6450())
  179. pd = &s5p6450_spi1_pdata;
  180. else
  181. pd = &s5p6440_spi1_pdata;
  182. s5p64x0_device_spi1.dev.platform_data = pd;
  183. break;
  184. default:
  185. printk(KERN_ERR "%s: Invalid SPI controller(%d)\n",
  186. __func__, cntrlr);
  187. return;
  188. }
  189. pd->num_cs = num_cs;
  190. pd->src_clk_nr = src_clk_nr;
  191. pd->src_clk_name = s5p64x0_spi_src_clks[src_clk_nr];
  192. }