dev-spi.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  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. .tx_st_done = 25,
  76. };
  77. static u64 spi_dmamask = DMA_BIT_MASK(32);
  78. struct platform_device s5pv210_device_spi0 = {
  79. .name = "s3c64xx-spi",
  80. .id = 0,
  81. .num_resources = ARRAY_SIZE(s5pv210_spi0_resource),
  82. .resource = s5pv210_spi0_resource,
  83. .dev = {
  84. .dma_mask = &spi_dmamask,
  85. .coherent_dma_mask = DMA_BIT_MASK(32),
  86. .platform_data = &s5pv210_spi0_pdata,
  87. },
  88. };
  89. static struct resource s5pv210_spi1_resource[] = {
  90. [0] = {
  91. .start = S5PV210_PA_SPI1,
  92. .end = S5PV210_PA_SPI1 + 0x100 - 1,
  93. .flags = IORESOURCE_MEM,
  94. },
  95. [1] = {
  96. .start = DMACH_SPI1_TX,
  97. .end = DMACH_SPI1_TX,
  98. .flags = IORESOURCE_DMA,
  99. },
  100. [2] = {
  101. .start = DMACH_SPI1_RX,
  102. .end = DMACH_SPI1_RX,
  103. .flags = IORESOURCE_DMA,
  104. },
  105. [3] = {
  106. .start = IRQ_SPI1,
  107. .end = IRQ_SPI1,
  108. .flags = IORESOURCE_IRQ,
  109. },
  110. };
  111. static struct s3c64xx_spi_info s5pv210_spi1_pdata = {
  112. .cfg_gpio = s5pv210_spi_cfg_gpio,
  113. .fifo_lvl_mask = 0x7f,
  114. .rx_lvl_offset = 15,
  115. .high_speed = 1,
  116. .tx_st_done = 25,
  117. };
  118. struct platform_device s5pv210_device_spi1 = {
  119. .name = "s3c64xx-spi",
  120. .id = 1,
  121. .num_resources = ARRAY_SIZE(s5pv210_spi1_resource),
  122. .resource = s5pv210_spi1_resource,
  123. .dev = {
  124. .dma_mask = &spi_dmamask,
  125. .coherent_dma_mask = DMA_BIT_MASK(32),
  126. .platform_data = &s5pv210_spi1_pdata,
  127. },
  128. };
  129. void __init s5pv210_spi_set_info(int cntrlr, int src_clk_nr, int num_cs)
  130. {
  131. struct s3c64xx_spi_info *pd;
  132. /* Reject invalid configuration */
  133. if (!num_cs || src_clk_nr < 0
  134. || src_clk_nr > S5PV210_SPI_SRCCLK_SCLK) {
  135. printk(KERN_ERR "%s: Invalid SPI configuration\n", __func__);
  136. return;
  137. }
  138. switch (cntrlr) {
  139. case 0:
  140. pd = &s5pv210_spi0_pdata;
  141. break;
  142. case 1:
  143. pd = &s5pv210_spi1_pdata;
  144. break;
  145. default:
  146. printk(KERN_ERR "%s: Invalid SPI controller(%d)\n",
  147. __func__, cntrlr);
  148. return;
  149. }
  150. pd->num_cs = num_cs;
  151. pd->src_clk_nr = src_clk_nr;
  152. pd->src_clk_name = spi_src_clks[src_clk_nr];
  153. }