blob: 61f8da4e413f149b22eb458c5ec6b6799350fb12 [file] [log] [blame]
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +09001/*
Masahiro Yamada4e3d8402016-07-19 21:56:13 +09002 * Copyright (C) 2016 Socionext Inc.
3 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +09004 *
5 * SPDX-License-Identifier: GPL-2.0+
6 */
7
8#include <common.h>
9#include <clk.h>
10#include <fdtdec.h>
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090011#include <mmc.h>
Simon Glass9d922452017-05-17 17:18:03 -060012#include <dm.h>
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090013#include <linux/compat.h>
Masahiro Yamadab27af392017-08-26 00:50:17 +090014#include <linux/dma-direction.h>
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090015#include <linux/io.h>
Masahiro Yamada4f805012016-03-24 22:32:42 +090016#include <linux/sizes.h>
Marek Vasut9f130212017-09-15 21:10:54 +020017#include <power/regulator.h>
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090018#include <asm/unaligned.h>
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090019
Marek Vasutcb0b6b02018-04-13 23:51:33 +020020#include "tmio-common.h"
Masahiro Yamada4eb00842016-08-25 14:52:36 +090021
22static const struct dm_mmc_ops uniphier_sd_ops = {
Marek Vasutcb0b6b02018-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 Yamada4eb00842016-08-25 14:52:36 +090026};
27
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090028static const struct udevice_id uniphier_sd_match[] = {
Marek Vasut4b26d5e2017-07-21 23:24:35 +020029 { .compatible = "socionext,uniphier-sdhc", .data = 0 },
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090030 { /* sentinel */ }
31};
32
Marek Vasutc769e602018-04-08 17:45:23 +020033static int uniphier_sd_probe(struct udevice *dev)
34{
Masahiro Yamada30b5d9a2018-04-20 18:14:24 +090035 struct tmio_sd_priv *priv = dev_get_priv(dev);
Masahiro Yamadafc2d0302018-04-20 18:14:25 +090036#ifndef CONFIG_SPL_BUILD
Masahiro Yamada30b5d9a2018-04-20 18:14:24 +090037 struct clk clk;
38 int ret;
39
40 ret = clk_get_by_index(dev, 0, &clk);
41 if (ret < 0) {
42 dev_err(dev, "failed to get host clock\n");
43 return ret;
44 }
45
46 /* set to max rate */
47 priv->mclk = clk_set_rate(&clk, ULONG_MAX);
48 if (IS_ERR_VALUE(priv->mclk)) {
49 dev_err(dev, "failed to set rate for host clock\n");
50 clk_free(&clk);
51 return priv->mclk;
52 }
53
54 ret = clk_enable(&clk);
55 clk_free(&clk);
56 if (ret) {
57 dev_err(dev, "failed to enable host clock\n");
58 return ret;
59 }
Masahiro Yamadafc2d0302018-04-20 18:14:25 +090060#else
61 priv->mclk = 100000000;
62#endif
Masahiro Yamada30b5d9a2018-04-20 18:14:24 +090063
Marek Vasutcb0b6b02018-04-13 23:51:33 +020064 return tmio_sd_probe(dev, 0);
Marek Vasutc769e602018-04-08 17:45:23 +020065}
66
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090067U_BOOT_DRIVER(uniphier_mmc) = {
68 .name = "uniphier-mmc",
69 .id = UCLASS_MMC,
70 .of_match = uniphier_sd_match,
Marek Vasutcb0b6b02018-04-13 23:51:33 +020071 .bind = tmio_sd_bind,
Marek Vasutc769e602018-04-08 17:45:23 +020072 .probe = uniphier_sd_probe,
Marek Vasutcb0b6b02018-04-13 23:51:33 +020073 .priv_auto_alloc_size = sizeof(struct tmio_sd_priv),
74 .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat),
Masahiro Yamada39374042016-08-25 14:52:35 +090075 .ops = &uniphier_sd_ops,
Masahiro Yamadaa111bfb2016-02-18 19:52:48 +090076};