Eddie James | c8a6581 | 2019-08-27 09:48:03 -0500 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2019 IBM Corp. |
| 4 | * Eddie James <eajames@linux.ibm.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <clk.h> |
| 9 | #include <dm.h> |
| 10 | #include <malloc.h> |
| 11 | #include <sdhci.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 12 | #include <linux/err.h> |
Eddie James | c8a6581 | 2019-08-27 09:48:03 -0500 | [diff] [blame] | 13 | |
| 14 | struct aspeed_sdhci_plat { |
| 15 | struct mmc_config cfg; |
| 16 | struct mmc mmc; |
| 17 | }; |
| 18 | |
| 19 | static int aspeed_sdhci_probe(struct udevice *dev) |
| 20 | { |
| 21 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 22 | struct aspeed_sdhci_plat *plat = dev_get_plat(dev); |
Eddie James | c8a6581 | 2019-08-27 09:48:03 -0500 | [diff] [blame] | 23 | struct sdhci_host *host = dev_get_priv(dev); |
| 24 | u32 max_clk; |
| 25 | struct clk clk; |
| 26 | int ret; |
| 27 | |
| 28 | ret = clk_get_by_index(dev, 0, &clk); |
| 29 | if (ret) |
| 30 | return ret; |
| 31 | |
| 32 | ret = clk_enable(&clk); |
| 33 | if (ret) |
| 34 | goto free; |
| 35 | |
| 36 | host->name = dev->name; |
Masahiro Yamada | 1096ae1 | 2020-07-17 14:36:46 +0900 | [diff] [blame] | 37 | host->ioaddr = dev_read_addr_ptr(dev); |
Eddie James | c8a6581 | 2019-08-27 09:48:03 -0500 | [diff] [blame] | 38 | |
| 39 | max_clk = clk_get_rate(&clk); |
| 40 | if (IS_ERR_VALUE(max_clk)) { |
| 41 | ret = max_clk; |
| 42 | goto err; |
| 43 | } |
| 44 | |
| 45 | host->max_clk = max_clk; |
| 46 | host->mmc = &plat->mmc; |
| 47 | host->mmc->dev = dev; |
| 48 | host->mmc->priv = host; |
| 49 | upriv->mmc = host->mmc; |
| 50 | |
| 51 | ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0); |
| 52 | if (ret) |
| 53 | goto err; |
| 54 | |
| 55 | ret = sdhci_probe(dev); |
| 56 | if (ret) |
| 57 | goto err; |
| 58 | |
| 59 | return 0; |
| 60 | |
| 61 | err: |
| 62 | clk_disable(&clk); |
| 63 | free: |
| 64 | clk_free(&clk); |
| 65 | return ret; |
| 66 | } |
| 67 | |
| 68 | static int aspeed_sdhci_bind(struct udevice *dev) |
| 69 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 70 | struct aspeed_sdhci_plat *plat = dev_get_plat(dev); |
Eddie James | c8a6581 | 2019-08-27 09:48:03 -0500 | [diff] [blame] | 71 | |
| 72 | return sdhci_bind(dev, &plat->mmc, &plat->cfg); |
| 73 | } |
| 74 | |
| 75 | static const struct udevice_id aspeed_sdhci_ids[] = { |
| 76 | { .compatible = "aspeed,ast2400-sdhci" }, |
| 77 | { .compatible = "aspeed,ast2500-sdhci" }, |
| 78 | { .compatible = "aspeed,ast2600-sdhci" }, |
| 79 | { } |
| 80 | }; |
| 81 | |
| 82 | U_BOOT_DRIVER(aspeed_sdhci_drv) = { |
| 83 | .name = "aspeed_sdhci", |
| 84 | .id = UCLASS_MMC, |
| 85 | .of_match = aspeed_sdhci_ids, |
| 86 | .ops = &sdhci_ops, |
| 87 | .bind = aspeed_sdhci_bind, |
| 88 | .probe = aspeed_sdhci_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 89 | .priv_auto = sizeof(struct sdhci_host), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 90 | .plat_auto = sizeof(struct aspeed_sdhci_plat), |
Eddie James | c8a6581 | 2019-08-27 09:48:03 -0500 | [diff] [blame] | 91 | }; |