All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pinctrl: sx150x: support building as module
@ 2021-03-04 20:11 Sander Vanheule
  2021-03-07 19:24 ` Andy Shevchenko
  0 siblings, 1 reply; 2+ messages in thread
From: Sander Vanheule @ 2021-03-04 20:11 UTC (permalink / raw)
  To: linux-gpio; +Cc: Linus Walleij, Sander Vanheule, Gregory Bean

The SX150x GPIO expander driver, and the subsystems it depends on, have
seen some development since its initial introduction. Let's add some
extra bits to enable building it as a module.

Build tested on 5.12-rc1. Run tested on a MIPS device with OpenWrt,
kernel version 5.4.101, to confirm unloading/reloading works.

Signed-off-by: Sander Vanheule <sander@svanheule.net>
---
This is the first time I've attempted to create a driver that can be
built as a module, so there's a reasonable chance I missed some things.

As the commit message notes, I've tested loading/unloading on a 5.4
kernel in OpenWrt, and no obvious regressions were encountered.

MODULE_LICENSE/_AUTHOR were copied from the driver's comment header.

 drivers/pinctrl/Kconfig          |  2 +-
 drivers/pinctrl/pinctrl-sx150x.c | 13 +++++++------
 2 files changed, 8 insertions(+), 7 deletions(-)

diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig
index b7675cce0027..50ce0caf18f0 100644
--- a/drivers/pinctrl/Kconfig
+++ b/drivers/pinctrl/Kconfig
@@ -227,7 +227,7 @@ config PINCTRL_SINGLE
 	  This selects the device tree based generic pinctrl driver.
 
 config PINCTRL_SX150X
-	bool "Semtech SX150x I2C GPIO expander pinctrl driver"
+	tristate "Semtech SX150x I2C GPIO expander pinctrl driver"
 	depends on I2C=y
 	select PINMUX
 	select PINCONF
diff --git a/drivers/pinctrl/pinctrl-sx150x.c b/drivers/pinctrl/pinctrl-sx150x.c
index 484a3b9e875c..ac589c1e939a 100644
--- a/drivers/pinctrl/pinctrl-sx150x.c
+++ b/drivers/pinctrl/pinctrl-sx150x.c
@@ -13,9 +13,9 @@
 
 #include <linux/regmap.h>
 #include <linux/i2c.h>
-#include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
+#include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/slab.h>
 #include <linux/of.h>
@@ -829,6 +829,7 @@ static const struct i2c_device_id sx150x_id[] = {
 	{"sx1509q", (kernel_ulong_t) &sx1509q_device_data },
 	{}
 };
+MODULE_DEVICE_TABLE(i2c, sx150x_id);
 
 static const struct of_device_id sx150x_of_match[] = {
 	{ .compatible = "semtech,sx1501q", .data = &sx1501q_device_data },
@@ -842,6 +843,7 @@ static const struct of_device_id sx150x_of_match[] = {
 	{ .compatible = "semtech,sx1509q", .data = &sx1509q_device_data },
 	{},
 };
+MODULE_DEVICE_TABLE(of, sx150x_of_match);
 
 static int sx150x_reset(struct sx150x_pinctrl *pctl)
 {
@@ -1258,9 +1260,8 @@ static struct i2c_driver sx150x_driver = {
 	.probe    = sx150x_probe,
 	.id_table = sx150x_id,
 };
+module_i2c_driver(sx150x_driver);
 
-static int __init sx150x_init(void)
-{
-	return i2c_add_driver(&sx150x_driver);
-}
-subsys_initcall(sx150x_init);
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Gregory Bean <gbean@codeaurora.org>");
+MODULE_DESCRIPTION("Semtech SX150x I2C GPIO expander");
-- 
2.29.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] pinctrl: sx150x: support building as module
  2021-03-04 20:11 [PATCH] pinctrl: sx150x: support building as module Sander Vanheule
@ 2021-03-07 19:24 ` Andy Shevchenko
  0 siblings, 0 replies; 2+ messages in thread
From: Andy Shevchenko @ 2021-03-07 19:24 UTC (permalink / raw)
  To: Sander Vanheule; +Cc: open list:GPIO SUBSYSTEM, Linus Walleij, Gregory Bean

On Fri, Mar 5, 2021 at 2:57 AM Sander Vanheule <sander@svanheule.net> wrote:
>
> The SX150x GPIO expander driver, and the subsystems it depends on, have
> seen some development since its initial introduction. Let's add some
> extra bits to enable building it as a module.
>
> Build tested on 5.12-rc1. Run tested on a MIPS device with OpenWrt,
> kernel version 5.4.101, to confirm unloading/reloading works.
>
> Signed-off-by: Sander Vanheule <sander@svanheule.net>
> ---
> This is the first time I've attempted to create a driver that can be
> built as a module, so there's a reasonable chance I missed some things.

Indeed, see below.

...

> -#include <linux/init.h>

Nope, you have to leave it. See more below.

>  #include <linux/interrupt.h>
>  #include <linux/irq.h>
> +#include <linux/module.h>

(This is correct)

...

> +module_i2c_driver(sx150x_driver);

Nope. You have to leave below.

> -subsys_initcall(sx150x_init);

subsys_initcall != device_initcall


-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-03-07 19:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-04 20:11 [PATCH] pinctrl: sx150x: support building as module Sander Vanheule
2021-03-07 19:24 ` Andy Shevchenko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.