Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 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> |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 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/arch/sata.h> |
| 17 | #include <asm/io.h> |
| 18 | #include <generic-phy.h> |
| 19 | |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 20 | struct dwc_ahci_priv { |
| 21 | void *base; |
| 22 | void *wrapper_base; |
| 23 | }; |
| 24 | |
Jean-Jacques Hiblot | 64563f5 | 2018-04-06 11:13:53 +0200 | [diff] [blame] | 25 | static int dwc_ahci_bind(struct udevice *dev) |
| 26 | { |
| 27 | struct udevice *scsi_dev; |
| 28 | |
| 29 | return ahci_bind_scsi(dev, &scsi_dev); |
| 30 | } |
| 31 | |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 32 | static int dwc_ahci_ofdata_to_platdata(struct udevice *dev) |
| 33 | { |
| 34 | struct dwc_ahci_priv *priv = dev_get_priv(dev); |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 35 | fdt_addr_t addr; |
| 36 | |
Masahiro Yamada | 2548493 | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 37 | priv->base = map_physmem(dev_read_addr(dev), sizeof(void *), |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 38 | MAP_NOCACHE); |
| 39 | |
Simon Glass | a821c4a | 2017-05-17 17:18:05 -0600 | [diff] [blame] | 40 | addr = devfdt_get_addr_index(dev, 1); |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 41 | if (addr != FDT_ADDR_T_NONE) { |
| 42 | priv->wrapper_base = map_physmem(addr, sizeof(void *), |
| 43 | MAP_NOCACHE); |
| 44 | } else { |
| 45 | priv->wrapper_base = NULL; |
| 46 | } |
| 47 | |
| 48 | return 0; |
| 49 | } |
| 50 | |
| 51 | static int dwc_ahci_probe(struct udevice *dev) |
| 52 | { |
| 53 | struct dwc_ahci_priv *priv = dev_get_priv(dev); |
| 54 | int ret; |
| 55 | struct phy phy; |
| 56 | |
| 57 | ret = generic_phy_get_by_name(dev, "sata-phy", &phy); |
| 58 | if (ret) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 59 | pr_err("can't get the phy from DT\n"); |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 60 | return ret; |
| 61 | } |
| 62 | |
| 63 | ret = generic_phy_init(&phy); |
| 64 | if (ret) { |
Patrick Delaunay | fc8ead1 | 2020-07-03 17:36:44 +0200 | [diff] [blame] | 65 | pr_debug("unable to initialize the sata phy\n"); |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 66 | return ret; |
| 67 | } |
| 68 | |
| 69 | ret = generic_phy_power_on(&phy); |
| 70 | if (ret) { |
Patrick Delaunay | fc8ead1 | 2020-07-03 17:36:44 +0200 | [diff] [blame] | 71 | pr_debug("unable to power on the sata phy\n"); |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 72 | return ret; |
| 73 | } |
| 74 | |
| 75 | if (priv->wrapper_base) { |
| 76 | u32 val = TI_SATA_IDLE_NO | TI_SATA_STANDBY_NO; |
| 77 | |
| 78 | /* Enable SATA module, No Idle, No Standby */ |
| 79 | writel(val, priv->wrapper_base + TI_SATA_SYSCONFIG); |
| 80 | } |
| 81 | |
Jean-Jacques Hiblot | 64563f5 | 2018-04-06 11:13:53 +0200 | [diff] [blame] | 82 | return ahci_probe_scsi(dev, (ulong)priv->base); |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | static const struct udevice_id dwc_ahci_ids[] = { |
| 86 | { .compatible = "snps,dwc-ahci" }, |
| 87 | { } |
| 88 | }; |
| 89 | |
| 90 | U_BOOT_DRIVER(dwc_ahci) = { |
| 91 | .name = "dwc_ahci", |
Jean-Jacques Hiblot | 64563f5 | 2018-04-06 11:13:53 +0200 | [diff] [blame] | 92 | .id = UCLASS_AHCI, |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 93 | .of_match = dwc_ahci_ids, |
Jean-Jacques Hiblot | 64563f5 | 2018-04-06 11:13:53 +0200 | [diff] [blame] | 94 | .bind = dwc_ahci_bind, |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 95 | .ofdata_to_platdata = dwc_ahci_ofdata_to_platdata, |
Simon Glass | f6ab5a9 | 2017-06-14 21:28:43 -0600 | [diff] [blame] | 96 | .ops = &scsi_ops, |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 97 | .probe = dwc_ahci_probe, |
| 98 | .priv_auto_alloc_size = sizeof(struct dwc_ahci_priv), |
Jean-Jacques Hiblot | 02a4b42 | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 99 | }; |