extcon: Use the unique id for external connector instead of string

This patch uses the unique id to identify the type of external connector instead
of string name. The string name have the many potential issues. So, this patch
defines the 'extcon' enumeration which includes all supported external connector
on EXTCON subsystem. If new external connector is necessary, the unique id of
new connector have to be added in 'extcon' enumeration. There are current
supported external connector in 'enum extcon' as following:

enum extcon {
	EXTCON_NONE		= 0x0,

	/* USB external connector */
	EXTCON_USB		= 0x1,
	EXTCON_USB_HOST		= 0x2,

	/* Charger external connector */
	EXTCON_TA		= 0x10,
	EXTCON_FAST_CHARGER	= 0x11,
	EXTCON_SLOW_CHARGER	= 0x12,
	EXTCON_CHARGE_DOWNSTREAM = 0x13,

	/* Audio and video external connector */
	EXTCON_LINE_IN		= 0x20,
	EXTCON_LINE_OUT		= 0x21,
	EXTCON_MICROPHONE	= 0x22,
	EXTCON_HEADPHONE	= 0x23,

	EXTCON_HDMI		= 0x30,
	EXTCON_MHL		= 0x31,
	EXTCON_DVI		= 0x32,
	EXTCON_VGA		= 0x33,
	EXTCON_SPDIF_IN		= 0x34,
	EXTCON_SPDIF_OUT	= 0x35,
	EXTCON_VIDEO_IN		= 0x36,
	EXTCON_VIDEO_OUT	= 0x37,

	/* Miscellaneous external connector */
	EXTCON_DOCK		= 0x50,
	EXTCON_JIG		= 0x51,
	EXTCON_MECHANICAL	= 0x52,

	EXTCON_END,
};

For example in extcon-arizona.c:
To use unique id removes the potential issue about handling
the inconsistent name of external connector with string.
- Previously, use the string to register the type of arizona jack connector
static const char *arizona_cable[] = {
	"Mechanical",
	"Microphone",
	"Headphone",
	"Line-out",
};
- Newly, use the unique id to register the type of arizona jack connector
static const enum extcon arizona_cable[] = {
	EXTCON_MECHANICAL,
	EXTCON_MICROPHONE,
	EXTCON_HEADPHONE,
	EXTCON_LINE_OUT,

	EXTCON_NONE,
};

And this patch modify the prototype of extcon_{get|set}_cable_state_() which
uses the 'enum extcon id' instead of 'cable_index'. Because although one more
extcon drivers support USB cable, each extcon driver might has the differnt
'cable_index' for USB cable. All extcon drivers can use the unique id number
for same external connector with modified extcon_{get|set}_cable_state_().

- Previously, use 'cable_index' on these functions:
extcon_get_cable_state_(struct extcon_dev*, int cable_index)
extcon_set_cable_state_(struct extcon_dev*, int cable_index, bool state)

-Newly, use 'enum extcon id' on these functions:
extcon_get_cable_state_(struct extcon_dev*, enum extcon id)
extcon_set_cable_state_(struct extcon_dev*, enum extcon id, bool state)

Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Felipe Balbi <balbi@ti.com>
Signed-off-by: Chanwoo Choi <cw00.choi@samsung.com>
Acked-by: Roger Quadros <rogerq@ti.com>
Acked-by: Charles Keepax <ckeepax@opensource.wolfsonmicro.com>
Acked-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
Reviewed-by: Krzysztof Kozlowski <k.kozlowski@samsung.com>
[arnd: Report the build break about drivers/usb/phy/phy-tahvo.c after using the
unique id for external connector insteadf of string]
Reported-by: Arnd Bergmann <arnd@arndb.de>
[dan.carpenter: Report the build warning of extcon_{set|get}_cable_state_()]
Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
This commit is contained in:
Chanwoo Choi 2015-04-24 19:16:05 +09:00
Родитель 35eed7a076
Коммит 2a9de9c0f0
14 изменённых файлов: 320 добавлений и 411 удалений

Просмотреть файл

