blob: 5b3650d52eead9124f3a5169288a09a252e97ddd [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
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +09007#include <clk.h>
8#include <fdtdec.h>
Simon Glass9bc15642020-02-03 07:36:16 -07009#include <malloc.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090010#include <mmc.h>
Simon Glass11c89f32017-05-17 17:18:03 -060011#include <dm.h>
Simon Glass9bc15642020-02-03 07:36:16 -070012#include <dm/device_compat.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090013#include <linux/compat.h>
Masahiro Yamadaef205ea2017-08-26 00:50:17 +090014#include <linux/dma-direction.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090015#include <linux/io.h>
Masahiro Yamadadc158ef2016-03-24 22:32:42 +090016#include <linux/sizes.h>
Marek Vasut10f0c3c2017-09-15 21:10:54 +020017#include <power/regulator.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090018#include <asm/unaligned.h>
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090019
Marek Vasutfd83e762018-04-13 23:51:33 +020020#include "tmio-common.h"
Masahiro Yamadab29afb92016-08-25 14:52:36 +090021
22static const struct dm_mmc_ops uniphier_sd_ops = {
Marek Vasutfd83e762018-04-13 23:51:33 +020023 .send_cmd = tmio_sd_send_cmd,
24 .set_ios = tmio_sd_set_ios,
25 .get_cd = tmio_sd_get_cd,
Masahiro Yamadab29afb92016-08-25 14:52:36 +090026};
27
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090028static const struct udevice_id uniphier_sd_match[] = {
Masahiro Yamada6c7ad4d2018-09-10 12:58:35 +090029 { .compatible = "socionext,uniphier-sd-v2.91" },
30 { .compatible = "socionext,uniphier-sd-v3.1" },
31 { .compatible = "socionext,uniphier-sd-v3.1.1" },
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090032 { /* sentinel */ }
33};
34
Marek Vasutda90a1b2018-06-13 08:02:55 +020035static ulong uniphier_sd_clk_get_rate(struct tmio_sd_priv *priv)
36{
37#if CONFIG_IS_ENABLED(CLK)
38 return clk_get_rate(&priv->clk);
39#elif CONFIG_SPL_BUILD
40 return 100000000;
41#else
42 return 0;
43#endif
44}
45
Marek Vasutabe3e952018-04-08 17:45:23 +020046static int uniphier_sd_probe(struct udevice *dev)
47{
Masahiro Yamada19989d832018-04-20 18:14:24 +090048 struct tmio_sd_priv *priv = dev_get_priv(dev);
Marek Vasutda90a1b2018-06-13 08:02:55 +020049
50 priv->clk_get_rate = uniphier_sd_clk_get_rate;
Marek Vasute9a28222019-01-11 23:45:54 +010051 priv->read_poll_flag = TMIO_SD_DMA_INFO1_END_RD2;
Marek Vasutda90a1b2018-06-13 08:02:55 +020052
Masahiro Yamada28afb862018-04-20 18:14:25 +090053#ifndef CONFIG_SPL_BUILD
Masahiro Yamada19989d832018-04-20 18:14:24 +090054 int ret;
55
Marek Vasutda90a1b2018-06-13 08:02:55 +020056 ret = clk_get_by_index(dev, 0, &priv->clk);
Masahiro Yamada19989d832018-04-20 18:14:24 +090057 if (ret < 0) {
58 dev_err(dev, "failed to get host clock\n");
59 return ret;
60 }
61
62 /* set to max rate */
Marek Vasutda90a1b2018-06-13 08:02:55 +020063 ret = clk_set_rate(&priv->clk, ULONG_MAX);
64 if (ret < 0) {
Masahiro Yamada19989d832018-04-20 18:14:24 +090065 dev_err(dev, "failed to set rate for host clock\n");
Marek Vasutda90a1b2018-06-13 08:02:55 +020066 return ret;
Masahiro Yamada19989d832018-04-20 18:14:24 +090067 }
68
Marek Vasutda90a1b2018-06-13 08:02:55 +020069 ret = clk_enable(&priv->clk);
Masahiro Yamada19989d832018-04-20 18:14:24 +090070 if (ret) {
71 dev_err(dev, "failed to enable host clock\n");
72 return ret;
73 }
Masahiro Yamada28afb862018-04-20 18:14:25 +090074#endif
Masahiro Yamada19989d832018-04-20 18:14:24 +090075
Marek Vasutfd83e762018-04-13 23:51:33 +020076 return tmio_sd_probe(dev, 0);
Marek Vasutabe3e952018-04-08 17:45:23 +020077}
78
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090079U_BOOT_DRIVER(uniphier_mmc) = {
80 .name = "uniphier-mmc",
81 .id = UCLASS_MMC,
82 .of_match = uniphier_sd_match,
Marek Vasutfd83e762018-04-13 23:51:33 +020083 .bind = tmio_sd_bind,
Marek Vasutabe3e952018-04-08 17:45:23 +020084 .probe = uniphier_sd_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -070085 .priv_auto = sizeof(struct tmio_sd_priv),
Simon Glass71fa5b42020-12-03 16:55:18 -070086 .plat_auto = sizeof(struct tmio_sd_plat),
Masahiro Yamadab26daaa2016-08-25 14:52:35 +090087 .ops = &uniphier_sd_ops,
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090088};