blob: 499c9f259456b520f8d3d14ae283b4a215e38555 [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright (c) 2020 MediaTek Inc.
4 * Author: Jianjun Wang <jianjun.wang@mediatek.com>
5 *
6 */
7
8#include <dt-bindings/phy/phy.h>
9#include <linux/clk.h>
10#include <linux/delay.h>
11#include <linux/io.h>
12#include <linux/iopoll.h>
13#include <linux/module.h>
14#include <linux/nvmem-consumer.h>
15#include <linux/of_address.h>
16#include <linux/of_device.h>
17#include <linux/phy/phy.h>
18#include <linux/pm_domain.h>
19#include <linux/platform_device.h>
20#include <linux/slab.h>
21#include <linux/sysfs.h>
22#include <linux/debugfs.h>
23#include <linux/of_device.h>
ll3149b302022-03-07 16:17:58 +080024#include <linux/gpio.h>
xjb04a4022021-11-25 15:01:52 +080025#define PCIE_PHY_0_NUM 0
26#define PCIE_PHY_1_NUM 1
27#define PCIE_PHY_2_NUM 2
28#define PCIE_PHY_3_NUM 3
29#define PCIE_PHY_0_EFUSE_CNT 5
30#define PCIE_PHY_CKM_REG04 0x04
31#define PCIE_EFSUE_P1_INDEX 0x108
32#define PCIE_EFSUE_P2_INDEX 0x10C
33#define PCIE_EFSUE_P3_INDEX 0x110
34#define CKM_PT0_CKTX_IMPSEL(val) ((val) & GENMASK(3, 0))
35#define CKM_PT0_CKTX_R50_EN BIT(5)
36#define CKM_PT0_CKTX_SLEW(val) ((val << 8) & GENMASK(9, 8))
37#define CKM_PT0_CKTX_OFFSET(val) ((val << 10) & GENMASK(11, 10))
38#define CKM_PT0_CKTX_AMP(val) ((val << 12) & GENMASK(15, 12))
39
40#define PEXTP_GLB_00_RG 0x9000
41#define PEXTP_04_RG 0xA004
42#define PEXTP_3C_RG 0xA03C
43#define PEXTP_104_RG 0xA104
44#define PEXTP_13C_RG 0xA13c
45
46#define EFUSE_FIELD_SIZE 4
47#define EFUSE_SHIFT(val, right, left, left_phy) \
48 ((((val) & GENMASK(right, left)) >> (left)) << (left_phy))
49
50struct mtk_pcie_phy {
51 struct device *dev;
52 struct phy *phy;
53 void __iomem *sif_base;
54 void __iomem *ckm_base;
55 struct clk *pipe_clk; /* pipe clock to mac */
56 enum phy_mode mode;
57};
58
59static const unsigned int efuse_field_offset[PCIE_PHY_0_EFUSE_CNT] = {
60 0x100, 0x104, 0x1B4, 0x1BC, 0x1C0
61};
62
63/*
64 * MT6890 RC portA is unlike the other ports, needs to get
65 * impedance select values from the efuse's multiple registers.
66 */
67static int pcie_fetch_efuse_scatter(struct mtk_pcie_phy *pcie_phy)
68{
69 struct nvmem_device *nvmem_dev;
70 u32 efuse_addr[PCIE_PHY_0_EFUSE_CNT] = {0}, val;
71 int ret;
72 int i;
73
74 nvmem_dev = nvmem_device_get(pcie_phy->dev, "mtk_efuse");
75 if (IS_ERR(nvmem_dev)) {
76 if (PTR_ERR(nvmem_dev) == -EPROBE_DEFER)
77 return PTR_ERR(nvmem_dev);
78 return -EINVAL;
79 }
80
81 for (i = 0; i < PCIE_PHY_0_EFUSE_CNT; i++) {
82 ret = nvmem_device_read(nvmem_dev, efuse_field_offset[i],
83 EFUSE_FIELD_SIZE, &efuse_addr[i]);
84 if (ret != EFUSE_FIELD_SIZE) {
85 dev_warn(pcie_phy->dev, "pcie efuse val is error\n");
86 return -EINVAL;
87 }
88 }
89
90 if (efuse_addr[0] == 0) {
91 dev_err(pcie_phy->dev, "Failed to read efuse value\n");
92 return -EINVAL;
93 }
94
95 /* PEXTP_GLB_00_RG[28:24] Internal RG Selection of TX Bias Current */
96 val = readl(pcie_phy->sif_base + PEXTP_GLB_00_RG);
97 val = (val & ~GENMASK(28, 24)) | EFUSE_SHIFT(efuse_addr[0], 27, 23, 24);
98 writel(val, pcie_phy->sif_base + PEXTP_GLB_00_RG);
99
100 /* PCIE_PHY_CKM_REG04[3:0] Internal R50 impedance select */
101 val = readl(pcie_phy->ckm_base + PCIE_PHY_CKM_REG04);
102 val = (val & ~GENMASK(3, 0)) | EFUSE_SHIFT(efuse_addr[1], 8, 5, 0);
103 writel(val, pcie_phy->ckm_base + PCIE_PHY_CKM_REG04);
104
105 /* PEXTP_04_RG[5:2] LN0 TX PMOS impedance selection */
106 val = readl(pcie_phy->sif_base + PEXTP_04_RG);
107 val = (val & ~GENMASK(5, 2)) | EFUSE_SHIFT(efuse_addr[2], 4, 1, 2);
108 writel(val, pcie_phy->sif_base + PEXTP_04_RG);
109
110 /* PEXTP_104_RG[5:2] LN1 TX PMOS impedance selection */
111 val = readl(pcie_phy->sif_base + PEXTP_104_RG);
112 val = (val & ~GENMASK(5, 2)) | EFUSE_SHIFT(efuse_addr[2], 8, 5, 2);
113 writel(val, pcie_phy->sif_base + PEXTP_104_RG);
114
115 /* PEXTP_04_RG[11:8] LN0 TX NMOS impedance selection */
116 val = readl(pcie_phy->sif_base + PEXTP_04_RG);
117 val = (val & ~GENMASK(11, 8)) | EFUSE_SHIFT(efuse_addr[2], 20, 17, 8);
118 writel(val, pcie_phy->sif_base + PEXTP_04_RG);
119
120 /* PEXTP_104_RG[11:8] LN1 TX NMOS impedance selection */
121 val = readl(pcie_phy->sif_base + PEXTP_104_RG);
122 val = (val & ~GENMASK(11, 8)) | EFUSE_SHIFT(efuse_addr[2], 24, 21, 8);
123 writel(val, pcie_phy->sif_base + PEXTP_104_RG);
124
125 /* PEXTP_3C_RG[3:0] LN0 RX impedance selection */
126 val = readl(pcie_phy->sif_base + PEXTP_3C_RG);
127 val = (val & ~GENMASK(3, 0)) | EFUSE_SHIFT(efuse_addr[3], 31, 28, 0);
128 writel(val, pcie_phy->sif_base + PEXTP_3C_RG);
129
130 /* PEXTP_13C_RG[3:0] LN1 RX impedance selection */
131 val = readl(pcie_phy->sif_base + PEXTP_13C_RG);
132 val = (val & ~GENMASK(3, 0)) | EFUSE_SHIFT(efuse_addr[4], 3, 0, 0);
133 writel(val, pcie_phy->sif_base + PEXTP_13C_RG);
134
135 nvmem_device_put(nvmem_dev);
136
137 return 0;
138}
139
140static int pcie_fetch_efuse_unify(struct mtk_pcie_phy *pcie_phy)
141{
142 struct nvmem_device *nvmem_dev;
143 u32 efuse_addr = 0, val;
144 unsigned int efuse_index_offset = 0;
145 int ret;
146
147 switch (pcie_phy->phy->id) {
148 case PCIE_PHY_1_NUM:
149 efuse_index_offset = PCIE_EFSUE_P1_INDEX;
150 break;
151 case PCIE_PHY_2_NUM:
152 efuse_index_offset = PCIE_EFSUE_P2_INDEX;
153 break;
154 case PCIE_PHY_3_NUM:
155 efuse_index_offset = PCIE_EFSUE_P3_INDEX;
156 break;
157 default:
158 dev_info(pcie_phy->dev, "pcie phy num for efuse is error\n");
159 }
160
161 nvmem_dev = nvmem_device_get(pcie_phy->dev, "mtk_efuse");
162 if (IS_ERR(nvmem_dev)) {
163 if (PTR_ERR(nvmem_dev) == -EPROBE_DEFER)
164 return PTR_ERR(nvmem_dev);
165 return -EINVAL;
166 }
167
168 ret = nvmem_device_read(nvmem_dev, efuse_index_offset,
169 EFUSE_FIELD_SIZE, &efuse_addr);
170 if (ret != EFUSE_FIELD_SIZE) {
171 dev_warn(pcie_phy->dev, "pcie efuse val is error\n");
172 return -EINVAL;
173 }
174
175 if (efuse_addr == 0) {
176 dev_err(pcie_phy->dev, "Failed to read efuse value\n");
177 return -EINVAL;
178 }
179
180 /* PEXTP_3C_RG[3:0] LN0 RX impedance selection */
181 val = readl(pcie_phy->sif_base + PEXTP_3C_RG);
182 val = (val & ~GENMASK(3, 0)) | EFUSE_SHIFT(efuse_addr, 3, 0, 0);
183 writel(val, pcie_phy->sif_base + PEXTP_3C_RG);
184
185 /* PEXTP_04_RG[5:2] LN0 TX PMOS impedance selection */
186 val = readl(pcie_phy->sif_base + PEXTP_04_RG);
187 val = (val & ~GENMASK(5, 2)) | EFUSE_SHIFT(efuse_addr, 7, 4, 2);
188 writel(val, pcie_phy->sif_base + PEXTP_04_RG);
189
190 /* PEXTP_04_RG[11:8] LN0 TX NMOS impedance selection */
191 val = readl(pcie_phy->sif_base + PEXTP_04_RG);
192 val = (val & ~GENMASK(11, 8)) | EFUSE_SHIFT(efuse_addr, 11, 8, 8);
193 writel(val, pcie_phy->sif_base + PEXTP_04_RG);
194
195 /* PEXTP_GLB_00_RG[28:24] Internal RG Selection of TX Bias Current */
196 val = readl(pcie_phy->sif_base + PEXTP_GLB_00_RG);
197 val = (val & ~GENMASK(28, 24)) | EFUSE_SHIFT(efuse_addr, 16, 12, 24);
198 writel(val, pcie_phy->sif_base + PEXTP_GLB_00_RG);
199
200 /* portB is two lanes */
201 if (pcie_phy->phy->id == 1) {
202 /* PEXTP_13C_RG[3:0] LN1 RX impedance selection */
203 val = readl(pcie_phy->sif_base + PEXTP_13C_RG);
204 val = (val & ~GENMASK(3, 0)) |
205 EFUSE_SHIFT(efuse_addr, 20, 17, 0);
206 writel(val, pcie_phy->sif_base + PEXTP_13C_RG);
207
208 /* PEXTP_104_RG[5:2] LN1 TX PMOS impedance selection */
209 val = readl(pcie_phy->sif_base + PEXTP_104_RG);
210 val = (val & ~GENMASK(5, 2)) |
211 EFUSE_SHIFT(efuse_addr, 24, 21, 2);
212 writel(val, pcie_phy->sif_base + PEXTP_104_RG);
213
214 /* PEXTP_104_RG[11:8] LN1 TX NMOS impedance selection */
215 val = readl(pcie_phy->sif_base + PEXTP_104_RG);
216 val = (val & ~GENMASK(11, 8)) |
217 EFUSE_SHIFT(efuse_addr, 28, 25, 8);
218 writel(val, pcie_phy->sif_base + PEXTP_104_RG);
219 }
220
221 nvmem_device_put(nvmem_dev);
222
223 return 0;
224}
225
226static int mtk_pcie_phy_init(struct phy *phy)
227{
228 struct mtk_pcie_phy *pcie_phy = phy_get_drvdata(phy);
229 struct device *dev = pcie_phy->dev;
230 struct generic_pm_domain *pcie_pd;
231 int err;
232
233 if (pcie_phy->mode == PHY_MODE_PCIE_EP) {
234 dev_info(pcie_phy->dev, "set phy to EP mode\n");
235 if (dev->pm_domain) {
236 pcie_pd = pd_to_genpd(dev->pm_domain);
237 pcie_pd->flags |= GENPD_FLAG_ALWAYS_ON;
238 }
239 }
240
241 if (pcie_phy->mode == PHY_MODE_PCIE_RC) {
242 if (pcie_phy->phy->id == PCIE_PHY_0_NUM) {
243 err = pcie_fetch_efuse_scatter(pcie_phy);
244 if (err)
245 return -EINVAL;
246 }
247
248 if (pcie_phy->phy->id > PCIE_PHY_0_NUM) {
249 err = pcie_fetch_efuse_unify(pcie_phy);
250 if (err)
251 return -EINVAL;
252 }
253 }
254
255 return 0;
256}
257
258static int mtk_pcie_phy_power_on(struct phy *phy)
259{
260 struct mtk_pcie_phy *pcie_phy = phy_get_drvdata(phy);
261 int val, ret;
262
263 pm_runtime_get_sync(pcie_phy->dev);
264
265 if (pcie_phy->mode == PHY_MODE_PCIE_RC) {
266 val = readl(pcie_phy->ckm_base + PCIE_PHY_CKM_REG04);
267 val &= ~GENMASK(11, 10);
268 val |= CKM_PT0_CKTX_OFFSET(0x2);
269 writel(val, pcie_phy->ckm_base + PCIE_PHY_CKM_REG04);
270 }
271
272 /* provide pipe clock to pcie mac */
273 if (pcie_phy->pipe_clk) {
274 ret = clk_prepare_enable(pcie_phy->pipe_clk);
275 if (ret) {
276 dev_err(pcie_phy->dev, "failed to enable pipe_clk\n");
277 return ret;
278 }
279 }
280
281 return 0;
282}
283
284static int mtk_pcie_phy_power_off(struct phy *phy)
285{
286 struct mtk_pcie_phy *pcie_phy = phy_get_drvdata(phy);
287
288 if (pcie_phy->pipe_clk)
289 clk_disable_unprepare(pcie_phy->pipe_clk);
290
291 pm_runtime_put_sync(pcie_phy->dev);
292
293 return 0;
294}
295
296static int mtk_pcie_phy_exit(struct phy *phy)
297{
298 return 0;
299}
300
301static int mtk_pcie_phy_set_mode(struct phy *phy, enum phy_mode mode)
302{
303 struct mtk_pcie_phy *pcie_phy = phy_get_drvdata(phy);
304
305 pcie_phy->mode = mode;
306
307 return 0;
308}
309
310static const struct phy_ops mtk_pcie_phy_ops = {
311 .init = mtk_pcie_phy_init,
312 .exit = mtk_pcie_phy_exit,
313 .power_on = mtk_pcie_phy_power_on,
314 .power_off = mtk_pcie_phy_power_off,
315 .set_mode = mtk_pcie_phy_set_mode,
316 .owner = THIS_MODULE,
317};
318
319static struct phy *mtk_pcie_phy_xlate(struct device *dev,
320 struct of_phandle_args *args)
321{
322 struct mtk_pcie_phy *pcie_phy = dev_get_drvdata(dev);
323
324 if (!pcie_phy)
325 return NULL;
326
327 return pcie_phy->phy;
328}
329
330
331//tianyan@2021.10.21 modify for pcie loopback test start
332
333static void pcie_loopback_save_reg(void __iomem *phy_base,int *reg,int *reg_value,int len,bool flag)
334{
335 int i=0;
336
337 for(i=0; i<len; i++){
338 if(flag)
339 *(reg_value+i) = readl(phy_base + *reg++);
340 else
341 writel(*(reg_value+i),phy_base + *reg++);
342 }
343}
344
345/* Loopback test for PCIe port
346 * Port 0 -> 2 lane
347 */
348static int pcie_loopback_test(void __iomem *phy_base)
349{
350 int val = 0, ret = 0;
351 int err_count = 0;
352 int reg[6]={0x28,0x70,0x4010,0x4110,0x501c,0x511c};
353 int reg_value[6]={0};
354
355 pr_info("pcie loopback test start\n");
356
357 if (!phy_base) {
358 pr_info("phy_base is not initialed!\n");
359 return -1;
360 }
361
362 pcie_loopback_save_reg(phy_base,reg,reg_value,6,true);
363
364 /* L1ss = enable */
365 val = readl(phy_base + 0x28);
366 val |= (0x01 << 5);
367 writel(val, phy_base + 0x28);
368
369 val = readl(phy_base + 0x28);
370 val |= (0x01 << 4);
371 writel(val, phy_base + 0x28);
372
373 val = readl(phy_base + 0x28);
374 val &= (~0x200);
375 writel(val, phy_base + 0x28);
376
377 val = readl(phy_base + 0x28);
378 val |= (0x01 << 8);
379 writel(val, phy_base + 0x28);
380
381 val = readl(phy_base + 0x28);
382 val &= (~0x800);
383 writel(val, phy_base + 0x28);
384
385 val = readl(phy_base + 0x28);
386 val |= (0x01 << 10);
387 writel(val, phy_base + 0x28);
388
389 /* Set Rate=Gen1 */
390 usleep_range(1, 2);
391 val = readl(phy_base + 0x70);
392 val |= (0x01);
393 writel(val, phy_base + 0x70);
394
395 val = readl(phy_base + 0x70);
396 val &= (~0x30000);
397 writel(val, phy_base + 0x70);
398
399 val = readl(phy_base + 0x70);
400 val |= (0x01 << 4);
401 writel(val, phy_base + 0x70);
402
403 usleep_range(1, 2);
404 val = readl(phy_base + 0x70);
405 val &= (~0x10);
406 writel(val, phy_base + 0x70);
407
408 /* Force PIPE (P0) */
409 val = readl(phy_base + 0x70);
410 val |= (0x01);
411 writel(val, phy_base + 0x70);
412
413 val = readl(phy_base + 0x70);
414 val &= (~0xc00);
415 writel(val, phy_base + 0x70);
416
417 val = readl(phy_base + 0x70);
418 val &= (~0x3000);
419 writel(val, phy_base + 0x70);
420
421 val = readl(phy_base + 0x70);
422 val |= (0x01 << 8);
423 writel(val, phy_base + 0x70);
424
425 val = readl(phy_base + 0x70);
426 val |= (0x01 << 4);
427 writel(val, phy_base + 0x70);
428
429 usleep_range(1, 2);
430 val = readl(phy_base + 0x70);
431 val &= (~0x10);
432 writel(val, phy_base + 0x70);
433
434 /* Set TX output Pattern */
435 usleep_range(1, 2);
436
437 /* Lane 0 */
438 val = readl(phy_base + 0x4010);
439 val |= (0x0d);
440 writel(val, phy_base + 0x4010);
441
442 /* Lane 1 */
443 val = readl(phy_base + 0x4110);
444 val |= (0x0d);
445 writel(val, phy_base + 0x4110);
446
447 /* Set TX PTG Enable */
448 val = readl(phy_base + 0x28);
449 val |= (0x01 << 30);
450 writel(val, phy_base + 0x28);
451
452 /* Set RX Pattern Checker (Type & Enable) */
453 /* Lane 0 */
454 val = readl(phy_base + 0x501c);
455 val |= (0x01 << 1);
456 writel(val, phy_base + 0x501c);
457
458 val = readl(phy_base + 0x501c);
459 val |= (0x0d << 4);
460 writel(val, phy_base + 0x501c);
461
462 /* Lane 1 */
463 val = readl(phy_base + 0x511c);
464 val |= (0x01 << 1);
465 writel(val, phy_base + 0x511c);
466
467 val = readl(phy_base + 0x511c);
468 val |= (0x0d << 4);
469 writel(val, phy_base + 0x511c);
470
471 /* toggle ptc_en for status counter clear */
472 /* Lane 0 */
473 val = readl(phy_base + 0x501c);
474 val &= (~0x2);
475 writel(val, phy_base + 0x501c);
476
477 val = readl(phy_base + 0x501c);
478 val |= (0x01 << 1);
479 writel(val, phy_base + 0x501c);
480
481 /* Lane 1 */
482 val = readl(phy_base + 0x511c);
483 val &= (~0x2);
484 writel(val, phy_base + 0x511c);
485
486 val = readl(phy_base + 0x511c);
487 val |= (0x01 << 1);
488 writel(val, phy_base + 0x511c);
489
490 /* Check status */
491 msleep(50);
492 val = readl(phy_base + 0x50c8);
493 if ((val & 0x3) != 0x3) {
494 err_count = val >> 12;
495 pr_info("PCIe test failed: %#x!\n", val);
496 pr_info("lane0 error count: %d\n", err_count);
497 ret = -1;
498 }
499
500 val = readl(phy_base + 0x51c8);
501 if ((val & 0x3) != 0x3) {
502 err_count = val >> 12;
503 pr_info("PCIe test failed: %#x!\n", val);
504 pr_info("lane1 error count: %d\n", err_count);
505 ret = -1;
506 }
507
508 pcie_loopback_save_reg(phy_base,reg,reg_value,6,false);
509 return ret;
510}
511
512static bool pcie_loopback_test_res=false;
513
514static int pcie_loopback_debugfs_open(struct inode *inode, struct file *file)
515{
516 file->private_data = inode->i_private;
517 return 0;
518}
519
520static ssize_t pcie_loopback_debugfs_read(struct file *file, char __user *buf,
521 size_t count, loff_t *pos)
522{
523 bool *result = file->private_data;
524 const int size = 128;
525 char *buffer = NULL; /* for reduce kernel stack */
526 int n = 0;
527 int ret = 0;
528
529 buffer = kmalloc(size, GFP_KERNEL);
530 if (!buffer || !buf)
531 return -ENOMEM;
532
533 if (!(*result)) {
534 pr_info("pcie loopback test failed!\n");
535 n += scnprintf(buffer + n, size - n, "pcie loopback test failed!\n");
536 }
537 else{
538 pr_info("pcie loopback test success!\n");
539 n += scnprintf(buffer + n, size - n, "pcie loopback test success!\n");
540 }
541
542 ret = simple_read_from_buffer(buf, count, pos, buffer, n);
543 kfree(buffer);
544 return ret;
545}
546
547
548static const struct file_operations pcie_loopback_debugfs_ops = {
549 .open = pcie_loopback_debugfs_open,
550 .read = pcie_loopback_debugfs_read,
551};
552
553//tianyan@2021.10.21 modify for pcie loopback test end
554
555static int mtk_pcie_phy_probe(struct platform_device *pdev)
556{
557 struct device *dev = &pdev->dev;
558 struct phy_provider *provider;
559 struct resource *reg_res;
560 struct mtk_pcie_phy *pcie_phy;
561
562 pcie_phy = devm_kzalloc(dev, sizeof(*pcie_phy), GFP_KERNEL);
563 if (!pcie_phy)
564 return -ENOMEM;
565
566 pcie_phy->dev = dev;
567
568//tianyan@2021.7.27 modify for add wifi6 module start
569/* pcie_phy->pipe_clk = devm_clk_get(pcie_phy->dev, "pipe_clk");
570 if (IS_ERR(pcie_phy->pipe_clk)) {
571 dev_warn(dev, "pcie pipe_clk not found\n");
572 pcie_phy->pipe_clk = NULL;
573 }*/
574//tianyan@2021.7.27 modify for add wifi6 module end
575
576 pm_runtime_enable(pcie_phy->dev);
577
578 reg_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy-sif");
579 pcie_phy->sif_base = devm_ioremap_resource(dev, reg_res);
580 if (IS_ERR(pcie_phy->sif_base)) {
581 dev_warn(dev, "failed to map pcie phy base\n");
582 return PTR_ERR(pcie_phy->sif_base);
583 }
584
585//tianyan@2021.10.21 modify for pcie loopback test start
586 if(!pcie_loopback_test(pcie_phy->sif_base)){
587 pcie_loopback_test_res = true;
ll3149b302022-03-07 16:17:58 +0800588 pr_info("pcie loopback test success! GPIO97 output high\n");
589 gpio_direction_output(268+97,1);
xjb04a4022021-11-25 15:01:52 +0800590 }
591 (void*)debugfs_create_file("pcie_loopback",
592 S_IFREG | 0444, NULL,
593 &pcie_loopback_test_res, &pcie_loopback_debugfs_ops);
594//tianyan@2021.10.21 modify for pcie loopback test end
595
596 reg_res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy-ckm");
597 pcie_phy->ckm_base = devm_ioremap_resource(dev, reg_res);
598 if (IS_ERR(pcie_phy->ckm_base)) {
599 dev_warn(dev, "failed to map pcie phy base\n");
600 return PTR_ERR(pcie_phy->ckm_base);
601 }
602
603 platform_set_drvdata(pdev, pcie_phy);
604
605 pcie_phy->phy = devm_phy_create(dev, dev->of_node, &mtk_pcie_phy_ops);
606 if (IS_ERR(pcie_phy->phy)) {
607 dev_err(dev, "failed to create pcie phy\n");
608 return PTR_ERR(pcie_phy->phy);
609 }
610
611 phy_set_drvdata(pcie_phy->phy, pcie_phy);
612
613 provider = devm_of_phy_provider_register(dev, mtk_pcie_phy_xlate);
614
615 return PTR_ERR_OR_ZERO(provider);
616}
617
618static const struct of_device_id mtk_pcie_phy_id_table[] = {
619 { .compatible = "mediatek,mt6880-pcie-phy" },
620 { .compatible = "mediatek,mt2735-pcie-phy" },
621 { },
622};
623
624static struct platform_driver mtk_pcie_phy_driver = {
625 .probe = mtk_pcie_phy_probe,
626 .driver = {
627 .name = "mtk-pcie-phy",
628 .of_match_table = mtk_pcie_phy_id_table,
629 },
630};
631
632module_platform_driver(mtk_pcie_phy_driver);
633MODULE_LICENSE("GPL v2");