@ -118,17 +118,12 @@ static const int arizona_micd_levels[] = {
1257, 1257,
}; };
#define ARIZONA_CABLE_MECHANICAL 0 static const enum extcon arizona_cable[] = {
#define ARIZONA_CABLE_MICROPHONE 1 EXTCON_MECHANICAL,
#define ARIZONA_CABLE_HEADPHONE 2 EXTCON_MICROPHONE,
#define ARIZONA_CABLE_LINEOUT 3 EXTCON_HEADPHONE,
EXTCON_LINE_OUT,
static const char *arizona_cable[] = { EXTCON_NONE,
"Mechanical",
"Microphone",
"Headphone",
"Line-out",
NULL,
}; };
static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info); 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_extcon_info *info = data;
struct arizona *arizona = info->arizona; struct arizona *arizona = info->arizona;
int id_gpio = arizona->pdata.hpdet_id_gpio; int id_gpio = arizona->pdata.hpdet_id_gpio;
int report = ARIZONA_CABLE_HEADPHONE; enum extcon report = EXTCON_HEADPHONE;
int ret, reading; int ret, reading;
bool mic = false; 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 */ /* 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) { if (ret < 0) {
dev_err(arizona->dev, "Failed to check cable state: %d\n", dev_err(arizona->dev, "Failed to check cable state: %d\n",
ret); ret);
@ -602,9 +597,9 @@ static irqreturn_t arizona_hpdet_irq(int irq, void *data)
/* Report high impedence cables as line outputs */ /* Report high impedence cables as line outputs */
if (reading >= 5000) if (reading >= 5000)
report = ARIZONA_CABLE_LINEOUT; report = EXTCON_LINE_OUT;
else else
report = ARIZONA_CABLE_HEADPHONE; report = EXTCON_HEADPHONE;
ret = extcon_set_cable_state_(info->edev, report, true); ret = extcon_set_cable_state_(info->edev, report, true);
if (ret != 0) if (ret != 0)
@ -689,8 +684,7 @@ err:
ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC); ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
/* Just report headphone */ /* Just report headphone */
ret = extcon_set_cable_state_(info->edev, ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true);
ARIZONA_CABLE_HEADPHONE, true);
if (ret != 0) if (ret != 0)
dev_err(arizona->dev, "Failed to report headphone: %d\n", ret); dev_err(arizona->dev, "Failed to report headphone: %d\n", ret);
@ -747,8 +741,7 @@ err:
ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC); ARIZONA_ACCDET_MODE_MASK, ARIZONA_ACCDET_MODE_MIC);
/* Just report headphone */ /* Just report headphone */
ret = extcon_set_cable_state_(info->edev, ret = extcon_set_cable_state_(info->edev, EXTCON_HEADPHONE, true);
ARIZONA_CABLE_HEADPHONE, true);
if (ret != 0) if (ret != 0)
dev_err(arizona->dev, "Failed to report headphone: %d\n", ret); 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); mutex_lock(&info->lock);
/* If the cable was removed while measuring ignore the result */ /* 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) { if (ret < 0) {
dev_err(arizona->dev, "Failed to check cable state: %d\n", dev_err(arizona->dev, "Failed to check cable state: %d\n",
ret); ret);
@ -836,8 +829,7 @@ static void arizona_micd_detect(struct work_struct *work)
arizona_identify_headphone(info); arizona_identify_headphone(info);
ret = extcon_set_cable_state_(info->edev, ret = extcon_set_cable_state_(info->edev,
ARIZONA_CABLE_MICROPHONE, true); EXTCON_MICROPHONE, true);
if (ret != 0) if (ret != 0)
dev_err(arizona->dev, "Headset report failed: %d\n", dev_err(arizona->dev, "Headset report failed: %d\n",
ret); ret);
@ -1028,7 +1020,7 @@ static irqreturn_t arizona_jackdet(int irq, void *data)
if (info->last_jackdet == present) { if (info->last_jackdet == present) {
dev_dbg(arizona->dev, "Detected jack\n"); dev_dbg(arizona->dev, "Detected jack\n");
ret = extcon_set_cable_state_(info->edev, ret = extcon_set_cable_state_(info->edev,
ARIZONA_CABLE_MECHANICAL, true); EXTCON_MECHANICAL, true);
if (ret != 0) if (ret != 0)
dev_err(arizona->dev, "Mechanical report failed: %d\n", dev_err(arizona->dev, "Mechanical report failed: %d\n",

Просмотреть файл

@ -77,10 +77,6 @@
/* IRQ enable-6 register */ /* IRQ enable-6 register */
#define BC12_IRQ_CFG_MASK BIT(1) #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 { enum axp288_extcon_reg {
AXP288_PS_STAT_REG = 0x00, AXP288_PS_STAT_REG = 0x00,
AXP288_PS_BOOT_REASON_REG = 0x02, AXP288_PS_BOOT_REASON_REG = 0x02,
@ -105,11 +101,11 @@ enum axp288_extcon_irq {
EXTCON_IRQ_END, EXTCON_IRQ_END,
}; };
static const char *axp288_extcon_cables[] = { static const enum extcon axp288_extcon_cables[] = {
AXP288_EXTCON_SLOW_CHARGER, EXTCON_SLOW_CHARGER,
AXP288_EXTCON_DOWNSTREAM_CHARGER, EXTCON_CHARGE_DOWNSTREAM,
AXP288_EXTCON_FAST_CHARGER, EXTCON_FAST_CHARGER,
NULL, EXTCON_NONE,
}; };
struct axp288_extcon_info { 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 int axp288_handle_chrg_det_event(struct axp288_extcon_info *info)
{ {
static bool notify_otg, notify_charger; static bool notify_otg, notify_charger;
static char *cable; static enum extcon cable;
int ret, stat, cfg, pwr_stat; int ret, stat, cfg, pwr_stat;
u8 chrg_type; u8 chrg_type;
bool vbus_attach = false; 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"); dev_dbg(info->dev, "sdp cable is connecetd\n");
notify_otg = true; notify_otg = true;
notify_charger = true; notify_charger = true;
cable = AXP288_EXTCON_SLOW_CHARGER; cable = EXTCON_SLOW_CHARGER;
break; break;
case DET_STAT_CDP: case DET_STAT_CDP:
dev_dbg(info->dev, "cdp cable is connecetd\n"); dev_dbg(info->dev, "cdp cable is connecetd\n");
notify_otg = true; notify_otg = true;
notify_charger = true; notify_charger = true;
cable = AXP288_EXTCON_DOWNSTREAM_CHARGER; cable = EXTCON_CHARGE_DOWNSTREAM;
break; break;
case DET_STAT_DCP: case DET_STAT_DCP:
dev_dbg(info->dev, "dcp cable is connecetd\n"); dev_dbg(info->dev, "dcp cable is connecetd\n");
notify_charger = true; notify_charger = true;
cable = AXP288_EXTCON_FAST_CHARGER; cable = EXTCON_FAST_CHARGER;
break; break;
default: default:
dev_warn(info->dev, dev_warn(info->dev,
@ -230,7 +226,7 @@ notify_otg:
} }
if (notify_charger) 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 */ /* Clear the flags on disconnect event */
if (!vbus_attach) if (!vbus_attach)

Просмотреть файл

@ -148,27 +148,14 @@ enum max14577_muic_acc_type {
MAX14577_MUIC_ADC_OPEN, MAX14577_MUIC_ADC_OPEN,
}; };
/* max14577 MUIC device support below list of accessories(external connector) */ static const enum extcon max14577_extcon_cable[] = {
enum { EXTCON_USB,
EXTCON_CABLE_USB = 0, EXTCON_TA,
EXTCON_CABLE_TA, EXTCON_FAST_CHARGER,
EXTCON_CABLE_FAST_CHARGER, EXTCON_SLOW_CHARGER,
EXTCON_CABLE_SLOW_CHARGER, EXTCON_CHARGE_DOWNSTREAM,
EXTCON_CABLE_CHARGE_DOWNSTREAM, EXTCON_JIG,
EXTCON_CABLE_JIG, EXTCON_NONE,
_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,
}; };
/* /*
@ -369,7 +356,7 @@ static int max14577_muic_jig_handler(struct max14577_muic_info *info,
if (ret < 0) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "JIG", attached); extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
return 0; return 0;
} }
@ -466,20 +453,22 @@ static int max14577_muic_chg_handler(struct max14577_muic_info *info)
if (ret < 0) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "USB", attached); extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
break; break;
case MAX14577_CHARGER_TYPE_DEDICATED_CHG: case MAX14577_CHARGER_TYPE_DEDICATED_CHG:
extcon_set_cable_state(info->edev, "TA", attached); extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
break; break;
case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT: case MAX14577_CHARGER_TYPE_DOWNSTREAM_PORT:
extcon_set_cable_state(info->edev, extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM,
"Charge-downstream", attached); attached);
break; break;
case MAX14577_CHARGER_TYPE_SPECIAL_500MA: 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; break;
case MAX14577_CHARGER_TYPE_SPECIAL_1A: 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; break;
case MAX14577_CHARGER_TYPE_NONE: case MAX14577_CHARGER_TYPE_NONE:
case MAX14577_CHARGER_TYPE_DEAD_BATTERY: case MAX14577_CHARGER_TYPE_DEAD_BATTERY:

Просмотреть файл

@ -200,32 +200,17 @@ enum max77693_muic_acc_type {
/* /*
* MAX77693 MUIC device support below list of accessories(external connector) * MAX77693 MUIC device support below list of accessories(external connector)
*/ */
enum { static const enum extcon max77693_extcon_cable[] = {
EXTCON_CABLE_USB = 0, EXTCON_USB,
EXTCON_CABLE_USB_HOST, EXTCON_USB_HOST,
EXTCON_CABLE_TA, EXTCON_TA,
EXTCON_CABLE_FAST_CHARGER, EXTCON_FAST_CHARGER,
EXTCON_CABLE_SLOW_CHARGER, EXTCON_SLOW_CHARGER,
EXTCON_CABLE_CHARGE_DOWNSTREAM, EXTCON_CHARGE_DOWNSTREAM,
EXTCON_CABLE_MHL, EXTCON_MHL,
EXTCON_CABLE_JIG, EXTCON_JIG,
EXTCON_CABLE_DOCK, EXTCON_DOCK,
EXTCON_NONE,
_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,
}; };
/* /*
@ -472,7 +457,7 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info,
int ret = 0; int ret = 0;
int vbvolt; int vbvolt;
bool cable_attached; bool cable_attached;
char dock_name[CABLE_NAME_MAX]; enum extcon dock_id;
dev_info(info->dev, dev_info(info->dev,
"external connector is %s (adc:0x%02x)\n", "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) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "DOCK", attached); extcon_set_cable_state_(info->edev, EXTCON_DOCK, attached);
extcon_set_cable_state(info->edev, "MHL", attached); extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
goto out; goto out;
case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk */ case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk */
strcpy(dock_name, "DOCK"); dock_id = EXTCON_DOCK;
break; break;
case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */ case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */
strcpy(dock_name, "DOCK"); dock_id = EXTCON_DOCK;
if (!attached) if (!attached)
extcon_set_cable_state(info->edev, "USB", false); extcon_set_cable_state_(info->edev, EXTCON_USB, false);
break; break;
default: default:
dev_err(info->dev, "failed to detect %s dock device\n", 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); ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached);
if (ret < 0) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, dock_name, attached); extcon_set_cable_state_(info->edev, dock_id, attached);
out: out:
return 0; 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); ret = max77693_muic_set_path(info, CONTROL1_SW_USB, attached);
if (ret < 0) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "USB-Host", attached); extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached);
break; break;
case MAX77693_MUIC_GND_AV_CABLE_LOAD: case MAX77693_MUIC_GND_AV_CABLE_LOAD:
/* Audio Video Cable with load, PATH:AUDIO */ /* Audio Video Cable with load, PATH:AUDIO */
ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached); ret = max77693_muic_set_path(info, CONTROL1_SW_AUDIO, attached);
if (ret < 0) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
"Audio-video-load", attached);
break; break;
case MAX77693_MUIC_GND_MHL: case MAX77693_MUIC_GND_MHL:
case MAX77693_MUIC_GND_MHL_VB: case MAX77693_MUIC_GND_MHL_VB:
/* MHL or MHL with USB/TA cable */ /* 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; break;
default: default:
dev_err(info->dev, "failed to detect %s cable of gnd type\n", 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) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "JIG", attached); extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
return 0; return 0;
} }
@ -812,10 +796,10 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
* - Support charging through micro-usb port without * - Support charging through micro-usb port without
* data connection * data connection
*/ */
extcon_set_cable_state(info->edev, "TA", attached); extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
if (!cable_attached) if (!cable_attached)
extcon_set_cable_state(info->edev, extcon_set_cable_state_(info->edev, EXTCON_MHL,
"MHL", cable_attached); cable_attached);
break; break;
} }
@ -838,11 +822,12 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
* - Support charging through micro-usb port without * - Support charging through micro-usb port without
* data connection. * data connection.
*/ */
extcon_set_cable_state(info->edev, "USB", attached); extcon_set_cable_state_(info->edev, EXTCON_USB,
attached);
if (!cable_attached) if (!cable_attached)
extcon_set_cable_state(info->edev, "DOCK", extcon_set_cable_state_(info->edev, EXTCON_DOCK,
cable_attached); cable_attached);
break; break;
case MAX77693_MUIC_ADC_RESERVED_ACC_3: /* Dock-Smart */ 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) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "DOCK", attached); extcon_set_cable_state_(info->edev, EXTCON_DOCK,
extcon_set_cable_state(info->edev, "MHL", attached); attached);
extcon_set_cable_state_(info->edev, EXTCON_MHL,
attached);
break; break;
} }
@ -905,23 +891,26 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info)
if (ret < 0) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "USB", attached); extcon_set_cable_state_(info->edev, EXTCON_USB,
attached);
break; break;
case MAX77693_CHARGER_TYPE_DEDICATED_CHG: case MAX77693_CHARGER_TYPE_DEDICATED_CHG:
/* Only TA cable */ /* Only TA cable */
extcon_set_cable_state(info->edev, "TA", attached); extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
break; break;
} }
break; break;
case MAX77693_CHARGER_TYPE_DOWNSTREAM_PORT: case MAX77693_CHARGER_TYPE_DOWNSTREAM_PORT:
extcon_set_cable_state(info->edev, extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM,
"Charge-downstream", attached); attached);
break; break;
case MAX77693_CHARGER_TYPE_APPLE_500MA: 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; break;
case MAX77693_CHARGER_TYPE_APPLE_1A_2A: 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; break;
case MAX77693_CHARGER_TYPE_DEAD_BATTERY: case MAX77693_CHARGER_TYPE_DEAD_BATTERY:
break; break;

