in jcore-pit.c [136:247]
static int __init jcore_pit_init(struct device_node *node)
{
int err;
unsigned pit_irq, cpu;
unsigned long hwirq;
u32 irqprio, enable_val;
jcore_pit_base = of_iomap(node, 0);
if (!jcore_pit_base) {
pr_err("Error: Cannot map base address for J-Core PIT\n");
return -ENXIO;
}
pit_irq = irq_of_parse_and_map(node, 0);
if (!pit_irq) {
pr_err("Error: J-Core PIT has no IRQ\n");
return -ENXIO;
}
pr_info("Initializing J-Core PIT at %p IRQ %d\n",
jcore_pit_base, pit_irq);
err = clocksource_mmio_init(jcore_pit_base, "jcore_pit_cs",
NSEC_PER_SEC, 400, 32,
jcore_clocksource_read);
if (err) {
pr_err("Error registering clocksource device: %d\n", err);
return err;
}
sched_clock_register(jcore_sched_clock_read, 32, NSEC_PER_SEC);
jcore_pit_percpu = alloc_percpu(struct jcore_pit);
if (!jcore_pit_percpu) {
pr_err("Failed to allocate memory for clock event device\n");
return -ENOMEM;
}
err = request_irq(pit_irq, jcore_timer_interrupt,
IRQF_TIMER | IRQF_PERCPU,
"jcore_pit", jcore_pit_percpu);
if (err) {
pr_err("pit irq request failed: %d\n", err);
free_percpu(jcore_pit_percpu);
return err;
}
/*
* The J-Core PIT is not hard-wired to a particular IRQ, but
* integrated with the interrupt controller such that the IRQ it
* generates is programmable, as follows:
*
* The bit layout of the PIT enable register is:
*
* .....e..ppppiiiiiiii............
*
* where the .'s indicate unrelated/unused bits, e is enable,
* p is priority, and i is hard irq number.
*
* For the PIT included in AIC1 (obsolete but still in use),
* any hard irq (trap number) can be programmed via the 8
* iiiiiiii bits, and a priority (0-15) is programmable
* separately in the pppp bits.
*
* For the PIT included in AIC2 (current), the programming
* interface is equivalent modulo interrupt mapping. This is
* why a different compatible tag was not used. However only
* traps 64-127 (the ones actually intended to be used for
* interrupts, rather than syscalls/exceptions/etc.) can be
* programmed (the high 2 bits of i are ignored) and the
* priority pppp is <<2'd and or'd onto the irq number. This
* choice seems to have been made on the hardware engineering
* side under an assumption that preserving old AIC1 priority
* mappings was important. Future models will likely ignore
* the pppp field.
*/
hwirq = irq_get_irq_data(pit_irq)->hwirq;
irqprio = (hwirq >> 2) & PIT_PRIO_MASK;
enable_val = (1U << PIT_ENABLE_SHIFT)
| (hwirq << PIT_IRQ_SHIFT)
| (irqprio << PIT_PRIO_SHIFT);
for_each_present_cpu(cpu) {
struct jcore_pit *pit = per_cpu_ptr(jcore_pit_percpu, cpu);
pit->base = of_iomap(node, cpu);
if (!pit->base) {
pr_err("Unable to map PIT for cpu %u\n", cpu);
continue;
}
pit->ced.name = "jcore_pit";
pit->ced.features = CLOCK_EVT_FEAT_PERIODIC
| CLOCK_EVT_FEAT_ONESHOT
| CLOCK_EVT_FEAT_PERCPU;
pit->ced.cpumask = cpumask_of(cpu);
pit->ced.rating = 400;
pit->ced.irq = pit_irq;
pit->ced.set_state_shutdown = jcore_pit_set_state_shutdown;
pit->ced.set_state_periodic = jcore_pit_set_state_periodic;
pit->ced.set_state_oneshot = jcore_pit_set_state_oneshot;
pit->ced.set_next_event = jcore_pit_set_next_event;
pit->enable_val = enable_val;
}
cpuhp_setup_state(CPUHP_AP_JCORE_TIMER_STARTING,
"clockevents/jcore:starting",
jcore_pit_local_init, NULL);
return 0;
}