Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Felipe Balbi | b756760 | 2017-02-20 14:24:14 +0300 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017 Intel Corporation |
Felipe Balbi | b756760 | 2017-02-20 14:24:14 +0300 | [diff] [blame] | 4 | */ |
| 5 | #include <common.h> |
| 6 | #include <dm.h> |
| 7 | #include <dm/device.h> |
| 8 | #include <linux/io.h> |
| 9 | #include <linux/sizes.h> |
| 10 | #include <malloc.h> |
| 11 | #include <mmc.h> |
| 12 | #include <sdhci.h> |
| 13 | |
| 14 | #define SDHCI_TANGIER_FMAX 200000000 |
| 15 | #define SDHCI_TANGIER_FMIN 400000 |
| 16 | |
| 17 | struct sdhci_tangier_plat { |
| 18 | struct mmc_config cfg; |
| 19 | struct mmc mmc; |
| 20 | void __iomem *ioaddr; |
| 21 | }; |
| 22 | |
| 23 | static int sdhci_tangier_bind(struct udevice *dev) |
| 24 | { |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 25 | struct sdhci_tangier_plat *plat = dev_get_plat(dev); |
Felipe Balbi | b756760 | 2017-02-20 14:24:14 +0300 | [diff] [blame] | 26 | |
| 27 | return sdhci_bind(dev, &plat->mmc, &plat->cfg); |
| 28 | } |
| 29 | |
| 30 | static int sdhci_tangier_probe(struct udevice *dev) |
| 31 | { |
| 32 | struct mmc_uclass_priv *upriv = dev_get_uclass_priv(dev); |
Simon Glass | fa20e93 | 2020-12-03 16:55:20 -0700 | [diff] [blame] | 33 | struct sdhci_tangier_plat *plat = dev_get_plat(dev); |
Felipe Balbi | b756760 | 2017-02-20 14:24:14 +0300 | [diff] [blame] | 34 | struct sdhci_host *host = dev_get_priv(dev); |
| 35 | fdt_addr_t base; |
| 36 | int ret; |
| 37 | |
Masahiro Yamada | a89b4de | 2020-07-17 14:36:48 +0900 | [diff] [blame] | 38 | base = dev_read_addr(dev); |
Felipe Balbi | b756760 | 2017-02-20 14:24:14 +0300 | [diff] [blame] | 39 | if (base == FDT_ADDR_T_NONE) |
| 40 | return -EINVAL; |
| 41 | |
| 42 | plat->ioaddr = devm_ioremap(dev, base, SZ_1K); |
| 43 | if (!plat->ioaddr) |
| 44 | return -ENOMEM; |
| 45 | |
| 46 | host->name = dev->name; |
| 47 | host->ioaddr = plat->ioaddr; |
| 48 | host->quirks = SDHCI_QUIRK_NO_HISPD_BIT | SDHCI_QUIRK_BROKEN_VOLTAGE | |
| 49 | SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD; |
| 50 | |
| 51 | /* MMC_VDD_32_33 | MMC_VDD_33_34 | MMC_VDD_165_195 */ |
| 52 | host->voltages = MMC_VDD_165_195; |
| 53 | |
Peng Fan | b22bdd9 | 2019-08-06 02:48:04 +0000 | [diff] [blame] | 54 | host->mmc = &plat->mmc; |
| 55 | host->mmc->dev = dev; |
Felipe Balbi | b756760 | 2017-02-20 14:24:14 +0300 | [diff] [blame] | 56 | ret = sdhci_setup_cfg(&plat->cfg, host, SDHCI_TANGIER_FMAX, |
| 57 | SDHCI_TANGIER_FMIN); |
| 58 | if (ret) |
| 59 | return ret; |
| 60 | |
| 61 | upriv->mmc = &plat->mmc; |
Felipe Balbi | b756760 | 2017-02-20 14:24:14 +0300 | [diff] [blame] | 62 | host->mmc->priv = host; |
| 63 | |
| 64 | return sdhci_probe(dev); |
| 65 | } |
| 66 | |
| 67 | static const struct udevice_id sdhci_tangier_match[] = { |
| 68 | { .compatible = "intel,sdhci-tangier" }, |
| 69 | { /* sentinel */ } |
| 70 | }; |
| 71 | |
| 72 | U_BOOT_DRIVER(sdhci_tangier) = { |
| 73 | .name = "sdhci-tangier", |
| 74 | .id = UCLASS_MMC, |
| 75 | .of_match = sdhci_tangier_match, |
| 76 | .bind = sdhci_tangier_bind, |
| 77 | .probe = sdhci_tangier_probe, |
| 78 | .ops = &sdhci_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 79 | .priv_auto = sizeof(struct sdhci_host), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 80 | .plat_auto = sizeof(struct sdhci_tangier_plat), |
Felipe Balbi | b756760 | 2017-02-20 14:24:14 +0300 | [diff] [blame] | 81 | }; |