1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014 STMicroelectronics
5 * STMicroelectronics Generic PHY driver for STiH407 USB2.
7 * Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
9 #include <linux/platform_device.h>
11 #include <linux/kernel.h>
12 #include <linux/module.h>
14 #include <linux/of_platform.h>
15 #include <linux/clk.h>
16 #include <linux/regmap.h>
17 #include <linux/reset.h>
18 #include <linux/mfd/syscon.h>
19 #include <linux/phy/phy.h>
21 #define PHYPARAM_REG 1
24 /* Default PHY_SEL and REFCLKSEL configuration */
25 #define STIH407_USB_PICOPHY_CTRL_PORT_CONF 0x6
26 #define STIH407_USB_PICOPHY_CTRL_PORT_MASK 0x1f
28 /* ports parameters overriding */
29 #define STIH407_USB_PICOPHY_PARAM_DEF 0x39a4dc
30 #define STIH407_USB_PICOPHY_PARAM_MASK 0xffffffff
32 struct stih407_usb2_picophy
{
34 struct regmap
*regmap
;
36 struct reset_control
*rstc
;
37 struct reset_control
*rstport
;
42 static int stih407_usb2_pico_ctrl(struct stih407_usb2_picophy
*phy_dev
)
44 reset_control_deassert(phy_dev
->rstc
);
46 return regmap_update_bits(phy_dev
->regmap
, phy_dev
->ctrl
,
47 STIH407_USB_PICOPHY_CTRL_PORT_MASK
,
48 STIH407_USB_PICOPHY_CTRL_PORT_CONF
);
51 static int stih407_usb2_init_port(struct phy
*phy
)
54 struct stih407_usb2_picophy
*phy_dev
= phy_get_drvdata(phy
);
56 stih407_usb2_pico_ctrl(phy_dev
);
58 ret
= regmap_update_bits(phy_dev
->regmap
,
60 STIH407_USB_PICOPHY_PARAM_MASK
,
61 STIH407_USB_PICOPHY_PARAM_DEF
);
65 return reset_control_deassert(phy_dev
->rstport
);
68 static int stih407_usb2_exit_port(struct phy
*phy
)
70 struct stih407_usb2_picophy
*phy_dev
= phy_get_drvdata(phy
);
73 * Only port reset is asserted, phy global reset is kept untouched
74 * as other ports may still be active. When all ports are in reset
75 * state, assumption is made that power will be cut off on the phy, in
76 * case of suspend for instance. Theoretically, asserting individual
77 * reset (like here) or global reset should be equivalent.
79 return reset_control_assert(phy_dev
->rstport
);
82 static const struct phy_ops stih407_usb2_picophy_data
= {
83 .init
= stih407_usb2_init_port
,
84 .exit
= stih407_usb2_exit_port
,
88 static int stih407_usb2_picophy_probe(struct platform_device
*pdev
)
90 struct stih407_usb2_picophy
*phy_dev
;
91 struct device
*dev
= &pdev
->dev
;
92 struct device_node
*np
= dev
->of_node
;
93 struct phy_provider
*phy_provider
;
97 phy_dev
= devm_kzalloc(dev
, sizeof(*phy_dev
), GFP_KERNEL
);
102 dev_set_drvdata(dev
, phy_dev
);
104 phy_dev
->rstc
= devm_reset_control_get_shared(dev
, "global");
105 if (IS_ERR(phy_dev
->rstc
)) {
106 dev_err(dev
, "failed to ctrl picoPHY reset\n");
107 return PTR_ERR(phy_dev
->rstc
);
110 phy_dev
->rstport
= devm_reset_control_get_exclusive(dev
, "port");
111 if (IS_ERR(phy_dev
->rstport
)) {
112 dev_err(dev
, "failed to ctrl picoPHY reset\n");
113 return PTR_ERR(phy_dev
->rstport
);
116 /* Reset port by default: only deassert it in phy init */
117 reset_control_assert(phy_dev
->rstport
);
119 phy_dev
->regmap
= syscon_regmap_lookup_by_phandle(np
, "st,syscfg");
120 if (IS_ERR(phy_dev
->regmap
)) {
121 dev_err(dev
, "No syscfg phandle specified\n");
122 return PTR_ERR(phy_dev
->regmap
);
125 ret
= of_property_read_u32_index(np
, "st,syscfg", PHYPARAM_REG
,
128 dev_err(dev
, "can't get phyparam offset (%d)\n", ret
);
132 ret
= of_property_read_u32_index(np
, "st,syscfg", PHYCTRL_REG
,
135 dev_err(dev
, "can't get phyctrl offset (%d)\n", ret
);
139 phy
= devm_phy_create(dev
, NULL
, &stih407_usb2_picophy_data
);
141 dev_err(dev
, "failed to create Display Port PHY\n");
146 phy_set_drvdata(phy
, phy_dev
);
148 phy_provider
= devm_of_phy_provider_register(dev
, of_phy_simple_xlate
);
149 if (IS_ERR(phy_provider
))
150 return PTR_ERR(phy_provider
);
152 dev_info(dev
, "STiH407 USB Generic picoPHY driver probed!");
157 static const struct of_device_id stih407_usb2_picophy_of_match
[] = {
158 { .compatible
= "st,stih407-usb2-phy" },
162 MODULE_DEVICE_TABLE(of
, stih407_usb2_picophy_of_match
);
164 static struct platform_driver stih407_usb2_picophy_driver
= {
165 .probe
= stih407_usb2_picophy_probe
,
167 .name
= "stih407-usb-genphy",
168 .of_match_table
= stih407_usb2_picophy_of_match
,
172 module_platform_driver(stih407_usb2_picophy_driver
);
174 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
175 MODULE_DESCRIPTION("STMicroelectronics Generic picoPHY driver for STiH407");
176 MODULE_LICENSE("GPL v2");