From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A, SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 66B3FC4338F for ; Sun, 1 Aug 2021 21:55:58 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 261E060E08 for ; Sun, 1 Aug 2021 21:55:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 261E060E08 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=samsung.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 29000831D6; Sun, 1 Aug 2021 23:55:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=samsung.com header.i=@samsung.com header.b="H4j5UTn2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A6ED5832D0; Sun, 1 Aug 2021 23:55:53 +0200 (CEST) Received: from mailout3.samsung.com (mailout3.samsung.com [203.254.224.33]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id AB44E831D6 for ; Sun, 1 Aug 2021 23:55:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=samsung.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jh80.chung@samsung.com Received: from epcas1p2.samsung.com (unknown [182.195.41.46]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20210801215544epoutp03e298da9153427d7da3c07307e7771dd6~XTXJ5xZMU1249312493epoutp03b for ; Sun, 1 Aug 2021 21:55:44 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20210801215544epoutp03e298da9153427d7da3c07307e7771dd6~XTXJ5xZMU1249312493epoutp03b DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1627854944; bh=fRPUUdT5ePhQAJbtVN0d1g8k++KvevIqpdnRpDxYUw8=; h=Subject:To:Cc:From:Date:In-Reply-To:References:From; b=H4j5UTn2ODlmbBJcjZKGqa73+JwDarqXyKYbS6J477C9R55c5HHusJmIicsS58QzL bDbEowHbAp6T+fXjnj5N3yRlhuKZSpaBfVjwYx7E1WMDNqYBz2E+imbZIilzyW6BOy u2sE6MxCaly65BjZh1jBVH46+DhqYvl0UEzo1JKg= Received: from epsnrtp1.localdomain (unknown [182.195.42.162]) by epcas1p2.samsung.com (KnoxPortal) with ESMTP id 20210801215543epcas1p2093452c05ba08afa40df054d2cff447c~XTXJUQMDT1369113691epcas1p2c; Sun, 1 Aug 2021 21:55:43 +0000 (GMT) Received: from epsmges1p5.samsung.com (unknown [182.195.40.155]) by epsnrtp1.localdomain (Postfix) with ESMTP id 4GdFLj44bmz4x9Pp; Sun, 1 Aug 2021 21:55:41 +0000 (GMT) Received: from epcas1p1.samsung.com ( [182.195.41.45]) by epsmges1p5.samsung.com (Symantec Messaging Gateway) with SMTP id AB.29.13454.C5817016; Mon, 2 Aug 2021 06:55:40 +0900 (KST) Received: from epsmtrp2.samsung.com (unknown [182.195.40.14]) by epcas1p4.samsung.com (KnoxPortal) with ESMTPA id 20210801215540epcas1p473e9846e414895c2a833142623274e7d~XTXGatIFx0178001780epcas1p4t; Sun, 1 Aug 2021 21:55:40 +0000 (GMT) Received: from epsmgms1p2.samsung.com (unknown [182.195.42.42]) by epsmtrp2.samsung.com (KnoxPortal) with ESMTP id 20210801215540epsmtrp2a5de8e6d3858c9dc972eff33177b7603~XTXGco5W32184621846epsmtrp2O; Sun, 1 Aug 2021 21:55:40 +0000 (GMT) X-AuditID: b6c32a39-185ff7000002348e-82-6107185c0c81 Received: from epsmtip1.samsung.com ( [182.195.34.30]) by epsmgms1p2.samsung.com (Symantec Messaging Gateway) with SMTP id 0F.94.08289.B5817016; Mon, 2 Aug 2021 06:55:39 +0900 (KST) Received: from [10.113.113.235] (unknown [10.113.113.235]) by epsmtip1.samsung.com (KnoxPortal) with ESMTPA id 20210801215540epsmtip1432081d523c578d72128ea1625e3b1ed~XTXGF752_0393703937epsmtip1F; Sun, 1 Aug 2021 21:55:40 +0000 (GMT) Subject: Re: [PATCH v2] mmc: Add support for enumerating MMC card in a given mode using mmc command To: Aswath Govindraju Cc: Lokesh Vutla , Kishon Vijay Abraham I , Vignesh Raghavendra , Peng Fan , Simon Glass , Heinrich Schuchardt , Bin Meng , Patrick Delaunay , Pragnesh Patel , =?UTF-8?Q?Fr=c3=a9d=c3=a9ric_Danis?= , Reuben Dowle , Yangbo Lu , Stefan Roese , Nicolas Saenz Julienne , Stefan Bosch , =?UTF-8?Q?Pali_Roh=c3=a1r?= , Ashok Reddy Soma , u-boot@lists.denx.de From: Jaehoon Chung Message-ID: Date: Mon, 2 Aug 2021 06:56:30 +0900 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: <20210730122640.26844-1-a-govindraju@ti.com> Content-Language: en-US Content-Transfer-Encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA02Te0xTZxjG953Tnh5wNYdy8YM/NmxIFnEtFCgeGBAJuJ3oYiBuLixKPYEz YPS2HnBTcGu4bNCwixriLBPBKbfgZYCl4CqxzYKMUZChA+QyIgzEgEWgwgiylpaM/37v+z1P 3u/5vrw4KljHAvAsZQ6jUdJyIebJMVj2iETHII8OtZqDyMrJfi5p7tMiZHmZjGz4u5pH9k2V YWRdyRIgDfpajKz6tRsjz918xCNXGpa45EP9PYd2/DpK2lsMgOy6YUPI5SRyzlTKIzd6bDzS Um4D5MWuiP3eVIX2AYcyjl4FVKX+Poea+v42j2rTj/Io20Iq1dRQilE9I0ZA/TJvRKgnli4e 1V/4F49q7s6jOgdbEcq0uMZJ2vlxdkwmQ6czmkBGmaZKz1JmxAoPHZElyKSRoRKRJIrcJwxU 0gomVpj4fpLo3Sy5I6ow8CQtz3W0kmiWFYbExWhUuTlMYKaKzYkVMup0uTpKLWZpBZurzBCn qRTRktDQMKlDeCI7s63yDqaezftiauIWogXnUnXAA4dEBJzosWE64IkLCCOAjRMD7uIFgAsF 9RxXsQjg6NC3vC2L9WUR6jpoB7BkosldPAfw6j/PgQ7guDfBwAs3xE6DD7EXNuvOcp0alBji wqLf+znOA4x4G7baOxEn84k4qCte5TqZQwRB48PhTfYlUmDvnSqOS+MFuy5ObrIHEQVHiq2Y k1FiFxyevIy4+E3YOvfT5oUgUeEBx35cwFzXToQtpRuIi73hbGeLO04AXJw3uTV5sL3wD7e5 BMBhQ4HbEA47rp1HnMlQYg+82R7iau+GbWuXgGvwTji/XMZ1SiDBhyVfC1ySINj/7CmyNWp0 coPrYgo+Lqvh/AB267dF02+Lo98WR///4CrAaQB+jJpVZDCsRC3d/t1NYHMPgqOM4MKcTWwG CA7MAOKo0IcfWY/RAn46feo0o1HJNLlyhjUDqeOxz6IBvmkqxyIpc2QSaVh4eDgZIYmUSiTC XXz78eUTAiKDzmGyGUbNaLZ8CO4RoEV+7kbfaO+tFifED8R9yhcF3T5jbHzxzHT98mxvwXeJ Y9ya92zB3Nlk8TeGVKxNoK3esXDAfFDi02yN/+Qp6ld/Kf+tw/vreMfxD1nt6gfHav98kDLd MYSb9v121FK83htzpOqAX9n04x0+pha7znj6M4X/3Fo+Ghvtm/Ka3+7Ek6d8IpOrlqBVy1Q2 9nv1XVuJ+cgiqN3wGC8uvrJ6r261Ru35yCCaGQmOn3mJvtIPJI9f0X5uPxPS5l8xd8v6pHmm JP7uynSHpbsuv8BrLP2durDc2vt7D93N/DLl3+juV/KElUn/wWx0HeZPMUfLD5OvN2QU+RcS yvMKmT3/q8G8oSEhh82kJcGohqX/A+eDjAqQBAAA X-Brightmail-Tracker: H4sIAAAAAAAAA02Ra0hTYRyHec85O+dorU5z1Zup5QhMq5UV8XZBUiJO0gcRikpST3lSyans mJVRjW7UsFmjEZ1qWUnlsuV1bqlFW2jLnJdlSW1dSL9Y1mLLEruuEfjt4f97nk9/Gpe9IiLp /MISXl3IFSjIcMLiUMQsyoAUt8T2QImMg30SZO/RYMhQnoVMb69SqGeonES3TgYAsog3SVTZ 2kki/d3nFPpuCkhQv/jwr/vmDo5GGy0AOc0+DH1NQyNtpyj0u8tHIYfBB9AF5/K1EexFTS/B Wr1VgDWKjwl2qKKJYm2il2J9XzLZetMpku3yWAFb98mKse8dTortO/qCYhs6D7AdA80Y2+Yf J9KmbAtfk8MX5Jfy6sVJ2eF5NmMLWTx8YN/Qu1pMA/SZWhBGQ2Y5dH07hmtBOC1jrAB2VtWC 0BAJ/UMGUgvovxwBHQ4h5IwA6D7djwfvEQwPz5uVQV3OLIAN2rOSoIMzXgkMtN/EQkE5gAGd EQ9aJLMQNo92YEGWMklQe3xMEmSCmQet/S//8XRmK/RXDktCzjTovDBIBDmMWQk9x11kkHEm Dv4w9uEhnglfDl7BQjwHNo9cws8AmTghFyck4oREnJBUAsIEZvHFgipXJSQWLy3k9yoFTiXs KcxV7ixS1YN//09IsIJWk09pBxgN7ADSuEIuXVFNcjJpDre/jFcXZan3FPCCHcymCcVMaY/W mSVjcrkSfjfPF/Pq/ytGh0VqsDnvNlLZ+xOFnprc+LItr39039PdSO8Vou9Hyz9HTb29qm3L s9pHseCblxTZX3c79DG6X0Wua/pV5jGXx9HYKu+qwC+PcLtuNK+tqZl7grC167KiY9QJpa4j dYdXH1r9RJ5idg9HzweTr9gz9BnnTjr3VkcOKBtaeMN7VmNRnNg+tjUub1mcLe5Taj41Oy1g x5OdZV97Wzz2g9ti/U0zDJt2bMiua+0zhzmbAu7GcakupSNnRUpyU9HZqI2pUet/Xz83K8JS P57+IW1NY+LDI6/E2IOpFXXJSSUfv49+2dn9ND6wPj3P0p7avk71yG3cPN2/TH/HW40mVbk9 Z1b+LFUQQh6XmICrBe4PFnqYZ24DAAA= X-CMS-MailID: 20210801215540epcas1p473e9846e414895c2a833142623274e7d X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20210730122724epcas1p30ad1d84eea1794454cf0eaddf1741e09 References: <20210730122640.26844-1-a-govindraju@ti.com> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean Hi Aswath, On 7/30/21 9:26 PM, Aswath Govindraju wrote: > Add support for enumerating MMC card in a given mode using mmc rescan and > mmc dev commands. The speed mode is provided as the last argument in these > commands and is indicated using the index from enum bus_mode in > include/mmc.h. A speed mode can be set only if it has already been enabled > in the device tree. > > Signed-off-by: Aswath Govindraju > --- > > Changes since v1: > - Removed #ifdef around the definition of user_speed_mode field > - Replaced #if with if (IS_ENABLED()) > - Removed repeated MMC_CAP(MMC_LEGACY) > - initialized user_speed_mode to MMC_MODES_SPEED in mmc_init_device > and mmc_dp_preinit > - corrected curr_device to dev and included part check, the case when > mode is provided in the argument > > cmd/Kconfig | 10 ++++++ > cmd/mmc.c | 75 +++++++++++++++++++++++++++++----------- > doc/usage/mmc.rst | 49 ++++++++++++++++++++++++-- > drivers/mmc/mmc-uclass.c | 5 ++- > drivers/mmc/mmc.c | 22 +++++++++++- > include/mmc.h | 2 ++ > 6 files changed, 138 insertions(+), 25 deletions(-) > > diff --git a/cmd/Kconfig b/cmd/Kconfig > index ffef3cc76ca4..3a857b3f6e2e 100644 > --- a/cmd/Kconfig > +++ b/cmd/Kconfig > @@ -2389,4 +2389,14 @@ config CMD_UBIFS > help > UBIFS is a file system for flash devices which works on top of UBI. > > +config MMC_SPEED_MODE_SET > + bool "set speed mode using mmc command" > + depends on CMD_MMC > + default n > + help > + Enable setting speed mode using mmc rescan and mmc dev commands. > + The speed mode is provided as the last argument in these commands > + and is indicated using the index from enum bus_mode in > + include/mmc.h. A speed mode can be set only if it has already > + been enabled in the device tree. > endmenu > diff --git a/cmd/mmc.c b/cmd/mmc.c > index b942576b58ac..e256210a3705 100644 > --- a/cmd/mmc.c > +++ b/cmd/mmc.c > @@ -120,7 +120,9 @@ static void print_mmcinfo(struct mmc *mmc) > } > } > } > -static struct mmc *init_mmc_device(int dev, bool force_init) > + > +static struct mmc *init_mmc_device(int dev, bool force_init, > + enum bus_mode speed_mode) how about using wrapper function? static struct mmc *__init_mmc_device(int dev, bool force_init, enum bus_mode spped_mode) { ... } static struct mmc *init_mmc_device(int dev, bool force_init) { return __init_mmc_device(dev, force_init, MMC_MODES_END); } Then it doesn't need to touch all init_mmc_device caller. Just my opinion :) Best Regards, Jaehoon Chung > { > struct mmc *mmc; > mmc = find_mmc_device(dev); > @@ -134,6 +136,10 @@ static struct mmc *init_mmc_device(int dev, bool force_init) > > if (force_init) > mmc->has_init = 0; > + > + if (IS_ENABLED(CONFIG_MMC_SPEED_MODE_SET)) > + mmc->user_speed_mode = speed_mode; > + > if (mmc_init(mmc)) > return NULL; > > @@ -159,7 +165,7 @@ static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc, > } > } > > - mmc = init_mmc_device(curr_device, false); > + mmc = init_mmc_device(curr_device, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -293,7 +299,7 @@ static int do_mmcrpmb(struct cmd_tbl *cmdtp, int flag, > if (flag == CMD_FLAG_REPEAT && !cmd_is_repeatable(cp)) > return CMD_RET_SUCCESS; > > - mmc = init_mmc_device(curr_device, false); > + mmc = init_mmc_device(curr_device, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -338,7 +344,7 @@ static int do_mmc_read(struct cmd_tbl *cmdtp, int flag, > blk = simple_strtoul(argv[2], NULL, 16); > cnt = simple_strtoul(argv[3], NULL, 16); > > - mmc = init_mmc_device(curr_device, false); > + mmc = init_mmc_device(curr_device, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -387,7 +393,7 @@ static int do_mmc_sparse_write(struct cmd_tbl *cmdtp, int flag, > return CMD_RET_FAILURE; > } > > - mmc = init_mmc_device(curr_device, false); > + mmc = init_mmc_device(curr_device, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -431,7 +437,7 @@ static int do_mmc_write(struct cmd_tbl *cmdtp, int flag, > blk = simple_strtoul(argv[2], NULL, 16); > cnt = simple_strtoul(argv[3], NULL, 16); > > - mmc = init_mmc_device(curr_device, false); > + mmc = init_mmc_device(curr_device, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -460,7 +466,7 @@ static int do_mmc_erase(struct cmd_tbl *cmdtp, int flag, > blk = simple_strtoul(argv[1], NULL, 16); > cnt = simple_strtoul(argv[2], NULL, 16); > > - mmc = init_mmc_device(curr_device, false); > + mmc = init_mmc_device(curr_device, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -482,8 +488,19 @@ static int do_mmc_rescan(struct cmd_tbl *cmdtp, int flag, > int argc, char *const argv[]) > { > struct mmc *mmc; > + enum bus_mode speed_mode = MMC_MODES_END; > + > + if (argc == 1) { > + mmc = init_mmc_device(curr_device, true, MMC_MODES_END); > + } else if (argc == 2) { > + /* parse the mode */ > + speed_mode = simple_strtoul(argv[1], NULL, 10); > + /* Need to pass the the speed mode required too */ > + mmc = init_mmc_device(curr_device, true, speed_mode); > + } else { > + return CMD_RET_USAGE; > + } > > - mmc = init_mmc_device(curr_device, true); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -496,7 +513,7 @@ static int do_mmc_part(struct cmd_tbl *cmdtp, int flag, > struct blk_desc *mmc_dev; > struct mmc *mmc; > > - mmc = init_mmc_device(curr_device, false); > + mmc = init_mmc_device(curr_device, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -515,11 +532,14 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag, > { > int dev, part = 0, ret; > struct mmc *mmc; > + enum bus_mode speed_mode = MMC_MODES_END; > > if (argc == 1) { > dev = curr_device; > + mmc = init_mmc_device(dev, true, MMC_MODES_END); > } else if (argc == 2) { > dev = simple_strtoul(argv[1], NULL, 10); > + mmc = init_mmc_device(dev, true, MMC_MODES_END); > } else if (argc == 3) { > dev = (int)simple_strtoul(argv[1], NULL, 10); > part = (int)simple_strtoul(argv[2], NULL, 10); > @@ -528,11 +548,21 @@ static int do_mmc_dev(struct cmd_tbl *cmdtp, int flag, > PART_ACCESS_MASK); > return CMD_RET_FAILURE; > } > + mmc = init_mmc_device(dev, true, MMC_MODES_END); > + } else if (argc == 4) { > + dev = (int)simple_strtoul(argv[1], NULL, 10); > + part = (int)simple_strtoul(argv[2], NULL, 10); > + if (part > PART_ACCESS_MASK) { > + printf("#part_num shouldn't be larger than %d\n", > + PART_ACCESS_MASK); > + return CMD_RET_FAILURE; > + } > + speed_mode = simple_strtoul(argv[3], NULL, 10); > + mmc = init_mmc_device(dev, true, speed_mode); > } else { > return CMD_RET_USAGE; > } > > - mmc = init_mmc_device(dev, true); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -636,7 +666,7 @@ static int do_mmc_hwpartition(struct cmd_tbl *cmdtp, int flag, > enum mmc_hwpart_conf_mode mode = MMC_HWPART_CONF_CHECK; > int i, r, pidx; > > - mmc = init_mmc_device(curr_device, false); > + mmc = init_mmc_device(curr_device, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -726,7 +756,7 @@ static int do_mmc_bootbus(struct cmd_tbl *cmdtp, int flag, > reset = simple_strtoul(argv[3], NULL, 10); > mode = simple_strtoul(argv[4], NULL, 10); > > - mmc = init_mmc_device(dev, false); > + mmc = init_mmc_device(dev, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -789,7 +819,7 @@ static int do_mmc_boot_resize(struct cmd_tbl *cmdtp, int flag, > bootsize = simple_strtoul(argv[2], NULL, 10); > rpmbsize = simple_strtoul(argv[3], NULL, 10); > > - mmc = init_mmc_device(dev, false); > + mmc = init_mmc_device(dev, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -844,7 +874,7 @@ static int do_mmc_partconf(struct cmd_tbl *cmdtp, int flag, > > dev = simple_strtoul(argv[1], NULL, 10); > > - mmc = init_mmc_device(dev, false); > + mmc = init_mmc_device(dev, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -887,7 +917,7 @@ static int do_mmc_rst_func(struct cmd_tbl *cmdtp, int flag, > return CMD_RET_USAGE; > } > > - mmc = init_mmc_device(dev, false); > + mmc = init_mmc_device(dev, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -939,7 +969,7 @@ static int do_mmc_bkops_enable(struct cmd_tbl *cmdtp, int flag, > > dev = simple_strtoul(argv[1], NULL, 10); > > - mmc = init_mmc_device(dev, false); > + mmc = init_mmc_device(dev, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > > @@ -958,7 +988,7 @@ static int do_mmc_boot_wp(struct cmd_tbl *cmdtp, int flag, > int err; > struct mmc *mmc; > > - mmc = init_mmc_device(curr_device, false); > + mmc = init_mmc_device(curr_device, false, MMC_MODES_END); > if (!mmc) > return CMD_RET_FAILURE; > if (IS_SD(mmc)) { > @@ -983,9 +1013,9 @@ static struct cmd_tbl cmd_mmc[] = { > #if CONFIG_IS_ENABLED(CMD_MMC_SWRITE) > U_BOOT_CMD_MKENT(swrite, 3, 0, do_mmc_sparse_write, "", ""), > #endif > - U_BOOT_CMD_MKENT(rescan, 1, 1, do_mmc_rescan, "", ""), > + U_BOOT_CMD_MKENT(rescan, 2, 1, do_mmc_rescan, "", ""), > U_BOOT_CMD_MKENT(part, 1, 1, do_mmc_part, "", ""), > - U_BOOT_CMD_MKENT(dev, 3, 0, do_mmc_dev, "", ""), > + U_BOOT_CMD_MKENT(dev, 4, 0, do_mmc_dev, "", ""), > U_BOOT_CMD_MKENT(list, 1, 1, do_mmc_list, "", ""), > #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING) > U_BOOT_CMD_MKENT(hwpartition, 28, 0, do_mmc_hwpartition, "", ""), > @@ -1042,9 +1072,12 @@ U_BOOT_CMD( > "mmc swrite addr blk#\n" > #endif > "mmc erase blk# cnt\n" > - "mmc rescan\n" > + "mmc rescan [mode]\n" > "mmc part - lists available partition on current mmc device\n" > - "mmc dev [dev] [part] - show or set current mmc device [partition]\n" > + "mmc dev [dev] [part] [mode] - show or set current mmc device [partition] and set mode\n" > + " - the required speed mode is passed as the index from the following list\n" > + " [MMC_LEGACY, MMC_HS, SD_HS, MMC_HS_52, MMC_DDR_52, UHS_SDR12, UHS_SDR25,\n" > + " UHS_SDR50, UHS_DDR50, UHS_SDR104, MMC_HS_200, MMC_HS_400, MMC_HS_400_ES]\n" > "mmc list - lists available devices\n" > "mmc wp - power on write protect boot partitions\n" > #if CONFIG_IS_ENABLED(MMC_HW_PARTITIONING) > diff --git a/doc/usage/mmc.rst b/doc/usage/mmc.rst > index f20efe3d7063..d15b151884fd 100644 > --- a/doc/usage/mmc.rst > +++ b/doc/usage/mmc.rst > @@ -12,9 +12,9 @@ Synopsis > mmc read addr blk# cnt > mmc write addr blk# cnt > mmc erase blk# cnt > - mmc rescan > + mmc rescan [mode] > mmc part > - mmc dev [dev] [part] > + mmc dev [dev] [part] [mode] > mmc list > mmc wp > mmc bootbus > @@ -49,6 +49,27 @@ The 'mmc erase' command erases *cnt* blocks on the MMC device starting at block > > The 'mmc rescan' command scans the available MMC device. > > + mode > + speed mode to set. > + CONFIG_MMC_SPEED_MODE_SET should be enabled. The required speed mode is > + passed as the index from the following list. > + > + 0 - MMC_LEGACY > + 1 - MMC_HS > + 2 - SD_HS > + 3 - MMC_HS_52 > + 4 - MMC_DDR_52 > + 5 - UHS_SDR12 > + 6 - UHS_SDR25 > + 7 - UHS_SDR50 > + 8 - UHS_DDR50 > + 9 - UHS_SDR104 > + 10 - MMC_HS_200 > + 11 - MMC_HS_400 > + 12 - MMC_HS_400_ES > + > + A speed mode can be set only if it has already been enabled in the device tree > + > The 'mmc part' command displays the list available partition on current mmc device. > > The 'mmc dev' command shows or set current mmc device. > @@ -58,6 +79,27 @@ The 'mmc dev' command shows or set current mmc device. > part > partition number to change > > + mode > + speed mode to set. > + CONFIG_MMC_SPEED_MODE_SET should be enabled. The required speed mode is > + passed as the index from the following list. > + > + 0 - MMC_LEGACY > + 1 - MMC_HS > + 2 - SD_HS > + 3 - MMC_HS_52 > + 4 - MMC_DDR_52 > + 5 - UHS_SDR12 > + 6 - UHS_SDR25 > + 7 - UHS_SDR50 > + 8 - UHS_DDR50 > + 9 - UHS_SDR104 > + 10 - MMC_HS_200 > + 11 - MMC_HS_400 > + 12 - MMC_HS_400_ES > + > + A speed mode can be set only if it has already been enabled in the device tree > + > The 'mmc list' command displays the list available devices. > > The 'mmc wp' command enables "power on write protect" function for boot partitions. > @@ -194,6 +236,9 @@ The current device can be shown or set via 'mmc dev' command: > => mmc dev 2 0 > switch to partitions #0, OK > mmc2 is current device > + => mmc dev 0 1 4 > + switch to partitions #1, OK > + mmc0(part 1) is current device > > The list of available devices can be shown via 'mmc list' command: > :: > diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c > index 0e13238c7e7a..3ee92d03ca23 100644 > --- a/drivers/mmc/mmc-uclass.c > +++ b/drivers/mmc/mmc-uclass.c > @@ -342,6 +342,9 @@ void mmc_do_preinit(void) > > if (!m) > continue; > + > + m->user_speed_mode = MMC_MODES_END; /* Initialising user set speed mode */ > + > if (m->preinit) > mmc_start_init(m); > } > @@ -414,7 +417,7 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg) > /* setup initial part type */ > bdesc->part_type = cfg->part_type; > mmc->dev = dev; > - > + mmc->user_speed_mode = MMC_MODES_END; > return 0; > } > > diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c > index 8078a89f18cb..bd348974ae7d 100644 > --- a/drivers/mmc/mmc.c > +++ b/drivers/mmc/mmc.c > @@ -2862,7 +2862,25 @@ int mmc_start_init(struct mmc *mmc) > * timings. > */ > mmc->host_caps = mmc->cfg->host_caps | MMC_CAP(MMC_LEGACY) | > - MMC_CAP(MMC_LEGACY) | MMC_MODE_1BIT; > + MMC_MODE_1BIT; > + > + if (IS_ENABLED(CONFIG_MMC_SPEED_MODE_SET)) { > + if (mmc->user_speed_mode != MMC_MODES_END) { > + int i; > + /* set host caps */ > + if (mmc->host_caps & MMC_CAP(mmc->user_speed_mode)) { > + /* Remove all existing speed capabilities */ > + for (i = MMC_LEGACY; i < MMC_MODES_END; i++) > + mmc->host_caps &= ~MMC_CAP(i); > + mmc->host_caps |= (MMC_CAP(mmc->user_speed_mode) > + | MMC_CAP(MMC_LEGACY) | > + MMC_MODE_1BIT); > + } else { > + pr_err("bus_mode requested is not supported\n"); > + return -EINVAL; > + } > + } > + } > #if CONFIG_IS_ENABLED(DM_MMC) > mmc_deferred_probe(mmc); > #endif > @@ -3060,6 +3078,8 @@ int mmc_init_device(int num) > } > > m = mmc_get_mmc_dev(dev); > + m->user_speed_mode = MMC_MODES_END; /* Initialising user set speed mode */ > + > if (!m) > return 0; > if (m->preinit) > diff --git a/include/mmc.h b/include/mmc.h > index 0bf19de20e52..d24cebbe4781 100644 > --- a/include/mmc.h > +++ b/include/mmc.h > @@ -726,6 +726,8 @@ struct mmc { > */ > u32 quirks; > u8 hs400_tuning; > + > + enum bus_mode user_speed_mode; /* intput speed mode from user */ > }; > > #if CONFIG_IS_ENABLED(DM_MMC) >