Lines Matching +full:debounce +full:- +full:delay +full:- +full:ms
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>
24 #define USB_GPIO_DEBOUNCE_MS 20 /* ms */
44 struct extcon_dev *edev = palmas_usb->edev; in palmas_vbus_irq_handler()
47 palmas_read(palmas_usb->palmas, PALMAS_INTERRUPT_BASE, in palmas_vbus_irq_handler()
51 if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) { in palmas_vbus_irq_handler()
52 palmas_usb->linkstat = PALMAS_USB_STATE_VBUS; in palmas_vbus_irq_handler()
54 dev_dbg(palmas_usb->dev, "USB cable is attached\n"); in palmas_vbus_irq_handler()
56 dev_dbg(palmas_usb->dev, in palmas_vbus_irq_handler()
60 if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) { in palmas_vbus_irq_handler()
61 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; in palmas_vbus_irq_handler()
63 dev_dbg(palmas_usb->dev, "USB cable is detached\n"); in palmas_vbus_irq_handler()
65 dev_dbg(palmas_usb->dev, in palmas_vbus_irq_handler()
77 struct extcon_dev *edev = palmas_usb->edev; in palmas_id_irq_handler()
79 palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_id_irq_handler()
81 palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_id_irq_handler()
86 palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_id_irq_handler()
89 palmas_usb->linkstat = PALMAS_USB_STATE_ID; in palmas_id_irq_handler()
91 dev_dbg(palmas_usb->dev, "USB-HOST cable is attached\n"); in palmas_id_irq_handler()
94 palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_id_irq_handler()
97 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; in palmas_id_irq_handler()
99 dev_dbg(palmas_usb->dev, "USB-HOST cable is detached\n"); in palmas_id_irq_handler()
100 } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) && in palmas_id_irq_handler()
102 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; in palmas_id_irq_handler()
104 dev_dbg(palmas_usb->dev, "USB-HOST cable is detached\n"); in palmas_id_irq_handler()
105 } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) && in palmas_id_irq_handler()
107 palmas_usb->linkstat = PALMAS_USB_STATE_ID; in palmas_id_irq_handler()
109 dev_dbg(palmas_usb->dev, "USB-HOST cable is attached\n"); in palmas_id_irq_handler()
121 struct extcon_dev *edev = palmas_usb->edev; in palmas_gpio_id_detect()
123 if (!palmas_usb->id_gpiod) in palmas_gpio_id_detect()
126 id = gpiod_get_value_cansleep(palmas_usb->id_gpiod); in palmas_gpio_id_detect()
130 dev_dbg(palmas_usb->dev, "USB-HOST cable is detached\n"); in palmas_gpio_id_detect()
133 dev_dbg(palmas_usb->dev, "USB-HOST cable is attached\n"); in palmas_gpio_id_detect()
141 queue_delayed_work(system_power_efficient_wq, &palmas_usb->wq_detectid, in palmas_gpio_id_irq_handler()
142 palmas_usb->sw_debounce_jiffies); in palmas_gpio_id_irq_handler()
149 palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_enable_irq()
153 if (palmas_usb->enable_id_detection) { in palmas_enable_irq()
154 palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_enable_irq()
158 palmas_write(palmas_usb->palmas, PALMAS_USB_OTG_BASE, in palmas_enable_irq()
164 if (palmas_usb->enable_vbus_detection) in palmas_enable_irq()
165 palmas_vbus_irq_handler(palmas_usb->vbus_irq, palmas_usb); in palmas_enable_irq()
167 /* cold plug for host mode needs this delay */ in palmas_enable_irq()
168 if (palmas_usb->enable_id_detection) { in palmas_enable_irq()
170 palmas_id_irq_handler(palmas_usb->id_irq, palmas_usb); in palmas_enable_irq()
176 struct palmas *palmas = dev_get_drvdata(pdev->dev.parent); in palmas_usb_probe()
177 struct palmas_usb_platform_data *pdata = dev_get_platdata(&pdev->dev); in palmas_usb_probe()
178 struct device_node *node = pdev->dev.of_node; in palmas_usb_probe()
183 dev_err(&pdev->dev, "failed to get valid parent\n"); in palmas_usb_probe()
184 return -EINVAL; in palmas_usb_probe()
187 palmas_usb = devm_kzalloc(&pdev->dev, sizeof(*palmas_usb), GFP_KERNEL); in palmas_usb_probe()
189 return -ENOMEM; in palmas_usb_probe()
192 palmas_usb->wakeup = of_property_read_bool(node, "ti,wakeup"); in palmas_usb_probe()
193 palmas_usb->enable_id_detection = of_property_read_bool(node, in palmas_usb_probe()
194 "ti,enable-id-detection"); in palmas_usb_probe()
195 palmas_usb->enable_vbus_detection = of_property_read_bool(node, in palmas_usb_probe()
196 "ti,enable-vbus-detection"); in palmas_usb_probe()
198 palmas_usb->wakeup = true; in palmas_usb_probe()
199 palmas_usb->enable_id_detection = true; in palmas_usb_probe()
200 palmas_usb->enable_vbus_detection = true; in palmas_usb_probe()
203 palmas_usb->wakeup = pdata->wakeup; in palmas_usb_probe()
206 palmas_usb->id_gpiod = devm_gpiod_get_optional(&pdev->dev, "id", in palmas_usb_probe()
208 if (IS_ERR(palmas_usb->id_gpiod)) in palmas_usb_probe()
209 return dev_err_probe(&pdev->dev, PTR_ERR(palmas_usb->id_gpiod), in palmas_usb_probe()
212 palmas_usb->vbus_gpiod = devm_gpiod_get_optional(&pdev->dev, "vbus", in palmas_usb_probe()
214 if (IS_ERR(palmas_usb->vbus_gpiod)) in palmas_usb_probe()
215 return dev_err_probe(&pdev->dev, PTR_ERR(palmas_usb->vbus_gpiod), in palmas_usb_probe()
218 if (palmas_usb->enable_id_detection && palmas_usb->id_gpiod) { in palmas_usb_probe()
219 palmas_usb->enable_id_detection = false; in palmas_usb_probe()
220 palmas_usb->enable_gpio_id_detection = true; in palmas_usb_probe()
223 if (palmas_usb->enable_vbus_detection && palmas_usb->vbus_gpiod) { in palmas_usb_probe()
224 palmas_usb->enable_vbus_detection = false; in palmas_usb_probe()
225 palmas_usb->enable_gpio_vbus_detection = true; in palmas_usb_probe()
228 if (palmas_usb->enable_gpio_id_detection) { in palmas_usb_probe()
229 u32 debounce; in palmas_usb_probe() local
231 if (of_property_read_u32(node, "debounce-delay-ms", &debounce)) in palmas_usb_probe()
232 debounce = USB_GPIO_DEBOUNCE_MS; in palmas_usb_probe()
234 status = gpiod_set_debounce(palmas_usb->id_gpiod, in palmas_usb_probe()
235 debounce * 1000); in palmas_usb_probe()
237 palmas_usb->sw_debounce_jiffies = msecs_to_jiffies(debounce); in palmas_usb_probe()
240 status = devm_delayed_work_autocancel(&pdev->dev, in palmas_usb_probe()
241 &palmas_usb->wq_detectid, in palmas_usb_probe()
246 palmas->usb = palmas_usb; in palmas_usb_probe()
247 palmas_usb->palmas = palmas; in palmas_usb_probe()
249 palmas_usb->dev = &pdev->dev; in palmas_usb_probe()
251 palmas_usb_wakeup(palmas, palmas_usb->wakeup); in palmas_usb_probe()
255 palmas_usb->edev = devm_extcon_dev_allocate(&pdev->dev, in palmas_usb_probe()
257 if (IS_ERR(palmas_usb->edev)) { in palmas_usb_probe()
258 dev_err(&pdev->dev, "failed to allocate extcon device\n"); in palmas_usb_probe()
259 return -ENOMEM; in palmas_usb_probe()
262 status = devm_extcon_dev_register(&pdev->dev, palmas_usb->edev); in palmas_usb_probe()
264 dev_err(&pdev->dev, "failed to register extcon device\n"); in palmas_usb_probe()
268 if (palmas_usb->enable_id_detection) { in palmas_usb_probe()
269 palmas_usb->id_otg_irq = regmap_irq_get_virq(palmas->irq_data, in palmas_usb_probe()
271 palmas_usb->id_irq = regmap_irq_get_virq(palmas->irq_data, in palmas_usb_probe()
273 status = devm_request_threaded_irq(palmas_usb->dev, in palmas_usb_probe()
274 palmas_usb->id_irq, in palmas_usb_probe()
280 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", in palmas_usb_probe()
281 palmas_usb->id_irq, status); in palmas_usb_probe()
284 } else if (palmas_usb->enable_gpio_id_detection) { in palmas_usb_probe()
285 palmas_usb->gpio_id_irq = gpiod_to_irq(palmas_usb->id_gpiod); in palmas_usb_probe()
286 if (palmas_usb->gpio_id_irq < 0) { in palmas_usb_probe()
287 dev_err(&pdev->dev, "failed to get id irq\n"); in palmas_usb_probe()
288 return palmas_usb->gpio_id_irq; in palmas_usb_probe()
290 status = devm_request_threaded_irq(&pdev->dev, in palmas_usb_probe()
291 palmas_usb->gpio_id_irq, in palmas_usb_probe()
300 dev_err(&pdev->dev, in palmas_usb_probe()
306 if (palmas_usb->enable_vbus_detection) { in palmas_usb_probe()
307 palmas_usb->vbus_otg_irq = regmap_irq_get_virq(palmas->irq_data, in palmas_usb_probe()
309 palmas_usb->vbus_irq = regmap_irq_get_virq(palmas->irq_data, in palmas_usb_probe()
311 status = devm_request_threaded_irq(palmas_usb->dev, in palmas_usb_probe()
312 palmas_usb->vbus_irq, NULL, in palmas_usb_probe()
318 dev_err(&pdev->dev, "can't get IRQ %d, err %d\n", in palmas_usb_probe()
319 palmas_usb->vbus_irq, status); in palmas_usb_probe()
322 } else if (palmas_usb->enable_gpio_vbus_detection) { in palmas_usb_probe()
330 dev_err(&pdev->dev, "can't remux GPIO1\n"); in palmas_usb_probe()
334 palmas_usb->vbus_otg_irq = regmap_irq_get_virq(palmas->irq_data, in palmas_usb_probe()
336 palmas_usb->gpio_vbus_irq = gpiod_to_irq(palmas_usb->vbus_gpiod); in palmas_usb_probe()
337 if (palmas_usb->gpio_vbus_irq < 0) { in palmas_usb_probe()
338 dev_err(&pdev->dev, "failed to get vbus irq\n"); in palmas_usb_probe()
339 return palmas_usb->gpio_vbus_irq; in palmas_usb_probe()
341 status = devm_request_threaded_irq(&pdev->dev, in palmas_usb_probe()
342 palmas_usb->gpio_vbus_irq, in palmas_usb_probe()
351 dev_err(&pdev->dev, in palmas_usb_probe()
359 if (palmas_usb->enable_gpio_vbus_detection) in palmas_usb_probe()
360 palmas_vbus_irq_handler(palmas_usb->gpio_vbus_irq, palmas_usb); in palmas_usb_probe()
361 palmas_gpio_id_detect(&palmas_usb->wq_detectid.work); in palmas_usb_probe()
362 device_set_wakeup_capable(&pdev->dev, true); in palmas_usb_probe()
372 if (palmas_usb->enable_vbus_detection) in palmas_usb_suspend()
373 enable_irq_wake(palmas_usb->vbus_irq); in palmas_usb_suspend()
374 if (palmas_usb->enable_gpio_vbus_detection) in palmas_usb_suspend()
375 enable_irq_wake(palmas_usb->gpio_vbus_irq); in palmas_usb_suspend()
376 if (palmas_usb->enable_id_detection) in palmas_usb_suspend()
377 enable_irq_wake(palmas_usb->id_irq); in palmas_usb_suspend()
378 if (palmas_usb->enable_gpio_id_detection) in palmas_usb_suspend()
379 enable_irq_wake(palmas_usb->gpio_id_irq); in palmas_usb_suspend()
389 if (palmas_usb->enable_vbus_detection) in palmas_usb_resume()
390 disable_irq_wake(palmas_usb->vbus_irq); in palmas_usb_resume()
391 if (palmas_usb->enable_gpio_vbus_detection) in palmas_usb_resume()
392 disable_irq_wake(palmas_usb->gpio_vbus_irq); in palmas_usb_resume()
393 if (palmas_usb->enable_id_detection) in palmas_usb_resume()
394 disable_irq_wake(palmas_usb->id_irq); in palmas_usb_resume()
395 if (palmas_usb->enable_gpio_id_detection) in palmas_usb_resume()
396 disable_irq_wake(palmas_usb->gpio_id_irq); in palmas_usb_resume()
400 if (palmas_usb->enable_gpio_vbus_detection) in palmas_usb_resume()
401 palmas_vbus_irq_handler(palmas_usb->gpio_vbus_irq, palmas_usb); in palmas_usb_resume()
402 palmas_gpio_id_detect(&palmas_usb->wq_detectid.work); in palmas_usb_resume()
411 { .compatible = "ti,palmas-usb", },
412 { .compatible = "ti,palmas-usb-vid", },
413 { .compatible = "ti,twl6035-usb", },
414 { .compatible = "ti,twl6035-usb-vid", },
421 .name = "palmas-usb",
429 MODULE_ALIAS("platform:palmas-usb");