can: mcp251x: Remove redundant spi driver bus initialization
PATCH 1/3 can: mcp251x: Remove redundant spi driver bus initialization
In ancient times it was necessary to manually initialize the bus field of an spi_driver to spi_bus_type. These days this is done in spi_driver_register() so we can drop the manual assignment.
The patch was generated using the following coccinelle semantic patch:
// <smpl>
@@
identifier _driver;
@@
struct spi_driver _driver = {
.driver = {
- .bus = &spi_bus_type,
},
};// </smpl>
--- drivers/net/can/mcp251x.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/can/mcp251x.c +0 -1
@@ -1207,7 +1207,6 @@ MODULE_DEVICE_TABLE(spi, mcp251x_id_table);static struct spi_driver mcp251x_can_driver = { .driver = { .name =DEVICE_NAME , - .bus = &spi_bus_type, .owner =THIS_MODULE , },
Signature · 1 line
1.8.0
PATCH 2/3 can: mcp251x: Use module_spi_driver
By using module_spi_driver we can eliminate a few lines of boilerplate code.
--- drivers/net/can/mcp251x.c | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-)
drivers/net/can/mcp251x.c +1 -13
@@ -1216,19 +1216,7 @@ static struct spi_driver mcp251x_can_driver = { .suspend = mcp251x_can_suspend, .resume = mcp251x_can_resume, }; - -static int __init mcp251x_can_init (void ) -{ -return spi_register_driver (&mcp251x_can_driver); -} - -static void __exit mcp251x_can_exit(void) -{ -spi_unregister_driver (&mcp251x_can_driver); -} - -module_init (mcp251x_can_init); -module_exit (mcp251x_can_exit); +module_spi_driver (mcp251x_can_driver);MODULE_AUTHOR ("Chris Elston <[email protected]>, " "Christian Pellegrin <[email protected]>" );
Signature · 1 line
1.8.0
PATCH 3/3 can: mcp251x: Use dev_pm_ops
In reply to Lars-Peter ClausenUse dev_pm_ops instead of the deprecated legacy suspend/resume callbacks.
--- drivers/net/can/mcp251x.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-)
drivers/net/can/mcp251x.c +13 -7
@@ -1138,9 +1138,11 @@ static int mcp251x_can_remove(struct spi_device *spi)return 0 ; } -#ifdef CONFIG_PM -static int mcp251x_can_suspend (struct spi_device *spi,pm_message_t state) +#ifdef CONFIG_PM_SLEEP + +static int mcp251x_can_suspend (struct device *dev) { +struct spi_device *spi =to_spi_device (dev);struct mcp251x_platform_data *pdata = spi->dev.platform_data;struct mcp251x_priv *priv =dev_get_drvdata (&spi->dev);struct net_device *net = priv->net;
@@ -1170,8 +1172,9 @@ static int mcp251x_can_suspend(struct spi_device *spi, pm_message_t state)return 0 ; } -static int mcp251x_can_resume (struct spi_device *spi) +static int mcp251x_can_resume (struct device *dev) { +struct spi_device *spi =to_spi_device (dev);struct mcp251x_platform_data *pdata = spi->dev.platform_data;struct mcp251x_priv *priv =dev_get_drvdata (&spi->dev);
@@ -1191,9 +1194,13 @@ static int mcp251x_can_resume(struct spi_device *spi)enable_irq (spi->irq);return 0 ; } + +static SIMPLE_DEV_PM_OPS(mcp251x_can_pm_ops, mcp251x_can_suspend, + mcp251x_can_resume); +#define MCP251X_PM_OPS (&mcp251x_can_pm_ops) +#else -#define mcp251x_can_suspend NULL -#define mcp251x_can_resume NULL +#define MCP251X_PM_OPS NULL#endif static const struct spi_device_id mcp251x_id_table[] = {
@@ -1208,13 +1215,12 @@ static struct spi_driver mcp251x_can_driver = { .driver = { .name = DEVICE_NAME, .owner = THIS_MODULE, + .pm = MCP251X_PM_OPS, }, .id_table = mcp251x_id_table, .probe = mcp251x_can_probe, .remove = mcp251x_can_remove, - .suspend = mcp251x_can_suspend, - .resume = mcp251x_can_resume, };module_spi_driver (mcp251x_can_driver);
Signature · 1 line
1.8.0
Marc Kleine-Budde
maintainerQuoted 3 lines · Lars-Peter Clausen
In ancient times it was necessary to manually initialize the bus field of an
spi_drivertospi_bus_type. These days this is done inspi_driver_register()so we can drop the manual assignment.
Applied all three patches.
Tnx,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |