From ed2c0604ace93a2c9b8fc055ab61fff68704cd1e Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 3 Apr 2015 09:51:26 +0900 Subject: [PATCH 01/21] extcon: Add manufactor name of each extcon device This patch adds the manufactor name of each extcon device and removes un-necessary comment in Kconfig. Signed-off-by: Chanwoo Choi --- drivers/extcon/Kconfig | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index fdc0bf0543ce..bd10b6c6962d 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig @@ -36,7 +36,7 @@ config EXTCON_GPIO extcon supports single state per extcon instance. config EXTCON_MAX14577 - tristate "MAX14577/77836 EXTCON Support" + tristate "Maxim MAX14577/77836 EXTCON Support" depends on MFD_MAX14577 select IRQ_DOMAIN select REGMAP_I2C @@ -46,7 +46,7 @@ config EXTCON_MAX14577 detector and switch. config EXTCON_MAX77693 - tristate "MAX77693 EXTCON Support" + tristate "Maxim MAX77693 EXTCON Support" depends on MFD_MAX77693 && INPUT select IRQ_DOMAIN select REGMAP_I2C @@ -56,7 +56,7 @@ config EXTCON_MAX77693 detector and switch. config EXTCON_MAX77843 - tristate "MAX77843 EXTCON Support" + tristate "Maxim MAX77843 EXTCON Support" depends on MFD_MAX77843 select IRQ_DOMAIN select REGMAP_I2C @@ -66,7 +66,7 @@ config EXTCON_MAX77843 detector add switch. config EXTCON_MAX8997 - tristate "MAX8997 EXTCON Support" + tristate "Maxim MAX8997 EXTCON Support" depends on MFD_MAX8997 && IRQ_DOMAIN help If you say yes here you get support for the MUIC device of @@ -81,7 +81,7 @@ config EXTCON_PALMAS detection by palmas usb. config EXTCON_RT8973A - tristate "RT8973A EXTCON support" + tristate "Richtek RT8973A EXTCON support" depends on I2C select IRQ_DOMAIN select REGMAP_I2C @@ -93,7 +93,7 @@ config EXTCON_RT8973A from abnormal high input voltage (up to 28V). config EXTCON_SM5502 - tristate "SM5502 EXTCON support" + tristate "Silicon Mitus SM5502 EXTCON support" depends on I2C select IRQ_DOMAIN select REGMAP_I2C @@ -110,4 +110,4 @@ config EXTCON_USB_GPIO Say Y here to enable GPIO based USB cable detection extcon support. Used typically if GPIO is used for USB ID pin detection. -endif # MULTISTATE_SWITCH +endif From d0fd5fbc09b17e26408f7e3db22511b57f6bf22e Mon Sep 17 00:00:00 2001 From: Richard Fitzgerald Date: Tue, 28 Apr 2015 13:34:27 +0100 Subject: [PATCH 02/21] extcon: arizona: Rename hpdet_ip to make its purpose clearer Renamed to hpdet_ip_version to make it clearer what it does and that the value in it is simply a version number. Signed-off-by: Richard Fitzgerald Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-arizona.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c index a0ed35b336e4..830c5f94bc18 100644 --- a/drivers/extcon/extcon-arizona.c +++ b/drivers/extcon/extcon-arizona.c @@ -94,7 +94,7 @@ struct arizona_extcon_info { bool detecting; int jack_flips; - int hpdet_ip; + int hpdet_ip_version; struct extcon_dev *edev; }; @@ -380,7 +380,7 @@ static int arizona_hpdet_read(struct arizona_extcon_info *info) return ret; } - switch (info->hpdet_ip) { + switch (info->hpdet_ip_version) { case 0: if (!(val & ARIZONA_HP_DONE)) { dev_err(arizona->dev, "HPDET did not complete: %x\n", @@ -441,7 +441,7 @@ static int arizona_hpdet_read(struct arizona_extcon_info *info) default: dev_warn(arizona->dev, "Unknown HPDET IP revision %d\n", - info->hpdet_ip); + info->hpdet_ip_version); case 2: if (!(val & ARIZONA_HP_DONE_B)) { dev_err(arizona->dev, "HPDET did not complete: %x\n", @@ -1161,7 +1161,7 @@ static int arizona_extcon_probe(struct platform_device *pdev) break; default: info->micd_clamp = true; - info->hpdet_ip = 1; + info->hpdet_ip_version = 1; break; } break; @@ -1172,7 +1172,7 @@ static int arizona_extcon_probe(struct platform_device *pdev) break; default: info->micd_clamp = true; - info->hpdet_ip = 2; + info->hpdet_ip_version = 2; break; } break; From f03123783d4e43cd59df58e23e963136e04f8280 Mon Sep 17 00:00:00 2001 From: Ramakrishna Pallala Date: Thu, 30 Apr 2015 20:44:45 +0530 Subject: [PATCH 03/21] extcon: axp288: Add axp288 extcon driver support This patch adds the extcon support for AXP288 PMIC which has the BC1.2 charger detection capability. Additionally it also adds the USB mux switching support b/w SOC and PMIC based on GPIO control. Signed-off-by: Ramakrishna Pallala Acked-by: Lee Jones [cw00.choi: Modify the log message to keep the consistent log message pattern] Signed-off-by: Chanwoo Choi --- drivers/extcon/Kconfig | 7 + drivers/extcon/Makefile | 1 + drivers/extcon/extcon-axp288.c | 385 +++++++++++++++++++++++++++++++++ include/linux/mfd/axp20x.h | 5 + 4 files changed, 398 insertions(+) create mode 100644 drivers/extcon/extcon-axp288.c diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index bd10b6c6962d..b74e1f27688b 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig @@ -28,6 +28,13 @@ config EXTCON_ARIZONA with Wolfson Arizona devices. These are audio CODECs with advanced audio accessory detection support. +config EXTCON_AXP288 + tristate "X-Power AXP288 EXTCON support" + depends on MFD_AXP20X && USB_PHY + help + Say Y here to enable support for USB peripheral detection + and USB MUX switching by X-Power AXP288 PMIC. + config EXTCON_GPIO tristate "GPIO extcon support" depends on GPIOLIB diff --git a/drivers/extcon/Makefile b/drivers/extcon/Makefile index 9204114791a3..ba787d04295b 100644 --- a/drivers/extcon/Makefile +++ b/drivers/extcon/Makefile @@ -5,6 +5,7 @@ obj-$(CONFIG_EXTCON) += extcon.o obj-$(CONFIG_EXTCON_ADC_JACK) += extcon-adc-jack.o obj-$(CONFIG_EXTCON_ARIZONA) += extcon-arizona.o +obj-$(CONFIG_EXTCON_AXP288) += extcon-axp288.o obj-$(CONFIG_EXTCON_GPIO) += extcon-gpio.o obj-$(CONFIG_EXTCON_MAX14577) += extcon-max14577.o obj-$(CONFIG_EXTCON_MAX77693) += extcon-max77693.o diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c new file mode 100644 index 000000000000..8299adb9b676 --- /dev/null +++ b/drivers/extcon/extcon-axp288.c @@ -0,0 +1,385 @@ +/* + * extcon-axp288.c - X-Power AXP288 PMIC extcon cable detection driver + * + * Copyright (C) 2015 Intel Corporation + * Author: Ramakrishna Pallala + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Power source status register */ +#define PS_STAT_VBUS_TRIGGER BIT(0) +#define PS_STAT_BAT_CHRG_DIR BIT(2) +#define PS_STAT_VBUS_ABOVE_VHOLD BIT(3) +#define PS_STAT_VBUS_VALID BIT(4) +#define PS_STAT_VBUS_PRESENT BIT(5) + +/* BC module global register */ +#define BC_GLOBAL_RUN BIT(0) +#define BC_GLOBAL_DET_STAT BIT(2) +#define BC_GLOBAL_DBP_TOUT BIT(3) +#define BC_GLOBAL_VLGC_COM_SEL BIT(4) +#define BC_GLOBAL_DCD_TOUT_MASK (BIT(6)|BIT(5)) +#define BC_GLOBAL_DCD_TOUT_300MS 0 +#define BC_GLOBAL_DCD_TOUT_100MS 1 +#define BC_GLOBAL_DCD_TOUT_500MS 2 +#define BC_GLOBAL_DCD_TOUT_900MS 3 +#define BC_GLOBAL_DCD_DET_SEL BIT(7) + +/* BC module vbus control and status register */ +#define VBUS_CNTL_DPDM_PD_EN BIT(4) +#define VBUS_CNTL_DPDM_FD_EN BIT(5) +#define VBUS_CNTL_FIRST_PO_STAT BIT(6) + +/* BC USB status register */ +#define USB_STAT_BUS_STAT_MASK (BIT(3)|BIT(2)|BIT(1)|BIT(0)) +#define USB_STAT_BUS_STAT_SHIFT 0 +#define USB_STAT_BUS_STAT_ATHD 0 +#define USB_STAT_BUS_STAT_CONN 1 +#define USB_STAT_BUS_STAT_SUSP 2 +#define USB_STAT_BUS_STAT_CONF 3 +#define USB_STAT_USB_SS_MODE BIT(4) +#define USB_STAT_DEAD_BAT_DET BIT(6) +#define USB_STAT_DBP_UNCFG BIT(7) + +/* BC detect status register */ +#define DET_STAT_MASK (BIT(7)|BIT(6)|BIT(5)) +#define DET_STAT_SHIFT 5 +#define DET_STAT_SDP 1 +#define DET_STAT_CDP 2 +#define DET_STAT_DCP 3 + +/* IRQ enable-1 register */ +#define PWRSRC_IRQ_CFG_MASK (BIT(4)|BIT(3)|BIT(2)) + +/* 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, + AXP288_BC_GLOBAL_REG = 0x2c, + AXP288_BC_VBUS_CNTL_REG = 0x2d, + AXP288_BC_USB_STAT_REG = 0x2e, + AXP288_BC_DET_STAT_REG = 0x2f, + AXP288_PWRSRC_IRQ_CFG_REG = 0x40, + AXP288_BC12_IRQ_CFG_REG = 0x45, +}; + +enum axp288_mux_select { + EXTCON_GPIO_MUX_SEL_PMIC = 0, + EXTCON_GPIO_MUX_SEL_SOC, +}; + +enum axp288_extcon_irq { + VBUS_FALLING_IRQ = 0, + VBUS_RISING_IRQ, + MV_CHNG_IRQ, + BC_USB_CHNG_IRQ, + EXTCON_IRQ_END, +}; + +static const char *axp288_extcon_cables[] = { + AXP288_EXTCON_SLOW_CHARGER, + AXP288_EXTCON_DOWNSTREAM_CHARGER, + AXP288_EXTCON_FAST_CHARGER, + NULL, +}; + +struct axp288_extcon_info { + struct device *dev; + struct regmap *regmap; + struct regmap_irq_chip_data *regmap_irqc; + struct axp288_extcon_pdata *pdata; + int irq[EXTCON_IRQ_END]; + struct extcon_dev *edev; + struct notifier_block extcon_nb; + struct usb_phy *otg; +}; + +/* Power up/down reason string array */ +static char *axp288_pwr_up_down_info[] = { + "Last wake caused by user pressing the power button", + "Last wake caused by a charger insertion", + "Last wake caused by a battery insertion", + "Last wake caused by SOC initiated global reset", + "Last wake caused by cold reset", + "Last shutdown caused by PMIC UVLO threshold", + "Last shutdown caused by SOC initiated cold off", + "Last shutdown caused by user pressing the power button", + NULL, +}; + +/* + * Decode and log the given "reset source indicator" (rsi) + * register and then clear it. + */ +static void axp288_extcon_log_rsi(struct axp288_extcon_info *info) +{ + char **rsi; + unsigned int val, i, clear_mask = 0; + int ret; + + ret = regmap_read(info->regmap, AXP288_PS_BOOT_REASON_REG, &val); + for (i = 0, rsi = axp288_pwr_up_down_info; *rsi; rsi++, i++) { + if (val & BIT(i)) { + dev_dbg(info->dev, "%s\n", *rsi); + clear_mask |= BIT(i); + } + } + + /* Clear the register value for next reboot (write 1 to clear bit) */ + regmap_write(info->regmap, AXP288_PS_BOOT_REASON_REG, clear_mask); +} + +static int axp288_handle_chrg_det_event(struct axp288_extcon_info *info) +{ + static bool notify_otg, notify_charger; + static char *cable; + int ret, stat, cfg, pwr_stat; + u8 chrg_type; + bool vbus_attach = false; + + ret = regmap_read(info->regmap, AXP288_PS_STAT_REG, &pwr_stat); + if (ret < 0) { + dev_err(info->dev, "failed to read vbus status\n"); + return ret; + } + + vbus_attach = (pwr_stat & PS_STAT_VBUS_PRESENT); + if (!vbus_attach) + goto notify_otg; + + /* Check charger detection completion status */ + ret = regmap_read(info->regmap, AXP288_BC_GLOBAL_REG, &cfg); + if (ret < 0) + goto dev_det_ret; + if (cfg & BC_GLOBAL_DET_STAT) { + dev_dbg(info->dev, "can't complete the charger detection\n"); + goto dev_det_ret; + } + + ret = regmap_read(info->regmap, AXP288_BC_DET_STAT_REG, &stat); + if (ret < 0) + goto dev_det_ret; + + chrg_type = (stat & DET_STAT_MASK) >> DET_STAT_SHIFT; + + switch (chrg_type) { + case DET_STAT_SDP: + dev_dbg(info->dev, "sdp cable is connecetd\n"); + notify_otg = true; + notify_charger = true; + cable = AXP288_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; + break; + case DET_STAT_DCP: + dev_dbg(info->dev, "dcp cable is connecetd\n"); + notify_charger = true; + cable = AXP288_EXTCON_FAST_CHARGER; + break; + default: + dev_warn(info->dev, + "disconnect or unknown or ID event\n"); + } + +notify_otg: + if (notify_otg) { + /* + * If VBUS is absent Connect D+/D- lines to PMIC for BC + * detection. Else connect them to SOC for USB communication. + */ + if (info->pdata->gpio_mux_cntl) + gpiod_set_value(info->pdata->gpio_mux_cntl, + vbus_attach ? EXTCON_GPIO_MUX_SEL_SOC + : EXTCON_GPIO_MUX_SEL_PMIC); + + atomic_notifier_call_chain(&info->otg->notifier, + vbus_attach ? USB_EVENT_VBUS : USB_EVENT_NONE, NULL); + } + + if (notify_charger) + extcon_set_cable_state(info->edev, cable, vbus_attach); + + /* Clear the flags on disconnect event */ + if (!vbus_attach) + notify_otg = notify_charger = false; + + return 0; + +dev_det_ret: + if (ret < 0) + dev_err(info->dev, "failed to detect BC Mod\n"); + + return ret; +} + +static irqreturn_t axp288_extcon_isr(int irq, void *data) +{ + struct axp288_extcon_info *info = data; + int ret; + + ret = axp288_handle_chrg_det_event(info); + if (ret < 0) + dev_err(info->dev, "failed to handle the interrupt\n"); + + return IRQ_HANDLED; +} + +static void axp288_extcon_enable_irq(struct axp288_extcon_info *info) +{ + /* Unmask VBUS interrupt */ + regmap_write(info->regmap, AXP288_PWRSRC_IRQ_CFG_REG, + PWRSRC_IRQ_CFG_MASK); + regmap_update_bits(info->regmap, AXP288_BC_GLOBAL_REG, + BC_GLOBAL_RUN, 0); + /* Unmask the BC1.2 complete interrupts */ + regmap_write(info->regmap, AXP288_BC12_IRQ_CFG_REG, BC12_IRQ_CFG_MASK); + /* Enable the charger detection logic */ + regmap_update_bits(info->regmap, AXP288_BC_GLOBAL_REG, + BC_GLOBAL_RUN, BC_GLOBAL_RUN); +} + +static int axp288_extcon_probe(struct platform_device *pdev) +{ + struct axp288_extcon_info *info; + struct axp20x_dev *axp20x = dev_get_drvdata(pdev->dev.parent); + int ret, i, pirq, gpio; + + info = devm_kzalloc(&pdev->dev, sizeof(*info), GFP_KERNEL); + if (!info) + return -ENOMEM; + + info->dev = &pdev->dev; + info->regmap = axp20x->regmap; + info->regmap_irqc = axp20x->regmap_irqc; + info->pdata = pdev->dev.platform_data; + + if (!info->pdata) { + /* Try ACPI provided pdata via device properties */ + if (!device_property_present(&pdev->dev, + "axp288_extcon_data\n")) + dev_err(&pdev->dev, "failed to get platform data\n"); + return -ENODEV; + } + platform_set_drvdata(pdev, info); + + axp288_extcon_log_rsi(info); + + /* Initialize extcon device */ + info->edev = devm_extcon_dev_allocate(&pdev->dev, + axp288_extcon_cables); + if (IS_ERR(info->edev)) { + dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); + return PTR_ERR(info->edev); + } + + /* Register extcon device */ + ret = devm_extcon_dev_register(&pdev->dev, info->edev); + if (ret) { + dev_err(&pdev->dev, "failed to register extcon device\n"); + return ret; + } + + /* Get otg transceiver phy */ + info->otg = usb_get_phy(USB_PHY_TYPE_USB2); + if (IS_ERR(info->otg)) { + dev_err(&pdev->dev, "failed to get otg transceiver\n"); + return PTR_ERR(info->otg); + } + + /* Set up gpio control for USB Mux */ + if (info->pdata->gpio_mux_cntl) { + gpio = desc_to_gpio(info->pdata->gpio_mux_cntl); + ret = gpio_request(gpio, "USB_MUX"); + if (ret < 0) { + dev_err(&pdev->dev, + "failed to request the gpio=%d\n", gpio); + goto gpio_req_failed; + } + gpiod_direction_output(info->pdata->gpio_mux_cntl, + EXTCON_GPIO_MUX_SEL_PMIC); + } + + for (i = 0; i < EXTCON_IRQ_END; i++) { + pirq = platform_get_irq(pdev, i); + info->irq[i] = regmap_irq_get_virq(info->regmap_irqc, pirq); + if (info->irq[i] < 0) { + dev_err(&pdev->dev, + "failed to get virtual interrupt=%d\n", pirq); + ret = info->irq[i]; + goto gpio_req_failed; + } + + ret = devm_request_threaded_irq(&pdev->dev, info->irq[i], + NULL, axp288_extcon_isr, + IRQF_ONESHOT | IRQF_NO_SUSPEND, + pdev->name, info); + if (ret) { + dev_err(&pdev->dev, "failed to request interrupt=%d\n", + info->irq[i]); + goto gpio_req_failed; + } + } + + /* Enable interrupts */ + axp288_extcon_enable_irq(info); + + return 0; + +gpio_req_failed: + usb_put_phy(info->otg); + return ret; +} + +static int axp288_extcon_remove(struct platform_device *pdev) +{ + struct axp288_extcon_info *info = platform_get_drvdata(pdev); + + usb_put_phy(info->otg); + return 0; +} + +static struct platform_driver axp288_extcon_driver = { + .probe = axp288_extcon_probe, + .remove = axp288_extcon_remove, + .driver = { + .name = "axp288_extcon", + }, +}; +module_platform_driver(axp288_extcon_driver); + +MODULE_AUTHOR("Ramakrishna Pallala "); +MODULE_DESCRIPTION("X-Powers AXP288 extcon driver"); +MODULE_LICENSE("GPL v2"); diff --git a/include/linux/mfd/axp20x.h b/include/linux/mfd/axp20x.h index dfabd6db7ddf..4ed8071d062e 100644 --- a/include/linux/mfd/axp20x.h +++ b/include/linux/mfd/axp20x.h @@ -275,4 +275,9 @@ struct axp20x_fg_pdata { int thermistor_curve[MAX_THERM_CURVE_SIZE][2]; }; +struct axp288_extcon_pdata { + /* GPIO pin control to switch D+/D- lines b/w PMIC and SOC */ + struct gpio_desc *gpio_mux_cntl; +}; + #endif /* __LINUX_MFD_AXP20X_H */ From 71c3ffa5d23af0554c27010cf12710da9bf85950 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 15 Apr 2015 15:02:01 +0900 Subject: [PATCH 04/21] extcon: Modify the device name as extcon[X] for sysfs This patch modify the device name as extcon[X] for sysfs by using the 'extcon' prefix word instead of separate device name. On user-space aspect, user would find the some extcon drvier with extcon[X] pattern. So, this patch modify the device name as following: - /sys/class/extcon/[device name] -> /sys/class/extcon/extcon[X] Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 4c9f165e4a04..1a932292d6c8 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -163,7 +163,7 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr, return ret; } - return sprintf(buf, "%s\n", dev_name(&edev->dev)); + return sprintf(buf, "%s\n", edev->name); } static DEVICE_ATTR_RO(name); @@ -701,6 +701,7 @@ EXPORT_SYMBOL_GPL(devm_extcon_dev_free); int extcon_dev_register(struct extcon_dev *edev) { int ret, index = 0; + static atomic_t edev_no = ATOMIC_INIT(-1); if (!extcon_class) { ret = create_extcon_class(); @@ -725,13 +726,14 @@ int extcon_dev_register(struct extcon_dev *edev) edev->dev.class = extcon_class; edev->dev.release = extcon_dev_release; - edev->name = edev->name ? edev->name : dev_name(edev->dev.parent); + edev->name = dev_name(edev->dev.parent); if (IS_ERR_OR_NULL(edev->name)) { dev_err(&edev->dev, "extcon device name is null\n"); return -EINVAL; } - dev_set_name(&edev->dev, "%s", edev->name); + dev_set_name(&edev->dev, "extcon%lu", + (unsigned long)atomic_inc_return(&edev_no)); if (edev->max_supported) { char buf[10]; From 707d7550875a9bd245ce5f1077d2d2cb44eab218 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 15 Apr 2015 13:57:51 +0900 Subject: [PATCH 05/21] extcon: Add extcon_get_edev_name() API to get the extcon device name This patch adds the extcon_get_edev_name() API to get the name of extcon device because all information inclued in the structure extcon_dev should be accessed by extcon core API instead of directly accessing the data. Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon.c | 9 +++++++++ include/linux/extcon.h | 4 ++++ 2 files changed, 13 insertions(+) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 1a932292d6c8..c5e9ebf0a914 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -1046,6 +1046,15 @@ struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index) #endif /* CONFIG_OF */ EXPORT_SYMBOL_GPL(extcon_get_edev_by_phandle); +/** + * extcon_get_edev_name() - Get the name of the extcon device. + * @edev: the extcon device + */ +const char *extcon_get_edev_name(struct extcon_dev *edev) +{ + return !edev ? NULL : edev->name; +} + static int __init extcon_class_init(void) { return create_extcon_class(); diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 36f49c405dfb..e2cf6254c86a 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -259,6 +259,10 @@ extern int extcon_unregister_notifier(struct extcon_dev *edev, * This function use phandle of devicetree to get extcon device directly. */ extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index); + +/* Following API to get information of extcon device */ +extern const char *extcon_get_edev_name(struct extcon_dev *edev); + #else /* CONFIG_EXTCON */ static inline int extcon_dev_register(struct extcon_dev *edev) { From b9ec23c08a0274d31ee626f14b359563ea0cae46 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 24 Apr 2015 14:48:52 +0900 Subject: [PATCH 06/21] extcon: Fix the checkpatch warning and minor coding style issue This patch clean up the extcon core driver by fixing the checkpatch warning and minor coding style issue. Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon.c | 10 +++++----- include/linux/extcon.h | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index c5e9ebf0a914..2fb5f757e811 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -1,5 +1,5 @@ /* - * drivers/extcon/extcon_class.c + * drivers/extcon/extcon.c - External Connector (extcon) framework. * * External connector (extcon) class driver * @@ -19,8 +19,7 @@ * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. - * -*/ + */ #include #include @@ -469,7 +468,6 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj, ret = raw_notifier_chain_register(&obj->edev->nh, &obj->internal_nb); spin_unlock_irqrestore(&obj->edev->lock, flags); - return ret; } else { struct class_dev_iter iter; struct extcon_dev *extd; @@ -489,8 +487,10 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj, cable_name, nb); } - return -ENODEV; + ret = -ENODEV; } + + return ret; } EXPORT_SYMBOL_GPL(extcon_register_interest); diff --git a/include/linux/extcon.h b/include/linux/extcon.h index e2cf6254c86a..799474d9dc48 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -97,8 +97,8 @@ struct extcon_cable; * @state: Attach/detach state of this extcon. Do not provide at * register-time. * @nh: Notifier for the state change events from this extcon - * @entry: To support list of extcon devices so that users can search - * for extcon devices based on the extcon name. + * @entry: To support list of extcon devices so that users can + * search for extcon devices based on the extcon name. * @lock: * @max_supported: Internal value to store the number of cables. * @extcon_dev_type: Device_type struct to provide attribute_groups @@ -258,7 +258,8 @@ extern int extcon_unregister_notifier(struct extcon_dev *edev, * Following API get the extcon device from devicetree. * This function use phandle of devicetree to get extcon device directly. */ -extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, int index); +extern struct extcon_dev *extcon_get_edev_by_phandle(struct device *dev, + int index); /* Following API to get information of extcon device */ extern const char *extcon_get_edev_name(struct extcon_dev *edev); From a71fbc1525c4fbe894c52256404575c5f697c571 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 15 Apr 2015 15:33:44 +0900 Subject: [PATCH 07/21] extcon: arizona: Remove the setting of device name This patch removes the setting of device name. Instead, extcon_dev_register() set the device name such as 'extcon[number]' naming method. - /sys/class/extcon/Headset Jack -> /sys/class/extcon/extcon[number] Cc: Charles Keepax Signed-off-by: Chanwoo Choi Acked-by: Charles Keepax --- drivers/extcon/extcon-arizona.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c index 830c5f94bc18..50975b3123d6 100644 --- a/drivers/extcon/extcon-arizona.c +++ b/drivers/extcon/extcon-arizona.c @@ -1185,7 +1185,6 @@ static int arizona_extcon_probe(struct platform_device *pdev) dev_err(&pdev->dev, "failed to allocate extcon device\n"); return -ENOMEM; } - info->edev->name = "Headset Jack"; ret = devm_extcon_dev_register(&pdev->dev, info->edev); if (ret < 0) { From 2b51f9c2f1bd43907e1dc75912de6f06c6f59860 Mon Sep 17 00:00:00 2001 From: Charles Keepax Date: Thu, 30 Apr 2015 23:43:37 +0900 Subject: [PATCH 08/21] extcon: arizona: Apply HP clamps correctly for WM8280 The headphone clamping is not set correctly currently, this was missed because the wm8280 patches and the patch fixing the clamping for wm5110 went upstream at very similar times. This patch sets the headphone clamping correctly for wm8280. Signed-off-by: Charles Keepax Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-arizona.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c index 50975b3123d6..5e08c358649b 100644 --- a/drivers/extcon/extcon-arizona.c +++ b/drivers/extcon/extcon-arizona.c @@ -145,6 +145,7 @@ static void arizona_extcon_hp_clamp(struct arizona_extcon_info *info, switch (arizona->type) { case WM5110: + case WM8280: mask = ARIZONA_HP1L_SHRTO | ARIZONA_HP1L_FLWR | ARIZONA_HP1L_SHRTI; if (clamp) From 9e86b2ad4c11fd52ee8133abce7a29e0b32d29a7 Mon Sep 17 00:00:00 2001 From: Inha Song Date: Mon, 4 May 2015 13:42:13 +0900 Subject: [PATCH 09/21] extcon: arizona: Add support for select accessory detect mode when headphone detection This patch add support for select accessory detect mode to HPDETL or HPDETR. Arizona provides a headphone detection circuit on the HPDETL and HPDETR pins to measure the impedance of an external load connected to the headphone. Depending on board design, headphone detect pins can change to HPDETR or HPDETL. Signed-off-by: Inha Song Acked-by: Lee Jones Acked-by: Charles Keepax Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-arizona.c | 38 ++++++++++++++++++++++++------- include/dt-bindings/mfd/arizona.h | 4 ++++ include/linux/mfd/arizona/pdata.h | 3 +++ 3 files changed, 37 insertions(+), 8 deletions(-) diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c index 5e08c358649b..1ec06b4b4875 100644 --- a/drivers/extcon/extcon-arizona.c +++ b/drivers/extcon/extcon-arizona.c @@ -32,13 +32,10 @@ #include #include #include +#include #define ARIZONA_MAX_MICD_RANGE 8 -#define ARIZONA_ACCDET_MODE_MIC 0 -#define ARIZONA_ACCDET_MODE_HPL 1 -#define ARIZONA_ACCDET_MODE_HPR 2 - #define ARIZONA_MICD_CLAMP_MODE_JDL 0x4 #define ARIZONA_MICD_CLAMP_MODE_JDH 0x5 #define ARIZONA_MICD_CLAMP_MODE_JDL_GP5H 0x9 @@ -671,9 +668,9 @@ static void arizona_identify_headphone(struct arizona_extcon_info *info) ret = regmap_update_bits(arizona->regmap, ARIZONA_ACCESSORY_DETECT_MODE_1, ARIZONA_ACCDET_MODE_MASK, - ARIZONA_ACCDET_MODE_HPL); + arizona->pdata.hpdet_channel); if (ret != 0) { - dev_err(arizona->dev, "Failed to set HPDETL mode: %d\n", ret); + dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret); goto err; } @@ -723,9 +720,9 @@ static void arizona_start_hpdet_acc_id(struct arizona_extcon_info *info) ARIZONA_ACCESSORY_DETECT_MODE_1, ARIZONA_ACCDET_SRC | ARIZONA_ACCDET_MODE_MASK, info->micd_modes[0].src | - ARIZONA_ACCDET_MODE_HPL); + arizona->pdata.hpdet_channel); if (ret != 0) { - dev_err(arizona->dev, "Failed to set HPDETL mode: %d\n", ret); + dev_err(arizona->dev, "Failed to set HPDET mode: %d\n", ret); goto err; } @@ -1121,6 +1118,26 @@ static void arizona_micd_set_level(struct arizona *arizona, int index, regmap_update_bits(arizona->regmap, reg, mask, level); } +static int arizona_extcon_of_get_pdata(struct arizona *arizona) +{ + struct arizona_pdata *pdata = &arizona->pdata; + unsigned int val = ARIZONA_ACCDET_MODE_HPL; + + of_property_read_u32(arizona->dev->of_node, "wlf,hpdet-channel", &val); + switch (val) { + case ARIZONA_ACCDET_MODE_HPL: + case ARIZONA_ACCDET_MODE_HPR: + pdata->hpdet_channel = val; + break; + default: + dev_err(arizona->dev, + "Wrong wlf,hpdet-channel DT value %d\n", val); + pdata->hpdet_channel = ARIZONA_ACCDET_MODE_HPL; + } + + return 0; +} + static int arizona_extcon_probe(struct platform_device *pdev) { struct arizona *arizona = dev_get_drvdata(pdev->dev.parent); @@ -1138,6 +1155,11 @@ static int arizona_extcon_probe(struct platform_device *pdev) if (!info) return -ENOMEM; + if (IS_ENABLED(CONFIG_OF)) { + if (!dev_get_platdata(arizona->dev)) + arizona_extcon_of_get_pdata(arizona); + } + info->micvdd = devm_regulator_get(&pdev->dev, "MICVDD"); if (IS_ERR(info->micvdd)) { ret = PTR_ERR(info->micvdd); diff --git a/include/dt-bindings/mfd/arizona.h b/include/dt-bindings/mfd/arizona.h index c7af7c7ef793..fee48e624036 100644 --- a/include/dt-bindings/mfd/arizona.h +++ b/include/dt-bindings/mfd/arizona.h @@ -90,4 +90,8 @@ #define ARIZONA_INMODE_SE 1 #define ARIZONA_INMODE_DMIC 2 +#define ARIZONA_ACCDET_MODE_MIC 0 +#define ARIZONA_ACCDET_MODE_HPL 1 +#define ARIZONA_ACCDET_MODE_HPR 2 + #endif diff --git a/include/linux/mfd/arizona/pdata.h b/include/linux/mfd/arizona/pdata.h index 1789cb0f4f17..aa5c48b06755 100644 --- a/include/linux/mfd/arizona/pdata.h +++ b/include/linux/mfd/arizona/pdata.h @@ -121,6 +121,9 @@ struct arizona_pdata { /** GPIO used for mic isolation with HPDET */ int hpdet_id_gpio; + /** Channel to use for headphone detection */ + unsigned int hpdet_channel; + /** Extra debounce timeout used during initial mic detection (ms) */ int micd_detect_debounce; From 9bf63cf858a5530df4fb48ab170cb7dbcab18d5e Mon Sep 17 00:00:00 2001 From: Inha Song Date: Mon, 4 May 2015 13:42:14 +0900 Subject: [PATCH 10/21] mfd: arizona: Update DT binding to support hpdet channel This patch add device tree bindings for the pdata needed to configure the Accessory Detect Mode select when Headphone detection. Signed-off-by: Inha Song Acked-by: Lee Jones Acked-by: Charles Keepax Signed-off-by: Chanwoo Choi --- Documentation/devicetree/bindings/mfd/arizona.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Documentation/devicetree/bindings/mfd/arizona.txt b/Documentation/devicetree/bindings/mfd/arizona.txt index 7665aa95979f..32a71b76794f 100644 --- a/Documentation/devicetree/bindings/mfd/arizona.txt +++ b/Documentation/devicetree/bindings/mfd/arizona.txt @@ -62,6 +62,12 @@ Optional properties: present, the number of values should be less than or equal to the number of inputs, unspecified inputs will use the chip default. + - wlf,hpdet-channel : Headphone detection channel. + ARIZONA_ACCDET_MODE_HPL or 1 - Headphone detect mode is set to HPDETL + ARIZONA_ACCDET_MODE_HPR or 2 - Headphone detect mode is set to HPDETR + If this node is not mentioned or if the value is unknown, then + headphone detection mode is set to HPDETL. + - DCVDD-supply, MICVDD-supply : Power supplies, only need to be specified if they are being externally supplied. As covered in Documentation/devicetree/bindings/regulator/regulator.txt From 41b3c0154c48940c39401f3ba74ade74badb17c5 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 24 Apr 2015 19:50:48 +0900 Subject: [PATCH 11/21] extcon: Unify the jig cable names on rt8973 and max14577/77693/77843 This patch change the name of various jig cables as 'JIG' because the name of various jig cables are strange and ambiguous on user-space aspect. They include the different information of either USB and UART state. It is never important for user-space process. This patch unifies the name of jig cables as following: - JIG-USB-ON -->|--> JIG - JIG-USB-OFF -->| - JIG-UART-ON -->| - JIG-UART-OFF -->| Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-max14577.c | 19 +++------------- drivers/extcon/extcon-max77693.c | 23 +++----------------- drivers/extcon/extcon-max77843.c | 37 +++++++++++--------------------- drivers/extcon/extcon-rt8973a.c | 22 +++++-------------- 4 files changed, 23 insertions(+), 78 deletions(-) diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c index 3823aa4a3a80..6d5febe91a39 100644 --- a/drivers/extcon/extcon-max14577.c +++ b/drivers/extcon/extcon-max14577.c @@ -155,10 +155,7 @@ enum { EXTCON_CABLE_FAST_CHARGER, EXTCON_CABLE_SLOW_CHARGER, EXTCON_CABLE_CHARGE_DOWNSTREAM, - EXTCON_CABLE_JIG_USB_ON, - EXTCON_CABLE_JIG_USB_OFF, - EXTCON_CABLE_JIG_UART_OFF, - EXTCON_CABLE_JIG_UART_ON, + EXTCON_CABLE_JIG, _EXTCON_CABLE_NUM, }; @@ -169,10 +166,7 @@ static const char *max14577_extcon_cable[] = { [EXTCON_CABLE_FAST_CHARGER] = "Fast-charger", [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger", [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream", - [EXTCON_CABLE_JIG_USB_ON] = "JIG-USB-ON", - [EXTCON_CABLE_JIG_USB_OFF] = "JIG-USB-OFF", - [EXTCON_CABLE_JIG_UART_OFF] = "JIG-UART-OFF", - [EXTCON_CABLE_JIG_UART_ON] = "JIG-UART-ON", + [EXTCON_CABLE_JIG] = "JIG", NULL, }; @@ -348,7 +342,6 @@ static int max14577_muic_get_cable_type(struct max14577_muic_info *info, static int max14577_muic_jig_handler(struct max14577_muic_info *info, int cable_type, bool attached) { - char cable_name[32]; int ret = 0; u8 path = CTRL1_SW_OPEN; @@ -358,18 +351,12 @@ static int max14577_muic_jig_handler(struct max14577_muic_info *info, switch (cable_type) { case MAX14577_MUIC_ADC_FACTORY_MODE_USB_OFF: /* ADC_JIG_USB_OFF */ - /* PATH:AP_USB */ - strcpy(cable_name, "JIG-USB-OFF"); - path = CTRL1_SW_USB; - break; case MAX14577_MUIC_ADC_FACTORY_MODE_USB_ON: /* ADC_JIG_USB_ON */ /* PATH:AP_USB */ - strcpy(cable_name, "JIG-USB-ON"); path = CTRL1_SW_USB; break; case MAX14577_MUIC_ADC_FACTORY_MODE_UART_OFF: /* ADC_JIG_UART_OFF */ /* PATH:AP_UART */ - strcpy(cable_name, "JIG-UART-OFF"); path = CTRL1_SW_UART; break; default: @@ -382,7 +369,7 @@ static int max14577_muic_jig_handler(struct max14577_muic_info *info, if (ret < 0) return ret; - extcon_set_cable_state(info->edev, cable_name, attached); + extcon_set_cable_state(info->edev, "JIG", attached); return 0; } diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index a66bec8f6252..107932105798 100644 --- a/drivers/extcon/extcon-max77693.c +++ b/drivers/extcon/extcon-max77693.c @@ -209,10 +209,7 @@ enum { EXTCON_CABLE_CHARGE_DOWNSTREAM, EXTCON_CABLE_MHL, EXTCON_CABLE_MHL_TA, - EXTCON_CABLE_JIG_USB_ON, - EXTCON_CABLE_JIG_USB_OFF, - EXTCON_CABLE_JIG_UART_OFF, - EXTCON_CABLE_JIG_UART_ON, + EXTCON_CABLE_JIG, EXTCON_CABLE_DOCK_SMART, EXTCON_CABLE_DOCK_DESK, EXTCON_CABLE_DOCK_AUDIO, @@ -229,10 +226,7 @@ static const char *max77693_extcon_cable[] = { [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream", [EXTCON_CABLE_MHL] = "MHL", [EXTCON_CABLE_MHL_TA] = "MHL-TA", - [EXTCON_CABLE_JIG_USB_ON] = "JIG-USB-ON", - [EXTCON_CABLE_JIG_USB_OFF] = "JIG-USB-OFF", - [EXTCON_CABLE_JIG_UART_OFF] = "JIG-UART-OFF", - [EXTCON_CABLE_JIG_UART_ON] = "JIG-UART-ON", + [EXTCON_CABLE_JIG] = "JIG", [EXTCON_CABLE_DOCK_SMART] = "Dock-Smart", [EXTCON_CABLE_DOCK_DESK] = "Dock-Desk", [EXTCON_CABLE_DOCK_AUDIO] = "Dock-Audio", @@ -642,7 +636,6 @@ static int max77693_muic_adc_ground_handler(struct max77693_muic_info *info) static int max77693_muic_jig_handler(struct max77693_muic_info *info, int cable_type, bool attached) { - char cable_name[32]; int ret = 0; u8 path = CONTROL1_SW_OPEN; @@ -652,23 +645,13 @@ static int max77693_muic_jig_handler(struct max77693_muic_info *info, switch (cable_type) { case MAX77693_MUIC_ADC_FACTORY_MODE_USB_OFF: /* ADC_JIG_USB_OFF */ - /* PATH:AP_USB */ - strcpy(cable_name, "JIG-USB-OFF"); - path = CONTROL1_SW_USB; - break; case MAX77693_MUIC_ADC_FACTORY_MODE_USB_ON: /* ADC_JIG_USB_ON */ /* PATH:AP_USB */ - strcpy(cable_name, "JIG-USB-ON"); path = CONTROL1_SW_USB; break; case MAX77693_MUIC_ADC_FACTORY_MODE_UART_OFF: /* ADC_JIG_UART_OFF */ - /* PATH:AP_UART */ - strcpy(cable_name, "JIG-UART-OFF"); - path = CONTROL1_SW_UART; - break; case MAX77693_MUIC_ADC_FACTORY_MODE_UART_ON: /* ADC_JIG_UART_ON */ /* PATH:AP_UART */ - strcpy(cable_name, "JIG-UART-ON"); path = CONTROL1_SW_UART; break; default: @@ -681,7 +664,7 @@ static int max77693_muic_jig_handler(struct max77693_muic_info *info, if (ret < 0) return ret; - extcon_set_cable_state(info->edev, cable_name, attached); + extcon_set_cable_state(info->edev, "JIG", attached); return 0; } diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c index 8db6a926ea07..d64aed485fdc 100644 --- a/drivers/extcon/extcon-max77843.c +++ b/drivers/extcon/extcon-max77843.c @@ -127,10 +127,7 @@ enum { MAX77843_CABLE_SLOW_CHARGER, MAX77843_CABLE_MHL, MAX77843_CABLE_MHL_TA, - MAX77843_CABLE_JIG_USB_ON, - MAX77843_CABLE_JIG_USB_OFF, - MAX77843_CABLE_JIG_UART_ON, - MAX77843_CABLE_JIG_UART_OFF, + MAX77843_CABLE_JIG, MAX77843_CABLE_NUM, }; @@ -144,10 +141,7 @@ static const char *max77843_extcon_cable[] = { [MAX77843_CABLE_SLOW_CHARGER] = "SLOW-CHARGER", [MAX77843_CABLE_MHL] = "MHL", [MAX77843_CABLE_MHL_TA] = "MHL-TA", - [MAX77843_CABLE_JIG_USB_ON] = "JIG-USB-ON", - [MAX77843_CABLE_JIG_USB_OFF] = "JIG-USB-OFF", - [MAX77843_CABLE_JIG_UART_ON] = "JIG-UART-ON", - [MAX77843_CABLE_JIG_UART_OFF] = "JIG-UART-OFF", + [MAX77843_CABLE_JIG] = "JIG", }; struct max77843_muic_irq { @@ -385,36 +379,29 @@ static int max77843_muic_jig_handler(struct max77843_muic_info *info, int cable_type, bool attached) { int ret; + u8 path = CONTROL1_SW_OPEN; dev_dbg(info->dev, "external connector is %s (adc:0x%02x)\n", attached ? "attached" : "detached", cable_type); switch (cable_type) { case MAX77843_MUIC_ADC_FACTORY_MODE_USB_OFF: - ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); - if (ret < 0) - return ret; - extcon_set_cable_state(info->edev, "JIG-USB-OFF", attached); - break; case MAX77843_MUIC_ADC_FACTORY_MODE_USB_ON: - ret = max77843_muic_set_path(info, CONTROL1_SW_USB, attached); - if (ret < 0) - return ret; - extcon_set_cable_state(info->edev, "JIG-USB-ON", attached); + path = CONTROL1_SW_USB; break; case MAX77843_MUIC_ADC_FACTORY_MODE_UART_OFF: - ret = max77843_muic_set_path(info, CONTROL1_SW_UART, attached); - if (ret < 0) - return ret; - extcon_set_cable_state(info->edev, "JIG-UART-OFF", attached); + path = CONTROL1_SW_UART; break; default: - ret = max77843_muic_set_path(info, CONTROL1_SW_OPEN, attached); - if (ret < 0) - return ret; - break; + return -EINVAL; } + ret = max77843_muic_set_path(info, path, attached); + if (ret < 0) + return ret; + + extcon_set_cable_state(info->edev, "JIG", attached); + return 0; } diff --git a/drivers/extcon/extcon-rt8973a.c b/drivers/extcon/extcon-rt8973a.c index 9ccd5af89d1c..8c2194fde387 100644 --- a/drivers/extcon/extcon-rt8973a.c +++ b/drivers/extcon/extcon-rt8973a.c @@ -94,10 +94,7 @@ enum { EXTCON_CABLE_USB = 0, EXTCON_CABLE_USB_HOST, EXTCON_CABLE_TA, - EXTCON_CABLE_JIG_OFF_USB, - EXTCON_CABLE_JIG_ON_USB, - EXTCON_CABLE_JIG_OFF_UART, - EXTCON_CABLE_JIG_ON_UART, + EXTCON_CABLE_JIG, EXTCON_CABLE_END, }; @@ -106,10 +103,7 @@ static const char *rt8973a_extcon_cable[] = { [EXTCON_CABLE_USB] = "USB", [EXTCON_CABLE_USB_HOST] = "USB-Host", [EXTCON_CABLE_TA] = "TA", - [EXTCON_CABLE_JIG_OFF_USB] = "JIG-USB-OFF", - [EXTCON_CABLE_JIG_ON_USB] = "JIG-USB-ON", - [EXTCON_CABLE_JIG_OFF_UART] = "JIG-UART-OFF", - [EXTCON_CABLE_JIG_ON_UART] = "JIG-UART-ON", + [EXTCON_CABLE_JIG] = "JIG", NULL, }; @@ -355,19 +349,13 @@ static int rt8973a_muic_cable_handler(struct rt8973a_muic_info *info, con_sw = DM_DP_SWITCH_OPEN; break; case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_USB: - idx = EXTCON_CABLE_JIG_OFF_USB; - con_sw = DM_DP_SWITCH_UART; - break; case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_USB: - idx = EXTCON_CABLE_JIG_ON_USB; - con_sw = DM_DP_SWITCH_UART; + idx = EXTCON_CABLE_JIG; + con_sw = DM_DP_SWITCH_USB; break; case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_OFF_UART: - idx = EXTCON_CABLE_JIG_OFF_UART; - con_sw = DM_DP_SWITCH_UART; - break; case RT8973A_MUIC_ADC_FACTORY_MODE_BOOT_ON_UART: - idx = EXTCON_CABLE_JIG_ON_UART; + idx = EXTCON_CABLE_JIG; con_sw = DM_DP_SWITCH_UART; break; case RT8973A_MUIC_ADC_USB: From d519c423ff4f1de2fd48778eacef1696a03ed934 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Sat, 25 Apr 2015 19:05:10 +0900 Subject: [PATCH 12/21] extcon: Unify the dock device names on max8997/77693 This patch change the name of various dock devices as 'DOCK' because the name of various dock devices have not the standard naming rules. The name of dock devices include the differenct word but it is ambiguous and never important information on user-space aspect. This patch unifies the name of dock devices as following: - Dock-Smart -->|--> DOCK - Dock-Desk -->| - Dock-Audio -->| - Dock-Card -->| Signed-off-by: Chanwoo Choi Reviewed-by: Krzysztof Kozlowski --- drivers/extcon/extcon-max77693.c | 31 +++++++++++++------------------ drivers/extcon/extcon-max8997.c | 10 +++------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index 107932105798..652bb13739f1 100644 --- a/drivers/extcon/extcon-max77693.c +++ b/drivers/extcon/extcon-max77693.c @@ -210,9 +210,7 @@ enum { EXTCON_CABLE_MHL, EXTCON_CABLE_MHL_TA, EXTCON_CABLE_JIG, - EXTCON_CABLE_DOCK_SMART, - EXTCON_CABLE_DOCK_DESK, - EXTCON_CABLE_DOCK_AUDIO, + EXTCON_CABLE_DOCK, _EXTCON_CABLE_NUM, }; @@ -227,9 +225,7 @@ static const char *max77693_extcon_cable[] = { [EXTCON_CABLE_MHL] = "MHL", [EXTCON_CABLE_MHL_TA] = "MHL-TA", [EXTCON_CABLE_JIG] = "JIG", - [EXTCON_CABLE_DOCK_SMART] = "Dock-Smart", - [EXTCON_CABLE_DOCK_DESK] = "Dock-Desk", - [EXTCON_CABLE_DOCK_AUDIO] = "Dock-Audio", + [EXTCON_CABLE_DOCK] = "DOCK", NULL, }; @@ -501,15 +497,15 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info, } /* - * Notify Dock-Smart/MHL state. - * - Dock-Smart device include three type of cable which + * Notify Dock/MHL state. + * - Dock device include three type of cable which * are HDMI, USB for mouse/keyboard and micro-usb port - * for USB/TA cable. Dock-Smart device need always exteranl - * power supply(USB/TA cable through micro-usb cable). Dock- - * Smart device support screen output of target to separate + * for USB/TA cable. Dock device need always exteranl + * power supply(USB/TA cable through micro-usb cable). Dock + * device support screen output of target to separate * monitor and mouse/keyboard for desktop mode. * - * Features of 'USB/TA cable with Dock-Smart device' + * Features of 'USB/TA cable with Dock device' * - Support MHL * - Support external output feature of audio * - Support charging through micro-usb port without data @@ -523,14 +519,14 @@ static int max77693_muic_dock_handler(struct max77693_muic_info *info, if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "Dock-Smart", attached); + extcon_set_cable_state(info->edev, "DOCK", attached); extcon_set_cable_state(info->edev, "MHL", attached); goto out; case MAX77693_MUIC_ADC_AUDIO_MODE_REMOTE: /* Dock-Desk */ - strcpy(dock_name, "Dock-Desk"); + strcpy(dock_name, "DOCK"); break; case MAX77693_MUIC_ADC_AV_CABLE_NOLOAD: /* Dock-Audio */ - strcpy(dock_name, "Dock-Audio"); + strcpy(dock_name, "DOCK"); if (!attached) extcon_set_cable_state(info->edev, "USB", false); break; @@ -847,7 +843,7 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info) extcon_set_cable_state(info->edev, "USB", attached); if (!cable_attached) - extcon_set_cable_state(info->edev, "Dock-Audio", + extcon_set_cable_state(info->edev, "DOCK", cable_attached); break; case MAX77693_MUIC_ADC_RESERVED_ACC_3: /* Dock-Smart */ @@ -876,8 +872,7 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info) if (ret < 0) return ret; - extcon_set_cable_state(info->edev, "Dock-Smart", - attached); + extcon_set_cable_state(info->edev, "DOCK", attached); extcon_set_cable_state(info->edev, "MHL", attached); break; diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c index 5774e56c6422..da269a170fd8 100644 --- a/drivers/extcon/extcon-max8997.c +++ b/drivers/extcon/extcon-max8997.c @@ -153,8 +153,7 @@ enum { EXTCON_CABLE_SLOW_CHARGER, EXTCON_CABLE_CHARGE_DOWNSTREAM, EXTCON_CABLE_MHL, - EXTCON_CABLE_DOCK_DESK, - EXTCON_CABLE_DOCK_CARD, + EXTCON_CABLE_DOCK, EXTCON_CABLE_JIG, _EXTCON_CABLE_NUM, @@ -168,8 +167,7 @@ static const char *max8997_extcon_cable[] = { [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger", [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream", [EXTCON_CABLE_MHL] = "MHL", - [EXTCON_CABLE_DOCK_DESK] = "Dock-Desk", - [EXTCON_CABLE_DOCK_CARD] = "Dock-Card", + [EXTCON_CABLE_DOCK] = "DOCK", [EXTCON_CABLE_JIG] = "JIG", NULL, @@ -374,10 +372,8 @@ static int max8997_muic_handle_dock(struct max8997_muic_info *info, switch (cable_type) { case MAX8997_MUIC_ADC_AV_CABLE_NOLOAD: - extcon_set_cable_state(info->edev, "Dock-desk", attached); - break; case MAX8997_MUIC_ADC_FACTORY_MODE_UART_ON: - extcon_set_cable_state(info->edev, "Dock-card", attached); + extcon_set_cable_state(info->edev, "DOCK", attached); break; default: dev_err(info->dev, "failed to detect %s dock device\n", From 942e0239d51185d6532f3ac846e5ab06db0a86cf Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Sat, 25 Apr 2015 19:06:18 +0900 Subject: [PATCH 13/21] extcon: Alter MHL-TA cable name to TA cable name This patch alters the MHL-TA cable name to TA cable name because MHL-TA is not standard name. The MHL-TA is MHL cable with charger cable (TA or USB). So, this patch use the TA cable instead of MHL-TA to inform the charger cable state. - MHL-TA -> TA Signed-off-by: Chanwoo Choi Reviewed-by: Krzysztof Kozlowski --- drivers/extcon/extcon-max77693.c | 12 +++++------- drivers/extcon/extcon-max77843.c | 6 ++---- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index 652bb13739f1..a4fe7fd3f74d 100644 --- a/drivers/extcon/extcon-max77693.c +++ b/drivers/extcon/extcon-max77693.c @@ -208,7 +208,6 @@ enum { EXTCON_CABLE_SLOW_CHARGER, EXTCON_CABLE_CHARGE_DOWNSTREAM, EXTCON_CABLE_MHL, - EXTCON_CABLE_MHL_TA, EXTCON_CABLE_JIG, EXTCON_CABLE_DOCK, @@ -223,7 +222,6 @@ static const char *max77693_extcon_cable[] = { [EXTCON_CABLE_SLOW_CHARGER] = "Slow-charger", [EXTCON_CABLE_CHARGE_DOWNSTREAM] = "Charge-downstream", [EXTCON_CABLE_MHL] = "MHL", - [EXTCON_CABLE_MHL_TA] = "MHL-TA", [EXTCON_CABLE_JIG] = "JIG", [EXTCON_CABLE_DOCK] = "DOCK", @@ -802,19 +800,19 @@ static int max77693_muic_chg_handler(struct max77693_muic_info *info) case MAX77693_MUIC_GND_MHL: case MAX77693_MUIC_GND_MHL_VB: /* - * MHL cable with MHL-TA(USB/TA) cable + * MHL cable with USB/TA cable * - MHL cable include two port(HDMI line and separate * micro-usb port. When the target connect MHL cable, - * extcon driver check whether MHL-TA(USB/TA) cable is - * connected. If MHL-TA cable is connected, extcon + * extcon driver check whether USB/TA cable is + * connected. If USB/TA cable is connected, extcon * driver notify state to notifiee for charging battery. * - * Features of 'MHL-TA(USB/TA) with MHL cable' + * Features of 'USB/TA with MHL cable' * - Support MHL * - Support charging through micro-usb port without * data connection */ - extcon_set_cable_state(info->edev, "MHL-TA", attached); + extcon_set_cable_state(info->edev, "TA", attached); if (!cable_attached) extcon_set_cable_state(info->edev, "MHL", cable_attached); diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c index d64aed485fdc..5746d7bc165f 100644 --- a/drivers/extcon/extcon-max77843.c +++ b/drivers/extcon/extcon-max77843.c @@ -126,7 +126,6 @@ enum { MAX77843_CABLE_FAST_CHARGER, MAX77843_CABLE_SLOW_CHARGER, MAX77843_CABLE_MHL, - MAX77843_CABLE_MHL_TA, MAX77843_CABLE_JIG, MAX77843_CABLE_NUM, @@ -140,7 +139,6 @@ static const char *max77843_extcon_cable[] = { [MAX77843_CABLE_FAST_CHARGER] = "FAST-CHARGER", [MAX77843_CABLE_SLOW_CHARGER] = "SLOW-CHARGER", [MAX77843_CABLE_MHL] = "MHL", - [MAX77843_CABLE_MHL_TA] = "MHL-TA", [MAX77843_CABLE_JIG] = "JIG", }; @@ -529,9 +527,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, "MHL-TA", true); + extcon_set_cable_state(info->edev, "TA", true); else if (gnd_type == MAX77843_MUIC_GND_MHL) - extcon_set_cable_state(info->edev, "MHL-TA", false); + extcon_set_cable_state(info->edev, "TA", false); break; case MAX77843_MUIC_CHG_NONE: break; From c571bbb4b699cfd3af5b4c1027b04eb4290e6726 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Sat, 25 Apr 2015 18:44:47 +0900 Subject: [PATCH 14/21] extcon: adc-jack: Remove the unneeded num_cables field This patch removes the 'num_cables' filed from 'struct adc_jack_pdata' because 'struct extcon_dev' contains the 'max_supported' field which means the number of supported cable of extcon device. Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-adc-jack.c | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c index 2bb82e55065a..768eaed66380 100644 --- a/drivers/extcon/extcon-adc-jack.c +++ b/drivers/extcon/extcon-adc-jack.c @@ -29,7 +29,6 @@ * struct adc_jack_data - internal data for adc_jack device driver * @edev: extcon device. * @cable_names: list of supported cables. - * @num_cables: size of cable_names. * @adc_conditions: list of adc value conditions. * @num_conditions: size of adc_conditions. * @irq: irq number of attach/detach event (0 if not exist). @@ -42,7 +41,6 @@ struct adc_jack_data { struct extcon_dev *edev; const char **cable_names; - int num_cables; struct adc_jack_cond *adc_conditions; int num_conditions; @@ -114,16 +112,6 @@ static int adc_jack_probe(struct platform_device *pdev) } data->edev->name = pdata->name; - /* Check the length of array and set num_cables */ - for (i = 0; data->edev->supported_cable[i]; i++) - ; - if (i == 0 || i > SUPPORTED_CABLE_MAX) { - dev_err(&pdev->dev, "error: pdata->cable_names size = %d\n", - i - 1); - return -EINVAL; - } - data->num_cables = i; - if (!pdata->adc_conditions || !pdata->adc_conditions[0].state) { dev_err(&pdev->dev, "error: adc_conditions not defined.\n"); From 638f958baeaf9d50f42cd09993f518b3a7a0f52e Mon Sep 17 00:00:00 2001 From: Geert Uytterhoeven Date: Tue, 5 May 2015 18:32:20 +0200 Subject: [PATCH 15/21] extcon: Allow compile test of GPIO consumers if !GPIOLIB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The GPIO subsystem provides dummy GPIO consumer functions if GPIOLIB is not enabled. Hence drivers that depend on GPIOLIB, but use GPIO consumer functionality only, can still be compiled if GPIOLIB is not enabled. Relax the dependency on GPIOLIB if COMPILE_TEST is enabled, where appropriate. If GPIOLIB=n and asm-generic/gpio.h is not used: drivers/extcon/extcon-usb-gpio.c: In function ‘usb_extcon_detect_cable’: drivers/extcon/extcon-usb-gpio.c:63: error: implicit declaration of function ‘gpiod_get_value_cansleep’ drivers/extcon/extcon-usb-gpio.c: In function ‘usb_extcon_probe’: drivers/extcon/extcon-usb-gpio.c:116: error: implicit declaration of function ‘devm_gpiod_get’ drivers/extcon/extcon-usb-gpio.c:116: warning: assignment makes pointer from integer without a cast drivers/extcon/extcon-usb-gpio.c:122: error: implicit declaration of function ‘gpiod_set_debounce’ drivers/extcon/extcon-usb-gpio.c:129: error: implicit declaration of function ‘gpiod_to_irq’ Add the missing #include to fix this. Signed-off-by: Geert Uytterhoeven Signed-off-by: Chanwoo Choi --- drivers/extcon/Kconfig | 4 ++-- drivers/extcon/extcon-usb-gpio.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/extcon/Kconfig b/drivers/extcon/Kconfig index b74e1f27688b..0cebbf668886 100644 --- a/drivers/extcon/Kconfig +++ b/drivers/extcon/Kconfig @@ -37,7 +37,7 @@ config EXTCON_AXP288 config EXTCON_GPIO tristate "GPIO extcon support" - depends on GPIOLIB + depends on GPIOLIB || COMPILE_TEST help Say Y here to enable GPIO based extcon support. Note that GPIO extcon supports single state per extcon instance. @@ -112,7 +112,7 @@ config EXTCON_SM5502 config EXTCON_USB_GPIO tristate "USB GPIO extcon support" - depends on GPIOLIB + depends on GPIOLIB || COMPILE_TEST help Say Y here to enable GPIO based USB cable detection extcon support. Used typically if GPIO is used for USB ID pin detection. diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c index e45d1f13f445..160ec12c2653 100644 --- a/drivers/extcon/extcon-usb-gpio.c +++ b/drivers/extcon/extcon-usb-gpio.c @@ -15,6 +15,7 @@ */ #include +#include #include #include #include From d71aadda19f83521eca301cb154b81a7bcca78a2 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 4 May 2015 20:20:27 +0900 Subject: [PATCH 16/21] extcon: Remove the optional name of extcon device This patch removes the optional name of extcon device. Instead, extcon_dev_register() set the device name as 'extcon[number]' naming pattern. - /sys/class/extcon/[hardcoded device name] -> /sys/class/extcon/extcon[number] Signed-off-by: Chanwoo Choi Acked-by: Krzysztof Kozlowski Cc: MyungJoo Ham Cc: Charles Keepax Cc: Graeme Gregory Cc: Kishon Vijay Abraham I Cc: Krzysztof Kozlowski Cc: Jaewon Kim --- drivers/extcon/extcon-adc-jack.c | 1 - drivers/extcon/extcon-gpio.c | 1 - drivers/extcon/extcon-max14577.c | 2 -- drivers/extcon/extcon-max77693.c | 1 - drivers/extcon/extcon-max8997.c | 1 - drivers/extcon/extcon-palmas.c | 1 - drivers/extcon/extcon-rt8973a.c | 1 - drivers/extcon/extcon-sm5502.c | 1 - 8 files changed, 9 deletions(-) diff --git a/drivers/extcon/extcon-adc-jack.c b/drivers/extcon/extcon-adc-jack.c index 768eaed66380..5bf08ec1cacf 100644 --- a/drivers/extcon/extcon-adc-jack.c +++ b/drivers/extcon/extcon-adc-jack.c @@ -110,7 +110,6 @@ static int adc_jack_probe(struct platform_device *pdev) dev_err(&pdev->dev, "failed to allocate extcon device\n"); return -ENOMEM; } - data->edev->name = pdata->name; if (!pdata->adc_conditions || !pdata->adc_conditions[0].state) { diff --git a/drivers/extcon/extcon-gpio.c b/drivers/extcon/extcon-gpio.c index 7af33fc433cd..355459a54e8b 100644 --- a/drivers/extcon/extcon-gpio.c +++ b/drivers/extcon/extcon-gpio.c @@ -104,7 +104,6 @@ static int gpio_extcon_probe(struct platform_device *pdev) dev_err(&pdev->dev, "failed to allocate extcon device\n"); return -ENOMEM; } - extcon_data->edev->name = pdata->name; extcon_data->gpio = pdata->gpio; extcon_data->gpio_active_low = pdata->gpio_active_low; diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c index 6d5febe91a39..ad8f8ddc8e51 100644 --- a/drivers/extcon/extcon-max14577.c +++ b/drivers/extcon/extcon-max14577.c @@ -729,8 +729,6 @@ static int max14577_muic_probe(struct platform_device *pdev) return -ENOMEM; } - info->edev->name = dev_name(&pdev->dev); - ret = devm_extcon_dev_register(&pdev->dev, info->edev); if (ret) { dev_err(&pdev->dev, "failed to register extcon device\n"); diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index a4fe7fd3f74d..c274249245ff 100644 --- a/drivers/extcon/extcon-max77693.c +++ b/drivers/extcon/extcon-max77693.c @@ -1158,7 +1158,6 @@ static int max77693_muic_probe(struct platform_device *pdev) dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); return -ENOMEM; } - info->edev->name = DEV_NAME; ret = devm_extcon_dev_register(&pdev->dev, info->edev); if (ret) { diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c index da269a170fd8..33613c490d34 100644 --- a/drivers/extcon/extcon-max8997.c +++ b/drivers/extcon/extcon-max8997.c @@ -696,7 +696,6 @@ static int max8997_muic_probe(struct platform_device *pdev) ret = -ENOMEM; goto err_irq; } - info->edev->name = DEV_NAME; ret = devm_extcon_dev_register(&pdev->dev, info->edev); if (ret) { diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c index 11c6757b6c40..9c8943d691b1 100644 --- a/drivers/extcon/extcon-palmas.c +++ b/drivers/extcon/extcon-palmas.c @@ -193,7 +193,6 @@ static int palmas_usb_probe(struct platform_device *pdev) dev_err(&pdev->dev, "failed to allocate extcon device\n"); return -ENOMEM; } - palmas_usb->edev->name = kstrdup(node->name, GFP_KERNEL); palmas_usb->edev->mutually_exclusive = mutually_exclusive; status = devm_extcon_dev_register(&pdev->dev, palmas_usb->edev); diff --git a/drivers/extcon/extcon-rt8973a.c b/drivers/extcon/extcon-rt8973a.c index 8c2194fde387..04447f36c994 100644 --- a/drivers/extcon/extcon-rt8973a.c +++ b/drivers/extcon/extcon-rt8973a.c @@ -631,7 +631,6 @@ static int rt8973a_muic_i2c_probe(struct i2c_client *i2c, dev_err(info->dev, "failed to allocate memory for extcon\n"); return -ENOMEM; } - info->edev->name = np->name; /* Register extcon device */ ret = devm_extcon_dev_register(info->dev, info->edev); diff --git a/drivers/extcon/extcon-sm5502.c b/drivers/extcon/extcon-sm5502.c index 2f93cf307852..6f1d11f8723b 100644 --- a/drivers/extcon/extcon-sm5502.c +++ b/drivers/extcon/extcon-sm5502.c @@ -623,7 +623,6 @@ static int sm5022_muic_i2c_probe(struct i2c_client *i2c, dev_err(info->dev, "failed to allocate memory for extcon\n"); return -ENOMEM; } - info->edev->name = np->name; /* Register extcon device */ ret = devm_extcon_dev_register(info->dev, info->edev); From 35eed7a0768886e2f66db3cdbf3faf6435275e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Uwe=20Kleine-K=C3=B6nig?= Date: Tue, 19 May 2015 14:18:30 +0200 Subject: [PATCH 17/21] extcon: usb-gpio: use flags argument of devm_gpiod_get to set direction MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since 39b2bbe3d715 (gpio: add flags argument to gpiod_get*() functions) which appeared in v3.17-rc1, the gpiod_get* functions take an additional parameter that allows to specify direction and initial value for output. Without this patch there is no call to gpiod_direction_input but the gpio is used for irq reporting and for that the line should be in input mode. Signed-off-by: Uwe Kleine-König Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-usb-gpio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c index 160ec12c2653..900744b978fc 100644 --- a/drivers/extcon/extcon-usb-gpio.c +++ b/drivers/extcon/extcon-usb-gpio.c @@ -114,7 +114,7 @@ static int usb_extcon_probe(struct platform_device *pdev) return -ENOMEM; info->dev = dev; - info->id_gpiod = devm_gpiod_get(&pdev->dev, "id"); + info->id_gpiod = devm_gpiod_get(&pdev->dev, "id", GPIOD_IN); if (IS_ERR(info->id_gpiod)) { dev_err(dev, "failed to get ID GPIO\n"); return PTR_ERR(info->id_gpiod); From 2a9de9c0f08d61fbe3764a21d22d0b72df97d6ae Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Fri, 24 Apr 2015 19:16:05 +0900 Subject: [PATCH 18/21] 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 Cc: Felipe Balbi Signed-off-by: Chanwoo Choi Acked-by: Roger Quadros Acked-by: Charles Keepax Acked-by: Ramakrishna Pallala Reviewed-by: Krzysztof Kozlowski [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 [dan.carpenter: Report the build warning of extcon_{set|get}_cable_state_()] Reported-by: Dan Carpenter --- 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 | 165 ++++++++++++++----------- drivers/usb/phy/phy-tahvo.c | 9 +- include/linux/extcon.h | 109 +++++++--------- include/linux/extcon/extcon-adc-jack.h | 5 +- 14 files changed, 320 insertions(+), 411 deletions(-) diff --git a/drivers/extcon/extcon-arizona.c b/drivers/extcon/extcon-arizona.c index 1ec06b4b4875..9262b45a4484 100644 --- a/drivers/extcon/extcon-arizona.c +++ b/drivers/extcon/extcon-arizona.c @@ -118,17 +118,12 @@ static const int arizona_micd_levels[] = { 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 8299adb9b676..3605aa96c25a 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 ad8f8ddc8e51..e7c3edb5bd4b 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 c274249245ff..20e796e10e57 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 5746d7bc165f..d78a64d7fc20 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 33613c490d34..4d10949c6eb2 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 9c8943d691b1..d68954045a33 100644 --- a/drivers/extcon/extcon-palmas.c +++ b/drivers/extcon/extcon-palmas.c @@ -29,10 +29,10 @@ #include #include -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 04447f36c994..f2a8672cbf82 100644 --- a/drivers/extcon/extcon-rt8973a.c +++ b/drivers/extcon/extcon-rt8973a.c @@ -90,21 +90,12 @@ static struct reg_data rt8973a_reg_data[] = { }; /* 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 6f1d11f8723b..520693d6fa8a 100644 --- a/drivers/extcon/extcon-sm5502.c +++ b/drivers/extcon/extcon-sm5502.c @@ -92,19 +92,11 @@ static struct reg_data sm5502_reg_data[] = { }; /* 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 900744b978fc..14da94cb57fa 100644 --- a/drivers/extcon/extcon-usb-gpio.c +++ b/drivers/extcon/extcon-usb-gpio.c @@ -39,18 +39,10 @@ struct usb_extcon_info { 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 2fb5f757e811..a57355fc8fea 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 + * * Copyright (C) 2012 Samsung Electronics * Author: Donggeun Kim * Author: MyungJoo Ham @@ -32,36 +35,32 @@ #include #include -/* - * 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_USB] = "USB", [EXTCON_USB_HOST] = "USB-Host", [EXTCON_TA] = "TA", [EXTCON_FAST_CHARGER] = "Fast-charger", [EXTCON_SLOW_CHARGER] = "Slow-charger", [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_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_DOCK] = "Dock", + [EXTCON_JIG] = "JIG", [EXTCON_MECHANICAL] = "Mechanical", + NULL, }; static struct class *extcon_class; @@ -101,6 +100,43 @@ static int check_mutually_exclusive(struct extcon_dev *edev, u32 new_state) 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, char *buf) { @@ -118,11 +154,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 +205,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,40 +317,20 @@ 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) -{ - 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. * @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 !!(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) { - return extcon_get_cable_state_(edev, extcon_find_cable_index + return extcon_get_cable_state_(edev, find_cable_index_by_name (edev, cable_name)); } 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. * @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 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; 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, 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); } EXPORT_SYMBOL_GPL(extcon_set_cable_state); @@ -455,8 +475,8 @@ int extcon_register_interest(struct extcon_specific_cable_nb *obj, if (!obj->edev) return -ENODEV; - obj->cable_index = extcon_find_cable_index(obj->edev, - cable_name); + obj->cable_index = find_cable_index_by_name(obj->edev, + cable_name); if (obj->cable_index < 0) 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))) { 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; 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. - * @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 * 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 */ -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; @@ -647,7 +667,7 @@ static void devm_extcon_dev_release(struct device *dev, void *res) /** * devm_extcon_dev_allocate - Allocate managed extcon device * @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 * are disabled. * @@ -659,7 +679,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 +729,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 +1088,7 @@ static void __exit extcon_class_exit(void) } module_exit(extcon_class_exit); +MODULE_AUTHOR("Chanwoo Choi "); MODULE_AUTHOR("Mike Lockwood "); MODULE_AUTHOR("Donggeun Kim "); MODULE_AUTHOR("MyungJoo Ham "); diff --git a/drivers/usb/phy/phy-tahvo.c b/drivers/usb/phy/phy-tahvo.c index 845f658276b1..1d1bb9ad8ccf 100644 --- a/drivers/usb/phy/phy-tahvo.c +++ b/drivers/usb/phy/phy-tahvo.c @@ -60,10 +60,11 @@ struct tahvo_usb { struct extcon_dev extcon; }; -static const char *tahvo_cable[] = { - "USB-HOST", - "USB", - NULL, +static const enum extcon tahvo_cable[] = { + EXTCON_USB, + EXTCON_USB_HOST, + + EXTCON_NONE, }; static ssize_t vbus_state_show(struct device *device, diff --git a/include/linux/extcon.h b/include/linux/extcon.h index 799474d9dc48..85c882f0029e 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -1,6 +1,9 @@ /* * External connector (extcon) class driver * + * Copyright (C) 2015 Samsung Electronics + * Author: Chanwoo Choi + * * Copyright (C) 2012 Samsung Electronics * Author: Donggeun Kim * Author: MyungJoo Ham @@ -27,50 +30,41 @@ #include #include -#define SUPPORTED_CABLE_MAX 32 -#define CABLE_NAME_MAX 30 +enum extcon { + EXTCON_NONE = 0x0, -/* - * The standard cable name is to help support general notifier - * and notifiee device drivers to share the common names. - * Please use standard cable names unless your notifier device has - * a very unique and abnormal cable or - * the cable type is supposed to be used with only one unique - * pair of notifier/notifiee devices. - * - * Please add any other "standard" cables used with extcon dev. - * - * You may add a dot and number to specify version or specification - * of the specific cable if it is required. (e.g., "Fast-charger.18" - * and "Fast-charger.10" for 1.8A and 1.0A chargers) - * However, the notifiee and notifier should be able to handle such - * string and if the notifiee can negotiate the protocol or identify, - * 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, + /* 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/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, + + /* Etc external connector */ + EXTCON_DOCK = 0x50, + EXTCON_JIG = 0x51, + EXTCON_MECHANICAL = 0x52, + + EXTCON_END, }; -extern const char extcon_cable_name[][CABLE_NAME_MAX + 1]; struct extcon_cable; @@ -78,7 +72,7 @@ struct extcon_cable; * struct extcon_dev - An extcon device represents one external connector. * @name: The name of this extcon device. Parent device name is * 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 * are disabled. * @mutually_exclusive: Array of mutually exclusive set of cables that cannot @@ -113,7 +107,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 +188,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 +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. - * 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 +272,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 +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 struct extcon_dev *devm_extcon_dev_allocate(struct device *dev, - const char **cables) + const enum extcon *cable) { return ERR_PTR(-ENOSYS); } @@ -312,20 +303,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 9ca958c4e94c..53c60806bcfb 100644 --- a/include/linux/extcon/extcon-adc-jack.h +++ b/include/linux/extcon/extcon-adc-jack.h @@ -44,7 +44,7 @@ struct adc_jack_cond { * @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; From 8e9bc36df56d6fa1db78032533c0e167f8a0bdcf Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 19 May 2015 19:58:49 +0900 Subject: [PATCH 19/21] extcon: Use capital letter for the name of external connectors This patch uses the capital letter for the name of external connectors to improve the readability instead of small letter. Cc: MyungJoo Ham Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon.c | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index a57355fc8fea..fce2687bde8e 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -39,27 +39,36 @@ #define CABLE_NAME_MAX 30 static const char *extcon_name[] = { + /* 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_LINE_IN] = "Line-in", - [EXTCON_LINE_OUT] = "Line-out", - [EXTCON_MICROPHONE] = "Microphone", - [EXTCON_HEADPHONE] = "Headphone", + [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_SPDIF_IN] = "SPDIF-in", - [EXTCON_SPDIF_OUT] = "SPDIF-out", - [EXTCON_VIDEO_IN] = "Video-in", - [EXTCON_VIDEO_OUT] = "Video-out", - [EXTCON_DOCK] = "Dock", + [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", + [EXTCON_MECHANICAL] = "MECHANICAL", + NULL, }; From 046050f6e623e442e9c71c525462ebd395dae526 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Tue, 19 May 2015 20:01:12 +0900 Subject: [PATCH 20/21] extcon: Update the prototype of extcon_register_notifier() with enum extcon 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 Reviewed-by: Krzysztof Kozlowski --- 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 fce2687bde8e..5099c11d8833 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -146,6 +146,16 @@ static int find_cable_index_by_name(struct extcon_dev *edev, const char *name) return find_cable_index_by_id(edev, id); } +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) { @@ -254,23 +264,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) { @@ -423,29 +437,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 @@ -491,11 +482,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; @@ -538,7 +528,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; @@ -548,21 +539,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 = find_cable_index_by_id(edev, 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; @@ -571,17 +565,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 = find_cable_index_by_id(edev, 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; @@ -893,7 +890,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 85c882f0029e..be9652b3a154 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -116,7 +116,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 */ @@ -155,8 +155,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. @@ -164,7 +162,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; @@ -240,10 +237,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. @@ -333,13 +330,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; } From f8df88081183bd4d3c461c617c3519445eb85642 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Wed, 27 May 2015 23:06:30 +0900 Subject: [PATCH 21/21] extcon: Remove optional print_name() function pointer of extcon_dev This patch removes the optional print_name() function pointer included in 'struct extcon_dev' because the extcon must maintain the consistent name of extcon device on sysfs instead of inconsistent name. After merged patch[1], extcon can maintain the consistent name of extcon device without any hard-coded device name. [1] https://lkml.org/lkml/2015/4/27/258 Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon.c | 8 -------- include/linux/extcon.h | 3 --- 2 files changed, 11 deletions(-) diff --git a/drivers/extcon/extcon.c b/drivers/extcon/extcon.c index 5099c11d8833..fafd428cae7f 100644 --- a/drivers/extcon/extcon.c +++ b/drivers/extcon/extcon.c @@ -207,14 +207,6 @@ static ssize_t name_show(struct device *dev, struct device_attribute *attr, { struct extcon_dev *edev = dev_get_drvdata(dev); - /* Optional callback given by the user */ - if (edev->print_name) { - int ret = edev->print_name(edev, buf); - - if (ret >= 0) - return ret; - } - return sprintf(buf, "%s\n", edev->name); } static DEVICE_ATTR_RO(name); diff --git a/include/linux/extcon.h b/include/linux/extcon.h index be9652b3a154..a7b224b20ecc 100644 --- a/include/linux/extcon.h +++ b/include/linux/extcon.h @@ -83,8 +83,6 @@ struct extcon_cable; * be attached simulataneously. {0x7, 0} is equivalent to * {0x3, 0x6, 0x5, 0}. If it is {0xFFFFFFFF, 0}, there * can be no simultaneous connections. - * @print_name: An optional callback to override the method to print the - * name of the extcon device. * @print_state: An optional callback to override the method to print the * status of the extcon device. * @dev: Device of this extcon. @@ -111,7 +109,6 @@ struct extcon_dev { const u32 *mutually_exclusive; /* Optional callbacks to override class functions */ - ssize_t (*print_name)(struct extcon_dev *edev, char *buf); ssize_t (*print_state)(struct extcon_dev *edev, char *buf); /* Internal data. Please do not set. */