1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2020 Lubomir Rintel <lkundrak@v3.sk>
4  */
5 
6 #include <linux/delay.h>
7 #include <linux/io.h>
8 #include <linux/module.h>
9 #include <linux/phy/phy.h>
10 #include <linux/platform_device.h>
11 
12 #define HSIC_CTRL	0x08
13 #define HSIC_ENABLE	BIT(7)
14 #define PLL_BYPASS	BIT(4)
15 
16 static int mmp3_hsic_phy_init(struct phy *phy)
17 {
18 	void __iomem *base = (void __iomem *)phy_get_drvdata(phy);
19 	u32 hsic_ctrl;
20 
21 	hsic_ctrl = readl_relaxed(base + HSIC_CTRL);
22 	hsic_ctrl |= HSIC_ENABLE;
23 	hsic_ctrl |= PLL_BYPASS;
24 	writel_relaxed(hsic_ctrl, base + HSIC_CTRL);
25 
26 	return 0;
27 }
28 
29 static const struct phy_ops mmp3_hsic_phy_ops = {
30 	.init		= mmp3_hsic_phy_init,
31 	.owner		= THIS_MODULE,
32 };
33 
34 static const struct of_device_id mmp3_hsic_phy_of_match[] = {
35 	{ .compatible = "marvell,mmp3-hsic-phy", },
36 	{ },
37 };
38 MODULE_DEVICE_TABLE(of, mmp3_hsic_phy_of_match);
39 
40 static int mmp3_hsic_phy_probe(struct platform_device *pdev)
41 {
42 	struct device *dev = &pdev->dev;
43 	struct phy_provider *provider;
44 	struct resource *resource;
45 	void __iomem *base;
46 	struct phy *phy;
47 
48 	resource = platform_get_resource(pdev, IORESOURCE_MEM, 0);
49 	base = devm_ioremap_resource(dev, resource);
50 	if (IS_ERR(base)) {
51 		dev_err(dev, "failed to remap PHY regs\n");
52 		return PTR_ERR(base);
53 	}
54 
55 	phy = devm_phy_create(dev, NULL, &mmp3_hsic_phy_ops);
56 	if (IS_ERR(phy)) {
57 		dev_err(dev, "failed to create PHY\n");
58 		return PTR_ERR(phy);
59 	}
60 
61 	phy_set_drvdata(phy, (void *)base);
62 	provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
63 	if (IS_ERR(provider)) {
64 		dev_err(dev, "failed to register PHY provider\n");
65 		return PTR_ERR(provider);
66 	}
67 
68 	return 0;
69 }
70 
71 static struct platform_driver mmp3_hsic_phy_driver = {
72 	.probe		= mmp3_hsic_phy_probe,
73 	.driver		= {
74 		.name	= "mmp3-hsic-phy",
75 		.of_match_table = mmp3_hsic_phy_of_match,
76 	},
77 };
78 module_platform_driver(mmp3_hsic_phy_driver);
79 
80 MODULE_AUTHOR("Lubomir Rintel <lkundrak@v3.sk>");
81 MODULE_DESCRIPTION("Marvell MMP3 USB HSIC PHY Driver");
82 MODULE_LICENSE("GPL");
83