Andrei Pistirica | 102142c | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 1 | /* |
| 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 Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 13 | #include <linux/errno.h> |
Andrei Pistirica | 102142c | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 14 | #include <mach/pic32.h> |
| 15 | |
| 16 | DECLARE_GLOBAL_DATA_PTR; |
| 17 | |
Masahiro Yamada | 2cd44e1 | 2017-01-13 12:13:48 +0900 | [diff] [blame] | 18 | static int pic32_sdhci_get_cd(struct sdhci_host *host) |
Jaehoon Chung | 5e96217 | 2016-12-30 15:30:14 +0900 | [diff] [blame] | 19 | { |
| 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 | |
| 28 | static const struct sdhci_ops pic32_sdhci_ops = { |
Masahiro Yamada | 2cd44e1 | 2017-01-13 12:13:48 +0900 | [diff] [blame] | 29 | .get_cd = pic32_sdhci_get_cd, |
Jaehoon Chung | 5e96217 | 2016-12-30 15:30:14 +0900 | [diff] [blame] | 30 | }; |
| 31 | |
Andrei Pistirica | 102142c | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 32 | static 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 | |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame^] | 41 | addr = fdtdec_get_addr_size(fdt, dev_of_offset(dev), "reg", &size); |
Andrei Pistirica | 102142c | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 42 | if (addr == FDT_ADDR_T_NONE) |
| 43 | return -EINVAL; |
| 44 | |
| 45 | host->ioaddr = ioremap(addr, size); |
Masahiro Yamada | cacd1d2 | 2016-04-22 20:59:31 +0900 | [diff] [blame] | 46 | host->name = dev->name; |
Jaehoon Chung | 6f88a3a | 2016-12-30 15:30:15 +0900 | [diff] [blame] | 47 | host->quirks = SDHCI_QUIRK_NO_HISPD_BIT; |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame^] | 48 | host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
Andrei Pistirica | 102142c | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 49 | "bus-width", 4); |
Jaehoon Chung | 5e96217 | 2016-12-30 15:30:14 +0900 | [diff] [blame] | 50 | host->ops = &pic32_sdhci_ops; |
Andrei Pistirica | 102142c | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 51 | |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame^] | 52 | ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev), |
Andrei Pistirica | 102142c | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 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 | |
Stefan Herbrechtsmeier | 6d0e34b | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 59 | host->max_clk = f_min_max[1]; |
| 60 | |
| 61 | ret = add_sdhci(host, 0, f_min_max[0]); |
Simon Glass | cffe5d8 | 2016-05-01 13:52:34 -0600 | [diff] [blame] | 62 | if (ret) |
| 63 | return ret; |
| 64 | host->mmc->dev = dev; |
| 65 | |
| 66 | return 0; |
Andrei Pistirica | 102142c | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static const struct udevice_id pic32_sdhci_ids[] = { |
| 70 | { .compatible = "microchip,pic32mzda-sdhci" }, |
| 71 | { } |
| 72 | }; |
| 73 | |
| 74 | U_BOOT_DRIVER(pic32_sdhci_drv) = { |
| 75 | .name = "pic32_sdhci", |
| 76 | .id = UCLASS_MMC, |
| 77 | .of_match = pic32_sdhci_ids, |
| 78 | .probe = pic32_sdhci_probe, |
| 79 | .priv_auto_alloc_size = sizeof(struct sdhci_host), |
| 80 | }; |