drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
Source file repositories/reference/linux-study-clean/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c- Extension
.c- Size
- 24944 bytes
- Lines
- 887
- Domain
- Driver Families
- Bucket
- drivers/iio
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/delay.hlinux/device.hlinux/iio/buffer.hlinux/iio/common/cros_ec_sensors_core.hlinux/iio/iio.hlinux/iio/kfifo_buf.hlinux/iio/sysfs.hlinux/iio/trigger.hlinux/iio/trigger_consumer.hlinux/iio/triggered_buffer.hlinux/kernel.hlinux/module.hlinux/slab.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/platform_data/cros_ec_sensorhub.hlinux/platform_device.hcros_ec_sensors_trace.h
Detected Declarations
function Copyrightfunction get_default_min_max_freqfunction cros_ec_sensor_set_report_latencyfunction cros_ec_sensor_get_report_latencyfunction hwfifo_watermark_max_showfunction cros_ec_sensors_push_datafunction cros_ec_sensors_core_cleanfunction cros_ec_sensors_core_initfunction cros_ec_sensors_core_registerfunction cros_ec_motion_send_host_cmdfunction cros_ec_sensors_calibratefunction cros_ec_sensors_idfunction cros_ec_sensors_idx_to_regfunction cros_ec_sensors_cmd_read_u8function cros_ec_sensors_cmd_read_u16function cros_ec_sensors_read_until_not_busyfunction cros_ec_sensors_read_data_unsafefunction cros_ec_sensors_read_lpcfunction cros_ec_sensors_read_cmdfunction for_each_set_bitfunction cros_ec_sensors_capturefunction cros_ec_sensors_core_readfunction cros_ec_sensors_core_read_availfunction cros_ec_sensors_core_writefunction cros_ec_sensors_resumeexport cros_ec_sensors_push_dataexport cros_ec_sensors_core_initexport cros_ec_sensors_core_registerexport cros_ec_motion_send_host_cmdexport cros_ec_sensors_ext_infoexport cros_ec_sensors_limited_infoexport cros_ec_sensors_read_lpcexport cros_ec_sensors_read_cmdexport cros_ec_sensors_captureexport cros_ec_sensors_core_readexport cros_ec_sensors_core_read_availexport cros_ec_sensors_core_writeexport cros_ec_sensors_pm_ops
Annotated Snippet
if (ret) {
dev_warn(dev, "Can not access sensor info\n");
return ret;
}
state->type = state->resp->info.type;
loc = state->resp->info.location;
if (loc == MOTIONSENSE_LOC_BASE)
indio_dev->label = "accel-base";
else if (loc == MOTIONSENSE_LOC_LID)
indio_dev->label = "accel-display";
else if (loc == MOTIONSENSE_LOC_CAMERA)
indio_dev->label = "accel-camera";
/* Set sign vector, only used for backward compatibility. */
memset(state->sign, 1, CROS_EC_SENSOR_MAX_AXIS);
for (i = CROS_EC_SENSOR_X; i < CROS_EC_SENSOR_MAX_AXIS; i++)
state->calib[i].scale = MOTION_SENSE_DEFAULT_SCALE;
/* 0 is a correct value used to stop the device */
if (state->msg->version < 3) {
get_default_min_max_freq(state->resp->info.type,
&frequencies[1],
&frequencies[2],
&state->fifo_max_event_count);
} else {
if (state->resp->info_3.max_frequency == 0) {
get_default_min_max_freq(state->resp->info.type,
&frequencies[1],
&frequencies[2],
&temp);
} else {
frequencies[1] = state->resp->info_3.min_frequency;
frequencies[2] = state->resp->info_3.max_frequency;
}
state->fifo_max_event_count = state->resp->info_3.fifo_max_event_count;
}
for (i = 0; i < ARRAY_SIZE(frequencies); i++) {
state->frequencies[2 * i] = frequencies[i] / 1000;
state->frequencies[2 * i + 1] =
(frequencies[i] % 1000) * 1000;
}
if (cros_ec_check_features(ec, EC_FEATURE_MOTION_SENSE_FIFO)) {
/*
* Create a software buffer, feed by the EC FIFO.
* We can not use trigger here, as events are generated
* as soon as sample_frequency is set.
*/
ret = devm_iio_kfifo_buffer_setup_ext(dev, indio_dev, NULL,
cros_ec_sensor_fifo_attributes);
if (ret)
return ret;
/* Timestamp coming from FIFO are in ns since boot. */
ret = iio_device_set_clock(indio_dev, CLOCK_BOOTTIME);
if (ret)
return ret;
} else {
/*
* The only way to get samples in buffer is to set a
* software trigger (systrig, hrtimer).
*/
ret = devm_iio_triggered_buffer_setup(dev, indio_dev,
NULL, trigger_capture, NULL);
if (ret)
return ret;
}
}
return 0;
}
EXPORT_SYMBOL_GPL(cros_ec_sensors_core_init);
/**
* cros_ec_sensors_core_register() - Register callback to FIFO and IIO when
* sensor is ready.
* It must be called at the end of the sensor probe routine.
* @dev: device created for the sensor
* @indio_dev: iio device structure of the device
* @push_data: function to call when cros_ec_sensorhub receives
* a sample for that sensor.
*
* Return: 0 on success, -errno on failure.
*/
int cros_ec_sensors_core_register(struct device *dev,
struct iio_dev *indio_dev,
cros_ec_sensorhub_push_data_cb_t push_data)
{
Annotation
- Immediate include surface: `linux/delay.h`, `linux/device.h`, `linux/iio/buffer.h`, `linux/iio/common/cros_ec_sensors_core.h`, `linux/iio/iio.h`, `linux/iio/kfifo_buf.h`, `linux/iio/sysfs.h`, `linux/iio/trigger.h`.
- Detected declarations: `function Copyright`, `function get_default_min_max_freq`, `function cros_ec_sensor_set_report_latency`, `function cros_ec_sensor_get_report_latency`, `function hwfifo_watermark_max_show`, `function cros_ec_sensors_push_data`, `function cros_ec_sensors_core_clean`, `function cros_ec_sensors_core_init`, `function cros_ec_sensors_core_register`, `function cros_ec_motion_send_host_cmd`.
- Atlas domain: Driver Families / drivers/iio.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.