18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/i2c.h>
21 #include <linux/slab.h>
31 #define DEV_NAME "max8997-muic"
34 #define STATUS1_ADC_SHIFT 0
35 #define STATUS1_ADCLOW_SHIFT 5
36 #define STATUS1_ADCERR_SHIFT 6
37 #define STATUS1_ADC_MASK (0x1f << STATUS1_ADC_SHIFT)
38 #define STATUS1_ADCLOW_MASK (0x1 << STATUS1_ADCLOW_SHIFT)
39 #define STATUS1_ADCERR_MASK (0x1 << STATUS1_ADCERR_SHIFT)
42 #define STATUS2_CHGTYP_SHIFT 0
43 #define STATUS2_CHGDETRUN_SHIFT 3
44 #define STATUS2_DCDTMR_SHIFT 4
45 #define STATUS2_DBCHG_SHIFT 5
46 #define STATUS2_VBVOLT_SHIFT 6
47 #define STATUS2_CHGTYP_MASK (0x7 << STATUS2_CHGTYP_SHIFT)
48 #define STATUS2_CHGDETRUN_MASK (0x1 << STATUS2_CHGDETRUN_SHIFT)
49 #define STATUS2_DCDTMR_MASK (0x1 << STATUS2_DCDTMR_SHIFT)
50 #define STATUS2_DBCHG_MASK (0x1 << STATUS2_DBCHG_SHIFT)
51 #define STATUS2_VBVOLT_MASK (0x1 << STATUS2_VBVOLT_SHIFT)
54 #define STATUS3_OVP_SHIFT 2
55 #define STATUS3_OVP_MASK (0x1 << STATUS3_OVP_SHIFT)
58 #define COMN1SW_SHIFT 0
59 #define COMP2SW_SHIFT 3
60 #define COMN1SW_MASK (0x7 << COMN1SW_SHIFT)
61 #define COMP2SW_MASK (0x7 << COMP2SW_SHIFT)
62 #define SW_MASK (COMP2SW_MASK | COMN1SW_MASK)
64 #define MAX8997_SW_USB ((1 << COMP2SW_SHIFT) | (1 << COMN1SW_SHIFT))
65 #define MAX8997_SW_AUDIO ((2 << COMP2SW_SHIFT) | (2 << COMN1SW_SHIFT))
66 #define MAX8997_SW_UART ((3 << COMP2SW_SHIFT) | (3 << COMN1SW_SHIFT))
67 #define MAX8997_SW_OPEN ((0 << COMP2SW_SHIFT) | (0 << COMN1SW_SHIFT))
69 #define MAX8997_ADC_GROUND 0x00
70 #define MAX8997_ADC_MHL 0x01
71 #define MAX8997_ADC_JIG_USB_1 0x18
72 #define MAX8997_ADC_JIG_USB_2 0x19
73 #define MAX8997_ADC_DESKDOCK 0x1a
74 #define MAX8997_ADC_JIG_UART 0x1c
75 #define MAX8997_ADC_CARDOCK 0x1d
76 #define MAX8997_ADC_OPEN 0x1f
116 [3] =
"Fast-charger",
117 [4] =
"Slow-charger",
118 [5] =
"Charge-downstream",
138 dev_err(info->
dev,
"failed to update muic register\n");
160 int adc,
bool attached)
169 dev_err(info->
dev,
"failed to update muic register\n");
198 dev_err(info->
dev,
"failed to update muic register\n");
224 ret = max8997_muic_handle_dock(info, info->
pre_adc,
false);
227 ret = max8997_muic_handle_jig_uart(info,
false);
253 ret = max8997_muic_handle_dock(info, adc,
true);
256 ret = max8997_muic_handle_jig_uart(info,
true);
259 ret = max8997_muic_handle_adc_detach(info);
271 static int max8997_muic_handle_charger_type_detach(
306 dev_err(info->
dev,
"failed to read muic register\n");
310 switch (charger_type) {
312 ret = max8997_muic_handle_charger_type_detach(info);
316 max8997_muic_handle_usb(info,
356 dev_err(info->
dev,
"failed to read muic register\n");
361 dev_dbg(info->
dev,
"%s: STATUS1:0x%x, 2:0x%x\n", __func__,
362 status[0], status[1]);
365 if (info->
irq == muic_irqs[i].
virq)
366 irq_type = muic_irqs[
i].
irq;
373 max8997_muic_handle_adc(info, adc);
379 max8997_muic_handle_charger_type(info, chg_type);
382 dev_info(info->
dev,
"misc interrupt: irq %d occurred\n",
407 u8 status[2],
adc, chg_type;
412 dev_err(info->
dev,
"failed to read muic register\n");
416 dev_info(info->
dev,
"STATUS1:0x%x, STATUS2:0x%x\n",
417 status[0], status[1]);
425 max8997_muic_handle_adc(info, adc);
426 max8997_muic_handle_charger_type(info, chg_type);
438 dev_err(&pdev->
dev,
"failed to allocate memory\n");
446 platform_set_drvdata(pdev, info);
461 0, muic_irq->
name, info);
464 "failed: irq request (IRQ: %d,"
474 dev_err(&pdev->
dev,
"failed to allocate memory for extcon\n");
482 dev_err(&pdev->
dev,
"failed to register extcon device\n");
497 max8997_muic_detect_dev(info);
533 .probe = max8997_muic_probe,