From 85e089d411eeee90c622c3a085086804e63e8f30 Mon Sep 17 00:00:00 2001 From: Baolin Wang Date: Tue, 24 Mar 2020 10:58:48 +0800 Subject: [PATCH] FROMLIST: clocksource/drivers/sprd: Add module support to Spreadtrum timer Timers still have devices created for them. So, when compiling a timer driver as a module, implement it as a normal platform device driver. Bug: 146868249 Change-Id: I04f939e855a985b1791c57ff1f36ace6e5a73049 Link: https://lore.kernel.org/patchwork/patch/1214448/ Signed-off-by: Saravana Kannan Signed-off-by: Baolin Wang Signed-off-by: Baolin Wang Signed-off-by: Orson Zhai --- drivers/clocksource/Kconfig | 2 +- drivers/clocksource/timer-sprd.c | 37 ++++++++++++++++++++++++++++++-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig index f35a53ce8988..8b39f38ee1b0 100644 --- a/drivers/clocksource/Kconfig +++ b/drivers/clocksource/Kconfig @@ -481,7 +481,7 @@ config MTK_TIMER Support for Mediatek timer driver. config SPRD_TIMER - bool "Spreadtrum timer driver" if EXPERT + tristate "Spreadtrum timer driver" if EXPERT depends on HAS_IOMEM depends on (ARCH_SPRD || COMPILE_TEST) default ARCH_SPRD diff --git a/drivers/clocksource/timer-sprd.c b/drivers/clocksource/timer-sprd.c index 430cb99d8d79..546178925ef9 100644 --- a/drivers/clocksource/timer-sprd.c +++ b/drivers/clocksource/timer-sprd.c @@ -5,6 +5,8 @@ #include #include +#include +#include #include "timer-of.h" @@ -141,7 +143,7 @@ static struct timer_of to = { }, }; -static int __init sprd_timer_init(struct device_node *np) +static int sprd_timer_init(struct device_node *np) { int ret; @@ -190,7 +192,7 @@ static struct clocksource suspend_clocksource = { .flags = CLOCK_SOURCE_IS_CONTINUOUS | CLOCK_SOURCE_SUSPEND_NONSTOP, }; -static int __init sprd_suspend_timer_init(struct device_node *np) +static int sprd_suspend_timer_init(struct device_node *np) { int ret; @@ -204,6 +206,37 @@ static int __init sprd_suspend_timer_init(struct device_node *np) return 0; } +#ifdef MODULE +static int sprd_timer_probe(struct platform_device *pdev) +{ + struct device_node *np = pdev->dev.of_node; + + if (of_property_read_bool(np, "interrupts")) + return sprd_timer_init(np); + + return sprd_suspend_timer_init(np); +} + +static const struct of_device_id sprd_timer_match_table[] = { + { .compatible = "sprd,sc9860-suspend-timer" }, + { .compatible = "sprd,sc9860-timer" }, + { } +}; +MODULE_DEVICE_TABLE(of, sprd_timer_match_table); + +static struct platform_driver sprd_timer_driver = { + .probe = sprd_timer_probe, + .driver = { + .name = "sprd-timer", + .of_match_table = sprd_timer_match_table, + }, +}; +module_platform_driver(sprd_timer_driver); + +#else TIMER_OF_DECLARE(sc9860_timer, "sprd,sc9860-timer", sprd_timer_init); TIMER_OF_DECLARE(sc9860_persistent_timer, "sprd,sc9860-suspend-timer", sprd_suspend_timer_init); +#endif + +MODULE_LICENSE("GPL v2");