From patchwork Tue Oct 14 05:41:53 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 399344 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 16E01140140 for ; Tue, 14 Oct 2014 16:45:15 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 62958A77EF; Tue, 14 Oct 2014 07:44:34 +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 iianZrSz-9JC; Tue, 14 Oct 2014 07:44:34 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id BAF48A771A; Tue, 14 Oct 2014 07:43:52 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 3D9F8A73FB for ; Tue, 14 Oct 2014 07:43:18 +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 N3Xs53ys+y4S for ; Tue, 14 Oct 2014 07:43:18 +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-pa0-f74.google.com (mail-pa0-f74.google.com [209.85.220.74]) by theia.denx.de (Postfix) with ESMTPS id 2D716A7480 for ; Tue, 14 Oct 2014 07:43:14 +0200 (CEST) Received: by mail-pa0-f74.google.com with SMTP id kq14so1294265pab.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=Z8cTiKT2whppsXrH6fqXBOZHASvMg/L89dFRJRYt9qE=; b=FAJ7O1W73UwSfX9DqbsltvZWRo+or4ahQQNih7bYDDgjxmuHTAtBvpJvVch1thd9PB v/FGp9noi9EwjfjEfTYdvtRxPdb+YfmbaLLXmMxGVo7c+UWUcxTZSqhpFjmsHaxKzZXv aiI5Vk5AAp+1gByAmSlLJ4jrGDrI+G1umw3i1EKz/2FxXkfvPk/8zVgMAKO7agx0ZdXJ w7DGstsfv9P0ZCL90i0xEgGXEWML9VfNkD6Myajffq5CW1oQ2SMkaYBrFKbmlpRnvN6Z uZLQhpWKOuinIrwzpA081fYjg//qv/Qk36ExBkefARhN3nL8abUlr/ZnzozfsHax44zv BXHQ== X-Gm-Message-State: ALoCoQnnDc8hLDzkgTPkvTQx/V6AjGBF/JonRGeT0ibIF5qs9jN12Vqq2UawU2lnTIRhIkTI64JL X-Received: by 10.68.135.99 with SMTP id pr3mr1650255pbb.9.1413265392997; Mon, 13 Oct 2014 22:43:12 -0700 (PDT) Received: from corpmail-nozzle1-2.hot.corp.google.com ([100.108.1.103]) by gmr-mx.google.com with ESMTPS id k66si806715yho.7.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:12 -0700 (PDT) Received: from kaki.bld.corp.google.com ([172.29.216.32]) by corpmail-nozzle1-2.hot.corp.google.com with ESMTP id KNKLB8VB.1; Mon, 13 Oct 2014 22:43:12 -0700 Received: by kaki.bld.corp.google.com (Postfix, from userid 121222) id C0048220F90; Mon, 13 Oct 2014 23:43:11 -0600 (MDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 13 Oct 2014 23:41:53 -0600 Message-Id: <1413265336-9571-7-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 06/29] dm: sandbox: Add a SPI emulation uclass 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 U-Boot includes a SPI emulation driver already but it is not explicit, and is hidden in the SPI flash code. Conceptually with sandbox's SPI implementation we have a layer which creates SPI bus transitions and a layer which interprets them, currently only for SPI flash. The latter is actually an emulation, and it should be possible to add more than one emulation - not just SPI flash. Add a SPI emulation uclass so that other emulations can be plugged in to support different types of emulated devices on difference buses/chip selects. Signed-off-by: Simon Glass Reviewed-by: Jagannadha Sutradharudu Teki --- Changes in v4: None Changes in v3: - Add a function comment for sandbox_spi_get_emul() Changes in v2: - Fix comment on 'slave' parameter to match the parameter name drivers/spi/Makefile | 1 + drivers/spi/spi-emul-uclass.c | 15 +++++++++++++++ include/dm/uclass-id.h | 1 + include/spi.h | 45 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 62 insertions(+) create mode 100644 drivers/spi/spi-emul-uclass.c diff --git a/drivers/spi/Makefile b/drivers/spi/Makefile index d1f1dd0..a1de028 100644 --- a/drivers/spi/Makefile +++ b/drivers/spi/Makefile @@ -8,6 +8,7 @@ # There are many options which enable SPI, so make this library available ifdef CONFIG_DM_SPI obj-y += spi-uclass.o +obj-$(CONFIG_SANDBOX) += spi-emul-uclass.o else obj-y += spi.o endif diff --git a/drivers/spi/spi-emul-uclass.c b/drivers/spi/spi-emul-uclass.c new file mode 100644 index 0000000..b436a0e --- /dev/null +++ b/drivers/spi/spi-emul-uclass.c @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2014 Google, Inc + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include +#include +#include + +UCLASS_DRIVER(spi_emul) = { + .id = UCLASS_SPI_EMUL, + .name = "spi_emul", +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 0afdc75..6e56382 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -18,6 +18,7 @@ enum uclass_id { UCLASS_TEST, UCLASS_TEST_FDT, UCLASS_TEST_BUS, + UCLASS_SPI_EMUL, /* sandbox SPI device emulator */ /* U-Boot uclasses start here */ UCLASS_GPIO, /* Bank of general-purpose I/O pins */ diff --git a/include/spi.h b/include/spi.h index 89949b1..aa0a48e 100644 --- a/include/spi.h +++ b/include/spi.h @@ -456,6 +456,35 @@ struct dm_spi_ops { int (*cs_info)(struct udevice *bus, uint cs, struct spi_cs_info *info); }; +struct dm_spi_emul_ops { + /** + * SPI transfer + * + * This writes "bitlen" bits out the SPI MOSI port and simultaneously + * clocks "bitlen" bits in the SPI MISO port. That's just the way SPI + * works. Here the device is a slave. + * + * The source of the outgoing bits is the "dout" parameter and the + * destination of the input bits is the "din" parameter. Note that + * "dout" and "din" can point to the same memory location, in which + * case the input data overwrites the output data (since both are + * buffered by temporary variables, this is OK). + * + * spi_xfer() interface: + * @slave: The SPI slave which will be sending/receiving the data. + * @bitlen: How many bits to write and read. + * @dout: Pointer to a string of bits sent to the device. The + * bits are held in a byte array and are sent MSB first. + * @din: Pointer to a string of bits that will be sent back to + * the master. + * @flags: A bitwise combination of SPI_XFER_* flags. + * + * Returns: 0 on success, not -1 on failure + */ + int (*xfer)(struct udevice *slave, unsigned int bitlen, + const void *dout, void *din, unsigned long flags); +}; + /** * spi_find_bus_and_cs() - Find bus and slave devices by number * @@ -545,12 +574,28 @@ int spi_ofdata_to_platdata(const void *blob, int node, struct spi_slave *spi); int spi_cs_info(struct udevice *bus, uint cs, struct spi_cs_info *info); struct sandbox_state; + +/** + * sandbox_spi_get_emul() - get an emulator for a SPI slave + * + * This provides a way to attach an emulated SPI device to a particular SPI + * slave, so that xfer() operations on the slave will be handled by the + * emulator. If a emulator already exists on that chip select it is returned. + * Otherwise one is created. + * + * @state: Sandbox state + * @bus: SPI bus requesting the emulator + * @slave: SPI slave device requesting the emulator + * @emuip: Returns pointer to emulator + * @return 0 if OK, -ve on error + */ int sandbox_spi_get_emul(struct sandbox_state *state, struct udevice *bus, struct udevice *slave, struct udevice **emulp); /* Access the serial operations for a device */ #define spi_get_ops(dev) ((struct dm_spi_ops *)(dev)->driver->ops) +#define spi_emul_get_ops(dev) ((struct dm_spi_emul_ops *)(dev)->driver->ops) #endif /* CONFIG_DM_SPI */ #endif /* _SPI_H_ */