platform-ahci-imx.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Copyright (C) 2011 Freescale Semiconductor, Inc. All Rights Reserved.
  3. */
  4. /*
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. */
  17. #include <linux/io.h>
  18. #include <linux/clk.h>
  19. #include <linux/err.h>
  20. #include <linux/device.h>
  21. #include <linux/dma-mapping.h>
  22. #include <asm/sizes.h>
  23. #include <mach/hardware.h>
  24. #include <mach/devices-common.h>
  25. #define imx_ahci_imx_data_entry_single(soc, _devid) \
  26. { \
  27. .devid = _devid, \
  28. .iobase = soc ## _SATA_BASE_ADDR, \
  29. .irq = soc ## _INT_SATA, \
  30. }
  31. #ifdef CONFIG_SOC_IMX53
  32. const struct imx_ahci_imx_data imx53_ahci_imx_data __initconst =
  33. imx_ahci_imx_data_entry_single(MX53, "imx53-ahci");
  34. #endif
  35. enum {
  36. HOST_CAP = 0x00,
  37. HOST_CAP_SSS = (1 << 27), /* Staggered Spin-up */
  38. HOST_PORTS_IMPL = 0x0c,
  39. HOST_TIMER1MS = 0xe0, /* Timer 1-ms */
  40. };
  41. static struct clk *sata_clk, *sata_ref_clk;
  42. /* AHCI module Initialization, if return 0, initialization is successful. */
  43. static int imx_sata_init(struct device *dev, void __iomem *addr)
  44. {
  45. u32 tmpdata;
  46. int ret = 0;
  47. struct clk *clk;
  48. sata_clk = clk_get(dev, "ahci");
  49. if (IS_ERR(sata_clk)) {
  50. dev_err(dev, "no sata clock.\n");
  51. return PTR_ERR(sata_clk);
  52. }
  53. ret = clk_enable(sata_clk);
  54. if (ret) {
  55. dev_err(dev, "can't enable sata clock.\n");
  56. goto put_sata_clk;
  57. }
  58. /* Get the AHCI SATA PHY CLK */
  59. sata_ref_clk = clk_get(dev, "ahci_phy");
  60. if (IS_ERR(sata_ref_clk)) {
  61. dev_err(dev, "no sata ref clock.\n");
  62. ret = PTR_ERR(sata_ref_clk);
  63. goto release_sata_clk;
  64. }
  65. ret = clk_enable(sata_ref_clk);
  66. if (ret) {
  67. dev_err(dev, "can't enable sata ref clock.\n");
  68. goto put_sata_ref_clk;
  69. }
  70. /* Get the AHB clock rate, and configure the TIMER1MS reg later */
  71. clk = clk_get(dev, "ahci_dma");
  72. if (IS_ERR(clk)) {
  73. dev_err(dev, "no dma clock.\n");
  74. ret = PTR_ERR(clk);
  75. goto release_sata_ref_clk;
  76. }
  77. tmpdata = clk_get_rate(clk) / 1000;
  78. clk_put(clk);
  79. writel(tmpdata, addr + HOST_TIMER1MS);
  80. tmpdata = readl(addr + HOST_CAP);
  81. if (!(tmpdata & HOST_CAP_SSS)) {
  82. tmpdata |= HOST_CAP_SSS;
  83. writel(tmpdata, addr + HOST_CAP);
  84. }
  85. if (!(readl(addr + HOST_PORTS_IMPL) & 0x1))
  86. writel((readl(addr + HOST_PORTS_IMPL) | 0x1),
  87. addr + HOST_PORTS_IMPL);
  88. return 0;
  89. release_sata_ref_clk:
  90. clk_disable(sata_ref_clk);
  91. put_sata_ref_clk:
  92. clk_put(sata_ref_clk);
  93. release_sata_clk:
  94. clk_disable(sata_clk);
  95. put_sata_clk:
  96. clk_put(sata_clk);
  97. return ret;
  98. }
  99. static void imx_sata_exit(struct device *dev)
  100. {
  101. clk_disable(sata_ref_clk);
  102. clk_put(sata_ref_clk);
  103. clk_disable(sata_clk);
  104. clk_put(sata_clk);
  105. }
  106. struct platform_device *__init imx_add_ahci_imx(
  107. const struct imx_ahci_imx_data *data,
  108. const struct ahci_platform_data *pdata)
  109. {
  110. struct resource res[] = {
  111. {
  112. .start = data->iobase,
  113. .end = data->iobase + SZ_4K - 1,
  114. .flags = IORESOURCE_MEM,
  115. }, {
  116. .start = data->irq,
  117. .end = data->irq,
  118. .flags = IORESOURCE_IRQ,
  119. },
  120. };
  121. return imx_add_platform_device_dmamask(data->devid, 0,
  122. res, ARRAY_SIZE(res),
  123. pdata, sizeof(*pdata), DMA_BIT_MASK(32));
  124. }
  125. struct platform_device *__init imx53_add_ahci_imx(void)
  126. {
  127. struct ahci_platform_data pdata = {
  128. .init = imx_sata_init,
  129. .exit = imx_sata_exit,
  130. };
  131. return imx_add_ahci_imx(&imx53_ahci_imx_data, &pdata);
  132. }