|
5 | 5 | * Copyright 2017 Google, Inc
|
6 | 6 | *
|
7 | 7 | * 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. |
9 | 9 | * Accelerometer access is presented through iio sysfs.
|
10 | 10 | */
|
11 | 11 |
|
|
33 | 33 | */
|
34 | 34 | #define ACCEL_LEGACY_NSCALE 9586168
|
35 | 35 |
|
| 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 | + |
36 | 69 | static int cros_ec_accel_legacy_read(struct iio_dev *indio_dev,
|
37 | 70 | struct iio_chan_spec const *chan,
|
38 | 71 | int *val, int *val2, long mask)
|
@@ -150,7 +183,10 @@ static int cros_ec_accel_legacy_probe(struct platform_device *pdev)
|
150 | 183 | indio_dev->info = &cros_ec_accel_legacy_info;
|
151 | 184 | state = iio_priv(indio_dev);
|
152 | 185 |
|
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; |
154 | 190 |
|
155 | 191 | indio_dev->channels = cros_ec_accel_legacy_channels;
|
156 | 192 | indio_dev->num_channels = ARRAY_SIZE(cros_ec_accel_legacy_channels);
|
|
0 commit comments