From 6aaad58c872db062f7ea2761421ca748bd0931cc Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Mon, 17 Aug 2020 09:00:00 +0200 Subject: extcon: ptn5150: Fix usage of atomic GPIO with sleeping GPIO chips The driver uses atomic version of gpiod_set_value() without any real reason. It is called in a workqueue under mutex so it could sleep there. Changing it to "can_sleep" flavor allows to use the driver with all GPIO chips. Fixes: 4ed754de2d66 ("extcon: Add support for ptn5150 extcon driver") Cc: Signed-off-by: Krzysztof Kozlowski Reviewed-by: Vijai Kumar K Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index d1c997599390..5f5252752644 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -127,7 +127,7 @@ static void ptn5150_irq_work(struct work_struct *work) case PTN5150_DFP_ATTACHED: extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false); - gpiod_set_value(info->vbus_gpiod, 0); + gpiod_set_value_cansleep(info->vbus_gpiod, 0); extcon_set_state_sync(info->edev, EXTCON_USB, true); break; @@ -138,9 +138,9 @@ static void ptn5150_irq_work(struct work_struct *work) PTN5150_REG_CC_VBUS_DETECTION_MASK) >> PTN5150_REG_CC_VBUS_DETECTION_SHIFT); if (vbus) - gpiod_set_value(info->vbus_gpiod, 0); + gpiod_set_value_cansleep(info->vbus_gpiod, 0); else - gpiod_set_value(info->vbus_gpiod, 1); + gpiod_set_value_cansleep(info->vbus_gpiod, 1); extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true); @@ -156,7 +156,7 @@ static void ptn5150_irq_work(struct work_struct *work) EXTCON_USB_HOST, false); extcon_set_state_sync(info->edev, EXTCON_USB, false); - gpiod_set_value(info->vbus_gpiod, 0); + gpiod_set_value_cansleep(info->vbus_gpiod, 0); } } -- cgit v1.2.3 From 45ce36f5d262d7361179c21143555ae2c4b261d2 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Mon, 17 Aug 2020 09:00:01 +0200 Subject: extcon: ptn5150: Use generic "interrupts" property Interrupts do not have to be always GPIO based so instead of expecting "int-gpios" property and converting the GPIO to an interrupt, just accept any interrupt via generic "interrupts" property. Keep support for old "int-gpios" for backward compatibility. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Vijai Kumar K Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index 5f5252752644..12e52ddbd77e 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -239,11 +239,6 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c, info->dev = &i2c->dev; info->i2c = i2c; - info->int_gpiod = devm_gpiod_get(&i2c->dev, "int", GPIOD_IN); - if (IS_ERR(info->int_gpiod)) { - dev_err(dev, "failed to get INT GPIO\n"); - return PTR_ERR(info->int_gpiod); - } info->vbus_gpiod = devm_gpiod_get(&i2c->dev, "vbus", GPIOD_IN); if (IS_ERR(info->vbus_gpiod)) { dev_err(dev, "failed to get VBUS GPIO\n"); @@ -267,22 +262,30 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c, return ret; } - if (info->int_gpiod) { + if (i2c->irq > 0) { + info->irq = i2c->irq; + } else { + info->int_gpiod = devm_gpiod_get(&i2c->dev, "int", GPIOD_IN); + if (IS_ERR(info->int_gpiod)) { + dev_err(dev, "failed to get INT GPIO\n"); + return PTR_ERR(info->int_gpiod); + } + info->irq = gpiod_to_irq(info->int_gpiod); if (info->irq < 0) { dev_err(dev, "failed to get INTB IRQ\n"); return info->irq; } + } - ret = devm_request_threaded_irq(dev, info->irq, NULL, - ptn5150_irq_handler, - IRQF_TRIGGER_FALLING | - IRQF_ONESHOT, - i2c->name, info); - if (ret < 0) { - dev_err(dev, "failed to request handler for INTB IRQ\n"); - return ret; - } + ret = devm_request_threaded_irq(dev, info->irq, NULL, + ptn5150_irq_handler, + IRQF_TRIGGER_FALLING | + IRQF_ONESHOT, + i2c->name, info); + if (ret < 0) { + dev_err(dev, "failed to request handler for INTB IRQ\n"); + return ret; } /* Allocate extcon device */ -- cgit v1.2.3 From e095882ee28a7b1c1c19c43606b83ec6a5912666 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Mon, 17 Aug 2020 09:00:02 +0200 Subject: extcon: ptn5150: Simplify getting vbus-gpios with flags Instead of obtaining GPIO as input and configuring it right after to output-low, just use proper GPIOD_OUT_LOW flag. Code is smaller and simpler. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Vijai Kumar K Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index 12e52ddbd77e..3b99ad41b06e 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -239,16 +239,11 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c, info->dev = &i2c->dev; info->i2c = i2c; - info->vbus_gpiod = devm_gpiod_get(&i2c->dev, "vbus", GPIOD_IN); + info->vbus_gpiod = devm_gpiod_get(&i2c->dev, "vbus", GPIOD_OUT_LOW); if (IS_ERR(info->vbus_gpiod)) { dev_err(dev, "failed to get VBUS GPIO\n"); return PTR_ERR(info->vbus_gpiod); } - ret = gpiod_direction_output(info->vbus_gpiod, 0); - if (ret) { - dev_err(dev, "failed to set VBUS GPIO direction\n"); - return -EINVAL; - } mutex_init(&info->mutex); -- cgit v1.2.3 From fa31f5871759bd635a81cce02991cb0ddf334ef5 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Mon, 17 Aug 2020 09:00:03 +0200 Subject: extcon: ptn5150: Lower the noisiness of probe The ptn5150 driver always prints device type on probe but as raw hex, without any translation to meaningful description. This is useful only for board bring up time so lower the verbosity to debug. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Vijai Kumar K Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index 3b99ad41b06e..a57fef384a29 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -199,8 +199,8 @@ static int ptn5150_init_dev_type(struct ptn5150_info *info) version_id = ((reg_data & PTN5150_REG_DEVICE_ID_VERSION_MASK) >> PTN5150_REG_DEVICE_ID_VERSION_SHIFT); - dev_info(info->dev, "Device type: version: 0x%x, vendor: 0x%x\n", - version_id, vendor_id); + dev_dbg(info->dev, "Device type: version: 0x%x, vendor: 0x%x\n", + version_id, vendor_id); /* Clear any existing interrupts */ ret = regmap_read(info->regmap, PTN5150_REG_INT_STATUS, ®_data); -- cgit v1.2.3 From 85256f611f664b0bd0f6c1c0693d0df6e096f279 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Mon, 17 Aug 2020 09:00:04 +0200 Subject: extcon: ptn5150: Check current USB mode when probing When machine boots up, the USB could be already in OTG mode. In such case there will be no interrupt coming to ptn5150 device and driver will report default state of nothing connected. Detection of USB connection would happen on first unplug of the cable. Factor out code for checking current connection mode and call it right after probe so the existing USB mode will be properly reported. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Vijai Kumar K Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 92 ++++++++++++++++++++++------------------- 1 file changed, 49 insertions(+), 43 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index a57fef384a29..342973726565 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -5,6 +5,7 @@ // Based on extcon-sm5502.c driver // Copyright (c) 2018-2019 by Vijai Kumar K // Author: Vijai Kumar K +// Copyright (c) 2020 Krzysztof Kozlowski #include #include @@ -83,12 +84,49 @@ static const struct regmap_config ptn5150_regmap_config = { .max_register = PTN5150_REG_END, }; +static void ptn5150_check_state(struct ptn5150_info *info) +{ + unsigned int port_status, reg_data, vbus; + int ret; + + ret = regmap_read(info->regmap, PTN5150_REG_CC_STATUS, ®_data); + if (ret) { + dev_err(info->dev, "failed to read CC STATUS %d\n", ret); + return; + } + + port_status = ((reg_data & + PTN5150_REG_CC_PORT_ATTACHMENT_MASK) >> + PTN5150_REG_CC_PORT_ATTACHMENT_SHIFT); + + switch (port_status) { + case PTN5150_DFP_ATTACHED: + extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false); + gpiod_set_value_cansleep(info->vbus_gpiod, 0); + extcon_set_state_sync(info->edev, EXTCON_USB, true); + break; + case PTN5150_UFP_ATTACHED: + extcon_set_state_sync(info->edev, EXTCON_USB, false); + vbus = ((reg_data & PTN5150_REG_CC_VBUS_DETECTION_MASK) >> + PTN5150_REG_CC_VBUS_DETECTION_SHIFT); + if (vbus) + gpiod_set_value_cansleep(info->vbus_gpiod, 0); + else + gpiod_set_value_cansleep(info->vbus_gpiod, 1); + + extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true); + break; + default: + dev_err(info->dev, "Unknown Port status : %x\n", port_status); + break; + } +} + static void ptn5150_irq_work(struct work_struct *work) { struct ptn5150_info *info = container_of(work, struct ptn5150_info, irq_work); int ret = 0; - unsigned int reg_data; unsigned int int_status; if (!info->edev) @@ -96,13 +134,6 @@ static void ptn5150_irq_work(struct work_struct *work) mutex_lock(&info->mutex); - ret = regmap_read(info->regmap, PTN5150_REG_CC_STATUS, ®_data); - if (ret) { - dev_err(info->dev, "failed to read CC STATUS %d\n", ret); - mutex_unlock(&info->mutex); - return; - } - /* Clear interrupt. Read would clear the register */ ret = regmap_read(info->regmap, PTN5150_REG_INT_STATUS, &int_status); if (ret) { @@ -116,41 +147,7 @@ static void ptn5150_irq_work(struct work_struct *work) cable_attach = int_status & PTN5150_REG_INT_CABLE_ATTACH_MASK; if (cable_attach) { - unsigned int port_status; - unsigned int vbus; - - port_status = ((reg_data & - PTN5150_REG_CC_PORT_ATTACHMENT_MASK) >> - PTN5150_REG_CC_PORT_ATTACHMENT_SHIFT); - - switch (port_status) { - case PTN5150_DFP_ATTACHED: - extcon_set_state_sync(info->edev, - EXTCON_USB_HOST, false); - gpiod_set_value_cansleep(info->vbus_gpiod, 0); - extcon_set_state_sync(info->edev, EXTCON_USB, - true); - break; - case PTN5150_UFP_ATTACHED: - extcon_set_state_sync(info->edev, EXTCON_USB, - false); - vbus = ((reg_data & - PTN5150_REG_CC_VBUS_DETECTION_MASK) >> - PTN5150_REG_CC_VBUS_DETECTION_SHIFT); - if (vbus) - gpiod_set_value_cansleep(info->vbus_gpiod, 0); - else - gpiod_set_value_cansleep(info->vbus_gpiod, 1); - - extcon_set_state_sync(info->edev, - EXTCON_USB_HOST, true); - break; - default: - dev_err(info->dev, - "Unknown Port status : %x\n", - port_status); - break; - } + ptn5150_check_state(info); } else { extcon_set_state_sync(info->edev, EXTCON_USB_HOST, false); @@ -302,6 +299,14 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c, if (ret) return -EINVAL; + /* + * Update current extcon state if for example OTG connection was there + * before the probe + */ + mutex_lock(&info->mutex); + ptn5150_check_state(info); + mutex_unlock(&info->mutex); + return 0; } @@ -334,4 +339,5 @@ subsys_initcall(ptn5150_i2c_init); MODULE_DESCRIPTION("NXP PTN5150 CC logic Extcon driver"); MODULE_AUTHOR("Vijai Kumar K "); +MODULE_AUTHOR("Krzysztof Kozlowski "); MODULE_LICENSE("GPL v2"); -- cgit v1.2.3 From fbaf3b67d4d27648daebf31cccd36eee8e26528b Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Mon, 17 Aug 2020 09:00:05 +0200 Subject: extcon: ptn5150: Make 'vbus-gpios' optional The PTN5150 chip can be used in hardware designs with only reporting of USB Type-C connection, without the VBUS control. The driver however unconditionally expected 'vbus-gpios'. Since all uses of the VBUS GPIO descriptor are NULL safe, the code can accept missing GPIO and provide only extcon status reporting. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Vijai Kumar K Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index 342973726565..008e664d8d56 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -238,8 +238,14 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c, info->i2c = i2c; info->vbus_gpiod = devm_gpiod_get(&i2c->dev, "vbus", GPIOD_OUT_LOW); if (IS_ERR(info->vbus_gpiod)) { - dev_err(dev, "failed to get VBUS GPIO\n"); - return PTR_ERR(info->vbus_gpiod); + ret = PTR_ERR(info->vbus_gpiod); + if (ret == -ENOENT) { + dev_info(dev, "No VBUS GPIO, ignoring VBUS control\n"); + info->vbus_gpiod = NULL; + } else { + dev_err(dev, "failed to get VBUS GPIO\n"); + return ret; + } } mutex_init(&info->mutex); -- cgit v1.2.3 From b8787ff8a4f4bc9255ce041f7b735d3d2b97b857 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Mon, 17 Aug 2020 09:00:06 +0200 Subject: extcon: ptn5150: Reduce the amount of logs on deferred probe There is no point to print deferred probe (and its failures to get resources) as an error. In case of multiple probe tries this would pollute the dmesg. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Vijai Kumar K Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index 008e664d8d56..c8611ff90990 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -243,7 +243,7 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c, dev_info(dev, "No VBUS GPIO, ignoring VBUS control\n"); info->vbus_gpiod = NULL; } else { - dev_err(dev, "failed to get VBUS GPIO\n"); + dev_err_probe(dev, ret, "failed to get VBUS GPIO\n"); return ret; } } @@ -255,8 +255,8 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c, info->regmap = devm_regmap_init_i2c(i2c, &ptn5150_regmap_config); if (IS_ERR(info->regmap)) { ret = PTR_ERR(info->regmap); - dev_err(info->dev, "failed to allocate register map: %d\n", - ret); + dev_err_probe(info->dev, ret, "failed to allocate register map: %d\n", + ret); return ret; } @@ -265,8 +265,9 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c, } else { info->int_gpiod = devm_gpiod_get(&i2c->dev, "int", GPIOD_IN); if (IS_ERR(info->int_gpiod)) { - dev_err(dev, "failed to get INT GPIO\n"); - return PTR_ERR(info->int_gpiod); + ret = PTR_ERR(info->int_gpiod); + dev_err_probe(dev, ret, "failed to get INT GPIO\n"); + return ret; } info->irq = gpiod_to_irq(info->int_gpiod); -- cgit v1.2.3 From 35f1f8f2a3fa0aa41bbb017d2e36248e6878ab68 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Mon, 17 Aug 2020 09:00:07 +0200 Subject: extcon: ptn5150: Convert to module_i2c_driver Use module_i2c_driver() to simplify driver init boilerplate. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Vijai Kumar K Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index c8611ff90990..690d878c65f1 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -337,12 +337,7 @@ static struct i2c_driver ptn5150_i2c_driver = { .probe = ptn5150_i2c_probe, .id_table = ptn5150_i2c_id, }; - -static int __init ptn5150_i2c_init(void) -{ - return i2c_add_driver(&ptn5150_i2c_driver); -} -subsys_initcall(ptn5150_i2c_init); +module_i2c_driver(ptn5150_i2c_driver); MODULE_DESCRIPTION("NXP PTN5150 CC logic Extcon driver"); MODULE_AUTHOR("Vijai Kumar K "); -- cgit v1.2.3 From 0b0549b6ac72a0fb15cf6e1493852d4046b8e0bb Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Mon, 17 Aug 2020 09:00:08 +0200 Subject: extcon: ptn5150: Convert to .probe_new The 'struct i2c_device_id' argument of probe function is not used, so convert the driver to simpler 'probe_new' interface. Signed-off-by: Krzysztof Kozlowski Reviewed-by: Vijai Kumar K Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index 690d878c65f1..8ba706fad887 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -218,8 +218,7 @@ static int ptn5150_init_dev_type(struct ptn5150_info *info) return 0; } -static int ptn5150_i2c_probe(struct i2c_client *i2c, - const struct i2c_device_id *id) +static int ptn5150_i2c_probe(struct i2c_client *i2c) { struct device *dev = &i2c->dev; struct device_node *np = i2c->dev.of_node; @@ -334,7 +333,7 @@ static struct i2c_driver ptn5150_i2c_driver = { .name = "ptn5150", .of_match_table = ptn5150_dt_match, }, - .probe = ptn5150_i2c_probe, + .probe_new = ptn5150_i2c_probe, .id_table = ptn5150_i2c_id, }; module_i2c_driver(ptn5150_i2c_driver); -- cgit v1.2.3 From f6dfb3c9a0bb4bc83f6583125bd3df24e38e5779 Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Mon, 13 Jul 2020 15:19:53 +0200 Subject: extcon: Replace HTTP links with HTTPS ones Rationale: Reduces attack surface on kernel devs opening the links for MITM as HTTPS traffic is much harder to manipulate. Deterministic algorithm: For each file: If not .svg: For each line: If doesn't contain `\bxmlns\b`: For each link, `\bhttp://[^# \t\r\n]*(?:\w|/)`: If neither `\bgnu\.org/license`, nor `\bmozilla\.org/MPL\b`: If both the HTTP and HTTPS versions return 200 OK and serve the same content: Replace HTTP with HTTPS. Signed-off-by: Alexander A. Klimov Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-palmas.c | 2 +- drivers/extcon/extcon-usb-gpio.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c index cea58d0cb457..e8e9eebe6b1d 100644 --- a/drivers/extcon/extcon-palmas.c +++ b/drivers/extcon/extcon-palmas.c @@ -2,7 +2,7 @@ /* * Palmas USB transceiver driver * - * Copyright (C) 2013 Texas Instruments Incorporated - http://www.ti.com + * Copyright (C) 2013 Texas Instruments Incorporated - https://www.ti.com * Author: Graeme Gregory * Author: Kishon Vijay Abraham I * Based on twl6030_usb.c diff --git a/drivers/extcon/extcon-usb-gpio.c b/drivers/extcon/extcon-usb-gpio.c index 98b5afa5b615..f06be6d4e2a9 100644 --- a/drivers/extcon/extcon-usb-gpio.c +++ b/drivers/extcon/extcon-usb-gpio.c @@ -2,7 +2,7 @@ /** * drivers/extcon/extcon-usb-gpio.c - USB GPIO extcon driver * - * Copyright (C) 2015 Texas Instruments Incorporated - http://www.ti.com + * Copyright (C) 2015 Texas Instruments Incorporated - https://www.ti.com * Author: Roger Quadros */ -- cgit v1.2.3 From 611e92a0a3dc654be2cca3617a34b433815cee00 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Wed, 26 Aug 2020 18:23:41 +0300 Subject: extcon: ptn5150: Deduplicate parts of dev_err_probe() dev_err_probe() is designed to be used like return dev_err_probe(dev, ret, "Error message\n"); Hence no need to have a separate return statement. Besides that dev_err_probe() prints already returned error code, no need to repeat that either. Signed-off-by: Andy Shevchenko Reviewed-by: Krzysztof Kozlowski Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index 8ba706fad887..051bf374b43f 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -242,8 +242,7 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c) dev_info(dev, "No VBUS GPIO, ignoring VBUS control\n"); info->vbus_gpiod = NULL; } else { - dev_err_probe(dev, ret, "failed to get VBUS GPIO\n"); - return ret; + return dev_err_probe(dev, ret, "failed to get VBUS GPIO\n"); } } @@ -253,10 +252,8 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c) info->regmap = devm_regmap_init_i2c(i2c, &ptn5150_regmap_config); if (IS_ERR(info->regmap)) { - ret = PTR_ERR(info->regmap); - dev_err_probe(info->dev, ret, "failed to allocate register map: %d\n", - ret); - return ret; + return dev_err_probe(info->dev, PTR_ERR(info->regmap), + "failed to allocate register map\n"); } if (i2c->irq > 0) { @@ -264,9 +261,8 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c) } else { info->int_gpiod = devm_gpiod_get(&i2c->dev, "int", GPIOD_IN); if (IS_ERR(info->int_gpiod)) { - ret = PTR_ERR(info->int_gpiod); - dev_err_probe(dev, ret, "failed to get INT GPIO\n"); - return ret; + return dev_err_probe(dev, PTR_ERR(info->int_gpiod), + "failed to get INT GPIO\n"); } info->irq = gpiod_to_irq(info->int_gpiod); -- cgit v1.2.3 From 7e3b1caffcfd8c260b570f21a8dc5abb5b00672c Mon Sep 17 00:00:00 2001 From: Ramuthevar Vadivel Murugan Date: Thu, 27 Aug 2020 11:56:32 +0800 Subject: extcon: ptn5150: Switch to GENMASK() and BIT() macros Switch to GENMASK() and BIT() macros. Signed-off-by: Ramuthevar Vadivel Murugan Reviewed-by: Krzysztof Kozlowski Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 43 +++++++++++------------------------------ 1 file changed, 11 insertions(+), 32 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index 051bf374b43f..841c9fe211f1 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -7,6 +7,7 @@ // Author: Vijai Kumar K // Copyright (c) 2020 Krzysztof Kozlowski +#include #include #include #include @@ -35,29 +36,13 @@ enum ptn5150_reg { #define PTN5150_UFP_ATTACHED 0x2 /* Define PTN5150 MASK/SHIFT constant */ -#define PTN5150_REG_DEVICE_ID_VENDOR_SHIFT 0 -#define PTN5150_REG_DEVICE_ID_VENDOR_MASK \ - (0x3 << PTN5150_REG_DEVICE_ID_VENDOR_SHIFT) +#define PTN5150_REG_DEVICE_ID_VERSION GENMASK(7, 3) +#define PTN5150_REG_DEVICE_ID_VENDOR GENMASK(2, 0) -#define PTN5150_REG_DEVICE_ID_VERSION_SHIFT 3 -#define PTN5150_REG_DEVICE_ID_VERSION_MASK \ - (0x1f << PTN5150_REG_DEVICE_ID_VERSION_SHIFT) - -#define PTN5150_REG_CC_PORT_ATTACHMENT_SHIFT 2 -#define PTN5150_REG_CC_PORT_ATTACHMENT_MASK \ - (0x7 << PTN5150_REG_CC_PORT_ATTACHMENT_SHIFT) - -#define PTN5150_REG_CC_VBUS_DETECTION_SHIFT 7 -#define PTN5150_REG_CC_VBUS_DETECTION_MASK \ - (0x1 << PTN5150_REG_CC_VBUS_DETECTION_SHIFT) - -#define PTN5150_REG_INT_CABLE_ATTACH_SHIFT 0 -#define PTN5150_REG_INT_CABLE_ATTACH_MASK \ - (0x1 << PTN5150_REG_INT_CABLE_ATTACH_SHIFT) - -#define PTN5150_REG_INT_CABLE_DETACH_SHIFT 1 -#define PTN5150_REG_INT_CABLE_DETACH_MASK \ - (0x1 << PTN5150_REG_CC_CABLE_DETACH_SHIFT) +#define PTN5150_REG_CC_PORT_ATTACHMENT GENMASK(4, 2) +#define PTN5150_REG_CC_VBUS_DETECTION BIT(7) +#define PTN5150_REG_INT_CABLE_ATTACH_MASK BIT(0) +#define PTN5150_REG_INT_CABLE_DETACH_MASK BIT(1) struct ptn5150_info { struct device *dev; @@ -95,9 +80,7 @@ static void ptn5150_check_state(struct ptn5150_info *info) return; } - port_status = ((reg_data & - PTN5150_REG_CC_PORT_ATTACHMENT_MASK) >> - PTN5150_REG_CC_PORT_ATTACHMENT_SHIFT); + port_status = FIELD_GET(PTN5150_REG_CC_PORT_ATTACHMENT, reg_data); switch (port_status) { case PTN5150_DFP_ATTACHED: @@ -107,8 +90,7 @@ static void ptn5150_check_state(struct ptn5150_info *info) break; case PTN5150_UFP_ATTACHED: extcon_set_state_sync(info->edev, EXTCON_USB, false); - vbus = ((reg_data & PTN5150_REG_CC_VBUS_DETECTION_MASK) >> - PTN5150_REG_CC_VBUS_DETECTION_SHIFT); + vbus = FIELD_GET(PTN5150_REG_CC_VBUS_DETECTION, reg_data); if (vbus) gpiod_set_value_cansleep(info->vbus_gpiod, 0); else @@ -191,11 +173,8 @@ static int ptn5150_init_dev_type(struct ptn5150_info *info) return -EINVAL; } - vendor_id = ((reg_data & PTN5150_REG_DEVICE_ID_VENDOR_MASK) >> - PTN5150_REG_DEVICE_ID_VENDOR_SHIFT); - version_id = ((reg_data & PTN5150_REG_DEVICE_ID_VERSION_MASK) >> - PTN5150_REG_DEVICE_ID_VERSION_SHIFT); - + vendor_id = FIELD_GET(PTN5150_REG_DEVICE_ID_VENDOR, reg_data); + version_id = FIELD_GET(PTN5150_REG_DEVICE_ID_VERSION, reg_data); dev_dbg(info->dev, "Device type: version: 0x%x, vendor: 0x%x\n", version_id, vendor_id); -- cgit v1.2.3 From ea6a95d09c1bd28113be8e90fb87c45807b1e674 Mon Sep 17 00:00:00 2001 From: Ramuthevar Vadivel Murugan Date: Thu, 27 Aug 2020 14:51:28 +0800 Subject: extcon: ptn5150: Set the VBUS and POLARITY property capability Set the capability value of property for VBUS and POLARITY. Signed-off-by: Ramuthevar Vadivel Murugan [cw00.choi: Replace the space with tab for the indentation] Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index 841c9fe211f1..dda5b3a3a908 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -275,6 +275,13 @@ static int ptn5150_i2c_probe(struct i2c_client *i2c) return ret; } + extcon_set_property_capability(info->edev, EXTCON_USB, + EXTCON_PROP_USB_VBUS); + extcon_set_property_capability(info->edev, EXTCON_USB_HOST, + EXTCON_PROP_USB_VBUS); + extcon_set_property_capability(info->edev, EXTCON_USB_HOST, + EXTCON_PROP_USB_TYPEC_POLARITY); + /* Initialize PTN5150 device and print vendor id and version id */ ret = ptn5150_init_dev_type(info); if (ret) -- cgit v1.2.3 From 4e984d83f444901e0187fdb228ce912e2fb7c6ff Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Sat, 29 Aug 2020 14:43:53 +0200 Subject: extcon: max14577: Return error code of extcon_dev_allocate() devm_extcon_dev_allocate() can fail of multiple reasons. The call returns proper error code on failure so pass it instead of fixed ENOMEM. Signed-off-by: Krzysztof Kozlowski Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-max14577.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-max14577.c b/drivers/extcon/extcon-max14577.c index cc47d626095c..ace523924e58 100644 --- a/drivers/extcon/extcon-max14577.c +++ b/drivers/extcon/extcon-max14577.c @@ -713,7 +713,7 @@ static int max14577_muic_probe(struct platform_device *pdev) max14577_extcon_cable); if (IS_ERR(info->edev)) { dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); - return -ENOMEM; + return PTR_ERR(info->edev); } ret = devm_extcon_dev_register(&pdev->dev, info->edev); -- cgit v1.2.3 From 1f339f3384e85b3610482d4af7e500227311c5f2 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Sat, 29 Aug 2020 14:43:54 +0200 Subject: extcon: max77693: Return error code of extcon_dev_allocate() devm_extcon_dev_allocate() can fail of multiple reasons. The call returns proper error code on failure so pass it instead of fixed ENOMEM. Signed-off-by: Krzysztof Kozlowski Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-max77693.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-max77693.c b/drivers/extcon/extcon-max77693.c index 32fc5a66ffa9..4a410fd2ea9a 100644 --- a/drivers/extcon/extcon-max77693.c +++ b/drivers/extcon/extcon-max77693.c @@ -1157,7 +1157,7 @@ static int max77693_muic_probe(struct platform_device *pdev) max77693_extcon_cable); if (IS_ERR(info->edev)) { dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); - return -ENOMEM; + return PTR_ERR(info->edev); } ret = devm_extcon_dev_register(&pdev->dev, info->edev); -- cgit v1.2.3 From a4cf11faf86243bab418f406cc8ebf16bd91bcf2 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Sat, 29 Aug 2020 14:43:55 +0200 Subject: extcon: max77843: Return error code of extcon_dev_allocate() devm_extcon_dev_allocate() can fail of multiple reasons. The call returns proper error code on failure so pass it instead of fixed ENOMEM. Signed-off-by: Krzysztof Kozlowski Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-max77843.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-max77843.c b/drivers/extcon/extcon-max77843.c index e6b50ca83008..8e6e97ec65a8 100644 --- a/drivers/extcon/extcon-max77843.c +++ b/drivers/extcon/extcon-max77843.c @@ -845,7 +845,7 @@ static int max77843_muic_probe(struct platform_device *pdev) max77843_extcon_cable); if (IS_ERR(info->edev)) { dev_err(&pdev->dev, "Failed to allocate memory for extcon\n"); - ret = -ENODEV; + ret = PTR_ERR(info->edev); goto err_muic_irq; } -- cgit v1.2.3 From ce90c3c9b3ab2e25530a9bb313f3c51718d5d96b Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Sat, 29 Aug 2020 14:43:56 +0200 Subject: extcon: max8997: Return error code of extcon_dev_allocate() devm_extcon_dev_allocate() can fail of multiple reasons. The call returns proper error code on failure so pass it instead of fixed ENOMEM. Signed-off-by: Krzysztof Kozlowski Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-max8997.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-max8997.c b/drivers/extcon/extcon-max8997.c index 172e116ac1ce..337b0eea4e62 100644 --- a/drivers/extcon/extcon-max8997.c +++ b/drivers/extcon/extcon-max8997.c @@ -674,7 +674,7 @@ static int max8997_muic_probe(struct platform_device *pdev) info->edev = devm_extcon_dev_allocate(&pdev->dev, max8997_extcon_cable); if (IS_ERR(info->edev)) { dev_err(&pdev->dev, "failed to allocate memory for extcon\n"); - ret = -ENOMEM; + ret = PTR_ERR(info->edev); goto err_irq; } -- cgit v1.2.3 From d0f668101713bd029e7d19a4fe9ddab9a33c8f85 Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Fri, 28 Aug 2020 17:13:37 +0200 Subject: extcon: palmas: Simplify with dev_err_probe() Common pattern of handling deferred probe can be simplified with dev_err_probe(). Less code and the error value gets printed. Signed-off-by: Krzysztof Kozlowski Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-palmas.c | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-palmas.c b/drivers/extcon/extcon-palmas.c index e8e9eebe6b1d..a2852bcc5f0d 100644 --- a/drivers/extcon/extcon-palmas.c +++ b/drivers/extcon/extcon-palmas.c @@ -205,21 +205,15 @@ static int palmas_usb_probe(struct platform_device *pdev) palmas_usb->id_gpiod = devm_gpiod_get_optional(&pdev->dev, "id", GPIOD_IN); - if (PTR_ERR(palmas_usb->id_gpiod) == -EPROBE_DEFER) { - return -EPROBE_DEFER; - } else if (IS_ERR(palmas_usb->id_gpiod)) { - dev_err(&pdev->dev, "failed to get id gpio\n"); - return PTR_ERR(palmas_usb->id_gpiod); - } + if (IS_ERR(palmas_usb->id_gpiod)) + return dev_err_probe(&pdev->dev, PTR_ERR(palmas_usb->id_gpiod), + "failed to get id gpio\n"); palmas_usb->vbus_gpiod = devm_gpiod_get_optional(&pdev->dev, "vbus", GPIOD_IN); - if (PTR_ERR(palmas_usb->vbus_gpiod) == -EPROBE_DEFER) { - return -EPROBE_DEFER; - } else if (IS_ERR(palmas_usb->vbus_gpiod)) { - dev_err(&pdev->dev, "failed to get vbus gpio\n"); - return PTR_ERR(palmas_usb->vbus_gpiod); - } + if (IS_ERR(palmas_usb->vbus_gpiod)) + return dev_err_probe(&pdev->dev, PTR_ERR(palmas_usb->vbus_gpiod), + "failed to get id gpio\n"); if (palmas_usb->enable_id_detection && palmas_usb->id_gpiod) { palmas_usb->enable_id_detection = false; -- cgit v1.2.3 From b9a32f624f7f1f0dc408fb7e62fbf10a8fe3ad9a Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Wed, 9 Sep 2020 17:01:28 +0200 Subject: extcon: ptn5150: Use defines for registers The register addresses are not continuous, so use simple defines for them. This also makes it easier to find the address for register. No functional change. Signed-off-by: Krzysztof Kozlowski Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index dda5b3a3a908..1b68f56d8372 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -19,18 +19,16 @@ #include /* PTN5150 registers */ -enum ptn5150_reg { - PTN5150_REG_DEVICE_ID = 0x01, - PTN5150_REG_CONTROL, - PTN5150_REG_INT_STATUS, - PTN5150_REG_CC_STATUS, - PTN5150_REG_CON_DET = 0x09, - PTN5150_REG_VCONN_STATUS, - PTN5150_REG_RESET, - PTN5150_REG_INT_MASK = 0x18, - PTN5150_REG_INT_REG_STATUS, - PTN5150_REG_END, -}; +#define PTN5150_REG_DEVICE_ID 0x01 +#define PTN5150_REG_CONTROL 0x02 +#define PTN5150_REG_INT_STATUS 0x03 +#define PTN5150_REG_CC_STATUS 0x04 +#define PTN5150_REG_CON_DET 0x09 +#define PTN5150_REG_VCONN_STATUS 0x0a +#define PTN5150_REG_RESET 0x0b +#define PTN5150_REG_INT_MASK 0x18 +#define PTN5150_REG_INT_REG_STATUS 0x19 +#define PTN5150_REG_END PTN5150_REG_INT_REG_STATUS #define PTN5150_DFP_ATTACHED 0x1 #define PTN5150_UFP_ATTACHED 0x2 -- cgit v1.2.3 From 6be65ed4f86aa7c4ba5c0193202d563f098e783f Mon Sep 17 00:00:00 2001 From: Krzysztof Kozlowski Date: Wed, 9 Sep 2020 17:01:29 +0200 Subject: extcon: ptn5150: Do not print error during probe if nothing is attached The commit 85256f611f66 ("extcon: ptn5150: Check current USB mode when probing") reused code for checking CC status register in the probe path to determine what is initially connected. However if nothing is connected, the CC status register will have 0x0 value and print an error message: ptn5150 1-003d: Unknown Port status : 0 This is not an error. Also any other unknown port status values are not really errors but unhandled cases. Fixes: 85256f611f66 ("extcon: ptn5150: Check current USB mode when probing") Signed-off-by: Krzysztof Kozlowski Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-ptn5150.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c index 1b68f56d8372..5b9a3cf8df26 100644 --- a/drivers/extcon/extcon-ptn5150.c +++ b/drivers/extcon/extcon-ptn5150.c @@ -97,7 +97,6 @@ static void ptn5150_check_state(struct ptn5150_info *info) extcon_set_state_sync(info->edev, EXTCON_USB_HOST, true); break; default: - dev_err(info->dev, "Unknown Port status : %x\n", port_status); break; } } -- cgit v1.2.3 From dbc888072a976c2a7f74ad2df1ca3e6894f96002 Mon Sep 17 00:00:00 2001 From: Liu Shixin Date: Mon, 14 Sep 2020 14:54:00 +0800 Subject: extcon: axp288: Use module_platform_driver to simplify the code module_platform_driver() makes the code simpler by eliminating boilerplate code. Signed-off-by: Liu Shixin Reviewed-by: Hans de Goede Signed-off-by: Chanwoo Choi --- drivers/extcon/extcon-axp288.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'drivers/extcon') diff --git a/drivers/extcon/extcon-axp288.c b/drivers/extcon/extcon-axp288.c index 525345367260..fdb31954cf2b 100644 --- a/drivers/extcon/extcon-axp288.c +++ b/drivers/extcon/extcon-axp288.c @@ -491,18 +491,7 @@ static struct platform_driver axp288_extcon_driver = { .pm = &axp288_extcon_pm_ops, }, }; - -static int __init axp288_extcon_init(void) -{ - return platform_driver_register(&axp288_extcon_driver); -} -module_init(axp288_extcon_init); - -static void __exit axp288_extcon_exit(void) -{ - platform_driver_unregister(&axp288_extcon_driver); -} -module_exit(axp288_extcon_exit); +module_platform_driver(axp288_extcon_driver); MODULE_AUTHOR("Ramakrishna Pallala "); MODULE_AUTHOR("Hans de Goede "); -- cgit v1.2.3