drivers/mfd/cros_ec_dev.c

Source file repositories/reference/linux-study-clean/drivers/mfd/cros_ec_dev.c

File Facts

System
Linux kernel
Corpus path
drivers/mfd/cros_ec_dev.c
Extension
.c
Size
10928 bytes
Lines
424
Domain
Driver Families
Bucket
drivers/mfd
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.

Dependency Surface

Detected Declarations

Annotated Snippet

retval = device_add(&ec->class_dev);
	if (retval)
		goto failed;

	dev_set_drvdata(dev, ec);

	/* check whether this EC is a sensor hub. */
	if (cros_ec_get_sensor_count(ec) > 0) {
		retval = mfd_add_hotplug_devices(ec->dev,
				cros_ec_sensorhub_cells,
				ARRAY_SIZE(cros_ec_sensorhub_cells));
		if (retval)
			dev_err(ec->dev, "failed to add %s subdevice: %d\n",
				cros_ec_sensorhub_cells->name, retval);
	}

	/*
	 * The following subdevices can be detected by sending the
	 * EC_FEATURE_GET_CMD Embedded Controller device.
	 */
	for (i = 0; i < ARRAY_SIZE(cros_subdevices); i++) {
		if (cros_ec_check_features(ec, cros_subdevices[i].id)) {
			retval = mfd_add_hotplug_devices(ec->dev,
						cros_subdevices[i].mfd_cells,
						cros_subdevices[i].num_cells);
			if (retval)
				dev_err(ec->dev,
					"failed to add %s subdevice: %d\n",
					cros_subdevices[i].mfd_cells->name,
					retval);
		}
	}

	/*
	 * FW nodes can load cros_ec_ucsi, but early PDC devices did not define
	 * the required nodes. On PDC systems without FW nodes for cros_ec_ucsi,
	 * the driver should be added as an mfd subdevice.
	 */
	if (cros_ec_check_features(ec, EC_FEATURE_USB_PD) &&
	    cros_ec_check_features(ec, EC_FEATURE_UCSI_PPM) &&
	    !acpi_dev_found("GOOG0021") &&
	    !of_find_compatible_node(NULL, NULL, "google,cros-ec-ucsi")) {
		retval = mfd_add_hotplug_devices(ec->dev,
						 cros_ec_ucsi_cells,
						 ARRAY_SIZE(cros_ec_ucsi_cells));

		if (retval)
			dev_warn(ec->dev, "failed to add cros_ec_ucsi: %d\n", retval);
	}

	/*
	 * UCSI provides power supply information so we don't need to separately
	 * load the cros_usbpd_charger driver.
	 */
	if (cros_ec_check_features(ec, EC_FEATURE_USB_PD) &&
	    !cros_ec_check_features(ec, EC_FEATURE_UCSI_PPM)) {
		retval = mfd_add_hotplug_devices(ec->dev,
						 cros_usbpd_charger_cells,
						 ARRAY_SIZE(cros_usbpd_charger_cells));

		if (retval)
			dev_warn(ec->dev, "failed to add usbpd-charger: %d\n",
				 retval);
	}

	/*
	 * Lightbar is a special case. Newer devices support autodetection,
	 * but older ones do not.
	 */
	if (cros_ec_check_features(ec, EC_FEATURE_LIGHTBAR) ||
	    dmi_match(DMI_PRODUCT_NAME, "Link")) {
		retval = mfd_add_hotplug_devices(ec->dev,
					cros_ec_lightbar_cells,
					ARRAY_SIZE(cros_ec_lightbar_cells));
		if (retval)
			dev_warn(ec->dev, "failed to add lightbar: %d\n",
				 retval);
	}

	/*
	 * The PD notifier driver cell is separate since it only needs to be
	 * explicitly added on platforms that don't have the PD notifier ACPI
	 * device entry defined.
	 */
	if (IS_ENABLED(CONFIG_OF) && ec->ec_dev->dev->of_node) {
		if (cros_ec_check_features(ec, EC_FEATURE_USB_PD)) {
			retval = mfd_add_hotplug_devices(ec->dev,
					cros_usbpd_notify_cells,
					ARRAY_SIZE(cros_usbpd_notify_cells));
			if (retval)

Annotation

Implementation Notes