Lines Matching +full:stm32 +full:- +full:timer +full:- +full:counter
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) STMicroelectronics 2019 - All Rights Reserved
11 #include <linux/mfd/stm32-lptimer.h>
40 regmap_write(priv->reg, STM32_LPTIM_CR, 0); in stm32_clkevent_lp_shutdown()
41 regmap_write(priv->reg, STM32_LPTIM_IER, 0); in stm32_clkevent_lp_shutdown()
43 regmap_write(priv->reg, STM32_LPTIM_ICR, STM32_LPTIM_ARRMCF); in stm32_clkevent_lp_shutdown()
55 regmap_write(priv->reg, STM32_LPTIM_CR, 0); in stm32_clkevent_lp_set_timer()
57 regmap_write(priv->reg, STM32_LPTIM_IER, STM32_LPTIM_ARRMIE); in stm32_clkevent_lp_set_timer()
59 regmap_write(priv->reg, STM32_LPTIM_CR, STM32_LPTIM_ENABLE); in stm32_clkevent_lp_set_timer()
60 /* set next event counter */ in stm32_clkevent_lp_set_timer()
61 regmap_write(priv->reg, STM32_LPTIM_ARR, evt); in stm32_clkevent_lp_set_timer()
63 /* start counter */ in stm32_clkevent_lp_set_timer()
65 regmap_write(priv->reg, STM32_LPTIM_CR, in stm32_clkevent_lp_set_timer()
68 regmap_write(priv->reg, STM32_LPTIM_CR, in stm32_clkevent_lp_set_timer()
85 return stm32_clkevent_lp_set_timer(priv->period, clkevt, true); in stm32_clkevent_lp_set_periodic()
92 return stm32_clkevent_lp_set_timer(priv->period, clkevt, false); in stm32_clkevent_lp_set_oneshot()
100 regmap_write(priv->reg, STM32_LPTIM_ICR, STM32_LPTIM_ARRMCF); in stm32_clkevent_lp_irq_handler()
102 if (clkevt->event_handler) in stm32_clkevent_lp_irq_handler()
103 clkevt->event_handler(clkevt); in stm32_clkevent_lp_irq_handler()
118 regmap_write(priv->reg, STM32_LPTIM_CFGR, i << CFGR_PSC_OFFSET); in stm32_clkevent_lp_set_prescaler()
122 priv->period = DIV_ROUND_UP(*rate, HZ); in stm32_clkevent_lp_set_prescaler()
128 priv->clkevt.name = np->full_name; in stm32_clkevent_lp_init()
129 priv->clkevt.cpumask = cpu_possible_mask; in stm32_clkevent_lp_init()
130 priv->clkevt.features = CLOCK_EVT_FEAT_PERIODIC | in stm32_clkevent_lp_init()
132 priv->clkevt.set_state_shutdown = stm32_clkevent_lp_shutdown; in stm32_clkevent_lp_init()
133 priv->clkevt.set_state_periodic = stm32_clkevent_lp_set_periodic; in stm32_clkevent_lp_init()
134 priv->clkevt.set_state_oneshot = stm32_clkevent_lp_set_oneshot; in stm32_clkevent_lp_init()
135 priv->clkevt.set_next_event = stm32_clkevent_lp_set_next_event; in stm32_clkevent_lp_init()
136 priv->clkevt.rating = STM32_LP_RATING; in stm32_clkevent_lp_init()
138 clockevents_config_and_register(&priv->clkevt, rate, 0x1, in stm32_clkevent_lp_init()
144 struct stm32_lptimer *ddata = dev_get_drvdata(pdev->dev.parent); in stm32_clkevent_lp_probe()
149 priv = devm_kzalloc(&pdev->dev, sizeof(*priv), GFP_KERNEL); in stm32_clkevent_lp_probe()
151 return -ENOMEM; in stm32_clkevent_lp_probe()
153 priv->reg = ddata->regmap; in stm32_clkevent_lp_probe()
154 ret = clk_prepare_enable(ddata->clk); in stm32_clkevent_lp_probe()
156 return -EINVAL; in stm32_clkevent_lp_probe()
158 rate = clk_get_rate(ddata->clk); in stm32_clkevent_lp_probe()
160 ret = -EINVAL; in stm32_clkevent_lp_probe()
164 irq = platform_get_irq(to_platform_device(pdev->dev.parent), 0); in stm32_clkevent_lp_probe()
170 if (of_property_read_bool(pdev->dev.parent->of_node, "wakeup-source")) { in stm32_clkevent_lp_probe()
171 ret = device_init_wakeup(&pdev->dev, true); in stm32_clkevent_lp_probe()
175 ret = dev_pm_set_wake_irq(&pdev->dev, irq); in stm32_clkevent_lp_probe()
180 ret = devm_request_irq(&pdev->dev, irq, stm32_clkevent_lp_irq_handler, in stm32_clkevent_lp_probe()
181 IRQF_TIMER, pdev->name, &priv->clkevt); in stm32_clkevent_lp_probe()
187 stm32_clkevent_lp_init(priv, pdev->dev.parent->of_node, rate); in stm32_clkevent_lp_probe()
189 priv->dev = &pdev->dev; in stm32_clkevent_lp_probe()
194 clk_disable_unprepare(ddata->clk); in stm32_clkevent_lp_probe()
199 { .compatible = "st,stm32-lptimer-timer", },
207 .name = "stm32-lptimer-timer",
214 MODULE_ALIAS("platform:stm32-lptimer-timer");
215 MODULE_DESCRIPTION("STMicroelectronics STM32 clockevent low power driver");