mirror of
https://github.com/edk2-porting/linux-next.git
synced 2024-12-20 19:23:57 +08:00
clocksource/drivers/integrator-ap: 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: Daniel Lezcano <daniel.lezcano@linaro.org>
This commit is contained in:
parent
c11cd416ae
commit
76804d0523
@ -36,11 +36,12 @@ static u64 notrace integrator_read_sched_clock(void)
|
||||
return -readl(sched_clk_base + TIMER_VALUE);
|
||||
}
|
||||
|
||||
static void integrator_clocksource_init(unsigned long inrate,
|
||||
void __iomem *base)
|
||||
static int integrator_clocksource_init(unsigned long inrate,
|
||||
void __iomem *base)
|
||||
{
|
||||
u32 ctrl = TIMER_CTRL_ENABLE | TIMER_CTRL_PERIODIC;
|
||||
unsigned long rate = inrate;
|
||||
int ret;
|
||||
|
||||
if (rate >= 1500000) {
|
||||
rate /= 16;
|
||||
@ -50,11 +51,15 @@ static void integrator_clocksource_init(unsigned long inrate,
|
||||
writel(0xffff, base + TIMER_LOAD);
|
||||
writel(ctrl, base + TIMER_CTRL);
|
||||
|
||||
clocksource_mmio_init(base + TIMER_VALUE, "timer2",
|
||||
rate, 200, 16, clocksource_mmio_readl_down);
|
||||
ret = clocksource_mmio_init(base + TIMER_VALUE, "timer2",
|
||||
rate, 200, 16, clocksource_mmio_readl_down);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
sched_clk_base = base;
|
||||
sched_clock_register(integrator_read_sched_clock, 16, rate);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static unsigned long timer_reload;
|
||||
@ -138,11 +143,12 @@ static struct irqaction integrator_timer_irq = {
|
||||
.dev_id = &integrator_clockevent,
|
||||
};
|
||||
|
||||
static void integrator_clockevent_init(unsigned long inrate,
|
||||
void __iomem *base, int irq)
|
||||
static int integrator_clockevent_init(unsigned long inrate,
|
||||
void __iomem *base, int irq)
|
||||
{
|
||||
unsigned long rate = inrate;
|
||||
unsigned int ctrl = 0;
|
||||
int ret;
|
||||
|
||||
clkevt_base = base;
|
||||
/* Calculate and program a divisor */
|
||||
@ -156,14 +162,18 @@ static void integrator_clockevent_init(unsigned long inrate,
|
||||
timer_reload = rate / HZ;
|
||||
writel(ctrl, clkevt_base + TIMER_CTRL);
|
||||
|
||||
setup_irq(irq, &integrator_timer_irq);
|
||||
ret = setup_irq(irq, &integrator_timer_irq);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
clockevents_config_and_register(&integrator_clockevent,
|
||||
rate,
|
||||
1,
|
||||
0xffffU);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __init integrator_ap_timer_init_of(struct device_node *node)
|
||||
static int __init integrator_ap_timer_init_of(struct device_node *node)
|
||||
{
|
||||
const char *path;
|
||||
void __iomem *base;
|
||||
@ -176,12 +186,12 @@ static void __init integrator_ap_timer_init_of(struct device_node *node)
|
||||
|
||||
base = of_io_request_and_map(node, 0, "integrator-timer");
|
||||
if (IS_ERR(base))
|
||||
return;
|
||||
return PTR_ERR(base);
|
||||
|
||||
clk = of_clk_get(node, 0);
|
||||
if (IS_ERR(clk)) {
|
||||
pr_err("No clock for %s\n", node->name);
|
||||
return;
|
||||
return PTR_ERR(clk);
|
||||
}
|
||||
clk_prepare_enable(clk);
|
||||
rate = clk_get_rate(clk);
|
||||
@ -189,31 +199,38 @@ static void __init integrator_ap_timer_init_of(struct device_node *node)
|
||||
|
||||
err = of_property_read_string(of_aliases,
|
||||
"arm,timer-primary", &path);
|
||||
if (WARN_ON(err))
|
||||
return;
|
||||
if (err) {
|
||||
pr_warn("Failed to read property");
|
||||
return err;
|
||||
}
|
||||
|
||||
pri_node = of_find_node_by_path(path);
|
||||
|
||||
err = of_property_read_string(of_aliases,
|
||||
"arm,timer-secondary", &path);
|
||||
if (WARN_ON(err))
|
||||
return;
|
||||
if (err) {
|
||||
pr_warn("Failed to read property");
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
sec_node = of_find_node_by_path(path);
|
||||
|
||||
if (node == pri_node) {
|
||||
if (node == pri_node)
|
||||
/* The primary timer lacks IRQ, use as clocksource */
|
||||
integrator_clocksource_init(rate, base);
|
||||
return;
|
||||
}
|
||||
return integrator_clocksource_init(rate, base);
|
||||
|
||||
if (node == sec_node) {
|
||||
/* The secondary timer will drive the clock event */
|
||||
irq = irq_of_parse_and_map(node, 0);
|
||||
integrator_clockevent_init(rate, base, irq);
|
||||
return;
|
||||
return integrator_clockevent_init(rate, base, irq);
|
||||
}
|
||||
|
||||
pr_info("Timer @%p unused\n", base);
|
||||
clk_disable_unprepare(clk);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
CLOCKSOURCE_OF_DECLARE(integrator_ap_timer, "arm,integrator-timer",
|
||||
CLOCKSOURCE_OF_DECLARE_RET(integrator_ap_timer, "arm,integrator-timer",
|
||||
integrator_ap_timer_init_of);
|
||||
|
Loading…
Reference in New Issue
Block a user