Re: [PATCH 06/10] iio: cros_ec_light_prox: add ChromeOS EC Light and Proximity Sensors
On 18/07/16 08:02, Enric Balletbo i Serra wrote: > Handle Light and Proximity sensors presented by the ChromeOS EC Sensor hub. > Creates an IIO device for each functions. > > Signed-off-by: Guenter Roeck> Signed-off-by: Enric Balletbo i Serra Few more nitpicks, but basically the same as the previous.. Jonathan > --- > drivers/iio/common/cros_ec_sensors/Kconfig | 9 + > drivers/iio/common/cros_ec_sensors/Makefile| 1 + > .../common/cros_ec_sensors/cros_ec_light_prox.c| 288 > + > 3 files changed, 298 insertions(+) > create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c > > diff --git a/drivers/iio/common/cros_ec_sensors/Kconfig > b/drivers/iio/common/cros_ec_sensors/Kconfig > index 18002d6..02559d2 100644 > --- a/drivers/iio/common/cros_ec_sensors/Kconfig > +++ b/drivers/iio/common/cros_ec_sensors/Kconfig > @@ -20,3 +20,12 @@ config IIO_CROS_EC_SENSORS > Accelerometers, Gyroscope and Magnetometer that are > presented by the ChromeOS EC Sensor hub. > Creates an IIO device for each functions. > + > +config IIO_CROS_EC_LIGHT_PROX > + tristate "ChromeOS EC Light and Proximity Sensors" > + select IIO_CROS_EC_SENSORS_CORE > + help > + Module to handle Light and Proximity sensors > + presented by the ChromeOS EC Sensor hub. > + Creates an IIO device for each functions. > + Only one source is exposed by the EC. > diff --git a/drivers/iio/common/cros_ec_sensors/Makefile > b/drivers/iio/common/cros_ec_sensors/Makefile > index ec716ff..7aaf2a2 100644 > --- a/drivers/iio/common/cros_ec_sensors/Makefile > +++ b/drivers/iio/common/cros_ec_sensors/Makefile > @@ -4,3 +4,4 @@ > > obj-$(CONFIG_IIO_CROS_EC_SENSORS_CORE) += cros_ec_sensors_core.o > obj-$(CONFIG_IIO_CROS_EC_SENSORS) += cros_ec_sensors.o > +obj-$(CONFIG_IIO_CROS_EC_LIGHT_PROX) += cros_ec_light_prox.o > diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c > b/drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c > new file mode 100644 > index 000..333e927 > --- /dev/null > +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c > @@ -0,0 +1,288 @@ > +/* > + * cros_ec_light_proxmity - Driver for light and prox sensors behing CrOS EC. > + * > + * Copyright (C) 2015 Google, Inc > + * > + * This software is licensed under the terms of the GNU General Public > + * License version 2, as published by the Free Software Foundation, and > + * may be copied, distributed, and modified under those terms. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * This driver uses the cros-ec interface to communicate with the Chrome OS > + * EC about accelerometer data. Accelerometer access is presented through > + * iio sysfs. Fix this comment as I doubt this driver does that ;) > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "cros_ec_sensors_core.h" > + > +/* > + * We only represent one entry for light or proximity. > + * EC is merging different light sensors to return the > + * what the eye would see. > + * For proximity, we currently support only one light source. > + */ > +#define MAX_CHANNELS (1 + 1) > + > +/* State data for ec_sensors iio driver. */ > +struct cros_ec_sensors_state { > + /* Shared by all sensors */ > + struct cros_ec_sensors_core_state core; > + > + struct iio_chan_spec channels[MAX_CHANNELS]; > +}; > + > +static int cros_ec_light_prox_read(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + int *val, int *val2, long mask) > +{ > + struct cros_ec_sensors_state *st = iio_priv(indio_dev); > + u16 data = 0; > + s64 val64; > + int ret = IIO_VAL_INT; > + int idx = chan->scan_index; > + > + mutex_lock(>core.cmd_lock); > + > + switch (mask) { > + case IIO_CHAN_INFO_RAW: > + if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx, > + (s16 *)) < 0) > + ret = -EIO; > + *val = data; > + break; > + case IIO_CHAN_INFO_CALIBBIAS: > + st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET; > + st->core.param.sensor_offset.flags = 0; > + > + if (cros_ec_motion_send_host_cmd(>core, 0)) { > + ret = -EIO; > + break; > + } > + > + /* Save values */ > + st->core.calib[0].offset = > + st->core.resp->sensor_offset.offset[0]; > + > + *val =
Re: [PATCH 06/10] iio: cros_ec_light_prox: add ChromeOS EC Light and Proximity Sensors
On 18/07/16 08:02, Enric Balletbo i Serra wrote: > Handle Light and Proximity sensors presented by the ChromeOS EC Sensor hub. > Creates an IIO device for each functions. > > Signed-off-by: Guenter Roeck > Signed-off-by: Enric Balletbo i Serra Few more nitpicks, but basically the same as the previous.. Jonathan > --- > drivers/iio/common/cros_ec_sensors/Kconfig | 9 + > drivers/iio/common/cros_ec_sensors/Makefile| 1 + > .../common/cros_ec_sensors/cros_ec_light_prox.c| 288 > + > 3 files changed, 298 insertions(+) > create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c > > diff --git a/drivers/iio/common/cros_ec_sensors/Kconfig > b/drivers/iio/common/cros_ec_sensors/Kconfig > index 18002d6..02559d2 100644 > --- a/drivers/iio/common/cros_ec_sensors/Kconfig > +++ b/drivers/iio/common/cros_ec_sensors/Kconfig > @@ -20,3 +20,12 @@ config IIO_CROS_EC_SENSORS > Accelerometers, Gyroscope and Magnetometer that are > presented by the ChromeOS EC Sensor hub. > Creates an IIO device for each functions. > + > +config IIO_CROS_EC_LIGHT_PROX > + tristate "ChromeOS EC Light and Proximity Sensors" > + select IIO_CROS_EC_SENSORS_CORE > + help > + Module to handle Light and Proximity sensors > + presented by the ChromeOS EC Sensor hub. > + Creates an IIO device for each functions. > + Only one source is exposed by the EC. > diff --git a/drivers/iio/common/cros_ec_sensors/Makefile > b/drivers/iio/common/cros_ec_sensors/Makefile > index ec716ff..7aaf2a2 100644 > --- a/drivers/iio/common/cros_ec_sensors/Makefile > +++ b/drivers/iio/common/cros_ec_sensors/Makefile > @@ -4,3 +4,4 @@ > > obj-$(CONFIG_IIO_CROS_EC_SENSORS_CORE) += cros_ec_sensors_core.o > obj-$(CONFIG_IIO_CROS_EC_SENSORS) += cros_ec_sensors.o > +obj-$(CONFIG_IIO_CROS_EC_LIGHT_PROX) += cros_ec_light_prox.o > diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c > b/drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c > new file mode 100644 > index 000..333e927 > --- /dev/null > +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c > @@ -0,0 +1,288 @@ > +/* > + * cros_ec_light_proxmity - Driver for light and prox sensors behing CrOS EC. > + * > + * Copyright (C) 2015 Google, Inc > + * > + * This software is licensed under the terms of the GNU General Public > + * License version 2, as published by the Free Software Foundation, and > + * may be copied, distributed, and modified under those terms. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + * > + * This driver uses the cros-ec interface to communicate with the Chrome OS > + * EC about accelerometer data. Accelerometer access is presented through > + * iio sysfs. Fix this comment as I doubt this driver does that ;) > + */ > + > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > +#include > + > +#include "cros_ec_sensors_core.h" > + > +/* > + * We only represent one entry for light or proximity. > + * EC is merging different light sensors to return the > + * what the eye would see. > + * For proximity, we currently support only one light source. > + */ > +#define MAX_CHANNELS (1 + 1) > + > +/* State data for ec_sensors iio driver. */ > +struct cros_ec_sensors_state { > + /* Shared by all sensors */ > + struct cros_ec_sensors_core_state core; > + > + struct iio_chan_spec channels[MAX_CHANNELS]; > +}; > + > +static int cros_ec_light_prox_read(struct iio_dev *indio_dev, > + struct iio_chan_spec const *chan, > + int *val, int *val2, long mask) > +{ > + struct cros_ec_sensors_state *st = iio_priv(indio_dev); > + u16 data = 0; > + s64 val64; > + int ret = IIO_VAL_INT; > + int idx = chan->scan_index; > + > + mutex_lock(>core.cmd_lock); > + > + switch (mask) { > + case IIO_CHAN_INFO_RAW: > + if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx, > + (s16 *)) < 0) > + ret = -EIO; > + *val = data; > + break; > + case IIO_CHAN_INFO_CALIBBIAS: > + st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET; > + st->core.param.sensor_offset.flags = 0; > + > + if (cros_ec_motion_send_host_cmd(>core, 0)) { > + ret = -EIO; > + break; > + } > + > + /* Save values */ > + st->core.calib[0].offset = > + st->core.resp->sensor_offset.offset[0]; > + > + *val = st->core.calib[idx].offset; > + break; > +
[PATCH 06/10] iio: cros_ec_light_prox: add ChromeOS EC Light and Proximity Sensors
Handle Light and Proximity sensors presented by the ChromeOS EC Sensor hub. Creates an IIO device for each functions. Signed-off-by: Guenter RoeckSigned-off-by: Enric Balletbo i Serra --- drivers/iio/common/cros_ec_sensors/Kconfig | 9 + drivers/iio/common/cros_ec_sensors/Makefile| 1 + .../common/cros_ec_sensors/cros_ec_light_prox.c| 288 + 3 files changed, 298 insertions(+) create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c diff --git a/drivers/iio/common/cros_ec_sensors/Kconfig b/drivers/iio/common/cros_ec_sensors/Kconfig index 18002d6..02559d2 100644 --- a/drivers/iio/common/cros_ec_sensors/Kconfig +++ b/drivers/iio/common/cros_ec_sensors/Kconfig @@ -20,3 +20,12 @@ config IIO_CROS_EC_SENSORS Accelerometers, Gyroscope and Magnetometer that are presented by the ChromeOS EC Sensor hub. Creates an IIO device for each functions. + +config IIO_CROS_EC_LIGHT_PROX + tristate "ChromeOS EC Light and Proximity Sensors" + select IIO_CROS_EC_SENSORS_CORE + help + Module to handle Light and Proximity sensors + presented by the ChromeOS EC Sensor hub. + Creates an IIO device for each functions. + Only one source is exposed by the EC. diff --git a/drivers/iio/common/cros_ec_sensors/Makefile b/drivers/iio/common/cros_ec_sensors/Makefile index ec716ff..7aaf2a2 100644 --- a/drivers/iio/common/cros_ec_sensors/Makefile +++ b/drivers/iio/common/cros_ec_sensors/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_IIO_CROS_EC_SENSORS_CORE) += cros_ec_sensors_core.o obj-$(CONFIG_IIO_CROS_EC_SENSORS) += cros_ec_sensors.o +obj-$(CONFIG_IIO_CROS_EC_LIGHT_PROX) += cros_ec_light_prox.o diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c b/drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c new file mode 100644 index 000..333e927 --- /dev/null +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c @@ -0,0 +1,288 @@ +/* + * cros_ec_light_proxmity - Driver for light and prox sensors behing CrOS EC. + * + * Copyright (C) 2015 Google, Inc + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This driver uses the cros-ec interface to communicate with the Chrome OS + * EC about accelerometer data. Accelerometer access is presented through + * iio sysfs. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cros_ec_sensors_core.h" + +/* + * We only represent one entry for light or proximity. + * EC is merging different light sensors to return the + * what the eye would see. + * For proximity, we currently support only one light source. + */ +#define MAX_CHANNELS (1 + 1) + +/* State data for ec_sensors iio driver. */ +struct cros_ec_sensors_state { + /* Shared by all sensors */ + struct cros_ec_sensors_core_state core; + + struct iio_chan_spec channels[MAX_CHANNELS]; +}; + +static int cros_ec_light_prox_read(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct cros_ec_sensors_state *st = iio_priv(indio_dev); + u16 data = 0; + s64 val64; + int ret = IIO_VAL_INT; + int idx = chan->scan_index; + + mutex_lock(>core.cmd_lock); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx, + (s16 *)) < 0) + ret = -EIO; + *val = data; + break; + case IIO_CHAN_INFO_CALIBBIAS: + st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET; + st->core.param.sensor_offset.flags = 0; + + if (cros_ec_motion_send_host_cmd(>core, 0)) { + ret = -EIO; + break; + } + + /* Save values */ + st->core.calib[0].offset = + st->core.resp->sensor_offset.offset[0]; + + *val = st->core.calib[idx].offset; + break; + case IIO_CHAN_INFO_CALIBSCALE: + /* +* RANGE is used for calibration +* scalse is a number x.y, where x is coded on 16bits, +* y coded on 16 bits, between 0 and . +*/ + st->core.param.cmd =
[PATCH 06/10] iio: cros_ec_light_prox: add ChromeOS EC Light and Proximity Sensors
Handle Light and Proximity sensors presented by the ChromeOS EC Sensor hub. Creates an IIO device for each functions. Signed-off-by: Guenter Roeck Signed-off-by: Enric Balletbo i Serra --- drivers/iio/common/cros_ec_sensors/Kconfig | 9 + drivers/iio/common/cros_ec_sensors/Makefile| 1 + .../common/cros_ec_sensors/cros_ec_light_prox.c| 288 + 3 files changed, 298 insertions(+) create mode 100644 drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c diff --git a/drivers/iio/common/cros_ec_sensors/Kconfig b/drivers/iio/common/cros_ec_sensors/Kconfig index 18002d6..02559d2 100644 --- a/drivers/iio/common/cros_ec_sensors/Kconfig +++ b/drivers/iio/common/cros_ec_sensors/Kconfig @@ -20,3 +20,12 @@ config IIO_CROS_EC_SENSORS Accelerometers, Gyroscope and Magnetometer that are presented by the ChromeOS EC Sensor hub. Creates an IIO device for each functions. + +config IIO_CROS_EC_LIGHT_PROX + tristate "ChromeOS EC Light and Proximity Sensors" + select IIO_CROS_EC_SENSORS_CORE + help + Module to handle Light and Proximity sensors + presented by the ChromeOS EC Sensor hub. + Creates an IIO device for each functions. + Only one source is exposed by the EC. diff --git a/drivers/iio/common/cros_ec_sensors/Makefile b/drivers/iio/common/cros_ec_sensors/Makefile index ec716ff..7aaf2a2 100644 --- a/drivers/iio/common/cros_ec_sensors/Makefile +++ b/drivers/iio/common/cros_ec_sensors/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_IIO_CROS_EC_SENSORS_CORE) += cros_ec_sensors_core.o obj-$(CONFIG_IIO_CROS_EC_SENSORS) += cros_ec_sensors.o +obj-$(CONFIG_IIO_CROS_EC_LIGHT_PROX) += cros_ec_light_prox.o diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c b/drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c new file mode 100644 index 000..333e927 --- /dev/null +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_light_prox.c @@ -0,0 +1,288 @@ +/* + * cros_ec_light_proxmity - Driver for light and prox sensors behing CrOS EC. + * + * Copyright (C) 2015 Google, Inc + * + * This software is licensed under the terms of the GNU General Public + * License version 2, as published by the Free Software Foundation, and + * may be copied, distributed, and modified under those terms. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * This driver uses the cros-ec interface to communicate with the Chrome OS + * EC about accelerometer data. Accelerometer access is presented through + * iio sysfs. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "cros_ec_sensors_core.h" + +/* + * We only represent one entry for light or proximity. + * EC is merging different light sensors to return the + * what the eye would see. + * For proximity, we currently support only one light source. + */ +#define MAX_CHANNELS (1 + 1) + +/* State data for ec_sensors iio driver. */ +struct cros_ec_sensors_state { + /* Shared by all sensors */ + struct cros_ec_sensors_core_state core; + + struct iio_chan_spec channels[MAX_CHANNELS]; +}; + +static int cros_ec_light_prox_read(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct cros_ec_sensors_state *st = iio_priv(indio_dev); + u16 data = 0; + s64 val64; + int ret = IIO_VAL_INT; + int idx = chan->scan_index; + + mutex_lock(>core.cmd_lock); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + if (cros_ec_sensors_read_cmd(indio_dev, 1 << idx, + (s16 *)) < 0) + ret = -EIO; + *val = data; + break; + case IIO_CHAN_INFO_CALIBBIAS: + st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_OFFSET; + st->core.param.sensor_offset.flags = 0; + + if (cros_ec_motion_send_host_cmd(>core, 0)) { + ret = -EIO; + break; + } + + /* Save values */ + st->core.calib[0].offset = + st->core.resp->sensor_offset.offset[0]; + + *val = st->core.calib[idx].offset; + break; + case IIO_CHAN_INFO_CALIBSCALE: + /* +* RANGE is used for calibration +* scalse is a number x.y, where x is coded on 16bits, +* y coded on 16 bits, between 0 and . +*/ + st->core.param.cmd = MOTIONSENSE_CMD_SENSOR_RANGE; + st->core.param.sensor_range.data