1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (C) 2018 John Crispin <john@phrozen.org>
6 * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
10 #include <linux/delay.h>
11 #include <linux/err.h>
13 #include <linux/kernel.h>
14 #include <linux/module.h>
15 #include <linux/mutex.h>
16 #include <linux/of_platform.h>
17 #include <linux/of_device.h>
18 #include <linux/phy/phy.h>
19 #include <linux/platform_device.h>
20 #include <linux/reset.h>
22 struct ipq4019_usb_phy
{
26 struct reset_control
*por_rst
;
27 struct reset_control
*srif_rst
;
30 static int ipq4019_ss_phy_power_off(struct phy
*_phy
)
32 struct ipq4019_usb_phy
*phy
= phy_get_drvdata(_phy
);
34 reset_control_assert(phy
->por_rst
);
40 static int ipq4019_ss_phy_power_on(struct phy
*_phy
)
42 struct ipq4019_usb_phy
*phy
= phy_get_drvdata(_phy
);
44 ipq4019_ss_phy_power_off(_phy
);
46 reset_control_deassert(phy
->por_rst
);
51 static const struct phy_ops ipq4019_usb_ss_phy_ops
= {
52 .power_on
= ipq4019_ss_phy_power_on
,
53 .power_off
= ipq4019_ss_phy_power_off
,
56 static int ipq4019_hs_phy_power_off(struct phy
*_phy
)
58 struct ipq4019_usb_phy
*phy
= phy_get_drvdata(_phy
);
60 reset_control_assert(phy
->por_rst
);
63 reset_control_assert(phy
->srif_rst
);
69 static int ipq4019_hs_phy_power_on(struct phy
*_phy
)
71 struct ipq4019_usb_phy
*phy
= phy_get_drvdata(_phy
);
73 ipq4019_hs_phy_power_off(_phy
);
75 reset_control_deassert(phy
->srif_rst
);
78 reset_control_deassert(phy
->por_rst
);
83 static const struct phy_ops ipq4019_usb_hs_phy_ops
= {
84 .power_on
= ipq4019_hs_phy_power_on
,
85 .power_off
= ipq4019_hs_phy_power_off
,
88 static const struct of_device_id ipq4019_usb_phy_of_match
[] = {
89 { .compatible
= "qcom,usb-hs-ipq4019-phy", .data
= &ipq4019_usb_hs_phy_ops
},
90 { .compatible
= "qcom,usb-ss-ipq4019-phy", .data
= &ipq4019_usb_ss_phy_ops
},
93 MODULE_DEVICE_TABLE(of
, ipq4019_usb_phy_of_match
);
95 static int ipq4019_usb_phy_probe(struct platform_device
*pdev
)
97 struct device
*dev
= &pdev
->dev
;
98 struct phy_provider
*phy_provider
;
99 struct ipq4019_usb_phy
*phy
;
101 phy
= devm_kzalloc(dev
, sizeof(*phy
), GFP_KERNEL
);
105 phy
->dev
= &pdev
->dev
;
106 phy
->base
= devm_platform_ioremap_resource(pdev
, 0);
107 if (IS_ERR(phy
->base
)) {
108 dev_err(dev
, "failed to remap register memory\n");
109 return PTR_ERR(phy
->base
);
112 phy
->por_rst
= devm_reset_control_get(phy
->dev
, "por_rst");
113 if (IS_ERR(phy
->por_rst
)) {
114 if (PTR_ERR(phy
->por_rst
) != -EPROBE_DEFER
)
115 dev_err(dev
, "POR reset is missing\n");
116 return PTR_ERR(phy
->por_rst
);
119 phy
->srif_rst
= devm_reset_control_get_optional(phy
->dev
, "srif_rst");
120 if (IS_ERR(phy
->srif_rst
))
121 return PTR_ERR(phy
->srif_rst
);
123 phy
->phy
= devm_phy_create(dev
, NULL
, of_device_get_match_data(dev
));
124 if (IS_ERR(phy
->phy
)) {
125 dev_err(dev
, "failed to create PHY\n");
126 return PTR_ERR(phy
->phy
);
128 phy_set_drvdata(phy
->phy
, phy
);
130 phy_provider
= devm_of_phy_provider_register(dev
, of_phy_simple_xlate
);
132 return PTR_ERR_OR_ZERO(phy_provider
);
135 static struct platform_driver ipq4019_usb_phy_driver
= {
136 .probe
= ipq4019_usb_phy_probe
,
138 .of_match_table
= ipq4019_usb_phy_of_match
,
139 .name
= "ipq4019-usb-phy",
142 module_platform_driver(ipq4019_usb_phy_driver
);
144 MODULE_DESCRIPTION("QCOM/IPQ4019 USB phy driver");
145 MODULE_AUTHOR("John Crispin <john@phrozen.org>");
146 MODULE_LICENSE("GPL v2");