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