blob: bc6e41dbf6dad580b7e90813db238a3fe7a605a6 [file] [log] [blame]
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +09001/*
Masahiro Yamadafa1f73f2016-07-19 21:56:13 +09002 * Copyright (C) 2016 Socionext Inc.
3 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadaa0cfcc02016-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 Yamadaa0cfcc02016-02-18 19:52:48 +090011#include <mmc.h>
Simon Glass11c89f32017-05-17 17:18:03 -060012#include <dm.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[] = {
Marek Vasutcd36d412017-07-21 23:24:35 +020029 { .compatible = "socionext,uniphier-sdhc", .data = 0 },
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090030 { /* sentinel */ }
31};
32
Marek Vasutabe3e952018-04-08 17:45:23 +020033static int uniphier_sd_probe(struct udevice *dev)
34{
Masahiro Yamada19989d832018-04-20 18:14:24 +090035 struct tmio_sd_priv *priv = dev_get_priv(dev);
36 struct clk clk;
37 int ret;
38
39 ret = clk_get_by_index(dev, 0, &clk);
40 if (ret < 0) {
41 dev_err(dev, "failed to get host clock\n");
42 return ret;
43 }
44
45 /* set to max rate */
46 priv->mclk = clk_set_rate(&clk, ULONG_MAX);
47 if (IS_ERR_VALUE(priv->mclk)) {
48 dev_err(dev, "failed to set rate for host clock\n");
49 clk_free(&clk);
50 return priv->mclk;
51 }
52
53 ret = clk_enable(&clk);
54 clk_free(&clk);
55 if (ret) {
56 dev_err(dev, "failed to enable host clock\n");
57 return ret;
58 }
59
Marek Vasutfd83e762018-04-13 23:51:33 +020060 return tmio_sd_probe(dev, 0);
Marek Vasutabe3e952018-04-08 17:45:23 +020061}
62
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090063U_BOOT_DRIVER(uniphier_mmc) = {
64 .name = "uniphier-mmc",
65 .id = UCLASS_MMC,
66 .of_match = uniphier_sd_match,
Marek Vasutfd83e762018-04-13 23:51:33 +020067 .bind = tmio_sd_bind,
Marek Vasutabe3e952018-04-08 17:45:23 +020068 .probe = uniphier_sd_probe,
Marek Vasutfd83e762018-04-13 23:51:33 +020069 .priv_auto_alloc_size = sizeof(struct tmio_sd_priv),
70 .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat),
Masahiro Yamadab26daaa2016-08-25 14:52:35 +090071 .ops = &uniphier_sd_ops,
Masahiro Yamadaa0cfcc02016-02-18 19:52:48 +090072};