]>
Commit | Line | Data |
---|---|---|
38bff327 FW |
1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | /* | |
3 | * MTK SATA platform driver | |
4 | * | |
a7e0ef15 | 5 | * Copyright (C) 2020 MediaTek Inc. |
38bff327 | 6 | * |
38bff327 | 7 | * Author: Ryder Lee <[email protected]> |
a7e0ef15 | 8 | * Author: Frank Wunderlich <[email protected]> |
38bff327 FW |
9 | */ |
10 | ||
11 | #include <common.h> | |
12 | #include <ahci.h> | |
401d1c4f | 13 | #include <asm/global_data.h> |
38bff327 FW |
14 | #include <asm/io.h> |
15 | #include <dm.h> | |
16 | #include <dm/of_access.h> | |
17 | #include <generic-phy.h> | |
18 | #include <linux/err.h> | |
19 | #include <regmap.h> | |
20 | #include <reset.h> | |
21 | #include <sata.h> | |
22 | #include <scsi.h> | |
23 | #include <syscon.h> | |
24 | ||
25 | #define SYS_CFG 0x14 | |
26 | #define SYS_CFG_SATA_MSK GENMASK(31, 30) | |
27 | #define SYS_CFG_SATA_EN BIT(31) | |
28 | ||
29 | struct mtk_ahci_priv { | |
30 | void *base; | |
31 | ||
32 | struct ahci_uc_priv ahci_priv; | |
33 | struct regmap *mode; | |
34 | struct reset_ctl_bulk rst_bulk; | |
35 | }; | |
36 | ||
37 | static int mtk_ahci_bind(struct udevice *dev) | |
38 | { | |
39 | struct udevice *scsi_dev; | |
40 | ||
41 | return ahci_bind_scsi(dev, &scsi_dev); | |
42 | } | |
43 | ||
d1998a9f | 44 | static int mtk_ahci_of_to_plat(struct udevice *dev) |
38bff327 FW |
45 | { |
46 | struct mtk_ahci_priv *priv = dev_get_priv(dev); | |
47 | ||
48 | priv->base = devfdt_remap_addr_index(dev, 0); | |
49 | ||
50 | return 0; | |
51 | } | |
52 | ||
53 | static int mtk_ahci_parse_property(struct ahci_uc_priv *hpriv, | |
54 | struct udevice *dev) | |
55 | { | |
56 | struct mtk_ahci_priv *plat = dev_get_priv(dev); | |
57 | const void *fdt = gd->fdt_blob; | |
58 | ||
59 | /* enable SATA function if needed */ | |
60 | if (fdt_get_property(fdt, dev_of_offset(dev), | |
61 | "mediatek,phy-mode", NULL)) { | |
62 | plat->mode = syscon_regmap_lookup_by_phandle(dev, | |
63 | "mediatek,phy-mode"); | |
64 | if (IS_ERR(plat->mode)) { | |
65 | dev_err(dev, "missing phy-mode phandle\n"); | |
66 | return PTR_ERR(plat->mode); | |
67 | } | |
68 | regmap_update_bits(plat->mode, SYS_CFG, | |
69 | SYS_CFG_SATA_MSK, SYS_CFG_SATA_EN); | |
70 | } | |
71 | ||
f10643cf SG |
72 | ofnode_read_u32(dev_ofnode(dev), "ports-implemented", |
73 | &hpriv->port_map); | |
38bff327 FW |
74 | return 0; |
75 | } | |
76 | ||
77 | static int mtk_ahci_probe(struct udevice *dev) | |
78 | { | |
79 | struct mtk_ahci_priv *priv = dev_get_priv(dev); | |
80 | int ret; | |
81 | struct phy phy; | |
82 | ||
83 | ret = mtk_ahci_parse_property(&priv->ahci_priv, dev); | |
84 | if (ret) | |
85 | return ret; | |
86 | ||
87 | ret = reset_get_bulk(dev, &priv->rst_bulk); | |
88 | if (!ret) { | |
89 | reset_assert_bulk(&priv->rst_bulk); | |
90 | reset_deassert_bulk(&priv->rst_bulk); | |
91 | } else { | |
92 | dev_err(dev, "Failed to get reset: %d\n", ret); | |
93 | } | |
94 | ||
95 | ret = generic_phy_get_by_name(dev, "sata-phy", &phy); | |
96 | if (ret) { | |
97 | pr_err("can't get the phy from DT\n"); | |
98 | return ret; | |
99 | } | |
100 | ||
101 | ret = generic_phy_init(&phy); | |
102 | if (ret) { | |
103 | pr_err("unable to initialize the sata phy\n"); | |
104 | return ret; | |
105 | } | |
106 | ||
107 | ret = generic_phy_power_on(&phy); | |
108 | if (ret) { | |
109 | pr_err("unable to power on the sata phy\n"); | |
110 | return ret; | |
111 | } | |
112 | ||
113 | return ahci_probe_scsi(dev, (ulong)priv->base); | |
114 | } | |
115 | ||
116 | static const struct udevice_id mtk_ahci_ids[] = { | |
117 | { .compatible = "mediatek,mtk-ahci" }, | |
118 | { } | |
119 | }; | |
120 | ||
121 | U_BOOT_DRIVER(mtk_ahci) = { | |
122 | .name = "mtk_ahci", | |
123 | .id = UCLASS_AHCI, | |
124 | .of_match = mtk_ahci_ids, | |
125 | .bind = mtk_ahci_bind, | |
d1998a9f | 126 | .of_to_plat = mtk_ahci_of_to_plat, |
38bff327 FW |
127 | .ops = &scsi_ops, |
128 | .probe = mtk_ahci_probe, | |
41575d8e | 129 | .priv_auto = sizeof(struct mtk_ahci_priv), |
38bff327 | 130 | }; |