From patchwork Tue Mar 22 07:37:28 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jagan Teki X-Patchwork-Id: 600422 X-Patchwork-Delegate: jagannadh.teki@gmail.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 3qTl5V59cHz9s5g for ; Tue, 22 Mar 2016 18:42:06 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id D799EA76FA; Tue, 22 Mar 2016 08:40:54 +0100 (CET) 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 V166AV6K8sgz; Tue, 22 Mar 2016 08:40:54 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 87BBEA76FD; Tue, 22 Mar 2016 08:40:33 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 020F7A76A7 for ; Tue, 22 Mar 2016 08:40:29 +0100 (CET) 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 2rtvQ2hQWv1k for ; Tue, 22 Mar 2016 08:40:28 +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-pf0-f194.google.com (mail-pf0-f194.google.com [209.85.192.194]) by theia.denx.de (Postfix) with ESMTPS id BA07BA74DE for ; Tue, 22 Mar 2016 08:40:11 +0100 (CET) Received: by mail-pf0-f194.google.com with SMTP id x3so34300379pfb.0 for ; Tue, 22 Mar 2016 00:40:11 -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=BskajDw8955B717jiYv0RPwxnsWUhaPYSIkIA2cTyjE=; b=PK+X/c8yc3fPj49BUs9C+wFF97HZWCcmAWwKxj8zCCZCb8mZEGyXSJOakKClvGJFxu tjXuEKBg9AOBXxfaUyGSXS3jPSL1e2OxYD7JVTGbt60zpj7bNWMsYrIMEKpda5vx89Y4 Zjtp3ulu4yjpk3dLY5GZyl1Acd+tZYbD/HL7OiuLmmN200ksxJcw9XfDqMoUiEICfOF2 GVriHWUEEoB+OBGoyDu79pVxjOPI/nmPjb6J/VtB4JAj8UrvTlJ/Z9knWcDWgLL07wS3 9B2tjb2cbnlkU/grycvktgcK6pQT5wg/TxOSdTd+NcXdZkmNZrBvjQmtQxMvN8/rQOOh k5Hg== X-Gm-Message-State: AD7BkJIdBwO/0FXUG+KEHBSj9tvFMQUyTlZfh/5SyHfXnKUDsIKcLu50ILiWLfJVmYlQmw== X-Received: by 10.98.80.10 with SMTP id e10mr51869143pfb.141.1458632410456; Tue, 22 Mar 2016 00:40:10 -0700 (PDT) Received: from jteki-Latitude-E7450.amcc.com ([182.73.239.130]) by smtp.gmail.com with ESMTPSA id ko9sm45814957pab.37.2016.03.22.00.40.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 22 Mar 2016 00:40:09 -0700 (PDT) From: Jagan Teki To: u-boot@lists.denx.de Date: Tue, 22 Mar 2016 13:07:28 +0530 Message-Id: <1458632319-24866-16-git-send-email-jteki@openedev.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1458632319-24866-1-git-send-email-jteki@openedev.com> References: <1458632319-24866-1-git-send-email-jteki@openedev.com> Cc: Michal Simek , Siva Durga Prasad Paladugu , Jagan Teki Subject: [U-Boot] [PATCH v7 16/87] spi_flash: Use mtd_info operation for SPI-NOR X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.15 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Since spi-nor is using mtd layer for flash operations this patch used mtd ops from user commands instead of legacy spi_flash{} ops. Cc: Simon Glass Cc: Bin Meng Cc: Mugunthan V N Cc: Michal Simek Cc: Siva Durga Prasad Paladugu Signed-off-by: Jagan Teki --- include/spi_flash.h | 60 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 48 insertions(+), 12 deletions(-) diff --git a/include/spi_flash.h b/include/spi_flash.h index c7fd4f3..43abec9 100644 --- a/include/spi_flash.h +++ b/include/spi_flash.h @@ -12,6 +12,7 @@ #include /* Because we dereference struct udevice here */ #include +#include #ifndef CONFIG_SF_DEFAULT_SPEED # define CONFIG_SF_DEFAULT_SPEED 1000000 @@ -112,6 +113,39 @@ struct spi_flash { typedef struct mtd_info spi_flash_t; +static inline int spi_flash_read(spi_flash_t *info, u32 offset, + size_t len, void *buf) +{ + return mtd_read(info, offset, len, &len, (u_char *)buf); +} + +static inline int spi_flash_write(spi_flash_t *info, u32 offset, + size_t len, const void *buf) +{ + return mtd_write(info, offset, len, &len, (u_char *)buf); +} + +static inline int spi_flash_erase(spi_flash_t *info, u32 offset, size_t len) +{ + struct erase_info instr; + + instr.mtd = info; + instr.addr = offset; + instr.len = len; + instr.callback = 0; + + return mtd_erase(info, &instr); +} + +static inline int spi_flash_protect(spi_flash_t *info, u32 ofs, + u32 len, bool prot) +{ + if (prot) + return mtd_lock(info, ofs, len); + else + return mtd_unlock(info, ofs, len); +} + #ifdef CONFIG_DM_MTD_SPI_NOR int spi_flash_probe_bus_cs(unsigned int busnum, unsigned int cs, @@ -137,6 +171,20 @@ void spi_flash_free(spi_flash_t *flash); #endif /* CONFIG_DM_MTD_SPI_NOR */ +#else + +static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len, + bool prot) +{ + if (!flash->flash_lock || !flash->flash_unlock) + return -EOPNOTSUPP; + + if (prot) + return flash->flash_lock(flash, ofs, len); + else + return flash->flash_unlock(flash, ofs, len); +} + #endif /* CONFIG_MTD_SPI_NOR */ struct dm_spi_flash_ops { @@ -266,18 +314,6 @@ static inline int spi_flash_erase(struct spi_flash *flash, u32 offset, } #endif -static inline int spi_flash_protect(struct spi_flash *flash, u32 ofs, u32 len, - bool prot) -{ - if (!flash->flash_lock || !flash->flash_unlock) - return -EOPNOTSUPP; - - if (prot) - return flash->flash_lock(flash, ofs, len); - else - return flash->flash_unlock(flash, ofs, len); -} - void spi_boot(void) __noreturn; void spi_spl_load_image(uint32_t offs, unsigned int size, void *vdst);