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