dev-spi.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /* linux/arch/arm/plat-s3c64xx/dev-spi.c
  2. *
  3. * Copyright (C) 2009 Samsung Electronics 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/kernel.h>
  11. #include <linux/string.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/dma-mapping.h>
  14. #include <mach/dma.h>
  15. #include <mach/map.h>
  16. #include <mach/gpio.h>
  17. #include <mach/gpio-bank-c.h>
  18. #include <mach/spi-clocks.h>
  19. #include <plat/s3c64xx-spi.h>
  20. #include <plat/gpio-cfg.h>
  21. #include <plat/irqs.h>
  22. static char *spi_src_clks[] = {
  23. [S3C64XX_SPI_SRCCLK_PCLK] = "pclk",
  24. [S3C64XX_SPI_SRCCLK_SPIBUS] = "spi-bus",
  25. [S3C64XX_SPI_SRCCLK_48M] = "spi_48m",
  26. };
  27. /* SPI Controller platform_devices */
  28. /* Since we emulate multi-cs capability, we do not touch the GPC-3,7.
  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 s3c64xx_spi_cfg_gpio(struct platform_device *pdev)
  35. {
  36. switch (pdev->id) {
  37. case 0:
  38. s3c_gpio_cfgpin(S3C64XX_GPC(0), S3C64XX_GPC0_SPI_MISO0);
  39. s3c_gpio_cfgpin(S3C64XX_GPC(1), S3C64XX_GPC1_SPI_CLKO);
  40. s3c_gpio_cfgpin(S3C64XX_GPC(2), S3C64XX_GPC2_SPI_MOSIO);
  41. s3c_gpio_setpull(S3C64XX_GPC(0), S3C_GPIO_PULL_UP);
  42. s3c_gpio_setpull(S3C64XX_GPC(1), S3C_GPIO_PULL_UP);
  43. s3c_gpio_setpull(S3C64XX_GPC(2), S3C_GPIO_PULL_UP);
  44. break;
  45. case 1:
  46. s3c_gpio_cfgpin(S3C64XX_GPC(4), S3C64XX_GPC4_SPI_MISO1);
  47. s3c_gpio_cfgpin(S3C64XX_GPC(5), S3C64XX_GPC5_SPI_CLK1);
  48. s3c_gpio_cfgpin(S3C64XX_GPC(6), S3C64XX_GPC6_SPI_MOSI1);
  49. s3c_gpio_setpull(S3C64XX_GPC(4), S3C_GPIO_PULL_UP);
  50. s3c_gpio_setpull(S3C64XX_GPC(5), S3C_GPIO_PULL_UP);
  51. s3c_gpio_setpull(S3C64XX_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 struct resource s3c64xx_spi0_resource[] = {
  60. [0] = {
  61. .start = S3C64XX_PA_SPI0,
  62. .end = S3C64XX_PA_SPI0 + 0x100 - 1,
  63. .flags = IORESOURCE_MEM,
  64. },
  65. [1] = {
  66. .start = DMACH_SPI0_TX,
  67. .end = DMACH_SPI0_TX,
  68. .flags = IORESOURCE_DMA,
  69. },
  70. [2] = {
  71. .start = DMACH_SPI0_RX,
  72. .end = DMACH_SPI0_RX,
  73. .flags = IORESOURCE_DMA,
  74. },
  75. [3] = {
  76. .start = IRQ_SPI0,
  77. .end = IRQ_SPI0,
  78. .flags = IORESOURCE_IRQ,
  79. },
  80. };
  81. static struct s3c64xx_spi_info s3c64xx_spi0_pdata = {
  82. .cfg_gpio = s3c64xx_spi_cfg_gpio,
  83. .fifo_lvl_mask = 0x7f,
  84. .rx_lvl_offset = 13,
  85. };
  86. static u64 spi_dmamask = DMA_BIT_MASK(32);
  87. struct platform_device s3c64xx_device_spi0 = {
  88. .name = "s3c64xx-spi",
  89. .id = 0,
  90. .num_resources = ARRAY_SIZE(s3c64xx_spi0_resource),
  91. .resource = s3c64xx_spi0_resource,
  92. .dev = {
  93. .dma_mask = &spi_dmamask,
  94. .coherent_dma_mask = DMA_BIT_MASK(32),
  95. .platform_data = &s3c64xx_spi0_pdata,
  96. },
  97. };
  98. EXPORT_SYMBOL(s3c64xx_device_spi0);
  99. static struct resource s3c64xx_spi1_resource[] = {
  100. [0] = {
  101. .start = S3C64XX_PA_SPI1,
  102. .end = S3C64XX_PA_SPI1 + 0x100 - 1,
  103. .flags = IORESOURCE_MEM,
  104. },
  105. [1] = {
  106. .start = DMACH_SPI1_TX,
  107. .end = DMACH_SPI1_TX,
  108. .flags = IORESOURCE_DMA,
  109. },
  110. [2] = {
  111. .start = DMACH_SPI1_RX,
  112. .end = DMACH_SPI1_RX,
  113. .flags = IORESOURCE_DMA,
  114. },
  115. [3] = {
  116. .start = IRQ_SPI1,
  117. .end = IRQ_SPI1,
  118. .flags = IORESOURCE_IRQ,
  119. },
  120. };
  121. static struct s3c64xx_spi_info s3c64xx_spi1_pdata = {
  122. .cfg_gpio = s3c64xx_spi_cfg_gpio,
  123. .fifo_lvl_mask = 0x7f,
  124. .rx_lvl_offset = 13,
  125. };
  126. struct platform_device s3c64xx_device_spi1 = {
  127. .name = "s3c64xx-spi",
  128. .id = 1,
  129. .num_resources = ARRAY_SIZE(s3c64xx_spi1_resource),
  130. .resource = s3c64xx_spi1_resource,
  131. .dev = {
  132. .dma_mask = &spi_dmamask,
  133. .coherent_dma_mask = DMA_BIT_MASK(32),
  134. .platform_data = &s3c64xx_spi1_pdata,
  135. },
  136. };
  137. EXPORT_SYMBOL(s3c64xx_device_spi1);
  138. void __init s3c64xx_spi_set_info(int cntrlr, int src_clk_nr, int num_cs)
  139. {
  140. struct s3c64xx_spi_info *pd;
  141. /* Reject invalid configuration */
  142. if (!num_cs || src_clk_nr < 0
  143. || src_clk_nr > S3C64XX_SPI_SRCCLK_48M) {
  144. printk(KERN_ERR "%s: Invalid SPI configuration\n", __func__);
  145. return;
  146. }
  147. switch (cntrlr) {
  148. case 0:
  149. pd = &s3c64xx_spi0_pdata;
  150. break;
  151. case 1:
  152. pd = &s3c64xx_spi1_pdata;
  153. break;
  154. default:
  155. printk(KERN_ERR "%s: Invalid SPI controller(%d)\n",
  156. __func__, cntrlr);
  157. return;
  158. }
  159. pd->num_cs = num_cs;
  160. pd->src_clk_nr = src_clk_nr;
  161. pd->src_clk_name = spi_src_clks[src_clk_nr];
  162. }