pinctrl: sx150x: support building as module
Subsystems (2)
PATCH 1/1 pinctrl: sx150x: support building as module
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.
---
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(-)
drivers/pinctrl/Kconfig +1 -1
@@ -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
drivers/pinctrl/pinctrl-sx150x.c +7 -6
@@ -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 <[email protected]>" ); +MODULE_DESCRIPTION ("Semtech SX150x I2C GPIO expander" );
Signature · 1 line
2.29.2
Quoted 5 lines · Sander Vanheule
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.
Quoted 7 lines
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 <[email protected]>---
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.
...
Quoted 1 line
-#include <
linux/init.h>
Nope, you have to leave it. See more below.
Quoted 3 lines
#include <
linux/interrupt.h>
#include <linux/irq.h>
+#include <linux/module.h>
(This is correct)
...
Quoted 1 line
+module_i2c_driver(sx150x_driver);
Nope. You have to leave below.
Quoted 1 line
-subsys_initcall(sx150x_init);
subsys_initcall != device_initcall
Signature · 2 lines
With Best Regards, Andy Shevchenko