Lines Matching +full:ovp +full:- +full:enable

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * extcon-rt8973a.c - Richtek RT8973A extcon driver to support USB switches
19 #include <linux/extcon-provider.h>
21 #include "extcon-rt8973a.h"
98 /* Define OVP (Over Voltage Protection), OTP (Over Temperature Protection) */
145 /* |---------|--ADC| */
152 { RT8973A_INT1_ATTACH, "muic-attach" },
153 { RT8973A_INT1_DETACH, "muic-detach" },
154 { RT8973A_INT1_CHGDET, "muic-chgdet" },
155 { RT8973A_INT1_DCD_T, "muic-dcd-t" },
156 { RT8973A_INT1_OVP, "muic-ovp" },
157 { RT8973A_INT1_CONNECT, "muic-connect" },
158 { RT8973A_INT1_ADC_CHG, "muic-adc-chg" },
159 { RT8973A_INT1_OTP, "muic-otp" },
160 { RT8973A_INT2_UVLO, "muic-uvlo" },
161 { RT8973A_INT2_POR, "muic-por" },
162 { RT8973A_INT2_OTP_FET, "muic-otp-fet" },
163 { RT8973A_INT2_OVP_FET, "muic-ovp-fet" },
164 { RT8973A_INT2_OCP_LATCH, "muic-ocp-latch" },
165 { RT8973A_INT2_OCP, "muic-ocp" },
166 { RT8973A_INT2_OVP_OCP, "muic-ovp-ocp" },
228 * if Auto-configuration mode of CONTROL1 register is true. in rt8973a_muic_set_path()
230 if (info->auto_config) in rt8973a_muic_set_path()
240 ret = regmap_update_bits(info->regmap, RT8973A_REG_MANUAL_SW1, in rt8973a_muic_set_path()
245 dev_err(info->dev, in rt8973a_muic_set_path()
251 dev_err(info->dev, "Unknown DM_CON/DP_CON switch type (%d)\n", in rt8973a_muic_set_path()
253 return -EINVAL; in rt8973a_muic_set_path()
265 ret = regmap_read(info->regmap, RT8973A_REG_ADC, &adc); in rt8973a_muic_get_cable_type()
267 dev_err(info->dev, "failed to read ADC register\n"); in rt8973a_muic_get_cable_type()
273 ret = regmap_read(info->regmap, RT8973A_REG_DEV1, &dev1); in rt8973a_muic_get_cable_type()
275 dev_err(info->dev, "failed to read DEV1 register\n"); in rt8973a_muic_get_cable_type()
315 dev_warn(info->dev, in rt8973a_muic_cable_handler()
322 dev_err(info->dev, in rt8973a_muic_cable_handler()
324 return -EINVAL; in rt8973a_muic_cable_handler()
358 dev_warn(info->dev, in rt8973a_muic_cable_handler()
375 dev_warn(info->dev, in rt8973a_muic_cable_handler()
386 dev_err(info->dev, in rt8973a_muic_cable_handler()
389 return -EINVAL; in rt8973a_muic_cable_handler()
398 extcon_set_state_sync(info->edev, id, attached); in rt8973a_muic_cable_handler()
400 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, in rt8973a_muic_cable_handler()
412 if (!info->edev) in rt8973a_muic_irq_work()
415 mutex_lock(&info->mutex); in rt8973a_muic_irq_work()
418 if (info->irq_attach) { in rt8973a_muic_irq_work()
420 info->irq_attach = false; in rt8973a_muic_irq_work()
423 if (info->irq_detach) { in rt8973a_muic_irq_work()
425 info->irq_detach = false; in rt8973a_muic_irq_work()
428 if (info->irq_ovp) { in rt8973a_muic_irq_work()
430 info->irq_ovp = false; in rt8973a_muic_irq_work()
433 if (info->irq_otp) { in rt8973a_muic_irq_work()
435 info->irq_otp = false; in rt8973a_muic_irq_work()
439 dev_err(info->dev, "failed to handle MUIC interrupt\n"); in rt8973a_muic_irq_work()
441 mutex_unlock(&info->mutex); in rt8973a_muic_irq_work()
447 int i, irq_type = -1; in rt8973a_muic_irq_handler()
449 for (i = 0; i < info->num_muic_irqs; i++) in rt8973a_muic_irq_handler()
450 if (irq == info->muic_irqs[i].virq) in rt8973a_muic_irq_handler()
451 irq_type = info->muic_irqs[i].irq; in rt8973a_muic_irq_handler()
455 info->irq_attach = true; in rt8973a_muic_irq_handler()
458 info->irq_detach = true; in rt8973a_muic_irq_handler()
461 info->irq_ovp = true; in rt8973a_muic_irq_handler()
464 info->irq_otp = true; in rt8973a_muic_irq_handler()
478 dev_dbg(info->dev, in rt8973a_muic_irq_handler()
483 schedule_work(&info->irq_work); in rt8973a_muic_irq_handler()
497 dev_warn(info->dev, "failed to detect cable state\n"); in rt8973a_muic_detect_cable_wq()
506 ret = regmap_read(info->regmap, RT8973A_REG_DEVICE_ID, &data); in rt8973a_init_dev_type()
508 dev_err(info->dev, in rt8973a_init_dev_type()
518 dev_info(info->dev, "Device type: version: 0x%x, vendor: 0x%x\n", in rt8973a_init_dev_type()
521 /* Initiazle the register of RT8973A device to bring-up */ in rt8973a_init_dev_type()
522 for (i = 0; i < info->num_reg_data; i++) { in rt8973a_init_dev_type()
523 u8 reg = info->reg_data[i].reg; in rt8973a_init_dev_type()
524 u8 mask = info->reg_data[i].mask; in rt8973a_init_dev_type()
527 if (info->reg_data[i].invert) in rt8973a_init_dev_type()
528 val = ~info->reg_data[i].val; in rt8973a_init_dev_type()
530 val = info->reg_data[i].val; in rt8973a_init_dev_type()
532 regmap_update_bits(info->regmap, reg, mask, val); in rt8973a_init_dev_type()
536 ret = regmap_read(info->regmap, RT8973A_REG_CONTROL1, &data); in rt8973a_init_dev_type()
538 dev_err(info->dev, in rt8973a_init_dev_type()
545 info->auto_config = true; in rt8973a_init_dev_type()
546 dev_info(info->dev, in rt8973a_init_dev_type()
547 "Enable Auto-configuration for internal path\n"); in rt8973a_init_dev_type()
553 struct device_node *np = i2c->dev.of_node; in rt8973a_muic_i2c_probe()
558 return -EINVAL; in rt8973a_muic_i2c_probe()
560 info = devm_kzalloc(&i2c->dev, sizeof(*info), GFP_KERNEL); in rt8973a_muic_i2c_probe()
562 return -ENOMEM; in rt8973a_muic_i2c_probe()
565 info->dev = &i2c->dev; in rt8973a_muic_i2c_probe()
566 info->i2c = i2c; in rt8973a_muic_i2c_probe()
567 info->irq = i2c->irq; in rt8973a_muic_i2c_probe()
568 info->muic_irqs = rt8973a_muic_irqs; in rt8973a_muic_i2c_probe()
569 info->num_muic_irqs = ARRAY_SIZE(rt8973a_muic_irqs); in rt8973a_muic_i2c_probe()
570 info->reg_data = rt8973a_reg_data; in rt8973a_muic_i2c_probe()
571 info->num_reg_data = ARRAY_SIZE(rt8973a_reg_data); in rt8973a_muic_i2c_probe()
573 mutex_init(&info->mutex); in rt8973a_muic_i2c_probe()
575 INIT_WORK(&info->irq_work, rt8973a_muic_irq_work); in rt8973a_muic_i2c_probe()
577 info->regmap = devm_regmap_init_i2c(i2c, &rt8973a_muic_regmap_config); in rt8973a_muic_i2c_probe()
578 if (IS_ERR(info->regmap)) { in rt8973a_muic_i2c_probe()
579 ret = PTR_ERR(info->regmap); in rt8973a_muic_i2c_probe()
580 dev_err(info->dev, "failed to allocate register map: %d\n", in rt8973a_muic_i2c_probe()
587 ret = regmap_add_irq_chip(info->regmap, info->irq, irq_flags, 0, in rt8973a_muic_i2c_probe()
588 &rt8973a_muic_irq_chip, &info->irq_data); in rt8973a_muic_i2c_probe()
590 dev_err(info->dev, "failed to add irq_chip (irq:%d, err:%d)\n", in rt8973a_muic_i2c_probe()
591 info->irq, ret); in rt8973a_muic_i2c_probe()
595 for (i = 0; i < info->num_muic_irqs; i++) { in rt8973a_muic_i2c_probe()
596 struct muic_irq *muic_irq = &info->muic_irqs[i]; in rt8973a_muic_i2c_probe()
599 virq = regmap_irq_get_virq(info->irq_data, muic_irq->irq); in rt8973a_muic_i2c_probe()
601 return -EINVAL; in rt8973a_muic_i2c_probe()
602 muic_irq->virq = virq; in rt8973a_muic_i2c_probe()
604 ret = devm_request_threaded_irq(info->dev, virq, NULL, in rt8973a_muic_i2c_probe()
607 muic_irq->name, info); in rt8973a_muic_i2c_probe()
609 dev_err(info->dev, in rt8973a_muic_i2c_probe()
611 muic_irq->irq, ret); in rt8973a_muic_i2c_probe()
617 info->edev = devm_extcon_dev_allocate(info->dev, rt8973a_extcon_cable); in rt8973a_muic_i2c_probe()
618 if (IS_ERR(info->edev)) { in rt8973a_muic_i2c_probe()
619 dev_err(info->dev, "failed to allocate memory for extcon\n"); in rt8973a_muic_i2c_probe()
620 return -ENOMEM; in rt8973a_muic_i2c_probe()
624 ret = devm_extcon_dev_register(info->dev, info->edev); in rt8973a_muic_i2c_probe()
626 dev_err(info->dev, "failed to register extcon device\n"); in rt8973a_muic_i2c_probe()
633 * - Use delayed workqueue to detect cable state and then in rt8973a_muic_i2c_probe()
638 INIT_DELAYED_WORK(&info->wq_detcable, rt8973a_muic_detect_cable_wq); in rt8973a_muic_i2c_probe()
639 queue_delayed_work(system_power_efficient_wq, &info->wq_detcable, in rt8973a_muic_i2c_probe()
652 regmap_del_irq_chip(info->irq, info->irq_data); in rt8973a_muic_i2c_remove()
656 { .compatible = "richtek,rt8973a-muic" },
667 enable_irq_wake(info->irq); in rt8973a_muic_suspend()
677 disable_irq_wake(info->irq); in rt8973a_muic_resume()