From patchwork Mon Dec 31 10:58:18 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amar X-Patchwork-Id: 13755 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 88D4223E03 for ; Mon, 31 Dec 2012 10:36:31 +0000 (UTC) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by fiordland.canonical.com (Postfix) with ESMTP id 3046BA18D4E for ; Mon, 31 Dec 2012 10:36:31 +0000 (UTC) Received: by mail-vc0-f175.google.com with SMTP id fy7so12500987vcb.6 for ; Mon, 31 Dec 2012 02:36:30 -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:dlp-filter:x-mtr:x-brightmail-tracker :x-brightmail-tracker:x-cfilter-loop:x-gm-message-state; bh=ddXbtb3hmvyw9s7xdTP6WDCLTIlaUda0jsXFJ+HMJYQ=; b=WD42MXhP2FKVOmUW/gsGgNF8fVTQJPJLuRBiQBwxWUr/n9PjvAyi34NW7TbgTQbBcl WomZhXwew8ipGWKSijyp+ky/W/o6DG3VHl8fNvDIHqaXXM5RgABmsBRw09py1KD+gYi+ bTSzag2f/+dZ/Fu9PafyiUi2KIfz4XlrnfSb/y13uFsXas2iolMxGRh9XZSPHMpHAl1a 6VY5e2ElWrHS+wdQhSRsLiLT5c0tM2dDXZmkQSOjbe6eQqOer4t9dt5HD1mZvL83IN4A NMLgMAlnC18NI0Xpuwrejt83FTUJKFm8EnK0ha89F7q0TI+2uLOQN0IHcWClm6JLFZeO 14Qw== X-Received: by 10.52.88.168 with SMTP id bh8mr53923102vdb.51.1356950190656; Mon, 31 Dec 2012 02:36:30 -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.214.195 with SMTP id oc3csp153817vec; Mon, 31 Dec 2012 02:36:30 -0800 (PST) X-Received: by 10.66.87.33 with SMTP id u1mr119059308paz.73.1356950189277; Mon, 31 Dec 2012 02:36:29 -0800 (PST) Received: from mailout2.samsung.com (mailout2.samsung.com. [203.254.224.25]) by mx.google.com with ESMTP id rg4si38963486pbc.203.2012.12.31.02.36.28; Mon, 31 Dec 2012 02:36:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of amarendra.xt@samsung.com designates 203.254.224.25 as permitted sender) client-ip=203.254.224.25; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of amarendra.xt@samsung.com designates 203.254.224.25 as permitted sender) smtp.mail=amarendra.xt@samsung.com Received: from epcpsbgm2.samsung.com (epcpsbgm2 [203.254.230.27]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MFW00AHN5GNQUD0@mailout2.samsung.com>; Mon, 31 Dec 2012 19:36:28 +0900 (KST) Received: from epcpsbgm2.samsung.com ( [172.20.52.126]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id 46.DE.12699.CAA61E05; Mon, 31 Dec 2012 19:36:28 +0900 (KST) X-AuditID: cbfee61b-b7f616d00000319b-32-50e16aac6408 Received: from epmmp1.local.host ( [203.254.227.16]) by epcpsbgm2.samsung.com (EPCPMTA) with SMTP id E5.DE.12699.CAA61E05; Mon, 31 Dec 2012 19:36:28 +0900 (KST) Received: from chrome-ubuntu.sisodomain.com ([107.108.73.106]) by mmp1.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTPA id <0MFW00JL05G0TP80@mmp1.samsung.com>; Mon, 31 Dec 2012 19:36:28 +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 Subject: [PATCH V3 7/9] MMC: APIs to support resize of EMMC boot partition Date: Mon, 31 Dec 2012 05:58:18 -0500 Message-id: <1356951500-22490-8-git-send-email-amarendra.xt@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1356951500-22490-1-git-send-email-amarendra.xt@samsung.com> References: <1356951500-22490-1-git-send-email-amarendra.xt@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrHLMWRmVeSWpSXmKPExsWyRsSkTndN1sMAg74X6hYP199ksZhy+AuL A5PHnWt72AIYo7hsUlJzMstSi/TtErgybq7azlhwQaPi4oW37A2MjxW6GDk4JARMJKbv5O1i 5AQyxSQu3FvP1sXIxSEksJRRYtmsJ2wQCROJ/V+WMEEkFjFKXN13Bqqql0ni+f+VjCCT2ARU JX4ttgdpEBEwkJj+ZDsrSJhZoEDi2W4xkLCwgJfEllfrmEFsFqDqw0s/s4GU8Ap4SEy5aw2x Sk7iw55H7CA2p4CnxOktO8DKhYBKbnYvZIdoFZD4NvkQC8T5shKbDjCDHCMhcJtNYsubvVAn S0ocXHGDZQKj8AJGhlWMoqkFyQXFSem5RnrFibnFpXnpesn5uZsYgYF4+t8z6R2MqxosDjEK cDAq8fByMj0MEGJNLCuuzD3EKMHBrCTC+1YLKMSbklhZlVqUH19UmpNafIjRB+iSicxSosn5 wCjJK4k3NDYxNzU2tTQyMjM1xSGsJM7b7JESICSQnliSmp2aWpBaBDOOiYNTqoEx9QTbwvWX Ba32cZa4Hflt2rxtYtFPpUN3z1Ze4tUM/vKV73pCv7r0Ts3YP+cnuH64tDr+bjLb/tB9LsEn Ny3euiOY+5qJ16s5/1aUn4u1n+Cxv03SRpdjYXDk7NkCS+ZE7S3JS5JzZd76cNPhncK/Es8c mXeWr8FFb8rDyU8khaSOrZ/zOimsU4mlOCPRUIu5qDgRAN0jGatxAgAA X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFupjkeLIzCtJLcpLzFFi42I5/e+xgO6arIcBBq+uS1o8XH+TxWLK4S8s Dkwed67tYQtgjGpgtMlITUxJLVJIzUvOT8nMS7dV8g6Od443NTMw1DW0tDBXUshLzE21VXLx CdB1y8wBmq2kUJaYUwoUCkgsLlbSt8M0ITTETdcCpjFC1zckCK7HyAANJKxhzLi5ajtjwQWN iosX3rI3MD5W6GLk5JAQMJHY/2UJE4QtJnHh3nq2LkYuDiGBRYwSV/edgXJ6mSSe/1/J2MXI wcEmoCrxa7E9SIOIgIHE9CfbWUHCzAIFEs92i4GEhQW8JLa8WscMYrMAVR9e+pkNpIRXwENi yl1riFVyEh/2PGIHsTkFPCVOb9kBVi4EVHKzeyH7BEbeBYwMqxhFUwuSC4qT0nON9IoTc4tL 89L1kvNzNzGCA/2Z9A7GVQ0WhxgFOBiVeHg5mR4GCLEmlhVX5h5ilOBgVhLhfasFFOJNSays Si3Kjy8qzUktPsToA3TURGYp0eR8YBTmlcQbGpuYmxqbWppYmJhZ4hBWEudt9kgJEBJITyxJ zU5NLUgtghnHxMEp1cAonqDXK2J7+cObsKoTrIc0sjgZ+mcr7tvBZe0X4zjr3uPQJM3VTIsT JOZX3Vxv2GFQZnbqrZ3ylk/PBefG6E5bcpQ9eLblZEsLhVsaIR9vxG0q0BZK5Avl32f2PLEr tO4Cc0LmrEiX6VfPNF1sWyfa/qn+l49OyNETGmtnxLKqXE6/niFydLESS3FGoqEWc1FxIgCX Z5CIoQIAAA== X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQk8thx4KWoMY5dU185hBGciBSV8rx7Jv7I2sRMKFZsXmPsbe1uayVv6NT8+T7UKEGSExmqj This patch adds APIs to open, close and to resize boot partiton for EMMC. Changes from V1: New patch. Changes from V2: 1)Updation of commit message and resubmition of proper patch set. Signed-off-by: Amar --- drivers/mmc/mmc.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ include/mmc.h | 16 ++++++++ 2 files changed, 134 insertions(+) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 72e8ce6..8175b49 100644 --- a/drivers/mmc/mmc.c +++ b/drivers/mmc/mmc.c @@ -1327,3 +1327,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)