blob: c06364cfc1205fe42e59e6a55d04f96a42875933 [file] [log] [blame]
Andrei Pistirica102142c2016-01-28 15:30:18 +05301/*
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>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090013#include <linux/errno.h>
Andrei Pistirica102142c2016-01-28 15:30:18 +053014#include <mach/pic32.h>
15
16DECLARE_GLOBAL_DATA_PTR;
17
Masahiro Yamada2cd44e12017-01-13 12:13:48 +090018static int pic32_sdhci_get_cd(struct sdhci_host *host)
Jaehoon Chung5e962172016-12-30 15:30:14 +090019{
20 /* PIC32 SDHCI CD errata:
21 * - set CD_TEST and clear CD_TEST_INS bit
22 */
23 sdhci_writeb(host, SDHCI_CTRL_CD_TEST, SDHCI_HOST_CONTROL);
24
25 return 0;
26}
27
28static const struct sdhci_ops pic32_sdhci_ops = {
Masahiro Yamada2cd44e12017-01-13 12:13:48 +090029 .get_cd = pic32_sdhci_get_cd,
Jaehoon Chung5e962172016-12-30 15:30:14 +090030};
31
Andrei Pistirica102142c2016-01-28 15:30:18 +053032static int pic32_sdhci_probe(struct udevice *dev)
33{
34 struct sdhci_host *host = dev_get_priv(dev);
35 const void *fdt = gd->fdt_blob;
36 u32 f_min_max[2];
37 fdt_addr_t addr;
38 fdt_size_t size;
39 int ret;
40
41 addr = fdtdec_get_addr_size(fdt, dev->of_offset, "reg", &size);
42 if (addr == FDT_ADDR_T_NONE)
43 return -EINVAL;
44
45 host->ioaddr = ioremap(addr, size);
Masahiro Yamadacacd1d22016-04-22 20:59:31 +090046 host->name = dev->name;
Jaehoon Chung6f88a3a2016-12-30 15:30:15 +090047 host->quirks = SDHCI_QUIRK_NO_HISPD_BIT;
Andrei Pistirica102142c2016-01-28 15:30:18 +053048 host->bus_width = fdtdec_get_int(gd->fdt_blob, dev->of_offset,
49 "bus-width", 4);
Jaehoon Chung5e962172016-12-30 15:30:14 +090050 host->ops = &pic32_sdhci_ops;
Andrei Pistirica102142c2016-01-28 15:30:18 +053051
52 ret = fdtdec_get_int_array(gd->fdt_blob, dev->of_offset,
53 "clock-freq-min-max", f_min_max, 2);
54 if (ret) {
55 printf("sdhci: clock-freq-min-max not found\n");
56 return ret;
57 }
58
Simon Glasscffe5d82016-05-01 13:52:34 -060059 ret = add_sdhci(host, f_min_max[1], f_min_max[0]);
60 if (ret)
61 return ret;
62 host->mmc->dev = dev;
63
64 return 0;
Andrei Pistirica102142c2016-01-28 15:30:18 +053065}
66
67static const struct udevice_id pic32_sdhci_ids[] = {
68 { .compatible = "microchip,pic32mzda-sdhci" },
69 { }
70};
71
72U_BOOT_DRIVER(pic32_sdhci_drv) = {
73 .name = "pic32_sdhci",
74 .id = UCLASS_MMC,
75 .of_match = pic32_sdhci_ids,
76 .probe = pic32_sdhci_probe,
77 .priv_auto_alloc_size = sizeof(struct sdhci_host),
78};