- Add the DT binding for the rk3576 compatible (Detlev Casanova)

- Use for_each_available_child_of_node_scoped() to remove the
   of_node_put() calls in the loop (Zhang Zekun)
 
 - Add the ability to register external callbacks for suspend/resume on
   ACPI PM driver and enable to turn it off when suspended (Marek
   Maslanka)
 
 - Use the devm_clk_get_enabled() variant on the ingenic timer (Huan
   Yang)
 
 - Add missing iounmap() on errors in msm_dt_timer_init() (Ankit
   Agrawal)
 
 - Add missing clk_disable_unprepare() in init routine error code path
   on the asm9260 and the cadence_ttc timers (Gaosheng Cui)
 
 - Use request_percpu_irq() instead of request_irq() in order to fix a
   wrong address space access reported by sparse (Uros Bizjak)
 
 - Fix comment format for the pmc_core_acpi_pm_timer_suspend_resume()
   function (Marek Maslanka)
 -----BEGIN PGP SIGNATURE-----
 
 iQEzBAABCAAdFiEEGn3N4YVz0WNVyHskqDIjiipP6E8FAmbbOBoACgkQqDIjiipP
 6E8wDwf/QkAJ/1eHSy9z+WWynRYq0j7J1/RLxmxjHa/bP7+LW0/i05JTS/ag0tcK
 2CO2yNFbsAgel3rxtnmV2xD8mzj9n2qt4Ome4nsFFWQpacIY90Amah/666ww2rhF
 sGQ9xumMbbdZ4GgDCZ/XwjrIAu+BT6WgHqWGxm5x+ElNYlMF6bIpFWHo3rKKtE1C
 yXZ2+K241A7nEhCjiflgT4R/uCG43lJj2REvUQNE0mbhTiaycOSSwvTxxUQIgoSR
 uXtifhq3GjFSul2KmdKhMNywZsmQqjfUI5f4qAeyURRnHSvz4fTXOdGH++JFNnm1
 CSaD8QfiuPq6tqXBSKwqscZqCyWxIg==
 =OZes
 -----END PGP SIGNATURE-----

Merge tag 'timers-v6.12-rc1' of https://git.linaro.org/people/daniel.lezcano/linux into timers/core

Pull clockevent/clocksource updates from Daniel Lezcano:

  - Add the DT binding for the rk3576 compatible (Detlev Casanova)

  - Use for_each_available_child_of_node_scoped() to remove the
    of_node_put() calls in the loop (Zhang Zekun)

  - Add the ability to register external callbacks for suspend/resume on
    ACPI PM driver and enable to turn it off when suspended (Marek
    Maslanka)

  - Use the devm_clk_get_enabled() variant on the ingenic timer (Huan
    Yang)

  - Add missing iounmap() on errors in msm_dt_timer_init() (Ankit
    Agrawal)

  - Add missing clk_disable_unprepare() in init routine error code path
    on the asm9260 and the cadence_ttc timers (Gaosheng Cui)

  - Use request_percpu_irq() instead of request_irq() in order to fix a
    wrong address space access reported by sparse (Uros Bizjak)

  - Fix comment format for the pmc_core_acpi_pm_timer_suspend_resume()
    function (Marek Maslanka)

Link: https://lore.kernel.org/all/6054852d-975f-4e83-850e-815f263a40c5@linaro.org
This commit is contained in:
Thomas Gleixner 2024-09-06 20:50:43 +02:00
commit d7b01b81bd
17 changed files with 129 additions and 21 deletions

View File

@ -24,6 +24,7 @@ properties:
- rockchip,rk3228-timer
- rockchip,rk3229-timer
- rockchip,rk3368-timer
- rockchip,rk3576-timer
- rockchip,rk3588-timer
- rockchip,px30-timer
- const: rockchip,rk3288-timer

View File

