buildman: Update the TODO items
[oweals/u-boot.git] / drivers / mmc / uniphier-sd.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2016 Socionext Inc.
4  *   Author: Masahiro Yamada <yamada.masahiro@socionext.com>
5  */
6
7 #include <common.h>
8 #include <clk.h>
9 #include <fdtdec.h>
10 #include <malloc.h>
11 #include <mmc.h>
12 #include <dm.h>
13 #include <dm/device_compat.h>
14 #include <linux/compat.h>
15 #include <linux/dma-direction.h>
16 #include <linux/io.h>
17 #include <linux/sizes.h>
18 #include <power/regulator.h>
19 #include <asm/unaligned.h>
20
21 #include "tmio-common.h"
22
23 static const struct dm_mmc_ops uniphier_sd_ops = {
24         .send_cmd = tmio_sd_send_cmd,
25         .set_ios = tmio_sd_set_ios,
26         .get_cd = tmio_sd_get_cd,
27 };
28
29 static const struct udevice_id uniphier_sd_match[] = {
30         { .compatible = "socionext,uniphier-sd-v2.91" },
31         { .compatible = "socionext,uniphier-sd-v3.1" },
32         { .compatible = "socionext,uniphier-sd-v3.1.1" },
33         { /* sentinel */ }
34 };
35
36 static ulong uniphier_sd_clk_get_rate(struct tmio_sd_priv *priv)
37 {
38 #if CONFIG_IS_ENABLED(CLK)
39         return clk_get_rate(&priv->clk);
40 #elif CONFIG_SPL_BUILD
41         return 100000000;
42 #else
43         return 0;
44 #endif
45 }
46
47 static int uniphier_sd_probe(struct udevice *dev)
48 {
49         struct tmio_sd_priv *priv = dev_get_priv(dev);
50
51         priv->clk_get_rate = uniphier_sd_clk_get_rate;
52         priv->read_poll_flag = TMIO_SD_DMA_INFO1_END_RD2;
53
54 #ifndef CONFIG_SPL_BUILD
55         int ret;
56
57         ret = clk_get_by_index(dev, 0, &priv->clk);
58         if (ret < 0) {
59                 dev_err(dev, "failed to get host clock\n");
60                 return ret;
61         }
62
63         /* set to max rate */
64         ret = clk_set_rate(&priv->clk, ULONG_MAX);
65         if (ret < 0) {
66                 dev_err(dev, "failed to set rate for host clock\n");
67                 clk_free(&priv->clk);
68                 return ret;
69         }
70
71         ret = clk_enable(&priv->clk);
72         if (ret) {
73                 dev_err(dev, "failed to enable host clock\n");
74                 return ret;
75         }
76 #endif
77
78         return tmio_sd_probe(dev, 0);
79 }
80
81 U_BOOT_DRIVER(uniphier_mmc) = {
82         .name = "uniphier-mmc",
83         .id = UCLASS_MMC,
84         .of_match = uniphier_sd_match,
85         .bind = tmio_sd_bind,
86         .probe = uniphier_sd_probe,
87         .priv_auto_alloc_size = sizeof(struct tmio_sd_priv),
88         .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat),
89         .ops = &uniphier_sd_ops,
90 };