Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 1 | /* |
Masahiro Yamada | 4e3d840 | 2016-07-19 21:56:13 +0900 | [diff] [blame] | 2 | * Copyright (C) 2016 Socionext Inc. |
| 3 | * Author: Masahiro Yamada <yamada.masahiro@socionext.com> |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 4 | * |
| 5 | * SPDX-License-Identifier: GPL-2.0+ |
| 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <clk.h> |
| 10 | #include <fdtdec.h> |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 11 | #include <mmc.h> |
Simon Glass | 9d92245 | 2017-05-17 17:18:03 -0600 | [diff] [blame] | 12 | #include <dm.h> |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 13 | #include <linux/compat.h> |
Masahiro Yamada | b27af39 | 2017-08-26 00:50:17 +0900 | [diff] [blame] | 14 | #include <linux/dma-direction.h> |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 15 | #include <linux/io.h> |
Masahiro Yamada | 4f80501 | 2016-03-24 22:32:42 +0900 | [diff] [blame] | 16 | #include <linux/sizes.h> |
Marek Vasut | 9f13021 | 2017-09-15 21:10:54 +0200 | [diff] [blame] | 17 | #include <power/regulator.h> |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 18 | #include <asm/unaligned.h> |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 19 | |
Marek Vasut | cb0b6b0 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 20 | #include "tmio-common.h" |
Masahiro Yamada | 4eb0084 | 2016-08-25 14:52:36 +0900 | [diff] [blame] | 21 | |
| 22 | static const struct dm_mmc_ops uniphier_sd_ops = { |
Marek Vasut | cb0b6b0 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 23 | .send_cmd = tmio_sd_send_cmd, |
| 24 | .set_ios = tmio_sd_set_ios, |
| 25 | .get_cd = tmio_sd_get_cd, |
Masahiro Yamada | 4eb0084 | 2016-08-25 14:52:36 +0900 | [diff] [blame] | 26 | }; |
| 27 | |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 28 | static const struct udevice_id uniphier_sd_match[] = { |
Marek Vasut | 4b26d5e | 2017-07-21 23:24:35 +0200 | [diff] [blame] | 29 | { .compatible = "socionext,uniphier-sdhc", .data = 0 }, |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 30 | { /* sentinel */ } |
| 31 | }; |
| 32 | |
Marek Vasut | c769e60 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 33 | static int uniphier_sd_probe(struct udevice *dev) |
| 34 | { |
Masahiro Yamada | 30b5d9a | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 35 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
Masahiro Yamada | fc2d030 | 2018-04-20 18:14:25 +0900 | [diff] [blame] | 36 | #ifndef CONFIG_SPL_BUILD |
Masahiro Yamada | 30b5d9a | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 37 | 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 Yamada | fc2d030 | 2018-04-20 18:14:25 +0900 | [diff] [blame] | 60 | #else |
| 61 | priv->mclk = 100000000; |
| 62 | #endif |
Masahiro Yamada | 30b5d9a | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 63 | |
Marek Vasut | cb0b6b0 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 64 | return tmio_sd_probe(dev, 0); |
Marek Vasut | c769e60 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 65 | } |
| 66 | |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 67 | U_BOOT_DRIVER(uniphier_mmc) = { |
| 68 | .name = "uniphier-mmc", |
| 69 | .id = UCLASS_MMC, |
| 70 | .of_match = uniphier_sd_match, |
Marek Vasut | cb0b6b0 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 71 | .bind = tmio_sd_bind, |
Marek Vasut | c769e60 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 72 | .probe = uniphier_sd_probe, |
Marek Vasut | cb0b6b0 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 73 | .priv_auto_alloc_size = sizeof(struct tmio_sd_priv), |
| 74 | .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat), |
Masahiro Yamada | 3937404 | 2016-08-25 14:52:35 +0900 | [diff] [blame] | 75 | .ops = &uniphier_sd_ops, |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 76 | }; |