Lines Matching +full:max77693 +full:- +full:charger

1 // SPDX-License-Identifier: GPL-2.0+
3 // extcon-max77843.c - Maxim MAX77843 extcon driver to support
9 #include <linux/extcon-provider.h>
13 #include <linux/mfd/max77693-common.h>
14 #include <linux/mfd/max77843-private.h>
106 /* Define charger cable type */
141 { MAX77843_MUIC_IRQ_INT1_ADC, "MUIC-ADC" },
142 { MAX77843_MUIC_IRQ_INT1_ADCERROR, "MUIC-ADC_ERROR" },
143 { MAX77843_MUIC_IRQ_INT1_ADC1K, "MUIC-ADC1K" },
144 { MAX77843_MUIC_IRQ_INT2_CHGTYP, "MUIC-CHGTYP" },
145 { MAX77843_MUIC_IRQ_INT2_CHGDETRUN, "MUIC-CHGDETRUN" },
146 { MAX77843_MUIC_IRQ_INT2_DCDTMR, "MUIC-DCDTMR" },
147 { MAX77843_MUIC_IRQ_INT2_DXOVP, "MUIC-DXOVP" },
148 { MAX77843_MUIC_IRQ_INT2_VBVOLT, "MUIC-VBVOLT" },
149 { MAX77843_MUIC_IRQ_INT3_VBADC, "MUIC-VBADC" },
150 { MAX77843_MUIC_IRQ_INT3_VDNMON, "MUIC-VDNMON" },
151 { MAX77843_MUIC_IRQ_INT3_DNRES, "MUIC-DNRES" },
152 { MAX77843_MUIC_IRQ_INT3_MPNACK, "MUIC-MPNACK"},
153 { MAX77843_MUIC_IRQ_INT3_MRXBUFOW, "MUIC-MRXBUFOW"},
154 { MAX77843_MUIC_IRQ_INT3_MRXTRF, "MUIC-MRXTRF"},
155 { MAX77843_MUIC_IRQ_INT3_MRXPERR, "MUIC-MRXPERR"},
156 { MAX77843_MUIC_IRQ_INT3_MRXRDY, "MUIC-MRXRDY"},
190 .name = "max77843-muic",
201 struct max77693_dev *max77843 = info->max77843; in max77843_muic_set_path()
214 ret = regmap_update_bits(max77843->regmap_muic, in max77843_muic_set_path()
220 dev_err(info->dev, "Cannot switch MUIC port\n"); in max77843_muic_set_path()
229 ret = regmap_update_bits(max77843->regmap_muic, in max77843_muic_set_path()
234 dev_err(info->dev, "Cannot update lowpower mode\n"); in max77843_muic_set_path()
238 dev_dbg(info->dev, in max77843_muic_set_path()
248 struct max77693_dev *max77843 = info->max77843; in max77843_charger_set_otg_vbus()
256 regmap_update_bits(max77843->regmap_chg, MAX77843_CHG_REG_CHG_CNFG_00, in max77843_charger_set_otg_vbus()
265 adc = info->status[MAX77843_MUIC_STATUS1] & in max77843_muic_get_cable_type()
273 cable_type = info->prev_cable_type; in max77843_muic_get_cable_type()
274 info->prev_cable_type = MAX77843_MUIC_ADC_OPEN; in max77843_muic_get_cable_type()
277 cable_type = info->prev_cable_type = adc; in max77843_muic_get_cable_type()
281 chg_type = info->status[MAX77843_MUIC_STATUS2] & in max77843_muic_get_cable_type()
284 /* Check GROUND accessory with charger cable */ in max77843_muic_get_cable_type()
288 * The following state when charger cable is in max77843_muic_get_cable_type()
293 cable_type = info->prev_chg_type; in max77843_muic_get_cable_type()
294 info->prev_chg_type = MAX77843_MUIC_CHG_NONE; in max77843_muic_get_cable_type()
298 * The following state when charger cable is in max77843_muic_get_cable_type()
303 info->prev_chg_type = MAX77843_MUIC_CHG_GND; in max77843_muic_get_cable_type()
311 cable_type = info->prev_chg_type; in max77843_muic_get_cable_type()
312 info->prev_chg_type = MAX77843_MUIC_CHG_NONE; in max77843_muic_get_cable_type()
316 info->prev_chg_type = MAX77843_MUIC_CHG_DOCK; in max77843_muic_get_cable_type()
323 cable_type = info->prev_chg_type; in max77843_muic_get_cable_type()
324 info->prev_chg_type = MAX77843_MUIC_CHG_NONE; in max77843_muic_get_cable_type()
327 cable_type = info->prev_chg_type = chg_type; in max77843_muic_get_cable_type()
333 cable_type = info->prev_gnd_type; in max77843_muic_get_cable_type()
334 info->prev_gnd_type = MAX77843_MUIC_ADC_OPEN; in max77843_muic_get_cable_type()
340 * 0x1| 0| 0| USB-HOST in max77843_muic_get_cable_type()
341 * 0x1| 0| 1| USB-HOST with VB in max77843_muic_get_cable_type()
346 gnd_type = (info->status[MAX77843_MUIC_STATUS1] & in max77843_muic_get_cable_type()
350 gnd_type |= (info->status[MAX77843_MUIC_STATUS2] & in max77843_muic_get_cable_type()
356 cable_type = info->prev_gnd_type = gnd_type; in max77843_muic_get_cable_type()
360 dev_err(info->dev, "Unknown cable group (%d)\n", group); in max77843_muic_get_cable_type()
361 cable_type = -EINVAL; in max77843_muic_get_cable_type()
375 dev_dbg(info->dev, "external connector is %s (gnd:0x%02x)\n", in max77843_muic_adc_gnd_handler()
387 extcon_set_state_sync(info->edev, EXTCON_USB_HOST, attached); in max77843_muic_adc_gnd_handler()
398 extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached); in max77843_muic_adc_gnd_handler()
401 dev_err(info->dev, "failed to detect %s accessory(gnd:0x%x)\n", in max77843_muic_adc_gnd_handler()
403 return -EINVAL; in max77843_muic_adc_gnd_handler()
415 dev_dbg(info->dev, "external connector is %s (adc:0x%02x)\n", in max77843_muic_jig_handler()
427 return -EINVAL; in max77843_muic_jig_handler()
434 extcon_set_state_sync(info->edev, EXTCON_JIG, attached); in max77843_muic_jig_handler()
444 dev_dbg(info->dev, "external connector is %s (adc: 0x10)\n", in max77843_muic_dock_handler()
452 extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached); in max77843_muic_dock_handler()
453 extcon_set_state_sync(info->edev, EXTCON_USB_HOST, attached); in max77843_muic_dock_handler()
454 extcon_set_state_sync(info->edev, EXTCON_DOCK, attached); in max77843_muic_dock_handler()
467 dev_dbg(info->dev, in max77843_muic_adc_handler()
470 info->prev_cable_type); in max77843_muic_adc_handler()
517 dev_err(info->dev, in max77843_muic_adc_handler()
520 return -EAGAIN; in max77843_muic_adc_handler()
522 dev_err(info->dev, in max77843_muic_adc_handler()
525 return -EINVAL; in max77843_muic_adc_handler()
539 dev_dbg(info->dev, in max77843_muic_chg_handler()
542 chg_type, info->prev_chg_type); in max77843_muic_chg_handler()
552 extcon_set_state_sync(info->edev, EXTCON_USB, attached); in max77843_muic_chg_handler()
553 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, in max77843_muic_chg_handler()
563 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP, in max77843_muic_chg_handler()
573 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, in max77843_muic_chg_handler()
583 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW, in max77843_muic_chg_handler()
593 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST, in max77843_muic_chg_handler()
600 /* Charger cable on MHL accessory is attach or detach */ in max77843_muic_chg_handler()
602 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, in max77843_muic_chg_handler()
605 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, in max77843_muic_chg_handler()
609 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, attached); in max77843_muic_chg_handler()
614 dev_err(info->dev, in max77843_muic_chg_handler()
620 return -EINVAL; in max77843_muic_chg_handler()
630 struct max77693_dev *max77843 = info->max77843; in max77843_muic_irq_work()
633 mutex_lock(&info->mutex); in max77843_muic_irq_work()
635 ret = regmap_bulk_read(max77843->regmap_muic, in max77843_muic_irq_work()
636 MAX77843_MUIC_REG_STATUS1, info->status, in max77843_muic_irq_work()
639 dev_err(info->dev, "Cannot read STATUS registers\n"); in max77843_muic_irq_work()
640 mutex_unlock(&info->mutex); in max77843_muic_irq_work()
644 if (info->irq_adc) { in max77843_muic_irq_work()
647 dev_err(info->dev, "Unknown cable type\n"); in max77843_muic_irq_work()
648 info->irq_adc = false; in max77843_muic_irq_work()
651 if (info->irq_chg) { in max77843_muic_irq_work()
654 dev_err(info->dev, "Unknown charger type\n"); in max77843_muic_irq_work()
655 info->irq_chg = false; in max77843_muic_irq_work()
658 mutex_unlock(&info->mutex); in max77843_muic_irq_work()
664 int i, irq_type = -1; in max77843_muic_irq_handler()
674 info->irq_adc = true; in max77843_muic_irq_handler()
681 info->irq_chg = true; in max77843_muic_irq_handler()
693 dev_err(info->dev, "Cannot recognize IRQ(%d)\n", irq_type); in max77843_muic_irq_handler()
697 schedule_work(&info->irq_work); in max77843_muic_irq_handler()
706 struct max77693_dev *max77843 = info->max77843; in max77843_muic_detect_cable_wq()
710 mutex_lock(&info->mutex); in max77843_muic_detect_cable_wq()
712 ret = regmap_bulk_read(max77843->regmap_muic, in max77843_muic_detect_cable_wq()
713 MAX77843_MUIC_REG_STATUS1, info->status, in max77843_muic_detect_cable_wq()
716 dev_err(info->dev, "Cannot read STATUS registers\n"); in max77843_muic_detect_cable_wq()
725 dev_err(info->dev, "Cannot detect accessory\n"); in max77843_muic_detect_cable_wq()
735 dev_err(info->dev, "Cannot detect charger accessory\n"); in max77843_muic_detect_cable_wq()
741 mutex_unlock(&info->mutex); in max77843_muic_detect_cable_wq()
747 struct max77693_dev *max77843 = info->max77843; in max77843_muic_set_debounce_time()
755 ret = regmap_update_bits(max77843->regmap_muic, in max77843_muic_set_debounce_time()
760 dev_err(info->dev, "Cannot write MUIC regmap\n"); in max77843_muic_set_debounce_time()
765 dev_err(info->dev, "Invalid ADC debounce time\n"); in max77843_muic_set_debounce_time()
766 return -EINVAL; in max77843_muic_set_debounce_time()
776 max77843->i2c_muic = i2c_new_dummy_device(max77843->i2c->adapter, in max77843_init_muic_regmap()
778 if (IS_ERR(max77843->i2c_muic)) { in max77843_init_muic_regmap()
779 dev_err(&max77843->i2c->dev, in max77843_init_muic_regmap()
781 return PTR_ERR(max77843->i2c_muic); in max77843_init_muic_regmap()
784 i2c_set_clientdata(max77843->i2c_muic, max77843); in max77843_init_muic_regmap()
786 max77843->regmap_muic = devm_regmap_init_i2c(max77843->i2c_muic, in max77843_init_muic_regmap()
788 if (IS_ERR(max77843->regmap_muic)) { in max77843_init_muic_regmap()
789 ret = PTR_ERR(max77843->regmap_muic); in max77843_init_muic_regmap()
793 ret = regmap_add_irq_chip(max77843->regmap_muic, max77843->irq, in max77843_init_muic_regmap()
795 0, &max77843_muic_irq_chip, &max77843->irq_data_muic); in max77843_init_muic_regmap()
797 dev_err(&max77843->i2c->dev, "Cannot add MUIC IRQ chip\n"); in max77843_init_muic_regmap()
804 i2c_unregister_device(max77843->i2c_muic); in max77843_init_muic_regmap()
811 struct max77693_dev *max77843 = dev_get_drvdata(pdev->dev.parent); in max77843_muic_probe()
818 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in max77843_muic_probe()
820 return -ENOMEM; in max77843_muic_probe()
822 info->dev = &pdev->dev; in max77843_muic_probe()
823 info->max77843 = max77843; in max77843_muic_probe()
826 mutex_init(&info->mutex); in max77843_muic_probe()
831 dev_err(&pdev->dev, "Failed to init MUIC regmap\n"); in max77843_muic_probe()
836 ret = regmap_update_bits(max77843->regmap_muic, in max77843_muic_probe()
843 info->edev = devm_extcon_dev_allocate(&pdev->dev, in max77843_muic_probe()
845 if (IS_ERR(info->edev)) { in max77843_muic_probe()
846 dev_err(&pdev->dev, "Failed to allocate memory for extcon\n"); in max77843_muic_probe()
847 ret = PTR_ERR(info->edev); in max77843_muic_probe()
851 ret = devm_extcon_dev_register(&pdev->dev, info->edev); in max77843_muic_probe()
853 dev_err(&pdev->dev, "Failed to register extcon device\n"); in max77843_muic_probe()
861 ret = regmap_bulk_read(max77843->regmap_muic, in max77843_muic_probe()
862 MAX77843_MUIC_REG_STATUS1, info->status, in max77843_muic_probe()
865 dev_err(info->dev, "Cannot read STATUS registers\n"); in max77843_muic_probe()
875 ret = regmap_read(max77843->regmap_muic, MAX77843_MUIC_REG_ID, &id); in max77843_muic_probe()
877 dev_err(&pdev->dev, "Failed to read revision number\n"); in max77843_muic_probe()
880 dev_info(info->dev, "MUIC device ID : 0x%x\n", id); in max77843_muic_probe()
883 INIT_WORK(&info->irq_work, max77843_muic_irq_work); in max77843_muic_probe()
886 ret = regmap_bulk_read(max77843->regmap_muic, in max77843_muic_probe()
887 MAX77843_MUIC_REG_INT1, info->status, in max77843_muic_probe()
890 dev_err(&pdev->dev, "Failed to Clear IRQ bits\n"); in max77843_muic_probe()
898 virq = regmap_irq_get_virq(max77843->irq_data_muic, in max77843_muic_probe()
899 muic_irq->irq); in max77843_muic_probe()
901 ret = -EINVAL; in max77843_muic_probe()
904 muic_irq->virq = virq; in max77843_muic_probe()
906 ret = devm_request_threaded_irq(&pdev->dev, virq, NULL, in max77843_muic_probe()
908 muic_irq->name, info); in max77843_muic_probe()
910 dev_err(&pdev->dev, in max77843_muic_probe()
912 muic_irq->irq, ret); in max77843_muic_probe()
918 INIT_DELAYED_WORK(&info->wq_detcable, max77843_muic_detect_cable_wq); in max77843_muic_probe()
920 &info->wq_detcable, msecs_to_jiffies(DELAY_MS_DEFAULT)); in max77843_muic_probe()
925 regmap_del_irq_chip(max77843->irq, max77843->irq_data_muic); in max77843_muic_probe()
926 i2c_unregister_device(max77843->i2c_muic); in max77843_muic_probe()
934 struct max77693_dev *max77843 = info->max77843; in max77843_muic_remove()
936 cancel_work_sync(&info->irq_work); in max77843_muic_remove()
937 regmap_del_irq_chip(max77843->irq, max77843->irq_data_muic); in max77843_muic_remove()
938 i2c_unregister_device(max77843->i2c_muic); in max77843_muic_remove()
944 { "max77843-muic", },
951 .name = "max77843-muic",