[PATCH] drm: Add helper macro for drm_i2c_encoder_driver boilerplate

Andrew F. Davis afd at ti.com
Thu Oct 22 11:30:12 PDT 2015


This patch introduces the module_drm_i2c_encoder_driver macro which is
a convenience macro for I2C encoder driver modules similar to others
such as module_platform_driver.

To help with this we also add the drm_i2c_encoder_register macro
that gets THIS_MODULE without include chaining or adding it to
every driver filel, renaming the old drm_i2c_encoder_register to
__drm_i2c_encoder_register, again similar to many other subsystems.

Finally, use this macro in all aplicable drivers.

Signed-off-by: Andrew F. Davis <afd at ti.com>
---
 drivers/gpu/drm/i2c/adv7511.c     | 12 +-----------
 drivers/gpu/drm/i2c/ch7006_drv.c  | 12 +-----------
 drivers/gpu/drm/i2c/sil164_drv.c  | 14 +-------------
 drivers/gpu/drm/i2c/tda998x_drv.c | 17 +----------------
 include/drm/drm_encoder_slave.h   | 23 +++++++++++++++++++----
 5 files changed, 23 insertions(+), 55 deletions(-)

diff --git a/drivers/gpu/drm/i2c/adv7511.c b/drivers/gpu/drm/i2c/adv7511.c
index 00416f2..c1d1206 100644
--- a/drivers/gpu/drm/i2c/adv7511.c
+++ b/drivers/gpu/drm/i2c/adv7511.c
@@ -997,17 +997,7 @@ static struct drm_i2c_encoder_driver adv7511_driver = {
 	.encoder_init = adv7511_encoder_init,
 };
 
-static int __init adv7511_init(void)
-{
-	return drm_i2c_encoder_register(THIS_MODULE, &adv7511_driver);
-}
-module_init(adv7511_init);
-
-static void __exit adv7511_exit(void)
-{
-	drm_i2c_encoder_unregister(&adv7511_driver);
-}
-module_exit(adv7511_exit);
+module_drm_i2c_encoder_driver(adv7511_driver);
 
 MODULE_AUTHOR("Lars-Peter Clausen <lars at metafoo.de>");
 MODULE_DESCRIPTION("ADV7511 HDMI transmitter driver");
diff --git a/drivers/gpu/drm/i2c/ch7006_drv.c b/drivers/gpu/drm/i2c/ch7006_drv.c
index 51fa323..cdf79f8 100644
--- a/drivers/gpu/drm/i2c/ch7006_drv.c
+++ b/drivers/gpu/drm/i2c/ch7006_drv.c
@@ -517,15 +517,7 @@ static struct drm_i2c_encoder_driver ch7006_driver = {
 
 /* Module initialization */
 
-static int __init ch7006_init(void)
-{
-	return drm_i2c_encoder_register(THIS_MODULE, &ch7006_driver);
-}
-
-static void __exit ch7006_exit(void)
-{
-	drm_i2c_encoder_unregister(&ch7006_driver);
-}
+module_drm_i2c_encoder_driver(ch7006_driver);
 
 int ch7006_debug;
 module_param_named(debug, ch7006_debug, int, 0600);
@@ -548,5 +540,3 @@ MODULE_AUTHOR("Francisco Jerez <currojerez at riseup.net>");
 MODULE_DESCRIPTION("Chrontel ch7006 TV encoder driver");
 MODULE_LICENSE("GPL and additional rights");
 
-module_init(ch7006_init);
-module_exit(ch7006_exit);
diff --git a/drivers/gpu/drm/i2c/sil164_drv.c b/drivers/gpu/drm/i2c/sil164_drv.c
index 002ce78..2d217ba 100644
--- a/drivers/gpu/drm/i2c/sil164_drv.c
+++ b/drivers/gpu/drm/i2c/sil164_drv.c
@@ -444,21 +444,9 @@ static struct drm_i2c_encoder_driver sil164_driver = {
 
 /* Module initialization */
 
-static int __init
-sil164_init(void)
-{
-	return drm_i2c_encoder_register(THIS_MODULE, &sil164_driver);
-}
-
-static void __exit
-sil164_exit(void)
-{
-	drm_i2c_encoder_unregister(&sil164_driver);
-}
+module_drm_i2c_encoder_driver(sil164_driver);
 
 MODULE_AUTHOR("Francisco Jerez <currojerez at riseup.net>");
 MODULE_DESCRIPTION("Silicon Image sil164 TMDS transmitter driver");
 MODULE_LICENSE("GPL and additional rights");
 
-module_init(sil164_init);
-module_exit(sil164_exit);
diff --git a/drivers/gpu/drm/i2c/tda998x_drv.c b/drivers/gpu/drm/i2c/tda998x_drv.c
index 424228b..2d77a5a 100644
--- a/drivers/gpu/drm/i2c/tda998x_drv.c
+++ b/drivers/gpu/drm/i2c/tda998x_drv.c
@@ -1620,23 +1620,8 @@ static struct drm_i2c_encoder_driver tda998x_driver = {
 
 /* Module initialization */
 
-static int __init
-tda998x_init(void)
-{
-	DBG("");
-	return drm_i2c_encoder_register(THIS_MODULE, &tda998x_driver);
-}
-
-static void __exit
-tda998x_exit(void)
-{
-	DBG("");
-	drm_i2c_encoder_unregister(&tda998x_driver);
-}
+module_drm_i2c_encoder_driver(tda998x_driver);
 
 MODULE_AUTHOR("Rob Clark <robdclark at gmail.com");
 MODULE_DESCRIPTION("NXP Semiconductors TDA998X HDMI Encoder");
 MODULE_LICENSE("GPL");
-
-module_init(tda998x_init);
-module_exit(tda998x_exit);
diff --git a/include/drm/drm_encoder_slave.h b/include/drm/drm_encoder_slave.h
index 8b9cc36..d80dc9d 100644
--- a/include/drm/drm_encoder_slave.h
+++ b/include/drm/drm_encoder_slave.h
@@ -138,16 +138,20 @@ static inline struct i2c_client *drm_i2c_encoder_get_client(struct drm_encoder *
 }
 
 /**
- * drm_i2c_encoder_register - Register an I2C encoder driver
+ * __drm_i2c_encoder_register - Register an I2C encoder driver
  * @owner:	Module containing the driver.
  * @driver:	Driver to be registered.
  */
-static inline int drm_i2c_encoder_register(struct module *owner,
-					   struct drm_i2c_encoder_driver *driver)
+static inline int __drm_i2c_encoder_register(struct module *owner,
+					     struct drm_i2c_encoder_driver *driver)
 {
 	return i2c_register_driver(owner, &driver->i2c_driver);
 }
 
+/* use a define to avoid include chaining to get THIS_MODULE */
+#define drm_i2c_encoder_register(driver) \
+	__drm_i2c_encoder_register(THIS_MODULE, driver)
+
 /**
  * drm_i2c_encoder_unregister - Unregister an I2C encoder driver
  * @driver:	Driver to be unregistered.
@@ -159,7 +163,6 @@ static inline void drm_i2c_encoder_unregister(struct drm_i2c_encoder_driver *dri
 
 void drm_i2c_encoder_destroy(struct drm_encoder *encoder);
 
-
 /*
  * Wrapper fxns which can be plugged in to drm_encoder_helper_funcs:
  */
@@ -178,5 +181,17 @@ enum drm_connector_status drm_i2c_encoder_detect(struct drm_encoder *encoder,
 void drm_i2c_encoder_save(struct drm_encoder *encoder);
 void drm_i2c_encoder_restore(struct drm_encoder *encoder);
 
+/**
+ * module_drm_i2c_encoder_driver() - Helper macro for registering a I2C
+ * Encoder driver
+ * @__drm_i2c_encoder_driver: drm_i2c_encoder_driver struct
+ *
+ * Helper macro for I2C Encoder drivers which do not do anything special in
+ * module init/exit. This eliminates a lot of boilerplate. Each module may only
+ * use this macro once, and calling it replaces module_init() and module_exit()
+ */
+#define module_drm_i2c_encoder_driver(__drm_i2c_encoder_driver) \
+	module_driver(__drm_i2c_encoder_driver, drm_i2c_encoder_register, \
+			drm_i2c_encoder_unregister)
 
 #endif
-- 
1.9.1



More information about the dri-devel mailing list