blob: 8739b50c2b36603e3f77e14a604157deb0256286 [file] [log] [blame]
Donggeun Kim99f09be2011-11-24 18:12:18 +09001/*
Chanwoo Choib76668b2012-05-09 12:31:58 +09002 * extcon-max8997.c - MAX8997 extcon driver to support MAX8997 MUIC
Donggeun Kim99f09be2011-11-24 18:12:18 +09003 *
Sachin Kamat2ca36f42012-11-20 15:46:33 +09004 * Copyright (C) 2012 Samsung Electronics
Donggeun Kim99f09be2011-11-24 18:12:18 +09005 * Donggeun Kim <dg77.kim@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.
Donggeun Kim99f09be2011-11-24 18:12:18 +090016 */
17
18#include <linux/kernel.h>
19#include <linux/module.h>
20#include <linux/i2c.h>
21#include <linux/slab.h>
22#include <linux/interrupt.h>
23#include <linux/err.h>
24#include <linux/platform_device.h>
25#include <linux/kobject.h>
26#include <linux/mfd/max8997.h>
27#include <linux/mfd/max8997-private.h>
Chanwoo Choib76668b2012-05-09 12:31:58 +090028#include <linux/extcon.h>
Chanwoo Choidca1a712012-07-02 09:03:00 +090029#include <linux/irqdomain.h>
Chanwoo Choib76668b2012-05-09 12:31:58 +090030
31#define DEV_NAME "max8997-muic"
Donggeun Kim99f09be2011-11-24 18:12:18 +090032
Donggeun Kim99f09be2011-11-24 18:12:18 +090033struct max8997_muic_irq {
34 unsigned int irq;
35 const char *name;
Chanwoo Choidca1a712012-07-02 09:03:00 +090036 unsigned int virq;
Donggeun Kim99f09be2011-11-24 18:12:18 +090037};
38
39static struct max8997_muic_irq muic_irqs[] = {
40 { MAX8997_MUICIRQ_ADCError, "muic-ADC_error" },
41 { MAX8997_MUICIRQ_ADCLow, "muic-ADC_low" },
42 { MAX8997_MUICIRQ_ADC, "muic-ADC" },
43 { MAX8997_MUICIRQ_VBVolt, "muic-VB_voltage" },
44 { MAX8997_MUICIRQ_DBChg, "muic-DB_charger" },
45 { MAX8997_MUICIRQ_DCDTmr, "muic-DCD_timer" },
46 { MAX8997_MUICIRQ_ChgDetRun, "muic-CDR_status" },
47 { MAX8997_MUICIRQ_ChgTyp, "muic-charger_type" },
48 { MAX8997_MUICIRQ_OVP, "muic-over_voltage" },
49};
50
51struct max8997_muic_info {
52 struct device *dev;
Donggeun Kim99f09be2011-11-24 18:12:18 +090053 struct i2c_client *muic;
54 struct max8997_muic_platform_data *muic_pdata;
55
56 int irq;
57 struct work_struct irq_work;
58
59 enum max8997_muic_charger_type pre_charger_type;
60 int pre_adc;
61
62 struct mutex mutex;
Chanwoo Choib76668b2012-05-09 12:31:58 +090063
64 struct extcon_dev *edev;
65};
66
Chanwoo Choie3e5bc02013-02-12 20:44:19 +090067enum {
68 EXTCON_CABLE_USB = 0,
69 EXTCON_CABLE_USB_HOST,
70 EXTCON_CABLE_TA,
71 EXTCON_CABLE_FAST_CHARGER,
72 EXTCON_CABLE_SLOW_CHARGER,
73 EXTCON_CABLE_CHARGE_DOWNSTREAM,
74 EXTCON_CABLE_MHL,
75 EXTCON_CABLE_DOCK_DESK,
76 EXTCON_CABLE_DOCK_CARD,
77 EXTCON_CABLE_JIG,
78
79 _EXTCON_CABLE_NUM,
80};
81
Sachin Kamatcae93db2013-01-31 09:29:29 +090082static const char *max8997_extcon_cable[] = {
Chanwoo Choie3e5bc02013-02-12 20:44:19 +090083 [EXTCON_CABLE_USB] = "USB",
84 [EXTCON_CABLE_USB_HOST] = "USB-Host",
85 [EXTCON_CABLE_TA] = "TA",
86 [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger",
87 [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger",
88 [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream",
89 [EXTCON_CABLE_MHL] = "MHL",
90 [EXTCON_CABLE_DOCK_DESK] = "Dock-Desk",
91 [EXTCON_CABLE_DOCK_CARD] = "Dock-Card",
92 [EXTCON_CABLE_JIG] = "JIG",
Chanwoo Choib76668b2012-05-09 12:31:58 +090093
94 NULL,
Donggeun Kim99f09be2011-11-24 18:12:18 +090095};
96
Chanwoo Choi07c70502013-02-13 08:42:37 +090097/*
98 * max8997_muic_set_path - Set hardware line according to attached cable
99 * @info: the instance including private data of max8997 MUIC
100 * @value: the path according to attached cable
101 * @attached: the state of cable (true:attached, false:detached)
102 *
103 * The max8997 MUIC device share outside H/W line among a varity of cables,
104 * so this function set internal path of H/W line according to the type of
105 * attached cable.
106 */
107static int max8997_muic_set_path(struct max8997_muic_info *info,
108 u8 val, bool attached)
109{
110 int ret = 0;
111 u8 ctrl1, ctrl2 = 0;
112
113 if (attached)
114 ctrl1 = val;
115 else
116 ctrl1 = CONTROL1_SW_OPEN;
117
118 ret = max8997_update_reg(info->muic,
119 MAX8997_MUIC_REG_CONTROL1, ctrl1, COMP_SW_MASK);
120 if (ret < 0) {
121 dev_err(info->dev, "failed to update MUIC register\n");
122 return -EAGAIN;
123 }
124
125 if (attached)
126 ctrl2 |= CONTROL2_CPEN_MASK; /* LowPwr=0, CPEn=1 */
127 else
128 ctrl2 |= CONTROL2_LOWPWR_MASK; /* LowPwr=1, CPEn=0 */
129
130 ret = max8997_update_reg(info->muic,
131 MAX8997_MUIC_REG_CONTROL2, ctrl2,
132 CONTROL2_LOWPWR_MASK | CONTROL2_CPEN_MASK);
133 if (ret < 0) {
134 dev_err(info->dev, "failed to update MUIC register\n");
135 return -EAGAIN;
136 }
137
138 dev_info(info->dev,
139 "CONTROL1 : 0x%02x, CONTROL2 : 0x%02x, state : %s\n",
140 ctrl1, ctrl2, attached ? "attached" : "detached");
141
142 return 0;
143}
144
Donggeun Kim99f09be2011-11-24 18:12:18 +0900145static int max8997_muic_handle_usb(struct max8997_muic_info *info,
146 enum max8997_muic_usb_type usb_type, bool attached)
147{
Donggeun Kim99f09be2011-11-24 18:12:18 +0900148 int ret = 0;
149
150 if (usb_type == MAX8997_USB_HOST) {
Chanwoo Choi07c70502013-02-13 08:42:37 +0900151 ret = max8997_muic_set_path(info, CONTROL1_SW_USB, attached);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900152 if (ret) {
153 dev_err(info->dev, "failed to update muic register\n");
154 goto out;
155 }
156 }
157
Chanwoo Choib76668b2012-05-09 12:31:58 +0900158 switch (usb_type) {
159 case MAX8997_USB_HOST:
160 extcon_set_cable_state(info->edev, "USB-Host", attached);
161 break;
162 case MAX8997_USB_DEVICE:
163 extcon_set_cable_state(info->edev, "USB", attached);
164 break;
165 default:
166 ret = -EINVAL;
167 break;
168 }
169
Donggeun Kim99f09be2011-11-24 18:12:18 +0900170out:
171 return ret;
172}
173
Donggeun Kim99f09be2011-11-24 18:12:18 +0900174static int max8997_muic_handle_dock(struct max8997_muic_info *info,
175 int adc, bool attached)
176{
Donggeun Kim99f09be2011-11-24 18:12:18 +0900177 int ret = 0;
178
Chanwoo Choi07c70502013-02-13 08:42:37 +0900179 ret = max8997_muic_set_path(info, CONTROL1_SW_AUDIO, attached);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900180 if (ret) {
181 dev_err(info->dev, "failed to update muic register\n");
182 goto out;
183 }
184
185 switch (adc) {
186 case MAX8997_ADC_DESKDOCK:
Chanwoo Choib76668b2012-05-09 12:31:58 +0900187 extcon_set_cable_state(info->edev, "Dock-desk", attached);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900188 break;
189 case MAX8997_ADC_CARDOCK:
Chanwoo Choib76668b2012-05-09 12:31:58 +0900190 extcon_set_cable_state(info->edev, "Dock-card", attached);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900191 break;
192 default:
Chanwoo Choib76668b2012-05-09 12:31:58 +0900193 ret = -EINVAL;
Donggeun Kim99f09be2011-11-24 18:12:18 +0900194 break;
195 }
196out:
197 return ret;
198}
199
200static int max8997_muic_handle_jig_uart(struct max8997_muic_info *info,
201 bool attached)
202{
Donggeun Kim99f09be2011-11-24 18:12:18 +0900203 int ret = 0;
204
205 /* switch to UART */
Chanwoo Choi07c70502013-02-13 08:42:37 +0900206 ret = max8997_muic_set_path(info, CONTROL1_SW_UART, attached);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900207 if (ret) {
208 dev_err(info->dev, "failed to update muic register\n");
209 goto out;
210 }
211
Chanwoo Choib76668b2012-05-09 12:31:58 +0900212 extcon_set_cable_state(info->edev, "JIG", attached);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900213out:
214 return ret;
215}
216
217static int max8997_muic_handle_adc_detach(struct max8997_muic_info *info)
218{
219 int ret = 0;
220
221 switch (info->pre_adc) {
222 case MAX8997_ADC_GROUND:
223 ret = max8997_muic_handle_usb(info, MAX8997_USB_HOST, false);
224 break;
225 case MAX8997_ADC_MHL:
Chanwoo Choib76668b2012-05-09 12:31:58 +0900226 extcon_set_cable_state(info->edev, "MHL", false);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900227 break;
228 case MAX8997_ADC_JIG_USB_1:
229 case MAX8997_ADC_JIG_USB_2:
230 ret = max8997_muic_handle_usb(info, MAX8997_USB_DEVICE, false);
231 break;
232 case MAX8997_ADC_DESKDOCK:
233 case MAX8997_ADC_CARDOCK:
234 ret = max8997_muic_handle_dock(info, info->pre_adc, false);
235 break;
236 case MAX8997_ADC_JIG_UART:
237 ret = max8997_muic_handle_jig_uart(info, false);
238 break;
239 default:
240 break;
241 }
242
243 return ret;
244}
245
246static int max8997_muic_handle_adc(struct max8997_muic_info *info, int adc)
247{
248 int ret = 0;
249
250 switch (adc) {
251 case MAX8997_ADC_GROUND:
252 ret = max8997_muic_handle_usb(info, MAX8997_USB_HOST, true);
253 break;
254 case MAX8997_ADC_MHL:
Chanwoo Choib76668b2012-05-09 12:31:58 +0900255 extcon_set_cable_state(info->edev, "MHL", true);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900256 break;
257 case MAX8997_ADC_JIG_USB_1:
258 case MAX8997_ADC_JIG_USB_2:
259 ret = max8997_muic_handle_usb(info, MAX8997_USB_DEVICE, true);
260 break;
261 case MAX8997_ADC_DESKDOCK:
262 case MAX8997_ADC_CARDOCK:
263 ret = max8997_muic_handle_dock(info, adc, true);
264 break;
265 case MAX8997_ADC_JIG_UART:
266 ret = max8997_muic_handle_jig_uart(info, true);
267 break;
268 case MAX8997_ADC_OPEN:
269 ret = max8997_muic_handle_adc_detach(info);
270 break;
271 default:
Chanwoo Choib76668b2012-05-09 12:31:58 +0900272 ret = -EINVAL;
273 goto out;
Donggeun Kim99f09be2011-11-24 18:12:18 +0900274 }
275
276 info->pre_adc = adc;
Chanwoo Choib76668b2012-05-09 12:31:58 +0900277out:
278 return ret;
279}
280
281static int max8997_muic_handle_charger_type_detach(
282 struct max8997_muic_info *info)
283{
Chanwoo Choib76668b2012-05-09 12:31:58 +0900284 switch (info->pre_charger_type) {
285 case MAX8997_CHARGER_TYPE_USB:
286 extcon_set_cable_state(info->edev, "USB", false);
287 break;
288 case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT:
289 extcon_set_cable_state(info->edev, "Charge-downstream", false);
290 break;
291 case MAX8997_CHARGER_TYPE_DEDICATED_CHG:
292 extcon_set_cable_state(info->edev, "TA", false);
293 break;
294 case MAX8997_CHARGER_TYPE_500MA:
295 extcon_set_cable_state(info->edev, "Slow-charger", false);
296 break;
297 case MAX8997_CHARGER_TYPE_1A:
298 extcon_set_cable_state(info->edev, "Fast-charger", false);
299 break;
300 default:
Devendra Naga3cafbd42012-08-31 14:00:19 +0530301 return -EINVAL;
Chanwoo Choib76668b2012-05-09 12:31:58 +0900302 }
Donggeun Kim99f09be2011-11-24 18:12:18 +0900303
Devendra Naga3cafbd42012-08-31 14:00:19 +0530304 return 0;
Donggeun Kim99f09be2011-11-24 18:12:18 +0900305}
306
307static int max8997_muic_handle_charger_type(struct max8997_muic_info *info,
308 enum max8997_muic_charger_type charger_type)
309{
Donggeun Kim99f09be2011-11-24 18:12:18 +0900310 u8 adc;
311 int ret;
312
313 ret = max8997_read_reg(info->muic, MAX8997_MUIC_REG_STATUS1, &adc);
314 if (ret) {
315 dev_err(info->dev, "failed to read muic register\n");
316 goto out;
317 }
318
319 switch (charger_type) {
320 case MAX8997_CHARGER_TYPE_NONE:
Chanwoo Choib76668b2012-05-09 12:31:58 +0900321 ret = max8997_muic_handle_charger_type_detach(info);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900322 break;
323 case MAX8997_CHARGER_TYPE_USB:
324 if ((adc & STATUS1_ADC_MASK) == MAX8997_ADC_OPEN) {
325 max8997_muic_handle_usb(info,
326 MAX8997_USB_DEVICE, true);
327 }
Donggeun Kim99f09be2011-11-24 18:12:18 +0900328 break;
329 case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT:
Chanwoo Choib76668b2012-05-09 12:31:58 +0900330 extcon_set_cable_state(info->edev, "Charge-downstream", true);
331 break;
Donggeun Kim99f09be2011-11-24 18:12:18 +0900332 case MAX8997_CHARGER_TYPE_DEDICATED_CHG:
Chanwoo Choib76668b2012-05-09 12:31:58 +0900333 extcon_set_cable_state(info->edev, "TA", true);
334 break;
Donggeun Kim99f09be2011-11-24 18:12:18 +0900335 case MAX8997_CHARGER_TYPE_500MA:
Chanwoo Choib76668b2012-05-09 12:31:58 +0900336 extcon_set_cable_state(info->edev, "Slow-charger", true);
337 break;
Donggeun Kim99f09be2011-11-24 18:12:18 +0900338 case MAX8997_CHARGER_TYPE_1A:
Chanwoo Choib76668b2012-05-09 12:31:58 +0900339 extcon_set_cable_state(info->edev, "Fast-charger", true);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900340 break;
341 default:
Chanwoo Choib76668b2012-05-09 12:31:58 +0900342 ret = -EINVAL;
343 goto out;
Donggeun Kim99f09be2011-11-24 18:12:18 +0900344 }
345
346 info->pre_charger_type = charger_type;
347out:
348 return ret;
349}
350
351static void max8997_muic_irq_work(struct work_struct *work)
352{
353 struct max8997_muic_info *info = container_of(work,
354 struct max8997_muic_info, irq_work);
Chanwoo Choib76668b2012-05-09 12:31:58 +0900355 u8 status[2];
Donggeun Kim71e58782011-12-15 18:20:47 +0900356 u8 adc, chg_type;
Chanwoo Choidca1a712012-07-02 09:03:00 +0900357 int irq_type = 0;
358 int i, ret;
Donggeun Kim99f09be2011-11-24 18:12:18 +0900359
360 mutex_lock(&info->mutex);
361
362 ret = max8997_bulk_read(info->muic, MAX8997_MUIC_REG_STATUS1,
Chanwoo Choib76668b2012-05-09 12:31:58 +0900363 2, status);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900364 if (ret) {
365 dev_err(info->dev, "failed to read muic register\n");
366 mutex_unlock(&info->mutex);
367 return;
368 }
369
370 dev_dbg(info->dev, "%s: STATUS1:0x%x, 2:0x%x\n", __func__,
371 status[0], status[1]);
372
Chanwoo Choidca1a712012-07-02 09:03:00 +0900373 for (i = 0 ; i < ARRAY_SIZE(muic_irqs) ; i++)
374 if (info->irq == muic_irqs[i].virq)
375 irq_type = muic_irqs[i].irq;
376
Donggeun Kim99f09be2011-11-24 18:12:18 +0900377 switch (irq_type) {
Donggeun Kim99f09be2011-11-24 18:12:18 +0900378 case MAX8997_MUICIRQ_ADC:
379 adc = status[0] & STATUS1_ADC_MASK;
380 adc >>= STATUS1_ADC_SHIFT;
381
382 max8997_muic_handle_adc(info, adc);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900383 break;
384 case MAX8997_MUICIRQ_ChgTyp:
385 chg_type = status[1] & STATUS2_CHGTYP_MASK;
386 chg_type >>= STATUS2_CHGTYP_SHIFT;
387
388 max8997_muic_handle_charger_type(info, chg_type);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900389 break;
390 default:
Chanwoo Choib76668b2012-05-09 12:31:58 +0900391 dev_info(info->dev, "misc interrupt: irq %d occurred\n",
392 irq_type);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900393 break;
394 }
395
Donggeun Kim99f09be2011-11-24 18:12:18 +0900396 mutex_unlock(&info->mutex);
397
398 return;
399}
400
401static irqreturn_t max8997_muic_irq_handler(int irq, void *data)
402{
403 struct max8997_muic_info *info = data;
404
405 dev_dbg(info->dev, "irq:%d\n", irq);
406 info->irq = irq;
407
408 schedule_work(&info->irq_work);
409
410 return IRQ_HANDLED;
411}
412
413static void max8997_muic_detect_dev(struct max8997_muic_info *info)
414{
415 int ret;
416 u8 status[2], adc, chg_type;
417
418 ret = max8997_bulk_read(info->muic, MAX8997_MUIC_REG_STATUS1,
419 2, status);
420 if (ret) {
421 dev_err(info->dev, "failed to read muic register\n");
422 return;
423 }
424
425 dev_info(info->dev, "STATUS1:0x%x, STATUS2:0x%x\n",
426 status[0], status[1]);
427
428 adc = status[0] & STATUS1_ADC_MASK;
429 adc >>= STATUS1_ADC_SHIFT;
430
431 chg_type = status[1] & STATUS2_CHGTYP_MASK;
432 chg_type >>= STATUS2_CHGTYP_SHIFT;
433
434 max8997_muic_handle_adc(info, adc);
435 max8997_muic_handle_charger_type(info, chg_type);
436}
437
Bill Pemberton44f34fd2012-11-19 13:23:21 -0500438static int max8997_muic_probe(struct platform_device *pdev)
Donggeun Kim99f09be2011-11-24 18:12:18 +0900439{
Chanwoo Choib76668b2012-05-09 12:31:58 +0900440 struct max8997_dev *max8997 = dev_get_drvdata(pdev->dev.parent);
441 struct max8997_platform_data *pdata = dev_get_platdata(max8997->dev);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900442 struct max8997_muic_info *info;
443 int ret, i;
444
Sachin Kamat0b672e92012-11-20 15:46:47 +0900445 info = devm_kzalloc(&pdev->dev, sizeof(struct max8997_muic_info),
446 GFP_KERNEL);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900447 if (!info) {
448 dev_err(&pdev->dev, "failed to allocate memory\n");
Sachin Kamat0b672e92012-11-20 15:46:47 +0900449 return -ENOMEM;
Donggeun Kim99f09be2011-11-24 18:12:18 +0900450 }
451
Donggeun Kim99f09be2011-11-24 18:12:18 +0900452 info->dev = &pdev->dev;
Chanwoo Choib76668b2012-05-09 12:31:58 +0900453 info->muic = max8997->muic;
Donggeun Kim99f09be2011-11-24 18:12:18 +0900454
455 platform_set_drvdata(pdev, info);
456 mutex_init(&info->mutex);
457
Donggeun Kim99f09be2011-11-24 18:12:18 +0900458 INIT_WORK(&info->irq_work, max8997_muic_irq_work);
459
460 for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) {
461 struct max8997_muic_irq *muic_irq = &muic_irqs[i];
Sachin Kamat68c92742012-11-20 15:46:41 +0900462 unsigned int virq = 0;
Donggeun Kim99f09be2011-11-24 18:12:18 +0900463
Chanwoo Choidca1a712012-07-02 09:03:00 +0900464 virq = irq_create_mapping(max8997->irq_domain, muic_irq->irq);
Sachin Kamat68c92742012-11-20 15:46:41 +0900465 if (!virq) {
466 ret = -EINVAL;
Chanwoo Choidca1a712012-07-02 09:03:00 +0900467 goto err_irq;
Sachin Kamat68c92742012-11-20 15:46:41 +0900468 }
Chanwoo Choidca1a712012-07-02 09:03:00 +0900469 muic_irq->virq = virq;
470
Chanwoo Choiae3b3212012-11-28 12:39:01 +0900471 ret = request_threaded_irq(virq, NULL,
472 max8997_muic_irq_handler,
473 IRQF_NO_SUSPEND,
474 muic_irq->name, info);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900475 if (ret) {
476 dev_err(&pdev->dev,
477 "failed: irq request (IRQ: %d,"
478 " error :%d)\n",
479 muic_irq->irq, ret);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900480 goto err_irq;
481 }
482 }
483
Chanwoo Choib76668b2012-05-09 12:31:58 +0900484 /* External connector */
Sachin Kamat0b672e92012-11-20 15:46:47 +0900485 info->edev = devm_kzalloc(&pdev->dev, sizeof(struct extcon_dev),
486 GFP_KERNEL);
Chanwoo Choib76668b2012-05-09 12:31:58 +0900487 if (!info->edev) {
488 dev_err(&pdev->dev, "failed to allocate memory for extcon\n");
489 ret = -ENOMEM;
490 goto err_irq;
491 }
492 info->edev->name = DEV_NAME;
493 info->edev->supported_cable = max8997_extcon_cable;
494 ret = extcon_dev_register(info->edev, NULL);
495 if (ret) {
496 dev_err(&pdev->dev, "failed to register extcon device\n");
Sachin Kamat0b672e92012-11-20 15:46:47 +0900497 goto err_irq;
Chanwoo Choib76668b2012-05-09 12:31:58 +0900498 }
499
Donggeun Kim99f09be2011-11-24 18:12:18 +0900500 /* Initialize registers according to platform data */
Chanwoo Choib76668b2012-05-09 12:31:58 +0900501 if (pdata->muic_pdata) {
502 struct max8997_muic_platform_data *mdata = info->muic_pdata;
503
504 for (i = 0; i < mdata->num_init_data; i++) {
505 max8997_write_reg(info->muic, mdata->init_data[i].addr,
506 mdata->init_data[i].data);
507 }
508 }
Donggeun Kim99f09be2011-11-24 18:12:18 +0900509
510 /* Initial device detection */
511 max8997_muic_detect_dev(info);
512
513 return ret;
514
515err_irq:
Axel Lin3241d562012-03-26 09:57:08 +0800516 while (--i >= 0)
Chanwoo Choidca1a712012-07-02 09:03:00 +0900517 free_irq(muic_irqs[i].virq, info);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900518 return ret;
519}
520
Bill Pemberton93ed0322012-11-19 13:25:49 -0500521static int max8997_muic_remove(struct platform_device *pdev)
Donggeun Kim99f09be2011-11-24 18:12:18 +0900522{
523 struct max8997_muic_info *info = platform_get_drvdata(pdev);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900524 int i;
525
Donggeun Kim99f09be2011-11-24 18:12:18 +0900526 for (i = 0; i < ARRAY_SIZE(muic_irqs); i++)
Chanwoo Choidca1a712012-07-02 09:03:00 +0900527 free_irq(muic_irqs[i].virq, info);
Donggeun Kim71e58782011-12-15 18:20:47 +0900528 cancel_work_sync(&info->irq_work);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900529
Chanwoo Choib76668b2012-05-09 12:31:58 +0900530 extcon_dev_unregister(info->edev);
531
Donggeun Kim99f09be2011-11-24 18:12:18 +0900532 return 0;
533}
534
535static struct platform_driver max8997_muic_driver = {
536 .driver = {
Chanwoo Choib76668b2012-05-09 12:31:58 +0900537 .name = DEV_NAME,
Donggeun Kim99f09be2011-11-24 18:12:18 +0900538 .owner = THIS_MODULE,
539 },
540 .probe = max8997_muic_probe,
Bill Pemberton5f7e2222012-11-19 13:20:06 -0500541 .remove = max8997_muic_remove,
Donggeun Kim99f09be2011-11-24 18:12:18 +0900542};
543
Axel Linb00e1262012-01-22 15:33:49 +0800544module_platform_driver(max8997_muic_driver);
Donggeun Kim99f09be2011-11-24 18:12:18 +0900545
Chanwoo Choib76668b2012-05-09 12:31:58 +0900546MODULE_DESCRIPTION("Maxim MAX8997 Extcon driver");
Donggeun Kim99f09be2011-11-24 18:12:18 +0900547MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>");
548MODULE_LICENSE("GPL");