From patchwork Fri Nov 22 18:05:50 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 293571 Return-Path: X-Original-To: incoming-dt@patchwork.ozlabs.org Delivered-To: patchwork-incoming-dt@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id B9A472C00E0 for ; Sat, 23 Nov 2013 05:06:26 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755647Ab3KVSGZ (ORCPT ); Fri, 22 Nov 2013 13:06:25 -0500 Received: from mail-bk0-f41.google.com ([209.85.214.41]:33139 "EHLO mail-bk0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755688Ab3KVSGY (ORCPT ); Fri, 22 Nov 2013 13:06:24 -0500 Received: by mail-bk0-f41.google.com with SMTP id v15so944605bkz.28 for ; Fri, 22 Nov 2013 10:06:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=lsLaHXnklkH8CEdso4mg1/fL5yM13DHuoZ7Z2ZasSSM=; b=JrSecrQc/wWZoI2/kAlPlQZyDhAHh6YrSfOhuxIhU52OJknFriY4OsWQHMwW0+hvWd X/iWDnUFG+SyW4w0GQP7n+5lfJ8R8nJdEHEGaFMOZ5NKKQEZVKLbffRQkJzaNYimPrdE X7F0uIZrogEJcwmgQyD70c7IKJkoMLvFUP7DCFhImG9bSHu0I++Vl19/Tgu2HDHo1ZOL yy/CKMumOiFDrqaOgCMpT5vpbXCGa08SirHgEBI6iPVMHi4skKziiAQVzBtaiAtAS6R4 UdZP2SdTPF8GnTnxlm8kCpIEhLqDJlhbt0biPOEUsnvlGXov1KRQfl8fQfPsBYHuJa8M eNIg== X-Received: by 10.205.36.193 with SMTP id tb1mr10342496bkb.28.1385143583543; Fri, 22 Nov 2013 10:06:23 -0800 (PST) Received: from localhost (port-90889.pppoe.wtnet.de. [84.46.67.125]) by mx.google.com with ESMTPSA id j6sm22433052bki.17.2013.11.22.10.06.22 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 22 Nov 2013 10:06:22 -0800 (PST) From: Thierry Reding To: Lee Jones , Samuel Ortiz Cc: Bernie Thompson , Andrew Bresticker , devicetree@vger.kernel.org, Rhyland Klein , Rob Herring , Pawel Moll , Mark Rutland , Ian Campbell Subject: [PATCH] mfd: cros ec: spi: Add delay for raising CS Date: Fri, 22 Nov 2013 19:05:50 +0100 Message-Id: <1385143550-31901-1-git-send-email-treding@nvidia.com> X-Mailer: git-send-email 1.8.4.2 Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org From: Rhyland Klein The EC has specific timing it requires. Add support for an optional delay after raising CS to fix timing issues. This is configurable based on a DT property "google,cros-ec-spi-msg-delay". If this property isn't set, then no delay will be added. However, if set it will cause a delay equal to the value passed to it to be inserted at the end of a transaction. Signed-off-by: Rhyland Klein Reviewed-by: Bernie Thompson Reviewed-by: Andrew Bresticker Cc: Rob Herring Cc: Pawel Moll Cc: Mark Rutland Cc: Ian Campbell Signed-off-by: Thierry Reding --- Changes in v2: - make property description more verbose Documentation/devicetree/bindings/mfd/cros-ec.txt | 9 +++++++ drivers/mfd/cros_ec_spi.c | 30 +++++++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/Documentation/devicetree/bindings/mfd/cros-ec.txt b/Documentation/devicetree/bindings/mfd/cros-ec.txt index 5f229c5f6da9..8009c3d87f33 100644 --- a/Documentation/devicetree/bindings/mfd/cros-ec.txt +++ b/Documentation/devicetree/bindings/mfd/cros-ec.txt @@ -17,6 +17,15 @@ Required properties (SPI): - compatible: "google,cros-ec-spi" - reg: SPI chip select +Optional properties (SPI): +- google,cros-ec-spi-msg-delay: Some implementations of the EC require some + additional processing time in order to accept new transactions. If the delay + between transactions is not long enough the EC may not be able to respond + properly to subsequent transactions and cause them to hang. This property + specifies the delay, in usecs, introduced between transactions to account + for the time required by the EC to get back into a state in which new data + can be accepted. + Required properties (LPC): - compatible: "google,cros-ec-lpc" - reg: List of (IO address, size) pairs defining the interface uses diff --git a/drivers/mfd/cros_ec_spi.c b/drivers/mfd/cros_ec_spi.c index 27be73523b9c..e3690fcb86ae 100644 --- a/drivers/mfd/cros_ec_spi.c +++ b/drivers/mfd/cros_ec_spi.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -62,10 +63,13 @@ * @spi: SPI device we are connected to * @last_transfer_ns: time that we last finished a transfer, or 0 if there * if no record + * @end_of_msg_delay: used to set the delay_usecs on the spi_transfer that + * is sent when we want to turn off CS at the end of a transaction. */ struct cros_ec_spi { struct spi_device *spi; s64 last_transfer_ns; + unsigned int end_of_msg_delay; }; static void debug_packet(struct device *dev, const char *name, u8 *ptr, @@ -238,6 +242,17 @@ static int cros_ec_command_spi_xfer(struct cros_ec_device *ec_dev, /* turn off CS */ spi_message_init(&msg); + + if (ec_spi->end_of_msg_delay) { + /* + * Add delay for last transaction, to ensure the rising edge + * doesn't come too soon after the end of the data. + */ + memset(&trans, '\0', sizeof(trans)); + trans.delay_usecs = ec_spi->end_of_msg_delay; + spi_message_add_tail(&trans, &msg); + } + final_ret = spi_sync(ec_spi->spi, &msg); ktime_get_ts(&ts); ec_spi->last_transfer_ns = timespec_to_ns(&ts); @@ -284,6 +299,17 @@ static int cros_ec_command_spi_xfer(struct cros_ec_device *ec_dev, return 0; } +static void cros_ec_probe_spi_dt(struct cros_ec_spi *ec_spi, struct device *dev) +{ + struct device_node *np = dev->of_node; + u32 val; + int ret; + + ret = of_property_read_u32(np, "google,cros-ec-spi-msg-delay", &val); + if (!ret) + ec_spi->end_of_msg_delay = val; +} + static int cros_ec_probe_spi(struct spi_device *spi) { struct device *dev = &spi->dev; @@ -305,6 +331,10 @@ static int cros_ec_probe_spi(struct spi_device *spi) if (!ec_dev) return -ENOMEM; + /* Check for any DT properties */ + if (IS_ENABLED(CONFIG_OF) && dev->of_node) + cros_ec_probe_spi_dt(ec_spi, dev); + spi_set_drvdata(spi, ec_dev); ec_dev->name = "SPI"; ec_dev->dev = dev;