32 #include <linux/slab.h>
33 #include <linux/module.h>
44 struct clock_event_device
ced;
48 #define STI_CONTROL 0x00
49 #define STI_COMPA_H 0x10
50 #define STI_COMPA_L 0x14
51 #define STI_COMPB_H 0x18
52 #define STI_COMPB_L 0x1c
53 #define STI_COUNT_H 0x20
54 #define STI_COUNT_L 0x24
55 #define STI_COUNT_RAW_H 0x28
56 #define STI_COUNT_RAW_L 0x2c
57 #define STI_SET_H 0x30
58 #define STI_SET_L 0x34
59 #define STI_INTSTATUS 0x40
60 #define STI_INTRAWSTATUS 0x44
61 #define STI_INTENSET 0x48
62 #define STI_INTENCLR 0x4c
63 #define STI_INTFFCLR 0x50
159 p->
ced.event_handler(&p->
ced);
172 ret = em_sti_enable(p);
181 static void em_sti_stop(
struct em_sti_priv *p,
unsigned int user)
184 int used_before, used_after;
191 if (used_before && !used_after)
203 return em_sti_count(cs_to_em_sti(cs));
206 static int em_sti_clocksource_enable(
struct clocksource *cs)
213 __clocksource_updatefreq_hz(cs, p->
rate);
217 static void em_sti_clocksource_disable(
struct clocksource *cs)
222 static void em_sti_clocksource_resume(
struct clocksource *cs)
224 em_sti_clocksource_enable(cs);
227 static int em_sti_register_clocksource(
struct em_sti_priv *p)
231 memset(cs, 0,
sizeof(*cs));
234 cs->
read = em_sti_clocksource_read;
235 cs->
enable = em_sti_clocksource_enable;
236 cs->
disable = em_sti_clocksource_disable;
237 cs->
suspend = em_sti_clocksource_disable;
238 cs->
resume = em_sti_clocksource_resume;
245 clocksource_register_hz(cs, 1);
249 static struct em_sti_priv *ced_to_em_sti(
struct clock_event_device *
ced)
254 static void em_sti_clock_event_mode(
enum clock_event_mode
mode,
255 struct clock_event_device *
ced)
261 case CLOCK_EVT_MODE_ONESHOT:
269 case CLOCK_EVT_MODE_ONESHOT:
270 dev_info(&p->
pdev->dev,
"used for oneshot clock events\n");
274 case CLOCK_EVT_MODE_SHUTDOWN:
275 case CLOCK_EVT_MODE_UNUSED:
283 static int em_sti_clock_event_next(
unsigned long delta,
284 struct clock_event_device *ced)
290 next = em_sti_set_next(p, em_sti_count(p) + delta);
291 safe = em_sti_count(p) < (next - 1);
296 static void em_sti_register_clockevent(
struct em_sti_priv *p)
298 struct clock_event_device *ced = &p->
ced;
300 memset(ced, 0,
sizeof(*ced));
301 ced->name = dev_name(&p->
pdev->dev);
302 ced->features = CLOCK_EVT_FEAT_ONESHOT;
305 ced->set_next_event = em_sti_clock_event_next;
306 ced->set_mode = em_sti_clock_event_mode;
322 dev_err(&pdev->
dev,
"failed to allocate driver data\n");
328 platform_set_drvdata(pdev, p);
332 dev_err(&pdev->
dev,
"failed to get I/O memory\n");
347 dev_err(&pdev->
dev,
"failed to remap I/O memory\n");
354 if (IS_ERR(p->
clk)) {
356 ret = PTR_ERR(p->
clk);
362 dev_name(&pdev->
dev), p)) {
363 dev_err(&pdev->
dev,
"failed to request low IRQ\n");
369 em_sti_register_clockevent(p);
370 em_sti_register_clocksource(p);
388 { .compatible =
"renesas,em-sti", },
394 .probe = em_sti_probe,
398 .of_match_table = em_sti_dt_ids,