Просмотреть файл

@ -118,28 +118,16 @@ enum max77843_muic_charger_type {
MAX77843_MUIC_CHG_GND, MAX77843_MUIC_CHG_GND,
}; };
enum { static const enum extcon max77843_extcon_cable[] = {
MAX77843_CABLE_USB = 0, EXTCON_USB,
MAX77843_CABLE_USB_HOST, EXTCON_USB_HOST,
MAX77843_CABLE_TA, EXTCON_TA,
MAX77843_CABLE_CHARGE_DOWNSTREAM, EXTCON_CHARGE_DOWNSTREAM,
MAX77843_CABLE_FAST_CHARGER, EXTCON_FAST_CHARGER,
MAX77843_CABLE_SLOW_CHARGER, EXTCON_SLOW_CHARGER,
MAX77843_CABLE_MHL, EXTCON_MHL,
MAX77843_CABLE_JIG, EXTCON_JIG,
EXTCON_NONE,
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",
}; };
struct max77843_muic_irq { struct max77843_muic_irq {
@ -354,7 +342,7 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info)
if (ret < 0) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "USB-HOST", attached); extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached);
break; break;
case MAX77843_MUIC_GND_MHL_VB: case MAX77843_MUIC_GND_MHL_VB:
case MAX77843_MUIC_GND_MHL: case MAX77843_MUIC_GND_MHL:
@ -362,7 +350,7 @@ static int max77843_muic_adc_gnd_handler(struct max77843_muic_info *info)
if (ret < 0) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "MHL", attached); extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
break; break;
default: default:
dev_err(info->dev, "failed to detect %s accessory(gnd:0x%x)\n", 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) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "JIG", attached); extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
return 0; return 0;
} }
@ -490,36 +478,38 @@ static int max77843_muic_chg_handler(struct max77843_muic_info *info)
if (ret < 0) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "USB", attached); extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
break; break;
case MAX77843_MUIC_CHG_DOWNSTREAM: case MAX77843_MUIC_CHG_DOWNSTREAM:
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached);
if (ret < 0) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM,
"CHARGER-DOWNSTREAM", attached); attached);
break; break;
case MAX77843_MUIC_CHG_DEDICATED: case MAX77843_MUIC_CHG_DEDICATED:
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached);
if (ret < 0) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "TA", attached); extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
break; break;
case MAX77843_MUIC_CHG_SPECIAL_500MA: case MAX77843_MUIC_CHG_SPECIAL_500MA:
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached);
if (ret < 0) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "SLOW-CHAREGER", attached); extcon_set_cable_state_(info->edev, EXTCON_SLOW_CHARGER,
attached);
break; break;
case MAX77843_MUIC_CHG_SPECIAL_1A: case MAX77843_MUIC_CHG_SPECIAL_1A:
ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached);
if (ret < 0) if (ret < 0)
return ret; return ret;
extcon_set_cable_state(info->edev, "FAST-CHARGER", attached); extcon_set_cable_state_(info->edev, EXTCON_FAST_CHARGER,
attached);
break; break;
case MAX77843_MUIC_CHG_GND: case MAX77843_MUIC_CHG_GND:
gnd_type = max77843_muic_get_cable_type(info, 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 */ /* Charger cable on MHL accessory is attach or detach */
if (gnd_type == MAX77843_MUIC_GND_MHL_VB) 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) 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; break;
case MAX77843_MUIC_CHG_NONE: case MAX77843_MUIC_CHG_NONE:
break; break;

