1a111bfbfSMasahiro Yamada /* 24e3d8406SMasahiro Yamada * Copyright (C) 2016 Socionext Inc. 34e3d8406SMasahiro Yamada * Author: Masahiro Yamada <yamada.masahiro@socionext.com> 4a111bfbfSMasahiro Yamada * 5a111bfbfSMasahiro Yamada * SPDX-License-Identifier: GPL-2.0+ 6a111bfbfSMasahiro Yamada */ 7a111bfbfSMasahiro Yamada 8a111bfbfSMasahiro Yamada #include <common.h> 9a111bfbfSMasahiro Yamada #include <clk.h> 10a111bfbfSMasahiro Yamada #include <fdtdec.h> 11a111bfbfSMasahiro Yamada #include <mmc.h> 129d922450SSimon Glass #include <dm.h> 13a111bfbfSMasahiro Yamada #include <linux/compat.h> 14b27af399SMasahiro Yamada #include <linux/dma-direction.h> 15a111bfbfSMasahiro Yamada #include <linux/io.h> 164f80501bSMasahiro Yamada #include <linux/sizes.h> 179f13021fSMarek Vasut #include <power/regulator.h> 18a111bfbfSMasahiro Yamada #include <asm/unaligned.h> 19a111bfbfSMasahiro Yamada 20cb0b6b03SMarek Vasut #include "tmio-common.h" 214eb00846SMasahiro Yamada 224eb00846SMasahiro Yamada static const struct dm_mmc_ops uniphier_sd_ops = { 23cb0b6b03SMarek Vasut .send_cmd = tmio_sd_send_cmd, 24cb0b6b03SMarek Vasut .set_ios = tmio_sd_set_ios, 25cb0b6b03SMarek Vasut .get_cd = tmio_sd_get_cd, 264eb00846SMasahiro Yamada }; 274eb00846SMasahiro Yamada 28a111bfbfSMasahiro Yamada static const struct udevice_id uniphier_sd_match[] = { 294b26d5e3SMarek Vasut { .compatible = "socionext,uniphier-sdhc", .data = 0 }, 30a111bfbfSMasahiro Yamada { /* sentinel */ } 31a111bfbfSMasahiro Yamada }; 32a111bfbfSMasahiro Yamada 33c769e609SMarek Vasut static int uniphier_sd_probe(struct udevice *dev) 34c769e609SMarek Vasut { 3530b5d9aaSMasahiro Yamada struct tmio_sd_priv *priv = dev_get_priv(dev); 36*fc2d0302SMasahiro Yamada #ifndef CONFIG_SPL_BUILD 3730b5d9aaSMasahiro Yamada struct clk clk; 3830b5d9aaSMasahiro Yamada int ret; 3930b5d9aaSMasahiro Yamada 4030b5d9aaSMasahiro Yamada ret = clk_get_by_index(dev, 0, &clk); 4130b5d9aaSMasahiro Yamada if (ret < 0) { 4230b5d9aaSMasahiro Yamada dev_err(dev, "failed to get host clock\n"); 4330b5d9aaSMasahiro Yamada return ret; 4430b5d9aaSMasahiro Yamada } 4530b5d9aaSMasahiro Yamada 4630b5d9aaSMasahiro Yamada /* set to max rate */ 4730b5d9aaSMasahiro Yamada priv->mclk = clk_set_rate(&clk, ULONG_MAX); 4830b5d9aaSMasahiro Yamada if (IS_ERR_VALUE(priv->mclk)) { 4930b5d9aaSMasahiro Yamada dev_err(dev, "failed to set rate for host clock\n"); 5030b5d9aaSMasahiro Yamada clk_free(&clk); 5130b5d9aaSMasahiro Yamada return priv->mclk; 5230b5d9aaSMasahiro Yamada } 5330b5d9aaSMasahiro Yamada 5430b5d9aaSMasahiro Yamada ret = clk_enable(&clk); 5530b5d9aaSMasahiro Yamada clk_free(&clk); 5630b5d9aaSMasahiro Yamada if (ret) { 5730b5d9aaSMasahiro Yamada dev_err(dev, "failed to enable host clock\n"); 5830b5d9aaSMasahiro Yamada return ret; 5930b5d9aaSMasahiro Yamada } 60*fc2d0302SMasahiro Yamada #else 61*fc2d0302SMasahiro Yamada priv->mclk = 100000000; 62*fc2d0302SMasahiro Yamada #endif 6330b5d9aaSMasahiro Yamada 64cb0b6b03SMarek Vasut return tmio_sd_probe(dev, 0); 65c769e609SMarek Vasut } 66c769e609SMarek Vasut 67a111bfbfSMasahiro Yamada U_BOOT_DRIVER(uniphier_mmc) = { 68a111bfbfSMasahiro Yamada .name = "uniphier-mmc", 69a111bfbfSMasahiro Yamada .id = UCLASS_MMC, 70a111bfbfSMasahiro Yamada .of_match = uniphier_sd_match, 71cb0b6b03SMarek Vasut .bind = tmio_sd_bind, 72c769e609SMarek Vasut .probe = uniphier_sd_probe, 73cb0b6b03SMarek Vasut .priv_auto_alloc_size = sizeof(struct tmio_sd_priv), 74cb0b6b03SMarek Vasut .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat), 753937404fSMasahiro Yamada .ops = &uniphier_sd_ops, 76a111bfbfSMasahiro Yamada }; 77