• Home
  • Raw
  • Download

Lines Matching +full:invert +full:- +full:interrupt

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * extcon-sm5502.c - Silicon Mitus SM5502 extcon drvier to support USB switches
11 #include <linux/interrupt.h>
18 #include <linux/extcon-provider.h>
20 #include "extcon-sm5502.h"
33 bool invert; member
70 .invert = true,
74 .invert = false,
80 .invert = true,
89 .invert = true,
141 /* |---------|--ADC| */
145 /* |Dev Type1|--ADC| */
151 /* List of supported interrupt for SM5502 */
153 { SM5502_IRQ_INT1_ATTACH, "muic-attach" },
154 { SM5502_IRQ_INT1_DETACH, "muic-detach" },
155 { SM5502_IRQ_INT1_KP, "muic-kp" },
156 { SM5502_IRQ_INT1_LKP, "muic-lkp" },
157 { SM5502_IRQ_INT1_LKR, "muic-lkr" },
158 { SM5502_IRQ_INT1_OVP_EVENT, "muic-ovp-event" },
159 { SM5502_IRQ_INT1_OCP_EVENT, "muic-ocp-event" },
160 { SM5502_IRQ_INT1_OVP_OCP_DIS, "muic-ovp-ocp-dis" },
161 { SM5502_IRQ_INT2_VBUS_DET, "muic-vbus-det" },
162 { SM5502_IRQ_INT2_REV_ACCE, "muic-rev-acce" },
163 { SM5502_IRQ_INT2_ADC_CHG, "muic-adc-chg" },
164 { SM5502_IRQ_INT2_STUCK_KEY, "muic-stuck-key" },
165 { SM5502_IRQ_INT2_STUCK_KEY_RCV, "muic-stuck-key-rcv" },
166 { SM5502_IRQ_INT2_MHL, "muic-mhl" },
169 /* Define interrupt list of SM5502 to register regmap_irq */
237 ret = regmap_update_bits(info->regmap, SM5502_REG_MANUAL_SW1, in sm5502_muic_set_path()
242 dev_err(info->dev, in sm5502_muic_set_path()
248 dev_err(info->dev, "Unknown DM_CON/DP_CON switch type (%d)\n", in sm5502_muic_set_path()
250 return -EINVAL; in sm5502_muic_set_path()
258 ret = regmap_update_bits(info->regmap, SM5502_REG_MANUAL_SW1, in sm5502_muic_set_path()
262 dev_err(info->dev, in sm5502_muic_set_path()
268 dev_err(info->dev, "Unknown VBUS switch type (%d)\n", vbus_sw); in sm5502_muic_set_path()
269 return -EINVAL; in sm5502_muic_set_path()
282 ret = regmap_read(info->regmap, SM5502_REG_ADC, &adc); in sm5502_muic_get_cable_type()
284 dev_err(info->dev, "failed to read ADC register\n"); in sm5502_muic_get_cable_type()
337 ret = regmap_read(info->regmap, SM5502_REG_DEV_TYPE1, in sm5502_muic_get_cable_type()
340 dev_err(info->dev, "failed to read DEV_TYPE1 reg\n"); in sm5502_muic_get_cable_type()
355 dev_dbg(info->dev, in sm5502_muic_get_cable_type()
358 return -EINVAL; in sm5502_muic_get_cable_type()
362 dev_err(info->dev, in sm5502_muic_get_cable_type()
364 return -EINVAL; in sm5502_muic_get_cable_type()
404 dev_dbg(info->dev, in sm5502_muic_cable_handler()
415 extcon_set_state_sync(info->edev, id, attached); in sm5502_muic_cable_handler()
417 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, in sm5502_muic_cable_handler()
429 if (!info->edev) in sm5502_muic_irq_work()
432 mutex_lock(&info->mutex); in sm5502_muic_irq_work()
435 if (info->irq_attach) { in sm5502_muic_irq_work()
437 info->irq_attach = false; in sm5502_muic_irq_work()
439 if (info->irq_detach) { in sm5502_muic_irq_work()
441 info->irq_detach = false; in sm5502_muic_irq_work()
445 dev_err(info->dev, "failed to handle MUIC interrupt\n"); in sm5502_muic_irq_work()
447 mutex_unlock(&info->mutex); in sm5502_muic_irq_work()
452 * Returns -ESRCH if irq_type does not match registered IRQ for this dev type.
458 info->irq_attach = true; in sm5502_parse_irq()
461 info->irq_detach = true; in sm5502_parse_irq()
485 int i, irq_type = -1, ret; in sm5502_muic_irq_handler()
487 for (i = 0; i < info->num_muic_irqs; i++) in sm5502_muic_irq_handler()
488 if (irq == info->muic_irqs[i].virq) in sm5502_muic_irq_handler()
489 irq_type = info->muic_irqs[i].irq; in sm5502_muic_irq_handler()
493 dev_warn(info->dev, "cannot handle is interrupt:%d\n", in sm5502_muic_irq_handler()
497 schedule_work(&info->irq_work); in sm5502_muic_irq_handler()
511 dev_warn(info->dev, "failed to detect cable state\n"); in sm5502_muic_detect_cable_wq()
520 ret = regmap_read(info->regmap, SM5502_REG_DEVICE_ID, &reg_data); in sm5502_init_dev_type()
522 dev_err(info->dev, in sm5502_init_dev_type()
532 dev_info(info->dev, "Device type: version: 0x%x, vendor: 0x%x\n", in sm5502_init_dev_type()
535 /* Initiazle the register of SM5502 device to bring-up */ in sm5502_init_dev_type()
536 for (i = 0; i < info->num_reg_data; i++) { in sm5502_init_dev_type()
539 if (!info->reg_data[i].invert) in sm5502_init_dev_type()
540 val |= ~info->reg_data[i].val; in sm5502_init_dev_type()
542 val = info->reg_data[i].val; in sm5502_init_dev_type()
543 regmap_write(info->regmap, info->reg_data[i].reg, val); in sm5502_init_dev_type()
550 struct device_node *np = i2c->dev.of_node; in sm5022_muic_i2c_probe()
555 return -EINVAL; in sm5022_muic_i2c_probe()
557 info = devm_kzalloc(&i2c->dev, sizeof(*info), GFP_KERNEL); in sm5022_muic_i2c_probe()
559 return -ENOMEM; in sm5022_muic_i2c_probe()
562 info->dev = &i2c->dev; in sm5022_muic_i2c_probe()
563 info->i2c = i2c; in sm5022_muic_i2c_probe()
564 info->irq = i2c->irq; in sm5022_muic_i2c_probe()
565 info->muic_irqs = sm5502_muic_irqs; in sm5022_muic_i2c_probe()
566 info->num_muic_irqs = ARRAY_SIZE(sm5502_muic_irqs); in sm5022_muic_i2c_probe()
567 info->reg_data = sm5502_reg_data; in sm5022_muic_i2c_probe()
568 info->num_reg_data = ARRAY_SIZE(sm5502_reg_data); in sm5022_muic_i2c_probe()
570 mutex_init(&info->mutex); in sm5022_muic_i2c_probe()
572 INIT_WORK(&info->irq_work, sm5502_muic_irq_work); in sm5022_muic_i2c_probe()
574 info->regmap = devm_regmap_init_i2c(i2c, &sm5502_muic_regmap_config); in sm5022_muic_i2c_probe()
575 if (IS_ERR(info->regmap)) { in sm5022_muic_i2c_probe()
576 ret = PTR_ERR(info->regmap); in sm5022_muic_i2c_probe()
577 dev_err(info->dev, "failed to allocate register map: %d\n", in sm5022_muic_i2c_probe()
584 ret = regmap_add_irq_chip(info->regmap, info->irq, irq_flags, 0, in sm5022_muic_i2c_probe()
585 &sm5502_muic_irq_chip, &info->irq_data); in sm5022_muic_i2c_probe()
587 dev_err(info->dev, "failed to request IRQ %d: %d\n", in sm5022_muic_i2c_probe()
588 info->irq, ret); in sm5022_muic_i2c_probe()
592 for (i = 0; i < info->num_muic_irqs; i++) { in sm5022_muic_i2c_probe()
593 struct muic_irq *muic_irq = &info->muic_irqs[i]; in sm5022_muic_i2c_probe()
596 virq = regmap_irq_get_virq(info->irq_data, muic_irq->irq); in sm5022_muic_i2c_probe()
598 return -EINVAL; in sm5022_muic_i2c_probe()
599 muic_irq->virq = virq; in sm5022_muic_i2c_probe()
601 ret = devm_request_threaded_irq(info->dev, virq, NULL, in sm5022_muic_i2c_probe()
604 muic_irq->name, info); in sm5022_muic_i2c_probe()
606 dev_err(info->dev, in sm5022_muic_i2c_probe()
608 muic_irq->irq, ret); in sm5022_muic_i2c_probe()
614 info->edev = devm_extcon_dev_allocate(info->dev, sm5502_extcon_cable); in sm5022_muic_i2c_probe()
615 if (IS_ERR(info->edev)) { in sm5022_muic_i2c_probe()
616 dev_err(info->dev, "failed to allocate memory for extcon\n"); in sm5022_muic_i2c_probe()
617 return -ENOMEM; in sm5022_muic_i2c_probe()
621 ret = devm_extcon_dev_register(info->dev, info->edev); in sm5022_muic_i2c_probe()
623 dev_err(info->dev, "failed to register extcon device\n"); in sm5022_muic_i2c_probe()
630 * - Use delayed workqueue to detect cable state and then in sm5022_muic_i2c_probe()
635 INIT_DELAYED_WORK(&info->wq_detcable, sm5502_muic_detect_cable_wq); in sm5022_muic_i2c_probe()
636 queue_delayed_work(system_power_efficient_wq, &info->wq_detcable, in sm5022_muic_i2c_probe()
649 regmap_del_irq_chip(info->irq, info->irq_data); in sm5502_muic_i2c_remove()
655 { .compatible = "siliconmitus,sm5502-muic" },
666 enable_irq_wake(info->irq); in sm5502_muic_suspend()
676 disable_irq_wake(info->irq); in sm5502_muic_resume()