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 	void __iomem *base;
45 	struct phy *phy;
46 
47 	base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
48 	if (IS_ERR(base))
49 		return PTR_ERR(base);
50 
51 	phy = devm_phy_create(dev, NULL, &mmp3_hsic_phy_ops);
52 	if (IS_ERR(phy)) {
53 		dev_err(dev, "failed to create PHY\n");
54 		return PTR_ERR(phy);
55 	}
56 
57 	phy_set_drvdata(phy, (void *)base);
58 	provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
59 	if (IS_ERR(provider)) {
60 		dev_err(dev, "failed to register PHY provider\n");
61 		return PTR_ERR(provider);
62 	}
63 
64 	return 0;
65 }
66 
67 static struct platform_driver mmp3_hsic_phy_driver = {
68 	.probe		= mmp3_hsic_phy_probe,
69 	.driver		= {
70 		.name	= "mmp3-hsic-phy",
71 		.of_match_table = mmp3_hsic_phy_of_match,
72 	},
73 };
74 module_platform_driver(mmp3_hsic_phy_driver);
75 
76 MODULE_AUTHOR("Lubomir Rintel <lkundrak@v3.sk>");
77 MODULE_DESCRIPTION("Marvell MMP3 USB HSIC PHY Driver");
78 MODULE_LICENSE("GPL");
79