From patchwork Fri Feb 2 13:43:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nam Cao X-Patchwork-Id: 1894550 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=DdtMzq28; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=linutronix.de header.i=@linutronix.de header.a=rsa-sha256 header.s=2020 header.b=VXfq+Rfk; dkim=fail reason="signature verification failed" header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=BjsX2eyK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TRH7F5T2Wz23gx for ; Sat, 3 Feb 2024 00:44:09 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sif6hCbHH0AluqfVWdvx7WUBe0Yb33Kao9AOuAT7YTg=; b=DdtMzq28wMvzGL i3lurN/fvZHb0Sx7DOiqfScuVbu8uPrZi/zYFPSzkS8hSBggfBDG3VCpO0Hhl2N+oerJA7p6Lw46j p3RDHiXcnMSiH/yt4MCrzRds6GvIs/w7Pf4A55kHSRQxZacivNzNV2oXQhLWMTmAjt2zWb3V5yWV1 +7JYGcNMqFoGRM8TFd+09BGQUHgAxvWkyvPhSm2TJ9w5M3Adbwnq/kE4SLMZONmh2Fb3dsLmqko80 gx6v4p6tn6XHdFPOHIJFPAaf8FnTCEdOMnuQ3fe2AfV3fWMksxP6VsyVN3zOoVKzUEoXza6SSuqAE /yimYSMdTDrUKR8IrRVw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVtpo-0000000Bdum-2kJy; Fri, 02 Feb 2024 13:44:00 +0000 Received: from galois.linutronix.de ([2a0a:51c0:0:12e:550::1]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rVtpU-0000000BdpA-0fTh for opensbi@lists.infradead.org; Fri, 02 Feb 2024 13:43:58 +0000 From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1706881414; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jFGjokFD901GS3OfOOvV9JF6VaY4EiNBgPX36Q6l3uc=; b=VXfq+Rfk8r0Hd23q+2Kbsgyuyp8LI6hVmWoRsJwgztaXOsz+MFWttIMdjTE3AZPAOw7AH4 dC1haUC6EJDgRP9tw9muU7tmXKzT171RzmMokuDziEb4tll4kNJrR7x+XMnnmqwC4uWwo3 v5h/JuVXNcjOe3qwHN4PrMlrfACkgwMMFnT0Pm9g5VrXc1igRVHZa6ESPvDdW3TZ72Mt/Y hSnfA+EUm1bNNevwdJubSc8qq7w0rGEKyT9pWjP/vpkaLq90PJxeOpc88LxSD1S4m2VKWT 73ygTJj2cB286D1weF2lna7vcNQaJ/NvtF1smOFmArqf81bk1iNx6hE2dZEUwQ== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1706881414; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=jFGjokFD901GS3OfOOvV9JF6VaY4EiNBgPX36Q6l3uc=; b=BjsX2eyKEuY3iXVTo/Rw5xJ1L236tAsaBRiKk+8Uu5yuZIDaUXcIpPWZMm4ywW7KRwLpLL puxGlqN8pgvnl1AQ== To: opensbi@lists.infradead.org, Cheehong Ang , Wei Liang Lim , minda.chen@starfivetech.com Cc: Nam Cao Subject: [PATCH v3 2/7] platform: starfive: get I2C offset address from clocks property Date: Fri, 2 Feb 2024 14:43:23 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240202_054342_056167_0601BA4C X-CRM114-Status: GOOD ( 13.99 ) X-Spam-Note: SpamAssassin invocation failed X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org 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 Reviewed-by: Minda Chen --- 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 + - (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; }