diff options
author | Ryder Lee <ryder.lee@mediatek.com> | 2017-08-17 21:13:07 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2017-08-28 13:54:42 -0400 |
commit | 47269605aa3bc191bdce6d2f6dec2e73d56b9c3b (patch) | |
tree | f8405199044e8bae3066724c46d492d1c486b51c /drivers | |
parent | be1dc3fb290beb394551b8cee45d03e6375b28e6 (diff) |
ata: mediatek: add support for MediaTek SATA controller
This adds support the AHCI-compliant Serial ATA controller present
on MediaTek SoCs.
Signed-off-by: Ryder Lee <ryder.lee@mediatek.com>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Tejun Heo <tj@kernel.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/ata/Kconfig | 10 | ||||
-rw-r--r-- | drivers/ata/Makefile | 1 | ||||
-rw-r--r-- | drivers/ata/ahci_mtk.c | 196 |
3 files changed, 207 insertions, 0 deletions
diff --git a/drivers/ata/Kconfig b/drivers/ata/Kconfig index 948fc86980a1..7d3eb47fcdab 100644 --- a/drivers/ata/Kconfig +++ b/drivers/ata/Kconfig | |||
@@ -153,6 +153,16 @@ config AHCI_CEVA | |||
153 | 153 | ||
154 | If unsure, say N. | 154 | If unsure, say N. |
155 | 155 | ||
156 | config AHCI_MTK | ||
157 | tristate "MediaTek AHCI SATA support" | ||
158 | depends on ARCH_MEDIATEK | ||
159 | select MFD_SYSCON | ||
160 | help | ||
161 | This option enables support for the MediaTek SoC's | ||
162 | onboard AHCI SATA controller. | ||
163 | |||
164 | If unsure, say N. | ||
165 | |||
156 | config AHCI_MVEBU | 166 | config AHCI_MVEBU |
157 | tristate "Marvell EBU AHCI SATA support" | 167 | tristate "Marvell EBU AHCI SATA support" |
158 | depends on ARCH_MVEBU | 168 | depends on ARCH_MVEBU |
diff --git a/drivers/ata/Makefile b/drivers/ata/Makefile index a26ef5a93919..ff9cd2e37458 100644 --- a/drivers/ata/Makefile +++ b/drivers/ata/Makefile | |||
@@ -17,6 +17,7 @@ obj-$(CONFIG_AHCI_CEVA) += ahci_ceva.o libahci.o libahci_platform.o | |||
17 | obj-$(CONFIG_AHCI_DA850) += ahci_da850.o libahci.o libahci_platform.o | 17 | obj-$(CONFIG_AHCI_DA850) += ahci_da850.o libahci.o libahci_platform.o |
18 | obj-$(CONFIG_AHCI_DM816) += ahci_dm816.o libahci.o libahci_platform.o | 18 | obj-$(CONFIG_AHCI_DM816) += ahci_dm816.o libahci.o libahci_platform.o |
19 | obj-$(CONFIG_AHCI_IMX) += ahci_imx.o libahci.o libahci_platform.o | 19 | obj-$(CONFIG_AHCI_IMX) += ahci_imx.o libahci.o libahci_platform.o |
20 | obj-$(CONFIG_AHCI_MTK) += ahci_mtk.o libahci.o libahci_platform.o | ||
20 | obj-$(CONFIG_AHCI_MVEBU) += ahci_mvebu.o libahci.o libahci_platform.o | 21 | obj-$(CONFIG_AHCI_MVEBU) += ahci_mvebu.o libahci.o libahci_platform.o |
21 | obj-$(CONFIG_AHCI_OCTEON) += ahci_octeon.o | 22 | obj-$(CONFIG_AHCI_OCTEON) += ahci_octeon.o |
22 | obj-$(CONFIG_AHCI_SUNXI) += ahci_sunxi.o libahci.o libahci_platform.o | 23 | obj-$(CONFIG_AHCI_SUNXI) += ahci_sunxi.o libahci.o libahci_platform.o |
diff --git a/drivers/ata/ahci_mtk.c b/drivers/ata/ahci_mtk.c new file mode 100644 index 000000000000..80854f71559a --- /dev/null +++ b/drivers/ata/ahci_mtk.c | |||
@@ -0,0 +1,196 @@ | |||
1 | /* | ||
2 | * MeidaTek AHCI SATA driver | ||
3 | * | ||
4 | * Copyright (c) 2017 MediaTek Inc. | ||
5 | * Author: Ryder Lee <ryder.lee@mediatek.com> | ||
6 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | ||
8 | * it under the terms of the GNU General Public License version 2 as | ||
9 | * published by the Free Software Foundation. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | */ | ||
16 | |||
17 | #include <linux/ahci_platform.h> | ||
18 | #include <linux/kernel.h> | ||
19 | #include <linux/libata.h> | ||
20 | #include <linux/mfd/syscon.h> | ||
21 | #include <linux/module.h> | ||
22 | #include <linux/platform_device.h> | ||
23 | #include <linux/pm.h> | ||
24 | #include <linux/regmap.h> | ||
25 | #include <linux/reset.h> | ||
26 | #include "ahci.h" | ||
27 | |||
28 | #define DRV_NAME "ahci" | ||
29 | |||
30 | #define SYS_CFG 0x14 | ||
31 | #define SYS_CFG_SATA_MSK GENMASK(31, 30) | ||
32 | #define SYS_CFG_SATA_EN BIT(31) | ||
33 | |||
34 | struct mtk_ahci_plat { | ||
35 | struct regmap *mode; | ||
36 | struct reset_control *axi_rst; | ||
37 | struct reset_control *sw_rst; | ||
38 | struct reset_control *reg_rst; | ||
39 | }; | ||
40 | |||
41 | static const struct ata_port_info ahci_port_info = { | ||
42 | .flags = AHCI_FLAG_COMMON, | ||
43 | .pio_mask = ATA_PIO4, | ||
44 | .udma_mask = ATA_UDMA6, | ||
45 | .port_ops = &ahci_platform_ops, | ||
46 | }; | ||
47 | |||
48 | static struct scsi_host_template ahci_platform_sht = { | ||
49 | AHCI_SHT(DRV_NAME), | ||
50 | }; | ||
51 | |||
52 | static int mtk_ahci_platform_resets(struct ahci_host_priv *hpriv, | ||
53 | struct device *dev) | ||
54 | { | ||
55 | struct mtk_ahci_plat *plat = hpriv->plat_data; | ||
56 | int err; | ||
57 | |||
58 | /* reset AXI bus and PHY part */ | ||
59 | plat->axi_rst = devm_reset_control_get_optional_exclusive(dev, "axi"); | ||
60 | if (PTR_ERR(plat->axi_rst) == -EPROBE_DEFER) | ||
61 | return PTR_ERR(plat->axi_rst); | ||
62 | |||
63 | plat->sw_rst = devm_reset_control_get_optional_exclusive(dev, "sw"); | ||
64 | if (PTR_ERR(plat->sw_rst) == -EPROBE_DEFER) | ||
65 | return PTR_ERR(plat->sw_rst); | ||
66 | |||
67 | plat->reg_rst = devm_reset_control_get_optional_exclusive(dev, "reg"); | ||
68 | if (PTR_ERR(plat->reg_rst) == -EPROBE_DEFER) | ||
69 | return PTR_ERR(plat->reg_rst); | ||
70 | |||
71 | err = reset_control_assert(plat->axi_rst); | ||
72 | if (err) { | ||
73 | dev_err(dev, "failed to assert AXI bus\n"); | ||
74 | return err; | ||
75 | } | ||
76 | |||
77 | err = reset_control_assert(plat->sw_rst); | ||
78 | if (err) { | ||
79 | dev_err(dev, "failed to assert PHY digital part\n"); | ||
80 | return err; | ||
81 | } | ||
82 | |||
83 | err = reset_control_assert(plat->reg_rst); | ||
84 | if (err) { | ||
85 | dev_err(dev, "failed to assert PHY register part\n"); | ||
86 | return err; | ||
87 | } | ||
88 | |||
89 | err = reset_control_deassert(plat->reg_rst); | ||
90 | if (err) { | ||
91 | dev_err(dev, "failed to deassert PHY register part\n"); | ||
92 | return err; | ||
93 | } | ||
94 | |||
95 | err = reset_control_deassert(plat->sw_rst); | ||
96 | if (err) { | ||
97 | dev_err(dev, "failed to deassert PHY digital part\n"); | ||
98 | return err; | ||
99 | } | ||
100 | |||
101 | err = reset_control_deassert(plat->axi_rst); | ||
102 | if (err) { | ||
103 | dev_err(dev, "failed to deassert AXI bus\n"); | ||
104 | return err; | ||
105 | } | ||
106 | |||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | static int mtk_ahci_parse_property(struct ahci_host_priv *hpriv, | ||
111 | struct device *dev) | ||
112 | { | ||
113 | struct mtk_ahci_plat *plat = hpriv->plat_data; | ||
114 | struct device_node *np = dev->of_node; | ||
115 | |||
116 | /* enable SATA function if needed */ | ||
117 | if (of_find_property(np, "mediatek,phy-mode", NULL)) { | ||
118 | plat->mode = syscon_regmap_lookup_by_phandle( | ||
119 | np, "mediatek,phy-mode"); | ||
120 | if (IS_ERR(plat->mode)) { | ||
121 | dev_err(dev, "missing phy-mode phandle\n"); | ||
122 | return PTR_ERR(plat->mode); | ||
123 | } | ||
124 | |||
125 | regmap_update_bits(plat->mode, SYS_CFG, SYS_CFG_SATA_MSK, | ||
126 | SYS_CFG_SATA_EN); | ||
127 | } | ||
128 | |||
129 | of_property_read_u32(np, "ports-implemented", &hpriv->force_port_map); | ||
130 | |||
131 | return 0; | ||
132 | } | ||
133 | |||
134 | static int mtk_ahci_probe(struct platform_device *pdev) | ||
135 | { | ||
136 | struct device *dev = &pdev->dev; | ||
137 | struct mtk_ahci_plat *plat; | ||
138 | struct ahci_host_priv *hpriv; | ||
139 | int err; | ||
140 | |||
141 | plat = devm_kzalloc(dev, sizeof(*plat), GFP_KERNEL); | ||
142 | if (!plat) | ||
143 | return -ENOMEM; | ||
144 | |||
145 | hpriv = ahci_platform_get_resources(pdev); | ||
146 | if (IS_ERR(hpriv)) | ||
147 | return PTR_ERR(hpriv); | ||
148 | |||
149 | hpriv->plat_data = plat; | ||
150 | |||
151 | err = mtk_ahci_parse_property(hpriv, dev); | ||
152 | if (err) | ||
153 | return err; | ||
154 | |||
155 | err = mtk_ahci_platform_resets(hpriv, dev); | ||
156 | if (err) | ||
157 | return err; | ||
158 | |||
159 | err = ahci_platform_enable_resources(hpriv); | ||
160 | if (err) | ||
161 | return err; | ||
162 | |||
163 | err = ahci_platform_init_host(pdev, hpriv, &ahci_port_info, | ||
164 | &ahci_platform_sht); | ||
165 | if (err) | ||
166 | goto disable_resources; | ||
167 | |||
168 | return 0; | ||
169 | |||
170 | disable_resources: | ||
171 | ahci_platform_disable_resources(hpriv); | ||
172 | return err; | ||
173 | } | ||
174 | |||
175 | static SIMPLE_DEV_PM_OPS(ahci_pm_ops, ahci_platform_suspend, | ||
176 | ahci_platform_resume); | ||
177 | |||
178 | static const struct of_device_id ahci_of_match[] = { | ||
179 | { .compatible = "mediatek,mtk-ahci", }, | ||
180 | {}, | ||
181 | }; | ||
182 | MODULE_DEVICE_TABLE(of, ahci_of_match); | ||
183 | |||
184 | static struct platform_driver mtk_ahci_driver = { | ||
185 | .probe = mtk_ahci_probe, | ||
186 | .remove = ata_platform_remove_one, | ||
187 | .driver = { | ||
188 | .name = DRV_NAME, | ||
189 | .of_match_table = ahci_of_match, | ||
190 | .pm = &ahci_pm_ops, | ||
191 | }, | ||
192 | }; | ||
193 | module_platform_driver(mtk_ahci_driver); | ||
194 | |||
195 | MODULE_DESCRIPTION("MeidaTek SATA AHCI Driver"); | ||
196 | MODULE_LICENSE("GPL v2"); | ||