dev-spi.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. unsigned int base;
  37. switch (pdev->id) {
  38. case 0:
  39. base = S5P6440_GPC(0);
  40. break;
  41. case 1:
  42. base = S5P6440_GPC(4);
  43. break;
  44. default:
  45. dev_err(&pdev->dev, "Invalid SPI Controller number!");
  46. return -EINVAL;
  47. }
  48. s3c_gpio_cfgall_range(base, 3,
  49. S3C_GPIO_SFN(2), S3C_GPIO_PULL_UP);
  50. return 0;
  51. }
  52. static int s5p6450_spi_cfg_gpio(struct platform_device *pdev)
  53. {
  54. unsigned int base;
  55. switch (pdev->id) {
  56. case 0:
  57. base = S5P6450_GPC(0);
  58. break;
  59. case 1:
  60. base = S5P6450_GPC(4);
  61. break;
  62. default:
  63. dev_err(&pdev->dev, "Invalid SPI Controller number!");
  64. return -EINVAL;
  65. }
  66. s3c_gpio_cfgall_range(base, 3,
  67. S3C_GPIO_SFN(2), S3C_GPIO_PULL_UP);
  68. return 0;
  69. }
  70. static struct resource s5p64x0_spi0_resource[] = {
  71. [0] = {
  72. .start = S5P64X0_PA_SPI0,
  73. .end = S5P64X0_PA_SPI0 + 0x100 - 1,
  74. .flags = IORESOURCE_MEM,
  75. },
  76. [1] = {
  77. .start = DMACH_SPI0_TX,
  78. .end = DMACH_SPI0_TX,
  79. .flags = IORESOURCE_DMA,
  80. },
  81. [2] = {
  82. .start = DMACH_SPI0_RX,
  83. .end = DMACH_SPI0_RX,
  84. .flags = IORESOURCE_DMA,
  85. },
  86. [3] = {
  87. .start = IRQ_SPI0,
  88. .end = IRQ_SPI0,
  89. .flags = IORESOURCE_IRQ,
  90. },
  91. };
  92. static struct s3c64xx_spi_info s5p6440_spi0_pdata = {
  93. .cfg_gpio = s5p6440_spi_cfg_gpio,
  94. .fifo_lvl_mask = 0x1ff,
  95. .rx_lvl_offset = 15,
  96. .tx_st_done = 25,
  97. };
  98. static struct s3c64xx_spi_info s5p6450_spi0_pdata = {
  99. .cfg_gpio = s5p6450_spi_cfg_gpio,
  100. .fifo_lvl_mask = 0x1ff,
  101. .rx_lvl_offset = 15,
  102. .tx_st_done = 25,
  103. };
  104. static u64 spi_dmamask = DMA_BIT_MASK(32);
  105. struct platform_device s5p64x0_device_spi0 = {
  106. .name = "s3c64xx-spi",
  107. .id = 0,
  108. .num_resources = ARRAY_SIZE(s5p64x0_spi0_resource),
  109. .resource = s5p64x0_spi0_resource,
  110. .dev = {
  111. .dma_mask = &spi_dmamask,
  112. .coherent_dma_mask = DMA_BIT_MASK(32),
  113. },
  114. };
  115. static struct resource s5p64x0_spi1_resource[] = {
  116. [0] = {
  117. .start = S5P64X0_PA_SPI1,
  118. .end = S5P64X0_PA_SPI1 + 0x100 - 1,
  119. .flags = IORESOURCE_MEM,
  120. },
  121. [1] = {
  122. .start = DMACH_SPI1_TX,
  123. .end = DMACH_SPI1_TX,
  124. .flags = IORESOURCE_DMA,
  125. },
  126. [2] = {
  127. .start = DMACH_SPI1_RX,
  128. .end = DMACH_SPI1_RX,
  129. .flags = IORESOURCE_DMA,
  130. },
  131. [3] = {
  132. .start = IRQ_SPI1,
  133. .end = IRQ_SPI1,
  134. .flags = IORESOURCE_IRQ,
  135. },
  136. };
  137. static struct s3c64xx_spi_info s5p6440_spi1_pdata = {
  138. .cfg_gpio = s5p6440_spi_cfg_gpio,
  139. .fifo_lvl_mask = 0x7f,
  140. .rx_lvl_offset = 15,
  141. .tx_st_done = 25,
  142. };
  143. static struct s3c64xx_spi_info s5p6450_spi1_pdata = {
  144. .cfg_gpio = s5p6450_spi_cfg_gpio,
  145. .fifo_lvl_mask = 0x7f,
  146. .rx_lvl_offset = 15,
  147. .tx_st_done = 25,
  148. };
  149. struct platform_device s5p64x0_device_spi1 = {
  150. .name = "s3c64xx-spi",
  151. .id = 1,
  152. .num_resources = ARRAY_SIZE(s5p64x0_spi1_resource),
  153. .resource = s5p64x0_spi1_resource,
  154. .dev = {
  155. .dma_mask = &spi_dmamask,
  156. .coherent_dma_mask = DMA_BIT_MASK(32),
  157. },
  158. };
  159. void __init s5p64x0_spi_set_info(int cntrlr, int src_clk_nr, int num_cs)
  160. {
  161. unsigned int id;
  162. struct s3c64xx_spi_info *pd;
  163. id = __raw_readl(S5P64X0_SYS_ID) & 0xFF000;
  164. /* Reject invalid configuration */
  165. if (!num_cs || src_clk_nr < 0
  166. || src_clk_nr > S5P64X0_SPI_SRCCLK_SCLK) {
  167. printk(KERN_ERR "%s: Invalid SPI configuration\n", __func__);
  168. return;
  169. }
  170. switch (cntrlr) {
  171. case 0:
  172. if (id == 0x50000)
  173. pd = &s5p6450_spi0_pdata;
  174. else
  175. pd = &s5p6440_spi0_pdata;
  176. s5p64x0_device_spi0.dev.platform_data = pd;
  177. break;
  178. case 1:
  179. if (id == 0x50000)
  180. pd = &s5p6450_spi1_pdata;
  181. else
  182. pd = &s5p6440_spi1_pdata;
  183. s5p64x0_device_spi1.dev.platform_data = pd;
  184. break;
  185. default:
  186. printk(KERN_ERR "%s: Invalid SPI controller(%d)\n",
  187. __func__, cntrlr);
  188. return;
  189. }
  190. pd->num_cs = num_cs;
  191. pd->src_clk_nr = src_clk_nr;
  192. pd->src_clk_name = s5p64x0_spi_src_clks[src_clk_nr];
  193. }