extcon: Add new EXTCON_DISP_HMD for Head-mounted Display device
[cascardo/linux.git] / drivers / extcon / extcon.c
1 /*
2  *  drivers/extcon/extcon.c - External Connector (extcon) framework.
3  *
4  *  External connector (extcon) class driver
5  *
6  * Copyright (C) 2015 Samsung Electronics
7  * Author: Chanwoo Choi <cw00.choi@samsung.com>
8  *
9  * Copyright (C) 2012 Samsung Electronics
10  * Author: Donggeun Kim <dg77.kim@samsung.com>
11  * Author: MyungJoo Ham <myungjoo.ham@samsung.com>
12  *
13  * based on android/drivers/switch/switch_class.c
14  * Copyright (C) 2008 Google, Inc.
15  * Author: Mike Lockwood <lockwood@android.com>
16  *
17  * This software is licensed under the terms of the GNU General Public
18  * License version 2, as published by the Free Software Foundation, and
19  * may be copied, distributed, and modified under those terms.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  */
26
27 #include <linux/module.h>
28 #include <linux/types.h>
29 #include <linux/init.h>
30 #include <linux/device.h>
31 #include <linux/fs.h>
32 #include <linux/err.h>
33 #include <linux/extcon.h>
34 #include <linux/of.h>
35 #include <linux/slab.h>
36 #include <linux/sysfs.h>
37
38 #define SUPPORTED_CABLE_MAX     32
39 #define CABLE_NAME_MAX          30
40
41 struct __extcon_info {
42         unsigned int type;
43         unsigned int id;
44         const char *name;
45
46 } extcon_info[] = {
47         [EXTCON_NONE] = {
48                 .type = EXTCON_TYPE_MISC,
49                 .id = EXTCON_NONE,
50                 .name = "NONE",
51         },
52
53         /* USB external connector */
54         [EXTCON_USB] = {
55                 .type = EXTCON_TYPE_USB,
56                 .id = EXTCON_USB,
57                 .name = "USB",
58         },
59         [EXTCON_USB_HOST] = {
60                 .type = EXTCON_TYPE_USB,
61                 .id = EXTCON_USB_HOST,
62                 .name = "USB_HOST",
63         },
64
65         /* Charging external connector */
66         [EXTCON_CHG_USB_SDP] = {
67                 .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
68                 .id = EXTCON_CHG_USB_SDP,
69                 .name = "SDP",
70         },
71         [EXTCON_CHG_USB_DCP] = {
72                 .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
73                 .id = EXTCON_CHG_USB_DCP,
74                 .name = "DCP",
75         },
76         [EXTCON_CHG_USB_CDP] = {
77                 .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
78                 .id = EXTCON_CHG_USB_CDP,
79                 .name = "CDP",
80         },
81         [EXTCON_CHG_USB_ACA] = {
82                 .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
83                 .id = EXTCON_CHG_USB_ACA,
84                 .name = "ACA",
85         },
86         [EXTCON_CHG_USB_FAST] = {
87                 .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
88                 .id = EXTCON_CHG_USB_FAST,
89                 .name = "FAST-CHARGER",
90         },
91         [EXTCON_CHG_USB_SLOW] = {
92                 .type = EXTCON_TYPE_CHG | EXTCON_TYPE_USB,
93                 .id = EXTCON_CHG_USB_SLOW,
94                 .name = "SLOW-CHARGER",
95         },
96
97         /* Jack external connector */
98         [EXTCON_JACK_MICROPHONE] = {
99                 .type = EXTCON_TYPE_JACK,
100                 .id = EXTCON_JACK_MICROPHONE,
101                 .name = "MICROPHONE",
102         },
103         [EXTCON_JACK_HEADPHONE] = {
104                 .type = EXTCON_TYPE_JACK,
105                 .id = EXTCON_JACK_HEADPHONE,
106                 .name = "HEADPHONE",
107         },
108         [EXTCON_JACK_LINE_IN] = {
109                 .type = EXTCON_TYPE_JACK,
110                 .id = EXTCON_JACK_LINE_IN,
111                 .name = "LINE-IN",
112         },
113         [EXTCON_JACK_LINE_OUT] = {
114                 .type = EXTCON_TYPE_JACK,
115                 .id = EXTCON_JACK_LINE_OUT,
116                 .name = "LINE-OUT",
117         },
118         [EXTCON_JACK_VIDEO_IN] = {
119                 .type = EXTCON_TYPE_JACK,
120                 .id = EXTCON_JACK_VIDEO_IN,
121                 .name = "VIDEO-IN",
122         },
123         [EXTCON_JACK_VIDEO_OUT] = {
124                 .type = EXTCON_TYPE_JACK,
125                 .id = EXTCON_JACK_VIDEO_OUT,
126                 .name = "VIDEO-OUT",
127         },
128         [EXTCON_JACK_SPDIF_IN] = {
129                 .type = EXTCON_TYPE_JACK,
130                 .id = EXTCON_JACK_SPDIF_IN,
131                 .name = "SPDIF-IN",
132         },
133         [EXTCON_JACK_SPDIF_OUT] = {
134                 .type = EXTCON_TYPE_JACK,
135                 .id = EXTCON_JACK_SPDIF_OUT,
136                 .name = "SPDIF-OUT",
137         },
138
139         /* Display external connector */
140         [EXTCON_DISP_HDMI] = {
141                 .type = EXTCON_TYPE_DISP,
142                 .id = EXTCON_DISP_HDMI,
143                 .name = "HDMI",
144         },
145         [EXTCON_DISP_MHL] = {
146                 .type = EXTCON_TYPE_DISP,
147                 .id = EXTCON_DISP_MHL,
148                 .name = "MHL",
149         },
150         [EXTCON_DISP_DVI] = {
151                 .type = EXTCON_TYPE_DISP,
152                 .id = EXTCON_DISP_DVI,
153                 .name = "DVI",
154         },
155         [EXTCON_DISP_VGA] = {
156                 .type = EXTCON_TYPE_DISP,
157                 .id = EXTCON_DISP_VGA,
158                 .name = "VGA",
159         },
160         [EXTCON_DISP_DP] = {
161                 .type = EXTCON_TYPE_DISP | EXTCON_TYPE_USB,
162                 .id = EXTCON_DISP_DP,
163                 .name = "DP",
164         },
165         [EXTCON_DISP_HMD] = {
166                 .type = EXTCON_TYPE_DISP | EXTCON_TYPE_USB,
167                 .id = EXTCON_DISP_HMD,
168                 .name = "HMD",
169         },
170
171         /* Miscellaneous external connector */
172         [EXTCON_DOCK] = {
173                 .type = EXTCON_TYPE_MISC,
174                 .id = EXTCON_DOCK,
175                 .name = "DOCK",
176         },
177         [EXTCON_JIG] = {
178                 .type = EXTCON_TYPE_MISC,
179                 .id = EXTCON_JIG,
180                 .name = "JIG",
181         },
182         [EXTCON_MECHANICAL] = {
183                 .type = EXTCON_TYPE_MISC,
184                 .id = EXTCON_MECHANICAL,
185                 .name = "MECHANICAL",
186         },
187
188         { /* sentinel */ }
189 };
190
191 /**
192  * struct extcon_cable - An internal data for each cable of extcon device.
193  * @edev:               The extcon device
194  * @cable_index:        Index of this cable in the edev
195  * @attr_g:             Attribute group for the cable
196  * @attr_name:          "name" sysfs entry
197  * @attr_state:         "state" sysfs entry
198  * @attrs:              Array pointing to attr_name and attr_state for attr_g
199  */
200 struct extcon_cable {
201         struct extcon_dev *edev;
202         int cable_index;
203
204         struct attribute_group attr_g;
205         struct device_attribute attr_name;
206         struct device_attribute attr_state;
207
208         struct attribute *attrs[3]; /* to be fed to attr_g.attrs */
209
210         union extcon_property_value usb_propval[EXTCON_PROP_USB_CNT];
211         union extcon_property_value chg_propval[EXTCON_PROP_CHG_CNT];
212         union extcon_property_value jack_propval[EXTCON_PROP_JACK_CNT];
213         union extcon_property_value disp_propval[EXTCON_PROP_DISP_CNT];
214
215         unsigned long usb_bits[BITS_TO_LONGS(EXTCON_PROP_USB_CNT)];
216         unsigned long chg_bits[BITS_TO_LONGS(EXTCON_PROP_CHG_CNT)];
217         unsigned long jack_bits[BITS_TO_LONGS(EXTCON_PROP_JACK_CNT)];
218         unsigned long disp_bits[BITS_TO_LONGS(EXTCON_PROP_DISP_CNT)];
219 };
220
221 static struct class *extcon_class;
222 #if defined(CONFIG_ANDROID)
223 static struct class_compat *switch_class;
224 #endif /* CONFIG_ANDROID */
225
226 static LIST_HEAD(extcon_dev_list);
227 static DEFINE_MUTEX(extcon_dev_list_lock);
228
229 /**
230  * check_mutually_exclusive - Check if new_state violates mutually_exclusive
231  *                            condition.
232  * @edev:       the extcon device
233  * @new_state:  new cable attach status for @edev
234  *
235  * Returns 0 if nothing violates. Returns the index + 1 for the first
236  * violated condition.
237  */
238 static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state)
239 {
240         int i = 0;
241
242         if (!edev->mutually_exclusive)
243                 return 0;
244
245         for (i = 0; edev->mutually_exclusive[i]; i++) {
246                 int weight;
247                 u32 correspondants = new_state & edev->mutually_exclusive[i];
248
249                 /* calculate the total number of bits set */
250                 weight = hweight32(correspondants);
251                 if (weight > 1)
252                         return i + 1;
253         }
254
255         return 0;
256 }
257
258 static int find_cable_index_by_id(struct extcon_dev *edev, const unsigned int id)
259 {
260         int i;
261
262         /* Find the the index of extcon cable in edev->supported_cable */
263         for (i = 0; i < edev->max_supported; i++) {
264                 if (edev->supported_cable[i] == id)
265                         return i;
266         }
267
268         return -EINVAL;
269 }
270
271 static int get_extcon_type(unsigned int prop)
272 {
273         switch (prop) {
274         case EXTCON_PROP_USB_MIN ... EXTCON_PROP_USB_MAX:
275                 return EXTCON_TYPE_USB;
276         case EXTCON_PROP_CHG_MIN ... EXTCON_PROP_CHG_MAX:
277                 return EXTCON_TYPE_CHG;
278         case EXTCON_PROP_JACK_MIN ... EXTCON_PROP_JACK_MAX:
279                 return EXTCON_TYPE_JACK;
280         case EXTCON_PROP_DISP_MIN ... EXTCON_PROP_DISP_MAX:
281                 return EXTCON_TYPE_DISP;
282         default:
283                 return -EINVAL;
284         }
285 }
286
287 static bool is_extcon_attached(struct extcon_dev *edev, unsigned int index)
288 {
289         return !!(edev->state & BIT(index));
290 }
291
292 static bool is_extcon_changed(struct extcon_dev *edev, int index,
293                                 bool new_state)
294 {
295         int state = !!(edev->state & BIT(index));
296         return (state != new_state);
297 }
298
299 static bool is_extcon_property_supported(unsigned int id, unsigned int prop)
300 {
301         int type;
302
303         /* Check whether the property is supported or not. */
304         type = get_extcon_type(prop);
305         if (type < 0)
306                 return false;
307
308         /* Check whether a specific extcon id supports the property or not. */
309         return !!(extcon_info[id].type & type);
310 }
311
312 static int is_extcon_property_capability(struct extcon_dev *edev,
313                                 unsigned int id, int index,unsigned int prop)
314 {
315         struct extcon_cable *cable;
316         int type, ret;
317
318         /* Check whether the property is supported or not. */
319         type = get_extcon_type(prop);
320         if (type < 0)
321                 return type;
322
323         cable = &edev->cables[index];
324
325         switch (type) {
326         case EXTCON_TYPE_USB:
327                 ret = test_bit(prop - EXTCON_PROP_USB_MIN, cable->usb_bits);
328                 break;
329         case EXTCON_TYPE_CHG:
330                 ret = test_bit(prop - EXTCON_PROP_CHG_MIN, cable->chg_bits);
331                 break;
332         case EXTCON_TYPE_JACK:
333                 ret = test_bit(prop - EXTCON_PROP_JACK_MIN, cable->jack_bits);
334                 break;
335         case EXTCON_TYPE_DISP:
336                 ret = test_bit(prop - EXTCON_PROP_DISP_MIN, cable->disp_bits);
337                 break;
338         default:
339                 ret = -EINVAL;
340         }
341
342         return ret;
343 }
344
345 static void init_property(struct extcon_dev *edev, unsigned int id, int index)
346 {
347         unsigned int type = extcon_info[id].type;
348         struct extcon_cable *cable = &edev->cables[index];
349
350         if (EXTCON_TYPE_USB & type)
351                 memset(cable->usb_propval, 0, sizeof(cable->usb_propval));
352         if (EXTCON_TYPE_CHG & type)
353                 memset(cable->chg_propval, 0, sizeof(cable->chg_propval));
354         if (EXTCON_TYPE_JACK & type)
355                 memset(cable->jack_propval, 0, sizeof(cable->jack_propval));
356         if (EXTCON_TYPE_DISP & type)
357                 memset(cable->disp_propval, 0, sizeof(cable->disp_propval));
358 }
359
360 static ssize_t state_show(struct device *dev, struct device_attribute *attr,
361                           char *buf)
362 {
363         int i, count = 0;
364         struct extcon_dev *edev = dev_get_drvdata(dev);
365
366         if (edev->max_supported == 0)
367                 return sprintf(buf, "%u\n", edev->state);
368
369         for (i = 0; i < edev->max_supported; i++) {
370                 count += sprintf(buf + count, "%s=%d\n",
371                                 extcon_info[edev->supported_cable[i]].name,
372                                  !!(edev->state & (1 << i)));
373         }
374
375         return count;
376 }
377 static DEVICE_ATTR_RO(state);
378
379 static ssize_t name_show(struct device *dev, struct device_attribute *attr,
380                 char *buf)
381 {
382         struct extcon_dev *edev = dev_get_drvdata(dev);
383
384         return sprintf(buf, "%s\n", edev->name);
385 }
386 static DEVICE_ATTR_RO(name);
387
388 static ssize_t cable_name_show(struct device *dev,
389                                struct device_attribute *attr, char *buf)
390 {
391         struct extcon_cable *cable = container_of(attr, struct extcon_cable,
392                                                   attr_name);
393         int i = cable->cable_index;
394
395         return sprintf(buf, "%s\n",
396                         extcon_info[cable->edev->supported_cable[i]].name);
397 }
398
399 static ssize_t cable_state_show(struct device *dev,
400                                 struct device_attribute *attr, char *buf)
401 {
402         struct extcon_cable *cable = container_of(attr, struct extcon_cable,
403                                                   attr_state);
404
405         int i = cable->cable_index;
406
407         return sprintf(buf, "%d\n",
408                 extcon_get_state(cable->edev, cable->edev->supported_cable[i]));
409 }
410
411 /**
412  * extcon_sync()        - Synchronize the states for both the attached/detached
413  * @edev:               the extcon device that has the cable.
414  *
415  * This function send a notification to synchronize the all states of a
416  * specific external connector
417  */
418 int extcon_sync(struct extcon_dev *edev, unsigned int id)
419 {
420         char name_buf[120];
421         char state_buf[120];
422         char *prop_buf;
423         char *envp[3];
424         int env_offset = 0;
425         int length;
426         int index;
427         int state;
428         unsigned long flags;
429
430         if (!edev)
431                 return -EINVAL;
432
433         index = find_cable_index_by_id(edev, id);
434         if (index < 0)
435                 return index;
436
437         spin_lock_irqsave(&edev->lock, flags);
438
439         state = !!(edev->state & BIT(index));
440         raw_notifier_call_chain(&edev->nh[index], state, edev);
441
442         /* This could be in interrupt handler */
443         prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
444         if (!prop_buf) {
445                 /* Unlock early before uevent */
446                 spin_unlock_irqrestore(&edev->lock, flags);
447
448                 dev_err(&edev->dev, "out of memory in extcon_set_state\n");
449                 kobject_uevent(&edev->dev.kobj, KOBJ_CHANGE);
450
451                 return 0;
452         }
453
454         length = name_show(&edev->dev, NULL, prop_buf);
455         if (length > 0) {
456                 if (prop_buf[length - 1] == '\n')
457                         prop_buf[length - 1] = 0;
458                 snprintf(name_buf, sizeof(name_buf), "NAME=%s", prop_buf);
459                 envp[env_offset++] = name_buf;
460         }
461
462         length = state_show(&edev->dev, NULL, prop_buf);
463         if (length > 0) {
464                 if (prop_buf[length - 1] == '\n')
465                         prop_buf[length - 1] = 0;
466                 snprintf(state_buf, sizeof(state_buf), "STATE=%s", prop_buf);
467                 envp[env_offset++] = state_buf;
468         }
469         envp[env_offset] = NULL;
470
471         /* Unlock early before uevent */
472         spin_unlock_irqrestore(&edev->lock, flags);
473         kobject_uevent_env(&edev->dev.kobj, KOBJ_CHANGE, envp);
474         free_page((unsigned long)prop_buf);
475
476         return 0;
477 }
478 EXPORT_SYMBOL_GPL(extcon_sync);
479
480 /**
481  * extcon_get_state() - Get the state of a external connector.
482  * @edev:       the extcon device that has the cable.
483  * @id:         the unique id of each external connector in extcon enumeration.
484  */
485 int extcon_get_state(struct extcon_dev *edev, const unsigned int id)
486 {
487         int index, state;
488         unsigned long flags;
489
490         if (!edev)
491                 return -EINVAL;
492
493         index = find_cable_index_by_id(edev, id);
494         if (index < 0)
495                 return index;
496
497         spin_lock_irqsave(&edev->lock, flags);
498         state = is_extcon_attached(edev, index);
499         spin_unlock_irqrestore(&edev->lock, flags);
500
501         return state;
502 }
503 EXPORT_SYMBOL_GPL(extcon_get_state);
504
505 /**
506  * extcon_set_state() - Set the state of a external connector.
507  *                      without a notification.
508  * @edev:               the extcon device that has the cable.
509  * @id:                 the unique id of each external connector
510  *                      in extcon enumeration.
511  * @state:              the new cable status. The default semantics is
512  *                      true: attached / false: detached.
513  *
514  * This function only set the state of a external connector without
515  * a notification. To synchronize the data of a external connector,
516  * use extcon_set_state_sync() and extcon_sync().
517  */
518 int extcon_set_state(struct extcon_dev *edev, unsigned int id,
519                                 bool cable_state)
520 {
521         unsigned long flags;
522         int index, ret = 0;
523
524         if (!edev)
525                 return -EINVAL;
526
527         index = find_cable_index_by_id(edev, id);
528         if (index < 0)
529                 return index;
530
531         spin_lock_irqsave(&edev->lock, flags);
532
533         /* Check whether the external connector's state is changed. */
534         if (!is_extcon_changed(edev, index, cable_state))
535                 goto out;
536
537         if (check_mutually_exclusive(edev,
538                 (edev->state & ~BIT(index)) | (cable_state & BIT(index)))) {
539                 ret = -EPERM;
540                 goto out;
541         }
542
543         /*
544          * Initialize the value of extcon property before setting
545          * the detached state for an external connector.
546          */
547         if (!cable_state)
548                 init_property(edev, id, index);
549
550         /* Update the state for a external connector. */
551         if (cable_state)
552                 edev->state |= BIT(index);
553         else
554                 edev->state &= ~(BIT(index));
555 out:
556         spin_unlock_irqrestore(&edev->lock, flags);
557
558         return ret;
559 }
560 EXPORT_SYMBOL_GPL(extcon_set_state);
561
562 /**
563  * extcon_set_state_sync() - Set the state of a external connector
564  *                      with a notification.
565  * @edev:               the extcon device that has the cable.
566  * @id:                 the unique id of each external connector
567  *                      in extcon enumeration.
568  * @state:              the new cable status. The default semantics is
569  *                      true: attached / false: detached.
570  *
571  * This function set the state of external connector and synchronize the data
572  * by usning a notification.
573  */
574 int extcon_set_state_sync(struct extcon_dev *edev, unsigned int id,
575                                 bool cable_state)
576 {
577         int ret, index;
578         unsigned long flags;
579
580         index = find_cable_index_by_id(edev, id);
581         if (index < 0)
582                 return index;
583
584         /* Check whether the external connector's state is changed. */
585         spin_lock_irqsave(&edev->lock, flags);
586         ret = is_extcon_changed(edev, index, cable_state);
587         spin_unlock_irqrestore(&edev->lock, flags);
588         if (!ret)
589                 return 0;
590
591         ret = extcon_set_state(edev, id, cable_state);
592         if (ret < 0)
593                 return ret;
594
595         return extcon_sync(edev, id);
596 }
597 EXPORT_SYMBOL_GPL(extcon_set_state_sync);
598
599 /**
600  * extcon_get_property() - Get the property value of a specific cable.
601  * @edev:               the extcon device that has the cable.
602  * @id:                 the unique id of each external connector
603  *                      in extcon enumeration.
604  * @prop:               the property id among enum extcon_property.
605  * @prop_val:           the pointer which store the value of property.
606  *
607  * When getting the property value of external connector, the external connector
608  * should be attached. If detached state, function just return 0 without
609  * property value. Also, the each property should be included in the list of
610  * supported properties according to the type of external connectors.
611  *
612  * Returns 0 if success or error number if fail
613  */
614 int extcon_get_property(struct extcon_dev *edev, unsigned int id,
615                                 unsigned int prop,
616                                 union extcon_property_value *prop_val)
617 {
618         struct extcon_cable *cable;
619         unsigned long flags;
620         int index, ret = 0;
621
622         *prop_val = (union extcon_property_value)(0);
623
624         if (!edev)
625                 return -EINVAL;
626
627         /* Check whether the property is supported or not */
628         if (!is_extcon_property_supported(id, prop))
629                 return -EINVAL;
630
631         /* Find the cable index of external connector by using id */
632         index = find_cable_index_by_id(edev, id);
633         if (index < 0)
634                 return index;
635
636         spin_lock_irqsave(&edev->lock, flags);
637
638         /* Check whether the property is available or not. */
639         if (!is_extcon_property_capability(edev, id, index, prop)) {
640                 spin_unlock_irqrestore(&edev->lock, flags);
641                 return -EPERM;
642         }
643
644         /*
645          * Check whether the external connector is attached.
646          * If external connector is detached, the user can not
647          * get the property value.
648          */
649         if (!is_extcon_attached(edev, index)) {
650                 spin_unlock_irqrestore(&edev->lock, flags);
651                 return 0;
652         }
653
654         cable = &edev->cables[index];
655
656         /* Get the property value according to extcon type */
657         switch (prop) {
658         case EXTCON_PROP_USB_MIN ... EXTCON_PROP_USB_MAX:
659                 *prop_val = cable->usb_propval[prop - EXTCON_PROP_USB_MIN];
660                 break;
661         case EXTCON_PROP_CHG_MIN ... EXTCON_PROP_CHG_MAX:
662                 *prop_val = cable->chg_propval[prop - EXTCON_PROP_CHG_MIN];
663                 break;
664         case EXTCON_PROP_JACK_MIN ... EXTCON_PROP_JACK_MAX:
665                 *prop_val = cable->jack_propval[prop - EXTCON_PROP_JACK_MIN];
666                 break;
667         case EXTCON_PROP_DISP_MIN ... EXTCON_PROP_DISP_MAX:
668                 *prop_val = cable->disp_propval[prop - EXTCON_PROP_DISP_MIN];
669                 break;
670         default:
671                 ret = -EINVAL;
672                 break;
673         }
674
675         spin_unlock_irqrestore(&edev->lock, flags);
676
677         return ret;
678 }
679 EXPORT_SYMBOL_GPL(extcon_get_property);
680
681 /**
682  * extcon_set_property() - Set the property value of a specific cable.
683  * @edev:               the extcon device that has the cable.
684  * @id:                 the unique id of each external connector
685  *                      in extcon enumeration.
686  * @prop:               the property id among enum extcon_property.
687  * @prop_val:           the pointer including the new value of property.
688  *
689  * The each property should be included in the list of supported properties
690  * according to the type of external connectors.
691  *
692  * Returns 0 if success or error number if fail
693  */
694 int extcon_set_property(struct extcon_dev *edev, unsigned int id,
695                                 unsigned int prop,
696                                 union extcon_property_value prop_val)
697 {
698         struct extcon_cable *cable;
699         unsigned long flags;
700         int index, ret = 0;
701
702         if (!edev)
703                 return -EINVAL;
704
705         /* Check whether the property is supported or not */
706         if (!is_extcon_property_supported(id, prop))
707                 return -EINVAL;
708
709         /* Find the cable index of external connector by using id */
710         index = find_cable_index_by_id(edev, id);
711         if (index < 0)
712                 return index;
713
714         spin_lock_irqsave(&edev->lock, flags);
715
716         /* Check whether the property is available or not. */
717         if (!is_extcon_property_capability(edev, id, index, prop)) {
718                 spin_unlock_irqrestore(&edev->lock, flags);
719                 return -EPERM;
720         }
721
722         cable = &edev->cables[index];
723
724         /* Set the property value according to extcon type */
725         switch (prop) {
726         case EXTCON_PROP_USB_MIN ... EXTCON_PROP_USB_MAX:
727                 cable->usb_propval[prop - EXTCON_PROP_USB_MIN] = prop_val;
728                 break;
729         case EXTCON_PROP_CHG_MIN ... EXTCON_PROP_CHG_MAX:
730                 cable->chg_propval[prop - EXTCON_PROP_CHG_MIN] = prop_val;
731                 break;
732         case EXTCON_PROP_JACK_MIN ... EXTCON_PROP_JACK_MAX:
733                 cable->jack_propval[prop - EXTCON_PROP_JACK_MIN] = prop_val;
734                 break;
735         case EXTCON_PROP_DISP_MIN ... EXTCON_PROP_DISP_MAX:
736                 cable->disp_propval[prop - EXTCON_PROP_DISP_MIN] = prop_val;
737                 break;
738         default:
739                 ret = -EINVAL;
740                 break;
741         }
742
743         spin_unlock_irqrestore(&edev->lock, flags);
744
745         return ret;
746 }
747 EXPORT_SYMBOL_GPL(extcon_set_property);
748
749 /**
750  * extcon_set_property_sync() - Set the property value of a specific cable
751                         with a notification.
752  * @prop_val:           the pointer including the new value of property.
753  *
754  * When setting the property value of external connector, the external connector
755  * should be attached. The each property should be included in the list of
756  * supported properties according to the type of external connectors.
757  *
758  * Returns 0 if success or error number if fail
759  */
760 int extcon_set_property_sync(struct extcon_dev *edev, unsigned int id,
761                                 unsigned int prop,
762                                 union extcon_property_value prop_val)
763 {
764         int ret;
765
766         ret = extcon_set_property(edev, id, prop, prop_val);
767         if (ret < 0)
768                 return ret;
769
770         return extcon_sync(edev, id);
771 }
772 EXPORT_SYMBOL_GPL(extcon_set_property_sync);
773
774 /**
775  * extcon_get_property_capability() - Get the capability of property
776  *                      of an external connector.
777  * @edev:               the extcon device that has the cable.
778  * @id:                 the unique id of each external connector
779  *                      in extcon enumeration.
780  * @prop:               the property id among enum extcon_property.
781  *
782  * Returns 1 if the property is available or 0 if not available.
783  */
784 int extcon_get_property_capability(struct extcon_dev *edev, unsigned int id,
785                                         unsigned int prop)
786 {
787         int index;
788
789         if (!edev)
790                 return -EINVAL;
791
792         /* Check whether the property is supported or not */
793         if (!is_extcon_property_supported(id, prop))
794                 return -EINVAL;
795
796         /* Find the cable index of external connector by using id */
797         index = find_cable_index_by_id(edev, id);
798         if (index < 0)
799                 return index;
800
801         return is_extcon_property_capability(edev, id, index, prop);
802 }
803 EXPORT_SYMBOL_GPL(extcon_get_property_capability);
804
805 /**
806  * extcon_set_property_capability() - Set the capability of a property
807  *                      of an external connector.
808  * @edev:               the extcon device that has the cable.
809  * @id:                 the unique id of each external connector
810  *                      in extcon enumeration.
811  * @prop:               the property id among enum extcon_property.
812  *
813  * This function set the capability of a property for an external connector
814  * to mark the bit in capability bitmap which mean the available state of
815  * a property.
816  *
817  * Returns 0 if success or error number if fail
818  */
819 int extcon_set_property_capability(struct extcon_dev *edev, unsigned int id,
820                                         unsigned int prop)
821 {
822         struct extcon_cable *cable;
823         int index, type, ret = 0;
824
825         if (!edev)
826                 return -EINVAL;
827
828         /* Check whether the property is supported or not. */
829         if (!is_extcon_property_supported(id, prop))
830                 return -EINVAL;
831
832         /* Find the cable index of external connector by using id. */
833         index = find_cable_index_by_id(edev, id);
834         if (index < 0)
835                 return index;
836
837         type = get_extcon_type(prop);
838         if (type < 0)
839                 return type;
840
841         cable = &edev->cables[index];
842
843         switch (type) {
844         case EXTCON_TYPE_USB:
845                 __set_bit(prop - EXTCON_PROP_USB_MIN, cable->usb_bits);
846                 break;
847         case EXTCON_TYPE_CHG:
848                 __set_bit(prop - EXTCON_PROP_CHG_MIN, cable->chg_bits);
849                 break;
850         case EXTCON_TYPE_JACK:
851                 __set_bit(prop - EXTCON_PROP_JACK_MIN, cable->jack_bits);
852                 break;
853         case EXTCON_TYPE_DISP:
854                 __set_bit(prop - EXTCON_PROP_DISP_MIN, cable->disp_bits);
855                 break;
856         default:
857                 ret = -EINVAL;
858         }
859
860         return ret;
861 }
862 EXPORT_SYMBOL_GPL(extcon_set_property_capability);
863
864 /**
865  * extcon_get_extcon_dev() - Get the extcon device instance from the name
866  * @extcon_name:        The extcon name provided with extcon_dev_register()
867  */
868 struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
869 {
870         struct extcon_dev *sd;
871
872         if (!extcon_name)
873                 return ERR_PTR(-EINVAL);
874
875         mutex_lock(&extcon_dev_list_lock);
876         list_for_each_entry(sd, &extcon_dev_list, entry) {
877                 if (!strcmp(sd->name, extcon_name))
878                         goto out;
879         }
880         sd = NULL;
881 out:
882         mutex_unlock(&extcon_dev_list_lock);
883         return sd;
884 }
885 EXPORT_SYMBOL_GPL(extcon_get_extcon_dev);
886
887 /**
888  * extcon_register_notifier() - Register a notifiee to get notified by
889  *                              any attach status changes from the extcon.
890  * @edev:       the extcon device that has the external connecotr.
891  * @id:         the unique id of each external connector in extcon enumeration.
892  * @nb:         a notifier block to be registered.
893  *
894  * Note that the second parameter given to the callback of nb (val) is
895  * "old_state", not the current state. The current state can be retrieved
896  * by looking at the third pameter (edev pointer)'s state value.
897  */
898 int extcon_register_notifier(struct extcon_dev *edev, unsigned int id,
899                              struct notifier_block *nb)
900 {
901         unsigned long flags;
902         int ret, idx = -EINVAL;
903
904         if (!nb)
905                 return -EINVAL;
906
907         if (edev) {
908                 idx = find_cable_index_by_id(edev, id);
909                 if (idx < 0)
910                         return idx;
911
912                 spin_lock_irqsave(&edev->lock, flags);
913                 ret = raw_notifier_chain_register(&edev->nh[idx], nb);
914                 spin_unlock_irqrestore(&edev->lock, flags);
915         } else {
916                 struct extcon_dev *extd;
917
918                 mutex_lock(&extcon_dev_list_lock);
919                 list_for_each_entry(extd, &extcon_dev_list, entry) {
920                         idx = find_cable_index_by_id(extd, id);
921                         if (idx >= 0)
922                                 break;
923                 }
924                 mutex_unlock(&extcon_dev_list_lock);
925
926                 if (idx >= 0) {
927                         edev = extd;
928                         return extcon_register_notifier(extd, id, nb);
929                 } else {
930                         ret = -ENODEV;
931                 }
932         }
933
934         return ret;
935 }
936 EXPORT_SYMBOL_GPL(extcon_register_notifier);
937
938 /**
939  * extcon_unregister_notifier() - Unregister a notifiee from the extcon device.
940  * @edev:       the extcon device that has the external connecotr.
941  * @id:         the unique id of each external connector in extcon enumeration.
942  * @nb:         a notifier block to be registered.
943  */
944 int extcon_unregister_notifier(struct extcon_dev *edev, unsigned int id,
945                                 struct notifier_block *nb)
946 {
947         unsigned long flags;
948         int ret, idx;
949
950         if (!edev || !nb)
951                 return -EINVAL;
952
953         idx = find_cable_index_by_id(edev, id);
954         if (idx < 0)
955                 return idx;
956
957         spin_lock_irqsave(&edev->lock, flags);
958         ret = raw_notifier_chain_unregister(&edev->nh[idx], nb);
959         spin_unlock_irqrestore(&edev->lock, flags);
960
961         return ret;
962 }
963 EXPORT_SYMBOL_GPL(extcon_unregister_notifier);
964
965 static struct attribute *extcon_attrs[] = {
966         &dev_attr_state.attr,
967         &dev_attr_name.attr,
968         NULL,
969 };
970 ATTRIBUTE_GROUPS(extcon);
971
972 static int create_extcon_class(void)
973 {
974         if (!extcon_class) {
975                 extcon_class = class_create(THIS_MODULE, "extcon");
976                 if (IS_ERR(extcon_class))
977                         return PTR_ERR(extcon_class);
978                 extcon_class->dev_groups = extcon_groups;
979
980 #if defined(CONFIG_ANDROID)
981                 switch_class = class_compat_register("switch");
982                 if (WARN(!switch_class, "cannot allocate"))
983                         return -ENOMEM;
984 #endif /* CONFIG_ANDROID */
985         }
986
987         return 0;
988 }
989
990 static void extcon_dev_release(struct device *dev)
991 {
992 }
993
994 static const char *muex_name = "mutually_exclusive";
995 static void dummy_sysfs_dev_release(struct device *dev)
996 {
997 }
998
999 /*
1000  * extcon_dev_allocate() - Allocate the memory of extcon device.
1001  * @supported_cable:    Array of supported extcon ending with EXTCON_NONE.
1002  *                      If supported_cable is NULL, cable name related APIs
1003  *                      are disabled.
1004  *
1005  * This function allocates the memory for extcon device without allocating
1006  * memory in each extcon provider driver and initialize default setting for
1007  * extcon device.
1008  *
1009  * Return the pointer of extcon device if success or ERR_PTR(err) if fail
1010  */
1011 struct extcon_dev *extcon_dev_allocate(const unsigned int *supported_cable)
1012 {
1013         struct extcon_dev *edev;
1014
1015         if (!supported_cable)
1016                 return ERR_PTR(-EINVAL);
1017
1018         edev = kzalloc(sizeof(*edev), GFP_KERNEL);
1019         if (!edev)
1020                 return ERR_PTR(-ENOMEM);
1021
1022         edev->max_supported = 0;
1023         edev->supported_cable = supported_cable;
1024
1025         return edev;
1026 }
1027
1028 /*
1029  * extcon_dev_free() - Free the memory of extcon device.
1030  * @edev:       the extcon device to free
1031  */
1032 void extcon_dev_free(struct extcon_dev *edev)
1033 {
1034         kfree(edev);
1035 }
1036 EXPORT_SYMBOL_GPL(extcon_dev_free);
1037
1038 /**
1039  * extcon_dev_register() - Register a new extcon device
1040  * @edev        : the new extcon device (should be allocated before calling)
1041  *
1042  * Among the members of edev struct, please set the "user initializing data"
1043  * in any case and set the "optional callbacks" if required. However, please
1044  * do not set the values of "internal data", which are initialized by
1045  * this function.
1046  */
1047 int extcon_dev_register(struct extcon_dev *edev)
1048 {
1049         int ret, index = 0;
1050         static atomic_t edev_no = ATOMIC_INIT(-1);
1051
1052         if (!extcon_class) {
1053                 ret = create_extcon_class();
1054                 if (ret < 0)
1055                         return ret;
1056         }
1057
1058         if (!edev || !edev->supported_cable)
1059                 return -EINVAL;
1060
1061         for (; edev->supported_cable[index] != EXTCON_NONE; index++);
1062
1063         edev->max_supported = index;
1064         if (index > SUPPORTED_CABLE_MAX) {
1065                 dev_err(&edev->dev,
1066                         "exceed the maximum number of supported cables\n");
1067                 return -EINVAL;
1068         }
1069
1070         edev->dev.class = extcon_class;
1071         edev->dev.release = extcon_dev_release;
1072
1073         edev->name = dev_name(edev->dev.parent);
1074         if (IS_ERR_OR_NULL(edev->name)) {
1075                 dev_err(&edev->dev,
1076                         "extcon device name is null\n");
1077                 return -EINVAL;
1078         }
1079         dev_set_name(&edev->dev, "extcon%lu",
1080                         (unsigned long)atomic_inc_return(&edev_no));
1081
1082         if (edev->max_supported) {
1083                 char buf[10];
1084                 char *str;
1085                 struct extcon_cable *cable;
1086
1087                 edev->cables = kzalloc(sizeof(struct extcon_cable) *
1088                                        edev->max_supported, GFP_KERNEL);
1089                 if (!edev->cables) {
1090                         ret = -ENOMEM;
1091                         goto err_sysfs_alloc;
1092                 }
1093                 for (index = 0; index < edev->max_supported; index++) {
1094                         cable = &edev->cables[index];
1095
1096                         snprintf(buf, 10, "cable.%d", index);
1097                         str = kzalloc(sizeof(char) * (strlen(buf) + 1),
1098                                       GFP_KERNEL);
1099                         if (!str) {
1100                                 for (index--; index >= 0; index--) {
1101                                         cable = &edev->cables[index];
1102                                         kfree(cable->attr_g.name);
1103                                 }
1104                                 ret = -ENOMEM;
1105
1106                                 goto err_alloc_cables;
1107                         }
1108                         strcpy(str, buf);
1109
1110                         cable->edev = edev;
1111                         cable->cable_index = index;
1112                         cable->attrs[0] = &cable->attr_name.attr;
1113                         cable->attrs[1] = &cable->attr_state.attr;
1114                         cable->attrs[2] = NULL;
1115                         cable->attr_g.name = str;
1116                         cable->attr_g.attrs = cable->attrs;
1117
1118                         sysfs_attr_init(&cable->attr_name.attr);
1119                         cable->attr_name.attr.name = "name";
1120                         cable->attr_name.attr.mode = 0444;
1121                         cable->attr_name.show = cable_name_show;
1122
1123                         sysfs_attr_init(&cable->attr_state.attr);
1124                         cable->attr_state.attr.name = "state";
1125                         cable->attr_state.attr.mode = 0444;
1126                         cable->attr_state.show = cable_state_show;
1127                 }
1128         }
1129
1130         if (edev->max_supported && edev->mutually_exclusive) {
1131                 char buf[80];
1132                 char *name;
1133
1134                 /* Count the size of mutually_exclusive array */
1135                 for (index = 0; edev->mutually_exclusive[index]; index++)
1136                         ;
1137
1138                 edev->attrs_muex = kzalloc(sizeof(struct attribute *) *
1139                                            (index + 1), GFP_KERNEL);
1140                 if (!edev->attrs_muex) {
1141                         ret = -ENOMEM;
1142                         goto err_muex;
1143                 }
1144
1145                 edev->d_attrs_muex = kzalloc(sizeof(struct device_attribute) *
1146                                              index, GFP_KERNEL);
1147                 if (!edev->d_attrs_muex) {
1148                         ret = -ENOMEM;
1149                         kfree(edev->attrs_muex);
1150                         goto err_muex;
1151                 }
1152
1153                 for (index = 0; edev->mutually_exclusive[index]; index++) {
1154                         sprintf(buf, "0x%x", edev->mutually_exclusive[index]);
1155                         name = kzalloc(sizeof(char) * (strlen(buf) + 1),
1156                                        GFP_KERNEL);
1157                         if (!name) {
1158                                 for (index--; index >= 0; index--) {
1159                                         kfree(edev->d_attrs_muex[index].attr.
1160                                               name);
1161                                 }
1162                                 kfree(edev->d_attrs_muex);
1163                                 kfree(edev->attrs_muex);
1164                                 ret = -ENOMEM;
1165                                 goto err_muex;
1166                         }
1167                         strcpy(name, buf);
1168                         sysfs_attr_init(&edev->d_attrs_muex[index].attr);
1169                         edev->d_attrs_muex[index].attr.name = name;
1170                         edev->d_attrs_muex[index].attr.mode = 0000;
1171                         edev->attrs_muex[index] = &edev->d_attrs_muex[index]
1172                                                         .attr;
1173                 }
1174                 edev->attr_g_muex.name = muex_name;
1175                 edev->attr_g_muex.attrs = edev->attrs_muex;
1176
1177         }
1178
1179         if (edev->max_supported) {
1180                 edev->extcon_dev_type.groups =
1181                         kzalloc(sizeof(struct attribute_group *) *
1182                                 (edev->max_supported + 2), GFP_KERNEL);
1183                 if (!edev->extcon_dev_type.groups) {
1184                         ret = -ENOMEM;
1185                         goto err_alloc_groups;
1186                 }
1187
1188                 edev->extcon_dev_type.name = dev_name(&edev->dev);
1189                 edev->extcon_dev_type.release = dummy_sysfs_dev_release;
1190
1191                 for (index = 0; index < edev->max_supported; index++)
1192                         edev->extcon_dev_type.groups[index] =
1193                                 &edev->cables[index].attr_g;
1194                 if (edev->mutually_exclusive)
1195                         edev->extcon_dev_type.groups[index] =
1196                                 &edev->attr_g_muex;
1197
1198                 edev->dev.type = &edev->extcon_dev_type;
1199         }
1200
1201         ret = device_register(&edev->dev);
1202         if (ret) {
1203                 put_device(&edev->dev);
1204                 goto err_dev;
1205         }
1206 #if defined(CONFIG_ANDROID)
1207         if (switch_class)
1208                 ret = class_compat_create_link(switch_class, &edev->dev, NULL);
1209 #endif /* CONFIG_ANDROID */
1210
1211         spin_lock_init(&edev->lock);
1212
1213         edev->nh = devm_kzalloc(&edev->dev,
1214                         sizeof(*edev->nh) * edev->max_supported, GFP_KERNEL);
1215         if (!edev->nh) {
1216                 ret = -ENOMEM;
1217                 goto err_dev;
1218         }
1219
1220         for (index = 0; index < edev->max_supported; index++)
1221                 RAW_INIT_NOTIFIER_HEAD(&edev->nh[index]);
1222
1223         dev_set_drvdata(&edev->dev, edev);
1224         edev->state = 0;
1225
1226         mutex_lock(&extcon_dev_list_lock);
1227         list_add(&edev->entry, &extcon_dev_list);
1228         mutex_unlock(&extcon_dev_list_lock);
1229
1230         return 0;
1231
1232 err_dev:
1233         if (edev->max_supported)
1234                 kfree(edev->extcon_dev_type.groups);
1235 err_alloc_groups:
1236         if (edev->max_supported && edev->mutually_exclusive) {
1237                 for (index = 0; edev->mutually_exclusive[index]; index++)
1238                         kfree(edev->d_attrs_muex[index].attr.name);
1239                 kfree(edev->d_attrs_muex);
1240                 kfree(edev->attrs_muex);
1241         }
1242 err_muex:
1243         for (index = 0; index < edev->max_supported; index++)
1244                 kfree(edev->cables[index].attr_g.name);
1245 err_alloc_cables:
1246         if (edev->max_supported)
1247                 kfree(edev->cables);
1248 err_sysfs_alloc:
1249         return ret;
1250 }
1251 EXPORT_SYMBOL_GPL(extcon_dev_register);
1252
1253 /**
1254  * extcon_dev_unregister() - Unregister the extcon device.
1255  * @edev:       the extcon device instance to be unregistered.
1256  *
1257  * Note that this does not call kfree(edev) because edev was not allocated
1258  * by this class.
1259  */
1260 void extcon_dev_unregister(struct extcon_dev *edev)
1261 {
1262         int index;
1263
1264         if (!edev)
1265                 return;
1266
1267         mutex_lock(&extcon_dev_list_lock);
1268         list_del(&edev->entry);
1269         mutex_unlock(&extcon_dev_list_lock);
1270
1271         if (IS_ERR_OR_NULL(get_device(&edev->dev))) {
1272                 dev_err(&edev->dev, "Failed to unregister extcon_dev (%s)\n",
1273                                 dev_name(&edev->dev));
1274                 return;
1275         }
1276
1277         device_unregister(&edev->dev);
1278
1279         if (edev->mutually_exclusive && edev->max_supported) {
1280                 for (index = 0; edev->mutually_exclusive[index];
1281                                 index++)
1282                         kfree(edev->d_attrs_muex[index].attr.name);
1283                 kfree(edev->d_attrs_muex);
1284                 kfree(edev->attrs_muex);
1285         }
1286
1287         for (index = 0; index < edev->max_supported; index++)
1288                 kfree(edev->cables[index].attr_g.name);
1289
1290         if (edev->max_supported) {
1291                 kfree(edev->extcon_dev_type.groups);
1292                 kfree(edev->cables);
1293         }
1294
1295 #if defined(CONFIG_ANDROID)
1296         if (switch_class)
1297                 class_compat_remove_link(switch_class, &edev->dev, NULL);
1298 #endif
1299         put_device(&edev->dev);
1300 }
1301 EXPORT_SYMBOL_GPL(extcon_dev_unregister);
1302
1303 #ifdef CONFIG_OF
1304 /*
1305  * extcon_get_edev_by_phandle - Get the extcon device from devicetree
1306  * @dev - instance to the given device
1307  * @index - index into list of extcon_dev
1308  *
1309  * return the instance of extcon device
1310  */
1311 struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index)
1312 {
1313         struct device_node *node;
1314         struct extcon_dev *edev;
1315
1316         if (!dev)
1317                 return ERR_PTR(-EINVAL);
1318
1319         if (!dev->of_node) {
1320                 dev_dbg(dev, "device does not have a device node entry\n");
1321                 return ERR_PTR(-EINVAL);
1322         }
1323
1324         node = of_parse_phandle(dev->of_node, "extcon", index);
1325         if (!node) {
1326                 dev_dbg(dev, "failed to get phandle in %s node\n",
1327                         dev->of_node->full_name);
1328                 return ERR_PTR(-ENODEV);
1329         }
1330
1331         mutex_lock(&extcon_dev_list_lock);
1332         list_for_each_entry(edev, &extcon_dev_list, entry) {
1333                 if (edev->dev.parent && edev->dev.parent->of_node == node) {
1334                         mutex_unlock(&extcon_dev_list_lock);
1335                         of_node_put(node);
1336                         return edev;
1337                 }
1338         }
1339         mutex_unlock(&extcon_dev_list_lock);
1340         of_node_put(node);
1341
1342         return ERR_PTR(-EPROBE_DEFER);
1343 }
1344 #else
1345 struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index)
1346 {
1347         return ERR_PTR(-ENOSYS);
1348 }
1349 #endif /* CONFIG_OF */
1350 EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle);
1351
1352 /**
1353  * extcon_get_edev_name() - Get the name of the extcon device.
1354  * @edev:       the extcon device
1355  */
1356 const char *extcon_get_edev_name(struct extcon_dev *edev)
1357 {
1358         return !edev ? NULL : edev->name;
1359 }
1360
1361 static int __init extcon_class_init(void)
1362 {
1363         return create_extcon_class();
1364 }
1365 module_init(extcon_class_init);
1366
1367 static void __exit extcon_class_exit(void)
1368 {
1369 #if defined(CONFIG_ANDROID)
1370         class_compat_unregister(switch_class);
1371 #endif
1372         class_destroy(extcon_class);
1373 }
1374 module_exit(extcon_class_exit);
1375
1376 MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
1377 MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>");
1378 MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>");
1379 MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>");
1380 MODULE_DESCRIPTION("External connector (extcon) class driver");
1381 MODULE_LICENSE("GPL");