1c3665006SThomas Abraham /* 2c3665006SThomas Abraham * Exynos Specific Extensions for Synopsys DW Multimedia Card Interface driver 3c3665006SThomas Abraham * 4c3665006SThomas Abraham * Copyright (C) 2012, Samsung Electronics Co., Ltd. 5c3665006SThomas Abraham * 6c3665006SThomas Abraham * This program is free software; you can redistribute it and/or modify 7c3665006SThomas Abraham * it under the terms of the GNU General Public License as published by 8c3665006SThomas Abraham * the Free Software Foundation; either version 2 of the License, or 9c3665006SThomas Abraham * (at your option) any later version. 10c3665006SThomas Abraham */ 11c3665006SThomas Abraham 12c3665006SThomas Abraham #include <linux/module.h> 13c3665006SThomas Abraham #include <linux/platform_device.h> 14c3665006SThomas Abraham #include <linux/clk.h> 15c3665006SThomas Abraham #include <linux/mmc/host.h> 16c3665006SThomas Abraham #include <linux/mmc/dw_mmc.h> 17c3665006SThomas Abraham #include <linux/of.h> 18c3665006SThomas Abraham #include <linux/of_gpio.h> 19c3665006SThomas Abraham 20c3665006SThomas Abraham #include "dw_mmc.h" 21c3665006SThomas Abraham #include "dw_mmc-pltfm.h" 22c3665006SThomas Abraham 23c3665006SThomas Abraham #define NUM_PINS(x) (x + 2) 24c3665006SThomas Abraham 25c3665006SThomas Abraham #define SDMMC_CLKSEL 0x09C 26c3665006SThomas Abraham #define SDMMC_CLKSEL_CCLK_SAMPLE(x) (((x) & 7) << 0) 27c3665006SThomas Abraham #define SDMMC_CLKSEL_CCLK_DRIVE(x) (((x) & 7) << 16) 28c3665006SThomas Abraham #define SDMMC_CLKSEL_CCLK_DIVIDER(x) (((x) & 7) << 24) 29c3665006SThomas Abraham #define SDMMC_CLKSEL_GET_DRV_WD3(x) (((x) >> 16) & 0x7) 30c3665006SThomas Abraham #define SDMMC_CLKSEL_TIMING(x, y, z) (SDMMC_CLKSEL_CCLK_SAMPLE(x) | \ 31c3665006SThomas Abraham SDMMC_CLKSEL_CCLK_DRIVE(y) | \ 32c3665006SThomas Abraham SDMMC_CLKSEL_CCLK_DIVIDER(z)) 33c3665006SThomas Abraham 34c3665006SThomas Abraham #define EXYNOS4210_FIXED_CIU_CLK_DIV 2 35c3665006SThomas Abraham #define EXYNOS4412_FIXED_CIU_CLK_DIV 4 36c3665006SThomas Abraham 37c3665006SThomas Abraham /* Variations in Exynos specific dw-mshc controller */ 38c3665006SThomas Abraham enum dw_mci_exynos_type { 39c3665006SThomas Abraham DW_MCI_TYPE_EXYNOS4210, 40c3665006SThomas Abraham DW_MCI_TYPE_EXYNOS4412, 41c3665006SThomas Abraham DW_MCI_TYPE_EXYNOS5250, 42*00fd041bSYuvaraj Kumar C D DW_MCI_TYPE_EXYNOS5420, 43c3665006SThomas Abraham }; 44c3665006SThomas Abraham 45c3665006SThomas Abraham /* Exynos implementation specific driver private data */ 46c3665006SThomas Abraham struct dw_mci_exynos_priv_data { 47c3665006SThomas Abraham enum dw_mci_exynos_type ctrl_type; 48c3665006SThomas Abraham u8 ciu_div; 49c3665006SThomas Abraham u32 sdr_timing; 50c3665006SThomas Abraham u32 ddr_timing; 51c3665006SThomas Abraham }; 52c3665006SThomas Abraham 53c3665006SThomas Abraham static struct dw_mci_exynos_compatible { 54c3665006SThomas Abraham char *compatible; 55c3665006SThomas Abraham enum dw_mci_exynos_type ctrl_type; 56c3665006SThomas Abraham } exynos_compat[] = { 57c3665006SThomas Abraham { 58c3665006SThomas Abraham .compatible = "samsung,exynos4210-dw-mshc", 59c3665006SThomas Abraham .ctrl_type = DW_MCI_TYPE_EXYNOS4210, 60c3665006SThomas Abraham }, { 61c3665006SThomas Abraham .compatible = "samsung,exynos4412-dw-mshc", 62c3665006SThomas Abraham .ctrl_type = DW_MCI_TYPE_EXYNOS4412, 63c3665006SThomas Abraham }, { 64c3665006SThomas Abraham .compatible = "samsung,exynos5250-dw-mshc", 65c3665006SThomas Abraham .ctrl_type = DW_MCI_TYPE_EXYNOS5250, 66*00fd041bSYuvaraj Kumar C D }, { 67*00fd041bSYuvaraj Kumar C D .compatible = "samsung,exynos5420-dw-mshc", 68*00fd041bSYuvaraj Kumar C D .ctrl_type = DW_MCI_TYPE_EXYNOS5420, 69c3665006SThomas Abraham }, 70c3665006SThomas Abraham }; 71c3665006SThomas Abraham 72c3665006SThomas Abraham static int dw_mci_exynos_priv_init(struct dw_mci *host) 73c3665006SThomas Abraham { 74c3665006SThomas Abraham struct dw_mci_exynos_priv_data *priv; 75c3665006SThomas Abraham int idx; 76c3665006SThomas Abraham 77c3665006SThomas Abraham priv = devm_kzalloc(host->dev, sizeof(*priv), GFP_KERNEL); 78c3665006SThomas Abraham if (!priv) { 79c3665006SThomas Abraham dev_err(host->dev, "mem alloc failed for private data\n"); 80c3665006SThomas Abraham return -ENOMEM; 81c3665006SThomas Abraham } 82c3665006SThomas Abraham 83c3665006SThomas Abraham for (idx = 0; idx < ARRAY_SIZE(exynos_compat); idx++) { 84c3665006SThomas Abraham if (of_device_is_compatible(host->dev->of_node, 85c3665006SThomas Abraham exynos_compat[idx].compatible)) 86c3665006SThomas Abraham priv->ctrl_type = exynos_compat[idx].ctrl_type; 87c3665006SThomas Abraham } 88c3665006SThomas Abraham 89c3665006SThomas Abraham host->priv = priv; 90c3665006SThomas Abraham return 0; 91c3665006SThomas Abraham } 92c3665006SThomas Abraham 93c3665006SThomas Abraham static int dw_mci_exynos_setup_clock(struct dw_mci *host) 94c3665006SThomas Abraham { 95c3665006SThomas Abraham struct dw_mci_exynos_priv_data *priv = host->priv; 96c3665006SThomas Abraham 97*00fd041bSYuvaraj Kumar C D if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS5250 || 98*00fd041bSYuvaraj Kumar C D priv->ctrl_type == DW_MCI_TYPE_EXYNOS5420) 99c3665006SThomas Abraham host->bus_hz /= (priv->ciu_div + 1); 100c3665006SThomas Abraham else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4412) 101c3665006SThomas Abraham host->bus_hz /= EXYNOS4412_FIXED_CIU_CLK_DIV; 102c3665006SThomas Abraham else if (priv->ctrl_type == DW_MCI_TYPE_EXYNOS4210) 103c3665006SThomas Abraham host->bus_hz /= EXYNOS4210_FIXED_CIU_CLK_DIV; 104c3665006SThomas Abraham 105c3665006SThomas Abraham return 0; 106c3665006SThomas Abraham } 107c3665006SThomas Abraham 108c3665006SThomas Abraham static void dw_mci_exynos_prepare_command(struct dw_mci *host, u32 *cmdr) 109c3665006SThomas Abraham { 110c3665006SThomas Abraham /* 111c3665006SThomas Abraham * Exynos4412 and Exynos5250 extends the use of CMD register with the 112c3665006SThomas Abraham * use of bit 29 (which is reserved on standard MSHC controllers) for 113c3665006SThomas Abraham * optionally bypassing the HOLD register for command and data. The 114c3665006SThomas Abraham * HOLD register should be bypassed in case there is no phase shift 115c3665006SThomas Abraham * applied on CMD/DATA that is sent to the card. 116c3665006SThomas Abraham */ 117c3665006SThomas Abraham if (SDMMC_CLKSEL_GET_DRV_WD3(mci_readl(host, CLKSEL))) 118c3665006SThomas Abraham *cmdr |= SDMMC_CMD_USE_HOLD_REG; 119c3665006SThomas Abraham } 120c3665006SThomas Abraham 121c3665006SThomas Abraham static void dw_mci_exynos_set_ios(struct dw_mci *host, struct mmc_ios *ios) 122c3665006SThomas Abraham { 123c3665006SThomas Abraham struct dw_mci_exynos_priv_data *priv = host->priv; 124c3665006SThomas Abraham 125c3665006SThomas Abraham if (ios->timing == MMC_TIMING_UHS_DDR50) 126c3665006SThomas Abraham mci_writel(host, CLKSEL, priv->ddr_timing); 127c3665006SThomas Abraham else 128c3665006SThomas Abraham mci_writel(host, CLKSEL, priv->sdr_timing); 129c3665006SThomas Abraham } 130c3665006SThomas Abraham 131c3665006SThomas Abraham static int dw_mci_exynos_parse_dt(struct dw_mci *host) 132c3665006SThomas Abraham { 133c3665006SThomas Abraham struct dw_mci_exynos_priv_data *priv = host->priv; 134c3665006SThomas Abraham struct device_node *np = host->dev->of_node; 135c3665006SThomas Abraham u32 timing[2]; 136c3665006SThomas Abraham u32 div = 0; 137c3665006SThomas Abraham int ret; 138c3665006SThomas Abraham 139c3665006SThomas Abraham of_property_read_u32(np, "samsung,dw-mshc-ciu-div", &div); 140c3665006SThomas Abraham priv->ciu_div = div; 141c3665006SThomas Abraham 142c3665006SThomas Abraham ret = of_property_read_u32_array(np, 143c3665006SThomas Abraham "samsung,dw-mshc-sdr-timing", timing, 2); 144c3665006SThomas Abraham if (ret) 145c3665006SThomas Abraham return ret; 146c3665006SThomas Abraham 147c3665006SThomas Abraham priv->sdr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); 148c3665006SThomas Abraham 149c3665006SThomas Abraham ret = of_property_read_u32_array(np, 150c3665006SThomas Abraham "samsung,dw-mshc-ddr-timing", timing, 2); 151c3665006SThomas Abraham if (ret) 152c3665006SThomas Abraham return ret; 153c3665006SThomas Abraham 154c3665006SThomas Abraham priv->ddr_timing = SDMMC_CLKSEL_TIMING(timing[0], timing[1], div); 155c3665006SThomas Abraham return 0; 156c3665006SThomas Abraham } 157c3665006SThomas Abraham 1580f6e73d0SDongjin Kim /* Common capabilities of Exynos4/Exynos5 SoC */ 1590f6e73d0SDongjin Kim static unsigned long exynos_dwmmc_caps[4] = { 160c3665006SThomas Abraham MMC_CAP_UHS_DDR50 | MMC_CAP_1_8V_DDR | 161c3665006SThomas Abraham MMC_CAP_8_BIT_DATA | MMC_CAP_CMD23, 162c3665006SThomas Abraham MMC_CAP_CMD23, 163c3665006SThomas Abraham MMC_CAP_CMD23, 164c3665006SThomas Abraham MMC_CAP_CMD23, 165c3665006SThomas Abraham }; 166c3665006SThomas Abraham 1670f6e73d0SDongjin Kim static const struct dw_mci_drv_data exynos_drv_data = { 1680f6e73d0SDongjin Kim .caps = exynos_dwmmc_caps, 169c3665006SThomas Abraham .init = dw_mci_exynos_priv_init, 170c3665006SThomas Abraham .setup_clock = dw_mci_exynos_setup_clock, 171c3665006SThomas Abraham .prepare_command = dw_mci_exynos_prepare_command, 172c3665006SThomas Abraham .set_ios = dw_mci_exynos_set_ios, 173c3665006SThomas Abraham .parse_dt = dw_mci_exynos_parse_dt, 174c3665006SThomas Abraham }; 175c3665006SThomas Abraham 176c3665006SThomas Abraham static const struct of_device_id dw_mci_exynos_match[] = { 1770f6e73d0SDongjin Kim { .compatible = "samsung,exynos4412-dw-mshc", 1780f6e73d0SDongjin Kim .data = &exynos_drv_data, }, 179c3665006SThomas Abraham { .compatible = "samsung,exynos5250-dw-mshc", 1800f6e73d0SDongjin Kim .data = &exynos_drv_data, }, 181*00fd041bSYuvaraj Kumar C D { .compatible = "samsung,exynos5420-dw-mshc", 182*00fd041bSYuvaraj Kumar C D .data = &exynos_drv_data, }, 183c3665006SThomas Abraham {}, 184c3665006SThomas Abraham }; 185517cb9f1SArnd Bergmann MODULE_DEVICE_TABLE(of, dw_mci_exynos_match); 186c3665006SThomas Abraham 1879665f7f2SSachin Kamat static int dw_mci_exynos_probe(struct platform_device *pdev) 188c3665006SThomas Abraham { 1898e2b36eaSArnd Bergmann const struct dw_mci_drv_data *drv_data; 190c3665006SThomas Abraham const struct of_device_id *match; 191c3665006SThomas Abraham 192c3665006SThomas Abraham match = of_match_node(dw_mci_exynos_match, pdev->dev.of_node); 193c3665006SThomas Abraham drv_data = match->data; 194c3665006SThomas Abraham return dw_mci_pltfm_register(pdev, drv_data); 195c3665006SThomas Abraham } 196c3665006SThomas Abraham 197c3665006SThomas Abraham static struct platform_driver dw_mci_exynos_pltfm_driver = { 198c3665006SThomas Abraham .probe = dw_mci_exynos_probe, 199c3665006SThomas Abraham .remove = __exit_p(dw_mci_pltfm_remove), 200c3665006SThomas Abraham .driver = { 201c3665006SThomas Abraham .name = "dwmmc_exynos", 20220183d50SSachin Kamat .of_match_table = dw_mci_exynos_match, 203c3665006SThomas Abraham .pm = &dw_mci_pltfm_pmops, 204c3665006SThomas Abraham }, 205c3665006SThomas Abraham }; 206c3665006SThomas Abraham 207c3665006SThomas Abraham module_platform_driver(dw_mci_exynos_pltfm_driver); 208c3665006SThomas Abraham 209c3665006SThomas Abraham MODULE_DESCRIPTION("Samsung Specific DW-MSHC Driver Extension"); 210c3665006SThomas Abraham MODULE_AUTHOR("Thomas Abraham <thomas.ab@samsung.com"); 211c3665006SThomas Abraham MODULE_LICENSE("GPL v2"); 212c3665006SThomas Abraham MODULE_ALIAS("platform:dwmmc-exynos"); 213