{"id":816919,"url":"http://patchwork.ozlabs.org/api/patches/816919/?format=json","web_url":"http://patchwork.ozlabs.org/project/uboot/patch/1506004213-22620-25-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-25-git-send-email-jjhiblot@ti.com>","list_archive_url":null,"date":"2017-09-21T14:30:11","name":"[U-Boot,v2,24/26] mmc: use the right voltage level for MMC DDR and HS200 modes","commit_ref":"bc1e3272ff3437f7cfc5e8bf1d1f2767f6d78262","pull_url":null,"state":"accepted","archived":false,"hash":"10343a71d7b1c6ae71f443e288eae4d7317e45fe","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-25-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/816919/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/816919/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=\"cRIqPr60\";\n\tdkim-atps=neutral"],"Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xyfbk6MXcz9sP1\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 22 Sep 2017 00:47:46 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid A6E64C22050; Thu, 21 Sep 2017 14:36:17 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id B5200C21E57;\n\tThu, 21 Sep 2017 14:32:57 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 8735CC2202D; Thu, 21 Sep 2017 14:31:21 +0000 (UTC)","from lelnx194.ext.ti.com (lelnx194.ext.ti.com [198.47.27.80])\n\tby lists.denx.de (Postfix) with ESMTPS id EB5D0C21FFA\n\tfor <u-boot@lists.denx.de>; Thu, 21 Sep 2017 14:31:14 +0000 (UTC)","from dflxv15.itg.ti.com ([128.247.5.124])\n\tby lelnx194.ext.ti.com (8.15.1/8.15.1) with ESMTP id v8LEVCGm002975; \n\tThu, 21 Sep 2017 09:31:12 -0500","from DFLE106.ent.ti.com (dfle106.ent.ti.com [10.64.6.27])\n\tby dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id v8LEVChf029492;\n\tThu, 21 Sep 2017 09:31:12 -0500","from DFLE101.ent.ti.com (10.64.6.22) by DFLE106.ent.ti.com\n\t(10.64.6.27) 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:12 -0500","from dlep33.itg.ti.com (157.170.170.75) by DFLE101.ent.ti.com\n\t(10.64.6.22) 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:12 -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 v8LEVBgR012093;\n\tThu, 21 Sep 2017 09:31:11 -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=1506004272;\n\tbh=CpGm1mGtVnMlAPU+jYXJAi/UWkalJovLWG2JIMtzv9E=;\n\th=From:To:CC:Subject:Date:In-Reply-To:References;\n\tb=cRIqPr60Wh48hCQyOMhKATtfMReBpFbqgaKUOdKVCaorQ4eeDP+hDC4ouu0Y56cet\n\tM9dAgXnmtWV7sUXDkr1Ukxj65Up/wJ4GYaXQgwiI6N8w667oTPu5H3heRtoTuoz61M\n\t2YvCTYhm66NOTCHY7EVgJMwo59K0AiiLarBUZB1k=","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:11 +0200","Message-ID":"<1506004213-22620-25-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 24/26] mmc: use the right voltage level for MMC\n\tDDR and HS200 modes","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":"HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v\nor 1.2v signal voltages.\nSelect the lowest voltage available when using those modes.\n\nSigned-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>\n---\n drivers/mmc/mmc.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++-\n include/mmc.h     | 20 +++++++++++++---\n 2 files changed, 84 insertions(+), 4 deletions(-)","diff":"diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c\nindex 6d1bf94..2d447dd 100644\n--- a/drivers/mmc/mmc.c\n+++ b/drivers/mmc/mmc.c\n@@ -767,6 +767,7 @@ static int mmc_get_capabilities(struct mmc *mmc)\n \tmmc->card_caps |= MMC_MODE_4BIT | MMC_MODE_8BIT;\n \n \tcardtype = ext_csd[EXT_CSD_CARD_TYPE] & 0x3f;\n+\tmmc->cardtype = cardtype;\n \n \tif (cardtype & (EXT_CSD_CARD_TYPE_HS200_1_2V |\n \t\t\tEXT_CSD_CARD_TYPE_HS200_1_8V)) {\n@@ -1441,10 +1442,30 @@ struct mode_width_tuning {\n \tuint tuning;\n };\n \n+int mmc_voltage_to_mv(enum mmc_voltage voltage)\n+{\n+\tswitch (voltage) {\n+\tcase MMC_SIGNAL_VOLTAGE_000: return 0;\n+\tcase MMC_SIGNAL_VOLTAGE_330: return 3300;\n+\tcase MMC_SIGNAL_VOLTAGE_180: return 1800;\n+\tcase MMC_SIGNAL_VOLTAGE_120: return 1200;\n+\t}\n+\treturn -EINVAL;\n+}\n+\n static int mmc_set_signal_voltage(struct mmc *mmc, uint signal_voltage)\n {\n+\tint err;\n+\n+\tif (mmc->signal_voltage == signal_voltage)\n+\t\treturn 0;\n+\n \tmmc->signal_voltage = signal_voltage;\n-\treturn mmc_set_ios(mmc);\n+\terr = mmc_set_ios(mmc);\n+\tif (err)\n+\t\tdebug(\"unable to set voltage (err %d)\\n\", err);\n+\n+\treturn err;\n }\n \n static const struct mode_width_tuning sd_modes_by_pref[] = {\n@@ -1584,6 +1605,43 @@ static int mmc_read_and_compare_ext_csd(struct mmc *mmc)\n \treturn -EBADMSG;\n }\n \n+static int mmc_set_lowest_voltage(struct mmc *mmc, enum bus_mode mode,\n+\t\t\t\t  uint32_t allowed_mask)\n+{\n+\tu32 card_mask = 0;\n+\n+\tswitch (mode) {\n+\tcase MMC_HS_200:\n+\t\tif (mmc->cardtype & EXT_CSD_CARD_TYPE_HS200_1_8V)\n+\t\t\tcard_mask |= MMC_SIGNAL_VOLTAGE_180;\n+\t\tif (mmc->cardtype & EXT_CSD_CARD_TYPE_HS200_1_2V)\n+\t\t\tcard_mask |= MMC_SIGNAL_VOLTAGE_120;\n+\t\tbreak;\n+\tcase MMC_DDR_52:\n+\t\tif (mmc->cardtype & EXT_CSD_CARD_TYPE_DDR_1_8V)\n+\t\t\tcard_mask |= MMC_SIGNAL_VOLTAGE_330 |\n+\t\t\t\t     MMC_SIGNAL_VOLTAGE_180;\n+\t\tif (mmc->cardtype & EXT_CSD_CARD_TYPE_DDR_1_2V)\n+\t\t\tcard_mask |= MMC_SIGNAL_VOLTAGE_120;\n+\t\tbreak;\n+\tdefault:\n+\t\tcard_mask |= MMC_SIGNAL_VOLTAGE_330;\n+\t\tbreak;\n+\t}\n+\n+\twhile (card_mask & allowed_mask) {\n+\t\tenum mmc_voltage best_match;\n+\n+\t\tbest_match = 1 << (ffs(card_mask & allowed_mask) - 1);\n+\t\tif (!mmc_set_signal_voltage(mmc,  best_match))\n+\t\t\treturn 0;\n+\n+\t\tallowed_mask &= ~best_match;\n+\t}\n+\n+\treturn -ENOTSUPP;\n+}\n+\n static const struct mode_width_tuning mmc_modes_by_pref[] = {\n \t{\n \t\t.mode = MMC_HS_200,\n@@ -1655,10 +1713,17 @@ static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps)\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\tenum mmc_voltage old_voltage;\n \t\t\tdebug(\"trying mode %s width %d (at %d MHz)\\n\",\n \t\t\t      mmc_mode_name(mwt->mode),\n \t\t\t      bus_width(ecbw->cap),\n \t\t\t      mmc_mode2freq(mmc, mwt->mode) / 1000000);\n+\t\t\told_voltage = mmc->signal_voltage;\n+\t\t\terr = mmc_set_lowest_voltage(mmc, mwt->mode,\n+\t\t\t\t\t\t     MMC_ALL_SIGNAL_VOLTAGE);\n+\t\t\tif (err)\n+\t\t\t\tcontinue;\n+\n \t\t\t/* configure the bus width (card + host) */\n \t\t\terr = mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,\n \t\t\t\t    EXT_CSD_BUS_WIDTH,\n@@ -1702,6 +1767,7 @@ static int mmc_select_mode_and_width(struct mmc *mmc, uint card_caps)\n \t\t\tif (!err)\n \t\t\t\treturn 0;\n error:\n+\t\t\tmmc_set_signal_voltage(mmc, old_voltage);\n \t\t\t/* if an error occured, revert to a safer bus mode */\n \t\t\tmmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,\n \t\t\t\t   EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_1);\ndiff --git a/include/mmc.h b/include/mmc.h\nindex a9ebc88..c11f698 100644\n--- a/include/mmc.h\n+++ b/include/mmc.h\n@@ -311,11 +311,15 @@ static inline bool mmc_is_tuning_cmd(uint cmdidx)\n \n enum mmc_voltage {\n \tMMC_SIGNAL_VOLTAGE_000 = 0,\n-\tMMC_SIGNAL_VOLTAGE_120,\n-\tMMC_SIGNAL_VOLTAGE_180,\n-\tMMC_SIGNAL_VOLTAGE_330\n+\tMMC_SIGNAL_VOLTAGE_120 = 1,\n+\tMMC_SIGNAL_VOLTAGE_180 = 2,\n+\tMMC_SIGNAL_VOLTAGE_330 = 4,\n };\n \n+#define MMC_ALL_SIGNAL_VOLTAGE (MMC_SIGNAL_VOLTAGE_120 |\\\n+\t\t\t\tMMC_SIGNAL_VOLTAGE_180 |\\\n+\t\t\t\tMMC_SIGNAL_VOLTAGE_330)\n+\n /* Maximum block size for MMC */\n #define MMC_MAX_BLOCK_LEN\t512\n \n@@ -588,6 +592,8 @@ struct mmc {\n #endif\n #endif\n \tu8 *ext_csd;\n+\tu32 cardtype;\t\t/* cardtype read from the MMC */\n+\tenum mmc_voltage current_voltage;\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@@ -647,6 +653,14 @@ int mmc_init(struct mmc *mmc);\n int mmc_read(struct mmc *mmc, u64 src, uchar *dst, int size);\n \n /**\n+ * mmc_voltage_to_mv() - Convert a mmc_voltage in mV\n+ *\n+ * @voltage:\tThe mmc_voltage to convert\n+ * @return the value in mV if OK, -EINVAL on error (invalid mmc_voltage value)\n+ */\n+int mmc_voltage_to_mv(enum mmc_voltage voltage);\n+\n+/**\n  * mmc_set_clock() - change the bus clock\n  * @mmc:\tMMC struct\n  * @clock:\tbus frequency in Hz\n","prefixes":["U-Boot","v2","24/26"]}