@ -25,6 +25,10 @@
#include <asm/io.h>
#include <asm/time.h>
static void *suspend_resume_cb_data;
static void (*suspend_resume_callback)(void *data, bool suspend);
/*
* The I/O port the PMTMR resides at.
* The location is detected during setup_arch(),
@ -58,6 +62,32 @@ u32 acpi_pm_read_verified(void)
return v2;
}
void acpi_pmtmr_register_suspend_resume_callback(void (*cb)(void *data, bool suspend), void *data)
{
suspend_resume_callback = cb;
suspend_resume_cb_data = data;
}
EXPORT_SYMBOL_GPL(acpi_pmtmr_register_suspend_resume_callback);
void acpi_pmtmr_unregister_suspend_resume_callback(void)
{
suspend_resume_callback = NULL;
suspend_resume_cb_data = NULL;
}
EXPORT_SYMBOL_GPL(acpi_pmtmr_unregister_suspend_resume_callback);
static void acpi_pm_suspend(struct clocksource *cs)
{
if (suspend_resume_callback)
suspend_resume_callback(suspend_resume_cb_data, true);
}
static void acpi_pm_resume(struct clocksource *cs)
{
if (suspend_resume_callback)
suspend_resume_callback(suspend_resume_cb_data, false);
}
static u64 acpi_pm_read(struct clocksource *cs)
{
return (u64)read_pmtmr();
@ -69,6 +99,8 @@ static struct clocksource clocksource_acpi_pm = {
.read = acpi_pm_read,
.mask = (u64)ACPI_PM_MASK,
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
.suspend = acpi_pm_suspend,
.resume = acpi_pm_resume,
};

View File

@ -1594,7 +1594,6 @@ static int __init arch_timer_mem_of_init(struct device_node *np)
{
struct arch_timer_mem *timer_mem;
struct arch_timer_mem_frame *frame;
struct device_node *frame_node;
struct resource res;
int ret = -EINVAL;
u32 rate;
@ -1608,33 +1607,29 @@ static int __init arch_timer_mem_of_init(struct device_node *np)
timer_mem->cntctlbase = res.start;
timer_mem->size = resource_size(&res);
for_each_available_child_of_node(np, frame_node) {
for_each_available_child_of_node_scoped(np, frame_node) {
u32 n;
struct arch_timer_mem_frame *frame;
if (of_property_read_u32(frame_node, "frame-number", &n)) {
pr_err(FW_BUG "Missing frame-number.\n");
of_node_put(frame_node);
goto out;
}
if (n >= ARCH_TIMER_MEM_MAX_FRAMES) {
pr_err(FW_BUG "Wrong frame-number, only 0-%u are permitted.\n",
ARCH_TIMER_MEM_MAX_FRAMES - 1);
of_node_put(frame_node);
goto out;
}
frame = &timer_mem->frame[n];
if (frame->valid) {
pr_err(FW_BUG "Duplicated frame-number.\n");
of_node_put(frame_node);
goto out;
}
if (of_address_to_resource(frame_node, 0, &res)) {
of_node_put(frame_node);
if (of_address_to_resource(frame_node, 0, &res))
goto out;
}
frame->cntbase = res.start;
frame->size = resource_size(&res);

View File

@ -210,6 +210,7 @@ static int __init asm9260_timer_init(struct device_node *np)
DRIVER_NAME, &event_dev);
if (ret) {
pr_err("Failed to setup irq!\n");
clk_disable_unprepare(clk);
return ret;
}

View File

@ -93,14 +93,10 @@ static int __init ingenic_ost_probe(struct platform_device *pdev)
return PTR_ERR(map);
}
ost->clk = devm_clk_get(dev, "ost");
ost->clk = devm_clk_get_enabled(dev, "ost");
if (IS_ERR(ost->clk))
return PTR_ERR(ost->clk);
err = clk_prepare_enable(ost->clk);
if (err)
return err;
/* Clear counter high/low registers */
if (soc_info->is64bit)
regmap_write(map, TCU_REG_OST_CNTL, 0);
@ -129,7 +125,6 @@ static int __init ingenic_ost_probe(struct platform_device *pdev)
err = clocksource_register_hz(cs, rate);
if (err) {
dev_err(dev, "clocksource registration failed");
clk_disable_unprepare(ost->clk);
return err;
}

View File

