Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B0D82C11F67 for ; Thu, 8 Jul 2021 01:08:54 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id DDEF661CD5 for ; Thu, 8 Jul 2021 01:08:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DDEF661CD5 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 8BCCB82EAC; Thu, 8 Jul 2021 03:08:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com 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=sifive.com header.i=@sifive.com header.b="ezmU68Jd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C415D82E85; Thu, 8 Jul 2021 03:08:37 +0200 (CEST) Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id E8C8C82E7D for ; Thu, 8 Jul 2021 03:08:34 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=vincent.chen@sifive.com Received: by mail-pf1-x429.google.com with SMTP id w22so3937536pff.5 for ; Wed, 07 Jul 2021 18:08:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZHzaiXJiAX9us0a/e5oMJ6RTwBYocKly19JWC31ca+c=; b=ezmU68JdiVlATKaWt0UVwVPvfxJcsTGZO/FVE5DjMAJ4SGXSaCW4UlxvYTv/4ED6M2 ySqFUP0E2E7ouhEV2SllG4T5oKRgwCmaVwXXTY1LWnDOej1/ZpjLsfr/qmOjG2VwkW5f lxWXbCZrZWMf+i+ke+OCeo46C3RG+bktcRzb5dalvSdwYZK6BCg92IINXdEMAbEeQGGs 34NLU2F2I6/+bWU1FVX0IbSQTewDFKNkBjQznchCwo7E+UJeH5XW74126Wg3MXbDVUxr WoQAwf0Lm8XltuqOwywtw7EpUgl/Ie1MC4bK5GMG3qfESqAwLLmhYQCe3dZP3YlT3lXm u4SA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZHzaiXJiAX9us0a/e5oMJ6RTwBYocKly19JWC31ca+c=; b=Wxabs4Nnl2sKvmmaLLkxQH14mxY8bvLS37T5Iw0YN7rx/DVjqF/QjGbCHa6DI+lV9Y 6L2YBBsYcX/fxy3kktL5J2LEZSvAAFsxQPfvQsimSBApzhvHeRakuMZCCZILd7SrNhGj CxO4AjPQatZzVvsFe/EUw5fntZYEQz2qeT+KLCddq+M4ihSvpFFt9o3YReIuNTlPBbn/ 9qytezm87zG42A4hqyyrEwFHXrvar9BrI8iP5h4zKW39inbEk/b+rUfhzSEtL2HPvpOu ncjhDlv+djKsAqeyFZYbwSAoK+yXD0TI/cnot90LQMyBVAO6scI/Dlq60XoDv5TiFke7 qrwg== X-Gm-Message-State: AOAM531mkO9iZBv4Kw+ykAaiLStRUqFo3fy2MpEd+fYqVkkS3jSg7MLN ThQZUpJfPquFre5QJZPirX7ssg== X-Google-Smtp-Source: ABdhPJw9QtuG6o9J4DOMWZM90l29T7k5dG1oRRt5ykt/Lp+NWHdm2r15NF7L2/9nHtx3Pu8gO22P0w== X-Received: by 2002:a62:d41e:0:b029:305:b3ff:4056 with SMTP id a30-20020a62d41e0000b0290305b3ff4056mr27723282pfh.78.1625706513301; Wed, 07 Jul 2021 18:08:33 -0700 (PDT) Received: from localhost.localdomain (111-243-35-231.dynamic-ip.hinet.net. [111.243.35.231]) by smtp.gmail.com with ESMTPSA id o1sm352321pjf.56.2021.07.07.18.08.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 07 Jul 2021 18:08:33 -0700 (PDT) From: Vincent Chen To: green.wan@sifive.com, rick@andestech.com, bmeng.cn@gmail.com, ycliang@andestech.com, u-boot@lists.denx.de Cc: vincent.chen@sifive.com Subject: [PATCH 1/2] board: sifive: unmatched: refine GEMGXL initialized function in SPL Date: Thu, 8 Jul 2021 09:08:20 +0800 Message-Id: <1625706501-964-2-git-send-email-vincent.chen@sifive.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1625706501-964-1-git-send-email-vincent.chen@sifive.com> References: <1625706501-964-1-git-send-email-vincent.chen@sifive.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean Create a new function spl_reset_device_by_gpio to reset the device whose reset pin is connected to the GPIO. Then, using this function to initialize GEMGXL. Signed-off-by: Vincent Chen --- board/sifive/unmatched/spl.c | 58 +++++++++++++++++++++++++++++--------------- 1 file changed, 39 insertions(+), 19 deletions(-) diff --git a/board/sifive/unmatched/spl.c b/board/sifive/unmatched/spl.c index 5e1333b..b598f9f 100644 --- a/board/sifive/unmatched/spl.c +++ b/board/sifive/unmatched/spl.c @@ -22,43 +22,63 @@ #define MODE_SELECT_SD 0xb #define MODE_SELECT_MASK GENMASK(3, 0) -int spl_board_init_f(void) +static inline int spl_reset_device_by_gpio(const char *label, int pin, int low_width) { int ret; - ret = spl_soc_init(); + ret = gpio_request(pin, label); if (ret) { - debug("HiFive Unmatched FU740 SPL init failed: %d\n", ret); + debug("%s gpio request failed: %d\n", label, ret); + return ret; + } + + ret = gpio_direction_output(pin, 1); + if (ret) { + debug("%s gpio direction set failed: %d\n", label, ret); return ret; } + udelay(1); + + gpio_set_value(pin, 0); + udelay(low_width); + gpio_set_value(pin, 1); + + return ret; +} + +static inline int spl_gemgxl_init(void) +{ + int ret; /* * GEMGXL init VSC8541 PHY reset sequence; * leave pull-down active for 2ms */ udelay(2000); - ret = gpio_request(GEM_PHY_RESET, "gem_phy_reset"); + ret = spl_reset_device_by_gpio("gem_phy_reset", GEM_PHY_RESET, 1); + mdelay(15); + + return ret; +} + +int spl_board_init_f(void) +{ + int ret; + + ret = spl_soc_init(); if (ret) { - debug("gem_phy_reset gpio request failed: %d\n", ret); - return ret; + debug("HiFive Unmatched FU740 SPL init failed: %d\n", ret); + goto end; } - /* Set GPIO 12 (PHY NRESET) */ - ret = gpio_direction_output(GEM_PHY_RESET, 1); + ret = spl_gemgxl_init(); if (ret) { - debug("gem_phy_reset gpio direction set failed: %d\n", ret); - return ret; + debug("Gigabit ethernet PHY (VSC8541) init failed: %d\n", ret); + goto end; } - udelay(1); - - /* Reset PHY again to enter unmanaged mode */ - gpio_set_value(GEM_PHY_RESET, 0); - udelay(1); - gpio_set_value(GEM_PHY_RESET, 1); - mdelay(15); - - return 0; +end: + return ret; } u32 spl_boot_device(void) -- 2.7.4