From: Matti Vaittinen <mazziesaccount@gmail.com>
To: Andreas Kemnade <andreas@kemnade.info>,
lee@kernel.org, robh+dt@kernel.org,
krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.org,
devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
imx@lists.linux.dev
Subject: Re: [RFC PATCH 2/2] mfd: rohm-bd71828: Add power off functionality
Date: Mon, 25 Mar 2024 13:31:15 +0200 [thread overview]
Message-ID: <472c6eaf-6cbc-484c-bc94-571d115176aa@gmail.com> (raw)
In-Reply-To: <20240324201210.232301-3-andreas@kemnade.info>
On 3/24/24 22:12, Andreas Kemnade wrote:
> Since the chip can power off the system, add the corresponding
> functionality.
> Based on https://github.com/kobolabs/Kobo-Reader/raw/master/hw/imx6sll-clara2e/kernel.tar.bz2
> No information source about the magic numbers found.
Oh, interesting repository :) Thanks for linking to it! I didn't know
someone had reworked this driver...
I have access to the data-sheets so I also have some pieces of
information. I hope I can clarify part of the puzzle. Unfortunately I
have no information about the magic delays. I guess I could try asking
though.
Oh, it seems to me this handler is only working on BD71828, not on
BD71815. So, it should be tied to the ROHM_CHIP_TYPE_BD71828.
> Signed-off-by: Andreas Kemnade <andreas@kemnade.info>
> ---
> drivers/mfd/rohm-bd71828.c | 31 ++++++++++++++++++++++++++++++-
> 1 file changed, 30 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/mfd/rohm-bd71828.c b/drivers/mfd/rohm-bd71828.c
> index 594718f7e8e1..5a55aa3620d0 100644
> --- a/drivers/mfd/rohm-bd71828.c
> +++ b/drivers/mfd/rohm-bd71828.c
> @@ -464,6 +464,24 @@ static int set_clk_mode(struct device *dev, struct regmap *regmap,
> OUT32K_MODE_CMOS);
> }
>
> +static struct i2c_client *bd71828_dev;
I'm not sure why to store pointer to the device and not a pointer to the
regmap?
> +static void bd71828_power_off(void)
> +{
> + i2c_smbus_write_byte_data(bd71828_dev, 0x03, 0xff);
0x03 is a "reset reason" - register. Spec I have states that the
register should clear when a reset occurs - but it also says the bits
are "write '1' to clear". So, for some reason(?), this clears the
previous reset reason. I am unsure why i2c_smbus_write_byte_data() and
not regmap()?
> + mdelay(500);
> + i2c_smbus_write_byte_data(bd71828_dev, BD71828_REG_INT_DCIN2, 0x02);
This clears the DCIN monitoring status bit from the IRQ status register.
I don't understand the purpose though.
> + mdelay(500);
> + while (true) {
> + i2c_smbus_write_byte_data(bd71828_dev, BD71828_REG_PS_CTRL_1, 0x02);
This write to PS_CTRL_1 initiates a state transition. 0x2 equals to HBNT
state. Eg, in usual cases this should be a start of the power-off sequence.
> + mdelay(500);
> + }
> +}
If you have the hardware to test this on, then it'd be great to see if
clearing the reset reason and IRQ status could be dropped. I can't
immediately think of a reason for those.
> +static void bd71828_remove_poweroff(void *data)
> +{
> + bd71828_dev = NULL;
This does not smell correct to me. Should we remove the
bd71828_power_off() from the pm_power_off instead?
> +}
> +
> static int bd71828_i2c_probe(struct i2c_client *i2c)
> {
> struct regmap_irq_chip_data *irq_data;
> @@ -542,7 +560,18 @@ static int bd71828_i2c_probe(struct i2c_client *i2c)
> ret = devm_mfd_add_devices(&i2c->dev, PLATFORM_DEVID_AUTO, mfd, cells,
> NULL, 0, regmap_irq_get_domain(irq_data));
> if (ret)
> - dev_err_probe(&i2c->dev, ret, "Failed to create subdevices\n");
> + return dev_err_probe(&i2c->dev, ret, "Failed to create subdevices\n");
> +
> + if (of_device_is_system_power_controller(i2c->dev.of_node)) {
> + if (!pm_power_off) {
> + bd71828_dev = i2c;
> + pm_power_off = bd71828_power_off;
> + ret = devm_add_action_or_reset(&i2c->dev,
> + bd71828_remove_poweroff,
> + NULL);
> + } else
> + dev_warn(&i2c->dev, "Poweroff callback already assigned\n");
> + }
>
> return ret;
> }
Thanks for doing the digging Andreas! I think supporting the power-off
for devices using this PMIC is nice!
Yours,
-- Matti
--
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland
~~ When things go utterly wrong vim users can always type :help! ~~
next prev parent reply other threads:[~2024-03-25 11:31 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-24 20:12 [RFC PATCH 0/2] mfd: rohm-bd71828: Add power off Andreas Kemnade
2024-03-24 20:12 ` [RFC PATCH 1/2] dt-bindings: mfd: Add ROHM BD71828 system-power-controller property Andreas Kemnade
2024-03-25 12:13 ` Krzysztof Kozlowski
2024-03-24 20:12 ` [RFC PATCH 2/2] mfd: rohm-bd71828: Add power off functionality Andreas Kemnade
2024-03-25 11:31 ` Matti Vaittinen [this message]
2024-03-25 12:16 ` Andreas Kemnade
2024-03-25 12:44 ` Matti Vaittinen
2024-03-25 13:28 ` Andreas Kemnade
2024-03-25 14:10 ` Lee Jones
2024-03-25 16:51 ` Lee Jones
2024-03-25 20:14 ` Andreas Kemnade
2024-03-25 12:13 ` Krzysztof Kozlowski
2024-03-25 20:21 ` Andreas Kemnade
2024-03-26 6:32 ` Krzysztof Kozlowski
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=472c6eaf-6cbc-484c-bc94-571d115176aa@gmail.com \
--to=mazziesaccount@gmail.com \
--cc=andreas@kemnade.info \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=imx@lists.linux.dev \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=lee@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=robh+dt@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