Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E349BC433EF for ; Fri, 21 Jan 2022 10:01:07 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B65B381DCA; Fri, 21 Jan 2022 11:01:05 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=kernel.org header.i=@kernel.org header.b="HnrfuAbn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3CE4481F6D; Fri, 21 Jan 2022 11:01:04 +0100 (CET) Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9CA9281DCA for ; Fri, 21 Jan 2022 11:01:00 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=kernel.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=pali@kernel.org Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B5039619EE; Fri, 21 Jan 2022 10:00:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 03ECEC340E1; Fri, 21 Jan 2022 10:00:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1642759258; bh=R7spV4wPFwsGI3dv3+/PFjMh1plo4pPUFTeKD9ZGFG8=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HnrfuAbnO5xLlEIIDJC70x99uqJbkhxbBZa/fCf9Oo1QgNa0/mdLFFrDQcYWl1r3f qt87MPbI7I3TKSpzV4yMRQ4ID8o2Qd1j6pPeONwG7LzbY0AusB8X4UTncIVHlhlTEo EuaVkJQvNrZBHJyt9V8CXXLg7RRo0NlTNIr+uPBLr3QL5r86cGLP3suyvWA0lm43gc jeECuCKvz2L2CM/2ZdyT1Ofgue5iT2Lyt8xR6NiZG6ctFkg7LWfftkAr6dLJqpYEiz BaHeACtOoYmoynn1RGmVRO/S3wJfbXo6vH/zu37wgLs9codee81Ch8vuVHwMcrIime MQwX8/cny4zTg== Received: by pali.im (Postfix) id E6C6D857; Fri, 21 Jan 2022 11:00:54 +0100 (CET) Date: Fri, 21 Jan 2022 11:00:54 +0100 From: Pali =?utf-8?B?Um9ow6Fy?= To: Tony Dinh Cc: U-Boot Mailing List , Stefan Roese , Tom Rini , David Purdy , Marek =?utf-8?B?QmVo77+9bg==?= Subject: Re: [PATCH v4 3/4] arm: kirkwood: Pogoplug-V4 : Add board implementation files Message-ID: <20220121100054.3gp2hrdr3ame7qs3@pali> References: <20220121015055.8287-1-mibodhi@gmail.com> <20220121015055.8287-4-mibodhi@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220121015055.8287-4-mibodhi@gmail.com> User-Agent: NeoMutt/20180716 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean On Thursday 20 January 2022 17:50:54 Tony Dinh wrote: > diff --git a/board/cloudengines/pogo_v4/pogo_v4.c b/board/cloudengines/pogo_v4/pogo_v4.c > new file mode 100644 > index 0000000000..c85de0b22e > --- /dev/null > +++ b/board/cloudengines/pogo_v4/pogo_v4.c > +int fdt_get_phy_addr(const char *path) > +{ > + const void *fdt = gd->fdt_blob; > + const u32 *reg; > + const u32 *val; > + int node, phandle, addr; > + > + /* Find the node by its full path */ > + node = fdt_path_offset(fdt, path); > + if (node >= 0) { > + /* Look up phy-handle */ > + val = fdt_getprop(fdt, node, "phy-handle", NULL); > + if (!val) { > + /* Look up phy (deprecated property for phy handle) */ > + val = fdt_getprop(fdt, node, "phy", NULL); > + } > + if (val) { > + phandle = fdt32_to_cpu(*val); > + if (!phandle) > + return -FDT_ERR_NOTFOUND; > + > + /* Follow it to its node */ > + node = fdt_node_offset_by_phandle(fdt, phandle); > + if (node) { > + /* Look up reg */ > + reg = fdt_getprop(fdt, node, "reg", NULL); > + if (reg) { > + addr = fdt32_to_cpu(*reg); > + return addr; > + } > + } > + } > + } > + return -FDT_ERR_NOTFOUND; > +} > + > +#if defined(CONFIG_RESET_PHY_R) > +/* Configure and initialize PHY */ > +void reset_phy(void) > +{ > + u16 reg; > + int phyaddr; > + char *name = "ethernet-controller@72000"; > + char *eth0_path = "/ocp@f1000000/ethernet-controller@72000"; Hello! I would suggest to avoid hardcoding DT node names and DT node paths into source code. How to avoid it? In DTS file define alias "ethernet0" as alias to eth0 node: aliases { ethernet0 = ð0; }; (just before memory {} node) ð0 label is already defined in arch/arm/dts/kirkwood.dtsi. Function fdt_path_offset() understands either full path or alias. So you can call fdt_get_phy_addr("ethernet0"). And to get node name you can use function fdt_get_name() which takes node offset - return value of fdt_path_offset(). And maybe... to avoid calling fdt_path_offset() two times, you may adjust fdt_get_phy_addr() to directly take node offset (not path/alias). So something like this: node = fdt_path_offset(gd->fdt_blob, "ethernet0"); ... error checking ... name = fdt_get_name(gd->fdt_blob, node, NULL); ... error checking ... miiphy_set_current_dev(name); ... error checking ... fdt_get_phy_addr(node); ... error checking ... > + if (miiphy_set_current_dev(name)) > + return; > + > + phyaddr = fdt_get_phy_addr(eth0_path); > + if (phyaddr < 0) > + return; > + > + /* > + * Enable RGMII delay on Tx and Rx for CPU port > + * Ref: sec 4.7.2 of chip datasheet > + */ > + miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 2); > + miiphy_read(name, phyaddr, MV88E1116_MAC_CTRL_REG, ®); > + reg |= (MV88E1116_RGMII_RXTM_CTRL | MV88E1116_RGMII_TXTM_CTRL); > + miiphy_write(name, phyaddr, MV88E1116_MAC_CTRL_REG, reg); > + miiphy_write(name, phyaddr, MV88E1116_PGADR_REG, 0); > + > + /* reset the phy */ > + miiphy_reset(name, phyaddr); > + > + printf("88E1116 Initialized on %s\n", name); > +}