From: claudiu beznea <claudiu.beznea@tuxon.dev>
To: Biju Das <biju.das.jz@bp.renesas.com>,
Chris Brandt <Chris.Brandt@renesas.com>,
"andi.shyti@kernel.org" <andi.shyti@kernel.org>,
"robh@kernel.org" <robh@kernel.org>,
"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
"conor+dt@kernel.org" <conor+dt@kernel.org>,
"geert+renesas@glider.be" <geert+renesas@glider.be>,
"magnus.damm@gmail.com" <magnus.damm@gmail.com>,
"mturquette@baylibre.com" <mturquette@baylibre.com>,
"sboyd@kernel.org" <sboyd@kernel.org>,
"p.zabel@pengutronix.de" <p.zabel@pengutronix.de>,
"wsa+renesas@sang-engineering.com"
<wsa+renesas@sang-engineering.com>
Cc: "linux-renesas-soc@vger.kernel.org"
<linux-renesas-soc@vger.kernel.org>,
"linux-i2c@vger.kernel.org" <linux-i2c@vger.kernel.org>,
"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"linux-clk@vger.kernel.org" <linux-clk@vger.kernel.org>,
Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
Subject: Re: [PATCH 06/12] i2c: riic: Add suspend/resume support
Date: Fri, 21 Jun 2024 15:51:28 +0300 [thread overview]
Message-ID: <4a693c1f-15ec-43b4-8f53-ab0a6bd4d7dc@tuxon.dev> (raw)
In-Reply-To: <TY3PR01MB113468CF1B6652524A2D101D686C92@TY3PR01MB11346.jpnprd01.prod.outlook.com>
On 21.06.2024 15:30, Biju Das wrote:
> Hi Claudiu,
>
> Thanks for the patch
>
>> -----Original Message-----
>> From: Claudiu <claudiu.beznea@tuxon.dev>
>> Sent: Friday, June 21, 2024 12:23 PM
>> Subject: [PATCH 06/12] i2c: riic: Add suspend/resume support
>>
>> From: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
>>
>> Add suspend/resume support for the RIIC driver. This is necessary for the Renesas RZ/G3S SoC which
>> support suspend to deep sleep state where power to most of the SoC components is turned off. As a
>> result the I2C controller needs to be reconfigured after suspend/resume. For this, the reset line
>> was stored in the driver private data structure as well as i2c timings.
>> The reset line and I2C timings are necessary to re-initialize the controller after resume.
>>
>> Signed-off-by: Claudiu Beznea <claudiu.beznea.uj@bp.renesas.com>
>> ---
>> drivers/i2c/busses/i2c-riic.c | 66 +++++++++++++++++++++++++++++------
>> 1 file changed, 55 insertions(+), 11 deletions(-)
>>
>> diff --git a/drivers/i2c/busses/i2c-riic.c b/drivers/i2c/busses/i2c-riic.c index
>> 00fb09786e48..f9b9e92570d8 100644
>> --- a/drivers/i2c/busses/i2c-riic.c
>> +++ b/drivers/i2c/busses/i2c-riic.c
>> @@ -105,6 +105,8 @@ struct riic_dev {
>> struct completion msg_done;
>> struct i2c_adapter adapter;
>> struct clk *clk;
>> + struct reset_control *rstc;
>> + struct i2c_timings i2c_t;
>> };
>>
>> struct riic_irq_desc {
>> @@ -306,11 +308,12 @@ static const struct i2c_algorithm riic_algo = {
>> .functionality = riic_func,
>> };
>>
>> -static int riic_init_hw(struct riic_dev *riic, struct i2c_timings *t)
>> +static int riic_init_hw(struct riic_dev *riic)
>> {
>> int ret;
>> unsigned long rate;
>> int total_ticks, cks, brl, brh;
>> + struct i2c_timings *t = &riic->i2c_t;
>> struct device *dev = riic->adapter.dev.parent;
>>
>> if (t->bus_freq_hz > I2C_MAX_FAST_MODE_FREQ) { @@ -429,8 +432,6 @@ static int
>> riic_i2c_probe(struct platform_device *pdev)
>> struct device *dev = &pdev->dev;
>> struct riic_dev *riic;
>> struct i2c_adapter *adap;
>> - struct i2c_timings i2c_t;
>> - struct reset_control *rstc;
>> int i, ret;
>>
>> riic = devm_kzalloc(dev, sizeof(*riic), GFP_KERNEL); @@ -447,16 +448,16 @@ static int
>> riic_i2c_probe(struct platform_device *pdev)
>> return PTR_ERR(riic->clk);
>> }
>>
>> - rstc = devm_reset_control_get_optional_exclusive(dev, NULL);
>> - if (IS_ERR(rstc))
>> - return dev_err_probe(dev, PTR_ERR(rstc),
>> + riic->rstc = devm_reset_control_get_optional_exclusive(dev, NULL);
>> + if (IS_ERR(riic->rstc))
>> + return dev_err_probe(dev, PTR_ERR(riic->rstc),
>> "Error: missing reset ctrl\n");
>>
>> - ret = reset_control_deassert(rstc);
>> + ret = reset_control_deassert(riic->rstc);
>> if (ret)
>> return ret;
>>
>> - ret = devm_add_action_or_reset(dev, riic_reset_control_assert, rstc);
>> + ret = devm_add_action_or_reset(dev, riic_reset_control_assert,
>> +riic->rstc);
>> if (ret)
>> return ret;
>>
>> @@ -485,13 +486,13 @@ static int riic_i2c_probe(struct platform_device *pdev)
>>
>> init_completion(&riic->msg_done);
>>
>> - i2c_parse_fw_timings(dev, &i2c_t, true);
>> + i2c_parse_fw_timings(dev, &riic->i2c_t, true);
>>
>> pm_runtime_set_autosuspend_delay(dev, 0);
>> pm_runtime_use_autosuspend(dev);
>> pm_runtime_enable(dev);
>>
>> - ret = riic_init_hw(riic, &i2c_t);
>> + ret = riic_init_hw(riic);
>> if (ret)
>> goto out;
>>
>> @@ -501,7 +502,7 @@ static int riic_i2c_probe(struct platform_device *pdev)
>>
>> platform_set_drvdata(pdev, riic);
>>
>> - dev_info(dev, "registered with %dHz bus speed\n", i2c_t.bus_freq_hz);
>> + dev_info(dev, "registered with %dHz bus speed\n",
>> +riic->i2c_t.bus_freq_hz);
>> return 0;
>>
>> out:
>> @@ -561,6 +562,48 @@ static const struct riic_of_data riic_rz_v2h_info = {
>> },
>> };
>>
>> +static int riic_i2c_suspend(struct device *dev) {
>> + struct riic_dev *riic = dev_get_drvdata(dev);
>> + int ret;
>> +
>> + ret = pm_runtime_resume_and_get(dev);
>> + if (ret)
>> + return ret;
>> +
>> + i2c_mark_adapter_suspended(&riic->adapter);
>> +
>> + /* Disable output on SDA, SCL pins. */
>> + riic_clear_set_bit(riic, ICCR1_ICE, 0, RIIC_ICCR1);
>> +
>> + pm_runtime_mark_last_busy(dev);
>> + pm_runtime_put_sync(dev);
>> +
>> + return reset_control_assert(riic->rstc); }
>> +
>> +static int riic_i2c_resume(struct device *dev) {
>> + struct riic_dev *riic = dev_get_drvdata(dev);
>> + int ret;
>> +
>> + ret = reset_control_deassert(riic->rstc);
>> + if (ret)
>> + return ret;
>> +
>> + ret = riic_init_hw(riic);
>> + if (ret)
>> + return ret;
>
> On error case we need to assert back??
Yes, it would be better as we cannot recover though other paths anymore, if
that happens.
>
> Cheers,
> Biju
>
>> +
>> + i2c_mark_adapter_resumed(&riic->adapter);
>> +
>> + return 0;
>> +}
>> +
>> +static const struct dev_pm_ops riic_i2c_pm_ops = {
>> + SYSTEM_SLEEP_PM_OPS(riic_i2c_suspend, riic_i2c_resume) };
>> +
>> static const struct of_device_id riic_i2c_dt_ids[] = {
>> { .compatible = "renesas,riic-rz", .data = &riic_rz_a_info },
>> { .compatible = "renesas,riic-r9a09g057", .data = &riic_rz_v2h_info }, @@ -573,6 +616,7 @@
>> static struct platform_driver riic_i2c_driver = {
>> .driver = {
>> .name = "i2c-riic",
>> .of_match_table = riic_i2c_dt_ids,
>> + .pm = pm_ptr(&riic_i2c_pm_ops),
>> },
>> };
>>
>> --
>> 2.39.2
>>
>
next prev parent reply other threads:[~2024-06-21 12:51 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-21 11:22 [PATCH 00/12] i2c: riic: Add support for Renesas RZ/G3S Claudiu
2024-06-21 11:22 ` [PATCH 01/12] clk: renesas: r9a08g045: Add clock, reset and power domain support for I2C Claudiu
2024-06-21 11:22 ` [PATCH 02/12] i2c: riic: Use temporary variable for struct device Claudiu
2024-06-21 11:22 ` [PATCH 03/12] i2c: riic: Call pm_runtime_get_sync() when need to access registers Claudiu
2024-06-21 11:22 ` [PATCH 04/12] i2c: riic: Use pm_runtime_resume_and_get() Claudiu
2024-06-21 12:24 ` Biju Das
2024-06-21 12:49 ` claudiu beznea
2024-06-21 11:22 ` [PATCH 05/12] i2c: riic: Enable runtime PM autosuspend support Claudiu
2024-06-21 11:22 ` [PATCH 06/12] i2c: riic: Add suspend/resume support Claudiu
2024-06-21 12:30 ` Biju Das
2024-06-21 12:51 ` claudiu beznea [this message]
2024-06-21 11:22 ` [PATCH 07/12] i2c: riic: Define individual arrays to describe the register offsets Claudiu
2024-06-21 11:22 ` [PATCH 08/12] dt-bindings: i2c: renesas,riic: Document the R9A08G045 support Claudiu
2024-06-21 12:34 ` Biju Das
2024-06-21 12:54 ` claudiu beznea
2024-06-21 12:56 ` Biju Das
2024-06-21 13:06 ` claudiu beznea
2024-06-21 13:10 ` Biju Das
2024-06-21 13:29 ` claudiu beznea
2024-06-21 14:06 ` Biju Das
2024-06-21 14:30 ` claudiu beznea
2024-06-21 14:37 ` Biju Das
2024-06-21 14:59 ` claudiu beznea
2024-06-21 15:04 ` Biju Das
2024-06-22 8:08 ` Biju Das
2024-06-21 14:15 ` Conor Dooley
2024-06-24 15:40 ` Geert Uytterhoeven
2024-06-25 5:07 ` claudiu beznea
2024-06-21 11:23 ` [PATCH 09/12] i2c: riic: Add support for fast mode plus Claudiu
2024-06-21 11:23 ` [PATCH 10/12] arm64: dts: renesas: r9a08g045: Add I2C nodes Claudiu
2024-06-21 11:23 ` [PATCH 11/12] arm64: dts: renesas: rzg3s-smarc: Enable i2c0 node Claudiu
2024-06-21 11:23 ` [PATCH 12/12] arm64: dts: renesas: rzg3s-smarc-som: Enable i2c1 node Claudiu
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=4a693c1f-15ec-43b4-8f53-ab0a6bd4d7dc@tuxon.dev \
--to=claudiu.beznea@tuxon.dev \
--cc=Chris.Brandt@renesas.com \
--cc=andi.shyti@kernel.org \
--cc=biju.das.jz@bp.renesas.com \
--cc=claudiu.beznea.uj@bp.renesas.com \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=geert+renesas@glider.be \
--cc=krzk+dt@kernel.org \
--cc=linux-clk@vger.kernel.org \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=magnus.damm@gmail.com \
--cc=mturquette@baylibre.com \
--cc=p.zabel@pengutronix.de \
--cc=robh@kernel.org \
--cc=sboyd@kernel.org \
--cc=wsa+renesas@sang-engineering.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;
as well as URLs for NNTP newsgroup(s).