2 * extcon-max77843.c - Maxim MAX77843 extcon driver to support
3 * MUIC(Micro USB Interface Controller)
5 * Copyright (C) 2015 Samsung Electronics
6 * Author: Jaewon Kim <jaewon02.kim@samsung.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
14 #include <linux/extcon.h>
15 #include <linux/i2c.h>
16 #include <linux/interrupt.h>
17 #include <linux/kernel.h>
18 #include <linux/mfd/max77693-common.h>
19 #include <linux/mfd/max77843-private.h>
20 #include <linux/module.h>
21 #include <linux/platform_device.h>
22 #include <linux/workqueue.h>
24 #define DELAY_MS_DEFAULT 15000 /* unit: millisecond */
26 enum max77843_muic_status
{
27 MAX77843_MUIC_STATUS1
= 0,
28 MAX77843_MUIC_STATUS2
,
29 MAX77843_MUIC_STATUS3
,
31 MAX77843_MUIC_STATUS_NUM
,
34 struct max77843_muic_info
{
36 struct max77693_dev
*max77843
;
37 struct extcon_dev
*edev
;
40 struct work_struct irq_work
;
41 struct delayed_work wq_detcable
;
43 u8 status
[MAX77843_MUIC_STATUS_NUM
];
52 enum max77843_muic_cable_group
{
53 MAX77843_CABLE_GROUP_ADC
= 0,
54 MAX77843_CABLE_GROUP_ADC_GND
,
55 MAX77843_CABLE_GROUP_CHG
,
58 enum max77843_muic_adc_debounce_time
{
59 MAX77843_DEBOUNCE_TIME_5MS
= 0,
60 MAX77843_DEBOUNCE_TIME_10MS
,
61 MAX77843_DEBOUNCE_TIME_25MS
,
62 MAX77843_DEBOUNCE_TIME_38_62MS
,
65 /* Define accessory cable type */
66 enum max77843_muic_accessory_type
{
67 MAX77843_MUIC_ADC_GROUND
= 0,
68 MAX77843_MUIC_ADC_SEND_END_BUTTON
,
69 MAX77843_MUIC_ADC_REMOTE_S1_BUTTON
,
70 MAX77843_MUIC_ADC_REMOTE_S2_BUTTON
,
71 MAX77843_MUIC_ADC_REMOTE_S3_BUTTON
,
72 MAX77843_MUIC_ADC_REMOTE_S4_BUTTON
,
73 MAX77843_MUIC_ADC_REMOTE_S5_BUTTON
,
74 MAX77843_MUIC_ADC_REMOTE_S6_BUTTON
,
75 MAX77843_MUIC_ADC_REMOTE_S7_BUTTON
,
76 MAX77843_MUIC_ADC_REMOTE_S8_BUTTON
,
77 MAX77843_MUIC_ADC_REMOTE_S9_BUTTON
,
78 MAX77843_MUIC_ADC_REMOTE_S10_BUTTON
,
79 MAX77843_MUIC_ADC_REMOTE_S11_BUTTON
,
80 MAX77843_MUIC_ADC_REMOTE_S12_BUTTON
,
81 MAX77843_MUIC_ADC_RESERVED_ACC_1
,
82 MAX77843_MUIC_ADC_RESERVED_ACC_2
,
83 MAX77843_MUIC_ADC_RESERVED_ACC_3
,
84 MAX77843_MUIC_ADC_RESERVED_ACC_4
,
85 MAX77843_MUIC_ADC_RESERVED_ACC_5
,
86 MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2
,
87 MAX77843_MUIC_ADC_PHONE_POWERED_DEV
,
88 MAX77843_MUIC_ADC_TTY_CONVERTER
,
89 MAX77843_MUIC_ADC_UART_CABLE
,
90 MAX77843_MUIC_ADC_CEA936A_TYPE1_CHG
,
91 MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF
,
92 MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON
,
93 MAX77843_MUIC_ADC_AV_CABLE_NOLOAD
,
94 MAX77843_MUIC_ADC_CEA936A_TYPE2_CHG
,
95 MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF
,
96 MAX77843_MUIC_ADC_FACTORY_MODE_UART_ON
,
97 MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE1
,
98 MAX77843_MUIC_ADC_OPEN
,
100 /* The blow accessories should check
101 not only ADC value but also ADC1K and VBVolt value. */
102 /* Offset|ADC1K|VBVolt| */
103 MAX77843_MUIC_GND_USB_HOST
= 0x100, /* 0x1| 0| 0| */
104 MAX77843_MUIC_GND_USB_HOST_VB
= 0x101, /* 0x1| 0| 1| */
105 MAX77843_MUIC_GND_MHL
= 0x102, /* 0x1| 1| 0| */
106 MAX77843_MUIC_GND_MHL_VB
= 0x103, /* 0x1| 1| 1| */
109 /* Define charger cable type */
110 enum max77843_muic_charger_type
{
111 MAX77843_MUIC_CHG_NONE
= 0,
112 MAX77843_MUIC_CHG_USB
,
113 MAX77843_MUIC_CHG_DOWNSTREAM
,
114 MAX77843_MUIC_CHG_DEDICATED
,
115 MAX77843_MUIC_CHG_SPECIAL_500MA
,
116 MAX77843_MUIC_CHG_SPECIAL_1A
,
117 MAX77843_MUIC_CHG_SPECIAL_BIAS
,
118 MAX77843_MUIC_CHG_RESERVED
,
119 MAX77843_MUIC_CHG_GND
,
122 static const unsigned int max77843_extcon_cable
[] = {
135 struct max77843_muic_irq
{
141 static struct max77843_muic_irq max77843_muic_irqs
[] = {
142 { MAX77843_MUIC_IRQ_INT1_ADC
, "MUIC-ADC" },
143 { MAX77843_MUIC_IRQ_INT1_ADCERROR
, "MUIC-ADC_ERROR" },
144 { MAX77843_MUIC_IRQ_INT1_ADC1K
, "MUIC-ADC1K" },
145 { MAX77843_MUIC_IRQ_INT2_CHGTYP
, "MUIC-CHGTYP" },
146 { MAX77843_MUIC_IRQ_INT2_CHGDETRUN
, "MUIC-CHGDETRUN" },
147 { MAX77843_MUIC_IRQ_INT2_DCDTMR
, "MUIC-DCDTMR" },
148 { MAX77843_MUIC_IRQ_INT2_DXOVP
, "MUIC-DXOVP" },
149 { MAX77843_MUIC_IRQ_INT2_VBVOLT
, "MUIC-VBVOLT" },
150 { MAX77843_MUIC_IRQ_INT3_VBADC
, "MUIC-VBADC" },
151 { MAX77843_MUIC_IRQ_INT3_VDNMON
, "MUIC-VDNMON" },
152 { MAX77843_MUIC_IRQ_INT3_DNRES
, "MUIC-DNRES" },
153 { MAX77843_MUIC_IRQ_INT3_MPNACK
, "MUIC-MPNACK"},
154 { MAX77843_MUIC_IRQ_INT3_MRXBUFOW
, "MUIC-MRXBUFOW"},
155 { MAX77843_MUIC_IRQ_INT3_MRXTRF
, "MUIC-MRXTRF"},
156 { MAX77843_MUIC_IRQ_INT3_MRXPERR
, "MUIC-MRXPERR"},
157 { MAX77843_MUIC_IRQ_INT3_MRXRDY
, "MUIC-MRXRDY"},
160 static const struct regmap_config max77843_muic_regmap_config
= {
163 .max_register
= MAX77843_MUIC_REG_END
,
166 static const struct regmap_irq max77843_muic_irq
[] = {
168 { .reg_offset
= 0, .mask
= MAX77843_MUIC_ADC
, },
169 { .reg_offset
= 0, .mask
= MAX77843_MUIC_ADCERROR
, },
170 { .reg_offset
= 0, .mask
= MAX77843_MUIC_ADC1K
, },
173 { .reg_offset
= 1, .mask
= MAX77843_MUIC_CHGTYP
, },
174 { .reg_offset
= 1, .mask
= MAX77843_MUIC_CHGDETRUN
, },
175 { .reg_offset
= 1, .mask
= MAX77843_MUIC_DCDTMR
, },
176 { .reg_offset
= 1, .mask
= MAX77843_MUIC_DXOVP
, },
177 { .reg_offset
= 1, .mask
= MAX77843_MUIC_VBVOLT
, },
180 { .reg_offset
= 2, .mask
= MAX77843_MUIC_VBADC
, },
181 { .reg_offset
= 2, .mask
= MAX77843_MUIC_VDNMON
, },
182 { .reg_offset
= 2, .mask
= MAX77843_MUIC_DNRES
, },
183 { .reg_offset
= 2, .mask
= MAX77843_MUIC_MPNACK
, },
184 { .reg_offset
= 2, .mask
= MAX77843_MUIC_MRXBUFOW
, },
185 { .reg_offset
= 2, .mask
= MAX77843_MUIC_MRXTRF
, },
186 { .reg_offset
= 2, .mask
= MAX77843_MUIC_MRXPERR
, },
187 { .reg_offset
= 2, .mask
= MAX77843_MUIC_MRXRDY
, },
190 static const struct regmap_irq_chip max77843_muic_irq_chip
= {
191 .name
= "max77843-muic",
192 .status_base
= MAX77843_MUIC_REG_INT1
,
193 .mask_base
= MAX77843_MUIC_REG_INTMASK1
,
196 .irqs
= max77843_muic_irq
,
197 .num_irqs
= ARRAY_SIZE(max77843_muic_irq
),
200 static int max77843_muic_set_path(struct max77843_muic_info
*info
,
201 u8 val
, bool attached
)
203 struct max77693_dev
*max77843
= info
->max77843
;
205 unsigned int ctrl1
, ctrl2
;
210 ctrl1
= MAX77843_MUIC_CONTROL1_SW_OPEN
;
212 ret
= regmap_update_bits(max77843
->regmap_muic
,
213 MAX77843_MUIC_REG_CONTROL1
,
214 MAX77843_MUIC_CONTROL1_COM_SW
, ctrl1
);
216 dev_err(info
->dev
, "Cannot switch MUIC port\n");
221 ctrl2
= MAX77843_MUIC_CONTROL2_CPEN_MASK
;
223 ctrl2
= MAX77843_MUIC_CONTROL2_LOWPWR_MASK
;
225 ret
= regmap_update_bits(max77843
->regmap_muic
,
226 MAX77843_MUIC_REG_CONTROL2
,
227 MAX77843_MUIC_CONTROL2_LOWPWR_MASK
|
228 MAX77843_MUIC_CONTROL2_CPEN_MASK
, ctrl2
);
230 dev_err(info
->dev
, "Cannot update lowpower mode\n");
235 "CONTROL1 : 0x%02x, CONTROL2 : 0x%02x, state : %s\n",
236 ctrl1
, ctrl2
, attached
? "attached" : "detached");
241 static int max77843_muic_get_cable_type(struct max77843_muic_info
*info
,
242 enum max77843_muic_cable_group group
, bool *attached
)
244 int adc
, chg_type
, cable_type
, gnd_type
;
246 adc
= info
->status
[MAX77843_MUIC_STATUS1
] &
247 MAX77843_MUIC_STATUS1_ADC_MASK
;
248 adc
>>= MAX77843_MUIC_STATUS1_ADC_SHIFT
;
251 case MAX77843_CABLE_GROUP_ADC
:
252 if (adc
== MAX77843_MUIC_ADC_OPEN
) {
254 cable_type
= info
->prev_cable_type
;
255 info
->prev_cable_type
= MAX77843_MUIC_ADC_OPEN
;
258 cable_type
= info
->prev_cable_type
= adc
;
261 case MAX77843_CABLE_GROUP_CHG
:
262 chg_type
= info
->status
[MAX77843_MUIC_STATUS2
] &
263 MAX77843_MUIC_STATUS2_CHGTYP_MASK
;
265 /* Check GROUND accessory with charger cable */
266 if (adc
== MAX77843_MUIC_ADC_GROUND
) {
267 if (chg_type
== MAX77843_MUIC_CHG_NONE
) {
268 /* The following state when charger cable is
269 * disconnected but the GROUND accessory still
272 cable_type
= info
->prev_chg_type
;
273 info
->prev_chg_type
= MAX77843_MUIC_CHG_NONE
;
276 /* The following state when charger cable is
277 * connected on the GROUND accessory */
279 cable_type
= MAX77843_MUIC_CHG_GND
;
280 info
->prev_chg_type
= MAX77843_MUIC_CHG_GND
;
285 if (chg_type
== MAX77843_MUIC_CHG_NONE
) {
287 cable_type
= info
->prev_chg_type
;
288 info
->prev_chg_type
= MAX77843_MUIC_CHG_NONE
;
291 cable_type
= info
->prev_chg_type
= chg_type
;
294 case MAX77843_CABLE_GROUP_ADC_GND
:
295 if (adc
== MAX77843_MUIC_ADC_OPEN
) {
297 cable_type
= info
->prev_gnd_type
;
298 info
->prev_gnd_type
= MAX77843_MUIC_ADC_OPEN
;
302 /* Offset|ADC1K|VBVolt|
303 * 0x1| 0| 0| USB-HOST
304 * 0x1| 0| 1| USB-HOST with VB
306 * 0x1| 1| 1| MHL with VB */
307 /* Get ADC1K register bit */
308 gnd_type
= (info
->status
[MAX77843_MUIC_STATUS1
] &
309 MAX77843_MUIC_STATUS1_ADC1K_MASK
);
311 /* Get VBVolt register bit */
312 gnd_type
|= (info
->status
[MAX77843_MUIC_STATUS2
] &
313 MAX77843_MUIC_STATUS2_VBVOLT_MASK
);
314 gnd_type
>>= MAX77843_MUIC_STATUS2_VBVOLT_SHIFT
;
316 /* Offset of GND cable */
317 gnd_type
|= MAX77843_MUIC_GND_USB_HOST
;
318 cable_type
= info
->prev_gnd_type
= gnd_type
;
322 dev_err(info
->dev
, "Unknown cable group (%d)\n", group
);
323 cable_type
= -EINVAL
;
330 static int max77843_muic_adc_gnd_handler(struct max77843_muic_info
*info
)
332 int ret
, gnd_cable_type
;
335 gnd_cable_type
= max77843_muic_get_cable_type(info
,
336 MAX77843_CABLE_GROUP_ADC_GND
, &attached
);
337 dev_dbg(info
->dev
, "external connector is %s (gnd:0x%02x)\n",
338 attached
? "attached" : "detached", gnd_cable_type
);
340 switch (gnd_cable_type
) {
341 case MAX77843_MUIC_GND_USB_HOST
:
342 case MAX77843_MUIC_GND_USB_HOST_VB
:
343 ret
= max77843_muic_set_path(info
,
344 MAX77843_MUIC_CONTROL1_SW_USB
,
349 extcon_set_cable_state_(info
->edev
, EXTCON_USB_HOST
, attached
);
351 case MAX77843_MUIC_GND_MHL_VB
:
352 case MAX77843_MUIC_GND_MHL
:
353 ret
= max77843_muic_set_path(info
,
354 MAX77843_MUIC_CONTROL1_SW_OPEN
,
359 extcon_set_cable_state_(info
->edev
, EXTCON_DISP_MHL
, attached
);
362 dev_err(info
->dev
, "failed to detect %s accessory(gnd:0x%x)\n",
363 attached
? "attached" : "detached", gnd_cable_type
);
370 static int max77843_muic_jig_handler(struct max77843_muic_info
*info
,
371 int cable_type
, bool attached
)
374 u8 path
= MAX77843_MUIC_CONTROL1_SW_OPEN
;
376 dev_dbg(info
->dev
, "external connector is %s (adc:0x%02x)\n",
377 attached
? "attached" : "detached", cable_type
);
379 switch (cable_type
) {
380 case MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF
:
381 case MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON
:
382 path
= MAX77843_MUIC_CONTROL1_SW_USB
;
384 case MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF
:
385 path
= MAX77843_MUIC_CONTROL1_SW_UART
;
391 ret
= max77843_muic_set_path(info
, path
, attached
);
395 extcon_set_cable_state_(info
->edev
, EXTCON_JIG
, attached
);
400 static int max77843_muic_adc_handler(struct max77843_muic_info
*info
)
405 cable_type
= max77843_muic_get_cable_type(info
,
406 MAX77843_CABLE_GROUP_ADC
, &attached
);
409 "external connector is %s (adc:0x%02x, prev_adc:0x%x)\n",
410 attached
? "attached" : "detached", cable_type
,
411 info
->prev_cable_type
);
413 switch (cable_type
) {
414 case MAX77843_MUIC_ADC_GROUND
:
415 ret
= max77843_muic_adc_gnd_handler(info
);
419 case MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF
:
420 case MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON
:
421 case MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF
:
422 ret
= max77843_muic_jig_handler(info
, cable_type
, attached
);
426 case MAX77843_MUIC_ADC_SEND_END_BUTTON
:
427 case MAX77843_MUIC_ADC_REMOTE_S1_BUTTON
:
428 case MAX77843_MUIC_ADC_REMOTE_S2_BUTTON
:
429 case MAX77843_MUIC_ADC_REMOTE_S3_BUTTON
:
430 case MAX77843_MUIC_ADC_REMOTE_S4_BUTTON
:
431 case MAX77843_MUIC_ADC_REMOTE_S5_BUTTON
:
432 case MAX77843_MUIC_ADC_REMOTE_S6_BUTTON
:
433 case MAX77843_MUIC_ADC_REMOTE_S7_BUTTON
:
434 case MAX77843_MUIC_ADC_REMOTE_S8_BUTTON
:
435 case MAX77843_MUIC_ADC_REMOTE_S9_BUTTON
:
436 case MAX77843_MUIC_ADC_REMOTE_S10_BUTTON
:
437 case MAX77843_MUIC_ADC_REMOTE_S11_BUTTON
:
438 case MAX77843_MUIC_ADC_REMOTE_S12_BUTTON
:
439 case MAX77843_MUIC_ADC_RESERVED_ACC_1
:
440 case MAX77843_MUIC_ADC_RESERVED_ACC_2
:
441 case MAX77843_MUIC_ADC_RESERVED_ACC_3
:
442 case MAX77843_MUIC_ADC_RESERVED_ACC_4
:
443 case MAX77843_MUIC_ADC_RESERVED_ACC_5
:
444 case MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE2
:
445 case MAX77843_MUIC_ADC_PHONE_POWERED_DEV
:
446 case MAX77843_MUIC_ADC_TTY_CONVERTER
:
447 case MAX77843_MUIC_ADC_UART_CABLE
:
448 case MAX77843_MUIC_ADC_CEA936A_TYPE1_CHG
:
449 case MAX77843_MUIC_ADC_AV_CABLE_NOLOAD
:
450 case MAX77843_MUIC_ADC_CEA936A_TYPE2_CHG
:
451 case MAX77843_MUIC_ADC_FACTORY_MODE_UART_ON
:
452 case MAX77843_MUIC_ADC_AUDIO_DEVICE_TYPE1
:
453 case MAX77843_MUIC_ADC_OPEN
:
455 "accessory is %s but it isn't used (adc:0x%x)\n",
456 attached
? "attached" : "detached", cable_type
);
460 "failed to detect %s accessory (adc:0x%x)\n",
461 attached
? "attached" : "detached", cable_type
);
468 static int max77843_muic_chg_handler(struct max77843_muic_info
*info
)
470 int ret
, chg_type
, gnd_type
;
473 chg_type
= max77843_muic_get_cable_type(info
,
474 MAX77843_CABLE_GROUP_CHG
, &attached
);
477 "external connector is %s(chg_type:0x%x, prev_chg_type:0x%x)\n",
478 attached
? "attached" : "detached",
479 chg_type
, info
->prev_chg_type
);
482 case MAX77843_MUIC_CHG_USB
:
483 ret
= max77843_muic_set_path(info
,
484 MAX77843_MUIC_CONTROL1_SW_USB
,
489 extcon_set_cable_state_(info
->edev
, EXTCON_USB
, attached
);
490 extcon_set_cable_state_(info
->edev
, EXTCON_CHG_USB_SDP
,
493 case MAX77843_MUIC_CHG_DOWNSTREAM
:
494 ret
= max77843_muic_set_path(info
,
495 MAX77843_MUIC_CONTROL1_SW_OPEN
,
500 extcon_set_cable_state_(info
->edev
, EXTCON_CHG_USB_CDP
,
503 case MAX77843_MUIC_CHG_DEDICATED
:
504 ret
= max77843_muic_set_path(info
,
505 MAX77843_MUIC_CONTROL1_SW_OPEN
,
510 extcon_set_cable_state_(info
->edev
, EXTCON_CHG_USB_DCP
,
513 case MAX77843_MUIC_CHG_SPECIAL_500MA
:
514 ret
= max77843_muic_set_path(info
,
515 MAX77843_MUIC_CONTROL1_SW_OPEN
,
520 extcon_set_cable_state_(info
->edev
, EXTCON_CHG_USB_SLOW
,
523 case MAX77843_MUIC_CHG_SPECIAL_1A
:
524 ret
= max77843_muic_set_path(info
,
525 MAX77843_MUIC_CONTROL1_SW_OPEN
,
530 extcon_set_cable_state_(info
->edev
, EXTCON_CHG_USB_FAST
,
533 case MAX77843_MUIC_CHG_GND
:
534 gnd_type
= max77843_muic_get_cable_type(info
,
535 MAX77843_CABLE_GROUP_ADC_GND
, &attached
);
537 /* Charger cable on MHL accessory is attach or detach */
538 if (gnd_type
== MAX77843_MUIC_GND_MHL_VB
)
539 extcon_set_cable_state_(info
->edev
, EXTCON_CHG_USB_DCP
,
541 else if (gnd_type
== MAX77843_MUIC_GND_MHL
)
542 extcon_set_cable_state_(info
->edev
, EXTCON_CHG_USB_DCP
,
545 case MAX77843_MUIC_CHG_NONE
:
549 "failed to detect %s accessory (chg_type:0x%x)\n",
550 attached
? "attached" : "detached", chg_type
);
552 max77843_muic_set_path(info
, MAX77843_MUIC_CONTROL1_SW_OPEN
,
560 static void max77843_muic_irq_work(struct work_struct
*work
)
562 struct max77843_muic_info
*info
= container_of(work
,
563 struct max77843_muic_info
, irq_work
);
564 struct max77693_dev
*max77843
= info
->max77843
;
567 mutex_lock(&info
->mutex
);
569 ret
= regmap_bulk_read(max77843
->regmap_muic
,
570 MAX77843_MUIC_REG_STATUS1
, info
->status
,
571 MAX77843_MUIC_STATUS_NUM
);
573 dev_err(info
->dev
, "Cannot read STATUS registers\n");
574 mutex_unlock(&info
->mutex
);
579 ret
= max77843_muic_adc_handler(info
);
581 dev_err(info
->dev
, "Unknown cable type\n");
582 info
->irq_adc
= false;
586 ret
= max77843_muic_chg_handler(info
);
588 dev_err(info
->dev
, "Unknown charger type\n");
589 info
->irq_chg
= false;
592 mutex_unlock(&info
->mutex
);
595 static irqreturn_t
max77843_muic_irq_handler(int irq
, void *data
)
597 struct max77843_muic_info
*info
= data
;
598 int i
, irq_type
= -1;
600 for (i
= 0; i
< ARRAY_SIZE(max77843_muic_irqs
); i
++)
601 if (irq
== max77843_muic_irqs
[i
].virq
)
602 irq_type
= max77843_muic_irqs
[i
].irq
;
605 case MAX77843_MUIC_IRQ_INT1_ADC
:
606 case MAX77843_MUIC_IRQ_INT1_ADCERROR
:
607 case MAX77843_MUIC_IRQ_INT1_ADC1K
:
608 info
->irq_adc
= true;
610 case MAX77843_MUIC_IRQ_INT2_CHGTYP
:
611 case MAX77843_MUIC_IRQ_INT2_CHGDETRUN
:
612 case MAX77843_MUIC_IRQ_INT2_DCDTMR
:
613 case MAX77843_MUIC_IRQ_INT2_DXOVP
:
614 case MAX77843_MUIC_IRQ_INT2_VBVOLT
:
615 info
->irq_chg
= true;
617 case MAX77843_MUIC_IRQ_INT3_VBADC
:
618 case MAX77843_MUIC_IRQ_INT3_VDNMON
:
619 case MAX77843_MUIC_IRQ_INT3_DNRES
:
620 case MAX77843_MUIC_IRQ_INT3_MPNACK
:
621 case MAX77843_MUIC_IRQ_INT3_MRXBUFOW
:
622 case MAX77843_MUIC_IRQ_INT3_MRXTRF
:
623 case MAX77843_MUIC_IRQ_INT3_MRXPERR
:
624 case MAX77843_MUIC_IRQ_INT3_MRXRDY
:
627 dev_err(info
->dev
, "Cannot recognize IRQ(%d)\n", irq_type
);
631 schedule_work(&info
->irq_work
);
636 static void max77843_muic_detect_cable_wq(struct work_struct
*work
)
638 struct max77843_muic_info
*info
= container_of(to_delayed_work(work
),
639 struct max77843_muic_info
, wq_detcable
);
640 struct max77693_dev
*max77843
= info
->max77843
;
641 int chg_type
, adc
, ret
;
644 mutex_lock(&info
->mutex
);
646 ret
= regmap_bulk_read(max77843
->regmap_muic
,
647 MAX77843_MUIC_REG_STATUS1
, info
->status
,
648 MAX77843_MUIC_STATUS_NUM
);
650 dev_err(info
->dev
, "Cannot read STATUS registers\n");
654 adc
= max77843_muic_get_cable_type(info
,
655 MAX77843_CABLE_GROUP_ADC
, &attached
);
656 if (attached
&& adc
!= MAX77843_MUIC_ADC_OPEN
) {
657 ret
= max77843_muic_adc_handler(info
);
659 dev_err(info
->dev
, "Cannot detect accessory\n");
664 chg_type
= max77843_muic_get_cable_type(info
,
665 MAX77843_CABLE_GROUP_CHG
, &attached
);
666 if (attached
&& chg_type
!= MAX77843_MUIC_CHG_NONE
) {
667 ret
= max77843_muic_chg_handler(info
);
669 dev_err(info
->dev
, "Cannot detect charger accessory\n");
675 mutex_unlock(&info
->mutex
);
678 static int max77843_muic_set_debounce_time(struct max77843_muic_info
*info
,
679 enum max77843_muic_adc_debounce_time time
)
681 struct max77693_dev
*max77843
= info
->max77843
;
685 case MAX77843_DEBOUNCE_TIME_5MS
:
686 case MAX77843_DEBOUNCE_TIME_10MS
:
687 case MAX77843_DEBOUNCE_TIME_25MS
:
688 case MAX77843_DEBOUNCE_TIME_38_62MS
:
689 ret
= regmap_update_bits(max77843
->regmap_muic
,
690 MAX77843_MUIC_REG_CONTROL4
,
691 MAX77843_MUIC_CONTROL4_ADCDBSET_MASK
,
692 time
<< MAX77843_MUIC_CONTROL4_ADCDBSET_SHIFT
);
694 dev_err(info
->dev
, "Cannot write MUIC regmap\n");
699 dev_err(info
->dev
, "Invalid ADC debounce time\n");
706 static int max77843_init_muic_regmap(struct max77693_dev
*max77843
)
710 max77843
->i2c_muic
= i2c_new_dummy(max77843
->i2c
->adapter
,
712 if (!max77843
->i2c_muic
) {
713 dev_err(&max77843
->i2c
->dev
,
714 "Cannot allocate I2C device for MUIC\n");
718 i2c_set_clientdata(max77843
->i2c_muic
, max77843
);
720 max77843
->regmap_muic
= devm_regmap_init_i2c(max77843
->i2c_muic
,
721 &max77843_muic_regmap_config
);
722 if (IS_ERR(max77843
->regmap_muic
)) {
723 ret
= PTR_ERR(max77843
->regmap_muic
);
727 ret
= regmap_add_irq_chip(max77843
->regmap_muic
, max77843
->irq
,
728 IRQF_TRIGGER_LOW
| IRQF_ONESHOT
| IRQF_SHARED
,
729 0, &max77843_muic_irq_chip
, &max77843
->irq_data_muic
);
731 dev_err(&max77843
->i2c
->dev
, "Cannot add MUIC IRQ chip\n");
738 i2c_unregister_device(max77843
->i2c_muic
);
743 static int max77843_muic_probe(struct platform_device
*pdev
)
745 struct max77693_dev
*max77843
= dev_get_drvdata(pdev
->dev
.parent
);
746 struct max77843_muic_info
*info
;
750 info
= devm_kzalloc(&pdev
->dev
, sizeof(*info
), GFP_KERNEL
);
754 info
->dev
= &pdev
->dev
;
755 info
->max77843
= max77843
;
757 platform_set_drvdata(pdev
, info
);
758 mutex_init(&info
->mutex
);
760 /* Initialize i2c and regmap */
761 ret
= max77843_init_muic_regmap(max77843
);
763 dev_err(&pdev
->dev
, "Failed to init MUIC regmap\n");
767 /* Turn off auto detection configuration */
768 ret
= regmap_update_bits(max77843
->regmap_muic
,
769 MAX77843_MUIC_REG_CONTROL4
,
770 MAX77843_MUIC_CONTROL4_USBAUTO_MASK
|
771 MAX77843_MUIC_CONTROL4_FCTAUTO_MASK
,
772 CONTROL4_AUTO_DISABLE
);
774 /* Initialize extcon device */
775 info
->edev
= devm_extcon_dev_allocate(&pdev
->dev
,
776 max77843_extcon_cable
);
777 if (IS_ERR(info
->edev
)) {
778 dev_err(&pdev
->dev
, "Failed to allocate memory for extcon\n");
783 ret
= devm_extcon_dev_register(&pdev
->dev
, info
->edev
);
785 dev_err(&pdev
->dev
, "Failed to register extcon device\n");
789 /* Set ADC debounce time */
790 max77843_muic_set_debounce_time(info
, MAX77843_DEBOUNCE_TIME_25MS
);
792 /* Set initial path for UART */
793 max77843_muic_set_path(info
, MAX77843_MUIC_CONTROL1_SW_UART
, true);
795 /* Check revision number of MUIC device */
796 ret
= regmap_read(max77843
->regmap_muic
, MAX77843_MUIC_REG_ID
, &id
);
798 dev_err(&pdev
->dev
, "Failed to read revision number\n");
801 dev_info(info
->dev
, "MUIC device ID : 0x%x\n", id
);
803 /* Support virtual irq domain for max77843 MUIC device */
804 INIT_WORK(&info
->irq_work
, max77843_muic_irq_work
);
806 /* Clear IRQ bits before request IRQs */
807 ret
= regmap_bulk_read(max77843
->regmap_muic
,
808 MAX77843_MUIC_REG_INT1
, info
->status
,
809 MAX77843_MUIC_STATUS_NUM
);
811 dev_err(&pdev
->dev
, "Failed to Clear IRQ bits\n");
815 for (i
= 0; i
< ARRAY_SIZE(max77843_muic_irqs
); i
++) {
816 struct max77843_muic_irq
*muic_irq
= &max77843_muic_irqs
[i
];
819 virq
= regmap_irq_get_virq(max77843
->irq_data_muic
,
825 muic_irq
->virq
= virq
;
827 ret
= devm_request_threaded_irq(&pdev
->dev
, virq
, NULL
,
828 max77843_muic_irq_handler
, IRQF_NO_SUSPEND
,
829 muic_irq
->name
, info
);
832 "Failed to request irq (IRQ: %d, error: %d)\n",
838 /* Detect accessory after completing the initialization of platform */
839 INIT_DELAYED_WORK(&info
->wq_detcable
, max77843_muic_detect_cable_wq
);
840 queue_delayed_work(system_power_efficient_wq
,
841 &info
->wq_detcable
, msecs_to_jiffies(DELAY_MS_DEFAULT
));
846 regmap_del_irq_chip(max77843
->irq
, max77843
->irq_data_muic
);
847 i2c_unregister_device(max77843
->i2c_muic
);
852 static int max77843_muic_remove(struct platform_device
*pdev
)
854 struct max77843_muic_info
*info
= platform_get_drvdata(pdev
);
855 struct max77693_dev
*max77843
= info
->max77843
;
857 cancel_work_sync(&info
->irq_work
);
858 regmap_del_irq_chip(max77843
->irq
, max77843
->irq_data_muic
);
859 i2c_unregister_device(max77843
->i2c_muic
);
864 static const struct platform_device_id max77843_muic_id
[] = {
865 { "max77843-muic", },
868 MODULE_DEVICE_TABLE(platform
, max77843_muic_id
);
870 static struct platform_driver max77843_muic_driver
= {
872 .name
= "max77843-muic",
874 .probe
= max77843_muic_probe
,
875 .remove
= max77843_muic_remove
,
876 .id_table
= max77843_muic_id
,
879 static int __init
max77843_muic_init(void)
881 return platform_driver_register(&max77843_muic_driver
);
883 subsys_initcall(max77843_muic_init
);
885 MODULE_DESCRIPTION("Maxim MAX77843 Extcon driver");
886 MODULE_AUTHOR("Jaewon Kim <jaewon02.kim@samsung.com>");
887 MODULE_LICENSE("GPL");