From patchwork Mon Dec 17 11:19:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amar X-Patchwork-Id: 13622 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 328C823E02 for ; Mon, 17 Dec 2012 10:57:58 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id B4EF5A18A5E for ; Mon, 17 Dec 2012 10:57:57 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id c10so8818581ieb.11 for ; Mon, 17 Dec 2012 02:57:57 -0800 (PST) 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:x-auditid :from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :dlp-filter:x-mtr:x-brightmail-tracker:x-brightmail-tracker :x-cfilter-loop:x-gm-message-state; bh=suJR5JhjECkUf54fE40CVZj/O92iboioG+GLkf4NId4=; b=Uwx3mi7E0bH5D4C5PgOLEGbQ7cQqlxcfPToONtkwyCUIi6Plsddt/ENsD7nda3yCMB Om0REOTLaf01HwLrLLLfEN1B3DQlS/KB5jejX+H5bJj9FwM7J3vvehEuhHUoK92Yu2K5 fW34MD1vZDcsgF3twqWxi2VirEfcS1Z7PHiATLiz6xlmIhmoPOXohC+UlfbTkfJv5JBJ vrIaTa6Tk0/BfWHUEWqdEhKyBX0/Zf75HsSx11vA6s3A6QW8425SCc/wWW31A6eOcomm yHRvw4nMpai3YfsshxZGu785PQLI8uh+cqLowNqsYr7GHwOA/B100j1M/f6S/Cp9MeK4 McZw== Received: by 10.43.125.133 with SMTP id gs5mr10801731icc.54.1355741877203; Mon, 17 Dec 2012 02:57:57 -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.50.67.148 with SMTP id n20csp66401igt; Mon, 17 Dec 2012 02:57:56 -0800 (PST) Received: by 10.68.245.37 with SMTP id xl5mr42031796pbc.120.1355741876279; Mon, 17 Dec 2012 02:57:56 -0800 (PST) Received: from mailout1.samsung.com (mailout1.samsung.com. [203.254.224.24]) by mx.google.com with ESMTP id d7si12979490paw.269.2012.12.17.02.57.55; Mon, 17 Dec 2012 02:57:56 -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 epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MF600ADA92QUC30@mailout1.samsung.com>; Mon, 17 Dec 2012 19:57:34 +0900 (KST) Received: from epcpdlpp23 ( [172.20.52.123]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 4E.AA.12699.E9AFEC05; Mon, 17 Dec 2012 19:57:34 +0900 (KST) X-AuditID: cbfee61b-b7f616d00000319b-10-50cefa9ede16 Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id FD.AA.12699.E9AFEC05; Mon, 17 Dec 2012 19:57:34 +0900 (KST) Received: from localhost.localdomain ([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 <0MF600FNU92TR670@mmp2.samsung.com>; Mon, 17 Dec 2012 19:57:34 +0900 (KST) From: Amar To: u-boot@lists.denx.de Cc: patches@linaro.org, sjg@chromium.org, mk7.kang@samsung.com, chander.kashyap@linaro.org, afleming@gmail.com, jh80.chung@samsung.com Subject: [PATCH 7/9] MMC: APIs to support creation of boot partition Date: Mon, 17 Dec 2012 16:49:34 +0530 Message-id: <1355743176-12305-8-git-send-email-amarendra.xt@samsung.com> X-Mailer: git-send-email 1.7.0.4 In-reply-to: <1355743176-12305-1-git-send-email-amarendra.xt@samsung.com> References: <1355743176-12305-1-git-send-email-amarendra.xt@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrALMWRmVeSWpSXmKPExsWyRsSkWnfer3MBBqdnGFg8XH+TxWLK4S8s Dkwed67tYQtgjOKySUnNySxLLdK3S+DKeP9uJ0vBS/WKtvttzA2MUxS6GDk5JARMJM71nmOE sMUkLtxbzwZiCwnMYpRYPicWpmbfj38sXYxcQPHpjBJv//YzQTjtTBJHzv8HynBwsAmoSvxa bA/SICIgIfGr/yojSA2zQAejxI6Jm8E2CAu4SMy+t5wVxGYBqj919y8rSC+vgIfEzHmWEMsU JFqXHWIHsTkFPCU+737IAnGQh8SeXdOZIVoFJL5NPgS2VkJAVmLTAWaQVRIC99kkDp07wQ4x R1Li4IobLBMYhRcwMqxiFE0tSC4oTkrPNdIrTswtLs1L10vOz93ECAzG0/+eSe9gXNVgcYhR gINRiYfXMPVcgBBrYllxZe4hRgkOZiURXuk3QCHelMTKqtSi/Pii0pzU4kOMPkCXTGSWEk3O B0ZKXkm8obGJuamxqaWRkZmpKQ5hJXHeZo+UACGB9MSS1OzU1ILUIphxTBycUg2MQWeO3di5 d7agpvbRZ7V31uxc7+53/frK0HZm1V8td02SD+01zfnEf0yk/rGQ1MSMNeaMV9rZnnIxO6po s1tEJF36pfcgTqHrRgzHz1Dt6+U2c2w8V0uUpD3TeX0gdtnX21VOpg92/X4iK/5ZPGffnZmf WWzDVI43X9/0r1hb/UW+mUnXc7cMJZbijERDLeai4kQA7oZ22HMCAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprAIsWRmVeSWpSXmKPExsVy+t9jQd15v84FGDx/pGzxcP1NFosph7+w ODB53Lm2hy2AMaqB0SYjNTEltUghNS85PyUzL91WyTs43jne1MzAUNfQ0sJcSSEvMTfVVsnF J0DXLTMHaLaSQlliTilQKCCxuFhJ3w7ThNAQN10LmMYIXd+QILgeIwM0kLCGMeP9u50sBS/V K9rutzE3ME5R6GLk5JAQMJHY9+MfC4QtJnHh3nq2LkYuDiGB6YwSb//2M0E47UwSR87/B6ri 4GATUJX4tdgepEFEQELiV/9VRpAaZoEORokdEzczgiSEBVwkZt9bzgpiswDVn7r7lxWkl1fA Q2LmPEuIZQoSrcsOsYPYnAKeEp93PwQ7QgioZM+u6cwTGHkXMDKsYhRNLUguKE5KzzXSK07M LS7NS9dLzs/dxAgO9mfSOxhXNVgcYhTgYFTi4TVMPRcgxJpYVlyZe4hRgoNZSYRX+g1QiDcl sbIqtSg/vqg0J7X4EKMP0FETmaVEk/OBkZhXEm9obGJuamxqaWJhYmaJQ1hJnLfZIyVASCA9 sSQ1OzW1ILUIZhwTB6dUA6P8yeNL1oXNbl8dy7f91oJflc7zFSes28EnLijrX2hxWWKmZ/G5 a77x6X+0P+e1s+imnb7zYDebO3Od6MSFpxjs30XLCXCfVYyS7Nl4bsF9UdUdJW8Ut20Rf7Ii 78ljHhOpFxaiUgt2SM5T/SN/QnxdyhSXsMSWU7u/zo2L2GB+f/P9R6oX/XKUWIozEg21mIuK EwEC2NHEowIAAA== X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQlJZeFiispfoMknhWoWVlXRx4KOYhva7KUgel8qpzxx8vrWE0EZ+hKzD9/jAqQgYxpu2iS2 This pathc adds APIs to open, close and to create boot partiton for eMMC. Signed-off-by: Amar --- drivers/mmc/mmc.c | 118 +++++++++++++++++++++++++++++++++++++++++++++++++++++ include/mmc.h | 16 +++++++ 2 files changed, 134 insertions(+), 0 deletions(-) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 5ffd8c5..88b0435 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -1302,3 +1302,121 @@ 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; +} + +int mmc_boot_open(struct mmc *mmc) +{ + 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_ENABLE | + EXT_CSD_BOOT_PARTITION_ENABLE | + EXT_CSD_PARTITION_ACCESS_ENABLE) << 8); + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_open: Error1 = %d\n", err); + return err; + } + + /* 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_open: Error2 = %d\n", err); + return err; + } + + return 0; +} + +int mmc_boot_close(struct mmc *mmc) +{ + 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_ENABLE | + EXT_CSD_BOOT_PARTITION_ENABLE | + EXT_CSD_PARTITION_ACCESS_DISABLE) << 8); + + err = mmc_send_cmd(mmc, &cmd, NULL); + if (err) { + debug("mmc_boot_close: Error = %d\n", err); + return err; + } + + return 0; +} diff --git a/include/mmc.h b/include/mmc.h index a13e2bd..999f0a3 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,12 @@ #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 R1_ILLEGAL_COMMAND (1 << 22) #define R1_APP_CMD (1 << 5) @@ -275,6 +287,10 @@ 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_open(struct mmc *mmc); +int mmc_boot_close(struct mmc *mmc); #ifdef CONFIG_GENERIC_MMC #define mmc_host_is_spi(mmc) ((mmc)->host_caps & MMC_MODE_SPI)