Lines Matching refs:hisi_hikey_usb
33 struct hisi_hikey_usb { struct
52 static void hub_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, int value) in hub_power_ctrl() argument
56 if (!hisi_hikey_usb->regulator) in hub_power_ctrl()
59 status = regulator_is_enabled(hisi_hikey_usb->regulator); in hub_power_ctrl()
64 ret = regulator_enable(hisi_hikey_usb->regulator); in hub_power_ctrl()
66 ret = regulator_disable(hisi_hikey_usb->regulator); in hub_power_ctrl()
69 dev_err(hisi_hikey_usb->dev, in hub_power_ctrl()
74 static void usb_switch_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, in usb_switch_ctrl() argument
77 if (!hisi_hikey_usb->otg_switch) in usb_switch_ctrl()
80 gpiod_set_value_cansleep(hisi_hikey_usb->otg_switch, switch_to); in usb_switch_ctrl()
83 static void usb_typec_power_ctrl(struct hisi_hikey_usb *hisi_hikey_usb, in usb_typec_power_ctrl() argument
86 if (!hisi_hikey_usb->typec_vbus) in usb_typec_power_ctrl()
89 gpiod_set_value_cansleep(hisi_hikey_usb->typec_vbus, value); in usb_typec_power_ctrl()
94 struct hisi_hikey_usb *hisi_hikey_usb = container_of(work, in relay_set_role_switch() local
95 struct hisi_hikey_usb, in relay_set_role_switch()
100 if (!hisi_hikey_usb || !hisi_hikey_usb->dev_role_sw) in relay_set_role_switch()
103 mutex_lock(&hisi_hikey_usb->lock); in relay_set_role_switch()
104 switch (hisi_hikey_usb->role) { in relay_set_role_switch()
106 usb_typec_power_ctrl(hisi_hikey_usb, TYPEC_VBUS_POWER_OFF); in relay_set_role_switch()
107 usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_HUB); in relay_set_role_switch()
108 hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_ON); in relay_set_role_switch()
111 hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_OFF); in relay_set_role_switch()
112 usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_TYPEC); in relay_set_role_switch()
113 usb_typec_power_ctrl(hisi_hikey_usb, TYPEC_VBUS_POWER_ON); in relay_set_role_switch()
116 hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_OFF); in relay_set_role_switch()
117 usb_typec_power_ctrl(hisi_hikey_usb, TYPEC_VBUS_POWER_OFF); in relay_set_role_switch()
118 usb_switch_ctrl(hisi_hikey_usb, USB_SWITCH_TO_TYPEC); in relay_set_role_switch()
123 sw = hisi_hikey_usb->dev_role_sw; in relay_set_role_switch()
124 role = hisi_hikey_usb->role; in relay_set_role_switch()
125 mutex_unlock(&hisi_hikey_usb->lock); in relay_set_role_switch()
132 struct hisi_hikey_usb *hisi_hikey_usb = usb_role_switch_get_drvdata(sw); in hub_usb_role_switch_set() local
134 if (!hisi_hikey_usb || !hisi_hikey_usb->dev_role_sw) in hub_usb_role_switch_set()
137 mutex_lock(&hisi_hikey_usb->lock); in hub_usb_role_switch_set()
138 hisi_hikey_usb->role = role; in hub_usb_role_switch_set()
139 mutex_unlock(&hisi_hikey_usb->lock); in hub_usb_role_switch_set()
141 schedule_work(&hisi_hikey_usb->work); in hub_usb_role_switch_set()
147 struct hisi_hikey_usb *hisi_hikey_usb) in hisi_hikey_usb_of_role_switch() argument
155 hisi_hikey_usb->otg_switch = devm_gpiod_get(dev, "otg-switch", in hisi_hikey_usb_of_role_switch()
157 if (IS_ERR(hisi_hikey_usb->otg_switch)) { in hisi_hikey_usb_of_role_switch()
159 PTR_ERR(hisi_hikey_usb->otg_switch)); in hisi_hikey_usb_of_role_switch()
160 return PTR_ERR(hisi_hikey_usb->otg_switch); in hisi_hikey_usb_of_role_switch()
163 hisi_hikey_usb->typec_vbus = devm_gpiod_get(dev, "typec-vbus", in hisi_hikey_usb_of_role_switch()
165 if (IS_ERR(hisi_hikey_usb->typec_vbus)) { in hisi_hikey_usb_of_role_switch()
167 PTR_ERR(hisi_hikey_usb->typec_vbus)); in hisi_hikey_usb_of_role_switch()
168 return PTR_ERR(hisi_hikey_usb->typec_vbus); in hisi_hikey_usb_of_role_switch()
171 hisi_hikey_usb->reset = devm_gpiod_get_optional(dev, in hisi_hikey_usb_of_role_switch()
174 if (IS_ERR(hisi_hikey_usb->reset)) { in hisi_hikey_usb_of_role_switch()
176 PTR_ERR(hisi_hikey_usb->reset)); in hisi_hikey_usb_of_role_switch()
177 return PTR_ERR(hisi_hikey_usb->reset); in hisi_hikey_usb_of_role_switch()
180 hisi_hikey_usb->dev_role_sw = usb_role_switch_get(dev); in hisi_hikey_usb_of_role_switch()
181 if (!hisi_hikey_usb->dev_role_sw) in hisi_hikey_usb_of_role_switch()
183 if (IS_ERR(hisi_hikey_usb->dev_role_sw)) { in hisi_hikey_usb_of_role_switch()
185 PTR_ERR(hisi_hikey_usb->dev_role_sw)); in hisi_hikey_usb_of_role_switch()
186 return PTR_ERR(hisi_hikey_usb->dev_role_sw); in hisi_hikey_usb_of_role_switch()
189 INIT_WORK(&hisi_hikey_usb->work, relay_set_role_switch); in hisi_hikey_usb_of_role_switch()
193 hub_role_switch.driver_data = hisi_hikey_usb; in hisi_hikey_usb_of_role_switch()
195 hisi_hikey_usb->hub_role_sw = usb_role_switch_register(dev, in hisi_hikey_usb_of_role_switch()
198 if (IS_ERR(hisi_hikey_usb->hub_role_sw)) { in hisi_hikey_usb_of_role_switch()
201 PTR_ERR(hisi_hikey_usb->hub_role_sw)); in hisi_hikey_usb_of_role_switch()
202 usb_role_switch_put(hisi_hikey_usb->dev_role_sw); in hisi_hikey_usb_of_role_switch()
203 return PTR_ERR(hisi_hikey_usb->hub_role_sw); in hisi_hikey_usb_of_role_switch()
212 struct hisi_hikey_usb *hisi_hikey_usb; in hisi_hikey_usb_probe() local
215 hisi_hikey_usb = devm_kzalloc(dev, sizeof(*hisi_hikey_usb), GFP_KERNEL); in hisi_hikey_usb_probe()
216 if (!hisi_hikey_usb) in hisi_hikey_usb_probe()
219 hisi_hikey_usb->dev = &pdev->dev; in hisi_hikey_usb_probe()
220 mutex_init(&hisi_hikey_usb->lock); in hisi_hikey_usb_probe()
222 hisi_hikey_usb->regulator = devm_regulator_get(dev, "hub-vdd"); in hisi_hikey_usb_probe()
223 if (IS_ERR(hisi_hikey_usb->regulator)) { in hisi_hikey_usb_probe()
224 if (PTR_ERR(hisi_hikey_usb->regulator) == -EPROBE_DEFER) { in hisi_hikey_usb_probe()
226 return PTR_ERR(hisi_hikey_usb->regulator); in hisi_hikey_usb_probe()
229 PTR_ERR(hisi_hikey_usb->regulator)); in hisi_hikey_usb_probe()
230 return PTR_ERR(hisi_hikey_usb->regulator); in hisi_hikey_usb_probe()
233 ret = hisi_hikey_usb_of_role_switch(pdev, hisi_hikey_usb); in hisi_hikey_usb_probe()
237 platform_set_drvdata(pdev, hisi_hikey_usb); in hisi_hikey_usb_probe()
244 struct hisi_hikey_usb *hisi_hikey_usb = platform_get_drvdata(pdev); in hisi_hikey_usb_remove() local
246 if (hisi_hikey_usb->hub_role_sw) { in hisi_hikey_usb_remove()
247 usb_role_switch_unregister(hisi_hikey_usb->hub_role_sw); in hisi_hikey_usb_remove()
249 if (hisi_hikey_usb->dev_role_sw) in hisi_hikey_usb_remove()
250 usb_role_switch_put(hisi_hikey_usb->dev_role_sw); in hisi_hikey_usb_remove()
252 hub_power_ctrl(hisi_hikey_usb, HUB_VBUS_POWER_OFF); in hisi_hikey_usb_remove()