ahci_da850.c 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. /*
  2. * DaVinci DA850 AHCI SATA platform driver
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2, or (at your option)
  7. * any later version.
  8. */
  9. #include <linux/kernel.h>
  10. #include <linux/module.h>
  11. #include <linux/pm.h>
  12. #include <linux/device.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/libata.h>
  15. #include <linux/ahci_platform.h>
  16. #include "ahci.h"
  17. #define DRV_NAME "ahci_da850"
  18. /* SATA PHY Control Register offset from AHCI base */
  19. #define SATA_P0PHYCR_REG 0x178
  20. #define SATA_PHY_MPY(x) ((x) << 0)
  21. #define SATA_PHY_LOS(x) ((x) << 6)
  22. #define SATA_PHY_RXCDR(x) ((x) << 10)
  23. #define SATA_PHY_RXEQ(x) ((x) << 13)
  24. #define SATA_PHY_TXSWING(x) ((x) << 19)
  25. #define SATA_PHY_ENPLL(x) ((x) << 31)
  26. /*
  27. * The multiplier needed for 1.5GHz PLL output.
  28. *
  29. * NOTE: This is currently hardcoded to be suitable for 100MHz crystal
  30. * frequency (which is used by DA850 EVM board) and may need to be changed
  31. * if you would like to use this driver on some other board.
  32. */
  33. #define DA850_SATA_CLK_MULTIPLIER 7
  34. static void da850_sata_init(struct device *dev, void __iomem *pwrdn_reg,
  35. void __iomem *ahci_base)
  36. {
  37. unsigned int val;
  38. /* Enable SATA clock receiver */
  39. val = readl(pwrdn_reg);
  40. val &= ~BIT(0);
  41. writel(val, pwrdn_reg);
  42. val = SATA_PHY_MPY(DA850_SATA_CLK_MULTIPLIER + 1) | SATA_PHY_LOS(1) |
  43. SATA_PHY_RXCDR(4) | SATA_PHY_RXEQ(1) | SATA_PHY_TXSWING(3) |
  44. SATA_PHY_ENPLL(1);
  45. writel(val, ahci_base + SATA_P0PHYCR_REG);
  46. }
  47. static int ahci_da850_softreset(struct ata_link *link,
  48. unsigned int *class, unsigned long deadline)
  49. {
  50. int pmp, ret;
  51. pmp = sata_srst_pmp(link);
  52. /*
  53. * There's an issue with the SATA controller on da850 SoCs: if we
  54. * enable Port Multiplier support, but the drive is connected directly
  55. * to the board, it can't be detected. As a workaround: if PMP is
  56. * enabled, we first call ahci_do_softreset() and pass it the result of
  57. * sata_srst_pmp(). If this call fails, we retry with pmp = 0.
  58. */
  59. ret = ahci_do_softreset(link, class, pmp, deadline, ahci_check_ready);
  60. if (pmp && ret == -EBUSY)
  61. return ahci_do_softreset(link, class, 0,
  62. deadline, ahci_check_ready);
  63. return ret;
  64. }
  65. static struct ata_port_operations ahci_da850_port_ops = {
  66. .inherits = &ahci_platform_ops,
  67. .softreset = ahci_da850_softreset,
  68. /*
  69. * No need to override .pmp_softreset - it's only used for actual
  70. * PMP-enabled ports.
  71. */
  72. };
  73. static const struct ata_port_info ahci_da850_port_info = {
  74. .flags = AHCI_FLAG_COMMON,
  75. .pio_mask = ATA_PIO4,
  76. .udma_mask = ATA_UDMA6,
  77. .port_ops = &ahci_da850_port_ops,
  78. };
  79. static struct scsi_host_template ahci_platform_sht = {
  80. AHCI_SHT(DRV_NAME),
  81. };
  82. static int ahci_da850_probe(struct platform_device *pdev)
  83. {
  84. struct device *dev = &pdev->dev;
  85. struct ahci_host_priv *hpriv;
  86. struct resource *res;
  87. void __iomem *pwrdn_reg;
  88. int rc;
  89. hpriv = ahci_platform_get_resources(pdev);
  90. if (IS_ERR(hpriv))
  91. return PTR_ERR(hpriv);
  92. rc = ahci_platform_enable_resources(hpriv);
  93. if (rc)
  94. return rc;
  95. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  96. if (!res)
  97. goto disable_resources;
  98. pwrdn_reg = devm_ioremap(dev, res->start, resource_size(res));
  99. if (!pwrdn_reg)
  100. goto disable_resources;
  101. da850_sata_init(dev, pwrdn_reg, hpriv->mmio);
  102. rc = ahci_platform_init_host(pdev, hpriv, &ahci_da850_port_info,
  103. &ahci_platform_sht);
  104. if (rc)
  105. goto disable_resources;
  106. return 0;
  107. disable_resources:
  108. ahci_platform_disable_resources(hpriv);
  109. return rc;
  110. }
  111. static SIMPLE_DEV_PM_OPS(ahci_da850_pm_ops, ahci_platform_suspend,
  112. ahci_platform_resume);
  113. static struct platform_driver ahci_da850_driver = {
  114. .probe = ahci_da850_probe,
  115. .remove = ata_platform_remove_one,
  116. .driver = {
  117. .name = DRV_NAME,
  118. .pm = &ahci_da850_pm_ops,
  119. },
  120. };
  121. module_platform_driver(ahci_da850_driver);
  122. MODULE_DESCRIPTION("DaVinci DA850 AHCI SATA platform driver");
  123. MODULE_AUTHOR("Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>");
  124. MODULE_LICENSE("GPL");