HPET (High Precision Event Timer) defines a new set of timers, which
are used by the operating system to schedule threads, interrupt the
kernel and interrupt the multimedia timer server. The operating
system can assign different timers to different applications. By
configuration, each timer can generate interrupt independently.
The Loongson-2 HPET module includes a main count and three comparators,
all of which are 32 bits wide. Among the three comparators, only
one comparator supports periodic interrupt, all three comparators
support non periodic interrupts.
Signed-off-by: Yinbo Zhu <zhuyinbo-cXZgJK919ebM1kAEIRd3EQ@xxxxxxxxxxxxxxxx>
---
+static int hpet_request_irq(struct clock_event_device *cd)
+{
+ unsigned long flags = IRQD_NO_BALANCING | IRQF_TIMER;
+
+ if (request_irq(cd->irq, hpet_irq_handler, flags, "hpet", NULL)) {
+ pr_err("Failed to register hpet interrupt\n");
+ return -1;
+ }
+
+ disable_irq(cd->irq);
+ irq_set_affinity(cd->irq, cd->cpumask);
+ enable_irq(cd->irq);
+
+ return 0;
+}
+
+static int __init loongson2_hpet_init(struct device_node *np)
+{
+ int ret;
+ struct clk *clk;
+
+ hpet_mmio_base = of_iomap(np, 0);
+ if (!hpet_mmio_base) {
+ pr_err("hpet: unable to map loongson2 hpet registers\n");
+ goto err;
+ }
+
+ ret = -EINVAL;
+ hpet_t0_irq = irq_of_parse_and_map(np, 0);
+ if (hpet_t0_irq <= 0) {
+ pr_err("hpet: unable to get IRQ from DT, %d\n", hpet_t0_irq);
+ goto err;
+ }
+
+ clk = of_clk_get(np, 0);
+ if (!IS_ERR(clk)) {
+ hpet_freq = clk_get_rate(clk);
+ clk_put(clk);
+ } else
+ goto err;
+
+ hpet_irq_flags = HPET_TN_LEVEL;
+
+ loongson2_hpet_clocksource_init();
+
+ loongson2_hpet_clockevent_init();
+
+ return 0;
+
+err:
+ iounmap(hpet_mmio_base);
+ return ret;
+}
+
+TIMER_OF_DECLARE(loongson2_hpet, "loongson,ls2k-hpet", loongson2_hpet_init);