Lines Matching +full:host +full:- +full:wakeup
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * Copyright (C) 2013 Texas Instruments Incorporated - https://www.ti.com
12 #include <linux/devm-helpers.h>
45 struct extcon_dev *edev = palmas_usb->edev; in palmas_vbus_irq_handler()
48 palmas_read(palmas_usb->palmas, PALMAS_INTERRUPT_BASE, in palmas_vbus_irq_handler()
52 if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) { in palmas_vbus_irq_handler()
53 palmas_usb->linkstat = PALMAS_USB_STATE_VBUS; in palmas_vbus_irq_handler()
55 dev_dbg(palmas_usb->dev, "USB cable is attached\n"); in palmas_vbus_irq_handler()
57 dev_dbg(palmas_usb->dev, in palmas_vbus_irq_handler()
61 if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) { in palmas_vbus_irq_handler()
62 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; in palmas_vbus_irq_handler()
64 dev_dbg(palmas_usb->dev, "USB cable is detached\n"); in palmas_vbus_irq_handler()
66 dev_dbg(palmas_usb->dev, in palmas_vbus_irq_handler()
78 struct extcon_dev *edev = palmas_usb->edev; in palmas_id_irq_handler()
80 palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_id_irq_handler()
82 palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_id_irq_handler()
87 palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_id_irq_handler()
90 palmas_usb->linkstat = PALMAS_USB_STATE_ID; in palmas_id_irq_handler()
92 dev_dbg(palmas_usb->dev, "USB-HOST cable is attached\n"); in palmas_id_irq_handler()
95 palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_id_irq_handler()
98 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; in palmas_id_irq_handler()
100 dev_dbg(palmas_usb->dev, "USB-HOST cable is detached\n"); in palmas_id_irq_handler()
101 } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) && in palmas_id_irq_handler()
103 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; in palmas_id_irq_handler()
105 dev_dbg(palmas_usb->dev, "USB-HOST cable is detached\n"); in palmas_id_irq_handler()
106 } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) && in palmas_id_irq_handler()
108 palmas_usb->linkstat = PALMAS_USB_STATE_ID; in palmas_id_irq_handler()
110 dev_dbg(palmas_usb->dev, "USB-HOST cable is attached\n"); in palmas_id_irq_handler()
122 struct extcon_dev *edev = palmas_usb->edev; in palmas_gpio_id_detect()
124 if (!palmas_usb->id_gpiod) in palmas_gpio_id_detect()
127 id = gpiod_get_value_cansleep(palmas_usb->id_gpiod); in palmas_gpio_id_detect()
131 dev_dbg(palmas_usb->dev, "USB-HOST cable is detached\n"); in palmas_gpio_id_detect()
134 dev_dbg(palmas_usb->dev, "USB-HOST cable is attached\n"); in palmas_gpio_id_detect()
142 queue_delayed_work(system_power_efficient_wq, &palmas_usb->wq_detectid, in palmas_gpio_id_irq_handler()
143 palmas_usb->sw_debounce_jiffies); in palmas_gpio_id_irq_handler()
150 palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_enable_irq()
154 if (palmas_usb->enable_id_detection) { in palmas_enable_irq()
155 palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_enable_irq()
159 palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_enable_irq()
165 if (palmas_usb->enable_vbus_detection) in palmas_enable_irq()
166 palmas_vbus_irq_handler(palmas_usb->vbus_irq, palmas_usb); in palmas_enable_irq()
168 /* cold plug for host mode needs this delay */ in palmas_enable_irq()
169 if (palmas_usb->enable_id_detection) { in palmas_enable_irq()
171 palmas_id_irq_handler(palmas_usb->id_irq, palmas_usb); in palmas_enable_irq()
177 struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); in palmas_usb_probe()
178 struct palmas_usb_platform_data *pdata = dev_get_platdata(&pdev->dev); in palmas_usb_probe()
179 struct device_node *node = pdev->dev.of_node; in palmas_usb_probe()
184 dev_err(&pdev->dev, "failed to get valid parent\n"); in palmas_usb_probe()
185 return -EINVAL; in palmas_usb_probe()
188 palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL); in palmas_usb_probe()
190 return -ENOMEM; in palmas_usb_probe()
193 palmas_usb->wakeup = of_property_read_bool(node, "ti,wakeup"); in palmas_usb_probe()
194 palmas_usb->enable_id_detection = of_property_read_bool(node, in palmas_usb_probe()
195 "ti,enable-id-detection"); in palmas_usb_probe()
196 palmas_usb->enable_vbus_detection = of_property_read_bool(node, in palmas_usb_probe()
197 "ti,enable-vbus-detection"); in palmas_usb_probe()
199 palmas_usb->wakeup = true; in palmas_usb_probe()
200 palmas_usb->enable_id_detection = true; in palmas_usb_probe()
201 palmas_usb->enable_vbus_detection = true; in palmas_usb_probe()
204 palmas_usb->wakeup = pdata->wakeup; in palmas_usb_probe()
207 palmas_usb->id_gpiod = devm_gpiod_get_optional(&pdev->dev, "id", in palmas_usb_probe()
209 if (IS_ERR(palmas_usb->id_gpiod)) in palmas_usb_probe()
210 return dev_err_probe(&pdev->dev, PTR_ERR(palmas_usb->id_gpiod), in palmas_usb_probe()
213 palmas_usb->vbus_gpiod = devm_gpiod_get_optional(&pdev->dev, "vbus", in palmas_usb_probe()
215 if (IS_ERR(palmas_usb->vbus_gpiod)) in palmas_usb_probe()
216 return dev_err_probe(&pdev->dev, PTR_ERR(palmas_usb->vbus_gpiod), in palmas_usb_probe()
219 if (palmas_usb->enable_id_detection && palmas_usb->id_gpiod) { in palmas_usb_probe()
220 palmas_usb->enable_id_detection = false; in palmas_usb_probe()
221 palmas_usb->enable_gpio_id_detection = true; in palmas_usb_probe()
224 if (palmas_usb->enable_vbus_detection && palmas_usb->vbus_gpiod) { in palmas_usb_probe()
225 palmas_usb->enable_vbus_detection = false; in palmas_usb_probe()
226 palmas_usb->enable_gpio_vbus_detection = true; in palmas_usb_probe()
229 if (palmas_usb->enable_gpio_id_detection) { in palmas_usb_probe()
232 if (of_property_read_u32(node, "debounce-delay-ms", &debounce)) in palmas_usb_probe()
235 status = gpiod_set_debounce(palmas_usb->id_gpiod, in palmas_usb_probe()
238 palmas_usb->sw_debounce_jiffies = msecs_to_jiffies(debounce); in palmas_usb_probe()
241 status = devm_delayed_work_autocancel(&pdev->dev, in palmas_usb_probe()
242 &palmas_usb->wq_detectid, in palmas_usb_probe()
247 palmas->usb = palmas_usb; in palmas_usb_probe()
248 palmas_usb->palmas = palmas; in palmas_usb_probe()
250 palmas_usb->dev = &pdev->dev; in palmas_usb_probe()
252 palmas_usb_wakeup(palmas, palmas_usb->wakeup); in palmas_usb_probe()
256 palmas_usb->edev = devm_extcon_dev_allocate(&pdev->dev, in palmas_usb_probe()
258 if (IS_ERR(palmas_usb->edev)) { in palmas_usb_probe()
259 dev_err(&pdev->dev, "failed to allocate extcon device\n"); in palmas_usb_probe()
260 return -ENOMEM; in palmas_usb_probe()
263 status = devm_extcon_dev_register(&pdev->dev, palmas_usb->edev); in palmas_usb_probe()
265 dev_err(&pdev->dev, "failed to register extcon device\n"); in palmas_usb_probe()
269 if (palmas_usb->enable_id_detection) { in palmas_usb_probe()
270 palmas_usb->id_otg_irq = regmap_irq_get_virq(palmas->irq_data, in palmas_usb_probe()
272 palmas_usb->id_irq = regmap_irq_get_virq(palmas->irq_data, in palmas_usb_probe()
274 status = devm_request_threaded_irq(palmas_usb->dev, in palmas_usb_probe()
275 palmas_usb->id_irq, in palmas_usb_probe()
281 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", in palmas_usb_probe()
282 palmas_usb->id_irq, status); in palmas_usb_probe()
285 } else if (palmas_usb->enable_gpio_id_detection) { in palmas_usb_probe()
286 palmas_usb->gpio_id_irq = gpiod_to_irq(palmas_usb->id_gpiod); in palmas_usb_probe()
287 if (palmas_usb->gpio_id_irq < 0) { in palmas_usb_probe()
288 dev_err(&pdev->dev, "failed to get id irq\n"); in palmas_usb_probe()
289 return palmas_usb->gpio_id_irq; in palmas_usb_probe()
291 status = devm_request_threaded_irq(&pdev->dev, in palmas_usb_probe()
292 palmas_usb->gpio_id_irq, in palmas_usb_probe()
301 dev_err(&pdev->dev, in palmas_usb_probe()
307 if (palmas_usb->enable_vbus_detection) { in palmas_usb_probe()
308 palmas_usb->vbus_otg_irq = regmap_irq_get_virq(palmas->irq_data, in palmas_usb_probe()
310 palmas_usb->vbus_irq = regmap_irq_get_virq(palmas->irq_data, in palmas_usb_probe()
312 status = devm_request_threaded_irq(palmas_usb->dev, in palmas_usb_probe()
313 palmas_usb->vbus_irq, NULL, in palmas_usb_probe()
319 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", in palmas_usb_probe()
320 palmas_usb->vbus_irq, status); in palmas_usb_probe()
323 } else if (palmas_usb->enable_gpio_vbus_detection) { in palmas_usb_probe()
331 dev_err(&pdev->dev, "can't remux GPIO1\n"); in palmas_usb_probe()
335 palmas_usb->vbus_otg_irq = regmap_irq_get_virq(palmas->irq_data, in palmas_usb_probe()
337 palmas_usb->gpio_vbus_irq = gpiod_to_irq(palmas_usb->vbus_gpiod); in palmas_usb_probe()
338 if (palmas_usb->gpio_vbus_irq < 0) { in palmas_usb_probe()
339 dev_err(&pdev->dev, "failed to get vbus irq\n"); in palmas_usb_probe()
340 return palmas_usb->gpio_vbus_irq; in palmas_usb_probe()
342 status = devm_request_threaded_irq(&pdev->dev, in palmas_usb_probe()
343 palmas_usb->gpio_vbus_irq, in palmas_usb_probe()
352 dev_err(&pdev->dev, in palmas_usb_probe()
360 if (palmas_usb->enable_gpio_vbus_detection) in palmas_usb_probe()
361 palmas_vbus_irq_handler(palmas_usb->gpio_vbus_irq, palmas_usb); in palmas_usb_probe()
362 palmas_gpio_id_detect(&palmas_usb->wq_detectid.work); in palmas_usb_probe()
363 device_set_wakeup_capable(&pdev->dev, true); in palmas_usb_probe()
373 if (palmas_usb->enable_vbus_detection) in palmas_usb_suspend()
374 enable_irq_wake(palmas_usb->vbus_irq); in palmas_usb_suspend()
375 if (palmas_usb->enable_gpio_vbus_detection) in palmas_usb_suspend()
376 enable_irq_wake(palmas_usb->gpio_vbus_irq); in palmas_usb_suspend()
377 if (palmas_usb->enable_id_detection) in palmas_usb_suspend()
378 enable_irq_wake(palmas_usb->id_irq); in palmas_usb_suspend()
379 if (palmas_usb->enable_gpio_id_detection) in palmas_usb_suspend()
380 enable_irq_wake(palmas_usb->gpio_id_irq); in palmas_usb_suspend()
390 if (palmas_usb->enable_vbus_detection) in palmas_usb_resume()
391 disable_irq_wake(palmas_usb->vbus_irq); in palmas_usb_resume()
392 if (palmas_usb->enable_gpio_vbus_detection) in palmas_usb_resume()
393 disable_irq_wake(palmas_usb->gpio_vbus_irq); in palmas_usb_resume()
394 if (palmas_usb->enable_id_detection) in palmas_usb_resume()
395 disable_irq_wake(palmas_usb->id_irq); in palmas_usb_resume()
396 if (palmas_usb->enable_gpio_id_detection) in palmas_usb_resume()
397 disable_irq_wake(palmas_usb->gpio_id_irq); in palmas_usb_resume()
401 if (palmas_usb->enable_gpio_vbus_detection) in palmas_usb_resume()
402 palmas_vbus_irq_handler(palmas_usb->gpio_vbus_irq, palmas_usb); in palmas_usb_resume()
403 palmas_gpio_id_detect(&palmas_usb->wq_detectid.work); in palmas_usb_resume()
412 { .compatible = "ti,palmas-usb", },
413 { .compatible = "ti,palmas-usb-vid", },
414 { .compatible = "ti,twl6035-usb", },
415 { .compatible = "ti,twl6035-usb-vid", },
422 .name = "palmas-usb",
430 MODULE_ALIAS("platform:palmas-usb");