diff options
author | Chanwoo Choi <cw00.choi@samsung.com> | 2014-05-22 01:06:33 -0400 |
---|---|---|
committer | Chanwoo Choi <cw00.choi@samsung.com> | 2014-07-22 21:22:30 -0400 |
commit | 914b881f9452fd615cc597b434fd8c0e12a7dae2 (patch) | |
tree | 00ca6bc5c90cca061921ef72b60847db3c38e5a9 | |
parent | 17271f608bf818a13b2c235d45258311308d5b03 (diff) |
extcon: sm5502: Add support new SM5502 extcon device driver
This patch add new SM5502 MUIC(Micro-USB Interface Controller) device by using
EXTCON subsystem. The extcon-sm5502 driver is capable of identifying the type
of the external power source and attached accessory. An external power sources,
such as Deticated Charger or a standard USB port, are able to charge the battery
in the smart phone via the connector.
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
-rw-r--r-- | drivers/extcon/Kconfig | 10 | ||||
-rw-r--r-- | drivers/extcon/Makefile | 1 | ||||
-rw-r--r-- | drivers/extcon/extcon-sm5502.c | 620 | ||||
-rw-r--r-- | include/linux/extcon/sm5502.h | 264 |
4 files changed, 895 insertions, 0 deletions
diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index 9125eba6b3d6..6f2f4727de2c 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig | |||
@@ -70,4 +70,14 @@ config EXTCON_PALMAS | |||
70 | Say Y here to enable support for USB peripheral and USB host | 70 | Say Y here to enable support for USB peripheral and USB host |
71 | detection by palmas usb. | 71 | detection by palmas usb. |
72 | 72 | ||
73 | config EXTCON_SM5502 | ||
74 | tristate "SM5502 EXTCON support" | ||
75 | select IRQ_DOMAIN | ||
76 | select REGMAP_I2C | ||
77 | select REGMAP_IRQ | ||
78 | help | ||
79 | If you say yes here you get support for the MUIC device of | ||
80 | Silicon Mitus SM5502. The SM5502 is a USB port accessory | ||
81 | detector and switch. | ||
82 | |||
73 | endif # MULTISTATE_SWITCH | 83 | endif # MULTISTATE_SWITCH |
diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile index e48abc6d230f..b38546eb522a 100644 --- a/drivers/extcon/Makefile +++ b/drivers/extcon/Makefile | |||
@@ -10,3 +10,4 @@ obj-$(CONFIG_EXTCON_MAX14577) += extcon-max14577.o | |||
10 | obj-$(CONFIG_EXTCON_MAX77693) += extcon-max77693.o | 10 | obj-$(CONFIG_EXTCON_MAX77693) += extcon-max77693.o |
11 | obj-$(CONFIG_EXTCON_MAX8997) += extcon-max8997.o | 11 | obj-$(CONFIG_EXTCON_MAX8997) += extcon-max8997.o |
12 | obj-$(CONFIG_EXTCON_PALMAS) += extcon-palmas.o | 12 | obj-$(CONFIG_EXTCON_PALMAS) += extcon-palmas.o |
13 | obj-$(CONFIG_EXTCON_SM5502) += extcon-sm5502.o | ||
diff --git a/drivers/extcon/extcon-sm5502.c b/drivers/extcon/extcon-sm5502.c new file mode 100644 index 000000000000..9f318c222b89 --- /dev/null +++ b/drivers/extcon/extcon-sm5502.c | |||
@@ -0,0 +1,620 @@ | |||
1 | /* | ||
2 | * extcon-sm5502.c - Silicon Mitus SM5502 extcon drvier to support USB switches | ||
3 | * | ||
4 | * Copyright (c) 2014 Samsung Electronics Co., Ltd | ||
5 | * Author: Chanwoo Choi <cw00.choi@samsung.com> | ||
6 | * | ||
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. | ||
11 | * | ||
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. | ||
16 | */ | ||
17 | |||
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> | ||
30 | |||
31 | struct muic_irq { | ||
32 | unsigned int irq; | ||
33 | const char *name; | ||
34 | unsigned int virq; | ||
35 | }; | ||
36 | |||
37 | struct reg_data { | ||
38 | u8 reg; | ||
39 | unsigned int val; | ||
40 | bool invert; | ||
41 | }; | ||
42 | |||
43 | struct sm5502_muic_info { | ||
44 | struct device *dev; | ||
45 | struct extcon_dev *edev; | ||
46 | |||
47 | struct i2c_client *i2c; | ||
48 | struct regmap *regmap; | ||
49 | |||
50 | struct regmap_irq_chip_data *irq_data; | ||
51 | struct muic_irq *muic_irqs; | ||
52 | unsigned int num_muic_irqs; | ||
53 | int irq; | ||
54 | bool irq_attach; | ||
55 | bool irq_detach; | ||
56 | struct work_struct irq_work; | ||
57 | |||
58 | struct reg_data *reg_data; | ||
59 | unsigned int num_reg_data; | ||
60 | |||
61 | struct mutex mutex; | ||
62 | }; | ||
63 | |||
64 | /* Default value of SM5502 register to bring up MUIC device. */ | ||
65 | static struct reg_data sm5502_reg_data[] = { | ||
66 | { | ||
67 | .reg = SM5502_REG_CONTROL, | ||
68 | .val = SM5502_REG_CONTROL_MASK_INT_MASK, | ||
69 | .invert = false, | ||
70 | }, { | ||
71 | .reg = SM5502_REG_INTMASK1, | ||
72 | .val = SM5502_REG_INTM1_KP_MASK | ||
73 | | SM5502_REG_INTM1_LKP_MASK | ||
74 | | SM5502_REG_INTM1_LKR_MASK, | ||
75 | .invert = true, | ||
76 | }, { | ||
77 | .reg = SM5502_REG_INTMASK2, | ||
78 | .val = SM5502_REG_INTM2_VBUS_DET_MASK | ||
79 | | SM5502_REG_INTM2_REV_ACCE_MASK | ||
80 | | SM5502_REG_INTM2_ADC_CHG_MASK | ||
81 | | SM5502_REG_INTM2_STUCK_KEY_MASK | ||
82 | | SM5502_REG_INTM2_STUCK_KEY_RCV_MASK | ||
83 | | SM5502_REG_INTM2_MHL_MASK, | ||
84 | .invert = true, | ||
85 | }, | ||
86 | { } | ||
87 | }; | ||
88 | |||
89 | /* List of detectable cables */ | ||
90 | enum { | ||
91 | EXTCON_CABLE_USB = 0, | ||
92 | EXTCON_CABLE_USB_HOST, | ||
93 | EXTCON_CABLE_TA, | ||
94 | |||
95 | EXTCON_CABLE_END, | ||
96 | }; | ||
97 | |||
98 | static const char *sm5502_extcon_cable[] = { | ||
99 | [EXTCON_CABLE_USB] = "USB", | ||
100 | [EXTCON_CABLE_USB_HOST] = "USB-Host", | ||
101 | [EXTCON_CABLE_TA] = "TA", | ||
102 | NULL, | ||
103 | }; | ||
104 | |||
105 | /* Define supported accessory type */ | ||
106 | enum sm5502_muic_acc_type { | ||
107 | SM5502_MUIC_ADC_GROUND = 0x0, | ||
108 | SM5502_MUIC_ADC_SEND_END_BUTTON, | ||
109 | SM5502_MUIC_ADC_REMOTE_S1_BUTTON, | ||
110 | SM5502_MUIC_ADC_REMOTE_S2_BUTTON, | ||
111 | SM5502_MUIC_ADC_REMOTE_S3_BUTTON, | ||
112 | SM5502_MUIC_ADC_REMOTE_S4_BUTTON, | ||
113 | SM5502_MUIC_ADC_REMOTE_S5_BUTTON, | ||
114 | SM5502_MUIC_ADC_REMOTE_S6_BUTTON, | ||
115 | SM5502_MUIC_ADC_REMOTE_S7_BUTTON, | ||
116 | SM5502_MUIC_ADC_REMOTE_S8_BUTTON, | ||
117 | SM5502_MUIC_ADC_REMOTE_S9_BUTTON, | ||
118 | SM5502_MUIC_ADC_REMOTE_S10_BUTTON, | ||
119 | SM5502_MUIC_ADC_REMOTE_S11_BUTTON, | ||
120 | SM5502_MUIC_ADC_REMOTE_S12_BUTTON, | ||
121 | SM5502_MUIC_ADC_RESERVED_ACC_1, | ||
122 | SM5502_MUIC_ADC_RESERVED_ACC_2, | ||
123 | SM5502_MUIC_ADC_RESERVED_ACC_3, | ||
124 | SM5502_MUIC_ADC_RESERVED_ACC_4, | ||
125 | SM5502_MUIC_ADC_RESERVED_ACC_5, | ||
126 | SM5502_MUIC_ADC_AUDIO_TYPE2, | ||
127 | SM5502_MUIC_ADC_PHONE_POWERED_DEV, | ||
128 | SM5502_MUIC_ADC_TTY_CONVERTER, | ||
129 | SM5502_MUIC_ADC_UART_CABLE, | ||
130 | SM5502_MUIC_ADC_TYPE1_CHARGER, | ||
131 | SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB, | ||
132 | SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB, | ||
133 | SM5502_MUIC_ADC_AUDIO_VIDEO_CABLE, | ||
134 | SM5502_MUIC_ADC_TYPE2_CHARGER, | ||
135 | SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART, | ||
136 | SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART, | ||
137 | SM5502_MUIC_ADC_AUDIO_TYPE1, | ||
138 | SM5502_MUIC_ADC_OPEN = 0x1f, | ||
139 | |||
140 | /* The below accessories have same ADC value (0x1f or 0x1e). | ||
141 | So, Device type1 is used to separate specific accessory. */ | ||
142 | /* |---------|--ADC| */ | ||
143 | /* | [7:5]|[4:0]| */ | ||
144 | SM5502_MUIC_ADC_AUDIO_TYPE1_FULL_REMOTE = 0x3e, /* | 001|11110| */ | ||
145 | SM5502_MUIC_ADC_AUDIO_TYPE1_SEND_END = 0x5e, /* | 010|11110| */ | ||
146 | /* |Dev Type1|--ADC| */ | ||
147 | SM5502_MUIC_ADC_OPEN_USB = 0x5f, /* | 010|11111| */ | ||
148 | SM5502_MUIC_ADC_OPEN_TA = 0xdf, /* | 110|11111| */ | ||
149 | SM5502_MUIC_ADC_OPEN_USB_OTG = 0xff, /* | 111|11111| */ | ||
150 | }; | ||
151 | |||
152 | /* List of supported interrupt for SM5502 */ | ||
153 | static struct muic_irq sm5502_muic_irqs[] = { | ||
154 | { SM5502_IRQ_INT1_ATTACH, "muic-attach" }, | ||
155 | { SM5502_IRQ_INT1_DETACH, "muic-detach" }, | ||
156 | { SM5502_IRQ_INT1_KP, "muic-kp" }, | ||
157 | { SM5502_IRQ_INT1_LKP, "muic-lkp" }, | ||
158 | { SM5502_IRQ_INT1_LKR, "muic-lkr" }, | ||
159 | { SM5502_IRQ_INT1_OVP_EVENT, "muic-ovp-event" }, | ||
160 | { SM5502_IRQ_INT1_OCP_EVENT, "muic-ocp-event" }, | ||
161 | { SM5502_IRQ_INT1_OVP_OCP_DIS, "muic-ovp-ocp-dis" }, | ||
162 | { SM5502_IRQ_INT2_VBUS_DET, "muic-vbus-det" }, | ||
163 | { SM5502_IRQ_INT2_REV_ACCE, "muic-rev-acce" }, | ||
164 | { SM5502_IRQ_INT2_ADC_CHG, "muic-adc-chg" }, | ||
165 | { SM5502_IRQ_INT2_STUCK_KEY, "muic-stuck-key" }, | ||
166 | { SM5502_IRQ_INT2_STUCK_KEY_RCV, "muic-stuck-key-rcv" }, | ||
167 | { SM5502_IRQ_INT2_MHL, "muic-mhl" }, | ||
168 | }; | ||
169 | |||
170 | /* Define interrupt list of SM5502 to register regmap_irq */ | ||
171 | static const struct regmap_irq sm5502_irqs[] = { | ||
172 | /* INT1 interrupts */ | ||
173 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_ATTACH_MASK, }, | ||
174 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_DETACH_MASK, }, | ||
175 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_KP_MASK, }, | ||
176 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_LKP_MASK, }, | ||
177 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_LKR_MASK, }, | ||
178 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_OVP_EVENT_MASK, }, | ||
179 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_OCP_EVENT_MASK, }, | ||
180 | { .reg_offset = 0, .mask = SM5502_IRQ_INT1_OVP_OCP_DIS_MASK, }, | ||
181 | |||
182 | /* INT2 interrupts */ | ||
183 | { .reg_offset = 1, .mask = SM5502_IRQ_INT2_VBUS_DET_MASK,}, | ||
184 | { .reg_offset = 1, .mask = SM5502_IRQ_INT2_REV_ACCE_MASK, }, | ||
185 | { .reg_offset = 1, .mask = SM5502_IRQ_INT2_ADC_CHG_MASK, }, | ||
186 | { .reg_offset = 1, .mask = SM5502_IRQ_INT2_STUCK_KEY_MASK, }, | ||
187 | { .reg_offset = 1, .mask = SM5502_IRQ_INT2_STUCK_KEY_RCV_MASK, }, | ||
188 | { .reg_offset = 1, .mask = SM5502_IRQ_INT2_MHL_MASK, }, | ||
189 | }; | ||
190 | |||
191 | static const struct regmap_irq_chip sm5502_muic_irq_chip = { | ||
192 | .name = "sm5502", | ||
193 | .status_base = SM5502_REG_INT1, | ||
194 | .mask_base = SM5502_REG_INTMASK1, | ||
195 | .mask_invert = false, | ||
196 | .num_regs = 2, | ||
197 | .irqs = sm5502_irqs, | ||
198 | .num_irqs = ARRAY_SIZE(sm5502_irqs), | ||
199 | }; | ||
200 | |||
201 | /* Define regmap configuration of SM5502 for I2C communication */ | ||
202 | static bool sm5502_muic_volatile_reg(struct device *dev, unsigned int reg) | ||
203 | { | ||
204 | switch (reg) { | ||
205 | case SM5502_REG_INTMASK1: | ||
206 | case SM5502_REG_INTMASK2: | ||
207 | return true; | ||
208 | default: | ||
209 | break; | ||
210 | } | ||
211 | return false; | ||
212 | } | ||
213 | |||
214 | static const struct regmap_config sm5502_muic_regmap_config = { | ||
215 | .reg_bits = 8, | ||
216 | .val_bits = 8, | ||
217 | .volatile_reg = sm5502_muic_volatile_reg, | ||
218 | .max_register = SM5502_REG_END, | ||
219 | }; | ||
220 | |||
221 | /* Return cable type of attached or detached accessories */ | ||
222 | static unsigned int sm5502_muic_get_cable_type(struct sm5502_muic_info *info) | ||
223 | { | ||
224 | unsigned int cable_type = -1, adc, dev_type1; | ||
225 | int ret; | ||
226 | |||
227 | /* Read ADC value according to external cable or button */ | ||
228 | ret = regmap_read(info->regmap, SM5502_REG_ADC, &adc); | ||
229 | if (ret) { | ||
230 | dev_err(info->dev, "failed to read ADC register\n"); | ||
231 | return ret; | ||
232 | } | ||
233 | |||
234 | /* | ||
235 | * If ADC is SM5502_MUIC_ADC_GROUND(0x0), external cable hasn't | ||
236 | * connected with to MUIC device. | ||
237 | */ | ||
238 | cable_type &= SM5502_REG_ADC_MASK; | ||
239 | if (cable_type == SM5502_MUIC_ADC_GROUND) | ||
240 | return SM5502_MUIC_ADC_GROUND; | ||
241 | |||
242 | switch (cable_type) { | ||
243 | case SM5502_MUIC_ADC_GROUND: | ||
244 | case SM5502_MUIC_ADC_SEND_END_BUTTON: | ||
245 | case SM5502_MUIC_ADC_REMOTE_S1_BUTTON: | ||
246 | case SM5502_MUIC_ADC_REMOTE_S2_BUTTON: | ||
247 | case SM5502_MUIC_ADC_REMOTE_S3_BUTTON: | ||
248 | case SM5502_MUIC_ADC_REMOTE_S4_BUTTON: | ||
249 | case SM5502_MUIC_ADC_REMOTE_S5_BUTTON: | ||
250 | case SM5502_MUIC_ADC_REMOTE_S6_BUTTON: | ||
251 | case SM5502_MUIC_ADC_REMOTE_S7_BUTTON: | ||
252 | case SM5502_MUIC_ADC_REMOTE_S8_BUTTON: | ||
253 | case SM5502_MUIC_ADC_REMOTE_S9_BUTTON: | ||
254 | case SM5502_MUIC_ADC_REMOTE_S10_BUTTON: | ||
255 | case SM5502_MUIC_ADC_REMOTE_S11_BUTTON: | ||
256 | case SM5502_MUIC_ADC_REMOTE_S12_BUTTON: | ||
257 | case SM5502_MUIC_ADC_RESERVED_ACC_1: | ||
258 | case SM5502_MUIC_ADC_RESERVED_ACC_2: | ||
259 | case SM5502_MUIC_ADC_RESERVED_ACC_3: | ||
260 | case SM5502_MUIC_ADC_RESERVED_ACC_4: | ||
261 | case SM5502_MUIC_ADC_RESERVED_ACC_5: | ||
262 | case SM5502_MUIC_ADC_AUDIO_TYPE2: | ||
263 | case SM5502_MUIC_ADC_PHONE_POWERED_DEV: | ||
264 | case SM5502_MUIC_ADC_TTY_CONVERTER: | ||
265 | case SM5502_MUIC_ADC_UART_CABLE: | ||
266 | case SM5502_MUIC_ADC_TYPE1_CHARGER: | ||
267 | case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB: | ||
268 | case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB: | ||
269 | case SM5502_MUIC_ADC_AUDIO_VIDEO_CABLE: | ||
270 | case SM5502_MUIC_ADC_TYPE2_CHARGER: | ||
271 | case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART: | ||
272 | case SM5502_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART: | ||
273 | break; | ||
274 | case SM5502_MUIC_ADC_AUDIO_TYPE1: | ||
275 | /* | ||
276 | * Check whether cable type is | ||
277 | * SM5502_MUIC_ADC_AUDIO_TYPE1_FULL_REMOTE | ||
278 | * or SM5502_MUIC_ADC_AUDIO_TYPE1_SEND_END | ||
279 | * by using Button event. | ||
280 | */ | ||
281 | break; | ||
282 | case SM5502_MUIC_ADC_OPEN: | ||
283 | ret = regmap_read(info->regmap, SM5502_REG_DEV_TYPE1, | ||
284 | &dev_type1); | ||
285 | if (ret) { | ||
286 | dev_err(info->dev, "failed to read DEV_TYPE1 reg\n"); | ||
287 | return ret; | ||
288 | } | ||
289 | |||
290 | switch (dev_type1) { | ||
291 | case SM5502_REG_DEV_TYPE1_USB_SDP_MASK: | ||
292 | cable_type = SM5502_MUIC_ADC_OPEN_USB; | ||
293 | break; | ||
294 | case SM5502_REG_DEV_TYPE1_DEDICATED_CHG_MASK: | ||
295 | cable_type = SM5502_MUIC_ADC_OPEN_TA; | ||
296 | break; | ||
297 | case SM5502_REG_DEV_TYPE1_USB_OTG_MASK: | ||
298 | cable_type = SM5502_MUIC_ADC_OPEN_USB_OTG; | ||
299 | break; | ||
300 | default: | ||
301 | dev_dbg(info->dev, | ||
302 | "cannot identify the cable type: adc(0x%x) " | ||
303 | "dev_type1(0x%x)\n", adc, dev_type1); | ||
304 | return -EINVAL; | ||
305 | }; | ||
306 | break; | ||
307 | default: | ||
308 | dev_err(info->dev, | ||
309 | "failed to identify the cable type: adc(0x%x)\n", adc); | ||
310 | return -EINVAL; | ||
311 | }; | ||
312 | |||
313 | return cable_type; | ||
314 | } | ||
315 | |||
316 | static int sm5502_muic_cable_handler(struct sm5502_muic_info *info, | ||
317 | bool attached) | ||
318 | { | ||
319 | static unsigned int prev_cable_type = SM5502_MUIC_ADC_GROUND; | ||
320 | const char **cable_names = info->edev->supported_cable; | ||
321 | unsigned int cable_type = SM5502_MUIC_ADC_GROUND; | ||
322 | unsigned int idx = 0; | ||
323 | |||
324 | if (!cable_names) | ||
325 | return 0; | ||
326 | |||
327 | /* Get the type of attached or detached cable */ | ||
328 | if (attached) | ||
329 | cable_type = sm5502_muic_get_cable_type(info); | ||
330 | else if (!attached) | ||
331 | cable_type = prev_cable_type; | ||
332 | prev_cable_type = cable_type; | ||
333 | |||
334 | switch (cable_type) { | ||
335 | case SM5502_MUIC_ADC_OPEN_USB: | ||
336 | idx = EXTCON_CABLE_USB; | ||
337 | break; | ||
338 | case SM5502_MUIC_ADC_OPEN_TA: | ||
339 | idx = EXTCON_CABLE_TA; | ||
340 | break; | ||
341 | case SM5502_MUIC_ADC_OPEN_USB_OTG: | ||
342 | idx = EXTCON_CABLE_USB_HOST; | ||
343 | break; | ||
344 | default: | ||
345 | dev_dbg(info->dev, | ||
346 | "cannot handle this cable_type (0x%x)\n", cable_type); | ||
347 | return 0; | ||
348 | }; | ||
349 | |||
350 | extcon_set_cable_state(info->edev, cable_names[idx], attached); | ||
351 | |||
352 | return 0; | ||
353 | } | ||
354 | |||
355 | static void sm5502_muic_irq_work(struct work_struct *work) | ||
356 | { | ||
357 | struct sm5502_muic_info *info = container_of(work, | ||
358 | struct sm5502_muic_info, irq_work); | ||
359 | int ret = 0; | ||
360 | |||
361 | if (!info->edev) | ||
362 | return; | ||
363 | |||
364 | mutex_lock(&info->mutex); | ||
365 | |||
366 | /* Detect attached or detached cables */ | ||
367 | if (info->irq_attach) { | ||
368 | ret = sm5502_muic_cable_handler(info, true); | ||
369 | info->irq_attach = false; | ||
370 | } | ||
371 | if (info->irq_detach) { | ||
372 | ret = sm5502_muic_cable_handler(info, false); | ||
373 | info->irq_detach = false; | ||
374 | } | ||
375 | |||
376 | if (ret < 0) | ||
377 | dev_err(info->dev, "failed to handle MUIC interrupt\n"); | ||
378 | |||
379 | mutex_unlock(&info->mutex); | ||
380 | |||
381 | return; | ||
382 | } | ||
383 | |||
384 | /* | ||
385 | * Sets irq_attach or irq_detach in sm5502_muic_info and returns 0. | ||
386 | * Returns -ESRCH if irq_type does not match registered IRQ for this dev type. | ||
387 | */ | ||
388 | static int sm5502_parse_irq(struct sm5502_muic_info *info, int irq_type) | ||
389 | { | ||
390 | switch (irq_type) { | ||
391 | case SM5502_IRQ_INT1_ATTACH: | ||
392 | info->irq_attach = true; | ||
393 | break; | ||
394 | case SM5502_IRQ_INT1_DETACH: | ||
395 | info->irq_detach = true; | ||
396 | break; | ||
397 | case SM5502_IRQ_INT1_KP: | ||
398 | case SM5502_IRQ_INT1_LKP: | ||
399 | case SM5502_IRQ_INT1_LKR: | ||
400 | case SM5502_IRQ_INT1_OVP_EVENT: | ||
401 | case SM5502_IRQ_INT1_OCP_EVENT: | ||
402 | case SM5502_IRQ_INT1_OVP_OCP_DIS: | ||
403 | case SM5502_IRQ_INT2_VBUS_DET: | ||
404 | case SM5502_IRQ_INT2_REV_ACCE: | ||
405 | case SM5502_IRQ_INT2_ADC_CHG: | ||
406 | case SM5502_IRQ_INT2_STUCK_KEY: | ||
407 | case SM5502_IRQ_INT2_STUCK_KEY_RCV: | ||
408 | case SM5502_IRQ_INT2_MHL: | ||
409 | default: | ||
410 | break; | ||
411 | } | ||
412 | |||
413 | return 0; | ||
414 | } | ||
415 | |||
416 | static irqreturn_t sm5502_muic_irq_handler(int irq, void *data) | ||
417 | { | ||
418 | struct sm5502_muic_info *info = data; | ||
419 | int i, irq_type = -1, ret; | ||
420 | |||
421 | for (i = 0; i < info->num_muic_irqs; i++) | ||
422 | if (irq == info->muic_irqs[i].virq) | ||
423 | irq_type = info->muic_irqs[i].irq; | ||
424 | |||
425 | ret = sm5502_parse_irq(info, irq_type); | ||
426 | if (ret < 0) { | ||
427 | dev_warn(info->dev, "cannot handle is interrupt:%d\n", | ||
428 | irq_type); | ||
429 | return IRQ_HANDLED; | ||
430 | } | ||
431 | schedule_work(&info->irq_work); | ||
432 | |||
433 | return IRQ_HANDLED; | ||
434 | } | ||
435 | |||
436 | static void sm5502_init_dev_type(struct sm5502_muic_info *info) | ||
437 | { | ||
438 | unsigned int reg_data, vendor_id, version_id; | ||
439 | int i, ret; | ||
440 | |||
441 | /* To test I2C, Print version_id and vendor_id of SM5502 */ | ||
442 | ret = regmap_read(info->regmap, SM5502_REG_DEVICE_ID, ®_data); | ||
443 | if (ret) { | ||
444 | dev_err(info->dev, | ||
445 | "failed to read DEVICE_ID register: %d\n", ret); | ||
446 | return; | ||
447 | } | ||
448 | |||
449 | vendor_id = ((reg_data & SM5502_REG_DEVICE_ID_VENDOR_MASK) >> | ||
450 | SM5502_REG_DEVICE_ID_VENDOR_SHIFT); | ||
451 | version_id = ((reg_data & SM5502_REG_DEVICE_ID_VERSION_MASK) >> | ||
452 | SM5502_REG_DEVICE_ID_VERSION_SHIFT); | ||
453 | |||
454 | dev_info(info->dev, "Device type: version: 0x%x, vendor: 0x%x\n", | ||
455 | version_id, vendor_id); | ||
456 | |||
457 | /* Initiazle the register of SM5502 device to bring-up */ | ||
458 | for (i = 0; i < info->num_reg_data; i++) { | ||
459 | unsigned int val = 0; | ||
460 | |||
461 | if (!info->reg_data[i].invert) | ||
462 | val |= ~info->reg_data[i].val; | ||
463 | else | ||
464 | val = info->reg_data[i].val; | ||
465 | regmap_write(info->regmap, info->reg_data[i].reg, val); | ||
466 | } | ||
467 | } | ||
468 | |||
469 | static int sm5022_muic_i2c_probe(struct i2c_client *i2c, | ||
470 | const struct i2c_device_id *id) | ||
471 | { | ||
472 | struct device_node *np = i2c->dev.of_node; | ||
473 | struct sm5502_muic_info *info; | ||
474 | int i, ret, irq_flags; | ||
475 | |||
476 | if (!np) | ||
477 | return -EINVAL; | ||
478 | |||
479 | info = devm_kzalloc(&i2c->dev, sizeof(*info), GFP_KERNEL); | ||
480 | if (!info) | ||
481 | return -ENOMEM; | ||
482 | i2c_set_clientdata(i2c, info); | ||
483 | |||
484 | info->dev = &i2c->dev; | ||
485 | info->i2c = i2c; | ||
486 | info->irq = i2c->irq; | ||
487 | info->muic_irqs = sm5502_muic_irqs; | ||
488 | info->num_muic_irqs = ARRAY_SIZE(sm5502_muic_irqs); | ||
489 | info->reg_data = sm5502_reg_data; | ||
490 | info->num_reg_data = ARRAY_SIZE(sm5502_reg_data); | ||
491 | |||
492 | mutex_init(&info->mutex); | ||
493 | |||
494 | INIT_WORK(&info->irq_work, sm5502_muic_irq_work); | ||
495 | |||
496 | info->regmap = devm_regmap_init_i2c(i2c, &sm5502_muic_regmap_config); | ||
497 | if (IS_ERR(info->regmap)) { | ||
498 | ret = PTR_ERR(info->regmap); | ||
499 | dev_err(info->dev, "failed to allocate register map: %d\n", | ||
500 | ret); | ||
501 | return ret; | ||
502 | } | ||
503 | |||
504 | /* Support irq domain for SM5502 MUIC device */ | ||
505 | irq_flags = IRQF_TRIGGER_FALLING | IRQF_ONESHOT | IRQF_SHARED; | ||
506 | ret = regmap_add_irq_chip(info->regmap, info->irq, irq_flags, 0, | ||
507 | &sm5502_muic_irq_chip, &info->irq_data); | ||
508 | if (ret != 0) { | ||
509 | dev_err(info->dev, "failed to request IRQ %d: %d\n", | ||
510 | info->irq, ret); | ||
511 | return ret; | ||
512 | } | ||
513 | |||
514 | for (i = 0; i < info->num_muic_irqs; i++) { | ||
515 | struct muic_irq *muic_irq = &info->muic_irqs[i]; | ||
516 | unsigned int virq = 0; | ||
517 | |||
518 | virq = regmap_irq_get_virq(info->irq_data, muic_irq->irq); | ||
519 | if (virq <= 0) | ||
520 | return -EINVAL; | ||
521 | muic_irq->virq = virq; | ||
522 | |||
523 | ret = devm_request_threaded_irq(info->dev, virq, NULL, | ||
524 | sm5502_muic_irq_handler, | ||
525 | IRQF_NO_SUSPEND, | ||
526 | muic_irq->name, info); | ||
527 | if (ret) { | ||
528 | dev_err(info->dev, "failed: irq request (IRQ: %d," | ||
529 | " error :%d)\n", muic_irq->irq, ret); | ||
530 | return ret; | ||
531 | } | ||
532 | } | ||
533 | |||
534 | /* Allocate extcon device */ | ||
535 | info->edev = devm_extcon_dev_allocate(info->dev, sm5502_extcon_cable); | ||
536 | if (IS_ERR(info->edev)) { | ||
537 | dev_err(info->dev, "failed to allocate memory for extcon\n"); | ||
538 | return -ENOMEM; | ||
539 | } | ||
540 | info->edev->name = np->name; | ||
541 | |||
542 | /* Register extcon device */ | ||
543 | ret = devm_extcon_dev_register(info->dev, info->edev); | ||
544 | if (ret) { | ||
545 | dev_err(info->dev, "failed to register extcon device\n"); | ||
546 | return ret; | ||
547 | } | ||
548 | |||
549 | /* Initialize SM5502 device and print vendor id and version id */ | ||
550 | sm5502_init_dev_type(info); | ||
551 | |||
552 | return 0; | ||
553 | } | ||
554 | |||
555 | static int sm5502_muic_i2c_remove(struct i2c_client *i2c) | ||
556 | { | ||
557 | struct sm5502_muic_info *info = i2c_get_clientdata(i2c); | ||
558 | |||
559 | regmap_del_irq_chip(info->irq, info->irq_data); | ||
560 | |||
561 | return 0; | ||
562 | } | ||
563 | |||
564 | static struct of_device_id sm5502_dt_match[] = { | ||
565 | { .compatible = "siliconmitus,sm5502-muic" }, | ||
566 | { }, | ||
567 | }; | ||
568 | |||
569 | #ifdef CONFIG_PM_SLEEP | ||
570 | static int sm5502_muic_suspend(struct device *dev) | ||
571 | { | ||
572 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); | ||
573 | struct sm5502_muic_info *info = i2c_get_clientdata(i2c); | ||
574 | |||
575 | enable_irq_wake(info->irq); | ||
576 | |||
577 | return 0; | ||
578 | } | ||
579 | |||
580 | static int sm5502_muic_resume(struct device *dev) | ||
581 | { | ||
582 | struct i2c_client *i2c = container_of(dev, struct i2c_client, dev); | ||
583 | struct sm5502_muic_info *info = i2c_get_clientdata(i2c); | ||
584 | |||
585 | disable_irq_wake(info->irq); | ||
586 | |||
587 | return 0; | ||
588 | } | ||
589 | #endif | ||
590 | |||
591 | static SIMPLE_DEV_PM_OPS(sm5502_muic_pm_ops, | ||
592 | sm5502_muic_suspend, sm5502_muic_resume); | ||
593 | |||
594 | static const struct i2c_device_id sm5502_i2c_id[] = { | ||
595 | { "sm5502", TYPE_SM5502 }, | ||
596 | { } | ||
597 | }; | ||
598 | MODULE_DEVICE_TABLE(i2c, sm5502_i2c_id); | ||
599 | |||
600 | static struct i2c_driver sm5502_muic_i2c_driver = { | ||
601 | .driver = { | ||
602 | .name = "sm5502", | ||
603 | .owner = THIS_MODULE, | ||
604 | .pm = &sm5502_muic_pm_ops, | ||
605 | .of_match_table = sm5502_dt_match, | ||
606 | }, | ||
607 | .probe = sm5022_muic_i2c_probe, | ||
608 | .remove = sm5502_muic_i2c_remove, | ||
609 | .id_table = sm5502_i2c_id, | ||
610 | }; | ||
611 | |||
612 | static int __init sm5502_muic_i2c_init(void) | ||
613 | { | ||
614 | return i2c_add_driver(&sm5502_muic_i2c_driver); | ||
615 | } | ||
616 | subsys_initcall(sm5502_muic_i2c_init); | ||
617 | |||
618 | MODULE_DESCRIPTION("Silicon Mitus SM5502 Extcon driver"); | ||
619 | MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>"); | ||
620 | MODULE_LICENSE("GPL"); | ||
diff --git a/include/linux/extcon/sm5502.h b/include/linux/extcon/sm5502.h new file mode 100644 index 000000000000..17bd6550c485 --- /dev/null +++ b/include/linux/extcon/sm5502.h | |||
@@ -0,0 +1,264 @@ | |||
1 | /* | ||
2 | * sm5502.h | ||
3 | * | ||
4 | * Copyright (c) 2014 Samsung Electronics Co., Ltd | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms of the GNU General Public License as published by the | ||
8 | * Free Software Foundation; either version 2 of the License, or (at your | ||
9 | * option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | */ | ||
16 | |||
17 | #ifndef __LINUX_EXTCON_SM5502_H | ||
18 | #define __LINUX_EXTCON_SM5502_H | ||
19 | |||
20 | enum sm5502_types { | ||
21 | TYPE_SM5502, | ||
22 | }; | ||
23 | |||
24 | /* SM5502 registers */ | ||
25 | enum sm5502_reg { | ||
26 | SM5502_REG_DEVICE_ID = 0x01, | ||
27 | SM5502_REG_CONTROL, | ||
28 | SM5502_REG_INT1, | ||
29 | SM5502_REG_INT2, | ||
30 | SM5502_REG_INTMASK1, | ||
31 | SM5502_REG_INTMASK2, | ||
32 | SM5502_REG_ADC, | ||
33 | SM5502_REG_TIMING_SET1, | ||
34 | SM5502_REG_TIMING_SET2, | ||
35 | SM5502_REG_DEV_TYPE1, | ||
36 | SM5502_REG_DEV_TYPE2, | ||
37 | SM5502_REG_BUTTON1, | ||
38 | SM5502_REG_BUTTON2, | ||
39 | SM5502_REG_CAR_KIT_STATUS, | ||
40 | SM5502_REG_RSVD1, | ||
41 | SM5502_REG_RSVD2, | ||
42 | SM5502_REG_RSVD3, | ||
43 | SM5502_REG_RSVD4, | ||
44 | SM5502_REG_MANUAL_SW1, | ||
45 | SM5502_REG_MANUAL_SW2, | ||
46 | SM5502_REG_DEV_TYPE3, | ||
47 | SM5502_REG_RSVD5, | ||
48 | SM5502_REG_RSVD6, | ||
49 | SM5502_REG_RSVD7, | ||
50 | SM5502_REG_RSVD8, | ||
51 | SM5502_REG_RSVD9, | ||
52 | SM5502_REG_RESET, | ||
53 | SM5502_REG_RSVD10, | ||
54 | SM5502_REG_RESERVED_ID1, | ||
55 | SM5502_REG_RSVD11, | ||
56 | SM5502_REG_RSVD12, | ||
57 | SM5502_REG_RESERVED_ID2, | ||
58 | SM5502_REG_RSVD13, | ||
59 | SM5502_REG_OCP, | ||
60 | SM5502_REG_RSVD14, | ||
61 | SM5502_REG_RSVD15, | ||
62 | SM5502_REG_RSVD16, | ||
63 | SM5502_REG_RSVD17, | ||
64 | SM5502_REG_RSVD18, | ||
65 | SM5502_REG_RSVD19, | ||
66 | SM5502_REG_RSVD20, | ||
67 | SM5502_REG_RSVD21, | ||
68 | SM5502_REG_RSVD22, | ||
69 | SM5502_REG_RSVD23, | ||
70 | SM5502_REG_RSVD24, | ||
71 | SM5502_REG_RSVD25, | ||
72 | SM5502_REG_RSVD26, | ||
73 | SM5502_REG_RSVD27, | ||
74 | SM5502_REG_RSVD28, | ||
75 | SM5502_REG_RSVD29, | ||
76 | SM5502_REG_RSVD30, | ||
77 | SM5502_REG_RSVD31, | ||
78 | SM5502_REG_RSVD32, | ||
79 | SM5502_REG_RSVD33, | ||
80 | SM5502_REG_RSVD34, | ||
81 | SM5502_REG_RSVD35, | ||
82 | SM5502_REG_RSVD36, | ||
83 | SM5502_REG_RESERVED_ID3, | ||
84 | |||
85 | SM5502_REG_END, | ||
86 | }; | ||
87 | |||
88 | /* Define SM5502 MASK/SHIFT constant */ | ||
89 | #define SM5502_REG_DEVICE_ID_VENDOR_SHIFT 0 | ||
90 | #define SM5502_REG_DEVICE_ID_VERSION_SHIFT 3 | ||
91 | #define SM5502_REG_DEVICE_ID_VENDOR_MASK (0x3 << SM5502_REG_DEVICE_ID_VENDOR_SHIFT) | ||
92 | #define SM5502_REG_DEVICE_ID_VERSION_MASK (0x1f << SM5502_REG_DEVICE_ID_VERSION_SHIFT) | ||
93 | |||
94 | #define SM5502_REG_CONTROL_MASK_INT_SHIFT 0 | ||
95 | #define SM5502_REG_CONTROL_WAIT_SHIFT 1 | ||
96 | #define SM5502_REG_CONTROL_MANUAL_SW_SHIFT 2 | ||
97 | #define SM5502_REG_CONTROL_RAW_DATA_SHIFT 3 | ||
98 | #define SM5502_REG_CONTROL_SW_OPEN_SHIFT 4 | ||
99 | #define SM5502_REG_CONTROL_MASK_INT_MASK (0x1 << SM5502_REG_CONTROL_MASK_INT_SHIFT) | ||
100 | #define SM5502_REG_CONTROL_WAIT_MASK (0x1 << SM5502_REG_CONTROL_WAIT_SHIFT) | ||
101 | #define SM5502_REG_CONTROL_MANUAL_SW_MASK (0x1 << SM5502_REG_CONTROL_MANUAL_SW_SHIFT) | ||
102 | #define SM5502_REG_CONTROL_RAW_DATA_MASK (0x1 << SM5502_REG_CONTROL_RAW_DATA_SHIFT) | ||
103 | #define SM5502_REG_CONTROL_SW_OPEN_MASK (0x1 << SM5502_REG_CONTROL_SW_OPEN_SHIFT) | ||
104 | |||
105 | #define SM5502_REG_INTM1_ATTACH_SHIFT 0 | ||
106 | #define SM5502_REG_INTM1_DETACH_SHIFT 1 | ||
107 | #define SM5502_REG_INTM1_KP_SHIFT 2 | ||
108 | #define SM5502_REG_INTM1_LKP_SHIFT 3 | ||
109 | #define SM5502_REG_INTM1_LKR_SHIFT 4 | ||
110 | #define SM5502_REG_INTM1_OVP_EVENT_SHIFT 5 | ||
111 | #define SM5502_REG_INTM1_OCP_EVENT_SHIFT 6 | ||
112 | #define SM5502_REG_INTM1_OVP_OCP_DIS_SHIFT 7 | ||
113 | #define SM5502_REG_INTM1_ATTACH_MASK (0x1 << SM5502_REG_INTM1_ATTACH_SHIFT) | ||
114 | #define SM5502_REG_INTM1_DETACH_MASK (0x1 << SM5502_REG_INTM1_DETACH_SHIFT) | ||
115 | #define SM5502_REG_INTM1_KP_MASK (0x1 << SM5502_REG_INTM1_KP_SHIFT) | ||
116 | #define SM5502_REG_INTM1_LKP_MASK (0x1 << SM5502_REG_INTM1_LKP_SHIFT) | ||
117 | #define SM5502_REG_INTM1_LKR_MASK (0x1 << SM5502_REG_INTM1_LKR_SHIFT) | ||
118 | #define SM5502_REG_INTM1_OVP_EVENT_MASK (0x1 << SM5502_REG_INTM1_OVP_EVENT_SHIFT) | ||
119 | #define SM5502_REG_INTM1_OCP_EVENT_MASK (0x1 << SM5502_REG_INTM1_OCP_EVENT_SHIFT) | ||
120 | #define SM5502_REG_INTM1_OVP_OCP_DIS_MASK (0x1 << SM5502_REG_INTM1_OVP_OCP_DIS_SHIFT) | ||
121 | |||
122 | #define SM5502_REG_INTM2_VBUS_DET_SHIFT 0 | ||
123 | #define SM5502_REG_INTM2_REV_ACCE_SHIFT 1 | ||
124 | #define SM5502_REG_INTM2_ADC_CHG_SHIFT 2 | ||
125 | #define SM5502_REG_INTM2_STUCK_KEY_SHIFT 3 | ||
126 | #define SM5502_REG_INTM2_STUCK_KEY_RCV_SHIFT 4 | ||
127 | #define SM5502_REG_INTM2_MHL_SHIFT 5 | ||
128 | #define SM5502_REG_INTM2_VBUS_DET_MASK (0x1 << SM5502_REG_INTM2_VBUS_DET_SHIFT) | ||
129 | #define SM5502_REG_INTM2_REV_ACCE_MASK (0x1 << SM5502_REG_INTM2_REV_ACCE_SHIFT) | ||
130 | #define SM5502_REG_INTM2_ADC_CHG_MASK (0x1 << SM5502_REG_INTM2_ADC_CHG_SHIFT) | ||
131 | #define SM5502_REG_INTM2_STUCK_KEY_MASK (0x1 << SM5502_REG_INTM2_STUCK_KEY_SHIFT) | ||
132 | #define SM5502_REG_INTM2_STUCK_KEY_RCV_MASK (0x1 << SM5502_REG_INTM2_STUCK_KEY_RCV_SHIFT) | ||
133 | #define SM5502_REG_INTM2_MHL_MASK (0x1 << SM5502_REG_INTM2_MHL_SHIFT) | ||
134 | |||
135 | #define SM5502_REG_ADC_SHIFT 0 | ||
136 | #define SM5502_REG_ADC_MASK (0x1f << SM5502_REG_ADC_SHIFT) | ||
137 | |||
138 | #define SM5502_REG_TIMING_SET1_KEY_PRESS_SHIFT 4 | ||
139 | #define SM5502_REG_TIMING_SET1_KEY_PRESS_MASK (0xf << SM5502_REG_TIMING_SET1_KEY_PRESS_SHIFT) | ||
140 | #define TIMING_KEY_PRESS_100MS 0x0 | ||
141 | #define TIMING_KEY_PRESS_200MS 0x1 | ||
142 | #define TIMING_KEY_PRESS_300MS 0x2 | ||
143 | #define TIMING_KEY_PRESS_400MS 0x3 | ||
144 | #define TIMING_KEY_PRESS_500MS 0x4 | ||
145 | #define TIMING_KEY_PRESS_600MS 0x5 | ||
146 | #define TIMING_KEY_PRESS_700MS 0x6 | ||
147 | #define TIMING_KEY_PRESS_800MS 0x7 | ||
148 | #define TIMING_KEY_PRESS_900MS 0x8 | ||
149 | #define TIMING_KEY_PRESS_1000MS 0x9 | ||
150 | #define SM5502_REG_TIMING_SET1_ADC_DET_SHIFT 0 | ||
151 | #define SM5502_REG_TIMING_SET1_ADC_DET_MASK (0xf << SM5502_REG_TIMING_SET1_ADC_DET_SHIFT) | ||
152 | #define TIMING_ADC_DET_50MS 0x0 | ||
153 | #define TIMING_ADC_DET_100MS 0x1 | ||
154 | #define TIMING_ADC_DET_150MS 0x2 | ||
155 | #define TIMING_ADC_DET_200MS 0x3 | ||
156 | #define TIMING_ADC_DET_300MS 0x4 | ||
157 | #define TIMING_ADC_DET_400MS 0x5 | ||
158 | #define TIMING_ADC_DET_500MS 0x6 | ||
159 | #define TIMING_ADC_DET_600MS 0x7 | ||
160 | #define TIMING_ADC_DET_700MS 0x8 | ||
161 | #define TIMING_ADC_DET_800MS 0x9 | ||
162 | #define TIMING_ADC_DET_900MS 0xA | ||
163 | #define TIMING_ADC_DET_1000MS 0xB | ||
164 | |||
165 | #define SM5502_REG_TIMING_SET2_SW_WAIT_SHIFT 4 | ||
166 | #define SM5502_REG_TIMING_SET2_SW_WAIT_MASK (0xf << SM5502_REG_TIMING_SET2_SW_WAIT_SHIFT) | ||
167 | #define TIMING_SW_WAIT_10MS 0x0 | ||
168 | #define TIMING_SW_WAIT_30MS 0x1 | ||
169 | #define TIMING_SW_WAIT_50MS 0x2 | ||
170 | #define TIMING_SW_WAIT_70MS 0x3 | ||
171 | #define TIMING_SW_WAIT_90MS 0x4 | ||
172 | #define TIMING_SW_WAIT_110MS 0x5 | ||
173 | #define TIMING_SW_WAIT_130MS 0x6 | ||
174 | #define TIMING_SW_WAIT_150MS 0x7 | ||
175 | #define TIMING_SW_WAIT_170MS 0x8 | ||
176 | #define TIMING_SW_WAIT_190MS 0x9 | ||
177 | #define TIMING_SW_WAIT_210MS 0xA | ||
178 | #define SM5502_REG_TIMING_SET2_LONG_KEY_SHIFT 0 | ||
179 | #define SM5502_REG_TIMING_SET2_LONG_KEY_MASK (0xf << SM5502_REG_TIMING_SET2_LONG_KEY_SHIFT) | ||
180 | #define TIMING_LONG_KEY_300MS 0x0 | ||
181 | #define TIMING_LONG_KEY_400MS 0x1 | ||
182 | #define TIMING_LONG_KEY_500MS 0x2 | ||
183 | #define TIMING_LONG_KEY_600MS 0x3 | ||
184 | #define TIMING_LONG_KEY_700MS 0x4 | ||
185 | #define TIMING_LONG_KEY_800MS 0x5 | ||
186 | #define TIMING_LONG_KEY_900MS 0x6 | ||
187 | #define TIMING_LONG_KEY_1000MS 0x7 | ||
188 | #define TIMING_LONG_KEY_1100MS 0x8 | ||
189 | #define TIMING_LONG_KEY_1200MS 0x9 | ||
190 | #define TIMING_LONG_KEY_1300MS 0xA | ||
191 | #define TIMING_LONG_KEY_1400MS 0xB | ||
192 | #define TIMING_LONG_KEY_1500MS 0xC | ||
193 | |||
194 | #define SM5502_REG_DEV_TYPE1_AUDIO_TYPE1_SHIFT 0 | ||
195 | #define SM5502_REG_DEV_TYPE1_AUDIO_TYPE2_SHIFT 1 | ||
196 | #define SM5502_REG_DEV_TYPE1_USB_SDP_SHIFT 2 | ||
197 | #define SM5502_REG_DEV_TYPE1_UART_SHIFT 3 | ||
198 | #define SM5502_REG_DEV_TYPE1_CAR_KIT_CHARGER_SHIFT 4 | ||
199 | #define SM5502_REG_DEV_TYPE1_USB_CHG_SHIFT 5 | ||
200 | #define SM5502_REG_DEV_TYPE1_DEDICATED_CHG_SHIFT 6 | ||
201 | #define SM5502_REG_DEV_TYPE1_USB_OTG_SHIFT 7 | ||
202 | #define SM5502_REG_DEV_TYPE1_AUDIO_TYPE1_MASK (0x1 << SM5502_REG_DEV_TYPE1_AUDIO_TYPE1_SHIFT) | ||
203 | #define SM5502_REG_DEV_TYPE1_AUDIO_TYPE1__MASK (0x1 << SM5502_REG_DEV_TYPE1_AUDIO_TYPE2_SHIFT) | ||
204 | #define SM5502_REG_DEV_TYPE1_USB_SDP_MASK (0x1 << SM5502_REG_DEV_TYPE1_USB_SDP_SHIFT) | ||
205 | #define SM5502_REG_DEV_TYPE1_UART_MASK (0x1 << SM5502_REG_DEV_TYPE1_UART_SHIFT) | ||
206 | #define SM5502_REG_DEV_TYPE1_CAR_KIT_CHARGER_MASK (0x1 << SM5502_REG_DEV_TYPE1_CAR_KIT_CHARGER_SHIFT) | ||
207 | #define SM5502_REG_DEV_TYPE1_USB_CHG_MASK (0x1 << SM5502_REG_DEV_TYPE1_USB_CHG_SHIFT) | ||
208 | #define SM5502_REG_DEV_TYPE1_DEDICATED_CHG_MASK (0x1 << SM5502_REG_DEV_TYPE1_DEDICATED_CHG_SHIFT) | ||
209 | #define SM5502_REG_DEV_TYPE1_USB_OTG_MASK (0x1 << SM5502_REG_DEV_TYPE1_USB_OTG_SHIFT) | ||
210 | |||
211 | #define SM5502_REG_DEV_TYPE2_JIG_USB_ON_SHIFT 0 | ||
212 | #define SM5502_REG_DEV_TYPE2_JIG_USB_OFF_SHIFT 1 | ||
213 | #define SM5502_REG_DEV_TYPE2_JIG_UART_ON_SHIFT 2 | ||
214 | #define SM5502_REG_DEV_TYPE2_JIG_UART_OFF_SHIFT 3 | ||
215 | #define SM5502_REG_DEV_TYPE2_PPD_SHIFT 4 | ||
216 | #define SM5502_REG_DEV_TYPE2_TTY_SHIFT 5 | ||
217 | #define SM5502_REG_DEV_TYPE2_AV_CABLE_SHIFT 6 | ||
218 | #define SM5502_REG_DEV_TYPE2_JIG_USB_ON_MASK (0x1 << SM5502_REG_DEV_TYPE2_JIG_USB_ON_SHIFT) | ||
219 | #define SM5502_REG_DEV_TYPE2_JIG_USB_OFF_MASK (0x1 << SM5502_REG_DEV_TYPE2_JIG_USB_OFF_SHIFT) | ||
220 | #define SM5502_REG_DEV_TYPE2_JIG_UART_ON_MASK (0x1 << SM5502_REG_DEV_TYPE2_JIG_UART_ON_SHIFT) | ||
221 | #define SM5502_REG_DEV_TYPE2_JIG_UART_OFF_MASK (0x1 << SM5502_REG_DEV_TYPE2_JIG_UART_OFF_SHIFT) | ||
222 | #define SM5502_REG_DEV_TYPE2_PPD_MASK (0x1 << SM5502_REG_DEV_TYPE2_PPD_SHIFT) | ||
223 | #define SM5502_REG_DEV_TYPE2_TTY_MASK (0x1 << SM5502_REG_DEV_TYPE2_TTY_SHIFT) | ||
224 | #define SM5502_REG_DEV_TYPE2_AV_CABLE_MASK (0x1 << SM5502_REG_DEV_TYPE2_AV_CABLE_SHIFT) | ||
225 | |||
226 | /* SM5502 Interrupts */ | ||
227 | enum sm5502_irq { | ||
228 | /* INT1 */ | ||
229 | SM5502_IRQ_INT1_ATTACH, | ||
230 | SM5502_IRQ_INT1_DETACH, | ||
231 | SM5502_IRQ_INT1_KP, | ||
232 | SM5502_IRQ_INT1_LKP, | ||
233 | SM5502_IRQ_INT1_LKR, | ||
234 | SM5502_IRQ_INT1_OVP_EVENT, | ||
235 | SM5502_IRQ_INT1_OCP_EVENT, | ||
236 | SM5502_IRQ_INT1_OVP_OCP_DIS, | ||
237 | |||
238 | /* INT2 */ | ||
239 | SM5502_IRQ_INT2_VBUS_DET, | ||
240 | SM5502_IRQ_INT2_REV_ACCE, | ||
241 | SM5502_IRQ_INT2_ADC_CHG, | ||
242 | SM5502_IRQ_INT2_STUCK_KEY, | ||
243 | SM5502_IRQ_INT2_STUCK_KEY_RCV, | ||
244 | SM5502_IRQ_INT2_MHL, | ||
245 | |||
246 | SM5502_IRQ_NUM, | ||
247 | }; | ||
248 | |||
249 | #define SM5502_IRQ_INT1_ATTACH_MASK BIT(0) | ||
250 | #define SM5502_IRQ_INT1_DETACH_MASK BIT(1) | ||
251 | #define SM5502_IRQ_INT1_KP_MASK BIT(2) | ||
252 | #define SM5502_IRQ_INT1_LKP_MASK BIT(3) | ||
253 | #define SM5502_IRQ_INT1_LKR_MASK BIT(4) | ||
254 | #define SM5502_IRQ_INT1_OVP_EVENT_MASK BIT(5) | ||
255 | #define SM5502_IRQ_INT1_OCP_EVENT_MASK BIT(6) | ||
256 | #define SM5502_IRQ_INT1_OVP_OCP_DIS_MASK BIT(7) | ||
257 | #define SM5502_IRQ_INT2_VBUS_DET_MASK BIT(0) | ||
258 | #define SM5502_IRQ_INT2_REV_ACCE_MASK BIT(1) | ||
259 | #define SM5502_IRQ_INT2_ADC_CHG_MASK BIT(2) | ||
260 | #define SM5502_IRQ_INT2_STUCK_KEY_MASK BIT(3) | ||
261 | #define SM5502_IRQ_INT2_STUCK_KEY_RCV_MASK BIT(4) | ||
262 | #define SM5502_IRQ_INT2_MHL_MASK BIT(5) | ||
263 | |||
264 | #endif /* __LINUX_EXTCON_SM5502_H */ | ||