Lines Matching +full:uart +full:- +full:attached

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>
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",
200 u8 val, bool attached, bool nobccomp) in max77843_muic_set_path() argument
202 struct max77693_dev *max77843 = info->max77843; in max77843_muic_set_path()
206 if (attached) in max77843_muic_set_path()
215 ret = regmap_update_bits(max77843->regmap_muic, in max77843_muic_set_path()
221 dev_err(info->dev, "Cannot switch MUIC port\n"); in max77843_muic_set_path()
225 if (attached) in max77843_muic_set_path()
230 ret = regmap_update_bits(max77843->regmap_muic, in max77843_muic_set_path()
235 dev_err(info->dev, "Cannot update lowpower mode\n"); in max77843_muic_set_path()
239 dev_dbg(info->dev, in max77843_muic_set_path()
241 ctrl1, ctrl2, attached ? "attached" : "detached"); in max77843_muic_set_path()
249 struct max77693_dev *max77843 = info->max77843; in max77843_charger_set_otg_vbus()
257 regmap_update_bits(max77843->regmap_chg, MAX77843_CHG_REG_CHG_CNFG_00, in max77843_charger_set_otg_vbus()
262 enum max77843_muic_cable_group group, bool *attached) in max77843_muic_get_cable_type() argument
266 adc = info->status[MAX77843_MUIC_STATUS1] & in max77843_muic_get_cable_type()
273 *attached = false; in max77843_muic_get_cable_type()
274 cable_type = info->prev_cable_type; in max77843_muic_get_cable_type()
275 info->prev_cable_type = MAX77843_MUIC_ADC_OPEN; in max77843_muic_get_cable_type()
277 *attached = true; in max77843_muic_get_cable_type()
278 cable_type = info->prev_cable_type = adc; in max77843_muic_get_cable_type()
282 chg_type = info->status[MAX77843_MUIC_STATUS2] & in max77843_muic_get_cable_type()
293 *attached = false; in max77843_muic_get_cable_type()
294 cable_type = info->prev_chg_type; in max77843_muic_get_cable_type()
295 info->prev_chg_type = MAX77843_MUIC_CHG_NONE; in max77843_muic_get_cable_type()
302 *attached = true; in max77843_muic_get_cable_type()
304 info->prev_chg_type = MAX77843_MUIC_CHG_GND; in max77843_muic_get_cable_type()
311 *attached = false; in max77843_muic_get_cable_type()
312 cable_type = info->prev_chg_type; in max77843_muic_get_cable_type()
313 info->prev_chg_type = MAX77843_MUIC_CHG_NONE; in max77843_muic_get_cable_type()
315 *attached = true; in max77843_muic_get_cable_type()
317 info->prev_chg_type = MAX77843_MUIC_CHG_DOCK; in max77843_muic_get_cable_type()
323 *attached = false; in max77843_muic_get_cable_type()
324 cable_type = info->prev_chg_type; in max77843_muic_get_cable_type()
325 info->prev_chg_type = MAX77843_MUIC_CHG_NONE; in max77843_muic_get_cable_type()
327 *attached = true; in max77843_muic_get_cable_type()
328 cable_type = info->prev_chg_type = chg_type; in max77843_muic_get_cable_type()
333 *attached = false; in max77843_muic_get_cable_type()
334 cable_type = info->prev_gnd_type; in max77843_muic_get_cable_type()
335 info->prev_gnd_type = MAX77843_MUIC_ADC_OPEN; in max77843_muic_get_cable_type()
337 *attached = true; in max77843_muic_get_cable_type()
341 * 0x1| 0| 0| USB-HOST in max77843_muic_get_cable_type()
342 * 0x1| 0| 1| USB-HOST with VB in max77843_muic_get_cable_type()
347 gnd_type = (info->status[MAX77843_MUIC_STATUS1] & in max77843_muic_get_cable_type()
351 gnd_type |= (info->status[MAX77843_MUIC_STATUS2] & in max77843_muic_get_cable_type()
357 cable_type = info->prev_gnd_type = gnd_type; in max77843_muic_get_cable_type()
361 dev_err(info->dev, "Unknown cable group (%d)\n", group); in max77843_muic_get_cable_type()
362 cable_type = -EINVAL; in max77843_muic_get_cable_type()
372 bool attached; in max77843_muic_adc_gnd_handler() local
375 MAX77843_CABLE_GROUP_ADC_GND, &attached); in max77843_muic_adc_gnd_handler()
376 dev_dbg(info->dev, "external connector is %s (gnd:0x%02x)\n", in max77843_muic_adc_gnd_handler()
377 attached ? "attached" : "detached", gnd_cable_type); in max77843_muic_adc_gnd_handler()
384 attached, false); in max77843_muic_adc_gnd_handler()
388 extcon_set_state_sync(info->edev, EXTCON_USB_HOST, attached); in max77843_muic_adc_gnd_handler()
389 max77843_charger_set_otg_vbus(info, attached); in max77843_muic_adc_gnd_handler()
395 attached, false); in max77843_muic_adc_gnd_handler()
399 extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached); in max77843_muic_adc_gnd_handler()
402 dev_err(info->dev, "failed to detect %s accessory(gnd:0x%x)\n", in max77843_muic_adc_gnd_handler()
403 attached ? "attached" : "detached", gnd_cable_type); in max77843_muic_adc_gnd_handler()
404 return -EINVAL; in max77843_muic_adc_gnd_handler()
411 int cable_type, bool attached) in max77843_muic_jig_handler() argument
416 dev_dbg(info->dev, "external connector is %s (adc:0x%02x)\n", in max77843_muic_jig_handler()
417 attached ? "attached" : "detached", cable_type); in max77843_muic_jig_handler()
428 return -EINVAL; in max77843_muic_jig_handler()
431 ret = max77843_muic_set_path(info, path, attached, false); in max77843_muic_jig_handler()
435 extcon_set_state_sync(info->edev, EXTCON_JIG, attached); in max77843_muic_jig_handler()
441 bool attached) in max77843_muic_dock_handler() argument
445 dev_dbg(info->dev, "external connector is %s (adc: 0x10)\n", in max77843_muic_dock_handler()
446 attached ? "attached" : "detached"); in max77843_muic_dock_handler()
449 attached, attached); in max77843_muic_dock_handler()
453 extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached); in max77843_muic_dock_handler()
454 extcon_set_state_sync(info->edev, EXTCON_USB_HOST, attached); in max77843_muic_dock_handler()
455 extcon_set_state_sync(info->edev, EXTCON_DOCK, attached); in max77843_muic_dock_handler()
463 bool attached; in max77843_muic_adc_handler() local
466 MAX77843_CABLE_GROUP_ADC, &attached); in max77843_muic_adc_handler()
468 dev_dbg(info->dev, in max77843_muic_adc_handler()
470 attached ? "attached" : "detached", cable_type, in max77843_muic_adc_handler()
471 info->prev_cable_type); in max77843_muic_adc_handler()
475 ret = max77843_muic_dock_handler(info, attached); in max77843_muic_adc_handler()
487 ret = max77843_muic_jig_handler(info, cable_type, attached); in max77843_muic_adc_handler()
518 dev_err(info->dev, in max77843_muic_adc_handler()
520 attached ? "attached" : "detached", cable_type); in max77843_muic_adc_handler()
521 return -EAGAIN; in max77843_muic_adc_handler()
523 dev_err(info->dev, in max77843_muic_adc_handler()
525 attached ? "attached" : "detached", cable_type); in max77843_muic_adc_handler()
526 return -EINVAL; in max77843_muic_adc_handler()
535 bool attached; in max77843_muic_chg_handler() local
538 MAX77843_CABLE_GROUP_CHG, &attached); in max77843_muic_chg_handler()
540 dev_dbg(info->dev, in max77843_muic_chg_handler()
542 attached ? "attached" : "detached", in max77843_muic_chg_handler()
543 chg_type, info->prev_chg_type); in max77843_muic_chg_handler()
549 attached, false); in max77843_muic_chg_handler()
553 extcon_set_state_sync(info->edev, EXTCON_USB, attached); in max77843_muic_chg_handler()
554 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, in max77843_muic_chg_handler()
555 attached); in max77843_muic_chg_handler()
560 attached, false); in max77843_muic_chg_handler()
564 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP, in max77843_muic_chg_handler()
565 attached); in max77843_muic_chg_handler()
570 attached, false); in max77843_muic_chg_handler()
574 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, in max77843_muic_chg_handler()
575 attached); in max77843_muic_chg_handler()
580 attached, false); in max77843_muic_chg_handler()
584 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW, in max77843_muic_chg_handler()
585 attached); in max77843_muic_chg_handler()
590 attached, false); in max77843_muic_chg_handler()
594 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST, in max77843_muic_chg_handler()
595 attached); in max77843_muic_chg_handler()
599 MAX77843_CABLE_GROUP_ADC_GND, &attached); in max77843_muic_chg_handler()
603 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, in max77843_muic_chg_handler()
606 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, in max77843_muic_chg_handler()
610 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, attached); in max77843_muic_chg_handler()
615 dev_err(info->dev, in max77843_muic_chg_handler()
617 attached ? "attached" : "detached", chg_type); in max77843_muic_chg_handler()
620 attached, false); in max77843_muic_chg_handler()
621 return -EINVAL; in max77843_muic_chg_handler()
631 struct max77693_dev *max77843 = info->max77843; in max77843_muic_irq_work()
634 mutex_lock(&info->mutex); in max77843_muic_irq_work()
636 ret = regmap_bulk_read(max77843->regmap_muic, in max77843_muic_irq_work()
637 MAX77843_MUIC_REG_STATUS1, info->status, in max77843_muic_irq_work()
640 dev_err(info->dev, "Cannot read STATUS registers\n"); in max77843_muic_irq_work()
641 mutex_unlock(&info->mutex); in max77843_muic_irq_work()
645 if (info->irq_adc) { in max77843_muic_irq_work()
648 dev_err(info->dev, "Unknown cable type\n"); in max77843_muic_irq_work()
649 info->irq_adc = false; in max77843_muic_irq_work()
652 if (info->irq_chg) { in max77843_muic_irq_work()
655 dev_err(info->dev, "Unknown charger type\n"); in max77843_muic_irq_work()
656 info->irq_chg = false; in max77843_muic_irq_work()
659 mutex_unlock(&info->mutex); in max77843_muic_irq_work()
665 int i, irq_type = -1; in max77843_muic_irq_handler()
675 info->irq_adc = true; in max77843_muic_irq_handler()
682 info->irq_chg = true; in max77843_muic_irq_handler()
694 dev_err(info->dev, "Cannot recognize IRQ(%d)\n", irq_type); in max77843_muic_irq_handler()
698 schedule_work(&info->irq_work); in max77843_muic_irq_handler()
707 struct max77693_dev *max77843 = info->max77843; in max77843_muic_detect_cable_wq()
709 bool attached; in max77843_muic_detect_cable_wq() local
711 mutex_lock(&info->mutex); in max77843_muic_detect_cable_wq()
713 ret = regmap_bulk_read(max77843->regmap_muic, in max77843_muic_detect_cable_wq()
714 MAX77843_MUIC_REG_STATUS1, info->status, in max77843_muic_detect_cable_wq()
717 dev_err(info->dev, "Cannot read STATUS registers\n"); in max77843_muic_detect_cable_wq()
722 MAX77843_CABLE_GROUP_ADC, &attached); in max77843_muic_detect_cable_wq()
723 if (attached && adc != MAX77843_MUIC_ADC_OPEN) { in max77843_muic_detect_cable_wq()
726 dev_err(info->dev, "Cannot detect accessory\n"); in max77843_muic_detect_cable_wq()
732 MAX77843_CABLE_GROUP_CHG, &attached); in max77843_muic_detect_cable_wq()
733 if (attached && chg_type != MAX77843_MUIC_CHG_NONE) { in max77843_muic_detect_cable_wq()
736 dev_err(info->dev, "Cannot detect charger accessory\n"); in max77843_muic_detect_cable_wq()
742 mutex_unlock(&info->mutex); in max77843_muic_detect_cable_wq()
748 struct max77693_dev *max77843 = info->max77843; in max77843_muic_set_debounce_time()
756 ret = regmap_update_bits(max77843->regmap_muic, in max77843_muic_set_debounce_time()
761 dev_err(info->dev, "Cannot write MUIC regmap\n"); in max77843_muic_set_debounce_time()
766 dev_err(info->dev, "Invalid ADC debounce time\n"); in max77843_muic_set_debounce_time()
767 return -EINVAL; in max77843_muic_set_debounce_time()
777 max77843->i2c_muic = i2c_new_dummy_device(max77843->i2c->adapter, in max77843_init_muic_regmap()
779 if (IS_ERR(max77843->i2c_muic)) { in max77843_init_muic_regmap()
780 dev_err(&max77843->i2c->dev, in max77843_init_muic_regmap()
782 return PTR_ERR(max77843->i2c_muic); in max77843_init_muic_regmap()
785 i2c_set_clientdata(max77843->i2c_muic, max77843); in max77843_init_muic_regmap()
787 max77843->regmap_muic = devm_regmap_init_i2c(max77843->i2c_muic, in max77843_init_muic_regmap()
789 if (IS_ERR(max77843->regmap_muic)) { in max77843_init_muic_regmap()
790 ret = PTR_ERR(max77843->regmap_muic); in max77843_init_muic_regmap()
794 ret = regmap_add_irq_chip(max77843->regmap_muic, max77843->irq, in max77843_init_muic_regmap()
796 0, &max77843_muic_irq_chip, &max77843->irq_data_muic); in max77843_init_muic_regmap()
798 dev_err(&max77843->i2c->dev, "Cannot add MUIC IRQ chip\n"); in max77843_init_muic_regmap()
805 i2c_unregister_device(max77843->i2c_muic); in max77843_init_muic_regmap()
812 struct max77693_dev *max77843 = dev_get_drvdata(pdev->dev.parent); in max77843_muic_probe()
816 bool attached; in max77843_muic_probe() local
819 info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); in max77843_muic_probe()
821 return -ENOMEM; in max77843_muic_probe()
823 info->dev = &pdev->dev; in max77843_muic_probe()
824 info->max77843 = max77843; in max77843_muic_probe()
827 mutex_init(&info->mutex); in max77843_muic_probe()
832 dev_err(&pdev->dev, "Failed to init MUIC regmap\n"); in max77843_muic_probe()
837 ret = regmap_update_bits(max77843->regmap_muic, in max77843_muic_probe()
844 info->edev = devm_extcon_dev_allocate(&pdev->dev, in max77843_muic_probe()
846 if (IS_ERR(info->edev)) { in max77843_muic_probe()
847 dev_err(&pdev->dev, "Failed to allocate memory for extcon\n"); in max77843_muic_probe()
848 ret = PTR_ERR(info->edev); in max77843_muic_probe()
852 ret = devm_extcon_dev_register(&pdev->dev, info->edev); in max77843_muic_probe()
854 dev_err(&pdev->dev, "Failed to register extcon device\n"); in max77843_muic_probe()
861 /* Set initial path for UART when JIG is connected to get serial logs */ in max77843_muic_probe()
862 ret = regmap_bulk_read(max77843->regmap_muic, in max77843_muic_probe()
863 MAX77843_MUIC_REG_STATUS1, info->status, in max77843_muic_probe()
866 dev_err(info->dev, "Cannot read STATUS registers\n"); in max77843_muic_probe()
870 &attached); in max77843_muic_probe()
871 if (attached && cable_type == MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF) in max77843_muic_probe()
876 ret = regmap_read(max77843->regmap_muic, MAX77843_MUIC_REG_ID, &id); in max77843_muic_probe()
878 dev_err(&pdev->dev, "Failed to read revision number\n"); in max77843_muic_probe()
881 dev_info(info->dev, "MUIC device ID : 0x%x\n", id); in max77843_muic_probe()
884 INIT_WORK(&info->irq_work, max77843_muic_irq_work); in max77843_muic_probe()
887 ret = regmap_bulk_read(max77843->regmap_muic, in max77843_muic_probe()
888 MAX77843_MUIC_REG_INT1, info->status, in max77843_muic_probe()
891 dev_err(&pdev->dev, "Failed to Clear IRQ bits\n"); in max77843_muic_probe()
899 virq = regmap_irq_get_virq(max77843->irq_data_muic, in max77843_muic_probe()
900 muic_irq->irq); in max77843_muic_probe()
902 ret = -EINVAL; in max77843_muic_probe()
905 muic_irq->virq = virq; in max77843_muic_probe()
907 ret = devm_request_threaded_irq(&pdev->dev, virq, NULL, in max77843_muic_probe()
909 muic_irq->name, info); in max77843_muic_probe()
911 dev_err(&pdev->dev, in max77843_muic_probe()
913 muic_irq->irq, ret); in max77843_muic_probe()
919 INIT_DELAYED_WORK(&info->wq_detcable, max77843_muic_detect_cable_wq); in max77843_muic_probe()
921 &info->wq_detcable, msecs_to_jiffies(DELAY_MS_DEFAULT)); in max77843_muic_probe()
926 regmap_del_irq_chip(max77843->irq, max77843->irq_data_muic); in max77843_muic_probe()
927 i2c_unregister_device(max77843->i2c_muic); in max77843_muic_probe()
935 struct max77693_dev *max77843 = info->max77843; in max77843_muic_remove()
937 cancel_work_sync(&info->irq_work); in max77843_muic_remove()
938 regmap_del_irq_chip(max77843->irq, max77843->irq_data_muic); in max77843_muic_remove()
939 i2c_unregister_device(max77843->i2c_muic); in max77843_muic_remove()
945 { "max77843-muic", },
952 .name = "max77843-muic",