2021-08-20 09:51:42

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH v3 0/3] Add module build support for timer driver

From: Chunyan Zhang <[email protected]>

This patchset was based on the previous one [1], and add a
boilerplate macro for module build purpose according to comments
from Thomas Gleixner on the patch [2].

Also switch sprd timer driver to use the help macro to support
module build.

* Changes from v2:
- Define one macro TIMER_PLATFORM_DECLEAR() to replace the three ones in the v2;
- Use builtin_platform_driver() to replace module_platform_driver() to make sure
unloading timer modules not supported;
- Add more description to explain that unloading is not supported.

* Changes from v1:
- Removed TIMER_OF_DECLARE() from timer-sprd.c, and removed ifdef;
- Rebased on v5.14-rc1.

[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 a boilerplate macro 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 | 19 +++++++++++++++++--
drivers/clocksource/timer-sprd.c | 17 ++++++++++++-----
4 files changed, 52 insertions(+), 16 deletions(-)

--
2.25.1


2021-08-20 09:52:27

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH v3 3/3] clocksource/drivers/sprd: Add module support to Unisoc timer

From: Chunyan Zhang <[email protected]>

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 <[email protected]>
Signed-off-by: Chunyan Zhang <[email protected]>
---
drivers/clocksource/Kconfig | 2 +-
drivers/clocksource/timer-sprd.c | 17 ++++++++++++-----
2 files changed, 13 insertions(+), 6 deletions(-)

diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index eb661b539a3e..a5a5b7c883ec 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -461,7 +461,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..e6b7a317e84f 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,11 @@ static int __init sprd_suspend_timer_init(struct device_node *np)
return 0;
}

-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);
+static const struct of_device_id sc9860_timer_match_table[] = {
+ { .compatible = "sprd,sc9860-timer", .data = sprd_timer_init },
+ { .compatible = "sprd,sc9860-suspend-timer", .data = sprd_suspend_timer_init },
+ {},
+};
+TIMER_PLATFORM_DECLEAR("Unisoc broadcast timer module", sc9860_timer,
+ sc9860_timer_match_table);
+
--
2.25.1

2021-08-20 09:54:01

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH v3 2/3] clocksource/drivers/timer-of: Add a boilerplate macro for timer module driver

From: Chunyan Zhang <[email protected]>

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 macro to take care of these things, and that would reduce the repeat
code lines in every sigle driver.

Since timer module should support loading only, we use
builtin_platform_driver() which doesn't include module_exit() to make
sure timer modules wouldn't be unloaded.

Signed-off-by: Chunyan Zhang <[email protected]>
---
drivers/clocksource/timer-of.c | 13 +++++++++++++
drivers/clocksource/timer-of.h | 15 +++++++++++++++
2 files changed, 28 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..04a476da01bb 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,18 @@ 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_DECLEAR(desc, drv_name, table) \
+MODULE_DEVICE_TABLE(of, table); \
+static struct platform_driver drv_name##_driver = { \
+ .probe = platform_timer_probe, \
+ .driver = { \
+ .name = #drv_name, \
+ .of_match_table = table, \
+ }, \
+}; \
+builtin_platform_driver(drv_name##_driver); \
+MODULE_DESCRIPTION(desc); \
+MODULE_LICENSE("GPL")
#endif
--
2.25.1

2021-08-20 10:09:30

by Chunyan Zhang

[permalink] [raw]
Subject: [PATCH v3 3/3] clocksource/drivers/sprd: Add module support to Unisoc timer

From: Chunyan Zhang <[email protected]>

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 <[email protected]>
Signed-off-by: Chunyan Zhang <[email protected]>
---
drivers/clocksource/Kconfig | 2 +-
drivers/clocksource/timer-sprd.c | 18 +++++++++++++-----
2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/clocksource/Kconfig b/drivers/clocksource/Kconfig
index eb661b539a3e..a5a5b7c883ec 100644
--- a/drivers/clocksource/Kconfig
+++ b/drivers/clocksource/Kconfig
@@ -461,7 +461,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..b29c48ef3ba5 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,12 @@ static int __init sprd_suspend_timer_init(struct device_node *np)
return 0;
}

-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);
+static const struct of_device_id sc9860_timer_match_table[] = {
+ { .compatible = "sprd,sc9860-timer",
+ .data = sprd_timer_init },
+ { .compatible = "sprd,sc9860-suspend-timer",
+ .data = sprd_suspend_timer_init },
+ {},
+};
+TIMER_PLATFORM_DECLEAR("Unisoc broadcast timer module", sc9860_timer,
+ sc9860_timer_match_table);
--
2.25.1