1 // SPDX-License-Identifier: GPL-2.0+
3 * Support of SDHCI for Microchip PIC32 SoC.
5 * Copyright (C) 2015 Microchip Technology Inc.
6 * Andrei Pistirica <andrei.pistirica@microchip.com>
12 #include <linux/errno.h>
13 #include <mach/pic32.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 static int pic32_sdhci_get_cd(struct sdhci_host *host)
19 /* PIC32 SDHCI CD errata:
20 * - set CD_TEST and clear CD_TEST_INS bit
22 sdhci_writeb(host, SDHCI_CTRL_CD_TEST, SDHCI_HOST_CONTROL);
27 static const struct sdhci_ops pic32_sdhci_ops = {
28 .get_cd = pic32_sdhci_get_cd,
31 static int pic32_sdhci_probe(struct udevice *dev)
33 struct sdhci_host *host = dev_get_priv(dev);
34 const void *fdt = gd->fdt_blob;
40 addr = fdtdec_get_addr_size(fdt, dev_of_offset(dev), "reg", &size);
41 if (addr == FDT_ADDR_T_NONE)
44 host->ioaddr = ioremap(addr, size);
45 host->name = dev->name;
46 host->quirks = SDHCI_QUIRK_NO_HISPD_BIT;
47 host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
49 host->ops = &pic32_sdhci_ops;
51 ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev),
52 "clock-freq-min-max", f_min_max, 2);
54 printf("sdhci: clock-freq-min-max not found\n");
58 host->max_clk = f_min_max[1];
60 ret = add_sdhci(host, 0, f_min_max[0]);
68 static const struct udevice_id pic32_sdhci_ids[] = {
69 { .compatible = "microchip,pic32mzda-sdhci" },
73 U_BOOT_DRIVER(pic32_sdhci_drv) = {
74 .name = "pic32_sdhci",
76 .of_match = pic32_sdhci_ids,
77 .probe = pic32_sdhci_probe,
78 .priv_auto_alloc_size = sizeof(struct sdhci_host),