[{"id":1773615,"web_url":"http://patchwork.ozlabs.org/comment/1773615/","msgid":"<833b30e7-6121-c751-599d-2e8269659d9d@samsung.com>","list_archive_url":null,"date":"2017-09-22T13:54:40","subject":"Re: [U-Boot] [PATCH v2 24/26] mmc: use the right voltage level for\n\tMMC DDR and HS200 modes","submitter":{"id":8006,"url":"http://patchwork.ozlabs.org/api/people/8006/","name":"Jaehoon Chung","email":"jh80.chung@samsung.com"},"content":"On 09/21/2017 11:30 PM, Jean-Jacques Hiblot wrote:\n> HS200 only supports 1.2v and 1.8v signal voltages. DDR52 supports 3.3v/1.8v\n> or 1.2v signal voltages.\n> Select the lowest voltage available when using those modes.\n> \n> Signed-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(-)\n> \n> diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c\n> index 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\nPlz, change line.\ncase xxx:\n\treturn xxx;\n\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\nInitialized err = 0\n\n> +\n> +\tif (mmc->signal_voltage == signal_voltage)\n> +\t\treturn 0;\n\nreturn err; or use return ret?\n\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\nJust return 0?\n\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\ndoesn't need to check the return value?\n\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);\n> diff --git a/include/mmc.h b/include/mmc.h\n> index 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>","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>)","Received":["from lists.denx.de (dione.denx.de [81.169.180.215])\n\tby ozlabs.org (Postfix) with ESMTP id 3xzFRx6P22z9sRW\n\tfor <incoming@patchwork.ozlabs.org>;\n\tFri, 22 Sep 2017 23:58:05 +1000 (AEST)","by lists.denx.de (Postfix, from userid 105)\n\tid 917BAC2207B; Fri, 22 Sep 2017 13:56:04 +0000 (UTC)","from lists.denx.de (localhost [IPv6:::1])\n\tby lists.denx.de (Postfix) with ESMTP id 83626C22044;\n\tFri, 22 Sep 2017 13:55:00 +0000 (UTC)","by lists.denx.de (Postfix, from userid 105)\n\tid 4BA11C2201D; Fri, 22 Sep 2017 13:54:54 +0000 (UTC)","from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33])\n\tby lists.denx.de (Postfix) with ESMTPS id 98B0CC2204B\n\tfor <u-boot@lists.denx.de>; Fri, 22 Sep 2017 13:54:46 +0000 (UTC)","from epcas1p4.samsung.com (unknown [182.195.41.48])\n\tby mailout3.samsung.com (KnoxPortal) with ESMTP id\n\t20170922135441epoutp031ebca11c0bf365afc01cea58f97ace2e~ms36H2Q_c0533105331epoutp038;\n\tFri, 22 Sep 2017 13:54:41 +0000 (GMT)","from epsmges2p4.samsung.com (unknown [182.195.40.64]) by\n\tepcas1p4.samsung.com (KnoxPortal) with ESMTP id\n\t20170922135441epcas1p4b14c3152eb1fb6863e29c0f81649efa1~ms35zzJTo1001310013epcas1p4n;\n\tFri, 22 Sep 2017 13:54:41 +0000 (GMT)","from epcas2p2.samsung.com ( [182.195.41.54]) by\n\tepsmges2p4.samsung.com (Symantec Messaging Gateway) with SMTP id\n\t91.02.13866.12615C95; Fri, 22 Sep 2017 22:54:41 +0900 (KST)","from epsmgms2p2new.samsung.com (unknown [182.195.42.143]) by\n\tepcas2p4.samsung.com (KnoxPortal) with ESMTP id\n\t20170922135440epcas2p4c50521da61a321a4f6d1c118a6f6636b~ms35kbu7T3181431814epcas2p4G;\n\tFri, 22 Sep 2017 13:54:40 +0000 (GMT)","from epmmp1.local.host ( [203.254.227.16]) by\n\tepsmgms2p2new.samsung.com (Symantec Messaging Gateway) with SMTP id\n\t76.ED.10338.02615C95; Fri, 22 Sep 2017 22:54:40 +0900 (KST)","from [10.113.62.216] by mmp1.samsung.com (Oracle Communications\n\tMessaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id\n\t<0OWO00FYRPB4TV30@mmp1.samsung.com>;\n\tFri, 22 Sep 2017 22:54:40 +0900 (KST)"],"X-Spam-Checker-Version":"SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de","X-Spam-Level":"","X-Spam-Status":"No, score=-5.0 required=5.0 tests=RCVD_IN_DNSWL_HI,\n\tRCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL,\n\tSPF_HELO_PASS autolearn=unavailable\n\tautolearn_force=no version=3.4.0","X-AuditID":"b6c32a48-f79a16d00000362a-26-59c51621cdd5","To":"Jean-Jacques Hiblot <jjhiblot@ti.com>, trini@konsulko.com,\n\tkishon@ti.com, sjg@chromium.org","From":"Jaehoon Chung <jh80.chung@samsung.com>","Message-id":"<833b30e7-6121-c751-599d-2e8269659d9d@samsung.com>","Date":"Fri, 22 Sep 2017 22:54:40 +0900","User-Agent":"Mozilla/5.0 (X11; Linux i686; rv:52.0) Gecko/20100101\n\tThunderbird/52.2.1","MIME-version":"1.0","In-reply-to":"<1506004213-22620-25-git-send-email-jjhiblot@ti.com>","Content-language":"en-US","X-Brightmail-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rytsuVfn1hb5KoOtaYaTwd/3zo+qOnLrl0w9qz5jrEuicU7PyFMw\n\tK8f8A4YgtO2lAwAA","H4sIAAAAAAAAA+NgFnrOLMWRmVeSWpSXmKPExsVy+t9jAV0FsaORBhuO6Fu0nJzEZHHhaQ+b\n\txdE995gtvm3ZxmgxddJmdou3ezvZHdg8ZjdcZPHYOesuu8erA6vYPc7e2cHocfzGdqYA1igu\n\tm5TUnMyy1CJ9uwSujB1vNrAW3NKtOHJhG0sD4w3lLkZODgkBE4mZj5uYuhi5OIQEdjJK7Lh7\n\tEMp5wCixZUYHM0iVsECMxNJPDYwgtohAgsT/LVfYQGxmAX2J56fXMEM0nALqPtcDlmAT0JHY\n\t/u04E4jNK2An8Wj7RLA4i4CqROPkw2C2qECYRH/zX2aIGkGJH5PvsYDYnAKOEk/nHwFaxgG0\n\tQF1iypRciF3iEs2tN1kgbHmJzWveMk9gFJiFpHsWQscsJB2zkHQsYGRZxSiZWlCcm55bbFRg\n\tlJdarlecmFtcmpeul5yfu4kRGPzbDmv172B8vCT+EKMAB6MSD6/BwcORQqyJZcWVuYcYJTiY\n\tlUR4j/47EinEm5JYWZValB9fVJqTWnyIUZqDRUmcN7NvRqSQQHpiSWp2ampBahFMlomDU6qB\n\tcd5OvX8R5zbNm1jQvuu2RJ23QrDbEc4li1cyH7GdJC/16k3l9oXq21Ys3LFtR8y3Dmnu7/Ef\n\thEI78rienQ1bWnRjUpYOlxZjj2GcZtiZnzvNVH8qCQkwLExdLvo2evOONfs1JuRsz3aJmp4z\n\t9ZbM0TPJ60PWK2q93Mle9q4gLOPilf8LVrHV1CqxFGckGmoxFxUnAgDtN27kegIAAA=="],"X-CMS-MailID":"20170922135440epcas2p4c50521da61a321a4f6d1c118a6f6636b","X-Msg-Generator":"CA","X-Sender-IP":"182.195.42.143","X-Local-Sender":"=?utf-8?b?7KCV7J6s7ZuIG1RpemVuIFBsYXRmb3JtIExhYihTL1c=?=\n\t=?utf-8?b?7IS87YSwKRvsgrzshLHsoITsnpAbU2VuaW9yIEVuZ2luZWVy?=","X-Global-Sender":"=?utf-8?q?Jaehoon_Chung=1BTizen_Platform_Lab=2E=1BSamsun?=\n\t=?utf-8?q?g_Electronics=1BSenior_Engineer?=","X-Sender-Code":"=?utf-8?q?C10=1BTELE=1BC10V8111?=","CMS-TYPE":"102P","DLP-Filter":"Pass","X-CFilter-Loop":"Reflected","X-CMS-RootMailID":"20170921143117epcas2p3034853e027617cb12224c7ecef24c1ae","X-RootMTR":"20170921143117epcas2p3034853e027617cb12224c7ecef24c1ae","References":"<1506004213-22620-1-git-send-email-jjhiblot@ti.com>\n\t<CGME20170921143117epcas2p3034853e027617cb12224c7ecef24c1ae@epcas2p3.samsung.com>\n\t<1506004213-22620-25-git-send-email-jjhiblot@ti.com>","Cc":"u-boot@lists.denx.de","Subject":"Re: [U-Boot] [PATCH v2 24/26] mmc: use the right voltage level for\n\tMMC DDR 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>"}}]