Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp2090927ybp; Thu, 10 Oct 2019 02:02:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrMXXIx+7DtjhNdN7kNfMgC4WqJPdLp783WjJSX46dnWz6rtINrASeXArovxZABzb+an9r X-Received: by 2002:a17:906:f15:: with SMTP id z21mr7106762eji.119.1570698131144; Thu, 10 Oct 2019 02:02:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570698131; cv=none; d=google.com; s=arc-20160816; b=BaulCV955EneW6zuEBULViD3jQKJoLROYjLy+Dl+95d6EOGvi71ARr1GEdSqaNAhlC XCburxJP5S4QGxElckKAG8jRa0o28GdZhrdZAU+1ajdCtiK/BeMESMjK4gcAN45mq/ge QZwh1Tth0NodYPF+ne1HLSBoGEVY9Uj25FhiN9I+xZx9+5yuUHjbxuPnzjUSJLmjxKGe ri36tu23wcRkhMltuVNx7EOgFoP2w1GF3UJ53/ddaH5H2a+juhxqBMlaBTHVWZOr8Djc 4JSNEng1OVK9mP9+Q0eOvt+DwCnkEsc7pQ3RTj2dZNjjHHhVHeKkdVcRM//4B5uPkzhk DmQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=GGWm+WVzmpDR0MGJoVJljOMOdXOxMxvyaeBC9i3cIfk=; b=f/AxaGwN2Osse2XkGNCX3WZ/Rj/iKeIwzEquGMbyFCyudqavjBL+jwqKcLY+mEX6DX YPCRpYoilvPWao6VCuzESlQ54Avd48D6dvRF7vUUEiw7gfbnWQmUGRJQn67fE3VbrpYM ZnSAtTD5WK6yIsL75BnJ7miQjVIEo8dKjgWAWWJhb9u4k5cxGYNjvXKcK6rTmjZDOO/f 7JAx7VGUCNkXsJw/v1isg2l0fE/eTWLVV6VNoxjsDSXy6z+JyQB37JiFsvM1PF1s1mZP uytcrjeaySkyp5Brq5lRgl8ST9B8eeKsI8RspS0SmRoPjtqV1ZHd0IdtPyFnQ86LsCrZ +DXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CE5bN0KQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o32si3012376edc.306.2019.10.10.02.01.48; Thu, 10 Oct 2019 02:02:11 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=CE5bN0KQ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388270AbfJJIlK (ORCPT + 99 others); Thu, 10 Oct 2019 04:41:10 -0400 Received: from mail.kernel.org ([198.145.29.99]:45424 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388266AbfJJIlJ (ORCPT ); Thu, 10 Oct 2019 04:41:09 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id D010321D7C; Thu, 10 Oct 2019 08:41:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1570696868; bh=ew0MqeqxkZeCjlz7MmeD69SyuCnfBxiZvDklep9KzFE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CE5bN0KQnlVB7vHq6LNBmAqYhNUrcuhTVHC9iXf3fxzN7b3NsRwFAG1Rh3QYbFX1y rzZENlgtJMVqNWnfu2fyDxqh5Pza6uP1LaBOTrBbXzR22SFlxQz2plqRsdp4aNCzkr ZFR2sMvg4u232IIOEa+AlNKWMpf1kHzRsKxyhrAE= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Sean Nyekjaer , Marc Kleine-Budde Subject: [PATCH 5.3 037/148] can: mcp251x: mcp251x_hw_reset(): allow more time after a reset Date: Thu, 10 Oct 2019 10:34:58 +0200 Message-Id: <20191010083613.400234335@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191010083609.660878383@linuxfoundation.org> References: <20191010083609.660878383@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marc Kleine-Budde commit d84ea2123f8d27144e3f4d58cd88c9c6ddc799de upstream. Some boards take longer than 5ms to power up after a reset, so allow some retries attempts before giving up. Fixes: ff06d611a31c ("can: mcp251x: Improve mcp251x_hw_reset()") Cc: linux-stable Tested-by: Sean Nyekjaer Signed-off-by: Marc Kleine-Budde Signed-off-by: Greg Kroah-Hartman --- drivers/net/can/spi/mcp251x.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) --- a/drivers/net/can/spi/mcp251x.c +++ b/drivers/net/can/spi/mcp251x.c @@ -612,7 +612,7 @@ static int mcp251x_setup(struct net_devi static int mcp251x_hw_reset(struct spi_device *spi) { struct mcp251x_priv *priv = spi_get_drvdata(spi); - u8 reg; + unsigned long timeout; int ret; /* Wait for oscillator startup timer after power up */ @@ -626,10 +626,19 @@ static int mcp251x_hw_reset(struct spi_d /* Wait for oscillator startup timer after reset */ mdelay(MCP251X_OST_DELAY_MS); - reg = mcp251x_read_reg(spi, CANSTAT); - if ((reg & CANCTRL_REQOP_MASK) != CANCTRL_REQOP_CONF) - return -ENODEV; - + /* Wait for reset to finish */ + timeout = jiffies + HZ; + while ((mcp251x_read_reg(spi, CANSTAT) & CANCTRL_REQOP_MASK) != + CANCTRL_REQOP_CONF) { + usleep_range(MCP251X_OST_DELAY_MS * 1000, + MCP251X_OST_DELAY_MS * 1000 * 2); + + if (time_after(jiffies, timeout)) { + dev_err(&spi->dev, + "MCP251x didn't enter in conf mode after reset\n"); + return -EBUSY; + } + } return 0; }