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 | |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 7 | #include <clk.h> |
| 8 | #include <fdtdec.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 9 | #include <malloc.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> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <dm/device_compat.h> |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 13 | #include <linux/compat.h> |
Masahiro Yamada | ef205ea | 2017-08-26 00:50:17 +0900 | [diff] [blame] | 14 | #include <linux/dma-direction.h> |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 15 | #include <linux/io.h> |
Masahiro Yamada | dc158ef | 2016-03-24 22:32:42 +0900 | [diff] [blame] | 16 | #include <linux/sizes.h> |
Marek Vasut | 10f0c3c | 2017-09-15 21:10:54 +0200 | [diff] [blame] | 17 | #include <power/regulator.h> |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 18 | #include <asm/unaligned.h> |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 19 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 20 | #include "tmio-common.h" |
Masahiro Yamada | b29afb9 | 2016-08-25 14:52:36 +0900 | [diff] [blame] | 21 | |
| 22 | static const struct dm_mmc_ops uniphier_sd_ops = { |
Marek Vasut | fd83e76 | 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 | b29afb9 | 2016-08-25 14:52:36 +0900 | [diff] [blame] | 26 | }; |
| 27 | |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 28 | static const struct udevice_id uniphier_sd_match[] = { |
Masahiro Yamada | 6c7ad4d | 2018-09-10 12:58:35 +0900 | [diff] [blame] | 29 | { .compatible = "socionext,uniphier-sd-v2.91" }, |
| 30 | { .compatible = "socionext,uniphier-sd-v3.1" }, |
| 31 | { .compatible = "socionext,uniphier-sd-v3.1.1" }, |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 32 | { /* sentinel */ } |
| 33 | }; |
| 34 | |
Marek Vasut | da90a1b | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 35 | static ulong uniphier_sd_clk_get_rate(struct tmio_sd_priv *priv) |
| 36 | { |
| 37 | #if CONFIG_IS_ENABLED(CLK) |
| 38 | return clk_get_rate(&priv->clk); |
Simon Glass | 7ec2413 | 2024-09-29 19:49:48 -0600 | [diff] [blame] | 39 | #elif CONFIG_XPL_BUILD |
Marek Vasut | da90a1b | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 40 | return 100000000; |
| 41 | #else |
| 42 | return 0; |
| 43 | #endif |
| 44 | } |
| 45 | |
Marek Vasut | abe3e95 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 46 | static int uniphier_sd_probe(struct udevice *dev) |
| 47 | { |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 48 | struct tmio_sd_priv *priv = dev_get_priv(dev); |
Marek Vasut | da90a1b | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 49 | |
| 50 | priv->clk_get_rate = uniphier_sd_clk_get_rate; |
Marek Vasut | e9a2822 | 2019-01-11 23:45:54 +0100 | [diff] [blame] | 51 | priv->read_poll_flag = TMIO_SD_DMA_INFO1_END_RD2; |
Marek Vasut | da90a1b | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 52 | |
Simon Glass | 7ec2413 | 2024-09-29 19:49:48 -0600 | [diff] [blame] | 53 | #ifndef CONFIG_XPL_BUILD |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 54 | int ret; |
| 55 | |
Marek Vasut | da90a1b | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 56 | ret = clk_get_by_index(dev, 0, &priv->clk); |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 57 | if (ret < 0) { |
| 58 | dev_err(dev, "failed to get host clock\n"); |
| 59 | return ret; |
| 60 | } |
| 61 | |
| 62 | /* set to max rate */ |
Marek Vasut | da90a1b | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 63 | ret = clk_set_rate(&priv->clk, ULONG_MAX); |
| 64 | if (ret < 0) { |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 65 | dev_err(dev, "failed to set rate for host clock\n"); |
Marek Vasut | da90a1b | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 66 | return ret; |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 67 | } |
| 68 | |
Marek Vasut | da90a1b | 2018-06-13 08:02:55 +0200 | [diff] [blame] | 69 | ret = clk_enable(&priv->clk); |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 70 | if (ret) { |
| 71 | dev_err(dev, "failed to enable host clock\n"); |
| 72 | return ret; |
| 73 | } |
Masahiro Yamada | 28afb86 | 2018-04-20 18:14:25 +0900 | [diff] [blame] | 74 | #endif |
Masahiro Yamada | 19989d83 | 2018-04-20 18:14:24 +0900 | [diff] [blame] | 75 | |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 76 | return tmio_sd_probe(dev, 0); |
Marek Vasut | abe3e95 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 77 | } |
| 78 | |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 79 | U_BOOT_DRIVER(uniphier_mmc) = { |
| 80 | .name = "uniphier-mmc", |
| 81 | .id = UCLASS_MMC, |
| 82 | .of_match = uniphier_sd_match, |
Marek Vasut | fd83e76 | 2018-04-13 23:51:33 +0200 | [diff] [blame] | 83 | .bind = tmio_sd_bind, |
Marek Vasut | abe3e95 | 2018-04-08 17:45:23 +0200 | [diff] [blame] | 84 | .probe = uniphier_sd_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 85 | .priv_auto = sizeof(struct tmio_sd_priv), |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 86 | .plat_auto = sizeof(struct tmio_sd_plat), |
Masahiro Yamada | b26daaa | 2016-08-25 14:52:35 +0900 | [diff] [blame] | 87 | .ops = &uniphier_sd_ops, |
Masahiro Yamada | a0cfcc0 | 2016-02-18 19:52:48 +0900 | [diff] [blame] | 88 | }; |