mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Krzysztof Kozlowski <krzk@kernel.org>
To: Artur Weber <aweber.kernel@gmail.com>,
	Chanwoo Choi <cw00.choi@samsung.com>
Cc: Sebastian Reichel <sre@kernel.org>, Rob Herring <robh@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>, Lee Jones <lee@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Alim Akhtar <alim.akhtar@samsung.com>,
	linux-pm@vger.kernel.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-samsung-soc@vger.kernel.org,
	~postmarketos/upstreaming@lists.sr.ht,
	Henrik Grimler <henrik@grimler.se>,
	Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>,
	Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Subject: Re: [PATCH v4 05/10] power: supply: max77693: Add USB extcon detection for enabling charging
Date: Fri, 16 Aug 2024 12:00:00 +0200	[thread overview]
Message-ID: <bf5350ec-f722-4188-9e10-da5d5cb93e44@kernel.org> (raw)
In-Reply-To: <20240816-max77693-charger-extcon-v4-5-050a0a9bfea0@gmail.com>

On 16/08/2024 10:19, Artur Weber wrote:
> 1. Add a function that allows for enabling/disabling charging.
> 
> 2. Add a device tree property, "maxim,usb-connector", that can be used to
> specify a USB connector to use to detect whether a charging cable has
> been plugged in/out, and enable/disable charging accordingly.
> 
> The extcon listener/worker implementation is inspired by the rt5033_charger
> driver.
> 
> Tested-by: Henrik Grimler <henrik@grimler.se>
> Signed-off-by: Artur Weber <aweber.kernel@gmail.com>
> ---
> Changes in v4:
> - Fix missing connector property causing probe deferrals
> 

Thank you for your patch. There is something to discuss/improve.


