mmc: matsushita-common: Add Renesas RCar quirks
[oweals/u-boot.git] / drivers / mmc / renesas-sdhi.c
1 /*
2  * Copyright (C) 2018 Marek Vasut <marek.vasut@gmail.com>
3  *
4  * SPDX-License-Identifier:     GPL-2.0+
5  */
6
7 #include <common.h>
8 #include <clk.h>
9 #include <fdtdec.h>
10 #include <mmc.h>
11 #include <dm.h>
12 #include <linux/compat.h>
13 #include <linux/dma-direction.h>
14 #include <linux/io.h>
15 #include <linux/sizes.h>
16 #include <power/regulator.h>
17 #include <asm/unaligned.h>
18
19 #include "matsushita-common.h"
20
21 static const struct dm_mmc_ops renesas_sdhi_ops = {
22         .send_cmd = matsu_sd_send_cmd,
23         .set_ios = matsu_sd_set_ios,
24         .get_cd = matsu_sd_get_cd,
25 };
26
27 #define RENESAS_GEN2_QUIRKS     MATSU_SD_CAP_RCAR_GEN2
28 #define RENESAS_GEN3_QUIRKS                             \
29         MATSU_SD_CAP_64BIT | MATSU_SD_CAP_RCAR_GEN3 | MATSU_SD_CAP_RCAR_UHS
30
31 static const struct udevice_id renesas_sdhi_match[] = {
32         { .compatible = "renesas,sdhi-r8a7790", .data = RENESAS_GEN2_QUIRKS },
33         { .compatible = "renesas,sdhi-r8a7791", .data = RENESAS_GEN2_QUIRKS },
34         { .compatible = "renesas,sdhi-r8a7792", .data = RENESAS_GEN2_QUIRKS },
35         { .compatible = "renesas,sdhi-r8a7793", .data = RENESAS_GEN2_QUIRKS },
36         { .compatible = "renesas,sdhi-r8a7794", .data = RENESAS_GEN2_QUIRKS },
37         { .compatible = "renesas,sdhi-r8a7795", .data = RENESAS_GEN3_QUIRKS },
38         { .compatible = "renesas,sdhi-r8a7796", .data = RENESAS_GEN3_QUIRKS },
39         { .compatible = "renesas,sdhi-r8a77965", .data = RENESAS_GEN3_QUIRKS },
40         { .compatible = "renesas,sdhi-r8a77970", .data = RENESAS_GEN3_QUIRKS },
41         { .compatible = "renesas,sdhi-r8a77995", .data = RENESAS_GEN3_QUIRKS },
42         { /* sentinel */ }
43 };
44
45 static int renesas_sdhi_probe(struct udevice *dev)
46 {
47         u32 quirks = dev_get_driver_data(dev);
48         struct fdt_resource reg_res;
49         DECLARE_GLOBAL_DATA_PTR;
50         int ret;
51
52         if (quirks == RENESAS_GEN2_QUIRKS) {
53                 ret = fdt_get_resource(gd->fdt_blob, dev_of_offset(dev),
54                                        "reg", 0, &reg_res);
55                 if (ret < 0) {
56                         dev_err(dev, "\"reg\" resource not found, ret=%i\n",
57                                 ret);
58                         return ret;
59                 }
60
61                 if (fdt_resource_size(&reg_res) == 0x100)
62                         quirks |= MATSU_SD_CAP_16BIT;
63         }
64
65         return matsu_sd_probe(dev, quirks);
66 }
67
68 U_BOOT_DRIVER(renesas_sdhi) = {
69         .name = "renesas-sdhi",
70         .id = UCLASS_MMC,
71         .of_match = renesas_sdhi_match,
72         .bind = matsu_sd_bind,
73         .probe = renesas_sdhi_probe,
74         .priv_auto_alloc_size = sizeof(struct matsu_sd_priv),
75         .platdata_auto_alloc_size = sizeof(struct matsu_sd_plat),
76         .ops = &renesas_sdhi_ops,
77 };