Lines Matching refs:p

53 static inline unsigned long em_sti_read(struct em_sti_priv *p, int offs)  in em_sti_read()  argument
55 return ioread32(p->base + offs); in em_sti_read()
58 static inline void em_sti_write(struct em_sti_priv *p, int offs, in em_sti_write() argument
61 iowrite32(value, p->base + offs); in em_sti_write()
64 static int em_sti_enable(struct em_sti_priv *p) in em_sti_enable() argument
69 ret = clk_enable(p->clk); in em_sti_enable()
71 dev_err(&p->pdev->dev, "cannot enable clock\n"); in em_sti_enable()
76 em_sti_write(p, STI_SET_H, 0x40000000); in em_sti_enable()
77 em_sti_write(p, STI_SET_L, 0x00000000); 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()
84 em_sti_write(p, STI_CONTROL, 1); in em_sti_enable()
89 static void em_sti_disable(struct em_sti_priv *p) in em_sti_disable() argument
92 em_sti_write(p, STI_INTENCLR, 3); in em_sti_disable()
95 clk_disable(p->clk); in em_sti_disable()
98 static u64 em_sti_count(struct em_sti_priv *p) in em_sti_count() argument
108 raw_spin_lock_irqsave(&p->lock, flags); in em_sti_count()
109 ticks = (u64)(em_sti_read(p, STI_COUNT_H) & 0xffff) << 32; in em_sti_count()
110 ticks |= em_sti_read(p, STI_COUNT_L); in em_sti_count()
111 raw_spin_unlock_irqrestore(&p->lock, flags); in em_sti_count()
116 static u64 em_sti_set_next(struct em_sti_priv *p, u64 next) in em_sti_set_next() argument
120 raw_spin_lock_irqsave(&p->lock, flags); in em_sti_set_next()
123 em_sti_write(p, STI_INTENCLR, 1); in em_sti_set_next()
126 em_sti_write(p, STI_COMPA_H, next >> 32); in em_sti_set_next()
127 em_sti_write(p, STI_COMPA_L, next & 0xffffffff); in em_sti_set_next()
130 em_sti_write(p, STI_INTFFCLR, 1); in em_sti_set_next()
133 em_sti_write(p, STI_INTENSET, 1); in em_sti_set_next()
135 raw_spin_unlock_irqrestore(&p->lock, flags); in em_sti_set_next()
142 struct em_sti_priv *p = dev_id; in em_sti_interrupt() local
144 p->ced.event_handler(&p->ced); in em_sti_interrupt()
148 static int em_sti_start(struct em_sti_priv *p, unsigned int user) in em_sti_start() argument
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()
157 ret = em_sti_enable(p); 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()
166 static void em_sti_stop(struct em_sti_priv *p, unsigned int user) in em_sti_stop() argument
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()
177 em_sti_disable(p); in em_sti_stop()
178 raw_spin_unlock_irqrestore(&p->lock, flags); in em_sti_stop()
193 struct em_sti_priv *p = cs_to_em_sti(cs); in em_sti_clocksource_enable() local
195 return em_sti_start(p, USER_CLOCKSOURCE); in em_sti_clocksource_enable()
208 static int em_sti_register_clocksource(struct em_sti_priv *p) in em_sti_register_clocksource() argument
210 struct clocksource *cs = &p->cs; in em_sti_register_clocksource()
212 cs->name = dev_name(&p->pdev->dev); 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()
235 struct em_sti_priv *p = ced_to_em_sti(ced); in em_sti_clock_event_shutdown() local
236 em_sti_stop(p, USER_CLOCKEVENT); in em_sti_clock_event_shutdown()
242 struct em_sti_priv *p = ced_to_em_sti(ced); in em_sti_clock_event_set_oneshot() local
244 dev_info(&p->pdev->dev, "used for oneshot clock events\n"); in em_sti_clock_event_set_oneshot()
245 em_sti_start(p, USER_CLOCKEVENT); in em_sti_clock_event_set_oneshot()
252 struct em_sti_priv *p = ced_to_em_sti(ced); in em_sti_clock_event_next() local
256 next = em_sti_set_next(p, em_sti_count(p) + delta); in em_sti_clock_event_next()
257 safe = em_sti_count(p) < (next - 1); in em_sti_clock_event_next()
262 static void em_sti_register_clockevent(struct em_sti_priv *p) in em_sti_register_clockevent() argument
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()
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()
281 struct em_sti_priv *p; in em_sti_probe() local
284 p = devm_kzalloc(&pdev->dev, sizeof(*p), GFP_KERNEL); in em_sti_probe()
285 if (p == NULL) in em_sti_probe()
288 p->pdev = pdev; in em_sti_probe()
289 platform_set_drvdata(pdev, p); 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()
302 dev_name(&pdev->dev), p); 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()
312 return PTR_ERR(p->clk); in em_sti_probe()
315 ret = clk_prepare(p->clk); 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()
331 em_sti_register_clockevent(p); in em_sti_probe()
332 em_sti_register_clocksource(p); in em_sti_probe()