aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDonggeun Kim <dg77.kim@samsung.com>2011-11-24 04:12:18 -0500
committerSamuel Ortiz <sameo@linux.intel.com>2012-01-08 18:37:32 -0500
commit99f09bebbe4e9e008a4e0555340494840c6bd644 (patch)
tree6e7bf515c045d46b7640620fb1e1253d40463ef9
parent2439d9714e8f4f106c8965e093f9892cfb347d76 (diff)
misc: Add driver support for MAX8997 MUIC
The MUIC function in MAX8997 device can be used as a USB port detector and switch. This patch supports the MUIC feature of MAX8997. Signed-off-by: Donggeun Kim <dg77.kim@samsung.com> Signed-off-by: MyungJoo Ham <myungjoo.ham@samsung.com> Signed-off-by: Kyungmin Park <kyungmin.park@samsung.com> Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
-rw-r--r--drivers/misc/Kconfig8
-rw-r--r--drivers/misc/Makefile1
-rw-r--r--drivers/misc/max8997-muic.c634
3 files changed, 643 insertions, 0 deletions
diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
index 5664696f2d3a..6a1a092db146 100644
--- a/drivers/misc/Kconfig
+++ b/drivers/misc/Kconfig
@@ -500,6 +500,14 @@ config USB_SWITCH_FSA9480
500 stereo and mono audio, video, microphone and UART data to use 500 stereo and mono audio, video, microphone and UART data to use
501 a common connector port. 501 a common connector port.
502 502
503config MAX8997_MUIC
504 tristate "MAX8997 MUIC Support"
505 depends on MFD_MAX8997
506 help
507 If you say yes here you get support for the MUIC device of
508 Maxim MAX8997 PMIC.
509 The MAX8997 MUIC is a USB port accessory detector and switch.
510
503source "drivers/misc/c2port/Kconfig" 511source "drivers/misc/c2port/Kconfig"
504source "drivers/misc/eeprom/Kconfig" 512source "drivers/misc/eeprom/Kconfig"
505source "drivers/misc/cb710/Kconfig" 513source "drivers/misc/cb710/Kconfig"
diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
index b26495a02554..3e1d80106f04 100644
--- a/drivers/misc/Makefile
+++ b/drivers/misc/Makefile
@@ -48,3 +48,4 @@ obj-y += lis3lv02d/
48obj-y += carma/ 48obj-y += carma/
49obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o 49obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
50obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/ 50obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/
51obj-$(CONFIG_MAX8997_MUIC) += max8997-muic.o
diff --git a/drivers/misc/max8997-muic.c b/drivers/misc/max8997-muic.c
new file mode 100644
index 000000000000..74a9448a93d2
--- /dev/null
+++ b/drivers/misc/max8997-muic.c
@@ -0,0 +1,634 @@
1/*
2 * max8997-muic.c - MAX8997 muic driver for the Maxim 8997
3 *
4 * Copyright (C) 2011 Samsung Electrnoics
5 * 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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 *
21 */
22
23#include <linux/kernel.h>
24#include <linux/module.h>
25#include <linux/i2c.h>
26#include <linux/slab.h>
27#include <linux/interrupt.h>
28#include <linux/err.h>
29#include <linux/platform_device.h>
30#include <linux/kobject.h>
31#include <linux/mfd/max8997.h>
32#include <linux/mfd/max8997-private.h>
33
34/* MAX8997-MUIC STATUS1 register */
35#define STATUS1_ADC_SHIFT 0
36#define STATUS1_ADCLOW_SHIFT 5
37#define STATUS1_ADCERR_SHIFT 6
38#define STATUS1_ADC_MASK (0x1f << STATUS1_ADC_SHIFT)
39#define STATUS1_ADCLOW_MASK (0x1 << STATUS1_ADCLOW_SHIFT)
40#define STATUS1_ADCERR_MASK (0x1 << STATUS1_ADCERR_SHIFT)
41
42/* MAX8997-MUIC STATUS2 register */
43#define STATUS2_CHGTYP_SHIFT 0
44#define STATUS2_CHGDETRUN_SHIFT 3
45#define STATUS2_DCDTMR_SHIFT 4
46#define STATUS2_DBCHG_SHIFT 5
47#define STATUS2_VBVOLT_SHIFT 6
48#define STATUS2_CHGTYP_MASK (0x7 << STATUS2_CHGTYP_SHIFT)
49#define STATUS2_CHGDETRUN_MASK (0x1 << STATUS2_CHGDETRUN_SHIFT)
50#define STATUS2_DCDTMR_MASK (0x1 << STATUS2_DCDTMR_SHIFT)
51#define STATUS2_DBCHG_MASK (0x1 << STATUS2_DBCHG_SHIFT)
52#define STATUS2_VBVOLT_MASK (0x1 << STATUS2_VBVOLT_SHIFT)
53
54/* MAX8997-MUIC STATUS3 register */
55#define STATUS3_OVP_SHIFT 2
56#define STATUS3_OVP_MASK (0x1 << STATUS3_OVP_SHIFT)
57
58/* MAX8997-MUIC CONTROL1 register */
59#define COMN1SW_SHIFT 0
60#define COMP2SW_SHIFT 3
61#define COMN1SW_MASK (0x7 << COMN1SW_SHIFT)
62#define COMP2SW_MASK (0x7 << COMP2SW_SHIFT)
63#define SW_MASK (COMP2SW_MASK | COMN1SW_MASK)
64
65#define MAX8997_SW_USB ((1 << COMP2SW_SHIFT) | (1 << COMN1SW_SHIFT))
66#define MAX8997_SW_AUDIO ((2 << COMP2SW_SHIFT) | (2 << COMN1SW_SHIFT))
67#define MAX8997_SW_UART ((3 << COMP2SW_SHIFT) | (3 << COMN1SW_SHIFT))
68#define MAX8997_SW_OPEN ((0 << COMP2SW_SHIFT) | (0 << COMN1SW_SHIFT))
69
70#define MAX8997_ADC_GROUND 0x00
71#define MAX8997_ADC_MHL 0x01
72#define MAX8997_ADC_JIG_USB_1 0x18
73#define MAX8997_ADC_JIG_USB_2 0x19
74#define MAX8997_ADC_DESKDOCK 0x1a
75#define MAX8997_ADC_JIG_UART 0x1c
76#define MAX8997_ADC_CARDOCK 0x1d
77#define MAX8997_ADC_OPEN 0x1f
78
79struct max8997_muic_irq {
80 unsigned int irq;
81 const char *name;
82};
83
84static struct max8997_muic_irq muic_irqs[] = {
85 { MAX8997_MUICIRQ_ADCError, "muic-ADC_error" },
86 { MAX8997_MUICIRQ_ADCLow, "muic-ADC_low" },
87 { MAX8997_MUICIRQ_ADC, "muic-ADC" },
88 { MAX8997_MUICIRQ_VBVolt, "muic-VB_voltage" },
89 { MAX8997_MUICIRQ_DBChg, "muic-DB_charger" },
90 { MAX8997_MUICIRQ_DCDTmr, "muic-DCD_timer" },
91 { MAX8997_MUICIRQ_ChgDetRun, "muic-CDR_status" },
92 { MAX8997_MUICIRQ_ChgTyp, "muic-charger_type" },
93 { MAX8997_MUICIRQ_OVP, "muic-over_voltage" },
94};
95
96struct max8997_muic_info {
97 struct device *dev;
98 struct max8997_dev *iodev;
99 struct i2c_client *muic;
100 struct max8997_muic_platform_data *muic_pdata;
101
102 int irq;
103 struct work_struct irq_work;
104
105 enum max8997_muic_charger_type pre_charger_type;
106 int pre_adc;
107
108 struct mutex mutex;
109};
110
111static int max8997_muic_handle_usb(struct max8997_muic_info *info,
112 enum max8997_muic_usb_type usb_type, bool attached)
113{
114 struct max8997_muic_platform_data *mdata = info->muic_pdata;
115 int ret = 0;
116
117 if (usb_type == MAX8997_USB_HOST) {
118 /* switch to USB */
119 ret = max8997_update_reg(info->muic, MAX8997_MUIC_REG_CONTROL1,
120 attached ? MAX8997_SW_USB : MAX8997_SW_OPEN,
121 SW_MASK);
122 if (ret) {
123 dev_err(info->dev, "failed to update muic register\n");
124 goto out;
125 }
126 }
127
128 if (mdata->usb_callback)
129 mdata->usb_callback(usb_type, attached);
130out:
131 return ret;
132}
133
134static void max8997_muic_handle_mhl(struct max8997_muic_info *info,
135 bool attached)
136{
137 struct max8997_muic_platform_data *mdata = info->muic_pdata;
138
139 if (mdata->mhl_callback)
140 mdata->mhl_callback(attached);
141}
142
143static int max8997_muic_handle_dock(struct max8997_muic_info *info,
144 int adc, bool attached)
145{
146 struct max8997_muic_platform_data *mdata = info->muic_pdata;
147 int ret = 0;
148
149 /* switch to AUDIO */
150 ret = max8997_update_reg(info->muic, MAX8997_MUIC_REG_CONTROL1,
151 attached ? MAX8997_SW_AUDIO : MAX8997_SW_OPEN,
152 SW_MASK);
153 if (ret) {
154 dev_err(info->dev, "failed to update muic register\n");
155 goto out;
156 }
157
158 switch (adc) {
159 case MAX8997_ADC_DESKDOCK:
160 if (mdata->deskdock_callback)
161 mdata->deskdock_callback(attached);
162 break;
163 case MAX8997_ADC_CARDOCK:
164 if (mdata->cardock_callback)
165 mdata->cardock_callback(attached);
166 break;
167 default:
168 break;
169 }
170out:
171 return ret;
172}
173
174static int max8997_muic_handle_jig_uart(struct max8997_muic_info *info,
175 bool attached)
176{
177 struct max8997_muic_platform_data *mdata = info->muic_pdata;
178 int ret = 0;
179
180 /* switch to UART */
181 ret = max8997_update_reg(info->muic, MAX8997_MUIC_REG_CONTROL1,
182 attached ? MAX8997_SW_UART : MAX8997_SW_OPEN,
183 SW_MASK);
184 if (ret) {
185 dev_err(info->dev, "failed to update muic register\n");
186 goto out;
187 }
188
189 if (mdata->uart_callback)
190 mdata->uart_callback(attached);
191out:
192 return ret;
193}
194
195static int max8997_muic_handle_adc_detach(struct max8997_muic_info *info)
196{
197 int ret = 0;
198
199 switch (info->pre_adc) {
200 case MAX8997_ADC_GROUND:
201 ret = max8997_muic_handle_usb(info, MAX8997_USB_HOST, false);
202 break;
203 case MAX8997_ADC_MHL:
204 max8997_muic_handle_mhl(info, false);
205 break;
206 case MAX8997_ADC_JIG_USB_1:
207 case MAX8997_ADC_JIG_USB_2:
208 ret = max8997_muic_handle_usb(info, MAX8997_USB_DEVICE, false);
209 break;
210 case MAX8997_ADC_DESKDOCK:
211 case MAX8997_ADC_CARDOCK:
212 ret = max8997_muic_handle_dock(info, info->pre_adc, false);
213 break;
214 case MAX8997_ADC_JIG_UART:
215 ret = max8997_muic_handle_jig_uart(info, false);
216 break;
217 default:
218 break;
219 }
220
221 return ret;
222}
223
224static int max8997_muic_handle_adc(struct max8997_muic_info *info, int adc)
225{
226 int ret = 0;
227
228 switch (adc) {
229 case MAX8997_ADC_GROUND:
230 ret = max8997_muic_handle_usb(info, MAX8997_USB_HOST, true);
231 break;
232 case MAX8997_ADC_MHL:
233 max8997_muic_handle_mhl(info, true);
234 break;
235 case MAX8997_ADC_JIG_USB_1:
236 case MAX8997_ADC_JIG_USB_2:
237 ret = max8997_muic_handle_usb(info, MAX8997_USB_DEVICE, true);
238 break;
239 case MAX8997_ADC_DESKDOCK:
240 case MAX8997_ADC_CARDOCK:
241 ret = max8997_muic_handle_dock(info, adc, true);
242 break;
243 case MAX8997_ADC_JIG_UART:
244 ret = max8997_muic_handle_jig_uart(info, true);
245 break;
246 case MAX8997_ADC_OPEN:
247 ret = max8997_muic_handle_adc_detach(info);
248 break;
249 default:
250 break;
251 }
252
253 info->pre_adc = adc;
254
255 return ret;
256}
257
258static int max8997_muic_handle_charger_type(struct max8997_muic_info *info,
259 enum max8997_muic_charger_type charger_type)
260{
261 struct max8997_muic_platform_data *mdata = info->muic_pdata;
262 u8 adc;
263 int ret;
264
265 ret = max8997_read_reg(info->muic, MAX8997_MUIC_REG_STATUS1, &adc);
266 if (ret) {
267 dev_err(info->dev, "failed to read muic register\n");
268 goto out;
269 }
270
271 switch (charger_type) {
272 case MAX8997_CHARGER_TYPE_NONE:
273 if (mdata->charger_callback)
274 mdata->charger_callback(false, charger_type);
275 if (info->pre_charger_type == MAX8997_CHARGER_TYPE_USB) {
276 max8997_muic_handle_usb(info,
277 MAX8997_USB_DEVICE, false);
278 }
279 break;
280 case MAX8997_CHARGER_TYPE_USB:
281 if ((adc & STATUS1_ADC_MASK) == MAX8997_ADC_OPEN) {
282 max8997_muic_handle_usb(info,
283 MAX8997_USB_DEVICE, true);
284 }
285 if (mdata->charger_callback)
286 mdata->charger_callback(true, charger_type);
287 break;
288 case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT:
289 case MAX8997_CHARGER_TYPE_DEDICATED_CHG:
290 case MAX8997_CHARGER_TYPE_500MA:
291 case MAX8997_CHARGER_TYPE_1A:
292 if (mdata->charger_callback)
293 mdata->charger_callback(true, charger_type);
294 break;
295 default:
296 break;
297 }
298
299 info->pre_charger_type = charger_type;
300out:
301 return ret;
302}
303
304static void max8997_muic_irq_work(struct work_struct *work)
305{
306 struct max8997_muic_info *info = container_of(work,
307 struct max8997_muic_info, irq_work);
308 struct max8997_platform_data *pdata =
309 dev_get_platdata(info->iodev->dev);
310 char env_name_str[30], env_state_str[15];
311 char *envp[] = { env_name_str, env_state_str, NULL };
312 u8 status[3];
313 u8 adc, adc_low, adc_err;
314 u8 vb_volt, db_chg, dcd_tmr, cdr, chg_type, ovp;
315
316 int irq_type = info->irq - pdata->irq_base;
317 int ret;
318
319 mutex_lock(&info->mutex);
320
321 ret = max8997_bulk_read(info->muic, MAX8997_MUIC_REG_STATUS1,
322 3, status);
323 if (ret) {
324 dev_err(info->dev, "failed to read muic register\n");
325 mutex_unlock(&info->mutex);
326 return;
327 }
328
329 dev_dbg(info->dev, "%s: STATUS1:0x%x, 2:0x%x\n", __func__,
330 status[0], status[1]);
331
332 switch (irq_type) {
333 case MAX8997_MUICIRQ_ADCError:
334 adc_err = status[0] & STATUS1_ADCERR_MASK;
335 adc_err >>= STATUS1_ADCERR_SHIFT;
336 sprintf(env_name_str, "IRQ=%s", "ADC_Error");
337 sprintf(env_state_str, "STATE=%d", adc_err);
338 break;
339 case MAX8997_MUICIRQ_ADCLow:
340 adc_low = status[0] & STATUS1_ADCLOW_MASK;
341 adc_low >>= STATUS1_ADCLOW_SHIFT;
342 sprintf(env_name_str, "IRQ=%s", "ADC_Low");
343 sprintf(env_state_str, "STATE=%d", adc_low);
344 break;
345 case MAX8997_MUICIRQ_ADC:
346 adc = status[0] & STATUS1_ADC_MASK;
347 adc >>= STATUS1_ADC_SHIFT;
348
349 max8997_muic_handle_adc(info, adc);
350
351 sprintf(env_name_str, "IRQ=%s", "ADC");
352 sprintf(env_state_str, "STATE=%d", adc);
353 break;
354 case MAX8997_MUICIRQ_VBVolt:
355 vb_volt = status[1] & STATUS2_VBVOLT_MASK;
356 vb_volt >>= STATUS2_VBVOLT_SHIFT;
357 sprintf(env_name_str, "IRQ=%s", "VB_Volt");
358 sprintf(env_state_str, "STATE=%d", vb_volt);
359 break;
360 case MAX8997_MUICIRQ_DBChg:
361 db_chg = status[1] & STATUS2_DBCHG_MASK;
362 db_chg >>= STATUS2_DBCHG_SHIFT;
363 sprintf(env_name_str, "IRQ=%s", "DB_CHARGER");
364 sprintf(env_state_str, "STATE=%d", db_chg);
365 break;
366 case MAX8997_MUICIRQ_DCDTmr:
367 dcd_tmr = status[1] & STATUS2_DCDTMR_MASK;
368 dcd_tmr >>= STATUS2_DCDTMR_SHIFT;
369 sprintf(env_name_str, "IRQ=%s", "DCD_TIMER");
370 sprintf(env_state_str, "STATE=%d", dcd_tmr);
371 break;
372 case MAX8997_MUICIRQ_ChgDetRun:
373 cdr = status[1] & STATUS2_CHGDETRUN_MASK;
374 cdr >>= STATUS2_CHGDETRUN_SHIFT;
375 sprintf(env_name_str, "IRQ=%s", "CHG_DET_RUN");
376 sprintf(env_state_str, "STATE=%d", cdr);
377 break;
378 case MAX8997_MUICIRQ_ChgTyp:
379 chg_type = status[1] & STATUS2_CHGTYP_MASK;
380 chg_type >>= STATUS2_CHGTYP_SHIFT;
381
382 max8997_muic_handle_charger_type(info, chg_type);
383
384 sprintf(env_name_str, "IRQ=%s", "CHARGER_TYPE");
385 sprintf(env_state_str, "STATE=%d", chg_type);
386 break;
387 case MAX8997_MUICIRQ_OVP:
388 ovp = status[2] & STATUS3_OVP_MASK;
389 ovp >>= STATUS3_OVP_SHIFT;
390 sprintf(env_name_str, "IRQ=%s", "OVER-VOLTAGE");
391 sprintf(env_state_str, "STATE=%d", ovp);
392 break;
393 default:
394 break;
395 }
396
397 kobject_uevent_env(&info->dev->kobj, KOBJ_CHANGE, envp);
398
399 mutex_unlock(&info->mutex);
400
401 return;
402}
403
404static irqreturn_t max8997_muic_irq_handler(int irq, void *data)
405{
406 struct max8997_muic_info *info = data;
407
408 dev_dbg(info->dev, "irq:%d\n", irq);
409 info->irq = irq;
410
411 schedule_work(&info->irq_work);
412
413 return IRQ_HANDLED;
414}
415
416static void max8997_muic_detect_dev(struct max8997_muic_info *info)
417{
418 int ret;
419 u8 status[2], adc, chg_type;
420
421 ret = max8997_bulk_read(info->muic, MAX8997_MUIC_REG_STATUS1,
422 2, status);
423 if (ret) {
424 dev_err(info->dev, "failed to read muic register\n");
425 return;
426 }
427
428 dev_info(info->dev, "STATUS1:0x%x, STATUS2:0x%x\n",
429 status[0], status[1]);
430
431 adc = status[0] & STATUS1_ADC_MASK;
432 adc >>= STATUS1_ADC_SHIFT;
433
434 chg_type = status[1] & STATUS2_CHGTYP_MASK;
435 chg_type >>= STATUS2_CHGTYP_SHIFT;
436
437 max8997_muic_handle_adc(info, adc);
438 max8997_muic_handle_charger_type(info, chg_type);
439}
440
441static ssize_t max8997_muic_show_manualsw(struct device *dev,
442 struct device_attribute *attr, char *buf)
443{
444 struct max8997_muic_info *info = dev_get_drvdata(dev);
445 int ret;
446 u8 value, manual_switch;
447
448 ret = max8997_read_reg(info->muic, MAX8997_MUIC_REG_CONTROL1, &value);
449 if (ret) {
450 dev_err(info->dev, "failed to read muic register\n");
451 return sprintf(buf, "UNKNOWN\n");
452 }
453
454 manual_switch = value & (COMN1SW_MASK | COMP2SW_MASK);
455
456 switch (manual_switch) {
457 case MAX8997_SW_USB:
458 return sprintf(buf, "USB\n");
459 case MAX8997_SW_AUDIO:
460 return sprintf(buf, "AUDIO\n");
461 case MAX8997_SW_UART:
462 return sprintf(buf, "UART\n");
463 default:
464 return sprintf(buf, "OPEN\n");
465 }
466}
467
468static ssize_t max8997_muic_store_manualsw(struct device *dev,
469 struct device_attribute *attr,
470 const char *buf, size_t count)
471{
472 struct max8997_muic_info *info = dev_get_drvdata(dev);
473 int ret;
474 u8 manual_switch;
475
476 if (!strncmp(buf, "USB", 3)) {
477 manual_switch = MAX8997_SW_USB;
478 } else if (!strncmp(buf, "AUDIO", 5)) {
479 manual_switch = MAX8997_SW_AUDIO;
480 } else if (!strncmp(buf, "UART", 4)) {
481 manual_switch = MAX8997_SW_UART;
482 } else if (!strncmp(buf, "OPEN", 4)) {
483 manual_switch = MAX8997_SW_OPEN;
484 } else {
485 dev_err(info->dev, "invalid parameter\n");
486 goto out;
487 }
488
489 ret = max8997_update_reg(info->muic, MAX8997_MUIC_REG_CONTROL1,
490 manual_switch, SW_MASK);
491 if (ret)
492 dev_err(info->dev, "failed to update muic register\n");
493out:
494 return count;
495}
496
497static DEVICE_ATTR(switch, S_IRUGO | S_IWUSR,
498 max8997_muic_show_manualsw, max8997_muic_store_manualsw);
499
500static struct attribute *max8997_muic_attributes[] = {
501 &dev_attr_switch.attr,
502 NULL
503};
504
505static const struct attribute_group max8997_muic_group = {
506 .attrs = max8997_muic_attributes,
507};
508
509static void max8997_initialize_device(struct max8997_muic_info *info)
510{
511 struct max8997_muic_platform_data *mdata = info->muic_pdata;
512 int i;
513
514 for (i = 0; i < mdata->num_init_data; i++) {
515 max8997_write_reg(info->muic, mdata->init_data[i].addr,
516 mdata->init_data[i].data);
517 }
518}
519
520static int __devinit max8997_muic_probe(struct platform_device *pdev)
521{
522 struct max8997_dev *iodev = dev_get_drvdata(pdev->dev.parent);
523 struct max8997_platform_data *pdata = dev_get_platdata(iodev->dev);
524 struct max8997_muic_info *info;
525 int ret, i;
526
527 info = kzalloc(sizeof(struct max8997_muic_info), GFP_KERNEL);
528 if (!info) {
529 dev_err(&pdev->dev, "failed to allocate memory\n");
530 ret = -ENOMEM;
531 goto err_kfree;
532 }
533
534 if (!pdata->muic_pdata) {
535 dev_err(&pdev->dev, "failed to get platform_data\n");
536 ret = -EINVAL;
537 goto err_pdata;
538 }
539 info->muic_pdata = pdata->muic_pdata;
540
541 info->dev = &pdev->dev;
542 info->iodev = iodev;
543 info->muic = iodev->muic;
544
545 platform_set_drvdata(pdev, info);
546 mutex_init(&info->mutex);
547
548 ret = sysfs_create_group(&pdev->dev.kobj, &max8997_muic_group);
549 if (ret) {
550 dev_err(&pdev->dev,
551 "failed to create max8997 muic attribute group\n");
552 goto err_sysfs;
553 }
554
555 INIT_WORK(&info->irq_work, max8997_muic_irq_work);
556
557 for (i = 0; i < ARRAY_SIZE(muic_irqs); i++) {
558 struct max8997_muic_irq *muic_irq = &muic_irqs[i];
559
560 ret = request_threaded_irq(pdata->irq_base + muic_irq->irq,
561 NULL, max8997_muic_irq_handler,
562 0, muic_irq->name,
563 info);
564 if (ret) {
565 dev_err(&pdev->dev,
566 "failed: irq request (IRQ: %d,"
567 " error :%d)\n",
568 muic_irq->irq, ret);
569
570 for (i = i - 1; i >= 0; i--)
571 free_irq(muic_irq->irq, info);
572
573 goto err_irq;
574 }
575 }
576
577 /* Initialize registers according to platform data */
578 max8997_initialize_device(info);
579
580 /* Initial device detection */
581 max8997_muic_detect_dev(info);
582
583 return ret;
584
585err_irq:
586 sysfs_remove_group(&pdev->dev.kobj, &max8997_muic_group);
587err_sysfs:
588err_pdata:
589 kfree(info);
590err_kfree:
591 return ret;
592}
593
594static int __devexit max8997_muic_remove(struct platform_device *pdev)
595{
596 struct max8997_muic_info *info = platform_get_drvdata(pdev);
597 struct max8997_platform_data *pdata =
598 dev_get_platdata(info->iodev->dev);
599 int i;
600
601 sysfs_remove_group(&pdev->dev.kobj, &max8997_muic_group);
602
603 for (i = 0; i < ARRAY_SIZE(muic_irqs); i++)
604 free_irq(pdata->irq_base + muic_irqs[i].irq, info);
605
606 kfree(info);
607
608 return 0;
609}
610
611static struct platform_driver max8997_muic_driver = {
612 .driver = {
613 .name = "max8997-muic",
614 .owner = THIS_MODULE,
615 },
616 .probe = max8997_muic_probe,
617 .remove = __devexit_p(max8997_muic_remove),
618};
619
620static int __init max8997_muic_init(void)
621{
622 return platform_driver_register(&max8997_muic_driver);
623}
624module_init(max8997_muic_init);
625
626static void __exit max8997_muic_exit(void)
627{
628 platform_driver_unregister(&max8997_muic_driver);
629}
630module_exit(max8997_muic_exit);
631
632MODULE_DESCRIPTION("Maxim MAX8997 MUIC driver");
633MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>");
634MODULE_LICENSE("GPL");