blob: 029e0fbc2bb92f08a682fd68593417006640958a [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Andrei Pistirica102142c2016-01-28 15:30:18 +05302/*
3 * Support of SDHCI for Microchip PIC32 SoC.
4 *
5 * Copyright (C) 2015 Microchip Technology Inc.
6 * Andrei Pistirica <andrei.pistirica@microchip.com>
Andrei Pistirica102142c2016-01-28 15:30:18 +05307 */
8
Andrei Pistirica102142c2016-01-28 15:30:18 +05309#include <common.h>
Simon Glass4af0d7e2017-05-17 17:18:07 -060010#include <dm.h>
Andrei Pistirica102142c2016-01-28 15:30:18 +053011#include <sdhci.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090012#include <linux/errno.h>
Andrei Pistirica102142c2016-01-28 15:30:18 +053013#include <mach/pic32.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
Masahiro Yamada2cd44e12017-01-13 12:13:48 +090017static int pic32_sdhci_get_cd(struct sdhci_host *host)
Jaehoon Chung5e962172016-12-30 15:30:14 +090018{
19 /* PIC32 SDHCI CD errata:
20 * - set CD_TEST and clear CD_TEST_INS bit
21 */
22 sdhci_writeb(host, SDHCI_CTRL_CD_TEST, SDHCI_HOST_CONTROL);
23
24 return 0;
25}
26
27static const struct sdhci_ops pic32_sdhci_ops = {
Masahiro Yamada2cd44e12017-01-13 12:13:48 +090028 .get_cd = pic32_sdhci_get_cd,
Jaehoon Chung5e962172016-12-30 15:30:14 +090029};
30
Andrei Pistirica102142c2016-01-28 15:30:18 +053031static int pic32_sdhci_probe(struct udevice *dev)
32{
33 struct sdhci_host *host = dev_get_priv(dev);
34 const void *fdt = gd->fdt_blob;
35 u32 f_min_max[2];
36 fdt_addr_t addr;
37 fdt_size_t size;
38 int ret;
39
Simon Glasse160f7d2017-01-17 16:52:55 -070040 addr = fdtdec_get_addr_size(fdt, dev_of_offset(dev), "reg", &size);
Andrei Pistirica102142c2016-01-28 15:30:18 +053041 if (addr == FDT_ADDR_T_NONE)
42 return -EINVAL;
43
44 host->ioaddr = ioremap(addr, size);
Masahiro Yamadacacd1d22016-04-22 20:59:31 +090045 host->name = dev->name;
Jaehoon Chung6f88a3a2016-12-30 15:30:15 +090046 host->quirks = SDHCI_QUIRK_NO_HISPD_BIT;
Simon Glasse160f7d2017-01-17 16:52:55 -070047 host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
Andrei Pistirica102142c2016-01-28 15:30:18 +053048 "bus-width", 4);
Jaehoon Chung5e962172016-12-30 15:30:14 +090049 host->ops = &pic32_sdhci_ops;
Andrei Pistirica102142c2016-01-28 15:30:18 +053050
Simon Glasse160f7d2017-01-17 16:52:55 -070051 ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev),
Andrei Pistirica102142c2016-01-28 15:30:18 +053052 "clock-freq-min-max", f_min_max, 2);
53 if (ret) {
54 printf("sdhci: clock-freq-min-max not found\n");
55 return ret;
56 }
57
Stefan Herbrechtsmeier6d0e34b2017-01-17 15:58:48 +010058 host->max_clk = f_min_max[1];
59
60 ret = add_sdhci(host, 0, f_min_max[0]);
Simon Glasscffe5d82016-05-01 13:52:34 -060061 if (ret)
62 return ret;
63 host->mmc->dev = dev;
64
65 return 0;
Andrei Pistirica102142c2016-01-28 15:30:18 +053066}
67
68static const struct udevice_id pic32_sdhci_ids[] = {
69 { .compatible = "microchip,pic32mzda-sdhci" },
70 { }
71};
72
73U_BOOT_DRIVER(pic32_sdhci_drv) = {
74 .name = "pic32_sdhci",
75 .id = UCLASS_MMC,
76 .of_match = pic32_sdhci_ids,
77 .probe = pic32_sdhci_probe,
78 .priv_auto_alloc_size = sizeof(struct sdhci_host),
79};