blob: 8cde4308aaede48ce195faaaf5c2914702e76831 [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>
Simon Glass9bc15642020-02-03 07:36:16 -070010#include <malloc.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090011#include <mmc.h>
Simon Glass11c89f32017-05-17 17:18:03 -060012#include <dm.h>
Simon Glass9bc15642020-02-03 07:36:16 -070013#include <dm/device_compat.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090014#include <linux/compat.h>
Masahiro Yamadaef205ea2017-08-26 00:50:17 +090015#include <linux/dma-direction.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090016#include <linux/io.h>
Masahiro Yamadadc158ef2016-03-24 22:32:42 +090017#include <linux/sizes.h>
Marek Vasut10f0c3c2017-09-15 21:10:54 +020018#include <power/regulator.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090019#include <asm/unaligned.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090020
Marek Vasutfd83e762018-04-13 23:51:33 +020021#include "tmio-common.h"
Masahiro Yamadab29afb92016-08-25 14:52:36 +090022
23static const struct dm_mmc_ops uniphier_sd_ops = {
Marek Vasutfd83e762018-04-13 23:51:33 +020024 .send_cmd = tmio_sd_send_cmd,
25 .set_ios = tmio_sd_set_ios,
26 .get_cd = tmio_sd_get_cd,
Masahiro Yamadab29afb92016-08-25 14:52:36 +090027};
28
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090029static const struct udevice_id uniphier_sd_match[] = {
Masahiro Yamada6c7ad4d2018-09-10 12:58:35 +090030 { .compatible = "socionext,uniphier-sd-v2.91" },
31 { .compatible = "socionext,uniphier-sd-v3.1" },
32 { .compatible = "socionext,uniphier-sd-v3.1.1" },
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090033 { /* sentinel */ }
34};
35
Marek Vasutda90a1b2018-06-13 08:02:55 +020036static 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
Marek Vasutabe3e952018-04-08 17:45:23 +020047static int uniphier_sd_probe(struct udevice *dev)
48{
Masahiro Yamada19989d832018-04-20 18:14:24 +090049 struct tmio_sd_priv *priv = dev_get_priv(dev);
Marek Vasutda90a1b2018-06-13 08:02:55 +020050
51 priv->clk_get_rate = uniphier_sd_clk_get_rate;
Marek Vasute9a28222019-01-11 23:45:54 +010052 priv->read_poll_flag = TMIO_SD_DMA_INFO1_END_RD2;
Marek Vasutda90a1b2018-06-13 08:02:55 +020053
Masahiro Yamada28afb862018-04-20 18:14:25 +090054#ifndef CONFIG_SPL_BUILD
Masahiro Yamada19989d832018-04-20 18:14:24 +090055 int ret;
56
Marek Vasutda90a1b2018-06-13 08:02:55 +020057 ret = clk_get_by_index(dev, 0, &priv->clk);
Masahiro Yamada19989d832018-04-20 18:14:24 +090058 if (ret < 0) {
59 dev_err(dev, "failed to get host clock\n");
60 return ret;
61 }
62
63 /* set to max rate */
Marek Vasutda90a1b2018-06-13 08:02:55 +020064 ret = clk_set_rate(&priv->clk, ULONG_MAX);
65 if (ret < 0) {
Masahiro Yamada19989d832018-04-20 18:14:24 +090066 dev_err(dev, "failed to set rate for host clock\n");
Marek Vasutda90a1b2018-06-13 08:02:55 +020067 return ret;
Masahiro Yamada19989d832018-04-20 18:14:24 +090068 }
69
Marek Vasutda90a1b2018-06-13 08:02:55 +020070 ret = clk_enable(&priv->clk);
Masahiro Yamada19989d832018-04-20 18:14:24 +090071 if (ret) {
72 dev_err(dev, "failed to enable host clock\n");
73 return ret;
74 }
Masahiro Yamada28afb862018-04-20 18:14:25 +090075#endif
Masahiro Yamada19989d832018-04-20 18:14:24 +090076
Marek Vasutfd83e762018-04-13 23:51:33 +020077 return tmio_sd_probe(dev, 0);
Marek Vasutabe3e952018-04-08 17:45:23 +020078}
79
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090080U_BOOT_DRIVER(uniphier_mmc) = {
81 .name = "uniphier-mmc",
82 .id = UCLASS_MMC,
83 .of_match = uniphier_sd_match,
Marek Vasutfd83e762018-04-13 23:51:33 +020084 .bind = tmio_sd_bind,
Marek Vasutabe3e952018-04-08 17:45:23 +020085 .probe = uniphier_sd_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -070086 .priv_auto = sizeof(struct tmio_sd_priv),
Simon Glass71fa5b42020-12-03 16:55:18 -070087 .plat_auto = sizeof(struct tmio_sd_plat),
Masahiro Yamadab26daaa2016-08-25 14:52:35 +090088 .ops = &uniphier_sd_ops,
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090089};