{"id":816910,"url":"http://patchwork.ozlabs.org/api/patches/816910/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/1506004213-22620-23-git-send-email-jjhiblot@ti.com/","project":{"id":18,"url":"http://patchwork.ozlabs.org/api/projects/18/?format=json","name":"U-Boot","link_name":"uboot","list_id":"u-boot.lists.denx.de","list_email":"u-boot@lists.denx.de","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<1506004213-22620-23-git-send-email-jjhiblot@ti.com>","list_archive_url":null,"date":"2017-09-21T14:30:09","name":"[U-Boot,v2,22/26] mmc: Change mode when switching to a boot partition","commit_ref":"01298da31d92ecc46cf9130d8cff68bc51698197","pull_url":null,"state":"accepted","archived":false,"hash":"a63737d715fe7e4ad577eb894af2c03395b7e363","submitter":{"id":70508,"url":"http://patchwork.ozlabs.org/api/people/70508/?format=json","name":"Jean-Jacques Hiblot","email":"jjhiblot@ti.com"},"delegate":{"id":12423,"url":"http://patchwork.ozlabs.org/api/users/12423/?format=json","username":"Jaehoon","first_name":"Jaehoon","last_name":"Chung","email":"jh80.chung@samsung.com"},"mbox":"http://patchwork.ozlabs.org/project/uboot/patch/1506004213-22620-23-git-send-email-jjhiblot@ti.com/mbox/","series":[{"id":4400,"url":"http://patchwork.ozlabs.org/api/series/4400/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/list/?series=4400","date":"2017-09-21T14:29:47","name":"mmc: Add support for HS200 and UHS modes","version":2,"mbox":"http://patchwork.ozlabs.org/series/4400/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/816910/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/816910/checks/","tags":{},"related":[],"headers":{"Return-Path":"<u-boot-bounces@lists.denx.de>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=lists.denx.de\n\t(client-ip=81.169.180.215; helo=lists.denx.de;\n\tenvelope-from=u-boot-bounces@lists.denx.de;\n\treceiver=<UNKNOWN>)","ozlabs.org;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ti.com header.i=@ti.com header.b=\"ZsbxP5D/\";\n\tdkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xyfTm3yX0z9t3C\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 22 Sep 2017 00:42:36 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 623E4C2202E; Thu, 21 Sep 2017 14:37:48 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 12B80C22041;\n\tThu, 21 Sep 2017 14:34:03 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 3925AC21F29; Thu, 21 Sep 2017 14:31:17 +0000 (UTC)","from lelnx194.ext.ti.com (lelnx194.ext.ti.com [198.47.27.80])\n\tby lists.denx.de (Postfix) with ESMTPS id 443C3C21FF9\n\tfor <u-boot@lists.denx.de>; Thu, 21 Sep 2017 14:31:10 +0000 (UTC)","from dlelxv90.itg.ti.com ([172.17.2.17])\n\tby lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id v8LEV82A002952; \n\tThu, 21 Sep 2017 09:31:08 -0500","from DFLE103.ent.ti.com (dfle103.ent.ti.com [10.64.6.24])\n\tby dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id v8LEV84l020573; \n\tThu, 21 Sep 2017 09:31:08 -0500","from DFLE110.ent.ti.com (10.64.6.31) by DFLE103.ent.ti.com\n\t(10.64.6.24) with Microsoft SMTP Server (version=TLS1_2,\n\tcipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.1.845.34;\n\tThu, 21 Sep 2017 09:31:07 -0500","from dlep33.itg.ti.com (157.170.170.75) by DFLE110.ent.ti.com\n\t(10.64.6.31) with Microsoft SMTP Server (version=TLS1_0,\n\tcipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.845.34 via Frontend\n\tTransport; Thu, 21 Sep 2017 09:31:07 -0500","from localhost (ileax41-snat.itg.ti.com [10.172.224.153])\n\tby dlep33.itg.ti.com (8.14.3/8.13.8) with ESMTP id v8LEV6Wi012007;\n\tThu, 21 Sep 2017 09:31:07 -0500"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=0.0 required=5.0 tests=RCVD_IN_DNSWL_NONE,\n\tT_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ti.com;\n\ts=ti-com-17Q1; t=1506004268;\n\tbh=NVD9KUrUt0IP1PASg3KkjQ4gd0yf2AwpPceqp4TNFeA=;\n\th=From:To:CC:Subject:Date:In-Reply-To:References;\n\tb=ZsbxP5D/mDxE7OH4lj4/ylolimbU+T+ofHCVD4SgS57ISy021+MXWmUYeTX3si7ia\n\tNYxlducZua94bn3GG7v9Rww3bEiDMzgf/ngZcmS0d4hz3et+0XTFtuCltNBsYZR7/1\n\t08jsgZK2IRJwGVin5s/CQ3zU2k02rY8C2lLXknH0=","From":"Jean-Jacques Hiblot <jjhiblot@ti.com>","To":"<jh80.chung@samsung.com>, <trini@konsulko.com>, <kishon@ti.com>,\n\t<sjg@chromium.org>","Date":"Thu, 21 Sep 2017 16:30:09 +0200","Message-ID":"<1506004213-22620-23-git-send-email-jjhiblot@ti.com>","X-Mailer":"git-send-email 1.9.1","In-Reply-To":"<1506004213-22620-1-git-send-email-jjhiblot@ti.com>","References":"<1506004213-22620-1-git-send-email-jjhiblot@ti.com>","MIME-Version":"1.0","X-EXCLAIMER-MD-CONFIG":"e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180","Cc":"u-boot@lists.denx.de","Subject":"[U-Boot] [PATCH v2 22/26] mmc: Change mode when switching to a boot\n\tpartition","X-BeenThere":"u-boot@lists.denx.de","X-Mailman-Version":"2.1.18","Precedence":"list","List-Id":"U-Boot discussion <u-boot.lists.denx.de>","List-Unsubscribe":"<https://lists.denx.de/options/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=unsubscribe>","List-Archive":"<http://lists.denx.de/pipermail/u-boot/>","List-Post":"<mailto:u-boot@lists.denx.de>","List-Help":"<mailto:u-boot-request@lists.denx.de?subject=help>","List-Subscribe":"<https://lists.denx.de/listinfo/u-boot>,\n\t<mailto:u-boot-request@lists.denx.de?subject=subscribe>","Content-Type":"text/plain; charset=\"utf-8\"","Content-Transfer-Encoding":"base64","Errors-To":"u-boot-bounces@lists.denx.de","Sender":"\"U-Boot\" <u-boot-bounces@lists.denx.de>"},"content":"Boot partitions do not support HS200. Changing to a lower performance mode\nis required to access them.\nmmc_select_mode_and_width() and sd_select_mode_and_width() are modified to\nmake it easier to call them outside of the initialization context.\n\nSigned-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>\nReviewed-by: Simon Glass <sjg@chromium.org>\n---\n drivers/mmc/mmc.c | 66 +++++++++++++++++++++++++++++++++++++++++--------------\n include/mmc.h     |  7 +++++-\n 2 files changed, 55 insertions(+), 18 deletions(-)","diff":"diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c\nindex 31accdd..c5eaeaf 100644\n--- a/drivers/mmc/mmc.c\n+++ b/drivers/mmc/mmc.c\n@@ -32,6 +32,7 @@ static const unsigned int sd_au_size[] = {\n \n static int mmc_set_signal_voltage(struct mmc *mmc, uint signal_voltage);\n static int mmc_power_cycle(struct mmc *mmc);\n+static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps);\n \n #if CONFIG_IS_ENABLED(MMC_TINY)\n static struct mmc mmc_static;\n@@ -792,10 +793,38 @@ static int mmc_set_capacity(struct mmc *mmc, int part_num)\n \treturn 0;\n }\n \n+static int mmc_boot_part_access_chk(struct mmc *mmc, unsigned int part_num)\n+{\n+\tint forbidden = 0;\n+\tbool change = false;\n+\n+\tif (part_num & PART_ACCESS_MASK)\n+\t\tforbidden = MMC_CAP(MMC_HS_200);\n+\n+\tif (MMC_CAP(mmc->selected_mode) & forbidden) {\n+\t\tdebug(\"selected mode (%s) is forbidden for part %d\\n\",\n+\t\t      mmc_mode_name(mmc->selected_mode), part_num);\n+\t\tchange = true;\n+\t} else if (mmc->selected_mode != mmc->best_mode) {\n+\t\tdebug(\"selected mode is not optimal\\n\");\n+\t\tchange = true;\n+\t}\n+\n+\tif (change)\n+\t\treturn mmc_select_mode_and_width(mmc,\n+\t\t\t\t\t\t mmc->card_caps & ~forbidden);\n+\n+\treturn 0;\n+}\n+\n int mmc_switch_part(struct mmc *mmc, unsigned int part_num)\n {\n \tint ret;\n \n+\tret = mmc_boot_part_access_chk(mmc, part_num);\n+\tif (ret)\n+\t\treturn ret;\n+\n \tret = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL, EXT_CSD_PART_CONF,\n \t\t\t (mmc->part_config & ~PART_ACCESS_MASK)\n \t\t\t | (part_num & PART_ACCESS_MASK));\n@@ -1438,7 +1467,7 @@ static const struct mode_width_tuning sd_modes_by_pref[] = {\n \t     mwt++) \\\n \t\tif (caps & MMC_CAP(mwt->mode))\n \n-static int sd_select_mode_and_width(struct mmc *mmc)\n+static int sd_select_mode_and_width(struct mmc *mmc, uint card_caps)\n {\n \tint err;\n \tuint widths[] = {MMC_MODE_4BIT, MMC_MODE_1BIT};\n@@ -1447,11 +1476,8 @@ static int sd_select_mode_and_width(struct mmc *mmc)\n \tuint caps;\n \n \n-\terr = sd_get_capabilities(mmc);\n-\tif (err)\n-\t\treturn err;\n \t/* Restrict card's capabilities by what the host can do */\n-\tcaps = mmc->card_caps & (mmc->host_caps | MMC_MODE_1BIT);\n+\tcaps = card_caps & (mmc->host_caps | MMC_MODE_1BIT);\n \n \tif (!uhs_en)\n \t\tcaps &= ~UHS_CAPS;\n@@ -1588,18 +1614,14 @@ static const struct ext_csd_bus_width {\n \t    ecbv++) \\\n \t\tif ((ddr == ecbv->is_ddr) && (caps & ecbv->cap))\n \n-static int mmc_select_mode_and_width(struct mmc *mmc)\n+static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps)\n {\n \tint err;\n \tconst struct mode_width_tuning *mwt;\n \tconst struct ext_csd_bus_width *ecbw;\n \n-\terr = mmc_get_capabilities(mmc);\n-\tif (err)\n-\t\treturn err;\n-\n \t/* Restrict card's capabilities by what the host can do */\n-\tmmc->card_caps &= (mmc->host_caps | MMC_MODE_1BIT);\n+\tcard_caps &= (mmc->host_caps | MMC_MODE_1BIT);\n \n \t/* Only version 4 of MMC supports wider bus widths */\n \tif (mmc->version < MMC_VERSION_4)\n@@ -1610,8 +1632,10 @@ static int mmc_select_mode_and_width(struct mmc *mmc)\n \t\treturn -ENOTSUPP;\n \t}\n \n-\tfor_each_mmc_mode_by_pref(mmc->card_caps, mwt) {\n-\t\tfor_each_supported_width(mmc->card_caps & mwt->widths,\n+\tmmc_set_clock(mmc, mmc->legacy_speed, false);\n+\n+\tfor_each_mmc_mode_by_pref(card_caps, mwt) {\n+\t\tfor_each_supported_width(card_caps & mwt->widths,\n \t\t\t\t\t mmc_is_mode_ddr(mwt->mode), ecbw) {\n \t\t\tdebug(\"trying mode %s width %d (at %d MHz)\\n\",\n \t\t\t      mmc_mode_name(mwt->mode),\n@@ -2006,14 +2030,22 @@ static int mmc_startup(struct mmc *mmc)\n \tif (err)\n \t\treturn err;\n \n-\tif (IS_SD(mmc))\n-\t\terr = sd_select_mode_and_width(mmc);\n-\telse\n-\t\terr = mmc_select_mode_and_width(mmc);\n+\tif (IS_SD(mmc)) {\n+\t\terr = sd_get_capabilities(mmc);\n+\t\tif (err)\n+\t\t\treturn err;\n+\t\terr = sd_select_mode_and_width(mmc, mmc->card_caps);\n+\t} else {\n+\t\terr = mmc_get_capabilities(mmc);\n+\t\tif (err)\n+\t\t\treturn err;\n+\t\tmmc_select_mode_and_width(mmc, mmc->card_caps);\n+\t}\n \n \tif (err)\n \t\treturn err;\n \n+\tmmc->best_mode = mmc->selected_mode;\n \n \t/* Fix the block length for DDR mode */\n \tif (mmc->ddr_mode) {\ndiff --git a/include/mmc.h b/include/mmc.h\nindex 59ea363..a8901bf 100644\n--- a/include/mmc.h\n+++ b/include/mmc.h\n@@ -585,7 +585,12 @@ struct mmc {\n #endif\n #endif\n \tu8 *ext_csd;\n-\tenum bus_mode selected_mode;\n+\tenum bus_mode selected_mode; /* mode currently used */\n+\tenum bus_mode best_mode; /* best mode is the supported mode with the\n+\t\t\t\t  * highest bandwidth. It may not always be the\n+\t\t\t\t  * operating mode due to limitations when\n+\t\t\t\t  * accessing the boot partitions\n+\t\t\t\t  */\n };\n \n struct mmc_hwpart_conf {\n","prefixes":["U-Boot","v2","22/26"]}