Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 2 | /* |
Masahiro Yamada | fa1f73f | 2016-07-19 21:56:13 +0900 | [diff] [blame] | 3 | * Copyright (C) 2016 Socionext Inc. |
| 4 | * Author: Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <clk.h> |
| 9 | #include <fdtdec.h> |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 10 | #include <mmc.h> |
Simon Glass | 11c89f3 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 11 | #include <dm.h> |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 12 | #include <linux/compat.h> |
Masahiro Yamada | ef205ea | 2017-08-26 00:50:17 +0900 | [diff] [blame] | 13 | #include <linux/dma-direction.h> |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 14 | #include <linux/io.h> |
Masahiro Yamada | dc158ef | 2016-03-24 22:32:42 +0900 | [diff] [blame] | 15 | #include <linux/sizes.h> |
Marek Vasut | 10f0c3c | 2017-09-15 21:10:54 +0200 | [diff] [blame] | 16 | #include <power/regulator.h> |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 17 | #include <asm/unaligned.h> |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 18 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 19 | #include "tmio-common.h" |
Masahiro Yamada | b29afb9 | 2016-08-25 14:52:36 +0900 | [diff] [blame] | 20 | |
| 21 | static const struct dm_mmc_ops uniphier_sd_ops = { |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 22 | .send_cmd = tmio_sd_send_cmd, |
| 23 | .set_ios = tmio_sd_set_ios, |
| 24 | .get_cd = tmio_sd_get_cd, |
Masahiro Yamada | b29afb9 | 2016-08-25 14:52:36 +0900 | [diff] [blame] | 25 | }; |
| 26 | |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 27 | static const struct udevice_id uniphier_sd_match[] = { |
Masahiro Yamada | 6c7ad4d | 2018-09-10 12:58:35 +0900 | [diff] [blame^] | 28 | { .compatible = "socionext,uniphier-sd-v2.91" }, |
| 29 | { .compatible = "socionext,uniphier-sd-v3.1" }, |
| 30 | { .compatible = "socionext,uniphier-sd-v3.1.1" }, |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 31 | { /* sentinel */ } |
| 32 | }; |
| 33 | |
Marek Vasut | abe3e95 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 34 | static int uniphier_sd_probe(struct udevice *dev) |
| 35 | { |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 36 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
Masahiro Yamada | 28afb86 | 2018-04-20 18:14:25 +0900 | [diff] [blame] | 37 | #ifndef CONFIG_SPL_BUILD |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 38 | struct clk clk; |
| 39 | int ret; |
| 40 | |
| 41 | ret = clk_get_by_index(dev, 0, &clk); |
| 42 | if (ret < 0) { |
| 43 | dev_err(dev, "failed to get host clock\n"); |
| 44 | return ret; |
| 45 | } |
| 46 | |
| 47 | /* set to max rate */ |
| 48 | priv->mclk = clk_set_rate(&clk, ULONG_MAX); |
| 49 | if (IS_ERR_VALUE(priv->mclk)) { |
| 50 | dev_err(dev, "failed to set rate for host clock\n"); |
| 51 | clk_free(&clk); |
| 52 | return priv->mclk; |
| 53 | } |
| 54 | |
| 55 | ret = clk_enable(&clk); |
| 56 | clk_free(&clk); |
| 57 | if (ret) { |
| 58 | dev_err(dev, "failed to enable host clock\n"); |
| 59 | return ret; |
| 60 | } |
Masahiro Yamada | 28afb86 | 2018-04-20 18:14:25 +0900 | [diff] [blame] | 61 | #else |
| 62 | priv->mclk = 100000000; |
| 63 | #endif |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 64 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 65 | return tmio_sd_probe(dev, 0); |
Marek Vasut | abe3e95 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 66 | } |
| 67 | |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 68 | U_BOOT_DRIVER(uniphier_mmc) = { |
| 69 | .name = "uniphier-mmc", |
| 70 | .id = UCLASS_MMC, |
| 71 | .of_match = uniphier_sd_match, |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 72 | .bind = tmio_sd_bind, |
Marek Vasut | abe3e95 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 73 | .probe = uniphier_sd_probe, |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 74 | .priv_auto_alloc_size = sizeof(struct tmio_sd_priv), |
| 75 | .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat), |
Masahiro Yamada | b26daaa | 2016-08-25 14:52:35 +0900 | [diff] [blame] | 76 | .ops = &uniphier_sd_ops, |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 77 | }; |