Received: by 10.223.164.202 with SMTP id h10csp933027wrb; Tue, 7 Nov 2017 17:54:49 -0800 (PST) X-Google-Smtp-Source: ABhQp+RCd2OnleNYzpVWUnm2VQAnPWZ8i10cMzUwmjK7kruFj40aTZxEMk6c6k6mucHp1/ijLdoC X-Received: by 10.99.154.65 with SMTP id e1mr667289pgo.18.1510106089141; Tue, 07 Nov 2017 17:54:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510106089; cv=none; d=google.com; s=arc-20160816; b=mwyOFnnRlloKLFC1FglBYWzrDzWmUmVP5nbJq+hIOJl8z1x7JPB67HYPbWKBoh5HRb M/n5jP5gP7ci814RzKu8JmktW/lxIRoU9OIAyH+uMMTilQXgC94FtDcYSfmK1O9u/jT1 zFePSCGcnac4uA2s09vJ36IDfnxVNID3teEYId/uD2oXeOEf7kkupoSpWZ/BqyzBzfgB bo0dEAH6AnUZQp6PRA4kKKDZ0f7zZYZGJgRx9gS1S4czpkNTjEN5HHDEQK8xBPsllhU/ nh6Lsfu1qcK6hPkoqJYEZsfEkpwlEaRnN+g/Z+Ov7ds3mCP8n/l2CEpTTppx9X8WQvuZ 54sQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature:dkim-signature :arc-authentication-results; bh=/TOCXGwxDdLRFgKePAqgCzH4Wq9PBkVMUZ5zXJZsFcI=; b=TcGgvkeSbSAxgsEuMYMm9BiW7zobEyYbcgGG7kbNHS1yCkpCcoHNtpgMgs4DLbENHV khp7MbYi0Fww6u3GBGuogYTIkjk4cJxC2Y0CbELZb2/0BfXYjTO8bTcWigVvNc/1r397 ftM1eHF8BHINuyyJouyAzhQTDUKdwKXzQwOVl2pg8yG2Nm/fJt6CGoLj+t/pyc4A/+vt NwEYO1ynXpExk4G9iFU3JVq58JL7opwq1vkGD/CnnKdvKVZnYhPUYHaYnSZ83OSAr30R lCfGnixl+k3kQOe74kR3eteWtYsKvQheSniyb4HWxNgH5M6K23PqM38fMiYVITNR8d18 7iVQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@google.com header.s=20161025 header.b=hUmV9ufR; dkim=fail header.i=@chromium.org header.s=google header.b=N5tngYon; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 9si2607098pfp.81.2017.11.07.17.54.36; Tue, 07 Nov 2017 17:54:49 -0800 (PST) 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=fail header.i=@google.com header.s=20161025 header.b=hUmV9ufR; dkim=fail header.i=@chromium.org header.s=google header.b=N5tngYon; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758385AbdKGRXC (ORCPT + 92 others); Tue, 7 Nov 2017 12:23:02 -0500 Received: from mail-ua0-f182.google.com ([209.85.217.182]:51578 "EHLO mail-ua0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753227AbdKGRW7 (ORCPT ); Tue, 7 Nov 2017 12:22:59 -0500 Received: by mail-ua0-f182.google.com with SMTP id 65so2202200uaq.8 for ; Tue, 07 Nov 2017 09:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=/TOCXGwxDdLRFgKePAqgCzH4Wq9PBkVMUZ5zXJZsFcI=; b=hUmV9ufRZGiSrkGe9cNbtQhssjhYWSIimimv68vLyjqWr9JPVaALDh58vVEJYjXtHb /V/a12ouf06hNjA0KHK4sHbVQlXA4Okwrk94wxHZSDdYoXlGJ2Au2sVu4okzK8ifY4Oi scpqZnUAml+AAtAxjXkglvZp403tfIxwU9F2kMZExnZ1TGxjm7ZBMzLYrM6EGTZcBztJ WX49CiNBA3EKl4sOXLqqLyePV1Xo2BMQbCZjOxjBEvEZi2H05hqSKRsqwt4C5WxTE26h ObrmSUc4ynw4r5zGg7ZEIB2ne7phL9/csbHEBq+eKbh6wacIfWKtkTP8ZthFNMKv8UB8 N7XA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=mime-version:sender:in-reply-to:references:from:date:message-id :subject:to:cc; bh=/TOCXGwxDdLRFgKePAqgCzH4Wq9PBkVMUZ5zXJZsFcI=; b=N5tngYon7/JntgaWnI32n/Q2hvTzviu/1IeXoAH3An66WghOBOWzp/KE6iT3UUgTfs dFQW6baGzrHPonxxZkGDNmUuQjUJvaHSA2q07u3AU08BYGesH+jBtbFQh8Smuw7LRA0+ q8yYFSlbFXLWlFklWwRCBaFx/QToGjfR/R1xk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:sender:in-reply-to:references:from :date:message-id:subject:to:cc; bh=/TOCXGwxDdLRFgKePAqgCzH4Wq9PBkVMUZ5zXJZsFcI=; b=Q2hZFhP5RIPea7gHoUGM9YxYIQCIiG2e7MjfbKZ6QLdmuFzNI9dIal432WZBVwdxyH ohd6tRP3e0DE3mF47P6avUiZO2j78wPlQRiFkVQ4TJrSOPT0J9m1nrPrkACFHrNRdwJ2 bopOx1JUFF+7tmKiFnPXsU5WlNm8KlJ72mV+l68g9sh+Xc7l+LD+RI7xDKIJbibfzN+4 b6hir+JPzhD+yrwDHEUJFbveMdFqf0b7JBmQSFe6xa7tHMg/ccR2UrYr5qnshJSVHM4s HABDTHFT4RdYDeQu876GKIKsnzQ9xIvt7STqaaDl79dKrfFmiYwefh2CtN4LyKq9b5zO aDYg== X-Gm-Message-State: AMCzsaXDdLckOekIZcEI6Htn7t82sJ7+gl3P08XmJqcPGY3jecfYp/5l tXo4NXa9HENOPE9rDOqObsB8Py5P/8PHhwfcHXiOIg== X-Received: by 10.159.55.82 with SMTP id a18mr16815317uae.130.1510075378261; Tue, 07 Nov 2017 09:22:58 -0800 (PST) MIME-Version: 1.0 Received: by 10.31.147.81 with HTTP; Tue, 7 Nov 2017 09:22:57 -0800 (PST) In-Reply-To: <5ae1292d-14dc-b917-84cc-2758e82c4795@nvidia.com> References: <20170908205011.77986-1-briannorris@chromium.org> <02aa65e7-e967-055b-2af3-2e9b6ef77935@nvidia.com> <20170919171401.GA10968@google.com> <20170920061317.GB13616@google.com> <6beb7b8c-f602-112b-73b2-22188dcea28e@nvidia.com> <5ae1292d-14dc-b917-84cc-2758e82c4795@nvidia.com> From: Doug Anderson Date: Tue, 7 Nov 2017 09:22:57 -0800 X-Google-Sender-Auth: KNX4EGgX9QZt1VhJ5vf1weVeYlY Message-ID: Subject: Re: [PATCH v3] platform/chrome: Use proper protocol transfer function To: Jon Hunter Cc: Shawn N , Olof Johansson , Benson Leung , Lee Jones , "linux-kernel@vger.kernel.org" , Brian Norris , Brian Norris , Gwendal Grignou , Enric Balletbo , Tomeu Vizoso , "linux-tegra@vger.kernel.org" , Alexandru M Stan Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, On Tue, Nov 7, 2017 at 3:28 AM, Jon Hunter wrote: > > On 10/10/17 17:52, Doug Anderson wrote: > > ... > >>> I'm still not clear on why we see an error only on the first >>> transaction after boot. In this case, the embedded controller >>> previously handled host commands from firmware just fine, and the >>> handoff between firmware and the kernel shouldn't be significant, from >>> the EC point of view. If host command timing is consistent from the >>> master, I would expect to see some constant error rate, eg. some >>> chance any host command will fail, rather than the first host command >>> always failing. >> >> The AP itself is often quite busy at boot and so the timings for >> everything change. That could easily explain the problems. > > Sorry for the delay, but I have finally had some time to look at this a > bit closer. I have been able to track down where the additional delay is > really needed and seems to explain what is going on. > > For starters, the SPI chip-select is under h/w control and so the > software delay has no impact on the timing between the chip-select > going active and the transaction starting as I had first thought. > > I found that a delay is needed between completing the probe the Tegra > SPI device and the first SPI transaction issued to the EC. In the Tegra > SPI probe the SPI controller is programmed for master mode, but at the > same time it clears the chip-select inactive polarity bit meaning that > initially the SPI chip-select default to active-high (rather that low > which seems odd). I believe that this then drives the chip-select low > (active for the EC) and until it is then configured when spi_setup() is > called which configures it as active-low for the EC. > To get the first transaction to work for the EC there needs to be a > delay after we program the chip-select polarity when spi_setup() is > called. For example ... > > diff --git a/drivers/mfd/cros_ec_spi.c b/drivers/mfd/cros_ec_spi.c > index 584367f3a0ed..c1075c3c60c8 100644 > --- a/drivers/mfd/cros_ec_spi.c > +++ b/drivers/mfd/cros_ec_spi.c > @@ -648,6 +648,8 @@ static int cros_ec_spi_probe(struct spi_device *spi) > if (err < 0) > return err; > > + udelay(100); > + This isn't totally crazy, but actually you could probably do this: ec_spi->last_transfer_ns = ktime_get_ns(); ...that will leverage already existing code and constants and also will avoid doing a delay if it wasn't needed. You could also then get rid of some "if (ec_spi->last_transfer_ns)" tests in the code. I'd support landing that. > ec_spi = devm_kzalloc(dev, sizeof(*ec_spi), GFP_KERNEL); > if (ec_spi == NULL) > return -ENOMEM; > > > You may say why not put a delay in the tegra_spi_setup() itself, but we > have some other SPI devices such as flash devices which are also use an > active-low chip-select which don't have any issues with this to date. > Furthermore, this delay is also probably device specific. > > From an EC perspective, if the chip-select is asserted is there a > turnaround time before it can be asserted again? Or in this case maybe > the issue is that the chip-select is asserted but no transaction occurs > before it is de-asserted and so is causing a problem. Please note that a > delay of around ~50us above still fails but 100us seems to be ok. Really nice detective work! > Finally, this also works-around the problem by avoiding the chip-select > from being pulsed low by defaulting all chip-selects to active-low but > maybe this just masks the problem. > > diff --git a/drivers/spi/spi-tegra114.c b/drivers/spi/spi-tegra114.c > index a76acedd7e2f..7c18204e61d9 100644 > --- a/drivers/spi/spi-tegra114.c > +++ b/drivers/spi/spi-tegra114.c > @@ -1117,7 +1117,7 @@ static int tegra_spi_probe(struct platform_device > goto exit_pm_disable; > } > - tspi->def_command1_reg = SPI_M_S; > + tspi->def_command1_reg = SPI_M_S | SPI_CS_POL_INACTIVE_MASK; Note that even though I'd support adding some sort of delay to the cros_ec driver, I'd also say that it _might_ make sense to mess with the SPI driver too, just to avoid glitching the lines at bootup. As you said, you shouldn't just willy nilly change the default but it seems like it could make sense to define an initial (board level) pinctrl state that's in effect until the first call to setup_bus(). That's a bit like the "init" pinctrl state that exists precisely to address these types of glitches, but unfortunately you can't use the automatic-ness of the "init" pinctrl state. That code assumes that by the end of probe you know how your pins should be configured. In your case you don't know how your pins should be configured until the first setup_bus() is called... Presumably you could add your own pinctrl state that mimics "init", or you could figure out how to improve the way the "init" pinctrl state works to allow a driver to defer the transition to "default". Another option might be to try to use the "idle" state, maybe in conjunction with the "init" pinctrl state. AKA use "init" to avoid glitches during probe and then require that by the end of probe that the device is Runtime Suspended, which would leave you in "idle" state. Then in setup_bus you make sure you keep track of the polarity in such a way that when you Runtime Resume you can come out of "idle" state without glitching. The board would need to define "init" and "idle" in a way that won't glitch things. As with my advice always, note that I'm not an expert so feel free to call into question my advice if it looks wrong. :-P > tegra_spi_writel(tspi, tspi->def_command1_reg, SPI_COMMAND1); > pm_runtime_put(&pdev->dev); > > Cheers > Jon > > -- > nvpublic From 1583412104406751059@xxx Tue Nov 07 12:57:36 +0000 2017 X-GM-THRID: 1578006392712496529 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread