Lines Matching +full:debounce +full:- +full:delay +full:- +full:us

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (c) 2010-2011, 2020-2021, The Linux Foundation. All rights reserved.
7 #include <linux/delay.h>
96 if (pwrkey->revision == 0) in pm8941_reboot_notify()
101 error = regmap_update_bits(pwrkey->regmap, in pm8941_reboot_notify()
102 pwrkey->baseaddr + enable_reg, in pm8941_reboot_notify()
106 dev_err(pwrkey->dev, in pm8941_reboot_notify()
130 error = regmap_update_bits(pwrkey->regmap, in pm8941_reboot_notify()
131 pwrkey->baseaddr + PON_PS_HOLD_RST_CTL, in pm8941_reboot_notify()
135 dev_err(pwrkey->dev, "unable to set ps hold reset type: %d\n", in pm8941_reboot_notify()
138 error = regmap_update_bits(pwrkey->regmap, in pm8941_reboot_notify()
139 pwrkey->baseaddr + enable_reg, in pm8941_reboot_notify()
143 dev_err(pwrkey->dev, "unable to re-set enable: %d\n", error); in pm8941_reboot_notify()
154 if (pwrkey->sw_debounce_time_us) { in pm8941_pwrkey_irq()
155 if (ktime_before(ktime_get(), pwrkey->sw_debounce_end_time)) { in pm8941_pwrkey_irq()
156 dev_dbg(pwrkey->dev, in pm8941_pwrkey_irq()
157 "ignoring key event received before debounce end %llu us\n", in pm8941_pwrkey_irq()
158 pwrkey->sw_debounce_end_time); in pm8941_pwrkey_irq()
163 err = regmap_read(pwrkey->regmap, pwrkey->baseaddr + PON_RT_STS, &sts); in pm8941_pwrkey_irq()
167 sts &= pwrkey->data->status_bit; in pm8941_pwrkey_irq()
169 if (pwrkey->sw_debounce_time_us && !sts) in pm8941_pwrkey_irq()
170 pwrkey->sw_debounce_end_time = ktime_add_us(ktime_get(), in pm8941_pwrkey_irq()
171 pwrkey->sw_debounce_time_us); in pm8941_pwrkey_irq()
177 if (!pwrkey->last_status && !sts) { in pm8941_pwrkey_irq()
178 input_report_key(pwrkey->input, pwrkey->code, 1); in pm8941_pwrkey_irq()
179 input_sync(pwrkey->input); in pm8941_pwrkey_irq()
181 pwrkey->last_status = sts; in pm8941_pwrkey_irq()
183 input_report_key(pwrkey->input, pwrkey->code, sts); in pm8941_pwrkey_irq()
184 input_sync(pwrkey->input); in pm8941_pwrkey_irq()
194 if (pwrkey->data->has_pon_pbs && !pwrkey->pon_pbs_baseaddr) { in pm8941_pwrkey_sw_debounce_init()
195 dev_err(pwrkey->dev, in pm8941_pwrkey_sw_debounce_init()
196 "PON_PBS address missing, can't read HW debounce time\n"); in pm8941_pwrkey_sw_debounce_init()
200 if (pwrkey->pon_pbs_baseaddr) in pm8941_pwrkey_sw_debounce_init()
201 addr = pwrkey->pon_pbs_baseaddr + PON_DBC_CTL; in pm8941_pwrkey_sw_debounce_init()
203 addr = pwrkey->baseaddr + PON_DBC_CTL; in pm8941_pwrkey_sw_debounce_init()
204 error = regmap_read(pwrkey->regmap, addr, &val); in pm8941_pwrkey_sw_debounce_init()
208 if (pwrkey->subtype >= PON_SUBTYPE_GEN2_PRIMARY) in pm8941_pwrkey_sw_debounce_init()
213 pwrkey->sw_debounce_time_us = in pm8941_pwrkey_sw_debounce_init()
214 2 * USEC_PER_SEC / (1 << (mask - (val & mask))); in pm8941_pwrkey_sw_debounce_init()
216 dev_dbg(pwrkey->dev, "SW debounce time = %u us\n", in pm8941_pwrkey_sw_debounce_init()
217 pwrkey->sw_debounce_time_us); in pm8941_pwrkey_sw_debounce_init()
227 enable_irq_wake(pwrkey->irq); in pm8941_pwrkey_suspend()
237 disable_irq_wake(pwrkey->irq); in pm8941_pwrkey_resume()
255 if (of_property_read_u32(pdev->dev.of_node, "debounce", &req_delay)) in pm8941_pwrkey_probe()
259 dev_err(&pdev->dev, "invalid debounce time: %u\n", req_delay); in pm8941_pwrkey_probe()
260 return -EINVAL; in pm8941_pwrkey_probe()
263 pull_up = of_property_read_bool(pdev->dev.of_node, "bias-pull-up"); in pm8941_pwrkey_probe()
265 pwrkey = devm_kzalloc(&pdev->dev, sizeof(*pwrkey), GFP_KERNEL); in pm8941_pwrkey_probe()
267 return -ENOMEM; in pm8941_pwrkey_probe()
269 pwrkey->dev = &pdev->dev; in pm8941_pwrkey_probe()
270 pwrkey->data = of_device_get_match_data(&pdev->dev); in pm8941_pwrkey_probe()
272 parent = pdev->dev.parent; in pm8941_pwrkey_probe()
273 regmap_node = pdev->dev.of_node; in pm8941_pwrkey_probe()
274 pwrkey->regmap = dev_get_regmap(parent, NULL); in pm8941_pwrkey_probe()
275 if (!pwrkey->regmap) { in pm8941_pwrkey_probe()
276 regmap_node = parent->of_node; in pm8941_pwrkey_probe()
282 pwrkey->regmap = dev_get_regmap(parent->parent, NULL); in pm8941_pwrkey_probe()
283 if (!pwrkey->regmap) { in pm8941_pwrkey_probe()
284 dev_err(&pdev->dev, "failed to locate regmap\n"); in pm8941_pwrkey_probe()
285 return -ENODEV; in pm8941_pwrkey_probe()
291 dev_err(&pdev->dev, "reg property missing\n"); in pm8941_pwrkey_probe()
292 return -EINVAL; in pm8941_pwrkey_probe()
294 pwrkey->baseaddr = be32_to_cpup(addr); in pm8941_pwrkey_probe()
296 if (pwrkey->data->has_pon_pbs) { in pm8941_pwrkey_probe()
300 pwrkey->pon_pbs_baseaddr = be32_to_cpup(addr); in pm8941_pwrkey_probe()
303 pwrkey->irq = platform_get_irq(pdev, 0); in pm8941_pwrkey_probe()
304 if (pwrkey->irq < 0) in pm8941_pwrkey_probe()
305 return pwrkey->irq; in pm8941_pwrkey_probe()
307 error = regmap_read(pwrkey->regmap, pwrkey->baseaddr + PON_REV2, in pm8941_pwrkey_probe()
308 &pwrkey->revision); in pm8941_pwrkey_probe()
310 dev_err(&pdev->dev, "failed to read revision: %d\n", error); in pm8941_pwrkey_probe()
314 error = regmap_read(pwrkey->regmap, pwrkey->baseaddr + PON_SUBTYPE, in pm8941_pwrkey_probe()
315 &pwrkey->subtype); in pm8941_pwrkey_probe()
317 dev_err(&pdev->dev, "failed to read subtype: %d\n", error); in pm8941_pwrkey_probe()
321 error = of_property_read_u32(pdev->dev.of_node, "linux,code", in pm8941_pwrkey_probe()
322 &pwrkey->code); in pm8941_pwrkey_probe()
324 dev_dbg(&pdev->dev, in pm8941_pwrkey_probe()
326 pwrkey->code = KEY_POWER; in pm8941_pwrkey_probe()
329 pwrkey->input = devm_input_allocate_device(&pdev->dev); in pm8941_pwrkey_probe()
330 if (!pwrkey->input) { in pm8941_pwrkey_probe()
331 dev_dbg(&pdev->dev, "unable to allocate input device\n"); in pm8941_pwrkey_probe()
332 return -ENOMEM; in pm8941_pwrkey_probe()
335 input_set_capability(pwrkey->input, EV_KEY, pwrkey->code); in pm8941_pwrkey_probe()
337 pwrkey->input->name = pwrkey->data->name; in pm8941_pwrkey_probe()
338 pwrkey->input->phys = pwrkey->data->phys; in pm8941_pwrkey_probe()
340 if (pwrkey->data->supports_debounce_config) { in pm8941_pwrkey_probe()
341 if (pwrkey->subtype >= PON_SUBTYPE_GEN2_PRIMARY) { in pm8941_pwrkey_probe()
352 error = regmap_update_bits(pwrkey->regmap, in pm8941_pwrkey_probe()
353 pwrkey->baseaddr + PON_DBC_CTL, in pm8941_pwrkey_probe()
357 dev_err(&pdev->dev, "failed to set debounce: %d\n", in pm8941_pwrkey_probe()
367 if (pwrkey->data->pull_up_bit) { in pm8941_pwrkey_probe()
368 error = regmap_update_bits(pwrkey->regmap, in pm8941_pwrkey_probe()
369 pwrkey->baseaddr + PON_PULL_CTL, in pm8941_pwrkey_probe()
370 pwrkey->data->pull_up_bit, in pm8941_pwrkey_probe()
371 pull_up ? pwrkey->data->pull_up_bit : in pm8941_pwrkey_probe()
374 dev_err(&pdev->dev, "failed to set pull: %d\n", error); in pm8941_pwrkey_probe()
379 error = devm_request_threaded_irq(&pdev->dev, pwrkey->irq, in pm8941_pwrkey_probe()
382 pwrkey->data->name, pwrkey); in pm8941_pwrkey_probe()
384 dev_err(&pdev->dev, "failed requesting IRQ: %d\n", error); in pm8941_pwrkey_probe()
388 error = input_register_device(pwrkey->input); in pm8941_pwrkey_probe()
390 dev_err(&pdev->dev, "failed to register input device: %d\n", in pm8941_pwrkey_probe()
395 if (pwrkey->data->supports_ps_hold_poff_config) { in pm8941_pwrkey_probe()
396 pwrkey->reboot_notifier.notifier_call = pm8941_reboot_notify; in pm8941_pwrkey_probe()
397 error = register_reboot_notifier(&pwrkey->reboot_notifier); in pm8941_pwrkey_probe()
399 dev_err(&pdev->dev, "failed to register reboot notifier: %d\n", in pm8941_pwrkey_probe()
406 device_init_wakeup(&pdev->dev, 1); in pm8941_pwrkey_probe()
415 if (pwrkey->data->supports_ps_hold_poff_config) in pm8941_pwrkey_remove()
416 unregister_reboot_notifier(&pwrkey->reboot_notifier); in pm8941_pwrkey_remove()
460 { .compatible = "qcom,pm8941-pwrkey", .data = &pwrkey_data },
461 { .compatible = "qcom,pm8941-resin", .data = &resin_data },
462 { .compatible = "qcom,pmk8350-pwrkey", .data = &pon_gen3_pwrkey_data },
463 { .compatible = "qcom,pmk8350-resin", .data = &pon_gen3_resin_data },
472 .name = "pm8941-pwrkey",