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=-16.9 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,MISSING_HEADERS, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 2AC77C4338F for ; Fri, 13 Aug 2021 17:37:24 +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 68646610CC for ; Fri, 13 Aug 2021 17:37:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 68646610CC Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=ti.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 A0B3082D91; Fri, 13 Aug 2021 19:37:21 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.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=ti.com header.i=@ti.com header.b="nj+yRWdg"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 945A682DD8; Fri, 13 Aug 2021 19:37:19 +0200 (CEST) Received: from fllv0016.ext.ti.com (fllv0016.ext.ti.com [198.47.19.142]) (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 75818829C6 for ; Fri, 13 Aug 2021 19:37:15 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=quarantine dis=none) header.from=ti.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=a-govindraju@ti.com Received: from fllv0035.itg.ti.com ([10.64.41.0]) by fllv0016.ext.ti.com (8.15.2/8.15.2) with ESMTP id 17DHb7Ne104183; Fri, 13 Aug 2021 12:37:07 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1628876227; bh=Mw5+0tTBeS2Rb8yD/ODRYixCxH158bZsvP+5ArlyJfU=; h=Subject:CC:References:From:Date:In-Reply-To; b=nj+yRWdgPYJjY+o9fcWm1J6zcr60/LJR5lDnhjk5IKn0TMphwEjujSqPpXlpC7ZP7 5R96z7uPBAK/AN4z4BpjaJMDI5fGphhsCB2h0lTuqemP1wIVn06zla9OpF/yNr8Rei Cb9YvwYnL2LNiY9B0gV8VHaG7fEd3ulTPt9N+9s8= Received: from DLEE109.ent.ti.com (dlee109.ent.ti.com [157.170.170.41]) by fllv0035.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 17DHb7to093411 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Fri, 13 Aug 2021 12:37:07 -0500 Received: from DLEE112.ent.ti.com (157.170.170.23) by DLEE109.ent.ti.com (157.170.170.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Fri, 13 Aug 2021 12:37:06 -0500 Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE112.ent.ti.com (157.170.170.23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2 via Frontend Transport; Fri, 13 Aug 2021 12:37:06 -0500 Received: from [10.250.232.51] (ileax41-snat.itg.ti.com [10.172.224.153]) by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 17DHb0qk083289; Fri, 13 Aug 2021 12:37:00 -0500 Subject: Re: [PATCH v3] mmc: Add support for enumerating MMC card in a given mode using mmc command CC: Lokesh Vutla , Vignesh Raghavendra , Kishon Vijay Abraham I , Peng Fan , Jaehoon Chung , Simon Glass , Heinrich Schuchardt , Bin Meng , Priyanka Jain , =?UTF-8?Q?Fr=c3=a9d=c3=a9ric_Danis?= , Patrick Delaunay , Reuben Dowle , Yangbo Lu , Nicolas Saenz Julienne , Stefan Bosch , Ashok Reddy Soma , =?UTF-8?Q?Pali_Roh=c3=a1r?= , References: <20210804143840.9756-1-a-govindraju@ti.com> From: Aswath Govindraju Message-ID: <444ead89-b4ec-e340-1fc2-eee99daa75b3@ti.com> Date: Fri, 13 Aug 2021 23:06:59 +0530 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: <20210804143840.9756-1-a-govindraju@ti.com> Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 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 all, On 04/08/21 8:08 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 > --- Posted respin(v4) for this patch seperating the documentation changes. Thanks, Aswath > > Changes since v2: > - made init_mmc_device as wrapper function around __init_mmc_device > - rebased on top of latest master > - used dectoul() instead of simple_strtoul() whereever possible > > 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 | 52 +++++++++++++++++++++++++++++++++------- > doc/usage/mmc.rst | 49 +++++++++++++++++++++++++++++++++++-- > drivers/mmc/mmc-uclass.c | 5 +++- > drivers/mmc/mmc.c | 22 ++++++++++++++++- > include/mmc.h | 2 ++ > 6 files changed, 128 insertions(+), 12 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 c67ad7624227..f1e30d0cf64b 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) > { > 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; > > @@ -145,6 +151,11 @@ static struct mmc *init_mmc_device(int dev, bool force_init) > return mmc; > } > > +static struct mmc *init_mmc_device(int dev, bool force_init) > +{ > + return __init_mmc_device(dev, force_init, MMC_MODES_END); > +} > + > static int do_mmcinfo(struct cmd_tbl *cmdtp, int flag, int argc, > char *const argv[]) > { > @@ -482,8 +493,17 @@ 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); > + } else if (argc == 2) { > + speed_mode = (int)dectoul(argv[1], NULL); > + 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; > > @@ -515,11 +535,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); > } else if (argc == 2) { > - dev = dectoul(argv[1], NULL); > + dev = (int)dectoul(argv[1], NULL); > + mmc = init_mmc_device(dev, true); > } else if (argc == 3) { > dev = (int)dectoul(argv[1], NULL); > part = (int)dectoul(argv[2], NULL); > @@ -528,11 +551,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); > + } else if (argc == 4) { > + dev = (int)dectoul(argv[1], NULL); > + part = (int)dectoul(argv[2], NULL); > + if (part > PART_ACCESS_MASK) { > + printf("#part_num shouldn't be larger than %d\n", > + PART_ACCESS_MASK); > + return CMD_RET_FAILURE; > + } > + speed_mode = (int)dectoul(argv[3], NULL); > + 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; > > @@ -983,9 +1016,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 +1075,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..b92e25534021 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; /* input speed mode from user */ > }; > > #if CONFIG_IS_ENABLED(DM_MMC) >