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.

Dependency Surface

Detected Declarations

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

Implementation Notes