Skip to content

Commit 40be064

Browse files
jic23dtor
authored andcommitted
Input: adxl34x - 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 <[email protected]> Cc: Michael Hennerich <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Dmitry Torokhov <[email protected]>
1 parent c0a150e commit 40be064

File tree

4 files changed

+16
-54
lines changed

4 files changed

+16
-54
lines changed

drivers/input/misc/adxl34x-i2c.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -105,29 +105,6 @@ static void adxl34x_i2c_remove(struct i2c_client *client)
105105
adxl34x_remove(ac);
106106
}
107107

108-
static int __maybe_unused adxl34x_i2c_suspend(struct device *dev)
109-
{
110-
struct i2c_client *client = to_i2c_client(dev);
111-
struct adxl34x *ac = i2c_get_clientdata(client);
112-
113-
adxl34x_suspend(ac);
114-
115-
return 0;
116-
}
117-
118-
static int __maybe_unused adxl34x_i2c_resume(struct device *dev)
119-
{
120-
struct i2c_client *client = to_i2c_client(dev);
121-
struct adxl34x *ac = i2c_get_clientdata(client);
122-
123-
adxl34x_resume(ac);
124-
125-
return 0;
126-
}
127-
128-
static SIMPLE_DEV_PM_OPS(adxl34x_i2c_pm, adxl34x_i2c_suspend,
129-
adxl34x_i2c_resume);
130-
131108
static const struct i2c_device_id adxl34x_id[] = {
132109
{ "adxl34x", 0 },
133110
{ }
@@ -155,7 +132,7 @@ MODULE_DEVICE_TABLE(of, adxl34x_of_id);
155132
static struct i2c_driver adxl34x_driver = {
156133
.driver = {
157134
.name = "adxl34x",
158-
.pm = &adxl34x_i2c_pm,
135+
.pm = pm_sleep_ptr(&adxl34x_pm),
159136
.of_match_table = adxl34x_of_id,
160137
},
161138
.probe_new = adxl34x_i2c_probe,

drivers/input/misc/adxl34x-spi.c

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -94,33 +94,10 @@ static void adxl34x_spi_remove(struct spi_device *spi)
9494
adxl34x_remove(ac);
9595
}
9696

97-
static int __maybe_unused adxl34x_spi_suspend(struct device *dev)
98-
{
99-
struct spi_device *spi = to_spi_device(dev);
100-
struct adxl34x *ac = spi_get_drvdata(spi);
101-
102-
adxl34x_suspend(ac);
103-
104-
return 0;
105-
}
106-
107-
static int __maybe_unused adxl34x_spi_resume(struct device *dev)
108-
{
109-
struct spi_device *spi = to_spi_device(dev);
110-
struct adxl34x *ac = spi_get_drvdata(spi);
111-
112-
adxl34x_resume(ac);
113-
114-
return 0;
115-
}
116-
117-
static SIMPLE_DEV_PM_OPS(adxl34x_spi_pm, adxl34x_spi_suspend,
118-
adxl34x_spi_resume);
119-
12097
static struct spi_driver adxl34x_driver = {
12198
.driver = {
12299
.name = "adxl34x",
123-
.pm = &adxl34x_spi_pm,
100+
.pm = pm_sleep_ptr(&adxl34x_pm),
124101
},
125102
.probe = adxl34x_spi_probe,
126103
.remove = adxl34x_spi_remove,

drivers/input/misc/adxl34x.c

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,10 @@ static void __adxl34x_enable(struct adxl34x *ac)
412412
AC_WRITE(ac, POWER_CTL, ac->pdata.power_mode | PCTL_MEASURE);
413413
}
414414

415-
void adxl34x_suspend(struct adxl34x *ac)
415+
static int adxl34x_suspend(struct device *dev)
416416
{
417+
struct adxl34x *ac = dev_get_drvdata(dev);
418+
417419
mutex_lock(&ac->mutex);
418420

419421
if (!ac->suspended && !ac->disabled && ac->opened)
@@ -422,11 +424,14 @@ void adxl34x_suspend(struct adxl34x *ac)
422424
ac->suspended = true;
423425

424426
mutex_unlock(&ac->mutex);
427+
428+
return 0;
425429
}
426-
EXPORT_SYMBOL_GPL(adxl34x_suspend);
427430

428-
void adxl34x_resume(struct adxl34x *ac)
431+
static int adxl34x_resume(struct device *dev)
429432
{
433+
struct adxl34x *ac = dev_get_drvdata(dev);
434+
430435
mutex_lock(&ac->mutex);
431436

432437
if (ac->suspended && !ac->disabled && ac->opened)
@@ -435,8 +440,9 @@ void adxl34x_resume(struct adxl34x *ac)
435440
ac->suspended = false;
436441

437442
mutex_unlock(&ac->mutex);
443+
444+
return 0;
438445
}
439-
EXPORT_SYMBOL_GPL(adxl34x_resume);
440446

441447
static ssize_t adxl34x_disable_show(struct device *dev,
442448
struct device_attribute *attr, char *buf)
@@ -906,6 +912,8 @@ void adxl34x_remove(struct adxl34x *ac)
906912
}
907913
EXPORT_SYMBOL_GPL(adxl34x_remove);
908914

915+
EXPORT_GPL_SIMPLE_DEV_PM_OPS(adxl34x_pm, adxl34x_suspend, adxl34x_resume);
916+
909917
MODULE_AUTHOR("Michael Hennerich <[email protected]>");
910918
MODULE_DESCRIPTION("ADXL345/346 Three-Axis Digital Accelerometer Driver");
911919
MODULE_LICENSE("GPL");

drivers/input/misc/adxl34x.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ struct adxl34x_bus_ops {
2020
int (*write)(struct device *, unsigned char, unsigned char);
2121
};
2222

23-
void adxl34x_suspend(struct adxl34x *ac);
24-
void adxl34x_resume(struct adxl34x *ac);
2523
struct adxl34x *adxl34x_probe(struct device *dev, int irq,
2624
bool fifo_delay_default,
2725
const struct adxl34x_bus_ops *bops);
2826
void adxl34x_remove(struct adxl34x *ac);
2927

28+
extern const struct dev_pm_ops adxl34x_pm;
29+
3030
#endif

0 commit comments

Comments
 (0)