2 * extcon-sm5502.c - Silicon Mitus SM5502 extcon drvier to support USB switches
4 * Copyright (c) 2014 Samsung Electronics Co., Ltd
5 * Author: Chanwoo Choi <cw00.choi@samsung.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2 of the License, or (at your
10 * option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
18 #include <linux/err.h>
19 #include <linux/i2c.h>
20 #include <linux/input.h>
21 #include <linux/interrupt.h>
22 #include <linux/irqdomain.h>
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/platform_device.h>
26 #include <linux/regmap.h>
27 #include <linux/slab.h>
28 #include <linux/extcon.h>
29 #include <linux/extcon/sm5502.h>
31 #define DELAY_MS_DEFAULT 17000 /* unit: millisecond */
45 struct sm5502_muic_info
{
47 struct extcon_dev
*edev
;
49 struct i2c_client
*i2c
;
50 struct regmap
*regmap
;
52 struct regmap_irq_chip_data
*irq_data
;
53 struct muic_irq
*muic_irqs
;
54 unsigned int num_muic_irqs
;
58 struct work_struct irq_work
;
60 struct reg_data
*reg_data
;
61 unsigned int num_reg_data
;
66 * Use delayed workqueue to detect cable state and then
67 * notify cable state to notifiee/platform through uevent.
68 * After completing the booting of platform, the extcon provider
69 * driver should notify cable state to upper layer.
71 struct delayed_work wq_detcable
;
74 /* Default value of SM5502 register to bring up MUIC device. */
75 static struct reg_data sm5502_reg_data
[] = {
77 .reg
= SM5502_REG_CONTROL
,
78 .val
= SM5502_REG_CONTROL_MASK_INT_MASK
,
81 .reg
= SM5502_REG_INTMASK1
,
82 .val
= SM5502_REG_INTM1_KP_MASK
83 | SM5502_REG_INTM1_LKP_MASK
84 | SM5502_REG_INTM1_LKR_MASK
,
87 .reg
= SM5502_REG_INTMASK2
,
88 .val
= SM5502_REG_INTM2_VBUS_DET_MASK
89 | SM5502_REG_INTM2_REV_ACCE_MASK
90 | SM5502_REG_INTM2_ADC_CHG_MASK
91 | SM5502_REG_INTM2_STUCK_KEY_MASK
92 | SM5502_REG_INTM2_STUCK_KEY_RCV_MASK
93 | SM5502_REG_INTM2_MHL_MASK
,
99 /* List of detectable cables */
101 EXTCON_CABLE_USB
= 0,
102 EXTCON_CABLE_USB_HOST
,
108 static const char *sm5502_extcon_cable
[] = {
109 [EXTCON_CABLE_USB
] = "USB",
110 [EXTCON_CABLE_USB_HOST
] = "USB-Host",
111 [EXTCON_CABLE_TA
] = "TA",
115 /* Define supported accessory type */
116 enum sm5502_muic_acc_type
{
117 SM5502_MUIC_ADC_GROUND
= 0x0,
118 SM5502_MUIC_ADC_SEND_END_BUTTON
,
119 SM5502_MUIC_ADC_REMOTE_S1_BUTTON
,
120 SM5502_MUIC_ADC_REMOTE_S2_BUTTON
,
121 SM5502_MUIC_ADC_REMOTE_S3_BUTTON
,
122 SM5502_MUIC_ADC_REMOTE_S4_BUTTON
,
123 SM5502_MUIC_ADC_REMOTE_S5_BUTTON
,
124 SM5502_MUIC_ADC_REMOTE_S6_BUTTON
,
125 SM5502_MUIC_ADC_REMOTE_S7_BUTTON
,
126 SM5502_MUIC_ADC_REMOTE_S8_BUTTON
,
127 SM5502_MUIC_ADC_REMOTE_S9_BUTTON
,
128 SM5502_MUIC_ADC_REMOTE_S10_BUTTON
,
129 SM5502_MUIC_ADC_REMOTE_S11_BUTTON
,
130 SM5502_MUIC_ADC_REMOTE_S12_BUTTON
,
131 SM5502_MUIC_ADC_RESERVED_ACC_1
,
132 SM5502_MUIC_ADC_RESERVED_ACC_2
,
133 SM5502_MUIC_ADC_RESERVED_ACC_3
,
134 SM5502_MUIC_ADC_RESERVED_ACC_4
,
135 SM5502_MUIC_ADC_RESERVED_ACC_5
,
136 SM5502_MUIC_ADC_AUDIO_TYPE2
,
137 SM5502_MUIC_ADC_PHONE_POWERED_DEV
,
138 SM5502_MUIC_ADC_TTY_CONVERTER
,
139 SM5502_MUIC_ADC_UART_CABLE
,
140 SM5502_MUIC_ADC_TYPE1_CHARGER
,
141 SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB
,
142 SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB
,
143 SM5502_MUIC_ADC_AUDIO_VIDEO_CABLE
,
144 SM5502_MUIC_ADC_TYPE2_CHARGER
,
145 SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART
,
146 SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART
,
147 SM5502_MUIC_ADC_AUDIO_TYPE1
,
148 SM5502_MUIC_ADC_OPEN
= 0x1f,
150 /* The below accessories have same ADC value (0x1f or 0x1e).
151 So, Device type1 is used to separate specific accessory. */
152 /* |---------|--ADC| */
154 SM5502_MUIC_ADC_AUDIO_TYPE1_FULL_REMOTE
= 0x3e, /* | 001|11110| */
155 SM5502_MUIC_ADC_AUDIO_TYPE1_SEND_END
= 0x5e, /* | 010|11110| */
156 /* |Dev Type1|--ADC| */
157 SM5502_MUIC_ADC_OPEN_USB
= 0x5f, /* | 010|11111| */
158 SM5502_MUIC_ADC_OPEN_TA
= 0xdf, /* | 110|11111| */
159 SM5502_MUIC_ADC_OPEN_USB_OTG
= 0xff, /* | 111|11111| */
162 /* List of supported interrupt for SM5502 */
163 static struct muic_irq sm5502_muic_irqs
[] = {
164 { SM5502_IRQ_INT1_ATTACH
, "muic-attach" },
165 { SM5502_IRQ_INT1_DETACH
, "muic-detach" },
166 { SM5502_IRQ_INT1_KP
, "muic-kp" },
167 { SM5502_IRQ_INT1_LKP
, "muic-lkp" },
168 { SM5502_IRQ_INT1_LKR
, "muic-lkr" },
169 { SM5502_IRQ_INT1_OVP_EVENT
, "muic-ovp-event" },
170 { SM5502_IRQ_INT1_OCP_EVENT
, "muic-ocp-event" },
171 { SM5502_IRQ_INT1_OVP_OCP_DIS
, "muic-ovp-ocp-dis" },
172 { SM5502_IRQ_INT2_VBUS_DET
, "muic-vbus-det" },
173 { SM5502_IRQ_INT2_REV_ACCE
, "muic-rev-acce" },
174 { SM5502_IRQ_INT2_ADC_CHG
, "muic-adc-chg" },
175 { SM5502_IRQ_INT2_STUCK_KEY
, "muic-stuck-key" },
176 { SM5502_IRQ_INT2_STUCK_KEY_RCV
, "muic-stuck-key-rcv" },
177 { SM5502_IRQ_INT2_MHL
, "muic-mhl" },
180 /* Define interrupt list of SM5502 to register regmap_irq */
181 static const struct regmap_irq sm5502_irqs
[] = {
182 /* INT1 interrupts */
183 { .reg_offset
= 0, .mask
= SM5502_IRQ_INT1_ATTACH_MASK
, },
184 { .reg_offset
= 0, .mask
= SM5502_IRQ_INT1_DETACH_MASK
, },
185 { .reg_offset
= 0, .mask
= SM5502_IRQ_INT1_KP_MASK
, },
186 { .reg_offset
= 0, .mask
= SM5502_IRQ_INT1_LKP_MASK
, },
187 { .reg_offset
= 0, .mask
= SM5502_IRQ_INT1_LKR_MASK
, },
188 { .reg_offset
= 0, .mask
= SM5502_IRQ_INT1_OVP_EVENT_MASK
, },
189 { .reg_offset
= 0, .mask
= SM5502_IRQ_INT1_OCP_EVENT_MASK
, },
190 { .reg_offset
= 0, .mask
= SM5502_IRQ_INT1_OVP_OCP_DIS_MASK
, },
192 /* INT2 interrupts */
193 { .reg_offset
= 1, .mask
= SM5502_IRQ_INT2_VBUS_DET_MASK
,},
194 { .reg_offset
= 1, .mask
= SM5502_IRQ_INT2_REV_ACCE_MASK
, },
195 { .reg_offset
= 1, .mask
= SM5502_IRQ_INT2_ADC_CHG_MASK
, },
196 { .reg_offset
= 1, .mask
= SM5502_IRQ_INT2_STUCK_KEY_MASK
, },
197 { .reg_offset
= 1, .mask
= SM5502_IRQ_INT2_STUCK_KEY_RCV_MASK
, },
198 { .reg_offset
= 1, .mask
= SM5502_IRQ_INT2_MHL_MASK
, },
201 static const struct regmap_irq_chip sm5502_muic_irq_chip
= {
203 .status_base
= SM5502_REG_INT1
,
204 .mask_base
= SM5502_REG_INTMASK1
,
205 .mask_invert
= false,
208 .num_irqs
= ARRAY_SIZE(sm5502_irqs
),
211 /* Define regmap configuration of SM5502 for I2C communication */
212 static bool sm5502_muic_volatile_reg(struct device
*dev
, unsigned int reg
)
215 case SM5502_REG_INTMASK1
:
216 case SM5502_REG_INTMASK2
:
224 static const struct regmap_config sm5502_muic_regmap_config
= {
227 .volatile_reg
= sm5502_muic_volatile_reg
,
228 .max_register
= SM5502_REG_END
,
231 /* Change DM_CON/DP_CON/VBUSIN switch according to cable type */
232 static int sm5502_muic_set_path(struct sm5502_muic_info
*info
,
233 unsigned int con_sw
, unsigned int vbus_sw
,
239 con_sw
= DM_DP_SWITCH_OPEN
;
240 vbus_sw
= VBUSIN_SWITCH_OPEN
;
244 case DM_DP_SWITCH_OPEN
:
245 case DM_DP_SWITCH_USB
:
246 case DM_DP_SWITCH_AUDIO
:
247 case DM_DP_SWITCH_UART
:
248 ret
= regmap_update_bits(info
->regmap
, SM5502_REG_MANUAL_SW1
,
249 SM5502_REG_MANUAL_SW1_DP_MASK
|
250 SM5502_REG_MANUAL_SW1_DM_MASK
,
254 "cannot update DM_CON/DP_CON switch\n");
259 dev_err(info
->dev
, "Unknown DM_CON/DP_CON switch type (%d)\n",
265 case VBUSIN_SWITCH_OPEN
:
266 case VBUSIN_SWITCH_VBUSOUT
:
267 case VBUSIN_SWITCH_MIC
:
268 case VBUSIN_SWITCH_VBUSOUT_WITH_USB
:
269 ret
= regmap_update_bits(info
->regmap
, SM5502_REG_MANUAL_SW1
,
270 SM5502_REG_MANUAL_SW1_VBUSIN_MASK
,
274 "cannot update VBUSIN switch\n");
279 dev_err(info
->dev
, "Unknown VBUS switch type (%d)\n", vbus_sw
);
286 /* Return cable type of attached or detached accessories */
287 static unsigned int sm5502_muic_get_cable_type(struct sm5502_muic_info
*info
)
289 unsigned int cable_type
= -1, adc
, dev_type1
;
292 /* Read ADC value according to external cable or button */
293 ret
= regmap_read(info
->regmap
, SM5502_REG_ADC
, &adc
);
295 dev_err(info
->dev
, "failed to read ADC register\n");
300 * If ADC is SM5502_MUIC_ADC_GROUND(0x0), external cable hasn't
301 * connected with to MUIC device.
303 cable_type
&= SM5502_REG_ADC_MASK
;
304 if (cable_type
== SM5502_MUIC_ADC_GROUND
)
305 return SM5502_MUIC_ADC_GROUND
;
307 switch (cable_type
) {
308 case SM5502_MUIC_ADC_GROUND
:
309 case SM5502_MUIC_ADC_SEND_END_BUTTON
:
310 case SM5502_MUIC_ADC_REMOTE_S1_BUTTON
:
311 case SM5502_MUIC_ADC_REMOTE_S2_BUTTON
:
312 case SM5502_MUIC_ADC_REMOTE_S3_BUTTON
:
313 case SM5502_MUIC_ADC_REMOTE_S4_BUTTON
:
314 case SM5502_MUIC_ADC_REMOTE_S5_BUTTON
:
315 case SM5502_MUIC_ADC_REMOTE_S6_BUTTON
:
316 case SM5502_MUIC_ADC_REMOTE_S7_BUTTON
:
317 case SM5502_MUIC_ADC_REMOTE_S8_BUTTON
:
318 case SM5502_MUIC_ADC_REMOTE_S9_BUTTON
:
319 case SM5502_MUIC_ADC_REMOTE_S10_BUTTON
:
320 case SM5502_MUIC_ADC_REMOTE_S11_BUTTON
:
321 case SM5502_MUIC_ADC_REMOTE_S12_BUTTON
:
322 case SM5502_MUIC_ADC_RESERVED_ACC_1
:
323 case SM5502_MUIC_ADC_RESERVED_ACC_2
:
324 case SM5502_MUIC_ADC_RESERVED_ACC_3
:
325 case SM5502_MUIC_ADC_RESERVED_ACC_4
:
326 case SM5502_MUIC_ADC_RESERVED_ACC_5
:
327 case SM5502_MUIC_ADC_AUDIO_TYPE2
:
328 case SM5502_MUIC_ADC_PHONE_POWERED_DEV
:
329 case SM5502_MUIC_ADC_TTY_CONVERTER
:
330 case SM5502_MUIC_ADC_UART_CABLE
:
331 case SM5502_MUIC_ADC_TYPE1_CHARGER
:
332 case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB
:
333 case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB
:
334 case SM5502_MUIC_ADC_AUDIO_VIDEO_CABLE
:
335 case SM5502_MUIC_ADC_TYPE2_CHARGER
:
336 case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART
:
337 case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART
:
339 case SM5502_MUIC_ADC_AUDIO_TYPE1
:
341 * Check whether cable type is
342 * SM5502_MUIC_ADC_AUDIO_TYPE1_FULL_REMOTE
343 * or SM5502_MUIC_ADC_AUDIO_TYPE1_SEND_END
344 * by using Button event.
347 case SM5502_MUIC_ADC_OPEN
:
348 ret
= regmap_read(info
->regmap
, SM5502_REG_DEV_TYPE1
,
351 dev_err(info
->dev
, "failed to read DEV_TYPE1 reg\n");
356 case SM5502_REG_DEV_TYPE1_USB_SDP_MASK
:
357 cable_type
= SM5502_MUIC_ADC_OPEN_USB
;
359 case SM5502_REG_DEV_TYPE1_DEDICATED_CHG_MASK
:
360 cable_type
= SM5502_MUIC_ADC_OPEN_TA
;
362 case SM5502_REG_DEV_TYPE1_USB_OTG_MASK
:
363 cable_type
= SM5502_MUIC_ADC_OPEN_USB_OTG
;
367 "cannot identify the cable type: adc(0x%x) "
368 "dev_type1(0x%x)\n", adc
, dev_type1
);
374 "failed to identify the cable type: adc(0x%x)\n", adc
);
381 static int sm5502_muic_cable_handler(struct sm5502_muic_info
*info
,
384 static unsigned int prev_cable_type
= SM5502_MUIC_ADC_GROUND
;
385 const char **cable_names
= info
->edev
->supported_cable
;
386 unsigned int cable_type
= SM5502_MUIC_ADC_GROUND
;
387 unsigned int con_sw
= DM_DP_SWITCH_OPEN
;
388 unsigned int vbus_sw
= VBUSIN_SWITCH_OPEN
;
389 unsigned int idx
= 0;
395 /* Get the type of attached or detached cable */
397 cable_type
= sm5502_muic_get_cable_type(info
);
399 cable_type
= prev_cable_type
;
400 prev_cable_type
= cable_type
;
402 switch (cable_type
) {
403 case SM5502_MUIC_ADC_OPEN_USB
:
404 idx
= EXTCON_CABLE_USB
;
405 con_sw
= DM_DP_SWITCH_USB
;
406 vbus_sw
= VBUSIN_SWITCH_VBUSOUT_WITH_USB
;
408 case SM5502_MUIC_ADC_OPEN_TA
:
409 idx
= EXTCON_CABLE_TA
;
410 con_sw
= DM_DP_SWITCH_OPEN
;
411 vbus_sw
= VBUSIN_SWITCH_VBUSOUT
;
413 case SM5502_MUIC_ADC_OPEN_USB_OTG
:
414 idx
= EXTCON_CABLE_USB_HOST
;
415 con_sw
= DM_DP_SWITCH_USB
;
416 vbus_sw
= VBUSIN_SWITCH_OPEN
;
420 "cannot handle this cable_type (0x%x)\n", cable_type
);
424 /* Change internal hardware path(DM_CON/DP_CON, VBUSIN) */
425 ret
= sm5502_muic_set_path(info
, con_sw
, vbus_sw
, attached
);
429 /* Change the state of external accessory */
430 extcon_set_cable_state(info
->edev
, cable_names
[idx
], attached
);
435 static void sm5502_muic_irq_work(struct work_struct
*work
)
437 struct sm5502_muic_info
*info
= container_of(work
,
438 struct sm5502_muic_info
, irq_work
);
444 mutex_lock(&info
->mutex
);
446 /* Detect attached or detached cables */
447 if (info
->irq_attach
) {
448 ret
= sm5502_muic_cable_handler(info
, true);
449 info
->irq_attach
= false;
451 if (info
->irq_detach
) {
452 ret
= sm5502_muic_cable_handler(info
, false);
453 info
->irq_detach
= false;
457 dev_err(info
->dev
, "failed to handle MUIC interrupt\n");
459 mutex_unlock(&info
->mutex
);
465 * Sets irq_attach or irq_detach in sm5502_muic_info and returns 0.
466 * Returns -ESRCH if irq_type does not match registered IRQ for this dev type.
468 static int sm5502_parse_irq(struct sm5502_muic_info
*info
, int irq_type
)
471 case SM5502_IRQ_INT1_ATTACH
:
472 info
->irq_attach
= true;
474 case SM5502_IRQ_INT1_DETACH
:
475 info
->irq_detach
= true;
477 case SM5502_IRQ_INT1_KP
:
478 case SM5502_IRQ_INT1_LKP
:
479 case SM5502_IRQ_INT1_LKR
:
480 case SM5502_IRQ_INT1_OVP_EVENT
:
481 case SM5502_IRQ_INT1_OCP_EVENT
:
482 case SM5502_IRQ_INT1_OVP_OCP_DIS
:
483 case SM5502_IRQ_INT2_VBUS_DET
:
484 case SM5502_IRQ_INT2_REV_ACCE
:
485 case SM5502_IRQ_INT2_ADC_CHG
:
486 case SM5502_IRQ_INT2_STUCK_KEY
:
487 case SM5502_IRQ_INT2_STUCK_KEY_RCV
:
488 case SM5502_IRQ_INT2_MHL
:
496 static irqreturn_t
sm5502_muic_irq_handler(int irq
, void *data
)
498 struct sm5502_muic_info
*info
= data
;
499 int i
, irq_type
= -1, ret
;
501 for (i
= 0; i
< info
->num_muic_irqs
; i
++)
502 if (irq
== info
->muic_irqs
[i
].virq
)
503 irq_type
= info
->muic_irqs
[i
].irq
;
505 ret
= sm5502_parse_irq(info
, irq_type
);
507 dev_warn(info
->dev
, "cannot handle is interrupt:%d\n",
511 schedule_work(&info
->irq_work
);
516 static void sm5502_muic_detect_cable_wq(struct work_struct
*work
)
518 struct sm5502_muic_info
*info
= container_of(to_delayed_work(work
),
519 struct sm5502_muic_info
, wq_detcable
);
522 /* Notify the state of connector cable or not */
523 ret
= sm5502_muic_cable_handler(info
, true);
525 dev_warn(info
->dev
, "failed to detect cable state\n");
528 static void sm5502_init_dev_type(struct sm5502_muic_info
*info
)
530 unsigned int reg_data
, vendor_id
, version_id
;
533 /* To test I2C, Print version_id and vendor_id of SM5502 */
534 ret
= regmap_read(info
->regmap
, SM5502_REG_DEVICE_ID
, ®_data
);
537 "failed to read DEVICE_ID register: %d\n", ret
);
541 vendor_id
= ((reg_data
& SM5502_REG_DEVICE_ID_VENDOR_MASK
) >>
542 SM5502_REG_DEVICE_ID_VENDOR_SHIFT
);
543 version_id
= ((reg_data
& SM5502_REG_DEVICE_ID_VERSION_MASK
) >>
544 SM5502_REG_DEVICE_ID_VERSION_SHIFT
);
546 dev_info(info
->dev
, "Device type: version: 0x%x, vendor: 0x%x\n",
547 version_id
, vendor_id
);
549 /* Initiazle the register of SM5502 device to bring-up */
550 for (i
= 0; i
< info
->num_reg_data
; i
++) {
551 unsigned int val
= 0;
553 if (!info
->reg_data
[i
].invert
)
554 val
|= ~info
->reg_data
[i
].val
;
556 val
= info
->reg_data
[i
].val
;
557 regmap_write(info
->regmap
, info
->reg_data
[i
].reg
, val
);
561 static int sm5022_muic_i2c_probe(struct i2c_client
*i2c
,
562 const struct i2c_device_id
*id
)
564 struct device_node
*np
= i2c
->dev
.of_node
;
565 struct sm5502_muic_info
*info
;
566 int i
, ret
, irq_flags
;
571 info
= devm_kzalloc(&i2c
->dev
, sizeof(*info
), GFP_KERNEL
);
574 i2c_set_clientdata(i2c
, info
);
576 info
->dev
= &i2c
->dev
;
578 info
->irq
= i2c
->irq
;
579 info
->muic_irqs
= sm5502_muic_irqs
;
580 info
->num_muic_irqs
= ARRAY_SIZE(sm5502_muic_irqs
);
581 info
->reg_data
= sm5502_reg_data
;
582 info
->num_reg_data
= ARRAY_SIZE(sm5502_reg_data
);
584 mutex_init(&info
->mutex
);
586 INIT_WORK(&info
->irq_work
, sm5502_muic_irq_work
);
588 info
->regmap
= devm_regmap_init_i2c(i2c
, &sm5502_muic_regmap_config
);
589 if (IS_ERR(info
->regmap
)) {
590 ret
= PTR_ERR(info
->regmap
);
591 dev_err(info
->dev
, "failed to allocate register map: %d\n",
596 /* Support irq domain for SM5502 MUIC device */
597 irq_flags
= IRQF_TRIGGER_FALLING
| IRQF_ONESHOT
| IRQF_SHARED
;
598 ret
= regmap_add_irq_chip(info
->regmap
, info
->irq
, irq_flags
, 0,
599 &sm5502_muic_irq_chip
, &info
->irq_data
);
601 dev_err(info
->dev
, "failed to request IRQ %d: %d\n",
606 for (i
= 0; i
< info
->num_muic_irqs
; i
++) {
607 struct muic_irq
*muic_irq
= &info
->muic_irqs
[i
];
608 unsigned int virq
= 0;
610 virq
= regmap_irq_get_virq(info
->irq_data
, muic_irq
->irq
);
613 muic_irq
->virq
= virq
;
615 ret
= devm_request_threaded_irq(info
->dev
, virq
, NULL
,
616 sm5502_muic_irq_handler
,
618 muic_irq
->name
, info
);
620 dev_err(info
->dev
, "failed: irq request (IRQ: %d,"
621 " error :%d)\n", muic_irq
->irq
, ret
);
626 /* Allocate extcon device */
627 info
->edev
= devm_extcon_dev_allocate(info
->dev
, sm5502_extcon_cable
);
628 if (IS_ERR(info
->edev
)) {
629 dev_err(info
->dev
, "failed to allocate memory for extcon\n");
632 info
->edev
->name
= np
->name
;
634 /* Register extcon device */
635 ret
= devm_extcon_dev_register(info
->dev
, info
->edev
);
637 dev_err(info
->dev
, "failed to register extcon device\n");
642 * Detect accessory after completing the initialization of platform
644 * - Use delayed workqueue to detect cable state and then
645 * notify cable state to notifiee/platform through uevent.
646 * After completing the booting of platform, the extcon provider
647 * driver should notify cable state to upper layer.
649 INIT_DELAYED_WORK(&info
->wq_detcable
, sm5502_muic_detect_cable_wq
);
650 queue_delayed_work(system_power_efficient_wq
, &info
->wq_detcable
,
651 msecs_to_jiffies(DELAY_MS_DEFAULT
));
653 /* Initialize SM5502 device and print vendor id and version id */
654 sm5502_init_dev_type(info
);
659 static int sm5502_muic_i2c_remove(struct i2c_client
*i2c
)
661 struct sm5502_muic_info
*info
= i2c_get_clientdata(i2c
);
663 regmap_del_irq_chip(info
->irq
, info
->irq_data
);
668 static struct of_device_id sm5502_dt_match
[] = {
669 { .compatible
= "siliconmitus,sm5502-muic" },
673 #ifdef CONFIG_PM_SLEEP
674 static int sm5502_muic_suspend(struct device
*dev
)
676 struct i2c_client
*i2c
= container_of(dev
, struct i2c_client
, dev
);
677 struct sm5502_muic_info
*info
= i2c_get_clientdata(i2c
);
679 enable_irq_wake(info
->irq
);
684 static int sm5502_muic_resume(struct device
*dev
)
686 struct i2c_client
*i2c
= container_of(dev
, struct i2c_client
, dev
);
687 struct sm5502_muic_info
*info
= i2c_get_clientdata(i2c
);
689 disable_irq_wake(info
->irq
);
695 static SIMPLE_DEV_PM_OPS(sm5502_muic_pm_ops
,
696 sm5502_muic_suspend
, sm5502_muic_resume
);
698 static const struct i2c_device_id sm5502_i2c_id
[] = {
699 { "sm5502", TYPE_SM5502
},
702 MODULE_DEVICE_TABLE(i2c
, sm5502_i2c_id
);
704 static struct i2c_driver sm5502_muic_i2c_driver
= {
707 .owner
= THIS_MODULE
,
708 .pm
= &sm5502_muic_pm_ops
,
709 .of_match_table
= sm5502_dt_match
,
711 .probe
= sm5022_muic_i2c_probe
,
712 .remove
= sm5502_muic_i2c_remove
,
713 .id_table
= sm5502_i2c_id
,
716 static int __init
sm5502_muic_i2c_init(void)
718 return i2c_add_driver(&sm5502_muic_i2c_driver
);
720 subsys_initcall(sm5502_muic_i2c_init
);
722 MODULE_DESCRIPTION("Silicon Mitus SM5502 Extcon driver");
723 MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
724 MODULE_LICENSE("GPL");