Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 /*
0003  * Copyright (C) 2018 John Crispin <john@phrozen.org>
0004  *
0005  * Based on code from
0006  * Allwinner Technology Co., Ltd. <www.allwinnertech.com>
0007  *
0008  */
0009 
0010 #include <linux/delay.h>
0011 #include <linux/err.h>
0012 #include <linux/io.h>
0013 #include <linux/kernel.h>
0014 #include <linux/module.h>
0015 #include <linux/mutex.h>
0016 #include <linux/of_platform.h>
0017 #include <linux/of_device.h>
0018 #include <linux/phy/phy.h>
0019 #include <linux/platform_device.h>
0020 #include <linux/reset.h>
0021 
0022 struct ipq4019_usb_phy {
0023     struct device       *dev;
0024     struct phy      *phy;
0025     void __iomem        *base;
0026     struct reset_control    *por_rst;
0027     struct reset_control    *srif_rst;
0028 };
0029 
0030 static int ipq4019_ss_phy_power_off(struct phy *_phy)
0031 {
0032     struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
0033 
0034     reset_control_assert(phy->por_rst);
0035     msleep(10);
0036 
0037     return 0;
0038 }
0039 
0040 static int ipq4019_ss_phy_power_on(struct phy *_phy)
0041 {
0042     struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
0043 
0044     ipq4019_ss_phy_power_off(_phy);
0045 
0046     reset_control_deassert(phy->por_rst);
0047 
0048     return 0;
0049 }
0050 
0051 static const struct phy_ops ipq4019_usb_ss_phy_ops = {
0052     .power_on   = ipq4019_ss_phy_power_on,
0053     .power_off  = ipq4019_ss_phy_power_off,
0054 };
0055 
0056 static int ipq4019_hs_phy_power_off(struct phy *_phy)
0057 {
0058     struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
0059 
0060     reset_control_assert(phy->por_rst);
0061     msleep(10);
0062 
0063     reset_control_assert(phy->srif_rst);
0064     msleep(10);
0065 
0066     return 0;
0067 }
0068 
0069 static int ipq4019_hs_phy_power_on(struct phy *_phy)
0070 {
0071     struct ipq4019_usb_phy *phy = phy_get_drvdata(_phy);
0072 
0073     ipq4019_hs_phy_power_off(_phy);
0074 
0075     reset_control_deassert(phy->srif_rst);
0076     msleep(10);
0077 
0078     reset_control_deassert(phy->por_rst);
0079 
0080     return 0;
0081 }
0082 
0083 static const struct phy_ops ipq4019_usb_hs_phy_ops = {
0084     .power_on   = ipq4019_hs_phy_power_on,
0085     .power_off  = ipq4019_hs_phy_power_off,
0086 };
0087 
0088 static const struct of_device_id ipq4019_usb_phy_of_match[] = {
0089     { .compatible = "qcom,usb-hs-ipq4019-phy", .data = &ipq4019_usb_hs_phy_ops},
0090     { .compatible = "qcom,usb-ss-ipq4019-phy", .data = &ipq4019_usb_ss_phy_ops},
0091     { },
0092 };
0093 MODULE_DEVICE_TABLE(of, ipq4019_usb_phy_of_match);
0094 
0095 static int ipq4019_usb_phy_probe(struct platform_device *pdev)
0096 {
0097     struct device *dev = &pdev->dev;
0098     struct phy_provider *phy_provider;
0099     struct ipq4019_usb_phy *phy;
0100 
0101     phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
0102     if (!phy)
0103         return -ENOMEM;
0104 
0105     phy->dev = &pdev->dev;
0106     phy->base = devm_platform_ioremap_resource(pdev, 0);
0107     if (IS_ERR(phy->base)) {
0108         dev_err(dev, "failed to remap register memory\n");
0109         return PTR_ERR(phy->base);
0110     }
0111 
0112     phy->por_rst = devm_reset_control_get(phy->dev, "por_rst");
0113     if (IS_ERR(phy->por_rst)) {
0114         if (PTR_ERR(phy->por_rst) != -EPROBE_DEFER)
0115             dev_err(dev, "POR reset is missing\n");
0116         return PTR_ERR(phy->por_rst);
0117     }
0118 
0119     phy->srif_rst = devm_reset_control_get_optional(phy->dev, "srif_rst");
0120     if (IS_ERR(phy->srif_rst))
0121         return PTR_ERR(phy->srif_rst);
0122 
0123     phy->phy = devm_phy_create(dev, NULL, of_device_get_match_data(dev));
0124     if (IS_ERR(phy->phy)) {
0125         dev_err(dev, "failed to create PHY\n");
0126         return PTR_ERR(phy->phy);
0127     }
0128     phy_set_drvdata(phy->phy, phy);
0129 
0130     phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
0131 
0132     return PTR_ERR_OR_ZERO(phy_provider);
0133 }
0134 
0135 static struct platform_driver ipq4019_usb_phy_driver = {
0136     .probe  = ipq4019_usb_phy_probe,
0137     .driver = {
0138         .of_match_table = ipq4019_usb_phy_of_match,
0139         .name  = "ipq4019-usb-phy",
0140     }
0141 };
0142 module_platform_driver(ipq4019_usb_phy_driver);
0143 
0144 MODULE_DESCRIPTION("QCOM/IPQ4019 USB phy driver");
0145 MODULE_AUTHOR("John Crispin <john@phrozen.org>");
0146 MODULE_LICENSE("GPL v2");