• Home
  • Raw
  • Download

Lines Matching +full:uart +full:- +full:w +full:- +full:state

1 // SPDX-License-Identifier: GPL-2.0+
3 // extcon-max8997.c - MAX8997 extcon driver to support MAX8997 MUIC
17 #include <linux/mfd/max8997-private.h>
18 #include <linux/extcon-provider.h>
21 #define DEV_NAME "max8997-muic"
38 { MAX8997_MUICIRQ_ADCError, "muic-ADCERROR" },
39 { MAX8997_MUICIRQ_ADCLow, "muic-ADCLOW" },
40 { MAX8997_MUICIRQ_ADC, "muic-ADC" },
41 { MAX8997_MUICIRQ_VBVolt, "muic-VBVOLT" },
42 { MAX8997_MUICIRQ_DBChg, "muic-DBCHG" },
43 { MAX8997_MUICIRQ_DCDTmr, "muic-DCDTMR" },
44 { MAX8997_MUICIRQ_ChgDetRun, "muic-CHGDETRUN" },
45 { MAX8997_MUICIRQ_ChgTyp, "muic-CHGTYP" },
46 { MAX8997_MUICIRQ_OVP, "muic-OVP" },
75 MAX8997_MUIC_ADC_FACTORY_MODE_USB_OFF, /* JIG-USB-OFF */
76 MAX8997_MUIC_ADC_FACTORY_MODE_USB_ON, /* JIG-USB-ON */
79 MAX8997_MUIC_ADC_FACTORY_MODE_UART_OFF, /* JIG-UART */
123 * Use delayed workqueue to detect cable state and then
124 * notify cable state to notifiee/platform through uevent.
126 * driver should notify cable state to upper layer.
131 * Default usb/uart path whether UART/USB or AUX_UART/AUX_USB
132 * h/w path of COMP2/COMN1 on CONTROL1 register.
153 * max8997_muic_set_debounce_time - Set the debounce time of ADC
167 ret = max8997_update_reg(info->muic, in max8997_muic_set_debounce_time()
172 dev_err(info->dev, "failed to set ADC debounce time\n"); in max8997_muic_set_debounce_time()
177 dev_err(info->dev, "invalid ADC debounce time\n"); in max8997_muic_set_debounce_time()
178 return -EINVAL; in max8997_muic_set_debounce_time()
185 * max8997_muic_set_path - Set hardware line according to attached cable
188 * @attached: the state of cable (true:attached, false:detached)
190 * The max8997 MUIC device share outside H/W line among a varity of cables,
191 * so this function set internal path of H/W line according to the type of
205 ret = max8997_update_reg(info->muic, in max8997_muic_set_path()
208 dev_err(info->dev, "failed to update MUIC register\n"); in max8997_muic_set_path()
217 ret = max8997_update_reg(info->muic, in max8997_muic_set_path()
221 dev_err(info->dev, "failed to update MUIC register\n"); in max8997_muic_set_path()
225 dev_info(info->dev, in max8997_muic_set_path()
226 "CONTROL1 : 0x%02x, CONTROL2 : 0x%02x, state : %s\n", in max8997_muic_set_path()
233 * max8997_muic_get_cable_type - Return cable type and check cable state
236 * @attached: store cable state and return
238 * This function check the cable state either attached or detached,
240 * - MAX8997_CABLE_GROUP_ADC
241 * - MAX8997_CABLE_GROUP_CHG
253 * Read ADC value to check cable type and decide cable state in max8997_muic_get_cable_type()
256 adc = info->status[0] & STATUS1_ADC_MASK; in max8997_muic_get_cable_type()
260 * Check current cable state/cable type and store cable type in max8997_muic_get_cable_type()
261 * (info->prev_cable_type) for handling cable when cable is in max8997_muic_get_cable_type()
267 cable_type = info->prev_cable_type; in max8997_muic_get_cable_type()
268 info->prev_cable_type = MAX8997_MUIC_ADC_OPEN; in max8997_muic_get_cable_type()
272 cable_type = info->prev_cable_type = adc; in max8997_muic_get_cable_type()
277 * Read charger type to check cable type and decide cable state in max8997_muic_get_cable_type()
280 chg_type = info->status[1] & STATUS2_CHGTYP_MASK; in max8997_muic_get_cable_type()
286 cable_type = info->prev_chg_type; in max8997_muic_get_cable_type()
287 info->prev_chg_type = MAX8997_CHARGER_TYPE_NONE; in max8997_muic_get_cable_type()
292 * Check current cable state/cable type and store cable in max8997_muic_get_cable_type()
293 * type(info->prev_chg_type) for handling cable when in max8997_muic_get_cable_type()
296 cable_type = info->prev_chg_type = chg_type; in max8997_muic_get_cable_type()
301 dev_err(info->dev, "Unknown cable group (%d)\n", group); in max8997_muic_get_cable_type()
302 cable_type = -EINVAL; in max8997_muic_get_cable_type()
314 ret = max8997_muic_set_path(info, info->path_usb, attached); in max8997_muic_handle_usb()
316 dev_err(info->dev, "failed to update muic register\n"); in max8997_muic_handle_usb()
322 extcon_set_state_sync(info->edev, EXTCON_USB_HOST, attached); in max8997_muic_handle_usb()
325 extcon_set_state_sync(info->edev, EXTCON_USB, attached); in max8997_muic_handle_usb()
326 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP, in max8997_muic_handle_usb()
330 dev_err(info->dev, "failed to detect %s usb cable\n", in max8997_muic_handle_usb()
332 return -EINVAL; in max8997_muic_handle_usb()
345 dev_err(info->dev, "failed to update muic register\n"); in max8997_muic_handle_dock()
352 extcon_set_state_sync(info->edev, EXTCON_DOCK, attached); in max8997_muic_handle_dock()
355 dev_err(info->dev, "failed to detect %s dock device\n", in max8997_muic_handle_dock()
357 return -EINVAL; in max8997_muic_handle_dock()
368 /* switch to UART */ in max8997_muic_handle_jig_uart()
369 ret = max8997_muic_set_path(info, info->path_uart, attached); in max8997_muic_handle_jig_uart()
371 dev_err(info->dev, "failed to update muic register\n"); in max8997_muic_handle_jig_uart()
375 extcon_set_state_sync(info->edev, EXTCON_JIG, attached); in max8997_muic_handle_jig_uart()
386 /* Check cable state which is either detached or attached */ in max8997_muic_adc_handler()
397 extcon_set_state_sync(info->edev, EXTCON_DISP_MHL, attached); in max8997_muic_adc_handler()
444 dev_info(info->dev, in max8997_muic_adc_handler()
447 return -EAGAIN; in max8997_muic_adc_handler()
449 dev_err(info->dev, in max8997_muic_adc_handler()
452 return -EINVAL; in max8997_muic_adc_handler()
471 adc = info->status[0] & STATUS1_ADC_MASK; in max8997_muic_chg_handler()
480 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_CDP, in max8997_muic_chg_handler()
484 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_DCP, in max8997_muic_chg_handler()
488 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SLOW, in max8997_muic_chg_handler()
492 extcon_set_state_sync(info->edev, EXTCON_CHG_USB_FAST, in max8997_muic_chg_handler()
496 dev_err(info->dev, in max8997_muic_chg_handler()
499 return -EINVAL; in max8997_muic_chg_handler()
512 if (!info->edev) in max8997_muic_irq_work()
515 mutex_lock(&info->mutex); in max8997_muic_irq_work()
518 if (info->irq == muic_irqs[i].virq) in max8997_muic_irq_work()
521 ret = max8997_bulk_read(info->muic, MAX8997_MUIC_REG_STATUS1, in max8997_muic_irq_work()
522 2, info->status); in max8997_muic_irq_work()
524 dev_err(info->dev, "failed to read muic register\n"); in max8997_muic_irq_work()
525 mutex_unlock(&info->mutex); in max8997_muic_irq_work()
547 dev_info(info->dev, "misc interrupt: irq %d occurred\n", in max8997_muic_irq_work()
549 mutex_unlock(&info->mutex); in max8997_muic_irq_work()
554 dev_err(info->dev, "failed to handle MUIC interrupt\n"); in max8997_muic_irq_work()
556 mutex_unlock(&info->mutex); in max8997_muic_irq_work()
563 dev_dbg(info->dev, "irq:%d\n", irq); in max8997_muic_irq_handler()
564 info->irq = irq; in max8997_muic_irq_handler()
566 schedule_work(&info->irq_work); in max8997_muic_irq_handler()
578 mutex_lock(&info->mutex); in max8997_muic_detect_dev()
581 ret = max8997_bulk_read(info->muic, in max8997_muic_detect_dev()
582 MAX8997_MUIC_REG_STATUS1, 2, info->status); in max8997_muic_detect_dev()
584 dev_err(info->dev, "failed to read MUIC register\n"); in max8997_muic_detect_dev()
585 mutex_unlock(&info->mutex); in max8997_muic_detect_dev()
594 dev_err(info->dev, "Cannot detect ADC cable\n"); in max8997_muic_detect_dev()
595 mutex_unlock(&info->mutex); in max8997_muic_detect_dev()
605 dev_err(info->dev, "Cannot detect charger cable\n"); in max8997_muic_detect_dev()
606 mutex_unlock(&info->mutex); in max8997_muic_detect_dev()
611 mutex_unlock(&info->mutex); in max8997_muic_detect_dev()
624 dev_err(info->dev, "failed to detect cable type\n"); in max8997_muic_detect_cable_wq()
629 struct max8997_dev *max8997 = dev_get_drvdata(pdev->dev.parent); in max8997_muic_probe()
630 struct max8997_platform_data *pdata = dev_get_platdata(max8997->dev); in max8997_muic_probe()
637 info = devm_kzalloc(&pdev->dev, sizeof(struct max8997_muic_info), in max8997_muic_probe()
640 return -ENOMEM; in max8997_muic_probe()
642 info->dev = &pdev->dev; in max8997_muic_probe()
643 info->muic = max8997->muic; in max8997_muic_probe()
646 mutex_init(&info->mutex); in max8997_muic_probe()
648 INIT_WORK(&info->irq_work, max8997_muic_irq_work); in max8997_muic_probe()
654 virq = irq_create_mapping(max8997->irq_domain, muic_irq->irq); in max8997_muic_probe()
656 ret = -EINVAL; in max8997_muic_probe()
659 muic_irq->virq = virq; in max8997_muic_probe()
664 muic_irq->name, info); in max8997_muic_probe()
666 dev_err(&pdev->dev, in max8997_muic_probe()
668 muic_irq->irq, ret); in max8997_muic_probe()
674 info->edev = devm_extcon_dev_allocate(&pdev->dev, max8997_extcon_cable); in max8997_muic_probe()
675 if (IS_ERR(info->edev)) { in max8997_muic_probe()
676 dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); in max8997_muic_probe()
677 ret = PTR_ERR(info->edev); in max8997_muic_probe()
681 ret = devm_extcon_dev_register(&pdev->dev, info->edev); in max8997_muic_probe()
683 dev_err(&pdev->dev, "failed to register extcon device\n"); in max8997_muic_probe()
687 if (pdata && pdata->muic_pdata) { in max8997_muic_probe()
689 = pdata->muic_pdata; in max8997_muic_probe()
692 for (i = 0; i < muic_pdata->num_init_data; i++) { in max8997_muic_probe()
693 max8997_write_reg(info->muic, in max8997_muic_probe()
694 muic_pdata->init_data[i].addr, in max8997_muic_probe()
695 muic_pdata->init_data[i].data); in max8997_muic_probe()
699 * Default usb/uart path whether UART/USB or AUX_UART/AUX_USB in max8997_muic_probe()
700 * h/w path of COMP2/COMN1 on CONTROL1 register. in max8997_muic_probe()
702 if (muic_pdata->path_uart) in max8997_muic_probe()
703 info->path_uart = muic_pdata->path_uart; in max8997_muic_probe()
705 info->path_uart = CONTROL1_SW_UART; in max8997_muic_probe()
707 if (muic_pdata->path_usb) in max8997_muic_probe()
708 info->path_usb = muic_pdata->path_usb; in max8997_muic_probe()
710 info->path_usb = CONTROL1_SW_USB; in max8997_muic_probe()
713 * Default delay time for detecting cable state in max8997_muic_probe()
716 if (muic_pdata->detcable_delay_ms) in max8997_muic_probe()
718 msecs_to_jiffies(muic_pdata->detcable_delay_ms); in max8997_muic_probe()
722 info->path_uart = CONTROL1_SW_UART; in max8997_muic_probe()
723 info->path_usb = CONTROL1_SW_USB; in max8997_muic_probe()
727 /* Set initial path for UART when JIG is connected to get serial logs */ in max8997_muic_probe()
728 ret = max8997_bulk_read(info->muic, MAX8997_MUIC_REG_STATUS1, in max8997_muic_probe()
729 2, info->status); in max8997_muic_probe()
731 dev_err(info->dev, "failed to read MUIC register\n"); in max8997_muic_probe()
737 max8997_muic_set_path(info, info->path_uart, true); in max8997_muic_probe()
745 * - Use delayed workqueue to detect cable state and then in max8997_muic_probe()
746 * notify cable state to notifiee/platform through uevent. in max8997_muic_probe()
748 * driver should notify cable state to upper layer. in max8997_muic_probe()
750 INIT_DELAYED_WORK(&info->wq_detcable, max8997_muic_detect_cable_wq); in max8997_muic_probe()
751 queue_delayed_work(system_power_efficient_wq, &info->wq_detcable, in max8997_muic_probe()
757 while (--i >= 0) in max8997_muic_probe()
769 cancel_work_sync(&info->irq_work); in max8997_muic_remove()
787 MODULE_ALIAS("platform:max8997-muic");