Просмотреть файл

@ -145,32 +145,17 @@ struct max8997_muic_info {
int path_uart; int path_uart;
}; };
enum { static const enum extcon max8997_extcon_cable[] = {
EXTCON_CABLE_USB = 0, EXTCON_USB,
EXTCON_CABLE_USB_HOST, EXTCON_USB_HOST,
EXTCON_CABLE_TA, EXTCON_TA,
EXTCON_CABLE_FAST_CHARGER, EXTCON_FAST_CHARGER,
EXTCON_CABLE_SLOW_CHARGER, EXTCON_SLOW_CHARGER,
EXTCON_CABLE_CHARGE_DOWNSTREAM, EXTCON_CHARGE_DOWNSTREAM,
EXTCON_CABLE_MHL, EXTCON_MHL,
EXTCON_CABLE_DOCK, EXTCON_DOCK,
EXTCON_CABLE_JIG, EXTCON_JIG,
EXTCON_NONE,
_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,
}; };
/* /*
@ -345,10 +330,10 @@ static int max8997_muic_handle_usb(struct max8997_muic_info *info,
switch (usb_type) { switch (usb_type) {
case MAX8997_USB_HOST: case MAX8997_USB_HOST:
extcon_set_cable_state(info->edev, "USB-Host", attached); extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, attached);
break; break;
case MAX8997_USB_DEVICE: case MAX8997_USB_DEVICE:
extcon_set_cable_state(info->edev, "USB", attached); extcon_set_cable_state_(info->edev, EXTCON_USB, attached);
break; break;
default: default:
dev_err(info->dev, "failed to detect %s usb cable\n", 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) { switch (cable_type) {
case MAX8997_MUIC_ADC_AV_CABLE_NOLOAD: case MAX8997_MUIC_ADC_AV_CABLE_NOLOAD:
case MAX8997_MUIC_ADC_FACTORY_MODE_UART_ON: 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; break;
default: default:
dev_err(info->dev, "failed to detect %s dock device\n", 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; return ret;
} }
extcon_set_cable_state(info->edev, "JIG", attached); extcon_set_cable_state_(info->edev, EXTCON_JIG, attached);
return 0; return 0;
} }
@ -418,7 +403,7 @@ static int max8997_muic_adc_handler(struct max8997_muic_info *info)
return ret; return ret;
break; break;
case MAX8997_MUIC_ADC_MHL: case MAX8997_MUIC_ADC_MHL:
extcon_set_cable_state(info->edev, "MHL", attached); extcon_set_cable_state_(info->edev, EXTCON_MHL, attached);
break; break;
case MAX8997_MUIC_ADC_FACTORY_MODE_USB_OFF: case MAX8997_MUIC_ADC_FACTORY_MODE_USB_OFF:
case MAX8997_MUIC_ADC_FACTORY_MODE_USB_ON: case MAX8997_MUIC_ADC_FACTORY_MODE_USB_ON:
@ -501,17 +486,19 @@ static int max8997_muic_chg_handler(struct max8997_muic_info *info)
} }
break; break;
case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT: case MAX8997_CHARGER_TYPE_DOWNSTREAM_PORT:
extcon_set_cable_state(info->edev, extcon_set_cable_state_(info->edev, EXTCON_CHARGE_DOWNSTREAM,
"Charge-downstream", attached); attached);
break; break;
case MAX8997_CHARGER_TYPE_DEDICATED_CHG: case MAX8997_CHARGER_TYPE_DEDICATED_CHG:
extcon_set_cable_state(info->edev, "TA", attached); extcon_set_cable_state_(info->edev, EXTCON_TA, attached);
break; break;
case MAX8997_CHARGER_TYPE_500MA: 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; break;
case MAX8997_CHARGER_TYPE_1A: 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; break;
default: default:
dev_err(info->dev, dev_err(info->dev,

Просмотреть файл

@ -29,10 +29,10 @@
#include <linux/of.h> #include <linux/of.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
static const char *palmas_extcon_cable[] = { static const enum extcon palmas_extcon_cable[] = {
[0] = "USB", EXTCON_USB,
[1] = "USB-HOST", EXTCON_USB_HOST,
NULL, EXTCON_NONE,
}; };
static const int mutually_exclusive[] = {0x3, 0x0}; 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) static irqreturn_t palmas_vbus_irq_handler(int irq, void *_palmas_usb)
{ {
struct palmas_usb *palmas_usb = _palmas_usb; struct palmas_usb *palmas_usb = _palmas_usb;
struct extcon_dev *edev = palmas_usb->edev;
unsigned int vbus_line_state; unsigned int vbus_line_state;
palmas_read(palmas_usb->palmas, PALMAS_INTERRUPT_BASE, 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 (vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS) {
if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) { if (palmas_usb->linkstat != PALMAS_USB_STATE_VBUS) {
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"); dev_info(palmas_usb->dev, "USB cable is attached\n");
} else { } else {
dev_dbg(palmas_usb->dev, 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)) { } else if (!(vbus_line_state & PALMAS_INT3_LINE_STATE_VBUS)) {
if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) { if (palmas_usb->linkstat == PALMAS_USB_STATE_VBUS) {
palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; 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"); dev_info(palmas_usb->dev, "USB cable is detached\n");
} else { } else {
dev_dbg(palmas_usb->dev, 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; unsigned int set, id_src;
struct palmas_usb *palmas_usb = _palmas_usb; struct palmas_usb *palmas_usb = _palmas_usb;
struct extcon_dev *edev = palmas_usb->edev;
palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE, palmas_read(palmas_usb->palmas, PALMAS_USB_OTG_BASE,
PALMAS_USB_ID_INT_LATCH_SET, &set); 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_LATCH_CLR,
PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND); PALMAS_USB_ID_INT_EN_HI_CLR_ID_GND);
palmas_usb->linkstat = PALMAS_USB_STATE_ID; 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"); dev_info(palmas_usb->dev, "USB-HOST cable is attached\n");
} else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) && } else if ((set & PALMAS_USB_ID_INT_SRC_ID_FLOAT) &&
(id_src & 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_LATCH_CLR,
PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT); PALMAS_USB_ID_INT_EN_HI_CLR_ID_FLOAT);
palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; 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"); dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) && } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_ID) &&
(!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) { (!(set & PALMAS_USB_ID_INT_SRC_ID_GND))) {
palmas_usb->linkstat = PALMAS_USB_STATE_DISCONNECT; 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"); dev_info(palmas_usb->dev, "USB-HOST cable is detached\n");
} else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) && } else if ((palmas_usb->linkstat == PALMAS_USB_STATE_DISCONNECT) &&
(id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) { (id_src & PALMAS_USB_ID_INT_SRC_ID_GND)) {
palmas_usb->linkstat = PALMAS_USB_STATE_ID; 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"); dev_info(palmas_usb->dev, " USB-HOST cable is attached\n");
} }

Просмотреть файл

@ -90,21 +90,12 @@ static struct reg_data rt8973a_reg_data[] = {
}; };
/* List of detectable cables */ /* List of detectable cables */
enum { static const enum extcon rt8973a_extcon_cable[] = {
EXTCON_CABLE_USB = 0, EXTCON_USB,
EXTCON_CABLE_USB_HOST, EXTCON_USB_HOST,
EXTCON_CABLE_TA, EXTCON_TA,
EXTCON_CABLE_JIG, EXTCON_JIG,
EXTCON_NONE,
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,
}; };
/* Define OVP (Over Voltage Protection), OTP (Over Temperature Protection) */ /* 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) enum rt8973a_event_type event)
{ {
static unsigned int prev_cable_type; static unsigned int prev_cable_type;
const char **cable_names = info->edev->supported_cable;
unsigned int con_sw = DM_DP_SWITCH_UART; unsigned int con_sw = DM_DP_SWITCH_UART;
int ret, idx = 0, cable_type; int ret, cable_type;
enum extcon id;
bool attached = false; bool attached = false;
if (!cable_names)
return 0;
switch (event) { switch (event) {
case RT8973A_EVENT_ATTACH: case RT8973A_EVENT_ATTACH:
cable_type = rt8973a_muic_get_cable_type(info); 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) { switch (cable_type) {
case RT8973A_MUIC_ADC_OTG: case RT8973A_MUIC_ADC_OTG:
idx = EXTCON_CABLE_USB_HOST; id = EXTCON_USB_HOST;
con_sw = DM_DP_SWITCH_USB; con_sw = DM_DP_SWITCH_USB;
break; break;
case RT8973A_MUIC_ADC_TA: case RT8973A_MUIC_ADC_TA:
idx = EXTCON_CABLE_TA; id = EXTCON_TA;
con_sw = DM_DP_SWITCH_OPEN; con_sw = DM_DP_SWITCH_OPEN;
break; break;
case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB: case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB:
case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB: case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB:
idx = EXTCON_CABLE_JIG; id = EXTCON_JIG;
con_sw = DM_DP_SWITCH_USB; con_sw = DM_DP_SWITCH_USB;
break; break;
case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART: case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART:
case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART: case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART:
idx = EXTCON_CABLE_JIG; id = EXTCON_JIG;
con_sw = DM_DP_SWITCH_UART; con_sw = DM_DP_SWITCH_UART;
break; break;
case RT8973A_MUIC_ADC_USB: case RT8973A_MUIC_ADC_USB:
idx = EXTCON_CABLE_USB; id = EXTCON_USB;
con_sw = DM_DP_SWITCH_USB; con_sw = DM_DP_SWITCH_USB;
break; break;
case RT8973A_MUIC_ADC_OPEN: case RT8973A_MUIC_ADC_OPEN:
@ -409,7 +397,7 @@ static int rt8973a_muic_cable_handler(struct rt8973a_muic_info *info,
return ret; return ret;
/* Change the state of external accessory */ /* 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; return 0;
} }

Просмотреть файл

@ -92,19 +92,11 @@ static struct reg_data sm5502_reg_data[] = {
}; };
/* List of detectable cables */ /* List of detectable cables */
enum { static const enum extcon sm5502_extcon_cable[] = {
EXTCON_CABLE_USB = 0, EXTCON_USB,
EXTCON_CABLE_USB_HOST, EXTCON_USB_HOST,
EXTCON_CABLE_TA, EXTCON_TA,
EXTCON_NONE,
EXTCON_CABLE_END,
};
static const char *sm5502_extcon_cable[] = {
[EXTCON_CABLE_USB] = "USB",
[EXTCON_CABLE_USB_HOST] = "USB-Host",
[EXTCON_CABLE_TA] = "TA",
NULL,
}; };
/* Define supported accessory type */ /* Define supported accessory type */
@ -377,16 +369,12 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info,
bool attached) bool attached)
{ {
static unsigned int prev_cable_type = SM5502_MUIC_ADC_GROUND; 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 cable_type = SM5502_MUIC_ADC_GROUND;
unsigned int con_sw = DM_DP_SWITCH_OPEN; unsigned int con_sw = DM_DP_SWITCH_OPEN;
unsigned int vbus_sw = VBUSIN_SWITCH_OPEN; unsigned int vbus_sw = VBUSIN_SWITCH_OPEN;
unsigned int idx = 0; enum extcon id;
int ret; int ret;
if (!cable_names)
return 0;
/* Get the type of attached or detached cable */ /* Get the type of attached or detached cable */
if (attached) if (attached)
cable_type = sm5502_muic_get_cable_type(info); 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) { switch (cable_type) {
case SM5502_MUIC_ADC_OPEN_USB: case SM5502_MUIC_ADC_OPEN_USB:
idx = EXTCON_CABLE_USB; id = EXTCON_USB;
con_sw = DM_DP_SWITCH_USB; con_sw = DM_DP_SWITCH_USB;
vbus_sw = VBUSIN_SWITCH_VBUSOUT_WITH_USB; vbus_sw = VBUSIN_SWITCH_VBUSOUT_WITH_USB;
break; break;
case SM5502_MUIC_ADC_OPEN_TA: case SM5502_MUIC_ADC_OPEN_TA:
idx = EXTCON_CABLE_TA; id = EXTCON_TA;
con_sw = DM_DP_SWITCH_OPEN; con_sw = DM_DP_SWITCH_OPEN;
vbus_sw = VBUSIN_SWITCH_VBUSOUT; vbus_sw = VBUSIN_SWITCH_VBUSOUT;
break; break;
case SM5502_MUIC_ADC_OPEN_USB_OTG: case SM5502_MUIC_ADC_OPEN_USB_OTG:
idx = EXTCON_CABLE_USB_HOST; id = EXTCON_USB_HOST;
con_sw = DM_DP_SWITCH_USB; con_sw = DM_DP_SWITCH_USB;
vbus_sw = VBUSIN_SWITCH_OPEN; vbus_sw = VBUSIN_SWITCH_OPEN;
break; break;
@ -422,7 +410,7 @@ static int sm5502_muic_cable_handler(struct sm5502_muic_info *info,
return ret; return ret;
/* Change the state of external accessory */ /* 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; return 0;
} }

Просмотреть файл

@ -39,18 +39,10 @@ struct usb_extcon_info {
struct delayed_work wq_detcable; struct delayed_work wq_detcable;
}; };
/* List of detectable cables */ static const enum extcon usb_extcon_cable[] = {
enum { EXTCON_USB,
EXTCON_CABLE_USB = 0, EXTCON_USB_HOST,
EXTCON_CABLE_USB_HOST, EXTCON_NONE,
EXTCON_CABLE_END,
};
static const char *usb_extcon_cable[] = {
[EXTCON_CABLE_USB] = "USB",
[EXTCON_CABLE_USB_HOST] = "USB-HOST",
NULL,
}; };
static void usb_extcon_detect_cable(struct work_struct *work) 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, * As we don't have event for USB peripheral cable attached,
* we simulate USB peripheral attach here. * we simulate USB peripheral attach here.
*/ */
extcon_set_cable_state(info->edev, extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, false);
usb_extcon_cable[EXTCON_CABLE_USB_HOST], extcon_set_cable_state_(info->edev, EXTCON_USB, true);
false);
extcon_set_cable_state(info->edev,
usb_extcon_cable[EXTCON_CABLE_USB],
true);
} else { } else {
/* /*
* ID = 0 means USB HOST cable attached. * ID = 0 means USB HOST cable attached.
* As we don't have event for USB peripheral cable detached, * As we don't have event for USB peripheral cable detached,
* we simulate USB peripheral detach here. * we simulate USB peripheral detach here.
*/ */
extcon_set_cable_state(info->edev, extcon_set_cable_state_(info->edev, EXTCON_USB, false);
usb_extcon_cable[EXTCON_CABLE_USB], extcon_set_cable_state_(info->edev, EXTCON_USB_HOST, true);
false);
extcon_set_cable_state(info->edev,
usb_extcon_cable[EXTCON_CABLE_USB_HOST],
true);
} }
} }

