Commit 41148358 authored by Nikita Travkin's avatar Nikita Travkin Committed by Jonathan Cameron

iio: ltr501: Export near level property for proximity sensor

Userspace tools like iio-sensor-proxy need to know the proximity level
that should be considered "near". This value is hardware-specific and
can be defined via the devicetree. Allow the driver to export the near
level.
Signed-off-by: default avatarNikita Travkin <nikita@trvn.ru>
Link: https://lore.kernel.org/r/20211125125646.54831-2-nikita@trvn.ruSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 2cc131ac
...@@ -166,6 +166,7 @@ struct ltr501_data { ...@@ -166,6 +166,7 @@ struct ltr501_data {
struct regmap_field *reg_ps_rate; struct regmap_field *reg_ps_rate;
struct regmap_field *reg_als_prst; struct regmap_field *reg_als_prst;
struct regmap_field *reg_ps_prst; struct regmap_field *reg_ps_prst;
uint32_t near_level;
}; };
static const struct ltr501_samp_table ltr501_als_samp_table[] = { static const struct ltr501_samp_table ltr501_als_samp_table[] = {
...@@ -525,6 +526,25 @@ static int ltr501_write_intr_prst(struct ltr501_data *data, ...@@ -525,6 +526,25 @@ static int ltr501_write_intr_prst(struct ltr501_data *data,
return -EINVAL; return -EINVAL;
} }
static ssize_t ltr501_read_near_level(struct iio_dev *indio_dev,
uintptr_t priv,
const struct iio_chan_spec *chan,
char *buf)
{
struct ltr501_data *data = iio_priv(indio_dev);
return sprintf(buf, "%u\n", data->near_level);
}
static const struct iio_chan_spec_ext_info ltr501_ext_info[] = {
{
.name = "nearlevel",
.shared = IIO_SEPARATE,
.read = ltr501_read_near_level,
},
{ /* sentinel */ }
};
static const struct iio_event_spec ltr501_als_event_spec[] = { static const struct iio_event_spec ltr501_als_event_spec[] = {
{ {
.type = IIO_EV_TYPE_THRESH, .type = IIO_EV_TYPE_THRESH,
...@@ -609,6 +629,7 @@ static const struct iio_chan_spec ltr501_channels[] = { ...@@ -609,6 +629,7 @@ static const struct iio_chan_spec ltr501_channels[] = {
}, },
.event_spec = ltr501_pxs_event_spec, .event_spec = ltr501_pxs_event_spec,
.num_event_specs = ARRAY_SIZE(ltr501_pxs_event_spec), .num_event_specs = ARRAY_SIZE(ltr501_pxs_event_spec),
.ext_info = ltr501_ext_info,
}, },
IIO_CHAN_SOFT_TIMESTAMP(3), IIO_CHAN_SOFT_TIMESTAMP(3),
}; };
...@@ -1531,6 +1552,10 @@ static int ltr501_probe(struct i2c_client *client, ...@@ -1531,6 +1552,10 @@ static int ltr501_probe(struct i2c_client *client,
if ((partid >> 4) != data->chip_info->partid) if ((partid >> 4) != data->chip_info->partid)
return -ENODEV; return -ENODEV;
if (device_property_read_u32(&client->dev, "proximity-near-level",
&data->near_level))
data->near_level = 0;
indio_dev->info = data->chip_info->info; indio_dev->info = data->chip_info->info;
indio_dev->channels = data->chip_info->channels; indio_dev->channels = data->chip_info->channels;
indio_dev->num_channels = data->chip_info->no_channels; indio_dev->num_channels = data->chip_info->no_channels;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment