ahci_da850.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. /* SATA PHY Control Register offset from AHCI base */
  18. #define SATA_P0PHYCR_REG 0x178
  19. #define SATA_PHY_MPY(x) ((x) << 0)
  20. #define SATA_PHY_LOS(x) ((x) << 6)
  21. #define SATA_PHY_RXCDR(x) ((x) << 10)
  22. #define SATA_PHY_RXEQ(x) ((x) << 13)
  23. #define SATA_PHY_TXSWING(x) ((x) << 19)
  24. #define SATA_PHY_ENPLL(x) ((x) << 31)
  25. /*
  26. * The multiplier needed for 1.5GHz PLL output.
  27. *
  28. * NOTE: This is currently hardcoded to be suitable for 100MHz crystal
  29. * frequency (which is used by DA850 EVM board) and may need to be changed
  30. * if you would like to use this driver on some other board.
  31. */
  32. #define DA850_SATA_CLK_MULTIPLIER 7
  33. static void da850_sata_init(struct device *dev, void __iomem *pwrdn_reg,
  34. void __iomem *ahci_base)
  35. {
  36. unsigned int val;
  37. /* Enable SATA clock receiver */
  38. val = readl(pwrdn_reg);
  39. val &= ~BIT(0);
  40. writel(val, pwrdn_reg);
  41. val = SATA_PHY_MPY(DA850_SATA_CLK_MULTIPLIER + 1) | SATA_PHY_LOS(1) |
  42. SATA_PHY_RXCDR(4) | SATA_PHY_RXEQ(1) | SATA_PHY_TXSWING(3) |
  43. SATA_PHY_ENPLL(1);
  44. writel(val, ahci_base + SATA_P0PHYCR_REG);
  45. }
  46. static const struct ata_port_info ahci_da850_port_info = {
  47. .flags = AHCI_FLAG_COMMON,
  48. .pio_mask = ATA_PIO4,
  49. .udma_mask = ATA_UDMA6,
  50. .port_ops = &ahci_platform_ops,
  51. };
  52. static int ahci_da850_probe(struct platform_device *pdev)
  53. {
  54. struct device *dev = &pdev->dev;
  55. struct ahci_host_priv *hpriv;
  56. struct resource *res;
  57. void __iomem *pwrdn_reg;
  58. int rc;
  59. hpriv = ahci_platform_get_resources(pdev);
  60. if (IS_ERR(hpriv))
  61. return PTR_ERR(hpriv);
  62. rc = ahci_platform_enable_resources(hpriv);
  63. if (rc)
  64. return rc;
  65. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  66. if (!res)
  67. goto disable_resources;
  68. pwrdn_reg = devm_ioremap(dev, res->start, resource_size(res));
  69. if (!pwrdn_reg)
  70. goto disable_resources;
  71. da850_sata_init(dev, pwrdn_reg, hpriv->mmio);
  72. rc = ahci_platform_init_host(pdev, hpriv, &ahci_da850_port_info,
  73. 0, 0, 0);
  74. if (rc)
  75. goto disable_resources;
  76. return 0;
  77. disable_resources:
  78. ahci_platform_disable_resources(hpriv);
  79. return rc;
  80. }
  81. static SIMPLE_DEV_PM_OPS(ahci_da850_pm_ops, ahci_platform_suspend,
  82. ahci_platform_resume);
  83. static struct platform_driver ahci_da850_driver = {
  84. .probe = ahci_da850_probe,
  85. .remove = ata_platform_remove_one,
  86. .driver = {
  87. .name = "ahci_da850",
  88. .owner = THIS_MODULE,
  89. .pm = &ahci_da850_pm_ops,
  90. },
  91. };
  92. module_platform_driver(ahci_da850_driver);
  93. MODULE_DESCRIPTION("DaVinci DA850 AHCI SATA platform driver");
  94. MODULE_AUTHOR("Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>");
  95. MODULE_LICENSE("GPL");