Lines Matching +full:en +full:- +full:usb

1 // SPDX-License-Identifier: GPL-2.0
3 * Support for usb functionality of Hikey series boards
6 * Copyright (C) 2017-2018 Hilisicon Electronics Co., Ltd.
21 #include <linux/usb/role.h>
55 if (!hisi_hikey_usb->regulator) in hub_power_ctrl()
58 status = regulator_is_enabled(hisi_hikey_usb->regulator); in hub_power_ctrl()
63 ret = regulator_enable(hisi_hikey_usb->regulator); in hub_power_ctrl()
65 ret = regulator_disable(hisi_hikey_usb->regulator); in hub_power_ctrl()
68 dev_err(hisi_hikey_usb->dev, in hub_power_ctrl()
76 if (!hisi_hikey_usb->otg_switch) in usb_switch_ctrl()
79 gpiod_set_value_cansleep(hisi_hikey_usb->otg_switch, switch_to); in usb_switch_ctrl()
85 if (!hisi_hikey_usb->typec_vbus) in usb_typec_power_ctrl()
88 gpiod_set_value_cansleep(hisi_hikey_usb->typec_vbus, value); in usb_typec_power_ctrl()
99 if (!hisi_hikey_usb || !hisi_hikey_usb->dev_role_sw) in relay_set_role_switch()
102 mutex_lock(&hisi_hikey_usb->lock); in relay_set_role_switch()
103 switch (hisi_hikey_usb->role) { in relay_set_role_switch()
122 sw = hisi_hikey_usb->dev_role_sw; in relay_set_role_switch()
123 role = hisi_hikey_usb->role; in relay_set_role_switch()
124 mutex_unlock(&hisi_hikey_usb->lock); in relay_set_role_switch()
133 if (!hisi_hikey_usb || !hisi_hikey_usb->dev_role_sw) in hub_usb_role_switch_set()
134 return -EINVAL; in hub_usb_role_switch_set()
136 mutex_lock(&hisi_hikey_usb->lock); in hub_usb_role_switch_set()
137 hisi_hikey_usb->role = role; in hub_usb_role_switch_set()
138 mutex_unlock(&hisi_hikey_usb->lock); in hub_usb_role_switch_set()
140 schedule_work(&hisi_hikey_usb->work); in hub_usb_role_switch_set()
148 struct device *dev = &pdev->dev; in hisi_hikey_usb_of_role_switch()
151 if (!device_property_read_bool(dev, "usb-role-switch")) in hisi_hikey_usb_of_role_switch()
154 hisi_hikey_usb->otg_switch = devm_gpiod_get(dev, "otg-switch", in hisi_hikey_usb_of_role_switch()
156 if (IS_ERR(hisi_hikey_usb->otg_switch)) { in hisi_hikey_usb_of_role_switch()
157 dev_err(dev, "get otg-switch failed with error %ld\n", in hisi_hikey_usb_of_role_switch()
158 PTR_ERR(hisi_hikey_usb->otg_switch)); in hisi_hikey_usb_of_role_switch()
159 return PTR_ERR(hisi_hikey_usb->otg_switch); in hisi_hikey_usb_of_role_switch()
162 hisi_hikey_usb->typec_vbus = devm_gpiod_get(dev, "typec-vbus", in hisi_hikey_usb_of_role_switch()
164 if (IS_ERR(hisi_hikey_usb->typec_vbus)) { in hisi_hikey_usb_of_role_switch()
165 dev_err(dev, "get typec-vbus failed with error %ld\n", in hisi_hikey_usb_of_role_switch()
166 PTR_ERR(hisi_hikey_usb->typec_vbus)); in hisi_hikey_usb_of_role_switch()
167 return PTR_ERR(hisi_hikey_usb->typec_vbus); in hisi_hikey_usb_of_role_switch()
170 hisi_hikey_usb->reset = devm_gpiod_get_optional(dev, in hisi_hikey_usb_of_role_switch()
171 "hub-reset-en", in hisi_hikey_usb_of_role_switch()
173 if (IS_ERR(hisi_hikey_usb->reset)) { in hisi_hikey_usb_of_role_switch()
174 dev_err(dev, "get hub-reset-en failed with error %ld\n", in hisi_hikey_usb_of_role_switch()
175 PTR_ERR(hisi_hikey_usb->reset)); in hisi_hikey_usb_of_role_switch()
176 return PTR_ERR(hisi_hikey_usb->reset); in hisi_hikey_usb_of_role_switch()
179 hisi_hikey_usb->dev_role_sw = usb_role_switch_get(dev); in hisi_hikey_usb_of_role_switch()
180 if (!hisi_hikey_usb->dev_role_sw) in hisi_hikey_usb_of_role_switch()
181 return -EPROBE_DEFER; in hisi_hikey_usb_of_role_switch()
182 if (IS_ERR(hisi_hikey_usb->dev_role_sw)) { in hisi_hikey_usb_of_role_switch()
184 PTR_ERR(hisi_hikey_usb->dev_role_sw)); in hisi_hikey_usb_of_role_switch()
185 return PTR_ERR(hisi_hikey_usb->dev_role_sw); in hisi_hikey_usb_of_role_switch()
188 INIT_WORK(&hisi_hikey_usb->work, relay_set_role_switch); in hisi_hikey_usb_of_role_switch()
194 hisi_hikey_usb->hub_role_sw = usb_role_switch_register(dev, in hisi_hikey_usb_of_role_switch()
197 if (IS_ERR(hisi_hikey_usb->hub_role_sw)) { in hisi_hikey_usb_of_role_switch()
200 PTR_ERR(hisi_hikey_usb->hub_role_sw)); in hisi_hikey_usb_of_role_switch()
201 usb_role_switch_put(hisi_hikey_usb->dev_role_sw); in hisi_hikey_usb_of_role_switch()
202 return PTR_ERR(hisi_hikey_usb->hub_role_sw); in hisi_hikey_usb_of_role_switch()
210 struct device *dev = &pdev->dev; in hisi_hikey_usb_probe()
216 return -ENOMEM; in hisi_hikey_usb_probe()
218 hisi_hikey_usb->dev = &pdev->dev; in hisi_hikey_usb_probe()
219 mutex_init(&hisi_hikey_usb->lock); in hisi_hikey_usb_probe()
221 hisi_hikey_usb->regulator = devm_regulator_get(dev, "hub-vdd"); in hisi_hikey_usb_probe()
222 if (IS_ERR(hisi_hikey_usb->regulator)) { in hisi_hikey_usb_probe()
223 if (PTR_ERR(hisi_hikey_usb->regulator) == -EPROBE_DEFER) { in hisi_hikey_usb_probe()
224 dev_info(dev, "waiting for hub-vdd-supply\n"); in hisi_hikey_usb_probe()
225 return PTR_ERR(hisi_hikey_usb->regulator); in hisi_hikey_usb_probe()
227 dev_err(dev, "get hub-vdd-supply failed with error %ld\n", in hisi_hikey_usb_probe()
228 PTR_ERR(hisi_hikey_usb->regulator)); in hisi_hikey_usb_probe()
229 return PTR_ERR(hisi_hikey_usb->regulator); in hisi_hikey_usb_probe()
245 if (hisi_hikey_usb->hub_role_sw) { in hisi_hikey_usb_remove()
246 usb_role_switch_unregister(hisi_hikey_usb->hub_role_sw); in hisi_hikey_usb_remove()
248 if (hisi_hikey_usb->dev_role_sw) in hisi_hikey_usb_remove()
249 usb_role_switch_put(hisi_hikey_usb->dev_role_sw); in hisi_hikey_usb_remove()
273 MODULE_DESCRIPTION("Driver Support for USB functionality of Hikey");