0001
0002
0003
0004
0005
0006
0007
0008
0009 #include <linux/platform_device.h>
0010 #include <linux/io.h>
0011 #include <linux/kernel.h>
0012 #include <linux/module.h>
0013 #include <linux/of.h>
0014 #include <linux/of_platform.h>
0015 #include <linux/clk.h>
0016 #include <linux/regmap.h>
0017 #include <linux/reset.h>
0018 #include <linux/mfd/syscon.h>
0019 #include <linux/phy/phy.h>
0020
0021 #define PHYPARAM_REG 1
0022 #define PHYCTRL_REG 2
0023
0024
0025 #define STIH407_USB_PICOPHY_CTRL_PORT_CONF 0x6
0026 #define STIH407_USB_PICOPHY_CTRL_PORT_MASK 0x1f
0027
0028
0029 #define STIH407_USB_PICOPHY_PARAM_DEF 0x39a4dc
0030 #define STIH407_USB_PICOPHY_PARAM_MASK 0xffffffff
0031
0032 struct stih407_usb2_picophy {
0033 struct phy *phy;
0034 struct regmap *regmap;
0035 struct device *dev;
0036 struct reset_control *rstc;
0037 struct reset_control *rstport;
0038 int ctrl;
0039 int param;
0040 };
0041
0042 static int stih407_usb2_pico_ctrl(struct stih407_usb2_picophy *phy_dev)
0043 {
0044 reset_control_deassert(phy_dev->rstc);
0045
0046 return regmap_update_bits(phy_dev->regmap, phy_dev->ctrl,
0047 STIH407_USB_PICOPHY_CTRL_PORT_MASK,
0048 STIH407_USB_PICOPHY_CTRL_PORT_CONF);
0049 }
0050
0051 static int stih407_usb2_init_port(struct phy *phy)
0052 {
0053 int ret;
0054 struct stih407_usb2_picophy *phy_dev = phy_get_drvdata(phy);
0055
0056 stih407_usb2_pico_ctrl(phy_dev);
0057
0058 ret = regmap_update_bits(phy_dev->regmap,
0059 phy_dev->param,
0060 STIH407_USB_PICOPHY_PARAM_MASK,
0061 STIH407_USB_PICOPHY_PARAM_DEF);
0062 if (ret)
0063 return ret;
0064
0065 return reset_control_deassert(phy_dev->rstport);
0066 }
0067
0068 static int stih407_usb2_exit_port(struct phy *phy)
0069 {
0070 struct stih407_usb2_picophy *phy_dev = phy_get_drvdata(phy);
0071
0072
0073
0074
0075
0076
0077
0078
0079 return reset_control_assert(phy_dev->rstport);
0080 }
0081
0082 static const struct phy_ops stih407_usb2_picophy_data = {
0083 .init = stih407_usb2_init_port,
0084 .exit = stih407_usb2_exit_port,
0085 .owner = THIS_MODULE,
0086 };
0087
0088 static int stih407_usb2_picophy_probe(struct platform_device *pdev)
0089 {
0090 struct stih407_usb2_picophy *phy_dev;
0091 struct device *dev = &pdev->dev;
0092 struct device_node *np = dev->of_node;
0093 struct phy_provider *phy_provider;
0094 struct phy *phy;
0095 int ret;
0096
0097 phy_dev = devm_kzalloc(dev, sizeof(*phy_dev), GFP_KERNEL);
0098 if (!phy_dev)
0099 return -ENOMEM;
0100
0101 phy_dev->dev = dev;
0102 dev_set_drvdata(dev, phy_dev);
0103
0104 phy_dev->rstc = devm_reset_control_get_shared(dev, "global");
0105 if (IS_ERR(phy_dev->rstc)) {
0106 dev_err(dev, "failed to ctrl picoPHY reset\n");
0107 return PTR_ERR(phy_dev->rstc);
0108 }
0109
0110 phy_dev->rstport = devm_reset_control_get_exclusive(dev, "port");
0111 if (IS_ERR(phy_dev->rstport)) {
0112 dev_err(dev, "failed to ctrl picoPHY reset\n");
0113 return PTR_ERR(phy_dev->rstport);
0114 }
0115
0116
0117 reset_control_assert(phy_dev->rstport);
0118
0119 phy_dev->regmap = syscon_regmap_lookup_by_phandle(np, "st,syscfg");
0120 if (IS_ERR(phy_dev->regmap)) {
0121 dev_err(dev, "No syscfg phandle specified\n");
0122 return PTR_ERR(phy_dev->regmap);
0123 }
0124
0125 ret = of_property_read_u32_index(np, "st,syscfg", PHYPARAM_REG,
0126 &phy_dev->param);
0127 if (ret) {
0128 dev_err(dev, "can't get phyparam offset (%d)\n", ret);
0129 return ret;
0130 }
0131
0132 ret = of_property_read_u32_index(np, "st,syscfg", PHYCTRL_REG,
0133 &phy_dev->ctrl);
0134 if (ret) {
0135 dev_err(dev, "can't get phyctrl offset (%d)\n", ret);
0136 return ret;
0137 }
0138
0139 phy = devm_phy_create(dev, NULL, &stih407_usb2_picophy_data);
0140 if (IS_ERR(phy)) {
0141 dev_err(dev, "failed to create Display Port PHY\n");
0142 return PTR_ERR(phy);
0143 }
0144
0145 phy_dev->phy = phy;
0146 phy_set_drvdata(phy, phy_dev);
0147
0148 phy_provider = devm_of_phy_provider_register(dev, of_phy_simple_xlate);
0149 if (IS_ERR(phy_provider))
0150 return PTR_ERR(phy_provider);
0151
0152 dev_info(dev, "STiH407 USB Generic picoPHY driver probed!");
0153
0154 return 0;
0155 }
0156
0157 static const struct of_device_id stih407_usb2_picophy_of_match[] = {
0158 { .compatible = "st,stih407-usb2-phy" },
0159 { },
0160 };
0161
0162 MODULE_DEVICE_TABLE(of, stih407_usb2_picophy_of_match);
0163
0164 static struct platform_driver stih407_usb2_picophy_driver = {
0165 .probe = stih407_usb2_picophy_probe,
0166 .driver = {
0167 .name = "stih407-usb-genphy",
0168 .of_match_table = stih407_usb2_picophy_of_match,
0169 }
0170 };
0171
0172 module_platform_driver(stih407_usb2_picophy_driver);
0173
0174 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
0175 MODULE_DESCRIPTION("STMicroelectronics Generic picoPHY driver for STiH407");
0176 MODULE_LICENSE("GPL v2");