Andrei Pistirica | 102142c | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Support of SDHCI for Microchip PIC32 SoC. |
| 3 | * |
| 4 | * Copyright (C) 2015 Microchip Technology Inc. |
| 5 | * Andrei Pistirica <andrei.pistirica@microchip.com> |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0+ |
| 8 | */ |
| 9 | |
| 10 | #include <dm.h> |
| 11 | #include <common.h> |
| 12 | #include <sdhci.h> |
| 13 | #include <asm/errno.h> |
| 14 | #include <mach/pic32.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
| 18 | static int pic32_sdhci_probe(struct udevice *dev) |
| 19 | { |
| 20 | struct sdhci_host *host = dev_get_priv(dev); |
| 21 | const void *fdt = gd->fdt_blob; |
| 22 | u32 f_min_max[2]; |
| 23 | fdt_addr_t addr; |
| 24 | fdt_size_t size; |
| 25 | int ret; |
| 26 | |
| 27 | addr = fdtdec_get_addr_size(fdt, dev->of_offset, "reg", &size); |
| 28 | if (addr == FDT_ADDR_T_NONE) |
| 29 | return -EINVAL; |
| 30 | |
| 31 | host->ioaddr = ioremap(addr, size); |
Masahiro Yamada | cacd1d2 | 2016-04-22 20:59:31 +0900 | [diff] [blame] | 32 | host->name = dev->name; |
Andrei Pistirica | 102142c | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 33 | host->quirks = SDHCI_QUIRK_NO_HISPD_BIT | SDHCI_QUIRK_NO_CD; |
| 34 | host->bus_width = fdtdec_get_int(gd->fdt_blob, dev->of_offset, |
| 35 | "bus-width", 4); |
| 36 | |
| 37 | ret = fdtdec_get_int_array(gd->fdt_blob, dev->of_offset, |
| 38 | "clock-freq-min-max", f_min_max, 2); |
| 39 | if (ret) { |
| 40 | printf("sdhci: clock-freq-min-max not found\n"); |
| 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | return add_sdhci(host, f_min_max[1], f_min_max[0]); |
| 45 | } |
| 46 | |
| 47 | static const struct udevice_id pic32_sdhci_ids[] = { |
| 48 | { .compatible = "microchip,pic32mzda-sdhci" }, |
| 49 | { } |
| 50 | }; |
| 51 | |
| 52 | U_BOOT_DRIVER(pic32_sdhci_drv) = { |
| 53 | .name = "pic32_sdhci", |
| 54 | .id = UCLASS_MMC, |
| 55 | .of_match = pic32_sdhci_ids, |
| 56 | .probe = pic32_sdhci_probe, |
| 57 | .priv_auto_alloc_size = sizeof(struct sdhci_host), |
| 58 | }; |