Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1561797
| From | fu.wei@linaro.org |
|---|---|
| Newsgroups | linux.kernel |
| Subject | [PATCH v20 12/17] clocksource/drivers/arm_arch_timer: Refactor MMIO timer probing. |
| Date | 2017-01-18 14:40 +0100 |
| Message-ID | <t0YD0-4Gk-7@gated-at.bofh.it> (permalink) |
| References | <t0Ytk-4D1-15@gated-at.bofh.it> |
| Organization | linux.* mail to news gateway |
From: Fu Wei <fu.wei@linaro.org>
Currently the code to probe MMIO architected timers mixes DT parsing with
actual poking of hardware. This makes the code harder than necessary to
understand, and makes it difficult to add support for probing via ACPI.
This patch factors all the DT-specific logic out of arch_timer_mem_init(),
into a new function arch_timer_mem_of_init().
The former pokes the hardware and determines the suitablility of frames
based on a datastructure populated by the latter.
This cleanly separates the two and will make it possible to add probing
using the ACPI GTDT in subsequent patches.
Signed-off-by: Fu Wei <fu.wei@linaro.org>
---
drivers/clocksource/arm_arch_timer.c | 142 ++++++++++++++++++++++++-----------
1 file changed, 99 insertions(+), 43 deletions(-)
diff --git a/drivers/clocksource/arm_arch_timer.c b/drivers/clocksource/arm_arch_timer.c
index 9db5fb9..6e8a20c 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -927,17 +927,17 @@ static int __init arch_timer_of_init(struct device_node *np)
CLOCKSOURCE_OF_DECLARE(armv7_arch_timer, "arm,armv7-timer", arch_timer_of_init);
CLOCKSOURCE_OF_DECLARE(armv8_arch_timer, "arm,armv8-timer", arch_timer_of_init);
-static int __init arch_timer_mem_init(struct device_node *np)
+static int __init arch_timer_mem_init(struct arch_timer_mem *timer_mem)
{
- struct device_node *frame, *best_frame = NULL;
void __iomem *cntctlbase, *base;
- unsigned int irq, ret = -EINVAL;
+ struct arch_timer_mem_frame *best_frame = NULL;
+ unsigned int irq;
u32 cnttidr;
+ int i, ret;
- arch_timers_present |= ARCH_TIMER_TYPE_MEM;
- cntctlbase = of_iomap(np, 0);
+ cntctlbase = ioremap(timer_mem->cntctlbase, timer_mem->size);
if (!cntctlbase) {
- pr_err("Can't find CNTCTLBase\n");
+ pr_err("Can't map CNTCTLBase.\n");
return -ENXIO;
}
@@ -947,26 +947,18 @@ static int __init arch_timer_mem_init(struct device_node *np)
* Try to find a virtual capable frame. Otherwise fall back to a
* physical capable frame.
*/
- for_each_available_child_of_node(np, frame) {
- int n;
- u32 cntacr;
-
- if (of_property_read_u32(frame, "frame-number", &n)) {
- pr_err("Missing frame-number\n");
- of_node_put(frame);
- goto out;
- }
+ for (i = 0; i < timer_mem->num_frames; i++) {
+ u32 cntacr = CNTACR_RFRQ | CNTACR_RWPT | CNTACR_RPCT |
+ CNTACR_RWVT | CNTACR_RVOFF | CNTACR_RVCT;
+ int n = timer_mem->frame[i].frame_nr;
/* Try enabling everything, and see what sticks */
- cntacr = CNTACR_RFRQ | CNTACR_RWPT | CNTACR_RPCT |
- CNTACR_RWVT | CNTACR_RVOFF | CNTACR_RVCT;
writel_relaxed(cntacr, cntctlbase + CNTACR(n));
cntacr = readl_relaxed(cntctlbase + CNTACR(n));
if ((cnttidr & CNTTIDR_VIRT(n)) &&
!(~cntacr & (CNTACR_RWVT | CNTACR_RVCT))) {
- of_node_put(best_frame);
- best_frame = frame;
+ best_frame = &timer_mem->frame[i];
arch_timer_mem_use_virtual = true;
break;
}
@@ -974,51 +966,115 @@ static int __init arch_timer_mem_init(struct device_node *np)
if (~cntacr & (CNTACR_RWPT | CNTACR_RPCT))
continue;
- of_node_put(best_frame);
- best_frame = of_node_get(frame);
+ best_frame = &timer_mem->frame[i];
}
+ iounmap(cntctlbase);
- ret= -ENXIO;
- base = arch_counter_base = of_io_request_and_map(best_frame, 0,
- "arch_mem_timer");
- if (IS_ERR(base)) {
- pr_err("Can't map frame's registers\n");
- goto out;
+ if (!best_frame) {
+ pr_err("Can't find frame for register\n");
+ return -EINVAL;
}
if (arch_timer_mem_use_virtual)
- irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_VIRT_SPI);
+ irq = best_frame->virt_irq;
else
- irq = irq_of_parse_and_map(best_frame, ARCH_TIMER_PHYS_SPI);
+ irq = best_frame->phys_irq;
- ret = -EINVAL;
if (!irq) {
pr_err("Frame missing %s irq.\n",
arch_timer_mem_use_virtual ? "virt" : "phys");
- goto out;
+ return -EINVAL;
}
- /*
- * Try to determine the frequency from the device tree,
- * if fail, get the frequency from the CNTFRQ reg of MMIO timer.
- */
- if (!arch_timer_rate &&
- of_property_read_u32(np, "clock-frequency", &arch_timer_rate))
- arch_timer_mem_detect_rate(base);
+ if (!request_mem_region(best_frame->cntbase, best_frame->size,
+ "arch_mem_timer"))
+ return -EBUSY;
+
+ base = ioremap(best_frame->cntbase, best_frame->size);
+ if (!base) {
+ pr_err("Can't map frame's registers\n");
+ return -ENXIO;
+ }
+
+ arch_timer_mem_detect_rate(base);
ret = arch_timer_mem_register(base, irq);
- if (ret)
+ if (ret) {
+ iounmap(base);
+ return ret;
+ }
+
+ arch_counter_base = base;
+ arch_timers_present |= ARCH_TIMER_TYPE_MEM;
+
+ return 0;
+}
+
+static int __init arch_timer_mem_of_init(struct device_node *np)
+{
+ struct arch_timer_mem *timer_mem;
+ struct device_node *frame_node;
+ struct resource res;
+ int i, ret = -EINVAL;
+
+ timer_mem = kzalloc(sizeof(*timer_mem), GFP_KERNEL);
+ if (!timer_mem)
+ return -ENOMEM;
+
+ if (of_address_to_resource(np, 0, &res))
goto out;
+ timer_mem->cntctlbase = res.start;
+ timer_mem->size = resource_size(&res);
+
+ i = 0;
+ for_each_available_child_of_node(np, frame_node) {
+ int n;
+ struct arch_timer_mem_frame *frame;
+
+ if (i >= ARCH_TIMER_MEM_MAX_FRAMES) {
+ pr_err(FW_BUG "too many frames, only %u are permitted.\n",
+ ARCH_TIMER_MEM_MAX_FRAMES);
+ goto out;
+ }
+
+ frame = &timer_mem->frame[i];
- if (!arch_timer_needs_of_probing())
+ if (of_property_read_u32(frame_node, "frame-number", &n)) {
+ pr_err(FW_BUG "Missing frame-number\n");
+ of_node_put(frame_node);
+ goto out;
+ }
+ frame->frame_nr = n;
+
+ if (of_address_to_resource(frame_node, 0, &res)) {
+ of_node_put(frame_node);
+ goto out;
+ }
+ frame->cntbase = res.start;
+ frame->size = resource_size(&res);
+
+ frame->virt_irq = irq_of_parse_and_map(frame_node,
+ ARCH_TIMER_VIRT_SPI);
+ frame->phys_irq = irq_of_parse_and_map(frame_node,
+ ARCH_TIMER_PHYS_SPI);
+
+ i++;
+ }
+ timer_mem->num_frames = i;
+
+ /* Try to determine the frequency from the device tree */
+ if (!arch_timer_rate)
+ of_property_read_u32(np, "clock-frequency", &arch_timer_rate);
+
+ ret = arch_timer_mem_init(timer_mem);
+ if (!ret && !arch_timer_needs_of_probing())
ret = arch_timer_common_init();
out:
- iounmap(cntctlbase);
- of_node_put(best_frame);
+ kfree(timer_mem);
return ret;
}
CLOCKSOURCE_OF_DECLARE(armv7_arch_timer_mem, "arm,armv7-timer-mem",
- arch_timer_mem_init);
+ arch_timer_mem_of_init);
#ifdef CONFIG_ACPI
static int __init map_generic_timer_interrupt(u32 interrupt, u32 flags)
--
2.9.3
Back to linux.kernel | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
[PATCH v20 00/17] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer fu.wei@linaro.org - 2017-01-18 14:30 +0100
[PATCH v20 01/17] clocksource/drivers/arm_arch_timer: Improve printk relevant code fu.wei@linaro.org - 2017-01-18 14:30 +0100
[PATCH v20 02/17] clocksource/drivers/arm_arch_timer: Rename the timer type macros. fu.wei@linaro.org - 2017-01-18 14:30 +0100
[PATCH v20 06/17] clocksource/drivers/arm_arch_timer: rework PPI determination fu.wei@linaro.org - 2017-01-18 14:30 +0100
[PATCH v20 12/17] clocksource/drivers/arm_arch_timer: Refactor MMIO timer probing. fu.wei@linaro.org - 2017-01-18 14:40 +0100
[PATCH v20 16/17] clocksource/drivers/arm_arch_timer: Add GTDT support for memory-mapped timer fu.wei@linaro.org - 2017-01-18 14:40 +0100
Re: [PATCH v20 16/17] clocksource/drivers/arm_arch_timer: Add GTDT support for memory-mapped timer Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 10:20 +0100
Re: [PATCH v20 16/17] clocksource/drivers/arm_arch_timer: Add GTDT support for memory-mapped timer Fu Wei <fu.wei@linaro.org> - 2017-01-19 11:10 +0100
Re: [PATCH v20 16/17] clocksource/drivers/arm_arch_timer: Add GTDT support for memory-mapped timer Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 13:50 +0100
[PATCH v20 11/17] clocksource/drivers/arm_arch_timer: Introduce some new structs to prepare for GTDT fu.wei@linaro.org - 2017-01-18 14:40 +0100
Re: [PATCH v20 11/17] clocksource/drivers/arm_arch_timer: Introduce some new structs to prepare for GTDT Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 09:30 +0100
Re: [PATCH v20 11/17] clocksource/drivers/arm_arch_timer: Introduce some new structs to prepare for GTDT Fu Wei <fu.wei@linaro.org> - 2017-01-19 11:00 +0100
[PATCH v20 07/17] clocksource/drivers/arm_arch_timer: Separate out device-tree code from arch_timer_detect_rate fu.wei@linaro.org - 2017-01-18 14:40 +0100
[PATCH v20 09/17] clocksource/drivers/arm_arch_timer: Refactor arch_timer_needs_probing fu.wei@linaro.org - 2017-01-18 14:40 +0100
[PATCH v20 13/17] acpi/arm64: Add GTDT table parse driver fu.wei@linaro.org - 2017-01-18 14:40 +0100
Re: [PATCH v20 13/17] acpi/arm64: Add GTDT table parse driver Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 10:20 +0100
Re: [PATCH v20 13/17] acpi/arm64: Add GTDT table parse driver Fu Wei <fu.wei@linaro.org> - 2017-01-19 11:40 +0100
Re: [PATCH v20 13/17] acpi/arm64: Add GTDT table parse driver Mark Rutland <mark.rutland@arm.com> - 2017-01-19 12:20 +0100
Re: [PATCH v20 13/17] acpi/arm64: Add GTDT table parse driver Fu Wei <fu.wei@linaro.org> - 2017-01-19 13:30 +0100
[PATCH v20 05/17] clocksource/drivers/arm_arch_timer: Add a new enum for spi type fu.wei@linaro.org - 2017-01-18 14:40 +0100
[PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. fu.wei@linaro.org - 2017-01-18 14:40 +0100
Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 09:10 +0100
Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. Fu Wei <fu.wei@linaro.org> - 2017-01-19 10:50 +0100
Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 13:50 +0100
Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. Mark Rutland <mark.rutland@arm.com> - 2017-01-24 18:30 +0100
Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. Fu Wei <fu.wei@linaro.org> - 2017-01-25 07:50 +0100
Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. Fu Wei <fu.wei@linaro.org> - 2017-01-25 08:30 +0100
Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. Christopher Covington <cov@codeaurora.org> - 2017-01-25 16:40 +0100
Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. Mark Rutland <mark.rutland@arm.com> - 2017-01-25 18:40 +0100
Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. Fu Wei <fu.wei@linaro.org> - 2017-01-26 07:00 +0100
Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. Mark Rutland <mark.rutland@arm.com> - 2017-01-25 18:30 +0100
Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. Fu Wei <fu.wei@linaro.org> - 2017-01-26 06:50 +0100
Re: [PATCH v20 08/17] clocksource/drivers/arm_arch_timer: Rework counter frequency detection. Mark Rutland <mark.rutland@arm.com> - 2017-01-30 19:00 +0100
[PATCH v20 10/17] clocksource/drivers/arm_arch_timer: Move arch_timer_needs_of_probing into DT init call fu.wei@linaro.org - 2017-01-18 14:40 +0100
[PATCH v20 14/17] clocksource/drivers/arm_arch_timer: Simplify ACPI support code. fu.wei@linaro.org - 2017-01-18 14:40 +0100
[PATCH v20 15/17] acpi/arm64: Add memory-mapped timer support in GTDT driver fu.wei@linaro.org - 2017-01-18 14:40 +0100
[PATCH v20 17/17] acpi/arm64: Add SBSA Generic Watchdog support in GTDT driver fu.wei@linaro.org - 2017-01-18 14:50 +0100
Re: [PATCH v20 00/17] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer Hanjun Guo <hanjun.guo@linaro.org> - 2017-01-19 10:30 +0100
Re: [PATCH v20 00/17] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer Fu Wei <fu.wei@linaro.org> - 2017-01-19 12:20 +0100
Re: [PATCH v20 00/17] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer Mark Rutland <mark.rutland@arm.com> - 2017-01-23 20:00 +0100
Re: [PATCH v20 00/17] acpi, clocksource: add GTDT driver and GTDT support in arm_arch_timer Fu Wei <fu.wei@linaro.org> - 2017-01-24 06:20 +0100
csiph-web