Skip to content

Commit

Permalink
i2c: create builtin_i2c_driver to avoid registration boilerplate
Browse files Browse the repository at this point in the history
In commit f309d44 ("platform_device:
better support builtin boilerplate avoidance") we introduced the
builtin_driver macro.

Here we use that support and extend it to I2C driver registration,
so where a driver is clearly non-modular and builtin-only, we can
register it in a similar fashion.  And existing code that is clearly
non-modular can be updated with the simple mapping of

     module_i2c_driver(...)  ---> builtin_i2c_driver(...)

We've essentially cloned the former to make the latter, and taken
out the remove/module_exit parts since those never get used in a
non-modular build of the code.

A similar thing was done in commit b4eb6cd
("PCI: Add builtin_pci_driver() to avoid registration boilerplate").

Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
  • Loading branch information
Paul Gortmaker authored and Wolfram Sang committed Jan 13, 2016
1 parent c552815 commit c698d63
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion include/linux/i2c.h
Original file line number Diff line number Diff line change
Expand Up @@ -655,7 +655,7 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap)
}

/**
* module_i2c_driver() - Helper macro for registering a I2C driver
* module_i2c_driver() - Helper macro for registering a modular I2C driver
* @__i2c_driver: i2c_driver struct
*
* Helper macro for I2C drivers which do not do anything special in module
Expand All @@ -666,6 +666,17 @@ static inline int i2c_adapter_id(struct i2c_adapter *adap)
module_driver(__i2c_driver, i2c_add_driver, \
i2c_del_driver)

/**
* builtin_i2c_driver() - Helper macro for registering a builtin I2C driver
* @__i2c_driver: i2c_driver struct
*
* Helper macro for I2C drivers which do not do anything special in their
* init. This eliminates a lot of boilerplate. Each driver may only
* use this macro once, and calling it replaces device_initcall().
*/
#define builtin_i2c_driver(__i2c_driver) \
builtin_driver(__i2c_driver, i2c_add_driver)

#endif /* I2C */

#if IS_ENABLED(CONFIG_OF)
Expand Down

0 comments on commit c698d63

Please sign in to comment.