diff mbox series

pinctrl: sx150x: support building as module

Message ID 20210304201119.702637-1-sander@svanheule.net
State New
Headers show
Series pinctrl: sx150x: support building as module | expand

Commit Message

Sander Vanheule March 4, 2021, 8:11 p.m. UTC
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(-)

Comments

Andy Shevchenko March 7, 2021, 7:24 p.m. UTC | #1
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
diff mbox series

Patch

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");