Lines Matching +full:max14577 +full:- +full:charger

1 // SPDX-License-Identifier: GPL-2.0+
3 // extcon-max14577.c - MAX14577/77836 extcon driver to support MUIC
9 #include <linux/devm-helpers.h>
15 #include <linux/mfd/max14577.h>
16 #include <linux/mfd/max14577-private.h>
17 #include <linux/extcon-provider.h>
47 { MAX14577_IRQ_INT1_ADC, "muic-ADC" },
48 { MAX14577_IRQ_INT1_ADCLOW, "muic-ADCLOW" },
49 { MAX14577_IRQ_INT1_ADCERR, "muic-ADCError" },
50 { MAX14577_IRQ_INT2_CHGTYP, "muic-CHGTYP" },
51 { MAX14577_IRQ_INT2_CHGDETRUN, "muic-CHGDETRUN" },
52 { MAX14577_IRQ_INT2_DCDTMR, "muic-DCDTMR" },
53 { MAX14577_IRQ_INT2_DBCHG, "muic-DBCHG" },
54 { MAX14577_IRQ_INT2_VBVOLT, "muic-VBVOLT" },
58 { MAX14577_IRQ_INT1_ADC, "muic-ADC" },
59 { MAX14577_IRQ_INT1_ADCLOW, "muic-ADCLOW" },
60 { MAX14577_IRQ_INT1_ADCERR, "muic-ADCError" },
61 { MAX77836_IRQ_INT1_ADC1K, "muic-ADC1K" },
62 { MAX14577_IRQ_INT2_CHGTYP, "muic-CHGTYP" },
63 { MAX14577_IRQ_INT2_CHGDETRUN, "muic-CHGDETRUN" },
64 { MAX14577_IRQ_INT2_DCDTMR, "muic-DCDTMR" },
65 { MAX14577_IRQ_INT2_DBCHG, "muic-DBCHG" },
66 { MAX14577_IRQ_INT2_VBVOLT, "muic-VBVOLT" },
67 { MAX77836_IRQ_INT2_VIDRM, "muic-VIDRM" },
72 struct max14577 *max14577; member
154 * max14577_muic_set_debounce_time - Set the debounce time of ADC
155 * @info: the instance including private data of max14577 MUIC
168 ret = max14577_update_reg(info->max14577->regmap, in max14577_muic_set_debounce_time()
173 dev_err(info->dev, "failed to set ADC debounce time\n"); in max14577_muic_set_debounce_time()
178 dev_err(info->dev, "invalid ADC debounce time\n"); in max14577_muic_set_debounce_time()
179 return -EINVAL; in max14577_muic_set_debounce_time()
186 * max14577_muic_set_path - Set hardware line according to attached cable
187 * @info: the instance including private data of max14577 MUIC
191 * The max14577 MUIC device share outside H/W line among a varity of cables
202 ret = max14577_update_reg(info->max14577->regmap, in max14577_muic_set_path()
206 dev_err(info->dev, "failed to update MUIC register\n"); in max14577_muic_set_path()
215 ret = max14577_update_reg(info->max14577->regmap, in max14577_muic_set_path()
219 dev_err(info->dev, "failed to update MUIC register\n"); in max14577_muic_set_path()
228 ret = max14577_update_reg(info->max14577->regmap, in max14577_muic_set_path()
232 dev_err(info->dev, "failed to update MUIC register\n"); in max14577_muic_set_path()
236 dev_dbg(info->dev, in max14577_muic_set_path()
244 * max14577_muic_get_cable_type - Return cable type and check cable state
245 * @info: the instance including private data of max14577 MUIC
251 * - max14577_CABLE_GROUP_ADC
252 * - max14577_CABLE_GROUP_CHG
267 adc = info->status[MAX14577_MUIC_STATUS1] & STATUS1_ADC_MASK; in max14577_muic_get_cable_type()
272 * (info->prev_cable_type) for handling cable when cable is in max14577_muic_get_cable_type()
278 cable_type = info->prev_cable_type; in max14577_muic_get_cable_type()
279 info->prev_cable_type = MAX14577_MUIC_ADC_OPEN; in max14577_muic_get_cable_type()
283 cable_type = info->prev_cable_type = adc; in max14577_muic_get_cable_type()
288 * Read charger type to check cable type and decide cable state in max14577_muic_get_cable_type()
289 * according to type of charger cable. in max14577_muic_get_cable_type()
291 chg_type = info->status[MAX14577_MUIC_STATUS2] & in max14577_muic_get_cable_type()
298 cable_type = info->prev_chg_type; in max14577_muic_get_cable_type()
299 info->prev_chg_type = MAX14577_CHARGER_TYPE_NONE; in max14577_muic_get_cable_type()
305 * type(info->prev_chg_type) for handling cable when in max14577_muic_get_cable_type()
306 * charger cable is detached. in max14577_muic_get_cable_type()
308 cable_type = info->prev_chg_type = chg_type; in max14577_muic_get_cable_type()
313 dev_err(info->dev, "Unknown cable group (%d)\n", group); in max14577_muic_get_cable_type()
314 cable_type = -EINVAL; in max14577_muic_get_cable_type()
327 dev_dbg(info->dev, in max14577_muic_jig_handler()
342 dev_err(info->dev, "failed to detect %s jig cable\n", in max14577_muic_jig_handler()
344 return -EINVAL; in max14577_muic_jig_handler()
351 extcon_set_state_sync(info->edev, EXTCON_JIG, attached); in max14577_muic_jig_handler()
366 dev_dbg(info->dev, in max14577_muic_adc_handler()
369 info->prev_cable_type); in max14577_muic_adc_handler()
413 dev_info(info->dev, in max14577_muic_adc_handler()
416 return -EAGAIN; in max14577_muic_adc_handler()
418 dev_err(info->dev, in max14577_muic_adc_handler()
421 return -EINVAL; in max14577_muic_adc_handler()
436 dev_dbg(info->dev, in max14577_muic_chg_handler()
439 chg_type, info->prev_chg_type); in max14577_muic_chg_handler()
444 ret = max14577_muic_set_path(info, info->path_usb, attached); in max14577_muic_chg_handler()
448 extcon_set_state_sync(info->edev, EXTCON_USB, attached); in max14577_muic_chg_handler()
449 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, in max14577_muic_chg_handler()
453 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, in max14577_muic_chg_handler()
457 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP, in max14577_muic_chg_handler()
461 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW, in max14577_muic_chg_handler()
465 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST, in max14577_muic_chg_handler()
472 dev_err(info->dev, in max14577_muic_chg_handler()
475 return -EINVAL; in max14577_muic_chg_handler()
487 if (!info->edev) in max14577_muic_irq_work()
490 mutex_lock(&info->mutex); in max14577_muic_irq_work()
492 ret = max14577_bulk_read(info->max14577->regmap, in max14577_muic_irq_work()
493 MAX14577_MUIC_REG_STATUS1, info->status, 2); in max14577_muic_irq_work()
495 dev_err(info->dev, "failed to read MUIC register\n"); in max14577_muic_irq_work()
496 mutex_unlock(&info->mutex); in max14577_muic_irq_work()
500 if (info->irq_adc) { in max14577_muic_irq_work()
502 info->irq_adc = false; in max14577_muic_irq_work()
504 if (info->irq_chg) { in max14577_muic_irq_work()
506 info->irq_chg = false; in max14577_muic_irq_work()
510 dev_err(info->dev, "failed to handle MUIC interrupt\n"); in max14577_muic_irq_work()
512 mutex_unlock(&info->mutex); in max14577_muic_irq_work()
527 * type of charger accessory. in max14577_parse_irq()
529 info->irq_adc = true; in max14577_parse_irq()
536 /* Handle charger accessory */ in max14577_parse_irq()
537 info->irq_chg = true; in max14577_parse_irq()
550 /* First check common max14577 interrupts */ in max77836_parse_irq()
556 info->irq_adc = true; in max77836_parse_irq()
559 /* Handle charger accessory */ in max77836_parse_irq()
560 info->irq_chg = true; in max77836_parse_irq()
570 int i, irq_type = -1; in max14577_muic_irq_handler()
574 * We may be called multiple times for different nested IRQ-s. in max14577_muic_irq_handler()
576 * However we only need to know whether it was ADC, charger in max14577_muic_irq_handler()
579 for (i = 0; i < info->muic_irqs_num; i++) in max14577_muic_irq_handler()
580 if (irq == info->muic_irqs[i].virq) in max14577_muic_irq_handler()
581 irq_type = info->muic_irqs[i].irq; in max14577_muic_irq_handler()
583 switch (info->max14577->dev_type) { in max14577_muic_irq_handler()
594 dev_err(info->dev, "muic interrupt: irq %d occurred, skipped\n", in max14577_muic_irq_handler()
598 schedule_work(&info->irq_work); in max14577_muic_irq_handler()
610 mutex_lock(&info->mutex); in max14577_muic_detect_accessory()
613 ret = max14577_bulk_read(info->max14577->regmap, in max14577_muic_detect_accessory()
614 MAX14577_MUIC_REG_STATUS1, info->status, 2); in max14577_muic_detect_accessory()
616 dev_err(info->dev, "failed to read MUIC register\n"); in max14577_muic_detect_accessory()
617 mutex_unlock(&info->mutex); in max14577_muic_detect_accessory()
626 dev_err(info->dev, "Cannot detect accessory\n"); in max14577_muic_detect_accessory()
627 mutex_unlock(&info->mutex); in max14577_muic_detect_accessory()
637 dev_err(info->dev, "Cannot detect charger accessory\n"); in max14577_muic_detect_accessory()
638 mutex_unlock(&info->mutex); in max14577_muic_detect_accessory()
643 mutex_unlock(&info->mutex); in max14577_muic_detect_accessory()
658 struct max14577 *max14577 = dev_get_drvdata(pdev->dev.parent); in max14577_muic_probe() local
667 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in max14577_muic_probe()
669 return -ENOMEM; in max14577_muic_probe()
671 info->dev = &pdev->dev; in max14577_muic_probe()
672 info->max14577 = max14577; in max14577_muic_probe()
675 mutex_init(&info->mutex); in max14577_muic_probe()
677 ret = devm_work_autocancel(&pdev->dev, &info->irq_work, in max14577_muic_probe()
682 switch (max14577->dev_type) { in max14577_muic_probe()
684 info->muic_irqs = max77836_muic_irqs; in max14577_muic_probe()
685 info->muic_irqs_num = ARRAY_SIZE(max77836_muic_irqs); in max14577_muic_probe()
689 info->muic_irqs = max14577_muic_irqs; in max14577_muic_probe()
690 info->muic_irqs_num = ARRAY_SIZE(max14577_muic_irqs); in max14577_muic_probe()
693 /* Support irq domain for max14577 MUIC device */ in max14577_muic_probe()
694 for (i = 0; i < info->muic_irqs_num; i++) { in max14577_muic_probe()
695 struct max14577_muic_irq *muic_irq = &info->muic_irqs[i]; in max14577_muic_probe()
698 virq = regmap_irq_get_virq(max14577->irq_data, muic_irq->irq); in max14577_muic_probe()
700 return -EINVAL; in max14577_muic_probe()
701 muic_irq->virq = virq; in max14577_muic_probe()
703 ret = devm_request_threaded_irq(&pdev->dev, virq, NULL, in max14577_muic_probe()
706 muic_irq->name, info); in max14577_muic_probe()
708 dev_err(&pdev->dev, in max14577_muic_probe()
710 muic_irq->irq, ret); in max14577_muic_probe()
716 info->edev = devm_extcon_dev_allocate(&pdev->dev, in max14577_muic_probe()
718 if (IS_ERR(info->edev)) { in max14577_muic_probe()
719 dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); in max14577_muic_probe()
720 return PTR_ERR(info->edev); in max14577_muic_probe()
723 ret = devm_extcon_dev_register(&pdev->dev, info->edev); in max14577_muic_probe()
725 dev_err(&pdev->dev, "failed to register extcon device\n"); in max14577_muic_probe()
730 info->path_usb = CTRL1_SW_USB; in max14577_muic_probe()
731 info->path_uart = CTRL1_SW_UART; in max14577_muic_probe()
735 ret = max14577_bulk_read(info->max14577->regmap, in max14577_muic_probe()
736 MAX14577_MUIC_REG_STATUS1, info->status, 2); in max14577_muic_probe()
738 dev_err(info->dev, "Cannot read STATUS registers\n"); in max14577_muic_probe()
744 max14577_muic_set_path(info, info->path_uart, true); in max14577_muic_probe()
747 ret = max14577_read_reg(info->max14577->regmap, in max14577_muic_probe()
750 dev_err(&pdev->dev, "failed to read revision number\n"); in max14577_muic_probe()
753 dev_info(info->dev, "device ID : 0x%x\n", id); in max14577_muic_probe()
761 * - Use delayed workqueue to detect cable state and then in max14577_muic_probe()
766 INIT_DELAYED_WORK(&info->wq_detcable, max14577_muic_detect_cable_wq); in max14577_muic_probe()
767 queue_delayed_work(system_power_efficient_wq, &info->wq_detcable, in max14577_muic_probe()
774 { "max14577-muic", MAXIM_DEVICE_TYPE_MAX14577, },
775 { "max77836-muic", MAXIM_DEVICE_TYPE_MAX77836, },
781 { .compatible = "maxim,max14577-muic",
783 { .compatible = "maxim,max77836-muic",
791 .name = "max14577-muic",
803 MODULE_ALIAS("platform:extcon-max14577");