blob: b1752d2f8811bb5b18a16c0b0b281461f57a15c4 [file] [log] [blame]
Eddie Jamesc8a65812019-08-27 09:48:03 -05001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2019 IBM Corp.
4 * Eddie James <eajames@linux.ibm.com>
5 */
6
Eddie Jamesc8a65812019-08-27 09:48:03 -05007#include <clk.h>
8#include <dm.h>
9#include <malloc.h>
10#include <sdhci.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070011#include <linux/err.h>
Joel Stanley818a6b52022-06-23 18:35:34 +093012#include <dm/lists.h>
Eddie Jamesc8a65812019-08-27 09:48:03 -050013
14struct aspeed_sdhci_plat {
15 struct mmc_config cfg;
16 struct mmc mmc;
17};
18
19static int aspeed_sdhci_probe(struct udevice *dev)
20{
21 struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev);
Simon Glassfa20e932020-12-03 16:55:20 -070022 struct aspeed_sdhci_plat *plat = dev_get_plat(dev);
Eddie Jamesc8a65812019-08-27 09:48:03 -050023 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);
Joel Stanley7dab5c12022-06-23 18:35:33 +093029 if (ret) {
30 debug("%s: clock get failed %d\n", __func__, ret);
Eddie Jamesc8a65812019-08-27 09:48:03 -050031 return ret;
Joel Stanley7dab5c12022-06-23 18:35:33 +093032 }
Eddie Jamesc8a65812019-08-27 09:48:03 -050033
34 ret = clk_enable(&clk);
Joel Stanley7dab5c12022-06-23 18:35:33 +093035 if (ret) {
36 debug("%s: clock enable failed %d\n", __func__, ret);
Sean Andersond318eb32023-12-16 14:38:42 -050037 return ret;
Joel Stanley7dab5c12022-06-23 18:35:33 +093038 }
Eddie Jamesc8a65812019-08-27 09:48:03 -050039
40 host->name = dev->name;
Masahiro Yamada1096ae12020-07-17 14:36:46 +090041 host->ioaddr = dev_read_addr_ptr(dev);
Eddie Jamesc8a65812019-08-27 09:48:03 -050042
43 max_clk = clk_get_rate(&clk);
44 if (IS_ERR_VALUE(max_clk)) {
45 ret = max_clk;
Joel Stanley7dab5c12022-06-23 18:35:33 +093046 debug("%s: clock rate get failed %d\n", __func__, ret);
Eddie Jamesc8a65812019-08-27 09:48:03 -050047 goto err;
48 }
49
50 host->max_clk = max_clk;
51 host->mmc = &plat->mmc;
52 host->mmc->dev = dev;
53 host->mmc->priv = host;
54 upriv->mmc = host->mmc;
55
56 ret = sdhci_setup_cfg(&plat->cfg, host, 0, 0);
57 if (ret)
58 goto err;
59
60 ret = sdhci_probe(dev);
61 if (ret)
62 goto err;
63
64 return 0;
65
66err:
67 clk_disable(&clk);
Eddie Jamesc8a65812019-08-27 09:48:03 -050068 return ret;
69}
70
71static int aspeed_sdhci_bind(struct udevice *dev)
72{
Simon Glassfa20e932020-12-03 16:55:20 -070073 struct aspeed_sdhci_plat *plat = dev_get_plat(dev);
Eddie Jamesc8a65812019-08-27 09:48:03 -050074
75 return sdhci_bind(dev, &plat->mmc, &plat->cfg);
76}
77
78static const struct udevice_id aspeed_sdhci_ids[] = {
79 { .compatible = "aspeed,ast2400-sdhci" },
80 { .compatible = "aspeed,ast2500-sdhci" },
81 { .compatible = "aspeed,ast2600-sdhci" },
82 { }
83};
84
85U_BOOT_DRIVER(aspeed_sdhci_drv) = {
86 .name = "aspeed_sdhci",
87 .id = UCLASS_MMC,
88 .of_match = aspeed_sdhci_ids,
89 .ops = &sdhci_ops,
90 .bind = aspeed_sdhci_bind,
91 .probe = aspeed_sdhci_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -070092 .priv_auto = sizeof(struct sdhci_host),
Simon Glass71fa5b42020-12-03 16:55:18 -070093 .plat_auto = sizeof(struct aspeed_sdhci_plat),
Eddie Jamesc8a65812019-08-27 09:48:03 -050094};
Joel Stanley818a6b52022-06-23 18:35:34 +093095
Joel Stanley818a6b52022-06-23 18:35:34 +093096static int aspeed_sdc_probe(struct udevice *parent)
97{
Joel Stanley8d2fb022022-06-23 18:35:35 +093098 struct clk clk;
99 int ret;
100
101 ret = clk_get_by_index(parent, 0, &clk);
102 if (ret) {
103 debug("%s: clock get failed %d\n", __func__, ret);
104 return ret;
105 }
106
107 ret = clk_enable(&clk);
108 if (ret) {
109 debug("%s: clock enable failed %d\n", __func__, ret);
110 return ret;
111 }
112
Joel Stanley818a6b52022-06-23 18:35:34 +0930113 return 0;
114}
115
116static const struct udevice_id aspeed_sdc_ids[] = {
117 { .compatible = "aspeed,ast2400-sd-controller" },
118 { .compatible = "aspeed,ast2500-sd-controller" },
119 { .compatible = "aspeed,ast2600-sd-controller" },
120 { }
121};
122
123U_BOOT_DRIVER(aspeed_sdc_drv) = {
124 .name = "aspeed_sdc",
125 .id = UCLASS_MISC,
126 .of_match = aspeed_sdc_ids,
127 .probe = aspeed_sdc_probe,
128};