diff options
Diffstat (limited to 'drivers/misc/apds9802als.c')
| -rw-r--r-- | drivers/misc/apds9802als.c | 59 | 
1 files changed, 17 insertions, 42 deletions
diff --git a/drivers/misc/apds9802als.c b/drivers/misc/apds9802als.c index 0ed09358027..c6cc3dc8ae1 100644 --- a/drivers/misc/apds9802als.c +++ b/drivers/misc/apds9802als.c @@ -22,7 +22,6 @@   */  #include <linux/module.h> -#include <linux/init.h>  #include <linux/slab.h>  #include <linux/i2c.h>  #include <linux/err.h> @@ -68,7 +67,7 @@ static int als_wait_for_data_ready(struct device *dev)  		ret = i2c_smbus_read_byte_data(client, 0x86);  	} while (!(ret & 0x80) && retry--); -	if (!retry) { +	if (retry < 0) {  		dev_warn(dev, "timeout waiting for data ready\n");  		return -ETIMEDOUT;  	} @@ -126,8 +125,9 @@ static ssize_t als_sensing_range_store(struct device *dev,  	int ret_val;  	unsigned long val; -	if (strict_strtoul(buf, 10, &val)) -		return -EINVAL; +	ret_val = kstrtoul(buf, 10, &val); +	if (ret_val) +		return ret_val;  	if (val < 4096)  		val = 1; @@ -245,13 +245,11 @@ static int apds9802als_probe(struct i2c_client *client,  	als_set_default_config(client);  	mutex_init(&data->mutex); +	pm_runtime_set_active(&client->dev);  	pm_runtime_enable(&client->dev); -	pm_runtime_get(&client->dev); -	pm_runtime_put(&client->dev);  	return res;  als_error1: -	i2c_set_clientdata(client, NULL);  	kfree(data);  	return res;  } @@ -260,29 +258,22 @@ static int apds9802als_remove(struct i2c_client *client)  {  	struct als_data *data = i2c_get_clientdata(client); +	pm_runtime_get_sync(&client->dev); +  	als_set_power_state(client, false);  	sysfs_remove_group(&client->dev.kobj, &m_als_gr); + +	pm_runtime_disable(&client->dev); +	pm_runtime_set_suspended(&client->dev); +	pm_runtime_put_noidle(&client->dev); +  	kfree(data);  	return 0;  }  #ifdef CONFIG_PM -static int apds9802als_suspend(struct i2c_client *client, pm_message_t mesg) -{ -	als_set_power_state(client, false); -	return 0; -} - -static int apds9802als_resume(struct i2c_client *client) -{ -	als_set_default_config(client); -	pm_runtime_get(&client->dev); -	pm_runtime_put(&client->dev); -	return 0; -} - -static int apds9802als_runtime_suspend(struct device *dev) +static int apds9802als_suspend(struct device *dev)  {  	struct i2c_client *client = to_i2c_client(dev); @@ -290,7 +281,7 @@ static int apds9802als_runtime_suspend(struct device *dev)  	return 0;  } -static int apds9802als_runtime_resume(struct device *dev) +static int apds9802als_resume(struct device *dev)  {  	struct i2c_client *client = to_i2c_client(dev); @@ -298,16 +289,12 @@ static int apds9802als_runtime_resume(struct device *dev)  	return 0;  } -static const struct dev_pm_ops apds9802als_pm_ops = { -	.runtime_suspend = apds9802als_runtime_suspend, -	.runtime_resume = apds9802als_runtime_resume, -}; +static UNIVERSAL_DEV_PM_OPS(apds9802als_pm_ops, apds9802als_suspend, +	apds9802als_resume, NULL);  #define APDS9802ALS_PM_OPS (&apds9802als_pm_ops)  #else	/* CONFIG_PM */ -#define apds9802als_suspend NULL -#define apds9802als_resume NULL  #define APDS9802ALS_PM_OPS NULL  #endif	/* CONFIG_PM */ @@ -325,22 +312,10 @@ static struct i2c_driver apds9802als_driver = {  	},  	.probe = apds9802als_probe,  	.remove = apds9802als_remove, -	.suspend = apds9802als_suspend, -	.resume = apds9802als_resume,  	.id_table = apds9802als_id,  }; -static int __init sensor_apds9802als_init(void) -{ -	return i2c_add_driver(&apds9802als_driver); -} - -static void  __exit sensor_apds9802als_exit(void) -{ -	i2c_del_driver(&apds9802als_driver); -} -module_init(sensor_apds9802als_init); -module_exit(sensor_apds9802als_exit); +module_i2c_driver(apds9802als_driver);  MODULE_AUTHOR("Anantha Narayanan <Anantha.Narayanan@intel.com");  MODULE_DESCRIPTION("Avago apds9802als ALS Driver");  | 
