blob: 6539880ab5d7cb885d33c05848c04e8a28f024e1 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +09002/*
Masahiro Yamadafa1f73f2016-07-19 21:56:13 +09003 * Copyright (C) 2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +09005 */
6
7#include <common.h>
8#include <clk.h>
9#include <fdtdec.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090010#include <mmc.h>
Simon Glass11c89f32017-05-17 17:18:03 -060011#include <dm.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090012#include <linux/compat.h>
Masahiro Yamadaef205ea2017-08-26 00:50:17 +090013#include <linux/dma-direction.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090014#include <linux/io.h>
Masahiro Yamadadc158ef2016-03-24 22:32:42 +090015#include <linux/sizes.h>
Marek Vasut10f0c3c2017-09-15 21:10:54 +020016#include <power/regulator.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090017#include <asm/unaligned.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090018
Marek Vasutfd83e762018-04-13 23:51:33 +020019#include "tmio-common.h"
Masahiro Yamadab29afb92016-08-25 14:52:36 +090020
21static const struct dm_mmc_ops uniphier_sd_ops = {
Marek Vasutfd83e762018-04-13 23:51:33 +020022 .send_cmd = tmio_sd_send_cmd,
23 .set_ios = tmio_sd_set_ios,
24 .get_cd = tmio_sd_get_cd,
Masahiro Yamadab29afb92016-08-25 14:52:36 +090025};
26
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090027static const struct udevice_id uniphier_sd_match[] = {
Masahiro Yamada6c7ad4d2018-09-10 12:58:35 +090028 { .compatible = "socionext,uniphier-sd-v2.91" },
29 { .compatible = "socionext,uniphier-sd-v3.1" },
30 { .compatible = "socionext,uniphier-sd-v3.1.1" },
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090031 { /* sentinel */ }
32};
33
Marek Vasutda90a1b2018-06-13 08:02:55 +020034static ulong uniphier_sd_clk_get_rate(struct tmio_sd_priv *priv)
35{
36#if CONFIG_IS_ENABLED(CLK)
37 return clk_get_rate(&priv->clk);
38#elif CONFIG_SPL_BUILD
39 return 100000000;
40#else
41 return 0;
42#endif
43}
44
Marek Vasutabe3e952018-04-08 17:45:23 +020045static int uniphier_sd_probe(struct udevice *dev)
46{
Masahiro Yamada19989d832018-04-20 18:14:24 +090047 struct tmio_sd_priv *priv = dev_get_priv(dev);
Marek Vasutda90a1b2018-06-13 08:02:55 +020048
49 priv->clk_get_rate = uniphier_sd_clk_get_rate;
50
Masahiro Yamada28afb862018-04-20 18:14:25 +090051#ifndef CONFIG_SPL_BUILD
Masahiro Yamada19989d832018-04-20 18:14:24 +090052 int ret;
53
Marek Vasutda90a1b2018-06-13 08:02:55 +020054 ret = clk_get_by_index(dev, 0, &priv->clk);
Masahiro Yamada19989d832018-04-20 18:14:24 +090055 if (ret < 0) {
56 dev_err(dev, "failed to get host clock\n");
57 return ret;
58 }
59
60 /* set to max rate */
Marek Vasutda90a1b2018-06-13 08:02:55 +020061 ret = clk_set_rate(&priv->clk, ULONG_MAX);
62 if (ret < 0) {
Masahiro Yamada19989d832018-04-20 18:14:24 +090063 dev_err(dev, "failed to set rate for host clock\n");
Marek Vasutda90a1b2018-06-13 08:02:55 +020064 clk_free(&priv->clk);
65 return ret;
Masahiro Yamada19989d832018-04-20 18:14:24 +090066 }
67
Marek Vasutda90a1b2018-06-13 08:02:55 +020068 ret = clk_enable(&priv->clk);
Masahiro Yamada19989d832018-04-20 18:14:24 +090069 if (ret) {
70 dev_err(dev, "failed to enable host clock\n");
71 return ret;
72 }
Masahiro Yamada28afb862018-04-20 18:14:25 +090073#endif
Masahiro Yamada19989d832018-04-20 18:14:24 +090074
Marek Vasutfd83e762018-04-13 23:51:33 +020075 return tmio_sd_probe(dev, 0);
Marek Vasutabe3e952018-04-08 17:45:23 +020076}
77
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090078U_BOOT_DRIVER(uniphier_mmc) = {
79 .name = "uniphier-mmc",
80 .id = UCLASS_MMC,
81 .of_match = uniphier_sd_match,
Marek Vasutfd83e762018-04-13 23:51:33 +020082 .bind = tmio_sd_bind,
Marek Vasutabe3e952018-04-08 17:45:23 +020083 .probe = uniphier_sd_probe,
Marek Vasutfd83e762018-04-13 23:51:33 +020084 .priv_auto_alloc_size = sizeof(struct tmio_sd_priv),
85 .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat),
Masahiro Yamadab26daaa2016-08-25 14:52:35 +090086 .ops = &uniphier_sd_ops,
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090087};