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 { 35*30b5d9aaSMasahiro Yamada struct tmio_sd_priv *priv = dev_get_priv(dev); 36*30b5d9aaSMasahiro Yamada struct clk clk; 37*30b5d9aaSMasahiro Yamada int ret; 38*30b5d9aaSMasahiro Yamada 39*30b5d9aaSMasahiro Yamada ret = clk_get_by_index(dev, 0, &clk); 40*30b5d9aaSMasahiro Yamada if (ret < 0) { 41*30b5d9aaSMasahiro Yamada dev_err(dev, "failed to get host clock\n"); 42*30b5d9aaSMasahiro Yamada return ret; 43*30b5d9aaSMasahiro Yamada } 44*30b5d9aaSMasahiro Yamada 45*30b5d9aaSMasahiro Yamada /* set to max rate */ 46*30b5d9aaSMasahiro Yamada priv->mclk = clk_set_rate(&clk, ULONG_MAX); 47*30b5d9aaSMasahiro Yamada if (IS_ERR_VALUE(priv->mclk)) { 48*30b5d9aaSMasahiro Yamada dev_err(dev, "failed to set rate for host clock\n"); 49*30b5d9aaSMasahiro Yamada clk_free(&clk); 50*30b5d9aaSMasahiro Yamada return priv->mclk; 51*30b5d9aaSMasahiro Yamada } 52*30b5d9aaSMasahiro Yamada 53*30b5d9aaSMasahiro Yamada ret = clk_enable(&clk); 54*30b5d9aaSMasahiro Yamada clk_free(&clk); 55*30b5d9aaSMasahiro Yamada if (ret) { 56*30b5d9aaSMasahiro Yamada dev_err(dev, "failed to enable host clock\n"); 57*30b5d9aaSMasahiro Yamada return ret; 58*30b5d9aaSMasahiro Yamada } 59*30b5d9aaSMasahiro Yamada 60cb0b6b03SMarek Vasut return tmio_sd_probe(dev, 0); 61c769e609SMarek Vasut } 62c769e609SMarek Vasut 63a111bfbfSMasahiro Yamada U_BOOT_DRIVER(uniphier_mmc) = { 64a111bfbfSMasahiro Yamada .name = "uniphier-mmc", 65a111bfbfSMasahiro Yamada .id = UCLASS_MMC, 66a111bfbfSMasahiro Yamada .of_match = uniphier_sd_match, 67cb0b6b03SMarek Vasut .bind = tmio_sd_bind, 68c769e609SMarek Vasut .probe = uniphier_sd_probe, 69cb0b6b03SMarek Vasut .priv_auto_alloc_size = sizeof(struct tmio_sd_priv), 70cb0b6b03SMarek Vasut .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat), 713937404fSMasahiro Yamada .ops = &uniphier_sd_ops, 72a111bfbfSMasahiro Yamada }; 73