Re: [PATCH 08/11] extcon: ptn5150: Check current USB mode when probing

Krzysztof Kozlowski
2020-08-13T06:03:30Z

On Wed, Aug 12, 2020 at 06:29:55PM +0200, Krzysztof Kozlowski wrote:
> 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 <krzk@kernel.org>
> ---
> drivers/extcon/extcon-ptn5150.c | 93 ++++++++++++++++++---------------
> 1 file changed, 50 insertions(+), 43 deletions(-)
>
> diff --git a/drivers/extcon/extcon-ptn5150.c b/drivers/extcon/extcon-ptn5150.c
> index a57fef384a29..bbb185378e4b 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 <vijaikumar.kanagarajan@gmail.com>
> +// Copyright (c) 2020 Krzysztof Kozlowski <krzk@kernel.org>
>
> #include <linux/err.h>
> #include <linux/i2c.h>
> @@ -83,12 +84,50 @@ 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, &reg_data);
> + if (ret) {
> + dev_err(info->dev, "failed to read CC STATUS %d\n", ret);
> + mutex_unlock(&info->mutex);

There is a double mutex unlock here, I'll send a v2.

Best regards,
Krzysztof