Lines Matching full:pmc
2 * drivers/soc/tegra/pmc.c
20 #define pr_fmt(fmt) "tegra-pmc: " fmt
46 #include <soc/tegra/pmc.h>
129 struct tegra_pmc *pmc; member
165 void (*init)(struct tegra_pmc *pmc);
166 void (*setup_irq_polarity)(struct tegra_pmc *pmc,
172 * struct tegra_pmc - NVIDIA Tegra PMC
173 * @dev: pointer to PMC device structure
224 static struct tegra_pmc *pmc = &(struct tegra_pmc) { variable
237 return readl(pmc->base + offset); in tegra_pmc_readl()
242 writel(value, pmc->base + offset); in tegra_pmc_writel()
247 if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps) in tegra_powergate_state()
255 return (pmc->soc && pmc->soc->powergates[id]); in tegra_powergate_is_valid()
260 return test_bit(id, pmc->powergates_available); in tegra_powergate_is_available()
263 static int tegra_powergate_lookup(struct tegra_pmc *pmc, const char *name) in tegra_powergate_lookup() argument
267 if (!pmc || !pmc->soc || !name) in tegra_powergate_lookup()
270 for (i = 0; i < pmc->soc->num_powergates; i++) { in tegra_powergate_lookup()
274 if (!strcmp(name, pmc->soc->powergates[i])) in tegra_powergate_lookup()
291 if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps) in tegra_powergate_set()
294 mutex_lock(&pmc->powergates_lock); in tegra_powergate_set()
297 mutex_unlock(&pmc->powergates_lock); in tegra_powergate_set()
306 mutex_unlock(&pmc->powergates_lock); in tegra_powergate_set()
315 mutex_lock(&pmc->powergates_lock); in __tegra_powergate_remove_clamping()
322 if (pmc->soc->has_gpu_clamps) { in __tegra_powergate_remove_clamping()
342 mutex_unlock(&pmc->powergates_lock); in __tegra_powergate_remove_clamping()
415 if (pg->pmc->soc->needs_mbist_war) in tegra_powergate_power_up()
574 pg->pmc = pmc; in tegra_powergate_sequence_power_up()
596 if (pmc->soc && cpuid < pmc->soc->num_cpu_powergates) in tegra_get_cpu_powergate_id()
597 return pmc->soc->cpu_powergates[cpuid]; in tegra_get_cpu_powergate_id()
654 value = readl(pmc->scratch + pmc->soc->regs->scratch0); in tegra_pmc_restart_notify()
668 writel(value, pmc->scratch + pmc->soc->regs->scratch0); in tegra_pmc_restart_notify()
691 for (i = 0; i < pmc->soc->num_powergates; i++) { in powergate_show()
696 seq_printf(s, " %9s %7s\n", pmc->soc->powergates[i], in powergate_show()
717 pmc->debugfs = debugfs_create_file("powergate", S_IRUGO, NULL, NULL, in tegra_powergate_debugfs_init()
719 if (!pmc->debugfs) in tegra_powergate_debugfs_init()
784 static void tegra_powergate_add(struct tegra_pmc *pmc, struct device_node *np) in tegra_powergate_add() argument
794 id = tegra_powergate_lookup(pmc, np->name); in tegra_powergate_add()
804 clear_bit(id, pmc->powergates_available); in tegra_powergate_add()
810 pg->pmc = pmc; in tegra_powergate_add()
880 set_bit(id, pmc->powergates_available); in tegra_powergate_add()
886 static void tegra_powergate_init(struct tegra_pmc *pmc, in tegra_powergate_init() argument
893 for (i = 0; i < pmc->soc->num_powergates; i++) in tegra_powergate_init()
894 if (pmc->soc->powergates[i]) in tegra_powergate_init()
895 set_bit(i, pmc->powergates_available); in tegra_powergate_init()
902 tegra_powergate_add(pmc, child); in tegra_powergate_init()
908 tegra_io_pad_find(struct tegra_pmc *pmc, enum tegra_io_pad id) in tegra_io_pad_find() argument
912 for (i = 0; i < pmc->soc->num_io_pads; i++) in tegra_io_pad_find()
913 if (pmc->soc->io_pads[i].id == id) in tegra_io_pad_find()
914 return &pmc->soc->io_pads[i]; in tegra_io_pad_find()
925 pad = tegra_io_pad_find(pmc, id); in tegra_io_pad_prepare()
937 *status = pmc->soc->regs->dpd_status; in tegra_io_pad_prepare()
938 *request = pmc->soc->regs->dpd_req; in tegra_io_pad_prepare()
940 *status = pmc->soc->regs->dpd2_status; in tegra_io_pad_prepare()
941 *request = pmc->soc->regs->dpd2_req; in tegra_io_pad_prepare()
944 if (pmc->clk) { in tegra_io_pad_prepare()
945 rate = clk_get_rate(pmc->clk); in tegra_io_pad_prepare()
982 if (pmc->clk) in tegra_io_pad_unprepare()
998 mutex_lock(&pmc->powergates_lock); in tegra_io_pad_power_enable()
1017 mutex_unlock(&pmc->powergates_lock); in tegra_io_pad_power_enable()
1034 mutex_lock(&pmc->powergates_lock); in tegra_io_pad_power_disable()
1053 mutex_unlock(&pmc->powergates_lock); in tegra_io_pad_power_disable()
1064 pad = tegra_io_pad_find(pmc, id); in tegra_io_pad_set_voltage()
1071 mutex_lock(&pmc->powergates_lock); in tegra_io_pad_set_voltage()
1073 if (pmc->soc->has_impl_33v_pwr) { in tegra_io_pad_set_voltage()
1099 mutex_unlock(&pmc->powergates_lock); in tegra_io_pad_set_voltage()
1112 pad = tegra_io_pad_find(pmc, id); in tegra_io_pad_get_voltage()
1119 if (pmc->soc->has_impl_33v_pwr) in tegra_io_pad_get_voltage()
1158 return pmc->suspend_mode; in tegra_pmc_get_suspend_mode()
1166 pmc->suspend_mode = mode; in tegra_pmc_set_suspend_mode()
1180 rate = clk_get_rate(pmc->clk); in tegra_pmc_enter_suspend_mode()
1190 if (rate != pmc->rate) { in tegra_pmc_enter_suspend_mode()
1193 ticks = pmc->cpu_good_time * rate + USEC_PER_SEC - 1; in tegra_pmc_enter_suspend_mode()
1197 ticks = pmc->cpu_off_time * rate + USEC_PER_SEC - 1; in tegra_pmc_enter_suspend_mode()
1203 pmc->rate = rate; in tegra_pmc_enter_suspend_mode()
1213 static int tegra_pmc_parse_dt(struct tegra_pmc *pmc, struct device_node *np) in tegra_pmc_parse_dt() argument
1221 pmc->suspend_mode = TEGRA_SUSPEND_LP0; in tegra_pmc_parse_dt()
1225 pmc->suspend_mode = TEGRA_SUSPEND_LP1; in tegra_pmc_parse_dt()
1229 pmc->suspend_mode = TEGRA_SUSPEND_LP2; in tegra_pmc_parse_dt()
1233 pmc->suspend_mode = TEGRA_SUSPEND_NONE; in tegra_pmc_parse_dt()
1238 pmc->suspend_mode = tegra_pm_validate_suspend_mode(pmc->suspend_mode); in tegra_pmc_parse_dt()
1241 pmc->suspend_mode = TEGRA_SUSPEND_NONE; in tegra_pmc_parse_dt()
1243 pmc->cpu_good_time = value; in tegra_pmc_parse_dt()
1246 pmc->suspend_mode = TEGRA_SUSPEND_NONE; in tegra_pmc_parse_dt()
1248 pmc->cpu_off_time = value; in tegra_pmc_parse_dt()
1252 pmc->suspend_mode = TEGRA_SUSPEND_NONE; in tegra_pmc_parse_dt()
1254 pmc->core_osc_time = values[0]; in tegra_pmc_parse_dt()
1255 pmc->core_pmu_time = values[1]; in tegra_pmc_parse_dt()
1258 pmc->suspend_mode = TEGRA_SUSPEND_NONE; in tegra_pmc_parse_dt()
1260 pmc->core_off_time = value; in tegra_pmc_parse_dt()
1262 pmc->corereq_high = of_property_read_bool(np, in tegra_pmc_parse_dt()
1265 pmc->sysclkreq_high = of_property_read_bool(np, in tegra_pmc_parse_dt()
1268 pmc->combined_req = of_property_read_bool(np, in tegra_pmc_parse_dt()
1271 pmc->cpu_pwr_good_en = of_property_read_bool(np, in tegra_pmc_parse_dt()
1276 if (pmc->suspend_mode == TEGRA_SUSPEND_LP0) in tegra_pmc_parse_dt()
1277 pmc->suspend_mode = TEGRA_SUSPEND_LP1; in tegra_pmc_parse_dt()
1279 pmc->lp0_vec_phys = values[0]; in tegra_pmc_parse_dt()
1280 pmc->lp0_vec_size = values[1]; in tegra_pmc_parse_dt()
1285 static void tegra_pmc_init(struct tegra_pmc *pmc) in tegra_pmc_init() argument
1287 if (pmc->soc->init) in tegra_pmc_init()
1288 pmc->soc->init(pmc); in tegra_pmc_init()
1291 static void tegra_pmc_init_tsense_reset(struct tegra_pmc *pmc) in tegra_pmc_init_tsense_reset() argument
1295 struct device *dev = pmc->dev; in tegra_pmc_init_tsense_reset()
1299 if (!pmc->soc->has_tsense_reset) in tegra_pmc_init_tsense_reset()
1302 np = of_get_child_by_name(pmc->dev->of_node, "i2c-thermtrip"); in tegra_pmc_init_tsense_reset()
1361 dev_info(pmc->dev, "emergency thermal reset enabled\n"); in tegra_pmc_init_tsense_reset()
1378 if (WARN_ON(!pmc->base || !pmc->soc)) in tegra_pmc_probe()
1381 err = tegra_pmc_parse_dt(pmc, pdev->dev.of_node); in tegra_pmc_probe()
1393 pmc->wake = devm_ioremap_resource(&pdev->dev, res); in tegra_pmc_probe()
1394 if (IS_ERR(pmc->wake)) in tegra_pmc_probe()
1395 return PTR_ERR(pmc->wake); in tegra_pmc_probe()
1397 pmc->wake = base; in tegra_pmc_probe()
1402 pmc->aotag = devm_ioremap_resource(&pdev->dev, res); in tegra_pmc_probe()
1403 if (IS_ERR(pmc->aotag)) in tegra_pmc_probe()
1404 return PTR_ERR(pmc->aotag); in tegra_pmc_probe()
1406 pmc->aotag = base; in tegra_pmc_probe()
1411 pmc->scratch = devm_ioremap_resource(&pdev->dev, res); in tegra_pmc_probe()
1412 if (IS_ERR(pmc->scratch)) in tegra_pmc_probe()
1413 return PTR_ERR(pmc->scratch); in tegra_pmc_probe()
1415 pmc->scratch = base; in tegra_pmc_probe()
1418 pmc->clk = devm_clk_get(&pdev->dev, "pclk"); in tegra_pmc_probe()
1419 if (IS_ERR(pmc->clk)) { in tegra_pmc_probe()
1420 err = PTR_ERR(pmc->clk); in tegra_pmc_probe()
1427 pmc->clk = NULL; in tegra_pmc_probe()
1430 pmc->dev = &pdev->dev; in tegra_pmc_probe()
1432 tegra_pmc_init(pmc); in tegra_pmc_probe()
1434 tegra_pmc_init_tsense_reset(pmc); in tegra_pmc_probe()
1444 debugfs_remove(pmc->debugfs); in tegra_pmc_probe()
1450 mutex_lock(&pmc->powergates_lock); in tegra_pmc_probe()
1451 iounmap(pmc->base); in tegra_pmc_probe()
1452 pmc->base = base; in tegra_pmc_probe()
1453 mutex_unlock(&pmc->powergates_lock); in tegra_pmc_probe()
1495 static void tegra20_pmc_init(struct tegra_pmc *pmc) in tegra20_pmc_init() argument
1506 if (pmc->sysclkreq_high) in tegra20_pmc_init()
1520 static void tegra20_pmc_setup_irq_polarity(struct tegra_pmc *pmc, in tegra20_pmc_setup_irq_polarity() argument
1853 static void tegra186_pmc_setup_irq_polarity(struct tegra_pmc *pmc, in tegra186_pmc_setup_irq_polarity() argument
1864 pr_err("failed to find PMC wake registers\n"); in tegra186_pmc_setup_irq_polarity()
1872 pr_err("failed to map PMC wake registers\n"); in tegra186_pmc_setup_irq_polarity()
1904 { .compatible = "nvidia,tegra194-pmc", .data = &tegra186_pmc_soc },
1905 { .compatible = "nvidia,tegra186-pmc", .data = &tegra186_pmc_soc },
1906 { .compatible = "nvidia,tegra210-pmc", .data = &tegra210_pmc_soc },
1907 { .compatible = "nvidia,tegra132-pmc", .data = &tegra124_pmc_soc },
1908 { .compatible = "nvidia,tegra124-pmc", .data = &tegra124_pmc_soc },
1909 { .compatible = "nvidia,tegra114-pmc", .data = &tegra114_pmc_soc },
1910 { .compatible = "nvidia,tegra30-pmc", .data = &tegra30_pmc_soc },
1911 { .compatible = "nvidia,tegra20-pmc", .data = &tegra20_pmc_soc },
1917 .name = "tegra-pmc",
1939 mutex_init(&pmc->powergates_lock); in tegra_pmc_early_init()
1946 * a PMC node. in tegra_pmc_early_init()
1949 * that didn't contain a PMC node. Note that in this case the in tegra_pmc_early_init()
1974 pr_err("failed to get PMC registers\n"); in tegra_pmc_early_init()
1980 pmc->base = ioremap_nocache(regs.start, resource_size(®s)); in tegra_pmc_early_init()
1981 if (!pmc->base) { in tegra_pmc_early_init()
1982 pr_err("failed to map PMC registers\n"); in tegra_pmc_early_init()
1988 pmc->soc = match->data; in tegra_pmc_early_init()
1990 tegra_powergate_init(pmc, np); in tegra_pmc_early_init()
1993 * Invert the interrupt polarity if a PMC device tree node in tegra_pmc_early_init()
1998 pmc->soc->setup_irq_polarity(pmc, np, invert); in tegra_pmc_early_init()