From patchwork Wed May 16 16:26:55 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saugata Das X-Patchwork-Id: 8697 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 5205523E61 for ; Wed, 16 May 2012 16:27:43 +0000 (UTC) Received: from mail-yx0-f180.google.com (mail-yx0-f180.google.com [209.85.213.180]) by fiordland.canonical.com (Postfix) with ESMTP id 21E30A18A6C for ; Wed, 16 May 2012 16:27:43 +0000 (UTC) Received: by mail-yx0-f180.google.com with SMTP id q6so1034521yen.11 for ; Wed, 16 May 2012 09:27:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf:from:to:cc :subject:date:message-id:x-mailer:in-reply-to:references :mime-version:content-type:x-gm-message-state; bh=xUnkPi5USqMtlzMG4m7hfWlID0JqqXkTOsuvMIWRIX4=; b=Lx74D9qKyktGEEDOHPGePapK/wtAZ/uVtrSZzQWmPFR9ScT7c+NkpCdJ6/oIK6Sxle nuJarNDkI8SO/y1zTv3jE7yO4BpJFUBFTWyyxXSxcUsUqvmSW8/Toz6gIhoyE4/RaDjg qcGL2Pim+AKK/WTL7RPqjDPwLTD/DK9RJkH1ab1NCuG+mfSfmGjPwJAz/jQHtGc/5HUe RRksaQBwFEcx0BRK8BsJnODM3zvUY+MLTpC2jZus9dnmgN7tmY89fReaBR3Vg+AhYdZp 8wsiaT8v8t+jRXKE4gcTw8Cjnr6lL/of7XjB7ybzWSjn8Wh2denEO4jOmJDvLouzc+CR wW2g== Received: by 10.42.88.135 with SMTP id c7mr2287571icm.57.1337185662631; Wed, 16 May 2012 09:27:42 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.35.72 with SMTP id o8csp505077ibd; Wed, 16 May 2012 09:27:41 -0700 (PDT) Received: by 10.213.13.197 with SMTP id d5mr1643232eba.21.1337185661299; Wed, 16 May 2012 09:27:41 -0700 (PDT) Received: from eu1sys200aog112.obsmtp.com (eu1sys200aog112.obsmtp.com. [207.126.144.133]) by mx.google.com with SMTP id v13si954428eef.186.2012.05.16.09.27.35 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 16 May 2012 09:27:41 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.133 is neither permitted nor denied by best guess record for domain of saugata.das@stericsson.com) client-ip=207.126.144.133; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.133 is neither permitted nor denied by best guess record for domain of saugata.das@stericsson.com) smtp.mail=saugata.das@stericsson.com Received: from beta.dmz-us.st.com ([167.4.1.35]) (using TLSv1) by eu1sys200aob112.postini.com ([207.126.147.11]) with SMTP ID DSNKT7PVd+lUxWxUXOIO27skkFTyzWQEPNEX@postini.com; Wed, 16 May 2012 16:27:39 UTC Received: from zeta.dmz-us.st.com (ns4.st.com [167.4.16.71]) by beta.dmz-us.st.com (STMicroelectronics) with ESMTP id 6972E57; Wed, 16 May 2012 16:27:10 +0000 (GMT) Received: from relay1.stm.gmessaging.net (unknown [10.230.100.17]) by zeta.dmz-us.st.com (STMicroelectronics) with ESMTP id 6B9774E; Wed, 16 May 2012 14:00:05 +0000 (GMT) Received: from exdcvycastm022.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm022", Issuer "exdcvycastm022" (not verified)) by relay1.stm.gmessaging.net (Postfix) with ESMTPS id 21CFF24C080; Wed, 16 May 2012 18:27:20 +0200 (CEST) Received: from localhost (10.201.54.119) by exdcvycastm022.EQ1STM.local (10.230.100.30) with Microsoft SMTP Server (TLS) id 8.3.83.0; Wed, 16 May 2012 18:27:29 +0200 From: Saugata Das To: , Cc: , , , Subject: [PATCH 2/2] [MMC-4.5] [MMC UTIL] Disable emulation Date: Wed, 16 May 2012 21:56:55 +0530 Message-ID: <1337185615-17202-2-git-send-email-saugata.das@stericsson.com> X-Mailer: git-send-email 1.7.4.3 In-Reply-To: <1337185615-17202-1-git-send-email-saugata.das@stericsson.com> References: <1337185615-17202-1-git-send-email-saugata.das@stericsson.com> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQkH+dMirRLypVqsG6TLfilm0f+m8LXxqMbWpbtY12GuhppGLEKKQBw7BJOqTd2/lYAFbvvx From: Saugata Das In this patch, we add utility to disable emulation mode in the eMMC-4.5. This is done to increase the data sector size to 4KB. Signed-off-by: Saugata Das changes in v2: Review rework based on comments from Subhash Reviewed-by: Subhash Jadavani --- mmc.c | 6 ++++++ mmc.h | 10 ++++++++++ mmc_cmds.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ mmc_cmds.h | 1 + 4 files changed, 68 insertions(+), 0 deletions(-) diff --git a/mmc.c b/mmc.c index c27fc24..ebc7ab2 100644 --- a/mmc.c +++ b/mmc.c @@ -65,6 +65,12 @@ static struct Command commands[] = { "Set the eMMC writeprotect status of .", NULL }, + { do_disable_512B_emulation, -1, + "disable 512B emulation", "\n" + "Set the eMMC data sector size to 4KB by disabling emulation .", + NULL + }, + { 0, 0, 0, 0 } }; diff --git a/mmc.h b/mmc.h index 3af36f1..34c31d3 100644 --- a/mmc.h +++ b/mmc.h @@ -35,6 +35,16 @@ #define EXT_CSD_PART_SWITCH_TIME 199 #define EXT_CSD_BOOT_CFG 179 #define EXT_CSD_BOOT_WP 173 +#define EXT_CSD_WR_REL_PARAM 166 +#define EXT_CSD_NATIVE_SECTOR_SIZE 63 /* R */ +#define EXT_CSD_USE_NATIVE_SECTOR 62 /* R/W */ +#define EXT_CSD_DATA_SECTOR_SIZE 61 /* R */ + +/* + * WR_REL_PARAM field definitions + */ +#define HS_CTRL_REL (1<<0) +#define EN_REL_WR (1<<2) /* * EXT_CSD field definitions diff --git a/mmc_cmds.c b/mmc_cmds.c index 4562cef..f0e64c9 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -168,6 +168,57 @@ int do_writeprotect_set(int nargs, char **argv) return ret; } + +int do_disable_512B_emulation(int nargs, char **argv) +{ + __u8 ext_csd[512], native_sector_size, data_sector_size, wr_rel_param; + int fd, ret; + char *device; + + CHECK(nargs != 2, "Usage: mmc \n", exit(1)); + + device = argv[1]; + + fd = open(device, O_RDWR); + if (fd < 0) { + perror("open"); + exit(1); + } + + ret = read_extcsd(fd, ext_csd); + if (ret) { + fprintf(stderr, "Could not read EXT_CSD from %s\n", device); + exit(1); + } + + wr_rel_param = ext_csd[EXT_CSD_WR_REL_PARAM]; + native_sector_size = ext_csd[EXT_CSD_NATIVE_SECTOR_SIZE]; + data_sector_size = ext_csd[EXT_CSD_DATA_SECTOR_SIZE]; + + if (native_sector_size && + !data_sector_size && + (wr_rel_param & EN_REL_WR)) { + ret = write_extcsd_value(fd, EXT_CSD_USE_NATIVE_SECTOR, 1); + + if (ret) { + fprintf(stderr, "Could not write 0x%02x to " + "EXT_CSD[%d] in %s\n", + 1, EXT_CSD_BOOT_WP, device); + exit(1); + } + printf("MMC disable 512B emulation successful\n" + "Now reset the device to switch to 4KB " + "native sector mode\n"); + } else if (native_sector_size && data_sector_size) { + printf("MMC already disabled 512B emulation mode\n"); + } else { + printf("MMC does not support disabling 512B emulation mode\n"); + } + + return ret; +} + + int do_read_extcsd(int nargs, char **argv) { __u8 ext_csd[512], ext_csd_rev, reg; diff --git a/mmc_cmds.h b/mmc_cmds.h index 66e9acb..56f46d7 100644 --- a/mmc_cmds.h +++ b/mmc_cmds.h @@ -19,3 +19,4 @@ int do_read_extcsd(int nargs, char **argv); int do_write_extcsd(int nargs, char **argv); int do_writeprotect_get(int nargs, char **argv); int do_writeprotect_set(int nargs, char **argv); +int do_disable_512B_emulation(int nargs, char **argv);