From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 07BB4C433DF for ; Tue, 16 Jun 2020 04:43:59 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id D29F7207D3 for ; Tue, 16 Jun 2020 04:43:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="O3S4bHhG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D29F7207D3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=XDhDbffzGZ5auFnzbuz7/1pxl84Lqr+FKKLF745sOo0=; b=O3S4bHhGvld0Mz /hPETjmSxOoys5k4NsfGwoUiXNYzHQIoK8jFpM3i8pzc1PrpA4psp003Q1BxseotZ5Di6axltqRjN 03sCprdzEbGSCHJaAETnJdxEGFznAMfYVkEY9ZFsnR7plKl8TCHPT7HMuB8c5NnPPNSoZmkDzx5ce rGWDedwkXM6cVYDHaqV7YmZuExg6fH7h3Sgac+QJajQR0uDWlUnixZEG5ExxzBIgPmR4t9SGaHh7B EUpwRV14FTpUj29sXysYhQqrln5RvGs4eEmlbQkZ83Qp9NdXrtazmzvaiv5Yzu6lOlSI7NsgBse2G 6g5Qwzh2mF/klHQbsUmw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jl3Rx-0001G1-Fe; Tue, 16 Jun 2020 04:43:53 +0000 Received: from mail-io1-f68.google.com ([209.85.166.68]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jl3Ru-0001Fg-0v for linux-arm-kernel@lists.infradead.org; Tue, 16 Jun 2020 04:43:51 +0000 Received: by mail-io1-f68.google.com with SMTP id w18so414585iom.5 for ; Mon, 15 Jun 2020 21:43:49 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=LmzMHIvmvF58EZXJmekpQXD5nDdYxi6HKu1Pmlrtz+M=; b=psiVMsoBA2lLzSdOgb9SVtcsG7hiauU2usRvx6mDEwPVQWAOhMtbx4aE1UPUe1dwrm gu6Y1OCLYghC7ZU9ZPpaiCVPcTNeUnjz9LDCkDWXq4of1s427TM4VT7aBWKYj2wiZy2X UpbgL1yWshim3ukmn7UVNqsjS5W6wpto+j9jk5ul8oBjAfBBoxv2uYnVe6KChVoJWOVX NNXywohWr0WOCk+Rn+O3ASuRz5Wary1OqbaOjeyLTwOU6o7gbzTgjM77buoxofStbM9V KqoNIUfRWC0PzkpTRh6SRvwo4ut3pClesMofqnL0fUxbo+RvieqnnweOWd62oK86oZaJ fBCw== X-Gm-Message-State: AOAM532ljL9jk2K6fc8PAGyqwdiGEb9L3PP7JvAopxQfUotkENGzjIKF hcxE0FSS8pFKheUGclLYfGrsG4D5LaM= X-Google-Smtp-Source: ABdhPJztXkJFcZT+mRv8x6WbAlQ2+knDwMSuXZBCslzSxlJCr1fZCeslAJy3cbCICzu0QKi5U0suaQ== X-Received: by 2002:a6b:8dd5:: with SMTP id p204mr864149iod.33.1592282628930; Mon, 15 Jun 2020 21:43:48 -0700 (PDT) Received: from localhost ([2601:647:5b00:1161:a4cc:eef9:fbc0:2781]) by smtp.gmail.com with ESMTPSA id r17sm9235940ilc.33.2020.06.15.21.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 15 Jun 2020 21:43:48 -0700 (PDT) Date: Mon, 15 Jun 2020 21:43:47 -0700 From: Moritz Fischer To: Luca Ceresoli Subject: Re: [PATCH 5/5] fpga manager: xilinx-spi: check INIT_B pin during write_init Message-ID: <20200616044347.GB46300@epycbox.lan> References: <20200611211144.9421-1-luca@lucaceresoli.net> <20200611211144.9421-5-luca@lucaceresoli.net> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200611211144.9421-5-luca@lucaceresoli.net> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200615_214350_066389_14519E6B X-CRM114-Status: GOOD ( 22.71 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, linux-fpga@vger.kernel.org, Michal Simek , linux-kernel@vger.kernel.org, Rob Herring , Moritz Fischer , Anatolij Gustschin , linux-arm-kernel@lists.infradead.org Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Luca, On Thu, Jun 11, 2020 at 11:11:44PM +0200, Luca Ceresoli wrote: > The INIT_B reports the status during startup and after the end of the > programming process. However the current driver completely ignores it. > > Check the pin status during startup to make sure programming is never > started too early and also to detect any hardware issues in the FPGA > connection. > > This is optional for backward compatibility. If INIT_B is not passed by > device tree, just fallback to the old udelays. > > Signed-off-by: Luca Ceresoli > --- > drivers/fpga/xilinx-spi.c | 54 ++++++++++++++++++++++++++++++++++++++- > 1 file changed, 53 insertions(+), 1 deletion(-) > > diff --git a/drivers/fpga/xilinx-spi.c b/drivers/fpga/xilinx-spi.c > index 799ae04301be..2710a15ed16b 100644 > --- a/drivers/fpga/xilinx-spi.c > +++ b/drivers/fpga/xilinx-spi.c > @@ -23,6 +23,7 @@ > struct xilinx_spi_conf { > struct spi_device *spi; > struct gpio_desc *prog_b; > + struct gpio_desc *init_b; > struct gpio_desc *done; > }; > > @@ -36,11 +37,44 @@ static enum fpga_mgr_states xilinx_spi_state(struct fpga_manager *mgr) > return FPGA_MGR_STATE_UNKNOWN; > } > > +/** > + * wait_for_init_b - wait for the INIT_B pin to have a given state, or wait > + * a given delay if the pin is unavailable > + * > + * @mgr The FPGA manager object > + * @value Value INIT_B to wait for (1 = asserted = low) > + * @act_udelay Delay to wait if the INIT_B pin is not available > + * > + * Returns 0 when the pin reached the given state or -ETIMEDOUT if too much > + * time passed waiting for that. If there is no INIT_B, always return 0. > + */ > +static int wait_for_init_b(struct fpga_manager *mgr, int value, > + unsigned long backup_udelay) > +{ > + struct xilinx_spi_conf *conf = mgr->priv; > + unsigned long timeout = jiffies + msecs_to_jiffies(1000); > + > + if (conf->init_b) { > + while (time_before(jiffies, timeout)) { > + /* dump_state(conf, "wait for init_d .."); */ > + if (gpiod_get_value(conf->init_b) == value) > + return 0; > + usleep_range(100, 400); > + } > + return -ETIMEDOUT; > + } > + > + udelay(backup_udelay); > + > + return 0; > +} > + > static int xilinx_spi_write_init(struct fpga_manager *mgr, > struct fpga_image_info *info, > const char *buf, size_t count) > { > struct xilinx_spi_conf *conf = mgr->priv; > + int err; > > if (info->flags & FPGA_MGR_PARTIAL_RECONFIG) { > dev_err(&mgr->dev, "Partial reconfiguration not supported.\n"); > @@ -49,10 +83,21 @@ static int xilinx_spi_write_init(struct fpga_manager *mgr, > > gpiod_set_value(conf->prog_b, 1); > > - udelay(1); /* min is 500 ns */ > + err = wait_for_init_b(mgr, 1, 1); /* min is 500 ns */ > + if (err) { > + dev_err(&mgr->dev, "INIT_B pin did not go low\n"); > + gpiod_set_value(conf->prog_b, 0); > + return err; > + } > > gpiod_set_value(conf->prog_b, 0); > > + err = wait_for_init_b(mgr, 0, 0); > + if (err) { > + dev_err(&mgr->dev, "INIT_B pin did not go high\n"); > + return err; > + } > + > if (gpiod_get_value(conf->done)) { > dev_err(&mgr->dev, "Unexpected DONE pin state...\n"); > return -EIO; > @@ -154,6 +199,13 @@ static int xilinx_spi_probe(struct spi_device *spi) > return PTR_ERR(conf->prog_b); > } > > + conf->init_b = devm_gpiod_get_optional(&spi->dev, "init_b", GPIOD_IN); > + if (IS_ERR(conf->init_b)) { > + dev_err(&spi->dev, "Failed to get INIT_B gpio: %ld\n", > + PTR_ERR(conf->init_b)); > + return PTR_ERR(conf->init_b); > + } > + > conf->done = devm_gpiod_get(&spi->dev, "done", GPIOD_IN); > if (IS_ERR(conf->done)) { > dev_err(&spi->dev, "Failed to get DONE gpio: %ld\n", > -- > 2.27.0 > Series looks good, will apply to for-next. Thanks, Moritz _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel