drivers/platform/chrome/cros_ec_sensorhub.c
Source file repositories/reference/linux-study-clean/drivers/platform/chrome/cros_ec_sensorhub.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/chrome/cros_ec_sensorhub.c- Extension
.c- Size
- 7359 bytes
- Lines
- 290
- Domain
- Driver Families
- Bucket
- drivers/platform
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- 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/init.hlinux/device.hlinux/delay.hlinux/mod_devicetable.hlinux/module.hlinux/platform_data/cros_ec_commands.hlinux/platform_data/cros_ec_proto.hlinux/platform_data/cros_ec_sensorhub.hlinux/platform_device.hlinux/slab.hlinux/types.h
Detected Declarations
function cros_ec_sensorhub_free_sensorfunction cros_ec_sensorhub_allocate_sensorfunction cros_ec_sensorhub_registerfunction cros_ec_sensorhub_probefunction cros_ec_sensorhub_suspendfunction cros_ec_sensorhub_resume
Annotated Snippet
if (ret == -EBUSY) {
/* The EC is still busy initializing sensors. */
usleep_range(5000, 6000);
retries--;
}
} while (ret == -EBUSY && retries);
if (ret < 0) {
dev_err(dev, "no info for EC sensor %d : %d/%d\n",
i, ret, msg->result);
continue;
}
if (retries < CROS_EC_CMD_INFO_RETRIES) {
dev_warn(dev, "%d retries needed to bring up sensor %d\n",
CROS_EC_CMD_INFO_RETRIES - retries, i);
}
switch (sensorhub->resp->info.type) {
case MOTIONSENSE_TYPE_ACCEL:
name = "cros-ec-accel";
break;
case MOTIONSENSE_TYPE_BARO:
name = "cros-ec-baro";
break;
case MOTIONSENSE_TYPE_GYRO:
name = "cros-ec-gyro";
break;
case MOTIONSENSE_TYPE_MAG:
name = "cros-ec-mag";
break;
case MOTIONSENSE_TYPE_PROX:
name = "cros-ec-prox";
break;
case MOTIONSENSE_TYPE_LIGHT:
name = "cros-ec-light";
break;
case MOTIONSENSE_TYPE_ACTIVITY:
name = "cros-ec-activity";
break;
default:
dev_warn(dev, "unknown type %d\n",
sensorhub->resp->info.type);
continue;
}
ret = cros_ec_sensorhub_allocate_sensor(dev, name, i);
if (ret)
return ret;
sensor_type[sensorhub->resp->info.type]++;
}
if (sensor_type[MOTIONSENSE_TYPE_ACCEL] >= 2) {
ec->has_kb_wake_angle = true;
if (ec->group && sysfs_update_group(&ec->class_dev.kobj,
ec->group))
dev_warn(dev, "Unable to update sysfs");
}
if (cros_ec_check_features(ec,
EC_FEATURE_REFINED_TABLET_MODE_HYSTERESIS)) {
ret = cros_ec_sensorhub_allocate_sensor(dev,
"cros-ec-lid-angle",
0);
if (ret)
return ret;
}
return 0;
}
static int cros_ec_sensorhub_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct cros_ec_dev *ec = dev_get_drvdata(dev->parent);
struct cros_ec_sensorhub *data;
struct cros_ec_command *msg;
int ret, i, sensor_num;
msg = devm_kzalloc(dev, sizeof(struct cros_ec_command) +
max((u16)sizeof(struct ec_params_motion_sense),
ec->ec_dev->max_response), GFP_KERNEL);
if (!msg)
return -ENOMEM;
msg->command = EC_CMD_MOTION_SENSE_CMD + ec->cmd_offset;
data = devm_kzalloc(dev, sizeof(struct cros_ec_sensorhub), GFP_KERNEL);
if (!data)
return -ENOMEM;
Annotation
- Immediate include surface: `linux/init.h`, `linux/device.h`, `linux/delay.h`, `linux/mod_devicetable.h`, `linux/module.h`, `linux/platform_data/cros_ec_commands.h`, `linux/platform_data/cros_ec_proto.h`, `linux/platform_data/cros_ec_sensorhub.h`.
- Detected declarations: `function cros_ec_sensorhub_free_sensor`, `function cros_ec_sensorhub_allocate_sensor`, `function cros_ec_sensorhub_register`, `function cros_ec_sensorhub_probe`, `function cros_ec_sensorhub_suspend`, `function cros_ec_sensorhub_resume`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: source implementation candidate.
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.