mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Konrad Dybcio <konrad.dybcio@oss.qualcomm.com>
To: Kamal Wadhwa <kamal.wadhwa@oss.qualcomm.com>,
	Sebastian Reichel <sre@kernel.org>
Cc: linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] power: supply: qcom_battmgr: Add multi-port USB-C power supply support
Date: Thu, 3 Sep 2026 09:13:58 +0200	[thread overview]
Message-ID: <be340fda-a8d6-40ab-a073-5acce519a90f@oss.qualcomm.com> (raw)
In-Reply-To: <20260806-b4-battmgr-multiport-usb-v2-1-1a6dd1e06cc2@oss.qualcomm.com>

On 8/6/26 5:06 PM, Kamal Wadhwa wrote:
> Extend the qcom_battmgr driver to report up to MAX_USB_PORTS (3)
> USB-C power supply ports on the X1E80100 & Glymur platform, which
> exposes more than one charger port to firmware.

[...]

>  #define BATTMGR_USB_PROPERTY_GET	0x32
>  #define BATTMGR_USB_PROPERTY_SET	0x33
> +#define BATTMGR_USB2_PROPERTY_GET	0xC0
> +#define BATTMGR_USB2_PROPERTY_SET	0xC1
> +#define BATTMGR_USB3_PROPERTY_GET	0xC2
> +#define BATTMGR_USB3_PROPERTY_SET	0xC3

nit: let's keep the defines lowercase

[...]


> +static int qcom_battmgr_usb_x1e80100_update(struct qcom_battmgr *battmgr,
> +					    enum power_supply_property psp)
> +{
> +	unsigned int prop;
> +	int ret;
> +
> +	if (psp >= ARRAY_SIZE(x1e80100_usb_prop_map))
> +		return -EINVAL;
> +
> +	prop = x1e80100_usb_prop_map[psp];
> +
> +	mutex_lock(&battmgr->lock);
> +	ret = qcom_battmgr_request_property(battmgr, BATTMGR_USB_PROPERTY_GET, prop, 0);
> +	mutex_unlock(&battmgr->lock);
> +
> +	return ret;
> +}

I'd rather you pass the array and its size to this function rather than
wholly duplicating it

[...]

> +static int qcom_battmgr_usb_x1e80100_get_property(struct power_supply *psy,
> +						   enum power_supply_property psp,
> +						   union power_supply_propval *val)

Likewise there's no reason to duplicate this one

[...]

> +static int qcom_battmgr_usb2_x1e80100_update(struct qcom_battmgr *battmgr,
> +					     enum power_supply_property psp)

We can add another parameter for the property and save some duplication
as well

[...]

> +static int qcom_battmgr_usb2_get_property(struct power_supply *psy,
> +					  enum power_supply_property psp,
> +					  union power_supply_propval *val)
> +{

This function is also wholly duplicated, we can extract out the common
part

[...]

>  static const enum power_supply_property sc8280xp_usb_props[] = {
>  	POWER_SUPPLY_PROP_ONLINE,
> +	POWER_SUPPLY_PROP_VOLTAGE_NOW,
> +	POWER_SUPPLY_PROP_VOLTAGE_MAX,
> +	POWER_SUPPLY_PROP_CURRENT_NOW,
> +	POWER_SUPPLY_PROP_CURRENT_MAX,
> +	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
> +	POWER_SUPPLY_PROP_USB_TYPE,
>  };

Hm, no one noticed this list was very short for a long time..

[...]

> +	case BATTMGR_USB_PROPERTY_GET:
> +		property = le32_to_cpu(resp->intval.property);
> +		if (payload_len != sizeof(resp->intval)) {
> +			dev_warn(battmgr->dev,
> +				 "invalid payload length for %#x request: %zd\n",
> +				 property, payload_len);
> +			battmgr->error = -ENODATA;
> +			return;
> +		}

We can do something like:

if (opcode == BATTMGR_USB2_PROPERTY_GET)
	usb_info = &battmgr->usb2;
else if (opcode == BATTMGR_USB3_PROPERTY_GET)
	usb_info = &battmgr->usb3;
else
	usb_info = &battmgr->usb;

and then have a shared case for all 3 in the switch-statement

[...]

> +static char *qcom_battmgr_battery[] = { "battery" };
> +
>  static void qcom_battmgr_enable_worker(struct work_struct *work)
>  {
>  	struct qcom_battmgr *battmgr = container_of(work, struct qcom_battmgr, enable_work);
> @@ -1591,11 +1989,53 @@ static void qcom_battmgr_enable_worker(struct work_struct *work)
>  		.hdr.type = cpu_to_le32(PMIC_GLINK_NOTIFY),
>  		.hdr.opcode = cpu_to_le32(BATTMGR_REQUEST_NOTIFICATION),
>  	};
> +	struct power_supply *psy;
>  	int ret;
> +	int num_ports_fw = 0;
>  
>  	ret = qcom_battmgr_request(battmgr, &req, sizeof(req));
>  	if (ret)
>  		dev_err(battmgr->dev, "failed to request power notifications\n");
> +
> +	if (battmgr->variant == QCOM_BATTMGR_X1E80100) {
> +		mutex_lock(&battmgr->lock);
> +		ret = qcom_battmgr_request_property(battmgr, BATTMGR_USB_PROPERTY_GET,
> +						     USB_NUM_PORTS, 0);
> +		mutex_unlock(&battmgr->lock);
> +		if (ret < 0) {
> +			dev_dbg(battmgr->dev, "Failed to read USB_NUM_PORTS from SoCCP, rc=%d\n",
> +				ret);

The pmic-glink drivers are supposed not to care what's on the other end,
let's just drop the "from SoCCP" part.

Also, the existing way this driver prints errors is:

"A problem occured: %d\n", without a 'rc=' prefix

Konrad

  reply	other threads:[~2026-09-03  7:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-06 15:06 Kamal Wadhwa
2026-09-03  7:13 ` Konrad Dybcio [this message]
2026-09-03  7:15 ` Konrad Dybcio
2026-09-03  7:44 ` Konrad Dybcio

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=be340fda-a8d6-40ab-a073-5acce519a90f@oss.qualcomm.com \
    --to=konrad.dybcio@oss.qualcomm.com \
    --cc=kamal.wadhwa@oss.qualcomm.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=sre@kernel.org \
    /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®