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 11 #include <common.h> 12 #include <dm.h> 13 #include <ahci.h> 14 #include <scsi.h> 15 #include <sata.h> 16 #include <asm/io.h> 17 #include <generic-phy.h> 18 19 struct dwc_ahci_priv { 20 void *base; 21 void *wrapper_base; 22 }; 23 24 static int dwc_ahci_bind(struct udevice *dev) 25 { 26 struct udevice *scsi_dev; 27 28 return ahci_bind_scsi(dev, &scsi_dev); 29 } 30 31 static int dwc_ahci_ofdata_to_platdata(struct udevice *dev) 32 { 33 struct dwc_ahci_priv *priv = dev_get_priv(dev); 34 fdt_addr_t addr; 35 36 priv->base = map_physmem(dev_read_addr(dev), sizeof(void *), 37 MAP_NOCACHE); 38 39 addr = devfdt_get_addr_index(dev, 1); 40 if (addr != FDT_ADDR_T_NONE) { 41 priv->wrapper_base = map_physmem(addr, sizeof(void *), 42 MAP_NOCACHE); 43 } else { 44 priv->wrapper_base = NULL; 45 } 46 47 return 0; 48 } 49 50 static int dwc_ahci_probe(struct udevice *dev) 51 { 52 struct dwc_ahci_priv *priv = dev_get_priv(dev); 53 int ret; 54 struct phy phy; 55 56 ret = generic_phy_get_by_name(dev, "sata-phy", &phy); 57 if (ret) { 58 pr_err("can't get the phy from DT\n"); 59 return ret; 60 } 61 62 ret = generic_phy_init(&phy); 63 if (ret) { 64 pr_err("unable to initialize the sata phy\n"); 65 return ret; 66 } 67 68 ret = generic_phy_power_on(&phy); 69 if (ret) { 70 pr_err("unable to power on the sata phy\n"); 71 return ret; 72 } 73 74 return ahci_probe_scsi(dev, (ulong)priv->base); 75 } 76 77 static const struct udevice_id dwc_ahci_ids[] = { 78 { .compatible = "snps,dwc-ahci" }, 79 { } 80 }; 81 82 U_BOOT_DRIVER(dwc_ahci) = { 83 .name = "dwc_ahci", 84 .id = UCLASS_AHCI, 85 .of_match = dwc_ahci_ids, 86 .bind = dwc_ahci_bind, 87 .ofdata_to_platdata = dwc_ahci_ofdata_to_platdata, 88 .ops = &scsi_ops, 89 .probe = dwc_ahci_probe, 90 .priv_auto_alloc_size = sizeof(struct dwc_ahci_priv), 91 }; 92