aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChanwoo Choi <cw00.choi@samsung.com>2015-04-24 06:16:05 -0400
committerChanwoo Choi <cw00.choi@samsung.com>2015-05-22 05:58:44 -0400
commit2a9de9c0f08d61fbe3764a21d22d0b72df97d6ae (patch)
treeabad4db6fcab2a64850e6874856b1d81608bd4bc
parent35eed7a0768886e2f66db3cdbf3faf6435275e6b (diff)
extcon: Use the unique id for external connector instead of string
This patch uses the unique id to identify the type of external connector instead of string name. The string name have the many potential issues. So, this patch defines the 'extcon' enumeration which includes all supported external connector on EXTCON subsystem. If new external connector is necessary, the unique id of new connector have to be added in 'extcon' enumeration. There are current supported external connector in 'enum extcon' as following: enum extcon { EXTCON_NONE = 0x0, /* USB external connector */ EXTCON_USB = 0x1, EXTCON_USB_HOST = 0x2, /* Charger external connector */ EXTCON_TA = 0x10, EXTCON_FAST_CHARGER = 0x11, EXTCON_SLOW_CHARGER = 0x12, EXTCON_CHARGE_DOWNSTREAM = 0x13, /* Audio and video external connector */ EXTCON_LINE_IN = 0x20, EXTCON_LINE_OUT = 0x21, EXTCON_MICROPHONE = 0x22, EXTCON_HEADPHONE = 0x23, EXTCON_HDMI = 0x30, EXTCON_MHL = 0x31, EXTCON_DVI = 0x32, EXTCON_VGA = 0x33, EXTCON_SPDIF_IN = 0x34, EXTCON_SPDIF_OUT = 0x35, EXTCON_VIDEO_IN = 0x36, EXTCON_VIDEO_OUT = 0x37, /* Miscellaneous external connector */ EXTCON_DOCK = 0x50, EXTCON_JIG = 0x51, EXTCON_MECHANICAL = 0x52, EXTCON_END, }; For example in extcon-arizona.c: To use unique id removes the potential issue about handling the inconsistent name of external connector with string. - Previously, use the string to register the type of arizona jack connector static const char *arizona_cable[] = { "Mechanical", "Microphone", "Headphone", "Line-out", }; - Newly, use the unique id to register the type of arizona jack connector static const enum extcon arizona_cable[] = { EXTCON_MECHANICAL, EXTCON_MICROPHONE, EXTCON_HEADPHONE, EXTCON_LINE_OUT, EXTCON_NONE, }; And this patch modify the prototype of extcon_{get|set}_cable_state_() which uses the 'enum extcon id' instead of 'cable_index'. Because although one more extcon drivers support USB cable, each extcon driver might has the differnt 'cable_index' for USB cable. All extcon drivers can use the unique id number for same external connector with modified extcon_{get|set}_cable_state_(). - Previously, use 'cable_index' on these functions: extcon_get_cable_state_(struct extcon_dev*, int cable_index) extcon_set_cable_state_(struct extcon_dev*, int cable_index, bool state) -Newly, use 'enum extcon id' on these functions: extcon_get_cable_state_(struct extcon_dev*, enum extcon id) extcon_set_cable_state_(struct extcon_dev*, enum extcon id, bool state) Cc: Arnd Bergmann <arnd@arndb.de> Cc: Felipe Balbi <balbi@ti.com> Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com> Acked-by: Roger Quadros <rogerq@ti.com> Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com> Acked-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com> Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> [arnd: Report the build break about drivers/usb/phy/phy-tahvo.c after using the unique id for external connector insteadf of string] Reported-by: Arnd Bergmann <arnd@arndb.de> [dan.carpenter: Report the build warning of extcon_{set|get}_cable_state_()] Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
-rw-r--r--drivers/extcon/extcon-arizona.c38
-rw-r--r--drivers/extcon/extcon-axp288.c24
-rw-r--r--drivers/extcon/extcon-max14577.c45
-rw-r--r--drivers/extcon/extcon-max77693.c95
-rw-r--r--drivers/extcon/extcon-max77843.c56
-rw-r--r--drivers/extcon/extcon-max8997.c59
-rw-r--r--drivers/extcon/extcon-palmas.c22
-rw-r--r--drivers/extcon/extcon-rt8973a.c40
-rw-r--r--drivers/extcon/extcon-sm5502.c32
-rw-r--r--drivers/extcon/extcon-usb-gpio.c32
-rw-r--r--drivers/extcon/extcon.c163
-rw-r--r--drivers/usb/phy/phy-tahvo.c9
-rw-r--r--include/linux/extcon.h111
-rw-r--r--include/linux/extcon/extcon-adc-jack.h5
14 files changed, 320 insertions, 411 deletions
diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
index 1ec06b4b4875..9262b45a4484 100644
--- a/drivers/extcon/extcon-arizona.c
+++ b/drivers/extcon/extcon-arizona.c
@@ -118,17 +118,12 @@ static const int arizona_micd_levels[] = {
118 1257, 118 1257,
119}; 119};
120 120
121#define ARIZONA_CABLE_MECHANICAL 0 121static const enum extcon arizona_cable[] = {
122#define ARIZONA_CABLE_MICROPHONE 1 122 EXTCON_MECHANICAL,
123#define ARIZONA_CABLE_HEADPHONE 2 123 EXTCON_MICROPHONE,
124#define ARIZONA_CABLE_LINEOUT 3 124 EXTCON_HEADPHONE,
125 125 EXTCON_LINE_OUT,
126static const char *arizona_cable[] = { 126 EXTCON_NONE,
127 "Mechanical",
128 "Microphone",
129 "Headphone",
130 "Line-out",
131 NULL,
132}; 127};
133 128
134static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info); 129static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info);
@@ -557,7 +552,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
557 struct arizona_extcon_info *info = data; 552 struct arizona_extcon_info *info = data;
558 struct arizona *arizona = info->arizona; 553 struct arizona *arizona = info->arizona;
559 int id_gpio = arizona->pdata.hpdet_id_gpio; 554 int id_gpio = arizona->pdata.hpdet_id_gpio;
560 int report = ARIZONA_CABLE_HEADPHONE; 555 enum extcon report = EXTCON_HEADPHONE;
561 int ret, reading; 556 int ret, reading;
562 bool mic = false; 557 bool mic = false;
563 558
@@ -571,7 +566,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
571 } 566 }
572 567
573 /* If the cable was removed while measuring ignore the result */ 568 /* If the cable was removed while measuring ignore the result */
574 ret = extcon_get_cable_state_(info->edev, ARIZONA_CABLE_MECHANICAL); 569 ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL);
575 if (ret < 0) { 570 if (ret < 0) {
576 dev_err(arizona->dev, "Failed to check cable state: %d\n", 571 dev_err(arizona->dev, "Failed to check cable state: %d\n",
577 ret); 572 ret);
@@ -602,9 +597,9 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
602 597
603 /* Report high impedence cables as line outputs */ 598 /* Report high impedence cables as line outputs */
604 if (reading >= 5000) 599 if (reading >= 5000)
605 report = ARIZONA_CABLE_LINEOUT; 600 report = EXTCON_LINE_OUT;
606 else 601 else
607 report = ARIZONA_CABLE_HEADPHONE; 602 report = EXTCON_HEADPHONE;
608 603
609 ret = extcon_set_cable_state_(info->edev, report, true); 604 ret = extcon_set_cable_state_(info->edev, report, true);
610 if (ret != 0) 605 if (ret != 0)
@@ -689,8 +684,7 @@ err:
689 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC); 684 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
690 685
691 /* Just report headphone */ 686 /* Just report headphone */
692 ret = extcon_set_cable_state_(info->edev, 687 ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true);
693 ARIZONA_CABLE_HEADPHONE, true);
694 if (ret != 0) 688 if (ret != 0)
695 dev_err(arizona->dev, "Failed to report headphone: %d\n", ret); 689 dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
696 690
@@ -747,8 +741,7 @@ err:
747 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC); 741 ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
748 742
749 /* Just report headphone */ 743 /* Just report headphone */
750 ret = extcon_set_cable_state_(info->edev, 744 ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true);
751 ARIZONA_CABLE_HEADPHONE, true);
752 if (ret != 0) 745 if (ret != 0)
753 dev_err(arizona->dev, "Failed to report headphone: %d\n", ret); 746 dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
754 747
@@ -787,7 +780,7 @@ static void arizona_micd_detect(struct work_struct *work)
787 mutex_lock(&info->lock); 780 mutex_lock(&info->lock);
788 781
789 /* If the cable was removed while measuring ignore the result */ 782 /* If the cable was removed while measuring ignore the result */
790 ret = extcon_get_cable_state_(info->edev, ARIZONA_CABLE_MECHANICAL); 783 ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL);
791 if (ret < 0) { 784 if (ret < 0) {
792 dev_err(arizona->dev, "Failed to check cable state: %d\n", 785 dev_err(arizona->dev, "Failed to check cable state: %d\n",
793 ret); 786 ret);
@@ -836,8 +829,7 @@ static void arizona_micd_detect(struct work_struct *work)
836 arizona_identify_headphone(info); 829 arizona_identify_headphone(info);
837 830
838 ret = extcon_set_cable_state_(info->edev, 831 ret = extcon_set_cable_state_(info->edev,
839 ARIZONA_CABLE_MICROPHONE, true); 832 EXTCON_MICROPHONE, true);
840
841 if (ret != 0) 833 if (ret != 0)
842 dev_err(arizona->dev, "Headset report failed: %d\n", 834 dev_err(arizona->dev, "Headset report failed: %d\n",
843 ret); 835 ret);
@@ -1028,7 +1020,7 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
1028 if (info->last_jackdet == present) { 1020 if (info->last_jackdet == present) {
1029 dev_dbg(arizona->dev, "Detected jack\n"); 1021 dev_dbg(arizona->dev, "Detected jack\n");
1030 ret = extcon_set_cable_state_(info->edev, 1022 ret = extcon_set_cable_state_(info->edev,
1031 ARIZONA_CABLE_MECHANICAL, true); 1023 EXTCON_MECHANICAL, true);
1032 1024
1033 if (ret != 0) 1025 if (ret != 0)
1034 dev_err(arizona->dev, "Mechanical report failed: %d\n", 1026 dev_err(arizona->dev, "Mechanical report failed: %d\n",
diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
index 8299adb9b676..3605aa96c25a 100644
--- a/drivers/extcon/extcon-axp288.c
+++ b/drivers/extcon/extcon-axp288.c
@@ -77,10 +77,6 @@
77/* IRQ enable-6 register */ 77/* IRQ enable-6 register */
78#define BC12_IRQ_CFG_MASK BIT(1) 78#define BC12_IRQ_CFG_MASK BIT(1)
79 79
80#define AXP288_EXTCON_SLOW_CHARGER "SLOW-CHARGER"
81#define AXP288_EXTCON_DOWNSTREAM_CHARGER "CHARGE-DOWNSTREAM"
82#define AXP288_EXTCON_FAST_CHARGER "FAST-CHARGER"
83
84enum axp288_extcon_reg { 80enum axp288_extcon_reg {
85 AXP288_PS_STAT_REG = 0x00, 81 AXP288_PS_STAT_REG = 0x00,
86 AXP288_PS_BOOT_REASON_REG = 0x02, 82 AXP288_PS_BOOT_REASON_REG = 0x02,
@@ -105,11 +101,11 @@ enum axp288_extcon_irq {
105 EXTCON_IRQ_END, 101 EXTCON_IRQ_END,
106}; 102};
107 103
108static const char *axp288_extcon_cables[] = { 104static const enum extcon axp288_extcon_cables[] = {
109 AXP288_EXTCON_SLOW_CHARGER, 105 EXTCON_SLOW_CHARGER,
110 AXP288_EXTCON_DOWNSTREAM_CHARGER, 106 EXTCON_CHARGE_DOWNSTREAM,
111 AXP288_EXTCON_FAST_CHARGER, 107 EXTCON_FAST_CHARGER,
112 NULL, 108 EXTCON_NONE,
113}; 109};
114 110
115struct axp288_extcon_info { 111struct axp288_extcon_info {
@@ -161,7 +157,7 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
161static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) 157static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
162{ 158{
163 static bool notify_otg, notify_charger; 159 static bool notify_otg, notify_charger;
164 static char *cable; 160 static enum extcon cable;
165 int ret, stat, cfg, pwr_stat; 161 int ret, stat, cfg, pwr_stat;
166 u8 chrg_type; 162 u8 chrg_type;
167 bool vbus_attach = false; 163 bool vbus_attach = false;
@@ -196,18 +192,18 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
196 dev_dbg(info->dev, "sdp cable is connecetd\n"); 192 dev_dbg(info->dev, "sdp cable is connecetd\n");
197 notify_otg = true; 193 notify_otg = true;
198 notify_charger = true; 194 notify_charger = true;
199 cable = AXP288_EXTCON_SLOW_CHARGER; 195 cable = EXTCON_SLOW_CHARGER;
200 break; 196 break;
201 case DET_STAT_CDP: 197 case DET_STAT_CDP:
202 dev_dbg(info->dev, "cdp cable is connecetd\n"); 198 dev_dbg(info->dev, "cdp cable is connecetd\n");
203 notify_otg = true; 199 notify_otg = true;
204 notify_charger = true; 200 notify_charger = true;
205 cable = AXP288_EXTCON_DOWNSTREAM_CHARGER; 201 cable = EXTCON_CHARGE_DOWNSTREAM;
206 break; 202 break;
207 case DET_STAT_DCP: 203 case DET_STAT_DCP:
208 dev_dbg(info->dev, "dcp cable is connecetd\n"); 204 dev_dbg(info->dev, "dcp cable is connecetd\n");
209 notify_charger = true; 205 notify_charger = true;
210 cable = AXP288_EXTCON_FAST_CHARGER; 206 cable = EXTCON_FAST_CHARGER;
211 break; 207 break;
212 default: 208 default:
213 dev_warn(info->dev, 209 dev_warn(info->dev,
@@ -230,7 +226,7 @@ notify_otg:
230 } 226 }
231 227
232 if (notify_charger) 228 if (notify_charger)
233 extcon_set_cable_state(info->edev, cable, vbus_attach); 229 extcon_set_cable_state_(info->edev, cable, vbus_attach);
234 230
235 /* Clear the flags on disconnect event */ 231 /* Clear the flags on disconnect event */
236 if (!vbus_attach) 232 if (!vbus_attach)
diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
index ad8f8ddc8e51..e7c3edb5bd4b 100644
--- a/drivers/extcon/extcon-max14577.c
+++ b/drivers/extcon/extcon-max14577.c
@@ -148,27 +148,14 @@ enum max14577_muic_acc_type {
148 MAX14577_MUIC_ADC_OPEN, 148 MAX14577_MUIC_ADC_OPEN,
149}; 149};
150 150
151/* max14577 MUIC device support below list of accessories(external connector) */ 151static const enum extcon max14577_extcon_cable[] = {
152enum { 152 EXTCON_USB,
153 EXTCON_CABLE_USB = 0, 153 EXTCON_TA,
154 EXTCON_CABLE_TA, 154 EXTCON_FAST_CHARGER,
155 EXTCON_CABLE_FAST_CHARGER, 155 EXTCON_SLOW_CHARGER,
156 EXTCON_CABLE_SLOW_CHARGER, 156 EXTCON_CHARGE_DOWNSTREAM,
157 EXTCON_CABLE_CHARGE_DOWNSTREAM, 157 EXTCON_JIG,
158 EXTCON_CABLE_JIG, 158 EXTCON_NONE,
159
160 _EXTCON_CABLE_NUM,
161};
162
163static const char *max14577_extcon_cable[] = {
164 [EXTCON_CABLE_USB] = "USB",
165 [EXTCON_CABLE_TA] = "TA",
166 [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger",
167 [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger",
168 [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream",
169 [EXTCON_CABLE_JIG] = "JIG",
170
171 NULL,
172}; 159};
173 160
174/* 161/*
@@ -369,7 +356,7 @@ static int max14577_muic_jig_handler(struct max14577_muic_info *info,
369 if (ret < 0) 356 if (ret < 0)
370 return ret; 357 return ret;
371 358
372 extcon_set_cable_state(info->edev, "JIG", attached); 359 extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
373 360
374 return 0; 361 return 0;
375} 362}
@@ -466,20 +453,22 @@ static int max14577_muic_chg_handler(struct max14577_muic_info *info)
466 if (ret < 0) 453 if (ret < 0)
467 return ret; 454 return ret;
468 455
469 extcon_set_cable_state(info->edev, "USB", attached); 456 extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
470 break; 457 break;
471 case MAX14577_CHARGER_TYPE_DEDICATED_CHG: 458 case MAX14577_CHARGER_TYPE_DEDICATED_CHG:
472 extcon_set_cable_state(info->edev, "TA", attached); 459 extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
473 break; 460 break;
474 case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT: 461 case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
475 extcon_set_cable_state(info->edev, 462 extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM,
476 "Charge-downstream", attached); 463 attached);
477 break; 464 break;
478 case MAX14577_CHARGER_TYPE_SPECIAL_500MA: 465 case MAX14577_CHARGER_TYPE_SPECIAL_500MA:
479 extcon_set_cable_state(info->edev, "Slow-charger", attached); 466 extcon_set_cable_state_(info->edev, EXTCON_SLOW_CHARGER,
467 attached);
480 break; 468 break;
481 case MAX14577_CHARGER_TYPE_SPECIAL_1A: 469 case MAX14577_CHARGER_TYPE_SPECIAL_1A:
482 extcon_set_cable_state(info->edev, "Fast-charger", attached); 470 extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER,
471 attached);
483 break; 472 break;
484 case MAX14577_CHARGER_TYPE_NONE: 473 case MAX14577_CHARGER_TYPE_NONE:
485 case MAX14577_CHARGER_TYPE_DEAD_BATTERY: 474 case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c
index c274249245ff..20e796e10e57 100644
--- a/drivers/extcon/extcon-max77693.c
+++ b/drivers/extcon/extcon-max77693.c
@@ -200,32 +200,17 @@ enum max77693_muic_acc_type {
200/* 200/*
201 * MAX77693 MUIC device support below list of accessories(external connector) 201 * MAX77693 MUIC device support below list of accessories(external connector)
202 */ 202 */
203enum { 203static const enum extcon max77693_extcon_cable[] = {
204 EXTCON_CABLE_USB = 0, 204 EXTCON_USB,
205 EXTCON_CABLE_USB_HOST, 205 EXTCON_USB_HOST,
206 EXTCON_CABLE_TA, 206 EXTCON_TA,
207 EXTCON_CABLE_FAST_CHARGER, 207 EXTCON_FAST_CHARGER,
208 EXTCON_CABLE_SLOW_CHARGER, 208 EXTCON_SLOW_CHARGER,
209 EXTCON_CABLE_CHARGE_DOWNSTREAM, 209 EXTCON_CHARGE_DOWNSTREAM,
210 EXTCON_CABLE_MHL, 210 EXTCON_MHL,
211 EXTCON_CABLE_JIG, 211 EXTCON_JIG,
212 EXTCON_CABLE_DOCK, 212 EXTCON_DOCK,
213 213 EXTCON_NONE,
214 _EXTCON_CABLE_NUM,
215};
216
217static const char *max77693_extcon_cable[] = {
218 [EXTCON_CABLE_USB] = "USB",
219 [EXTCON_CABLE_USB_HOST] = "USB-Host",
220 [EXTCON_CABLE_TA] = "TA",
221 [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger",
222 [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger",
223 [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream",
224 [EXTCON_CABLE_MHL] = "MHL",
225 [EXTCON_CABLE_JIG] = "JIG",
226 [EXTCON_CABLE_DOCK] = "DOCK",
227
228 NULL,
229}; 214};
230 215
231/* 216/*
@@ -472,7 +457,7 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info,
472 int ret = 0; 457 int ret = 0;
473 int vbvolt; 458 int vbvolt;
474 bool cable_attached; 459 bool cable_attached;
475 char dock_name[CABLE_NAME_MAX]; 460 enum extcon dock_id;
476 461
477 dev_info(info->dev, 462 dev_info(info->dev,
478 "external connector is %s (adc:0x%02x)\n", 463 "external connector is %s (adc:0x%02x)\n",
@@ -517,16 +502,16 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info,
517 if (ret < 0) 502 if (ret < 0)
518 return ret; 503 return ret;
519 504
520 extcon_set_cable_state(info->edev, "DOCK", attached); 505 extcon_set_cable_state_(info->edev, EXTCON_DOCK, attached);
521 extcon_set_cable_state(info->edev, "MHL", attached); 506 extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
522 goto out; 507 goto out;
523 case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk */ 508 case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk */
524 strcpy(dock_name, "DOCK"); 509 dock_id = EXTCON_DOCK;
525 break; 510 break;
526 case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */ 511 case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */
527 strcpy(dock_name, "DOCK"); 512 dock_id = EXTCON_DOCK;
528 if (!attached) 513 if (!attached)
529 extcon_set_cable_state(info->edev, "USB", false); 514 extcon_set_cable_state_(info->edev, EXTCON_USB, false);
530 break; 515 break;
531 default: 516 default:
532 dev_err(info->dev, "failed to detect %s dock device\n", 517 dev_err(info->dev, "failed to detect %s dock device\n",
@@ -538,7 +523,7 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info,
538 ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached); 523 ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached);
539 if (ret < 0) 524 if (ret < 0)
540 return ret; 525 return ret;
541 extcon_set_cable_state(info->edev, dock_name, attached); 526 extcon_set_cable_state_(info->edev, dock_id, attached);
542 527
543out: 528out:
544 return 0; 529 return 0;
@@ -603,20 +588,19 @@ static int max77693_muic_adc_ground_handler(struct max77693_muic_info *info)
603 ret = max77693_muic_set_path(info, CONTROL1_SW_USB, attached); 588 ret = max77693_muic_set_path(info, CONTROL1_SW_USB, attached);
604 if (ret < 0) 589 if (ret < 0)
605 return ret; 590 return ret;
606 extcon_set_cable_state(info->edev, "USB-Host", attached); 591 extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached);
607 break; 592 break;
608 case MAX77693_MUIC_GND_AV_CABLE_LOAD: 593 case MAX77693_MUIC_GND_AV_CABLE_LOAD:
609 /* Audio Video Cable with load, PATH:AUDIO */ 594 /* Audio Video Cable with load, PATH:AUDIO */
610 ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached); 595 ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached);
611 if (ret < 0) 596 if (ret < 0)
612 return ret; 597 return ret;
613 extcon_set_cable_state(info->edev, 598 extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
614 "Audio-video-load", attached);
615 break; 599 break;
616 case MAX77693_MUIC_GND_MHL: 600 case MAX77693_MUIC_GND_MHL:
617 case MAX77693_MUIC_GND_MHL_VB: 601 case MAX77693_MUIC_GND_MHL_VB:
618 /* MHL or MHL with USB/TA cable */ 602 /* MHL or MHL with USB/TA cable */
619 extcon_set_cable_state(info->edev, "MHL", attached); 603 extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
620 break; 604 break;
621 default: 605 default:
622 dev_err(info->dev, "failed to detect %s cable of gnd type\n", 606 dev_err(info->dev, "failed to detect %s cable of gnd type\n",
@@ -658,7 +642,7 @@ static int max77693_muic_jig_handler(struct max77693_muic_info *info,
658 if (ret < 0) 642 if (ret < 0)
659 return ret; 643 return ret;
660 644
661 extcon_set_cable_state(info->edev, "JIG", attached); 645 extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
662 646
663 return 0; 647 return 0;
664} 648}
@@ -812,10 +796,10 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
812 * - Support charging through micro-usb port without 796 * - Support charging through micro-usb port without
813 * data connection 797 * data connection
814 */ 798 */
815 extcon_set_cable_state(info->edev, "TA", attached); 799 extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
816 if (!cable_attached) 800 if (!cable_attached)
817 extcon_set_cable_state(info->edev, 801 extcon_set_cable_state_(info->edev, EXTCON_MHL,
818 "MHL", cable_attached); 802 cable_attached);
819 break; 803 break;
820 } 804 }
821 805
@@ -838,11 +822,12 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
838 * - Support charging through micro-usb port without 822 * - Support charging through micro-usb port without
839 * data connection. 823 * data connection.
840 */ 824 */
841 extcon_set_cable_state(info->edev, "USB", attached); 825 extcon_set_cable_state_(info->edev, EXTCON_USB,
826 attached);
842 827
843 if (!cable_attached) 828 if (!cable_attached)
844 extcon_set_cable_state(info->edev, "DOCK", 829 extcon_set_cable_state_(info->edev, EXTCON_DOCK,
845 cable_attached); 830 cable_attached);
846 break; 831 break;
847 case MAX77693_MUIC_ADC_RESERVED_ACC_3: /* Dock-Smart */ 832 case MAX77693_MUIC_ADC_RESERVED_ACC_3: /* Dock-Smart */
848 /* 833 /*
@@ -870,9 +855,10 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
870 if (ret < 0) 855 if (ret < 0)
871 return ret; 856 return ret;
872 857
873 extcon_set_cable_state(info->edev, "DOCK", attached); 858 extcon_set_cable_state_(info->edev, EXTCON_DOCK,
874 extcon_set_cable_state(info->edev, "MHL", attached); 859 attached);
875 860 extcon_set_cable_state_(info->edev, EXTCON_MHL,
861 attached);
876 break; 862 break;
877 } 863 }
878 864
@@ -905,23 +891,26 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
905 if (ret < 0) 891 if (ret < 0)
906 return ret; 892 return ret;
907 893
908 extcon_set_cable_state(info->edev, "USB", attached); 894 extcon_set_cable_state_(info->edev, EXTCON_USB,
895 attached);
909 break; 896 break;
910 case MAX77693_CHARGER_TYPE_DEDICATED_CHG: 897 case MAX77693_CHARGER_TYPE_DEDICATED_CHG:
911 /* Only TA cable */ 898 /* Only TA cable */
912 extcon_set_cable_state(info->edev, "TA", attached); 899 extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
913 break; 900 break;
914 } 901 }
915 break; 902 break;
916 case MAX77693_CHARGER_TYPE_DOWNSTREAM_PORT: 903 case MAX77693_CHARGER_TYPE_DOWNSTREAM_PORT:
917 extcon_set_cable_state(info->edev, 904 extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM,
918 "Charge-downstream", attached); 905 attached);
919 break; 906 break;
920 case MAX77693_CHARGER_TYPE_APPLE_500MA: 907 case MAX77693_CHARGER_TYPE_APPLE_500MA:
921 extcon_set_cable_state(info->edev, "Slow-charger", attached); 908 extcon_set_cable_state_(info->edev, EXTCON_SLOW_CHARGER,
909 attached);
922 break; 910 break;
923 case MAX77693_CHARGER_TYPE_APPLE_1A_2A: 911 case MAX77693_CHARGER_TYPE_APPLE_1A_2A:
924 extcon_set_cable_state(info->edev, "Fast-charger", attached); 912 extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER,
913 attached);
925 break; 914 break;
926 case MAX77693_CHARGER_TYPE_DEAD_BATTERY: 915 case MAX77693_CHARGER_TYPE_DEAD_BATTERY:
927 break; 916 break;
diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c
index 5746d7bc165f..d78a64d7fc20 100644
--- a/drivers/extcon/extcon-max77843.c
+++ b/drivers/extcon/extcon-max77843.c
@@ -118,28 +118,16 @@ enum max77843_muic_charger_type {
118 MAX77843_MUIC_CHG_GND, 118 MAX77843_MUIC_CHG_GND,
119}; 119};
120 120
121enum { 121static const enum extcon max77843_extcon_cable[] = {
122 MAX77843_CABLE_USB = 0, 122 EXTCON_USB,
123 MAX77843_CABLE_USB_HOST, 123 EXTCON_USB_HOST,
124 MAX77843_CABLE_TA, 124 EXTCON_TA,
125 MAX77843_CABLE_CHARGE_DOWNSTREAM, 125 EXTCON_CHARGE_DOWNSTREAM,
126 MAX77843_CABLE_FAST_CHARGER, 126 EXTCON_FAST_CHARGER,
127 MAX77843_CABLE_SLOW_CHARGER, 127 EXTCON_SLOW_CHARGER,
128 MAX77843_CABLE_MHL, 128 EXTCON_MHL,
129 MAX77843_CABLE_JIG, 129 EXTCON_JIG,
130 130 EXTCON_NONE,
131 MAX77843_CABLE_NUM,
132};
133
134static const char *max77843_extcon_cable[] = {
135 [MAX77843_CABLE_USB] = "USB",
136 [MAX77843_CABLE_USB_HOST] = "USB-HOST",
137 [MAX77843_CABLE_TA] = "TA",
138 [MAX77843_CABLE_CHARGE_DOWNSTREAM] = "CHARGER-DOWNSTREAM",
139 [MAX77843_CABLE_FAST_CHARGER] = "FAST-CHARGER",
140 [MAX77843_CABLE_SLOW_CHARGER] = "SLOW-CHARGER",
141 [MAX77843_CABLE_MHL] = "MHL",
142 [MAX77843_CABLE_JIG] = "JIG",
143}; 131};
144 132
145struct max77843_muic_irq { 133struct max77843_muic_irq {
@@ -354,7 +342,7 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info)
354 if (ret < 0) 342 if (ret < 0)
355 return ret; 343 return ret;
356 344
357 extcon_set_cable_state(info->edev, "USB-HOST", attached); 345 extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached);
358 break; 346 break;
359 case MAX77843_MUIC_GND_MHL_VB: 347 case MAX77843_MUIC_GND_MHL_VB:
360 case MAX77843_MUIC_GND_MHL: 348 case MAX77843_MUIC_GND_MHL:
@@ -362,7 +350,7 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info)
362 if (ret < 0) 350 if (ret < 0)
363 return ret; 351 return ret;
364 352
365 extcon_set_cable_state(info->edev, "MHL", attached); 353 extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
366 break; 354 break;
367 default: 355 default:
368 dev_err(info->dev, "failed to detect %s accessory(gnd:0x%x)\n", 356 dev_err(info->dev, "failed to detect %s accessory(gnd:0x%x)\n",
@@ -398,7 +386,7 @@ static int max77843_muic_jig_handler(struct max77843_muic_info *info,
398 if (ret < 0) 386 if (ret < 0)
399 return ret; 387 return ret;
400 388
401 extcon_set_cable_state(info->edev, "JIG", attached); 389 extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
402 390
403 return 0; 391 return 0;
404} 392}
@@ -490,36 +478,38 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
490 if (ret < 0) 478 if (ret < 0)
491 return ret; 479 return ret;
492 480
493 extcon_set_cable_state(info->edev, "USB", attached); 481 extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
494 break; 482 break;
495 case MAX77843_MUIC_CHG_DOWNSTREAM: 483 case MAX77843_MUIC_CHG_DOWNSTREAM:
496 ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 484 ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached);
497 if (ret < 0) 485 if (ret < 0)
498 return ret; 486 return ret;
499 487
500 extcon_set_cable_state(info->edev, 488 extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM,
501 "CHARGER-DOWNSTREAM", attached); 489 attached);
502 break; 490 break;
503 case MAX77843_MUIC_CHG_DEDICATED: 491 case MAX77843_MUIC_CHG_DEDICATED:
504 ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 492 ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached);
505 if (ret < 0) 493 if (ret < 0)
506 return ret; 494 return ret;
507 495
508 extcon_set_cable_state(info->edev, "TA", attached); 496 extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
509 break; 497 break;
510 case MAX77843_MUIC_CHG_SPECIAL_500MA: 498 case MAX77843_MUIC_CHG_SPECIAL_500MA:
511 ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 499 ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached);
512 if (ret < 0) 500 if (ret < 0)
513 return ret; 501 return ret;
514 502
515 extcon_set_cable_state(info->edev, "SLOW-CHAREGER", attached); 503 extcon_set_cable_state_(info->edev, EXTCON_SLOW_CHARGER,
504 attached);
516 break; 505 break;
517 case MAX77843_MUIC_CHG_SPECIAL_1A: 506 case MAX77843_MUIC_CHG_SPECIAL_1A:
518 ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); 507 ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached);
519 if (ret < 0) 508 if (ret < 0)
520 return ret; 509 return ret;
521 510
522 extcon_set_cable_state(info->edev, "FAST-CHARGER", attached); 511 extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER,
512 attached);
523 break; 513 break;
524 case MAX77843_MUIC_CHG_GND: 514 case MAX77843_MUIC_CHG_GND:
525 gnd_type = max77843_muic_get_cable_type(info, 515 gnd_type = max77843_muic_get_cable_type(info,
@@ -527,9 +517,9 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
527 517
528 /* Charger cable on MHL accessory is attach or detach */ 518 /* Charger cable on MHL accessory is attach or detach */
529 if (gnd_type == MAX77843_MUIC_GND_MHL_VB) 519 if (gnd_type == MAX77843_MUIC_GND_MHL_VB)
530 extcon_set_cable_state(info->edev, "TA", true); 520 extcon_set_cable_state_(info->edev, EXTCON_TA, true);
531 else if (gnd_type == MAX77843_MUIC_GND_MHL) 521 else if (gnd_type == MAX77843_MUIC_GND_MHL)
532 extcon_set_cable_state(info->edev, "TA", false); 522 extcon_set_cable_state_(info->edev, EXTCON_TA, false);
533 break; 523 break;
534 case MAX77843_MUIC_CHG_NONE: 524 case MAX77843_MUIC_CHG_NONE:
535 break; 525 break;
diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index 33613c490d34..4d10949c6eb2 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -145,32 +145,17 @@ struct max8997_muic_info {
145 int path_uart; 145 int path_uart;
146}; 146};
147 147
148enum { 148static const enum extcon max8997_extcon_cable[] = {
149 EXTCON_CABLE_USB = 0, 149 EXTCON_USB,
150 EXTCON_CABLE_USB_HOST, 150 EXTCON_USB_HOST,
151 EXTCON_CABLE_TA, 151 EXTCON_TA,
152 EXTCON_CABLE_FAST_CHARGER, 152 EXTCON_FAST_CHARGER,
153 EXTCON_CABLE_SLOW_CHARGER, 153 EXTCON_SLOW_CHARGER,
154 EXTCON_CABLE_CHARGE_DOWNSTREAM, 154 EXTCON_CHARGE_DOWNSTREAM,
155 EXTCON_CABLE_MHL, 155 EXTCON_MHL,
156 EXTCON_CABLE_DOCK, 156 EXTCON_DOCK,
157 EXTCON_CABLE_JIG, 157 EXTCON_JIG,
158 158 EXTCON_NONE,
159 _EXTCON_CABLE_NUM,
160};
161
162static const char *max8997_extcon_cable[] = {
163 [EXTCON_CABLE_USB] = "USB",
164 [EXTCON_CABLE_USB_HOST] = "USB-Host",
165 [EXTCON_CABLE_TA] = "TA",
166 [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger",
167 [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger",
168 [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream",
169 [EXTCON_CABLE_MHL] = "MHL",
170 [EXTCON_CABLE_DOCK] = "DOCK",
171 [EXTCON_CABLE_JIG] = "JIG",
172
173 NULL,
174}; 159};
175 160
176/* 161/*
@@ -345,10 +330,10 @@ static int max8997_muic_handle_usb(struct max8997_muic_info *info,
345 330
346 switch (usb_type) { 331 switch (usb_type) {
347 case MAX8997_USB_HOST: 332 case MAX8997_USB_HOST:
348 extcon_set_cable_state(info->edev, "USB-Host", attached); 333 extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached);
349 break; 334 break;
350 case MAX8997_USB_DEVICE: 335 case MAX8997_USB_DEVICE:
351 extcon_set_cable_state(info->edev, "USB", attached); 336 extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
352 break; 337 break;
353 default: 338 default:
354 dev_err(info->dev, "failed to detect %s usb cable\n", 339 dev_err(info->dev, "failed to detect %s usb cable\n",
@@ -373,7 +358,7 @@ static int max8997_muic_handle_dock(struct max8997_muic_info *info,
373 switch (cable_type) { 358 switch (cable_type) {
374 case MAX8997_MUIC_ADC_AV_CABLE_NOLOAD: 359 case MAX8997_MUIC_ADC_AV_CABLE_NOLOAD:
375 case MAX8997_MUIC_ADC_FACTORY_MODE_UART_ON: 360 case MAX8997_MUIC_ADC_FACTORY_MODE_UART_ON:
376 extcon_set_cable_state(info->edev, "DOCK", attached); 361 extcon_set_cable_state_(info->edev, EXTCON_DOCK, attached);
377 break; 362 break;
378 default: 363 default:
379 dev_err(info->dev, "failed to detect %s dock device\n", 364 dev_err(info->dev, "failed to detect %s dock device\n",
@@ -396,7 +381,7 @@ static int max8997_muic_handle_jig_uart(struct max8997_muic_info *info,
396 return ret; 381 return ret;
397 } 382 }
398 383
399 extcon_set_cable_state(info->edev, "JIG", attached); 384 extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
400 385
401 return 0; 386 return 0;
402} 387}
@@ -418,7 +403,7 @@ static int max8997_muic_adc_handler(struct max8997_muic_info *info)
418 return ret; 403 return ret;
419 break; 404 break;
420 case MAX8997_MUIC_ADC_MHL: 405 case MAX8997_MUIC_ADC_MHL:
421 extcon_set_cable_state(info->edev, "MHL", attached); 406 extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
422 break; 407 break;
423 case MAX8997_MUIC_ADC_FACTORY_MODE_USB_OFF: 408 case MAX8997_MUIC_ADC_FACTORY_MODE_USB_OFF:
424 case MAX8997_MUIC_ADC_FACTORY_MODE_USB_ON: 409 case MAX8997_MUIC_ADC_FACTORY_MODE_USB_ON:
@@ -501,17 +486,19 @@ static int max8997_muic_chg_handler(struct max8997_muic_info *info)
501 } 486 }
502 break; 487 break;
503 case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT: 488 case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT:
504 extcon_set_cable_state(info->edev, 489 extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM,
505 "Charge-downstream", attached); 490 attached);
506 break; 491 break;
507 case MAX8997_CHARGER_TYPE_DEDICATED_CHG: 492 case MAX8997_CHARGER_TYPE_DEDICATED_CHG:
508 extcon_set_cable_state(info->edev, "TA", attached); 493 extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
509 break; 494 break;
510 case MAX8997_CHARGER_TYPE_500MA: 495 case MAX8997_CHARGER_TYPE_500MA:
511 extcon_set_cable_state(info->edev, "Slow-charger", attached); 496 extcon_set_cable_state_(info->edev, EXTCON_SLOW_CHARGER,
497 attached);
512 break; 498 break;
513 case MAX8997_CHARGER_TYPE_1A: 499 case MAX8997_CHARGER_TYPE_1A:
514 extcon_set_cable_state(info->edev, "Fast-charger", attached); 500 extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER,
501 attached);
515 break; 502 break;
516 default: 503 default:
517 dev_err(info->dev, 504 dev_err(info->dev,
diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
index 9c8943d691b1..d68954045a33 100644
--- a/drivers/extcon/extcon-palmas.c
+++ b/drivers/extcon/extcon-palmas.c
@@ -29,10 +29,10 @@
29#include <linux/of.h> 29#include <linux/of.h>
30#include <linux/of_platform.h> 30#include <linux/of_platform.h>
31 31
32static const char *palmas_extcon_cable[] = { 32static const enum extcon palmas_extcon_cable[] = {
33 [0] = "USB", 33 EXTCON_USB,
34 [1] = "USB-HOST", 34 EXTCON_USB_HOST,
35 NULL, 35 EXTCON_NONE,
36}; 36};
37 37
38static const int mutually_exclusive[] = {0x3, 0x0}; 38static const int mutually_exclusive[] = {0x3, 0x0};
@@ -49,6 +49,7 @@ static void palmas_usb_wakeup(struct palmas *palmas, int enable)
49static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb) 49static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
50{ 50{
51 struct palmas_usb *palmas_usb = _palmas_usb; 51 struct palmas_usb *palmas_usb = _palmas_usb;
52 struct extcon_dev *edev = palmas_usb->edev;
52 unsigned int vbus_line_state; 53 unsigned int vbus_line_state;
53 54
54 palmas_read(palmas_usb->palmas, PALMAS_INTERRUPT_BASE, 55 palmas_read(palmas_usb->palmas, PALMAS_INTERRUPT_BASE,
@@ -57,7 +58,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
57 if (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) { 58 if (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) {
58 if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) { 59 if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) {
59 palmas_usb->linkstat = PALMAS_USB_STATE_VBUS; 60 palmas_usb->linkstat = PALMAS_USB_STATE_VBUS;
60 extcon_set_cable_state(palmas_usb->edev, "USB", true); 61 extcon_set_cable_state_(edev, EXTCON_USB, true);
61 dev_info(palmas_usb->dev, "USB cable is attached\n"); 62 dev_info(palmas_usb->dev, "USB cable is attached\n");
62 } else { 63 } else {
63 dev_dbg(palmas_usb->dev, 64 dev_dbg(palmas_usb->dev,
@@ -66,7 +67,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
66 } else if (!(vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS)) { 67 } else if (!(vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS)) {
67 if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) { 68 if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) {
68 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; 69 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
69 extcon_set_cable_state(palmas_usb->edev, "USB", false); 70 extcon_set_cable_state_(edev, EXTCON_USB, false);
70 dev_info(palmas_usb->dev, "USB cable is detached\n"); 71 dev_info(palmas_usb->dev, "USB cable is detached\n");
71 } else { 72 } else {
72 dev_dbg(palmas_usb->dev, 73 dev_dbg(palmas_usb->dev,
@@ -81,6 +82,7 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
81{ 82{
82 unsigned int set, id_src; 83 unsigned int set, id_src;
83 struct palmas_usb *palmas_usb = _palmas_usb; 84 struct palmas_usb *palmas_usb = _palmas_usb;
85 struct extcon_dev *edev = palmas_usb->edev;
84 86
85 palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE, 87 palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
86 PALMAS_USB_ID_INT_LATCH_SET, &set); 88 PALMAS_USB_ID_INT_LATCH_SET, &set);
@@ -93,7 +95,7 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
93 PALMAS_USB_ID_INT_LATCH_CLR, 95 PALMAS_USB_ID_INT_LATCH_CLR,
94 PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND); 96 PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
95 palmas_usb->linkstat = PALMAS_USB_STATE_ID; 97 palmas_usb->linkstat = PALMAS_USB_STATE_ID;
96 extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true); 98 extcon_set_cable_state_(edev, EXTCON_USB_HOST, true);
97 dev_info(palmas_usb->dev, "USB-HOST cable is attached\n"); 99 dev_info(palmas_usb->dev, "USB-HOST cable is attached\n");
98 } else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) && 100 } else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) &&
99 (id_src & PALMAS_USB_ID_INT_SRC_ID_FLOAT)) { 101 (id_src & PALMAS_USB_ID_INT_SRC_ID_FLOAT)) {
@@ -101,17 +103,17 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
101 PALMAS_USB_ID_INT_LATCH_CLR, 103 PALMAS_USB_ID_INT_LATCH_CLR,
102 PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT); 104 PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
103 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; 105 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
104 extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false); 106 extcon_set_cable_state_(edev, EXTCON_USB_HOST, false);
105 dev_info(palmas_usb->dev, "USB-HOST cable is detached\n"); 107 dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
106 } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) && 108 } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) &&
107 (!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) { 109 (!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) {
108 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; 110 palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
109 extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false); 111 extcon_set_cable_state_(edev, EXTCON_USB_HOST, false);
110 dev_info(palmas_usb->dev, "USB-HOST cable is detached\n"); 112 dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
111 } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) && 113 } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) &&
112 (id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) { 114 (id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) {
113 palmas_usb->linkstat = PALMAS_USB_STATE_ID; 115 palmas_usb->linkstat = PALMAS_USB_STATE_ID;
114 extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true); 116 extcon_set_cable_state_(edev, EXTCON_USB_HOST, true);
115 dev_info(palmas_usb->dev, " USB-HOST cable is attached\n"); 117 dev_info(palmas_usb->dev, " USB-HOST cable is attached\n");
116 } 118 }
117 119
diff --git a/drivers/extcon/extcon-rt8973a.c b/drivers/extcon/extcon-rt8973a.c
index 04447f36c994..f2a8672cbf82 100644
--- a/drivers/extcon/extcon-rt8973a.c
+++ b/drivers/extcon/extcon-rt8973a.c
@@ -90,21 +90,12 @@ static struct reg_data rt8973a_reg_data[] = {
90}; 90};
91 91
92/* List of detectable cables */ 92/* List of detectable cables */
93enum { 93static const enum extcon rt8973a_extcon_cable[] = {
94 EXTCON_CABLE_USB = 0, 94 EXTCON_USB,
95 EXTCON_CABLE_USB_HOST, 95 EXTCON_USB_HOST,
96 EXTCON_CABLE_TA, 96 EXTCON_TA,
97 EXTCON_CABLE_JIG, 97 EXTCON_JIG,
98 98 EXTCON_NONE,
99 EXTCON_CABLE_END,
100};
101
102static const char *rt8973a_extcon_cable[] = {
103 [EXTCON_CABLE_USB] = "USB",
104 [EXTCON_CABLE_USB_HOST] = "USB-Host",
105 [EXTCON_CABLE_TA] = "TA",
106 [EXTCON_CABLE_JIG] = "JIG",
107 NULL,
108}; 99};
109 100
110/* Define OVP (Over Voltage Protection), OTP (Over Temperature Protection) */ 101/* Define OVP (Over Voltage Protection), OTP (Over Temperature Protection) */
@@ -307,14 +298,11 @@ static int rt8973a_muic_cable_handler(struct rt8973a_muic_info *info,
307 enum rt8973a_event_type event) 298 enum rt8973a_event_type event)
308{ 299{
309 static unsigned int prev_cable_type; 300 static unsigned int prev_cable_type;
310 const char **cable_names = info->edev->supported_cable;
311 unsigned int con_sw = DM_DP_SWITCH_UART; 301 unsigned int con_sw = DM_DP_SWITCH_UART;
312 int ret, idx = 0, cable_type; 302 int ret, cable_type;
303 enum extcon id;
313 bool attached = false; 304 bool attached = false;
314 305
315 if (!cable_names)
316 return 0;
317
318 switch (event) { 306 switch (event) {
319 case RT8973A_EVENT_ATTACH: 307 case RT8973A_EVENT_ATTACH:
320 cable_type = rt8973a_muic_get_cable_type(info); 308 cable_type = rt8973a_muic_get_cable_type(info);
@@ -341,25 +329,25 @@ static int rt8973a_muic_cable_handler(struct rt8973a_muic_info *info,
341 329
342 switch (cable_type) { 330 switch (cable_type) {
343 case RT8973A_MUIC_ADC_OTG: 331 case RT8973A_MUIC_ADC_OTG:
344 idx = EXTCON_CABLE_USB_HOST; 332 id = EXTCON_USB_HOST;
345 con_sw = DM_DP_SWITCH_USB; 333 con_sw = DM_DP_SWITCH_USB;
346 break; 334 break;
347 case RT8973A_MUIC_ADC_TA: 335 case RT8973A_MUIC_ADC_TA:
348 idx = EXTCON_CABLE_TA; 336 id = EXTCON_TA;
349 con_sw = DM_DP_SWITCH_OPEN; 337 con_sw = DM_DP_SWITCH_OPEN;
350 break; 338 break;
351 case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB: 339 case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB:
352 case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB: 340 case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB:
353 idx = EXTCON_CABLE_JIG; 341 id = EXTCON_JIG;
354 con_sw = DM_DP_SWITCH_USB; 342 con_sw = DM_DP_SWITCH_USB;
355 break; 343 break;
356 case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART: 344 case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART:
357 case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART: 345 case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART:
358 idx = EXTCON_CABLE_JIG; 346 id = EXTCON_JIG;
359 con_sw = DM_DP_SWITCH_UART; 347 con_sw = DM_DP_SWITCH_UART;
360 break; 348 break;
361 case RT8973A_MUIC_ADC_USB: 349 case RT8973A_MUIC_ADC_USB:
362 idx = EXTCON_CABLE_USB; 350 id = EXTCON_USB;
363 con_sw = DM_DP_SWITCH_USB; 351 con_sw = DM_DP_SWITCH_USB;
364 break; 352 break;
365 case RT8973A_MUIC_ADC_OPEN: 353 case RT8973A_MUIC_ADC_OPEN:
@@ -409,7 +397,7 @@ static int rt8973a_muic_cable_handler(struct rt8973a_muic_info *info,
409 return ret; 397 return ret;
410 398
411 /* Change the state of external accessory */ 399 /* Change the state of external accessory */
412 extcon_set_cable_state(info->edev, cable_names[idx], attached); 400 extcon_set_cable_state_(info->edev, id, attached);
413 401
414 return 0; 402 return 0;
415} 403}
diff --git a/drivers/extcon/extcon-sm5502.c b/drivers/extcon/extcon-sm5502.c
index 6f1d11f8723b..520693d6fa8a 100644
--- a/drivers/extcon/extcon-sm5502.c
+++ b/drivers/extcon/extcon-sm5502.c
@@ -92,19 +92,11 @@ static struct reg_data sm5502_reg_data[] = {
92}; 92};
93 93
94/* List of detectable cables */ 94/* List of detectable cables */
95enum { 95static const enum extcon sm5502_extcon_cable[] = {
96 EXTCON_CABLE_USB = 0, 96 EXTCON_USB,
97 EXTCON_CABLE_USB_HOST, 97 EXTCON_USB_HOST,
98 EXTCON_CABLE_TA, 98 EXTCON_TA,
99 99 EXTCON_NONE,
100 EXTCON_CABLE_END,
101};
102
103static const char *sm5502_extcon_cable[] = {
104 [EXTCON_CABLE_USB] = "USB",
105 [EXTCON_CABLE_USB_HOST] = "USB-Host",
106 [EXTCON_CABLE_TA] = "TA",
107 NULL,
108}; 100};
109 101
110/* Define supported accessory type */ 102/* Define supported accessory type */
@@ -377,16 +369,12 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info,
377 bool attached) 369 bool attached)
378{ 370{
379 static unsigned int prev_cable_type = SM5502_MUIC_ADC_GROUND; 371 static unsigned int prev_cable_type = SM5502_MUIC_ADC_GROUND;
380 const char **cable_names = info->edev->supported_cable;
381 unsigned int cable_type = SM5502_MUIC_ADC_GROUND; 372 unsigned int cable_type = SM5502_MUIC_ADC_GROUND;
382 unsigned int con_sw = DM_DP_SWITCH_OPEN; 373 unsigned int con_sw = DM_DP_SWITCH_OPEN;
383 unsigned int vbus_sw = VBUSIN_SWITCH_OPEN; 374 unsigned int vbus_sw = VBUSIN_SWITCH_OPEN;
384 unsigned int idx = 0; 375 enum extcon id;
385 int ret; 376 int ret;
386 377
387 if (!cable_names)
388 return 0;
389
390 /* Get the type of attached or detached cable */ 378 /* Get the type of attached or detached cable */
391 if (attached) 379 if (attached)
392 cable_type = sm5502_muic_get_cable_type(info); 380 cable_type = sm5502_muic_get_cable_type(info);
@@ -396,17 +384,17 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info,
396 384
397 switch (cable_type) { 385 switch (cable_type) {
398 case SM5502_MUIC_ADC_OPEN_USB: 386 case SM5502_MUIC_ADC_OPEN_USB:
399 idx = EXTCON_CABLE_USB; 387 id = EXTCON_USB;
400 con_sw = DM_DP_SWITCH_USB; 388 con_sw = DM_DP_SWITCH_USB;
401 vbus_sw = VBUSIN_SWITCH_VBUSOUT_WITH_USB; 389 vbus_sw = VBUSIN_SWITCH_VBUSOUT_WITH_USB;
402 break; 390 break;
403 case SM5502_MUIC_ADC_OPEN_TA: 391 case SM5502_MUIC_ADC_OPEN_TA:
404 idx = EXTCON_CABLE_TA; 392 id = EXTCON_TA;
405 con_sw = DM_DP_SWITCH_OPEN; 393 con_sw = DM_DP_SWITCH_OPEN;
406 vbus_sw = VBUSIN_SWITCH_VBUSOUT; 394 vbus_sw = VBUSIN_SWITCH_VBUSOUT;
407 break; 395 break;
408 case SM5502_MUIC_ADC_OPEN_USB_OTG: 396 case SM5502_MUIC_ADC_OPEN_USB_OTG:
409 idx = EXTCON_CABLE_USB_HOST; 397 id = EXTCON_USB_HOST;
410 con_sw = DM_DP_SWITCH_USB; 398 con_sw = DM_DP_SWITCH_USB;
411 vbus_sw = VBUSIN_SWITCH_OPEN; 399 vbus_sw = VBUSIN_SWITCH_OPEN;
412 break; 400 break;
@@ -422,7 +410,7 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info,
422 return ret; 410 return ret;
423 411
424 /* Change the state of external accessory */ 412 /* Change the state of external accessory */
425 extcon_set_cable_state(info->edev, cable_names[idx], attached); 413 extcon_set_cable_state_(info->edev, id, attached);
426 414
427 return 0; 415 return 0;
428} 416}
diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
index 900744b978fc..14da94cb57fa 100644
--- a/drivers/extcon/extcon-usb-gpio.c
+++ b/drivers/extcon/extcon-usb-gpio.c
@@ -39,18 +39,10 @@ struct usb_extcon_info {
39 struct delayed_work wq_detcable; 39 struct delayed_work wq_detcable;
40}; 40};
41 41
42/* List of detectable cables */ 42static const enum extcon usb_extcon_cable[] = {
43enum { 43 EXTCON_USB,
44 EXTCON_CABLE_USB = 0, 44 EXTCON_USB_HOST,
45 EXTCON_CABLE_USB_HOST, 45 EXTCON_NONE,
46
47 EXTCON_CABLE_END,
48};
49
50static const char *usb_extcon_cable[] = {
51 [EXTCON_CABLE_USB] = "USB",
52 [EXTCON_CABLE_USB_HOST] = "USB-HOST",
53 NULL,
54}; 46};
55 47
56static void usb_extcon_detect_cable(struct work_struct *work) 48static void usb_extcon_detect_cable(struct work_struct *work)
@@ -68,24 +60,16 @@ static void usb_extcon_detect_cable(struct work_struct *work)
68 * As we don't have event for USB peripheral cable attached, 60 * As we don't have event for USB peripheral cable attached,
69 * we simulate USB peripheral attach here. 61 * we simulate USB peripheral attach here.
70 */ 62 */
71 extcon_set_cable_state(info->edev, 63 extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, false);
72 usb_extcon_cable[EXTCON_CABLE_USB_HOST], 64 extcon_set_cable_state_(info->edev, EXTCON_USB, true);
73 false);
74 extcon_set_cable_state(info->edev,
75 usb_extcon_cable[EXTCON_CABLE_USB],
76 true);
77 } else { 65 } else {
78 /* 66 /*
79 * ID = 0 means USB HOST cable attached. 67 * ID = 0 means USB HOST cable attached.
80 * As we don't have event for USB peripheral cable detached, 68 * As we don't have event for USB peripheral cable detached,
81 * we simulate USB peripheral detach here. 69 * we simulate USB peripheral detach here.
82 */ 70 */
83 extcon_set_cable_state(info->edev, 71 extcon_set_cable_state_(info->edev, EXTCON_USB, false);
84 usb_extcon_cable[EXTCON_CABLE_USB], 72 extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, true);
85 false);
86 extcon_set_cable_state(info->edev,
87 usb_extcon_cable[EXTCON_CABLE_USB_HOST],
88 true);
89 } 73 }
90} 74}
91 75
diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index 2fb5f757e811..a57355fc8fea 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -3,6 +3,9 @@
3 * 3 *
4 * External connector (extcon) class driver 4 * External connector (extcon) class driver
5 * 5 *
6 * Copyright (C) 2015 Samsung Electronics
7 * Author: Chanwoo Choi <cw00.choi@samsung.com>
8 *
6 * Copyright (C) 2012 Samsung Electronics 9 * Copyright (C) 2012 Samsung Electronics
7 * Author: Donggeun Kim <dg77.kim@samsung.com> 10 * Author: Donggeun Kim <dg77.kim@samsung.com>
8 * Author: MyungJoo Ham <myungjoo.ham@samsung.com> 11 * Author: MyungJoo Ham <myungjoo.ham@samsung.com>
@@ -32,36 +35,32 @@
32#include <linux/slab.h> 35#include <linux/slab.h>
33#include <linux/sysfs.h> 36#include <linux/sysfs.h>
34 37
35/* 38#define SUPPORTED_CABLE_MAX 32
36 * extcon_cable_name suggests the standard cable names for commonly used 39#define CABLE_NAME_MAX 30
37 * cable types. 40
38 * 41static const char *extcon_name[] = {
39 * However, please do not use extcon_cable_name directly for extcon_dev
40 * struct's supported_cable pointer unless your device really supports
41 * every single port-type of the following cable names. Please choose cable
42 * names that are actually used in your extcon device.
43 */
44const char extcon_cable_name[][CABLE_NAME_MAX + 1] = {
45 [EXTCON_USB] = "USB", 42 [EXTCON_USB] = "USB",
46 [EXTCON_USB_HOST] = "USB-Host", 43 [EXTCON_USB_HOST] = "USB-Host",
47 [EXTCON_TA] = "TA", 44 [EXTCON_TA] = "TA",
48 [EXTCON_FAST_CHARGER] = "Fast-charger", 45 [EXTCON_FAST_CHARGER] = "Fast-charger",
49 [EXTCON_SLOW_CHARGER] = "Slow-charger", 46 [EXTCON_SLOW_CHARGER] = "Slow-charger",
50 [EXTCON_CHARGE_DOWNSTREAM] = "Charge-downstream", 47 [EXTCON_CHARGE_DOWNSTREAM] = "Charge-downstream",
48 [EXTCON_LINE_IN] = "Line-in",
49 [EXTCON_LINE_OUT] = "Line-out",
50 [EXTCON_MICROPHONE] = "Microphone",
51 [EXTCON_HEADPHONE] = "Headphone",
51 [EXTCON_HDMI] = "HDMI", 52 [EXTCON_HDMI] = "HDMI",
52 [EXTCON_MHL] = "MHL", 53 [EXTCON_MHL] = "MHL",
53 [EXTCON_DVI] = "DVI", 54 [EXTCON_DVI] = "DVI",
54 [EXTCON_VGA] = "VGA", 55 [EXTCON_VGA] = "VGA",
55 [EXTCON_DOCK] = "Dock",
56 [EXTCON_LINE_IN] = "Line-in",
57 [EXTCON_LINE_OUT] = "Line-out",
58 [EXTCON_MIC_IN] = "Microphone",
59 [EXTCON_HEADPHONE_OUT] = "Headphone",
60 [EXTCON_SPDIF_IN] = "SPDIF-in", 56 [EXTCON_SPDIF_IN] = "SPDIF-in",
61 [EXTCON_SPDIF_OUT] = "SPDIF-out", 57 [EXTCON_SPDIF_OUT] = "SPDIF-out",
62 [EXTCON_VIDEO_IN] = "Video-in", 58 [EXTCON_VIDEO_IN] = "Video-in",
63 [EXTCON_VIDEO_OUT] = "Video-out", 59 [EXTCON_VIDEO_OUT] = "Video-out",
60 [EXTCON_DOCK] = "Dock",
61 [EXTCON_JIG] = "JIG",
64 [EXTCON_MECHANICAL] = "Mechanical", 62 [EXTCON_MECHANICAL] = "Mechanical",
63 NULL,
65}; 64};
66 65
67static struct class *extcon_class; 66static struct class *extcon_class;
@@ -101,6 +100,43 @@ static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state)
101 return 0; 100 return 0;
102} 101}
103 102
103static int find_cable_index_by_id(struct extcon_dev *edev, const enum extcon id)
104{
105 int i;
106
107 /* Find the the index of extcon cable in edev->supported_cable */
108 for (i = 0; i < edev->max_supported; i++) {
109 if (edev->supported_cable[i] == id)
110 return i;
111 }
112
113 return -EINVAL;
114}
115
116static int find_cable_index_by_name(struct extcon_dev *edev, const char *name)
117{
118 enum extcon id = EXTCON_NONE;
119 int i;
120
121 if (edev->max_supported == 0)
122 return -EINVAL;
123
124 /* Find the the number of extcon cable */
125 for (i = 0; i < EXTCON_END; i++) {
126 if (!extcon_name[i])
127 continue;
128 if (!strncmp(extcon_name[i], name, CABLE_NAME_MAX)) {
129 id = i;
130 break;
131 }
132 }
133
134 if (id == EXTCON_NONE)
135 return -EINVAL;
136
137 return find_cable_index_by_id(edev, id);
138}
139
104static ssize_t state_show(struct device *dev, struct device_attribute *attr, 140static ssize_t state_show(struct device *dev, struct device_attribute *attr,
105 char *buf) 141 char *buf)
106{ 142{
@@ -118,11 +154,9 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
118 if (edev->max_supported == 0) 154 if (edev->max_supported == 0)
119 return sprintf(buf, "%u\n", edev->state); 155 return sprintf(buf, "%u\n", edev->state);
120 156
121 for (i = 0; i < SUPPORTED_CABLE_MAX; i++) { 157 for (i = 0; i < edev->max_supported; i++) {
122 if (!edev->supported_cable[i])
123 break;
124 count += sprintf(buf + count, "%s=%d\n", 158 count += sprintf(buf + count, "%s=%d\n",
125 edev->supported_cable[i], 159 extcon_name[edev->supported_cable[i]],
126 !!(edev->state & (1 << i))); 160 !!(edev->state & (1 << i)));
127 } 161 }
128 162
@@ -171,9 +205,10 @@ static ssize_t cable_name_show(struct device *dev,
171{ 205{
172 struct extcon_cable *cable = container_of(attr, struct extcon_cable, 206 struct extcon_cable *cable = container_of(attr, struct extcon_cable,
173 attr_name); 207 attr_name);
208 int i = cable->cable_index;
174 209
175 return sprintf(buf, "%s\n", 210 return sprintf(buf, "%s\n",
176 cable->edev->supported_cable[cable->cable_index]); 211 extcon_name[cable->edev->supported_cable[i]]);
177} 212}
178 213
179static ssize_t cable_state_show(struct device *dev, 214static ssize_t cable_state_show(struct device *dev,
@@ -283,39 +318,19 @@ int extcon_set_state(struct extcon_dev *edev, u32 state)
283EXPORT_SYMBOL_GPL(extcon_set_state); 318EXPORT_SYMBOL_GPL(extcon_set_state);
284 319
285/** 320/**
286 * extcon_find_cable_index() - Get the cable index based on the cable name. 321 * extcon_get_cable_state_() - Get the status of a specific cable.
287 * @edev: the extcon device that has the cable. 322 * @edev: the extcon device that has the cable.
288 * @cable_name: cable name to be searched. 323 * @id: the unique id of each external connector in extcon enumeration.
289 *
290 * Note that accessing a cable state based on cable_index is faster than
291 * cable_name because using cable_name induces a loop with strncmp().
292 * Thus, when get/set_cable_state is repeatedly used, using cable_index
293 * is recommended.
294 */ 324 */
295int extcon_find_cable_index(struct extcon_dev *edev, const char *cable_name) 325int extcon_get_cable_state_(struct extcon_dev *edev, const enum extcon id)
296{ 326{
297 int i; 327 int index;
298
299 if (edev->supported_cable) {
300 for (i = 0; edev->supported_cable[i]; i++) {
301 if (!strncmp(edev->supported_cable[i],
302 cable_name, CABLE_NAME_MAX))
303 return i;
304 }
305 }
306 328
307 return -EINVAL; 329 index = find_cable_index_by_id(edev, id);
308} 330 if (index < 0)
309EXPORT_SYMBOL_GPL(extcon_find_cable_index); 331 return index;
310 332
311/** 333 if (edev->max_supported && edev->max_supported <= index)
312 * extcon_get_cable_state_() - Get the status of a specific cable.
313 * @edev: the extcon device that has the cable.
314 * @index: cable index that can be retrieved by extcon_find_cable_index().
315 */
316int extcon_get_cable_state_(struct extcon_dev *edev, int index)
317{
318 if (index < 0 || (edev->max_supported && edev->max_supported <= index))
319 return -EINVAL; 334 return -EINVAL;
320 335
321 return !!(edev->state & (1 << index)); 336 return !!(edev->state & (1 << index));
@@ -331,7 +346,7 @@ EXPORT_SYMBOL_GPL(extcon_get_cable_state_);
331 */ 346 */
332int extcon_get_cable_state(struct extcon_dev *edev, const char *cable_name) 347int extcon_get_cable_state(struct extcon_dev *edev, const char *cable_name)
333{ 348{
334 return extcon_get_cable_state_(edev, extcon_find_cable_index 349 return extcon_get_cable_state_(edev, find_cable_index_by_name
335 (edev, cable_name)); 350 (edev, cable_name));
336} 351}
337EXPORT_SYMBOL_GPL(extcon_get_cable_state); 352EXPORT_SYMBOL_GPL(extcon_get_cable_state);
@@ -339,17 +354,22 @@ EXPORT_SYMBOL_GPL(extcon_get_cable_state);
339/** 354/**
340 * extcon_set_cable_state_() - Set the status of a specific cable. 355 * extcon_set_cable_state_() - Set the status of a specific cable.
341 * @edev: the extcon device that has the cable. 356 * @edev: the extcon device that has the cable.
342 * @index: cable index that can be retrieved by 357 * @id: the unique id of each external connector
343 * extcon_find_cable_index(). 358 * in extcon enumeration.
344 * @cable_state: the new cable status. The default semantics is 359 * @state: the new cable status. The default semantics is
345 * true: attached / false: detached. 360 * true: attached / false: detached.
346 */ 361 */
347int extcon_set_cable_state_(struct extcon_dev *edev, 362int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id,
348 int index, bool cable_state) 363 bool cable_state)
349{ 364{
350 u32 state; 365 u32 state;
366 int index;
351 367
352 if (index < 0 || (edev->max_supported && edev->max_supported <= index)) 368 index = find_cable_index_by_id(edev, id);
369 if (index < 0)
370 return index;
371
372 if (edev->max_supported && edev->max_supported <= index)
353 return -EINVAL; 373 return -EINVAL;
354 374
355 state = cable_state ? (1 << index) : 0; 375 state = cable_state ? (1 << index) : 0;
@@ -369,7 +389,7 @@ EXPORT_SYMBOL_GPL(extcon_set_cable_state_);
369int extcon_set_cable_state(struct extcon_dev *edev, 389int extcon_set_cable_state(struct extcon_dev *edev,
370 const char *cable_name, bool cable_state) 390 const char *cable_name, bool cable_state)
371{ 391{
372 return extcon_set_cable_state_(edev, extcon_find_cable_index 392 return extcon_set_cable_state_(edev, find_cable_index_by_name
373 (edev, cable_name), cable_state); 393 (edev, cable_name), cable_state);
374} 394}
375EXPORT_SYMBOL_GPL(extcon_set_cable_state); 395EXPORT_SYMBOL_GPL(extcon_set_cable_state);
@@ -455,8 +475,8 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj,
455 if (!obj->edev) 475 if (!obj->edev)
456 return -ENODEV; 476 return -ENODEV;
457 477
458 obj->cable_index = extcon_find_cable_index(obj->edev, 478 obj->cable_index = find_cable_index_by_name(obj->edev,
459 cable_name); 479 cable_name);
460 if (obj->cable_index < 0) 480 if (obj->cable_index < 0)
461 return obj->cable_index; 481 return obj->cable_index;
462 482
@@ -479,7 +499,7 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj,
479 while ((dev = class_dev_iter_next(&iter))) { 499 while ((dev = class_dev_iter_next(&iter))) {
480 extd = dev_get_drvdata(dev); 500 extd = dev_get_drvdata(dev);
481 501
482 if (extcon_find_cable_index(extd, cable_name) < 0) 502 if (find_cable_index_by_name(extd, cable_name) < 0)
483 continue; 503 continue;
484 504
485 class_dev_iter_exit(&iter); 505 class_dev_iter_exit(&iter);
@@ -595,7 +615,7 @@ static void dummy_sysfs_dev_release(struct device *dev)
595 615
596/* 616/*
597 * extcon_dev_allocate() - Allocate the memory of extcon device. 617 * extcon_dev_allocate() - Allocate the memory of extcon device.
598 * @supported_cable: Array of supported cable names ending with NULL. 618 * @supported_cable: Array of supported extcon ending with EXTCON_NONE.
599 * If supported_cable is NULL, cable name related APIs 619 * If supported_cable is NULL, cable name related APIs
600 * are disabled. 620 * are disabled.
601 * 621 *
@@ -605,7 +625,7 @@ static void dummy_sysfs_dev_release(struct device *dev)
605 * 625 *
606 * Return the pointer of extcon device if success or ERR_PTR(err) if fail 626 * Return the pointer of extcon device if success or ERR_PTR(err) if fail
607 */ 627 */
608struct extcon_dev *extcon_dev_allocate(const char **supported_cable) 628struct extcon_dev *extcon_dev_allocate(const enum extcon *supported_cable)
609{ 629{
610 struct extcon_dev *edev; 630 struct extcon_dev *edev;
611 631
@@ -647,7 +667,7 @@ static void devm_extcon_dev_release(struct device *dev, void *res)
647/** 667/**
648 * devm_extcon_dev_allocate - Allocate managed extcon device 668 * devm_extcon_dev_allocate - Allocate managed extcon device
649 * @dev: device owning the extcon device being created 669 * @dev: device owning the extcon device being created
650 * @supported_cable: Array of supported cable names ending with NULL. 670 * @supported_cable: Array of supported extcon ending with EXTCON_NONE.
651 * If supported_cable is NULL, cable name related APIs 671 * If supported_cable is NULL, cable name related APIs
652 * are disabled. 672 * are disabled.
653 * 673 *
@@ -659,7 +679,7 @@ static void devm_extcon_dev_release(struct device *dev, void *res)
659 * or ERR_PTR(err) if fail 679 * or ERR_PTR(err) if fail
660 */ 680 */
661struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, 681struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
662 const char **supported_cable) 682 const enum extcon *supported_cable)
663{ 683{
664 struct extcon_dev **ptr, *edev; 684 struct extcon_dev **ptr, *edev;
665 685
@@ -709,17 +729,15 @@ int extcon_dev_register(struct extcon_dev *edev)
709 return ret; 729 return ret;
710 } 730 }
711 731
712 if (edev->supported_cable) { 732 if (!edev->supported_cable)
713 /* Get size of array */ 733 return -EINVAL;
714 for (index = 0; edev->supported_cable[index]; index++) 734
715 ; 735 for (; edev->supported_cable[index] != EXTCON_NONE; index++);
716 edev->max_supported = index;
717 } else {
718 edev->max_supported = 0;
719 }
720 736
737 edev->max_supported = index;
721 if (index > SUPPORTED_CABLE_MAX) { 738 if (index > SUPPORTED_CABLE_MAX) {
722 dev_err(&edev->dev, "extcon: maximum number of supported cables exceeded.\n"); 739 dev_err(&edev->dev,
740 "exceed the maximum number of supported cables\n");
723 return -EINVAL; 741 return -EINVAL;
724 } 742 }
725 743
@@ -1070,6 +1088,7 @@ static void __exit extcon_class_exit(void)
1070} 1088}
1071module_exit(extcon_class_exit); 1089module_exit(extcon_class_exit);
1072 1090
1091MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
1073MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>"); 1092MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>");
1074MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>"); 1093MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>");
1075MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); 1094MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>");
diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c
index 845f658276b1..1d1bb9ad8ccf 100644
--- a/drivers/usb/phy/phy-tahvo.c
+++ b/drivers/usb/phy/phy-tahvo.c
@@ -60,10 +60,11 @@ struct tahvo_usb {
60 struct extcon_dev extcon; 60 struct extcon_dev extcon;
61}; 61};
62 62
63static const char *tahvo_cable[] = { 63static const enum extcon tahvo_cable[] = {
64 "USB-HOST", 64 EXTCON_USB,
65 "USB", 65 EXTCON_USB_HOST,
66 NULL, 66
67 EXTCON_NONE,
67}; 68};
68 69
69static ssize_t vbus_state_show(struct device *device, 70static ssize_t vbus_state_show(struct device *device,
diff --git a/include/linux/extcon.h b/include/linux/extcon.h
index 799474d9dc48..85c882f0029e 100644
--- a/include/linux/extcon.h
+++ b/include/linux/extcon.h
@@ -1,6 +1,9 @@
1/* 1/*
2 * External connector (extcon) class driver 2 * External connector (extcon) class driver
3 * 3 *
4 * Copyright (C) 2015 Samsung Electronics
5 * Author: Chanwoo Choi <cw00.choi@samsung.com>
6 *
4 * Copyright (C) 2012 Samsung Electronics 7 * Copyright (C) 2012 Samsung Electronics
5 * Author: Donggeun Kim <dg77.kim@samsung.com> 8 * Author: Donggeun Kim <dg77.kim@samsung.com>
6 * Author: MyungJoo Ham <myungjoo.ham@samsung.com> 9 * Author: MyungJoo Ham <myungjoo.ham@samsung.com>
@@ -27,50 +30,41 @@
27#include <linux/notifier.h> 30#include <linux/notifier.h>
28#include <linux/sysfs.h> 31#include <linux/sysfs.h>
29 32
30#define SUPPORTED_CABLE_MAX 32 33enum extcon {
31#define CABLE_NAME_MAX 30 34 EXTCON_NONE = 0x0,
32 35
33/* 36 /* USB external connector */
34 * The standard cable name is to help support general notifier 37 EXTCON_USB = 0x1,
35 * and notifiee device drivers to share the common names. 38 EXTCON_USB_HOST = 0x2,
36 * Please use standard cable names unless your notifier device has 39
37 * a very unique and abnormal cable or 40 /* Charger external connector */
38 * the cable type is supposed to be used with only one unique 41 EXTCON_TA = 0x10,
39 * pair of notifier/notifiee devices. 42 EXTCON_FAST_CHARGER = 0x11,
40 * 43 EXTCON_SLOW_CHARGER = 0x12,
41 * Please add any other "standard" cables used with extcon dev. 44 EXTCON_CHARGE_DOWNSTREAM = 0x13,
42 * 45
43 * You may add a dot and number to specify version or specification 46 /* Audio/Video external connector */
44 * of the specific cable if it is required. (e.g., "Fast-charger.18" 47 EXTCON_LINE_IN = 0x20,
45 * and "Fast-charger.10" for 1.8A and 1.0A chargers) 48 EXTCON_LINE_OUT = 0x21,
46 * However, the notifiee and notifier should be able to handle such 49 EXTCON_MICROPHONE = 0x22,
47 * string and if the notifiee can negotiate the protocol or identify, 50 EXTCON_HEADPHONE = 0x23,
48 * you don't need such convention. This convention is helpful when 51
49 * notifier can distinguish but notifiee cannot. 52 EXTCON_HDMI = 0x30,
50 */ 53 EXTCON_MHL = 0x31,
51enum extcon_cable_name { 54 EXTCON_DVI = 0x32,
52 EXTCON_USB = 0, 55 EXTCON_VGA = 0x33,
53 EXTCON_USB_HOST, 56 EXTCON_SPDIF_IN = 0x34,
54 EXTCON_TA, /* Travel Adaptor */ 57 EXTCON_SPDIF_OUT = 0x35,
55 EXTCON_FAST_CHARGER, 58 EXTCON_VIDEO_IN = 0x36,
56 EXTCON_SLOW_CHARGER, 59 EXTCON_VIDEO_OUT = 0x37,
57 EXTCON_CHARGE_DOWNSTREAM, /* Charging an external device */ 60
58 EXTCON_HDMI, 61 /* Etc external connector */
59 EXTCON_MHL, 62 EXTCON_DOCK = 0x50,
60 EXTCON_DVI, 63 EXTCON_JIG = 0x51,
61 EXTCON_VGA, 64 EXTCON_MECHANICAL = 0x52,
62 EXTCON_DOCK, 65
63 EXTCON_LINE_IN, 66 EXTCON_END,
64 EXTCON_LINE_OUT,
65 EXTCON_MIC_IN,
66 EXTCON_HEADPHONE_OUT,
67 EXTCON_SPDIF_IN,
68 EXTCON_SPDIF_OUT,
69 EXTCON_VIDEO_IN,
70 EXTCON_VIDEO_OUT,
71 EXTCON_MECHANICAL,
72}; 67};
73extern const char extcon_cable_name[][CABLE_NAME_MAX + 1];
74 68
75struct extcon_cable; 69struct extcon_cable;
76 70
@@ -78,7 +72,7 @@ struct extcon_cable;
78 * struct extcon_dev - An extcon device represents one external connector. 72 * struct extcon_dev - An extcon device represents one external connector.
79 * @name: The name of this extcon device. Parent device name is 73 * @name: The name of this extcon device. Parent device name is
80 * used if NULL. 74 * used if NULL.
81 * @supported_cable: Array of supported cable names ending with NULL. 75 * @supported_cable: Array of supported cable names ending with EXTCON_NONE.
82 * If supported_cable is NULL, cable name related APIs 76 * If supported_cable is NULL, cable name related APIs
83 * are disabled. 77 * are disabled.
84 * @mutually_exclusive: Array of mutually exclusive set of cables that cannot 78 * @mutually_exclusive: Array of mutually exclusive set of cables that cannot
@@ -113,7 +107,7 @@ struct extcon_cable;
113struct extcon_dev { 107struct extcon_dev {
114 /* Optional user initializing data */ 108 /* Optional user initializing data */
115 const char *name; 109 const char *name;
116 const char **supported_cable; 110 const enum extcon *supported_cable;
117 const u32 *mutually_exclusive; 111 const u32 *mutually_exclusive;
118 112
119 /* Optional callbacks to override class functions */ 113 /* Optional callbacks to override class functions */
@@ -194,10 +188,10 @@ extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
194/* 188/*
195 * Following APIs control the memory of extcon device. 189 * Following APIs control the memory of extcon device.
196 */ 190 */
197extern struct extcon_dev *extcon_dev_allocate(const char **cables); 191extern struct extcon_dev *extcon_dev_allocate(const enum extcon *cable);
198extern void extcon_dev_free(struct extcon_dev *edev); 192extern void extcon_dev_free(struct extcon_dev *edev);
199extern struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, 193extern struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
200 const char **cables); 194 const enum extcon *cable);
201extern void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev); 195extern void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev);
202 196
203/* 197/*
@@ -216,13 +210,10 @@ extern int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state);
216 210
217/* 211/*
218 * get/set_cable_state access each bit of the 32b encoded state value. 212 * get/set_cable_state access each bit of the 32b encoded state value.
219 * They are used to access the status of each cable based on the cable_name 213 * They are used to access the status of each cable based on the cable_name.
220 * or cable_index, which is retrieved by extcon_find_cable_index
221 */ 214 */
222extern int extcon_find_cable_index(struct extcon_dev *sdev, 215extern int extcon_get_cable_state_(struct extcon_dev *edev, enum extcon id);
223 const char *cable_name); 216extern int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id,
224extern int extcon_get_cable_state_(struct extcon_dev *edev, int cable_index);
225extern int extcon_set_cable_state_(struct extcon_dev *edev, int cable_index,
226 bool cable_state); 217 bool cable_state);
227 218
228extern int extcon_get_cable_state(struct extcon_dev *edev, 219extern int extcon_get_cable_state(struct extcon_dev *edev,
@@ -281,7 +272,7 @@ static inline int devm_extcon_dev_register(struct device *dev,
281static inline void devm_extcon_dev_unregister(struct device *dev, 272static inline void devm_extcon_dev_unregister(struct device *dev,
282 struct extcon_dev *edev) { } 273 struct extcon_dev *edev) { }
283 274
284static inline struct extcon_dev *extcon_dev_allocate(const char **cables) 275static inline struct extcon_dev *extcon_dev_allocate(const enum extcon *cable)
285{ 276{
286 return ERR_PTR(-ENOSYS); 277 return ERR_PTR(-ENOSYS);
287} 278}
@@ -289,7 +280,7 @@ static inline struct extcon_dev *extcon_dev_allocate(const char **cables)
289static inline void extcon_dev_free(struct extcon_dev *edev) { } 280static inline void extcon_dev_free(struct extcon_dev *edev) { }
290 281
291static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, 282static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
292 const char **cables) 283 const enum extcon *cable)
293{ 284{
294 return ERR_PTR(-ENOSYS); 285 return ERR_PTR(-ENOSYS);
295} 286}
@@ -312,20 +303,14 @@ static inline int extcon_update_state(struct extcon_dev *edev, u32 mask,
312 return 0; 303 return 0;
313} 304}
314 305
315static inline int extcon_find_cable_index(struct extcon_dev *edev,
316 const char *cable_name)
317{
318 return 0;
319}
320
321static inline int extcon_get_cable_state_(struct extcon_dev *edev, 306static inline int extcon_get_cable_state_(struct extcon_dev *edev,
322 int cable_index) 307 enum extcon id)
323{ 308{
324 return 0; 309 return 0;
325} 310}
326 311
327static inline int extcon_set_cable_state_(struct extcon_dev *edev, 312static inline int extcon_set_cable_state_(struct extcon_dev *edev,
328 int cable_index, bool cable_state) 313 enum extcon id, bool cable_state)
329{ 314{
330 return 0; 315 return 0;
331} 316}
diff --git a/include/linux/extcon/extcon-adc-jack.h b/include/linux/extcon/extcon-adc-jack.h
index 9ca958c4e94c..53c60806bcfb 100644
--- a/include/linux/extcon/extcon-adc-jack.h
+++ b/include/linux/extcon/extcon-adc-jack.h
@@ -44,7 +44,7 @@ struct adc_jack_cond {
44 * @consumer_channel: Unique name to identify the channel on the consumer 44 * @consumer_channel: Unique name to identify the channel on the consumer
45 * side. This typically describes the channels used within 45 * side. This typically describes the channels used within
46 * the consumer. E.g. 'battery_voltage' 46 * the consumer. E.g. 'battery_voltage'
47 * @cable_names: array of cable names ending with null. 47 * @cable_names: array of extcon id for supported cables.
48 * @adc_contitions: array of struct adc_jack_cond conditions ending 48 * @adc_contitions: array of struct adc_jack_cond conditions ending
49 * with .state = 0 entry. This describes how to decode 49 * with .state = 0 entry. This describes how to decode
50 * adc values into extcon state. 50 * adc values into extcon state.
@@ -58,8 +58,7 @@ struct adc_jack_pdata {
58 const char *name; 58 const char *name;
59 const char *consumer_channel; 59 const char *consumer_channel;
60 60
61 /* The last entry should be NULL */ 61 const enum extcon *cable_names;
62 const char **cable_names;
63 62
64 /* The last entry's state should be 0 */ 63 /* The last entry's state should be 0 */
65 struct adc_jack_cond *adc_conditions; 64 struct adc_jack_cond *adc_conditions;