Lines Matching refs:pmc
147 struct tegra_pmc *pmc; member
225 void (*init)(struct tegra_pmc *pmc);
226 void (*setup_irq_polarity)(struct tegra_pmc *pmc,
349 static struct tegra_pmc *pmc = &(struct tegra_pmc) { variable
360 static u32 tegra_pmc_readl(struct tegra_pmc *pmc, unsigned long offset) in tegra_pmc_readl() argument
364 if (pmc->tz_only) { in tegra_pmc_readl()
368 if (pmc->dev) in tegra_pmc_readl()
369 dev_warn(pmc->dev, "%s(): SMC failed: %lu\n", in tegra_pmc_readl()
379 return readl(pmc->base + offset); in tegra_pmc_readl()
382 static void tegra_pmc_writel(struct tegra_pmc *pmc, u32 value, in tegra_pmc_writel() argument
387 if (pmc->tz_only) { in tegra_pmc_writel()
391 if (pmc->dev) in tegra_pmc_writel()
392 dev_warn(pmc->dev, "%s(): SMC failed: %lu\n", in tegra_pmc_writel()
399 writel(value, pmc->base + offset); in tegra_pmc_writel()
403 static u32 tegra_pmc_scratch_readl(struct tegra_pmc *pmc, unsigned long offset) in tegra_pmc_scratch_readl() argument
405 if (pmc->tz_only) in tegra_pmc_scratch_readl()
406 return tegra_pmc_readl(pmc, offset); in tegra_pmc_scratch_readl()
408 return readl(pmc->scratch + offset); in tegra_pmc_scratch_readl()
411 static void tegra_pmc_scratch_writel(struct tegra_pmc *pmc, u32 value, in tegra_pmc_scratch_writel() argument
414 if (pmc->tz_only) in tegra_pmc_scratch_writel()
415 tegra_pmc_writel(pmc, value, offset); in tegra_pmc_scratch_writel()
417 writel(value, pmc->scratch + offset); in tegra_pmc_scratch_writel()
427 if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps) in tegra_powergate_state()
428 return (tegra_pmc_readl(pmc, GPU_RG_CNTRL) & 0x1) == 0; in tegra_powergate_state()
430 return (tegra_pmc_readl(pmc, PWRGATE_STATUS) & BIT(id)) != 0; in tegra_powergate_state()
433 static inline bool tegra_powergate_is_valid(struct tegra_pmc *pmc, int id) in tegra_powergate_is_valid() argument
435 return (pmc->soc && pmc->soc->powergates[id]); in tegra_powergate_is_valid()
438 static inline bool tegra_powergate_is_available(struct tegra_pmc *pmc, int id) in tegra_powergate_is_available() argument
440 return test_bit(id, pmc->powergates_available); in tegra_powergate_is_available()
443 static int tegra_powergate_lookup(struct tegra_pmc *pmc, const char *name) in tegra_powergate_lookup() argument
447 if (!pmc || !pmc->soc || !name) in tegra_powergate_lookup()
450 for (i = 0; i < pmc->soc->num_powergates; i++) { in tegra_powergate_lookup()
451 if (!tegra_powergate_is_valid(pmc, i)) in tegra_powergate_lookup()
454 if (!strcmp(name, pmc->soc->powergates[i])) in tegra_powergate_lookup()
467 static int tegra_powergate_set(struct tegra_pmc *pmc, unsigned int id, in tegra_powergate_set() argument
473 if (id == TEGRA_POWERGATE_3D && pmc->soc->has_gpu_clamps) in tegra_powergate_set()
476 mutex_lock(&pmc->powergates_lock); in tegra_powergate_set()
479 mutex_unlock(&pmc->powergates_lock); in tegra_powergate_set()
483 tegra_pmc_writel(pmc, PWRGATE_TOGGLE_START | id, PWRGATE_TOGGLE); in tegra_powergate_set()
488 mutex_unlock(&pmc->powergates_lock); in tegra_powergate_set()
493 static int __tegra_powergate_remove_clamping(struct tegra_pmc *pmc, in __tegra_powergate_remove_clamping() argument
498 mutex_lock(&pmc->powergates_lock); in __tegra_powergate_remove_clamping()
505 if (pmc->soc->has_gpu_clamps) { in __tegra_powergate_remove_clamping()
506 tegra_pmc_writel(pmc, 0, GPU_RG_CNTRL); in __tegra_powergate_remove_clamping()
522 tegra_pmc_writel(pmc, mask, REMOVE_CLAMPING); in __tegra_powergate_remove_clamping()
525 mutex_unlock(&pmc->powergates_lock); in __tegra_powergate_remove_clamping()
574 err = tegra_powergate_set(pg->pmc, pg->id, true); in tegra_powergate_power_up()
586 err = __tegra_powergate_remove_clamping(pg->pmc, pg->id); in tegra_powergate_power_up()
598 if (pg->pmc->soc->needs_mbist_war) in tegra_powergate_power_up()
613 tegra_powergate_set(pg->pmc, pg->id, false); in tegra_powergate_power_up()
638 err = tegra_powergate_set(pg->pmc, pg->id, false); in tegra_powergate_power_down()
659 struct device *dev = pg->pmc->dev; in tegra_genpd_power_on()
678 struct device *dev = pg->pmc->dev; in tegra_genpd_power_off()
703 if (!tegra_powergate_is_available(pmc, id)) in tegra_powergate_power_on()
706 return tegra_powergate_set(pmc, id, true); in tegra_powergate_power_on()
716 if (!tegra_powergate_is_available(pmc, id)) in tegra_powergate_power_off()
719 return tegra_powergate_set(pmc, id, false); in tegra_powergate_power_off()
728 static int tegra_powergate_is_powered(struct tegra_pmc *pmc, unsigned int id) in tegra_powergate_is_powered() argument
730 if (!tegra_powergate_is_valid(pmc, id)) in tegra_powergate_is_powered()
742 if (!tegra_powergate_is_available(pmc, id)) in tegra_powergate_remove_clamping()
745 return __tegra_powergate_remove_clamping(pmc, id); in tegra_powergate_remove_clamping()
763 if (!tegra_powergate_is_available(pmc, id)) in tegra_powergate_sequence_power_up()
774 pg->pmc = pmc; in tegra_powergate_sequence_power_up()
778 dev_err(pmc->dev, "failed to turn on partition %d: %d\n", id, in tegra_powergate_sequence_power_up()
795 static int tegra_get_cpu_powergate_id(struct tegra_pmc *pmc, in tegra_get_cpu_powergate_id() argument
798 if (pmc->soc && cpuid < pmc->soc->num_cpu_powergates) in tegra_get_cpu_powergate_id()
799 return pmc->soc->cpu_powergates[cpuid]; in tegra_get_cpu_powergate_id()
812 id = tegra_get_cpu_powergate_id(pmc, cpuid); in tegra_pmc_cpu_is_powered()
816 return tegra_powergate_is_powered(pmc, id); in tegra_pmc_cpu_is_powered()
827 id = tegra_get_cpu_powergate_id(pmc, cpuid); in tegra_pmc_cpu_power_on()
831 return tegra_powergate_set(pmc, id, true); in tegra_pmc_cpu_power_on()
842 id = tegra_get_cpu_powergate_id(pmc, cpuid); in tegra_pmc_cpu_remove_clamping()
855 value = tegra_pmc_scratch_readl(pmc, pmc->soc->regs->scratch0); in tegra_pmc_restart_notify()
869 tegra_pmc_scratch_writel(pmc, value, pmc->soc->regs->scratch0); in tegra_pmc_restart_notify()
872 value = tegra_pmc_readl(pmc, PMC_CNTRL); in tegra_pmc_restart_notify()
874 tegra_pmc_writel(pmc, value, PMC_CNTRL); in tegra_pmc_restart_notify()
892 for (i = 0; i < pmc->soc->num_powergates; i++) { in powergate_show()
893 status = tegra_powergate_is_powered(pmc, i); in powergate_show()
897 seq_printf(s, " %9s %7s\n", pmc->soc->powergates[i], in powergate_show()
908 pmc->debugfs = debugfs_create_file("powergate", S_IRUGO, NULL, NULL, in tegra_powergate_debugfs_init()
910 if (!pmc->debugfs) in tegra_powergate_debugfs_init()
955 struct device *dev = pg->pmc->dev; in tegra_powergate_of_get_resets()
990 static int tegra_powergate_add(struct tegra_pmc *pmc, struct device_node *np) in tegra_powergate_add() argument
992 struct device *dev = pmc->dev; in tegra_powergate_add()
1001 id = tegra_powergate_lookup(pmc, np->name); in tegra_powergate_add()
1012 clear_bit(id, pmc->powergates_available); in tegra_powergate_add()
1018 pg->pmc = pmc; in tegra_powergate_add()
1020 off = !tegra_powergate_is_powered(pmc, pg->id); in tegra_powergate_add()
1072 set_bit(id, pmc->powergates_available); in tegra_powergate_add()
1080 static int tegra_powergate_init(struct tegra_pmc *pmc, in tegra_powergate_init() argument
1091 err = tegra_powergate_add(pmc, child); in tegra_powergate_init()
1114 set_bit(pg->id, pmc->powergates_available); in tegra_powergate_remove()
1142 tegra_io_pad_find(struct tegra_pmc *pmc, enum tegra_io_pad id) in tegra_io_pad_find() argument
1146 for (i = 0; i < pmc->soc->num_io_pads; i++) in tegra_io_pad_find()
1147 if (pmc->soc->io_pads[i].id == id) in tegra_io_pad_find()
1148 return &pmc->soc->io_pads[i]; in tegra_io_pad_find()
1153 static int tegra_io_pad_get_dpd_register_bit(struct tegra_pmc *pmc, in tegra_io_pad_get_dpd_register_bit() argument
1161 pad = tegra_io_pad_find(pmc, id); in tegra_io_pad_get_dpd_register_bit()
1163 dev_err(pmc->dev, "invalid I/O pad ID %u\n", id); in tegra_io_pad_get_dpd_register_bit()
1173 *status = pmc->soc->regs->dpd_status; in tegra_io_pad_get_dpd_register_bit()
1174 *request = pmc->soc->regs->dpd_req; in tegra_io_pad_get_dpd_register_bit()
1176 *status = pmc->soc->regs->dpd2_status; in tegra_io_pad_get_dpd_register_bit()
1177 *request = pmc->soc->regs->dpd2_req; in tegra_io_pad_get_dpd_register_bit()
1183 static int tegra_io_pad_prepare(struct tegra_pmc *pmc, enum tegra_io_pad id, in tegra_io_pad_prepare() argument
1190 err = tegra_io_pad_get_dpd_register_bit(pmc, id, request, status, mask); in tegra_io_pad_prepare()
1194 if (pmc->clk) { in tegra_io_pad_prepare()
1195 rate = clk_get_rate(pmc->clk); in tegra_io_pad_prepare()
1197 dev_err(pmc->dev, "failed to get clock rate\n"); in tegra_io_pad_prepare()
1201 tegra_pmc_writel(pmc, DPD_SAMPLE_ENABLE, DPD_SAMPLE); in tegra_io_pad_prepare()
1206 tegra_pmc_writel(pmc, value, SEL_DPD_TIM); in tegra_io_pad_prepare()
1212 static int tegra_io_pad_poll(struct tegra_pmc *pmc, unsigned long offset, in tegra_io_pad_poll() argument
1220 value = tegra_pmc_readl(pmc, offset); in tegra_io_pad_poll()
1230 static void tegra_io_pad_unprepare(struct tegra_pmc *pmc) in tegra_io_pad_unprepare() argument
1232 if (pmc->clk) in tegra_io_pad_unprepare()
1233 tegra_pmc_writel(pmc, DPD_SAMPLE_DISABLE, DPD_SAMPLE); in tegra_io_pad_unprepare()
1248 mutex_lock(&pmc->powergates_lock); in tegra_io_pad_power_enable()
1250 err = tegra_io_pad_prepare(pmc, id, &request, &status, &mask); in tegra_io_pad_power_enable()
1252 dev_err(pmc->dev, "failed to prepare I/O pad: %d\n", err); in tegra_io_pad_power_enable()
1256 tegra_pmc_writel(pmc, IO_DPD_REQ_CODE_OFF | mask, request); in tegra_io_pad_power_enable()
1258 err = tegra_io_pad_poll(pmc, status, mask, 0, 250); in tegra_io_pad_power_enable()
1260 dev_err(pmc->dev, "failed to enable I/O pad: %d\n", err); in tegra_io_pad_power_enable()
1264 tegra_io_pad_unprepare(pmc); in tegra_io_pad_power_enable()
1267 mutex_unlock(&pmc->powergates_lock); in tegra_io_pad_power_enable()
1284 mutex_lock(&pmc->powergates_lock); in tegra_io_pad_power_disable()
1286 err = tegra_io_pad_prepare(pmc, id, &request, &status, &mask); in tegra_io_pad_power_disable()
1288 dev_err(pmc->dev, "failed to prepare I/O pad: %d\n", err); in tegra_io_pad_power_disable()
1292 tegra_pmc_writel(pmc, IO_DPD_REQ_CODE_ON | mask, request); in tegra_io_pad_power_disable()
1294 err = tegra_io_pad_poll(pmc, status, mask, mask, 250); in tegra_io_pad_power_disable()
1296 dev_err(pmc->dev, "failed to disable I/O pad: %d\n", err); in tegra_io_pad_power_disable()
1300 tegra_io_pad_unprepare(pmc); in tegra_io_pad_power_disable()
1303 mutex_unlock(&pmc->powergates_lock); in tegra_io_pad_power_disable()
1308 static int tegra_io_pad_is_powered(struct tegra_pmc *pmc, enum tegra_io_pad id) in tegra_io_pad_is_powered() argument
1314 err = tegra_io_pad_get_dpd_register_bit(pmc, id, &request, &status, in tegra_io_pad_is_powered()
1319 value = tegra_pmc_readl(pmc, status); in tegra_io_pad_is_powered()
1324 static int tegra_io_pad_set_voltage(struct tegra_pmc *pmc, enum tegra_io_pad id, in tegra_io_pad_set_voltage() argument
1330 pad = tegra_io_pad_find(pmc, id); in tegra_io_pad_set_voltage()
1337 mutex_lock(&pmc->powergates_lock); in tegra_io_pad_set_voltage()
1339 if (pmc->soc->has_impl_33v_pwr) { in tegra_io_pad_set_voltage()
1340 value = tegra_pmc_readl(pmc, PMC_IMPL_E_33V_PWR); in tegra_io_pad_set_voltage()
1347 tegra_pmc_writel(pmc, value, PMC_IMPL_E_33V_PWR); in tegra_io_pad_set_voltage()
1350 value = tegra_pmc_readl(pmc, PMC_PWR_DET); in tegra_io_pad_set_voltage()
1352 tegra_pmc_writel(pmc, value, PMC_PWR_DET); in tegra_io_pad_set_voltage()
1355 value = tegra_pmc_readl(pmc, PMC_PWR_DET_VALUE); in tegra_io_pad_set_voltage()
1362 tegra_pmc_writel(pmc, value, PMC_PWR_DET_VALUE); in tegra_io_pad_set_voltage()
1365 mutex_unlock(&pmc->powergates_lock); in tegra_io_pad_set_voltage()
1372 static int tegra_io_pad_get_voltage(struct tegra_pmc *pmc, enum tegra_io_pad id) in tegra_io_pad_get_voltage() argument
1377 pad = tegra_io_pad_find(pmc, id); in tegra_io_pad_get_voltage()
1384 if (pmc->soc->has_impl_33v_pwr) in tegra_io_pad_get_voltage()
1385 value = tegra_pmc_readl(pmc, PMC_IMPL_E_33V_PWR); in tegra_io_pad_get_voltage()
1387 value = tegra_pmc_readl(pmc, PMC_PWR_DET_VALUE); in tegra_io_pad_get_voltage()
1422 return pmc->suspend_mode; in tegra_pmc_get_suspend_mode()
1430 pmc->suspend_mode = mode; in tegra_pmc_set_suspend_mode()
1444 rate = clk_get_rate(pmc->clk); in tegra_pmc_enter_suspend_mode()
1454 if (rate != pmc->rate) { in tegra_pmc_enter_suspend_mode()
1457 ticks = pmc->cpu_good_time * rate + USEC_PER_SEC - 1; in tegra_pmc_enter_suspend_mode()
1459 tegra_pmc_writel(pmc, ticks, PMC_CPUPWRGOOD_TIMER); in tegra_pmc_enter_suspend_mode()
1461 ticks = pmc->cpu_off_time * rate + USEC_PER_SEC - 1; in tegra_pmc_enter_suspend_mode()
1463 tegra_pmc_writel(pmc, ticks, PMC_CPUPWROFF_TIMER); in tegra_pmc_enter_suspend_mode()
1467 pmc->rate = rate; in tegra_pmc_enter_suspend_mode()
1470 value = tegra_pmc_readl(pmc, PMC_CNTRL); in tegra_pmc_enter_suspend_mode()
1473 tegra_pmc_writel(pmc, value, PMC_CNTRL); in tegra_pmc_enter_suspend_mode()
1477 static int tegra_pmc_parse_dt(struct tegra_pmc *pmc, struct device_node *np) in tegra_pmc_parse_dt() argument
1485 pmc->suspend_mode = TEGRA_SUSPEND_LP0; in tegra_pmc_parse_dt()
1489 pmc->suspend_mode = TEGRA_SUSPEND_LP1; in tegra_pmc_parse_dt()
1493 pmc->suspend_mode = TEGRA_SUSPEND_LP2; in tegra_pmc_parse_dt()
1497 pmc->suspend_mode = TEGRA_SUSPEND_NONE; in tegra_pmc_parse_dt()
1502 pmc->suspend_mode = tegra_pm_validate_suspend_mode(pmc->suspend_mode); in tegra_pmc_parse_dt()
1505 pmc->suspend_mode = TEGRA_SUSPEND_NONE; in tegra_pmc_parse_dt()
1507 pmc->cpu_good_time = value; in tegra_pmc_parse_dt()
1510 pmc->suspend_mode = TEGRA_SUSPEND_NONE; in tegra_pmc_parse_dt()
1512 pmc->cpu_off_time = value; in tegra_pmc_parse_dt()
1516 pmc->suspend_mode = TEGRA_SUSPEND_NONE; in tegra_pmc_parse_dt()
1518 pmc->core_osc_time = values[0]; in tegra_pmc_parse_dt()
1519 pmc->core_pmu_time = values[1]; in tegra_pmc_parse_dt()
1522 pmc->suspend_mode = TEGRA_SUSPEND_NONE; in tegra_pmc_parse_dt()
1524 pmc->core_off_time = value; in tegra_pmc_parse_dt()
1526 pmc->corereq_high = of_property_read_bool(np, in tegra_pmc_parse_dt()
1529 pmc->sysclkreq_high = of_property_read_bool(np, in tegra_pmc_parse_dt()
1532 pmc->combined_req = of_property_read_bool(np, in tegra_pmc_parse_dt()
1535 pmc->cpu_pwr_good_en = of_property_read_bool(np, in tegra_pmc_parse_dt()
1540 if (pmc->suspend_mode == TEGRA_SUSPEND_LP0) in tegra_pmc_parse_dt()
1541 pmc->suspend_mode = TEGRA_SUSPEND_LP1; in tegra_pmc_parse_dt()
1543 pmc->lp0_vec_phys = values[0]; in tegra_pmc_parse_dt()
1544 pmc->lp0_vec_size = values[1]; in tegra_pmc_parse_dt()
1549 static void tegra_pmc_init(struct tegra_pmc *pmc) in tegra_pmc_init() argument
1551 if (pmc->soc->init) in tegra_pmc_init()
1552 pmc->soc->init(pmc); in tegra_pmc_init()
1555 static void tegra_pmc_init_tsense_reset(struct tegra_pmc *pmc) in tegra_pmc_init_tsense_reset() argument
1559 struct device *dev = pmc->dev; in tegra_pmc_init_tsense_reset()
1563 if (!pmc->soc->has_tsense_reset) in tegra_pmc_init_tsense_reset()
1566 np = of_get_child_by_name(pmc->dev->of_node, "i2c-thermtrip"); in tegra_pmc_init_tsense_reset()
1595 value = tegra_pmc_readl(pmc, PMC_SENSOR_CTRL); in tegra_pmc_init_tsense_reset()
1597 tegra_pmc_writel(pmc, value, PMC_SENSOR_CTRL); in tegra_pmc_init_tsense_reset()
1601 tegra_pmc_writel(pmc, value, PMC_SCRATCH54); in tegra_pmc_init_tsense_reset()
1619 tegra_pmc_writel(pmc, value, PMC_SCRATCH55); in tegra_pmc_init_tsense_reset()
1621 value = tegra_pmc_readl(pmc, PMC_SENSOR_CTRL); in tegra_pmc_init_tsense_reset()
1623 tegra_pmc_writel(pmc, value, PMC_SENSOR_CTRL); in tegra_pmc_init_tsense_reset()
1625 dev_info(pmc->dev, "emergency thermal reset enabled\n"); in tegra_pmc_init_tsense_reset()
1633 struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl_dev); in tegra_io_pad_pinctrl_get_groups_count() local
1635 return pmc->soc->num_io_pads; in tegra_io_pad_pinctrl_get_groups_count()
1641 struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl); in tegra_io_pad_pinctrl_get_group_name() local
1643 return pmc->soc->io_pads[group].name; in tegra_io_pad_pinctrl_get_group_name()
1651 struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl_dev); in tegra_io_pad_pinctrl_get_group_pins() local
1653 *pins = &pmc->soc->io_pads[group].id; in tegra_io_pad_pinctrl_get_group_pins()
1671 struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl_dev); in tegra_io_pad_pinconf_get() local
1676 pad = tegra_io_pad_find(pmc, pin); in tegra_io_pad_pinconf_get()
1682 ret = tegra_io_pad_get_voltage(pmc, pad->id); in tegra_io_pad_pinconf_get()
1690 ret = tegra_io_pad_is_powered(pmc, pad->id); in tegra_io_pad_pinconf_get()
1710 struct tegra_pmc *pmc = pinctrl_dev_get_drvdata(pctl_dev); in tegra_io_pad_pinconf_set() local
1717 pad = tegra_io_pad_find(pmc, pin); in tegra_io_pad_pinconf_set()
1738 err = tegra_io_pad_set_voltage(pmc, pad->id, arg); in tegra_io_pad_pinconf_set()
1761 static int tegra_pmc_pinctrl_init(struct tegra_pmc *pmc) in tegra_pmc_pinctrl_init() argument
1765 if (!pmc->soc->num_pin_descs) in tegra_pmc_pinctrl_init()
1768 tegra_pmc_pctl_desc.name = dev_name(pmc->dev); in tegra_pmc_pinctrl_init()
1769 tegra_pmc_pctl_desc.pins = pmc->soc->pin_descs; in tegra_pmc_pinctrl_init()
1770 tegra_pmc_pctl_desc.npins = pmc->soc->num_pin_descs; in tegra_pmc_pinctrl_init()
1772 pmc->pctl_dev = devm_pinctrl_register(pmc->dev, &tegra_pmc_pctl_desc, in tegra_pmc_pinctrl_init()
1773 pmc); in tegra_pmc_pinctrl_init()
1774 if (IS_ERR(pmc->pctl_dev)) { in tegra_pmc_pinctrl_init()
1775 err = PTR_ERR(pmc->pctl_dev); in tegra_pmc_pinctrl_init()
1776 dev_err(pmc->dev, "failed to register pin controller: %d\n", in tegra_pmc_pinctrl_init()
1789 value = tegra_pmc_readl(pmc, pmc->soc->regs->rst_status); in reset_reason_show()
1790 value &= pmc->soc->regs->rst_source_mask; in reset_reason_show()
1791 value >>= pmc->soc->regs->rst_source_shift; in reset_reason_show()
1793 if (WARN_ON(value >= pmc->soc->num_reset_sources)) in reset_reason_show()
1796 return sprintf(buf, "%s\n", pmc->soc->reset_sources[value]); in reset_reason_show()
1806 value = tegra_pmc_readl(pmc, pmc->soc->regs->rst_status); in reset_level_show()
1807 value &= pmc->soc->regs->rst_level_mask; in reset_level_show()
1808 value >>= pmc->soc->regs->rst_level_shift; in reset_level_show()
1810 if (WARN_ON(value >= pmc->soc->num_reset_levels)) in reset_level_show()
1813 return sprintf(buf, "%s\n", pmc->soc->reset_levels[value]); in reset_level_show()
1818 static void tegra_pmc_reset_sysfs_init(struct tegra_pmc *pmc) in tegra_pmc_reset_sysfs_init() argument
1820 struct device *dev = pmc->dev; in tegra_pmc_reset_sysfs_init()
1823 if (pmc->soc->reset_sources) { in tegra_pmc_reset_sysfs_init()
1831 if (pmc->soc->reset_levels) { in tegra_pmc_reset_sysfs_init()
1857 struct tegra_pmc *pmc = domain->host_data; in tegra_pmc_irq_alloc() local
1858 const struct tegra_pmc_soc *soc = pmc->soc; in tegra_pmc_irq_alloc()
1877 &pmc->irq, pmc); in tegra_pmc_irq_alloc()
1881 spec.fwnode = &pmc->dev->of_node->fwnode; in tegra_pmc_irq_alloc()
1900 &pmc->irq, pmc); in tegra_pmc_irq_alloc()
1927 &pmc->irq, pmc); in tegra_pmc_irq_alloc()
1951 struct tegra_pmc *pmc = irq_data_get_irq_chip_data(data); in tegra_pmc_irq_set_wake() local
1963 writel(0x1, pmc->wake + WAKE_AOWAKE_STATUS_W(data->hwirq)); in tegra_pmc_irq_set_wake()
1966 value = readl(pmc->wake + WAKE_AOWAKE_TIER2_ROUTING(offset)); in tegra_pmc_irq_set_wake()
1973 writel(value, pmc->wake + WAKE_AOWAKE_TIER2_ROUTING(offset)); in tegra_pmc_irq_set_wake()
1976 writel(!!on, pmc->wake + WAKE_AOWAKE_MASK_W(data->hwirq)); in tegra_pmc_irq_set_wake()
1983 struct tegra_pmc *pmc = irq_data_get_irq_chip_data(data); in tegra_pmc_irq_set_type() local
1990 value = readl(pmc->wake + WAKE_AOWAKE_CNTRL(data->hwirq)); in tegra_pmc_irq_set_type()
2011 writel(value, pmc->wake + WAKE_AOWAKE_CNTRL(data->hwirq)); in tegra_pmc_irq_set_type()
2016 static int tegra_pmc_irq_init(struct tegra_pmc *pmc) in tegra_pmc_irq_init() argument
2021 np = of_irq_find_parent(pmc->dev->of_node); in tegra_pmc_irq_init()
2030 pmc->irq.name = dev_name(pmc->dev); in tegra_pmc_irq_init()
2031 pmc->irq.irq_mask = irq_chip_mask_parent; in tegra_pmc_irq_init()
2032 pmc->irq.irq_unmask = irq_chip_unmask_parent; in tegra_pmc_irq_init()
2033 pmc->irq.irq_eoi = irq_chip_eoi_parent; in tegra_pmc_irq_init()
2034 pmc->irq.irq_set_affinity = irq_chip_set_affinity_parent; in tegra_pmc_irq_init()
2035 pmc->irq.irq_set_type = tegra_pmc_irq_set_type; in tegra_pmc_irq_init()
2036 pmc->irq.irq_set_wake = tegra_pmc_irq_set_wake; in tegra_pmc_irq_init()
2038 pmc->domain = irq_domain_add_hierarchy(parent, 0, 96, pmc->dev->of_node, in tegra_pmc_irq_init()
2039 &tegra_pmc_irq_domain_ops, pmc); in tegra_pmc_irq_init()
2040 if (!pmc->domain) { in tegra_pmc_irq_init()
2041 dev_err(pmc->dev, "failed to allocate domain\n"); in tegra_pmc_irq_init()
2059 if (WARN_ON(!pmc->base || !pmc->soc)) in tegra_pmc_probe()
2062 err = tegra_pmc_parse_dt(pmc, pdev->dev.of_node); in tegra_pmc_probe()
2074 pmc->wake = devm_ioremap_resource(&pdev->dev, res); in tegra_pmc_probe()
2075 if (IS_ERR(pmc->wake)) in tegra_pmc_probe()
2076 return PTR_ERR(pmc->wake); in tegra_pmc_probe()
2078 pmc->wake = base; in tegra_pmc_probe()
2083 pmc->aotag = devm_ioremap_resource(&pdev->dev, res); in tegra_pmc_probe()
2084 if (IS_ERR(pmc->aotag)) in tegra_pmc_probe()
2085 return PTR_ERR(pmc->aotag); in tegra_pmc_probe()
2087 pmc->aotag = base; in tegra_pmc_probe()
2092 pmc->scratch = devm_ioremap_resource(&pdev->dev, res); in tegra_pmc_probe()
2093 if (IS_ERR(pmc->scratch)) in tegra_pmc_probe()
2094 return PTR_ERR(pmc->scratch); in tegra_pmc_probe()
2096 pmc->scratch = base; in tegra_pmc_probe()
2099 pmc->clk = devm_clk_get(&pdev->dev, "pclk"); in tegra_pmc_probe()
2100 if (IS_ERR(pmc->clk)) { in tegra_pmc_probe()
2101 err = PTR_ERR(pmc->clk); in tegra_pmc_probe()
2108 pmc->clk = NULL; in tegra_pmc_probe()
2111 pmc->dev = &pdev->dev; in tegra_pmc_probe()
2113 tegra_pmc_init(pmc); in tegra_pmc_probe()
2115 tegra_pmc_init_tsense_reset(pmc); in tegra_pmc_probe()
2117 tegra_pmc_reset_sysfs_init(pmc); in tegra_pmc_probe()
2132 err = tegra_pmc_pinctrl_init(pmc); in tegra_pmc_probe()
2136 err = tegra_powergate_init(pmc, pdev->dev.of_node); in tegra_pmc_probe()
2140 err = tegra_pmc_irq_init(pmc); in tegra_pmc_probe()
2144 mutex_lock(&pmc->powergates_lock); in tegra_pmc_probe()
2145 iounmap(pmc->base); in tegra_pmc_probe()
2146 pmc->base = base; in tegra_pmc_probe()
2147 mutex_unlock(&pmc->powergates_lock); in tegra_pmc_probe()
2149 platform_set_drvdata(pdev, pmc); in tegra_pmc_probe()
2158 debugfs_remove(pmc->debugfs); in tegra_pmc_probe()
2168 struct tegra_pmc *pmc = dev_get_drvdata(dev); in tegra_pmc_suspend() local
2170 tegra_pmc_writel(pmc, virt_to_phys(tegra_resume), PMC_SCRATCH41); in tegra_pmc_suspend()
2177 struct tegra_pmc *pmc = dev_get_drvdata(dev); in tegra_pmc_resume() local
2179 tegra_pmc_writel(pmc, 0x0, PMC_SCRATCH41); in tegra_pmc_resume()
2211 static void tegra20_pmc_init(struct tegra_pmc *pmc) in tegra20_pmc_init() argument
2216 value = tegra_pmc_readl(pmc, PMC_CNTRL); in tegra20_pmc_init()
2218 tegra_pmc_writel(pmc, value, PMC_CNTRL); in tegra20_pmc_init()
2220 value = tegra_pmc_readl(pmc, PMC_CNTRL); in tegra20_pmc_init()
2222 if (pmc->sysclkreq_high) in tegra20_pmc_init()
2228 tegra_pmc_writel(pmc, value, PMC_CNTRL); in tegra20_pmc_init()
2231 value = tegra_pmc_readl(pmc, PMC_CNTRL); in tegra20_pmc_init()
2233 tegra_pmc_writel(pmc, value, PMC_CNTRL); in tegra20_pmc_init()
2236 static void tegra20_pmc_setup_irq_polarity(struct tegra_pmc *pmc, in tegra20_pmc_setup_irq_polarity() argument
2242 value = tegra_pmc_readl(pmc, PMC_CNTRL); in tegra20_pmc_setup_irq_polarity()
2249 tegra_pmc_writel(pmc, value, PMC_CNTRL); in tegra20_pmc_setup_irq_polarity()
2652 static void tegra186_pmc_setup_irq_polarity(struct tegra_pmc *pmc, in tegra186_pmc_setup_irq_polarity() argument
2663 dev_err(pmc->dev, "failed to find PMC wake registers\n"); in tegra186_pmc_setup_irq_polarity()
2671 dev_err(pmc->dev, "failed to map PMC wake registers\n"); in tegra186_pmc_setup_irq_polarity()
2816 static bool __init tegra_pmc_detect_tz_only(struct tegra_pmc *pmc) in tegra_pmc_detect_tz_only() argument
2820 saved = readl(pmc->base + pmc->soc->regs->scratch0); in tegra_pmc_detect_tz_only()
2827 writel(value, pmc->base + pmc->soc->regs->scratch0); in tegra_pmc_detect_tz_only()
2828 value = readl(pmc->base + pmc->soc->regs->scratch0); in tegra_pmc_detect_tz_only()
2837 writel(saved, pmc->base + pmc->soc->regs->scratch0); in tegra_pmc_detect_tz_only()
2854 mutex_init(&pmc->powergates_lock); in tegra_pmc_early_init()
2895 pmc->base = ioremap_nocache(regs.start, resource_size(®s)); in tegra_pmc_early_init()
2896 if (!pmc->base) { in tegra_pmc_early_init()
2903 pmc->soc = match->data; in tegra_pmc_early_init()
2905 if (pmc->soc->maybe_tz_only) in tegra_pmc_early_init()
2906 pmc->tz_only = tegra_pmc_detect_tz_only(pmc); in tegra_pmc_early_init()
2909 for (i = 0; i < pmc->soc->num_powergates; i++) in tegra_pmc_early_init()
2910 if (pmc->soc->powergates[i]) in tegra_pmc_early_init()
2911 set_bit(i, pmc->powergates_available); in tegra_pmc_early_init()
2919 pmc->soc->setup_irq_polarity(pmc, np, invert); in tegra_pmc_early_init()