* [PATCH 0/3] Add module build support for timer driver
@ 2021-07-01 8:51 Chunyan Zhang
2021-07-01 8:51 ` [PATCH 1/3] drivers/clocksource/timer-of: Remove __init markings Chunyan Zhang
` (2 more replies)
0 siblings, 3 replies; 6+ messages in thread
From: Chunyan Zhang @ 2021-07-01 8:51 UTC (permalink / raw)
To: Daniel Lezcano, Thomas Gleixner
Cc: Saravana Kannan, Baolin Wang, Orson Zhai, Chunyan Zhang,
Chunyan Zhang, LKML
From: Chunyan Zhang <chunyan.zhang@unisoc.com>
This patchset was based on the previous one [1], and add a few
boilerplate macros for module build purpose according to comments
from Thomas Gleixner on the patch [2].
Also switch sprd timer driver to use the help macros for support
module build.
[1] https://lkml.org/lkml/2020/3/24/72
[2] https://www.spinics.net/lists/arm-kernel/msg826631.html
Chunyan Zhang (2):
clocksource/drivers/timer-of: Add boilerplate macros for timer module
driver
clocksource/drivers/sprd: Add module support to Unisoc timer
Saravana Kannan (1):
drivers/clocksource/timer-of: Remove __init markings
drivers/clocksource/Kconfig | 2 +-
drivers/clocksource/timer-of.c | 30 ++++++++++++++++++++++--------
drivers/clocksource/timer-of.h | 24 ++++++++++++++++++++++--
drivers/clocksource/timer-sprd.c | 15 +++++++++++++--
4 files changed, 58 insertions(+), 13 deletions(-)
--
2.25.1
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH 1/3] drivers/clocksource/timer-of: Remove __init markings
2021-07-01 8:51 [PATCH 0/3] Add module build support for timer driver Chunyan Zhang
@ 2021-07-01 8:51 ` Chunyan Zhang
2021-07-01 8:51 ` [PATCH 2/3] clocksource/drivers/timer-of: Add boilerplate macros for timer module driver Chunyan Zhang
2021-07-01 8:51 ` [PATCH 3/3] clocksource/drivers/sprd: Add module support to Unisoc timer Chunyan Zhang
2 siblings, 0 replies; 6+ messages in thread
From: Chunyan Zhang @ 2021-07-01 8:51 UTC (permalink / raw)
To: Daniel Lezcano, Thomas Gleixner
Cc: Saravana Kannan, Baolin Wang, Orson Zhai, Chunyan Zhang,
Chunyan Zhang, LKML
From: Saravana Kannan <saravanak@google.com>
This allows timer drivers to be compiled as modules.
Signed-off-by: Saravana Kannan <saravanak@google.com>
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
---
drivers/clocksource/timer-of.c | 17 +++++++++--------
drivers/clocksource/timer-of.h | 4 ++--
2 files changed, 11 insertions(+), 10 deletions(-)
diff --git a/drivers/clocksource/timer-of.c b/drivers/clocksource/timer-of.c
index 529cc6a51cdb..7f108978fd51 100644
--- a/drivers/clocksource/timer-of.c
+++ b/drivers/clocksource/timer-of.c
@@ -19,7 +19,7 @@
*
* Free the irq resource
*/
-static __init void timer_of_irq_exit(struct of_timer_irq *of_irq)
+static void timer_of_irq_exit(struct of_timer_irq *of_irq)
{
struct timer_of *to = container_of(of_irq, struct timer_of, of_irq);
@@ -47,7 +47,7 @@ static __init void timer_of_irq_exit(struct of_timer_irq *of_irq)
*
* Returns 0 on success, < 0 otherwise
*/
-static __init int timer_of_irq_init(struct device_node *np,
+static int timer_of_irq_init(struct device_node *np,
struct of_timer_irq *of_irq)
{
int ret;
@@ -91,7 +91,7 @@ static __init int timer_of_irq_init(struct device_node *np,
*
* Disables and releases the refcount on the clk
*/
-static __init void timer_of_clk_exit(struct of_timer_clk *of_clk)
+static void timer_of_clk_exit(struct of_timer_clk *of_clk)
{
of_clk->rate = 0;
clk_disable_unprepare(of_clk->clk);
@@ -107,7 +107,7 @@ static __init void timer_of_clk_exit(struct of_timer_clk *of_clk)
*
* Returns 0 on success, < 0 otherwise
*/
-static __init int timer_of_clk_init(struct device_node *np,
+static int timer_of_clk_init(struct device_node *np,
struct of_timer_clk *of_clk)
{
int ret;
@@ -146,12 +146,12 @@ static __init int timer_of_clk_init(struct device_node *np,
goto out;
}
-static __init void timer_of_base_exit(struct of_timer_base *of_base)
+static void timer_of_base_exit(struct of_timer_base *of_base)
{
iounmap(of_base->base);
}
-static __init int timer_of_base_init(struct device_node *np,
+static int timer_of_base_init(struct device_node *np,
struct of_timer_base *of_base)
{
of_base->base = of_base->name ?
@@ -165,7 +165,7 @@ static __init int timer_of_base_init(struct device_node *np,
return 0;
}
-int __init timer_of_init(struct device_node *np, struct timer_of *to)
+int timer_of_init(struct device_node *np, struct timer_of *to)
{
int ret = -EINVAL;
int flags = 0;
@@ -209,6 +209,7 @@ int __init timer_of_init(struct device_node *np, struct timer_of *to)
timer_of_base_exit(&to->of_base);
return ret;
}
+EXPORT_SYMBOL_GPL(timer_of_init);
/**
* timer_of_cleanup - release timer_of resources
@@ -217,7 +218,7 @@ int __init timer_of_init(struct device_node *np, struct timer_of *to)
* Release the resources that has been used in timer_of_init().
* This function should be called in init error cases
*/
-void __init timer_of_cleanup(struct timer_of *to)
+void timer_of_cleanup(struct timer_of *to)
{
if (to->flags & TIMER_OF_IRQ)
timer_of_irq_exit(&to->of_irq);
diff --git a/drivers/clocksource/timer-of.h b/drivers/clocksource/timer-of.h
index a5478f3e8589..1b8cfac5900a 100644
--- a/drivers/clocksource/timer-of.h
+++ b/drivers/clocksource/timer-of.h
@@ -66,9 +66,9 @@ static inline unsigned long timer_of_period(struct timer_of *to)
return to->of_clk.period;
}
-extern int __init timer_of_init(struct device_node *np,
+extern int timer_of_init(struct device_node *np,
struct timer_of *to);
-extern void __init timer_of_cleanup(struct timer_of *to);
+extern void timer_of_cleanup(struct timer_of *to);
#endif
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 2/3] clocksource/drivers/timer-of: Add boilerplate macros for timer module driver
2021-07-01 8:51 [PATCH 0/3] Add module build support for timer driver Chunyan Zhang
2021-07-01 8:51 ` [PATCH 1/3] drivers/clocksource/timer-of: Remove __init markings Chunyan Zhang
@ 2021-07-01 8:51 ` Chunyan Zhang
2021-07-01 8:51 ` [PATCH 3/3] clocksource/drivers/sprd: Add module support to Unisoc timer Chunyan Zhang
2 siblings, 0 replies; 6+ messages in thread
From: Chunyan Zhang @ 2021-07-01 8:51 UTC (permalink / raw)
To: Daniel Lezcano, Thomas Gleixner
Cc: Saravana Kannan, Baolin Wang, Orson Zhai, Chunyan Zhang,
Chunyan Zhang, LKML
From: Chunyan Zhang <chunyan.zhang@unisoc.com>
To support module build, platform driver structs, .probe(), match table and
module macros need to be added to the timer driver. So this patch provides
a few macros to take care of these things, and that would reduce the repeat
code lines in every sigle driver.
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
---
drivers/clocksource/timer-of.c | 13 +++++++++++++
drivers/clocksource/timer-of.h | 20 ++++++++++++++++++++
2 files changed, 33 insertions(+)
diff --git a/drivers/clocksource/timer-of.c b/drivers/clocksource/timer-of.c
index 7f108978fd51..ecd7f7379400 100644
--- a/drivers/clocksource/timer-of.c
+++ b/drivers/clocksource/timer-of.c
@@ -8,7 +8,9 @@
#include <linux/interrupt.h>
#include <linux/of.h>
#include <linux/of_address.h>
+#include <linux/of_device.h>
#include <linux/of_irq.h>
+#include <linux/platform_device.h>
#include <linux/slab.h>
#include "timer-of.h"
@@ -229,3 +231,14 @@ void timer_of_cleanup(struct timer_of *to)
if (to->flags & TIMER_OF_BASE)
timer_of_base_exit(&to->of_base);
}
+
+int platform_timer_probe(struct platform_device *pdev)
+{
+ int (*init_cb)(struct device_node *node);
+ struct device_node *np = pdev->dev.of_node;
+
+ init_cb = of_device_get_match_data(&pdev->dev);
+
+ return init_cb(np);
+}
+EXPORT_SYMBOL_GPL(platform_timer_probe);
diff --git a/drivers/clocksource/timer-of.h b/drivers/clocksource/timer-of.h
index 1b8cfac5900a..129f539d5f54 100644
--- a/drivers/clocksource/timer-of.h
+++ b/drivers/clocksource/timer-of.h
@@ -3,6 +3,7 @@
#define __TIMER_OF_H__
#include <linux/clockchips.h>
+#include <linux/platform_device.h>
#define TIMER_OF_BASE 0x1
#define TIMER_OF_CLOCK 0x2
@@ -71,4 +72,23 @@ extern int timer_of_init(struct device_node *np,
extern void timer_of_cleanup(struct timer_of *to);
+extern int platform_timer_probe(struct platform_device *pdev);
+
+#define TIMER_PLATFORM_DRIVER_BEGIN(drv_name) \
+static const struct of_device_id drv_name##_timer_match_table[] = {
+
+#define TIMER_MATCH(compat, _data) { .compatible = compat, .data = _data },
+
+#define TIMER_PLATFORM_DRIVER_END(drv_name) \
+ {}, \
+}; \
+MODULE_DEVICE_TABLE(of, drv_name##_timer_match_table); \
+static struct platform_driver drv_name##_driver = { \
+ .probe = platform_timer_probe, \
+ .driver = { \
+ .name = #drv_name, \
+ .of_match_table = drv_name##_timer_match_table, \
+ }, \
+}; \
+module_platform_driver(drv_name##_driver)
#endif
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH 3/3] clocksource/drivers/sprd: Add module support to Unisoc timer
2021-07-01 8:51 [PATCH 0/3] Add module build support for timer driver Chunyan Zhang
2021-07-01 8:51 ` [PATCH 1/3] drivers/clocksource/timer-of: Remove __init markings Chunyan Zhang
2021-07-01 8:51 ` [PATCH 2/3] clocksource/drivers/timer-of: Add boilerplate macros for timer module driver Chunyan Zhang
@ 2021-07-01 8:51 ` Chunyan Zhang
2021-07-01 19:17 ` Saravana Kannan
2 siblings, 1 reply; 6+ messages in thread
From: Chunyan Zhang @ 2021-07-01 8:51 UTC (permalink / raw)
To: Daniel Lezcano, Thomas Gleixner
Cc: Saravana Kannan, Baolin Wang, Orson Zhai, Chunyan Zhang,
Chunyan Zhang, LKML
From: Chunyan Zhang <chunyan.zhang@unisoc.com>
Timers still have devices created for them. So, when compiling a timer
driver as a module, implement it as a normal platform device driver.
Original-by: Baolin Wang <baolin.wang7@gmail.com>
Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
---
drivers/clocksource/Kconfig | 2 +-
drivers/clocksource/timer-sprd.c | 15 +++++++++++++--
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index 39aa21d01e05..9f16c2779edb 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -447,7 +447,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..73c7b3f8c901 100644
--- a/drivers/clocksource/timer-sprd.c
+++ b/drivers/clocksource/timer-sprd.c
@@ -5,6 +5,8 @@
#include <linux/init.h>
#include <linux/interrupt.h>
+#include <linux/module.h>
+#include <linux/platform_device.h>
#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,15 @@ static int __init sprd_suspend_timer_init(struct device_node *np)
return 0;
}
+#ifdef MODULE
+TIMER_PLATFORM_DRIVER_BEGIN(sprd_timer)
+TIMER_MATCH("sprd,sc9860-timer", sprd_timer_init)
+TIMER_MATCH("sprd,sc9860-suspend-timer", sprd_suspend_timer_init)
+TIMER_PLATFORM_DRIVER_END(sprd_timer);
+MODULE_DESCRIPTION("Unisoc broadcast timer module");
+MODULE_LICENSE("GPL");
+#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
--
2.25.1
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] clocksource/drivers/sprd: Add module support to Unisoc timer
2021-07-01 8:51 ` [PATCH 3/3] clocksource/drivers/sprd: Add module support to Unisoc timer Chunyan Zhang
@ 2021-07-01 19:17 ` Saravana Kannan
2021-07-02 2:25 ` Chunyan Zhang
0 siblings, 1 reply; 6+ messages in thread
From: Saravana Kannan @ 2021-07-01 19:17 UTC (permalink / raw)
To: Chunyan Zhang
Cc: Daniel Lezcano, Thomas Gleixner, Baolin Wang, Orson Zhai,
Chunyan Zhang, LKML
On Thu, Jul 1, 2021 at 1:52 AM Chunyan Zhang <zhang.lyra@gmail.com> wrote:
>
> From: Chunyan Zhang <chunyan.zhang@unisoc.com>
>
> Timers still have devices created for them. So, when compiling a timer
> driver as a module, implement it as a normal platform device driver.
>
> Original-by: Baolin Wang <baolin.wang7@gmail.com>
> Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
> ---
> drivers/clocksource/Kconfig | 2 +-
> drivers/clocksource/timer-sprd.c | 15 +++++++++++++--
> 2 files changed, 14 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
> index 39aa21d01e05..9f16c2779edb 100644
> --- a/drivers/clocksource/Kconfig
> +++ b/drivers/clocksource/Kconfig
> @@ -447,7 +447,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..73c7b3f8c901 100644
> --- a/drivers/clocksource/timer-sprd.c
> +++ b/drivers/clocksource/timer-sprd.c
> @@ -5,6 +5,8 @@
>
> #include <linux/init.h>
> #include <linux/interrupt.h>
> +#include <linux/module.h>
> +#include <linux/platform_device.h>
>
> #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,15 @@ static int __init sprd_suspend_timer_init(struct device_node *np)
> return 0;
> }
>
> +#ifdef MODULE
> +TIMER_PLATFORM_DRIVER_BEGIN(sprd_timer)
> +TIMER_MATCH("sprd,sc9860-timer", sprd_timer_init)
> +TIMER_MATCH("sprd,sc9860-suspend-timer", sprd_suspend_timer_init)
> +TIMER_PLATFORM_DRIVER_END(sprd_timer);
> +MODULE_DESCRIPTION("Unisoc broadcast timer module");
> +MODULE_LICENSE("GPL");
> +#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
Would it be a problem if you removed the ifdef and dropped these
TIMER_OF_DECLARE? Doesn't look like either of these timers are needed
for the early scheduler timer.
-Saravana
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH 3/3] clocksource/drivers/sprd: Add module support to Unisoc timer
2021-07-01 19:17 ` Saravana Kannan
@ 2021-07-02 2:25 ` Chunyan Zhang
0 siblings, 0 replies; 6+ messages in thread
From: Chunyan Zhang @ 2021-07-02 2:25 UTC (permalink / raw)
To: Saravana Kannan
Cc: Daniel Lezcano, Thomas Gleixner, Baolin Wang, Orson Zhai,
Chunyan Zhang, LKML
On Fri, 2 Jul 2021 at 03:18, Saravana Kannan <saravanak@google.com> wrote:
>
> On Thu, Jul 1, 2021 at 1:52 AM Chunyan Zhang <zhang.lyra@gmail.com> wrote:
> >
> > From: Chunyan Zhang <chunyan.zhang@unisoc.com>
> >
> > Timers still have devices created for them. So, when compiling a timer
> > driver as a module, implement it as a normal platform device driver.
> >
> > Original-by: Baolin Wang <baolin.wang7@gmail.com>
> > Signed-off-by: Chunyan Zhang <chunyan.zhang@unisoc.com>
> > ---
> > drivers/clocksource/Kconfig | 2 +-
> > drivers/clocksource/timer-sprd.c | 15 +++++++++++++--
> > 2 files changed, 14 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
> > index 39aa21d01e05..9f16c2779edb 100644
> > --- a/drivers/clocksource/Kconfig
> > +++ b/drivers/clocksource/Kconfig
> > @@ -447,7 +447,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..73c7b3f8c901 100644
> > --- a/drivers/clocksource/timer-sprd.c
> > +++ b/drivers/clocksource/timer-sprd.c
> > @@ -5,6 +5,8 @@
> >
> > #include <linux/init.h>
> > #include <linux/interrupt.h>
> > +#include <linux/module.h>
> > +#include <linux/platform_device.h>
> >
> > #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,15 @@ static int __init sprd_suspend_timer_init(struct device_node *np)
> > return 0;
> > }
> >
> > +#ifdef MODULE
> > +TIMER_PLATFORM_DRIVER_BEGIN(sprd_timer)
> > +TIMER_MATCH("sprd,sc9860-timer", sprd_timer_init)
> > +TIMER_MATCH("sprd,sc9860-suspend-timer", sprd_suspend_timer_init)
> > +TIMER_PLATFORM_DRIVER_END(sprd_timer);
> > +MODULE_DESCRIPTION("Unisoc broadcast timer module");
> > +MODULE_LICENSE("GPL");
> > +#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
>
> Would it be a problem if you removed the ifdef and dropped these
> TIMER_OF_DECLARE? Doesn't look like either of these timers are needed
> for the early scheduler timer.
Yes, there seems no problem indeed for now, I will drop them.
Thanks,
Chunyan
>
> -Saravana
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-07-02 2:26 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-01 8:51 [PATCH 0/3] Add module build support for timer driver Chunyan Zhang
2021-07-01 8:51 ` [PATCH 1/3] drivers/clocksource/timer-of: Remove __init markings Chunyan Zhang
2021-07-01 8:51 ` [PATCH 2/3] clocksource/drivers/timer-of: Add boilerplate macros for timer module driver Chunyan Zhang
2021-07-01 8:51 ` [PATCH 3/3] clocksource/drivers/sprd: Add module support to Unisoc timer Chunyan Zhang
2021-07-01 19:17 ` Saravana Kannan
2021-07-02 2:25 ` Chunyan Zhang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).