Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 2 | /* |
Masahiro Yamada | 4e3d840 | 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 | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <clk.h> |
| 9 | #include <fdtdec.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 10 | #include <malloc.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> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 13 | #include <dm/device_compat.h> |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 14 | #include <linux/compat.h> |
Masahiro Yamada | b27af39 | 2017-08-26 00:50:17 +0900 | [diff] [blame] | 15 | #include <linux/dma-direction.h> |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 16 | #include <linux/io.h> |
Masahiro Yamada | 4f80501 | 2016-03-24 22:32:42 +0900 | [diff] [blame] | 17 | #include <linux/sizes.h> |
Marek Vasut | 9f13021 | 2017-09-15 21:10:54 +0200 | [diff] [blame] | 18 | #include <power/regulator.h> |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 19 | #include <asm/unaligned.h> |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 20 | |
Marek Vasut | cb0b6b0 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 21 | #include "tmio-common.h" |
Masahiro Yamada | 4eb0084 | 2016-08-25 14:52:36 +0900 | [diff] [blame] | 22 | |
| 23 | static const struct dm_mmc_ops uniphier_sd_ops = { |
Marek Vasut | cb0b6b0 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 24 | .send_cmd = tmio_sd_send_cmd, |
| 25 | .set_ios = tmio_sd_set_ios, |
| 26 | .get_cd = tmio_sd_get_cd, |
Masahiro Yamada | 4eb0084 | 2016-08-25 14:52:36 +0900 | [diff] [blame] | 27 | }; |
| 28 | |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 29 | static const struct udevice_id uniphier_sd_match[] = { |
Masahiro Yamada | c3ab1e1 | 2018-09-10 12:58:35 +0900 | [diff] [blame] | 30 | { .compatible = "socionext,uniphier-sd-v2.91" }, |
| 31 | { .compatible = "socionext,uniphier-sd-v3.1" }, |
| 32 | { .compatible = "socionext,uniphier-sd-v3.1.1" }, |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 33 | { /* sentinel */ } |
| 34 | }; |
| 35 | |
Marek Vasut | 8ec6a04 | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 36 | static ulong uniphier_sd_clk_get_rate(struct tmio_sd_priv *priv) |
| 37 | { |
| 38 | #if CONFIG_IS_ENABLED(CLK) |
| 39 | return clk_get_rate(&priv->clk); |
| 40 | #elif CONFIG_SPL_BUILD |
| 41 | return 100000000; |
| 42 | #else |
| 43 | return 0; |
| 44 | #endif |
| 45 | } |
| 46 | |
Marek Vasut | c769e60 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 47 | static int uniphier_sd_probe(struct udevice *dev) |
| 48 | { |
Masahiro Yamada | 30b5d9a | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 49 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
Marek Vasut | 8ec6a04 | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 50 | |
| 51 | priv->clk_get_rate = uniphier_sd_clk_get_rate; |
Marek Vasut | 992bcf4 | 2019-01-11 23:45:54 +0100 | [diff] [blame] | 52 | priv->read_poll_flag = TMIO_SD_DMA_INFO1_END_RD2; |
Marek Vasut | 8ec6a04 | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 53 | |
Masahiro Yamada | fc2d030 | 2018-04-20 18:14:25 +0900 | [diff] [blame] | 54 | #ifndef CONFIG_SPL_BUILD |
Masahiro Yamada | 30b5d9a | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 55 | int ret; |
| 56 | |
Marek Vasut | 8ec6a04 | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 57 | ret = clk_get_by_index(dev, 0, &priv->clk); |
Masahiro Yamada | 30b5d9a | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 58 | if (ret < 0) { |
| 59 | dev_err(dev, "failed to get host clock\n"); |
| 60 | return ret; |
| 61 | } |
| 62 | |
| 63 | /* set to max rate */ |
Marek Vasut | 8ec6a04 | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 64 | ret = clk_set_rate(&priv->clk, ULONG_MAX); |
| 65 | if (ret < 0) { |
Masahiro Yamada | 30b5d9a | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 66 | dev_err(dev, "failed to set rate for host clock\n"); |
Marek Vasut | 8ec6a04 | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 67 | clk_free(&priv->clk); |
| 68 | return ret; |
Masahiro Yamada | 30b5d9a | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 69 | } |
| 70 | |
Marek Vasut | 8ec6a04 | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 71 | ret = clk_enable(&priv->clk); |
Masahiro Yamada | 30b5d9a | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 72 | if (ret) { |
| 73 | dev_err(dev, "failed to enable host clock\n"); |
| 74 | return ret; |
| 75 | } |
Masahiro Yamada | fc2d030 | 2018-04-20 18:14:25 +0900 | [diff] [blame] | 76 | #endif |
Masahiro Yamada | 30b5d9a | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 77 | |
Marek Vasut | cb0b6b0 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 78 | return tmio_sd_probe(dev, 0); |
Marek Vasut | c769e60 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 79 | } |
| 80 | |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 81 | U_BOOT_DRIVER(uniphier_mmc) = { |
| 82 | .name = "uniphier-mmc", |
| 83 | .id = UCLASS_MMC, |
| 84 | .of_match = uniphier_sd_match, |
Marek Vasut | cb0b6b0 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 85 | .bind = tmio_sd_bind, |
Marek Vasut | c769e60 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 86 | .probe = uniphier_sd_probe, |
Simon Glass | 41575d8 | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 87 | .priv_auto = sizeof(struct tmio_sd_priv), |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame^] | 88 | .plat_auto = sizeof(struct tmio_sd_plat), |
Masahiro Yamada | 3937404 | 2016-08-25 14:52:35 +0900 | [diff] [blame] | 89 | .ops = &uniphier_sd_ops, |
Masahiro Yamada | a111bfb | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 90 | }; |