From patchwork Mon Jan 21 11:43:55 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amar X-Patchwork-Id: 14140 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 EEA7D23E02 for ; Mon, 21 Jan 2013 11:29:03 +0000 (UTC) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by fiordland.canonical.com (Postfix) with ESMTP id 968F0A189F6 for ; Mon, 21 Jan 2013 11:29:03 +0000 (UTC) Received: by mail-ve0-f175.google.com with SMTP id db12so202795veb.34 for ; Mon, 21 Jan 2013 03:29:03 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:x-forwarded-to:x-forwarded-for:delivered-to:x-received :received-spf:x-auditid:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-brightmail-tracker:x-brightmail-tracker :dlp-filter:x-mtr:x-cfilter-loop:x-gm-message-state; bh=F8DDkr1O3xa80k/W5Qc6M1xJzzeF6RMp6OdsYrYID0A=; b=Vtha4GkBwe14vVw3WaBKaL8zCvWUhQ408tz4HIu7ZJ6nsgAhsAXcKyBA3DJ09WOZFA +xV31zOQrmOBl9n8e8sl5V7Wm4enufh9gAZETLSY7I+COwA0F9IWMdYz4XpN8xY2Uvpy GQn5iOBA1evD7WECvvAYltb+LnrDegYYZfYBoitOhjRmHO6LWL1cuzgMhVT7VxsE0RWC /fQu94oCI7+td6fm0TIV0j/hmqh19XUecm/X/G6PPkPNTPRSNuc3jLfo0VEaS3j71KqS XmzEguOudYc23LtI5oamtgzyoVewE9HMJ1ExtIcRSKAyMSYS1xVuo8vuuP1VHBC2hJ5X SRvQ== X-Received: by 10.220.218.197 with SMTP id hr5mr18670011vcb.8.1358767743120; Mon, 21 Jan 2013 03:29:03 -0800 (PST) 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.58.145.101 with SMTP id st5csp196487veb; Mon, 21 Jan 2013 03:29:02 -0800 (PST) X-Received: by 10.68.230.101 with SMTP id sx5mr29041928pbc.50.1358767741778; Mon, 21 Jan 2013 03:29:01 -0800 (PST) Received: from mailout1.samsung.com (mailout1.samsung.com. [203.254.224.24]) by mx.google.com with ESMTP id wk7si13425745pbc.199.2013.01.21.03.29.01; Mon, 21 Jan 2013 03:29:01 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of amarendra.xt@samsung.com designates 203.254.224.24 as permitted sender) client-ip=203.254.224.24; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of amarendra.xt@samsung.com designates 203.254.224.24 as permitted sender) smtp.mail=amarendra.xt@samsung.com Received: from epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MGZ00BJZ3W6RDP0@mailout1.samsung.com>; Mon, 21 Jan 2013 20:29:00 +0900 (KST) Received: from epcpsbgm1.samsung.com ( [172.20.52.124]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id A6.C3.03918.C762DF05; Mon, 21 Jan 2013 20:29:00 +0900 (KST) X-AuditID: cbfee61a-b7f7d6d000000f4e-63-50fd267cf7f9 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 65.C3.03918.B762DF05; Mon, 21 Jan 2013 20:28:59 +0900 (KST) Received: from chrome-ubuntu.sisodomain.com ([107.108.73.106]) by mmp2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MGZ0092C3L1A540@mmp2.samsung.com>; Mon, 21 Jan 2013 20:28:59 +0900 (KST) From: Amar To: u-boot@lists.denx.de, jh80.chung@samsung.com Cc: patches@linaro.org, sjg@chromium.org, mk7.kang@samsung.com, chander.kashyap@linaro.org, afleming@gmail.com, hs@denx.de Subject: [PATCH V5 07/10] MMC: APIs to support resize of EMMC boot partition Date: Mon, 21 Jan 2013 06:43:55 -0500 Message-id: <1358768638-14187-8-git-send-email-amarendra.xt@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1358768638-14187-1-git-send-email-amarendra.xt@samsung.com> References: <1358768638-14187-1-git-send-email-amarendra.xt@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrBLMWRmVeSWpSXmKPExsWyRsSkRrdG7W+Awc1vkhYP199ksZhy+AuL A5PHnWt72AIYo7hsUlJzMstSi/TtErgyvk96xlhwzaBi+9Q7LA2MD9W6GDk5JARMJPaf+MQG YYtJXLi3Hsjm4hASWMooMXX6UWaYojPN6xghEtMZJb5sv80O4fQySRzau5Kpi5GDg01AVeLX YnuQBhEBA4npT7azgtjMAjUSk+ffYgKxhQV8JCbMOAhmswCVt/9/ygJi8wp4SOzqP8EKsUxO 4sOeR+wgNqeAp8T+v3vA4kIgNQv+s4LslRC4zSYx4cpbRohBAhLfJh9iAblBQkBWYtMBqKMl JQ6uuMEygVF4ASPDKkbR1ILkguKk9FxDveLE3OLSvHS95PzcTYzAcDz975nUDsaVDRaHGAU4 GJV4eDOm/gkQYk0sK67MPcQowcGsJML7cwZQiDclsbIqtSg/vqg0J7X4EGMy0PKJzFKiyfnA WMkriTc0NjE3NTa1NDIyMzUlTVhJnJfx1JMAIYH0xJLU7NTUgtQimC1MHJxSDYyJZxQUN53/ 8fwSz5QD96aemX8/gCMs5Vo4Sz4Tc+md1kJv9l3MczdyHNx16tbnz8kcKV7f94r6TLgSoBx6 Lm11UZ6TVo+EJ9vF57OTT7225breIbRhIfMG0Y7G9xf/d2+vZ2QvCFgY4nMrbZvGlcs/l3Nc 493BkHfrvnR9M8uiy6EpVqqf9jEpsRRnJBpqMRcVJwIA8V5q+osCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrOIsWRmVeSWpSXmKPExsVy+t9jQd1qtb8BBnMfmVg8XH+TxWLK4S8s Dkwed67tYQtgjGpgtMlITUxJLVJIzUvOT8nMS7dV8g6Od443NTMw1DW0tDBXUshLzE21VXLx CdB1y8wBmq2kUJaYUwoUCkgsLlbSt8M0ITTETdcCpjFC1zckCK7HyAANJKxhzPg+6RljwTWD iu1T77A0MD5U62Lk5JAQMJE407yOEcIWk7hwbz1bFyMXh5DAdEaJL9tvs0M4vUwSh/auZOpi 5OBgE1CV+LXYHqRBRMBAYvqT7awgNrNAjcTk+beYQGxhAR+JCTMOgtksQOXt/5+ygNi8Ah4S u/pPsEIsk5P4sOcRO4jNKeApsf/vHrC4EEjNgv+sExh5FzAyrGIUTS1ILihOSs811CtOzC0u zUvXS87P3cQIDvZnUjsYVzZYHGIU4GBU4uHNmPonQIg1say4MvcQowQHs5II788ZQCHelMTK qtSi/Pii0pzU4kOMyUBXTWSWEk3OB0ZiXkm8obGJuamxqaWJhYmZJWnCSuK8jKeeBAgJpCeW pGanphakFsFsYeLglGpgDGFjvdXjVtns+PvmwWKPx/8jmJ5z7L83JUlWi2P/F51DE4szjpu/ vNTH23Hjq9f1Fi+X7u5mYamty85tsu73y1hx8T2X8t/XL3ne7lUs63jwqEJFk9/vpJ/mgWPZ W4765MVcTzsTdrduspVa1kLZAk7maTbBjH8rhf43iYTpKkT9bXevP1WvxFKckWioxVxUnAgA Rdt5MLoCAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQk8YQKMbdSe2P6ceFZ1hjI/f3JaJoooKC4eu+rtDXKAGXHqvjL3Zji5sOoMTDoPhRcSLYVC This patch adds APIs to access(open / close) and to resize boot partiton of EMMC. Signed-off-by: Amar --- Changes since V1: New patch. Changes since V2: 1)Updation of commit message and resubmition of proper patch set. Changes since V3: No change. Changes since V4: 1)Replaced the functions mmc_boot_open() & mmc_boot_close() with a single function mmc_boot_part_access(). drivers/mmc/mmc.c | 117 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/mmc.h | 24 +++++++++++ 2 files changed, 141 insertions(+) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 72e8ce6..c152934 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -1327,3 +1327,120 @@ int mmc_initialize(bd_t *bis) return 0; } + +int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize, + unsigned long rpmbsize) +{ + int err; + struct mmc_cmd cmd; + + /* Only use this command for raw EMMC moviNAND */ + /* Enter backdoor mode */ + cmd.cmdidx = MMC_CMD_RES_MAN; + cmd.resp_type = MMC_RSP_R1b; + cmd.cmdarg = MMC_CMD62_ARG1; + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_partition_size_change: Error1 = %d\n", err); + return err; + } + + /* Boot partition changing mode */ + cmd.cmdidx = MMC_CMD_RES_MAN; + cmd.resp_type = MMC_RSP_R1b; + cmd.cmdarg = MMC_CMD62_ARG2; + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_partition_size_change: Error2 = %d\n", err); + return err; + } + /* boot partition size is multiple of 128KB */ + bootsize = ((bootsize*1024)/128); + + /* Arg: boot partition size */ + cmd.cmdidx = MMC_CMD_RES_MAN; + cmd.resp_type = MMC_RSP_R1b; + cmd.cmdarg = bootsize; + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_partition_size_change: Error3 = %d\n", err); + return err; + } + /* RPMB partition size is multiple of 128KB */ + rpmbsize = ((rpmbsize*1024)/128); + /* Arg: RPMB partition size */ + cmd.cmdidx = MMC_CMD_RES_MAN; + cmd.resp_type = MMC_RSP_R1b; + cmd.cmdarg = rpmbsize; + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_partition_size_change: Error4 = %d\n", err); + return err; + } + return 0; +} + +/* This function shall form and send the commands to open / close the + * boot partition specified by user. + * + * ack: 0x0 - No boot acknowledge sent (default) + * 0x1 - Boot acknowledge sent during boot operation + * part_num: User selects boot data that will be sent to master + * 0x0 - Device not boot enabled (default) + * 0x1 - Boot partition 1 enabled for boot + * 0x2 - Boot partition 2 enabled for boot + * access: User selects partitions to access + * 0x0 : No access to boot partition (default) + * 0x1 : R/W boot partition 1 + * 0x2 : R/W boot partition 2 + * 0x3 : R/W Replay Protected Memory Block (RPMB) + */ +int mmc_boot_part_access(struct mmc *mmc, u32 ack, u32 part_num, u32 access) +{ + int err; + struct mmc_cmd cmd; + + /* Boot ack enable, boot partition enable , boot partition access */ + cmd.cmdidx = MMC_CMD_SWITCH; + cmd.resp_type = MMC_RSP_R1b; + + cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24 | + EXT_CSD_PART_CONF << 16 | + (EXT_CSD_BOOT_ACK(ack) | + EXT_CSD_BOOT_PART_NUM(part_num) | + EXT_CSD_PARTITION_ACCESS(access)) << 8); + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + if (access) { + debug("mmc boot partition#%d open failure:" + "Error1 = %d\n", part_num, err); + } else { + debug("mmc boot partition#%d close failure:" + "Error = %d\n", part_num, err); + } + return err; + } + + if (access) { + /* 4bit transfer mode at booting time. */ + cmd.cmdidx = MMC_CMD_SWITCH; + cmd.resp_type = MMC_RSP_R1b; + + cmd.cmdarg = (MMC_SWITCH_MODE_WRITE_BYTE << 24| + EXT_CSD_BOOT_BUS_WIDTH << 16| + ((1<<0) << 8)); + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc boot partition#%d open failure:" + "Error2 = %d\n", part_num, err); + return err; + } + } + return 0; +} diff --git a/include/mmc.h b/include/mmc.h index a13e2bd..fcd9c54 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -86,6 +86,11 @@ #define MMC_CMD_APP_CMD 55 #define MMC_CMD_SPI_READ_OCR 58 #define MMC_CMD_SPI_CRC_ON_OFF 59 +#define MMC_CMD_RES_MAN 62 + +#define MMC_CMD62_ARG1 0xefac62ec +#define MMC_CMD62_ARG2 0xcbaea7 + #define SD_CMD_SEND_RELATIVE_ADDR 3 #define SD_CMD_SWITCH_FUNC 6 @@ -153,6 +158,7 @@ */ #define EXT_CSD_PARTITIONING_SUPPORT 160 /* RO */ #define EXT_CSD_ERASE_GROUP_DEF 175 /* R/W */ +#define EXT_CSD_BOOT_BUS_WIDTH 177 #define EXT_CSD_PART_CONF 179 /* R/W */ #define EXT_CSD_BUS_WIDTH 183 /* R/W */ #define EXT_CSD_HS_TIMING 185 /* R/W */ @@ -177,6 +183,16 @@ #define EXT_CSD_BUS_WIDTH_4 1 /* Card is in 4 bit mode */ #define EXT_CSD_BUS_WIDTH_8 2 /* Card is in 8 bit mode */ +#define EXT_CSD_BOOT_ACK_ENABLE (1<<6) +#define EXT_CSD_BOOT_PARTITION_ENABLE (1<<3) +#define EXT_CSD_PARTITION_ACCESS_ENABLE (1<<0) +#define EXT_CSD_PARTITION_ACCESS_DISABLE (0<<0) + +#define EXT_CSD_BOOT_ACK(x) (x<<6) +#define EXT_CSD_BOOT_PART_NUM(x) (x<<3) +#define EXT_CSD_PARTITION_ACCESS(x) (x<<0) + + #define R1_ILLEGAL_COMMAND (1 << 22) #define R1_APP_CMD (1 << 5) @@ -201,6 +217,11 @@ #define PART_ACCESS_MASK (0x7) #define PART_SUPPORT (0x1) +/* The number of MMC physical partitions. These consist of: + * boot partitions (2), general purpose partitions (4) in MMC v4.4. + */ +#define MMC_NUM_BOOT_PARTITION 2 + struct mmc_cid { unsigned long psn; unsigned short oid; @@ -275,6 +296,9 @@ int board_mmc_getcd(struct mmc *mmc); int mmc_switch_part(int dev_num, unsigned int part_num); int mmc_getcd(struct mmc *mmc); void spl_mmc_load(void) __noreturn; +int mmc_boot_partition_size_change(struct mmc *mmc, unsigned long bootsize, + unsigned long rpmbsize); +int mmc_boot_part_access(struct mmc *mmc, u32 ack, u32 part_num, u32 access); #ifdef CONFIG_GENERIC_MMC #define mmc_host_is_spi(mmc) ((mmc)->host_caps & MMC_MODE_SPI)