Skip to content

Commit 9566cb1

Browse files
gwendalcrjic23
authored andcommitted
iio: cros_ec_accel_legacy: Add support for veyron-minnie
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. Signed-off-by: Gwendal Grignou <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent d96e267 commit 9566cb1

File tree

1 file changed

+38
-2
lines changed

1 file changed

+38
-2
lines changed

drivers/iio/accel/cros_ec_accel_legacy.c

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright 2017 Google, Inc
66
*
77
* This driver uses the memory mapper cros-ec interface to communicate
8-
* with the Chrome OS EC about accelerometer data.
8+
* with the Chrome OS EC about accelerometer data or older commands.
99
* Accelerometer access is presented through iio sysfs.
1010
*/
1111

@@ -33,6 +33,39 @@
3333
*/
3434
#define ACCEL_LEGACY_NSCALE 9586168
3535

36+
static int cros_ec_accel_legacy_read_cmd(struct iio_dev *indio_dev,
37+
unsigned long scan_mask, s16 *data)
38+
{
39+
struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
40+
int ret;
41+
unsigned int i;
42+
u8 sensor_num;
43+
44+
/*
45+
* Read all sensor data through a command.
46+
* Save sensor_num, it is assumed to stay.
47+
*/
48+
sensor_num = st->param.info.sensor_num;
49+
st->param.cmd = MOTIONSENSE_CMD_DUMP;
50+
st->param.dump.max_sensor_count = CROS_EC_SENSOR_LEGACY_NUM;
51+
ret = cros_ec_motion_send_host_cmd(st,
52+
sizeof(st->resp->dump) + CROS_EC_SENSOR_LEGACY_NUM *
53+
sizeof(struct ec_response_motion_sensor_data));
54+
st->param.info.sensor_num = sensor_num;
55+
if (ret != 0) {
56+
dev_warn(&indio_dev->dev, "Unable to read sensor data\n");
57+
return ret;
58+
}
59+
60+
for_each_set_bit(i, &scan_mask, indio_dev->masklength) {
61+
*data = st->resp->dump.sensor[sensor_num].data[i] *
62+
st->sign[i];
63+
data++;
64+
}
65+
66+
return 0;
67+
}
68+
3669
static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev,
3770
struct iio_chan_spec const *chan,
3871
int *val, int *val2, long mask)
@@ -150,7 +183,10 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
150183
indio_dev->info = &cros_ec_accel_legacy_info;
151184
state = iio_priv(indio_dev);
152185

153-
state->read_ec_sensors_data = cros_ec_sensors_read_lpc;
186+
if (state->ec->cmd_readmem != NULL)
187+
state->read_ec_sensors_data = cros_ec_sensors_read_lpc;
188+
else
189+
state->read_ec_sensors_data = cros_ec_accel_legacy_read_cmd;
154190

155191
indio_dev->channels = cros_ec_accel_legacy_channels;
156192
indio_dev->num_channels = ARRAY_SIZE(cros_ec_accel_legacy_channels);

0 commit comments

Comments
 (0)