dwc_ahci.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * DWC SATA platform driver
  4. *
  5. * (C) Copyright 2016
  6. * Texas Instruments Incorporated, <www.ti.com>
  7. *
  8. * Author: Mugunthan V N <mugunthanvnm@ti.com>
  9. */
  10. #include <common.h>
  11. #include <dm.h>
  12. #include <ahci.h>
  13. #include <scsi.h>
  14. #include <sata.h>
  15. #include <asm/arch/sata.h>
  16. #include <asm/io.h>
  17. #include <generic-phy.h>
  18. struct dwc_ahci_priv {
  19. void *base;
  20. void *wrapper_base;
  21. };
  22. static int dwc_ahci_bind(struct udevice *dev)
  23. {
  24. struct udevice *scsi_dev;
  25. return ahci_bind_scsi(dev, &scsi_dev);
  26. }
  27. static int dwc_ahci_of_to_plat(struct udevice *dev)
  28. {
  29. struct dwc_ahci_priv *priv = dev_get_priv(dev);
  30. fdt_addr_t addr;
  31. priv->base = map_physmem(dev_read_addr(dev), sizeof(void *),
  32. MAP_NOCACHE);
  33. addr = devfdt_get_addr_index(dev, 1);
  34. if (addr != FDT_ADDR_T_NONE) {
  35. priv->wrapper_base = map_physmem(addr, sizeof(void *),
  36. MAP_NOCACHE);
  37. } else {
  38. priv->wrapper_base = NULL;
  39. }
  40. return 0;
  41. }
  42. static int dwc_ahci_probe(struct udevice *dev)
  43. {
  44. struct dwc_ahci_priv *priv = dev_get_priv(dev);
  45. int ret;
  46. struct phy phy;
  47. ret = generic_phy_get_by_name(dev, "sata-phy", &phy);
  48. if (ret) {
  49. pr_err("can't get the phy from DT\n");
  50. return ret;
  51. }
  52. ret = generic_phy_init(&phy);
  53. if (ret) {
  54. pr_debug("unable to initialize the sata phy\n");
  55. return ret;
  56. }
  57. ret = generic_phy_power_on(&phy);
  58. if (ret) {
  59. pr_debug("unable to power on the sata phy\n");
  60. return ret;
  61. }
  62. if (priv->wrapper_base) {
  63. u32 val = TI_SATA_IDLE_NO | TI_SATA_STANDBY_NO;
  64. /* Enable SATA module, No Idle, No Standby */
  65. writel(val, priv->wrapper_base + TI_SATA_SYSCONFIG);
  66. }
  67. return ahci_probe_scsi(dev, (ulong)priv->base);
  68. }
  69. static const struct udevice_id dwc_ahci_ids[] = {
  70. { .compatible = "snps,dwc-ahci" },
  71. { }
  72. };
  73. U_BOOT_DRIVER(dwc_ahci) = {
  74. .name = "dwc_ahci",
  75. .id = UCLASS_AHCI,
  76. .of_match = dwc_ahci_ids,
  77. .bind = dwc_ahci_bind,
  78. .of_to_plat = dwc_ahci_of_to_plat,
  79. .ops = &scsi_ops,
  80. .probe = dwc_ahci_probe,
  81. .priv_auto = sizeof(struct dwc_ahci_priv),
  82. };