blob: 6c7371e3eddde133a504e735cb6c81f2fc1fc935 [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
Jean-Jacques Hiblot64563f52018-04-06 11:13:53 +020028static int dwc_ahci_bind(struct udevice *dev)
29{
30 struct udevice *scsi_dev;
31
32 return ahci_bind_scsi(dev, &scsi_dev);
33}
34
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +020035static int dwc_ahci_ofdata_to_platdata(struct udevice *dev)
36{
37 struct dwc_ahci_priv *priv = dev_get_priv(dev);
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +020038 fdt_addr_t addr;
39
Simon Glassa821c4a2017-05-17 17:18:05 -060040 priv->base = map_physmem(devfdt_get_addr(dev), sizeof(void *),
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +020041 MAP_NOCACHE);
42
Simon Glassa821c4a2017-05-17 17:18:05 -060043 addr = devfdt_get_addr_index(dev, 1);
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +020044 if (addr != FDT_ADDR_T_NONE) {
45 priv->wrapper_base = map_physmem(addr, sizeof(void *),
46 MAP_NOCACHE);
47 } else {
48 priv->wrapper_base = NULL;
49 }
50
51 return 0;
52}
53
54static int dwc_ahci_probe(struct udevice *dev)
55{
56 struct dwc_ahci_priv *priv = dev_get_priv(dev);
57 int ret;
58 struct phy phy;
59
60 ret = generic_phy_get_by_name(dev, "sata-phy", &phy);
61 if (ret) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090062 pr_err("can't get the phy from DT\n");
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +020063 return ret;
64 }
65
66 ret = generic_phy_init(&phy);
67 if (ret) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090068 pr_err("unable to initialize the sata phy\n");
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +020069 return ret;
70 }
71
72 ret = generic_phy_power_on(&phy);
73 if (ret) {
Masahiro Yamada9b643e32017-09-16 14:10:41 +090074 pr_err("unable to power on the sata phy\n");
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +020075 return ret;
76 }
77
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
Jean-Jacques Hiblot64563f52018-04-06 11:13:53 +020085 return ahci_probe_scsi(dev, (ulong)priv->base);
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +020086}
87
88static const struct udevice_id dwc_ahci_ids[] = {
89 { .compatible = "snps,dwc-ahci" },
90 { }
91};
92
93U_BOOT_DRIVER(dwc_ahci) = {
94 .name = "dwc_ahci",
Jean-Jacques Hiblot64563f52018-04-06 11:13:53 +020095 .id = UCLASS_AHCI,
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +020096 .of_match = dwc_ahci_ids,
Jean-Jacques Hiblot64563f52018-04-06 11:13:53 +020097 .bind = dwc_ahci_bind,
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +020098 .ofdata_to_platdata = dwc_ahci_ofdata_to_platdata,
Simon Glassf6ab5a92017-06-14 21:28:43 -060099 .ops = &scsi_ops,
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +0200100 .probe = dwc_ahci_probe,
101 .priv_auto_alloc_size = sizeof(struct dwc_ahci_priv),
Jean-Jacques Hiblot02a4b422017-04-24 11:51:31 +0200102};