2 * DWC SATA platform driver
5 * Texas Instruments Incorporated, <www.ti.com>
7 * Author: Mugunthan V N <mugunthanvnm@ti.com>
9 * SPDX-License-Identifier: GPL-2.0+
17 #include <asm/arch/sata.h>
19 #include <generic-phy.h>
21 DECLARE_GLOBAL_DATA_PTR;
23 struct dwc_ahci_priv {
28 static int dwc_ahci_ofdata_to_platdata(struct udevice *dev)
30 struct dwc_ahci_priv *priv = dev_get_priv(dev);
31 struct scsi_platdata *plat = dev_get_platdata(dev);
34 plat->max_id = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev),
35 "max-id", CONFIG_SYS_SCSI_MAX_SCSI_ID);
36 plat->max_lun = fdtdec_get_uint(gd->fdt_blob, dev_of_offset(dev),
37 "max-lun", CONFIG_SYS_SCSI_MAX_LUN);
39 priv->base = map_physmem(devfdt_get_addr(dev), sizeof(void *),
42 addr = devfdt_get_addr_index(dev, 1);
43 if (addr != FDT_ADDR_T_NONE) {
44 priv->wrapper_base = map_physmem(addr, sizeof(void *),
47 priv->wrapper_base = NULL;
53 static int dwc_ahci_probe(struct udevice *dev)
55 struct dwc_ahci_priv *priv = dev_get_priv(dev);
59 ret = generic_phy_get_by_name(dev, "sata-phy", &phy);
61 error("can't get the phy from DT\n");
65 ret = generic_phy_init(&phy);
67 error("unable to initialize the sata phy\n");
71 ret = generic_phy_power_on(&phy);
73 error("unable to power on the sata phy\n");
77 if (priv->wrapper_base) {
78 u32 val = TI_SATA_IDLE_NO | TI_SATA_STANDBY_NO;
80 /* Enable SATA module, No Idle, No Standby */
81 writel(val, priv->wrapper_base + TI_SATA_SYSCONFIG);
84 return ahci_init(priv->base);
87 static const struct udevice_id dwc_ahci_ids[] = {
88 { .compatible = "snps,dwc-ahci" },
92 U_BOOT_DRIVER(dwc_ahci) = {
95 .of_match = dwc_ahci_ids,
96 .ofdata_to_platdata = dwc_ahci_ofdata_to_platdata,
97 .probe = dwc_ahci_probe,
98 .priv_auto_alloc_size = sizeof(struct dwc_ahci_priv),
99 .platdata_auto_alloc_size = sizeof(struct scsi_platdata),
100 .flags = DM_FLAG_ALLOC_PRIV_DMA,