diff --git a/arch/arm64/boot/dts/adi/sc59x-64.dtsi b/arch/arm64/boot/dts/adi/sc59x-64.dtsi index 53fe274bbf8591..e5367c059f7246 100644 --- a/arch/arm64/boot/dts/adi/sc59x-64.dtsi +++ b/arch/arm64/boot/dts/adi/sc59x-64.dtsi @@ -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"; diff --git a/drivers/clocksource/timer-adi-adsp-sc5xx.c b/drivers/clocksource/timer-adi-adsp-sc5xx.c index 2596bd1f13142f..ce3f07a9a2ddee 100644 --- a/drivers/clocksource/timer-adi-adsp-sc5xx.c +++ b/drivers/clocksource/timer-adi-adsp-sc5xx.c @@ -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 @@ -430,18 +429,22 @@ 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)) { @@ -449,6 +452,7 @@ static int __init sc5xx_gptimer_controller_init(struct device_node *np) PTR_ERR(clk)); return PTR_ERR(clk); } + printk(KERN_ERR" sc5xx_gptimer_controller_init %d\n",__LINE__); ret = clk_prepare_enable(clk); if (ret) { @@ -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__); @@ -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; @@ -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[] = {