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 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E130C433EF for ; Sat, 23 Oct 2021 23:32:01 +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 AB23260E9C for ; Sat, 23 Oct 2021 23:32:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AB23260E9C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org 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 2399D83565; Sun, 24 Oct 2021 01:30:55 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org 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=chromium.org header.i=@chromium.org header.b="CXGvmDUr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2CE4083549; Sun, 24 Oct 2021 01:27:59 +0200 (CEST) Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 54A48834D6 for ; Sun, 24 Oct 2021 01:27:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x32a.google.com with SMTP id l16-20020a9d6a90000000b0054e7ab56f27so9257030otq.12 for ; Sat, 23 Oct 2021 16:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Tc5BBRvXvall+qfUFSou3PrKhkvCL2iIFYy92XzCoFE=; b=CXGvmDUrAJ6ZcUxilX2H7V+9ijUp95D+MWQUNNlvs+FJd9l4ZwiGtLPHR5qTZ1vMda nExHOLe2guqWVtwsJNRx2oZbMkw3iXgFG3GMWp0nfQi8o6fLIJbBZlXgG3eF/9ofXVWM 3mE7sSC9Qll62WZB85V7knnCDMyn2ccuNACJ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Tc5BBRvXvall+qfUFSou3PrKhkvCL2iIFYy92XzCoFE=; b=lv5+lDGiAyLwMzQGucsrfKbhjFXTGgoRn8YAdMjlRs/H/ergzuBlaFzj8FH0TczQv0 8pp0NpcfRSY2gU8MDLhkND8zxzIuQ426HtHNGtGLkf0LurKvL1i6hRKkzLxod6WTn1TI UK6bc+20g7Rk5Nx25CH+MF0YlXU3GTiXnxWsIpvPahEuJpworc8lk/WffsD1yRO1kdQZ 73XyWuwHkTn3mD/ETyETG0JyyCXfQBjT8wrtRWaPD51Frp2N0vS2JcFsY4YAzQHZXLMG AAc9yXOLHJBPxgTEZD7DVPQi/0PHfgqzgN4CUCHqmWCpOCGeaOhv6ZaqHthJGAhCu49m Aefg== X-Gm-Message-State: AOAM533F7/Z8rsqfEIAUWpaVX8VfLX2G+LSAZesRkjJJXOqGW5G3xY8b p6lkme/n/JcxhKJvTiCXj8TCy1NjFIvF+Q== X-Google-Smtp-Source: ABdhPJzxKQKbK4sv4b3wp0U2sIC8VWqnEf42yUpKBw28nzRe9mBd+hz3YMqFYHfPB7qx05eshZiH7Q== X-Received: by 2002:a05:6830:25d1:: with SMTP id d17mr3403839otu.197.1635031635760; Sat, 23 Oct 2021 16:27:15 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id l24sm2253885oop.4.2021.10.23.16.27.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 23 Oct 2021 16:27:15 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Michal Simek , Heinrich Schuchardt , Tom Rini , Ilias Apalodimas , Daniel Schwierzeck , Steffen Jaeckel , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Lukas Auer , Dennis Gilmore , Simon Glass , Jaehoon Chung , Peng Fan Subject: [PATCH v2 28/41] bootstd: mmc: Add a bootdev driver Date: Sat, 23 Oct 2021 17:26:22 -0600 Message-Id: <20211023172618.v2.28.Idda0c29539776a431958d22f1ac59dd20eec9697@changeid> X-Mailer: git-send-email 2.33.0.1079.g6e70778dc9-goog In-Reply-To: <20211023232635.9195-1-sjg@chromium.org> References: <20211023232635.9195-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 Add a bootdev driver for MMC. It mostly just calls the bootdev helper function. Add a function to obtain the block device for an MMC controller. Fix up the comment for mmc_get_blk_desc() while we are here. Signed-off-by: Simon Glass --- (no changes since v1) MAINTAINERS | 1 + drivers/mmc/Makefile | 5 ++++ drivers/mmc/mmc-uclass.c | 23 +++++++++++++++ drivers/mmc/mmc_bootdev.c | 62 +++++++++++++++++++++++++++++++++++++++ include/mmc.h | 12 +++++++- 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 drivers/mmc/mmc_bootdev.c diff --git a/MAINTAINERS b/MAINTAINERS index fc05570f11d..8a19d08623f 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -642,6 +642,7 @@ F: boot/bootmeth*.c F: boot/bootstd.c F: cmd/bootdev.c F: cmd/bootflow.c +F: drivers/mmc/mmc_bootdev.c F: include/bootdev.h F: include/bootflow.h F: include/bootmeth.h diff --git a/drivers/mmc/Makefile b/drivers/mmc/Makefile index 7e819d2b3a2..06d67718ddb 100644 --- a/drivers/mmc/Makefile +++ b/drivers/mmc/Makefile @@ -5,6 +5,11 @@ obj-y += mmc.o obj-$(CONFIG_$(SPL_)DM_MMC) += mmc-uclass.o + +ifdef CONFIG_$(SPL_TPL_)DM_MMC +obj-$(CONFIG_$(SPL_TPL_)BOOTSTD) += mmc_bootdev.o +endif + obj-$(CONFIG_$(SPL_)MMC_WRITE) += mmc_write.o obj-$(CONFIG_MMC_PWRSEQ) += mmc-pwrseq.o obj-$(CONFIG_MMC_SDHCI_ADMA_HELPERS) += sdhci-adma.o diff --git a/drivers/mmc/mmc-uclass.c b/drivers/mmc/mmc-uclass.c index b80e838066c..35b8cdbe35f 100644 --- a/drivers/mmc/mmc-uclass.c +++ b/drivers/mmc/mmc-uclass.c @@ -8,6 +8,7 @@ #define LOG_CATEGORY UCLASS_MMC #include +#include #include #include #include @@ -315,6 +316,20 @@ int mmc_get_next_devnum(void) return blk_find_max_devnum(IF_TYPE_MMC); } +int mmc_get_blk(struct udevice *dev, struct udevice **blkp) +{ + struct udevice *blk; + int ret; + + device_find_first_child_by_uclass(dev, UCLASS_BLK, &blk); + ret = device_probe(blk); + if (ret) + return ret; + *blkp = blk; + + return 0; +} + struct blk_desc *mmc_get_blk_desc(struct mmc *mmc) { struct blk_desc *desc; @@ -406,6 +421,10 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg) mmc->cfg = cfg; mmc->priv = dev; + ret = bootdev_setup_for_dev(dev, "mmc_bootdev"); + if (ret) + return log_msg_ret("bootdev", ret); + /* the following chunk was from mmc_register() */ /* Setup dsr related values */ @@ -424,12 +443,16 @@ int mmc_bind(struct udevice *dev, struct mmc *mmc, const struct mmc_config *cfg) int mmc_unbind(struct udevice *dev) { struct udevice *bdev; + int ret; device_find_first_child_by_uclass(dev, UCLASS_BLK, &bdev); if (bdev) { device_remove(bdev, DM_REMOVE_NORMAL); device_unbind(bdev); } + ret = bootdev_unbind_dev(dev); + if (ret) + return log_msg_ret("bootdev", ret); return 0; } diff --git a/drivers/mmc/mmc_bootdev.c b/drivers/mmc/mmc_bootdev.c new file mode 100644 index 00000000000..b4f41fb3a67 --- /dev/null +++ b/drivers/mmc/mmc_bootdev.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Bootdevice for MMC + * + * Copyright 2021 Google LLC + * Written by Simon Glass + */ + +#include +#include +#include +#include + +static int mmc_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, + struct bootflow *bflow) +{ + struct udevice *mmc_dev = dev_get_parent(dev); + struct udevice *blk; + int ret; + + ret = mmc_get_blk(mmc_dev, &blk); + /* + * If there is no media, indicate that no more partitions should be + * checked + */ + if (ret == -EOPNOTSUPP) + ret = -ESHUTDOWN; + if (ret) + return log_msg_ret("blk", ret); + assert(blk); + ret = bootdev_find_in_blk(dev, blk, iter, bflow); + if (ret) + return log_msg_ret("find", ret); + + return 0; +} + +static int mmc_bootdev_bind(struct udevice *dev) +{ + struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); + + ucp->prio = BOOTDEVP_0_INTERNAL_FAST; + + return 0; +} + +struct bootdev_ops mmc_bootdev_ops = { + .get_bootflow = mmc_get_bootflow, +}; + +static const struct udevice_id mmc_bootdev_ids[] = { + { .compatible = "u-boot,bootdev-mmc" }, + { } +}; + +U_BOOT_DRIVER(mmc_bootdev) = { + .name = "mmc_bootdev", + .id = UCLASS_BOOTDEV, + .ops = &mmc_bootdev_ops, + .bind = mmc_bootdev_bind, + .of_match = mmc_bootdev_ids, +}; diff --git a/include/mmc.h b/include/mmc.h index b92e2553402..668a8634a04 100644 --- a/include/mmc.h +++ b/include/mmc.h @@ -961,10 +961,20 @@ int mmc_get_env_dev(void); * mmc_get_blk_desc() - Get the block descriptor for an MMC device * * @mmc: MMC device - * @return block device if found, else NULL + * @return block descriptor if found, else NULL */ struct blk_desc *mmc_get_blk_desc(struct mmc *mmc); +/** + * mmc_get_blk() - Get the block device for an MMC device + * + * @dev: MMC device + * @blkp: Returns pointer to probed block device on sucesss + * + * @return 0 on success, -ve on error + */ +int mmc_get_blk(struct udevice *dev, struct udevice **blkp); + /** * mmc_send_ext_csd() - read the extended CSD register * -- 2.33.0.1079.g6e70778dc9-goog