Commit ce5dc743 authored by Daniel Lezcano's avatar Daniel Lezcano

clocksource/drivers/sun4i: Convert init function to return error

The init functions do not return any error. They behave as the following:

  - panic, thus leading to a kernel crash while another timer may work and
       make the system boot up correctly

  or

  - print an error and let the caller unaware if the state of the system

Change that by converting the init functions to return an error conforming
to the CLOCKSOURCE_OF_RET prototype.

Proper error handling (rollback, errno value) will be changed later case
by case, thus this change just return back an error or success in the init
function.
Signed-off-by: default avatarDaniel Lezcano <daniel.lezcano@linaro.org>
parent 0993f57b
...@@ -146,7 +146,7 @@ static u64 notrace sun4i_timer_sched_read(void) ...@@ -146,7 +146,7 @@ static u64 notrace sun4i_timer_sched_read(void)
return ~readl(timer_base + TIMER_CNTVAL_REG(1)); return ~readl(timer_base + TIMER_CNTVAL_REG(1));
} }
static void __init sun4i_timer_init(struct device_node *node) static int __init sun4i_timer_init(struct device_node *node)
{ {
unsigned long rate = 0; unsigned long rate = 0;
struct clk *clk; struct clk *clk;
...@@ -154,17 +154,28 @@ static void __init sun4i_timer_init(struct device_node *node) ...@@ -154,17 +154,28 @@ static void __init sun4i_timer_init(struct device_node *node)
u32 val; u32 val;
timer_base = of_iomap(node, 0); timer_base = of_iomap(node, 0);
if (!timer_base) if (!timer_base) {
panic("Can't map registers"); pr_crit("Can't map registers");
return -ENXIO;
}
irq = irq_of_parse_and_map(node, 0); irq = irq_of_parse_and_map(node, 0);
if (irq <= 0) if (irq <= 0) {
panic("Can't parse IRQ"); pr_crit("Can't parse IRQ");
return -EINVAL;
}
clk = of_clk_get(node, 0); clk = of_clk_get(node, 0);
if (IS_ERR(clk)) if (IS_ERR(clk)) {
panic("Can't get timer clock"); pr_crit("Can't get timer clock");
clk_prepare_enable(clk); return PTR_ERR(clk);
}
ret = clk_prepare_enable(clk);
if (ret) {
pr_err("Failed to prepare clock");
return ret;
}
rate = clk_get_rate(clk); rate = clk_get_rate(clk);
...@@ -182,8 +193,12 @@ static void __init sun4i_timer_init(struct device_node *node) ...@@ -182,8 +193,12 @@ static void __init sun4i_timer_init(struct device_node *node)
of_machine_is_compatible("allwinner,sun5i-a10s")) of_machine_is_compatible("allwinner,sun5i-a10s"))
sched_clock_register(sun4i_timer_sched_read, 32, rate); sched_clock_register(sun4i_timer_sched_read, 32, rate);
clocksource_mmio_init(timer_base + TIMER_CNTVAL_REG(1), node->name, ret = clocksource_mmio_init(timer_base + TIMER_CNTVAL_REG(1), node->name,
rate, 350, 32, clocksource_mmio_readl_down); rate, 350, 32, clocksource_mmio_readl_down);
if (ret) {
pr_err("Failed to register clocksource");
return ret;
}
ticks_per_jiffy = DIV_ROUND_UP(rate, HZ); ticks_per_jiffy = DIV_ROUND_UP(rate, HZ);
...@@ -200,12 +215,16 @@ static void __init sun4i_timer_init(struct device_node *node) ...@@ -200,12 +215,16 @@ static void __init sun4i_timer_init(struct device_node *node)
TIMER_SYNC_TICKS, 0xffffffff); TIMER_SYNC_TICKS, 0xffffffff);
ret = setup_irq(irq, &sun4i_timer_irq); ret = setup_irq(irq, &sun4i_timer_irq);
if (ret) if (ret) {
pr_warn("failed to setup irq %d\n", irq); pr_err("failed to setup irq %d\n", irq);
return ret;
}
/* Enable timer0 interrupt */ /* Enable timer0 interrupt */
val = readl(timer_base + TIMER_IRQ_EN_REG); val = readl(timer_base + TIMER_IRQ_EN_REG);
writel(val | TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_EN_REG); writel(val | TIMER_IRQ_EN(0), timer_base + TIMER_IRQ_EN_REG);
return ret;
} }
CLOCKSOURCE_OF_DECLARE(sun4i, "allwinner,sun4i-a10-timer", CLOCKSOURCE_OF_DECLARE_RET(sun4i, "allwinner,sun4i-a10-timer",
sun4i_timer_init); sun4i_timer_init);
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment