Skip to contentSkip to conversation

Support accelerometers for veyron_minnie

PATCH Superseded Gwendal Grignou 1 participant 5 messages Jul 15, 2019

Subsystems (2)

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

v5 cover Support accelerometers for veyron_minnie

veyron_minnie - ASUS Chromebook Flip C100PA - embedded controller controls two accelerometers, one in the lid, one in the base. However, the EC firmware does not follow the new interface that cros_ec_accel driver use.
Extend the legacy driver used on glimmer - Lenovo ThinkPad 11e Chromebook - to veyron_minnie.
veyron_minnie being ARM based, issue command over the I2C bus to the EC instead of relying on the shared registers over LPC.

Gwendal Grignou (4):
iio: cros_ec: Add sign vector in core for backward compatibility
iio: cros_ec_accel_legacy: Fix incorrect channel setting
iio: cros_ec_accel_legacy: Use cros_ec_sensors_core
iio: cros_ec_accel_legacy: Add support for veyron-minnie

Changes in v4:
- In "Use cros_ec_sensors_core", fix return without unlock on the error path.
- Add acked for the last 2 patches.

Changes in v4:
- No change in iio/common/cros_ec_sensors
- Split cros_ec_accel_legacy code in 3:
- fix an error in channel setting.
- remove duplicate code in cros_ec_accel, use cros_ec_sensors_core.
- extend cros_ec_accel to ARM device.
- Define cros_ec_accel_legacy_read_cmd() as static.

Changes in v3:
- Fix commit message, add reviewed-by for first patch.

Changes in v2:
- Readd empty line to reduce amount of change in patch.
- Remove Keywords used by ChromeOS commit queue.

 drivers/iio/accel/Kconfig                     |   4 +-
 drivers/iio/accel/cros_ec_accel_legacy.c      | 352 ++++--------------
 .../cros_ec_sensors/cros_ec_sensors_core.c    |   4 +
 .../linux/iio/common/cros_ec_sensors_core.h   |   1 +
 4 files changed, 85 insertions(+), 276 deletions(-)
Signature · 1 line
2.22.0.510.g264f2c817a-goog
#1 lore raw

PATCH v5 1/4 iio: cros_ec: Add sign vector in core for backward compatibility

To allow cros_ec iio core library to be used with legacy device, add a vector to rotate sensor data if necessary: legacy devices are not reporting data in HTML5/Android sensor referential.

Check the data is not rotated on recent chromebooks that use the HTML5 standard to present sensor data.

---
 drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c | 4 ++++
 include/linux/iio/common/cros_ec_sensors_core.h           | 1 +
 2 files changed, 5 insertions(+)
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +4 -0
index 719a0df5aeeb..e8a4d78659c8 100644
@@ -66,6 +66,9 @@ int cros_ec_sensors_core_init(struct platform_device *pdev,
 		}
 		state->type = state->resp->info.type;
 		state->loc = state->resp->info.location;
+
+		/* Set sign vector, only used for backward compatibility. */
+		memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
 	}
 
 	return 0;
@@ -254,6 +257,7 @@ static int cros_ec_sensors_read_data_unsafe(struct iio_dev *indio_dev,
 		if (ret < 0)
 			return ret;
 
+		*data *= st->sign[i];
 		data++;
 	}
 
include/linux/iio/common/cros_ec_sensors_core.h +1 -0
index ce16445411ac..a1c85ad4df91 100644
@@ -71,6 +71,7 @@ struct cros_ec_sensors_core_state {
 	enum motionsensor_location loc;
 
 	s16 calib[CROS_EC_SENSOR_MAX_AXIS];
+	s8 sign[CROS_EC_SENSOR_MAX_AXIS];
 
 	u8 samples[CROS_EC_SAMPLE_SIZE];
 
Signature · 1 line
2.22.0.510.g264f2c817a-goog
#2 lore raw

PATCH v5 2/4 iio: cros_ec_accel_legacy: Fix incorrect channel setting

In reply to Gwendal Grignou

INFO_SCALE is set both for each channel and all channels. iio is using all channel setting, so the error was not user visible.

---
 drivers/iio/accel/cros_ec_accel_legacy.c | 1 -
 1 file changed, 1 deletion(-)
drivers/iio/accel/cros_ec_accel_legacy.c +0 -1
index 46bb2e421bb9..ad19d9c716f4 100644
@@ -319,7 +319,6 @@ static const struct iio_chan_spec_ext_info cros_ec_accel_legacy_ext_info[] = {
 		.modified = 1,					        \
 		.info_mask_separate =					\
 			BIT(IIO_CHAN_INFO_RAW) |			\
-			BIT(IIO_CHAN_INFO_SCALE) |			\
 			BIT(IIO_CHAN_INFO_CALIBBIAS),			\
 		.info_mask_shared_by_all = BIT(IIO_CHAN_INFO_SCALE),	\
 		.ext_info = cros_ec_accel_legacy_ext_info,		\
Signature · 1 line
2.22.0.510.g264f2c817a-goog
#3 lore raw

PATCH v5 3/4 iio: cros_ec_accel_legacy: Use cros_ec_sensors_core

In reply to Gwendal Grignou

Remove duplicate code in cros-ec-accel-legacy,
use cros-ec-sensors-core functions and structures when possible.

On glimmer, check the 2 accelerometers are presented and working.

---
 drivers/iio/accel/Kconfig                |   4 +-
 drivers/iio/accel/cros_ec_accel_legacy.c | 335 ++++-------------------
 2 files changed, 54 insertions(+), 285 deletions(-)
drivers/iio/accel/Kconfig +1 -3
index 62a970a20219..7d0848f9ea45 100644
@@ -201,9 +201,7 @@ config HID_SENSOR_ACCEL_3D
 
 config IIO_CROS_EC_ACCEL_LEGACY
 	tristate "ChromeOS EC Legacy Accelerometer Sensor"
-	select IIO_BUFFER
-	select IIO_TRIGGERED_BUFFER
-	select CROS_EC_LPC_REGISTER_DEVICE
+	depends on IIO_CROS_EC_SENSORS_CORE
 	help
 	  Say yes here to get support for accelerometers on Chromebook using
 	  legacy EC firmware.
drivers/iio/accel/cros_ec_accel_legacy.c +53 -282

410 lines not on this page · raw message

Signature · 1 line
2.22.0.510.g264f2c817a-goog
#4 lore raw

PATCH v5 4/4 iio: cros_ec_accel_legacy: Add support for veyron-minnie

In reply to Gwendal Grignou

Veyron minnie embedded controller presents 2 accelerometers using an older interface. Add function to query the data in cros_ec_accel.

Verify accelerometers on veyron-minnie are presented and working.

---
 drivers/iio/accel/cros_ec_accel_legacy.c | 40 ++++++++++++++++++++++--
 1 file changed, 38 insertions(+), 2 deletions(-)
drivers/iio/accel/cros_ec_accel_legacy.c +38 -2
index 4d77472e2f72..545e23f0c033 100644
@@ -5,7 +5,7 @@
  * Copyright 2017 Google, Inc
  *
  * This driver uses the memory mapper cros-ec interface to communicate
- * with the Chrome OS EC about accelerometer data.
+ * with the Chrome OS EC about accelerometer data or older commands.
  * Accelerometer access is presented through iio sysfs.
  */
 
@@ -33,6 +33,39 @@
  */
 #define ACCEL_LEGACY_NSCALE 9586168
 
+static int cros_ec_accel_legacy_read_cmd(struct iio_dev *indio_dev,
+				  unsigned long scan_mask, s16 *data)
+{
+	struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
+	int ret;
+	unsigned int i;
+	u8 sensor_num;
+
+	/*
+	 * Read all sensor data through a command.
+	 * Save sensor_num, it is assumed to stay.
+	 */
+	sensor_num = st->param.info.sensor_num;
+	st->param.cmd = MOTIONSENSE_CMD_DUMP;
+	st->param.dump.max_sensor_count = CROS_EC_SENSOR_LEGACY_NUM;
+	ret = cros_ec_motion_send_host_cmd(st,
+			sizeof(st->resp->dump) + CROS_EC_SENSOR_LEGACY_NUM *
+			sizeof(struct ec_response_motion_sensor_data));
+	st->param.info.sensor_num = sensor_num;
+	if (ret != 0) {
+		dev_warn(&indio_dev->dev, "Unable to read sensor data\n");
+		return ret;
+	}
+
+	for_each_set_bit(i, &scan_mask, indio_dev->masklength) {
+		*data = st->resp->dump.sensor[sensor_num].data[i] *
+			st->sign[i];
+		data++;
+	}
+
+	return 0;
+}
+
 static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev,
 				     struct iio_chan_spec const *chan,
 				     int *val, int *val2, long mask)
@@ -149,7 +182,10 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
 	indio_dev->info = &cros_ec_accel_legacy_info;
 	state = iio_priv(indio_dev);
 
-	state->read_ec_sensors_data = cros_ec_sensors_read_lpc;
+	if (state->ec->cmd_readmem != NULL)
+		state->read_ec_sensors_data = cros_ec_sensors_read_lpc;
+	else
+		state->read_ec_sensors_data = cros_ec_accel_legacy_read_cmd;
 
 	indio_dev->channels = cros_ec_accel_legacy_channels;
 	indio_dev->num_channels = ARRAY_SIZE(cros_ec_accel_legacy_channels);
Signature · 1 line
2.22.0.510.g264f2c817a-goog