xref: /openbmc/u-boot/drivers/mmc/uniphier-sd.c (revision c3ab1e118fc64b5ac49e949dab40507f6fdbbde3)
183d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
2a111bfbfSMasahiro Yamada /*
34e3d8406SMasahiro Yamada  * Copyright (C) 2016 Socionext Inc.
44e3d8406SMasahiro Yamada  *   Author: Masahiro Yamada <yamada.masahiro@socionext.com>
5a111bfbfSMasahiro Yamada  */
6a111bfbfSMasahiro Yamada 
7a111bfbfSMasahiro Yamada #include <common.h>
8a111bfbfSMasahiro Yamada #include <clk.h>
9a111bfbfSMasahiro Yamada #include <fdtdec.h>
10a111bfbfSMasahiro Yamada #include <mmc.h>
119d922450SSimon Glass #include <dm.h>
12a111bfbfSMasahiro Yamada #include <linux/compat.h>
13b27af399SMasahiro Yamada #include <linux/dma-direction.h>
14a111bfbfSMasahiro Yamada #include <linux/io.h>
154f80501bSMasahiro Yamada #include <linux/sizes.h>
169f13021fSMarek Vasut #include <power/regulator.h>
17a111bfbfSMasahiro Yamada #include <asm/unaligned.h>
18a111bfbfSMasahiro Yamada 
19cb0b6b03SMarek Vasut #include "tmio-common.h"
204eb00846SMasahiro Yamada 
214eb00846SMasahiro Yamada static const struct dm_mmc_ops uniphier_sd_ops = {
22cb0b6b03SMarek Vasut 	.send_cmd = tmio_sd_send_cmd,
23cb0b6b03SMarek Vasut 	.set_ios = tmio_sd_set_ios,
24cb0b6b03SMarek Vasut 	.get_cd = tmio_sd_get_cd,
254eb00846SMasahiro Yamada };
264eb00846SMasahiro Yamada 
27a111bfbfSMasahiro Yamada static const struct udevice_id uniphier_sd_match[] = {
28*c3ab1e11SMasahiro Yamada 	{ .compatible = "socionext,uniphier-sd-v2.91" },
29*c3ab1e11SMasahiro Yamada 	{ .compatible = "socionext,uniphier-sd-v3.1" },
30*c3ab1e11SMasahiro Yamada 	{ .compatible = "socionext,uniphier-sd-v3.1.1" },
31a111bfbfSMasahiro Yamada 	{ /* sentinel */ }
32a111bfbfSMasahiro Yamada };
33a111bfbfSMasahiro Yamada 
34c769e609SMarek Vasut static int uniphier_sd_probe(struct udevice *dev)
35c769e609SMarek Vasut {
3630b5d9aaSMasahiro Yamada 	struct tmio_sd_priv *priv = dev_get_priv(dev);
37fc2d0302SMasahiro Yamada #ifndef CONFIG_SPL_BUILD
3830b5d9aaSMasahiro Yamada 	struct clk clk;
3930b5d9aaSMasahiro Yamada 	int ret;
4030b5d9aaSMasahiro Yamada 
4130b5d9aaSMasahiro Yamada 	ret = clk_get_by_index(dev, 0, &clk);
4230b5d9aaSMasahiro Yamada 	if (ret < 0) {
4330b5d9aaSMasahiro Yamada 		dev_err(dev, "failed to get host clock\n");
4430b5d9aaSMasahiro Yamada 		return ret;
4530b5d9aaSMasahiro Yamada 	}
4630b5d9aaSMasahiro Yamada 
4730b5d9aaSMasahiro Yamada 	/* set to max rate */
4830b5d9aaSMasahiro Yamada 	priv->mclk = clk_set_rate(&clk, ULONG_MAX);
4930b5d9aaSMasahiro Yamada 	if (IS_ERR_VALUE(priv->mclk)) {
5030b5d9aaSMasahiro Yamada 		dev_err(dev, "failed to set rate for host clock\n");
5130b5d9aaSMasahiro Yamada 		clk_free(&clk);
5230b5d9aaSMasahiro Yamada 		return priv->mclk;
5330b5d9aaSMasahiro Yamada 	}
5430b5d9aaSMasahiro Yamada 
5530b5d9aaSMasahiro Yamada 	ret = clk_enable(&clk);
5630b5d9aaSMasahiro Yamada 	clk_free(&clk);
5730b5d9aaSMasahiro Yamada 	if (ret) {
5830b5d9aaSMasahiro Yamada 		dev_err(dev, "failed to enable host clock\n");
5930b5d9aaSMasahiro Yamada 		return ret;
6030b5d9aaSMasahiro Yamada 	}
61fc2d0302SMasahiro Yamada #else
62fc2d0302SMasahiro Yamada 	priv->mclk = 100000000;
63fc2d0302SMasahiro Yamada #endif
6430b5d9aaSMasahiro Yamada 
65cb0b6b03SMarek Vasut 	return tmio_sd_probe(dev, 0);
66c769e609SMarek Vasut }
67c769e609SMarek Vasut 
68a111bfbfSMasahiro Yamada U_BOOT_DRIVER(uniphier_mmc) = {
69a111bfbfSMasahiro Yamada 	.name = "uniphier-mmc",
70a111bfbfSMasahiro Yamada 	.id = UCLASS_MMC,
71a111bfbfSMasahiro Yamada 	.of_match = uniphier_sd_match,
72cb0b6b03SMarek Vasut 	.bind = tmio_sd_bind,
73c769e609SMarek Vasut 	.probe = uniphier_sd_probe,
74cb0b6b03SMarek Vasut 	.priv_auto_alloc_size = sizeof(struct tmio_sd_priv),
75cb0b6b03SMarek Vasut 	.platdata_auto_alloc_size = sizeof(struct tmio_sd_plat),
763937404fSMasahiro Yamada 	.ops = &uniphier_sd_ops,
77a111bfbfSMasahiro Yamada };
78