diff mbox series

[u-boot-marvell,08/11] ata: ahci_mvebu: add PHY support

Message ID 20200419154850.25868-9-marek.behun@nic.cz
State New
Headers show
Series Armada 37xx: port comphy to generic-phys (PLEASE TEST) | expand

Commit Message

Marek BehĂșn April 19, 2020, 3:48 p.m. UTC
Use generic-phy API to power on SATA PHY.

Signed-off-by: Marek Beh?n <marek.behun at nic.cz>
---
 drivers/ata/ahci_mvebu.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
diff mbox series

Patch

diff --git a/drivers/ata/ahci_mvebu.c b/drivers/ata/ahci_mvebu.c
index 48a9d00d14..d229ab84ed 100644
--- a/drivers/ata/ahci_mvebu.c
+++ b/drivers/ata/ahci_mvebu.c
@@ -6,6 +6,7 @@ 
 #include <common.h>
 #include <ahci.h>
 #include <dm.h>
+#include <generic-phy.h>
 
 /*
  * Dummy implementation that can be overwritten by a board
@@ -30,14 +31,48 @@  static int mvebu_ahci_bind(struct udevice *dev)
 	return 0;
 }
 
+static int mvebu_ahci_phy_power_on(struct udevice *dev)
+{
+	struct phy phy;
+	int ret;
+
+	ret = generic_phy_get_by_index(dev, 0, &phy);
+	if (ret == -ENOENT)
+		return 0;
+
+	ret = generic_phy_init(&phy);
+	if (ret)
+		return ret;
+
+	ret = generic_phy_set_mode(&phy, PHY_MODE_SATA, 0);
+	if (ret)
+		goto err;
+
+	ret = generic_phy_power_on(&phy);
+	if (ret)
+		goto err;
+
+	return 0;
+
+err:
+	generic_phy_exit(&phy);
+	return ret;
+}
+
 static int mvebu_ahci_probe(struct udevice *dev)
 {
+	int ret;
+
 	/*
 	 * Board specific SATA / AHCI enable code, e.g. enable the
 	 * AHCI power or deassert reset
 	 */
 	board_ahci_enable();
 
+	ret = mvebu_ahci_phy_power_on(dev);
+	if (ret)
+		return ret;
+
 	ahci_probe_scsi(dev, (ulong)devfdt_get_addr_ptr(dev));
 
 	return 0;