This patch-set update the extcon core to resolve the ambiguous identification
method for each external connectors. So, first patch define the unique id
for each external connector to identify them by using common unique id on
various extcon device driver as following:
enum extcon {
EXTCON_NONE = 0x0, /* NONE */
/* USB external connector */
EXTCON_USB = 0x1, /* USB */
EXTCON_USB_HOST = 0x2, /* USB-HOST */
/* Charger external connector */
EXTCON_TA = 0x10, /* TA */
EXTCON_FAST_CHARGER = 0x11, /* FAST-CHARGER */
EXTCON_SLOW_CHARGER = 0x12, /* SLOW-CHARGER */
EXTCON_CHARGE_DOWNSTREAM= 0x13, /* CHARGE-DOWNSTREAM */
.....
};
And the second patch simplify the prototype of extcon notifier's register
and unregister function with the unique id. All extcon driver have to use
the unique id (enum extcon definition) when registering the notifier and
getting/setting the state of cable state.
: int extcon_{register|unregister}_notifier(struct extcon_dev *edev,
enum extcon id, struct notifier_block *nb)
In result, the extcon_{register|unregister}_interest() will be deprecated
by using the simply extcon_{register|unregister}_notifier().
Chanwoo Choi (2):
extcon: Use the unique id for external connector instead of string
extcon: Update the prototype of extcon_register_notifier() with enum extcon
drivers/extcon/extcon-arizona.c | 38 ++---
drivers/extcon/extcon-axp288.c | 24 ++-
drivers/extcon/extcon-max14577.c | 45 +++---
drivers/extcon/extcon-max77693.c | 95 ++++++------
drivers/extcon/extcon-max77843.c | 56 +++----
drivers/extcon/extcon-max8997.c | 59 +++-----
drivers/extcon/extcon-palmas.c | 22 +--
drivers/extcon/extcon-rt8973a.c | 40 ++---
drivers/extcon/extcon-sm5502.c | 32 ++--
drivers/extcon/extcon-usb-gpio.c | 32 +---
drivers/extcon/extcon.c | 257 +++++++++++++++++++--------------
include/linux/extcon.h | 109 +++++++-------
include/linux/extcon/extcon-adc-jack.h | 5 +-
13 files changed, 382 insertions(+), 432 deletions(-)
--
1.8.5.5
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, /* NONE */
/* USB external connector */
EXTCON_USB = 0x1, /* USB */
EXTCON_USB_HOST = 0x2, /* USB-HOST */
/* Charger external connector */
EXTCON_TA = 0x10, /* TA */
EXTCON_FAST_CHARGER = 0x11, /* FAST-CHARGER */
EXTCON_SLOW_CHARGER = 0x12, /* SLOW-CHARGER */
EXTCON_CHARGE_DOWNSTREAM= 0x13, /* CHARGE-DOWNSTREAM */
/* Audio and video external connector */
EXTCON_LINE_IN = 0x20, /* LINE-IN */
EXTCON_LINE_OUT = 0x21, /* LINE-OUT */
EXTCON_MICROPHONE = 0x22, /* MICROPHONE */
EXTCON_HEADPHONE = 0x23, /* HEADPHONE */
EXTCON_HDMI = 0x30, /* HDMI */
EXTCON_MHL = 0x31, /* MHL */
EXTCON_DVI = 0x32, /* DVI */
EXTCON_VGA = 0x33, /* VGA */
EXTCON_SPDIF_IN = 0x34, /* SPDIF-IN */
EXTCON_SPDIF_OUT = 0x35, /* SPDIF-OUT */
EXTCON_VIDEO_IN = 0x36, /* VIDEO-IN */
EXTCON_VIDEO_OUT = 0x37, /* VIDEO-OUT */
/* Miscellaneous external connector */
EXTCON_DOCK = 0x50, /* DOCK */
EXTCON_JIG = 0x51, /* JIG */
EXTCON_MECHANICAL = 0x52, /* MECHANICAL */
__EXTCON_END,
};
For exmaple in extcon-arizoan.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)
Signed-off-by: Chanwoo Choi <[email protected]>
Cc: MyungJoo Ham <[email protected]>
Cc: Krzysztof Kozlowski <[email protected]>
Cc: Charles Keepax <[email protected]>
Cc: Graeme Gregory <[email protected]>
Cc: Kishon Vijay Abraham I <[email protected]>
Cc: Jaewon Kim <[email protected]>
Cc: Roger Quadros <[email protected]>
Cc: Ramakrishna Pallala <[email protected]>
---
drivers/extcon/extcon-arizona.c | 38 +++-----
drivers/extcon/extcon-axp288.c | 24 ++---
drivers/extcon/extcon-max14577.c | 45 ++++-----
drivers/extcon/extcon-max77693.c | 95 +++++++++----------
drivers/extcon/extcon-max77843.c | 56 +++++------
drivers/extcon/extcon-max8997.c | 59 +++++-------
drivers/extcon/extcon-palmas.c | 22 +++--
drivers/extcon/extcon-rt8973a.c | 40 +++-----
drivers/extcon/extcon-sm5502.c | 32 ++-----
drivers/extcon/extcon-usb-gpio.c | 32 ++-----
drivers/extcon/extcon.c | 166 ++++++++++++++++++++-------------
include/linux/extcon.h | 92 +++++++++---------
include/linux/extcon/extcon-adc-jack.h | 5 +-
13 files changed, 326 insertions(+), 380 deletions(-)
diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
index 1ec06b4..9262b45 100644
--- a/drivers/extcon/extcon-arizona.c
+++ b/drivers/extcon/extcon-arizona.c
@@ -118,17 +118,12 @@ static const int arizona_micd_levels[] = {
1257,
};
-#define ARIZONA_CABLE_MECHANICAL 0
-#define ARIZONA_CABLE_MICROPHONE 1
-#define ARIZONA_CABLE_HEADPHONE 2
-#define ARIZONA_CABLE_LINEOUT 3
-
-static const char *arizona_cable[] = {
- "Mechanical",
- "Microphone",
- "Headphone",
- "Line-out",
- NULL,
+static const enum extcon arizona_cable[] = {
+ EXTCON_MECHANICAL,
+ EXTCON_MICROPHONE,
+ EXTCON_HEADPHONE,
+ EXTCON_LINE_OUT,
+ EXTCON_NONE,
};
static 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)
struct arizona_extcon_info *info = data;
struct arizona *arizona = info->arizona;
int id_gpio = arizona->pdata.hpdet_id_gpio;
- int report = ARIZONA_CABLE_HEADPHONE;
+ enum extcon report = EXTCON_HEADPHONE;
int ret, reading;
bool mic = false;
@@ -571,7 +566,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
}
/* If the cable was removed while measuring ignore the result */
- ret = extcon_get_cable_state_(info->edev, ARIZONA_CABLE_MECHANICAL);
+ ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL);
if (ret < 0) {
dev_err(arizona->dev, "Failed to check cable state: %d\n",
ret);
@@ -602,9 +597,9 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
/* Report high impedence cables as line outputs */
if (reading >= 5000)
- report = ARIZONA_CABLE_LINEOUT;
+ report = EXTCON_LINE_OUT;
else
- report = ARIZONA_CABLE_HEADPHONE;
+ report = EXTCON_HEADPHONE;
ret = extcon_set_cable_state_(info->edev, report, true);
if (ret != 0)
@@ -689,8 +684,7 @@ err:
ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
/* Just report headphone */
- ret = extcon_set_cable_state_(info->edev,
- ARIZONA_CABLE_HEADPHONE, true);
+ ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true);
if (ret != 0)
dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
@@ -747,8 +741,7 @@ err:
ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
/* Just report headphone */
- ret = extcon_set_cable_state_(info->edev,
- ARIZONA_CABLE_HEADPHONE, true);
+ ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true);
if (ret != 0)
dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
@@ -787,7 +780,7 @@ static void arizona_micd_detect(struct work_struct *work)
mutex_lock(&info->lock);
/* If the cable was removed while measuring ignore the result */
- ret = extcon_get_cable_state_(info->edev, ARIZONA_CABLE_MECHANICAL);
+ ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL);
if (ret < 0) {
dev_err(arizona->dev, "Failed to check cable state: %d\n",
ret);
@@ -836,8 +829,7 @@ static void arizona_micd_detect(struct work_struct *work)
arizona_identify_headphone(info);
ret = extcon_set_cable_state_(info->edev,
- ARIZONA_CABLE_MICROPHONE, true);
-
+ EXTCON_MICROPHONE, true);
if (ret != 0)
dev_err(arizona->dev, "Headset report failed: %d\n",
ret);
@@ -1028,7 +1020,7 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
if (info->last_jackdet == present) {
dev_dbg(arizona->dev, "Detected jack\n");
ret = extcon_set_cable_state_(info->edev,
- ARIZONA_CABLE_MECHANICAL, true);
+ EXTCON_MECHANICAL, true);
if (ret != 0)
dev_err(arizona->dev, "Mechanical report failed: %d\n",
diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
index 8299adb..3605aa96 100644
--- a/drivers/extcon/extcon-axp288.c
+++ b/drivers/extcon/extcon-axp288.c
@@ -77,10 +77,6 @@
/* IRQ enable-6 register */
#define BC12_IRQ_CFG_MASK BIT(1)
-#define AXP288_EXTCON_SLOW_CHARGER "SLOW-CHARGER"
-#define AXP288_EXTCON_DOWNSTREAM_CHARGER "CHARGE-DOWNSTREAM"
-#define AXP288_EXTCON_FAST_CHARGER "FAST-CHARGER"
-
enum axp288_extcon_reg {
AXP288_PS_STAT_REG = 0x00,
AXP288_PS_BOOT_REASON_REG = 0x02,
@@ -105,11 +101,11 @@ enum axp288_extcon_irq {
EXTCON_IRQ_END,
};
-static const char *axp288_extcon_cables[] = {
- AXP288_EXTCON_SLOW_CHARGER,
- AXP288_EXTCON_DOWNSTREAM_CHARGER,
- AXP288_EXTCON_FAST_CHARGER,
- NULL,
+static const enum extcon axp288_extcon_cables[] = {
+ EXTCON_SLOW_CHARGER,
+ EXTCON_CHARGE_DOWNSTREAM,
+ EXTCON_FAST_CHARGER,
+ EXTCON_NONE,
};
struct axp288_extcon_info {
@@ -161,7 +157,7 @@ static void axp288_extcon_log_rsi(struct axp288_extcon_info *info)
static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
{
static bool notify_otg, notify_charger;
- static char *cable;
+ static enum extcon cable;
int ret, stat, cfg, pwr_stat;
u8 chrg_type;
bool vbus_attach = false;
@@ -196,18 +192,18 @@ static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
dev_dbg(info->dev, "sdp cable is connecetd\n");
notify_otg = true;
notify_charger = true;
- cable = AXP288_EXTCON_SLOW_CHARGER;
+ cable = EXTCON_SLOW_CHARGER;
break;
case DET_STAT_CDP:
dev_dbg(info->dev, "cdp cable is connecetd\n");
notify_otg = true;
notify_charger = true;
- cable = AXP288_EXTCON_DOWNSTREAM_CHARGER;
+ cable = EXTCON_CHARGE_DOWNSTREAM;
break;
case DET_STAT_DCP:
dev_dbg(info->dev, "dcp cable is connecetd\n");
notify_charger = true;
- cable = AXP288_EXTCON_FAST_CHARGER;
+ cable = EXTCON_FAST_CHARGER;
break;
default:
dev_warn(info->dev,
@@ -230,7 +226,7 @@ notify_otg:
}
if (notify_charger)
- extcon_set_cable_state(info->edev, cable, vbus_attach);
+ extcon_set_cable_state_(info->edev, cable, vbus_attach);
/* Clear the flags on disconnect event */
if (!vbus_attach)
diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c
index ad8f8dd..e7c3edb 100644
--- a/drivers/extcon/extcon-max14577.c
+++ b/drivers/extcon/extcon-max14577.c
@@ -148,27 +148,14 @@ enum max14577_muic_acc_type {
MAX14577_MUIC_ADC_OPEN,
};
-/* max14577 MUIC device support below list of accessories(external connector) */
-enum {
- EXTCON_CABLE_USB = 0,
- EXTCON_CABLE_TA,
- EXTCON_CABLE_FAST_CHARGER,
- EXTCON_CABLE_SLOW_CHARGER,
- EXTCON_CABLE_CHARGE_DOWNSTREAM,
- EXTCON_CABLE_JIG,
-
- _EXTCON_CABLE_NUM,
-};
-
-static const char *max14577_extcon_cable[] = {
- [EXTCON_CABLE_USB] = "USB",
- [EXTCON_CABLE_TA] = "TA",
- [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger",
- [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger",
- [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream",
- [EXTCON_CABLE_JIG] = "JIG",
-
- NULL,
+static const enum extcon max14577_extcon_cable[] = {
+ EXTCON_USB,
+ EXTCON_TA,
+ EXTCON_FAST_CHARGER,
+ EXTCON_SLOW_CHARGER,
+ EXTCON_CHARGE_DOWNSTREAM,
+ EXTCON_JIG,
+ EXTCON_NONE,
};
/*
@@ -369,7 +356,7 @@ static int max14577_muic_jig_handler(struct max14577_muic_info *info,
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "JIG", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
return 0;
}
@@ -466,20 +453,22 @@ static int max14577_muic_chg_handler(struct max14577_muic_info *info)
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "USB", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
break;
case MAX14577_CHARGER_TYPE_DEDICATED_CHG:
- extcon_set_cable_state(info->edev, "TA", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
break;
case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
- extcon_set_cable_state(info->edev,
- "Charge-downstream", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM,
+ attached);
break;
case MAX14577_CHARGER_TYPE_SPECIAL_500MA:
- extcon_set_cable_state(info->edev, "Slow-charger", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_SLOW_CHARGER,
+ attached);
break;
case MAX14577_CHARGER_TYPE_SPECIAL_1A:
- extcon_set_cable_state(info->edev, "Fast-charger", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER,
+ attached);
break;
case MAX14577_CHARGER_TYPE_NONE:
case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c
index c274249..20e796e 100644
--- a/drivers/extcon/extcon-max77693.c
+++ b/drivers/extcon/extcon-max77693.c
@@ -200,32 +200,17 @@ enum max77693_muic_acc_type {
/*
* MAX77693 MUIC device support below list of accessories(external connector)
*/
-enum {
- EXTCON_CABLE_USB = 0,
- EXTCON_CABLE_USB_HOST,
- EXTCON_CABLE_TA,
- EXTCON_CABLE_FAST_CHARGER,
- EXTCON_CABLE_SLOW_CHARGER,
- EXTCON_CABLE_CHARGE_DOWNSTREAM,
- EXTCON_CABLE_MHL,
- EXTCON_CABLE_JIG,
- EXTCON_CABLE_DOCK,
-
- _EXTCON_CABLE_NUM,
-};
-
-static const char *max77693_extcon_cable[] = {
- [EXTCON_CABLE_USB] = "USB",
- [EXTCON_CABLE_USB_HOST] = "USB-Host",
- [EXTCON_CABLE_TA] = "TA",
- [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger",
- [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger",
- [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream",
- [EXTCON_CABLE_MHL] = "MHL",
- [EXTCON_CABLE_JIG] = "JIG",
- [EXTCON_CABLE_DOCK] = "DOCK",
-
- NULL,
+static const enum extcon max77693_extcon_cable[] = {
+ EXTCON_USB,
+ EXTCON_USB_HOST,
+ EXTCON_TA,
+ EXTCON_FAST_CHARGER,
+ EXTCON_SLOW_CHARGER,
+ EXTCON_CHARGE_DOWNSTREAM,
+ EXTCON_MHL,
+ EXTCON_JIG,
+ EXTCON_DOCK,
+ EXTCON_NONE,
};
/*
@@ -472,7 +457,7 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info,
int ret = 0;
int vbvolt;
bool cable_attached;
- char dock_name[CABLE_NAME_MAX];
+ enum extcon dock_id;
dev_info(info->dev,
"external connector is %s (adc:0x%02x)\n",
@@ -517,16 +502,16 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info,
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "DOCK", attached);
- extcon_set_cable_state(info->edev, "MHL", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_DOCK, attached);
+ extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
goto out;
case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk */
- strcpy(dock_name, "DOCK");
+ dock_id = EXTCON_DOCK;
break;
case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */
- strcpy(dock_name, "DOCK");
+ dock_id = EXTCON_DOCK;
if (!attached)
- extcon_set_cable_state(info->edev, "USB", false);
+ extcon_set_cable_state_(info->edev, EXTCON_USB, false);
break;
default:
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,
ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached);
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, dock_name, attached);
+ extcon_set_cable_state_(info->edev, dock_id, attached);
out:
return 0;
@@ -603,20 +588,19 @@ static int max77693_muic_adc_ground_handler(struct max77693_muic_info *info)
ret = max77693_muic_set_path(info, CONTROL1_SW_USB, attached);
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "USB-Host", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached);
break;
case MAX77693_MUIC_GND_AV_CABLE_LOAD:
/* Audio Video Cable with load, PATH:AUDIO */
ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached);
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev,
- "Audio-video-load", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
break;
case MAX77693_MUIC_GND_MHL:
case MAX77693_MUIC_GND_MHL_VB:
/* MHL or MHL with USB/TA cable */
- extcon_set_cable_state(info->edev, "MHL", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
break;
default:
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,
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "JIG", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
return 0;
}
@@ -812,10 +796,10 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
* - Support charging through micro-usb port without
* data connection
*/
- extcon_set_cable_state(info->edev, "TA", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
if (!cable_attached)
- extcon_set_cable_state(info->edev,
- "MHL", cable_attached);
+ extcon_set_cable_state_(info->edev, EXTCON_MHL,
+ cable_attached);
break;
}
@@ -838,11 +822,12 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
* - Support charging through micro-usb port without
* data connection.
*/
- extcon_set_cable_state(info->edev, "USB", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_USB,
+ attached);
if (!cable_attached)
- extcon_set_cable_state(info->edev, "DOCK",
- cable_attached);
+ extcon_set_cable_state_(info->edev, EXTCON_DOCK,
+ cable_attached);
break;
case MAX77693_MUIC_ADC_RESERVED_ACC_3: /* Dock-Smart */
/*
@@ -870,9 +855,10 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "DOCK", attached);
- extcon_set_cable_state(info->edev, "MHL", attached);
-
+ extcon_set_cable_state_(info->edev, EXTCON_DOCK,
+ attached);
+ extcon_set_cable_state_(info->edev, EXTCON_MHL,
+ attached);
break;
}
@@ -905,23 +891,26 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "USB", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_USB,
+ attached);
break;
case MAX77693_CHARGER_TYPE_DEDICATED_CHG:
/* Only TA cable */
- extcon_set_cable_state(info->edev, "TA", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
break;
}
break;
case MAX77693_CHARGER_TYPE_DOWNSTREAM_PORT:
- extcon_set_cable_state(info->edev,
- "Charge-downstream", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM,
+ attached);
break;
case MAX77693_CHARGER_TYPE_APPLE_500MA:
- extcon_set_cable_state(info->edev, "Slow-charger", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_SLOW_CHARGER,
+ attached);
break;
case MAX77693_CHARGER_TYPE_APPLE_1A_2A:
- extcon_set_cable_state(info->edev, "Fast-charger", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER,
+ attached);
break;
case MAX77693_CHARGER_TYPE_DEAD_BATTERY:
break;
diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c
index 5746d7b..d78a64d 100644
--- a/drivers/extcon/extcon-max77843.c
+++ b/drivers/extcon/extcon-max77843.c
@@ -118,28 +118,16 @@ enum max77843_muic_charger_type {
MAX77843_MUIC_CHG_GND,
};
-enum {
- MAX77843_CABLE_USB = 0,
- MAX77843_CABLE_USB_HOST,
- MAX77843_CABLE_TA,
- MAX77843_CABLE_CHARGE_DOWNSTREAM,
- MAX77843_CABLE_FAST_CHARGER,
- MAX77843_CABLE_SLOW_CHARGER,
- MAX77843_CABLE_MHL,
- MAX77843_CABLE_JIG,
-
- MAX77843_CABLE_NUM,
-};
-
-static const char *max77843_extcon_cable[] = {
- [MAX77843_CABLE_USB] = "USB",
- [MAX77843_CABLE_USB_HOST] = "USB-HOST",
- [MAX77843_CABLE_TA] = "TA",
- [MAX77843_CABLE_CHARGE_DOWNSTREAM] = "CHARGER-DOWNSTREAM",
- [MAX77843_CABLE_FAST_CHARGER] = "FAST-CHARGER",
- [MAX77843_CABLE_SLOW_CHARGER] = "SLOW-CHARGER",
- [MAX77843_CABLE_MHL] = "MHL",
- [MAX77843_CABLE_JIG] = "JIG",
+static const enum extcon max77843_extcon_cable[] = {
+ EXTCON_USB,
+ EXTCON_USB_HOST,
+ EXTCON_TA,
+ EXTCON_CHARGE_DOWNSTREAM,
+ EXTCON_FAST_CHARGER,
+ EXTCON_SLOW_CHARGER,
+ EXTCON_MHL,
+ EXTCON_JIG,
+ EXTCON_NONE,
};
struct max77843_muic_irq {
@@ -354,7 +342,7 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info)
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "USB-HOST", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached);
break;
case MAX77843_MUIC_GND_MHL_VB:
case MAX77843_MUIC_GND_MHL:
@@ -362,7 +350,7 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info)
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "MHL", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
break;
default:
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,
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "JIG", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
return 0;
}
@@ -490,36 +478,38 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "USB", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
break;
case MAX77843_MUIC_CHG_DOWNSTREAM:
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached);
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev,
- "CHARGER-DOWNSTREAM", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM,
+ attached);
break;
case MAX77843_MUIC_CHG_DEDICATED:
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached);
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "TA", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
break;
case MAX77843_MUIC_CHG_SPECIAL_500MA:
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached);
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "SLOW-CHAREGER", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_SLOW_CHARGER,
+ attached);
break;
case MAX77843_MUIC_CHG_SPECIAL_1A:
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached);
if (ret < 0)
return ret;
- extcon_set_cable_state(info->edev, "FAST-CHARGER", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER,
+ attached);
break;
case MAX77843_MUIC_CHG_GND:
gnd_type = max77843_muic_get_cable_type(info,
@@ -527,9 +517,9 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
/* Charger cable on MHL accessory is attach or detach */
if (gnd_type == MAX77843_MUIC_GND_MHL_VB)
- extcon_set_cable_state(info->edev, "TA", true);
+ extcon_set_cable_state_(info->edev, EXTCON_TA, true);
else if (gnd_type == MAX77843_MUIC_GND_MHL)
- extcon_set_cable_state(info->edev, "TA", false);
+ extcon_set_cable_state_(info->edev, EXTCON_TA, false);
break;
case MAX77843_MUIC_CHG_NONE:
break;
diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c
index 33613c4..4d10949 100644
--- a/drivers/extcon/extcon-max8997.c
+++ b/drivers/extcon/extcon-max8997.c
@@ -145,32 +145,17 @@ struct max8997_muic_info {
int path_uart;
};
-enum {
- EXTCON_CABLE_USB = 0,
- EXTCON_CABLE_USB_HOST,
- EXTCON_CABLE_TA,
- EXTCON_CABLE_FAST_CHARGER,
- EXTCON_CABLE_SLOW_CHARGER,
- EXTCON_CABLE_CHARGE_DOWNSTREAM,
- EXTCON_CABLE_MHL,
- EXTCON_CABLE_DOCK,
- EXTCON_CABLE_JIG,
-
- _EXTCON_CABLE_NUM,
-};
-
-static const char *max8997_extcon_cable[] = {
- [EXTCON_CABLE_USB] = "USB",
- [EXTCON_CABLE_USB_HOST] = "USB-Host",
- [EXTCON_CABLE_TA] = "TA",
- [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger",
- [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger",
- [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream",
- [EXTCON_CABLE_MHL] = "MHL",
- [EXTCON_CABLE_DOCK] = "DOCK",
- [EXTCON_CABLE_JIG] = "JIG",
-
- NULL,
+static const enum extcon max8997_extcon_cable[] = {
+ EXTCON_USB,
+ EXTCON_USB_HOST,
+ EXTCON_TA,
+ EXTCON_FAST_CHARGER,
+ EXTCON_SLOW_CHARGER,
+ EXTCON_CHARGE_DOWNSTREAM,
+ EXTCON_MHL,
+ EXTCON_DOCK,
+ EXTCON_JIG,
+ EXTCON_NONE,
};
/*
@@ -345,10 +330,10 @@ static int max8997_muic_handle_usb(struct max8997_muic_info *info,
switch (usb_type) {
case MAX8997_USB_HOST:
- extcon_set_cable_state(info->edev, "USB-Host", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached);
break;
case MAX8997_USB_DEVICE:
- extcon_set_cable_state(info->edev, "USB", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
break;
default:
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,
switch (cable_type) {
case MAX8997_MUIC_ADC_AV_CABLE_NOLOAD:
case MAX8997_MUIC_ADC_FACTORY_MODE_UART_ON:
- extcon_set_cable_state(info->edev, "DOCK", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_DOCK, attached);
break;
default:
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,
return ret;
}
- extcon_set_cable_state(info->edev, "JIG", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
return 0;
}
@@ -418,7 +403,7 @@ static int max8997_muic_adc_handler(struct max8997_muic_info *info)
return ret;
break;
case MAX8997_MUIC_ADC_MHL:
- extcon_set_cable_state(info->edev, "MHL", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
break;
case MAX8997_MUIC_ADC_FACTORY_MODE_USB_OFF:
case MAX8997_MUIC_ADC_FACTORY_MODE_USB_ON:
@@ -501,17 +486,19 @@ static int max8997_muic_chg_handler(struct max8997_muic_info *info)
}
break;
case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT:
- extcon_set_cable_state(info->edev,
- "Charge-downstream", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM,
+ attached);
break;
case MAX8997_CHARGER_TYPE_DEDICATED_CHG:
- extcon_set_cable_state(info->edev, "TA", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
break;
case MAX8997_CHARGER_TYPE_500MA:
- extcon_set_cable_state(info->edev, "Slow-charger", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_SLOW_CHARGER,
+ attached);
break;
case MAX8997_CHARGER_TYPE_1A:
- extcon_set_cable_state(info->edev, "Fast-charger", attached);
+ extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER,
+ attached);
break;
default:
dev_err(info->dev,
diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
index 9c8943d..d689540 100644
--- a/drivers/extcon/extcon-palmas.c
+++ b/drivers/extcon/extcon-palmas.c
@@ -29,10 +29,10 @@
#include <linux/of.h>
#include <linux/of_platform.h>
-static const char *palmas_extcon_cable[] = {
- [0] = "USB",
- [1] = "USB-HOST",
- NULL,
+static const enum extcon palmas_extcon_cable[] = {
+ EXTCON_USB,
+ EXTCON_USB_HOST,
+ EXTCON_NONE,
};
static const int mutually_exclusive[] = {0x3, 0x0};
@@ -49,6 +49,7 @@ static void palmas_usb_wakeup(struct palmas *palmas, int enable)
static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
{
struct palmas_usb *palmas_usb = _palmas_usb;
+ struct extcon_dev *edev = palmas_usb->edev;
unsigned int vbus_line_state;
palmas_read(palmas_usb->palmas, PALMAS_INTERRUPT_BASE,
@@ -57,7 +58,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
if (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) {
if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) {
palmas_usb->linkstat = PALMAS_USB_STATE_VBUS;
- extcon_set_cable_state(palmas_usb->edev, "USB", true);
+ extcon_set_cable_state_(edev, EXTCON_USB, true);
dev_info(palmas_usb->dev, "USB cable is attached\n");
} else {
dev_dbg(palmas_usb->dev,
@@ -66,7 +67,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
} else if (!(vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS)) {
if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) {
palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
- extcon_set_cable_state(palmas_usb->edev, "USB", false);
+ extcon_set_cable_state_(edev, EXTCON_USB, false);
dev_info(palmas_usb->dev, "USB cable is detached\n");
} else {
dev_dbg(palmas_usb->dev,
@@ -81,6 +82,7 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
{
unsigned int set, id_src;
struct palmas_usb *palmas_usb = _palmas_usb;
+ struct extcon_dev *edev = palmas_usb->edev;
palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
PALMAS_USB_ID_INT_LATCH_SET, &set);
@@ -93,7 +95,7 @@ static irqreturn_t palmas_id_irq_handler(int irq, void *_palmas_usb)
PALMAS_USB_ID_INT_LATCH_CLR,
PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
palmas_usb->linkstat = PALMAS_USB_STATE_ID;
- extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true);
+ extcon_set_cable_state_(edev, EXTCON_USB_HOST, true);
dev_info(palmas_usb->dev, "USB-HOST cable is attached\n");
} else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) &&
(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)
PALMAS_USB_ID_INT_LATCH_CLR,
PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
- extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false);
+ extcon_set_cable_state_(edev, EXTCON_USB_HOST, false);
dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) &&
(!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) {
palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
- extcon_set_cable_state(palmas_usb->edev, "USB-HOST", false);
+ extcon_set_cable_state_(edev, EXTCON_USB_HOST, false);
dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) &&
(id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) {
palmas_usb->linkstat = PALMAS_USB_STATE_ID;
- extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true);
+ extcon_set_cable_state_(edev, EXTCON_USB_HOST, true);
dev_info(palmas_usb->dev, " USB-HOST cable is attached\n");
}
diff --git a/drivers/extcon/extcon-rt8973a.c b/drivers/extcon/extcon-rt8973a.c
index 04447f3..f2a8672 100644
--- a/drivers/extcon/extcon-rt8973a.c
+++ b/drivers/extcon/extcon-rt8973a.c
@@ -90,21 +90,12 @@ static struct reg_data rt8973a_reg_data[] = {
};
/* List of detectable cables */
-enum {
- EXTCON_CABLE_USB = 0,
- EXTCON_CABLE_USB_HOST,
- EXTCON_CABLE_TA,
- EXTCON_CABLE_JIG,
-
- EXTCON_CABLE_END,
-};
-
-static const char *rt8973a_extcon_cable[] = {
- [EXTCON_CABLE_USB] = "USB",
- [EXTCON_CABLE_USB_HOST] = "USB-Host",
- [EXTCON_CABLE_TA] = "TA",
- [EXTCON_CABLE_JIG] = "JIG",
- NULL,
+static const enum extcon rt8973a_extcon_cable[] = {
+ EXTCON_USB,
+ EXTCON_USB_HOST,
+ EXTCON_TA,
+ EXTCON_JIG,
+ EXTCON_NONE,
};
/* Define OVP (Over Voltage Protection), OTP (Over Temperature Protection) */
@@ -307,14 +298,11 @@ static int rt8973a_muic_cable_handler(struct rt8973a_muic_info *info,
enum rt8973a_event_type event)
{
static unsigned int prev_cable_type;
- const char **cable_names = info->edev->supported_cable;
unsigned int con_sw = DM_DP_SWITCH_UART;
- int ret, idx = 0, cable_type;
+ int ret, cable_type;
+ enum extcon id;
bool attached = false;
- if (!cable_names)
- return 0;
-
switch (event) {
case RT8973A_EVENT_ATTACH:
cable_type = rt8973a_muic_get_cable_type(info);
@@ -341,25 +329,25 @@ static int rt8973a_muic_cable_handler(struct rt8973a_muic_info *info,
switch (cable_type) {
case RT8973A_MUIC_ADC_OTG:
- idx = EXTCON_CABLE_USB_HOST;
+ id = EXTCON_USB_HOST;
con_sw = DM_DP_SWITCH_USB;
break;
case RT8973A_MUIC_ADC_TA:
- idx = EXTCON_CABLE_TA;
+ id = EXTCON_TA;
con_sw = DM_DP_SWITCH_OPEN;
break;
case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB:
case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB:
- idx = EXTCON_CABLE_JIG;
+ id = EXTCON_JIG;
con_sw = DM_DP_SWITCH_USB;
break;
case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART:
case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART:
- idx = EXTCON_CABLE_JIG;
+ id = EXTCON_JIG;
con_sw = DM_DP_SWITCH_UART;
break;
case RT8973A_MUIC_ADC_USB:
- idx = EXTCON_CABLE_USB;
+ id = EXTCON_USB;
con_sw = DM_DP_SWITCH_USB;
break;
case RT8973A_MUIC_ADC_OPEN:
@@ -409,7 +397,7 @@ static int rt8973a_muic_cable_handler(struct rt8973a_muic_info *info,
return ret;
/* Change the state of external accessory */
- extcon_set_cable_state(info->edev, cable_names[idx], attached);
+ extcon_set_cable_state_(info->edev, id, attached);
return 0;
}
diff --git a/drivers/extcon/extcon-sm5502.c b/drivers/extcon/extcon-sm5502.c
index 6f1d11f..520693d 100644
--- a/drivers/extcon/extcon-sm5502.c
+++ b/drivers/extcon/extcon-sm5502.c
@@ -92,19 +92,11 @@ static struct reg_data sm5502_reg_data[] = {
};
/* List of detectable cables */
-enum {
- EXTCON_CABLE_USB = 0,
- EXTCON_CABLE_USB_HOST,
- EXTCON_CABLE_TA,
-
- EXTCON_CABLE_END,
-};
-
-static const char *sm5502_extcon_cable[] = {
- [EXTCON_CABLE_USB] = "USB",
- [EXTCON_CABLE_USB_HOST] = "USB-Host",
- [EXTCON_CABLE_TA] = "TA",
- NULL,
+static const enum extcon sm5502_extcon_cable[] = {
+ EXTCON_USB,
+ EXTCON_USB_HOST,
+ EXTCON_TA,
+ EXTCON_NONE,
};
/* Define supported accessory type */
@@ -377,16 +369,12 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info,
bool attached)
{
static unsigned int prev_cable_type = SM5502_MUIC_ADC_GROUND;
- const char **cable_names = info->edev->supported_cable;
unsigned int cable_type = SM5502_MUIC_ADC_GROUND;
unsigned int con_sw = DM_DP_SWITCH_OPEN;
unsigned int vbus_sw = VBUSIN_SWITCH_OPEN;
- unsigned int idx = 0;
+ enum extcon id;
int ret;
- if (!cable_names)
- return 0;
-
/* Get the type of attached or detached cable */
if (attached)
cable_type = sm5502_muic_get_cable_type(info);
@@ -396,17 +384,17 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info,
switch (cable_type) {
case SM5502_MUIC_ADC_OPEN_USB:
- idx = EXTCON_CABLE_USB;
+ id = EXTCON_USB;
con_sw = DM_DP_SWITCH_USB;
vbus_sw = VBUSIN_SWITCH_VBUSOUT_WITH_USB;
break;
case SM5502_MUIC_ADC_OPEN_TA:
- idx = EXTCON_CABLE_TA;
+ id = EXTCON_TA;
con_sw = DM_DP_SWITCH_OPEN;
vbus_sw = VBUSIN_SWITCH_VBUSOUT;
break;
case SM5502_MUIC_ADC_OPEN_USB_OTG:
- idx = EXTCON_CABLE_USB_HOST;
+ id = EXTCON_USB_HOST;
con_sw = DM_DP_SWITCH_USB;
vbus_sw = VBUSIN_SWITCH_OPEN;
break;
@@ -422,7 +410,7 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info,
return ret;
/* Change the state of external accessory */
- extcon_set_cable_state(info->edev, cable_names[idx], attached);
+ extcon_set_cable_state_(info->edev, id, attached);
return 0;
}
diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c
index 160ec12..4cf4f19 100644
--- a/drivers/extcon/extcon-usb-gpio.c
+++ b/drivers/extcon/extcon-usb-gpio.c
@@ -39,18 +39,10 @@ struct usb_extcon_info {
struct delayed_work wq_detcable;
};
-/* List of detectable cables */
-enum {
- EXTCON_CABLE_USB = 0,
- EXTCON_CABLE_USB_HOST,
-
- EXTCON_CABLE_END,
-};
-
-static const char *usb_extcon_cable[] = {
- [EXTCON_CABLE_USB] = "USB",
- [EXTCON_CABLE_USB_HOST] = "USB-HOST",
- NULL,
+static const enum extcon usb_extcon_cable[] = {
+ EXTCON_USB,
+ EXTCON_USB_HOST,
+ EXTCON_NONE,
};
static void usb_extcon_detect_cable(struct work_struct *work)
@@ -68,24 +60,16 @@ static void usb_extcon_detect_cable(struct work_struct *work)
* As we don't have event for USB peripheral cable attached,
* we simulate USB peripheral attach here.
*/
- extcon_set_cable_state(info->edev,
- usb_extcon_cable[EXTCON_CABLE_USB_HOST],
- false);
- extcon_set_cable_state(info->edev,
- usb_extcon_cable[EXTCON_CABLE_USB],
- true);
+ extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, false);
+ extcon_set_cable_state_(info->edev, EXTCON_USB, true);
} else {
/*
* ID = 0 means USB HOST cable attached.
* As we don't have event for USB peripheral cable detached,
* we simulate USB peripheral detach here.
*/
- extcon_set_cable_state(info->edev,
- usb_extcon_cable[EXTCON_CABLE_USB],
- false);
- extcon_set_cable_state(info->edev,
- usb_extcon_cable[EXTCON_CABLE_USB_HOST],
- true);
+ extcon_set_cable_state_(info->edev, EXTCON_USB, false);
+ extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, true);
}
}
diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index 2fb5f75..4aeb585 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -3,6 +3,9 @@
*
* External connector (extcon) class driver
*
+ * Copyright (C) 2015 Samsung Electronics
+ * Author: Chanwoo Choi <[email protected]>
+ *
* Copyright (C) 2012 Samsung Electronics
* Author: Donggeun Kim <[email protected]>
* Author: MyungJoo Ham <[email protected]>
@@ -32,36 +35,43 @@
#include <linux/slab.h>
#include <linux/sysfs.h>
-/*
- * extcon_cable_name suggests the standard cable names for commonly used
- * cable types.
- *
- * However, please do not use extcon_cable_name directly for extcon_dev
- * struct's supported_cable pointer unless your device really supports
- * every single port-type of the following cable names. Please choose cable
- * names that are actually used in your extcon device.
- */
-const char extcon_cable_name[][CABLE_NAME_MAX + 1] = {
+#define SUPPORTED_CABLE_MAX 32
+#define CABLE_NAME_MAX 30
+
+static const char *extcon_name[] = {
+ [EXTCON_NONE] = "NONE",
+
+ /* USB external connector */
[EXTCON_USB] = "USB",
- [EXTCON_USB_HOST] = "USB-Host",
+ [EXTCON_USB_HOST] = "USB-HOST",
+
+ /* Charger external connector */
[EXTCON_TA] = "TA",
- [EXTCON_FAST_CHARGER] = "Fast-charger",
- [EXTCON_SLOW_CHARGER] = "Slow-charger",
- [EXTCON_CHARGE_DOWNSTREAM] = "Charge-downstream",
+ [EXTCON_FAST_CHARGER] = "FAST-CHARGER",
+ [EXTCON_SLOW_CHARGER] = "SLOW-CHARGER",
+ [EXTCON_CHARGE_DOWNSTREAM] = "CHARGE-DOWNSTREAM",
+
+ /* Audio/Video external connector */
+ [EXTCON_LINE_IN] = "LINE-IN",
+ [EXTCON_LINE_OUT] = "LINE-OUT",
+ [EXTCON_MICROPHONE] = "MICROPHONE",
+ [EXTCON_HEADPHONE] = "HEADPHONE",
+
[EXTCON_HDMI] = "HDMI",
[EXTCON_MHL] = "MHL",
[EXTCON_DVI] = "DVI",
[EXTCON_VGA] = "VGA",
- [EXTCON_DOCK] = "Dock",
- [EXTCON_LINE_IN] = "Line-in",
- [EXTCON_LINE_OUT] = "Line-out",
- [EXTCON_MIC_IN] = "Microphone",
- [EXTCON_HEADPHONE_OUT] = "Headphone",
- [EXTCON_SPDIF_IN] = "SPDIF-in",
- [EXTCON_SPDIF_OUT] = "SPDIF-out",
- [EXTCON_VIDEO_IN] = "Video-in",
- [EXTCON_VIDEO_OUT] = "Video-out",
- [EXTCON_MECHANICAL] = "Mechanical",
+ [EXTCON_SPDIF_IN] = "SPDIF-IN",
+ [EXTCON_SPDIF_OUT] = "SPDIF-OUT",
+ [EXTCON_VIDEO_IN] = "VIDEO-IN",
+ [EXTCON_VIDEO_OUT] = "VIDEO-OUT",
+
+ /* Etc external connector */
+ [EXTCON_DOCK] = "DOCK",
+ [EXTCON_JIG] = "JIG",
+ [EXTCON_MECHANICAL] = "MECHANICAL",
+
+ NULL,
};
static struct class *extcon_class;
@@ -118,11 +128,9 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
if (edev->max_supported == 0)
return sprintf(buf, "%u\n", edev->state);
- for (i = 0; i < SUPPORTED_CABLE_MAX; i++) {
- if (!edev->supported_cable[i])
- break;
+ for (i = 0; i < edev->max_supported; i++) {
count += sprintf(buf + count, "%s=%d\n",
- edev->supported_cable[i],
+ extcon_name[edev->supported_cable[i]],
!!(edev->state & (1 << i)));
}
@@ -171,9 +179,10 @@ static ssize_t cable_name_show(struct device *dev,
{
struct extcon_cable *cable = container_of(attr, struct extcon_cable,
attr_name);
+ int i = cable->cable_index;
return sprintf(buf, "%s\n",
- cable->edev->supported_cable[cable->cable_index]);
+ extcon_name[cable->edev->supported_cable[i]]);
}
static ssize_t cable_state_show(struct device *dev,
@@ -282,39 +291,57 @@ int extcon_set_state(struct extcon_dev *edev, u32 state)
}
EXPORT_SYMBOL_GPL(extcon_set_state);
-/**
- * extcon_find_cable_index() - Get the cable index based on the cable name.
- * @edev: the extcon device that has the cable.
- * @cable_name: cable name to be searched.
- *
- * Note that accessing a cable state based on cable_index is faster than
- * cable_name because using cable_name induces a loop with strncmp().
- * Thus, when get/set_cable_state is repeatedly used, using cable_index
- * is recommended.
- */
-int extcon_find_cable_index(struct extcon_dev *edev, const char *cable_name)
+static int extcon_find_cable_index(struct extcon_dev *edev,
+ const char *cable_name)
{
+ enum extcon id = EXTCON_NONE;
int i;
- if (edev->supported_cable) {
- for (i = 0; edev->supported_cable[i]; i++) {
- if (!strncmp(edev->supported_cable[i],
- cable_name, CABLE_NAME_MAX))
- return i;
+ if (edev->max_supported == 0)
+ return -EINVAL;
+
+ /* Find the the number of extcon cable */
+ for (i = 0; i < __EXTCON_END; i++) {
+ if (!extcon_name[i])
+ continue;
+ if (!strncmp(extcon_name[i], cable_name, CABLE_NAME_MAX)) {
+ id = i;
+ break;
}
}
+ if (id == EXTCON_NONE)
+ return -EINVAL;
+
+ /* Find the the index of extcon cable in edev->supported_cable */
+ for (i = 0; i < edev->max_supported; i++) {
+ if (edev->supported_cable[i] == id)
+ return i;
+ }
+
return -EINVAL;
}
-EXPORT_SYMBOL_GPL(extcon_find_cable_index);
/**
* extcon_get_cable_state_() - Get the status of a specific cable.
* @edev: the extcon device that has the cable.
- * @index: cable index that can be retrieved by extcon_find_cable_index().
+ * @id: the unique id of each external connector in extcon enumeration.
*/
-int extcon_get_cable_state_(struct extcon_dev *edev, int index)
+int extcon_get_cable_state_(struct extcon_dev *edev, const enum extcon id)
{
+ int i, index = -EINVAL;
+
+ /* Find the the index of extcon cable in edev->supported_cable */
+ for (i = 0; edev->max_supported < i; i++) {
+ if (edev->supported_cable[i] == id) {
+ index = i;
+ break;
+ }
+ }
+
+ if (i == edev->max_supported)
+ return -EINVAL;
+
if (index < 0 || (edev->max_supported && edev->max_supported <= index))
return -EINVAL;
@@ -339,15 +366,27 @@ EXPORT_SYMBOL_GPL(extcon_get_cable_state);
/**
* extcon_set_cable_state_() - Set the status of a specific cable.
* @edev: the extcon device that has the cable.
- * @index: cable index that can be retrieved by
- * extcon_find_cable_index().
- * @cable_state: the new cable status. The default semantics is
+ * @id: the unique id of each external connector
+ * in extcon enumeration.
+ * @state: the new cable status. The default semantics is
* true: attached / false: detached.
*/
-int extcon_set_cable_state_(struct extcon_dev *edev,
- int index, bool cable_state)
+int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id,
+ bool cable_state)
{
u32 state;
+ int i, index = -EINVAL;
+
+ /* Find the the index of extcon cable in edev->supported_cable */
+ for (i = 0; i < edev->max_supported; i++) {
+ if (edev->supported_cable[i] == id) {
+ index = i;
+ break;
+ }
+ }
+
+ if (i == edev->max_supported)
+ return -EINVAL;
if (index < 0 || (edev->max_supported && edev->max_supported <= index))
return -EINVAL;
@@ -605,7 +644,7 @@ static void dummy_sysfs_dev_release(struct device *dev)
*
* Return the pointer of extcon device if success or ERR_PTR(err) if fail
*/
-struct extcon_dev *extcon_dev_allocate(const char **supported_cable)
+struct extcon_dev *extcon_dev_allocate(const enum extcon *supported_cable)
{
struct extcon_dev *edev;
@@ -659,7 +698,7 @@ static void devm_extcon_dev_release(struct device *dev, void *res)
* or ERR_PTR(err) if fail
*/
struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
- const char **supported_cable)
+ const enum extcon *supported_cable)
{
struct extcon_dev **ptr, *edev;
@@ -709,17 +748,15 @@ int extcon_dev_register(struct extcon_dev *edev)
return ret;
}
- if (edev->supported_cable) {
- /* Get size of array */
- for (index = 0; edev->supported_cable[index]; index++)
- ;
- edev->max_supported = index;
- } else {
- edev->max_supported = 0;
- }
+ if (!edev->supported_cable)
+ return -EINVAL;
+ for (; edev->supported_cable[index] != EXTCON_NONE; index++);
+
+ edev->max_supported = index;
if (index > SUPPORTED_CABLE_MAX) {
- dev_err(&edev->dev, "extcon: maximum number of supported cables exceeded.\n");
+ dev_err(&edev->dev,
+ "exceed the maximum number of supported cables\n");
return -EINVAL;
}
@@ -1070,6 +1107,7 @@ static void __exit extcon_class_exit(void)
}
module_exit(extcon_class_exit);
+MODULE_AUTHOR("Chanwoo Choi <[email protected]>");
MODULE_AUTHOR("Mike Lockwood <[email protected]>");
MODULE_AUTHOR("Donggeun Kim <[email protected]>");
MODULE_AUTHOR("MyungJoo Ham <[email protected]>");
diff --git a/include/linux/extcon.h b/include/linux/extcon.h
index 799474d9d..de158a1 100644
--- a/include/linux/extcon.h
+++ b/include/linux/extcon.h
@@ -1,6 +1,9 @@
/*
* External connector (extcon) class driver
*
+ * Copyright (C) 2015 Samsung Electronics
+ * Author: Chanwoo Choi <[email protected]>
+ *
* Copyright (C) 2012 Samsung Electronics
* Author: Donggeun Kim <[email protected]>
* Author: MyungJoo Ham <[email protected]>
@@ -27,8 +30,41 @@
#include <linux/notifier.h>
#include <linux/sysfs.h>
-#define SUPPORTED_CABLE_MAX 32
-#define CABLE_NAME_MAX 30
+enum extcon {
+ EXTCON_NONE = 0x0, /* NONE */
+
+ /* USB external connector */
+ EXTCON_USB = 0x1, /* USB */
+ EXTCON_USB_HOST = 0x2, /* USB-HOST */
+
+ /* Charger external connector */
+ EXTCON_TA = 0x10, /* TA */
+ EXTCON_FAST_CHARGER = 0x11, /* FAST-CHARGER */
+ EXTCON_SLOW_CHARGER = 0x12, /* SLOW-CHARGER */
+ EXTCON_CHARGE_DOWNSTREAM= 0x13, /* CHARGE-DOWNSTREAM */
+
+ /* Audio/Video external connector */
+ EXTCON_LINE_IN = 0x20, /* LINE-IN */
+ EXTCON_LINE_OUT = 0x21, /* LINE-OUT */
+ EXTCON_MICROPHONE = 0x22, /* MICROPHONE */
+ EXTCON_HEADPHONE = 0x23, /* HEADPHONE */
+
+ EXTCON_HDMI = 0x30, /* HDMI */
+ EXTCON_MHL = 0x31, /* MHL */
+ EXTCON_DVI = 0x32, /* DVI */
+ EXTCON_VGA = 0x33, /* VGA */
+ EXTCON_SPDIF_IN = 0x34, /* SPDIF-IN */
+ EXTCON_SPDIF_OUT = 0x35, /* SPDIF-OUT */
+ EXTCON_VIDEO_IN = 0x36, /* VIDEO-IN */
+ EXTCON_VIDEO_OUT = 0x37, /* VIDEO-OUT */
+
+ /* Etc external connector */
+ EXTCON_DOCK = 0x50, /* DOCK */
+ EXTCON_JIG = 0x51, /* JIG */
+ EXTCON_MECHANICAL = 0x52, /* MECHANICAL */
+
+ __EXTCON_END,
+};
/*
* The standard cable name is to help support general notifier
@@ -48,29 +84,6 @@
* you don't need such convention. This convention is helpful when
* notifier can distinguish but notifiee cannot.
*/
-enum extcon_cable_name {
- EXTCON_USB = 0,
- EXTCON_USB_HOST,
- EXTCON_TA, /* Travel Adaptor */
- EXTCON_FAST_CHARGER,
- EXTCON_SLOW_CHARGER,
- EXTCON_CHARGE_DOWNSTREAM, /* Charging an external device */
- EXTCON_HDMI,
- EXTCON_MHL,
- EXTCON_DVI,
- EXTCON_VGA,
- EXTCON_DOCK,
- EXTCON_LINE_IN,
- EXTCON_LINE_OUT,
- EXTCON_MIC_IN,
- EXTCON_HEADPHONE_OUT,
- EXTCON_SPDIF_IN,
- EXTCON_SPDIF_OUT,
- EXTCON_VIDEO_IN,
- EXTCON_VIDEO_OUT,
- EXTCON_MECHANICAL,
-};
-extern const char extcon_cable_name[][CABLE_NAME_MAX + 1];
struct extcon_cable;
@@ -113,7 +126,7 @@ struct extcon_cable;
struct extcon_dev {
/* Optional user initializing data */
const char *name;
- const char **supported_cable;
+ const enum extcon *supported_cable;
const u32 *mutually_exclusive;
/* Optional callbacks to override class functions */
@@ -194,10 +207,10 @@ extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
/*
* Following APIs control the memory of extcon device.
*/
-extern struct extcon_dev *extcon_dev_allocate(const char **cables);
+extern struct extcon_dev *extcon_dev_allocate(const enum extcon *cable);
extern void extcon_dev_free(struct extcon_dev *edev);
extern struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
- const char **cables);
+ const enum extcon *cable);
extern void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev);
/*
@@ -216,13 +229,10 @@ extern int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state);
/*
* get/set_cable_state access each bit of the 32b encoded state value.
- * They are used to access the status of each cable based on the cable_name
- * or cable_index, which is retrieved by extcon_find_cable_index
+ * They are used to access the status of each cable based on the cable_name.
*/
-extern int extcon_find_cable_index(struct extcon_dev *sdev,
- const char *cable_name);
-extern int extcon_get_cable_state_(struct extcon_dev *edev, int cable_index);
-extern int extcon_set_cable_state_(struct extcon_dev *edev, int cable_index,
+extern int extcon_get_cable_state_(struct extcon_dev *edev, enum extcon id);
+extern int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id,
bool cable_state);
extern int extcon_get_cable_state(struct extcon_dev *edev,
@@ -281,7 +291,7 @@ static inline int devm_extcon_dev_register(struct device *dev,
static inline void devm_extcon_dev_unregister(struct device *dev,
struct extcon_dev *edev) { }
-static inline struct extcon_dev *extcon_dev_allocate(const char **cables)
+static inline struct extcon_dev *extcon_dev_allocate(const enum extcon *cable)
{
return ERR_PTR(-ENOSYS);
}
@@ -289,7 +299,7 @@ static inline struct extcon_dev *extcon_dev_allocate(const char **cables)
static inline void extcon_dev_free(struct extcon_dev *edev) { }
static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
- const char **cables)
+ const enum extcon *cable)
{
return ERR_PTR(-ENOSYS);
}
@@ -312,20 +322,14 @@ static inline int extcon_update_state(struct extcon_dev *edev, u32 mask,
return 0;
}
-static inline int extcon_find_cable_index(struct extcon_dev *edev,
- const char *cable_name)
-{
- return 0;
-}
-
static inline int extcon_get_cable_state_(struct extcon_dev *edev,
- int cable_index)
+ enum extcon id)
{
return 0;
}
static inline int extcon_set_cable_state_(struct extcon_dev *edev,
- int cable_index, bool cable_state)
+ enum extcon id, bool cable_state)
{
return 0;
}
diff --git a/include/linux/extcon/extcon-adc-jack.h b/include/linux/extcon/extcon-adc-jack.h
index 9ca958c..53c6080 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 {
* @consumer_channel: Unique name to identify the channel on the consumer
* side. This typically describes the channels used within
* the consumer. E.g. 'battery_voltage'
- * @cable_names: array of cable names ending with null.
+ * @cable_names: array of extcon id for supported cables.
* @adc_contitions: array of struct adc_jack_cond conditions ending
* with .state = 0 entry. This describes how to decode
* adc values into extcon state.
@@ -58,8 +58,7 @@ struct adc_jack_pdata {
const char *name;
const char *consumer_channel;
- /* The last entry should be NULL */
- const char **cable_names;
+ const enum extcon *cable_names;
/* The last entry's state should be 0 */
struct adc_jack_cond *adc_conditions;
--
1.8.5.5
Previously, extcon consumer driver used the extcon_register_interest()
to register the notifier chain and then to receive the notifier event
when external connector's state is changed. When registering the notifier chain
for specific external connector with extcon_register_interest(), it used the
the string name of external connector directly. There are potential problem
because of unclear, non-standard and inconsequent cable name. Namely,
it is not appropriate method to identify each external connector.
So, this patch modify the prototype of extcon_register_notifier() by using
the 'enum extcon' which are the unique id for each external connector
instead of unclear string method.
- Previously, the extcon consumer driver used the extcon_register_interest()
with 'cable_name' to point out the specific external connector. Also. it used
the un-needed structure (struct extcon_specific_cable_nb).
: int extcon_register_interest(struct extcon_specific_cable_nb *obj,
const char *extcon_name, const char *cable_name,
struct notifier_block *nb)
- Newly, the updated extcon_register_notifier() would definitely support
the same feature to detech the changed state of external connector without
any specific structure (struct extcon_specific_cable_nb).
: int extcon_register_notifier(struct extcon_dev *edev, enum extcon id,
struct notifier_block *nb)
This patch support the both extcon_register_interest() and new extcon_register_
notifier(). But the extcon_{register|unregister}_interest() will be deprecated
because extcon core would support the notifier event for extcon consumer driver
with only updated extcon_register_notifier() and 'extcon_specific_cable_nb'
will be removed if there are no extcon consumer driver with legacy
extcon_{register|unregister}_interest().
Signed-off-by: Chanwoo Choi <[email protected]>
Cc: MyungJoo Ham <[email protected]>
Cc: George Cherian <[email protected]>
Cc: Felipe Balbi <[email protected]>
Cc: Aaro Koskinen <[email protected]>
---
drivers/extcon/extcon.c | 91 ++++++++++++++++++++++++++-----------------------
include/linux/extcon.h | 17 +++++----
2 files changed, 56 insertions(+), 52 deletions(-)
diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
index 4aeb585..14c8c95 100644
--- a/drivers/extcon/extcon.c
+++ b/drivers/extcon/extcon.c
@@ -111,6 +111,16 @@ static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state)
return 0;
}
+static bool is_extcon_changed(u32 prev, u32 new, int idx, bool *attached)
+{
+ if (((prev >> idx) & 0x1) != ((new >> idx) & 0x1)) {
+ *attached = new ? true : false;
+ return true;
+ }
+
+ return false;
+}
+
static ssize_t state_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
@@ -219,23 +229,27 @@ int extcon_update_state(struct extcon_dev *edev, u32 mask, u32 state)
char *envp[3];
int env_offset = 0;
int length;
+ int index;
unsigned long flags;
+ bool attached;
spin_lock_irqsave(&edev->lock, flags);
if (edev->state != ((edev->state & ~mask) | (state & mask))) {
- u32 old_state = edev->state;
-
if (check_mutually_exclusive(edev, (edev->state & ~mask) |
(state & mask))) {
spin_unlock_irqrestore(&edev->lock, flags);
return -EPERM;
}
+ for (index = 0; index < edev->max_supported; index++) {
+ if (is_extcon_changed(edev->state, state, index, &attached))
+ raw_notifier_call_chain(&edev->nh[index], attached, edev);
+ }
+
edev->state &= ~mask;
edev->state |= state & mask;
- raw_notifier_call_chain(&edev->nh, old_state, edev);
/* This could be in interrupt handler */
prop_buf = (char *)get_zeroed_page(GFP_ATOMIC);
if (prop_buf) {
@@ -433,29 +447,6 @@ out:
}
EXPORT_SYMBOL_GPL(extcon_get_extcon_dev);
-static int _call_per_cable(struct notifier_block *nb, unsigned long val,
- void *ptr)
-{
- struct extcon_specific_cable_nb *obj = container_of(nb,
- struct extcon_specific_cable_nb, internal_nb);
- struct extcon_dev *edev = ptr;
-
- if ((val & (1 << obj->cable_index)) !=
- (edev->state & (1 << obj->cable_index))) {
- bool cable_state = true;
-
- obj->previous_value = val;
-
- if (val & (1 << obj->cable_index))
- cable_state = false;
-
- return obj->user_nb->notifier_call(obj->user_nb,
- cable_state, ptr);
- }
-
- return NOTIFY_OK;
-}
-
/**
* extcon_register_interest() - Register a notifier for a state change of a
* specific cable, not an entier set of cables of a
@@ -501,11 +492,10 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj,
obj->user_nb = nb;
- obj->internal_nb.notifier_call = _call_per_cable;
-
spin_lock_irqsave(&obj->edev->lock, flags);
- ret = raw_notifier_chain_register(&obj->edev->nh,
- &obj->internal_nb);
+ ret = raw_notifier_chain_register(
+ &obj->edev->nh[obj->cable_index],
+ obj->user_nb);
spin_unlock_irqrestore(&obj->edev->lock, flags);
} else {
struct class_dev_iter iter;
@@ -548,7 +538,8 @@ int extcon_unregister_interest(struct extcon_specific_cable_nb *obj)
return -EINVAL;
spin_lock_irqsave(&obj->edev->lock, flags);
- ret = raw_notifier_chain_unregister(&obj->edev->nh, &obj->internal_nb);
+ ret = raw_notifier_chain_unregister(
+ &obj->edev->nh[obj->cable_index], obj->user_nb);
spin_unlock_irqrestore(&obj->edev->lock, flags);
return ret;
@@ -558,21 +549,24 @@ EXPORT_SYMBOL_GPL(extcon_unregister_interest);
/**
* extcon_register_notifier() - Register a notifiee to get notified by
* any attach status changes from the extcon.
- * @edev: the extcon device.
+ * @edev: the extcon device that has the external connecotr.
+ * @id: the unique id of each external connector in extcon enumeration.
* @nb: a notifier block to be registered.
*
* Note that the second parameter given to the callback of nb (val) is
* "old_state", not the current state. The current state can be retrieved
* by looking at the third pameter (edev pointer)'s state value.
*/
-int extcon_register_notifier(struct extcon_dev *edev,
- struct notifier_block *nb)
+int extcon_register_notifier(struct extcon_dev *edev, enum extcon id,
+ struct notifier_block *nb)
{
unsigned long flags;
- int ret;
+ int ret, idx;
+
+ idx = extcon_find_cable_index(edev, extcon_name[id]);
spin_lock_irqsave(&edev->lock, flags);
- ret = raw_notifier_chain_register(&edev->nh, nb);
+ ret = raw_notifier_chain_register(&edev->nh[idx], nb);
spin_unlock_irqrestore(&edev->lock, flags);
return ret;
@@ -581,17 +575,20 @@ EXPORT_SYMBOL_GPL(extcon_register_notifier);
/**
* extcon_unregister_notifier() - Unregister a notifiee from the extcon device.
- * @edev: the extcon device.
- * @nb: a registered notifier block to be unregistered.
+ * @edev: the extcon device that has the external connecotr.
+ * @id: the unique id of each external connector in extcon enumeration.
+ * @nb: a notifier block to be registered.
*/
-int extcon_unregister_notifier(struct extcon_dev *edev,
- struct notifier_block *nb)
+int extcon_unregister_notifier(struct extcon_dev *edev, enum extcon id,
+ struct notifier_block *nb)
{
unsigned long flags;
- int ret;
+ int ret, idx;
+
+ idx = extcon_find_cable_index(edev, extcon_name[id]);
spin_lock_irqsave(&edev->lock, flags);
- ret = raw_notifier_chain_unregister(&edev->nh, nb);
+ ret = raw_notifier_chain_unregister(&edev->nh[idx], nb);
spin_unlock_irqrestore(&edev->lock, flags);
return ret;
@@ -903,7 +900,15 @@ int extcon_dev_register(struct extcon_dev *edev)
spin_lock_init(&edev->lock);
- RAW_INIT_NOTIFIER_HEAD(&edev->nh);
+ edev->nh = devm_kzalloc(&edev->dev,
+ sizeof(*edev->nh) * edev->max_supported, GFP_KERNEL);
+ if (!edev->nh) {
+ ret = -ENOMEM;
+ goto err_dev;
+ }
+
+ for (index = 0; index < edev->max_supported; index++)
+ RAW_INIT_NOTIFIER_HEAD(&edev->nh[index]);
dev_set_drvdata(&edev->dev, edev);
edev->state = 0;
diff --git a/include/linux/extcon.h b/include/linux/extcon.h
index de158a1..918ba89 100644
--- a/include/linux/extcon.h
+++ b/include/linux/extcon.h
@@ -135,7 +135,7 @@ struct extcon_dev {
/* Internal data. Please do not set. */
struct device dev;
- struct raw_notifier_head nh;
+ struct raw_notifier_head *nh;
struct list_head entry;
int max_supported;
spinlock_t lock; /* could be called by irq handler */
@@ -174,8 +174,6 @@ struct extcon_cable {
/**
* struct extcon_specific_cable_nb - An internal data for
* extcon_register_interest().
- * @internal_nb: A notifier block bridging extcon notifier
- * and cable notifier.
* @user_nb: user provided notifier block for events from
* a specific cable.
* @cable_index: the target cable.
@@ -183,7 +181,6 @@ struct extcon_cable {
* @previous_value: the saved previous event value.
*/
struct extcon_specific_cable_nb {
- struct notifier_block internal_nb;
struct notifier_block *user_nb;
int cable_index;
struct extcon_dev *edev;
@@ -259,10 +256,10 @@ extern int extcon_unregister_interest(struct extcon_specific_cable_nb *nb);
* we do not recommend to use this for normal 'notifiee' device drivers who
* want to be notified by a specific external port of the notifier.
*/
-extern int extcon_register_notifier(struct extcon_dev *edev,
+extern int extcon_register_notifier(struct extcon_dev *edev, enum extcon id,
+ struct notifier_block *nb);
+extern int extcon_unregister_notifier(struct extcon_dev *edev, enum extcon id,
struct notifier_block *nb);
-extern int extcon_unregister_notifier(struct extcon_dev *edev,
- struct notifier_block *nb);
/*
* Following API get the extcon device from devicetree.
@@ -352,13 +349,15 @@ static inline struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name)
}
static inline int extcon_register_notifier(struct extcon_dev *edev,
- struct notifier_block *nb)
+ enum extcon id,
+ struct notifier_block *nb)
{
return 0;
}
static inline int extcon_unregister_notifier(struct extcon_dev *edev,
- struct notifier_block *nb)
+ enum extcon id,
+ struct notifier_block *nb)
{
return 0;
}
--
1.8.5.5
On 15/05/15 17:31, Chanwoo Choi wrote:
> 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, /* NONE */
>
> /* USB external connector */
> EXTCON_USB = 0x1, /* USB */
> EXTCON_USB_HOST = 0x2, /* USB-HOST */
>
> /* Charger external connector */
> EXTCON_TA = 0x10, /* TA */
> EXTCON_FAST_CHARGER = 0x11, /* FAST-CHARGER */
> EXTCON_SLOW_CHARGER = 0x12, /* SLOW-CHARGER */
> EXTCON_CHARGE_DOWNSTREAM= 0x13, /* CHARGE-DOWNSTREAM */
>
> /* Audio and video external connector */
> EXTCON_LINE_IN = 0x20, /* LINE-IN */
> EXTCON_LINE_OUT = 0x21, /* LINE-OUT */
> EXTCON_MICROPHONE = 0x22, /* MICROPHONE */
> EXTCON_HEADPHONE = 0x23, /* HEADPHONE */
>
> EXTCON_HDMI = 0x30, /* HDMI */
> EXTCON_MHL = 0x31, /* MHL */
> EXTCON_DVI = 0x32, /* DVI */
> EXTCON_VGA = 0x33, /* VGA */
> EXTCON_SPDIF_IN = 0x34, /* SPDIF-IN */
> EXTCON_SPDIF_OUT = 0x35, /* SPDIF-OUT */
> EXTCON_VIDEO_IN = 0x36, /* VIDEO-IN */
> EXTCON_VIDEO_OUT = 0x37, /* VIDEO-OUT */
>
> /* Miscellaneous external connector */
> EXTCON_DOCK = 0x50, /* DOCK */
> EXTCON_JIG = 0x51, /* JIG */
> EXTCON_MECHANICAL = 0x52, /* MECHANICAL */
>
> __EXTCON_END,
> };
>
> For exmaple in extcon-arizoan.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)
>
> Signed-off-by: Chanwoo Choi <[email protected]>
> Cc: MyungJoo Ham <[email protected]>
> Cc: Krzysztof Kozlowski <[email protected]>
> Cc: Charles Keepax <[email protected]>
> Cc: Graeme Gregory <[email protected]>
> Cc: Kishon Vijay Abraham I <[email protected]>
> Cc: Jaewon Kim <[email protected]>
> Cc: Roger Quadros <[email protected]>
> Cc: Ramakrishna Pallala <[email protected]>
for drivers/extcon/extcon-usb-gpio.c
Acked-by: Roger Quadros <[email protected]>
cheers,
-roger
> ---
> drivers/extcon/extcon-arizona.c | 38 +++-----
> drivers/extcon/extcon-axp288.c | 24 ++---
> drivers/extcon/extcon-max14577.c | 45 ++++-----
> drivers/extcon/extcon-max77693.c | 95 +++++++++----------
> drivers/extcon/extcon-max77843.c | 56 +++++------
> drivers/extcon/extcon-max8997.c | 59 +++++-------
> drivers/extcon/extcon-palmas.c | 22 +++--
> drivers/extcon/extcon-rt8973a.c | 40 +++-----
> drivers/extcon/extcon-sm5502.c | 32 ++-----
> drivers/extcon/extcon-usb-gpio.c | 32 ++-----
> drivers/extcon/extcon.c | 166 ++++++++++++++++++++-------------
> include/linux/extcon.h | 92 +++++++++---------
> include/linux/extcon/extcon-adc-jack.h | 5 +-
> 13 files changed, 326 insertions(+), 380 deletions(-)
>
On Fri, May 15, 2015 at 11:31:17PM +0900, Chanwoo Choi wrote:
> 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, /* NONE */
>
> /* USB external connector */
> EXTCON_USB = 0x1, /* USB */
> EXTCON_USB_HOST = 0x2, /* USB-HOST */
>
> /* Charger external connector */
> EXTCON_TA = 0x10, /* TA */
> EXTCON_FAST_CHARGER = 0x11, /* FAST-CHARGER */
> EXTCON_SLOW_CHARGER = 0x12, /* SLOW-CHARGER */
> EXTCON_CHARGE_DOWNSTREAM= 0x13, /* CHARGE-DOWNSTREAM */
>
> /* Audio and video external connector */
> EXTCON_LINE_IN = 0x20, /* LINE-IN */
> EXTCON_LINE_OUT = 0x21, /* LINE-OUT */
> EXTCON_MICROPHONE = 0x22, /* MICROPHONE */
> EXTCON_HEADPHONE = 0x23, /* HEADPHONE */
>
> EXTCON_HDMI = 0x30, /* HDMI */
> EXTCON_MHL = 0x31, /* MHL */
> EXTCON_DVI = 0x32, /* DVI */
> EXTCON_VGA = 0x33, /* VGA */
> EXTCON_SPDIF_IN = 0x34, /* SPDIF-IN */
> EXTCON_SPDIF_OUT = 0x35, /* SPDIF-OUT */
> EXTCON_VIDEO_IN = 0x36, /* VIDEO-IN */
> EXTCON_VIDEO_OUT = 0x37, /* VIDEO-OUT */
>
> /* Miscellaneous external connector */
> EXTCON_DOCK = 0x50, /* DOCK */
> EXTCON_JIG = 0x51, /* JIG */
> EXTCON_MECHANICAL = 0x52, /* MECHANICAL */
>
> __EXTCON_END,
> };
>
> For exmaple in extcon-arizoan.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)
>
> Signed-off-by: Chanwoo Choi <[email protected]>
> Cc: MyungJoo Ham <[email protected]>
> Cc: Krzysztof Kozlowski <[email protected]>
> Cc: Charles Keepax <[email protected]>
> Cc: Graeme Gregory <[email protected]>
> Cc: Kishon Vijay Abraham I <[email protected]>
> Cc: Jaewon Kim <[email protected]>
> Cc: Roger Quadros <[email protected]>
> Cc: Ramakrishna Pallala <[email protected]>
> ---
Acked-by: Charles Keepax <[email protected]>
Thanks,
Charles
> 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, /* NONE */
>
> /* USB external connector */
> EXTCON_USB = 0x1, /* USB */
> EXTCON_USB_HOST = 0x2, /* USB-HOST */
>
> /* Charger external connector */
> EXTCON_TA = 0x10, /* TA */
> EXTCON_FAST_CHARGER = 0x11, /* FAST-CHARGER */
> EXTCON_SLOW_CHARGER = 0x12, /* SLOW-CHARGER */
> EXTCON_CHARGE_DOWNSTREAM= 0x13, /* CHARGE-
> DOWNSTREAM */
>
> /* Audio and video external connector */
> EXTCON_LINE_IN = 0x20, /* LINE-IN */
> EXTCON_LINE_OUT = 0x21, /* LINE-OUT */
> EXTCON_MICROPHONE = 0x22, /* MICROPHONE */
> EXTCON_HEADPHONE = 0x23, /* HEADPHONE */
>
> EXTCON_HDMI = 0x30, /* HDMI */
> EXTCON_MHL = 0x31, /* MHL */
> EXTCON_DVI = 0x32, /* DVI */
> EXTCON_VGA = 0x33, /* VGA */
> EXTCON_SPDIF_IN = 0x34, /* SPDIF-IN */
> EXTCON_SPDIF_OUT = 0x35, /* SPDIF-OUT */
> EXTCON_VIDEO_IN = 0x36, /* VIDEO-IN */
> EXTCON_VIDEO_OUT = 0x37, /* VIDEO-OUT */
>
> /* Miscellaneous external connector */
> EXTCON_DOCK = 0x50, /* DOCK */
> EXTCON_JIG = 0x51, /* JIG */
> EXTCON_MECHANICAL = 0x52, /* MECHANICAL */
>
> __EXTCON_END,
> };
>
> For exmaple in extcon-arizoan.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)
>
> Signed-off-by: Chanwoo Choi <[email protected]>
> Cc: MyungJoo Ham <[email protected]>
> Cc: Krzysztof Kozlowski <[email protected]>
> Cc: Charles Keepax <[email protected]>
> Cc: Graeme Gregory <[email protected]>
> Cc: Kishon Vijay Abraham I <[email protected]>
> Cc: Jaewon Kim <[email protected]>
> Cc: Roger Quadros <[email protected]>
> Cc: Ramakrishna Pallala <[email protected]>
For drivers/extcon/extcon-axp288.c
Acked-by: Ramakrishna Pallala <[email protected]>
Thanks,
Ram
> ---
> drivers/extcon/extcon-arizona.c | 38 +++-----
> drivers/extcon/extcon-axp288.c | 24 ++---
> drivers/extcon/extcon-max14577.c | 45 ++++-----
> drivers/extcon/extcon-max77693.c | 95 +++++++++----------
> drivers/extcon/extcon-max77843.c | 56 +++++------
> drivers/extcon/extcon-max8997.c | 59 +++++-------
> drivers/extcon/extcon-palmas.c | 22 +++--
> drivers/extcon/extcon-rt8973a.c | 40 +++-----
> drivers/extcon/extcon-sm5502.c | 32 ++-----
> drivers/extcon/extcon-usb-gpio.c | 32 ++-----
> drivers/extcon/extcon.c | 166 ++++++++++++++++++++-------------
> include/linux/extcon.h | 92 +++++++++---------
> include/linux/extcon/extcon-adc-jack.h | 5 +-
> 13 files changed, 326 insertions(+), 380 deletions(-)
>
> diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c
> index 1ec06b4..9262b45 100644
> --- a/drivers/extcon/extcon-arizona.c
> +++ b/drivers/extcon/extcon-arizona.c
> @@ -118,17 +118,12 @@ static const int arizona_micd_levels[] = {
> 1257,
> };
>
> -#define ARIZONA_CABLE_MECHANICAL 0
> -#define ARIZONA_CABLE_MICROPHONE 1
> -#define ARIZONA_CABLE_HEADPHONE 2
> -#define ARIZONA_CABLE_LINEOUT 3
> -
> -static const char *arizona_cable[] = {
> - "Mechanical",
> - "Microphone",
> - "Headphone",
> - "Line-out",
> - NULL,
> +static const enum extcon arizona_cable[] = {
> + EXTCON_MECHANICAL,
> + EXTCON_MICROPHONE,
> + EXTCON_HEADPHONE,
> + EXTCON_LINE_OUT,
> + EXTCON_NONE,
> };
>
> static 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)
> struct arizona_extcon_info *info = data;
> struct arizona *arizona = info->arizona;
> int id_gpio = arizona->pdata.hpdet_id_gpio;
> - int report = ARIZONA_CABLE_HEADPHONE;
> + enum extcon report = EXTCON_HEADPHONE;
> int ret, reading;
> bool mic = false;
>
> @@ -571,7 +566,7 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
> }
>
> /* If the cable was removed while measuring ignore the result */
> - ret = extcon_get_cable_state_(info->edev,
> ARIZONA_CABLE_MECHANICAL);
> + ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL);
> if (ret < 0) {
> dev_err(arizona->dev, "Failed to check cable state: %d\n",
> ret);
> @@ -602,9 +597,9 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
>
> /* Report high impedence cables as line outputs */
> if (reading >= 5000)
> - report = ARIZONA_CABLE_LINEOUT;
> + report = EXTCON_LINE_OUT;
> else
> - report = ARIZONA_CABLE_HEADPHONE;
> + report = EXTCON_HEADPHONE;
>
> ret = extcon_set_cable_state_(info->edev, report, true);
> if (ret != 0)
> @@ -689,8 +684,7 @@ err:
> ARIZONA_ACCDET_MODE_MASK,
> ARIZONA_ACCDET_MODE_MIC);
>
> /* Just report headphone */
> - ret = extcon_set_cable_state_(info->edev,
> - ARIZONA_CABLE_HEADPHONE, true);
> + ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true);
> if (ret != 0)
> dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
>
> @@ -747,8 +741,7 @@ err:
> ARIZONA_ACCDET_MODE_MASK,
> ARIZONA_ACCDET_MODE_MIC);
>
> /* Just report headphone */
> - ret = extcon_set_cable_state_(info->edev,
> - ARIZONA_CABLE_HEADPHONE, true);
> + ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true);
> if (ret != 0)
> dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
>
> @@ -787,7 +780,7 @@ static void arizona_micd_detect(struct work_struct
> *work)
> mutex_lock(&info->lock);
>
> /* If the cable was removed while measuring ignore the result */
> - ret = extcon_get_cable_state_(info->edev,
> ARIZONA_CABLE_MECHANICAL);
> + ret = extcon_get_cable_state_(info->edev, EXTCON_MECHANICAL);
> if (ret < 0) {
> dev_err(arizona->dev, "Failed to check cable state: %d\n",
> ret);
> @@ -836,8 +829,7 @@ static void arizona_micd_detect(struct work_struct
> *work)
> arizona_identify_headphone(info);
>
> ret = extcon_set_cable_state_(info->edev,
> - ARIZONA_CABLE_MICROPHONE,
> true);
> -
> + EXTCON_MICROPHONE, true);
> if (ret != 0)
> dev_err(arizona->dev, "Headset report failed: %d\n",
> ret);
> @@ -1028,7 +1020,7 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
> if (info->last_jackdet == present) {
> dev_dbg(arizona->dev, "Detected jack\n");
> ret = extcon_set_cable_state_(info->edev,
> - ARIZONA_CABLE_MECHANICAL,
> true);
> + EXTCON_MECHANICAL, true);
>
> if (ret != 0)
> dev_err(arizona->dev, "Mechanical report failed:
> %d\n",
> diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c
> index 8299adb..3605aa96 100644
> --- a/drivers/extcon/extcon-axp288.c
> +++ b/drivers/extcon/extcon-axp288.c
> @@ -77,10 +77,6 @@
> /* IRQ enable-6 register */
> #define BC12_IRQ_CFG_MASK BIT(1)
>
> -#define AXP288_EXTCON_SLOW_CHARGER "SLOW-CHARGER"
> -#define AXP288_EXTCON_DOWNSTREAM_CHARGER "CHARGE-
> DOWNSTREAM"
> -#define AXP288_EXTCON_FAST_CHARGER "FAST-CHARGER"
> -
> enum axp288_extcon_reg {
> AXP288_PS_STAT_REG = 0x00,
> AXP288_PS_BOOT_REASON_REG = 0x02,
> @@ -105,11 +101,11 @@ enum axp288_extcon_irq {
> EXTCON_IRQ_END,
> };
>
> -static const char *axp288_extcon_cables[] = {
> - AXP288_EXTCON_SLOW_CHARGER,
> - AXP288_EXTCON_DOWNSTREAM_CHARGER,
> - AXP288_EXTCON_FAST_CHARGER,
> - NULL,
> +static const enum extcon axp288_extcon_cables[] = {
> + EXTCON_SLOW_CHARGER,
> + EXTCON_CHARGE_DOWNSTREAM,
> + EXTCON_FAST_CHARGER,
> + EXTCON_NONE,
> };
>
> struct axp288_extcon_info {
> @@ -161,7 +157,7 @@ static void axp288_extcon_log_rsi(struct
> axp288_extcon_info *info)
> static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
> {
> static bool notify_otg, notify_charger;
> - static char *cable;
> + static enum extcon cable;
> int ret, stat, cfg, pwr_stat;
> u8 chrg_type;
> bool vbus_attach = false;
> @@ -196,18 +192,18 @@ static int axp288_handle_chrg_det_event(struct
> axp288_extcon_info *info)
> dev_dbg(info->dev, "sdp cable is connecetd\n");
> notify_otg = true;
> notify_charger = true;
> - cable = AXP288_EXTCON_SLOW_CHARGER;
> + cable = EXTCON_SLOW_CHARGER;
> break;
> case DET_STAT_CDP:
> dev_dbg(info->dev, "cdp cable is connecetd\n");
> notify_otg = true;
> notify_charger = true;
> - cable = AXP288_EXTCON_DOWNSTREAM_CHARGER;
> + cable = EXTCON_CHARGE_DOWNSTREAM;
> break;
> case DET_STAT_DCP:
> dev_dbg(info->dev, "dcp cable is connecetd\n");
> notify_charger = true;
> - cable = AXP288_EXTCON_FAST_CHARGER;
> + cable = EXTCON_FAST_CHARGER;
> break;
> default:
> dev_warn(info->dev,
> @@ -230,7 +226,7 @@ notify_otg:
> }
>
> if (notify_charger)
> - extcon_set_cable_state(info->edev, cable, vbus_attach);
> + extcon_set_cable_state_(info->edev, cable, vbus_attach);
>
> /* Clear the flags on disconnect event */
> if (!vbus_attach)
> diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-
> max14577.c
> index ad8f8dd..e7c3edb 100644
> --- a/drivers/extcon/extcon-max14577.c
> +++ b/drivers/extcon/extcon-max14577.c
> @@ -148,27 +148,14 @@ enum max14577_muic_acc_type {
> MAX14577_MUIC_ADC_OPEN,
> };
>
> -/* max14577 MUIC device support below list of accessories(external
> connector) */
> -enum {
> - EXTCON_CABLE_USB = 0,
> - EXTCON_CABLE_TA,
> - EXTCON_CABLE_FAST_CHARGER,
> - EXTCON_CABLE_SLOW_CHARGER,
> - EXTCON_CABLE_CHARGE_DOWNSTREAM,
> - EXTCON_CABLE_JIG,
> -
> - _EXTCON_CABLE_NUM,
> -};
> -
> -static const char *max14577_extcon_cable[] = {
> - [EXTCON_CABLE_USB] = "USB",
> - [EXTCON_CABLE_TA] = "TA",
> - [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger",
> - [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger",
> - [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-
> downstream",
> - [EXTCON_CABLE_JIG] = "JIG",
> -
> - NULL,
> +static const enum extcon max14577_extcon_cable[] = {
> + EXTCON_USB,
> + EXTCON_TA,
> + EXTCON_FAST_CHARGER,
> + EXTCON_SLOW_CHARGER,
> + EXTCON_CHARGE_DOWNSTREAM,
> + EXTCON_JIG,
> + EXTCON_NONE,
> };
>
> /*
> @@ -369,7 +356,7 @@ static int max14577_muic_jig_handler(struct
> max14577_muic_info *info,
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev, "JIG", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
>
> return 0;
> }
> @@ -466,20 +453,22 @@ static int max14577_muic_chg_handler(struct
> max14577_muic_info *info)
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev, "USB", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
> break;
> case MAX14577_CHARGER_TYPE_DEDICATED_CHG:
> - extcon_set_cable_state(info->edev, "TA", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
> break;
> case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
> - extcon_set_cable_state(info->edev,
> - "Charge-downstream", attached);
> + extcon_set_cable_state_(info->edev,
> EXTCON_CHARGE_DOWNSTREAM,
> + attached);
> break;
> case MAX14577_CHARGER_TYPE_SPECIAL_500MA:
> - extcon_set_cable_state(info->edev, "Slow-charger", attached);
> + extcon_set_cable_state_(info->edev,
> EXTCON_SLOW_CHARGER,
> + attached);
> break;
> case MAX14577_CHARGER_TYPE_SPECIAL_1A:
> - extcon_set_cable_state(info->edev, "Fast-charger", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER,
> + attached);
> break;
> case MAX14577_CHARGER_TYPE_NONE:
> case MAX14577_CHARGER_TYPE_DEAD_BATTERY:
> diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-
> max77693.c
> index c274249..20e796e 100644
> --- a/drivers/extcon/extcon-max77693.c
> +++ b/drivers/extcon/extcon-max77693.c
> @@ -200,32 +200,17 @@ enum max77693_muic_acc_type {
> /*
> * MAX77693 MUIC device support below list of accessories(external connector)
> */
> -enum {
> - EXTCON_CABLE_USB = 0,
> - EXTCON_CABLE_USB_HOST,
> - EXTCON_CABLE_TA,
> - EXTCON_CABLE_FAST_CHARGER,
> - EXTCON_CABLE_SLOW_CHARGER,
> - EXTCON_CABLE_CHARGE_DOWNSTREAM,
> - EXTCON_CABLE_MHL,
> - EXTCON_CABLE_JIG,
> - EXTCON_CABLE_DOCK,
> -
> - _EXTCON_CABLE_NUM,
> -};
> -
> -static const char *max77693_extcon_cable[] = {
> - [EXTCON_CABLE_USB] = "USB",
> - [EXTCON_CABLE_USB_HOST] = "USB-Host",
> - [EXTCON_CABLE_TA] = "TA",
> - [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger",
> - [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger",
> - [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-
> downstream",
> - [EXTCON_CABLE_MHL] = "MHL",
> - [EXTCON_CABLE_JIG] = "JIG",
> - [EXTCON_CABLE_DOCK] = "DOCK",
> -
> - NULL,
> +static const enum extcon max77693_extcon_cable[] = {
> + EXTCON_USB,
> + EXTCON_USB_HOST,
> + EXTCON_TA,
> + EXTCON_FAST_CHARGER,
> + EXTCON_SLOW_CHARGER,
> + EXTCON_CHARGE_DOWNSTREAM,
> + EXTCON_MHL,
> + EXTCON_JIG,
> + EXTCON_DOCK,
> + EXTCON_NONE,
> };
>
> /*
> @@ -472,7 +457,7 @@ static int max77693_muic_dock_handler(struct
> max77693_muic_info *info,
> int ret = 0;
> int vbvolt;
> bool cable_attached;
> - char dock_name[CABLE_NAME_MAX];
> + enum extcon dock_id;
>
> dev_info(info->dev,
> "external connector is %s (adc:0x%02x)\n",
> @@ -517,16 +502,16 @@ static int max77693_muic_dock_handler(struct
> max77693_muic_info *info,
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev, "DOCK", attached);
> - extcon_set_cable_state(info->edev, "MHL", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_DOCK,
> attached);
> + extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
> goto out;
> case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk
> */
> - strcpy(dock_name, "DOCK");
> + dock_id = EXTCON_DOCK;
> break;
> case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /*
> Dock-Audio */
> - strcpy(dock_name, "DOCK");
> + dock_id = EXTCON_DOCK;
> if (!attached)
> - extcon_set_cable_state(info->edev, "USB", false);
> + extcon_set_cable_state_(info->edev, EXTCON_USB,
> false);
> break;
> default:
> 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,
> ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO,
> attached);
> if (ret < 0)
> return ret;
> - extcon_set_cable_state(info->edev, dock_name, attached);
> + extcon_set_cable_state_(info->edev, dock_id, attached);
>
> out:
> return 0;
> @@ -603,20 +588,19 @@ static int
> max77693_muic_adc_ground_handler(struct max77693_muic_info *info)
> ret = max77693_muic_set_path(info, CONTROL1_SW_USB,
> attached);
> if (ret < 0)
> return ret;
> - extcon_set_cable_state(info->edev, "USB-Host", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_USB_HOST,
> attached);
> break;
> case MAX77693_MUIC_GND_AV_CABLE_LOAD:
> /* Audio Video Cable with load, PATH:AUDIO */
> ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO,
> attached);
> if (ret < 0)
> return ret;
> - extcon_set_cable_state(info->edev,
> - "Audio-video-load", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
> break;
> case MAX77693_MUIC_GND_MHL:
> case MAX77693_MUIC_GND_MHL_VB:
> /* MHL or MHL with USB/TA cable */
> - extcon_set_cable_state(info->edev, "MHL", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
> break;
> default:
> 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,
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev, "JIG", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
>
> return 0;
> }
> @@ -812,10 +796,10 @@ static int max77693_muic_chg_handler(struct
> max77693_muic_info *info)
> * - Support charging through micro-usb port without
> * data connection
> */
> - extcon_set_cable_state(info->edev, "TA", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_TA,
> attached);
> if (!cable_attached)
> - extcon_set_cable_state(info->edev,
> - "MHL", cable_attached);
> + extcon_set_cable_state_(info->edev,
> EXTCON_MHL,
> + cable_attached);
> break;
> }
>
> @@ -838,11 +822,12 @@ static int max77693_muic_chg_handler(struct
> max77693_muic_info *info)
> * - Support charging through micro-usb port without
> * data connection.
> */
> - extcon_set_cable_state(info->edev, "USB", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_USB,
> + attached);
>
> if (!cable_attached)
> - extcon_set_cable_state(info->edev, "DOCK",
> - cable_attached);
> + extcon_set_cable_state_(info->edev,
> EXTCON_DOCK,
> + cable_attached);
> break;
> case MAX77693_MUIC_ADC_RESERVED_ACC_3: /*
> Dock-Smart */
> /*
> @@ -870,9 +855,10 @@ static int max77693_muic_chg_handler(struct
> max77693_muic_info *info)
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev, "DOCK", attached);
> - extcon_set_cable_state(info->edev, "MHL", attached);
> -
> + extcon_set_cable_state_(info->edev, EXTCON_DOCK,
> + attached);
> + extcon_set_cable_state_(info->edev, EXTCON_MHL,
> + attached);
> break;
> }
>
> @@ -905,23 +891,26 @@ static int max77693_muic_chg_handler(struct
> max77693_muic_info *info)
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev, "USB", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_USB,
> + attached);
> break;
> case MAX77693_CHARGER_TYPE_DEDICATED_CHG:
> /* Only TA cable */
> - extcon_set_cable_state(info->edev, "TA", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_TA,
> attached);
> break;
> }
> break;
> case MAX77693_CHARGER_TYPE_DOWNSTREAM_PORT:
> - extcon_set_cable_state(info->edev,
> - "Charge-downstream", attached);
> + extcon_set_cable_state_(info->edev,
> EXTCON_CHARGE_DOWNSTREAM,
> + attached);
> break;
> case MAX77693_CHARGER_TYPE_APPLE_500MA:
> - extcon_set_cable_state(info->edev, "Slow-charger", attached);
> + extcon_set_cable_state_(info->edev,
> EXTCON_SLOW_CHARGER,
> + attached);
> break;
> case MAX77693_CHARGER_TYPE_APPLE_1A_2A:
> - extcon_set_cable_state(info->edev, "Fast-charger", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER,
> + attached);
> break;
> case MAX77693_CHARGER_TYPE_DEAD_BATTERY:
> break;
> diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-
> max77843.c
> index 5746d7b..d78a64d 100644
> --- a/drivers/extcon/extcon-max77843.c
> +++ b/drivers/extcon/extcon-max77843.c
> @@ -118,28 +118,16 @@ enum max77843_muic_charger_type {
> MAX77843_MUIC_CHG_GND,
> };
>
> -enum {
> - MAX77843_CABLE_USB = 0,
> - MAX77843_CABLE_USB_HOST,
> - MAX77843_CABLE_TA,
> - MAX77843_CABLE_CHARGE_DOWNSTREAM,
> - MAX77843_CABLE_FAST_CHARGER,
> - MAX77843_CABLE_SLOW_CHARGER,
> - MAX77843_CABLE_MHL,
> - MAX77843_CABLE_JIG,
> -
> - MAX77843_CABLE_NUM,
> -};
> -
> -static const char *max77843_extcon_cable[] = {
> - [MAX77843_CABLE_USB] = "USB",
> - [MAX77843_CABLE_USB_HOST] = "USB-HOST",
> - [MAX77843_CABLE_TA] = "TA",
> - [MAX77843_CABLE_CHARGE_DOWNSTREAM] = "CHARGER-
> DOWNSTREAM",
> - [MAX77843_CABLE_FAST_CHARGER] = "FAST-CHARGER",
> - [MAX77843_CABLE_SLOW_CHARGER] = "SLOW-CHARGER",
> - [MAX77843_CABLE_MHL] = "MHL",
> - [MAX77843_CABLE_JIG] = "JIG",
> +static const enum extcon max77843_extcon_cable[] = {
> + EXTCON_USB,
> + EXTCON_USB_HOST,
> + EXTCON_TA,
> + EXTCON_CHARGE_DOWNSTREAM,
> + EXTCON_FAST_CHARGER,
> + EXTCON_SLOW_CHARGER,
> + EXTCON_MHL,
> + EXTCON_JIG,
> + EXTCON_NONE,
> };
>
> struct max77843_muic_irq {
> @@ -354,7 +342,7 @@ static int max77843_muic_adc_gnd_handler(struct
> max77843_muic_info *info)
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev, "USB-HOST", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_USB_HOST,
> attached);
> break;
> case MAX77843_MUIC_GND_MHL_VB:
> case MAX77843_MUIC_GND_MHL:
> @@ -362,7 +350,7 @@ static int max77843_muic_adc_gnd_handler(struct
> max77843_muic_info *info)
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev, "MHL", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
> break;
> default:
> 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,
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev, "JIG", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
>
> return 0;
> }
> @@ -490,36 +478,38 @@ static int max77843_muic_chg_handler(struct
> max77843_muic_info *info)
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev, "USB", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
> break;
> case MAX77843_MUIC_CHG_DOWNSTREAM:
> ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN,
> attached);
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev,
> - "CHARGER-DOWNSTREAM", attached);
> + extcon_set_cable_state_(info->edev,
> EXTCON_CHARGE_DOWNSTREAM,
> + attached);
> break;
> case MAX77843_MUIC_CHG_DEDICATED:
> ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN,
> attached);
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev, "TA", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
> break;
> case MAX77843_MUIC_CHG_SPECIAL_500MA:
> ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN,
> attached);
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev, "SLOW-CHAREGER",
> attached);
> + extcon_set_cable_state_(info->edev,
> EXTCON_SLOW_CHARGER,
> + attached);
> break;
> case MAX77843_MUIC_CHG_SPECIAL_1A:
> ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN,
> attached);
> if (ret < 0)
> return ret;
>
> - extcon_set_cable_state(info->edev, "FAST-CHARGER",
> attached);
> + extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER,
> + attached);
> break;
> case MAX77843_MUIC_CHG_GND:
> gnd_type = max77843_muic_get_cable_type(info,
> @@ -527,9 +517,9 @@ static int max77843_muic_chg_handler(struct
> max77843_muic_info *info)
>
> /* Charger cable on MHL accessory is attach or detach */
> if (gnd_type == MAX77843_MUIC_GND_MHL_VB)
> - extcon_set_cable_state(info->edev, "TA", true);
> + extcon_set_cable_state_(info->edev, EXTCON_TA,
> true);
> else if (gnd_type == MAX77843_MUIC_GND_MHL)
> - extcon_set_cable_state(info->edev, "TA", false);
> + extcon_set_cable_state_(info->edev, EXTCON_TA,
> false);
> break;
> case MAX77843_MUIC_CHG_NONE:
> break;
> diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-
> max8997.c
> index 33613c4..4d10949 100644
> --- a/drivers/extcon/extcon-max8997.c
> +++ b/drivers/extcon/extcon-max8997.c
> @@ -145,32 +145,17 @@ struct max8997_muic_info {
> int path_uart;
> };
>
> -enum {
> - EXTCON_CABLE_USB = 0,
> - EXTCON_CABLE_USB_HOST,
> - EXTCON_CABLE_TA,
> - EXTCON_CABLE_FAST_CHARGER,
> - EXTCON_CABLE_SLOW_CHARGER,
> - EXTCON_CABLE_CHARGE_DOWNSTREAM,
> - EXTCON_CABLE_MHL,
> - EXTCON_CABLE_DOCK,
> - EXTCON_CABLE_JIG,
> -
> - _EXTCON_CABLE_NUM,
> -};
> -
> -static const char *max8997_extcon_cable[] = {
> - [EXTCON_CABLE_USB] = "USB",
> - [EXTCON_CABLE_USB_HOST] = "USB-Host",
> - [EXTCON_CABLE_TA] = "TA",
> - [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger",
> - [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger",
> - [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-
> downstream",
> - [EXTCON_CABLE_MHL] = "MHL",
> - [EXTCON_CABLE_DOCK] = "DOCK",
> - [EXTCON_CABLE_JIG] = "JIG",
> -
> - NULL,
> +static const enum extcon max8997_extcon_cable[] = {
> + EXTCON_USB,
> + EXTCON_USB_HOST,
> + EXTCON_TA,
> + EXTCON_FAST_CHARGER,
> + EXTCON_SLOW_CHARGER,
> + EXTCON_CHARGE_DOWNSTREAM,
> + EXTCON_MHL,
> + EXTCON_DOCK,
> + EXTCON_JIG,
> + EXTCON_NONE,
> };
>
> /*
> @@ -345,10 +330,10 @@ static int max8997_muic_handle_usb(struct
> max8997_muic_info *info,
>
> switch (usb_type) {
> case MAX8997_USB_HOST:
> - extcon_set_cable_state(info->edev, "USB-Host", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_USB_HOST,
> attached);
> break;
> case MAX8997_USB_DEVICE:
> - extcon_set_cable_state(info->edev, "USB", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
> break;
> default:
> 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,
> switch (cable_type) {
> case MAX8997_MUIC_ADC_AV_CABLE_NOLOAD:
> case MAX8997_MUIC_ADC_FACTORY_MODE_UART_ON:
> - extcon_set_cable_state(info->edev, "DOCK", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_DOCK,
> attached);
> break;
> default:
> 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,
> return ret;
> }
>
> - extcon_set_cable_state(info->edev, "JIG", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
>
> return 0;
> }
> @@ -418,7 +403,7 @@ static int max8997_muic_adc_handler(struct
> max8997_muic_info *info)
> return ret;
> break;
> case MAX8997_MUIC_ADC_MHL:
> - extcon_set_cable_state(info->edev, "MHL", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
> break;
> case MAX8997_MUIC_ADC_FACTORY_MODE_USB_OFF:
> case MAX8997_MUIC_ADC_FACTORY_MODE_USB_ON:
> @@ -501,17 +486,19 @@ static int max8997_muic_chg_handler(struct
> max8997_muic_info *info)
> }
> break;
> case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT:
> - extcon_set_cable_state(info->edev,
> - "Charge-downstream", attached);
> + extcon_set_cable_state_(info->edev,
> EXTCON_CHARGE_DOWNSTREAM,
> + attached);
> break;
> case MAX8997_CHARGER_TYPE_DEDICATED_CHG:
> - extcon_set_cable_state(info->edev, "TA", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
> break;
> case MAX8997_CHARGER_TYPE_500MA:
> - extcon_set_cable_state(info->edev, "Slow-charger", attached);
> + extcon_set_cable_state_(info->edev,
> EXTCON_SLOW_CHARGER,
> + attached);
> break;
> case MAX8997_CHARGER_TYPE_1A:
> - extcon_set_cable_state(info->edev, "Fast-charger", attached);
> + extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER,
> + attached);
> break;
> default:
> dev_err(info->dev,
> diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c
> index 9c8943d..d689540 100644
> --- a/drivers/extcon/extcon-palmas.c
> +++ b/drivers/extcon/extcon-palmas.c
> @@ -29,10 +29,10 @@
> #include <linux/of.h>
> #include <linux/of_platform.h>
>
> -static const char *palmas_extcon_cable[] = {
> - [0] = "USB",
> - [1] = "USB-HOST",
> - NULL,
> +static const enum extcon palmas_extcon_cable[] = {
> + EXTCON_USB,
> + EXTCON_USB_HOST,
> + EXTCON_NONE,
> };
>
> static const int mutually_exclusive[] = {0x3, 0x0};
> @@ -49,6 +49,7 @@ static void palmas_usb_wakeup(struct palmas *palmas, int
> enable)
> static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
> {
> struct palmas_usb *palmas_usb = _palmas_usb;
> + struct extcon_dev *edev = palmas_usb->edev;
> unsigned int vbus_line_state;
>
> palmas_read(palmas_usb->palmas, PALMAS_INTERRUPT_BASE,
> @@ -57,7 +58,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void
> *_palmas_usb)
> if (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) {
> if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) {
> palmas_usb->linkstat = PALMAS_USB_STATE_VBUS;
> - extcon_set_cable_state(palmas_usb->edev, "USB",
> true);
> + extcon_set_cable_state_(edev, EXTCON_USB, true);
> dev_info(palmas_usb->dev, "USB cable is attached\n");
> } else {
> dev_dbg(palmas_usb->dev,
> @@ -66,7 +67,7 @@ static irqreturn_t palmas_vbus_irq_handler(int irq, void
> *_palmas_usb)
> } else if (!(vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS)) {
> if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) {
> palmas_usb->linkstat =
> PALMAS_USB_STATE_DISCONNECT;
> - extcon_set_cable_state(palmas_usb->edev, "USB",
> false);
> + extcon_set_cable_state_(edev, EXTCON_USB, false);
> dev_info(palmas_usb->dev, "USB cable is detached\n");
> } else {
> dev_dbg(palmas_usb->dev,
> @@ -81,6 +82,7 @@ static irqreturn_t palmas_id_irq_handler(int irq, void
> *_palmas_usb)
> {
> unsigned int set, id_src;
> struct palmas_usb *palmas_usb = _palmas_usb;
> + struct extcon_dev *edev = palmas_usb->edev;
>
> palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
> PALMAS_USB_ID_INT_LATCH_SET, &set);
> @@ -93,7 +95,7 @@ static irqreturn_t palmas_id_irq_handler(int irq, void
> *_palmas_usb)
> PALMAS_USB_ID_INT_LATCH_CLR,
> PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
> palmas_usb->linkstat = PALMAS_USB_STATE_ID;
> - extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true);
> + extcon_set_cable_state_(edev, EXTCON_USB_HOST, true);
> dev_info(palmas_usb->dev, "USB-HOST cable is attached\n");
> } else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) &&
> (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)
> PALMAS_USB_ID_INT_LATCH_CLR,
> PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
> palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
> - extcon_set_cable_state(palmas_usb->edev, "USB-HOST",
> false);
> + extcon_set_cable_state_(edev, EXTCON_USB_HOST, false);
> dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
> } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) &&
> (!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) {
> palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT;
> - extcon_set_cable_state(palmas_usb->edev, "USB-HOST",
> false);
> + extcon_set_cable_state_(edev, EXTCON_USB_HOST, false);
> dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
> } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT)
> &&
> (id_src & PALMAS_USB_ID_INT_SRC_ID_GND))
> {
> palmas_usb->linkstat = PALMAS_USB_STATE_ID;
> - extcon_set_cable_state(palmas_usb->edev, "USB-HOST", true);
> + extcon_set_cable_state_(edev, EXTCON_USB_HOST, true);
> dev_info(palmas_usb->dev, " USB-HOST cable is attached\n");
> }
>
> diff --git a/drivers/extcon/extcon-rt8973a.c b/drivers/extcon/extcon-rt8973a.c
> index 04447f3..f2a8672 100644
> --- a/drivers/extcon/extcon-rt8973a.c
> +++ b/drivers/extcon/extcon-rt8973a.c
> @@ -90,21 +90,12 @@ static struct reg_data rt8973a_reg_data[] = {
> };
>
> /* List of detectable cables */
> -enum {
> - EXTCON_CABLE_USB = 0,
> - EXTCON_CABLE_USB_HOST,
> - EXTCON_CABLE_TA,
> - EXTCON_CABLE_JIG,
> -
> - EXTCON_CABLE_END,
> -};
> -
> -static const char *rt8973a_extcon_cable[] = {
> - [EXTCON_CABLE_USB] = "USB",
> - [EXTCON_CABLE_USB_HOST] = "USB-Host",
> - [EXTCON_CABLE_TA] = "TA",
> - [EXTCON_CABLE_JIG] = "JIG",
> - NULL,
> +static const enum extcon rt8973a_extcon_cable[] = {
> + EXTCON_USB,
> + EXTCON_USB_HOST,
> + EXTCON_TA,
> + EXTCON_JIG,
> + EXTCON_NONE,
> };
>
> /* Define OVP (Over Voltage Protection), OTP (Over Temperature Protection) */
> @@ -307,14 +298,11 @@ static int rt8973a_muic_cable_handler(struct
> rt8973a_muic_info *info,
> enum rt8973a_event_type event)
> {
> static unsigned int prev_cable_type;
> - const char **cable_names = info->edev->supported_cable;
> unsigned int con_sw = DM_DP_SWITCH_UART;
> - int ret, idx = 0, cable_type;
> + int ret, cable_type;
> + enum extcon id;
> bool attached = false;
>
> - if (!cable_names)
> - return 0;
> -
> switch (event) {
> case RT8973A_EVENT_ATTACH:
> cable_type = rt8973a_muic_get_cable_type(info);
> @@ -341,25 +329,25 @@ static int rt8973a_muic_cable_handler(struct
> rt8973a_muic_info *info,
>
> switch (cable_type) {
> case RT8973A_MUIC_ADC_OTG:
> - idx = EXTCON_CABLE_USB_HOST;
> + id = EXTCON_USB_HOST;
> con_sw = DM_DP_SWITCH_USB;
> break;
> case RT8973A_MUIC_ADC_TA:
> - idx = EXTCON_CABLE_TA;
> + id = EXTCON_TA;
> con_sw = DM_DP_SWITCH_OPEN;
> break;
> case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB:
> case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB:
> - idx = EXTCON_CABLE_JIG;
> + id = EXTCON_JIG;
> con_sw = DM_DP_SWITCH_USB;
> break;
> case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART:
> case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART:
> - idx = EXTCON_CABLE_JIG;
> + id = EXTCON_JIG;
> con_sw = DM_DP_SWITCH_UART;
> break;
> case RT8973A_MUIC_ADC_USB:
> - idx = EXTCON_CABLE_USB;
> + id = EXTCON_USB;
> con_sw = DM_DP_SWITCH_USB;
> break;
> case RT8973A_MUIC_ADC_OPEN:
> @@ -409,7 +397,7 @@ static int rt8973a_muic_cable_handler(struct
> rt8973a_muic_info *info,
> return ret;
>
> /* Change the state of external accessory */
> - extcon_set_cable_state(info->edev, cable_names[idx], attached);
> + extcon_set_cable_state_(info->edev, id, attached);
>
> return 0;
> }
> diff --git a/drivers/extcon/extcon-sm5502.c b/drivers/extcon/extcon-sm5502.c
> index 6f1d11f..520693d 100644
> --- a/drivers/extcon/extcon-sm5502.c
> +++ b/drivers/extcon/extcon-sm5502.c
> @@ -92,19 +92,11 @@ static struct reg_data sm5502_reg_data[] = {
> };
>
> /* List of detectable cables */
> -enum {
> - EXTCON_CABLE_USB = 0,
> - EXTCON_CABLE_USB_HOST,
> - EXTCON_CABLE_TA,
> -
> - EXTCON_CABLE_END,
> -};
> -
> -static const char *sm5502_extcon_cable[] = {
> - [EXTCON_CABLE_USB] = "USB",
> - [EXTCON_CABLE_USB_HOST] = "USB-Host",
> - [EXTCON_CABLE_TA] = "TA",
> - NULL,
> +static const enum extcon sm5502_extcon_cable[] = {
> + EXTCON_USB,
> + EXTCON_USB_HOST,
> + EXTCON_TA,
> + EXTCON_NONE,
> };
>
> /* Define supported accessory type */
> @@ -377,16 +369,12 @@ static int sm5502_muic_cable_handler(struct
> sm5502_muic_info *info,
> bool attached)
> {
> static unsigned int prev_cable_type = SM5502_MUIC_ADC_GROUND;
> - const char **cable_names = info->edev->supported_cable;
> unsigned int cable_type = SM5502_MUIC_ADC_GROUND;
> unsigned int con_sw = DM_DP_SWITCH_OPEN;
> unsigned int vbus_sw = VBUSIN_SWITCH_OPEN;
> - unsigned int idx = 0;
> + enum extcon id;
> int ret;
>
> - if (!cable_names)
> - return 0;
> -
> /* Get the type of attached or detached cable */
> if (attached)
> cable_type = sm5502_muic_get_cable_type(info);
> @@ -396,17 +384,17 @@ static int sm5502_muic_cable_handler(struct
> sm5502_muic_info *info,
>
> switch (cable_type) {
> case SM5502_MUIC_ADC_OPEN_USB:
> - idx = EXTCON_CABLE_USB;
> + id = EXTCON_USB;
> con_sw = DM_DP_SWITCH_USB;
> vbus_sw = VBUSIN_SWITCH_VBUSOUT_WITH_USB;
> break;
> case SM5502_MUIC_ADC_OPEN_TA:
> - idx = EXTCON_CABLE_TA;
> + id = EXTCON_TA;
> con_sw = DM_DP_SWITCH_OPEN;
> vbus_sw = VBUSIN_SWITCH_VBUSOUT;
> break;
> case SM5502_MUIC_ADC_OPEN_USB_OTG:
> - idx = EXTCON_CABLE_USB_HOST;
> + id = EXTCON_USB_HOST;
> con_sw = DM_DP_SWITCH_USB;
> vbus_sw = VBUSIN_SWITCH_OPEN;
> break;
> @@ -422,7 +410,7 @@ static int sm5502_muic_cable_handler(struct
> sm5502_muic_info *info,
> return ret;
>
> /* Change the state of external accessory */
> - extcon_set_cable_state(info->edev, cable_names[idx], attached);
> + extcon_set_cable_state_(info->edev, id, attached);
>
> return 0;
> }
> diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-
> gpio.c
> index 160ec12..4cf4f19 100644
> --- a/drivers/extcon/extcon-usb-gpio.c
> +++ b/drivers/extcon/extcon-usb-gpio.c
> @@ -39,18 +39,10 @@ struct usb_extcon_info {
> struct delayed_work wq_detcable;
> };
>
> -/* List of detectable cables */
> -enum {
> - EXTCON_CABLE_USB = 0,
> - EXTCON_CABLE_USB_HOST,
> -
> - EXTCON_CABLE_END,
> -};
> -
> -static const char *usb_extcon_cable[] = {
> - [EXTCON_CABLE_USB] = "USB",
> - [EXTCON_CABLE_USB_HOST] = "USB-HOST",
> - NULL,
> +static const enum extcon usb_extcon_cable[] = {
> + EXTCON_USB,
> + EXTCON_USB_HOST,
> + EXTCON_NONE,
> };
>
> static void usb_extcon_detect_cable(struct work_struct *work)
> @@ -68,24 +60,16 @@ static void usb_extcon_detect_cable(struct work_struct
> *work)
> * As we don't have event for USB peripheral cable attached,
> * we simulate USB peripheral attach here.
> */
> - extcon_set_cable_state(info->edev,
> -
> usb_extcon_cable[EXTCON_CABLE_USB_HOST],
> - false);
> - extcon_set_cable_state(info->edev,
> - usb_extcon_cable[EXTCON_CABLE_USB],
> - true);
> + extcon_set_cable_state_(info->edev, EXTCON_USB_HOST,
> false);
> + extcon_set_cable_state_(info->edev, EXTCON_USB, true);
> } else {
> /*
> * ID = 0 means USB HOST cable attached.
> * As we don't have event for USB peripheral cable detached,
> * we simulate USB peripheral detach here.
> */
> - extcon_set_cable_state(info->edev,
> - usb_extcon_cable[EXTCON_CABLE_USB],
> - false);
> - extcon_set_cable_state(info->edev,
> -
> usb_extcon_cable[EXTCON_CABLE_USB_HOST],
> - true);
> + extcon_set_cable_state_(info->edev, EXTCON_USB, false);
> + extcon_set_cable_state_(info->edev, EXTCON_USB_HOST,
> true);
> }
> }
>
> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
> index 2fb5f75..4aeb585 100644
> --- a/drivers/extcon/extcon.c
> +++ b/drivers/extcon/extcon.c
> @@ -3,6 +3,9 @@
> *
> * External connector (extcon) class driver
> *
> + * Copyright (C) 2015 Samsung Electronics
> + * Author: Chanwoo Choi <[email protected]>
> + *
> * Copyright (C) 2012 Samsung Electronics
> * Author: Donggeun Kim <[email protected]>
> * Author: MyungJoo Ham <[email protected]>
> @@ -32,36 +35,43 @@
> #include <linux/slab.h>
> #include <linux/sysfs.h>
>
> -/*
> - * extcon_cable_name suggests the standard cable names for commonly used
> - * cable types.
> - *
> - * However, please do not use extcon_cable_name directly for extcon_dev
> - * struct's supported_cable pointer unless your device really supports
> - * every single port-type of the following cable names. Please choose cable
> - * names that are actually used in your extcon device.
> - */
> -const char extcon_cable_name[][CABLE_NAME_MAX + 1] = {
> +#define SUPPORTED_CABLE_MAX 32
> +#define CABLE_NAME_MAX 30
> +
> +static const char *extcon_name[] = {
> + [EXTCON_NONE] = "NONE",
> +
> + /* USB external connector */
> [EXTCON_USB] = "USB",
> - [EXTCON_USB_HOST] = "USB-Host",
> + [EXTCON_USB_HOST] = "USB-HOST",
> +
> + /* Charger external connector */
> [EXTCON_TA] = "TA",
> - [EXTCON_FAST_CHARGER] = "Fast-charger",
> - [EXTCON_SLOW_CHARGER] = "Slow-charger",
> - [EXTCON_CHARGE_DOWNSTREAM] = "Charge-downstream",
> + [EXTCON_FAST_CHARGER] = "FAST-CHARGER",
> + [EXTCON_SLOW_CHARGER] = "SLOW-CHARGER",
> + [EXTCON_CHARGE_DOWNSTREAM] = "CHARGE-DOWNSTREAM",
> +
> + /* Audio/Video external connector */
> + [EXTCON_LINE_IN] = "LINE-IN",
> + [EXTCON_LINE_OUT] = "LINE-OUT",
> + [EXTCON_MICROPHONE] = "MICROPHONE",
> + [EXTCON_HEADPHONE] = "HEADPHONE",
> +
> [EXTCON_HDMI] = "HDMI",
> [EXTCON_MHL] = "MHL",
> [EXTCON_DVI] = "DVI",
> [EXTCON_VGA] = "VGA",
> - [EXTCON_DOCK] = "Dock",
> - [EXTCON_LINE_IN] = "Line-in",
> - [EXTCON_LINE_OUT] = "Line-out",
> - [EXTCON_MIC_IN] = "Microphone",
> - [EXTCON_HEADPHONE_OUT] = "Headphone",
> - [EXTCON_SPDIF_IN] = "SPDIF-in",
> - [EXTCON_SPDIF_OUT] = "SPDIF-out",
> - [EXTCON_VIDEO_IN] = "Video-in",
> - [EXTCON_VIDEO_OUT] = "Video-out",
> - [EXTCON_MECHANICAL] = "Mechanical",
> + [EXTCON_SPDIF_IN] = "SPDIF-IN",
> + [EXTCON_SPDIF_OUT] = "SPDIF-OUT",
> + [EXTCON_VIDEO_IN] = "VIDEO-IN",
> + [EXTCON_VIDEO_OUT] = "VIDEO-OUT",
> +
> + /* Etc external connector */
> + [EXTCON_DOCK] = "DOCK",
> + [EXTCON_JIG] = "JIG",
> + [EXTCON_MECHANICAL] = "MECHANICAL",
> +
> + NULL,
> };
>
> static struct class *extcon_class;
> @@ -118,11 +128,9 @@ static ssize_t state_show(struct device *dev, struct
> device_attribute *attr,
> if (edev->max_supported == 0)
> return sprintf(buf, "%u\n", edev->state);
>
> - for (i = 0; i < SUPPORTED_CABLE_MAX; i++) {
> - if (!edev->supported_cable[i])
> - break;
> + for (i = 0; i < edev->max_supported; i++) {
> count += sprintf(buf + count, "%s=%d\n",
> - edev->supported_cable[i],
> + extcon_name[edev->supported_cable[i]],
> !!(edev->state & (1 << i)));
> }
>
> @@ -171,9 +179,10 @@ static ssize_t cable_name_show(struct device *dev,
> {
> struct extcon_cable *cable = container_of(attr, struct extcon_cable,
> attr_name);
> + int i = cable->cable_index;
>
> return sprintf(buf, "%s\n",
> - cable->edev->supported_cable[cable->cable_index]);
> + extcon_name[cable->edev->supported_cable[i]]);
> }
>
> static ssize_t cable_state_show(struct device *dev,
> @@ -282,39 +291,57 @@ int extcon_set_state(struct extcon_dev *edev, u32
> state)
> }
> EXPORT_SYMBOL_GPL(extcon_set_state);
>
> -/**
> - * extcon_find_cable_index() - Get the cable index based on the cable name.
> - * @edev: the extcon device that has the cable.
> - * @cable_name: cable name to be searched.
> - *
> - * Note that accessing a cable state based on cable_index is faster than
> - * cable_name because using cable_name induces a loop with strncmp().
> - * Thus, when get/set_cable_state is repeatedly used, using cable_index
> - * is recommended.
> - */
> -int extcon_find_cable_index(struct extcon_dev *edev, const char *cable_name)
> +static int extcon_find_cable_index(struct extcon_dev *edev,
> + const char *cable_name)
> {
> + enum extcon id = EXTCON_NONE;
> int i;
>
> - if (edev->supported_cable) {
> - for (i = 0; edev->supported_cable[i]; i++) {
> - if (!strncmp(edev->supported_cable[i],
> - cable_name, CABLE_NAME_MAX))
> - return i;
> + if (edev->max_supported == 0)
> + return -EINVAL;
> +
> + /* Find the the number of extcon cable */
> + for (i = 0; i < __EXTCON_END; i++) {
> + if (!extcon_name[i])
> + continue;
> + if (!strncmp(extcon_name[i], cable_name, CABLE_NAME_MAX))
> {
> + id = i;
> + break;
> }
> }
>
> + if (id == EXTCON_NONE)
> + return -EINVAL;
> +
> + /* Find the the index of extcon cable in edev->supported_cable */
> + for (i = 0; i < edev->max_supported; i++) {
> + if (edev->supported_cable[i] == id)
> + return i;
> + }
> +
> return -EINVAL;
> }
> -EXPORT_SYMBOL_GPL(extcon_find_cable_index);
>
> /**
> * extcon_get_cable_state_() - Get the status of a specific cable.
> * @edev: the extcon device that has the cable.
> - * @index: cable index that can be retrieved by extcon_find_cable_index().
> + * @id: the unique id of each external connector in extcon
> enumeration.
> */
> -int extcon_get_cable_state_(struct extcon_dev *edev, int index)
> +int extcon_get_cable_state_(struct extcon_dev *edev, const enum extcon id)
> {
> + int i, index = -EINVAL;
> +
> + /* Find the the index of extcon cable in edev->supported_cable */
> + for (i = 0; edev->max_supported < i; i++) {
> + if (edev->supported_cable[i] == id) {
> + index = i;
> + break;
> + }
> + }
> +
> + if (i == edev->max_supported)
> + return -EINVAL;
> +
> if (index < 0 || (edev->max_supported && edev->max_supported <=
> index))
> return -EINVAL;
>
> @@ -339,15 +366,27 @@ EXPORT_SYMBOL_GPL(extcon_get_cable_state);
> /**
> * extcon_set_cable_state_() - Set the status of a specific cable.
> * @edev: the extcon device that has the cable.
> - * @index: cable index that can be retrieved by
> - * extcon_find_cable_index().
> - * @cable_state: the new cable status. The default semantics is
> + * @id: the unique id of each external connector
> + * in extcon enumeration.
> + * @state: the new cable status. The default semantics is
> * true: attached / false: detached.
> */
> -int extcon_set_cable_state_(struct extcon_dev *edev,
> - int index, bool cable_state)
> +int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id,
> + bool cable_state)
> {
> u32 state;
> + int i, index = -EINVAL;
> +
> + /* Find the the index of extcon cable in edev->supported_cable */
> + for (i = 0; i < edev->max_supported; i++) {
> + if (edev->supported_cable[i] == id) {
> + index = i;
> + break;
> + }
> + }
> +
> + if (i == edev->max_supported)
> + return -EINVAL;
>
> if (index < 0 || (edev->max_supported && edev->max_supported <=
> index))
> return -EINVAL;
> @@ -605,7 +644,7 @@ static void dummy_sysfs_dev_release(struct device
> *dev)
> *
> * Return the pointer of extcon device if success or ERR_PTR(err) if fail
> */
> -struct extcon_dev *extcon_dev_allocate(const char **supported_cable)
> +struct extcon_dev *extcon_dev_allocate(const enum extcon
> *supported_cable)
> {
> struct extcon_dev *edev;
>
> @@ -659,7 +698,7 @@ static void devm_extcon_dev_release(struct device
> *dev, void *res)
> * or ERR_PTR(err) if fail
> */
> struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
> - const char **supported_cable)
> + const enum extcon *supported_cable)
> {
> struct extcon_dev **ptr, *edev;
>
> @@ -709,17 +748,15 @@ int extcon_dev_register(struct extcon_dev *edev)
> return ret;
> }
>
> - if (edev->supported_cable) {
> - /* Get size of array */
> - for (index = 0; edev->supported_cable[index]; index++)
> - ;
> - edev->max_supported = index;
> - } else {
> - edev->max_supported = 0;
> - }
> + if (!edev->supported_cable)
> + return -EINVAL;
>
> + for (; edev->supported_cable[index] != EXTCON_NONE; index++);
> +
> + edev->max_supported = index;
> if (index > SUPPORTED_CABLE_MAX) {
> - dev_err(&edev->dev, "extcon: maximum number of supported
> cables exceeded.\n");
> + dev_err(&edev->dev,
> + "exceed the maximum number of supported cables\n");
> return -EINVAL;
> }
>
> @@ -1070,6 +1107,7 @@ static void __exit extcon_class_exit(void)
> }
> module_exit(extcon_class_exit);
>
> +MODULE_AUTHOR("Chanwoo Choi <[email protected]>");
> MODULE_AUTHOR("Mike Lockwood <[email protected]>");
> MODULE_AUTHOR("Donggeun Kim <[email protected]>");
> MODULE_AUTHOR("MyungJoo Ham <[email protected]>");
> diff --git a/include/linux/extcon.h b/include/linux/extcon.h
> index 799474d9d..de158a1 100644
> --- a/include/linux/extcon.h
> +++ b/include/linux/extcon.h
> @@ -1,6 +1,9 @@
> /*
> * External connector (extcon) class driver
> *
> + * Copyright (C) 2015 Samsung Electronics
> + * Author: Chanwoo Choi <[email protected]>
> + *
> * Copyright (C) 2012 Samsung Electronics
> * Author: Donggeun Kim <[email protected]>
> * Author: MyungJoo Ham <[email protected]>
> @@ -27,8 +30,41 @@
> #include <linux/notifier.h>
> #include <linux/sysfs.h>
>
> -#define SUPPORTED_CABLE_MAX 32
> -#define CABLE_NAME_MAX 30
> +enum extcon {
> + EXTCON_NONE = 0x0, /* NONE */
> +
> + /* USB external connector */
> + EXTCON_USB = 0x1, /* USB */
> + EXTCON_USB_HOST = 0x2, /* USB-HOST */
> +
> + /* Charger external connector */
> + EXTCON_TA = 0x10, /* TA */
> + EXTCON_FAST_CHARGER = 0x11, /* FAST-CHARGER */
> + EXTCON_SLOW_CHARGER = 0x12, /* SLOW-CHARGER */
> + EXTCON_CHARGE_DOWNSTREAM= 0x13, /* CHARGE-
> DOWNSTREAM */
> +
> + /* Audio/Video external connector */
> + EXTCON_LINE_IN = 0x20, /* LINE-IN */
> + EXTCON_LINE_OUT = 0x21, /* LINE-OUT */
> + EXTCON_MICROPHONE = 0x22, /* MICROPHONE */
> + EXTCON_HEADPHONE = 0x23, /* HEADPHONE */
> +
> + EXTCON_HDMI = 0x30, /* HDMI */
> + EXTCON_MHL = 0x31, /* MHL */
> + EXTCON_DVI = 0x32, /* DVI */
> + EXTCON_VGA = 0x33, /* VGA */
> + EXTCON_SPDIF_IN = 0x34, /* SPDIF-IN */
> + EXTCON_SPDIF_OUT = 0x35, /* SPDIF-OUT */
> + EXTCON_VIDEO_IN = 0x36, /* VIDEO-IN */
> + EXTCON_VIDEO_OUT = 0x37, /* VIDEO-OUT */
> +
> + /* Etc external connector */
> + EXTCON_DOCK = 0x50, /* DOCK */
> + EXTCON_JIG = 0x51, /* JIG */
> + EXTCON_MECHANICAL = 0x52, /* MECHANICAL */
> +
> + __EXTCON_END,
> +};
>
> /*
> * The standard cable name is to help support general notifier
> @@ -48,29 +84,6 @@
> * you don't need such convention. This convention is helpful when
> * notifier can distinguish but notifiee cannot.
> */
> -enum extcon_cable_name {
> - EXTCON_USB = 0,
> - EXTCON_USB_HOST,
> - EXTCON_TA, /* Travel Adaptor */
> - EXTCON_FAST_CHARGER,
> - EXTCON_SLOW_CHARGER,
> - EXTCON_CHARGE_DOWNSTREAM, /* Charging an external device
> */
> - EXTCON_HDMI,
> - EXTCON_MHL,
> - EXTCON_DVI,
> - EXTCON_VGA,
> - EXTCON_DOCK,
> - EXTCON_LINE_IN,
> - EXTCON_LINE_OUT,
> - EXTCON_MIC_IN,
> - EXTCON_HEADPHONE_OUT,
> - EXTCON_SPDIF_IN,
> - EXTCON_SPDIF_OUT,
> - EXTCON_VIDEO_IN,
> - EXTCON_VIDEO_OUT,
> - EXTCON_MECHANICAL,
> -};
> -extern const char extcon_cable_name[][CABLE_NAME_MAX + 1];
>
> struct extcon_cable;
>
> @@ -113,7 +126,7 @@ struct extcon_cable;
> struct extcon_dev {
> /* Optional user initializing data */
> const char *name;
> - const char **supported_cable;
> + const enum extcon *supported_cable;
> const u32 *mutually_exclusive;
>
> /* Optional callbacks to override class functions */
> @@ -194,10 +207,10 @@ extern struct extcon_dev
> *extcon_get_extcon_dev(const char *extcon_name);
> /*
> * Following APIs control the memory of extcon device.
> */
> -extern struct extcon_dev *extcon_dev_allocate(const char **cables);
> +extern struct extcon_dev *extcon_dev_allocate(const enum extcon *cable);
> extern void extcon_dev_free(struct extcon_dev *edev);
> extern struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
> - const char **cables);
> + const enum extcon *cable);
> extern void devm_extcon_dev_free(struct device *dev, struct extcon_dev
> *edev);
>
> /*
> @@ -216,13 +229,10 @@ extern int extcon_update_state(struct extcon_dev
> *edev, u32 mask, u32 state);
>
> /*
> * get/set_cable_state access each bit of the 32b encoded state value.
> - * They are used to access the status of each cable based on the cable_name
> - * or cable_index, which is retrieved by extcon_find_cable_index
> + * They are used to access the status of each cable based on the cable_name.
> */
> -extern int extcon_find_cable_index(struct extcon_dev *sdev,
> - const char *cable_name);
> -extern int extcon_get_cable_state_(struct extcon_dev *edev, int cable_index);
> -extern int extcon_set_cable_state_(struct extcon_dev *edev, int cable_index,
> +extern int extcon_get_cable_state_(struct extcon_dev *edev, enum extcon id);
> +extern int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id,
> bool cable_state);
>
> extern int extcon_get_cable_state(struct extcon_dev *edev,
> @@ -281,7 +291,7 @@ static inline int devm_extcon_dev_register(struct device
> *dev,
> static inline void devm_extcon_dev_unregister(struct device *dev,
> struct extcon_dev *edev) { }
>
> -static inline struct extcon_dev *extcon_dev_allocate(const char **cables)
> +static inline struct extcon_dev *extcon_dev_allocate(const enum extcon
> *cable)
> {
> return ERR_PTR(-ENOSYS);
> }
> @@ -289,7 +299,7 @@ static inline struct extcon_dev
> *extcon_dev_allocate(const char **cables)
> static inline void extcon_dev_free(struct extcon_dev *edev) { }
>
> static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
> - const char **cables)
> + const enum extcon *cable)
> {
> return ERR_PTR(-ENOSYS);
> }
> @@ -312,20 +322,14 @@ static inline int extcon_update_state(struct
> extcon_dev *edev, u32 mask,
> return 0;
> }
>
> -static inline int extcon_find_cable_index(struct extcon_dev *edev,
> - const char *cable_name)
> -{
> - return 0;
> -}
> -
> static inline int extcon_get_cable_state_(struct extcon_dev *edev,
> - int cable_index)
> + enum extcon id)
> {
> return 0;
> }
>
> static inline int extcon_set_cable_state_(struct extcon_dev *edev,
> - int cable_index, bool cable_state)
> + enum extcon id, bool cable_state)
> {
> return 0;
> }
> diff --git a/include/linux/extcon/extcon-adc-jack.h
> b/include/linux/extcon/extcon-adc-jack.h
> index 9ca958c..53c6080 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 {
> * @consumer_channel: Unique name to identify the channel on the
> consumer
> * side. This typically describes the channels used within
> * the consumer. E.g. 'battery_voltage'
> - * @cable_names: array of cable names ending with null.
> + * @cable_names: array of extcon id for supported cables.
> * @adc_contitions: array of struct adc_jack_cond conditions ending
> * with .state = 0 entry. This describes how to decode
> * adc values into extcon state.
> @@ -58,8 +58,7 @@ struct adc_jack_pdata {
> const char *name;
> const char *consumer_channel;
>
> - /* The last entry should be NULL */
> - const char **cable_names;
> + const enum extcon *cable_names;
>
> /* The last entry's state should be 0 */
> struct adc_jack_cond *adc_conditions;
> --
> 1.8.5.5
2015-05-15 23:31 GMT+09:00 Chanwoo Choi <[email protected]>:
> 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:
I like the idea of switching to unique identifier. Some comments below.
>
> enum extcon {
> EXTCON_NONE = 0x0, /* NONE */
>
> /* USB external connector */
> EXTCON_USB = 0x1, /* USB */
> EXTCON_USB_HOST = 0x2, /* USB-HOST */
>
> /* Charger external connector */
> EXTCON_TA = 0x10, /* TA */
> EXTCON_FAST_CHARGER = 0x11, /* FAST-CHARGER */
> EXTCON_SLOW_CHARGER = 0x12, /* SLOW-CHARGER */
> EXTCON_CHARGE_DOWNSTREAM= 0x13, /* CHARGE-DOWNSTREAM */
>
> /* Audio and video external connector */
> EXTCON_LINE_IN = 0x20, /* LINE-IN */
> EXTCON_LINE_OUT = 0x21, /* LINE-OUT */
> EXTCON_MICROPHONE = 0x22, /* MICROPHONE */
> EXTCON_HEADPHONE = 0x23, /* HEADPHONE */
>
> EXTCON_HDMI = 0x30, /* HDMI */
> EXTCON_MHL = 0x31, /* MHL */
> EXTCON_DVI = 0x32, /* DVI */
> EXTCON_VGA = 0x33, /* VGA */
> EXTCON_SPDIF_IN = 0x34, /* SPDIF-IN */
> EXTCON_SPDIF_OUT = 0x35, /* SPDIF-OUT */
> EXTCON_VIDEO_IN = 0x36, /* VIDEO-IN */
> EXTCON_VIDEO_OUT = 0x37, /* VIDEO-OUT */
>
> /* Miscellaneous external connector */
> EXTCON_DOCK = 0x50, /* DOCK */
> EXTCON_JIG = 0x51, /* JIG */
> EXTCON_MECHANICAL = 0x52, /* MECHANICAL */
>
> __EXTCON_END,
> };
>
> For exmaple in extcon-arizoan.c:
s/exmaple/example/
s/arizoan/arizona/
> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
> index 2fb5f75..4aeb585 100644
> --- a/drivers/extcon/extcon.c
> +++ b/drivers/extcon/extcon.c
> @@ -3,6 +3,9 @@
> *
> * External connector (extcon) class driver
> *
> + * Copyright (C) 2015 Samsung Electronics
> + * Author: Chanwoo Choi <[email protected]>
> + *
> * Copyright (C) 2012 Samsung Electronics
> * Author: Donggeun Kim <[email protected]>
> * Author: MyungJoo Ham <[email protected]>
> @@ -32,36 +35,43 @@
> #include <linux/slab.h>
> #include <linux/sysfs.h>
>
> -/*
> - * extcon_cable_name suggests the standard cable names for commonly used
> - * cable types.
> - *
> - * However, please do not use extcon_cable_name directly for extcon_dev
> - * struct's supported_cable pointer unless your device really supports
> - * every single port-type of the following cable names. Please choose cable
> - * names that are actually used in your extcon device.
> - */
> -const char extcon_cable_name[][CABLE_NAME_MAX + 1] = {
> +#define SUPPORTED_CABLE_MAX 32
Why only 32 cables are supported? I mean what is the reason behind the
hard limit?
> +#define CABLE_NAME_MAX 30
> +
> +static const char *extcon_name[] = {
> + [EXTCON_NONE] = "NONE",
> +
> + /* USB external connector */
> [EXTCON_USB] = "USB",
> - [EXTCON_USB_HOST] = "USB-Host",
> + [EXTCON_USB_HOST] = "USB-HOST",
> +
> + /* Charger external connector */
> [EXTCON_TA] = "TA",
> - [EXTCON_FAST_CHARGER] = "Fast-charger",
> - [EXTCON_SLOW_CHARGER] = "Slow-charger",
> - [EXTCON_CHARGE_DOWNSTREAM] = "Charge-downstream",
> + [EXTCON_FAST_CHARGER] = "FAST-CHARGER",
> + [EXTCON_SLOW_CHARGER] = "SLOW-CHARGER",
> + [EXTCON_CHARGE_DOWNSTREAM] = "CHARGE-DOWNSTREAM",
> +
> + /* Audio/Video external connector */
> + [EXTCON_LINE_IN] = "LINE-IN",
> + [EXTCON_LINE_OUT] = "LINE-OUT",
> + [EXTCON_MICROPHONE] = "MICROPHONE",
> + [EXTCON_HEADPHONE] = "HEADPHONE",
> +
> [EXTCON_HDMI] = "HDMI",
> [EXTCON_MHL] = "MHL",
> [EXTCON_DVI] = "DVI",
> [EXTCON_VGA] = "VGA",
> - [EXTCON_DOCK] = "Dock",
> - [EXTCON_LINE_IN] = "Line-in",
> - [EXTCON_LINE_OUT] = "Line-out",
> - [EXTCON_MIC_IN] = "Microphone",
> - [EXTCON_HEADPHONE_OUT] = "Headphone",
> - [EXTCON_SPDIF_IN] = "SPDIF-in",
> - [EXTCON_SPDIF_OUT] = "SPDIF-out",
> - [EXTCON_VIDEO_IN] = "Video-in",
> - [EXTCON_VIDEO_OUT] = "Video-out",
> - [EXTCON_MECHANICAL] = "Mechanical",
> + [EXTCON_SPDIF_IN] = "SPDIF-IN",
> + [EXTCON_SPDIF_OUT] = "SPDIF-OUT",
> + [EXTCON_VIDEO_IN] = "VIDEO-IN",
> + [EXTCON_VIDEO_OUT] = "VIDEO-OUT",
> +
> + /* Etc external connector */
> + [EXTCON_DOCK] = "DOCK",
> + [EXTCON_JIG] = "JIG",
> + [EXTCON_MECHANICAL] = "MECHANICAL",
> +
> + NULL,
> };
This change does not look related to the topic. Can you split it to
separate patch?
>
> static struct class *extcon_class;
> @@ -118,11 +128,9 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
> if (edev->max_supported == 0)
> return sprintf(buf, "%u\n", edev->state);
>
> - for (i = 0; i < SUPPORTED_CABLE_MAX; i++) {
> - if (!edev->supported_cable[i])
> - break;
> + for (i = 0; i < edev->max_supported; i++) {
> count += sprintf(buf + count, "%s=%d\n",
> - edev->supported_cable[i],
> + extcon_name[edev->supported_cable[i]],
> !!(edev->state & (1 << i)));
> }
>
> @@ -171,9 +179,10 @@ static ssize_t cable_name_show(struct device *dev,
> {
> struct extcon_cable *cable = container_of(attr, struct extcon_cable,
> attr_name);
> + int i = cable->cable_index;
>
> return sprintf(buf, "%s\n",
> - cable->edev->supported_cable[cable->cable_index]);
> + extcon_name[cable->edev->supported_cable[i]]);
> }
>
> static ssize_t cable_state_show(struct device *dev,
> @@ -282,39 +291,57 @@ int extcon_set_state(struct extcon_dev *edev, u32 state)
> }
> EXPORT_SYMBOL_GPL(extcon_set_state);
>
> -/**
> - * extcon_find_cable_index() - Get the cable index based on the cable name.
> - * @edev: the extcon device that has the cable.
> - * @cable_name: cable name to be searched.
> - *
> - * Note that accessing a cable state based on cable_index is faster than
> - * cable_name because using cable_name induces a loop with strncmp().
> - * Thus, when get/set_cable_state is repeatedly used, using cable_index
> - * is recommended.
> - */
> -int extcon_find_cable_index(struct extcon_dev *edev, const char *cable_name)
> +static int extcon_find_cable_index(struct extcon_dev *edev,
> + const char *cable_name)
> {
> + enum extcon id = EXTCON_NONE;
> int i;
>
> - if (edev->supported_cable) {
> - for (i = 0; edev->supported_cable[i]; i++) {
> - if (!strncmp(edev->supported_cable[i],
> - cable_name, CABLE_NAME_MAX))
> - return i;
> + if (edev->max_supported == 0)
> + return -EINVAL;
> +
> + /* Find the the number of extcon cable */
> + for (i = 0; i < __EXTCON_END; i++) {
> + if (!extcon_name[i])
> + continue;
> + if (!strncmp(extcon_name[i], cable_name, CABLE_NAME_MAX)) {
> + id = i;
> + break;
> }
> }
>
> + if (id == EXTCON_NONE)
> + return -EINVAL;
> +
> + /* Find the the index of extcon cable in edev->supported_cable */
> + for (i = 0; i < edev->max_supported; i++) {
> + if (edev->supported_cable[i] == id)
> + return i;
> + }
> +
> return -EINVAL;
> }
> -EXPORT_SYMBOL_GPL(extcon_find_cable_index);
>
> /**
> * extcon_get_cable_state_() - Get the status of a specific cable.
> * @edev: the extcon device that has the cable.
> - * @index: cable index that can be retrieved by extcon_find_cable_index().
> + * @id: the unique id of each external connector in extcon enumeration.
> */
> -int extcon_get_cable_state_(struct extcon_dev *edev, int index)
> +int extcon_get_cable_state_(struct extcon_dev *edev, const enum extcon id)
> {
> + int i, index = -EINVAL;
> +
> + /* Find the the index of extcon cable in edev->supported_cable */
> + for (i = 0; edev->max_supported < i; i++) {
> + if (edev->supported_cable[i] == id) {
> + index = i;
> + break;
> + }
> + }
> +
> + if (i == edev->max_supported)
> + return -EINVAL;
> +
> if (index < 0 || (edev->max_supported && edev->max_supported <= index))
> return -EINVAL;
>
> @@ -339,15 +366,27 @@ EXPORT_SYMBOL_GPL(extcon_get_cable_state);
> /**
> * extcon_set_cable_state_() - Set the status of a specific cable.
> * @edev: the extcon device that has the cable.
> - * @index: cable index that can be retrieved by
> - * extcon_find_cable_index().
> - * @cable_state: the new cable status. The default semantics is
> + * @id: the unique id of each external connector
> + * in extcon enumeration.
> + * @state: the new cable status. The default semantics is
> * true: attached / false: detached.
> */
> -int extcon_set_cable_state_(struct extcon_dev *edev,
> - int index, bool cable_state)
> +int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id,
> + bool cable_state)
> {
> u32 state;
> + int i, index = -EINVAL;
> +
> + /* Find the the index of extcon cable in edev->supported_cable */
> + for (i = 0; i < edev->max_supported; i++) {
> + if (edev->supported_cable[i] == id) {
> + index = i;
> + break;
> + }
> + }
This loop shows in few places, maybe split it to separate static
function? Just to avoid duplication of code.
> +
> + if (i == edev->max_supported)
> + return -EINVAL;
>
> if (index < 0 || (edev->max_supported && edev->max_supported <= index))
> return -EINVAL;
> @@ -605,7 +644,7 @@ static void dummy_sysfs_dev_release(struct device *dev)
> *
> * Return the pointer of extcon device if success or ERR_PTR(err) if fail
> */
> -struct extcon_dev *extcon_dev_allocate(const char **supported_cable)
> +struct extcon_dev *extcon_dev_allocate(const enum extcon *supported_cable)
I think you also have to update the documentation. At least for
{devm}_extcon_dev_allocate but maybe in other places too. Previously
the documentation states that supported_cable is an array of strings.
Additionally AFAIU now it must end with EXTCON_NONE. This
sentinel-like info must be clearly documented.
> {
> struct extcon_dev *edev;
>
> @@ -659,7 +698,7 @@ static void devm_extcon_dev_release(struct device *dev, void *res)
> * or ERR_PTR(err) if fail
> */
> struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
> - const char **supported_cable)
> + const enum extcon *supported_cable)
> {
> struct extcon_dev **ptr, *edev;
>
> @@ -709,17 +748,15 @@ int extcon_dev_register(struct extcon_dev *edev)
> return ret;
> }
>
> - if (edev->supported_cable) {
> - /* Get size of array */
> - for (index = 0; edev->supported_cable[index]; index++)
> - ;
> - edev->max_supported = index;
> - } else {
> - edev->max_supported = 0;
> - }
> + if (!edev->supported_cable)
> + return -EINVAL;
>
> + for (; edev->supported_cable[index] != EXTCON_NONE; index++);
> +
> + edev->max_supported = index;
> if (index > SUPPORTED_CABLE_MAX) {
> - dev_err(&edev->dev, "extcon: maximum number of supported cables exceeded.\n");
> + dev_err(&edev->dev,
> + "exceed the maximum number of supported cables\n");
> return -EINVAL;
> }
>
> @@ -1070,6 +1107,7 @@ static void __exit extcon_class_exit(void)
> }
> module_exit(extcon_class_exit);
>
> +MODULE_AUTHOR("Chanwoo Choi <[email protected]>");
> MODULE_AUTHOR("Mike Lockwood <[email protected]>");
> MODULE_AUTHOR("Donggeun Kim <[email protected]>");
> MODULE_AUTHOR("MyungJoo Ham <[email protected]>");
> diff --git a/include/linux/extcon.h b/include/linux/extcon.h
> index 799474d9d..de158a1 100644
> --- a/include/linux/extcon.h
> +++ b/include/linux/extcon.h
> @@ -1,6 +1,9 @@
> /*
> * External connector (extcon) class driver
> *
> + * Copyright (C) 2015 Samsung Electronics
> + * Author: Chanwoo Choi <[email protected]>
> + *
> * Copyright (C) 2012 Samsung Electronics
> * Author: Donggeun Kim <[email protected]>
> * Author: MyungJoo Ham <[email protected]>
> @@ -27,8 +30,41 @@
> #include <linux/notifier.h>
> #include <linux/sysfs.h>
>
> -#define SUPPORTED_CABLE_MAX 32
> -#define CABLE_NAME_MAX 30
> +enum extcon {
> + EXTCON_NONE = 0x0, /* NONE */
> +
> + /* USB external connector */
> + EXTCON_USB = 0x1, /* USB */
> + EXTCON_USB_HOST = 0x2, /* USB-HOST */
> +
> + /* Charger external connector */
> + EXTCON_TA = 0x10, /* TA */
> + EXTCON_FAST_CHARGER = 0x11, /* FAST-CHARGER */
> + EXTCON_SLOW_CHARGER = 0x12, /* SLOW-CHARGER */
> + EXTCON_CHARGE_DOWNSTREAM= 0x13, /* CHARGE-DOWNSTREAM */
Space before '='. I know it will mess the alignment in indentation but
it would be still more readable.
> +
> + /* Audio/Video external connector */
> + EXTCON_LINE_IN = 0x20, /* LINE-IN */
> + EXTCON_LINE_OUT = 0x21, /* LINE-OUT */
> + EXTCON_MICROPHONE = 0x22, /* MICROPHONE */
> + EXTCON_HEADPHONE = 0x23, /* HEADPHONE */
> +
> + EXTCON_HDMI = 0x30, /* HDMI */
> + EXTCON_MHL = 0x31, /* MHL */
> + EXTCON_DVI = 0x32, /* DVI */
> + EXTCON_VGA = 0x33, /* VGA */
> + EXTCON_SPDIF_IN = 0x34, /* SPDIF-IN */
> + EXTCON_SPDIF_OUT = 0x35, /* SPDIF-OUT */
> + EXTCON_VIDEO_IN = 0x36, /* VIDEO-IN */
> + EXTCON_VIDEO_OUT = 0x37, /* VIDEO-OUT */
> +
> + /* Etc external connector */
> + EXTCON_DOCK = 0x50, /* DOCK */
> + EXTCON_JIG = 0x51, /* JIG */
> + EXTCON_MECHANICAL = 0x52, /* MECHANICAL */
> +
There is no benefit of each comment here. The comment just duplicates
name, it does not give any additional information. Get rid of it.
> + __EXTCON_END,
Why "__" prefix?
> +};
>
> /*
> * The standard cable name is to help support general notifier
> @@ -48,29 +84,6 @@
> * you don't need such convention. This convention is helpful when
> * notifier can distinguish but notifiee cannot.
> */
Isn't the comment above related to the enum "extcon_cable_name" which
you are removing?
> -enum extcon_cable_name {
> - EXTCON_USB = 0,
> - EXTCON_USB_HOST,
> - EXTCON_TA, /* Travel Adaptor */
> - EXTCON_FAST_CHARGER,
> - EXTCON_SLOW_CHARGER,
> - EXTCON_CHARGE_DOWNSTREAM, /* Charging an external device */
> - EXTCON_HDMI,
> - EXTCON_MHL,
> - EXTCON_DVI,
> - EXTCON_VGA,
> - EXTCON_DOCK,
> - EXTCON_LINE_IN,
> - EXTCON_LINE_OUT,
> - EXTCON_MIC_IN,
> - EXTCON_HEADPHONE_OUT,
> - EXTCON_SPDIF_IN,
> - EXTCON_SPDIF_OUT,
> - EXTCON_VIDEO_IN,
> - EXTCON_VIDEO_OUT,
> - EXTCON_MECHANICAL,
> -};
Best regards,
Krzysztof
2015-05-15 23:31 GMT+09:00 Chanwoo Choi <[email protected]>:
> Previously, extcon consumer driver used the extcon_register_interest()
> to register the notifier chain and then to receive the notifier event
> when external connector's state is changed. When registering the notifier chain
> for specific external connector with extcon_register_interest(), it used the
> the string name of external connector directly. There are potential problem
> because of unclear, non-standard and inconsequent cable name. Namely,
> it is not appropriate method to identify each external connector.
>
> So, this patch modify the prototype of extcon_register_notifier() by using
> the 'enum extcon' which are the unique id for each external connector
> instead of unclear string method.
>
> - Previously, the extcon consumer driver used the extcon_register_interest()
> with 'cable_name' to point out the specific external connector. Also. it used
> the un-needed structure (struct extcon_specific_cable_nb).
> : int extcon_register_interest(struct extcon_specific_cable_nb *obj,
> const char *extcon_name, const char *cable_name,
> struct notifier_block *nb)
>
> - Newly, the updated extcon_register_notifier() would definitely support
> the same feature to detech the changed state of external connector without
> any specific structure (struct extcon_specific_cable_nb).
> : int extcon_register_notifier(struct extcon_dev *edev, enum extcon id,
> struct notifier_block *nb)
>
> This patch support the both extcon_register_interest() and new extcon_register_
> notifier(). But the extcon_{register|unregister}_interest() will be deprecated
> because extcon core would support the notifier event for extcon consumer driver
> with only updated extcon_register_notifier() and 'extcon_specific_cable_nb'
> will be removed if there are no extcon consumer driver with legacy
> extcon_{register|unregister}_interest().
>
> Signed-off-by: Chanwoo Choi <[email protected]>
> Cc: MyungJoo Ham <[email protected]>
> Cc: George Cherian <[email protected]>
> Cc: Felipe Balbi <[email protected]>
> Cc: Aaro Koskinen <[email protected]>
> ---
> drivers/extcon/extcon.c | 91 ++++++++++++++++++++++++++-----------------------
> include/linux/extcon.h | 17 +++++----
> 2 files changed, 56 insertions(+), 52 deletions(-)
>
> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
> index 4aeb585..14c8c95 100644
> --- a/drivers/extcon/extcon.c
> +++ b/drivers/extcon/extcon.c
> @@ -111,6 +111,16 @@ static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state)
> return 0;
> }
>
> +static bool is_extcon_changed(u32 prev, u32 new, int idx, bool *attached)
> +{
> + if (((prev >> idx) & 0x1) != ((new >> idx) & 0x1)) {
How about switching "state" to unsigned long and using bit operations
everywhere, like test_bit()?
The patch itself looks good and change above is not actually related
to the code here, so:
Reviewed-by: Krzysztof Kozlowski <[email protected]>
Best regards,
Krzysztof
Hi Krzysztof,
On Sun, May 17, 2015 at 4:10 PM, Krzysztof Kozlowski
<[email protected]> wrote:
> 2015-05-15 23:31 GMT+09:00 Chanwoo Choi <[email protected]>:
>> 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:
>
> I like the idea of switching to unique identifier. Some comments below.
>
>>
>> enum extcon {
>> EXTCON_NONE = 0x0, /* NONE */
>>
>> /* USB external connector */
>> EXTCON_USB = 0x1, /* USB */
>> EXTCON_USB_HOST = 0x2, /* USB-HOST */
>>
>> /* Charger external connector */
>> EXTCON_TA = 0x10, /* TA */
>> EXTCON_FAST_CHARGER = 0x11, /* FAST-CHARGER */
>> EXTCON_SLOW_CHARGER = 0x12, /* SLOW-CHARGER */
>> EXTCON_CHARGE_DOWNSTREAM= 0x13, /* CHARGE-DOWNSTREAM */
>>
>> /* Audio and video external connector */
>> EXTCON_LINE_IN = 0x20, /* LINE-IN */
>> EXTCON_LINE_OUT = 0x21, /* LINE-OUT */
>> EXTCON_MICROPHONE = 0x22, /* MICROPHONE */
>> EXTCON_HEADPHONE = 0x23, /* HEADPHONE */
>>
>> EXTCON_HDMI = 0x30, /* HDMI */
>> EXTCON_MHL = 0x31, /* MHL */
>> EXTCON_DVI = 0x32, /* DVI */
>> EXTCON_VGA = 0x33, /* VGA */
>> EXTCON_SPDIF_IN = 0x34, /* SPDIF-IN */
>> EXTCON_SPDIF_OUT = 0x35, /* SPDIF-OUT */
>> EXTCON_VIDEO_IN = 0x36, /* VIDEO-IN */
>> EXTCON_VIDEO_OUT = 0x37, /* VIDEO-OUT */
>>
>> /* Miscellaneous external connector */
>> EXTCON_DOCK = 0x50, /* DOCK */
>> EXTCON_JIG = 0x51, /* JIG */
>> EXTCON_MECHANICAL = 0x52, /* MECHANICAL */
>>
>> __EXTCON_END,
>> };
>>
>> For exmaple in extcon-arizoan.c:
> s/exmaple/example/
> s/arizoan/arizona/
Good catch. I'll fix it.
>
>> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
>> index 2fb5f75..4aeb585 100644
>> --- a/drivers/extcon/extcon.c
>> +++ b/drivers/extcon/extcon.c
>> @@ -3,6 +3,9 @@
>> *
>> * External connector (extcon) class driver
>> *
>> + * Copyright (C) 2015 Samsung Electronics
>> + * Author: Chanwoo Choi <[email protected]>
>> + *
>> * Copyright (C) 2012 Samsung Electronics
>> * Author: Donggeun Kim <[email protected]>
>> * Author: MyungJoo Ham <[email protected]>
>> @@ -32,36 +35,43 @@
>> #include <linux/slab.h>
>> #include <linux/sysfs.h>
>>
>> -/*
>> - * extcon_cable_name suggests the standard cable names for commonly used
>> - * cable types.
>> - *
>> - * However, please do not use extcon_cable_name directly for extcon_dev
>> - * struct's supported_cable pointer unless your device really supports
>> - * every single port-type of the following cable names. Please choose cable
>> - * names that are actually used in your extcon device.
>> - */
>> -const char extcon_cable_name[][CABLE_NAME_MAX + 1] = {
>> +#define SUPPORTED_CABLE_MAX 32
>
> Why only 32 cables are supported? I mean what is the reason behind the
> hard limit?
Current extcon core use the 32bit variable to identify the supported
external connectors of each extcon device. But, the number of
supported connectors should be updated. I have the plan about it.
>
>> +#define CABLE_NAME_MAX 30
>> +
>> +static const char *extcon_name[] = {
>> + [EXTCON_NONE] = "NONE",
>> +
>> + /* USB external connector */
>> [EXTCON_USB] = "USB",
>> - [EXTCON_USB_HOST] = "USB-Host",
>> + [EXTCON_USB_HOST] = "USB-HOST",
>> +
>> + /* Charger external connector */
>> [EXTCON_TA] = "TA",
>> - [EXTCON_FAST_CHARGER] = "Fast-charger",
>> - [EXTCON_SLOW_CHARGER] = "Slow-charger",
>> - [EXTCON_CHARGE_DOWNSTREAM] = "Charge-downstream",
>> + [EXTCON_FAST_CHARGER] = "FAST-CHARGER",
>> + [EXTCON_SLOW_CHARGER] = "SLOW-CHARGER",
>> + [EXTCON_CHARGE_DOWNSTREAM] = "CHARGE-DOWNSTREAM",
>> +
>> + /* Audio/Video external connector */
>> + [EXTCON_LINE_IN] = "LINE-IN",
>> + [EXTCON_LINE_OUT] = "LINE-OUT",
>> + [EXTCON_MICROPHONE] = "MICROPHONE",
>> + [EXTCON_HEADPHONE] = "HEADPHONE",
>> +
>> [EXTCON_HDMI] = "HDMI",
>> [EXTCON_MHL] = "MHL",
>> [EXTCON_DVI] = "DVI",
>> [EXTCON_VGA] = "VGA",
>> - [EXTCON_DOCK] = "Dock",
>> - [EXTCON_LINE_IN] = "Line-in",
>> - [EXTCON_LINE_OUT] = "Line-out",
>> - [EXTCON_MIC_IN] = "Microphone",
>> - [EXTCON_HEADPHONE_OUT] = "Headphone",
>> - [EXTCON_SPDIF_IN] = "SPDIF-in",
>> - [EXTCON_SPDIF_OUT] = "SPDIF-out",
>> - [EXTCON_VIDEO_IN] = "Video-in",
>> - [EXTCON_VIDEO_OUT] = "Video-out",
>> - [EXTCON_MECHANICAL] = "Mechanical",
>> + [EXTCON_SPDIF_IN] = "SPDIF-IN",
>> + [EXTCON_SPDIF_OUT] = "SPDIF-OUT",
>> + [EXTCON_VIDEO_IN] = "VIDEO-IN",
>> + [EXTCON_VIDEO_OUT] = "VIDEO-OUT",
>> +
>> + /* Etc external connector */
>> + [EXTCON_DOCK] = "DOCK",
>> + [EXTCON_JIG] = "JIG",
>> + [EXTCON_MECHANICAL] = "MECHANICAL",
>> +
>> + NULL,
>> };
>
> This change does not look related to the topic. Can you split it to
> separate patch?
Do you mean about changing the name of external connectors from small
letter to capital letter?
>
>>
>> static struct class *extcon_class;
>> @@ -118,11 +128,9 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
>> if (edev->max_supported == 0)
>> return sprintf(buf, "%u\n", edev->state);
>>
>> - for (i = 0; i < SUPPORTED_CABLE_MAX; i++) {
>> - if (!edev->supported_cable[i])
>> - break;
>> + for (i = 0; i < edev->max_supported; i++) {
>> count += sprintf(buf + count, "%s=%d\n",
>> - edev->supported_cable[i],
>> + extcon_name[edev->supported_cable[i]],
>> !!(edev->state & (1 << i)));
>> }
>>
>> @@ -171,9 +179,10 @@ static ssize_t cable_name_show(struct device *dev,
>> {
>> struct extcon_cable *cable = container_of(attr, struct extcon_cable,
>> attr_name);
>> + int i = cable->cable_index;
>>
>> return sprintf(buf, "%s\n",
>> - cable->edev->supported_cable[cable->cable_index]);
>> + extcon_name[cable->edev->supported_cable[i]]);
>> }
>>
>> static ssize_t cable_state_show(struct device *dev,
>> @@ -282,39 +291,57 @@ int extcon_set_state(struct extcon_dev *edev, u32 state)
>> }
>> EXPORT_SYMBOL_GPL(extcon_set_state);
>>
>> -/**
>> - * extcon_find_cable_index() - Get the cable index based on the cable name.
>> - * @edev: the extcon device that has the cable.
>> - * @cable_name: cable name to be searched.
>> - *
>> - * Note that accessing a cable state based on cable_index is faster than
>> - * cable_name because using cable_name induces a loop with strncmp().
>> - * Thus, when get/set_cable_state is repeatedly used, using cable_index
>> - * is recommended.
>> - */
>> -int extcon_find_cable_index(struct extcon_dev *edev, const char *cable_name)
>> +static int extcon_find_cable_index(struct extcon_dev *edev,
>> + const char *cable_name)
>> {
>> + enum extcon id = EXTCON_NONE;
>> int i;
>>
>> - if (edev->supported_cable) {
>> - for (i = 0; edev->supported_cable[i]; i++) {
>> - if (!strncmp(edev->supported_cable[i],
>> - cable_name, CABLE_NAME_MAX))
>> - return i;
>> + if (edev->max_supported == 0)
>> + return -EINVAL;
>> +
>> + /* Find the the number of extcon cable */
>> + for (i = 0; i < __EXTCON_END; i++) {
>> + if (!extcon_name[i])
>> + continue;
>> + if (!strncmp(extcon_name[i], cable_name, CABLE_NAME_MAX)) {
>> + id = i;
>> + break;
>> }
>> }
>>
>> + if (id == EXTCON_NONE)
>> + return -EINVAL;
>> +
>> + /* Find the the index of extcon cable in edev->supported_cable */
>> + for (i = 0; i < edev->max_supported; i++) {
>> + if (edev->supported_cable[i] == id)
>> + return i;
>> + }
>> +
>> return -EINVAL;
>> }
>> -EXPORT_SYMBOL_GPL(extcon_find_cable_index);
>>
>> /**
>> * extcon_get_cable_state_() - Get the status of a specific cable.
>> * @edev: the extcon device that has the cable.
>> - * @index: cable index that can be retrieved by extcon_find_cable_index().
>> + * @id: the unique id of each external connector in extcon enumeration.
>> */
>> -int extcon_get_cable_state_(struct extcon_dev *edev, int index)
>> +int extcon_get_cable_state_(struct extcon_dev *edev, const enum extcon id)
>> {
>> + int i, index = -EINVAL;
>> +
>> + /* Find the the index of extcon cable in edev->supported_cable */
>> + for (i = 0; edev->max_supported < i; i++) {
>> + if (edev->supported_cable[i] == id) {
>> + index = i;
>> + break;
>> + }
>> + }
>> +
>> + if (i == edev->max_supported)
>> + return -EINVAL;
>> +
>> if (index < 0 || (edev->max_supported && edev->max_supported <= index))
>> return -EINVAL;
>>
>> @@ -339,15 +366,27 @@ EXPORT_SYMBOL_GPL(extcon_get_cable_state);
>> /**
>> * extcon_set_cable_state_() - Set the status of a specific cable.
>> * @edev: the extcon device that has the cable.
>> - * @index: cable index that can be retrieved by
>> - * extcon_find_cable_index().
>> - * @cable_state: the new cable status. The default semantics is
>> + * @id: the unique id of each external connector
>> + * in extcon enumeration.
>> + * @state: the new cable status. The default semantics is
>> * true: attached / false: detached.
>> */
>> -int extcon_set_cable_state_(struct extcon_dev *edev,
>> - int index, bool cable_state)
>> +int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id,
>> + bool cable_state)
>> {
>> u32 state;
>> + int i, index = -EINVAL;
>> +
>> + /* Find the the index of extcon cable in edev->supported_cable */
>> + for (i = 0; i < edev->max_supported; i++) {
>> + if (edev->supported_cable[i] == id) {
>> + index = i;
>> + break;
>> + }
>> + }
>
> This loop shows in few places, maybe split it to separate static
> function? Just to avoid duplication of code.
OK.
>
>> +
>> + if (i == edev->max_supported)
>> + return -EINVAL;
>>
>> if (index < 0 || (edev->max_supported && edev->max_supported <= index))
>> return -EINVAL;
>> @@ -605,7 +644,7 @@ static void dummy_sysfs_dev_release(struct device *dev)
>> *
>> * Return the pointer of extcon device if success or ERR_PTR(err) if fail
>> */
>> -struct extcon_dev *extcon_dev_allocate(const char **supported_cable)
>> +struct extcon_dev *extcon_dev_allocate(const enum extcon *supported_cable)
>
> I think you also have to update the documentation. At least for
> {devm}_extcon_dev_allocate but maybe in other places too. Previously
> the documentation states that supported_cable is an array of strings.
> Additionally AFAIU now it must end with EXTCON_NONE. This
> sentinel-like info must be clearly documented.
OK.
>
>> {
>> struct extcon_dev *edev;
>>
>> @@ -659,7 +698,7 @@ static void devm_extcon_dev_release(struct device *dev, void *res)
>> * or ERR_PTR(err) if fail
>> */
>> struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
>> - const char **supported_cable)
>> + const enum extcon *supported_cable)
>> {
>> struct extcon_dev **ptr, *edev;
>>
>> @@ -709,17 +748,15 @@ int extcon_dev_register(struct extcon_dev *edev)
>> return ret;
>> }
>>
>> - if (edev->supported_cable) {
>> - /* Get size of array */
>> - for (index = 0; edev->supported_cable[index]; index++)
>> - ;
>> - edev->max_supported = index;
>> - } else {
>> - edev->max_supported = 0;
>> - }
>> + if (!edev->supported_cable)
>> + return -EINVAL;
>>
>> + for (; edev->supported_cable[index] != EXTCON_NONE; index++);
>> +
>> + edev->max_supported = index;
>> if (index > SUPPORTED_CABLE_MAX) {
>> - dev_err(&edev->dev, "extcon: maximum number of supported cables exceeded.\n");
>> + dev_err(&edev->dev,
>> + "exceed the maximum number of supported cables\n");
>> return -EINVAL;
>> }
>>
>> @@ -1070,6 +1107,7 @@ static void __exit extcon_class_exit(void)
>> }
>> module_exit(extcon_class_exit);
>>
>> +MODULE_AUTHOR("Chanwoo Choi <[email protected]>");
>> MODULE_AUTHOR("Mike Lockwood <[email protected]>");
>> MODULE_AUTHOR("Donggeun Kim <[email protected]>");
>> MODULE_AUTHOR("MyungJoo Ham <[email protected]>");
>> diff --git a/include/linux/extcon.h b/include/linux/extcon.h
>> index 799474d9d..de158a1 100644
>> --- a/include/linux/extcon.h
>> +++ b/include/linux/extcon.h
>> @@ -1,6 +1,9 @@
>> /*
>> * External connector (extcon) class driver
>> *
>> + * Copyright (C) 2015 Samsung Electronics
>> + * Author: Chanwoo Choi <[email protected]>
>> + *
>> * Copyright (C) 2012 Samsung Electronics
>> * Author: Donggeun Kim <[email protected]>
>> * Author: MyungJoo Ham <[email protected]>
>> @@ -27,8 +30,41 @@
>> #include <linux/notifier.h>
>> #include <linux/sysfs.h>
>>
>> -#define SUPPORTED_CABLE_MAX 32
>> -#define CABLE_NAME_MAX 30
>> +enum extcon {
>> + EXTCON_NONE = 0x0, /* NONE */
>> +
>> + /* USB external connector */
>> + EXTCON_USB = 0x1, /* USB */
>> + EXTCON_USB_HOST = 0x2, /* USB-HOST */
>> +
>> + /* Charger external connector */
>> + EXTCON_TA = 0x10, /* TA */
>> + EXTCON_FAST_CHARGER = 0x11, /* FAST-CHARGER */
>> + EXTCON_SLOW_CHARGER = 0x12, /* SLOW-CHARGER */
>> + EXTCON_CHARGE_DOWNSTREAM= 0x13, /* CHARGE-DOWNSTREAM */
>
> Space before '='. I know it will mess the alignment in indentation but
> it would be still more readable.
OK.
>
>> +
>> + /* Audio/Video external connector */
>> + EXTCON_LINE_IN = 0x20, /* LINE-IN */
>> + EXTCON_LINE_OUT = 0x21, /* LINE-OUT */
>> + EXTCON_MICROPHONE = 0x22, /* MICROPHONE */
>> + EXTCON_HEADPHONE = 0x23, /* HEADPHONE */
>> +
>> + EXTCON_HDMI = 0x30, /* HDMI */
>> + EXTCON_MHL = 0x31, /* MHL */
>> + EXTCON_DVI = 0x32, /* DVI */
>> + EXTCON_VGA = 0x33, /* VGA */
>> + EXTCON_SPDIF_IN = 0x34, /* SPDIF-IN */
>> + EXTCON_SPDIF_OUT = 0x35, /* SPDIF-OUT */
>> + EXTCON_VIDEO_IN = 0x36, /* VIDEO-IN */
>> + EXTCON_VIDEO_OUT = 0x37, /* VIDEO-OUT */
>> +
>> + /* Etc external connector */
>> + EXTCON_DOCK = 0x50, /* DOCK */
>> + EXTCON_JIG = 0x51, /* JIG */
>> + EXTCON_MECHANICAL = 0x52, /* MECHANICAL */
>> +
>
> There is no benefit of each comment here. The comment just duplicates
> name, it does not give any additional information. Get rid of it.
OK.
>
>> + __EXTCON_END,
>
> Why "__" prefix?
This variable should be used in extcon core. So, I just add '__' prefix.
But, It is not clear. I'll define it without '__' prefix.
>
>> +};
>>
>> /*
>> * The standard cable name is to help support general notifier
>> @@ -48,29 +84,6 @@
>> * you don't need such convention. This convention is helpful when
>> * notifier can distinguish but notifiee cannot.
>> */
>
> Isn't the comment above related to the enum "extcon_cable_name" which
> you are removing?
OK. I'll modify the upper comment.
Thanks,
Chanwoo Choi
On Sun, May 17, 2015 at 4:41 PM, Krzysztof Kozlowski
<[email protected]> wrote:
> 2015-05-15 23:31 GMT+09:00 Chanwoo Choi <[email protected]>:
>> Previously, extcon consumer driver used the extcon_register_interest()
>> to register the notifier chain and then to receive the notifier event
>> when external connector's state is changed. When registering the notifier chain
>> for specific external connector with extcon_register_interest(), it used the
>> the string name of external connector directly. There are potential problem
>> because of unclear, non-standard and inconsequent cable name. Namely,
>> it is not appropriate method to identify each external connector.
>>
>> So, this patch modify the prototype of extcon_register_notifier() by using
>> the 'enum extcon' which are the unique id for each external connector
>> instead of unclear string method.
>>
>> - Previously, the extcon consumer driver used the extcon_register_interest()
>> with 'cable_name' to point out the specific external connector. Also. it used
>> the un-needed structure (struct extcon_specific_cable_nb).
>> : int extcon_register_interest(struct extcon_specific_cable_nb *obj,
>> const char *extcon_name, const char *cable_name,
>> struct notifier_block *nb)
>>
>> - Newly, the updated extcon_register_notifier() would definitely support
>> the same feature to detech the changed state of external connector without
>> any specific structure (struct extcon_specific_cable_nb).
>> : int extcon_register_notifier(struct extcon_dev *edev, enum extcon id,
>> struct notifier_block *nb)
>>
>> This patch support the both extcon_register_interest() and new extcon_register_
>> notifier(). But the extcon_{register|unregister}_interest() will be deprecated
>> because extcon core would support the notifier event for extcon consumer driver
>> with only updated extcon_register_notifier() and 'extcon_specific_cable_nb'
>> will be removed if there are no extcon consumer driver with legacy
>> extcon_{register|unregister}_interest().
>>
>> Signed-off-by: Chanwoo Choi <[email protected]>
>> Cc: MyungJoo Ham <[email protected]>
>> Cc: George Cherian <[email protected]>
>> Cc: Felipe Balbi <[email protected]>
>> Cc: Aaro Koskinen <[email protected]>
>> ---
>> drivers/extcon/extcon.c | 91 ++++++++++++++++++++++++++-----------------------
>> include/linux/extcon.h | 17 +++++----
>> 2 files changed, 56 insertions(+), 52 deletions(-)
>>
>> diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c
>> index 4aeb585..14c8c95 100644
>> --- a/drivers/extcon/extcon.c
>> +++ b/drivers/extcon/extcon.c
>> @@ -111,6 +111,16 @@ static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state)
>> return 0;
>> }
>>
>> +static bool is_extcon_changed(u32 prev, u32 new, int idx, bool *attached)
>> +{
>> + if (((prev >> idx) & 0x1) != ((new >> idx) & 0x1)) {
>
> How about switching "state" to unsigned long and using bit operations
> everywhere, like test_bit()?
As I replied on other patch, I'm having the plan to extend the number
of supported external connectors of each extcon device. I'll consider
to use the test_bit() on next time for updating extcon core.
>
> The patch itself looks good and change above is not actually related
> to the code here, so:
> Reviewed-by: Krzysztof Kozlowski <[email protected]>
Thanks,
Chanwoo Choi
[email protected]
Mail bounces.
2015-05-17 16:53 GMT+09:00 Chanwoo Choi <[email protected]>:
> Hi Krzysztof,
>
> On Sun, May 17, 2015 at 4:10 PM, Krzysztof Kozlowski
>>> @@ -32,36 +35,43 @@
>>> #include <linux/slab.h>
>>> #include <linux/sysfs.h>
>>>
>>> -/*
>>> - * extcon_cable_name suggests the standard cable names for commonly used
>>> - * cable types.
>>> - *
>>> - * However, please do not use extcon_cable_name directly for extcon_dev
>>> - * struct's supported_cable pointer unless your device really supports
>>> - * every single port-type of the following cable names. Please choose cable
>>> - * names that are actually used in your extcon device.
>>> - */
>>> -const char extcon_cable_name[][CABLE_NAME_MAX + 1] = {
>>> +#define SUPPORTED_CABLE_MAX 32
>>
>> Why only 32 cables are supported? I mean what is the reason behind the
>> hard limit?
>
> Current extcon core use the 32bit variable to identify the supported
> external connectors of each extcon device. But, the number of
> supported connectors should be updated. I have the plan about it.
I get it, it is related to 'state' variable which is u32 now.
>
>>
>>> +#define CABLE_NAME_MAX 30
>>> +
>>> +static const char *extcon_name[] = {
>>> + [EXTCON_NONE] = "NONE",
>>> +
>>> + /* USB external connector */
>>> [EXTCON_USB] = "USB",
>>> - [EXTCON_USB_HOST] = "USB-Host",
>>> + [EXTCON_USB_HOST] = "USB-HOST",
>>> +
>>> + /* Charger external connector */
>>> [EXTCON_TA] = "TA",
>>> - [EXTCON_FAST_CHARGER] = "Fast-charger",
>>> - [EXTCON_SLOW_CHARGER] = "Slow-charger",
>>> - [EXTCON_CHARGE_DOWNSTREAM] = "Charge-downstream",
>>> + [EXTCON_FAST_CHARGER] = "FAST-CHARGER",
>>> + [EXTCON_SLOW_CHARGER] = "SLOW-CHARGER",
>>> + [EXTCON_CHARGE_DOWNSTREAM] = "CHARGE-DOWNSTREAM",
>>> +
>>> + /* Audio/Video external connector */
>>> + [EXTCON_LINE_IN] = "LINE-IN",
>>> + [EXTCON_LINE_OUT] = "LINE-OUT",
>>> + [EXTCON_MICROPHONE] = "MICROPHONE",
>>> + [EXTCON_HEADPHONE] = "HEADPHONE",
>>> +
>>> [EXTCON_HDMI] = "HDMI",
>>> [EXTCON_MHL] = "MHL",
>>> [EXTCON_DVI] = "DVI",
>>> [EXTCON_VGA] = "VGA",
>>> - [EXTCON_DOCK] = "Dock",
>>> - [EXTCON_LINE_IN] = "Line-in",
>>> - [EXTCON_LINE_OUT] = "Line-out",
>>> - [EXTCON_MIC_IN] = "Microphone",
>>> - [EXTCON_HEADPHONE_OUT] = "Headphone",
>>> - [EXTCON_SPDIF_IN] = "SPDIF-in",
>>> - [EXTCON_SPDIF_OUT] = "SPDIF-out",
>>> - [EXTCON_VIDEO_IN] = "Video-in",
>>> - [EXTCON_VIDEO_OUT] = "Video-out",
>>> - [EXTCON_MECHANICAL] = "Mechanical",
>>> + [EXTCON_SPDIF_IN] = "SPDIF-IN",
>>> + [EXTCON_SPDIF_OUT] = "SPDIF-OUT",
>>> + [EXTCON_VIDEO_IN] = "VIDEO-IN",
>>> + [EXTCON_VIDEO_OUT] = "VIDEO-OUT",
>>> +
>>> + /* Etc external connector */
>>> + [EXTCON_DOCK] = "DOCK",
>>> + [EXTCON_JIG] = "JIG",
>>> + [EXTCON_MECHANICAL] = "MECHANICAL",
>>> +
>>> + NULL,
>>> };
>>
>> This change does not look related to the topic. Can you split it to
>> separate patch?
>
> Do you mean about changing the name of external connectors from small
> letter to capital letter?
Yes. This should be separate commit.
Best regards,
Krzysztof
Hi Krzysztof,
>>> +
>>> + if (i == edev->max_supported)
>>> + return -EINVAL;
>>>
>>> if (index < 0 || (edev->max_supported && edev->max_supported <= index))
>>> return -EINVAL;
>>> @@ -605,7 +644,7 @@ static void dummy_sysfs_dev_release(struct device *dev)
>>> *
>>> * Return the pointer of extcon device if success or ERR_PTR(err) if fail
>>> */
>>> -struct extcon_dev *extcon_dev_allocate(const char **supported_cable)
>>> +struct extcon_dev *extcon_dev_allocate(const enum extcon *supported_cable)
>>
>> I think you also have to update the documentation. At least for
>> {devm}_extcon_dev_allocate but maybe in other places too. Previously
>> the documentation states that supported_cable is an array of strings.
>> Additionally AFAIU now it must end with EXTCON_NONE. This
>> sentinel-like info must be clearly documented.
As you commented, extcon must need to document the update and usage method of extcon core.
The mainline kernel includes only the 'Documentation/extcon/porting-android-switch-class'.
Namely, the mainline kernel have not included the document showing the usage method of extcon core.
So, I'll make the proper document for extcon core as later job.
Thanks,
Chanwoo Choi
On 19.05.2015 21:28, Chanwoo Choi wrote:
> Hi Krzysztof,
>
>>>> +
>>>> + if (i == edev->max_supported)
>>>> + return -EINVAL;
>>>>
>>>> if (index < 0 || (edev->max_supported && edev->max_supported <= index))
>>>> return -EINVAL;
>>>> @@ -605,7 +644,7 @@ static void dummy_sysfs_dev_release(struct device *dev)
>>>> *
>>>> * Return the pointer of extcon device if success or ERR_PTR(err) if fail
>>>> */
>>>> -struct extcon_dev *extcon_dev_allocate(const char **supported_cable)
>>>> +struct extcon_dev *extcon_dev_allocate(const enum extcon *supported_cable)
>>>
>>> I think you also have to update the documentation. At least for
>>> {devm}_extcon_dev_allocate but maybe in other places too. Previously
>>> the documentation states that supported_cable is an array of strings.
>>> Additionally AFAIU now it must end with EXTCON_NONE. This
>>> sentinel-like info must be clearly documented.
>
> As you commented, extcon must need to document the update and usage method of extcon core.
> The mainline kernel includes only the 'Documentation/extcon/porting-android-switch-class'.
> Namely, the mainline kernel have not included the document showing the usage method of extcon core.
I mean documentation for the function. The kerneldoc above functions says:
* @supported_cable: Array of supported cable names ending with NULL.
* If supported_cable is NULL, cable name related APIs
* are disabled.
AFAIU now the supported cable must end with EXTCON_NONE. Is it correct?
Best regards,
Krzysztof
On 05/20/2015 12:24 PM, Krzysztof Kozlowski wrote:
> On 19.05.2015 21:28, Chanwoo Choi wrote:
>> Hi Krzysztof,
>>
>>>>> +
>>>>> + if (i == edev->max_supported)
>>>>> + return -EINVAL;
>>>>>
>>>>> if (index < 0 || (edev->max_supported && edev->max_supported <= index))
>>>>> return -EINVAL;
>>>>> @@ -605,7 +644,7 @@ static void dummy_sysfs_dev_release(struct device *dev)
>>>>> *
>>>>> * Return the pointer of extcon device if success or ERR_PTR(err) if fail
>>>>> */
>>>>> -struct extcon_dev *extcon_dev_allocate(const char **supported_cable)
>>>>> +struct extcon_dev *extcon_dev_allocate(const enum extcon *supported_cable)
>>>>
>>>> I think you also have to update the documentation. At least for
>>>> {devm}_extcon_dev_allocate but maybe in other places too. Previously
>>>> the documentation states that supported_cable is an array of strings.
>>>> Additionally AFAIU now it must end with EXTCON_NONE. This
>>>> sentinel-like info must be clearly documented.
>>
>> As you commented, extcon must need to document the update and usage method of extcon core.
>> The mainline kernel includes only the 'Documentation/extcon/porting-android-switch-class'.
>> Namely, the mainline kernel have not included the document showing the usage method of extcon core.
>
> I mean documentation for the function. The kerneldoc above functions says:
>
> * @supported_cable: Array of supported cable names ending with NULL.
> * If supported_cable is NULL, cable name related APIs
> * are disabled.
Ah. I misunderstand on previous mail. I'll fix upper description.
>
> AFAIU now the supported cable must end with EXTCON_NONE. Is it correct?
Right.
Thanks,
Chanwoo Choi