From patchwork Mon Mar 11 16:08:08 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 226589 X-Patchwork-Delegate: trini@ti.com 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 5F4B92C02A6 for ; Tue, 12 Mar 2013 03:12:42 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 54CDD4A242; Mon, 11 Mar 2013 17:12:00 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 trCHRDwl+HGF; Mon, 11 Mar 2013 17:12:00 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 625BA4A253; Mon, 11 Mar 2013 17:10:40 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id A45BE4A16B for ; Mon, 11 Mar 2013 17:09:25 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de 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 fATGYBvktdT4 for ; Mon, 11 Mar 2013 17:09:19 +0100 (CET) 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-qe0-f74.google.com (mail-qe0-f74.google.com [209.85.128.74]) by theia.denx.de (Postfix) with ESMTPS id 0A2DD4A202 for ; Mon, 11 Mar 2013 17:09:03 +0100 (CET) Received: by mail-qe0-f74.google.com with SMTP id 9so394193qea.3 for ; Mon, 11 Mar 2013 09:09:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer:in-reply-to :references:x-gm-message-state; bh=JtKdEiHhN+jQYFty3VcRTnGHmeCtwx6FHcuCsSnWI+M=; b=cTNzfzaKZrAAt+nY0KT1gYxZmDBQZ7huONewEKh+PDvwJNvzOslwAgCK4/BMM226z+ c/yhD/5Q1PzRTidhqFIuLXMbpYgNS0FxGgvMydUvQRYL4hcfxFrkXwh6fJb2kfPVAze9 UtB6gZDavlbPwtEaeYgli0ygI2McEbH+iRH6bCnONNveKX7XlXDwexagn3oCjEDDJ7fV BPO6ZRlyihEq5SeyO1CdNuLfQqICjH3ZqVz0EtteWJ+eN78mfEQTnvgHpF+I60dWh2+C Hyb/BysaBeXuw6+WQ7tyBNYqdCGcXXs4zulJmSkGJMOn2Mqe/Gbm7lBJmvaGeLUG+39/ J4pg== X-Received: by 10.236.116.194 with SMTP id g42mr7800929yhh.29.1363018142245; Mon, 11 Mar 2013 09:09:02 -0700 (PDT) Received: from corp2gmr1-1.hot.corp.google.com (corp2gmr1-1.hot.corp.google.com [172.24.189.92]) by gmr-mx.google.com with ESMTPS id f64si1086905yhj.7.2013.03.11.09.09.00 (version=TLSv1.1 cipher=AES128-SHA bits=128/128); Mon, 11 Mar 2013 09:09:02 -0700 (PDT) Received: from kaka.mtv.corp.google.com (kaka.mtv.corp.google.com [172.22.73.79]) by corp2gmr1-1.hot.corp.google.com (Postfix) with ESMTP id 4F3ED31C107; Mon, 11 Mar 2013 09:08:59 -0700 (PDT) Received: by kaka.mtv.corp.google.com (Postfix, from userid 121222) id 2D965160412; Mon, 11 Mar 2013 09:08:59 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Date: Mon, 11 Mar 2013 09:08:08 -0700 Message-Id: <1363018093-28979-11-git-send-email-sjg@chromium.org> X-Mailer: git-send-email 1.8.1.3 In-Reply-To: <1363018093-28979-1-git-send-email-sjg@chromium.org> References: <1363018093-28979-1-git-send-email-sjg@chromium.org> X-Gm-Message-State: ALoCoQn7dB28qqLr+XRFz001EUAMg/DDkvqfbRWovHjDmR9hp+c5BZ615OHJbAmz9483RkuOKWgTfapFunZ9xa+4iTiCXVk/OA56KTEOUIy6htABoVVD4e+n+TWeDivctQTQ9KOSMPo+KLN//ch8MFfV0TKWRYwTyEd4FV1VLSW+1I4GLA5LZ7OaLNJx87Wfp/OBM0AQdMky Cc: Graeme Russ , Tom Warren Subject: [U-Boot] [PATCH v2 10/15] sf: Enable FDT-based configuration and memory mapping X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 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 Enable device tree control of SPI flash, and use this to implement memory-mapped SPI flash, which is supported on Intel chips. Signed-off-by: Simon Glass --- Changes in v2: None drivers/mtd/spi/spi_flash.c | 46 ++++++++++++++++++++++++++++++++++++++++++++- include/fdtdec.h | 1 + include/spi_flash.h | 1 + lib/fdtdec.c | 1 + 4 files changed, 48 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi/spi_flash.c b/drivers/mtd/spi/spi_flash.c index b82011d..111185a 100644 --- a/drivers/mtd/spi/spi_flash.c +++ b/drivers/mtd/spi/spi_flash.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -15,6 +16,8 @@ #include "spi_flash_internal.h" +DECLARE_GLOBAL_DATA_PTR; + static void spi_flash_addr(u32 addr, u8 *cmd) { /* cmd[0] is actual command */ @@ -146,6 +149,10 @@ int spi_flash_cmd_read_fast(struct spi_flash *flash, u32 offset, { u8 cmd[5]; + /* Handle memory-mapped SPI */ + if (flash->memory_map) + memcpy(data, flash->memory_map + offset, len); + cmd[0] = CMD_READ_ARRAY_FAST; spi_flash_addr(offset, cmd); cmd[4] = 0x00; @@ -275,6 +282,34 @@ int spi_flash_cmd_write_status(struct spi_flash *flash, u8 sr) return 0; } +#ifdef CONFIG_OF_CONTROL +int spi_flash_decode_fdt(const void *blob, struct spi_flash *flash) +{ + fdt_addr_t addr; + fdt_size_t size; + int node; + + /* If there is no node, do nothing */ + node = fdtdec_next_compatible(blob, 0, COMPAT_GENERIC_SPI_FLASH); + if (node < 0) + return 0; + + addr = fdtdec_get_addr_size(blob, node, "memory-map", &size); + if (addr == FDT_ADDR_T_NONE) { + debug("%s: Cannot decode address\n", __func__); + return 0; + } + + if (flash->size != size) { + debug("%s: Memory map must cover entire device\n", __func__); + return -1; + } + flash->memory_map = (void *)addr; + + return 0; +} +#endif /* CONFIG_OF_CONTROL */ + /* * The following table holds all device probe functions * @@ -391,9 +426,18 @@ struct spi_flash *spi_flash_probe(unsigned int bus, unsigned int cs, goto err_manufacturer_probe; } +#ifdef CONFIG_OF_CONTROL + if (spi_flash_decode_fdt(gd->fdt_blob, flash)) { + debug("SF: FDT decode error\n"); + goto err_manufacturer_probe; + } +#endif printf("SF: Detected %s with page size ", flash->name); print_size(flash->sector_size, ", total "); - print_size(flash->size, "\n"); + print_size(flash->size, ""); + if (flash->memory_map) + printf(", mapped at %p", flash->memory_map); + puts("\n"); spi_release_bus(spi); diff --git a/include/fdtdec.h b/include/fdtdec.h index d86dbe2..a46e51c 100644 --- a/include/fdtdec.h +++ b/include/fdtdec.h @@ -83,6 +83,7 @@ enum fdt_compat_id { COMPAT_SAMSUNG_EXYNOS_EHCI, /* Exynos EHCI controller */ COMPAT_SAMSUNG_EXYNOS_USB_PHY, /* Exynos phy controller for usb2.0 */ COMPAT_MAXIM_MAX77686_PMIC, /* MAX77686 PMIC */ + COMPAT_GENERIC_SPI_FLASH, /* Generic SPI Flash chip */ COMPAT_COUNT, }; diff --git a/include/spi_flash.h b/include/spi_flash.h index 030d49c..3b6a44e 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -39,6 +39,7 @@ struct spi_flash { /* Erase (sector) size */ u32 sector_size; + void *memory_map; /* Address of read-only SPI flash access */ int (*read)(struct spi_flash *flash, u32 offset, size_t len, void *buf); int (*write)(struct spi_flash *flash, u32 offset, diff --git a/lib/fdtdec.c b/lib/fdtdec.c index e99a4b9..2145354 100644 --- a/lib/fdtdec.c +++ b/lib/fdtdec.c @@ -56,6 +56,7 @@ static const char * const compat_names[COMPAT_COUNT] = { COMPAT(SAMSUNG_EXYNOS_EHCI, "samsung,exynos-ehci"), COMPAT(SAMSUNG_EXYNOS_USB_PHY, "samsung,exynos-usb-phy"), COMPAT(MAXIM_MAX77686_PMIC, "maxim,max77686_pmic"), + COMPAT(GENERIC_SPI_FLASH, "spi-flash"), }; const char *fdtdec_get_compatible(enum fdt_compat_id id)