From 2b6af97a260ab5eb456086e614ad9973f25445ff Mon Sep 17 00:00:00 2001 From: mattis fjallstrom Date: Fri, 4 Mar 2016 13:58:51 -0800 Subject: Adding suspend and resume functions for ALS, to ensure that it's off when the rest of the watch is. Change-Id: I8da5b894ec45fbc95de5115833b2785812b7b580 --- drivers/iio/light/cm3391.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'drivers/iio/light/cm3391.c') diff --git a/drivers/iio/light/cm3391.c b/drivers/iio/light/cm3391.c index 8049446d98a..b6461852a57 100644 --- a/drivers/iio/light/cm3391.c +++ b/drivers/iio/light/cm3391.c @@ -828,6 +828,28 @@ static int cm3391_remove(struct i2c_client *client) return 0; } +static int old_config = CM3391_CMD_DEFAULT; + +static int cm3391_suspend(struct i2c_client *client, pm_message_t mesg) +{ + old_config = i2c_smbus_read_word_data(client, + CM3391_REG_ADDR_CMD); + /* Disable device */ + i2c_smbus_write_word_data(client, CM3391_REG_ADDR_CMD, + CM3391_CMD_CS_DISABLE); + + return 0; +} + +static int cm3391_resume(struct i2c_client *client) +{ + /* enable device */ + i2c_smbus_write_word_data(client, CM3391_REG_ADDR_CMD, + old_config); + + return 0; +} + static const struct i2c_device_id cm3391_id[] = { { "cm3391", 0}, { } @@ -861,6 +883,8 @@ static struct i2c_driver cm3391_driver = { .id_table = cm3391_id, .probe = cm3391_probe, .remove = cm3391_remove, + .suspend = cm3391_suspend, + .resume = cm3391_resume, }; module_i2c_driver(cm3391_driver); -- cgit v1.2.3-70-g09d2