xref: /rk3399_rockchip-uboot/drivers/mmc/pic32_sdhci.c (revision cacd1d2f33da2d78e8568f2e48539a4a57de20ae)
1102142c9SAndrei Pistirica /*
2102142c9SAndrei Pistirica  * Support of SDHCI for Microchip PIC32 SoC.
3102142c9SAndrei Pistirica  *
4102142c9SAndrei Pistirica  * Copyright (C) 2015 Microchip Technology Inc.
5102142c9SAndrei Pistirica  * Andrei Pistirica <andrei.pistirica@microchip.com>
6102142c9SAndrei Pistirica  *
7102142c9SAndrei Pistirica  * SPDX-License-Identifier:	GPL-2.0+
8102142c9SAndrei Pistirica  */
9102142c9SAndrei Pistirica 
10102142c9SAndrei Pistirica #include <dm.h>
11102142c9SAndrei Pistirica #include <common.h>
12102142c9SAndrei Pistirica #include <sdhci.h>
13102142c9SAndrei Pistirica #include <asm/errno.h>
14102142c9SAndrei Pistirica #include <mach/pic32.h>
15102142c9SAndrei Pistirica 
16102142c9SAndrei Pistirica DECLARE_GLOBAL_DATA_PTR;
17102142c9SAndrei Pistirica 
18102142c9SAndrei Pistirica static int pic32_sdhci_probe(struct udevice *dev)
19102142c9SAndrei Pistirica {
20102142c9SAndrei Pistirica 	struct sdhci_host *host = dev_get_priv(dev);
21102142c9SAndrei Pistirica 	const void *fdt = gd->fdt_blob;
22102142c9SAndrei Pistirica 	u32 f_min_max[2];
23102142c9SAndrei Pistirica 	fdt_addr_t addr;
24102142c9SAndrei Pistirica 	fdt_size_t size;
25102142c9SAndrei Pistirica 	int ret;
26102142c9SAndrei Pistirica 
27102142c9SAndrei Pistirica 	addr = fdtdec_get_addr_size(fdt, dev->of_offset, "reg", &size);
28102142c9SAndrei Pistirica 	if (addr == FDT_ADDR_T_NONE)
29102142c9SAndrei Pistirica 		return -EINVAL;
30102142c9SAndrei Pistirica 
31102142c9SAndrei Pistirica 	host->ioaddr	= ioremap(addr, size);
32*cacd1d2fSMasahiro Yamada 	host->name	= dev->name;
33102142c9SAndrei Pistirica 	host->quirks	= SDHCI_QUIRK_NO_HISPD_BIT | SDHCI_QUIRK_NO_CD;
34102142c9SAndrei Pistirica 	host->bus_width	= fdtdec_get_int(gd->fdt_blob, dev->of_offset,
35102142c9SAndrei Pistirica 					"bus-width", 4);
36102142c9SAndrei Pistirica 
37102142c9SAndrei Pistirica 	ret = fdtdec_get_int_array(gd->fdt_blob, dev->of_offset,
38102142c9SAndrei Pistirica 				   "clock-freq-min-max", f_min_max, 2);
39102142c9SAndrei Pistirica 	if (ret) {
40102142c9SAndrei Pistirica 		printf("sdhci: clock-freq-min-max not found\n");
41102142c9SAndrei Pistirica 		return ret;
42102142c9SAndrei Pistirica 	}
43102142c9SAndrei Pistirica 
44102142c9SAndrei Pistirica 	return add_sdhci(host, f_min_max[1], f_min_max[0]);
45102142c9SAndrei Pistirica }
46102142c9SAndrei Pistirica 
47102142c9SAndrei Pistirica static const struct udevice_id pic32_sdhci_ids[] = {
48102142c9SAndrei Pistirica 	{ .compatible = "microchip,pic32mzda-sdhci" },
49102142c9SAndrei Pistirica 	{ }
50102142c9SAndrei Pistirica };
51102142c9SAndrei Pistirica 
52102142c9SAndrei Pistirica U_BOOT_DRIVER(pic32_sdhci_drv) = {
53102142c9SAndrei Pistirica 	.name			= "pic32_sdhci",
54102142c9SAndrei Pistirica 	.id			= UCLASS_MMC,
55102142c9SAndrei Pistirica 	.of_match		= pic32_sdhci_ids,
56102142c9SAndrei Pistirica 	.probe			= pic32_sdhci_probe,
57102142c9SAndrei Pistirica 	.priv_auto_alloc_size	= sizeof(struct sdhci_host),
58102142c9SAndrei Pistirica };
59