提交 a22a3c5c 编写于 作者: A Adriana Reus 提交者: Jonathan Cameron

iio: light: us5182d: Add functions for selectively enabling als and proximity

Keep track of the als and px enabled/disabled status in
order to enable them selectively.
Signed-off-by: NAdriana Reus <adriana.reus@intel.com>
Signed-off-by: NJonathan Cameron <jic23@kernel.org>
上级 023e30fb
...@@ -119,6 +119,9 @@ struct us5182d_data { ...@@ -119,6 +119,9 @@ struct us5182d_data {
u8 opmode; u8 opmode;
u8 power_mode; u8 power_mode;
bool als_enabled;
bool px_enabled;
bool default_continuous; bool default_continuous;
}; };
...@@ -227,6 +230,50 @@ static int us5182d_set_opmode(struct us5182d_data *data, u8 mode) ...@@ -227,6 +230,50 @@ static int us5182d_set_opmode(struct us5182d_data *data, u8 mode)
return 0; return 0;
} }
static int us5182d_als_enable(struct us5182d_data *data)
{
int ret;
u8 mode;
if (data->power_mode == US5182D_ONESHOT)
return us5182d_set_opmode(data, US5182D_ALS_ONLY);
if (data->als_enabled)
return 0;
mode = data->px_enabled ? US5182D_ALS_PX : US5182D_ALS_ONLY;
ret = us5182d_set_opmode(data, mode);
if (ret < 0)
return ret;
data->als_enabled = true;
return 0;
}
static int us5182d_px_enable(struct us5182d_data *data)
{
int ret;
u8 mode;
if (data->power_mode == US5182D_ONESHOT)
return us5182d_set_opmode(data, US5182D_PX_ONLY);
if (data->px_enabled)
return 0;
mode = data->als_enabled ? US5182D_ALS_PX : US5182D_PX_ONLY;
ret = us5182d_set_opmode(data, mode);
if (ret < 0)
return ret;
data->px_enabled = true;
return 0;
}
static int us5182d_shutdown_en(struct us5182d_data *data, u8 state) static int us5182d_shutdown_en(struct us5182d_data *data, u8 state)
{ {
int ret; int ret;
...@@ -241,7 +288,16 @@ static int us5182d_shutdown_en(struct us5182d_data *data, u8 state) ...@@ -241,7 +288,16 @@ static int us5182d_shutdown_en(struct us5182d_data *data, u8 state)
ret = ret & ~US5182D_CFG0_SHUTDOWN_EN; ret = ret & ~US5182D_CFG0_SHUTDOWN_EN;
ret = ret | state; ret = ret | state;
return i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, ret); ret = i2c_smbus_write_byte_data(data->client, US5182D_REG_CFG0, ret);
if (ret < 0)
return ret;
if (state & US5182D_CFG0_SHUTDOWN_EN) {
data->als_enabled = false;
data->px_enabled = false;
}
return ret;
} }
static int us5182d_read_raw(struct iio_dev *indio_dev, static int us5182d_read_raw(struct iio_dev *indio_dev,
...@@ -261,7 +317,7 @@ static int us5182d_read_raw(struct iio_dev *indio_dev, ...@@ -261,7 +317,7 @@ static int us5182d_read_raw(struct iio_dev *indio_dev,
if (ret < 0) if (ret < 0)
goto out_err; goto out_err;
} }
ret = us5182d_set_opmode(data, US5182D_OPMODE_ALS); ret = us5182d_als_enable(data);
if (ret < 0) if (ret < 0)
goto out_err; goto out_err;
...@@ -278,7 +334,7 @@ static int us5182d_read_raw(struct iio_dev *indio_dev, ...@@ -278,7 +334,7 @@ static int us5182d_read_raw(struct iio_dev *indio_dev,
if (ret < 0) if (ret < 0)
goto out_err; goto out_err;
} }
ret = us5182d_set_opmode(data, US5182D_OPMODE_PX); ret = us5182d_px_enable(data);
if (ret < 0) if (ret < 0)
goto out_err; goto out_err;
...@@ -421,6 +477,9 @@ static int us5182d_init(struct iio_dev *indio_dev) ...@@ -421,6 +477,9 @@ static int us5182d_init(struct iio_dev *indio_dev)
return ret; return ret;
} }
data->als_enabled = true;
data->px_enabled = true;
if (!data->default_continuous) { if (!data->default_continuous) {
ret = us5182d_shutdown_en(data, US5182D_CFG0_SHUTDOWN_EN); ret = us5182d_shutdown_en(data, US5182D_CFG0_SHUTDOWN_EN);
if (ret < 0) if (ret < 0)
...@@ -428,7 +487,6 @@ static int us5182d_init(struct iio_dev *indio_dev) ...@@ -428,7 +487,6 @@ static int us5182d_init(struct iio_dev *indio_dev)
data->power_mode = US5182D_ONESHOT; data->power_mode = US5182D_ONESHOT;
} }
return ret; return ret;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册