From: Samuel Kayode <samuel.kayode@savoirfairelinux.com>
To: Frank Li <Frank.li@nxp.com>
Cc: Lee Jones <lee@kernel.org>, Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Liam Girdwood <lgirdwood@gmail.com>,
Mark Brown <broonie@kernel.org>,
Dmitry Torokhov <dmitry.torokhov@gmail.com>,
Sebastian Reichel <sre@kernel.org>,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-input@vger.kernel.org, linux-pm@vger.kernel.org,
Abel Vesa <abelvesa@kernel.org>, Abel Vesa <abelvesa@linux.com>,
Robin Gong <b38343@freescale.com>,
Robin Gong <yibin.gong@nxp.com>,
Enric Balletbo i Serra <eballetbo@gmail.com>
Subject: Re: [PATCH v5 5/6] power: supply: pf1550: add battery charger support
Date: Wed, 11 Jun 2025 10:30:08 -0400 [thread overview]
Message-ID: <aEmS8N8gdz8-6GBD@fedora> (raw)
In-Reply-To: <aEifg/+mIuVVm6El@lizhi-Precision-Tower-5810>
On Tue, Jun 10, 2025 at 05:11:31PM -0400, Frank Li wrote:
> > +static void pf1550_chg_vbus_work(struct work_struct *work)
> > +{
> > + struct pf1550_charger *chg = container_of(to_delayed_work(work),
> > + struct pf1550_charger,
> > + vbus_sense_work);
> > + unsigned int data;
> > + bool psy_changed = false;
> > +
> > + if (!chg->charger)
> > + return;
> > +
> > + if (regmap_read(chg->pf1550->regmap, PF1550_CHARG_REG_VBUS_SNS, &data)) {
> > + dev_err(chg->dev, "Read VBUS_SNS error.\n");
> > + return;
> > + }
> > +
> > + mutex_lock(&chg->mutex);
> > +
> > + if (data & PF1550_VBUS_UVLO) {
> > + chg->psy_desc.type = POWER_SUPPLY_TYPE_BATTERY;
> > + psy_changed = true;
> > + dev_dbg(chg->dev, "VBUS detached.\n");
> > + }
> > + if (data & PF1550_VBUS_IN2SYS)
> > + dev_dbg(chg->dev, "VBUS_IN2SYS_SNS.\n");
> > + if (data & PF1550_VBUS_OVLO)
> > + dev_dbg(chg->dev, "VBUS_OVLO_SNS.\n");
> > + if (data & PF1550_VBUS_VALID) {
> > + chg->psy_desc.type = POWER_SUPPLY_TYPE_MAINS;
> > + psy_changed = true;
> > + dev_dbg(chg->dev, "VBUS attached.\n");
> > + }
> > +
> > + mutex_unlock(&chg->mutex);
>
> not sure why need lock here, you just update chg->psy_desc.type?
>
It prevents concurrent access in this delayed work and in pf1550_reg_init.
However, it's unlikely that the probe is still active during the first execution
of the delayed work. So, i also think this mutex can be removed.
> > +
> > + if (psy_changed)
> > + power_supply_changed(chg->charger);
> > +}
> > +
> > +static irqreturn_t pf1550_charger_irq_handler(int irq, void *data)
> > +{
> > + struct pf1550_charger *chg = data;
> > + struct device *dev = chg->dev;
> > + struct platform_device *pdev = to_platform_device(dev);
> > + int i, irq_type = -1;
> > +
> > + for (i = 0; i < PF1550_CHARGER_IRQ_NR; i++)
> > + if (irq == platform_get_irq(pdev, i))
> > + irq_type = i;
> > +
> > + switch (irq_type) {
> > + case PF1550_CHARG_IRQ_BAT2SOCI:
> > + dev_info(dev, "BAT to SYS Overcurrent interrupt.\n");
> > + break;
> > + case PF1550_CHARG_IRQ_BATI:
> > + schedule_delayed_work(&chg->bat_sense_work,
> > + msecs_to_jiffies(10));
> > + break;
> > + case PF1550_CHARG_IRQ_CHGI:
> > + schedule_delayed_work(&chg->chg_sense_work,
> > + msecs_to_jiffies(10));
> > + break;
> > + case PF1550_CHARG_IRQ_VBUSI:
> > + schedule_delayed_work(&chg->vbus_sense_work,
> > + msecs_to_jiffies(10));
> > + break;
> > + case PF1550_CHARG_IRQ_THMI:
> > + dev_info(dev, "Thermal interrupt.\n");
> > + break;
> > + default:
> > + dev_err(dev, "unknown interrupt occurred.\n");
> > + }
> > +
> > + return IRQ_HANDLED;
> > +}
> > +
> > +static int pf1550_charger_probe(struct platform_device *pdev)
> > + mutex_init(&chg->mutex);
...
> > +
> > + INIT_DELAYED_WORK(&chg->vbus_sense_work, pf1550_chg_vbus_work);
> > + INIT_DELAYED_WORK(&chg->chg_sense_work, pf1550_chg_chg_work);
> > + INIT_DELAYED_WORK(&chg->bat_sense_work, pf1550_chg_bat_work);
...
> > + ret = pf1550_reg_init(chg);
Thanks,
Sam
next prev parent reply other threads:[~2025-06-11 14:30 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-10 19:47 [PATCH v5 0/6] add support for pf1550 PMIC MFD-based drivers Samuel Kayode via B4 Relay
2025-06-10 19:47 ` [PATCH v5 1/6] dt-bindings: mfd: add pf1550 Samuel Kayode via B4 Relay
2025-06-10 19:47 ` [PATCH v5 2/6] mfd: pf1550: add core mfd driver Samuel Kayode via B4 Relay
2025-06-10 20:48 ` Frank Li
2025-06-10 19:47 ` [PATCH v5 3/6] regulator: pf1550: add support for regulator Samuel Kayode via B4 Relay
2025-06-10 20:58 ` Frank Li
2025-06-11 10:38 ` Mark Brown
2025-06-10 19:47 ` [PATCH v5 4/6] input: pf1550: add onkey support Samuel Kayode via B4 Relay
2025-06-10 21:02 ` Frank Li
2025-06-10 19:47 ` [PATCH v5 5/6] power: supply: pf1550: add battery charger support Samuel Kayode via B4 Relay
2025-06-10 21:11 ` Frank Li
2025-06-11 14:30 ` Samuel Kayode [this message]
2025-06-10 19:47 ` [PATCH v5 6/6] MAINTAINERS: add an entry for pf1550 mfd driver Samuel Kayode via B4 Relay
2025-06-10 20:28 ` Frank Li
2025-06-11 3:15 ` Samuel Kayode
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=aEmS8N8gdz8-6GBD@fedora \
--to=samuel.kayode@savoirfairelinux.com \
--cc=Frank.li@nxp.com \
--cc=abelvesa@kernel.org \
--cc=abelvesa@linux.com \
--cc=b38343@freescale.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=eballetbo@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=lee@kernel.org \
--cc=lgirdwood@gmail.com \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=robh@kernel.org \
--cc=sre@kernel.org \
--cc=yibin.gong@nxp.com \
/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