Lines Matching +full:tegra +full:- +full:pmc

1 // SPDX-License-Identifier: GPL-2.0+
4 * Copyright (C) 2019 GRATE-DRIVER project
7 * Copyright (C) 2010-2011 NVIDIA Corporation
10 #define pr_fmt(fmt) "tegra voltage-coupler: " fmt
21 #include <soc/tegra/fuse.h>
22 #include <soc/tegra/pmc.h>
44 static int tegra20_core_limit(struct tegra_regulator_coupler *tegra, in tegra20_core_limit() argument
53 * Tegra20 SoC has critical DVFS-capable devices that are in tegra20_core_limit()
54 * permanently-active or active at a boot time, like EMC in tegra20_core_limit()
60 * the state of all DVFS-critical CORE devices is synced. in tegra20_core_limit()
62 if (tegra_pmc_core_domain_state_synced() && !tegra->sys_reboot_mode) { in tegra20_core_limit()
67 if (tegra->core_min_uV > 0) in tegra20_core_limit()
68 return tegra->core_min_uV; in tegra20_core_limit()
83 * whatever maximum value defined via board's device-tree. in tegra20_core_limit()
85 tegra->core_min_uV = core_max_uV; in tegra20_core_limit()
87 pr_info("core voltage initialized to %duV\n", tegra->core_min_uV); in tegra20_core_limit()
89 return tegra->core_min_uV; in tegra20_core_limit()
95 struct coupling_desc *c_desc = &core_rdev->coupling_desc; in tegra20_core_rtc_max_spread()
100 for (i = 1; i < c_desc->n_coupled; i++) { in tegra20_core_rtc_max_spread()
101 max_spread = core_rdev->constraints->max_spread[i - 1]; in tegra20_core_rtc_max_spread()
102 rdev = c_desc->coupled_rdevs[i]; in tegra20_core_rtc_max_spread()
108 pr_err_once("rtc-core max-spread is undefined in device-tree\n"); in tegra20_core_rtc_max_spread()
135 static int tegra20_core_rtc_update(struct tegra_regulator_coupler *tegra, in tegra20_core_rtc_update() argument
161 core_min_uV = tegra20_core_limit(tegra, core_rdev); in tegra20_core_rtc_update()
175 if (tegra->sys_suspend_mode) in tegra20_core_rtc_update()
185 return -EINVAL; in tegra20_core_rtc_update()
188 pr_err("core-cpu voltage constraint violated: %d %d\n", in tegra20_core_rtc_update()
196 pr_err("rtc-cpu voltage constraint violated: %d %d\n", in tegra20_core_rtc_update()
199 if (abs(core_uV - rtc_uV) > 170000) in tegra20_core_rtc_update()
200 pr_err("core-rtc voltage constraint violated: %d %d\n", in tegra20_core_rtc_update()
203 rtc_min_uV = max(cpu_min_uV + 125000, core_min_uV - max_spread); in tegra20_core_rtc_update()
214 core_target_uV = max(core_uV - max_spread, core_min_uV); in tegra20_core_rtc_update()
215 core_target_uV = max(rtc_uV - max_spread, core_target_uV); in tegra20_core_rtc_update()
234 rtc_target_uV = max(rtc_uV - max_spread, rtc_min_uV); in tegra20_core_rtc_update()
235 rtc_target_uV = max(core_uV - max_spread, rtc_target_uV); in tegra20_core_rtc_update()
254 static int tegra20_core_voltage_update(struct tegra_regulator_coupler *tegra, in tegra20_core_voltage_update() argument
265 return tegra20_core_rtc_update(tegra, core_rdev, rtc_rdev, in tegra20_core_voltage_update()
269 static int tegra20_cpu_voltage_update(struct tegra_regulator_coupler *tegra, in tegra20_cpu_voltage_update() argument
299 if (!tegra->cpu_min_uV) in tegra20_cpu_voltage_update()
300 tegra->cpu_min_uV = cpu_uV; in tegra20_cpu_voltage_update()
311 if (tegra->sys_reboot_mode) in tegra20_cpu_voltage_update()
312 cpu_min_uV = max(cpu_min_uV, tegra->cpu_min_uV); in tegra20_cpu_voltage_update()
315 if (tegra->sys_suspend_mode) in tegra20_cpu_voltage_update()
320 err = tegra20_core_rtc_update(tegra, core_rdev, rtc_rdev, in tegra20_cpu_voltage_update()
335 err = tegra20_core_rtc_update(tegra, core_rdev, rtc_rdev, in tegra20_cpu_voltage_update()
348 struct tegra_regulator_coupler *tegra = to_tegra_coupler(coupler); in tegra20_regulator_balance_voltage() local
349 struct regulator_dev *core_rdev = tegra->core_rdev; in tegra20_regulator_balance_voltage()
350 struct regulator_dev *cpu_rdev = tegra->cpu_rdev; in tegra20_regulator_balance_voltage()
351 struct regulator_dev *rtc_rdev = tegra->rtc_rdev; in tegra20_regulator_balance_voltage()
356 return -EINVAL; in tegra20_regulator_balance_voltage()
359 tegra->sys_reboot_mode = READ_ONCE(tegra->sys_reboot_mode_req); in tegra20_regulator_balance_voltage()
360 tegra->sys_suspend_mode = READ_ONCE(tegra->sys_suspend_mode_req); in tegra20_regulator_balance_voltage()
363 return tegra20_cpu_voltage_update(tegra, cpu_rdev, in tegra20_regulator_balance_voltage()
367 return tegra20_core_voltage_update(tegra, cpu_rdev, in tegra20_regulator_balance_voltage()
372 return -EPERM; in tegra20_regulator_balance_voltage()
375 static int tegra20_regulator_prepare_suspend(struct tegra_regulator_coupler *tegra, in tegra20_regulator_prepare_suspend() argument
380 if (!tegra->core_rdev || !tegra->rtc_rdev || !tegra->cpu_rdev) in tegra20_regulator_prepare_suspend()
390 WRITE_ONCE(tegra->sys_suspend_mode_req, sys_suspend_mode); in tegra20_regulator_prepare_suspend()
392 err = regulator_sync_voltage_rdev(tegra->cpu_rdev); in tegra20_regulator_prepare_suspend()
396 err = regulator_sync_voltage_rdev(tegra->core_rdev); in tegra20_regulator_prepare_suspend()
406 struct tegra_regulator_coupler *tegra; in tegra20_regulator_suspend() local
409 tegra = container_of(notifier, struct tegra_regulator_coupler, in tegra20_regulator_suspend()
416 ret = tegra20_regulator_prepare_suspend(tegra, true); in tegra20_regulator_suspend()
422 ret = tegra20_regulator_prepare_suspend(tegra, false); in tegra20_regulator_suspend()
432 static int tegra20_regulator_prepare_reboot(struct tegra_regulator_coupler *tegra, in tegra20_regulator_prepare_reboot() argument
437 if (!tegra->core_rdev || !tegra->rtc_rdev || !tegra->cpu_rdev) in tegra20_regulator_prepare_reboot()
440 WRITE_ONCE(tegra->sys_reboot_mode_req, true); in tegra20_regulator_prepare_reboot()
443 * Some devices use CPU soft-reboot method and in this case we in tegra20_regulator_prepare_reboot()
447 err = regulator_sync_voltage_rdev(tegra->cpu_rdev); in tegra20_regulator_prepare_reboot()
451 err = regulator_sync_voltage_rdev(tegra->core_rdev); in tegra20_regulator_prepare_reboot()
455 WRITE_ONCE(tegra->sys_reboot_mode_req, sys_reboot_mode); in tegra20_regulator_prepare_reboot()
463 struct tegra_regulator_coupler *tegra; in tegra20_regulator_reboot() local
469 tegra = container_of(notifier, struct tegra_regulator_coupler, in tegra20_regulator_reboot()
472 ret = tegra20_regulator_prepare_reboot(tegra, true); in tegra20_regulator_reboot()
480 struct tegra_regulator_coupler *tegra = to_tegra_coupler(coupler); in tegra20_regulator_attach() local
481 struct device_node *np = rdev->dev.of_node; in tegra20_regulator_attach()
483 if (of_property_read_bool(np, "nvidia,tegra-core-regulator") && in tegra20_regulator_attach()
484 !tegra->core_rdev) { in tegra20_regulator_attach()
485 tegra->core_rdev = rdev; in tegra20_regulator_attach()
489 if (of_property_read_bool(np, "nvidia,tegra-rtc-regulator") && in tegra20_regulator_attach()
490 !tegra->rtc_rdev) { in tegra20_regulator_attach()
491 tegra->rtc_rdev = rdev; in tegra20_regulator_attach()
495 if (of_property_read_bool(np, "nvidia,tegra-cpu-regulator") && in tegra20_regulator_attach()
496 !tegra->cpu_rdev) { in tegra20_regulator_attach()
497 tegra->cpu_rdev = rdev; in tegra20_regulator_attach()
501 return -EINVAL; in tegra20_regulator_attach()
507 struct tegra_regulator_coupler *tegra = to_tegra_coupler(coupler); in tegra20_regulator_detach() local
515 return -EPERM; in tegra20_regulator_detach()
517 if (tegra->core_rdev == rdev) { in tegra20_regulator_detach()
518 tegra->core_rdev = NULL; in tegra20_regulator_detach()
522 if (tegra->rtc_rdev == rdev) { in tegra20_regulator_detach()
523 tegra->rtc_rdev = NULL; in tegra20_regulator_detach()
527 if (tegra->cpu_rdev == rdev) { in tegra20_regulator_detach()
528 tegra->cpu_rdev = NULL; in tegra20_regulator_detach()
532 return -EINVAL; in tegra20_regulator_detach()