Lines Matching +full:12 +full:bit +full:- +full:clkdiv +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0-only
11 #include <linux/mmc/slot-gpio.h>
22 #include "sdhci-pltfm.h"
25 #define CON_DW8 BIT(5)
26 #define CON_DMA_MASTER BIT(20)
27 #define CON_DDR BIT(19)
28 #define CON_CLKEXTFREE BIT(16)
29 #define CON_PADEN BIT(15)
30 #define CON_CTPL BIT(11)
31 #define CON_INIT BIT(1)
32 #define CON_OD BIT(0)
35 #define DLL_SWT BIT(20)
38 #define DLL_FORCE_VALUE BIT(12)
39 #define DLL_CALIB BIT(1)
44 #define PSTATE_DLEV_DAT0 BIT(20)
45 #define PSTATE_DATI BIT(1)
48 #define HCTL_SDBP BIT(8)
56 #define SYSCTL_CEN BIT(2)
63 #define INT_CC_EN BIT(0)
68 #define AC12_V1V8_SIGEN BIT(19)
69 #define AC12_SCLK_SEL BIT(23)
72 #define CAPA_VS33 BIT(24)
73 #define CAPA_VS30 BIT(25)
74 #define CAPA_VS18 BIT(26)
77 #define CAPA2_TSDR50 BIT(13)
89 /* sdhci-omap controller flags */
90 #define SDHCI_OMAP_REQUIRE_IODELAY BIT(0)
91 #define SDHCI_OMAP_SPECIAL_RESET BIT(1)
128 return readl(host->base + offset); in sdhci_omap_readl()
134 writel(data, host->base + offset); in sdhci_omap_writel()
141 struct device *dev = omap_host->dev; in sdhci_omap_set_pbias()
143 if (IS_ERR(omap_host->pbias)) in sdhci_omap_set_pbias()
147 ret = regulator_set_voltage(omap_host->pbias, iov, iov); in sdhci_omap_set_pbias()
153 if (omap_host->pbias_enabled) in sdhci_omap_set_pbias()
156 ret = regulator_enable(omap_host->pbias); in sdhci_omap_set_pbias()
162 omap_host->pbias_enabled = true; in sdhci_omap_set_pbias()
164 if (!omap_host->pbias_enabled) in sdhci_omap_set_pbias()
167 ret = regulator_disable(omap_host->pbias); in sdhci_omap_set_pbias()
172 omap_host->pbias_enabled = false; in sdhci_omap_set_pbias()
182 struct sdhci_host *host = omap_host->host; in sdhci_omap_enable_iov()
183 struct mmc_host *mmc = host->mmc; in sdhci_omap_enable_iov()
189 if (!IS_ERR(mmc->supply.vqmmc)) { in sdhci_omap_enable_iov()
190 ret = regulator_set_voltage(mmc->supply.vqmmc, iov, iov); in sdhci_omap_enable_iov()
295 struct device *dev = omap_host->dev; in sdhci_omap_execute_tuning()
296 struct mmc_ios *ios = &mmc->ios; in sdhci_omap_execute_tuning()
309 if (ios->clock <= 52000000) in sdhci_omap_execute_tuning()
313 if (ios->timing == MMC_TIMING_UHS_SDR50 && !(reg & CAPA2_TSDR50)) in sdhci_omap_execute_tuning()
336 if (host->ier & SDHCI_INT_DATA_CRC) { in sdhci_omap_execute_tuning()
337 host->ier &= ~SDHCI_INT_DATA_CRC; in sdhci_omap_execute_tuning()
341 omap_host->is_tuning = true; in sdhci_omap_execute_tuning()
377 ret = -EIO; in sdhci_omap_execute_tuning()
385 if (temperature < -20000) in sdhci_omap_execute_tuning()
386 phase_delay = min(max_window + 4 * (max_len - 1) - 24, in sdhci_omap_execute_tuning()
405 * +2 to -10 range. If found, move away from it in the appropriate in sdhci_omap_execute_tuning()
415 phase_delay += i - 12; in sdhci_omap_execute_tuning()
417 phase_delay += i - 8; in sdhci_omap_execute_tuning()
419 phase_delay += i - 6; in sdhci_omap_execute_tuning()
425 for (i = 2; i >= -10; i--) { in sdhci_omap_execute_tuning()
430 phase_delay += i + 12; in sdhci_omap_execute_tuning()
438 phase_delay += i + 12; in sdhci_omap_execute_tuning()
447 ret = -EIO; in sdhci_omap_execute_tuning()
453 omap_host->is_tuning = false; in sdhci_omap_execute_tuning()
458 omap_host->is_tuning = false; in sdhci_omap_execute_tuning()
466 host->ier |= SDHCI_INT_DATA_CRC; in sdhci_omap_execute_tuning()
467 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_omap_execute_tuning()
468 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_omap_execute_tuning()
479 u32 ier = host->ier; in sdhci_omap_card_busy()
492 disable_irq(host->irq); in sdhci_omap_card_busy()
510 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_omap_card_busy()
511 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_omap_card_busy()
512 enable_irq(host->irq); in sdhci_omap_card_busy()
530 dev = omap_host->dev; in sdhci_omap_start_signal_voltage_switch()
532 if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330) { in sdhci_omap_start_signal_voltage_switch()
535 return -EOPNOTSUPP; in sdhci_omap_start_signal_voltage_switch()
537 sdhci_omap_conf_bus_power(omap_host, ios->signal_voltage); in sdhci_omap_start_signal_voltage_switch()
544 } else if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180) { in sdhci_omap_start_signal_voltage_switch()
547 return -EOPNOTSUPP; in sdhci_omap_start_signal_voltage_switch()
549 sdhci_omap_conf_bus_power(omap_host, ios->signal_voltage); in sdhci_omap_start_signal_voltage_switch()
557 return -EOPNOTSUPP; in sdhci_omap_start_signal_voltage_switch()
574 struct device *dev = omap_host->dev; in sdhci_omap_set_timing()
576 if (!(omap_host->flags & SDHCI_OMAP_REQUIRE_IODELAY)) in sdhci_omap_set_timing()
579 if (omap_host->timing == timing) in sdhci_omap_set_timing()
584 pinctrl_state = omap_host->pinctrl_state[timing]; in sdhci_omap_set_timing()
585 ret = pinctrl_select_state(omap_host->pinctrl, pinctrl_state); in sdhci_omap_set_timing()
592 omap_host->timing = timing; in sdhci_omap_set_timing()
598 if (omap_host->bus_mode == MMC_POWER_OFF) in sdhci_omap_set_power_mode()
600 omap_host->power_mode = power_mode; in sdhci_omap_set_power_mode()
604 unsigned int mode) in sdhci_omap_set_bus_mode() argument
608 if (omap_host->bus_mode == mode) in sdhci_omap_set_bus_mode()
612 if (mode == MMC_BUSMODE_OPENDRAIN) in sdhci_omap_set_bus_mode()
618 omap_host->bus_mode = mode; in sdhci_omap_set_bus_mode()
630 sdhci_omap_set_bus_mode(omap_host, ios->bus_mode); in sdhci_omap_set_ios()
631 sdhci_omap_set_timing(omap_host, ios->timing); in sdhci_omap_set_ios()
633 sdhci_omap_set_power_mode(omap_host, ios->power_mode); in sdhci_omap_set_ios()
641 dsor = DIV_ROUND_UP(clk_get_rate(host->clk), clock); in sdhci_omap_calc_divisor()
670 unsigned long clkdiv; in sdhci_omap_set_clock() local
677 clkdiv = sdhci_omap_calc_divisor(pltfm_host, clock); in sdhci_omap_set_clock()
678 clkdiv = (clkdiv & SYSCTL_CLKD_MASK) << SYSCTL_CLKD_SHIFT; in sdhci_omap_set_clock()
679 sdhci_enable_clk(host, clkdiv); in sdhci_omap_set_clock()
684 static void sdhci_omap_set_power(struct sdhci_host *host, unsigned char mode, in sdhci_omap_set_power() argument
687 struct mmc_host *mmc = host->mmc; in sdhci_omap_set_power()
689 if (!IS_ERR(mmc->supply.vmmc)) in sdhci_omap_set_power()
690 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd); in sdhci_omap_set_power()
701 /* Switch to DMA slave mode when using external DMA */ in sdhci_omap_enable_dma()
702 if (!host->use_external_dma) in sdhci_omap_enable_dma()
714 return clk_get_rate(pltfm_host->clk) / SYSCTL_CLKD_MAX; in sdhci_omap_get_min_clock()
740 if (omap_host->power_mode == power_mode) in sdhci_omap_init_74_clocks()
746 disable_irq(host->irq); in sdhci_omap_init_74_clocks()
770 enable_irq(host->irq); in sdhci_omap_init_74_clocks()
802 if (omap_host->is_tuning) in sdhci_omap_reset()
805 if (omap_host->flags & SDHCI_OMAP_SPECIAL_RESET) { in sdhci_omap_reset()
816 dev_err(mmc_dev(host->mmc), in sdhci_omap_reset()
834 if (omap_host->is_tuning && host->cmd && !host->data_early && in sdhci_omap_irq()
844 host->cmd->error = -ETIMEDOUT; in sdhci_omap_irq()
846 host->cmd->error = -EILSEQ; in sdhci_omap_irq()
848 host->cmd = NULL; in sdhci_omap_irq()
865 if (cmd->opcode == MMC_ERASE) in sdhci_omap_set_timeout()
889 struct device *dev = omap_host->dev; in sdhci_omap_set_capabilities()
948 { .compatible = "ti,dra7-sdhci", .data = &dra7_data },
949 { .compatible = "ti,k2g-sdhci", .data = &k2g_data },
950 { .compatible = "ti,am335-sdhci", .data = &am335_data },
951 { .compatible = "ti,am437-sdhci", .data = &am437_data },
957 *sdhci_omap_iodelay_pinctrl_state(struct sdhci_omap_host *omap_host, char *mode, in sdhci_omap_iodelay_pinctrl_state() argument
960 struct device *dev = omap_host->dev; in sdhci_omap_iodelay_pinctrl_state()
961 char *version = omap_host->version; in sdhci_omap_iodelay_pinctrl_state()
962 struct pinctrl_state *pinctrl_state = ERR_PTR(-ENODEV); in sdhci_omap_iodelay_pinctrl_state()
969 snprintf(str, 20, "%s-%s", mode, version); in sdhci_omap_iodelay_pinctrl_state()
970 pinctrl_state = pinctrl_lookup_state(omap_host->pinctrl, str); in sdhci_omap_iodelay_pinctrl_state()
974 pinctrl_state = pinctrl_lookup_state(omap_host->pinctrl, mode); in sdhci_omap_iodelay_pinctrl_state()
977 dev_err(dev, "no pinctrl state for %s mode", mode); in sdhci_omap_iodelay_pinctrl_state()
988 struct device *dev = omap_host->dev; in sdhci_omap_config_iodelay_pinctrl_state()
989 struct sdhci_host *host = omap_host->host; in sdhci_omap_config_iodelay_pinctrl_state()
990 struct mmc_host *mmc = host->mmc; in sdhci_omap_config_iodelay_pinctrl_state()
991 u32 *caps = &mmc->caps; in sdhci_omap_config_iodelay_pinctrl_state()
992 u32 *caps2 = &mmc->caps2; in sdhci_omap_config_iodelay_pinctrl_state()
996 if (!(omap_host->flags & SDHCI_OMAP_REQUIRE_IODELAY)) in sdhci_omap_config_iodelay_pinctrl_state()
1004 return -ENOMEM; in sdhci_omap_config_iodelay_pinctrl_state()
1006 omap_host->pinctrl = devm_pinctrl_get(omap_host->dev); in sdhci_omap_config_iodelay_pinctrl_state()
1007 if (IS_ERR(omap_host->pinctrl)) { in sdhci_omap_config_iodelay_pinctrl_state()
1009 return PTR_ERR(omap_host->pinctrl); in sdhci_omap_config_iodelay_pinctrl_state()
1012 state = pinctrl_lookup_state(omap_host->pinctrl, "default"); in sdhci_omap_config_iodelay_pinctrl_state()
1014 dev_err(dev, "no pinctrl state for default mode\n"); in sdhci_omap_config_iodelay_pinctrl_state()
1071 omap_host->pinctrl_state = pinctrl_state; in sdhci_omap_config_iodelay_pinctrl_state()
1090 struct device *dev = &pdev->dev; in sdhci_omap_probe()
1102 return -EINVAL; in sdhci_omap_probe()
1104 data = (struct sdhci_omap_data *)match->data; in sdhci_omap_probe()
1107 return -EINVAL; in sdhci_omap_probe()
1109 offset = data->offset; in sdhci_omap_probe()
1113 return -ENXIO; in sdhci_omap_probe()
1124 omap_host->host = host; in sdhci_omap_probe()
1125 omap_host->base = host->ioaddr; in sdhci_omap_probe()
1126 omap_host->dev = dev; in sdhci_omap_probe()
1127 omap_host->power_mode = MMC_POWER_UNDEFINED; in sdhci_omap_probe()
1128 omap_host->timing = MMC_TIMING_LEGACY; in sdhci_omap_probe()
1129 omap_host->flags = data->flags; in sdhci_omap_probe()
1130 host->ioaddr += offset; in sdhci_omap_probe()
1131 host->mapbase = regs->start + offset; in sdhci_omap_probe()
1133 mmc = host->mmc; in sdhci_omap_probe()
1141 omap_host->version = "rev11"; in sdhci_omap_probe()
1143 mmc->f_max = 96000000; in sdhci_omap_probe()
1145 mmc->f_max = 48000000; in sdhci_omap_probe()
1147 mmc->f_max = 48000000; in sdhci_omap_probe()
1151 mmc->caps2 |= MMC_CAP2_NO_WRITE_PROTECT; in sdhci_omap_probe()
1153 pltfm_host->clk = devm_clk_get(dev, "fck"); in sdhci_omap_probe()
1154 if (IS_ERR(pltfm_host->clk)) { in sdhci_omap_probe()
1155 ret = PTR_ERR(pltfm_host->clk); in sdhci_omap_probe()
1159 ret = clk_set_rate(pltfm_host->clk, mmc->f_max); in sdhci_omap_probe()
1161 dev_err(dev, "failed to set clock to %d\n", mmc->f_max); in sdhci_omap_probe()
1165 omap_host->pbias = devm_regulator_get_optional(dev, "pbias"); in sdhci_omap_probe()
1166 if (IS_ERR(omap_host->pbias)) { in sdhci_omap_probe()
1167 ret = PTR_ERR(omap_host->pbias); in sdhci_omap_probe()
1168 if (ret != -ENODEV) in sdhci_omap_probe()
1172 omap_host->pbias_enabled = false; in sdhci_omap_probe()
1194 host->mmc_host_ops.start_signal_voltage_switch = in sdhci_omap_probe()
1196 host->mmc_host_ops.set_ios = sdhci_omap_set_ios; in sdhci_omap_probe()
1197 host->mmc_host_ops.card_busy = sdhci_omap_card_busy; in sdhci_omap_probe()
1198 host->mmc_host_ops.execute_tuning = sdhci_omap_execute_tuning; in sdhci_omap_probe()
1199 host->mmc_host_ops.enable_sdio_irq = sdhci_omap_enable_sdio_irq; in sdhci_omap_probe()
1202 if (of_find_property(dev->of_node, "dmas", NULL)) in sdhci_omap_probe()
1206 mmc->caps |= MMC_CAP_NEED_RSP_BUSY; in sdhci_omap_probe()
1238 struct device *dev = &pdev->dev; in sdhci_omap_remove()
1251 omap_host->con = sdhci_omap_readl(omap_host, SDHCI_OMAP_CON); in sdhci_omap_context_save()
1252 omap_host->hctl = sdhci_omap_readl(omap_host, SDHCI_OMAP_HCTL); in sdhci_omap_context_save()
1253 omap_host->sysctl = sdhci_omap_readl(omap_host, SDHCI_OMAP_SYSCTL); in sdhci_omap_context_save()
1254 omap_host->capa = sdhci_omap_readl(omap_host, SDHCI_OMAP_CAPA); in sdhci_omap_context_save()
1255 omap_host->ie = sdhci_omap_readl(omap_host, SDHCI_OMAP_IE); in sdhci_omap_context_save()
1256 omap_host->ise = sdhci_omap_readl(omap_host, SDHCI_OMAP_ISE); in sdhci_omap_context_save()
1262 sdhci_omap_writel(omap_host, SDHCI_OMAP_HCTL, omap_host->hctl); in sdhci_omap_context_restore()
1263 sdhci_omap_writel(omap_host, SDHCI_OMAP_CAPA, omap_host->capa); in sdhci_omap_context_restore()
1264 sdhci_omap_writel(omap_host, SDHCI_OMAP_HCTL, omap_host->hctl); in sdhci_omap_context_restore()
1266 sdhci_omap_writel(omap_host, SDHCI_OMAP_SYSCTL, omap_host->sysctl); in sdhci_omap_context_restore()
1267 sdhci_omap_writel(omap_host, SDHCI_OMAP_CON, omap_host->con); in sdhci_omap_context_restore()
1268 sdhci_omap_writel(omap_host, SDHCI_OMAP_IE, omap_host->ie); in sdhci_omap_context_restore()
1269 sdhci_omap_writel(omap_host, SDHCI_OMAP_ISE, omap_host->ise); in sdhci_omap_context_restore()
1313 .name = "sdhci-omap",