blob: 029b7784f64c351f0e55682d4815e91df5c06b1a [file] [log] [blame]
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +02001/*
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
21DECLARE_GLOBAL_DATA_PTR;
22
23struct dwc_ahci_priv {
24 void *base;
25 void *wrapper_base;
26};
27
28static int dwc_ahci_ofdata_to_platdata(struct udevice *dev)
29{
30 struct dwc_ahci_priv *priv = dev_get_priv(dev);
Simon Glassb08fbff2017-06-14 21:28:31 -060031 struct scsi_platdata *plat = dev_get_uclass_platdata(dev);
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020032 fdt_addr_t addr;
33
Simon Glass7a494432017-05-17 17:18:09 -060034 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),
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020037 "max-lun", CONFIG_SYS_SCSI_MAX_LUN);
38
Simon Glassba1dea42017-05-17 17:18:05 -060039 priv->base = map_physmem(devfdt_get_addr(dev), sizeof(void *),
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020040 MAP_NOCACHE);
41
Simon Glassba1dea42017-05-17 17:18:05 -060042 addr = devfdt_get_addr_index(dev, 1);
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020043 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
53static 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) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090061 pr_err("can't get the phy from DT\n");
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020062 return ret;
63 }
64
65 ret = generic_phy_init(&phy);
66 if (ret) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090067 pr_err("unable to initialize the sata phy\n");
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020068 return ret;
69 }
70
71 ret = generic_phy_power_on(&phy);
72 if (ret) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090073 pr_err("unable to power on the sata phy\n");
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020074 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
Simon Glasscf01b5b2017-06-14 21:28:38 -060084 ret = ahci_init_dm(dev, priv->base);
Simon Glass84fac542017-06-14 21:28:37 -060085 if (ret)
86 return ret;
87
Michal Simek2d72d3c2017-11-02 15:53:56 +010088 return ahci_start_ports_dm(dev);
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020089}
90
91static const struct udevice_id dwc_ahci_ids[] = {
92 { .compatible = "snps,dwc-ahci" },
93 { }
94};
95
96U_BOOT_DRIVER(dwc_ahci) = {
97 .name = "dwc_ahci",
98 .id = UCLASS_SCSI,
99 .of_match = dwc_ahci_ids,
100 .ofdata_to_platdata = dwc_ahci_ofdata_to_platdata,
Simon Glassc4dfa892017-06-14 21:28:43 -0600101 .ops = &scsi_ops,
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +0200102 .probe = dwc_ahci_probe,
103 .priv_auto_alloc_size = sizeof(struct dwc_ahci_priv),
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +0200104 .flags = DM_FLAG_ALLOC_PRIV_DMA,
105};