> +static void max77693_charger_extcon_work(struct work_struct *work)
> +{
> +	struct max77693_charger *chg = container_of(work, struct max77693_charger,
> +						  cable.work);
> +	struct extcon_dev *edev = chg->cable.edev;
> +	int connector, state;
> +	int ret;
> +
> +	for (connector = EXTCON_USB_HOST; connector <= EXTCON_CHG_USB_PD;
> +	     connector++) {
> +		state = extcon_get_state(edev, connector);
> +		if (state == 1)
> +			break;
> +	}
> +
> +	switch (connector) {
> +	case EXTCON_CHG_USB_SDP:
> +	case EXTCON_CHG_USB_DCP:
> +	case EXTCON_CHG_USB_CDP:
> +	case EXTCON_CHG_USB_ACA:
> +	case EXTCON_CHG_USB_FAST:
> +	case EXTCON_CHG_USB_SLOW:
> +	case EXTCON_CHG_USB_PD:
> +		ret = max77693_set_charging(chg, true);
> +		if (ret) {
> +			dev_err(chg->dev, "failed to enable charging\n");
> +			break;
> +		}
> +		dev_info(chg->dev, "charging. connector type: %d\n",
> +			 connector);

This and next one should be also dev_dbg. It is completely normal
condition, kind of expected thing to happen, so users do not need to be
bugged every time they plugs cable.

> +		break;
> +	default:
> +		ret = max77693_set_charging(chg, false);
> +		if (ret) {
> +			dev_err(chg->dev, "failed to disable charging\n");
> +			break;
> +		}
> +		dev_info(chg->dev, "not charging. connector type: %d\n",
> +			 connector);
> +		break;
> +	}
> +
> +	power_supply_changed(chg->charger);
> +}
> +
> +static int max77693_charger_extcon_notifier(struct notifier_block *nb,
> +					  unsigned long event, void *param)
> +{
> +	struct max77693_charger *chg = container_of(nb, struct max77693_charger,
> +						    cable.nb);
> +
> +	schedule_work(&chg->cable.work);
> +
> +	return NOTIFY_OK;
> +}
> +
>  /*
>   * Sets charger registers to proper and safe default values.
>   */
> @@ -734,12 +814,34 @@ static int max77693_dt_init(struct device *dev, struct max77693_charger *chg)
>  {
>  	struct device_node *np = dev->of_node;
>  	struct power_supply_battery_info *battery_info;
> +	struct device_node *np_conn, *np_edev;
>  
>  	if (!np) {
>  		dev_err(dev, "no charger OF node\n");
>  		return -EINVAL;
>  	}
>  
> +	np_conn = of_parse_phandle(np, "maxim,usb-connector", 0);

Where is the reference dropped?

> +	if (np_conn) {
> +		np_edev = of_get_parent(np_conn);

Same question

> +
> +		chg->cable.edev = extcon_find_edev_by_node(np_edev);

You probably need device_link_add() as well. I don't think above extcon
code cares about it.

> +		if (IS_ERR(chg->cable.edev)) {
> +			/*
> +			 * In case of deferred extcon probe, defer our probe as well
> +			 * until it appears.
> +			 */
> +			if (PTR_ERR(chg->cable.edev) == -EPROBE_DEFER)
> +				return PTR_ERR(chg->cable.edev);
> +			/*
> +			 * Otherwise, ignore errors (the charger can run without a
> +			 * connector provided).
> +			 */
> +			dev_warn(dev, "no extcon device found in device-tree (%ld)\n",
> +				 PTR_ERR(chg->cable.edev));
> +		}
> +	}


Best regards,
Krzysztof


  reply	other threads:[~2024-08-16 10:00 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-16  8:19 [PATCH v4 00/10] power: supply: max77693: Toggle charging/OTG based on extcon status Artur Weber
2024-08-16  8:19 ` [PATCH v4 01/10] dt-bindings: power: supply: max77693: Add monitored-battery property Artur Weber
2024-08-16  8:19 ` [PATCH v4 02/10] dt-bindings: power: supply: max77693: Add maxim,usb-connector property Artur Weber
2024-08-16  8:19 ` [PATCH v4 03/10] power: supply: max77693: Expose input current limit and CC current properties Artur Weber
2024-08-16  9:49   ` Krzysztof Kozlowski
2024-08-16  8:19 ` [PATCH v4 04/10] power: supply: max77693: Set charge current limits during init Artur Weber
2024-08-16  9:54   ` Krzysztof Kozlowski
2024-08-16 14:25     ` Artur Weber
2024-08-16 15:40       ` Krzysztof Kozlowski
2024-08-27 17:14         ` Sebastian Reichel
2024-08-16  8:19 ` [PATCH v4 05/10] power: supply: max77693: Add USB extcon detection for enabling charging Artur Weber
2024-08-16 10:00   ` Krzysztof Kozlowski [this message]
2024-08-16  8:19 ` [PATCH v4 06/10] power: supply: max77693: Add support for detecting and enabling OTG Artur Weber
2024-08-16 10:00   ` Krzysztof Kozlowski
2024-08-16  8:19 ` [PATCH v4 07/10] power: supply: max77693: Set up charge/input current according to cable type Artur Weber
2024-08-16 10:02   ` Krzysztof Kozlowski
2024-08-16  8:19 ` [PATCH v4 08/10] ARM: dts: samsung: exynos4212-tab3: Add battery node with charge current value Artur Weber
2024-08-16 10:03   ` Krzysztof Kozlowski
2024-08-27 16:51     ` Sebastian Reichel
2024-08-16  8:19 ` [PATCH v4 09/10] ARM: dts: samsung: exynos4212-tab3: Add USB connector node Artur Weber
2024-08-16  8:19 ` [PATCH v4 10/10] ARM: dts: samsung: exynos4212-tab3: Drop CHARGER regulator Artur Weber
2024-08-16 10:04   ` Krzysztof Kozlowski
2024-08-27 16:58 ` (subset) [PATCH v4 00/10] power: supply: max77693: Toggle charging/OTG based on extcon status Sebastian Reichel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bf5350ec-f722-4188-9e10-da5d5cb93e44@kernel.org \
    --to=krzk@kernel.org \
    --cc=GNUtoo@cyberdimension.org \
    --cc=alim.akhtar@samsung.com \
    --cc=aweber.kernel@gmail.com \
    --cc=conor+dt@kernel.org \
    --cc=cw00.choi@samsung.com \
    --cc=devicetree@vger.kernel.org \
    --cc=henrik@grimler.se \
    --cc=krzk+dt@kernel.org \
    --cc=lee@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=robh@kernel.org \
    --cc=sre@kernel.org \
    --cc=wolfgit@wiedmeyer.de \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®