Jean-Jacques Hiblot | d7cb71b | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 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 | DECLARE_GLOBAL_DATA_PTR; |
| 22 | |
| 23 | struct dwc_ahci_priv { |
| 24 | void *base; |
| 25 | void *wrapper_base; |
| 26 | }; |
| 27 | |
| 28 | static int dwc_ahci_ofdata_to_platdata(struct udevice *dev) |
| 29 | { |
| 30 | struct dwc_ahci_priv *priv = dev_get_priv(dev); |
| 31 | struct scsi_platdata *plat = dev_get_platdata(dev); |
| 32 | fdt_addr_t addr; |
| 33 | |
| 34 | plat->max_id = fdtdec_get_uint(gd->fdt_blob, dev->of_offset, "max-id", |
| 35 | CONFIG_SYS_SCSI_MAX_SCSI_ID); |
| 36 | plat->max_lun = fdtdec_get_uint(gd->fdt_blob, dev->of_offset, |
| 37 | "max-lun", CONFIG_SYS_SCSI_MAX_LUN); |
| 38 | |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame^] | 39 | priv->base = map_physmem(devfdt_get_addr(dev), sizeof(void *), |
Jean-Jacques Hiblot | d7cb71b | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 40 | MAP_NOCACHE); |
| 41 | |
Simon Glass | ba1dea4 | 2017-05-17 17:18:05 -0600 | [diff] [blame^] | 42 | addr = devfdt_get_addr_index(dev, 1); |
Jean-Jacques Hiblot | d7cb71b | 2017-04-24 11:51:31 +0200 | [diff] [blame] | 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 | error("can't get the phy from DT\n"); |
| 62 | return ret; |
| 63 | } |
| 64 | |
| 65 | ret = generic_phy_init(&phy); |
| 66 | if (ret) { |
| 67 | error("unable to initialize the sata phy\n"); |
| 68 | return ret; |
| 69 | } |
| 70 | |
| 71 | ret = generic_phy_power_on(&phy); |
| 72 | if (ret) { |
| 73 | error("unable to power on the sata phy\n"); |
| 74 | return ret; |
| 75 | } |
| 76 | |
| 77 | if (priv->wrapper_base) { |
| 78 | u32 val = TI_SATA_IDLE_NO | TI_SATA_STANDBY_NO; |
| 79 | |
| 80 | /* Enable SATA module, No Idle, No Standby */ |
| 81 | writel(val, priv->wrapper_base + TI_SATA_SYSCONFIG); |
| 82 | } |
| 83 | |
| 84 | return ahci_init(priv->base); |
| 85 | } |
| 86 | |
| 87 | static const struct udevice_id dwc_ahci_ids[] = { |
| 88 | { .compatible = "snps,dwc-ahci" }, |
| 89 | { } |
| 90 | }; |
| 91 | |
| 92 | U_BOOT_DRIVER(dwc_ahci) = { |
| 93 | .name = "dwc_ahci", |
| 94 | .id = UCLASS_SCSI, |
| 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, |
| 101 | }; |