Jaehoon Chung | 48ad827 | 2021-02-16 10:16:52 +0900 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2021 SAMSUNG Electronics |
| 4 | * Jaehoon Chung <jh80.chung@samsung.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <mmc.h> |
| 10 | #include <pwrseq.h> |
| 11 | #include <asm/gpio.h> |
| 12 | #include <linux/delay.h> |
| 13 | |
| 14 | int mmc_pwrseq_get_power(struct udevice *dev, struct mmc_config *cfg) |
| 15 | { |
| 16 | /* Enable power if needed */ |
| 17 | return uclass_get_device_by_phandle(UCLASS_PWRSEQ, dev, "mmc-pwrseq", |
| 18 | &cfg->pwr_dev); |
| 19 | } |
| 20 | |
| 21 | static int mmc_pwrseq_set_power(struct udevice *dev, bool enable) |
| 22 | { |
| 23 | struct gpio_desc reset; |
| 24 | int ret; |
| 25 | |
| 26 | ret = gpio_request_by_name(dev, "reset-gpios", 0, &reset, GPIOD_IS_OUT); |
| 27 | if (ret) |
| 28 | return ret; |
| 29 | dm_gpio_set_value(&reset, 1); |
| 30 | udelay(1); |
| 31 | dm_gpio_set_value(&reset, 0); |
| 32 | udelay(200); |
| 33 | |
| 34 | return 0; |
| 35 | } |
| 36 | |
| 37 | static const struct pwrseq_ops mmc_pwrseq_ops = { |
| 38 | .set_power = mmc_pwrseq_set_power, |
| 39 | }; |
| 40 | |
| 41 | static const struct udevice_id mmc_pwrseq_ids[] = { |
| 42 | { .compatible = "mmc-pwrseq-emmc" }, |
| 43 | { } |
| 44 | }; |
| 45 | |
| 46 | U_BOOT_DRIVER(mmc_pwrseq_drv) = { |
| 47 | .name = "mmc_pwrseq_emmc", |
| 48 | .id = UCLASS_PWRSEQ, |
| 49 | .of_match = mmc_pwrseq_ids, |
| 50 | .ops = &mmc_pwrseq_ops, |
| 51 | }; |