// SPDX-License-Identifier: GPL-2.0 /* * Driver for older Chrome OS EC accelerometer * * Copyright 2017 Google, Inc * * This driver uses the memory mapper cros-ec interface to communicate * with the Chrome OS EC about accelerometer data or older commands. * Accelerometer access is presented through iio sysfs.
*/
/* * 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;
}
staticint cros_ec_accel_legacy_read(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask)
{ struct cros_ec_sensors_core_state *st = iio_priv(indio_dev);
s16 data = 0; int ret; int idx = chan->scan_index;
mutex_lock(&st->cmd_lock);
switch (mask) { case IIO_CHAN_INFO_RAW:
ret = st->read_ec_sensors_data(indio_dev, 1 << idx, &data); if (ret < 0) break;
ret = IIO_VAL_INT;
*val = data; break; case IIO_CHAN_INFO_SCALE:
WARN_ON(st->type != MOTIONSENSE_TYPE_ACCEL);
*val = 0;
*val2 = ACCEL_LEGACY_NSCALE;
ret = IIO_VAL_INT_PLUS_NANO; break; case IIO_CHAN_INFO_CALIBBIAS: /* Calibration not supported. */
*val = 0;
ret = IIO_VAL_INT; break; case IIO_CHAN_INFO_SAMP_FREQ:
*val = cros_ec_legacy_sample_freq[0];
*val2 = cros_ec_legacy_sample_freq[1];
ret = IIO_VAL_INT_PLUS_MICRO; break; default:
ret = cros_ec_sensors_core_read(st, chan, val, val2,
mask); break;
}
mutex_unlock(&st->cmd_lock);
return ret;
}
staticint cros_ec_accel_legacy_write(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask)
{ /* * Do nothing but don't return an error code to allow calibration * script to work.
*/ if (mask == IIO_CHAN_INFO_CALIBBIAS) return 0;
return -EINVAL;
}
/** * cros_ec_accel_legacy_read_avail() - get available values * @indio_dev: pointer to state information for device * @chan: channel specification structure table * @vals: list of available values * @type: type of data returned * @length: number of data returned in the array * @mask: specifies which values to be requested * * Return: an error code or IIO_AVAIL_LIST
*/ staticint cros_ec_accel_legacy_read_avail(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, constint **vals, int *type, int *length, long mask)
{ switch (mask) { case IIO_CHAN_INFO_SAMP_FREQ:
*length = ARRAY_SIZE(cros_ec_legacy_sample_freq);
*vals = cros_ec_legacy_sample_freq;
*type = IIO_VAL_INT_PLUS_MICRO; return IIO_AVAIL_LIST;
}
/* * Present the channel using HTML5 standard: * need to invert X and Y and invert some lid axis.
*/ #define CROS_EC_ACCEL_ROTATE_AXIS(_axis) \
((_axis) == CROS_EC_SENSOR_Z ? CROS_EC_SENSOR_Z : \
((_axis) == CROS_EC_SENSOR_X ? CROS_EC_SENSOR_Y : \
CROS_EC_SENSOR_X))
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.