From patchwork Thu Jan 18 09:20:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nam Cao X-Patchwork-Id: 1887831 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=jb05cV6N; 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=O2w59Kt/; dkim=fail reason="signature verification failed" header.d=linutronix.de header.i=@linutronix.de header.a=ed25519-sha256 header.s=2020e header.b=/sqMfxkC; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=198.137.202.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 [198.137.202.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 4TFy0M02f0z23dx for ; Thu, 18 Jan 2024 20:20:50 +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=k5MWXs+KiRhkUn3Ptq6Q+h8x8pb0kRwNYgSUJlzu/ZY=; b=jb05cV6NR2pQvd gRKO1oNfdR7P0/Q8jeAJQPxVuujW7IDsZxjCGX7Ve3UbNZzqebva+C+3OvvOLmp4VZfqHZMFNCI+v TiUrJ2jrk0ye6Zklzf3adj0DVBCt93DMpxqrzAAT3TiRkYLv5CSrnHMDXVNDuhRAXTqVDbjl8pmAh +ZtfN4xXLTBC2LJUDzmAvL94KT3iSUXkjdB19LCMtKL/RkLTNe9ad49/7VqgkJz5ipc0T0GAWMPAf knpdky4Pw0T/9+zxBYC/fQeDB7HfK4mdRAYZb0aP6yHYn4UPdh2f0qdq85FR05HI/EcTp1OH+ZX+b NZ/rlShErUx40PtuuIHA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1rQOZV-002Fu8-0Q; Thu, 18 Jan 2024 09:20:25 +0000 Received: from galois.linutronix.de ([2a0a:51c0:0:12e:550::1]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1rQOZS-002FtD-0f for opensbi@lists.infradead.org; Thu, 18 Jan 2024 09:20:23 +0000 From: Nam Cao DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1705569620; 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=7pcTgRF8givB1jgzQ8eO20ERFNmSyMFdLX8SBlVGzVg=; b=O2w59Kt/HgxabMtwUpCrLwd7KCEmrk623vNnLXo+q5jglXQ1lsmVzwqy9V4nf4ysEzEntw JsjD2R7aWt6wKANilexxgJzC1a+wyFMZFGCRqzW2ul7HypYOkfo1isZCkfLSGiJQlKOmJW 0+wYFj6nEedss+xEpcoJWdb1V8ORGKXSnbhX4Cqijz/gAFyl/wIu2aa+TuRQsgZJ75TTPp QDoHpiUl3j/p7Cz1QgWRmhPSNvpMoqObE1PKHbfwWosNchUY3bInMJd+vvyCSAAlHXa4rq kXif7s/TsVaoCSve9aAeQMvQcnUxydffwbxOsxmVGTCdFe+rX7IyW+2JDHCzxA== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1705569620; 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=7pcTgRF8givB1jgzQ8eO20ERFNmSyMFdLX8SBlVGzVg=; b=/sqMfxkCk3t0sX3ekFxuWNST0+1BiUuC/sdnUc0YbpRvsXNuPI7CtTJ5oS0MNK8LSY/iZU zqS0ejAGYGODjWCA== To: Xiang W , opensbi@lists.infradead.org Cc: Nam Cao Subject: [PATCH v2 2/2] platform: starfive: get I2C offset address from "clocks" property Date: Thu, 18 Jan 2024 10:20:10 +0100 Message-Id: <3ddf6f902297c6e673a6abe517a1cc5497d03294.1705569454.git.namcao@linutronix.de> In-Reply-To: <55183c9a19dc5fc4dd9152c0055016b076ac9c23.1705569454.git.namcao@linutronix.de> References: <55183c9a19dc5fc4dd9152c0055016b076ac9c23.1705569454.git.namcao@linutronix.de> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240118_012022_391685_079A2779 X-CRM114-Status: GOOD ( 14.48 ) X-Spam-Score: -2.5 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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 de [...] Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2a0a:51c0:0:12e:550:0:0:1 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 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 --- v2: - also remove the now unused macro I2C_APB_CLK_OFFSET (Xiang W) platform/generic/starfive/jh7110.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/platform/generic/starfive/jh7110.c b/platform/generic/starfive/jh7110.c index 4b22175..308fe39 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; @@ -67,7 +67,6 @@ static u32 selected_hartid = -1; #define AXP15060_POWER_OFF_BIT BIT(7) #define AXP15060_RESET_BIT BIT(6) -#define I2C_APB_CLK_OFFSET 0x228 #define I2C_APB_CLK_ENABLE_BIT BIT(31) static int pm_system_reset_check(u32 type, u32 reason) @@ -163,10 +162,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 +237,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 +258,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; }