1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/ahci_platform.h>
21#include <linux/kernel.h>
22#include <linux/libata.h>
23#include <linux/module.h>
24#include <linux/of_device.h>
25#include <linux/platform_device.h>
26#include "ahci.h"
27
28
29#define AHCI_VEND_PCFG 0xA4
30#define AHCI_VEND_PPCFG 0xA8
31#define AHCI_VEND_PP2C 0xAC
32#define AHCI_VEND_PP3C 0xB0
33#define AHCI_VEND_PP4C 0xB4
34#define AHCI_VEND_PP5C 0xB8
35#define AHCI_VEND_AXICC 0xBC
36#define AHCI_VEND_PAXIC 0xC0
37#define AHCI_VEND_PTC 0xC8
38
39
40#define PAXIC_ADBW_BW64 0x1
41#define PAXIC_MAWIDD (1 << 8)
42#define PAXIC_MARIDD (1 << 16)
43#define PAXIC_OTL (0x4 << 20)
44
45
46#define AXICC_ARCA_VAL (0xF << 0)
47#define AXICC_ARCF_VAL (0xF << 4)
48#define AXICC_ARCH_VAL (0xF << 8)
49#define AXICC_ARCP_VAL (0xF << 12)
50#define AXICC_AWCFD_VAL (0xF << 16)
51#define AXICC_AWCD_VAL (0xF << 20)
52#define AXICC_AWCF_VAL (0xF << 24)
53
54#define PCFG_TPSS_VAL (0x32 << 16)
55#define PCFG_TPRS_VAL (0x2 << 12)
56#define PCFG_PAD_VAL 0x2
57
58#define PPCFG_TTA 0x1FFFE
59#define PPCFG_PSSO_EN (1 << 28)
60#define PPCFG_PSS_EN (1 << 29)
61#define PPCFG_ESDF_EN (1 << 31)
62
63#define PP5C_RIT 0x60216
64#define PP5C_RCT (0x7f0 << 20)
65
66#define PTC_RX_WM_VAL 0x40
67#define PTC_RSVD (1 << 27)
68
69#define PORT0_BASE 0x100
70#define PORT1_BASE 0x180
71
72
73#define PORT_SCTL_SPD_GEN3 (0x3 << 4)
74#define PORT_SCTL_SPD_GEN2 (0x2 << 4)
75#define PORT_SCTL_SPD_GEN1 (0x1 << 4)
76#define PORT_SCTL_IPM (0x3 << 8)
77
78#define PORT_BASE 0x100
79#define PORT_OFFSET 0x80
80#define NR_PORTS 2
81#define DRV_NAME "ahci-ceva"
82#define CEVA_FLAG_BROKEN_GEN2 1
83
84static unsigned int rx_watermark = PTC_RX_WM_VAL;
85module_param(rx_watermark, uint, 0);
86MODULE_PARM_DESC(rx_watermark, "RxWaterMark value (0 - 0x80)");
87
88struct ceva_ahci_priv {
89 struct platform_device *ahci_pdev;
90
91 u32 pp2c[NR_PORTS];
92 u32 pp3c[NR_PORTS];
93 u32 pp4c[NR_PORTS];
94 u32 pp5c[NR_PORTS];
95
96 u32 axicc;
97 bool is_cci_enabled;
98 int flags;
99};
100
101static unsigned int ceva_ahci_read_id(struct ata_device *dev,
102 struct ata_taskfile *tf, u16 *id)
103{
104 u32 err_mask;
105
106 err_mask = ata_do_dev_read_id(dev, tf, id);
107 if (err_mask)
108 return err_mask;
109
110
111
112
113 id[ATA_ID_FEATURE_SUPP] &= cpu_to_le16(~(1 << 8));
114
115 return 0;
116}
117
118static struct ata_port_operations ahci_ceva_ops = {
119 .inherits = &ahci_platform_ops,
120 .read_id = ceva_ahci_read_id,
121};
122
123static const struct ata_port_info ahci_ceva_port_info = {
124 .flags = AHCI_FLAG_COMMON,
125 .pio_mask = ATA_PIO4,
126 .udma_mask = ATA_UDMA6,
127 .port_ops = &ahci_ceva_ops,
128};
129
130static void ahci_ceva_setup(struct ahci_host_priv *hpriv)
131{
132 void __iomem *mmio = hpriv->mmio;
133 struct ceva_ahci_priv *cevapriv = hpriv->plat_data;
134 u32 tmp;
135 int i;
136
137
138 tmp = readl(mmio + HOST_CTL);
139 tmp |= HOST_AHCI_EN;
140 writel(tmp, mmio + HOST_CTL);
141
142 for (i = 0; i < NR_PORTS; i++) {
143
144 tmp = PCFG_TPSS_VAL | PCFG_TPRS_VAL | (PCFG_PAD_VAL + i);
145 writel(tmp, mmio + AHCI_VEND_PCFG);
146
147
148
149
150
151
152 tmp = PAXIC_ADBW_BW64 | PAXIC_MAWIDD | PAXIC_MARIDD | PAXIC_OTL;
153 writel(tmp, mmio + AHCI_VEND_PAXIC);
154
155
156 if (cevapriv->is_cci_enabled) {
157 tmp = readl(mmio + AHCI_VEND_AXICC);
158 tmp |= AXICC_ARCA_VAL | AXICC_ARCF_VAL |
159 AXICC_ARCH_VAL | AXICC_ARCP_VAL |
160 AXICC_AWCFD_VAL | AXICC_AWCD_VAL |
161 AXICC_AWCF_VAL;
162 writel(tmp, mmio + AHCI_VEND_AXICC);
163 }
164
165
166 tmp = PPCFG_TTA | PPCFG_PSS_EN | PPCFG_ESDF_EN;
167 writel(tmp, mmio + AHCI_VEND_PPCFG);
168
169
170 writel(cevapriv->pp2c[i], mmio + AHCI_VEND_PP2C);
171
172
173 writel(cevapriv->pp3c[i], mmio + AHCI_VEND_PP3C);
174
175
176 writel(cevapriv->pp4c[i], mmio + AHCI_VEND_PP4C);
177
178
179 writel(cevapriv->pp5c[i], mmio + AHCI_VEND_PP5C);
180
181
182 tmp = rx_watermark | PTC_RSVD;
183 writel(tmp, mmio + AHCI_VEND_PTC);
184
185
186 tmp = PORT_SCTL_SPD_GEN3 | PORT_SCTL_IPM;
187 if (cevapriv->flags & CEVA_FLAG_BROKEN_GEN2)
188 tmp = PORT_SCTL_SPD_GEN1 | PORT_SCTL_IPM;
189 writel(tmp, mmio + PORT_SCR_CTL + PORT_BASE + PORT_OFFSET * i);
190 }
191}
192
193static struct scsi_host_template ahci_platform_sht = {
194 AHCI_SHT(DRV_NAME),
195};
196
197static int ceva_ahci_probe(struct platform_device *pdev)
198{
199 struct device_node *np = pdev->dev.of_node;
200 struct device *dev = &pdev->dev;
201 struct ahci_host_priv *hpriv;
202 struct ceva_ahci_priv *cevapriv;
203 enum dev_dma_attr attr;
204 int rc;
205
206 cevapriv = devm_kzalloc(dev, sizeof(*cevapriv), GFP_KERNEL);
207 if (!cevapriv)
208 return -ENOMEM;
209
210 cevapriv->ahci_pdev = pdev;
211
212 hpriv = ahci_platform_get_resources(pdev);
213 if (IS_ERR(hpriv))
214 return PTR_ERR(hpriv);
215
216 rc = ahci_platform_enable_resources(hpriv);
217 if (rc)
218 return rc;
219
220 if (of_property_read_bool(np, "ceva,broken-gen2"))
221 cevapriv->flags = CEVA_FLAG_BROKEN_GEN2;
222
223
224 if (of_property_read_u8_array(np, "ceva,p0-cominit-params",
225 (u8 *)&cevapriv->pp2c[0], 4) < 0) {
226 dev_warn(dev, "ceva,p0-cominit-params property not defined\n");
227 return -EINVAL;
228 }
229
230 if (of_property_read_u8_array(np, "ceva,p1-cominit-params",
231 (u8 *)&cevapriv->pp2c[1], 4) < 0) {
232 dev_warn(dev, "ceva,p1-cominit-params property not defined\n");
233 return -EINVAL;
234 }
235
236
237 if (of_property_read_u8_array(np, "ceva,p0-comwake-params",
238 (u8 *)&cevapriv->pp3c[0], 4) < 0) {
239 dev_warn(dev, "ceva,p0-comwake-params property not defined\n");
240 return -EINVAL;
241 }
242
243 if (of_property_read_u8_array(np, "ceva,p1-comwake-params",
244 (u8 *)&cevapriv->pp3c[1], 4) < 0) {
245 dev_warn(dev, "ceva,p1-comwake-params property not defined\n");
246 return -EINVAL;
247 }
248
249
250 if (of_property_read_u8_array(np, "ceva,p0-burst-params",
251 (u8 *)&cevapriv->pp4c[0], 4) < 0) {
252 dev_warn(dev, "ceva,p0-burst-params property not defined\n");
253 return -EINVAL;
254 }
255
256 if (of_property_read_u8_array(np, "ceva,p1-burst-params",
257 (u8 *)&cevapriv->pp4c[1], 4) < 0) {
258 dev_warn(dev, "ceva,p1-burst-params property not defined\n");
259 return -EINVAL;
260 }
261
262
263 if (of_property_read_u16_array(np, "ceva,p0-retry-params",
264 (u16 *)&cevapriv->pp5c[0], 2) < 0) {
265 dev_warn(dev, "ceva,p0-retry-params property not defined\n");
266 return -EINVAL;
267 }
268
269 if (of_property_read_u16_array(np, "ceva,p1-retry-params",
270 (u16 *)&cevapriv->pp5c[1], 2) < 0) {
271 dev_warn(dev, "ceva,p1-retry-params property not defined\n");
272 return -EINVAL;
273 }
274
275
276
277
278
279 attr = device_get_dma_attr(dev);
280 cevapriv->is_cci_enabled = (attr == DEV_DMA_COHERENT);
281
282 hpriv->plat_data = cevapriv;
283
284
285 ahci_ceva_setup(hpriv);
286
287 rc = ahci_platform_init_host(pdev, hpriv, &ahci_ceva_port_info,
288 &ahci_platform_sht);
289 if (rc)
290 goto disable_resources;
291
292 return 0;
293
294disable_resources:
295 ahci_platform_disable_resources(hpriv);
296 return rc;
297}
298
299static int __maybe_unused ceva_ahci_suspend(struct device *dev)
300{
301 return ahci_platform_suspend_host(dev);
302}
303
304static int __maybe_unused ceva_ahci_resume(struct device *dev)
305{
306 return ahci_platform_resume_host(dev);
307}
308
309static SIMPLE_DEV_PM_OPS(ahci_ceva_pm_ops, ceva_ahci_suspend, ceva_ahci_resume);
310
311static const struct of_device_id ceva_ahci_of_match[] = {
312 { .compatible = "ceva,ahci-1v84" },
313 {},
314};
315MODULE_DEVICE_TABLE(of, ceva_ahci_of_match);
316
317static struct platform_driver ceva_ahci_driver = {
318 .probe = ceva_ahci_probe,
319 .remove = ata_platform_remove_one,
320 .driver = {
321 .name = DRV_NAME,
322 .of_match_table = ceva_ahci_of_match,
323 .pm = &ahci_ceva_pm_ops,
324 },
325};
326module_platform_driver(ceva_ahci_driver);
327
328MODULE_DESCRIPTION("CEVA AHCI SATA platform driver");
329MODULE_AUTHOR("Xilinx Inc.");
330MODULE_LICENSE("GPL v2");
331