Lines Matching +full:k2g +full:- +full:gpio
1 // SPDX-License-Identifier: GPL-2.0-only
11 #include <linux/mmc/slot-gpio.h>
24 #include "sdhci-pltfm.h"
98 /* sdhci-omap controller flags */
143 return readl(host->base + host->omap_offset + offset); in sdhci_omap_readl()
149 writel(data, host->base + host->omap_offset + offset); in sdhci_omap_writel()
156 struct device *dev = omap_host->dev; in sdhci_omap_set_pbias()
158 if (IS_ERR(omap_host->pbias)) in sdhci_omap_set_pbias()
162 ret = regulator_set_voltage(omap_host->pbias, iov, iov); in sdhci_omap_set_pbias()
168 if (omap_host->pbias_enabled) in sdhci_omap_set_pbias()
171 ret = regulator_enable(omap_host->pbias); in sdhci_omap_set_pbias()
177 omap_host->pbias_enabled = true; in sdhci_omap_set_pbias()
179 if (!omap_host->pbias_enabled) in sdhci_omap_set_pbias()
182 ret = regulator_disable(omap_host->pbias); in sdhci_omap_set_pbias()
187 omap_host->pbias_enabled = false; in sdhci_omap_set_pbias()
197 struct sdhci_host *host = omap_host->host; in sdhci_omap_enable_iov()
198 struct mmc_host *mmc = host->mmc; in sdhci_omap_enable_iov()
204 if (!IS_ERR(mmc->supply.vqmmc)) { in sdhci_omap_enable_iov()
206 ret = mmc_regulator_set_vqmmc(mmc, &mmc->ios); in sdhci_omap_enable_iov()
237 dev_warn(omap_host->dev, "misconfigured CAPA: %08x\n", in sdhci_omap_conf_bus_power()
323 struct device *dev = omap_host->dev; in sdhci_omap_execute_tuning()
324 struct mmc_ios *ios = &mmc->ios; in sdhci_omap_execute_tuning()
337 if (ios->clock <= 52000000) in sdhci_omap_execute_tuning()
341 if (ios->timing == MMC_TIMING_UHS_SDR50 && !(reg & CAPA2_TSDR50)) in sdhci_omap_execute_tuning()
364 if (host->ier & SDHCI_INT_DATA_CRC) { in sdhci_omap_execute_tuning()
365 host->ier &= ~SDHCI_INT_DATA_CRC; in sdhci_omap_execute_tuning()
369 omap_host->is_tuning = true; in sdhci_omap_execute_tuning()
405 ret = -EIO; in sdhci_omap_execute_tuning()
413 if (temperature < -20000) in sdhci_omap_execute_tuning()
414 phase_delay = min(max_window + 4 * (max_len - 1) - 24, in sdhci_omap_execute_tuning()
433 * +2 to -10 range. If found, move away from it in the appropriate in sdhci_omap_execute_tuning()
443 phase_delay += i - 12; in sdhci_omap_execute_tuning()
445 phase_delay += i - 8; in sdhci_omap_execute_tuning()
447 phase_delay += i - 6; in sdhci_omap_execute_tuning()
453 for (i = 2; i >= -10; i--) { in sdhci_omap_execute_tuning()
475 ret = -EIO; in sdhci_omap_execute_tuning()
481 omap_host->is_tuning = false; in sdhci_omap_execute_tuning()
486 omap_host->is_tuning = false; in sdhci_omap_execute_tuning()
494 host->ier |= SDHCI_INT_DATA_CRC; in sdhci_omap_execute_tuning()
495 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_omap_execute_tuning()
496 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_omap_execute_tuning()
507 u32 ier = host->ier; in sdhci_omap_card_busy()
520 disable_irq(host->irq); in sdhci_omap_card_busy()
538 sdhci_writel(host, host->ier, SDHCI_INT_ENABLE); in sdhci_omap_card_busy()
539 sdhci_writel(host, host->ier, SDHCI_SIGNAL_ENABLE); in sdhci_omap_card_busy()
540 enable_irq(host->irq); in sdhci_omap_card_busy()
558 dev = omap_host->dev; in sdhci_omap_start_signal_voltage_switch()
560 if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_330) { in sdhci_omap_start_signal_voltage_switch()
563 return -EOPNOTSUPP; in sdhci_omap_start_signal_voltage_switch()
570 sdhci_omap_conf_bus_power(omap_host, ios->signal_voltage); in sdhci_omap_start_signal_voltage_switch()
576 } else if (ios->signal_voltage == MMC_SIGNAL_VOLTAGE_180) { in sdhci_omap_start_signal_voltage_switch()
579 return -EOPNOTSUPP; in sdhci_omap_start_signal_voltage_switch()
583 sdhci_omap_conf_bus_power(omap_host, ios->signal_voltage); in sdhci_omap_start_signal_voltage_switch()
589 return -EOPNOTSUPP; in sdhci_omap_start_signal_voltage_switch()
606 struct device *dev = omap_host->dev; in sdhci_omap_set_timing()
608 if (!(omap_host->flags & SDHCI_OMAP_REQUIRE_IODELAY)) in sdhci_omap_set_timing()
611 if (omap_host->timing == timing) in sdhci_omap_set_timing()
616 pinctrl_state = omap_host->pinctrl_state[timing]; in sdhci_omap_set_timing()
617 ret = pinctrl_select_state(omap_host->pinctrl, pinctrl_state); in sdhci_omap_set_timing()
624 omap_host->timing = timing; in sdhci_omap_set_timing()
630 if (omap_host->bus_mode == MMC_POWER_OFF) in sdhci_omap_set_power_mode()
632 omap_host->power_mode = power_mode; in sdhci_omap_set_power_mode()
640 if (omap_host->bus_mode == mode) in sdhci_omap_set_bus_mode()
650 omap_host->bus_mode = mode; in sdhci_omap_set_bus_mode()
662 sdhci_omap_set_bus_mode(omap_host, ios->bus_mode); in sdhci_omap_set_ios()
663 sdhci_omap_set_timing(omap_host, ios->timing); in sdhci_omap_set_ios()
665 sdhci_omap_set_power_mode(omap_host, ios->power_mode); in sdhci_omap_set_ios()
673 dsor = DIV_ROUND_UP(clk_get_rate(host->clk), clock); in sdhci_omap_calc_divisor()
719 struct mmc_host *mmc = host->mmc; in sdhci_omap_set_power()
721 if (!IS_ERR(mmc->supply.vmmc)) in sdhci_omap_set_power()
722 mmc_regulator_set_ocr(mmc, mmc->supply.vmmc, vdd); in sdhci_omap_set_power()
738 return readl(omap_host->base + 4) & 1; in sdhci_omap_has_adma()
750 if (!host->use_external_dma) in sdhci_omap_enable_dma()
762 return clk_get_rate(pltfm_host->clk) / SYSCTL_CLKD_MAX; in sdhci_omap_get_min_clock()
788 if (omap_host->power_mode == power_mode) in sdhci_omap_init_74_clocks()
794 disable_irq(host->irq); in sdhci_omap_init_74_clocks()
818 enable_irq(host->irq); in sdhci_omap_init_74_clocks()
855 if (omap_host->is_tuning) in sdhci_omap_reset()
858 if (omap_host->flags & SDHCI_OMAP_SPECIAL_RESET) { in sdhci_omap_reset()
869 dev_err(mmc_dev(host->mmc), in sdhci_omap_reset()
892 if (omap_host->is_tuning && host->cmd && !host->data_early && in sdhci_omap_irq()
902 host->cmd->error = -ETIMEDOUT; in sdhci_omap_irq()
904 host->cmd->error = -EILSEQ; in sdhci_omap_irq()
906 host->cmd = NULL; in sdhci_omap_irq()
923 if (cmd->opcode == MMC_ERASE) in sdhci_omap_set_timeout()
969 struct device *dev = omap_host->dev; in sdhci_omap_set_capabilities()
1006 host->caps &= ~mask; in sdhci_omap_set_capabilities()
1007 host->caps |= caps; in sdhci_omap_set_capabilities()
1071 { .compatible = "ti,omap2430-sdhci", .data = &omap2430_data },
1072 { .compatible = "ti,omap3-sdhci", .data = &omap3_data },
1073 { .compatible = "ti,omap4-sdhci", .data = &omap4_data },
1074 { .compatible = "ti,omap5-sdhci", .data = &omap5_data },
1075 { .compatible = "ti,dra7-sdhci", .data = &dra7_data },
1076 { .compatible = "ti,k2g-sdhci", .data = &k2g_data },
1077 { .compatible = "ti,am335-sdhci", .data = &am335_data },
1078 { .compatible = "ti,am437-sdhci", .data = &am437_data },
1087 struct device *dev = omap_host->dev; in sdhci_omap_iodelay_pinctrl_state()
1088 char *version = omap_host->version; in sdhci_omap_iodelay_pinctrl_state()
1089 struct pinctrl_state *pinctrl_state = ERR_PTR(-ENODEV); in sdhci_omap_iodelay_pinctrl_state()
1096 snprintf(str, 20, "%s-%s", mode, version); in sdhci_omap_iodelay_pinctrl_state()
1097 pinctrl_state = pinctrl_lookup_state(omap_host->pinctrl, str); in sdhci_omap_iodelay_pinctrl_state()
1101 pinctrl_state = pinctrl_lookup_state(omap_host->pinctrl, mode); in sdhci_omap_iodelay_pinctrl_state()
1115 struct device *dev = omap_host->dev; in sdhci_omap_config_iodelay_pinctrl_state()
1116 struct sdhci_host *host = omap_host->host; in sdhci_omap_config_iodelay_pinctrl_state()
1117 struct mmc_host *mmc = host->mmc; in sdhci_omap_config_iodelay_pinctrl_state()
1118 u32 *caps = &mmc->caps; in sdhci_omap_config_iodelay_pinctrl_state()
1119 u32 *caps2 = &mmc->caps2; in sdhci_omap_config_iodelay_pinctrl_state()
1123 if (!(omap_host->flags & SDHCI_OMAP_REQUIRE_IODELAY)) in sdhci_omap_config_iodelay_pinctrl_state()
1131 return -ENOMEM; in sdhci_omap_config_iodelay_pinctrl_state()
1133 omap_host->pinctrl = devm_pinctrl_get(omap_host->dev); in sdhci_omap_config_iodelay_pinctrl_state()
1134 if (IS_ERR(omap_host->pinctrl)) { in sdhci_omap_config_iodelay_pinctrl_state()
1136 return PTR_ERR(omap_host->pinctrl); in sdhci_omap_config_iodelay_pinctrl_state()
1139 state = pinctrl_lookup_state(omap_host->pinctrl, "default"); in sdhci_omap_config_iodelay_pinctrl_state()
1198 omap_host->pinctrl_state = pinctrl_state; in sdhci_omap_config_iodelay_pinctrl_state()
1217 struct device *dev = &pdev->dev; in sdhci_omap_probe()
1226 data = of_device_get_match_data(&pdev->dev); in sdhci_omap_probe()
1229 return -EINVAL; in sdhci_omap_probe()
1231 offset = data->offset; in sdhci_omap_probe()
1235 return -ENXIO; in sdhci_omap_probe()
1246 omap_host->host = host; in sdhci_omap_probe()
1247 omap_host->base = host->ioaddr; in sdhci_omap_probe()
1248 omap_host->dev = dev; in sdhci_omap_probe()
1249 omap_host->power_mode = MMC_POWER_UNDEFINED; in sdhci_omap_probe()
1250 omap_host->timing = MMC_TIMING_LEGACY; in sdhci_omap_probe()
1251 omap_host->flags = data->flags; in sdhci_omap_probe()
1252 omap_host->omap_offset = data->omap_offset; in sdhci_omap_probe()
1253 omap_host->con = -EINVAL; /* Prevent invalid restore on first resume */ in sdhci_omap_probe()
1254 host->ioaddr += offset; in sdhci_omap_probe()
1255 host->mapbase = regs->start + offset; in sdhci_omap_probe()
1257 mmc = host->mmc; in sdhci_omap_probe()
1265 omap_host->version = "rev11"; in sdhci_omap_probe()
1267 mmc->f_max = 96000000; in sdhci_omap_probe()
1269 mmc->f_max = 48000000; in sdhci_omap_probe()
1271 mmc->f_max = 48000000; in sdhci_omap_probe()
1275 mmc->caps2 |= MMC_CAP2_NO_WRITE_PROTECT; in sdhci_omap_probe()
1277 pltfm_host->clk = devm_clk_get(dev, "fck"); in sdhci_omap_probe()
1278 if (IS_ERR(pltfm_host->clk)) { in sdhci_omap_probe()
1279 ret = PTR_ERR(pltfm_host->clk); in sdhci_omap_probe()
1283 ret = clk_set_rate(pltfm_host->clk, mmc->f_max); in sdhci_omap_probe()
1285 dev_err(dev, "failed to set clock to %d\n", mmc->f_max); in sdhci_omap_probe()
1289 omap_host->pbias = devm_regulator_get_optional(dev, "pbias"); in sdhci_omap_probe()
1290 if (IS_ERR(omap_host->pbias)) { in sdhci_omap_probe()
1291 ret = PTR_ERR(omap_host->pbias); in sdhci_omap_probe()
1292 if (ret != -ENODEV) in sdhci_omap_probe()
1296 omap_host->pbias_enabled = false; in sdhci_omap_probe()
1320 host->mmc_host_ops.start_signal_voltage_switch = in sdhci_omap_probe()
1322 host->mmc_host_ops.set_ios = sdhci_omap_set_ios; in sdhci_omap_probe()
1323 host->mmc_host_ops.card_busy = sdhci_omap_card_busy; in sdhci_omap_probe()
1324 host->mmc_host_ops.execute_tuning = sdhci_omap_execute_tuning; in sdhci_omap_probe()
1325 host->mmc_host_ops.enable_sdio_irq = sdhci_omap_enable_sdio_irq; in sdhci_omap_probe()
1335 if (device_property_read_bool(dev, "ti,non-removable")) { in sdhci_omap_probe()
1336 dev_warn_once(dev, "using old ti,non-removable property\n"); in sdhci_omap_probe()
1337 mmc->caps |= MMC_CAP_NONREMOVABLE; in sdhci_omap_probe()
1341 mmc->caps |= MMC_CAP_NEED_RSP_BUSY; in sdhci_omap_probe()
1344 mmc->caps |= MMC_CAP_POWER_OFF_CARD | MMC_CAP_AGGRESSIVE_PM; in sdhci_omap_probe()
1359 * SDIO devices can use the dat1 pin as a wake-up interrupt. Some in sdhci_omap_probe()
1360 * devices like wl1xxx, use an out-of-band GPIO interrupt instead. in sdhci_omap_probe()
1362 omap_host->wakeirq = of_irq_get_byname(dev->of_node, "wakeup"); in sdhci_omap_probe()
1363 if (omap_host->wakeirq == -EPROBE_DEFER) { in sdhci_omap_probe()
1364 ret = -EPROBE_DEFER; in sdhci_omap_probe()
1367 if (omap_host->wakeirq > 0) { in sdhci_omap_probe()
1369 ret = dev_pm_set_dedicated_wake_irq(dev, omap_host->wakeirq); in sdhci_omap_probe()
1374 host->mmc->pm_caps |= MMC_PM_KEEP_POWER | MMC_PM_WAKE_SDIO_IRQ; in sdhci_omap_probe()
1399 struct device *dev = &pdev->dev; in sdhci_omap_remove()
1418 omap_host->con = sdhci_omap_readl(omap_host, SDHCI_OMAP_CON); in sdhci_omap_context_save()
1419 omap_host->hctl = sdhci_omap_readl(omap_host, SDHCI_OMAP_HCTL); in sdhci_omap_context_save()
1420 omap_host->sysctl = sdhci_omap_readl(omap_host, SDHCI_OMAP_SYSCTL); in sdhci_omap_context_save()
1421 omap_host->capa = sdhci_omap_readl(omap_host, SDHCI_OMAP_CAPA); in sdhci_omap_context_save()
1422 omap_host->ie = sdhci_omap_readl(omap_host, SDHCI_OMAP_IE); in sdhci_omap_context_save()
1423 omap_host->ise = sdhci_omap_readl(omap_host, SDHCI_OMAP_ISE); in sdhci_omap_context_save()
1429 sdhci_omap_writel(omap_host, SDHCI_OMAP_HCTL, omap_host->hctl); in sdhci_omap_context_restore()
1430 sdhci_omap_writel(omap_host, SDHCI_OMAP_CAPA, omap_host->capa); in sdhci_omap_context_restore()
1431 sdhci_omap_writel(omap_host, SDHCI_OMAP_HCTL, omap_host->hctl); in sdhci_omap_context_restore()
1433 sdhci_omap_writel(omap_host, SDHCI_OMAP_SYSCTL, omap_host->sysctl); in sdhci_omap_context_restore()
1434 sdhci_omap_writel(omap_host, SDHCI_OMAP_CON, omap_host->con); in sdhci_omap_context_restore()
1435 sdhci_omap_writel(omap_host, SDHCI_OMAP_IE, omap_host->ie); in sdhci_omap_context_restore()
1436 sdhci_omap_writel(omap_host, SDHCI_OMAP_ISE, omap_host->ise); in sdhci_omap_context_restore()
1445 if (omap_host->con != -EINVAL) in sdhci_omap_runtime_suspend()
1463 if (omap_host->con != -EINVAL) { in sdhci_omap_runtime_resume()
1483 .name = "sdhci-omap",