Lines Matching full:info
67 struct usb_conn_info *info; in usb_conn_detect_cable() local
71 info = container_of(to_delayed_work(work), in usb_conn_detect_cable()
75 id = info->id_gpiod ? in usb_conn_detect_cable()
76 gpiod_get_value_cansleep(info->id_gpiod) : 1; in usb_conn_detect_cable()
77 vbus = info->vbus_gpiod ? in usb_conn_detect_cable()
78 gpiod_get_value_cansleep(info->vbus_gpiod) : id; in usb_conn_detect_cable()
87 dev_dbg(info->dev, "role %s -> %s, gpios: id %d, vbus %d\n", in usb_conn_detect_cable()
88 usb_role_string(info->last_role), usb_role_string(role), id, vbus); in usb_conn_detect_cable()
90 if (!info->initial_detection && info->last_role == role) { in usb_conn_detect_cable()
91 dev_warn(info->dev, "repeated role: %s\n", usb_role_string(role)); in usb_conn_detect_cable()
95 info->initial_detection = false; in usb_conn_detect_cable()
97 if (info->last_role == USB_ROLE_HOST && info->vbus) in usb_conn_detect_cable()
98 regulator_disable(info->vbus); in usb_conn_detect_cable()
100 ret = usb_role_switch_set_role(info->role_sw, role); in usb_conn_detect_cable()
102 dev_err(info->dev, "failed to set role: %d\n", ret); in usb_conn_detect_cable()
104 if (role == USB_ROLE_HOST && info->vbus) { in usb_conn_detect_cable()
105 ret = regulator_enable(info->vbus); in usb_conn_detect_cable()
107 dev_err(info->dev, "enable vbus regulator failed\n"); in usb_conn_detect_cable()
110 info->last_role = role; in usb_conn_detect_cable()
112 if (info->vbus) in usb_conn_detect_cable()
113 dev_dbg(info->dev, "vbus regulator is %s\n", in usb_conn_detect_cable()
114 regulator_is_enabled(info->vbus) ? "enabled" : "disabled"); in usb_conn_detect_cable()
116 power_supply_changed(info->charger); in usb_conn_detect_cable()
119 static void usb_conn_queue_dwork(struct usb_conn_info *info, in usb_conn_queue_dwork() argument
122 queue_delayed_work(system_power_efficient_wq, &info->dw_det, delay); in usb_conn_queue_dwork()
127 struct usb_conn_info *info = dev_id; in usb_conn_isr() local
129 usb_conn_queue_dwork(info, info->debounce_jiffies); in usb_conn_isr()
142 struct usb_conn_info *info = power_supply_get_drvdata(psy); in usb_charger_get_property() local
146 val->intval = info->last_role == USB_ROLE_DEVICE; in usb_charger_get_property()
155 static int usb_conn_psy_register(struct usb_conn_info *info) in usb_conn_psy_register() argument
157 struct device *dev = info->dev; in usb_conn_psy_register()
158 struct power_supply_desc *desc = &info->desc; in usb_conn_psy_register()
168 cfg.drv_data = info; in usb_conn_psy_register()
170 info->charger = devm_power_supply_register(dev, desc, &cfg); in usb_conn_psy_register()
171 if (IS_ERR(info->charger)) in usb_conn_psy_register()
174 return PTR_ERR_OR_ZERO(info->charger); in usb_conn_psy_register()
180 struct usb_conn_info *info; in usb_conn_probe() local
183 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); in usb_conn_probe()
184 if (!info) in usb_conn_probe()
187 info->dev = dev; in usb_conn_probe()
188 info->id_gpiod = devm_gpiod_get_optional(dev, "id", GPIOD_IN); in usb_conn_probe()
189 if (IS_ERR(info->id_gpiod)) in usb_conn_probe()
190 return PTR_ERR(info->id_gpiod); in usb_conn_probe()
192 info->vbus_gpiod = devm_gpiod_get_optional(dev, "vbus", GPIOD_IN); in usb_conn_probe()
193 if (IS_ERR(info->vbus_gpiod)) in usb_conn_probe()
194 return PTR_ERR(info->vbus_gpiod); in usb_conn_probe()
196 if (!info->id_gpiod && !info->vbus_gpiod) { in usb_conn_probe()
201 if (info->id_gpiod) in usb_conn_probe()
202 ret = gpiod_set_debounce(info->id_gpiod, USB_GPIO_DEB_US); in usb_conn_probe()
203 if (!ret && info->vbus_gpiod) in usb_conn_probe()
204 ret = gpiod_set_debounce(info->vbus_gpiod, USB_GPIO_DEB_US); in usb_conn_probe()
206 info->debounce_jiffies = msecs_to_jiffies(USB_GPIO_DEB_MS); in usb_conn_probe()
208 INIT_DELAYED_WORK(&info->dw_det, usb_conn_detect_cable); in usb_conn_probe()
210 info->vbus = devm_regulator_get_optional(dev, "vbus"); in usb_conn_probe()
211 if (PTR_ERR(info->vbus) == -ENODEV) in usb_conn_probe()
212 info->vbus = NULL; in usb_conn_probe()
214 if (IS_ERR(info->vbus)) in usb_conn_probe()
215 return dev_err_probe(dev, PTR_ERR(info->vbus), "failed to get vbus\n"); in usb_conn_probe()
217 info->role_sw = usb_role_switch_get(dev); in usb_conn_probe()
218 if (IS_ERR(info->role_sw)) in usb_conn_probe()
219 return dev_err_probe(dev, PTR_ERR(info->role_sw), in usb_conn_probe()
222 ret = usb_conn_psy_register(info); in usb_conn_probe()
226 if (info->id_gpiod) { in usb_conn_probe()
227 info->id_irq = gpiod_to_irq(info->id_gpiod); in usb_conn_probe()
228 if (info->id_irq < 0) { in usb_conn_probe()
230 ret = info->id_irq; in usb_conn_probe()
234 ret = devm_request_threaded_irq(dev, info->id_irq, NULL, in usb_conn_probe()
236 pdev->name, info); in usb_conn_probe()
243 if (info->vbus_gpiod) { in usb_conn_probe()
244 info->vbus_irq = gpiod_to_irq(info->vbus_gpiod); in usb_conn_probe()
245 if (info->vbus_irq < 0) { in usb_conn_probe()
247 ret = info->vbus_irq; in usb_conn_probe()
251 ret = devm_request_threaded_irq(dev, info->vbus_irq, NULL, in usb_conn_probe()
253 pdev->name, info); in usb_conn_probe()
260 platform_set_drvdata(pdev, info); in usb_conn_probe()
264 info->initial_detection = true; in usb_conn_probe()
265 usb_conn_queue_dwork(info, 0); in usb_conn_probe()
270 usb_role_switch_put(info->role_sw); in usb_conn_probe()
276 struct usb_conn_info *info = platform_get_drvdata(pdev); in usb_conn_remove() local
278 cancel_delayed_work_sync(&info->dw_det); in usb_conn_remove()
280 if (info->last_role == USB_ROLE_HOST && info->vbus) in usb_conn_remove()
281 regulator_disable(info->vbus); in usb_conn_remove()
283 usb_role_switch_put(info->role_sw); in usb_conn_remove()
288 struct usb_conn_info *info = dev_get_drvdata(dev); in usb_conn_suspend() local
291 if (info->id_gpiod) in usb_conn_suspend()
292 enable_irq_wake(info->id_irq); in usb_conn_suspend()
293 if (info->vbus_gpiod) in usb_conn_suspend()
294 enable_irq_wake(info->vbus_irq); in usb_conn_suspend()
298 if (info->id_gpiod) in usb_conn_suspend()
299 disable_irq(info->id_irq); in usb_conn_suspend()
300 if (info->vbus_gpiod) in usb_conn_suspend()
301 disable_irq(info->vbus_irq); in usb_conn_suspend()
310 struct usb_conn_info *info = dev_get_drvdata(dev); in usb_conn_resume() local
313 if (info->id_gpiod) in usb_conn_resume()
314 disable_irq_wake(info->id_irq); in usb_conn_resume()
315 if (info->vbus_gpiod) in usb_conn_resume()
316 disable_irq_wake(info->vbus_irq); in usb_conn_resume()
322 if (info->id_gpiod) in usb_conn_resume()
323 enable_irq(info->id_irq); in usb_conn_resume()
324 if (info->vbus_gpiod) in usb_conn_resume()
325 enable_irq(info->vbus_irq); in usb_conn_resume()
327 usb_conn_queue_dwork(info, 0); in usb_conn_resume()