From patchwork Fri Dec 28 15:52:50 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amar X-Patchwork-Id: 13746 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 256E023EF7 for ; Fri, 28 Dec 2012 15:31:06 +0000 (UTC) Received: from mail-vb0-f50.google.com (mail-vb0-f50.google.com [209.85.212.50]) by fiordland.canonical.com (Postfix) with ESMTP id C1413A181DF for ; Fri, 28 Dec 2012 15:31:05 +0000 (UTC) Received: by mail-vb0-f50.google.com with SMTP id fr13so10944396vbb.9 for ; Fri, 28 Dec 2012 07:31:05 -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=9rXr1Ri1vAodHW/1X80T6c+Ac/tEi3c9n6ZRogMJNJ4=; b=EyC2sWWCz4Ut0w7U0MtVofD/fXQ3l2QcpL70lKLPRm90iWy4YgTrFo1XPzIoJxytXT MIiVIIuILlpTMGbiDqQp75KfiyM/VKcrrETwUvGTPQ3D9VdOKFIOF0G81zDjxICp3Z/C Aq4LQGDJ3SbKYLTiZUC6UgMjDFuXlAZHiJtuEfr4he3a5G5YrHYhfI6xkCzYTaKrL5Ie aJOEJefO6RgefryW3pVJvzo3Rkfpy/5JfhG523vfDTSeybWLPneCd0csxdRRHNHhAaW0 +RVedbhmtPraqHNDv6MxQwc6Q6eKO14z7lqA/ODXGhIIp9sd14qgxKw7ojbje05/SNQb q/mA== X-Received: by 10.52.70.205 with SMTP id o13mr45188067vdu.75.1356708665180; Fri, 28 Dec 2012 07:31:05 -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 oc3csp63576vec; Fri, 28 Dec 2012 07:31:04 -0800 (PST) X-Received: by 10.66.79.66 with SMTP id h2mr99885674pax.31.1356708663395; Fri, 28 Dec 2012 07:31:03 -0800 (PST) Received: from mailout2.samsung.com (mailout2.samsung.com. [203.254.224.25]) by mx.google.com with ESMTP id ru9si32332234pbc.250.2012.12.28.07.31.02; Fri, 28 Dec 2012 07:31:03 -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 epcpsbgm1.samsung.com (epcpsbgm1 [203.254.230.26]) by mailout2.samsung.com (Oracle Communications Messaging Server 7u4-24.01(7.0.4.24.0) 64bit (built Nov 17 2011)) with ESMTP id <0MFQ00MY1Z2Z6040@mailout2.samsung.com>; Sat, 29 Dec 2012 00:30:53 +0900 (KST) Received: from epcpdlpp25 ( [172.20.52.125]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id E2.06.01231.D2BBDD05; Sat, 29 Dec 2012 00:30:53 +0900 (KST) X-AuditID: cbfee61a-b7fa66d0000004cf-d0-50ddbb2d634b Received: from epmmp2 ( [203.254.227.17]) by epcpsbgm1.samsung.com (EPCPMTA) with SMTP id 92.06.01231.C2BBDD05; Sat, 29 Dec 2012 00:30:53 +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 <0MFQ008MSZ2SO710@mmp2.samsung.com>; Sat, 29 Dec 2012 00:30:52 +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 7/9] MMC: APIs to support creation of boot partition Date: Fri, 28 Dec 2012 10:52:50 -0500 Message-id: <1356709972-26549-8-git-send-email-amarendra.xt@samsung.com> X-Mailer: git-send-email 1.8.0 In-reply-to: <1356709972-26549-1-git-send-email-amarendra.xt@samsung.com> References: <1356709972-26549-1-git-send-email-amarendra.xt@samsung.com> DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrHLMWRmVeSWpSXmKPExsWyRsSkVld3990Ag2N7+S0err/JYjHl8BcW ByaPO9f2sAUwRnHZpKTmZJalFunbJXBlPNwaX3BdveL7snlMDYxtCl2MnBwSAiYS71a9Y4Ow xSQu3FsPZHNxCAnMYpToPzOdDabo6K6DLBCJ6YwSHWfOM0M4vUwSpx5cAHI4ONgEVCV+LbYH aRARMJCY/mQ7K0iYWaBA4tluMZCwsICLxOx7y1lBbBag6tcfZoJ18gp4SMzZZwuxSk7iw55H 7CA2p4CnxKNni5hBbCGgkqubdrFBtApIfJt8iAWkVUJAVmLTAbBjJARus0k0t+xmhpgjKXFw xQ2WCYzCCxgZVjGKphYkFxQnpeca6hUn5haX5qXrJefnbmIEBuLpf8+kdjCubLA4xCjAwajE w7uw506AEGtiWXFl7iFGCQ5mJRHevua7AUK8KYmVValF+fFFpTmpxYcYfYAumcgsJZqcD4yS vJJ4Q2MTc1NjU0sjIzNTUxzCSuK8zR4pAUIC6YklqdmpqQWpRTDjmDg4pRoYJ/ve7LmzMuzN /AW+DYzOTYvX3sssMlaUO9KgYzEz7YRybOFKyxu8V0pnGfsLJCdb3RReseCqqmm3nvTP2CXZ +4IK3K/lG68Kb1/4v6RrmqFp3IJWkYTJa//2p6/t/2H47omVmY3ElUoH1te6zanSs5Y0Xt5n vq9Gxd4pf/9PlffFRdWTS1YrsRRnJBpqMRcVJwIAbwrfyHECAAA= X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplkeLIzCtJLcpLzFFi42I5/e+xoK7u7rsBBj2bmS0err/JYjHl8BcW ByaPO9f2sAUwRjUw2mSkJqakFimk5iXnp2TmpdsqeQfHO8ebmhkY6hpaWpgrKeQl5qbaKrn4 BOi6ZeYAzVZSKEvMKQUKBSQWFyvp22GaEBripmsB0xih6xsSBNdjZIAGEtYwZjzcGl9wXb3i +7J5TA2MbQpdjJwcEgImEkd3HWSBsMUkLtxbz9bFyMUhJDCdUaLjzHlmCKeXSeLUgwtADgcH m4CqxK/F9iANIgIGEtOfbGcFCTMLFEg82y0GEhYWcJGYfW85K4jNAlT9+sNMsE5eAQ+JOfts IVbJSXzY84gdxOYU8JR49GwRM4gtBFRyddMutgmMvAsYGVYxiqYWJBcUJ6XnGuoVJ+YWl+al 6yXn525iBIf5M6kdjCsbLA4xCnAwKvHwLuy5EyDEmlhWXJl7iFGCg1lJhLev+W6AEG9KYmVV alF+fFFpTmrxIUYfoKMmMkuJJucDYzCvJN7Q2MTc1NjU0sTCxMwSh7CSOG+zR0qAkEB6Yklq dmpqQWoRzDgmDk6pBkanM2WZadPCbZvDnwT+XNCkcEDl+4Oy1VaHXzo9r5kbW84tFHdtXzHz DMXXRv//BZ9MmHLlShHTe72taXtv3NzdZ2JyUTDKPzBt54vcryXGrQ+FtR5MKcwvnROuPN0k 7FMV26PrzrHnhe5NMPJwkW2557DleIVidGNW3RMG6ySls21HtivPu6HEUpyRaKjFXFScCAAp 7ziDoAIAAA== X-CFilter-Loop: Reflected X-Gm-Message-State: ALoCoQkNgCmG3RvGa4t0tn68IUQetIK3MLAvXNEccQO14iidaTJ5p59OAdt249EHKK+0akTcnD4/ This patch 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(+) diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c index 5ffd8c5..9496bb9 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)