blob: 813c28494c377e49146965997afcc685c535f3e8 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +09002/*
Masahiro Yamada4e3d8402016-07-19 21:56:13 +09003 * Copyright (C) 2016 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +09005 */
6
7#include <common.h>
8#include <clk.h>
9#include <fdtdec.h>
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090010#include <mmc.h>
Simon Glass9d922452017-05-17 17:18:03 -060011#include <dm.h>
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090012#include <linux/compat.h>
Masahiro Yamadab27af392017-08-26 00:50:17 +090013#include <linux/dma-direction.h>
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090014#include <linux/io.h>
Masahiro Yamada4f805012016-03-24 22:32:42 +090015#include <linux/sizes.h>
Marek Vasut9f130212017-09-15 21:10:54 +020016#include <power/regulator.h>
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090017#include <asm/unaligned.h>
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090018
Marek Vasutcb0b6b02018-04-13 23:51:33 +020019#include "tmio-common.h"
Masahiro Yamada4eb00842016-08-25 14:52:36 +090020
21static const struct dm_mmc_ops uniphier_sd_ops = {
Marek Vasutcb0b6b02018-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 Yamada4eb00842016-08-25 14:52:36 +090025};
26
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090027static const struct udevice_id uniphier_sd_match[] = {
Masahiro Yamadac3ab1e12018-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 Yamadaa111bfb2016-02-18 19:52:48 +090031 { /* sentinel */ }
32};
33
Marek Vasutc769e602018-04-08 17:45:23 +020034static int uniphier_sd_probe(struct udevice *dev)
35{
Masahiro Yamada30b5d9a2018-04-20 18:14:24 +090036 struct tmio_sd_priv *priv = dev_get_priv(dev);
Masahiro Yamadafc2d0302018-04-20 18:14:25 +090037#ifndef CONFIG_SPL_BUILD
Masahiro Yamada30b5d9a2018-04-20 18:14:24 +090038 struct clk clk;
39 int ret;
40
41 ret = clk_get_by_index(dev, 0, &clk);
42 if (ret < 0) {
43 dev_err(dev, "failed to get host clock\n");
44 return ret;
45 }
46
47 /* set to max rate */
48 priv->mclk = clk_set_rate(&clk, ULONG_MAX);
49 if (IS_ERR_VALUE(priv->mclk)) {
50 dev_err(dev, "failed to set rate for host clock\n");
51 clk_free(&clk);
52 return priv->mclk;
53 }
54
55 ret = clk_enable(&clk);
56 clk_free(&clk);
57 if (ret) {
58 dev_err(dev, "failed to enable host clock\n");
59 return ret;
60 }
Masahiro Yamadafc2d0302018-04-20 18:14:25 +090061#else
62 priv->mclk = 100000000;
63#endif
Masahiro Yamada30b5d9a2018-04-20 18:14:24 +090064
Marek Vasutcb0b6b02018-04-13 23:51:33 +020065 return tmio_sd_probe(dev, 0);
Marek Vasutc769e602018-04-08 17:45:23 +020066}
67
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090068U_BOOT_DRIVER(uniphier_mmc) = {
69 .name = "uniphier-mmc",
70 .id = UCLASS_MMC,
71 .of_match = uniphier_sd_match,
Marek Vasutcb0b6b02018-04-13 23:51:33 +020072 .bind = tmio_sd_bind,
Marek Vasutc769e602018-04-08 17:45:23 +020073 .probe = uniphier_sd_probe,
Marek Vasutcb0b6b02018-04-13 23:51:33 +020074 .priv_auto_alloc_size = sizeof(struct tmio_sd_priv),
75 .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat),
Masahiro Yamada39374042016-08-25 14:52:35 +090076 .ops = &uniphier_sd_ops,
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090077};