blob: bb45214fc243da9a2d53129dcbfa5e2c84cbcbf4 [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
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020021struct dwc_ahci_priv {
22 void *base;
23 void *wrapper_base;
24};
25
Jean-Jacques Hiblotd05ef522018-04-06 11:13:53 +020026static int dwc_ahci_bind(struct udevice *dev)
27{
28 struct udevice *scsi_dev;
29
30 return ahci_bind_scsi(dev, &scsi_dev);
31}
32
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020033static int dwc_ahci_ofdata_to_platdata(struct udevice *dev)
34{
35 struct dwc_ahci_priv *priv = dev_get_priv(dev);
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020036 fdt_addr_t addr;
37
Simon Glassba1dea42017-05-17 17:18:05 -060038 priv->base = map_physmem(devfdt_get_addr(dev), sizeof(void *),
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020039 MAP_NOCACHE);
40
Simon Glassba1dea42017-05-17 17:18:05 -060041 addr = devfdt_get_addr_index(dev, 1);
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020042 if (addr != FDT_ADDR_T_NONE) {
43 priv->wrapper_base = map_physmem(addr, sizeof(void *),
44 MAP_NOCACHE);
45 } else {
46 priv->wrapper_base = NULL;
47 }
48
49 return 0;
50}
51
52static int dwc_ahci_probe(struct udevice *dev)
53{
54 struct dwc_ahci_priv *priv = dev_get_priv(dev);
55 int ret;
56 struct phy phy;
57
58 ret = generic_phy_get_by_name(dev, "sata-phy", &phy);
59 if (ret) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090060 pr_err("can't get the phy from DT\n");
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020061 return ret;
62 }
63
64 ret = generic_phy_init(&phy);
65 if (ret) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090066 pr_err("unable to initialize the sata phy\n");
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020067 return ret;
68 }
69
70 ret = generic_phy_power_on(&phy);
71 if (ret) {
Masahiro Yamada81e10422017-09-16 14:10:41 +090072 pr_err("unable to power on the sata phy\n");
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020073 return ret;
74 }
75
76 if (priv->wrapper_base) {
77 u32 val = TI_SATA_IDLE_NO | TI_SATA_STANDBY_NO;
78
79 /* Enable SATA module, No Idle, No Standby */
80 writel(val, priv->wrapper_base + TI_SATA_SYSCONFIG);
81 }
82
Jean-Jacques Hiblotd05ef522018-04-06 11:13:53 +020083 return ahci_probe_scsi(dev, (ulong)priv->base);
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020084}
85
86static const struct udevice_id dwc_ahci_ids[] = {
87 { .compatible = "snps,dwc-ahci" },
88 { }
89};
90
91U_BOOT_DRIVER(dwc_ahci) = {
92 .name = "dwc_ahci",
Jean-Jacques Hiblotd05ef522018-04-06 11:13:53 +020093 .id = UCLASS_AHCI,
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020094 .of_match = dwc_ahci_ids,
Jean-Jacques Hiblotd05ef522018-04-06 11:13:53 +020095 .bind = dwc_ahci_bind,
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020096 .ofdata_to_platdata = dwc_ahci_ofdata_to_platdata,
Simon Glassc4dfa892017-06-14 21:28:43 -060097 .ops = &scsi_ops,
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +020098 .probe = dwc_ahci_probe,
99 .priv_auto_alloc_size = sizeof(struct dwc_ahci_priv),
Jean-Jacques Hiblotd7cb71b2017-04-24 11:51:31 +0200100};