LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
From: Chunyan Zhang <zhang.lyra@gmail.com>
To: Daniel Lezcano <daniel.lezcano@linaro.org>,
Thomas Gleixner <tglx@linutronix.de>
Cc: Saravana Kannan <saravanak@google.com>,
Baolin Wang <baolin.wang7@gmail.com>,
Orson Zhai <orsonzhai@gmail.com>,
Chunyan Zhang <zhang.lyra@gmail.com>,
Chunyan Zhang <chunyan.zhang@unisoc.com>,
LKML <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 2/3] clocksource/drivers/timer-of: Add boilerplate macros for timer module driver
Date: Thu, 15 Jul 2021 14:54:54 +0800 [thread overview]
Message-ID: <20210715065455.392923-3-zhang.lyra@gmail.com> (raw)
In-Reply-To: <20210715065455.392923-1-zhang.lyra@gmail.com>
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
next prev parent reply other threads:[~2021-07-15 6:55 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-15 6:54 [PATCH v2 0/3] Add module build support for timer driver Chunyan Zhang
2021-07-15 6:54 ` [PATCH v2 1/3] drivers/clocksource/timer-of: Remove __init markings Chunyan Zhang
2021-08-01 6:17 ` kernel test robot
2021-08-12 6:39 ` Chunyan Zhang
2021-08-12 7:58 ` [kbuild-all] " Chen, Rong A
2021-08-12 14:49 ` Thomas Gleixner
2021-08-13 2:29 ` Chunyan Zhang
2021-08-13 13:33 ` Daniel Lezcano
2021-08-20 7:45 ` Chunyan Zhang
2021-07-15 6:54 ` Chunyan Zhang [this message]
2021-07-15 6:54 ` [PATCH v2 3/3] clocksource/drivers/sprd: Add module support to Unisoc timer Chunyan Zhang
2021-08-13 16:00 ` Daniel Lezcano
2021-08-13 17:44 ` Saravana Kannan
2021-08-20 7:46 ` Chunyan Zhang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210715065455.392923-3-zhang.lyra@gmail.com \
--to=zhang.lyra@gmail.com \
--cc=baolin.wang7@gmail.com \
--cc=chunyan.zhang@unisoc.com \
--cc=daniel.lezcano@linaro.org \
--cc=linux-kernel@vger.kernel.org \
--cc=orsonzhai@gmail.com \
--cc=saravanak@google.com \
--cc=tglx@linutronix.de \
--subject='Re: [PATCH v2 2/3] clocksource/drivers/timer-of: Add boilerplate macros for timer module driver' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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).