1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0-or-later
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun * extcon-sm5502.c - Silicon Mitus SM5502 extcon drvier to support USB switches
4*4882a593Smuzhiyun *
5*4882a593Smuzhiyun * Copyright (c) 2014 Samsung Electronics Co., Ltd
6*4882a593Smuzhiyun * Author: Chanwoo Choi <cw00.choi@samsung.com>
7*4882a593Smuzhiyun */
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun #include <linux/err.h>
10*4882a593Smuzhiyun #include <linux/i2c.h>
11*4882a593Smuzhiyun #include <linux/interrupt.h>
12*4882a593Smuzhiyun #include <linux/irqdomain.h>
13*4882a593Smuzhiyun #include <linux/kernel.h>
14*4882a593Smuzhiyun #include <linux/module.h>
15*4882a593Smuzhiyun #include <linux/platform_device.h>
16*4882a593Smuzhiyun #include <linux/regmap.h>
17*4882a593Smuzhiyun #include <linux/slab.h>
18*4882a593Smuzhiyun #include <linux/extcon-provider.h>
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun #include "extcon-sm5502.h"
21*4882a593Smuzhiyun
22*4882a593Smuzhiyun #define DELAY_MS_DEFAULT 17000 /* unit: millisecond */
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun struct muic_irq {
25*4882a593Smuzhiyun unsigned int irq;
26*4882a593Smuzhiyun const char *name;
27*4882a593Smuzhiyun unsigned int virq;
28*4882a593Smuzhiyun };
29*4882a593Smuzhiyun
30*4882a593Smuzhiyun struct reg_data {
31*4882a593Smuzhiyun u8 reg;
32*4882a593Smuzhiyun unsigned int val;
33*4882a593Smuzhiyun bool invert;
34*4882a593Smuzhiyun };
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun struct sm5502_muic_info {
37*4882a593Smuzhiyun struct device *dev;
38*4882a593Smuzhiyun struct extcon_dev *edev;
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun struct i2c_client *i2c;
41*4882a593Smuzhiyun struct regmap *regmap;
42*4882a593Smuzhiyun
43*4882a593Smuzhiyun struct regmap_irq_chip_data *irq_data;
44*4882a593Smuzhiyun struct muic_irq *muic_irqs;
45*4882a593Smuzhiyun unsigned int num_muic_irqs;
46*4882a593Smuzhiyun int irq;
47*4882a593Smuzhiyun bool irq_attach;
48*4882a593Smuzhiyun bool irq_detach;
49*4882a593Smuzhiyun struct work_struct irq_work;
50*4882a593Smuzhiyun
51*4882a593Smuzhiyun struct reg_data *reg_data;
52*4882a593Smuzhiyun unsigned int num_reg_data;
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun struct mutex mutex;
55*4882a593Smuzhiyun
56*4882a593Smuzhiyun /*
57*4882a593Smuzhiyun * Use delayed workqueue to detect cable state and then
58*4882a593Smuzhiyun * notify cable state to notifiee/platform through uevent.
59*4882a593Smuzhiyun * After completing the booting of platform, the extcon provider
60*4882a593Smuzhiyun * driver should notify cable state to upper layer.
61*4882a593Smuzhiyun */
62*4882a593Smuzhiyun struct delayed_work wq_detcable;
63*4882a593Smuzhiyun };
64*4882a593Smuzhiyun
65*4882a593Smuzhiyun /* Default value of SM5502 register to bring up MUIC device. */
66*4882a593Smuzhiyun static struct reg_data sm5502_reg_data[] = {
67*4882a593Smuzhiyun {
68*4882a593Smuzhiyun .reg = SM5502_REG_RESET,
69*4882a593Smuzhiyun .val = SM5502_REG_RESET_MASK,
70*4882a593Smuzhiyun .invert = true,
71*4882a593Smuzhiyun }, {
72*4882a593Smuzhiyun .reg = SM5502_REG_CONTROL,
73*4882a593Smuzhiyun .val = SM5502_REG_CONTROL_MASK_INT_MASK,
74*4882a593Smuzhiyun .invert = false,
75*4882a593Smuzhiyun }, {
76*4882a593Smuzhiyun .reg = SM5502_REG_INTMASK1,
77*4882a593Smuzhiyun .val = SM5502_REG_INTM1_KP_MASK
78*4882a593Smuzhiyun | SM5502_REG_INTM1_LKP_MASK
79*4882a593Smuzhiyun | SM5502_REG_INTM1_LKR_MASK,
80*4882a593Smuzhiyun .invert = true,
81*4882a593Smuzhiyun }, {
82*4882a593Smuzhiyun .reg = SM5502_REG_INTMASK2,
83*4882a593Smuzhiyun .val = SM5502_REG_INTM2_VBUS_DET_MASK
84*4882a593Smuzhiyun | SM5502_REG_INTM2_REV_ACCE_MASK
85*4882a593Smuzhiyun | SM5502_REG_INTM2_ADC_CHG_MASK
86*4882a593Smuzhiyun | SM5502_REG_INTM2_STUCK_KEY_MASK
87*4882a593Smuzhiyun | SM5502_REG_INTM2_STUCK_KEY_RCV_MASK
88*4882a593Smuzhiyun | SM5502_REG_INTM2_MHL_MASK,
89*4882a593Smuzhiyun .invert = true,
90*4882a593Smuzhiyun },
91*4882a593Smuzhiyun };
92*4882a593Smuzhiyun
93*4882a593Smuzhiyun /* List of detectable cables */
94*4882a593Smuzhiyun static const unsigned int sm5502_extcon_cable[] = {
95*4882a593Smuzhiyun EXTCON_USB,
96*4882a593Smuzhiyun EXTCON_USB_HOST,
97*4882a593Smuzhiyun EXTCON_CHG_USB_SDP,
98*4882a593Smuzhiyun EXTCON_CHG_USB_DCP,
99*4882a593Smuzhiyun EXTCON_NONE,
100*4882a593Smuzhiyun };
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun /* Define supported accessory type */
103*4882a593Smuzhiyun enum sm5502_muic_acc_type {
104*4882a593Smuzhiyun SM5502_MUIC_ADC_GROUND = 0x0,
105*4882a593Smuzhiyun SM5502_MUIC_ADC_SEND_END_BUTTON,
106*4882a593Smuzhiyun SM5502_MUIC_ADC_REMOTE_S1_BUTTON,
107*4882a593Smuzhiyun SM5502_MUIC_ADC_REMOTE_S2_BUTTON,
108*4882a593Smuzhiyun SM5502_MUIC_ADC_REMOTE_S3_BUTTON,
109*4882a593Smuzhiyun SM5502_MUIC_ADC_REMOTE_S4_BUTTON,
110*4882a593Smuzhiyun SM5502_MUIC_ADC_REMOTE_S5_BUTTON,
111*4882a593Smuzhiyun SM5502_MUIC_ADC_REMOTE_S6_BUTTON,
112*4882a593Smuzhiyun SM5502_MUIC_ADC_REMOTE_S7_BUTTON,
113*4882a593Smuzhiyun SM5502_MUIC_ADC_REMOTE_S8_BUTTON,
114*4882a593Smuzhiyun SM5502_MUIC_ADC_REMOTE_S9_BUTTON,
115*4882a593Smuzhiyun SM5502_MUIC_ADC_REMOTE_S10_BUTTON,
116*4882a593Smuzhiyun SM5502_MUIC_ADC_REMOTE_S11_BUTTON,
117*4882a593Smuzhiyun SM5502_MUIC_ADC_REMOTE_S12_BUTTON,
118*4882a593Smuzhiyun SM5502_MUIC_ADC_RESERVED_ACC_1,
119*4882a593Smuzhiyun SM5502_MUIC_ADC_RESERVED_ACC_2,
120*4882a593Smuzhiyun SM5502_MUIC_ADC_RESERVED_ACC_3,
121*4882a593Smuzhiyun SM5502_MUIC_ADC_RESERVED_ACC_4,
122*4882a593Smuzhiyun SM5502_MUIC_ADC_RESERVED_ACC_5,
123*4882a593Smuzhiyun SM5502_MUIC_ADC_AUDIO_TYPE2,
124*4882a593Smuzhiyun SM5502_MUIC_ADC_PHONE_POWERED_DEV,
125*4882a593Smuzhiyun SM5502_MUIC_ADC_TTY_CONVERTER,
126*4882a593Smuzhiyun SM5502_MUIC_ADC_UART_CABLE,
127*4882a593Smuzhiyun SM5502_MUIC_ADC_TYPE1_CHARGER,
128*4882a593Smuzhiyun SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB,
129*4882a593Smuzhiyun SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB,
130*4882a593Smuzhiyun SM5502_MUIC_ADC_AUDIO_VIDEO_CABLE,
131*4882a593Smuzhiyun SM5502_MUIC_ADC_TYPE2_CHARGER,
132*4882a593Smuzhiyun SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART,
133*4882a593Smuzhiyun SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART,
134*4882a593Smuzhiyun SM5502_MUIC_ADC_AUDIO_TYPE1,
135*4882a593Smuzhiyun SM5502_MUIC_ADC_OPEN = 0x1f,
136*4882a593Smuzhiyun
137*4882a593Smuzhiyun /*
138*4882a593Smuzhiyun * The below accessories have same ADC value (0x1f or 0x1e).
139*4882a593Smuzhiyun * So, Device type1 is used to separate specific accessory.
140*4882a593Smuzhiyun */
141*4882a593Smuzhiyun /* |---------|--ADC| */
142*4882a593Smuzhiyun /* | [7:5]|[4:0]| */
143*4882a593Smuzhiyun SM5502_MUIC_ADC_AUDIO_TYPE1_FULL_REMOTE = 0x3e, /* | 001|11110| */
144*4882a593Smuzhiyun SM5502_MUIC_ADC_AUDIO_TYPE1_SEND_END = 0x5e, /* | 010|11110| */
145*4882a593Smuzhiyun /* |Dev Type1|--ADC| */
146*4882a593Smuzhiyun SM5502_MUIC_ADC_OPEN_USB = 0x5f, /* | 010|11111| */
147*4882a593Smuzhiyun SM5502_MUIC_ADC_OPEN_TA = 0xdf, /* | 110|11111| */
148*4882a593Smuzhiyun SM5502_MUIC_ADC_OPEN_USB_OTG = 0xff, /* | 111|11111| */
149*4882a593Smuzhiyun };
150*4882a593Smuzhiyun
151*4882a593Smuzhiyun /* List of supported interrupt for SM5502 */
152*4882a593Smuzhiyun static struct muic_irq sm5502_muic_irqs[] = {
153*4882a593Smuzhiyun { SM5502_IRQ_INT1_ATTACH, "muic-attach" },
154*4882a593Smuzhiyun { SM5502_IRQ_INT1_DETACH, "muic-detach" },
155*4882a593Smuzhiyun { SM5502_IRQ_INT1_KP, "muic-kp" },
156*4882a593Smuzhiyun { SM5502_IRQ_INT1_LKP, "muic-lkp" },
157*4882a593Smuzhiyun { SM5502_IRQ_INT1_LKR, "muic-lkr" },
158*4882a593Smuzhiyun { SM5502_IRQ_INT1_OVP_EVENT, "muic-ovp-event" },
159*4882a593Smuzhiyun { SM5502_IRQ_INT1_OCP_EVENT, "muic-ocp-event" },
160*4882a593Smuzhiyun { SM5502_IRQ_INT1_OVP_OCP_DIS, "muic-ovp-ocp-dis" },
161*4882a593Smuzhiyun { SM5502_IRQ_INT2_VBUS_DET, "muic-vbus-det" },
162*4882a593Smuzhiyun { SM5502_IRQ_INT2_REV_ACCE, "muic-rev-acce" },
163*4882a593Smuzhiyun { SM5502_IRQ_INT2_ADC_CHG, "muic-adc-chg" },
164*4882a593Smuzhiyun { SM5502_IRQ_INT2_STUCK_KEY, "muic-stuck-key" },
165*4882a593Smuzhiyun { SM5502_IRQ_INT2_STUCK_KEY_RCV, "muic-stuck-key-rcv" },
166*4882a593Smuzhiyun { SM5502_IRQ_INT2_MHL, "muic-mhl" },
167*4882a593Smuzhiyun };
168*4882a593Smuzhiyun
169*4882a593Smuzhiyun /* Define interrupt list of SM5502 to register regmap_irq */
170*4882a593Smuzhiyun static const struct regmap_irq sm5502_irqs[] = {
171*4882a593Smuzhiyun /* INT1 interrupts */
172*4882a593Smuzhiyun { .reg_offset = 0, .mask = SM5502_IRQ_INT1_ATTACH_MASK, },
173*4882a593Smuzhiyun { .reg_offset = 0, .mask = SM5502_IRQ_INT1_DETACH_MASK, },
174*4882a593Smuzhiyun { .reg_offset = 0, .mask = SM5502_IRQ_INT1_KP_MASK, },
175*4882a593Smuzhiyun { .reg_offset = 0, .mask = SM5502_IRQ_INT1_LKP_MASK, },
176*4882a593Smuzhiyun { .reg_offset = 0, .mask = SM5502_IRQ_INT1_LKR_MASK, },
177*4882a593Smuzhiyun { .reg_offset = 0, .mask = SM5502_IRQ_INT1_OVP_EVENT_MASK, },
178*4882a593Smuzhiyun { .reg_offset = 0, .mask = SM5502_IRQ_INT1_OCP_EVENT_MASK, },
179*4882a593Smuzhiyun { .reg_offset = 0, .mask = SM5502_IRQ_INT1_OVP_OCP_DIS_MASK, },
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun /* INT2 interrupts */
182*4882a593Smuzhiyun { .reg_offset = 1, .mask = SM5502_IRQ_INT2_VBUS_DET_MASK,},
183*4882a593Smuzhiyun { .reg_offset = 1, .mask = SM5502_IRQ_INT2_REV_ACCE_MASK, },
184*4882a593Smuzhiyun { .reg_offset = 1, .mask = SM5502_IRQ_INT2_ADC_CHG_MASK, },
185*4882a593Smuzhiyun { .reg_offset = 1, .mask = SM5502_IRQ_INT2_STUCK_KEY_MASK, },
186*4882a593Smuzhiyun { .reg_offset = 1, .mask = SM5502_IRQ_INT2_STUCK_KEY_RCV_MASK, },
187*4882a593Smuzhiyun { .reg_offset = 1, .mask = SM5502_IRQ_INT2_MHL_MASK, },
188*4882a593Smuzhiyun };
189*4882a593Smuzhiyun
190*4882a593Smuzhiyun static const struct regmap_irq_chip sm5502_muic_irq_chip = {
191*4882a593Smuzhiyun .name = "sm5502",
192*4882a593Smuzhiyun .status_base = SM5502_REG_INT1,
193*4882a593Smuzhiyun .mask_base = SM5502_REG_INTMASK1,
194*4882a593Smuzhiyun .mask_invert = false,
195*4882a593Smuzhiyun .num_regs = 2,
196*4882a593Smuzhiyun .irqs = sm5502_irqs,
197*4882a593Smuzhiyun .num_irqs = ARRAY_SIZE(sm5502_irqs),
198*4882a593Smuzhiyun };
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun /* Define regmap configuration of SM5502 for I2C communication */
sm5502_muic_volatile_reg(struct device * dev,unsigned int reg)201*4882a593Smuzhiyun static bool sm5502_muic_volatile_reg(struct device *dev, unsigned int reg)
202*4882a593Smuzhiyun {
203*4882a593Smuzhiyun switch (reg) {
204*4882a593Smuzhiyun case SM5502_REG_INTMASK1:
205*4882a593Smuzhiyun case SM5502_REG_INTMASK2:
206*4882a593Smuzhiyun return true;
207*4882a593Smuzhiyun default:
208*4882a593Smuzhiyun break;
209*4882a593Smuzhiyun }
210*4882a593Smuzhiyun return false;
211*4882a593Smuzhiyun }
212*4882a593Smuzhiyun
213*4882a593Smuzhiyun static const struct regmap_config sm5502_muic_regmap_config = {
214*4882a593Smuzhiyun .reg_bits = 8,
215*4882a593Smuzhiyun .val_bits = 8,
216*4882a593Smuzhiyun .volatile_reg = sm5502_muic_volatile_reg,
217*4882a593Smuzhiyun .max_register = SM5502_REG_END,
218*4882a593Smuzhiyun };
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun /* Change DM_CON/DP_CON/VBUSIN switch according to cable type */
sm5502_muic_set_path(struct sm5502_muic_info * info,unsigned int con_sw,unsigned int vbus_sw,bool attached)221*4882a593Smuzhiyun static int sm5502_muic_set_path(struct sm5502_muic_info *info,
222*4882a593Smuzhiyun unsigned int con_sw, unsigned int vbus_sw,
223*4882a593Smuzhiyun bool attached)
224*4882a593Smuzhiyun {
225*4882a593Smuzhiyun int ret;
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun if (!attached) {
228*4882a593Smuzhiyun con_sw = DM_DP_SWITCH_OPEN;
229*4882a593Smuzhiyun vbus_sw = VBUSIN_SWITCH_OPEN;
230*4882a593Smuzhiyun }
231*4882a593Smuzhiyun
232*4882a593Smuzhiyun switch (con_sw) {
233*4882a593Smuzhiyun case DM_DP_SWITCH_OPEN:
234*4882a593Smuzhiyun case DM_DP_SWITCH_USB:
235*4882a593Smuzhiyun case DM_DP_SWITCH_AUDIO:
236*4882a593Smuzhiyun case DM_DP_SWITCH_UART:
237*4882a593Smuzhiyun ret = regmap_update_bits(info->regmap, SM5502_REG_MANUAL_SW1,
238*4882a593Smuzhiyun SM5502_REG_MANUAL_SW1_DP_MASK |
239*4882a593Smuzhiyun SM5502_REG_MANUAL_SW1_DM_MASK,
240*4882a593Smuzhiyun con_sw);
241*4882a593Smuzhiyun if (ret < 0) {
242*4882a593Smuzhiyun dev_err(info->dev,
243*4882a593Smuzhiyun "cannot update DM_CON/DP_CON switch\n");
244*4882a593Smuzhiyun return ret;
245*4882a593Smuzhiyun }
246*4882a593Smuzhiyun break;
247*4882a593Smuzhiyun default:
248*4882a593Smuzhiyun dev_err(info->dev, "Unknown DM_CON/DP_CON switch type (%d)\n",
249*4882a593Smuzhiyun con_sw);
250*4882a593Smuzhiyun return -EINVAL;
251*4882a593Smuzhiyun }
252*4882a593Smuzhiyun
253*4882a593Smuzhiyun switch (vbus_sw) {
254*4882a593Smuzhiyun case VBUSIN_SWITCH_OPEN:
255*4882a593Smuzhiyun case VBUSIN_SWITCH_VBUSOUT:
256*4882a593Smuzhiyun case VBUSIN_SWITCH_MIC:
257*4882a593Smuzhiyun case VBUSIN_SWITCH_VBUSOUT_WITH_USB:
258*4882a593Smuzhiyun ret = regmap_update_bits(info->regmap, SM5502_REG_MANUAL_SW1,
259*4882a593Smuzhiyun SM5502_REG_MANUAL_SW1_VBUSIN_MASK,
260*4882a593Smuzhiyun vbus_sw);
261*4882a593Smuzhiyun if (ret < 0) {
262*4882a593Smuzhiyun dev_err(info->dev,
263*4882a593Smuzhiyun "cannot update VBUSIN switch\n");
264*4882a593Smuzhiyun return ret;
265*4882a593Smuzhiyun }
266*4882a593Smuzhiyun break;
267*4882a593Smuzhiyun default:
268*4882a593Smuzhiyun dev_err(info->dev, "Unknown VBUS switch type (%d)\n", vbus_sw);
269*4882a593Smuzhiyun return -EINVAL;
270*4882a593Smuzhiyun }
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun return 0;
273*4882a593Smuzhiyun }
274*4882a593Smuzhiyun
275*4882a593Smuzhiyun /* Return cable type of attached or detached accessories */
sm5502_muic_get_cable_type(struct sm5502_muic_info * info)276*4882a593Smuzhiyun static unsigned int sm5502_muic_get_cable_type(struct sm5502_muic_info *info)
277*4882a593Smuzhiyun {
278*4882a593Smuzhiyun unsigned int cable_type, adc, dev_type1;
279*4882a593Smuzhiyun int ret;
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun /* Read ADC value according to external cable or button */
282*4882a593Smuzhiyun ret = regmap_read(info->regmap, SM5502_REG_ADC, &adc);
283*4882a593Smuzhiyun if (ret) {
284*4882a593Smuzhiyun dev_err(info->dev, "failed to read ADC register\n");
285*4882a593Smuzhiyun return ret;
286*4882a593Smuzhiyun }
287*4882a593Smuzhiyun
288*4882a593Smuzhiyun /*
289*4882a593Smuzhiyun * If ADC is SM5502_MUIC_ADC_GROUND(0x0), external cable hasn't
290*4882a593Smuzhiyun * connected with to MUIC device.
291*4882a593Smuzhiyun */
292*4882a593Smuzhiyun cable_type = adc & SM5502_REG_ADC_MASK;
293*4882a593Smuzhiyun if (cable_type == SM5502_MUIC_ADC_GROUND)
294*4882a593Smuzhiyun return SM5502_MUIC_ADC_GROUND;
295*4882a593Smuzhiyun
296*4882a593Smuzhiyun switch (cable_type) {
297*4882a593Smuzhiyun case SM5502_MUIC_ADC_GROUND:
298*4882a593Smuzhiyun case SM5502_MUIC_ADC_SEND_END_BUTTON:
299*4882a593Smuzhiyun case SM5502_MUIC_ADC_REMOTE_S1_BUTTON:
300*4882a593Smuzhiyun case SM5502_MUIC_ADC_REMOTE_S2_BUTTON:
301*4882a593Smuzhiyun case SM5502_MUIC_ADC_REMOTE_S3_BUTTON:
302*4882a593Smuzhiyun case SM5502_MUIC_ADC_REMOTE_S4_BUTTON:
303*4882a593Smuzhiyun case SM5502_MUIC_ADC_REMOTE_S5_BUTTON:
304*4882a593Smuzhiyun case SM5502_MUIC_ADC_REMOTE_S6_BUTTON:
305*4882a593Smuzhiyun case SM5502_MUIC_ADC_REMOTE_S7_BUTTON:
306*4882a593Smuzhiyun case SM5502_MUIC_ADC_REMOTE_S8_BUTTON:
307*4882a593Smuzhiyun case SM5502_MUIC_ADC_REMOTE_S9_BUTTON:
308*4882a593Smuzhiyun case SM5502_MUIC_ADC_REMOTE_S10_BUTTON:
309*4882a593Smuzhiyun case SM5502_MUIC_ADC_REMOTE_S11_BUTTON:
310*4882a593Smuzhiyun case SM5502_MUIC_ADC_REMOTE_S12_BUTTON:
311*4882a593Smuzhiyun case SM5502_MUIC_ADC_RESERVED_ACC_1:
312*4882a593Smuzhiyun case SM5502_MUIC_ADC_RESERVED_ACC_2:
313*4882a593Smuzhiyun case SM5502_MUIC_ADC_RESERVED_ACC_3:
314*4882a593Smuzhiyun case SM5502_MUIC_ADC_RESERVED_ACC_4:
315*4882a593Smuzhiyun case SM5502_MUIC_ADC_RESERVED_ACC_5:
316*4882a593Smuzhiyun case SM5502_MUIC_ADC_AUDIO_TYPE2:
317*4882a593Smuzhiyun case SM5502_MUIC_ADC_PHONE_POWERED_DEV:
318*4882a593Smuzhiyun case SM5502_MUIC_ADC_TTY_CONVERTER:
319*4882a593Smuzhiyun case SM5502_MUIC_ADC_UART_CABLE:
320*4882a593Smuzhiyun case SM5502_MUIC_ADC_TYPE1_CHARGER:
321*4882a593Smuzhiyun case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB:
322*4882a593Smuzhiyun case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB:
323*4882a593Smuzhiyun case SM5502_MUIC_ADC_AUDIO_VIDEO_CABLE:
324*4882a593Smuzhiyun case SM5502_MUIC_ADC_TYPE2_CHARGER:
325*4882a593Smuzhiyun case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART:
326*4882a593Smuzhiyun case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART:
327*4882a593Smuzhiyun break;
328*4882a593Smuzhiyun case SM5502_MUIC_ADC_AUDIO_TYPE1:
329*4882a593Smuzhiyun /*
330*4882a593Smuzhiyun * Check whether cable type is
331*4882a593Smuzhiyun * SM5502_MUIC_ADC_AUDIO_TYPE1_FULL_REMOTE
332*4882a593Smuzhiyun * or SM5502_MUIC_ADC_AUDIO_TYPE1_SEND_END
333*4882a593Smuzhiyun * by using Button event.
334*4882a593Smuzhiyun */
335*4882a593Smuzhiyun break;
336*4882a593Smuzhiyun case SM5502_MUIC_ADC_OPEN:
337*4882a593Smuzhiyun ret = regmap_read(info->regmap, SM5502_REG_DEV_TYPE1,
338*4882a593Smuzhiyun &dev_type1);
339*4882a593Smuzhiyun if (ret) {
340*4882a593Smuzhiyun dev_err(info->dev, "failed to read DEV_TYPE1 reg\n");
341*4882a593Smuzhiyun return ret;
342*4882a593Smuzhiyun }
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun switch (dev_type1) {
345*4882a593Smuzhiyun case SM5502_REG_DEV_TYPE1_USB_SDP_MASK:
346*4882a593Smuzhiyun cable_type = SM5502_MUIC_ADC_OPEN_USB;
347*4882a593Smuzhiyun break;
348*4882a593Smuzhiyun case SM5502_REG_DEV_TYPE1_DEDICATED_CHG_MASK:
349*4882a593Smuzhiyun cable_type = SM5502_MUIC_ADC_OPEN_TA;
350*4882a593Smuzhiyun break;
351*4882a593Smuzhiyun case SM5502_REG_DEV_TYPE1_USB_OTG_MASK:
352*4882a593Smuzhiyun cable_type = SM5502_MUIC_ADC_OPEN_USB_OTG;
353*4882a593Smuzhiyun break;
354*4882a593Smuzhiyun default:
355*4882a593Smuzhiyun dev_dbg(info->dev,
356*4882a593Smuzhiyun "cannot identify the cable type: adc(0x%x)\n",
357*4882a593Smuzhiyun adc);
358*4882a593Smuzhiyun return -EINVAL;
359*4882a593Smuzhiyun }
360*4882a593Smuzhiyun break;
361*4882a593Smuzhiyun default:
362*4882a593Smuzhiyun dev_err(info->dev,
363*4882a593Smuzhiyun "failed to identify the cable type: adc(0x%x)\n", adc);
364*4882a593Smuzhiyun return -EINVAL;
365*4882a593Smuzhiyun }
366*4882a593Smuzhiyun
367*4882a593Smuzhiyun return cable_type;
368*4882a593Smuzhiyun }
369*4882a593Smuzhiyun
sm5502_muic_cable_handler(struct sm5502_muic_info * info,bool attached)370*4882a593Smuzhiyun static int sm5502_muic_cable_handler(struct sm5502_muic_info *info,
371*4882a593Smuzhiyun bool attached)
372*4882a593Smuzhiyun {
373*4882a593Smuzhiyun static unsigned int prev_cable_type = SM5502_MUIC_ADC_GROUND;
374*4882a593Smuzhiyun unsigned int cable_type = SM5502_MUIC_ADC_GROUND;
375*4882a593Smuzhiyun unsigned int con_sw = DM_DP_SWITCH_OPEN;
376*4882a593Smuzhiyun unsigned int vbus_sw = VBUSIN_SWITCH_OPEN;
377*4882a593Smuzhiyun unsigned int id;
378*4882a593Smuzhiyun int ret;
379*4882a593Smuzhiyun
380*4882a593Smuzhiyun /* Get the type of attached or detached cable */
381*4882a593Smuzhiyun if (attached)
382*4882a593Smuzhiyun cable_type = sm5502_muic_get_cable_type(info);
383*4882a593Smuzhiyun else
384*4882a593Smuzhiyun cable_type = prev_cable_type;
385*4882a593Smuzhiyun prev_cable_type = cable_type;
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun switch (cable_type) {
388*4882a593Smuzhiyun case SM5502_MUIC_ADC_OPEN_USB:
389*4882a593Smuzhiyun id = EXTCON_USB;
390*4882a593Smuzhiyun con_sw = DM_DP_SWITCH_USB;
391*4882a593Smuzhiyun vbus_sw = VBUSIN_SWITCH_VBUSOUT_WITH_USB;
392*4882a593Smuzhiyun break;
393*4882a593Smuzhiyun case SM5502_MUIC_ADC_OPEN_TA:
394*4882a593Smuzhiyun id = EXTCON_CHG_USB_DCP;
395*4882a593Smuzhiyun con_sw = DM_DP_SWITCH_OPEN;
396*4882a593Smuzhiyun vbus_sw = VBUSIN_SWITCH_VBUSOUT;
397*4882a593Smuzhiyun break;
398*4882a593Smuzhiyun case SM5502_MUIC_ADC_OPEN_USB_OTG:
399*4882a593Smuzhiyun id = EXTCON_USB_HOST;
400*4882a593Smuzhiyun con_sw = DM_DP_SWITCH_USB;
401*4882a593Smuzhiyun vbus_sw = VBUSIN_SWITCH_OPEN;
402*4882a593Smuzhiyun break;
403*4882a593Smuzhiyun default:
404*4882a593Smuzhiyun dev_dbg(info->dev,
405*4882a593Smuzhiyun "cannot handle this cable_type (0x%x)\n", cable_type);
406*4882a593Smuzhiyun return 0;
407*4882a593Smuzhiyun }
408*4882a593Smuzhiyun
409*4882a593Smuzhiyun /* Change internal hardware path(DM_CON/DP_CON, VBUSIN) */
410*4882a593Smuzhiyun ret = sm5502_muic_set_path(info, con_sw, vbus_sw, attached);
411*4882a593Smuzhiyun if (ret < 0)
412*4882a593Smuzhiyun return ret;
413*4882a593Smuzhiyun
414*4882a593Smuzhiyun /* Change the state of external accessory */
415*4882a593Smuzhiyun extcon_set_state_sync(info->edev, id, attached);
416*4882a593Smuzhiyun if (id == EXTCON_USB)
417*4882a593Smuzhiyun extcon_set_state_sync(info->edev, EXTCON_CHG_USB_SDP,
418*4882a593Smuzhiyun attached);
419*4882a593Smuzhiyun
420*4882a593Smuzhiyun return 0;
421*4882a593Smuzhiyun }
422*4882a593Smuzhiyun
sm5502_muic_irq_work(struct work_struct * work)423*4882a593Smuzhiyun static void sm5502_muic_irq_work(struct work_struct *work)
424*4882a593Smuzhiyun {
425*4882a593Smuzhiyun struct sm5502_muic_info *info = container_of(work,
426*4882a593Smuzhiyun struct sm5502_muic_info, irq_work);
427*4882a593Smuzhiyun int ret = 0;
428*4882a593Smuzhiyun
429*4882a593Smuzhiyun if (!info->edev)
430*4882a593Smuzhiyun return;
431*4882a593Smuzhiyun
432*4882a593Smuzhiyun mutex_lock(&info->mutex);
433*4882a593Smuzhiyun
434*4882a593Smuzhiyun /* Detect attached or detached cables */
435*4882a593Smuzhiyun if (info->irq_attach) {
436*4882a593Smuzhiyun ret = sm5502_muic_cable_handler(info, true);
437*4882a593Smuzhiyun info->irq_attach = false;
438*4882a593Smuzhiyun }
439*4882a593Smuzhiyun if (info->irq_detach) {
440*4882a593Smuzhiyun ret = sm5502_muic_cable_handler(info, false);
441*4882a593Smuzhiyun info->irq_detach = false;
442*4882a593Smuzhiyun }
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun if (ret < 0)
445*4882a593Smuzhiyun dev_err(info->dev, "failed to handle MUIC interrupt\n");
446*4882a593Smuzhiyun
447*4882a593Smuzhiyun mutex_unlock(&info->mutex);
448*4882a593Smuzhiyun }
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun /*
451*4882a593Smuzhiyun * Sets irq_attach or irq_detach in sm5502_muic_info and returns 0.
452*4882a593Smuzhiyun * Returns -ESRCH if irq_type does not match registered IRQ for this dev type.
453*4882a593Smuzhiyun */
sm5502_parse_irq(struct sm5502_muic_info * info,int irq_type)454*4882a593Smuzhiyun static int sm5502_parse_irq(struct sm5502_muic_info *info, int irq_type)
455*4882a593Smuzhiyun {
456*4882a593Smuzhiyun switch (irq_type) {
457*4882a593Smuzhiyun case SM5502_IRQ_INT1_ATTACH:
458*4882a593Smuzhiyun info->irq_attach = true;
459*4882a593Smuzhiyun break;
460*4882a593Smuzhiyun case SM5502_IRQ_INT1_DETACH:
461*4882a593Smuzhiyun info->irq_detach = true;
462*4882a593Smuzhiyun break;
463*4882a593Smuzhiyun case SM5502_IRQ_INT1_KP:
464*4882a593Smuzhiyun case SM5502_IRQ_INT1_LKP:
465*4882a593Smuzhiyun case SM5502_IRQ_INT1_LKR:
466*4882a593Smuzhiyun case SM5502_IRQ_INT1_OVP_EVENT:
467*4882a593Smuzhiyun case SM5502_IRQ_INT1_OCP_EVENT:
468*4882a593Smuzhiyun case SM5502_IRQ_INT1_OVP_OCP_DIS:
469*4882a593Smuzhiyun case SM5502_IRQ_INT2_VBUS_DET:
470*4882a593Smuzhiyun case SM5502_IRQ_INT2_REV_ACCE:
471*4882a593Smuzhiyun case SM5502_IRQ_INT2_ADC_CHG:
472*4882a593Smuzhiyun case SM5502_IRQ_INT2_STUCK_KEY:
473*4882a593Smuzhiyun case SM5502_IRQ_INT2_STUCK_KEY_RCV:
474*4882a593Smuzhiyun case SM5502_IRQ_INT2_MHL:
475*4882a593Smuzhiyun default:
476*4882a593Smuzhiyun break;
477*4882a593Smuzhiyun }
478*4882a593Smuzhiyun
479*4882a593Smuzhiyun return 0;
480*4882a593Smuzhiyun }
481*4882a593Smuzhiyun
sm5502_muic_irq_handler(int irq,void * data)482*4882a593Smuzhiyun static irqreturn_t sm5502_muic_irq_handler(int irq, void *data)
483*4882a593Smuzhiyun {
484*4882a593Smuzhiyun struct sm5502_muic_info *info = data;
485*4882a593Smuzhiyun int i, irq_type = -1, ret;
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun for (i = 0; i < info->num_muic_irqs; i++)
488*4882a593Smuzhiyun if (irq == info->muic_irqs[i].virq)
489*4882a593Smuzhiyun irq_type = info->muic_irqs[i].irq;
490*4882a593Smuzhiyun
491*4882a593Smuzhiyun ret = sm5502_parse_irq(info, irq_type);
492*4882a593Smuzhiyun if (ret < 0) {
493*4882a593Smuzhiyun dev_warn(info->dev, "cannot handle is interrupt:%d\n",
494*4882a593Smuzhiyun irq_type);
495*4882a593Smuzhiyun return IRQ_HANDLED;
496*4882a593Smuzhiyun }
497*4882a593Smuzhiyun schedule_work(&info->irq_work);
498*4882a593Smuzhiyun
499*4882a593Smuzhiyun return IRQ_HANDLED;
500*4882a593Smuzhiyun }
501*4882a593Smuzhiyun
sm5502_muic_detect_cable_wq(struct work_struct * work)502*4882a593Smuzhiyun static void sm5502_muic_detect_cable_wq(struct work_struct *work)
503*4882a593Smuzhiyun {
504*4882a593Smuzhiyun struct sm5502_muic_info *info = container_of(to_delayed_work(work),
505*4882a593Smuzhiyun struct sm5502_muic_info, wq_detcable);
506*4882a593Smuzhiyun int ret;
507*4882a593Smuzhiyun
508*4882a593Smuzhiyun /* Notify the state of connector cable or not */
509*4882a593Smuzhiyun ret = sm5502_muic_cable_handler(info, true);
510*4882a593Smuzhiyun if (ret < 0)
511*4882a593Smuzhiyun dev_warn(info->dev, "failed to detect cable state\n");
512*4882a593Smuzhiyun }
513*4882a593Smuzhiyun
sm5502_init_dev_type(struct sm5502_muic_info * info)514*4882a593Smuzhiyun static void sm5502_init_dev_type(struct sm5502_muic_info *info)
515*4882a593Smuzhiyun {
516*4882a593Smuzhiyun unsigned int reg_data, vendor_id, version_id;
517*4882a593Smuzhiyun int i, ret;
518*4882a593Smuzhiyun
519*4882a593Smuzhiyun /* To test I2C, Print version_id and vendor_id of SM5502 */
520*4882a593Smuzhiyun ret = regmap_read(info->regmap, SM5502_REG_DEVICE_ID, ®_data);
521*4882a593Smuzhiyun if (ret) {
522*4882a593Smuzhiyun dev_err(info->dev,
523*4882a593Smuzhiyun "failed to read DEVICE_ID register: %d\n", ret);
524*4882a593Smuzhiyun return;
525*4882a593Smuzhiyun }
526*4882a593Smuzhiyun
527*4882a593Smuzhiyun vendor_id = ((reg_data & SM5502_REG_DEVICE_ID_VENDOR_MASK) >>
528*4882a593Smuzhiyun SM5502_REG_DEVICE_ID_VENDOR_SHIFT);
529*4882a593Smuzhiyun version_id = ((reg_data & SM5502_REG_DEVICE_ID_VERSION_MASK) >>
530*4882a593Smuzhiyun SM5502_REG_DEVICE_ID_VERSION_SHIFT);
531*4882a593Smuzhiyun
532*4882a593Smuzhiyun dev_info(info->dev, "Device type: version: 0x%x, vendor: 0x%x\n",
533*4882a593Smuzhiyun version_id, vendor_id);
534*4882a593Smuzhiyun
535*4882a593Smuzhiyun /* Initiazle the register of SM5502 device to bring-up */
536*4882a593Smuzhiyun for (i = 0; i < info->num_reg_data; i++) {
537*4882a593Smuzhiyun unsigned int val = 0;
538*4882a593Smuzhiyun
539*4882a593Smuzhiyun if (!info->reg_data[i].invert)
540*4882a593Smuzhiyun val |= ~info->reg_data[i].val;
541*4882a593Smuzhiyun else
542*4882a593Smuzhiyun val = info->reg_data[i].val;
543*4882a593Smuzhiyun regmap_write(info->regmap, info->reg_data[i].reg, val);
544*4882a593Smuzhiyun }
545*4882a593Smuzhiyun }
546*4882a593Smuzhiyun
sm5022_muic_i2c_probe(struct i2c_client * i2c,const struct i2c_device_id * id)547*4882a593Smuzhiyun static int sm5022_muic_i2c_probe(struct i2c_client *i2c,
548*4882a593Smuzhiyun const struct i2c_device_id *id)
549*4882a593Smuzhiyun {
550*4882a593Smuzhiyun struct device_node *np = i2c->dev.of_node;
551*4882a593Smuzhiyun struct sm5502_muic_info *info;
552*4882a593Smuzhiyun int i, ret, irq_flags;
553*4882a593Smuzhiyun
554*4882a593Smuzhiyun if (!np)
555*4882a593Smuzhiyun return -EINVAL;
556*4882a593Smuzhiyun
557*4882a593Smuzhiyun info = devm_kzalloc(&i2c->dev, sizeof(*info), GFP_KERNEL);
558*4882a593Smuzhiyun if (!info)
559*4882a593Smuzhiyun return -ENOMEM;
560*4882a593Smuzhiyun i2c_set_clientdata(i2c, info);
561*4882a593Smuzhiyun
562*4882a593Smuzhiyun info->dev = &i2c->dev;
563*4882a593Smuzhiyun info->i2c = i2c;
564*4882a593Smuzhiyun info->irq = i2c->irq;
565*4882a593Smuzhiyun info->muic_irqs = sm5502_muic_irqs;
566*4882a593Smuzhiyun info->num_muic_irqs = ARRAY_SIZE(sm5502_muic_irqs);
567*4882a593Smuzhiyun info->reg_data = sm5502_reg_data;
568*4882a593Smuzhiyun info->num_reg_data = ARRAY_SIZE(sm5502_reg_data);
569*4882a593Smuzhiyun
570*4882a593Smuzhiyun mutex_init(&info->mutex);
571*4882a593Smuzhiyun
572*4882a593Smuzhiyun INIT_WORK(&info->irq_work, sm5502_muic_irq_work);
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun info->regmap = devm_regmap_init_i2c(i2c, &sm5502_muic_regmap_config);
575*4882a593Smuzhiyun if (IS_ERR(info->regmap)) {
576*4882a593Smuzhiyun ret = PTR_ERR(info->regmap);
577*4882a593Smuzhiyun dev_err(info->dev, "failed to allocate register map: %d\n",
578*4882a593Smuzhiyun ret);
579*4882a593Smuzhiyun return ret;
580*4882a593Smuzhiyun }
581*4882a593Smuzhiyun
582*4882a593Smuzhiyun /* Support irq domain for SM5502 MUIC device */
583*4882a593Smuzhiyun irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_SHARED;
584*4882a593Smuzhiyun ret = regmap_add_irq_chip(info->regmap, info->irq, irq_flags, 0,
585*4882a593Smuzhiyun &sm5502_muic_irq_chip, &info->irq_data);
586*4882a593Smuzhiyun if (ret != 0) {
587*4882a593Smuzhiyun dev_err(info->dev, "failed to request IRQ %d: %d\n",
588*4882a593Smuzhiyun info->irq, ret);
589*4882a593Smuzhiyun return ret;
590*4882a593Smuzhiyun }
591*4882a593Smuzhiyun
592*4882a593Smuzhiyun for (i = 0; i < info->num_muic_irqs; i++) {
593*4882a593Smuzhiyun struct muic_irq *muic_irq = &info->muic_irqs[i];
594*4882a593Smuzhiyun int virq = 0;
595*4882a593Smuzhiyun
596*4882a593Smuzhiyun virq = regmap_irq_get_virq(info->irq_data, muic_irq->irq);
597*4882a593Smuzhiyun if (virq <= 0)
598*4882a593Smuzhiyun return -EINVAL;
599*4882a593Smuzhiyun muic_irq->virq = virq;
600*4882a593Smuzhiyun
601*4882a593Smuzhiyun ret = devm_request_threaded_irq(info->dev, virq, NULL,
602*4882a593Smuzhiyun sm5502_muic_irq_handler,
603*4882a593Smuzhiyun IRQF_NO_SUSPEND | IRQF_ONESHOT,
604*4882a593Smuzhiyun muic_irq->name, info);
605*4882a593Smuzhiyun if (ret) {
606*4882a593Smuzhiyun dev_err(info->dev,
607*4882a593Smuzhiyun "failed: irq request (IRQ: %d, error :%d)\n",
608*4882a593Smuzhiyun muic_irq->irq, ret);
609*4882a593Smuzhiyun return ret;
610*4882a593Smuzhiyun }
611*4882a593Smuzhiyun }
612*4882a593Smuzhiyun
613*4882a593Smuzhiyun /* Allocate extcon device */
614*4882a593Smuzhiyun info->edev = devm_extcon_dev_allocate(info->dev, sm5502_extcon_cable);
615*4882a593Smuzhiyun if (IS_ERR(info->edev)) {
616*4882a593Smuzhiyun dev_err(info->dev, "failed to allocate memory for extcon\n");
617*4882a593Smuzhiyun return -ENOMEM;
618*4882a593Smuzhiyun }
619*4882a593Smuzhiyun
620*4882a593Smuzhiyun /* Register extcon device */
621*4882a593Smuzhiyun ret = devm_extcon_dev_register(info->dev, info->edev);
622*4882a593Smuzhiyun if (ret) {
623*4882a593Smuzhiyun dev_err(info->dev, "failed to register extcon device\n");
624*4882a593Smuzhiyun return ret;
625*4882a593Smuzhiyun }
626*4882a593Smuzhiyun
627*4882a593Smuzhiyun /*
628*4882a593Smuzhiyun * Detect accessory after completing the initialization of platform
629*4882a593Smuzhiyun *
630*4882a593Smuzhiyun * - Use delayed workqueue to detect cable state and then
631*4882a593Smuzhiyun * notify cable state to notifiee/platform through uevent.
632*4882a593Smuzhiyun * After completing the booting of platform, the extcon provider
633*4882a593Smuzhiyun * driver should notify cable state to upper layer.
634*4882a593Smuzhiyun */
635*4882a593Smuzhiyun INIT_DELAYED_WORK(&info->wq_detcable, sm5502_muic_detect_cable_wq);
636*4882a593Smuzhiyun queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
637*4882a593Smuzhiyun msecs_to_jiffies(DELAY_MS_DEFAULT));
638*4882a593Smuzhiyun
639*4882a593Smuzhiyun /* Initialize SM5502 device and print vendor id and version id */
640*4882a593Smuzhiyun sm5502_init_dev_type(info);
641*4882a593Smuzhiyun
642*4882a593Smuzhiyun return 0;
643*4882a593Smuzhiyun }
644*4882a593Smuzhiyun
sm5502_muic_i2c_remove(struct i2c_client * i2c)645*4882a593Smuzhiyun static int sm5502_muic_i2c_remove(struct i2c_client *i2c)
646*4882a593Smuzhiyun {
647*4882a593Smuzhiyun struct sm5502_muic_info *info = i2c_get_clientdata(i2c);
648*4882a593Smuzhiyun
649*4882a593Smuzhiyun regmap_del_irq_chip(info->irq, info->irq_data);
650*4882a593Smuzhiyun
651*4882a593Smuzhiyun return 0;
652*4882a593Smuzhiyun }
653*4882a593Smuzhiyun
654*4882a593Smuzhiyun static const struct of_device_id sm5502_dt_match[] = {
655*4882a593Smuzhiyun { .compatible = "siliconmitus,sm5502-muic" },
656*4882a593Smuzhiyun { },
657*4882a593Smuzhiyun };
658*4882a593Smuzhiyun MODULE_DEVICE_TABLE(of, sm5502_dt_match);
659*4882a593Smuzhiyun
660*4882a593Smuzhiyun #ifdef CONFIG_PM_SLEEP
sm5502_muic_suspend(struct device * dev)661*4882a593Smuzhiyun static int sm5502_muic_suspend(struct device *dev)
662*4882a593Smuzhiyun {
663*4882a593Smuzhiyun struct i2c_client *i2c = to_i2c_client(dev);
664*4882a593Smuzhiyun struct sm5502_muic_info *info = i2c_get_clientdata(i2c);
665*4882a593Smuzhiyun
666*4882a593Smuzhiyun enable_irq_wake(info->irq);
667*4882a593Smuzhiyun
668*4882a593Smuzhiyun return 0;
669*4882a593Smuzhiyun }
670*4882a593Smuzhiyun
sm5502_muic_resume(struct device * dev)671*4882a593Smuzhiyun static int sm5502_muic_resume(struct device *dev)
672*4882a593Smuzhiyun {
673*4882a593Smuzhiyun struct i2c_client *i2c = to_i2c_client(dev);
674*4882a593Smuzhiyun struct sm5502_muic_info *info = i2c_get_clientdata(i2c);
675*4882a593Smuzhiyun
676*4882a593Smuzhiyun disable_irq_wake(info->irq);
677*4882a593Smuzhiyun
678*4882a593Smuzhiyun return 0;
679*4882a593Smuzhiyun }
680*4882a593Smuzhiyun #endif
681*4882a593Smuzhiyun
682*4882a593Smuzhiyun static SIMPLE_DEV_PM_OPS(sm5502_muic_pm_ops,
683*4882a593Smuzhiyun sm5502_muic_suspend, sm5502_muic_resume);
684*4882a593Smuzhiyun
685*4882a593Smuzhiyun static const struct i2c_device_id sm5502_i2c_id[] = {
686*4882a593Smuzhiyun { "sm5502", TYPE_SM5502 },
687*4882a593Smuzhiyun { }
688*4882a593Smuzhiyun };
689*4882a593Smuzhiyun MODULE_DEVICE_TABLE(i2c, sm5502_i2c_id);
690*4882a593Smuzhiyun
691*4882a593Smuzhiyun static struct i2c_driver sm5502_muic_i2c_driver = {
692*4882a593Smuzhiyun .driver = {
693*4882a593Smuzhiyun .name = "sm5502",
694*4882a593Smuzhiyun .pm = &sm5502_muic_pm_ops,
695*4882a593Smuzhiyun .of_match_table = sm5502_dt_match,
696*4882a593Smuzhiyun },
697*4882a593Smuzhiyun .probe = sm5022_muic_i2c_probe,
698*4882a593Smuzhiyun .remove = sm5502_muic_i2c_remove,
699*4882a593Smuzhiyun .id_table = sm5502_i2c_id,
700*4882a593Smuzhiyun };
701*4882a593Smuzhiyun
sm5502_muic_i2c_init(void)702*4882a593Smuzhiyun static int __init sm5502_muic_i2c_init(void)
703*4882a593Smuzhiyun {
704*4882a593Smuzhiyun return i2c_add_driver(&sm5502_muic_i2c_driver);
705*4882a593Smuzhiyun }
706*4882a593Smuzhiyun subsys_initcall(sm5502_muic_i2c_init);
707*4882a593Smuzhiyun
708*4882a593Smuzhiyun MODULE_DESCRIPTION("Silicon Mitus SM5502 Extcon driver");
709*4882a593Smuzhiyun MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
710*4882a593Smuzhiyun MODULE_LICENSE("GPL");
711