Skip to content

Commit

Permalink
ADSP enable adsp-gptimer-counter
Browse files Browse the repository at this point in the history
  • Loading branch information
artursartamonovsadi committed Apr 15, 2024
1 parent 76b1771 commit 9bb4a10
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
8 changes: 4 additions & 4 deletions arch/arm64/boot/dts/adi/sc59x-64.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,10 @@
status = "disabled";
};

// gptimer_counter: gptimer-counters@0 {
// compatible = "adi,gptimer-counter";
// status = "okay";
// };
gptimer_counter: gptimer-counters@0 {
compatible = "adi,gptimer-counter";
status = "okay";
};

rcu: rcu@3108c000 {
compatible = "adi,reset-controller";
Expand Down
61 changes: 40 additions & 21 deletions drivers/clocksource/timer-adi-adsp-sc5xx.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,9 @@ struct sc5xx_gptimer_controller {
struct clockevent_gptimer *cevt;
struct sc5xx_gptimer *timers;
size_t num_timers;
struct counter_device counter_dev;
};

static struct sc5xx_gptimer_controller gptimer_controller = { 0 };
static struct sc5xx_gptimer_controller gptimer_controller = { 0x00 };

static struct clockevent_gptimer *to_clockevent_gptimer(struct
clock_event_device
Expand Down Expand Up @@ -430,25 +429,30 @@ static int __init sc5xx_gptimer_controller_init(struct device_node *np)
int ret;
int i, n;

printk(KERN_ERR" sc5xx_gptimer_controller_init %d\n",__LINE__);

if (gptimer_controller.base) {
pr_err
("%s: Tried to initialize a second gptimer controller; check your device tree\n",
__func__);
return -EINVAL;
}
printk(KERN_ERR" sc5xx_gptimer_controller_init %d\n",__LINE__);

base = of_iomap(np, 0);
if (!base) {
pr_err("%s: Unable to map gptimer registers\n", __func__);
return -ENODEV;
}
printk(KERN_ERR" sc5xx_gptimer_controller_init %d\n",__LINE__);

clk = of_clk_get(np, 0);
if (IS_ERR(clk)) {
pr_err("%s: could not find sclk0_0 = %ld\n", __func__,
PTR_ERR(clk));
return PTR_ERR(clk);
}
printk(KERN_ERR" sc5xx_gptimer_controller_init %d\n",__LINE__);

ret = clk_prepare_enable(clk);
if (ret) {
Expand All @@ -463,8 +467,9 @@ static int __init sc5xx_gptimer_controller_init(struct device_node *np)
n = of_get_child_count(np);
gptimer_controller.num_timers = n;
gptimer_controller.timers =
kcalloc(n, sizeof(*gptimer_controller.timers), GFP_KERNEL);
kcalloc(n, sizeof(*gptimer_controller.timers), GFP_KERNEL);

printk(KERN_ERR" sc5xx_gptimer_controller_init %d\n",__LINE__);
if (!gptimer_controller.timers) {
pr_err("%s: Unable to allocate memory for timers\n",
__func__);
Expand All @@ -476,6 +481,7 @@ static int __init sc5xx_gptimer_controller_init(struct device_node *np)
ret =
sc5xx_gptimer_init(timer_np,
&gptimer_controller.timers[i]);
printk(KERN_ERR" sc5xx_gptimer_controller_init %d\n",__LINE__);
if (ret) {
of_node_put(timer_np);
return ret;
Expand All @@ -493,35 +499,48 @@ TIMER_OF_DECLARE(sc5xx_gptimers, "adi,sc5xx-gptimers",
static int gptimer_counter_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct counter_count *counts;
struct counter_count *adi_counts;
struct sc5xx_gptimer_controller *priv;
struct counter_device *counter;
uint32_t i;
int ret;

if (!gptimer_controller.base) {
dev_err(dev, "gptimer controller not yet mapped?\n");
return -ENODEV;
adi_counts =
devm_kcalloc(dev, gptimer_controller.num_timers,
sizeof(*adi_counts), GFP_KERNEL);
if (!adi_counts) {
return -ENOMEM;
}

counts =
devm_kcalloc(dev, gptimer_controller.num_timers,
sizeof(*counts), GFP_KERNEL);
if (!counts)

counter = devm_counter_alloc(dev, sizeof(*priv));
if (!counter)
return -ENOMEM;

priv = counter_priv(counter);


for (i = 0; i < gptimer_controller.num_timers; ++i) {
counts[i].id = i;
counts[i].name =
adi_counts[i].name =
kasprintf(GFP_KERNEL, "gptimer_counter%d", i);
}

gptimer_controller.counter_dev.name = dev_name(dev);
gptimer_controller.counter_dev.parent = dev;
gptimer_controller.counter_dev.ops = &gptimer_counter_ops;
gptimer_controller.counter_dev.counts = counts;
gptimer_controller.counter_dev.num_counts =
gptimer_controller.num_timers;
priv->clk = gptimer_controller.clk;

counter->name = dev_name(dev);
counter->parent = dev;
counter->ops = &gptimer_counter_ops;
counter->counts = adi_counts;
counter->num_counts = gptimer_controller.num_timers;

/* Register Counter device */
ret = devm_counter_add(dev, counter);
if (ret < 0) {
dev_err_probe(dev, ret, "Failed to add counter\n");
}
return ret;

//changed from devm_counter_register
return devm_counter_add(dev, &gptimer_controller.counter_dev);

}

static const struct of_device_id adsp_gptimer_counter_match[] = {
Expand Down

0 comments on commit 9bb4a10

Please sign in to comment.