dev-spi.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  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/s3c64xx-spi.h>
  22. #include <plat/gpio-cfg.h>
  23. static char *s5p64x0_spi_src_clks[] = {
  24. [S5P64X0_SPI_SRCCLK_PCLK] = "pclk",
  25. [S5P64X0_SPI_SRCCLK_SCLK] = "sclk_spi",
  26. };
  27. /* SPI Controller platform_devices */
  28. /* Since we emulate multi-cs capability, we do not touch the CS.
  29. * The emulated CS is toggled by board specific mechanism, as it can
  30. * be either some immediate GPIO or some signal out of some other
  31. * chip in between ... or some yet another way.
  32. * We simply do not assume anything about CS.
  33. */
  34. static int s5p6440_spi_cfg_gpio(struct platform_device *pdev)
  35. {
  36. switch (pdev->id) {
  37. case 0:
  38. s3c_gpio_cfgpin(S5P6440_GPC(0), S3C_GPIO_SFN(2));
  39. s3c_gpio_cfgpin(S5P6440_GPC(1), S3C_GPIO_SFN(2));
  40. s3c_gpio_cfgpin(S5P6440_GPC(2), S3C_GPIO_SFN(2));
  41. s3c_gpio_setpull(S5P6440_GPC(0), S3C_GPIO_PULL_UP);
  42. s3c_gpio_setpull(S5P6440_GPC(1), S3C_GPIO_PULL_UP);
  43. s3c_gpio_setpull(S5P6440_GPC(2), S3C_GPIO_PULL_UP);
  44. break;
  45. case 1:
  46. s3c_gpio_cfgpin(S5P6440_GPC(4), S3C_GPIO_SFN(2));
  47. s3c_gpio_cfgpin(S5P6440_GPC(5), S3C_GPIO_SFN(2));
  48. s3c_gpio_cfgpin(S5P6440_GPC(6), S3C_GPIO_SFN(2));
  49. s3c_gpio_setpull(S5P6440_GPC(4), S3C_GPIO_PULL_UP);
  50. s3c_gpio_setpull(S5P6440_GPC(5), S3C_GPIO_PULL_UP);
  51. s3c_gpio_setpull(S5P6440_GPC(6), S3C_GPIO_PULL_UP);
  52. break;
  53. default:
  54. dev_err(&pdev->dev, "Invalid SPI Controller number!");
  55. return -EINVAL;
  56. }
  57. return 0;
  58. }
  59. static int s5p6450_spi_cfg_gpio(struct platform_device *pdev)
  60. {
  61. switch (pdev->id) {
  62. case 0:
  63. s3c_gpio_cfgpin(S5P6450_GPC(0), S3C_GPIO_SFN(2));
  64. s3c_gpio_cfgpin(S5P6450_GPC(1), S3C_GPIO_SFN(2));
  65. s3c_gpio_cfgpin(S5P6450_GPC(2), S3C_GPIO_SFN(2));
  66. s3c_gpio_setpull(S5P6450_GPC(0), S3C_GPIO_PULL_UP);
  67. s3c_gpio_setpull(S5P6450_GPC(1), S3C_GPIO_PULL_UP);
  68. s3c_gpio_setpull(S5P6450_GPC(2), S3C_GPIO_PULL_UP);
  69. break;
  70. case 1:
  71. s3c_gpio_cfgpin(S5P6450_GPC(4), S3C_GPIO_SFN(2));
  72. s3c_gpio_cfgpin(S5P6450_GPC(5), S3C_GPIO_SFN(2));
  73. s3c_gpio_cfgpin(S5P6450_GPC(6), S3C_GPIO_SFN(2));
  74. s3c_gpio_setpull(S5P6450_GPC(4), S3C_GPIO_PULL_UP);
  75. s3c_gpio_setpull(S5P6450_GPC(5), S3C_GPIO_PULL_UP);
  76. s3c_gpio_setpull(S5P6450_GPC(6), S3C_GPIO_PULL_UP);
  77. break;
  78. default:
  79. dev_err(&pdev->dev, "Invalid SPI Controller number!");
  80. return -EINVAL;
  81. }
  82. return 0;
  83. }
  84. static struct resource s5p64x0_spi0_resource[] = {
  85. [0] = {
  86. .start = S5P64X0_PA_SPI0,
  87. .end = S5P64X0_PA_SPI0 + 0x100 - 1,
  88. .flags = IORESOURCE_MEM,
  89. },
  90. [1] = {
  91. .start = DMACH_SPI0_TX,
  92. .end = DMACH_SPI0_TX,
  93. .flags = IORESOURCE_DMA,
  94. },
  95. [2] = {
  96. .start = DMACH_SPI0_RX,
  97. .end = DMACH_SPI0_RX,
  98. .flags = IORESOURCE_DMA,
  99. },
  100. [3] = {
  101. .start = IRQ_SPI0,
  102. .end = IRQ_SPI0,
  103. .flags = IORESOURCE_IRQ,
  104. },
  105. };
  106. static struct s3c64xx_spi_info s5p6440_spi0_pdata = {
  107. .cfg_gpio = s5p6440_spi_cfg_gpio,
  108. .fifo_lvl_mask = 0x1ff,
  109. .rx_lvl_offset = 15,
  110. };
  111. static struct s3c64xx_spi_info s5p6450_spi0_pdata = {
  112. .cfg_gpio = s5p6450_spi_cfg_gpio,
  113. .fifo_lvl_mask = 0x1ff,
  114. .rx_lvl_offset = 15,
  115. };
  116. static u64 spi_dmamask = DMA_BIT_MASK(32);
  117. struct platform_device s5p64x0_device_spi0 = {
  118. .name = "s3c64xx-spi",
  119. .id = 0,
  120. .num_resources = ARRAY_SIZE(s5p64x0_spi0_resource),
  121. .resource = s5p64x0_spi0_resource,
  122. .dev = {
  123. .dma_mask = &spi_dmamask,
  124. .coherent_dma_mask = DMA_BIT_MASK(32),
  125. },
  126. };
  127. static struct resource s5p64x0_spi1_resource[] = {
  128. [0] = {
  129. .start = S5P64X0_PA_SPI1,
  130. .end = S5P64X0_PA_SPI1 + 0x100 - 1,
  131. .flags = IORESOURCE_MEM,
  132. },
  133. [1] = {
  134. .start = DMACH_SPI1_TX,
  135. .end = DMACH_SPI1_TX,
  136. .flags = IORESOURCE_DMA,
  137. },
  138. [2] = {
  139. .start = DMACH_SPI1_RX,
  140. .end = DMACH_SPI1_RX,
  141. .flags = IORESOURCE_DMA,
  142. },
  143. [3] = {
  144. .start = IRQ_SPI1,
  145. .end = IRQ_SPI1,
  146. .flags = IORESOURCE_IRQ,
  147. },
  148. };
  149. static struct s3c64xx_spi_info s5p6440_spi1_pdata = {
  150. .cfg_gpio = s5p6440_spi_cfg_gpio,
  151. .fifo_lvl_mask = 0x7f,
  152. .rx_lvl_offset = 15,
  153. };
  154. static struct s3c64xx_spi_info s5p6450_spi1_pdata = {
  155. .cfg_gpio = s5p6450_spi_cfg_gpio,
  156. .fifo_lvl_mask = 0x7f,
  157. .rx_lvl_offset = 15,
  158. };
  159. struct platform_device s5p64x0_device_spi1 = {
  160. .name = "s3c64xx-spi",
  161. .id = 1,
  162. .num_resources = ARRAY_SIZE(s5p64x0_spi1_resource),
  163. .resource = s5p64x0_spi1_resource,
  164. .dev = {
  165. .dma_mask = &spi_dmamask,
  166. .coherent_dma_mask = DMA_BIT_MASK(32),
  167. },
  168. };
  169. void __init s5p64x0_spi_set_info(int cntrlr, int src_clk_nr, int num_cs)
  170. {
  171. unsigned int id;
  172. struct s3c64xx_spi_info *pd;
  173. id = __raw_readl(S5P64X0_SYS_ID) & 0xFF000;
  174. /* Reject invalid configuration */
  175. if (!num_cs || src_clk_nr < 0
  176. || src_clk_nr > S5P64X0_SPI_SRCCLK_SCLK) {
  177. printk(KERN_ERR "%s: Invalid SPI configuration\n", __func__);
  178. return;
  179. }
  180. switch (cntrlr) {
  181. case 0:
  182. if (id == 0x50000)
  183. pd = &s5p6450_spi0_pdata;
  184. else
  185. pd = &s5p6440_spi0_pdata;
  186. s5p64x0_device_spi0.dev.platform_data = pd;
  187. break;
  188. case 1:
  189. if (id == 0x50000)
  190. pd = &s5p6450_spi1_pdata;
  191. else
  192. pd = &s5p6440_spi1_pdata;
  193. s5p64x0_device_spi1.dev.platform_data = pd;
  194. break;
  195. default:
  196. printk(KERN_ERR "%s: Invalid SPI controller(%d)\n",
  197. __func__, cntrlr);
  198. return;
  199. }
  200. pd->num_cs = num_cs;
  201. pd->src_clk_nr = src_clk_nr;
  202. pd->src_clk_name = s5p64x0_spi_src_clks[src_clk_nr];
  203. }