xref: /openbmc/u-boot/drivers/ata/dwc_ahci.c (revision 699e831e)
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 struct dwc_ahci_priv {
22 	void *base;
23 	void *wrapper_base;
24 };
25 
26 static int dwc_ahci_bind(struct udevice *dev)
27 {
28 	struct udevice *scsi_dev;
29 
30 	return ahci_bind_scsi(dev, &scsi_dev);
31 }
32 
33 static int dwc_ahci_ofdata_to_platdata(struct udevice *dev)
34 {
35 	struct dwc_ahci_priv *priv = dev_get_priv(dev);
36 	fdt_addr_t addr;
37 
38 	priv->base = map_physmem(devfdt_get_addr(dev), sizeof(void *),
39 				 MAP_NOCACHE);
40 
41 	addr = devfdt_get_addr_index(dev, 1);
42 	if (addr != FDT_ADDR_T_NONE) {
43 		priv->wrapper_base = map_physmem(addr, sizeof(void *),
44 						 MAP_NOCACHE);
45 	} else {
46 		priv->wrapper_base = NULL;
47 	}
48 
49 	return 0;
50 }
51 
52 static int dwc_ahci_probe(struct udevice *dev)
53 {
54 	struct dwc_ahci_priv *priv = dev_get_priv(dev);
55 	int ret;
56 	struct phy phy;
57 
58 	ret = generic_phy_get_by_name(dev, "sata-phy", &phy);
59 	if (ret) {
60 		pr_err("can't get the phy from DT\n");
61 		return ret;
62 	}
63 
64 	ret = generic_phy_init(&phy);
65 	if (ret) {
66 		pr_err("unable to initialize the sata phy\n");
67 		return ret;
68 	}
69 
70 	ret = generic_phy_power_on(&phy);
71 	if (ret) {
72 		pr_err("unable to power on the sata phy\n");
73 		return ret;
74 	}
75 
76 	if (priv->wrapper_base) {
77 		u32 val = TI_SATA_IDLE_NO | TI_SATA_STANDBY_NO;
78 
79 		/* Enable SATA module, No Idle, No Standby */
80 		writel(val, priv->wrapper_base + TI_SATA_SYSCONFIG);
81 	}
82 
83 	return ahci_probe_scsi(dev, (ulong)priv->base);
84 }
85 
86 static const struct udevice_id dwc_ahci_ids[] = {
87 	{ .compatible = "snps,dwc-ahci" },
88 	{ }
89 };
90 
91 U_BOOT_DRIVER(dwc_ahci) = {
92 	.name	= "dwc_ahci",
93 	.id	= UCLASS_AHCI,
94 	.of_match = dwc_ahci_ids,
95 	.bind	= dwc_ahci_bind,
96 	.ofdata_to_platdata = dwc_ahci_ofdata_to_platdata,
97 	.ops	= &scsi_ops,
98 	.probe	= dwc_ahci_probe,
99 	.priv_auto_alloc_size = sizeof(struct dwc_ahci_priv),
100 };
101