@ -120,7 +120,7 @@ static int jcore_pit_local_init(unsigned cpu)
static irqreturn_t jcore_timer_interrupt(int irq, void *dev_id)
{
struct jcore_pit *pit = this_cpu_ptr(dev_id);
struct jcore_pit *pit = dev_id;
if (clockevent_state_oneshot(&pit->ced))
jcore_pit_disable(pit);
@ -168,9 +168,8 @@ static int __init jcore_pit_init(struct device_node *node)
return -ENOMEM;
}
err = request_irq(pit_irq, jcore_timer_interrupt,
IRQF_TIMER | IRQF_PERCPU,
"jcore_pit", jcore_pit_percpu);
err = request_percpu_irq(pit_irq, jcore_timer_interrupt,
"jcore_pit", jcore_pit_percpu);
if (err) {
pr_err("pit irq request failed: %d\n", err);
free_percpu(jcore_pit_percpu);

View File

@ -435,7 +435,7 @@ static int __init ttc_setup_clockevent(struct clk *clk,
&ttcce->ttc.clk_rate_change_nb);
if (err) {
pr_warn("Unable to register clock notifier.\n");
goto out_kfree;
goto out_clk_unprepare;
}
ttcce->ttc.freq = clk_get_rate(ttcce->ttc.clk);
@ -465,13 +465,15 @@ static int __init ttc_setup_clockevent(struct clk *clk,
err = request_irq(irq, ttc_clock_event_interrupt,
IRQF_TIMER, ttcce->ce.name, ttcce);
if (err)
goto out_kfree;
goto out_clk_unprepare;
clockevents_config_and_register(&ttcce->ce,
ttcce->ttc.freq / PRESCALE, 1, 0xfffe);
return 0;
out_clk_unprepare:
clk_disable_unprepare(ttcce->ttc.clk);
out_kfree:
kfree(ttcce);
return err;

View File

@ -233,6 +233,7 @@ static int __init msm_dt_timer_init(struct device_node *np)
}
if (of_property_read_u32(np, "clock-frequency", &freq)) {
iounmap(cpu0_base);
pr_err("Unknown frequency\n");
return -EINVAL;
}
@ -243,7 +244,11 @@ static int __init msm_dt_timer_init(struct device_node *np)
freq /= 4;
writel_relaxed(DGT_CLK_CTL_DIV_4, source_base + DGT_CLK_CTL);
return msm_timer_init(freq, 32, irq, !!percpu_offset);
ret = msm_timer_init(freq, 32, irq, !!percpu_offset);
if (ret)
iounmap(cpu0_base);
return ret;
}
TIMER_OF_DECLARE(kpss_timer, "qcom,kpss-timer", msm_dt_timer_init);
TIMER_OF_DECLARE(scss_timer, "qcom,scss-timer", msm_dt_timer_init);

View File

