Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Andrei Pistirica | be03317 | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Support of SDHCI for Microchip PIC32 SoC. |
| 4 | * |
| 5 | * Copyright (C) 2015 Microchip Technology Inc. |
| 6 | * Andrei Pistirica <andrei.pistirica@microchip.com> |
Andrei Pistirica | be03317 | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 7 | */ |
| 8 | |
Andrei Pistirica | be03317 | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 9 | #include <common.h> |
Simon Glass | 51a3ec3 | 2017-05-17 17:18:07 -0600 | [diff] [blame] | 10 | #include <dm.h> |
Andrei Pistirica | be03317 | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 11 | #include <sdhci.h> |
Masahiro Yamada | 56a931c | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 12 | #include <linux/errno.h> |
Andrei Pistirica | be03317 | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 13 | #include <mach/pic32.h> |
| 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
Masahiro Yamada | 483a01d | 2017-01-13 12:13:48 +0900 | [diff] [blame] | 17 | static int pic32_sdhci_get_cd(struct sdhci_host *host) |
Jaehoon Chung | 9174eb4 | 2016-12-30 15:30:14 +0900 | [diff] [blame] | 18 | { |
| 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 | |
| 27 | static const struct sdhci_ops pic32_sdhci_ops = { |
Masahiro Yamada | 483a01d | 2017-01-13 12:13:48 +0900 | [diff] [blame] | 28 | .get_cd = pic32_sdhci_get_cd, |
Jaehoon Chung | 9174eb4 | 2016-12-30 15:30:14 +0900 | [diff] [blame] | 29 | }; |
| 30 | |
Andrei Pistirica | be03317 | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 31 | static 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 Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 40 | addr = fdtdec_get_addr_size(fdt, dev_of_offset(dev), "reg", &size); |
Andrei Pistirica | be03317 | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 41 | if (addr == FDT_ADDR_T_NONE) |
| 42 | return -EINVAL; |
| 43 | |
| 44 | host->ioaddr = ioremap(addr, size); |
Masahiro Yamada | a440561 | 2016-04-22 20:59:31 +0900 | [diff] [blame] | 45 | host->name = dev->name; |
Jaehoon Chung | 730a595 | 2016-12-30 15:30:15 +0900 | [diff] [blame] | 46 | host->quirks = SDHCI_QUIRK_NO_HISPD_BIT; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 47 | host->bus_width = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev), |
Andrei Pistirica | be03317 | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 48 | "bus-width", 4); |
Jaehoon Chung | 9174eb4 | 2016-12-30 15:30:14 +0900 | [diff] [blame] | 49 | host->ops = &pic32_sdhci_ops; |
Andrei Pistirica | be03317 | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 50 | |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 51 | ret = fdtdec_get_int_array(gd->fdt_blob, dev_of_offset(dev), |
Andrei Pistirica | be03317 | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 52 | "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 Herbrechtsmeier | bc47e0e | 2017-01-17 15:58:48 +0100 | [diff] [blame] | 58 | host->max_clk = f_min_max[1]; |
| 59 | |
| 60 | ret = add_sdhci(host, 0, f_min_max[0]); |
Simon Glass | 77ca42b | 2016-05-01 13:52:34 -0600 | [diff] [blame] | 61 | if (ret) |
| 62 | return ret; |
| 63 | host->mmc->dev = dev; |
| 64 | |
| 65 | return 0; |
Andrei Pistirica | be03317 | 2016-01-28 15:30:18 +0530 | [diff] [blame] | 66 | } |
| 67 | |
| 68 | static const struct udevice_id pic32_sdhci_ids[] = { |
| 69 | { .compatible = "microchip,pic32mzda-sdhci" }, |
| 70 | { } |
| 71 | }; |
| 72 | |
| 73 | U_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 | }; |