1 /* 2 * Copyright (C) 2016 Socionext Inc. 3 * Author: Masahiro Yamada <yamada.masahiro@socionext.com> 4 * 5 * SPDX-License-Identifier: GPL-2.0+ 6 */ 7 8 #include <common.h> 9 #include <clk.h> 10 #include <fdtdec.h> 11 #include <mmc.h> 12 #include <dm.h> 13 #include <linux/compat.h> 14 #include <linux/dma-direction.h> 15 #include <linux/io.h> 16 #include <linux/sizes.h> 17 #include <power/regulator.h> 18 #include <asm/unaligned.h> 19 20 #include "tmio-common.h" 21 22 static const struct dm_mmc_ops uniphier_sd_ops = { 23 .send_cmd = tmio_sd_send_cmd, 24 .set_ios = tmio_sd_set_ios, 25 .get_cd = tmio_sd_get_cd, 26 }; 27 28 static const struct udevice_id uniphier_sd_match[] = { 29 { .compatible = "socionext,uniphier-sdhc", .data = 0 }, 30 { /* sentinel */ } 31 }; 32 33 static int uniphier_sd_probe(struct udevice *dev) 34 { 35 struct tmio_sd_priv *priv = dev_get_priv(dev); 36 struct clk clk; 37 int ret; 38 39 ret = clk_get_by_index(dev, 0, &clk); 40 if (ret < 0) { 41 dev_err(dev, "failed to get host clock\n"); 42 return ret; 43 } 44 45 /* set to max rate */ 46 priv->mclk = clk_set_rate(&clk, ULONG_MAX); 47 if (IS_ERR_VALUE(priv->mclk)) { 48 dev_err(dev, "failed to set rate for host clock\n"); 49 clk_free(&clk); 50 return priv->mclk; 51 } 52 53 ret = clk_enable(&clk); 54 clk_free(&clk); 55 if (ret) { 56 dev_err(dev, "failed to enable host clock\n"); 57 return ret; 58 } 59 60 return tmio_sd_probe(dev, 0); 61 } 62 63 U_BOOT_DRIVER(uniphier_mmc) = { 64 .name = "uniphier-mmc", 65 .id = UCLASS_MMC, 66 .of_match = uniphier_sd_match, 67 .bind = tmio_sd_bind, 68 .probe = uniphier_sd_probe, 69 .priv_auto_alloc_size = sizeof(struct tmio_sd_priv), 70 .platdata_auto_alloc_size = sizeof(struct tmio_sd_plat), 71 .ops = &uniphier_sd_ops, 72 }; 73