From patchwork Tue Oct 14 05:41:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 399332 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 2E0EB140140 for ; Tue, 14 Oct 2014 16:43:23 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C097BA7544; Tue, 14 Oct 2014 07:43:21 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id rSi2YLPT6eYE; Tue, 14 Oct 2014 07:43:21 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 01B42A74C3; Tue, 14 Oct 2014 07:43:20 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id C7713A73FB for ; Tue, 14 Oct 2014 07:43:15 +0200 (CEST) Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GhhD9VnZ5tyt for ; Tue, 14 Oct 2014 07:43:15 +0200 (CEST) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-oi0-f74.google.com (mail-oi0-f74.google.com [209.85.218.74]) by theia.denx.de (Postfix) with ESMTPS id 6D067A73FA for ; Tue, 14 Oct 2014 07:43:15 +0200 (CEST) Received: by mail-oi0-f74.google.com with SMTP id v63so2879765oia.1 for ; Mon, 13 Oct 2014 22:43:13 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+g7+ZWf48QvgRBuMNvLtU6OpPj3JPm436naJiC9xNeY=; b=HRYPkoroGxAOe9gKy+4Yi0jy+rgQGX4OezfLh3/aRmUkkWmkGlU9PHzTXthk/kXK4k K59xzQONsUjF++O62dwLdVkEVW66tcqg213ZXcuxkuqMaaGHMqunxobwCPgA7OFSVe5i e5jWVHPsUiP2wrlmn3k7jvG+7f6TXleexUR6tU7coKsH8T/3tCAiQE92lmfUEf/fsJYW P6GudTUrDUIUX/NDeipdtn09iCScTu0qvELg0ejyhEMdUQRgeeGDv8YdGPbRq0bAVWDu S7l5b3wsdUcBnCWdOatMRyiY2OKpBMzQZ0ISjIsVm/1RnE5fDi4DBuCOy0SHekGFDs/C ri5g== X-Gm-Message-State: ALoCoQnEpBDJ9jCFds4EWOSEe3WooaKzTXGDvVkEZWpYAMj0dypHoUv7DcCjwSixEsYrGyJUHzYk X-Received: by 10.42.110.66 with SMTP id o2mr2277580icp.11.1413265393210; Mon, 13 Oct 2014 22:43:13 -0700 (PDT) Received: from corpmail-nozzle1-1.hot.corp.google.com ([100.108.1.104]) by gmr-mx.google.com with ESMTPS id n63si807682yho.5.2014.10.13.22.43.12 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Oct 2014 22:43:13 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-1.hot.corp.google.com with ESMTP id UK3byWnA.1; Mon, 13 Oct 2014 22:43:13 -0700 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id 1B9E82206F3; Mon, 13 Oct 2014 23:43:12 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 13 Oct 2014 23:41:56 -0600 Message-Id: <1413265336-9571-10-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 2.1.0.rc2.206.gedb03e5 In-Reply-To: <1413265336-9571-1-git-send-email-sjg@chromium.org> References: <1413265336-9571-1-git-send-email-sjg@chromium.org> Cc: u-boot-review@google.com, Jagannadha Sutradharudu Teki Subject: [U-Boot] [PATCH v4 09/29] dm: spi: Adjust cmd_spi to work with driver model X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.13 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de Driver model uses a different way to find the SPI bus and slave from the numbered devices given on the command line. Adjust the code to suit. We use a generic SPI device, and attach it to the SPI bus before performing the transaction. Signed-off-by: Simon Glass Reviewed-by: Jagannadha Sutradharudu Teki --- Changes in v4: None Changes in v3: - Use a generic SPI device for the 'sspi command' Changes in v2: None common/cmd_spi.c | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/common/cmd_spi.c b/common/cmd_spi.c index be5709c..64c3ffc 100644 --- a/common/cmd_spi.c +++ b/common/cmd_spi.c @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -42,19 +43,38 @@ static uchar din[MAX_SPI_BYTES]; static int do_spi_xfer(int bus, int cs) { struct spi_slave *slave; - int rcode = 0; - + int ret = 0; + +#ifdef CONFIG_DM_SPI + char name[30], *str; + struct udevice *dev; + + snprintf(name, sizeof(name), "generic_%d:%d", bus, cs); + str = strdup(name); + ret = spi_get_bus_and_cs(bus, cs, 1000000, mode, "spi_generic_drv", + str, &dev, &slave); + if (ret) + return ret; +#else slave = spi_setup_slave(bus, cs, 1000000, mode); if (!slave) { printf("Invalid device %d:%d\n", bus, cs); return -EINVAL; } +#endif - spi_claim_bus(slave); - if (spi_xfer(slave, bitlen, dout, din, - SPI_XFER_BEGIN | SPI_XFER_END) != 0) { - printf("Error during SPI transaction\n"); - rcode = -EIO; + ret = spi_claim_bus(slave); + if (ret) + goto done; + ret = spi_xfer(slave, bitlen, dout, din, + SPI_XFER_BEGIN | SPI_XFER_END); +#ifndef CONFIG_DM_SPI + /* We don't get an error code in this case */ + if (ret) + ret = -EIO; +#endif + if (ret) { + printf("Error %d during SPI transaction\n", ret); } else { int j; @@ -62,10 +82,13 @@ static int do_spi_xfer(int bus, int cs) printf("%02X", din[j]); printf("\n"); } +done: spi_release_bus(slave); +#ifndef CONFIG_DM_SPI spi_free_slave(slave); +#endif - return rcode; + return ret; } /*