blob: f6147989b1c811b01d474c325d6f735428297bbe [file] [log] [blame]
Jean-Jacques Hiblot02a4b422017-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 Glass1dc64f62017-06-14 21:28:31 -060031 struct scsi_platdata *plat = dev_get_uclass_platdata(dev);
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +020032 fdt_addr_t addr;
33
Simon Glassda409cc2017-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 Hiblot02a4b422017-04-24 11:51:31 +020037 "max-lun", CONFIG_SYS_SCSI_MAX_LUN);
38
Simon Glassa821c4a2017-05-17 17:18:05 -060039 priv->base = map_physmem(devfdt_get_addr(dev), sizeof(void *),
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +020040 MAP_NOCACHE);
41
Simon Glassa821c4a2017-05-17 17:18:05 -060042 addr = devfdt_get_addr_index(dev, 1);
Jean-Jacques Hiblot02a4b422017-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) {
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
Simon Glass4279efc2017-06-14 21:28:38 -060084 ret = ahci_init_dm(dev, priv->base);
Simon Glass7cf1afc2017-06-14 21:28:37 -060085 if (ret)
86 return ret;
87
88 return achi_start_ports_dm(dev);
Jean-Jacques Hiblot02a4b422017-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 Glassf6ab5a92017-06-14 21:28:43 -0600101 .ops = &scsi_ops,
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +0200102 .probe = dwc_ahci_probe,
103 .priv_auto_alloc_size = sizeof(struct dwc_ahci_priv),
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +0200104 .flags = DM_FLAG_ALLOC_PRIV_DMA,
105};