Lines Matching refs:info
66 struct usb_conn_info *info; in usb_conn_detect_cable() local
70 info = container_of(to_delayed_work(work), in usb_conn_detect_cable()
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()
116 static void usb_conn_queue_dwork(struct usb_conn_info *info, in usb_conn_queue_dwork() argument
119 queue_delayed_work(system_power_efficient_wq, &info->dw_det, delay); in usb_conn_queue_dwork()
124 struct usb_conn_info *info = dev_id; in usb_conn_isr() local
126 usb_conn_queue_dwork(info, info->debounce_jiffies); in usb_conn_isr()
139 struct usb_conn_info *info = power_supply_get_drvdata(psy); in usb_charger_get_property() local
143 val->intval = info->last_role == USB_ROLE_DEVICE; in usb_charger_get_property()
152 static int usb_conn_psy_register(struct usb_conn_info *info) in usb_conn_psy_register() argument
154 struct device *dev = info->dev; in usb_conn_psy_register()
155 struct power_supply_desc *desc = &info->desc; in usb_conn_psy_register()
165 cfg.drv_data = info; 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()
177 struct usb_conn_info *info; in usb_conn_probe() local
180 info = devm_kzalloc(dev, sizeof(*info), GFP_KERNEL); in usb_conn_probe()
181 if (!info) 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()
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()
219 ret = usb_conn_psy_register(info); 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()
257 platform_set_drvdata(pdev, info); in usb_conn_probe()
261 usb_conn_queue_dwork(info, 0); in usb_conn_probe()
266 usb_role_switch_put(info->role_sw); in usb_conn_probe()
272 struct usb_conn_info *info = platform_get_drvdata(pdev); in usb_conn_remove() local
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()
286 struct usb_conn_info *info = dev_get_drvdata(dev); in usb_conn_suspend() local
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()
308 struct usb_conn_info *info = dev_get_drvdata(dev); in usb_conn_resume() local
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()
325 usb_conn_queue_dwork(info, 0); in usb_conn_resume()