ahci_da850.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 const struct ata_port_info ahci_da850_port_info = {
  48. .flags = AHCI_FLAG_COMMON,
  49. .pio_mask = ATA_PIO4,
  50. .udma_mask = ATA_UDMA6,
  51. .port_ops = &ahci_platform_ops,
  52. };
  53. static struct scsi_host_template ahci_platform_sht = {
  54. AHCI_SHT(DRV_NAME),
  55. };
  56. static int ahci_da850_probe(struct platform_device *pdev)
  57. {
  58. struct device *dev = &pdev->dev;
  59. struct ahci_host_priv *hpriv;
  60. struct resource *res;
  61. void __iomem *pwrdn_reg;
  62. int rc;
  63. hpriv = ahci_platform_get_resources(pdev);
  64. if (IS_ERR(hpriv))
  65. return PTR_ERR(hpriv);
  66. rc = ahci_platform_enable_resources(hpriv);
  67. if (rc)
  68. return rc;
  69. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  70. if (!res)
  71. goto disable_resources;
  72. pwrdn_reg = devm_ioremap(dev, res->start, resource_size(res));
  73. if (!pwrdn_reg)
  74. goto disable_resources;
  75. da850_sata_init(dev, pwrdn_reg, hpriv->mmio);
  76. rc = ahci_platform_init_host(pdev, hpriv, &ahci_da850_port_info,
  77. &ahci_platform_sht);
  78. if (rc)
  79. goto disable_resources;
  80. return 0;
  81. disable_resources:
  82. ahci_platform_disable_resources(hpriv);
  83. return rc;
  84. }
  85. static SIMPLE_DEV_PM_OPS(ahci_da850_pm_ops, ahci_platform_suspend,
  86. ahci_platform_resume);
  87. static struct platform_driver ahci_da850_driver = {
  88. .probe = ahci_da850_probe,
  89. .remove = ata_platform_remove_one,
  90. .driver = {
  91. .name = DRV_NAME,
  92. .pm = &ahci_da850_pm_ops,
  93. },
  94. };
  95. module_platform_driver(ahci_da850_driver);
  96. MODULE_DESCRIPTION("DaVinci DA850 AHCI SATA platform driver");
  97. MODULE_AUTHOR("Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>");
  98. MODULE_LICENSE("GPL");