From patchwork Tue Oct 14 05:42:10 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 399351 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 3C9B114007D for ; Tue, 14 Oct 2014 16:46:12 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 7F3C2A764F; Tue, 14 Oct 2014 07:45:08 +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 ypCCaY-bTXRO; Tue, 14 Oct 2014 07:45:08 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id DB5ADA77F6; Tue, 14 Oct 2014 07:44:10 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 720C2A7516 for ; Tue, 14 Oct 2014 07:43:20 +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 X3NPmtCBBmSE for ; Tue, 14 Oct 2014 07:43:20 +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-f73.google.com (mail-oi0-f73.google.com [209.85.218.73]) by theia.denx.de (Postfix) with ESMTPS id 4EF15A7475 for ; Tue, 14 Oct 2014 07:43:15 +0200 (CEST) Received: by mail-oi0-f73.google.com with SMTP id u20so2857957oif.2 for ; Mon, 13 Oct 2014 22:43:14 -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=4qJmMDqniFIK92itvaP78jrn6R0wQfT624nmKhwFUMc=; b=bP+0AqM9CYCQbrj15RiooYTl/Pl2d/2X2aA2uis+LtWqIhoURSHj3WpInuVgcfV5y1 QH5U79d+Acf0LnAiWqNrYxMq/uivlWWJUpfcBTXoAuCmrpRu26wzIERrx7eJlw15V89f CIvaePeUkv2BMdTHzbdoLO/lASUKEsD4aXYaNxM844vO1L2oVQENyrQp+L36Gu0Mt1Y7 GvmPheomuy1rXOlkrrRL3YDotGu/BL0QiS5dwGV3L0M5Lwz1O++5Z7eRhzmYI/Sc/eVp Oz8c9y1H+npHVHI6RueruTUZTtgqKTJ2iBdQSL29z3mStTobVe617nwyNGF+ARuYOjXC JvCQ== X-Gm-Message-State: ALoCoQnyJ4Yf+3g3RZxllaX49fxnzL8SIc+mABuSgJTnVlJ0J4d48vzUnkkT0F/CM2IZJjIrNIbV X-Received: by 10.43.147.196 with SMTP id kd4mr2352876icc.2.1413265394600; Mon, 13 Oct 2014 22:43:14 -0700 (PDT) Received: from corpmail-nozzle1-1.hot.corp.google.com ([100.108.1.104]) by gmr-mx.google.com with ESMTPS id n24si807372yha.6.2014.10.13.22.43.14 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Oct 2014 22:43:14 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-1.hot.corp.google.com with ESMTP id 4jCPH2nB.3; Mon, 13 Oct 2014 22:43:14 -0700 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id C6196221D7F; Mon, 13 Oct 2014 23:43:13 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 13 Oct 2014 23:42:10 -0600 Message-Id: <1413265336-9571-24-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 23/29] dm: spi: Add tests 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 These tests use SPI flash (and the sandbox emulation) to operate. Signed-off-by: Simon Glass Acked-by: Jagannadha Sutradharudu Teki --- Changes in v4: None Changes in v3: - Expand SPI tests to cover compatibility functions - Minor renames for clarity Changes in v2: - Create a 'spi.bin' file for the SPI tests test/dm/Makefile | 1 + test/dm/spi.c | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++++ test/dm/test-dm.sh | 2 + 3 files changed, 130 insertions(+) create mode 100644 test/dm/spi.c diff --git a/test/dm/Makefile b/test/dm/Makefile index 5c2415e..d1b9c9a 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -18,4 +18,5 @@ obj-$(CONFIG_DM_TEST) += core.o obj-$(CONFIG_DM_TEST) += ut.o ifneq ($(CONFIG_SANDBOX),) obj-$(CONFIG_DM_GPIO) += gpio.o +obj-$(CONFIG_DM_SPI) += spi.o endif diff --git a/test/dm/spi.c b/test/dm/spi.c new file mode 100644 index 0000000..61b5b25 --- /dev/null +++ b/test/dm/spi.c @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2013 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Test that we can find buses and chip-selects */ +static int dm_test_spi_find(struct dm_test_state *dms) +{ + struct sandbox_state *state = state_get_current(); + struct spi_slave *slave; + struct udevice *bus, *dev; + const int busnum = 0, cs = 0, mode = 0, speed = 1000000, cs_b = 1; + struct spi_cs_info info; + int of_offset; + + ut_asserteq(-ENODEV, uclass_find_device_by_seq(UCLASS_SPI, busnum, + false, &bus)); + + /* + * spi_post_bind() will bind devices to chip selects. Check this then + * remove the emulation and the slave device. + */ + ut_asserteq(0, uclass_get_device_by_seq(UCLASS_SPI, busnum, &bus)); + ut_assertok(spi_cs_info(bus, cs, &info)); + of_offset = info.dev->of_offset; + sandbox_sf_unbind_emul(state_get_current(), busnum, cs); + device_remove(info.dev); + device_unbind(info.dev); + + /* + * Even though the device is gone, the sandbox SPI drivers always + * reports that CS 0 is present + */ + ut_assertok(spi_cs_info(bus, cs, &info)); + ut_asserteq_ptr(info.dev, NULL); + + /* This finds nothing because we removed the device */ + ut_asserteq(-ENODEV, spi_find_bus_and_cs(busnum, cs, &bus, &dev)); + ut_asserteq(-ENODEV, spi_get_bus_and_cs(busnum, cs, speed, mode, + NULL, 0, &bus, &slave)); + + /* + * This forces the device to be re-added, but there is no emulation + * connected so the probe will fail. We require that bus is left + * alone on failure, and that the spi_get_bus_and_cs() does not add + * a 'partially-inited' device. + */ + ut_asserteq(-ENODEV, spi_find_bus_and_cs(busnum, cs, &bus, &dev)); + ut_asserteq(-ENOENT, spi_get_bus_and_cs(busnum, cs, speed, mode, + "spi_flash_std", "name", &bus, + &slave)); + ut_assertok(spi_cs_info(bus, cs, &info)); + ut_asserteq_ptr(info.dev, NULL); + + /* Add the emulation and try again */ + ut_assertok(sandbox_sf_bind_emul(state, busnum, cs, bus, of_offset, + "name")); + ut_assertok(spi_find_bus_and_cs(busnum, cs, &bus, &dev)); + ut_assertok(spi_get_bus_and_cs(busnum, cs, speed, mode, + "spi_flash_std", "name", &bus, &slave)); + + ut_assertok(spi_cs_info(bus, cs, &info)); + ut_asserteq_ptr(info.dev, slave->dev); + + /* We should be able to add something to another chip select */ + ut_assertok(sandbox_sf_bind_emul(state, busnum, cs_b, bus, of_offset, + "name")); + ut_assertok(spi_get_bus_and_cs(busnum, cs_b, speed, mode, + "spi_flash_std", "name", &bus, &slave)); + ut_assertok(spi_cs_info(bus, cs_b, &info)); + ut_asserteq_ptr(info.dev, slave->dev); + + /* + * Since we are about to destroy all devices, we must tell sandbox + * to forget the emulation device + */ + sandbox_sf_unbind_emul(state_get_current(), busnum, cs); + sandbox_sf_unbind_emul(state_get_current(), busnum, cs_b); + + return 0; +} +DM_TEST(dm_test_spi_find, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test that sandbox SPI works correctly */ +static int dm_test_spi_xfer(struct dm_test_state *dms) +{ + struct spi_slave *slave; + struct udevice *bus; + const int busnum = 0, cs = 0, mode = 0; + const char dout[5] = {0x9f}; + unsigned char din[5]; + + ut_assertok(spi_get_bus_and_cs(busnum, cs, 1000000, mode, NULL, 0, + &bus, &slave)); + ut_assertok(spi_claim_bus(slave)); + ut_assertok(spi_xfer(slave, 40, dout, din, + SPI_XFER_BEGIN | SPI_XFER_END)); + ut_asserteq(0xff, din[0]); + ut_asserteq(0x20, din[1]); + ut_asserteq(0x20, din[2]); + ut_asserteq(0x15, din[3]); + spi_release_bus(slave); + + /* + * Since we are about to destroy all devices, we must tell sandbox + * to forget the emulation device + */ +#ifdef CONFIG_DM_SPI_FLASH + sandbox_sf_unbind_emul(state_get_current(), busnum, cs); +#endif + + return 0; +} +DM_TEST(dm_test_spi_xfer, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); diff --git a/test/dm/test-dm.sh b/test/dm/test-dm.sh index ef5aca5..bb99677 100755 --- a/test/dm/test-dm.sh +++ b/test/dm/test-dm.sh @@ -4,4 +4,6 @@ NUM_CPUS=$(cat /proc/cpuinfo |grep -c processor) dtc -I dts -O dtb test/dm/test.dts -o test/dm/test.dtb make O=sandbox sandbox_config make O=sandbox -s -j${NUM_CPUS} +dd if=/dev/zero of=spi.bin bs=1M count=2 ./sandbox/u-boot -d test/dm/test.dtb -c "dm test" +rm spi.bin