@ -295,6 +295,8 @@ const struct pmc_reg_map adl_reg_map = {
.ppfear_buckets = CNP_PPFEAR_NUM_ENTRIES,
.pm_cfg_offset = CNP_PMC_PM_CFG_OFFSET,
.pm_read_disable_bit = CNP_PMC_READ_DISABLE_BIT,
.acpi_pm_tmr_ctl_offset = SPT_PMC_ACPI_PM_TMR_CTL_OFFSET,
.acpi_pm_tmr_disable_bit = SPT_PMC_BIT_ACPI_PM_TMR_DISABLE,
.ltr_ignore_max = ADL_NUM_IP_IGN_ALLOWED,
.lpm_num_modes = ADL_LPM_NUM_MODES,
.lpm_num_maps = ADL_LPM_NUM_MAPS,

View File

@ -200,6 +200,8 @@ const struct pmc_reg_map cnp_reg_map = {
.ppfear_buckets = CNP_PPFEAR_NUM_ENTRIES,
.pm_cfg_offset = CNP_PMC_PM_CFG_OFFSET,
.pm_read_disable_bit = CNP_PMC_READ_DISABLE_BIT,
.acpi_pm_tmr_ctl_offset = SPT_PMC_ACPI_PM_TMR_CTL_OFFSET,
.acpi_pm_tmr_disable_bit = SPT_PMC_BIT_ACPI_PM_TMR_DISABLE,
.ltr_ignore_max = CNP_NUM_IP_IGN_ALLOWED,
.etr3_offset = ETR3_OFFSET,
};

View File

@ -11,6 +11,7 @@
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/acpi_pmtmr.h>
#include <linux/bitfield.h>
#include <linux/debugfs.h>
#include <linux/delay.h>
@ -1208,6 +1209,38 @@ static bool pmc_core_is_pson_residency_enabled(struct pmc_dev *pmcdev)
return val == 1;
}
/*
* Enable or disable ACPI PM Timer
*
* This function is intended to be a callback for ACPI PM suspend/resume event.
* The ACPI PM Timer is enabled on resume only if it was enabled during suspend.
*/
static void pmc_core_acpi_pm_timer_suspend_resume(void *data, bool suspend)
{
struct pmc_dev *pmcdev = data;
struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
const struct pmc_reg_map *map = pmc->map;
bool enabled;
u32 reg;
if (!map->acpi_pm_tmr_ctl_offset)
return;
guard(mutex)(&pmcdev->lock);
if (!suspend && !pmcdev->enable_acpi_pm_timer_on_resume)
return;
reg = pmc_core_reg_read(pmc, map->acpi_pm_tmr_ctl_offset);
enabled = !(reg & map->acpi_pm_tmr_disable_bit);
if (suspend)
reg |= map->acpi_pm_tmr_disable_bit;
else
reg &= ~map->acpi_pm_tmr_disable_bit;
pmc_core_reg_write(pmc, map->acpi_pm_tmr_ctl_offset, reg);
pmcdev->enable_acpi_pm_timer_on_resume = suspend && enabled;
}
static void pmc_core_dbgfs_unregister(struct pmc_dev *pmcdev)
{
@ -1404,6 +1437,7 @@ static int pmc_core_probe(struct platform_device *pdev)
struct pmc_dev *pmcdev;
const struct x86_cpu_id *cpu_id;
int (*core_init)(struct pmc_dev *pmcdev);
const struct pmc_reg_map *map;
struct pmc *primary_pmc;
int ret;
@ -1462,6 +1496,11 @@ static int pmc_core_probe(struct platform_device *pdev)
pm_report_max_hw_sleep(FIELD_MAX(SLP_S0_RES_COUNTER_MASK) *
pmc_core_adjust_slp_s0_step(primary_pmc, 1));
map = primary_pmc->map;
if (map->acpi_pm_tmr_ctl_offset)
acpi_pmtmr_register_suspend_resume_callback(pmc_core_acpi_pm_timer_suspend_resume,
pmcdev);
device_initialized = true;
dev_info(&pdev->dev, " initialized\n");
@ -1471,6 +1510,12 @@ static int pmc_core_probe(struct platform_device *pdev)
static void pmc_core_remove(struct platform_device *pdev)
{
struct pmc_dev *pmcdev = platform_get_drvdata(pdev);
const struct pmc *pmc = pmcdev->pmcs[PMC_IDX_MAIN];
const struct pmc_reg_map *map = pmc->map;
if (map->acpi_pm_tmr_ctl_offset)
acpi_pmtmr_unregister_suspend_resume_callback();
pmc_core_dbgfs_unregister(pmcdev);
pmc_core_clean_structure(pdev);
}

View File

@ -68,6 +68,8 @@ struct telem_endpoint;
#define SPT_PMC_LTR_SCC 0x3A0
#define SPT_PMC_LTR_ISH 0x3A4
#define SPT_PMC_ACPI_PM_TMR_CTL_OFFSET 0x18FC
/* Sunrise Point: PGD PFET Enable Ack Status Registers */
enum ppfear_regs {
SPT_PMC_XRAM_PPFEAR0A = 0x590,
@ -148,6 +150,8 @@ enum ppfear_regs {
#define SPT_PMC_VRIC1_SLPS0LVEN BIT(13)
#define SPT_PMC_VRIC1_XTALSDQDIS BIT(22)
#define SPT_PMC_BIT_ACPI_PM_TMR_DISABLE BIT(1)
/* Cannonlake Power Management Controller register offsets */
#define CNP_PMC_SLPS0_DBG_OFFSET 0x10B4
#define CNP_PMC_PM_CFG_OFFSET 0x1818
@ -351,6 +355,8 @@ struct pmc_reg_map {
const u8 *lpm_reg_index;
const u32 pson_residency_offset;
const u32 pson_residency_counter_step;
const u32 acpi_pm_tmr_ctl_offset;
const u32 acpi_pm_tmr_disable_bit;
};
/**
@ -424,6 +430,8 @@ struct pmc_dev {
u32 die_c6_offset;
struct telem_endpoint *punit_ep;
struct pmc_info *regmap_list;
bool enable_acpi_pm_timer_on_resume;
};
enum pmc_index {

View File

@ -46,6 +46,8 @@ const struct pmc_reg_map icl_reg_map = {
.ppfear_buckets = ICL_PPFEAR_NUM_ENTRIES,
.pm_cfg_offset = CNP_PMC_PM_CFG_OFFSET,
.pm_read_disable_bit = CNP_PMC_READ_DISABLE_BIT,
.acpi_pm_tmr_ctl_offset = SPT_PMC_ACPI_PM_TMR_CTL_OFFSET,
.acpi_pm_tmr_disable_bit = SPT_PMC_BIT_ACPI_PM_TMR_DISABLE,
.ltr_ignore_max = ICL_NUM_IP_IGN_ALLOWED,
.etr3_offset = ETR3_OFFSET,
};

View File

@ -462,6 +462,8 @@ const struct pmc_reg_map mtl_socm_reg_map = {
.ppfear_buckets = MTL_SOCM_PPFEAR_NUM_ENTRIES,
.pm_cfg_offset = CNP_PMC_PM_CFG_OFFSET,
.pm_read_disable_bit = CNP_PMC_READ_DISABLE_BIT,
.acpi_pm_tmr_ctl_offset = SPT_PMC_ACPI_PM_TMR_CTL_OFFSET,
.acpi_pm_tmr_disable_bit = SPT_PMC_BIT_ACPI_PM_TMR_DISABLE,
.lpm_num_maps = ADL_LPM_NUM_MAPS,
.ltr_ignore_max = MTL_SOCM_NUM_IP_IGN_ALLOWED,
.lpm_res_counter_step_x2 = TGL_PMC_LPM_RES_COUNTER_STEP_X2,

View File

@ -130,6 +130,8 @@ const struct pmc_reg_map spt_reg_map = {
.ppfear_buckets = SPT_PPFEAR_NUM_ENTRIES,
.pm_cfg_offset = SPT_PMC_PM_CFG_OFFSET,
.pm_read_disable_bit = SPT_PMC_READ_DISABLE_BIT,
.acpi_pm_tmr_ctl_offset = SPT_PMC_ACPI_PM_TMR_CTL_OFFSET,
.acpi_pm_tmr_disable_bit = SPT_PMC_BIT_ACPI_PM_TMR_DISABLE,
.ltr_ignore_max = SPT_NUM_IP_IGN_ALLOWED,
.pm_vric1_offset = SPT_PMC_VRIC1_OFFSET,
};

View File

@ -197,6 +197,8 @@ const struct pmc_reg_map tgl_reg_map = {
.ppfear_buckets = ICL_PPFEAR_NUM_ENTRIES,
.pm_cfg_offset = CNP_PMC_PM_CFG_OFFSET,
.pm_read_disable_bit = CNP_PMC_READ_DISABLE_BIT,
.acpi_pm_tmr_ctl_offset = SPT_PMC_ACPI_PM_TMR_CTL_OFFSET,
.acpi_pm_tmr_disable_bit = SPT_PMC_BIT_ACPI_PM_TMR_DISABLE,
.ltr_ignore_max = TGL_NUM_IP_IGN_ALLOWED,
.lpm_num_maps = TGL_LPM_NUM_MAPS,
.lpm_res_counter_step_x2 = TGL_PMC_LPM_RES_COUNTER_STEP_X2,

View File

@ -26,6 +26,19 @@ static inline u32 acpi_pm_read_early(void)
return acpi_pm_read_verified() & ACPI_PM_MASK;
}
/**
* Register callback for suspend and resume event
*
* @cb Callback triggered on suspend and resume
* @data Data passed with the callback
*/
void acpi_pmtmr_register_suspend_resume_callback(void (*cb)(void *data, bool suspend), void *data);
/**
* Remove registered callback for suspend and resume event
*/
void acpi_pmtmr_unregister_suspend_resume_callback(void);
#else
static inline u32 acpi_pm_read_early(void)