Lines Matching refs:rps
62 struct oxnas_rps_timer *rps = dev_id; in oxnas_rps_timer_irq() local
64 writel_relaxed(0, rps->clkevt_base + TIMER_CLRINT_REG); in oxnas_rps_timer_irq()
66 rps->clkevent.event_handler(&rps->clkevent); in oxnas_rps_timer_irq()
71 static void oxnas_rps_timer_config(struct oxnas_rps_timer *rps, in oxnas_rps_timer_config() argument
75 uint32_t cfg = rps->timer_prescaler; in oxnas_rps_timer_config()
83 writel_relaxed(period, rps->clkevt_base + TIMER_LOAD_REG); in oxnas_rps_timer_config()
84 writel_relaxed(cfg, rps->clkevt_base + TIMER_CTRL_REG); in oxnas_rps_timer_config()
89 struct oxnas_rps_timer *rps = in oxnas_rps_timer_shutdown() local
92 oxnas_rps_timer_config(rps, 0, 0); in oxnas_rps_timer_shutdown()
99 struct oxnas_rps_timer *rps = in oxnas_rps_timer_set_periodic() local
102 oxnas_rps_timer_config(rps, rps->timer_period, 1); in oxnas_rps_timer_set_periodic()
109 struct oxnas_rps_timer *rps = in oxnas_rps_timer_set_oneshot() local
112 oxnas_rps_timer_config(rps, rps->timer_period, 0); in oxnas_rps_timer_set_oneshot()
120 struct oxnas_rps_timer *rps = in oxnas_rps_timer_next_event() local
123 oxnas_rps_timer_config(rps, delta, 0); in oxnas_rps_timer_next_event()
128 static int __init oxnas_rps_clockevent_init(struct oxnas_rps_timer *rps) in oxnas_rps_clockevent_init() argument
130 ulong clk_rate = clk_get_rate(rps->clk); in oxnas_rps_clockevent_init()
134 rps->timer_prescaler = TIMER_DIV1; in oxnas_rps_clockevent_init()
135 rps->timer_period = DIV_ROUND_UP(clk_rate, HZ); in oxnas_rps_clockevent_init()
138 if (rps->timer_period > TIMER_MAX_VAL) { in oxnas_rps_clockevent_init()
139 rps->timer_prescaler = TIMER_DIV16; in oxnas_rps_clockevent_init()
141 rps->timer_period = DIV_ROUND_UP(timer_rate, HZ); in oxnas_rps_clockevent_init()
143 if (rps->timer_period > TIMER_MAX_VAL) { in oxnas_rps_clockevent_init()
144 rps->timer_prescaler = TIMER_DIV256; in oxnas_rps_clockevent_init()
146 rps->timer_period = DIV_ROUND_UP(timer_rate, HZ); in oxnas_rps_clockevent_init()
149 rps->clkevent.name = "oxnas-rps"; in oxnas_rps_clockevent_init()
150 rps->clkevent.features = CLOCK_EVT_FEAT_PERIODIC | in oxnas_rps_clockevent_init()
153 rps->clkevent.tick_resume = oxnas_rps_timer_shutdown; in oxnas_rps_clockevent_init()
154 rps->clkevent.set_state_shutdown = oxnas_rps_timer_shutdown; in oxnas_rps_clockevent_init()
155 rps->clkevent.set_state_periodic = oxnas_rps_timer_set_periodic; in oxnas_rps_clockevent_init()
156 rps->clkevent.set_state_oneshot = oxnas_rps_timer_set_oneshot; in oxnas_rps_clockevent_init()
157 rps->clkevent.set_next_event = oxnas_rps_timer_next_event; in oxnas_rps_clockevent_init()
158 rps->clkevent.rating = 200; in oxnas_rps_clockevent_init()
159 rps->clkevent.cpumask = cpu_possible_mask; in oxnas_rps_clockevent_init()
160 rps->clkevent.irq = rps->irq; in oxnas_rps_clockevent_init()
161 clockevents_config_and_register(&rps->clkevent, in oxnas_rps_clockevent_init()
168 rps->timer_prescaler, in oxnas_rps_clockevent_init()
169 rps->timer_period); in oxnas_rps_clockevent_init()
183 static int __init oxnas_rps_clocksource_init(struct oxnas_rps_timer *rps) in oxnas_rps_clocksource_init() argument
185 ulong clk_rate = clk_get_rate(rps->clk); in oxnas_rps_clocksource_init()
191 writel_relaxed(TIMER_MAX_VAL, rps->clksrc_base + TIMER_LOAD_REG); in oxnas_rps_clocksource_init()
193 rps->clksrc_base + TIMER_CTRL_REG); in oxnas_rps_clocksource_init()
195 timer_sched_base = rps->clksrc_base + TIMER_CURR_REG; in oxnas_rps_clocksource_init()
214 struct oxnas_rps_timer *rps; in oxnas_rps_timer_init() local
218 rps = kzalloc(sizeof(*rps), GFP_KERNEL); in oxnas_rps_timer_init()
219 if (!rps) in oxnas_rps_timer_init()
222 rps->clk = of_clk_get(np, 0); in oxnas_rps_timer_init()
223 if (IS_ERR(rps->clk)) { in oxnas_rps_timer_init()
224 ret = PTR_ERR(rps->clk); in oxnas_rps_timer_init()
228 ret = clk_prepare_enable(rps->clk); in oxnas_rps_timer_init()
238 rps->irq = irq_of_parse_and_map(np, 0); in oxnas_rps_timer_init()
239 if (rps->irq < 0) { in oxnas_rps_timer_init()
244 rps->clkevt_base = base + TIMER1_REG_OFFSET; in oxnas_rps_timer_init()
245 rps->clksrc_base = base + TIMER2_REG_OFFSET; in oxnas_rps_timer_init()
248 writel_relaxed(0, rps->clkevt_base + TIMER_CTRL_REG); in oxnas_rps_timer_init()
249 writel_relaxed(0, rps->clksrc_base + TIMER_CTRL_REG); in oxnas_rps_timer_init()
250 writel_relaxed(0, rps->clkevt_base + TIMER_LOAD_REG); in oxnas_rps_timer_init()
251 writel_relaxed(0, rps->clksrc_base + TIMER_LOAD_REG); in oxnas_rps_timer_init()
252 writel_relaxed(0, rps->clkevt_base + TIMER_CLRINT_REG); in oxnas_rps_timer_init()
253 writel_relaxed(0, rps->clksrc_base + TIMER_CLRINT_REG); in oxnas_rps_timer_init()
255 ret = request_irq(rps->irq, oxnas_rps_timer_irq, in oxnas_rps_timer_init()
257 "rps-timer", rps); in oxnas_rps_timer_init()
261 ret = oxnas_rps_clocksource_init(rps); in oxnas_rps_timer_init()
265 ret = oxnas_rps_clockevent_init(rps); in oxnas_rps_timer_init()
272 free_irq(rps->irq, rps); in oxnas_rps_timer_init()
276 clk_disable_unprepare(rps->clk); in oxnas_rps_timer_init()
278 clk_put(rps->clk); in oxnas_rps_timer_init()
280 kfree(rps); in oxnas_rps_timer_init()