Lines Matching +full:inactive +full:- +full:delay +full:- +full:ms
1 // SPDX-License-Identifier: GPL-2.0
9 * Some code borrowed from drivers/extcon/extcon-usb-gpio.c
24 #define USB_GPIO_DEB_MS 20 /* ms */
50 * so if "HOST" is active (i.e. ID is 0) we keep "DEVICE" inactive
54 * ------------------------------------
61 * - VBUS only - we want to distinguish between [1] and [2], so ID is always 1
62 * - ID only - we want to distinguish between [1] and [4], so VBUS = ID
74 id = info->id_gpiod ? in usb_conn_detect_cable()
75 gpiod_get_value_cansleep(info->id_gpiod) : 1; in usb_conn_detect_cable()
76 vbus = info->vbus_gpiod ? in usb_conn_detect_cable()
77 gpiod_get_value_cansleep(info->vbus_gpiod) : id; in usb_conn_detect_cable()
86 dev_dbg(info->dev, "role %s -> %s, gpios: id %d, vbus %d\n", in usb_conn_detect_cable()
87 usb_role_string(info->last_role), usb_role_string(role), id, vbus); in usb_conn_detect_cable()
89 if (info->last_role == role) { in usb_conn_detect_cable()
90 dev_warn(info->dev, "repeated role: %s\n", usb_role_string(role)); in usb_conn_detect_cable()
94 if (info->last_role == USB_ROLE_HOST && info->vbus) in usb_conn_detect_cable()
95 regulator_disable(info->vbus); in usb_conn_detect_cable()
97 ret = usb_role_switch_set_role(info->role_sw, role); in usb_conn_detect_cable()
99 dev_err(info->dev, "failed to set role: %d\n", ret); in usb_conn_detect_cable()
101 if (role == USB_ROLE_HOST && info->vbus) { in usb_conn_detect_cable()
102 ret = regulator_enable(info->vbus); in usb_conn_detect_cable()
104 dev_err(info->dev, "enable vbus regulator failed\n"); in usb_conn_detect_cable()
107 info->last_role = role; in usb_conn_detect_cable()
109 if (info->vbus) in usb_conn_detect_cable()
110 dev_dbg(info->dev, "vbus regulator is %s\n", in usb_conn_detect_cable()
111 regulator_is_enabled(info->vbus) ? "enabled" : "disabled"); in usb_conn_detect_cable()
113 power_supply_changed(info->charger); in usb_conn_detect_cable()
117 unsigned long delay) in usb_conn_queue_dwork() argument
119 queue_delayed_work(system_power_efficient_wq, &info->dw_det, delay); in usb_conn_queue_dwork()
126 usb_conn_queue_dwork(info, info->debounce_jiffies); in usb_conn_isr()
143 val->intval = info->last_role == USB_ROLE_DEVICE; in usb_charger_get_property()
146 return -EINVAL; in usb_charger_get_property()
154 struct device *dev = info->dev; in usb_conn_psy_register()
155 struct power_supply_desc *desc = &info->desc; in usb_conn_psy_register()
157 .of_node = dev->of_node, in usb_conn_psy_register()
160 desc->name = "usb-charger"; in usb_conn_psy_register()
161 desc->properties = usb_charger_properties; in usb_conn_psy_register()
162 desc->num_properties = ARRAY_SIZE(usb_charger_properties); in usb_conn_psy_register()
163 desc->get_property = usb_charger_get_property; in usb_conn_psy_register()
164 desc->type = POWER_SUPPLY_TYPE_USB; in usb_conn_psy_register()
167 info->charger = devm_power_supply_register(dev, desc, &cfg); in usb_conn_psy_register()
168 if (IS_ERR(info->charger)) in usb_conn_psy_register()
171 return PTR_ERR_OR_ZERO(info->charger); in usb_conn_psy_register()
176 struct device *dev = &pdev->dev; in usb_conn_probe()
182 return -ENOMEM; in usb_conn_probe()
184 info->dev = dev; in usb_conn_probe()
185 info->id_gpiod = devm_gpiod_get_optional(dev, "id", GPIOD_IN); in usb_conn_probe()
186 if (IS_ERR(info->id_gpiod)) in usb_conn_probe()
187 return PTR_ERR(info->id_gpiod); in usb_conn_probe()
189 info->vbus_gpiod = devm_gpiod_get_optional(dev, "vbus", GPIOD_IN); in usb_conn_probe()
190 if (IS_ERR(info->vbus_gpiod)) in usb_conn_probe()
191 return PTR_ERR(info->vbus_gpiod); in usb_conn_probe()
193 if (!info->id_gpiod && !info->vbus_gpiod) { in usb_conn_probe()
195 return -ENODEV; in usb_conn_probe()
198 if (info->id_gpiod) in usb_conn_probe()
199 ret = gpiod_set_debounce(info->id_gpiod, USB_GPIO_DEB_US); in usb_conn_probe()
200 if (!ret && info->vbus_gpiod) in usb_conn_probe()
201 ret = gpiod_set_debounce(info->vbus_gpiod, USB_GPIO_DEB_US); in usb_conn_probe()
203 info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEB_MS); in usb_conn_probe()
205 INIT_DELAYED_WORK(&info->dw_det, usb_conn_detect_cable); in usb_conn_probe()
207 info->vbus = devm_regulator_get_optional(dev, "vbus"); in usb_conn_probe()
208 if (PTR_ERR(info->vbus) == -ENODEV) in usb_conn_probe()
209 info->vbus = NULL; in usb_conn_probe()
211 if (IS_ERR(info->vbus)) in usb_conn_probe()
212 return dev_err_probe(dev, PTR_ERR(info->vbus), "failed to get vbus\n"); in usb_conn_probe()
214 info->role_sw = usb_role_switch_get(dev); in usb_conn_probe()
215 if (IS_ERR(info->role_sw)) in usb_conn_probe()
216 return dev_err_probe(dev, PTR_ERR(info->role_sw), in usb_conn_probe()
223 if (info->id_gpiod) { in usb_conn_probe()
224 info->id_irq = gpiod_to_irq(info->id_gpiod); in usb_conn_probe()
225 if (info->id_irq < 0) { in usb_conn_probe()
227 ret = info->id_irq; in usb_conn_probe()
231 ret = devm_request_threaded_irq(dev, info->id_irq, NULL, in usb_conn_probe()
233 pdev->name, info); in usb_conn_probe()
240 if (info->vbus_gpiod) { in usb_conn_probe()
241 info->vbus_irq = gpiod_to_irq(info->vbus_gpiod); in usb_conn_probe()
242 if (info->vbus_irq < 0) { in usb_conn_probe()
244 ret = info->vbus_irq; in usb_conn_probe()
248 ret = devm_request_threaded_irq(dev, info->vbus_irq, NULL, in usb_conn_probe()
250 pdev->name, info); in usb_conn_probe()
258 device_set_wakeup_capable(&pdev->dev, true); in usb_conn_probe()
266 usb_role_switch_put(info->role_sw); in usb_conn_probe()
274 cancel_delayed_work_sync(&info->dw_det); in usb_conn_remove()
276 if (info->last_role == USB_ROLE_HOST && info->vbus) in usb_conn_remove()
277 regulator_disable(info->vbus); in usb_conn_remove()
279 usb_role_switch_put(info->role_sw); in usb_conn_remove()
289 if (info->id_gpiod) in usb_conn_suspend()
290 enable_irq_wake(info->id_irq); in usb_conn_suspend()
291 if (info->vbus_gpiod) in usb_conn_suspend()
292 enable_irq_wake(info->vbus_irq); in usb_conn_suspend()
296 if (info->id_gpiod) in usb_conn_suspend()
297 disable_irq(info->id_irq); in usb_conn_suspend()
298 if (info->vbus_gpiod) in usb_conn_suspend()
299 disable_irq(info->vbus_irq); in usb_conn_suspend()
311 if (info->id_gpiod) in usb_conn_resume()
312 disable_irq_wake(info->id_irq); in usb_conn_resume()
313 if (info->vbus_gpiod) in usb_conn_resume()
314 disable_irq_wake(info->vbus_irq); in usb_conn_resume()
320 if (info->id_gpiod) in usb_conn_resume()
321 enable_irq(info->id_irq); in usb_conn_resume()
322 if (info->vbus_gpiod) in usb_conn_resume()
323 enable_irq(info->vbus_irq); in usb_conn_resume()
334 { .compatible = "gpio-usb-b-connector", },
343 .name = "usb-conn-gpio",