From patchwork Thu May 17 11:02:22 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Saugata Das X-Patchwork-Id: 8718 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 0CBC123F00 for ; Thu, 17 May 2012 11:06:27 +0000 (UTC) Received: from mail-gg0-f180.google.com (mail-gg0-f180.google.com [209.85.161.180]) by fiordland.canonical.com (Postfix) with ESMTP id B8485A186B7 for ; Thu, 17 May 2012 11:06:26 +0000 (UTC) Received: by ggnf1 with SMTP id f1so1999582ggn.11 for ; Thu, 17 May 2012 04:06:26 -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=hN651G96/9ZdNjRdqKo1BmvHZAYaGs+wINvLdbSqdbA=; b=AcnQOczHMwoPiCLZWJhW43o1kxCsPKCyA+GLvQIHemHNhzVkDye/6uDKsO8aUdbAtZ vvabGRlxFR9eOj6DJlQxVmaE8wL4VFDC9XGZtGL+NUpJotnOx2ZmqFYbIuQunEjbpAoB 3xkDIy/F1wzR+dJ2kyYxvLJqeBIKo5cXVnOEuS9h5wK62Q1aQja3Gj/ozB70UoFSy4YF CRh70BTV2rwpzw1H9sUSyo+iOlzz8IhaXvTOWE9l5VfYB5G5oG0lQC9Lq6faZ5FQHBEO 5EyQug0lJ9npInYsvi5a7DWP08pEHAcVrUOnrqEgUNUN0Zytty6RevkTZdrqZ//6aDJr IOeQ== Received: by 10.50.203.39 with SMTP id kn7mr4701890igc.53.1337252786055; Thu, 17 May 2012 04:06:26 -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 o8csp20217ibd; Thu, 17 May 2012 04:06:25 -0700 (PDT) Received: by 10.14.98.198 with SMTP id v46mr1404890eef.36.1337252784384; Thu, 17 May 2012 04:06:24 -0700 (PDT) Received: from eu1sys200aog101.obsmtp.com (eu1sys200aog101.obsmtp.com. [207.126.144.111]) by mx.google.com with SMTP id f43si1712927eea.67.2012.05.17.04.06.20 (version=TLSv1/SSLv3 cipher=OTHER); Thu, 17 May 2012 04:06:24 -0700 (PDT) Received-SPF: neutral (google.com: 207.126.144.111 is neither permitted nor denied by best guess record for domain of saugata.das@stericsson.com) client-ip=207.126.144.111; Authentication-Results: mx.google.com; spf=neutral (google.com: 207.126.144.111 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-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob101.postini.com ([207.126.147.11]) with SMTP ID DSNKT7Tbql11wF54h1qjfSPs7XtTFkLK2E0T@postini.com; Thu, 17 May 2012 11:06:24 UTC Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C396B12E; Thu, 17 May 2012 11:05:58 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C080C29A7; Thu, 17 May 2012 11:05:56 +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 relay2.stm.gmessaging.net (Postfix) with ESMTPS id 973FAA8074; Thu, 17 May 2012 13:04:06 +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; Thu, 17 May 2012 13:04:16 +0200 From: Saugata Das To: Cc: , , , , , , Subject: [PATCH v2 2/2] [MMC-4.5] [MMC UTIL] Disable emulation Date: Thu, 17 May 2012 16:32:22 +0530 Message-ID: <1337252542-25795-2-git-send-email-saugata.das@stericsson.com> X-Mailer: git-send-email 1.7.4.3 In-Reply-To: <1337252542-25795-1-git-send-email-saugata.das@stericsson.com> References: <1337252542-25795-1-git-send-email-saugata.das@stericsson.com> MIME-Version: 1.0 X-Gm-Message-State: ALoCoQlXnEJXjB5eh3oAwHJ3M41YfgDsruXkH88lrnaJqQU2E4+JsdJjGkJRkocJoFI6tJYrdj05 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: Removed extra blank lines around do_disable_512B_emulation Review rework based on comments from Subhash Reviewed-by: Subhash Jadavani --- mmc.c | 6 ++++++ mmc.h | 10 ++++++++++ mmc_cmds.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ mmc_cmds.h | 1 + 4 files changed, 66 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..4bc1fd6 100644 --- a/mmc_cmds.c +++ b/mmc_cmds.c @@ -168,6 +168,55 @@ 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);