Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return allocated IRQ from FDT #39

Merged
merged 1 commit into from
Sep 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ typedef struct {
volatile struct rk_map *hw;
void *rk_map_base;
pmem_region_t pmem;
ps_irq_t irq;
irq_id_t irq_id;
} rk_t;

Expand Down
49 changes: 41 additions & 8 deletions libplatsupport/src/plat/rockpro64/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <errno.h>
#include <utils/util.h>
#include <platsupport/timer.h>
#include <platsupport/fdt.h>
#include <platsupport/plat/timer.h>
#include <utils/frequency.h>

Expand Down Expand Up @@ -138,6 +139,24 @@ void rk_destroy(rk_t *rk)
}
}

static int irq_index_walker(ps_irq_t irq, unsigned curr_num, size_t num_irqs, void *token)
{
rk_t *rk = token;

if (RK_IRQ_CHOICE == curr_num) {
irq_id_t registered_id = ps_irq_register(&rk->ops.irq_ops, irq, rk_handle_irq, rk);
if (registered_id >= 0) {
rk->irq_id = registered_id;
rk->irq = irq;
} else {
/* Bail on error */
return registered_id;
}
}

return 0;
}

int rk_init(rk_t *rk, ps_io_ops_t ops, rk_config_t config)
{
int error;
Expand All @@ -152,17 +171,31 @@ int rk_init(rk_t *rk, ps_io_ops_t ops, rk_config_t config)
rk->user_cb_token = config.user_cb_token;
rk->user_cb_event = config.user_cb_event;

error = helper_fdt_alloc_simple(
&ops, config.fdt_path,
RK_REG_CHOICE, RK_IRQ_CHOICE,
&rk->rk_map_base, &rk->pmem, &rk->irq_id,
rk_handle_irq, rk
);
ps_fdt_cookie_t *cookie = NULL;
error = ps_fdt_read_path(&ops.io_fdt, &ops.malloc_ops, config.fdt_path, &cookie);
if (error) {
ZF_LOGE("rockpro64 timer failed to read path (%d, %s)", error, config.fdt_path);
return error;
}

rk->rk_map_base = ps_fdt_index_map_register(&ops, cookie, RK_REG_CHOICE, &rk->pmem);
if (rk->rk_map_base == NULL) {
ZF_LOGE("rockpro64 timer failed to map registers");
return ENODEV;
}

error = ps_fdt_walk_irqs(&ops.io_fdt, cookie, irq_index_walker, rk);
if (error) {
ZF_LOGE("Simple fdt alloc helper failed");
ZF_LOGE("rockpro64 timer failed to register irqs (%d)", error);
return error;
}

rk->irq_id = ps_fdt_cleanup_cookie(&ops.malloc_ops, cookie);
if (rk->irq_id) {
ZF_LOGE("rockpro64 timer to clean up cookie (%d)", error);
return rk->irq_id;
}

rk->hw = rk->rk_map_base;

return 0;
Expand Down Expand Up @@ -190,7 +223,7 @@ int rk_init_secondary(rk_t *rk, rk_t *rkp, ps_io_ops_t ops, rk_config_t config)
rk->hw = (void *)((uintptr_t) rkp->rk_map_base) + 0x20;
/* similarly, the IRQ for this secondary timer is offset by 1 */
rk->irq_id = PS_INVALID_IRQ_ID;
ps_irq_t irq2 = { .type = PS_INTERRUPT, .irq.number = rkp->irq_id + 1 };
ps_irq_t irq2 = { .type = PS_INTERRUPT, .irq.number = rkp->irq.irq.number + 1 };
irq_id_t irq2_id = ps_irq_register(&ops.irq_ops, irq2, rk_handle_irq, rk);
if (irq2_id < 0) {
ZF_LOGE("Failed to register secondary irq for rk timer");
Expand Down