From patchwork Wed May 28 22:15:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Rae X-Patchwork-Id: 31077 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f198.google.com (mail-ve0-f198.google.com [209.85.128.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 9E730201F1 for ; Wed, 28 May 2014 22:17:22 +0000 (UTC) Received: by mail-ve0-f198.google.com with SMTP id sa20sf47170981veb.9 for ; Wed, 28 May 2014 15:17:22 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:date:message-id :mime-version:cc:subject:precedence:list-id:list-unsubscribe :list-archive:list-post:list-help:list-subscribe:sender:errors-to :x-original-sender:x-original-authentication-results:mailing-list :content-type:content-transfer-encoding; bh=YVc57iLdheV4rZLKlakhAAQx7J9X5mix46WFRvIxBls=; b=GfL+QZA1DZisdFrwq3vZ0XiuPQ6m7bHv+Jt+PRvUhSYPtM7e9pxMerQ+bMSP+H34hO 6EEd413wmSO6BjS3NM+OqhWYb4HLqLXPyHF6qfQ5+VptQEA+8hC07oI6O2qJq2krq40F zJ0W3NngNbUTQXsPgq9G3vw5U1ua3hafBWjEwAarCX6p4WDeqlRbDQpggrGiwovkOwe9 pNYt/65mKFnocJfFWgMLjuy1UF4vVHfZURyDZK0DCT83i6Muf3/+mhv4djYvMzTuDjSH wnmfZjL6zCyc24CPWwM1p+O68EJqKTqd2zIFk+kPTt8j+AF80ONl+euU42X+PxSH0KPC XtKA== X-Gm-Message-State: ALoCoQnE479kHyq/TOMw+EJKAhBBv5CcnJGYKS3/B9qV7EHLbrYYhGhA57U8Z+z7scqZIpikg9il X-Received: by 10.236.228.98 with SMTP id e92mr912575yhq.58.1401315442381; Wed, 28 May 2014 15:17:22 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.86.100 with SMTP id o91ls342516qgd.30.gmail; Wed, 28 May 2014 15:17:22 -0700 (PDT) X-Received: by 10.52.143.6 with SMTP id sa6mr2513221vdb.22.1401315442295; Wed, 28 May 2014 15:17:22 -0700 (PDT) Received: from mail-vc0-f182.google.com (mail-vc0-f182.google.com [209.85.220.182]) by mx.google.com with ESMTPS id to8si11846912vdb.2.2014.05.28.15.17.22 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 28 May 2014 15:17:22 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) client-ip=209.85.220.182; Received: by mail-vc0-f182.google.com with SMTP id id10so1068948vcb.41 for ; Wed, 28 May 2014 15:17:22 -0700 (PDT) X-Received: by 10.52.14.9 with SMTP id l9mr2259445vdc.41.1401315442164; Wed, 28 May 2014 15:17:22 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp238831vcb; Wed, 28 May 2014 15:17:21 -0700 (PDT) X-Received: by 10.180.19.201 with SMTP id h9mr5087594wie.17.1401315441172; Wed, 28 May 2014 15:17:21 -0700 (PDT) Received: from theia.denx.de (theia.denx.de. [85.214.87.163]) by mx.google.com with ESMTP id et8si16704196wib.78.2014.05.28.15.17.20 for ; Wed, 28 May 2014 15:17:21 -0700 (PDT) Received-SPF: none (google.com: u-boot-bounces@lists.denx.de does not designate permitted sender hosts) client-ip=85.214.87.163; Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id B74454B6A2; Thu, 29 May 2014 00:17:18 +0200 (CEST) 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 cwBcdMV7ihOg; Thu, 29 May 2014 00:17:17 +0200 (CEST) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 4932F4B6ED; Thu, 29 May 2014 00:16:44 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 456894B6ED for ; Thu, 29 May 2014 00:16:26 +0200 (CEST) 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 2HN8qgSJZJHs for ; Thu, 29 May 2014 00:16:02 +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-gw2-out.broadcom.com (mail-gw2-out.broadcom.com [216.31.210.63]) by theia.denx.de (Postfix) with ESMTP id 72FCB4B6A2 for ; Thu, 29 May 2014 00:15:52 +0200 (CEST) X-IronPort-AV: E=Sophos;i="4.98,930,1392192000"; d="scan'208";a="31692179" Received: from irvexchcas08.broadcom.com (HELO IRVEXCHCAS08.corp.ad.broadcom.com) ([10.9.208.57]) by mail-gw2-out.broadcom.com with ESMTP; 28 May 2014 15:17:22 -0700 Received: from IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) by IRVEXCHCAS08.corp.ad.broadcom.com (10.9.208.57) with Microsoft SMTP Server (TLS) id 14.3.174.1; Wed, 28 May 2014 15:15:48 -0700 Received: from mail-irva-13.broadcom.com (10.10.10.20) by IRVEXCHSMTP1.corp.ad.broadcom.com (10.9.207.51) with Microsoft SMTP Server id 14.3.174.1; Wed, 28 May 2014 15:15:48 -0700 Received: from mail.broadcom.com (lbrmn-vmlnx03.ric.broadcom.com [10.136.4.105]) by mail-irva-13.broadcom.com (Postfix) with ESMTP id 0D7539F9F7; Wed, 28 May 2014 15:15:47 -0700 (PDT) From: Steve Rae To: Date: Wed, 28 May 2014 15:15:46 -0700 Message-ID: <1401315346-30231-1-git-send-email-srae@broadcom.com> X-Mailer: git-send-email 1.8.5 MIME-Version: 1.0 Cc: Steve Rae , Stephen Warren , Pantelis@theia.denx.de, Antoniou , Tom Rini Subject: [U-Boot] [PATCH] mmc: add wrappers for MMC block_{read, write, erase} X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: , List-Help: , List-Subscribe: , Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: srae@broadcom.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.182 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 Each wrapper function: - switches to the specified physical partition, then - performs the original function, and then - switches back to the original physical partition where the physical partition (aka HW partition) is 0=User, 1=Boot1, 2=Boot2, etc. Signed-off-by: Steve Rae --- based on a discussion: http://lists.denx.de/pipermail/u-boot/2014-April/178171.html The original calling code is (for example): mmc->block_dev.block_read(dev_num, start, blkcnt, buffer) Therefore, these wrappers use the following naming convention: mmc_block_read_hwpart(dev_num, part_num, start, blkcnt, buffer) "hwpart" comes from: Stephen Warren drivers/mmc/Makefile | 1 + drivers/mmc/mmc_hwpart.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++ include/mmc.h | 10 +++++++ 3 files changed, 86 insertions(+) create mode 100644 drivers/mmc/mmc_hwpart.c diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile index 4c6ab9e..04f87f9 100644 --- a/drivers/mmc/Makefile +++ b/drivers/mmc/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_FSL_ESDHC) += fsl_esdhc.o obj-$(CONFIG_FTSDC010) += ftsdc010_mci.o obj-$(CONFIG_FTSDC021) += ftsdc021_sdhci.o obj-$(CONFIG_GENERIC_MMC) += mmc.o +obj-$(CONFIG_GENERIC_MMC) += mmc_hwpart.o obj-$(CONFIG_GENERIC_ATMEL_MCI) += gen_atmel_mci.o obj-$(CONFIG_MMC_SPI) += mmc_spi.o obj-$(CONFIG_ARM_PL180_MMCI) += arm_pl180_mmci.o diff --git a/drivers/mmc/mmc_hwpart.c b/drivers/mmc/mmc_hwpart.c new file mode 100644 index 0000000..1c29f8f --- /dev/null +++ b/drivers/mmc/mmc_hwpart.c @@ -0,0 +1,75 @@ +/* + * Copyright 2014 Broadcom Corporation. + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include + +static int switch_part(struct mmc *mmc, + int dev, + unsigned int chk_part_num, + unsigned int part_num) +{ + if (!mmc) + return -1; + + if (mmc->part_num != chk_part_num) { + if (mmc_switch_part(dev, part_num)) { + printf("MMC partition switch to %d failed [dev=%d]\n", + part_num, dev); + return -1; + } + } + return 0; +} + +unsigned long mmc_block_read_hwpart(int dev, + unsigned int part_num, + lbaint_t start, + lbaint_t blkcnt, + void *buffer) +{ + unsigned long rc = 0; + struct mmc *mmc = find_mmc_device(dev); + + if (switch_part(mmc, dev, part_num, part_num)) + return 0; + rc = mmc->block_dev.block_read(dev, start, blkcnt, buffer); + switch_part(mmc, dev, part_num, mmc->part_num); + + return rc; +} + +unsigned long mmc_block_write_hwpart(int dev, + unsigned int part_num, + lbaint_t start, + lbaint_t blkcnt, + const void *buffer) +{ + unsigned long rc = 0; + struct mmc *mmc = find_mmc_device(dev); + + if (switch_part(mmc, dev, part_num, part_num)) + return 0; + rc = mmc->block_dev.block_write(dev, start, blkcnt, buffer); + switch_part(mmc, dev, part_num, mmc->part_num); + + return rc; +} + +unsigned long mmc_block_erase_hwpart(int dev, + unsigned int part_num, + lbaint_t start, + lbaint_t blkcnt) +{ + unsigned long rc = -1; + struct mmc *mmc = find_mmc_device(dev); + + if (switch_part(mmc, dev, part_num, part_num)) + return -1; + rc = mmc->block_dev.block_erase(dev, start, blkcnt); + switch_part(mmc, dev, part_num, mmc->part_num); + + return rc; +} diff --git a/include/mmc.h b/include/mmc.h index a3a100b..4871c08 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -347,6 +347,16 @@ int mmc_rpmb_read(struct mmc *mmc, void *addr, unsigned short blk, unsigned short cnt, unsigned char *key); int mmc_rpmb_write(struct mmc *mmc, void *addr, unsigned short blk, unsigned short cnt, unsigned char *key); +/* Functions to read/write/erase from the specified HW partition */ +unsigned long mmc_block_read_hwpart(int dev, unsigned int part_num, + lbaint_t start, lbaint_t blkcnt, + void *buffer); +unsigned long mmc_block_write_hwpart(int dev, unsigned int part_num, + lbaint_t start, lbaint_t blkcnt, + const void *buffer); + +unsigned long mmc_block_erase_hwpart(int dev, unsigned int part_num, + lbaint_t start, lbaint_t blkcnt); /** * Start device initialization and return immediately; it does not block on * polling OCR (operation condition register) status. Then you should call