Prepare v2023.10
[platform/kernel/u-boot.git] / drivers / ata / dwc_ahci.c
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 #ifdef CONFIG_ARCH_OMAP2PLUS
17 #include <asm/arch/sata.h>
18 #endif
19 #include <asm/io.h>
20 #include <generic-phy.h>
21
22 struct dwc_ahci_priv {
23         void *base;
24         void *wrapper_base;
25 };
26
27 static int dwc_ahci_bind(struct udevice *dev)
28 {
29         struct udevice *scsi_dev;
30
31         return ahci_bind_scsi(dev, &scsi_dev);
32 }
33
34 static int dwc_ahci_of_to_plat(struct udevice *dev)
35 {
36         struct dwc_ahci_priv *priv = dev_get_priv(dev);
37         fdt_addr_t addr;
38
39         priv->base = map_physmem(dev_read_addr(dev), sizeof(void *),
40                                  MAP_NOCACHE);
41
42         addr = devfdt_get_addr_index(dev, 1);
43         if (addr != FDT_ADDR_T_NONE) {
44                 priv->wrapper_base = map_physmem(addr, sizeof(void *),
45                                                  MAP_NOCACHE);
46         } else {
47                 priv->wrapper_base = NULL;
48         }
49
50         return 0;
51 }
52
53 static int dwc_ahci_probe(struct udevice *dev)
54 {
55         struct dwc_ahci_priv *priv = dev_get_priv(dev);
56         int ret;
57         struct phy phy;
58
59         ret = generic_phy_get_by_name(dev, "sata-phy", &phy);
60         if (ret) {
61                 pr_err("can't get the phy from DT\n");
62                 return ret;
63         }
64
65         ret = generic_phy_init(&phy);
66         if (ret) {
67                 pr_debug("unable to initialize the sata phy\n");
68                 return ret;
69         }
70
71         ret = generic_phy_power_on(&phy);
72         if (ret) {
73                 pr_debug("unable to power on the sata phy\n");
74                 return ret;
75         }
76
77 #ifdef CONFIG_ARCH_OMAP2PLUS
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 #endif
85
86         return ahci_probe_scsi(dev, (ulong)priv->base);
87 }
88
89 static const struct udevice_id dwc_ahci_ids[] = {
90         { .compatible = "snps,dwc-ahci" },
91         { }
92 };
93
94 U_BOOT_DRIVER(dwc_ahci) = {
95         .name   = "dwc_ahci",
96         .id     = UCLASS_AHCI,
97         .of_match = dwc_ahci_ids,
98         .bind   = dwc_ahci_bind,
99         .of_to_plat = dwc_ahci_of_to_plat,
100         .ops    = &scsi_ops,
101         .probe  = dwc_ahci_probe,
102         .priv_auto      = sizeof(struct dwc_ahci_priv),
103 };