Lines Matching +full:cs +full:- +full:3

1 // SPDX-License-Identifier: GPL-2.0-only
3 * Emma Mobile Timer Support - STI
33 struct clocksource cs; member
55 return ioread32(p->base + offs); in em_sti_read()
61 iowrite32(value, p->base + offs); in em_sti_write()
69 ret = clk_enable(p->clk); in em_sti_enable()
71 dev_err(&p->pdev->dev, "cannot enable clock\n"); in em_sti_enable()
80 em_sti_write(p, STI_INTENCLR, 3); in em_sti_enable()
81 em_sti_write(p, STI_INTFFCLR, 3); in em_sti_enable()
92 em_sti_write(p, STI_INTENCLR, 3); in em_sti_disable()
95 clk_disable(p->clk); in em_sti_disable()
103 /* the STI hardware buffers the 48-bit count, but to in em_sti_count()
104 * break it out into two 32-bit access the registers in em_sti_count()
108 raw_spin_lock_irqsave(&p->lock, flags); in em_sti_count()
111 raw_spin_unlock_irqrestore(&p->lock, flags); in em_sti_count()
120 raw_spin_lock_irqsave(&p->lock, flags); in em_sti_set_next()
135 raw_spin_unlock_irqrestore(&p->lock, flags); in em_sti_set_next()
144 p->ced.event_handler(&p->ced); in em_sti_interrupt()
154 raw_spin_lock_irqsave(&p->lock, flags); in em_sti_start()
155 used_before = p->active[USER_CLOCKSOURCE] | p->active[USER_CLOCKEVENT]; in em_sti_start()
160 p->active[user] = 1; in em_sti_start()
161 raw_spin_unlock_irqrestore(&p->lock, flags); in em_sti_start()
171 raw_spin_lock_irqsave(&p->lock, flags); in em_sti_stop()
172 used_before = p->active[USER_CLOCKSOURCE] | p->active[USER_CLOCKEVENT]; in em_sti_stop()
173 p->active[user] = 0; in em_sti_stop()
174 used_after = p->active[USER_CLOCKSOURCE] | p->active[USER_CLOCKEVENT]; in em_sti_stop()
178 raw_spin_unlock_irqrestore(&p->lock, flags); in em_sti_stop()
181 static struct em_sti_priv *cs_to_em_sti(struct clocksource *cs) in cs_to_em_sti() argument
183 return container_of(cs, struct em_sti_priv, cs); in cs_to_em_sti()
186 static u64 em_sti_clocksource_read(struct clocksource *cs) in em_sti_clocksource_read() argument
188 return em_sti_count(cs_to_em_sti(cs)); in em_sti_clocksource_read()
191 static int em_sti_clocksource_enable(struct clocksource *cs) in em_sti_clocksource_enable() argument
193 struct em_sti_priv *p = cs_to_em_sti(cs); in em_sti_clocksource_enable()
198 static void em_sti_clocksource_disable(struct clocksource *cs) in em_sti_clocksource_disable() argument
200 em_sti_stop(cs_to_em_sti(cs), USER_CLOCKSOURCE); in em_sti_clocksource_disable()
203 static void em_sti_clocksource_resume(struct clocksource *cs) in em_sti_clocksource_resume() argument
205 em_sti_clocksource_enable(cs); in em_sti_clocksource_resume()
210 struct clocksource *cs = &p->cs; in em_sti_register_clocksource() local
212 cs->name = dev_name(&p->pdev->dev); in em_sti_register_clocksource()
213 cs->rating = 200; in em_sti_register_clocksource()
214 cs->read = em_sti_clocksource_read; in em_sti_register_clocksource()
215 cs->enable = em_sti_clocksource_enable; in em_sti_register_clocksource()
216 cs->disable = em_sti_clocksource_disable; in em_sti_register_clocksource()
217 cs->suspend = em_sti_clocksource_disable; in em_sti_register_clocksource()
218 cs->resume = em_sti_clocksource_resume; in em_sti_register_clocksource()
219 cs->mask = CLOCKSOURCE_MASK(48); in em_sti_register_clocksource()
220 cs->flags = CLOCK_SOURCE_IS_CONTINUOUS; in em_sti_register_clocksource()
222 dev_info(&p->pdev->dev, "used as clock source\n"); in em_sti_register_clocksource()
224 clocksource_register_hz(cs, p->rate); in em_sti_register_clocksource()
244 dev_info(&p->pdev->dev, "used for oneshot clock events\n"); in em_sti_clock_event_set_oneshot()
257 safe = em_sti_count(p) < (next - 1); in em_sti_clock_event_next()
264 struct clock_event_device *ced = &p->ced; in em_sti_register_clockevent()
266 ced->name = dev_name(&p->pdev->dev); in em_sti_register_clockevent()
267 ced->features = CLOCK_EVT_FEAT_ONESHOT; in em_sti_register_clockevent()
268 ced->rating = 200; in em_sti_register_clockevent()
269 ced->cpumask = cpu_possible_mask; in em_sti_register_clockevent()
270 ced->set_next_event = em_sti_clock_event_next; in em_sti_register_clockevent()
271 ced->set_state_shutdown = em_sti_clock_event_shutdown; in em_sti_register_clockevent()
272 ced->set_state_oneshot = em_sti_clock_event_set_oneshot; in em_sti_register_clockevent()
274 dev_info(&p->pdev->dev, "used for clock events\n"); in em_sti_register_clockevent()
276 clockevents_config_and_register(ced, p->rate, 2, 0xffffffff); in em_sti_register_clockevent()
284 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); in em_sti_probe()
286 return -ENOMEM; in em_sti_probe()
288 p->pdev = pdev; in em_sti_probe()
296 p->base = devm_platform_ioremap_resource(pdev, 0); in em_sti_probe()
297 if (IS_ERR(p->base)) in em_sti_probe()
298 return PTR_ERR(p->base); in em_sti_probe()
300 ret = devm_request_irq(&pdev->dev, irq, em_sti_interrupt, in em_sti_probe()
302 dev_name(&pdev->dev), p); in em_sti_probe()
304 dev_err(&pdev->dev, "failed to request low IRQ\n"); in em_sti_probe()
309 p->clk = devm_clk_get(&pdev->dev, "sclk"); in em_sti_probe()
310 if (IS_ERR(p->clk)) { in em_sti_probe()
311 dev_err(&pdev->dev, "cannot get clock\n"); in em_sti_probe()
312 return PTR_ERR(p->clk); in em_sti_probe()
315 ret = clk_prepare(p->clk); in em_sti_probe()
317 dev_err(&pdev->dev, "cannot prepare clock\n"); in em_sti_probe()
321 ret = clk_enable(p->clk); in em_sti_probe()
323 dev_err(&p->pdev->dev, "cannot enable clock\n"); in em_sti_probe()
324 clk_unprepare(p->clk); in em_sti_probe()
327 p->rate = clk_get_rate(p->clk); in em_sti_probe()
328 clk_disable(p->clk); in em_sti_probe()
330 raw_spin_lock_init(&p->lock); in em_sti_probe()
337 { .compatible = "renesas,em-sti", },