2 * Copyright (C) 2016 Linaro Ltd
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
8 #include <linux/module.h>
9 #include <linux/ulpi/driver.h>
10 #include <linux/ulpi/regs.h>
11 #include <linux/pinctrl/consumer.h>
12 #include <linux/pinctrl/pinctrl-state.h>
13 #include <linux/delay.h>
14 #include <linux/clk.h>
18 #define ULPI_HSIC_CFG 0x30
19 #define ULPI_HSIC_IO_CAL 0x33
21 struct qcom_usb_hsic_phy
{
27 struct clk
*cal_sleep_clk
;
30 static int qcom_usb_hsic_phy_power_on(struct phy
*phy
)
32 struct qcom_usb_hsic_phy
*uphy
= phy_get_drvdata(phy
);
33 struct ulpi
*ulpi
= uphy
->ulpi
;
34 struct pinctrl_state
*pins_default
;
37 ret
= clk_prepare_enable(uphy
->phy_clk
);
41 ret
= clk_prepare_enable(uphy
->cal_clk
);
45 ret
= clk_prepare_enable(uphy
->cal_sleep_clk
);
49 /* Set periodic calibration interval to ~2.048sec in HSIC_IO_CAL_REG */
50 ret
= ulpi_write(ulpi
, ULPI_HSIC_IO_CAL
, 0xff);
54 /* Enable periodic IO calibration in HSIC_CFG register */
55 ret
= ulpi_write(ulpi
, ULPI_HSIC_CFG
, 0xa8);
59 /* Configure pins for HSIC functionality */
60 pins_default
= pinctrl_lookup_state(uphy
->pctl
, PINCTRL_STATE_DEFAULT
);
61 if (IS_ERR(pins_default
))
62 return PTR_ERR(pins_default
);
64 ret
= pinctrl_select_state(uphy
->pctl
, pins_default
);
68 /* Enable HSIC mode in HSIC_CFG register */
69 ret
= ulpi_write(ulpi
, ULPI_SET(ULPI_HSIC_CFG
), 0x01);
73 /* Disable auto-resume */
74 ret
= ulpi_write(ulpi
, ULPI_CLR(ULPI_IFC_CTRL
),
75 ULPI_IFC_CTRL_AUTORESUME
);
81 clk_disable_unprepare(uphy
->cal_sleep_clk
);
83 clk_disable_unprepare(uphy
->cal_clk
);
85 clk_disable_unprepare(uphy
->phy_clk
);
89 static int qcom_usb_hsic_phy_power_off(struct phy
*phy
)
91 struct qcom_usb_hsic_phy
*uphy
= phy_get_drvdata(phy
);
93 clk_disable_unprepare(uphy
->cal_sleep_clk
);
94 clk_disable_unprepare(uphy
->cal_clk
);
95 clk_disable_unprepare(uphy
->phy_clk
);
100 static const struct phy_ops qcom_usb_hsic_phy_ops
= {
101 .power_on
= qcom_usb_hsic_phy_power_on
,
102 .power_off
= qcom_usb_hsic_phy_power_off
,
103 .owner
= THIS_MODULE
,
106 static int qcom_usb_hsic_phy_probe(struct ulpi
*ulpi
)
108 struct qcom_usb_hsic_phy
*uphy
;
109 struct phy_provider
*p
;
112 uphy
= devm_kzalloc(&ulpi
->dev
, sizeof(*uphy
), GFP_KERNEL
);
115 ulpi_set_drvdata(ulpi
, uphy
);
118 uphy
->pctl
= devm_pinctrl_get(&ulpi
->dev
);
119 if (IS_ERR(uphy
->pctl
))
120 return PTR_ERR(uphy
->pctl
);
122 uphy
->phy_clk
= clk
= devm_clk_get(&ulpi
->dev
, "phy");
126 uphy
->cal_clk
= clk
= devm_clk_get(&ulpi
->dev
, "cal");
130 uphy
->cal_sleep_clk
= clk
= devm_clk_get(&ulpi
->dev
, "cal_sleep");
134 uphy
->phy
= devm_phy_create(&ulpi
->dev
, ulpi
->dev
.of_node
,
135 &qcom_usb_hsic_phy_ops
);
136 if (IS_ERR(uphy
->phy
))
137 return PTR_ERR(uphy
->phy
);
138 phy_set_drvdata(uphy
->phy
, uphy
);
140 p
= devm_of_phy_provider_register(&ulpi
->dev
, of_phy_simple_xlate
);
141 return PTR_ERR_OR_ZERO(p
);
144 static const struct of_device_id qcom_usb_hsic_phy_match
[] = {
145 { .compatible
= "qcom,usb-hsic-phy", },
148 MODULE_DEVICE_TABLE(of
, qcom_usb_hsic_phy_match
);
150 static struct ulpi_driver qcom_usb_hsic_phy_driver
= {
151 .probe
= qcom_usb_hsic_phy_probe
,
153 .name
= "qcom_usb_hsic_phy",
154 .of_match_table
= qcom_usb_hsic_phy_match
,
157 module_ulpi_driver(qcom_usb_hsic_phy_driver
);
159 MODULE_DESCRIPTION("Qualcomm USB HSIC phy");
160 MODULE_LICENSE("GPL v2");