Simon Glass | b8aa463 | 2022-04-24 23:31:14 -0600 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Bootdevice for MMC |
| 4 | * |
| 5 | * Copyright 2021 Google LLC |
| 6 | * Written by Simon Glass <sjg@chromium.org> |
| 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <bootdev.h> |
| 11 | #include <dm.h> |
| 12 | #include <mmc.h> |
| 13 | |
| 14 | static int mmc_get_bootflow(struct udevice *dev, struct bootflow_iter *iter, |
| 15 | struct bootflow *bflow) |
| 16 | { |
| 17 | struct udevice *mmc_dev = dev_get_parent(dev); |
| 18 | struct udevice *blk; |
| 19 | int ret; |
| 20 | |
| 21 | ret = mmc_get_blk(mmc_dev, &blk); |
| 22 | /* |
| 23 | * If there is no media, indicate that no more partitions should be |
| 24 | * checked |
| 25 | */ |
| 26 | if (ret == -EOPNOTSUPP) |
| 27 | ret = -ESHUTDOWN; |
| 28 | if (ret) |
| 29 | return log_msg_ret("blk", ret); |
| 30 | assert(blk); |
| 31 | ret = bootdev_find_in_blk(dev, blk, iter, bflow); |
| 32 | if (ret) |
| 33 | return log_msg_ret("find", ret); |
| 34 | |
| 35 | return 0; |
| 36 | } |
| 37 | |
| 38 | static int mmc_bootdev_bind(struct udevice *dev) |
| 39 | { |
| 40 | struct bootdev_uc_plat *ucp = dev_get_uclass_plat(dev); |
| 41 | |
| 42 | ucp->prio = BOOTDEVP_0_INTERNAL_FAST; |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | struct bootdev_ops mmc_bootdev_ops = { |
| 48 | .get_bootflow = mmc_get_bootflow, |
| 49 | }; |
| 50 | |
| 51 | static const struct udevice_id mmc_bootdev_ids[] = { |
| 52 | { .compatible = "u-boot,bootdev-mmc" }, |
| 53 | { } |
| 54 | }; |
| 55 | |
| 56 | U_BOOT_DRIVER(mmc_bootdev) = { |
| 57 | .name = "mmc_bootdev", |
| 58 | .id = UCLASS_BOOTDEV, |
| 59 | .ops = &mmc_bootdev_ops, |
| 60 | .bind = mmc_bootdev_bind, |
| 61 | .of_match = mmc_bootdev_ids, |
| 62 | }; |