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