Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Input: ad714x - unify dev_pm_ops using EXPORT_SIMPLE_DEV_PM_OPS()

The I2C and SPI PM callbacks were identical (though wrapped in some
bouncing out to the bus specific container of the struct device and
then back again to get the drvdata). As such rather than just moving
these to SIMPLE_DEV_PM_OPS() and pm_sleep_ptr() take the opportunity
to unify the struct dev_pm_ops and use the new EXPORT_SIMPLE_DEV_PM_OPS()
macro so that we can drop the unused suspend and resume callbacks as well
as the structure if !CONFIG_PM_SLEEP without needing to mark the callbacks
__maybe_unused.

Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Cc: Michael Hennerich <michael.hennerich@analog.com>
Link: https://lore.kernel.org/r/20230114171620.42891-8-jic23@kernel.org
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>

authored by

Jonathan Cameron and committed by
Dmitry Torokhov
c0a150ee 90208b31

+10 -34
+1 -13
drivers/input/misc/ad714x-i2c.c
··· 12 12 #include <linux/pm.h> 13 13 #include "ad714x.h" 14 14 15 - static int __maybe_unused ad714x_i2c_suspend(struct device *dev) 16 - { 17 - return ad714x_disable(i2c_get_clientdata(to_i2c_client(dev))); 18 - } 19 - 20 - static int __maybe_unused ad714x_i2c_resume(struct device *dev) 21 - { 22 - return ad714x_enable(i2c_get_clientdata(to_i2c_client(dev))); 23 - } 24 - 25 - static SIMPLE_DEV_PM_OPS(ad714x_i2c_pm, ad714x_i2c_suspend, ad714x_i2c_resume); 26 - 27 15 static int ad714x_i2c_write(struct ad714x_chip *chip, 28 16 unsigned short reg, unsigned short data) 29 17 { ··· 84 96 static struct i2c_driver ad714x_i2c_driver = { 85 97 .driver = { 86 98 .name = "ad714x_captouch", 87 - .pm = &ad714x_i2c_pm, 99 + .pm = pm_sleep_ptr(&ad714x_pm), 88 100 }, 89 101 .probe_new = ad714x_i2c_probe, 90 102 .id_table = ad714x_id,
+1 -13
drivers/input/misc/ad714x-spi.c
··· 15 15 #define AD714x_SPI_CMD_PREFIX 0xE000 /* bits 15:11 */ 16 16 #define AD714x_SPI_READ BIT(10) 17 17 18 - static int __maybe_unused ad714x_spi_suspend(struct device *dev) 19 - { 20 - return ad714x_disable(spi_get_drvdata(to_spi_device(dev))); 21 - } 22 - 23 - static int __maybe_unused ad714x_spi_resume(struct device *dev) 24 - { 25 - return ad714x_enable(spi_get_drvdata(to_spi_device(dev))); 26 - } 27 - 28 - static SIMPLE_DEV_PM_OPS(ad714x_spi_pm, ad714x_spi_suspend, ad714x_spi_resume); 29 - 30 18 static int ad714x_spi_read(struct ad714x_chip *chip, 31 19 unsigned short reg, unsigned short *data, size_t len) 32 20 { ··· 91 103 static struct spi_driver ad714x_spi_driver = { 92 104 .driver = { 93 105 .name = "ad714x_captouch", 94 - .pm = &ad714x_spi_pm, 106 + .pm = pm_sleep_ptr(&ad714x_pm), 95 107 }, 96 108 .probe = ad714x_spi_probe, 97 109 };
+6 -6
drivers/input/misc/ad714x.c
··· 1162 1162 } 1163 1163 EXPORT_SYMBOL(ad714x_probe); 1164 1164 1165 - #ifdef CONFIG_PM 1166 - int ad714x_disable(struct ad714x_chip *ad714x) 1165 + static int ad714x_suspend(struct device *dev) 1167 1166 { 1167 + struct ad714x_chip *ad714x = dev_get_drvdata(dev); 1168 1168 unsigned short data; 1169 1169 1170 1170 dev_dbg(ad714x->dev, "%s enter\n", __func__); ··· 1178 1178 1179 1179 return 0; 1180 1180 } 1181 - EXPORT_SYMBOL(ad714x_disable); 1182 1181 1183 - int ad714x_enable(struct ad714x_chip *ad714x) 1182 + static int ad714x_resume(struct device *dev) 1184 1183 { 1184 + struct ad714x_chip *ad714x = dev_get_drvdata(dev); 1185 1185 dev_dbg(ad714x->dev, "%s enter\n", __func__); 1186 1186 1187 1187 mutex_lock(&ad714x->mutex); ··· 1201 1201 1202 1202 return 0; 1203 1203 } 1204 - EXPORT_SYMBOL(ad714x_enable); 1205 - #endif 1204 + 1205 + EXPORT_SIMPLE_DEV_PM_OPS(ad714x_pm, ad714x_suspend, ad714x_resume); 1206 1206 1207 1207 MODULE_DESCRIPTION("Analog Devices AD714X Capacitance Touch Sensor Driver"); 1208 1208 MODULE_AUTHOR("Barry Song <21cnbao@gmail.com>");
+2 -2
drivers/input/misc/ad714x.h
··· 8 8 #ifndef _AD714X_H_ 9 9 #define _AD714X_H_ 10 10 11 + #include <linux/pm.h> 11 12 #include <linux/types.h> 12 13 13 14 #define STAGE_NUM 12 ··· 46 45 47 46 }; 48 47 49 - int ad714x_disable(struct ad714x_chip *ad714x); 50 - int ad714x_enable(struct ad714x_chip *ad714x); 48 + extern const struct dev_pm_ops ad714x_pm; 51 49 struct ad714x_chip *ad714x_probe(struct device *dev, u16 bus_type, int irq, 52 50 ad714x_read_t read, ad714x_write_t write); 53 51