Просмотреть файл

@ -3,6 +3,9 @@
* *
* External connector (extcon) class driver * External connector (extcon) class driver
* *
* Copyright (C) 2015 Samsung Electronics
* Author: Chanwoo Choi <cw00.choi@samsung.com>
*
* Copyright (C) 2012 Samsung Electronics * Copyright (C) 2012 Samsung Electronics
* Author: Donggeun Kim <dg77.kim@samsung.com> * Author: Donggeun Kim <dg77.kim@samsung.com>
* Author: MyungJoo Ham <myungjoo.ham@samsung.com> * Author: MyungJoo Ham <myungjoo.ham@samsung.com>
@ -32,36 +35,32 @@
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
/* #define SUPPORTED_CABLE_MAX 32
* extcon_cable_name suggests the standard cable names for commonly used #define CABLE_NAME_MAX 30
* cable types.
* static const char *extcon_name[] = {
* 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] = {
[EXTCON_USB] = "USB", [EXTCON_USB] = "USB",
[EXTCON_USB_HOST] = "USB-Host", [EXTCON_USB_HOST] = "USB-Host",
[EXTCON_TA] = "TA", [EXTCON_TA] = "TA",
[EXTCON_FAST_CHARGER] = "Fast-charger", [EXTCON_FAST_CHARGER] = "Fast-charger",
[EXTCON_SLOW_CHARGER] = "Slow-charger", [EXTCON_SLOW_CHARGER] = "Slow-charger",
[EXTCON_CHARGE_DOWNSTREAM] = "Charge-downstream", [EXTCON_CHARGE_DOWNSTREAM] = "Charge-downstream",
[EXTCON_LINE_IN] = "Line-in",
[EXTCON_LINE_OUT] = "Line-out",
[EXTCON_MICROPHONE] = "Microphone",
[EXTCON_HEADPHONE] = "Headphone",
[EXTCON_HDMI] = "HDMI", [EXTCON_HDMI] = "HDMI",
[EXTCON_MHL] = "MHL", [EXTCON_MHL] = "MHL",
[EXTCON_DVI] = "DVI", [EXTCON_DVI] = "DVI",
[EXTCON_VGA] = "VGA", [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_IN] = "SPDIF-in",
[EXTCON_SPDIF_OUT] = "SPDIF-out", [EXTCON_SPDIF_OUT] = "SPDIF-out",
[EXTCON_VIDEO_IN] = "Video-in", [EXTCON_VIDEO_IN] = "Video-in",
[EXTCON_VIDEO_OUT] = "Video-out", [EXTCON_VIDEO_OUT] = "Video-out",
[EXTCON_DOCK] = "Dock",
[EXTCON_JIG] = "JIG",
[EXTCON_MECHANICAL] = "Mechanical", [EXTCON_MECHANICAL] = "Mechanical",
NULL,
}; };
static struct class *extcon_class; static struct class *extcon_class;
@ -101,6 +100,43 @@ static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state)
return 0; return 0;
} }
static int find_cable_index_by_id(struct extcon_dev *edev, const enum extcon id)
{
int i;
/* 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;
}
static int find_cable_index_by_name(struct extcon_dev *edev, const char *name)
{
enum extcon id = EXTCON_NONE;
int 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], name, CABLE_NAME_MAX)) {
id = i;
break;
}
}
if (id == EXTCON_NONE)
return -EINVAL;
return find_cable_index_by_id(edev, id);
}
static ssize_t state_show(struct device *dev, struct device_attribute *attr, static ssize_t state_show(struct device *dev, struct device_attribute *attr,
char *buf) char *buf)
{ {
@ -118,11 +154,9 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr,
if (edev->max_supported == 0) if (edev->max_supported == 0)
return sprintf(buf, "%u\n", edev->state); return sprintf(buf, "%u\n", edev->state);
for (i = 0; i < SUPPORTED_CABLE_MAX; i++) { for (i = 0; i < edev->max_supported; i++) {
if (!edev->supported_cable[i])
break;
count += sprintf(buf + count, "%s=%d\n", count += sprintf(buf + count, "%s=%d\n",
edev->supported_cable[i], extcon_name[edev->supported_cable[i]],
!!(edev->state & (1 << i))); !!(edev->state & (1 << i)));
} }
@ -171,9 +205,10 @@ static ssize_t cable_name_show(struct device *dev,
{ {
struct extcon_cable *cable = container_of(attr, struct extcon_cable, struct extcon_cable *cable = container_of(attr, struct extcon_cable,
attr_name); attr_name);
int i = cable->cable_index;
return sprintf(buf, "%s\n", 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, static ssize_t cable_state_show(struct device *dev,
@ -282,40 +317,20 @@ int extcon_set_state(struct extcon_dev *edev, u32 state)
} }
EXPORT_SYMBOL_GPL(extcon_set_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)
{
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;
}
}
return -EINVAL;
}
EXPORT_SYMBOL_GPL(extcon_find_cable_index);
/** /**
* extcon_get_cable_state_() - Get the status of a specific cable. * extcon_get_cable_state_() - Get the status of a specific cable.
* @edev: the extcon device that has the 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)
{ {
if (index < 0 || (edev->max_supported && edev->max_supported <= index)) int index;
index = find_cable_index_by_id(edev, id);
if (index < 0)
return index;
if (edev->max_supported && edev->max_supported <= index)
return -EINVAL; return -EINVAL;
return !!(edev->state & (1 << index)); return !!(edev->state & (1 << index));
@ -331,7 +346,7 @@ EXPORT_SYMBOL_GPL(extcon_get_cable_state_);
*/ */
int extcon_get_cable_state(struct extcon_dev *edev, const char *cable_name) int extcon_get_cable_state(struct extcon_dev *edev, const char *cable_name)
{ {
return extcon_get_cable_state_(edev, extcon_find_cable_index return extcon_get_cable_state_(edev, find_cable_index_by_name
(edev, cable_name)); (edev, cable_name));
} }
EXPORT_SYMBOL_GPL(extcon_get_cable_state); EXPORT_SYMBOL_GPL(extcon_get_cable_state);
@ -339,17 +354,22 @@ EXPORT_SYMBOL_GPL(extcon_get_cable_state);
/** /**
* extcon_set_cable_state_() - Set the status of a specific cable. * extcon_set_cable_state_() - Set the status of a specific cable.
* @edev: the extcon device that has the cable. * @edev: the extcon device that has the cable.
* @index: cable index that can be retrieved by * @id: the unique id of each external connector
* extcon_find_cable_index(). * in extcon enumeration.
* @cable_state: the new cable status. The default semantics is * @state: the new cable status. The default semantics is
* true: attached / false: detached. * true: attached / false: detached.
*/ */
int extcon_set_cable_state_(struct extcon_dev *edev, int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id,
int index, bool cable_state) bool cable_state)
{ {
u32 state; u32 state;
int index;
if (index < 0 || (edev->max_supported && edev->max_supported <= index)) index = find_cable_index_by_id(edev, id);
if (index < 0)
return index;
if (edev->max_supported && edev->max_supported <= index)
return -EINVAL; return -EINVAL;
state = cable_state ? (1 << index) : 0; state = cable_state ? (1 << index) : 0;
@ -369,7 +389,7 @@ EXPORT_SYMBOL_GPL(extcon_set_cable_state_);
int extcon_set_cable_state(struct extcon_dev *edev, int extcon_set_cable_state(struct extcon_dev *edev,
const char *cable_name, bool cable_state) const char *cable_name, bool cable_state)
{ {
return extcon_set_cable_state_(edev, extcon_find_cable_index return extcon_set_cable_state_(edev, find_cable_index_by_name
(edev, cable_name), cable_state); (edev, cable_name), cable_state);
} }
EXPORT_SYMBOL_GPL(extcon_set_cable_state); EXPORT_SYMBOL_GPL(extcon_set_cable_state);
@ -455,8 +475,8 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj,
if (!obj->edev) if (!obj->edev)
return -ENODEV; return -ENODEV;
obj->cable_index = extcon_find_cable_index(obj->edev, obj->cable_index = find_cable_index_by_name(obj->edev,
cable_name); cable_name);
if (obj->cable_index < 0) if (obj->cable_index < 0)
return obj->cable_index; return obj->cable_index;
@ -479,7 +499,7 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj,
while ((dev = class_dev_iter_next(&iter))) { while ((dev = class_dev_iter_next(&iter))) {
extd = dev_get_drvdata(dev); extd = dev_get_drvdata(dev);
if (extcon_find_cable_index(extd, cable_name) < 0) if (find_cable_index_by_name(extd, cable_name) < 0)
continue; continue;
class_dev_iter_exit(&iter); class_dev_iter_exit(&iter);
@ -595,7 +615,7 @@ static void dummy_sysfs_dev_release(struct device *dev)
/* /*
* extcon_dev_allocate() - Allocate the memory of extcon device. * extcon_dev_allocate() - Allocate the memory of extcon device.
* @supported_cable: Array of supported cable names ending with NULL. * @supported_cable: Array of supported extcon ending with EXTCON_NONE.
* If supported_cable is NULL, cable name related APIs * If supported_cable is NULL, cable name related APIs
* are disabled. * are disabled.
* *
@ -605,7 +625,7 @@ static void dummy_sysfs_dev_release(struct device *dev)
* *
* Return the pointer of extcon device if success or ERR_PTR(err) if fail * 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; struct extcon_dev *edev;
@ -647,7 +667,7 @@ static void devm_extcon_dev_release(struct device *dev, void *res)
/** /**
* devm_extcon_dev_allocate - Allocate managed extcon device * devm_extcon_dev_allocate - Allocate managed extcon device
* @dev: device owning the extcon device being created * @dev: device owning the extcon device being created
* @supported_cable: Array of supported cable names ending with NULL. * @supported_cable: Array of supported extcon ending with EXTCON_NONE.
* If supported_cable is NULL, cable name related APIs * If supported_cable is NULL, cable name related APIs
* are disabled. * are disabled.
* *
@ -659,7 +679,7 @@ static void devm_extcon_dev_release(struct device *dev, void *res)
* or ERR_PTR(err) if fail * or ERR_PTR(err) if fail
*/ */
struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
const char **supported_cable) const enum extcon *supported_cable)
{ {
struct extcon_dev **ptr, *edev; struct extcon_dev **ptr, *edev;
@ -709,17 +729,15 @@ int extcon_dev_register(struct extcon_dev *edev)
return ret; return ret;
} }
if (edev->supported_cable) { if (!edev->supported_cable)
/* Get size of array */ return -EINVAL;
for (index = 0; edev->supported_cable[index]; index++)
;
edev->max_supported = index;
} else {
edev->max_supported = 0;
}
for (; edev->supported_cable[index] != EXTCON_NONE; index++);
edev->max_supported = index;
if (index > SUPPORTED_CABLE_MAX) { 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; return -EINVAL;
} }
@ -1070,6 +1088,7 @@ static void __exit extcon_class_exit(void)
} }
module_exit(extcon_class_exit); module_exit(extcon_class_exit);
MODULE_AUTHOR("Chanwoo Choi <cw00.choi@samsung.com>");
MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>"); MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>");
MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>"); MODULE_AUTHOR("Donggeun Kim <dg77.kim@samsung.com>");
MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>"); MODULE_AUTHOR("MyungJoo Ham <myungjoo.ham@samsung.com>");

Просмотреть файл

@ -60,10 +60,11 @@ struct tahvo_usb {
struct extcon_dev extcon; struct extcon_dev extcon;
}; };
static const char *tahvo_cable[] = { static const enum extcon tahvo_cable[] = {
"USB-HOST", EXTCON_USB,
"USB", EXTCON_USB_HOST,
NULL,
EXTCON_NONE,
}; };
static ssize_t vbus_state_show(struct device *device, static ssize_t vbus_state_show(struct device *device,

Просмотреть файл

@ -1,6 +1,9 @@
/* /*
* External connector (extcon) class driver * External connector (extcon) class driver
* *
* Copyright (C) 2015 Samsung Electronics
* Author: Chanwoo Choi <cw00.choi@samsung.com>
*
* Copyright (C) 2012 Samsung Electronics * Copyright (C) 2012 Samsung Electronics
* Author: Donggeun Kim <dg77.kim@samsung.com> * Author: Donggeun Kim <dg77.kim@samsung.com>
* Author: MyungJoo Ham <myungjoo.ham@samsung.com> * Author: MyungJoo Ham <myungjoo.ham@samsung.com>
@ -27,50 +30,41 @@
#include <linux/notifier.h> #include <linux/notifier.h>
#include <linux/sysfs.h> #include <linux/sysfs.h>
#define SUPPORTED_CABLE_MAX 32 enum extcon {
#define CABLE_NAME_MAX 30 EXTCON_NONE = 0x0,
/* /* USB external connector */
* The standard cable name is to help support general notifier EXTCON_USB = 0x1,
* and notifiee device drivers to share the common names. EXTCON_USB_HOST = 0x2,
* Please use standard cable names unless your notifier device has
* a very unique and abnormal cable or /* Charger external connector */
* the cable type is supposed to be used with only one unique EXTCON_TA = 0x10,
* pair of notifier/notifiee devices. EXTCON_FAST_CHARGER = 0x11,
* EXTCON_SLOW_CHARGER = 0x12,
* Please add any other "standard" cables used with extcon dev. EXTCON_CHARGE_DOWNSTREAM = 0x13,
*
* You may add a dot and number to specify version or specification /* Audio/Video external connector */
* of the specific cable if it is required. (e.g., "Fast-charger.18" EXTCON_LINE_IN = 0x20,
* and "Fast-charger.10" for 1.8A and 1.0A chargers) EXTCON_LINE_OUT = 0x21,
* However, the notifiee and notifier should be able to handle such EXTCON_MICROPHONE = 0x22,
* string and if the notifiee can negotiate the protocol or identify, EXTCON_HEADPHONE = 0x23,
* you don't need such convention. This convention is helpful when
* notifier can distinguish but notifiee cannot. EXTCON_HDMI = 0x30,
*/ EXTCON_MHL = 0x31,
enum extcon_cable_name { EXTCON_DVI = 0x32,
EXTCON_USB = 0, EXTCON_VGA = 0x33,
EXTCON_USB_HOST, EXTCON_SPDIF_IN = 0x34,
EXTCON_TA, /* Travel Adaptor */ EXTCON_SPDIF_OUT = 0x35,
EXTCON_FAST_CHARGER, EXTCON_VIDEO_IN = 0x36,
EXTCON_SLOW_CHARGER, EXTCON_VIDEO_OUT = 0x37,
EXTCON_CHARGE_DOWNSTREAM, /* Charging an external device */
EXTCON_HDMI, /* Etc external connector */
EXTCON_MHL, EXTCON_DOCK = 0x50,
EXTCON_DVI, EXTCON_JIG = 0x51,
EXTCON_VGA, EXTCON_MECHANICAL = 0x52,
EXTCON_DOCK,
EXTCON_LINE_IN, EXTCON_END,
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; struct extcon_cable;
@ -78,7 +72,7 @@ struct extcon_cable;
* struct extcon_dev - An extcon device represents one external connector. * struct extcon_dev - An extcon device represents one external connector.
* @name: The name of this extcon device. Parent device name is * @name: The name of this extcon device. Parent device name is
* used if NULL. * used if NULL.
* @supported_cable: Array of supported cable names ending with NULL. * @supported_cable: Array of supported cable names ending with EXTCON_NONE.
* If supported_cable is NULL, cable name related APIs * If supported_cable is NULL, cable name related APIs
* are disabled. * are disabled.
* @mutually_exclusive: Array of mutually exclusive set of cables that cannot * @mutually_exclusive: Array of mutually exclusive set of cables that cannot
@ -113,7 +107,7 @@ struct extcon_cable;
struct extcon_dev { struct extcon_dev {
/* Optional user initializing data */ /* Optional user initializing data */
const char *name; const char *name;
const char **supported_cable; const enum extcon *supported_cable;
const u32 *mutually_exclusive; const u32 *mutually_exclusive;
/* Optional callbacks to override class functions */ /* Optional callbacks to override class functions */
@ -194,10 +188,10 @@ extern struct extcon_dev *extcon_get_extcon_dev(const char *extcon_name);
/* /*
* Following APIs control the memory of extcon device. * 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 void extcon_dev_free(struct extcon_dev *edev);
extern struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, 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); extern void devm_extcon_dev_free(struct device *dev, struct extcon_dev *edev);
/* /*
@ -216,13 +210,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. * 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 * 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
*/ */
extern int extcon_find_cable_index(struct extcon_dev *sdev, extern int extcon_get_cable_state_(struct extcon_dev *edev, enum extcon id);
const char *cable_name); extern int extcon_set_cable_state_(struct extcon_dev *edev, enum extcon id,
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,
bool cable_state); bool cable_state);
extern int extcon_get_cable_state(struct extcon_dev *edev, extern int extcon_get_cable_state(struct extcon_dev *edev,
@ -281,7 +272,7 @@ static inline int devm_extcon_dev_register(struct device *dev,
static inline void devm_extcon_dev_unregister(struct device *dev, static inline void devm_extcon_dev_unregister(struct device *dev,
struct extcon_dev *edev) { } 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); return ERR_PTR(-ENOSYS);
} }
@ -289,7 +280,7 @@ static inline struct extcon_dev *extcon_dev_allocate(const char **cables)
static inline void extcon_dev_free(struct extcon_dev *edev) { } static inline void extcon_dev_free(struct extcon_dev *edev) { }
static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, static inline struct extcon_dev *devm_extcon_dev_allocate(struct device *dev,
const char **cables) const enum extcon *cable)
{ {
return ERR_PTR(-ENOSYS); return ERR_PTR(-ENOSYS);
} }
@ -312,20 +303,14 @@ static inline int extcon_update_state(struct extcon_dev *edev, u32 mask,
return 0; 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, static inline int extcon_get_cable_state_(struct extcon_dev *edev,
int cable_index) enum extcon id)
{ {
return 0; return 0;
} }
static inline int extcon_set_cable_state_(struct extcon_dev *edev, 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; return 0;
} }

Просмотреть файл

@ -44,7 +44,7 @@ struct adc_jack_cond {
* @consumer_channel: Unique name to identify the channel on the consumer * @consumer_channel: Unique name to identify the channel on the consumer
* side. This typically describes the channels used within * side. This typically describes the channels used within
* the consumer. E.g. 'battery_voltage' * 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 * @adc_contitions: array of struct adc_jack_cond conditions ending
* with .state = 0 entry. This describes how to decode * with .state = 0 entry. This describes how to decode
* adc values into extcon state. * adc values into extcon state.
@ -58,8 +58,7 @@ struct adc_jack_pdata {
const char *name; const char *name;
const char *consumer_channel; const char *consumer_channel;
/* The last entry should be NULL */ const enum extcon *cable_names;
const char **cable_names;
/* The last entry's state should be 0 */ /* The last entry's state should be 0 */
struct adc_jack_cond *adc_conditions; struct adc_jack_cond *adc_conditions;