From: Xiang W <wxjstz@126.com>
To: opensbi@lists.infradead.org
Subject: [PATCH 2/2] platform: starfive: get I2C offset address from clocks property
Date: Thu, 18 Jan 2024 12:57:03 +0800 [thread overview]
Message-ID: <5f4e6f13fe6504fe1a987ae00989c7b02fb32aea.camel@126.com> (raw)
In-Reply-To: <b05b20a4c97e6e7f752d860355c01c4168f949e2.1705490088.git.namcao@linutronix.de>
? 2024-01-17???? 12:16 +0100?Nam Cao???
> The current code gets the I2C offset address using the device tree node
> name: it get the I2C device index from the 4th character in the node
> name (for example, "i2c5" -> i2c device 5). However, the device tree
> node's name in U-Boot is actually just "i2c" without the number, so the
> current code cannot be used with the device tree from U-Boot.
>
> Get the I2C offset address from the "clocks" property instead.
>
> Signed-off-by: Nam Cao <namcao@linutronix.de>
> ---
> ?platform/generic/starfive/jh7110.c | 19 ++++++++++---------
> ?1 file changed, 10 insertions(+), 9 deletions(-)
>
> diff --git a/platform/generic/starfive/jh7110.c b/platform/generic/starfive/jh7110.c
> index 4b22175..846b068 100644
> --- a/platform/generic/starfive/jh7110.c
> +++ b/platform/generic/starfive/jh7110.c
> @@ -29,7 +29,7 @@ struct pmic {
> ?struct jh7110 {
> ? u64 pmu_reg_base;
> ? u64 clk_reg_base;
> - u32 i2c_index;
> + u32 i2c_clk_offset;
> ?};
> ?
> ?static struct pmic pmic_inst;
> @@ -163,10 +163,7 @@ static void pmic_i2c_clk_enable(void)
> ? unsigned long clock_base;
> ? unsigned int val;
> ?
> - clock_base = jh7110_inst.clk_reg_base +
> - I2C_APB_CLK_OFFSET +
The I2C_APB_CLK_OFFSET is no longer needed and can be removed.
Regards,
Xiang W
> - (jh7110_inst.i2c_index << 2);
> -
> + clock_base = jh7110_inst.clk_reg_base + jh7110_inst.i2c_clk_offset;
> ? val = readl((void *)clock_base);
> ?
> ? if (!val)
> @@ -241,7 +238,8 @@ static struct fdt_reset fdt_reset_pmic = {
> ?static int starfive_jh7110_inst_init(void *fdt)
> ?{
> ? int noff, rc = 0;
> - const char *name;
> + const fdt32_t *val;
> + int len;
> ? u64 addr;
> ?
> ? noff = fdt_node_offset_by_compatible(fdt, -1, "starfive,jh7110-pmu");
> @@ -261,9 +259,12 @@ static int starfive_jh7110_inst_init(void *fdt)
> ? }
> ?
> ? if (pmic_inst.adapter) {
> - name = fdt_get_name(fdt, pmic_inst.adapter->id, NULL);
> - if (!sbi_strncmp(name, "i2c", 3))
> - jh7110_inst.i2c_index = name[3] - '0';
> + val = fdt_getprop(fdt, pmic_inst.adapter->id, "clocks", &len);
> + /* The clocks property looks like this: clocks = <&syscrg JH7110_SYSCLK_I2C5_APB>;
> + * So check that the length is 8 bytes, and get the offset from the second value
> + */
> + if (val && len == 8)
> + jh7110_inst.i2c_clk_offset = fdt32_to_cpu(val[1]) << 2;
> ? else
> ? rc = SBI_EINVAL;
> ? }
> --
> 2.39.2
>
>
next prev parent reply other threads:[~2024-01-18 4:57 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-17 11:16 [PATCH 1/2] platform: starfive: correct system clock device tree node Nam Cao
2024-01-17 11:16 ` [PATCH 2/2] platform: starfive: get I2C offset address from clocks property Nam Cao
2024-01-18 4:57 ` Xiang W [this message]
2024-01-17 11:32 ` [PATCH 1/2] platform: starfive: correct system clock device tree node Xiang W
2024-01-17 11:47 ` David Abdurachmanov
2024-01-17 12:03 ` Nam Cao
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=5f4e6f13fe6504fe1a987ae00989c7b02fb32aea.camel@126.com \
--to=wxjstz@126.com \
--cc=opensbi@lists.infradead.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