1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2016 Linaro Ltd
5 #include <linux/module.h>
6 #include <linux/ulpi/driver.h>
7 #include <linux/ulpi/regs.h>
8 #include <linux/phy/phy.h>
9 #include <linux/pinctrl/consumer.h>
10 #include <linux/pinctrl/pinctrl-state.h>
11 #include <linux/delay.h>
12 #include <linux/clk.h>
14 #define ULPI_HSIC_CFG 0x30
15 #define ULPI_HSIC_IO_CAL 0x33
17 struct qcom_usb_hsic_phy
{
23 struct clk
*cal_sleep_clk
;
26 static int qcom_usb_hsic_phy_power_on(struct phy
*phy
)
28 struct qcom_usb_hsic_phy
*uphy
= phy_get_drvdata(phy
);
29 struct ulpi
*ulpi
= uphy
->ulpi
;
30 struct pinctrl_state
*pins_default
;
33 ret
= clk_prepare_enable(uphy
->phy_clk
);
37 ret
= clk_prepare_enable(uphy
->cal_clk
);
41 ret
= clk_prepare_enable(uphy
->cal_sleep_clk
);
45 /* Set periodic calibration interval to ~2.048sec in HSIC_IO_CAL_REG */
46 ret
= ulpi_write(ulpi
, ULPI_HSIC_IO_CAL
, 0xff);
50 /* Enable periodic IO calibration in HSIC_CFG register */
51 ret
= ulpi_write(ulpi
, ULPI_HSIC_CFG
, 0xa8);
55 /* Configure pins for HSIC functionality */
56 pins_default
= pinctrl_lookup_state(uphy
->pctl
, PINCTRL_STATE_DEFAULT
);
57 if (IS_ERR(pins_default
))
58 return PTR_ERR(pins_default
);
60 ret
= pinctrl_select_state(uphy
->pctl
, pins_default
);
64 /* Enable HSIC mode in HSIC_CFG register */
65 ret
= ulpi_write(ulpi
, ULPI_SET(ULPI_HSIC_CFG
), 0x01);
69 /* Disable auto-resume */
70 ret
= ulpi_write(ulpi
, ULPI_CLR(ULPI_IFC_CTRL
),
71 ULPI_IFC_CTRL_AUTORESUME
);
77 clk_disable_unprepare(uphy
->cal_sleep_clk
);
79 clk_disable_unprepare(uphy
->cal_clk
);
81 clk_disable_unprepare(uphy
->phy_clk
);
85 static int qcom_usb_hsic_phy_power_off(struct phy
*phy
)
87 struct qcom_usb_hsic_phy
*uphy
= phy_get_drvdata(phy
);
89 clk_disable_unprepare(uphy
->cal_sleep_clk
);
90 clk_disable_unprepare(uphy
->cal_clk
);
91 clk_disable_unprepare(uphy
->phy_clk
);
96 static const struct phy_ops qcom_usb_hsic_phy_ops
= {
97 .power_on
= qcom_usb_hsic_phy_power_on
,
98 .power_off
= qcom_usb_hsic_phy_power_off
,
102 static int qcom_usb_hsic_phy_probe(struct ulpi
*ulpi
)
104 struct qcom_usb_hsic_phy
*uphy
;
105 struct phy_provider
*p
;
108 uphy
= devm_kzalloc(&ulpi
->dev
, sizeof(*uphy
), GFP_KERNEL
);
111 ulpi_set_drvdata(ulpi
, uphy
);
114 uphy
->pctl
= devm_pinctrl_get(&ulpi
->dev
);
115 if (IS_ERR(uphy
->pctl
))
116 return PTR_ERR(uphy
->pctl
);
118 uphy
->phy_clk
= clk
= devm_clk_get(&ulpi
->dev
, "phy");
122 uphy
->cal_clk
= clk
= devm_clk_get(&ulpi
->dev
, "cal");
126 uphy
->cal_sleep_clk
= clk
= devm_clk_get(&ulpi
->dev
, "cal_sleep");
130 uphy
->phy
= devm_phy_create(&ulpi
->dev
, ulpi
->dev
.of_node
,
131 &qcom_usb_hsic_phy_ops
);
132 if (IS_ERR(uphy
->phy
))
133 return PTR_ERR(uphy
->phy
);
134 phy_set_drvdata(uphy
->phy
, uphy
);
136 p
= devm_of_phy_provider_register(&ulpi
->dev
, of_phy_simple_xlate
);
137 return PTR_ERR_OR_ZERO(p
);
140 static const struct of_device_id qcom_usb_hsic_phy_match
[] = {
141 { .compatible
= "qcom,usb-hsic-phy", },
144 MODULE_DEVICE_TABLE(of
, qcom_usb_hsic_phy_match
);
146 static struct ulpi_driver qcom_usb_hsic_phy_driver
= {
147 .probe
= qcom_usb_hsic_phy_probe
,
149 .name
= "qcom_usb_hsic_phy",
150 .of_match_table
= qcom_usb_hsic_phy_match
,
153 module_ulpi_driver(qcom_usb_hsic_phy_driver
);
155 MODULE_DESCRIPTION("Qualcomm USB HSIC phy");
156 MODULE_LICENSE("GPL v2");