blob: 107932105798b8e4f08137d5b898ec4ce6ee9b8b [file] [log] [blame]
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001/*
2 * extcon-max77693.c - MAX77693 extcon driver to support MAX77693 MUIC
3 *
4 * Copyright (C) 2012 Samsung Electrnoics
5 * Chanwoo Choi <cw00.choi@samsung.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your 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/kernel.h>
19#include <linux/module.h>
20#include <linux/i2c.h>
21#include <linux/slab.h>
Chanwoo Choi39bf3692012-12-03 13:09:41 +090022#include <linux/input.h>
Chanwoo Choidb1b9032012-07-17 13:28:28 +090023#include <linux/interrupt.h>
24#include <linux/err.h>
25#include <linux/platform_device.h>
26#include <linux/mfd/max77693.h>
27#include <linux/mfd/max77693-private.h>
28#include <linux/extcon.h>
29#include <linux/regmap.h>
30#include <linux/irqdomain.h>
31
32#define DEV_NAME "max77693-muic"
Chanwoo Choi297620f2012-12-26 13:10:11 +090033#define DELAY_MS_DEFAULT 20000 /* unit: millisecond */
Chanwoo Choidb1b9032012-07-17 13:28:28 +090034
Chanwoo Choi0ec83bd2013-03-13 17:38:57 +090035/*
36 * Default value of MAX77693 register to bring up MUIC device.
37 * If user don't set some initial value for MUIC device through platform data,
38 * extcon-max77693 driver use 'default_init_data' to bring up base operation
39 * of MAX77693 MUIC device.
40 */
Sachin Kamat813b4512013-04-08 09:09:41 +090041static struct max77693_reg_data default_init_data[] = {
Chanwoo Choi0ec83bd2013-03-13 17:38:57 +090042 {
43 /* STATUS2 - [3]ChgDetRun */
44 .addr = MAX77693_MUIC_REG_STATUS2,
45 .data = STATUS2_CHGDETRUN_MASK,
46 }, {
47 /* INTMASK1 - Unmask [3]ADC1KM,[0]ADCM */
48 .addr = MAX77693_MUIC_REG_INTMASK1,
49 .data = INTMASK1_ADC1K_MASK
50 | INTMASK1_ADC_MASK,
51 }, {
52 /* INTMASK2 - Unmask [0]ChgTypM */
53 .addr = MAX77693_MUIC_REG_INTMASK2,
54 .data = INTMASK2_CHGTYP_MASK,
55 }, {
56 /* INTMASK3 - Mask all of interrupts */
57 .addr = MAX77693_MUIC_REG_INTMASK3,
58 .data = 0x0,
59 }, {
60 /* CDETCTRL2 */
61 .addr = MAX77693_MUIC_REG_CDETCTRL2,
62 .data = CDETCTRL2_VIDRMEN_MASK
63 | CDETCTRL2_DXOVPEN_MASK,
64 },
65};
66
Chanwoo Choidb1b9032012-07-17 13:28:28 +090067enum max77693_muic_adc_debounce_time {
68 ADC_DEBOUNCE_TIME_5MS = 0,
69 ADC_DEBOUNCE_TIME_10MS,
70 ADC_DEBOUNCE_TIME_25MS,
71 ADC_DEBOUNCE_TIME_38_62MS,
72};
73
74struct max77693_muic_info {
75 struct device *dev;
76 struct max77693_dev *max77693;
77 struct extcon_dev *edev;
Chanwoo Choi154f757f2012-11-27 09:40:32 +090078 int prev_cable_type;
79 int prev_cable_type_gnd;
Chanwoo Choidb1b9032012-07-17 13:28:28 +090080 int prev_chg_type;
Chanwoo Choi39bf3692012-12-03 13:09:41 +090081 int prev_button_type;
Chanwoo Choidb1b9032012-07-17 13:28:28 +090082 u8 status[2];
83
84 int irq;
85 struct work_struct irq_work;
86 struct mutex mutex;
Chanwoo Choi39bf3692012-12-03 13:09:41 +090087
Chanwoo Choi297620f2012-12-26 13:10:11 +090088 /*
89 * Use delayed workqueue to detect cable state and then
90 * notify cable state to notifiee/platform through uevent.
91 * After completing the booting of platform, the extcon provider
92 * driver should notify cable state to upper layer.
93 */
94 struct delayed_work wq_detcable;
95
Chanwoo Choi39bf3692012-12-03 13:09:41 +090096 /* Button of dock device */
97 struct input_dev *dock;
Chanwoo Choi2b757992012-12-06 21:27:56 +090098
99 /*
100 * Default usb/uart path whether UART/USB or AUX_UART/AUX_USB
101 * h/w path of COMP2/COMN1 on CONTROL1 register.
102 */
103 int path_usb;
104 int path_uart;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900105};
106
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900107enum max77693_muic_cable_group {
108 MAX77693_CABLE_GROUP_ADC = 0,
109 MAX77693_CABLE_GROUP_ADC_GND,
110 MAX77693_CABLE_GROUP_CHG,
111 MAX77693_CABLE_GROUP_VBVOLT,
112};
113
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900114enum max77693_muic_charger_type {
115 MAX77693_CHARGER_TYPE_NONE = 0,
116 MAX77693_CHARGER_TYPE_USB,
117 MAX77693_CHARGER_TYPE_DOWNSTREAM_PORT,
118 MAX77693_CHARGER_TYPE_DEDICATED_CHG,
119 MAX77693_CHARGER_TYPE_APPLE_500MA,
120 MAX77693_CHARGER_TYPE_APPLE_1A_2A,
121 MAX77693_CHARGER_TYPE_DEAD_BATTERY = 7,
122};
123
124/**
125 * struct max77693_muic_irq
126 * @irq: the index of irq list of MUIC device.
127 * @name: the name of irq.
128 * @virq: the virtual irq to use irq domain
129 */
130struct max77693_muic_irq {
131 unsigned int irq;
132 const char *name;
133 unsigned int virq;
134};
135
136static struct max77693_muic_irq muic_irqs[] = {
137 { MAX77693_MUIC_IRQ_INT1_ADC, "muic-ADC" },
138 { MAX77693_MUIC_IRQ_INT1_ADC_LOW, "muic-ADCLOW" },
139 { MAX77693_MUIC_IRQ_INT1_ADC_ERR, "muic-ADCError" },
140 { MAX77693_MUIC_IRQ_INT1_ADC1K, "muic-ADC1K" },
141 { MAX77693_MUIC_IRQ_INT2_CHGTYP, "muic-CHGTYP" },
142 { MAX77693_MUIC_IRQ_INT2_CHGDETREUN, "muic-CHGDETREUN" },
143 { MAX77693_MUIC_IRQ_INT2_DCDTMR, "muic-DCDTMR" },
144 { MAX77693_MUIC_IRQ_INT2_DXOVP, "muic-DXOVP" },
145 { MAX77693_MUIC_IRQ_INT2_VBVOLT, "muic-VBVOLT" },
146 { MAX77693_MUIC_IRQ_INT2_VIDRM, "muic-VIDRM" },
147 { MAX77693_MUIC_IRQ_INT3_EOC, "muic-EOC" },
148 { MAX77693_MUIC_IRQ_INT3_CGMBC, "muic-CGMBC" },
149 { MAX77693_MUIC_IRQ_INT3_OVP, "muic-OVP" },
150 { MAX77693_MUIC_IRQ_INT3_MBCCHG_ERR, "muic-MBCCHG_ERR" },
151 { MAX77693_MUIC_IRQ_INT3_CHG_ENABLED, "muic-CHG_ENABLED" },
152 { MAX77693_MUIC_IRQ_INT3_BAT_DET, "muic-BAT_DET" },
153};
154
155/* Define supported accessory type */
156enum max77693_muic_acc_type {
157 MAX77693_MUIC_ADC_GROUND = 0x0,
158 MAX77693_MUIC_ADC_SEND_END_BUTTON,
159 MAX77693_MUIC_ADC_REMOTE_S1_BUTTON,
160 MAX77693_MUIC_ADC_REMOTE_S2_BUTTON,
161 MAX77693_MUIC_ADC_REMOTE_S3_BUTTON,
162 MAX77693_MUIC_ADC_REMOTE_S4_BUTTON,
163 MAX77693_MUIC_ADC_REMOTE_S5_BUTTON,
164 MAX77693_MUIC_ADC_REMOTE_S6_BUTTON,
165 MAX77693_MUIC_ADC_REMOTE_S7_BUTTON,
166 MAX77693_MUIC_ADC_REMOTE_S8_BUTTON,
167 MAX77693_MUIC_ADC_REMOTE_S9_BUTTON,
168 MAX77693_MUIC_ADC_REMOTE_S10_BUTTON,
169 MAX77693_MUIC_ADC_REMOTE_S11_BUTTON,
170 MAX77693_MUIC_ADC_REMOTE_S12_BUTTON,
171 MAX77693_MUIC_ADC_RESERVED_ACC_1,
172 MAX77693_MUIC_ADC_RESERVED_ACC_2,
173 MAX77693_MUIC_ADC_RESERVED_ACC_3,
174 MAX77693_MUIC_ADC_RESERVED_ACC_4,
175 MAX77693_MUIC_ADC_RESERVED_ACC_5,
176 MAX77693_MUIC_ADC_CEA936_AUDIO,
177 MAX77693_MUIC_ADC_PHONE_POWERED_DEV,
178 MAX77693_MUIC_ADC_TTY_CONVERTER,
179 MAX77693_MUIC_ADC_UART_CABLE,
180 MAX77693_MUIC_ADC_CEA936A_TYPE1_CHG,
181 MAX77693_MUIC_ADC_FACTORY_MODE_USB_OFF,
182 MAX77693_MUIC_ADC_FACTORY_MODE_USB_ON,
183 MAX77693_MUIC_ADC_AV_CABLE_NOLOAD,
184 MAX77693_MUIC_ADC_CEA936A_TYPE2_CHG,
185 MAX77693_MUIC_ADC_FACTORY_MODE_UART_OFF,
186 MAX77693_MUIC_ADC_FACTORY_MODE_UART_ON,
187 MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE,
188 MAX77693_MUIC_ADC_OPEN,
189
190 /* The below accessories have same ADC value so ADCLow and
191 ADC1K bit is used to separate specific accessory */
Chanwoo Choic2275d22013-08-23 10:21:37 +0900192 /* ADC|VBVolot|ADCLow|ADC1K| */
Jaewon Kim4c883ab2015-01-29 17:45:24 +0900193 MAX77693_MUIC_GND_USB_HOST = 0x100, /* 0x0| 0| 0| 0| */
194 MAX77693_MUIC_GND_USB_HOST_VB = 0x104, /* 0x0| 1| 0| 0| */
Chanwoo Choic2275d22013-08-23 10:21:37 +0900195 MAX77693_MUIC_GND_AV_CABLE_LOAD = 0x102,/* 0x0| 0| 1| 0| */
196 MAX77693_MUIC_GND_MHL = 0x103, /* 0x0| 0| 1| 1| */
197 MAX77693_MUIC_GND_MHL_VB = 0x107, /* 0x0| 1| 1| 1| */
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900198};
199
Chanwoo Choic2275d22013-08-23 10:21:37 +0900200/*
201 * MAX77693 MUIC device support below list of accessories(external connector)
202 */
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900203enum {
204 EXTCON_CABLE_USB = 0,
205 EXTCON_CABLE_USB_HOST,
206 EXTCON_CABLE_TA,
207 EXTCON_CABLE_FAST_CHARGER,
208 EXTCON_CABLE_SLOW_CHARGER,
209 EXTCON_CABLE_CHARGE_DOWNSTREAM,
210 EXTCON_CABLE_MHL,
Chanwoo Choi06bed0a2012-11-27 11:30:35 +0900211 EXTCON_CABLE_MHL_TA,
Chanwoo Choi41b3c012015-04-24 19:50:48 +0900212 EXTCON_CABLE_JIG,
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900213 EXTCON_CABLE_DOCK_SMART,
214 EXTCON_CABLE_DOCK_DESK,
215 EXTCON_CABLE_DOCK_AUDIO,
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900216
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900217 _EXTCON_CABLE_NUM,
218};
219
Sachin Kamat45d4a4e2013-01-31 09:31:47 +0900220static const char *max77693_extcon_cable[] = {
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900221 [EXTCON_CABLE_USB] = "USB",
222 [EXTCON_CABLE_USB_HOST] = "USB-Host",
223 [EXTCON_CABLE_TA] = "TA",
224 [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger",
225 [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger",
226 [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream",
227 [EXTCON_CABLE_MHL] = "MHL",
Jaewon Kim4f0be262015-01-29 17:45:23 +0900228 [EXTCON_CABLE_MHL_TA] = "MHL-TA",
Chanwoo Choi41b3c012015-04-24 19:50:48 +0900229 [EXTCON_CABLE_JIG] = "JIG",
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900230 [EXTCON_CABLE_DOCK_SMART] = "Dock-Smart",
231 [EXTCON_CABLE_DOCK_DESK] = "Dock-Desk",
232 [EXTCON_CABLE_DOCK_AUDIO] = "Dock-Audio",
Chanwoo Choid0587eb2012-11-27 12:06:49 +0900233
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900234 NULL,
235};
236
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900237/*
238 * max77693_muic_set_debounce_time - Set the debounce time of ADC
239 * @info: the instance including private data of max77693 MUIC
240 * @time: the debounce time of ADC
241 */
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900242static int max77693_muic_set_debounce_time(struct max77693_muic_info *info,
243 enum max77693_muic_adc_debounce_time time)
244{
Axel Linbf2627d2012-10-04 09:55:23 +0900245 int ret;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900246
247 switch (time) {
248 case ADC_DEBOUNCE_TIME_5MS:
249 case ADC_DEBOUNCE_TIME_10MS:
250 case ADC_DEBOUNCE_TIME_25MS:
251 case ADC_DEBOUNCE_TIME_38_62MS:
Jonghwa Leedc6048d2014-09-17 12:58:43 +0900252 /*
253 * Don't touch BTLDset, JIGset when you want to change adc
254 * debounce time. If it writes other than 0 to BTLDset, JIGset
255 * muic device will be reset and loose current state.
256 */
257 ret = regmap_write(info->max77693->regmap_muic,
258 MAX77693_MUIC_REG_CTRL3,
259 time << CONTROL3_ADCDBSET_SHIFT);
Chanwoo Choi19d32432013-02-13 18:35:08 +0900260 if (ret) {
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900261 dev_err(info->dev, "failed to set ADC debounce time\n");
Sachin Kamatc2536542013-04-08 09:12:32 +0900262 return ret;
Chanwoo Choi19d32432013-02-13 18:35:08 +0900263 }
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900264 break;
265 default:
266 dev_err(info->dev, "invalid ADC debounce time\n");
Chanwoo Choi19d32432013-02-13 18:35:08 +0900267 return -EINVAL;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900268 }
269
Chanwoo Choi19d32432013-02-13 18:35:08 +0900270 return 0;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900271};
272
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900273/*
274 * max77693_muic_set_path - Set hardware line according to attached cable
275 * @info: the instance including private data of max77693 MUIC
276 * @value: the path according to attached cable
277 * @attached: the state of cable (true:attached, false:detached)
278 *
279 * The max77693 MUIC device share outside H/W line among a varity of cables
280 * so, this function set internal path of H/W line according to the type of
281 * attached cable.
282 */
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900283static int max77693_muic_set_path(struct max77693_muic_info *info,
284 u8 val, bool attached)
285{
286 int ret = 0;
Robert Baldygad0540f92014-05-21 08:52:47 +0200287 unsigned int ctrl1, ctrl2 = 0;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900288
289 if (attached)
290 ctrl1 = val;
291 else
292 ctrl1 = CONTROL1_SW_OPEN;
293
Robert Baldygad0540f92014-05-21 08:52:47 +0200294 ret = regmap_update_bits(info->max77693->regmap_muic,
295 MAX77693_MUIC_REG_CTRL1, COMP_SW_MASK, ctrl1);
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900296 if (ret < 0) {
297 dev_err(info->dev, "failed to update MUIC register\n");
Sachin Kamatc2536542013-04-08 09:12:32 +0900298 return ret;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900299 }
300
301 if (attached)
302 ctrl2 |= CONTROL2_CPEN_MASK; /* LowPwr=0, CPEn=1 */
303 else
304 ctrl2 |= CONTROL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */
305
Robert Baldygad0540f92014-05-21 08:52:47 +0200306 ret = regmap_update_bits(info->max77693->regmap_muic,
307 MAX77693_MUIC_REG_CTRL2,
308 CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK, ctrl2);
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900309 if (ret < 0) {
310 dev_err(info->dev, "failed to update MUIC register\n");
Sachin Kamatc2536542013-04-08 09:12:32 +0900311 return ret;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900312 }
313
314 dev_info(info->dev,
315 "CONTROL1 : 0x%02x, CONTROL2 : 0x%02x, state : %s\n",
316 ctrl1, ctrl2, attached ? "attached" : "detached");
Chanwoo Choi19d32432013-02-13 18:35:08 +0900317
318 return 0;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900319}
320
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900321/*
322 * max77693_muic_get_cable_type - Return cable type and check cable state
323 * @info: the instance including private data of max77693 MUIC
324 * @group: the path according to attached cable
325 * @attached: store cable state and return
326 *
327 * This function check the cable state either attached or detached,
328 * and then divide precise type of cable according to cable group.
329 * - MAX77693_CABLE_GROUP_ADC
330 * - MAX77693_CABLE_GROUP_ADC_GND
331 * - MAX77693_CABLE_GROUP_CHG
332 * - MAX77693_CABLE_GROUP_VBVOLT
333 */
334static int max77693_muic_get_cable_type(struct max77693_muic_info *info,
335 enum max77693_muic_cable_group group, bool *attached)
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900336{
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900337 int cable_type = 0;
338 int adc;
339 int adc1k;
340 int adclow;
341 int vbvolt;
342 int chg_type;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900343
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900344 switch (group) {
345 case MAX77693_CABLE_GROUP_ADC:
346 /*
347 * Read ADC value to check cable type and decide cable state
348 * according to cable type
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900349 */
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900350 adc = info->status[0] & STATUS1_ADC_MASK;
351 adc >>= STATUS1_ADC_SHIFT;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900352
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900353 /*
354 * Check current cable state/cable type and store cable type
355 * (info->prev_cable_type) for handling cable when cable is
356 * detached.
357 */
358 if (adc == MAX77693_MUIC_ADC_OPEN) {
359 *attached = false;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900360
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900361 cable_type = info->prev_cable_type;
362 info->prev_cable_type = MAX77693_MUIC_ADC_OPEN;
363 } else {
364 *attached = true;
365
366 cable_type = info->prev_cable_type = adc;
367 }
368 break;
369 case MAX77693_CABLE_GROUP_ADC_GND:
370 /*
371 * Read ADC value to check cable type and decide cable state
372 * according to cable type
373 */
374 adc = info->status[0] & STATUS1_ADC_MASK;
375 adc >>= STATUS1_ADC_SHIFT;
376
377 /*
378 * Check current cable state/cable type and store cable type
379 * (info->prev_cable_type/_gnd) for handling cable when cable
380 * is detached.
381 */
382 if (adc == MAX77693_MUIC_ADC_OPEN) {
383 *attached = false;
384
385 cable_type = info->prev_cable_type_gnd;
386 info->prev_cable_type_gnd = MAX77693_MUIC_ADC_OPEN;
387 } else {
388 *attached = true;
389
390 adclow = info->status[0] & STATUS1_ADCLOW_MASK;
391 adclow >>= STATUS1_ADCLOW_SHIFT;
392 adc1k = info->status[0] & STATUS1_ADC1K_MASK;
393 adc1k >>= STATUS1_ADC1K_SHIFT;
394
395 vbvolt = info->status[1] & STATUS2_VBVOLT_MASK;
396 vbvolt >>= STATUS2_VBVOLT_SHIFT;
397
398 /**
Chanwoo Choic2275d22013-08-23 10:21:37 +0900399 * [0x1|VBVolt|ADCLow|ADC1K]
Jaewon Kim4c883ab2015-01-29 17:45:24 +0900400 * [0x1| 0| 0| 0] USB_HOST
401 * [0x1| 1| 0| 0] USB_HSOT_VB
Chanwoo Choic2275d22013-08-23 10:21:37 +0900402 * [0x1| 0| 1| 0] Audio Video cable with load
403 * [0x1| 0| 1| 1] MHL without charging cable
404 * [0x1| 1| 1| 1] MHL with charging cable
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900405 */
406 cable_type = ((0x1 << 8)
407 | (vbvolt << 2)
408 | (adclow << 1)
409 | adc1k);
410
411 info->prev_cable_type = adc;
412 info->prev_cable_type_gnd = cable_type;
413 }
414
415 break;
416 case MAX77693_CABLE_GROUP_CHG:
417 /*
418 * Read charger type to check cable type and decide cable state
419 * according to type of charger cable.
420 */
421 chg_type = info->status[1] & STATUS2_CHGTYP_MASK;
422 chg_type >>= STATUS2_CHGTYP_SHIFT;
423
424 if (chg_type == MAX77693_CHARGER_TYPE_NONE) {
425 *attached = false;
426
427 cable_type = info->prev_chg_type;
428 info->prev_chg_type = MAX77693_CHARGER_TYPE_NONE;
429 } else {
430 *attached = true;
431
432 /*
433 * Check current cable state/cable type and store cable
434 * type(info->prev_chg_type) for handling cable when
435 * charger cable is detached.
436 */
437 cable_type = info->prev_chg_type = chg_type;
438 }
439
440 break;
441 case MAX77693_CABLE_GROUP_VBVOLT:
442 /*
443 * Read ADC value to check cable type and decide cable state
444 * according to cable type
445 */
446 adc = info->status[0] & STATUS1_ADC_MASK;
447 adc >>= STATUS1_ADC_SHIFT;
448 chg_type = info->status[1] & STATUS2_CHGTYP_MASK;
449 chg_type >>= STATUS2_CHGTYP_SHIFT;
450
451 if (adc == MAX77693_MUIC_ADC_OPEN
452 && chg_type == MAX77693_CHARGER_TYPE_NONE)
453 *attached = false;
454 else
455 *attached = true;
456
457 /*
458 * Read vbvolt field, if vbvolt is 1,
459 * this cable is used for charging.
460 */
461 vbvolt = info->status[1] & STATUS2_VBVOLT_MASK;
462 vbvolt >>= STATUS2_VBVOLT_SHIFT;
463
464 cable_type = vbvolt;
465 break;
466 default:
467 dev_err(info->dev, "Unknown cable group (%d)\n", group);
468 cable_type = -EINVAL;
469 break;
470 }
471
472 return cable_type;
473}
474
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900475static int max77693_muic_dock_handler(struct max77693_muic_info *info,
476 int cable_type, bool attached)
477{
478 int ret = 0;
Chanwoo Choia1626292012-12-10 19:07:53 +0900479 int vbvolt;
480 bool cable_attached;
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900481 char dock_name[CABLE_NAME_MAX];
482
483 dev_info(info->dev,
484 "external connector is %s (adc:0x%02x)\n",
485 attached ? "attached" : "detached", cable_type);
486
487 switch (cable_type) {
488 case MAX77693_MUIC_ADC_RESERVED_ACC_3: /* Dock-Smart */
Chanwoo Choia1626292012-12-10 19:07:53 +0900489 /*
490 * Check power cable whether attached or detached state.
491 * The Dock-Smart device need surely external power supply.
492 * If power cable(USB/TA) isn't connected to Dock device,
493 * user can't use Dock-Smart for desktop mode.
494 */
495 vbvolt = max77693_muic_get_cable_type(info,
496 MAX77693_CABLE_GROUP_VBVOLT, &cable_attached);
497 if (attached && !vbvolt) {
498 dev_warn(info->dev,
499 "Cannot detect external power supply\n");
500 return 0;
501 }
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900502
Chanwoo Choia1626292012-12-10 19:07:53 +0900503 /*
504 * Notify Dock-Smart/MHL state.
505 * - Dock-Smart device include three type of cable which
506 * are HDMI, USB for mouse/keyboard and micro-usb port
507 * for USB/TA cable. Dock-Smart device need always exteranl
508 * power supply(USB/TA cable through micro-usb cable). Dock-
509 * Smart device support screen output of target to separate
510 * monitor and mouse/keyboard for desktop mode.
511 *
512 * Features of 'USB/TA cable with Dock-Smart device'
513 * - Support MHL
514 * - Support external output feature of audio
515 * - Support charging through micro-usb port without data
516 * connection if TA cable is connected to target.
517 * - Support charging and data connection through micro-usb port
518 * if USB cable is connected between target and host
519 * device.
Jaewon Kim4c883ab2015-01-29 17:45:24 +0900520 * - Support OTG(On-The-Go) device (Ex: Mouse/Keyboard)
Chanwoo Choia1626292012-12-10 19:07:53 +0900521 */
522 ret = max77693_muic_set_path(info, info->path_usb, attached);
523 if (ret < 0)
524 return ret;
525
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900526 extcon_set_cable_state(info->edev, "Dock-Smart", attached);
Chanwoo Choia1626292012-12-10 19:07:53 +0900527 extcon_set_cable_state(info->edev, "MHL", attached);
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900528 goto out;
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900529 case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk */
530 strcpy(dock_name, "Dock-Desk");
531 break;
532 case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */
533 strcpy(dock_name, "Dock-Audio");
534 if (!attached)
535 extcon_set_cable_state(info->edev, "USB", false);
536 break;
Chanwoo Choi19d32432013-02-13 18:35:08 +0900537 default:
538 dev_err(info->dev, "failed to detect %s dock device\n",
539 attached ? "attached" : "detached");
540 return -EINVAL;
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900541 }
542
543 /* Dock-Car/Desk/Audio, PATH:AUDIO */
544 ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached);
545 if (ret < 0)
Chanwoo Choia1626292012-12-10 19:07:53 +0900546 return ret;
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900547 extcon_set_cable_state(info->edev, dock_name, attached);
548
549out:
Chanwoo Choia1626292012-12-10 19:07:53 +0900550 return 0;
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900551}
552
553static int max77693_muic_dock_button_handler(struct max77693_muic_info *info,
554 int button_type, bool attached)
555{
556 struct input_dev *dock = info->dock;
557 unsigned int code;
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900558
559 switch (button_type) {
560 case MAX77693_MUIC_ADC_REMOTE_S3_BUTTON-1
561 ... MAX77693_MUIC_ADC_REMOTE_S3_BUTTON+1:
562 /* DOCK_KEY_PREV */
563 code = KEY_PREVIOUSSONG;
564 break;
565 case MAX77693_MUIC_ADC_REMOTE_S7_BUTTON-1
566 ... MAX77693_MUIC_ADC_REMOTE_S7_BUTTON+1:
567 /* DOCK_KEY_NEXT */
568 code = KEY_NEXTSONG;
569 break;
570 case MAX77693_MUIC_ADC_REMOTE_S9_BUTTON:
571 /* DOCK_VOL_DOWN */
572 code = KEY_VOLUMEDOWN;
573 break;
574 case MAX77693_MUIC_ADC_REMOTE_S10_BUTTON:
575 /* DOCK_VOL_UP */
576 code = KEY_VOLUMEUP;
577 break;
578 case MAX77693_MUIC_ADC_REMOTE_S12_BUTTON-1
579 ... MAX77693_MUIC_ADC_REMOTE_S12_BUTTON+1:
580 /* DOCK_KEY_PLAY_PAUSE */
581 code = KEY_PLAYPAUSE;
582 break;
583 default:
584 dev_err(info->dev,
585 "failed to detect %s key (adc:0x%x)\n",
586 attached ? "pressed" : "released", button_type);
Chanwoo Choi19d32432013-02-13 18:35:08 +0900587 return -EINVAL;
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900588 }
589
590 input_event(dock, EV_KEY, code, attached);
591 input_sync(dock);
592
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900593 return 0;
594}
595
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900596static int max77693_muic_adc_ground_handler(struct max77693_muic_info *info)
597{
598 int cable_type_gnd;
599 int ret = 0;
600 bool attached;
601
602 cable_type_gnd = max77693_muic_get_cable_type(info,
603 MAX77693_CABLE_GROUP_ADC_GND, &attached);
604
605 switch (cable_type_gnd) {
Jaewon Kim4c883ab2015-01-29 17:45:24 +0900606 case MAX77693_MUIC_GND_USB_HOST:
607 case MAX77693_MUIC_GND_USB_HOST_VB:
608 /* USB_HOST, PATH: AP_USB */
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900609 ret = max77693_muic_set_path(info, CONTROL1_SW_USB, attached);
610 if (ret < 0)
Chanwoo Choi19d32432013-02-13 18:35:08 +0900611 return ret;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900612 extcon_set_cable_state(info->edev, "USB-Host", attached);
613 break;
614 case MAX77693_MUIC_GND_AV_CABLE_LOAD:
Chanwoo Choi06bed0a2012-11-27 11:30:35 +0900615 /* Audio Video Cable with load, PATH:AUDIO */
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900616 ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached);
617 if (ret < 0)
Chanwoo Choi19d32432013-02-13 18:35:08 +0900618 return ret;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900619 extcon_set_cable_state(info->edev,
620 "Audio-video-load", attached);
621 break;
Chanwoo Choi06bed0a2012-11-27 11:30:35 +0900622 case MAX77693_MUIC_GND_MHL:
623 case MAX77693_MUIC_GND_MHL_VB:
624 /* MHL or MHL with USB/TA cable */
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900625 extcon_set_cable_state(info->edev, "MHL", attached);
626 break;
627 default:
Chanwoo Choi19d32432013-02-13 18:35:08 +0900628 dev_err(info->dev, "failed to detect %s cable of gnd type\n",
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900629 attached ? "attached" : "detached");
Chanwoo Choi19d32432013-02-13 18:35:08 +0900630 return -EINVAL;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900631 }
632
Chanwoo Choi19d32432013-02-13 18:35:08 +0900633 return 0;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900634}
635
Chanwoo Choid0587eb2012-11-27 12:06:49 +0900636static int max77693_muic_jig_handler(struct max77693_muic_info *info,
637 int cable_type, bool attached)
638{
Chanwoo Choid0587eb2012-11-27 12:06:49 +0900639 int ret = 0;
640 u8 path = CONTROL1_SW_OPEN;
641
642 dev_info(info->dev,
643 "external connector is %s (adc:0x%02x)\n",
644 attached ? "attached" : "detached", cable_type);
645
646 switch (cable_type) {
647 case MAX77693_MUIC_ADC_FACTORY_MODE_USB_OFF: /* ADC_JIG_USB_OFF */
Chanwoo Choid0587eb2012-11-27 12:06:49 +0900648 case MAX77693_MUIC_ADC_FACTORY_MODE_USB_ON: /* ADC_JIG_USB_ON */
649 /* PATH:AP_USB */
Chanwoo Choid0587eb2012-11-27 12:06:49 +0900650 path = CONTROL1_SW_USB;
651 break;
652 case MAX77693_MUIC_ADC_FACTORY_MODE_UART_OFF: /* ADC_JIG_UART_OFF */
Krzysztof Kozlowskic22159a2014-10-22 10:45:40 +0200653 case MAX77693_MUIC_ADC_FACTORY_MODE_UART_ON: /* ADC_JIG_UART_ON */
654 /* PATH:AP_UART */
Krzysztof Kozlowskic22159a2014-10-22 10:45:40 +0200655 path = CONTROL1_SW_UART;
656 break;
Chanwoo Choi19d32432013-02-13 18:35:08 +0900657 default:
658 dev_err(info->dev, "failed to detect %s jig cable\n",
659 attached ? "attached" : "detached");
660 return -EINVAL;
Chanwoo Choid0587eb2012-11-27 12:06:49 +0900661 }
662
663 ret = max77693_muic_set_path(info, path, attached);
664 if (ret < 0)
Chanwoo Choi19d32432013-02-13 18:35:08 +0900665 return ret;
Chanwoo Choid0587eb2012-11-27 12:06:49 +0900666
Chanwoo Choi41b3c012015-04-24 19:50:48 +0900667 extcon_set_cable_state(info->edev, "JIG", attached);
Chanwoo Choi19d32432013-02-13 18:35:08 +0900668
669 return 0;
Chanwoo Choid0587eb2012-11-27 12:06:49 +0900670}
671
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900672static int max77693_muic_adc_handler(struct max77693_muic_info *info)
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900673{
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900674 int cable_type;
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900675 int button_type;
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900676 bool attached;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900677 int ret = 0;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900678
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900679 /* Check accessory state which is either detached or attached */
680 cable_type = max77693_muic_get_cable_type(info,
681 MAX77693_CABLE_GROUP_ADC, &attached);
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900682
683 dev_info(info->dev,
684 "external connector is %s (adc:0x%02x, prev_adc:0x%x)\n",
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900685 attached ? "attached" : "detached", cable_type,
686 info->prev_cable_type);
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900687
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900688 switch (cable_type) {
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900689 case MAX77693_MUIC_ADC_GROUND:
Jaewon Kim4c883ab2015-01-29 17:45:24 +0900690 /* USB_HOST/MHL/Audio */
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900691 max77693_muic_adc_ground_handler(info);
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900692 break;
693 case MAX77693_MUIC_ADC_FACTORY_MODE_USB_OFF:
694 case MAX77693_MUIC_ADC_FACTORY_MODE_USB_ON:
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900695 case MAX77693_MUIC_ADC_FACTORY_MODE_UART_OFF:
Krzysztof Kozlowskic22159a2014-10-22 10:45:40 +0200696 case MAX77693_MUIC_ADC_FACTORY_MODE_UART_ON:
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900697 /* JIG */
Chanwoo Choid0587eb2012-11-27 12:06:49 +0900698 ret = max77693_muic_jig_handler(info, cable_type, attached);
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900699 if (ret < 0)
Chanwoo Choi19d32432013-02-13 18:35:08 +0900700 return ret;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900701 break;
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900702 case MAX77693_MUIC_ADC_RESERVED_ACC_3: /* Dock-Smart */
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900703 case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk */
704 case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */
705 /*
706 * DOCK device
707 *
708 * The MAX77693 MUIC device can detect total 34 cable type
709 * except of charger cable and MUIC device didn't define
710 * specfic role of cable in the range of from 0x01 to 0x12
711 * of ADC value. So, can use/define cable with no role according
712 * to schema of hardware board.
713 */
714 ret = max77693_muic_dock_handler(info, cable_type, attached);
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900715 if (ret < 0)
Chanwoo Choi19d32432013-02-13 18:35:08 +0900716 return ret;
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900717 break;
Chanwoo Choic2275d22013-08-23 10:21:37 +0900718 case MAX77693_MUIC_ADC_REMOTE_S3_BUTTON: /* DOCK_KEY_PREV */
719 case MAX77693_MUIC_ADC_REMOTE_S7_BUTTON: /* DOCK_KEY_NEXT */
720 case MAX77693_MUIC_ADC_REMOTE_S9_BUTTON: /* DOCK_VOL_DOWN */
721 case MAX77693_MUIC_ADC_REMOTE_S10_BUTTON: /* DOCK_VOL_UP */
722 case MAX77693_MUIC_ADC_REMOTE_S12_BUTTON: /* DOCK_KEY_PLAY_PAUSE */
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900723 /*
724 * Button of DOCK device
725 * - the Prev/Next/Volume Up/Volume Down/Play-Pause button
726 *
727 * The MAX77693 MUIC device can detect total 34 cable type
728 * except of charger cable and MUIC device didn't define
729 * specfic role of cable in the range of from 0x01 to 0x12
730 * of ADC value. So, can use/define cable with no role according
731 * to schema of hardware board.
732 */
733 if (attached)
734 button_type = info->prev_button_type = cable_type;
735 else
736 button_type = info->prev_button_type;
737
738 ret = max77693_muic_dock_button_handler(info, button_type,
739 attached);
740 if (ret < 0)
Chanwoo Choi19d32432013-02-13 18:35:08 +0900741 return ret;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900742 break;
743 case MAX77693_MUIC_ADC_SEND_END_BUTTON:
744 case MAX77693_MUIC_ADC_REMOTE_S1_BUTTON:
745 case MAX77693_MUIC_ADC_REMOTE_S2_BUTTON:
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900746 case MAX77693_MUIC_ADC_REMOTE_S4_BUTTON:
747 case MAX77693_MUIC_ADC_REMOTE_S5_BUTTON:
748 case MAX77693_MUIC_ADC_REMOTE_S6_BUTTON:
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900749 case MAX77693_MUIC_ADC_REMOTE_S8_BUTTON:
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900750 case MAX77693_MUIC_ADC_REMOTE_S11_BUTTON:
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900751 case MAX77693_MUIC_ADC_RESERVED_ACC_1:
752 case MAX77693_MUIC_ADC_RESERVED_ACC_2:
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900753 case MAX77693_MUIC_ADC_RESERVED_ACC_4:
754 case MAX77693_MUIC_ADC_RESERVED_ACC_5:
755 case MAX77693_MUIC_ADC_CEA936_AUDIO:
756 case MAX77693_MUIC_ADC_PHONE_POWERED_DEV:
757 case MAX77693_MUIC_ADC_TTY_CONVERTER:
758 case MAX77693_MUIC_ADC_UART_CABLE:
759 case MAX77693_MUIC_ADC_CEA936A_TYPE1_CHG:
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900760 case MAX77693_MUIC_ADC_CEA936A_TYPE2_CHG:
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900761 /*
762 * This accessory isn't used in general case if it is specially
763 * needed to detect additional accessory, should implement
764 * proper operation when this accessory is attached/detached.
765 */
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900766 dev_info(info->dev,
767 "accessory is %s but it isn't used (adc:0x%x)\n",
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900768 attached ? "attached" : "detached", cable_type);
Chanwoo Choi19d32432013-02-13 18:35:08 +0900769 return -EAGAIN;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900770 default:
771 dev_err(info->dev,
772 "failed to detect %s accessory (adc:0x%x)\n",
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900773 attached ? "attached" : "detached", cable_type);
Chanwoo Choi19d32432013-02-13 18:35:08 +0900774 return -EINVAL;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900775 }
776
Chanwoo Choi19d32432013-02-13 18:35:08 +0900777 return 0;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900778}
779
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900780static int max77693_muic_chg_handler(struct max77693_muic_info *info)
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900781{
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900782 int chg_type;
Chanwoo Choi06bed0a2012-11-27 11:30:35 +0900783 int cable_type_gnd;
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900784 int cable_type;
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900785 bool attached;
Chanwoo Choi06bed0a2012-11-27 11:30:35 +0900786 bool cable_attached;
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900787 int ret = 0;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900788
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900789 chg_type = max77693_muic_get_cable_type(info,
790 MAX77693_CABLE_GROUP_CHG, &attached);
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900791
792 dev_info(info->dev,
793 "external connector is %s(chg_type:0x%x, prev_chg_type:0x%x)\n",
794 attached ? "attached" : "detached",
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900795 chg_type, info->prev_chg_type);
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900796
797 switch (chg_type) {
798 case MAX77693_CHARGER_TYPE_USB:
Chanwoo Choia1626292012-12-10 19:07:53 +0900799 case MAX77693_CHARGER_TYPE_DEDICATED_CHG:
Chanwoo Choi0e2738f2012-12-06 21:36:18 +0900800 case MAX77693_CHARGER_TYPE_NONE:
Chanwoo Choia1626292012-12-10 19:07:53 +0900801 /* Check MAX77693_CABLE_GROUP_ADC_GND type */
Chanwoo Choi06bed0a2012-11-27 11:30:35 +0900802 cable_type_gnd = max77693_muic_get_cable_type(info,
803 MAX77693_CABLE_GROUP_ADC_GND,
804 &cable_attached);
Chanwoo Choia1626292012-12-10 19:07:53 +0900805 switch (cable_type_gnd) {
806 case MAX77693_MUIC_GND_MHL:
807 case MAX77693_MUIC_GND_MHL_VB:
808 /*
Jaewon Kim4f0be262015-01-29 17:45:23 +0900809 * MHL cable with MHL-TA(USB/TA) cable
Chanwoo Choic2275d22013-08-23 10:21:37 +0900810 * - MHL cable include two port(HDMI line and separate
811 * micro-usb port. When the target connect MHL cable,
Jaewon Kim4f0be262015-01-29 17:45:23 +0900812 * extcon driver check whether MHL-TA(USB/TA) cable is
813 * connected. If MHL-TA cable is connected, extcon
Chanwoo Choic2275d22013-08-23 10:21:37 +0900814 * driver notify state to notifiee for charging battery.
Chanwoo Choia1626292012-12-10 19:07:53 +0900815 *
Jaewon Kim4f0be262015-01-29 17:45:23 +0900816 * Features of 'MHL-TA(USB/TA) with MHL cable'
Chanwoo Choia1626292012-12-10 19:07:53 +0900817 * - Support MHL
Chanwoo Choic2275d22013-08-23 10:21:37 +0900818 * - Support charging through micro-usb port without
819 * data connection
Chanwoo Choia1626292012-12-10 19:07:53 +0900820 */
Jaewon Kim4f0be262015-01-29 17:45:23 +0900821 extcon_set_cable_state(info->edev, "MHL-TA", attached);
Chanwoo Choi06bed0a2012-11-27 11:30:35 +0900822 if (!cable_attached)
Chanwoo Choic2275d22013-08-23 10:21:37 +0900823 extcon_set_cable_state(info->edev,
824 "MHL", cable_attached);
Chanwoo Choia1626292012-12-10 19:07:53 +0900825 break;
Chanwoo Choi06bed0a2012-11-27 11:30:35 +0900826 }
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900827
Chanwoo Choia1626292012-12-10 19:07:53 +0900828 /* Check MAX77693_CABLE_GROUP_ADC type */
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900829 cable_type = max77693_muic_get_cable_type(info,
830 MAX77693_CABLE_GROUP_ADC,
831 &cable_attached);
Chanwoo Choia1626292012-12-10 19:07:53 +0900832 switch (cable_type) {
833 case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */
834 /*
835 * Dock-Audio device with USB/TA cable
Chanwoo Choic2275d22013-08-23 10:21:37 +0900836 * - Dock device include two port(Dock-Audio and micro-
837 * usb port). When the target connect Dock-Audio device,
838 * extcon driver check whether USB/TA cable is connected
839 * or not. If USB/TA cable is connected, extcon driver
840 * notify state to notifiee for charging battery.
Chanwoo Choia1626292012-12-10 19:07:53 +0900841 *
842 * Features of 'USB/TA cable with Dock-Audio device'
843 * - Support external output feature of audio.
Chanwoo Choic2275d22013-08-23 10:21:37 +0900844 * - Support charging through micro-usb port without
845 * data connection.
Chanwoo Choia1626292012-12-10 19:07:53 +0900846 */
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900847 extcon_set_cable_state(info->edev, "USB", attached);
848
849 if (!cable_attached)
Chanwoo Choic2275d22013-08-23 10:21:37 +0900850 extcon_set_cable_state(info->edev, "Dock-Audio",
851 cable_attached);
Chanwoo Choia1626292012-12-10 19:07:53 +0900852 break;
853 case MAX77693_MUIC_ADC_RESERVED_ACC_3: /* Dock-Smart */
854 /*
855 * Dock-Smart device with USB/TA cable
856 * - Dock-Desk device include three type of cable which
857 * are HDMI, USB for mouse/keyboard and micro-usb port
Chanwoo Choic2275d22013-08-23 10:21:37 +0900858 * for USB/TA cable. Dock-Smart device need always
859 * exteranl power supply(USB/TA cable through micro-usb
860 * cable). Dock-Smart device support screen output of
861 * target to separate monitor and mouse/keyboard for
862 * desktop mode.
Chanwoo Choia1626292012-12-10 19:07:53 +0900863 *
864 * Features of 'USB/TA cable with Dock-Smart device'
865 * - Support MHL
866 * - Support external output feature of audio
Chanwoo Choic2275d22013-08-23 10:21:37 +0900867 * - Support charging through micro-usb port without
868 * data connection if TA cable is connected to target.
869 * - Support charging and data connection through micro-
870 * usb port if USB cable is connected between target
871 * and host device
Jaewon Kim4c883ab2015-01-29 17:45:24 +0900872 * - Support OTG(On-The-Go) device (Ex: Mouse/Keyboard)
Chanwoo Choia1626292012-12-10 19:07:53 +0900873 */
Chanwoo Choic2275d22013-08-23 10:21:37 +0900874 ret = max77693_muic_set_path(info, info->path_usb,
875 attached);
Chanwoo Choia1626292012-12-10 19:07:53 +0900876 if (ret < 0)
877 return ret;
878
Chanwoo Choic2275d22013-08-23 10:21:37 +0900879 extcon_set_cable_state(info->edev, "Dock-Smart",
880 attached);
Chanwoo Choia1626292012-12-10 19:07:53 +0900881 extcon_set_cable_state(info->edev, "MHL", attached);
882
883 break;
Chanwoo Choi39bf3692012-12-03 13:09:41 +0900884 }
885
Chanwoo Choia1626292012-12-10 19:07:53 +0900886 /* Check MAX77693_CABLE_GROUP_CHG type */
887 switch (chg_type) {
888 case MAX77693_CHARGER_TYPE_NONE:
889 /*
Chanwoo Choic2275d22013-08-23 10:21:37 +0900890 * When MHL(with USB/TA cable) or Dock-Audio with USB/TA
891 * cable is attached, muic device happen below two irq.
892 * - 'MAX77693_MUIC_IRQ_INT1_ADC' for detecting
893 * MHL/Dock-Audio.
894 * - 'MAX77693_MUIC_IRQ_INT2_CHGTYP' for detecting
895 * USB/TA cable connected to MHL or Dock-Audio.
896 * Always, happen eariler MAX77693_MUIC_IRQ_INT1_ADC
897 * irq than MAX77693_MUIC_IRQ_INT2_CHGTYP irq.
Chanwoo Choia1626292012-12-10 19:07:53 +0900898 *
Chanwoo Choic2275d22013-08-23 10:21:37 +0900899 * If user attach MHL (with USB/TA cable and immediately
900 * detach MHL with USB/TA cable before MAX77693_MUIC_IRQ
901 * _INT2_CHGTYP irq is happened, USB/TA cable remain
902 * connected state to target. But USB/TA cable isn't
903 * connected to target. The user be face with unusual
904 * action. So, driver should check this situation in
905 * spite of, that previous charger type is N/A.
Chanwoo Choia1626292012-12-10 19:07:53 +0900906 */
Chanwoo Choi0e2738f2012-12-06 21:36:18 +0900907 break;
Chanwoo Choia1626292012-12-10 19:07:53 +0900908 case MAX77693_CHARGER_TYPE_USB:
909 /* Only USB cable, PATH:AP_USB */
Chanwoo Choic2275d22013-08-23 10:21:37 +0900910 ret = max77693_muic_set_path(info, info->path_usb,
911 attached);
Chanwoo Choia1626292012-12-10 19:07:53 +0900912 if (ret < 0)
913 return ret;
Chanwoo Choi0e2738f2012-12-06 21:36:18 +0900914
Chanwoo Choia1626292012-12-10 19:07:53 +0900915 extcon_set_cable_state(info->edev, "USB", attached);
916 break;
917 case MAX77693_CHARGER_TYPE_DEDICATED_CHG:
918 /* Only TA cable */
919 extcon_set_cable_state(info->edev, "TA", attached);
920 break;
921 }
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900922 break;
923 case MAX77693_CHARGER_TYPE_DOWNSTREAM_PORT:
924 extcon_set_cable_state(info->edev,
925 "Charge-downstream", attached);
926 break;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900927 case MAX77693_CHARGER_TYPE_APPLE_500MA:
928 extcon_set_cable_state(info->edev, "Slow-charger", attached);
929 break;
930 case MAX77693_CHARGER_TYPE_APPLE_1A_2A:
931 extcon_set_cable_state(info->edev, "Fast-charger", attached);
932 break;
933 case MAX77693_CHARGER_TYPE_DEAD_BATTERY:
934 break;
935 default:
936 dev_err(info->dev,
937 "failed to detect %s accessory (chg_type:0x%x)\n",
938 attached ? "attached" : "detached", chg_type);
Chanwoo Choia1626292012-12-10 19:07:53 +0900939 return -EINVAL;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900940 }
941
Chanwoo Choia1626292012-12-10 19:07:53 +0900942 return 0;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900943}
944
945static void max77693_muic_irq_work(struct work_struct *work)
946{
947 struct max77693_muic_info *info = container_of(work,
948 struct max77693_muic_info, irq_work);
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900949 int irq_type = -1;
950 int i, ret = 0;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900951
952 if (!info->edev)
953 return;
954
955 mutex_lock(&info->mutex);
956
Sachin Kamata33411b2013-08-05 14:32:04 +0530957 for (i = 0; i < ARRAY_SIZE(muic_irqs); i++)
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900958 if (info->irq == muic_irqs[i].virq)
959 irq_type = muic_irqs[i].irq;
960
Robert Baldygad0540f92014-05-21 08:52:47 +0200961 ret = regmap_bulk_read(info->max77693->regmap_muic,
962 MAX77693_MUIC_REG_STATUS1, info->status, 2);
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900963 if (ret) {
964 dev_err(info->dev, "failed to read MUIC register\n");
965 mutex_unlock(&info->mutex);
966 return;
967 }
968
969 switch (irq_type) {
970 case MAX77693_MUIC_IRQ_INT1_ADC:
971 case MAX77693_MUIC_IRQ_INT1_ADC_LOW:
972 case MAX77693_MUIC_IRQ_INT1_ADC_ERR:
973 case MAX77693_MUIC_IRQ_INT1_ADC1K:
974 /* Handle all of accessory except for
975 type of charger accessory */
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900976 ret = max77693_muic_adc_handler(info);
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900977 break;
978 case MAX77693_MUIC_IRQ_INT2_CHGTYP:
979 case MAX77693_MUIC_IRQ_INT2_CHGDETREUN:
980 case MAX77693_MUIC_IRQ_INT2_DCDTMR:
981 case MAX77693_MUIC_IRQ_INT2_DXOVP:
982 case MAX77693_MUIC_IRQ_INT2_VBVOLT:
983 case MAX77693_MUIC_IRQ_INT2_VIDRM:
984 /* Handle charger accessory */
Chanwoo Choi154f757f2012-11-27 09:40:32 +0900985 ret = max77693_muic_chg_handler(info);
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900986 break;
987 case MAX77693_MUIC_IRQ_INT3_EOC:
988 case MAX77693_MUIC_IRQ_INT3_CGMBC:
989 case MAX77693_MUIC_IRQ_INT3_OVP:
990 case MAX77693_MUIC_IRQ_INT3_MBCCHG_ERR:
991 case MAX77693_MUIC_IRQ_INT3_CHG_ENABLED:
992 case MAX77693_MUIC_IRQ_INT3_BAT_DET:
993 break;
994 default:
995 dev_err(info->dev, "muic interrupt: irq %d occurred\n",
996 irq_type);
Chanwoo Choi19d32432013-02-13 18:35:08 +0900997 mutex_unlock(&info->mutex);
998 return;
Chanwoo Choidb1b9032012-07-17 13:28:28 +0900999 }
1000
1001 if (ret < 0)
1002 dev_err(info->dev, "failed to handle MUIC interrupt\n");
1003
1004 mutex_unlock(&info->mutex);
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001005}
1006
1007static irqreturn_t max77693_muic_irq_handler(int irq, void *data)
1008{
1009 struct max77693_muic_info *info = data;
1010
1011 info->irq = irq;
1012 schedule_work(&info->irq_work);
1013
1014 return IRQ_HANDLED;
1015}
1016
Krzysztof Kozlowski65948902015-01-05 09:57:27 +01001017static const struct regmap_config max77693_muic_regmap_config = {
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001018 .reg_bits = 8,
1019 .val_bits = 8,
1020};
1021
1022static int max77693_muic_detect_accessory(struct max77693_muic_info *info)
1023{
1024 int ret = 0;
Chanwoo Choi154f757f2012-11-27 09:40:32 +09001025 int adc;
1026 int chg_type;
1027 bool attached;
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001028
1029 mutex_lock(&info->mutex);
1030
1031 /* Read STATUSx register to detect accessory */
Robert Baldygad0540f92014-05-21 08:52:47 +02001032 ret = regmap_bulk_read(info->max77693->regmap_muic,
1033 MAX77693_MUIC_REG_STATUS1, info->status, 2);
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001034 if (ret) {
1035 dev_err(info->dev, "failed to read MUIC register\n");
1036 mutex_unlock(&info->mutex);
Sachin Kamatc2536542013-04-08 09:12:32 +09001037 return ret;
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001038 }
1039
Chanwoo Choi154f757f2012-11-27 09:40:32 +09001040 adc = max77693_muic_get_cable_type(info, MAX77693_CABLE_GROUP_ADC,
1041 &attached);
1042 if (attached && adc != MAX77693_MUIC_ADC_OPEN) {
1043 ret = max77693_muic_adc_handler(info);
Chanwoo Choi19d32432013-02-13 18:35:08 +09001044 if (ret < 0) {
Chanwoo Choi154f757f2012-11-27 09:40:32 +09001045 dev_err(info->dev, "Cannot detect accessory\n");
Chanwoo Choi19d32432013-02-13 18:35:08 +09001046 mutex_unlock(&info->mutex);
1047 return ret;
1048 }
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001049 }
1050
Chanwoo Choi154f757f2012-11-27 09:40:32 +09001051 chg_type = max77693_muic_get_cable_type(info, MAX77693_CABLE_GROUP_CHG,
1052 &attached);
1053 if (attached && chg_type != MAX77693_CHARGER_TYPE_NONE) {
1054 ret = max77693_muic_chg_handler(info);
Chanwoo Choi19d32432013-02-13 18:35:08 +09001055 if (ret < 0) {
Chanwoo Choi154f757f2012-11-27 09:40:32 +09001056 dev_err(info->dev, "Cannot detect charger accessory\n");
Chanwoo Choi19d32432013-02-13 18:35:08 +09001057 mutex_unlock(&info->mutex);
1058 return ret;
1059 }
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001060 }
1061
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001062 mutex_unlock(&info->mutex);
Chanwoo Choi154f757f2012-11-27 09:40:32 +09001063
Chanwoo Choi19d32432013-02-13 18:35:08 +09001064 return 0;
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001065}
1066
Chanwoo Choi297620f2012-12-26 13:10:11 +09001067static void max77693_muic_detect_cable_wq(struct work_struct *work)
1068{
1069 struct max77693_muic_info *info = container_of(to_delayed_work(work),
1070 struct max77693_muic_info, wq_detcable);
1071
1072 max77693_muic_detect_accessory(info);
1073}
1074
Bill Pemberton44f34fd2012-11-19 13:23:21 -05001075static int max77693_muic_probe(struct platform_device *pdev)
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001076{
1077 struct max77693_dev *max77693 = dev_get_drvdata(pdev->dev.parent);
Chanwoo Choif8457d572012-10-08 14:41:49 +09001078 struct max77693_platform_data *pdata = dev_get_platdata(max77693->dev);
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001079 struct max77693_muic_info *info;
Chanwoo Choi0ec83bd2013-03-13 17:38:57 +09001080 struct max77693_reg_data *init_data;
1081 int num_init_data;
Chanwoo Choi297620f2012-12-26 13:10:11 +09001082 int delay_jiffies;
1083 int ret;
1084 int i;
Robert Baldygad0540f92014-05-21 08:52:47 +02001085 unsigned int id;
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001086
Sachin Kamatf4bb5cb2012-11-20 15:46:50 +09001087 info = devm_kzalloc(&pdev->dev, sizeof(struct max77693_muic_info),
1088 GFP_KERNEL);
Jingoo Han0a16ee62014-07-23 10:07:09 +09001089 if (!info)
Sachin Kamatf4bb5cb2012-11-20 15:46:50 +09001090 return -ENOMEM;
Jingoo Han0a16ee62014-07-23 10:07:09 +09001091
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001092 info->dev = &pdev->dev;
1093 info->max77693 = max77693;
Sachin Kamat1967fa02012-11-21 10:04:58 +05301094 if (info->max77693->regmap_muic) {
Chanwoo Choib186b122012-08-21 15:16:23 +09001095 dev_dbg(&pdev->dev, "allocate register map\n");
Sachin Kamat1967fa02012-11-21 10:04:58 +05301096 } else {
Chanwoo Choib186b122012-08-21 15:16:23 +09001097 info->max77693->regmap_muic = devm_regmap_init_i2c(
1098 info->max77693->muic,
1099 &max77693_muic_regmap_config);
1100 if (IS_ERR(info->max77693->regmap_muic)) {
1101 ret = PTR_ERR(info->max77693->regmap_muic);
1102 dev_err(max77693->dev,
1103 "failed to allocate register map: %d\n", ret);
Sachin Kamat3bf742f2012-11-21 10:04:57 +05301104 return ret;
Chanwoo Choib186b122012-08-21 15:16:23 +09001105 }
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001106 }
Chanwoo Choi39bf3692012-12-03 13:09:41 +09001107
1108 /* Register input device for button of dock device */
Chanwoo Choieff7d742013-02-13 18:35:05 +09001109 info->dock = devm_input_allocate_device(&pdev->dev);
Chanwoo Choi39bf3692012-12-03 13:09:41 +09001110 if (!info->dock) {
1111 dev_err(&pdev->dev, "%s: failed to allocate input\n", __func__);
1112 return -ENOMEM;
1113 }
1114 info->dock->name = "max77693-muic/dock";
1115 info->dock->phys = "max77693-muic/extcon";
1116 info->dock->dev.parent = &pdev->dev;
1117
1118 __set_bit(EV_REP, info->dock->evbit);
1119
1120 input_set_capability(info->dock, EV_KEY, KEY_VOLUMEUP);
1121 input_set_capability(info->dock, EV_KEY, KEY_VOLUMEDOWN);
1122 input_set_capability(info->dock, EV_KEY, KEY_PLAYPAUSE);
1123 input_set_capability(info->dock, EV_KEY, KEY_PREVIOUSSONG);
1124 input_set_capability(info->dock, EV_KEY, KEY_NEXTSONG);
1125
1126 ret = input_register_device(info->dock);
1127 if (ret < 0) {
1128 dev_err(&pdev->dev, "Cannot register input device error(%d)\n",
1129 ret);
1130 return ret;
1131 }
1132
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001133 platform_set_drvdata(pdev, info);
1134 mutex_init(&info->mutex);
1135
1136 INIT_WORK(&info->irq_work, max77693_muic_irq_work);
1137
1138 /* Support irq domain for MAX77693 MUIC device */
1139 for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) {
1140 struct max77693_muic_irq *muic_irq = &muic_irqs[i];
Sachin Kamat00af4b12012-11-20 15:46:44 +09001141 unsigned int virq = 0;
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001142
Robert Baldyga342d6692014-05-21 08:52:48 +02001143 virq = regmap_irq_get_virq(max77693->irq_data_muic,
1144 muic_irq->irq);
Krzysztof Kozlowskid7155232014-09-12 15:16:37 +02001145 if (!virq)
1146 return -EINVAL;
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001147 muic_irq->virq = virq;
1148
Krzysztof Kozlowskid7155232014-09-12 15:16:37 +02001149 ret = devm_request_threaded_irq(&pdev->dev, virq, NULL,
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001150 max77693_muic_irq_handler,
Chanwoo Choiae3b3212012-11-28 12:39:01 +09001151 IRQF_NO_SUSPEND,
1152 muic_irq->name, info);
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001153 if (ret) {
1154 dev_err(&pdev->dev,
Chanwoo Choi34825e52015-03-07 01:41:36 +09001155 "failed: irq request (IRQ: %d, error :%d)\n",
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001156 muic_irq->irq, ret);
Krzysztof Kozlowskid7155232014-09-12 15:16:37 +02001157 return ret;
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001158 }
1159 }
1160
1161 /* Initialize extcon device */
Chanwoo Choi577bef12014-04-21 20:39:53 +09001162 info->edev = devm_extcon_dev_allocate(&pdev->dev,
1163 max77693_extcon_cable);
1164 if (IS_ERR(info->edev)) {
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001165 dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
Krzysztof Kozlowskid7155232014-09-12 15:16:37 +02001166 return -ENOMEM;
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001167 }
1168 info->edev->name = DEV_NAME;
Chanwoo Choi577bef12014-04-21 20:39:53 +09001169
Sangjung Woo10fae112014-04-21 19:10:12 +09001170 ret = devm_extcon_dev_register(&pdev->dev, info->edev);
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001171 if (ret) {
1172 dev_err(&pdev->dev, "failed to register extcon device\n");
Krzysztof Kozlowskid7155232014-09-12 15:16:37 +02001173 return ret;
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001174 }
1175
Chanwoo Choi0ec83bd2013-03-13 17:38:57 +09001176 /* Initialize MUIC register by using platform data or default data */
Krzysztof Kozlowskid5653f22014-04-09 15:20:12 +02001177 if (pdata && pdata->muic_data) {
Chanwoo Choi0ec83bd2013-03-13 17:38:57 +09001178 init_data = pdata->muic_data->init_data;
1179 num_init_data = pdata->muic_data->num_init_data;
1180 } else {
1181 init_data = default_init_data;
1182 num_init_data = ARRAY_SIZE(default_init_data);
1183 }
1184
Sachin Kamata33411b2013-08-05 14:32:04 +05301185 for (i = 0; i < num_init_data; i++) {
Chanwoo Choi0ec83bd2013-03-13 17:38:57 +09001186 enum max77693_irq_source irq_src
1187 = MAX77693_IRQ_GROUP_NR;
1188
Robert Baldygad0540f92014-05-21 08:52:47 +02001189 regmap_write(info->max77693->regmap_muic,
Chanwoo Choi0ec83bd2013-03-13 17:38:57 +09001190 init_data[i].addr,
1191 init_data[i].data);
1192
1193 switch (init_data[i].addr) {
1194 case MAX77693_MUIC_REG_INTMASK1:
1195 irq_src = MUIC_INT1;
1196 break;
1197 case MAX77693_MUIC_REG_INTMASK2:
1198 irq_src = MUIC_INT2;
1199 break;
1200 case MAX77693_MUIC_REG_INTMASK3:
1201 irq_src = MUIC_INT3;
1202 break;
1203 }
1204
1205 if (irq_src < MAX77693_IRQ_GROUP_NR)
1206 info->max77693->irq_masks_cur[irq_src]
1207 = init_data[i].data;
1208 }
1209
Krzysztof Kozlowskid5653f22014-04-09 15:20:12 +02001210 if (pdata && pdata->muic_data) {
Chanwoo Choic2275d22013-08-23 10:21:37 +09001211 struct max77693_muic_platform_data *muic_pdata
1212 = pdata->muic_data;
Chanwoo Choif8457d572012-10-08 14:41:49 +09001213
Chanwoo Choi190d7cf2013-02-18 10:03:32 +09001214 /*
1215 * Default usb/uart path whether UART/USB or AUX_UART/AUX_USB
1216 * h/w path of COMP2/COMN1 on CONTROL1 register.
1217 */
1218 if (muic_pdata->path_uart)
1219 info->path_uart = muic_pdata->path_uart;
1220 else
1221 info->path_uart = CONTROL1_SW_UART;
Chanwoo Choif8457d572012-10-08 14:41:49 +09001222
Chanwoo Choi190d7cf2013-02-18 10:03:32 +09001223 if (muic_pdata->path_usb)
1224 info->path_usb = muic_pdata->path_usb;
1225 else
1226 info->path_usb = CONTROL1_SW_USB;
Chanwoo Choi2b757992012-12-06 21:27:56 +09001227
Chanwoo Choi190d7cf2013-02-18 10:03:32 +09001228 /*
1229 * Default delay time for detecting cable state
1230 * after certain time.
1231 */
1232 if (muic_pdata->detcable_delay_ms)
1233 delay_jiffies =
1234 msecs_to_jiffies(muic_pdata->detcable_delay_ms);
1235 else
1236 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
1237 } else {
Chanwoo Choi2b757992012-12-06 21:27:56 +09001238 info->path_usb = CONTROL1_SW_USB;
Chanwoo Choi190d7cf2013-02-18 10:03:32 +09001239 info->path_uart = CONTROL1_SW_UART;
1240 delay_jiffies = msecs_to_jiffies(DELAY_MS_DEFAULT);
1241 }
Chanwoo Choi2b757992012-12-06 21:27:56 +09001242
1243 /* Set initial path for UART */
1244 max77693_muic_set_path(info, info->path_uart, true);
1245
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001246 /* Check revision number of MUIC device*/
Robert Baldygad0540f92014-05-21 08:52:47 +02001247 ret = regmap_read(info->max77693->regmap_muic,
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001248 MAX77693_MUIC_REG_ID, &id);
1249 if (ret < 0) {
1250 dev_err(&pdev->dev, "failed to read revision number\n");
Krzysztof Kozlowskid7155232014-09-12 15:16:37 +02001251 return ret;
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001252 }
1253 dev_info(info->dev, "device ID : 0x%x\n", id);
1254
1255 /* Set ADC debounce time */
1256 max77693_muic_set_debounce_time(info, ADC_DEBOUNCE_TIME_25MS);
1257
Chanwoo Choi297620f2012-12-26 13:10:11 +09001258 /*
1259 * Detect accessory after completing the initialization of platform
1260 *
1261 * - Use delayed workqueue to detect cable state and then
1262 * notify cable state to notifiee/platform through uevent.
1263 * After completing the booting of platform, the extcon provider
1264 * driver should notify cable state to upper layer.
1265 */
1266 INIT_DELAYED_WORK(&info->wq_detcable, max77693_muic_detect_cable_wq);
Krzysztof Kozlowskib8629412014-04-09 15:20:13 +02001267 queue_delayed_work(system_power_efficient_wq, &info->wq_detcable,
1268 delay_jiffies);
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001269
1270 return ret;
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001271}
1272
Bill Pemberton93ed0322012-11-19 13:25:49 -05001273static int max77693_muic_remove(struct platform_device *pdev)
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001274{
1275 struct max77693_muic_info *info = platform_get_drvdata(pdev);
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001276
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001277 cancel_work_sync(&info->irq_work);
Chanwoo Choi39bf3692012-12-03 13:09:41 +09001278 input_unregister_device(info->dock);
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001279
1280 return 0;
1281}
1282
1283static struct platform_driver max77693_muic_driver = {
1284 .driver = {
1285 .name = DEV_NAME,
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001286 },
1287 .probe = max77693_muic_probe,
Bill Pemberton5f7e2222012-11-19 13:20:06 -05001288 .remove = max77693_muic_remove,
Chanwoo Choidb1b9032012-07-17 13:28:28 +09001289};
1290
1291module_platform_driver(max77693_muic_driver);
1292
1293MODULE_DESCRIPTION("Maxim MAX77693 Extcon driver");
1294MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
1295MODULE_LICENSE("GPL");
1296MODULE_ALIAS("platform:extcon-max77693");