drivers/platform/chrome/cros_ec_lpc_mec.c

Source file repositories/reference/linux-study-clean/drivers/platform/chrome/cros_ec_lpc_mec.c

File Facts

System
Linux kernel
Corpus path
drivers/platform/chrome/cros_ec_lpc_mec.c
Extension
.c
Size
5189 bytes
Lines
222
Domain
Driver Families
Bucket
drivers/platform
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

while (io_addr <= MEC_EMI_EC_DATA_B3(mec_emi_base)) {
			if (io_type == MEC_IO_READ)
				buf[i] = inb(io_addr++);
			else
				outb(buf[i], io_addr++);

			sum += buf[i++];
			offset++;

			/* Extra bounds check in case of misaligned length */
			if (i == length)
				goto done;
		}

		/*
		 * Use long auto-increment access except for misaligned write,
		 * since writing B3 triggers the flush.
		 */
		if (length - i < 4 && io_type == MEC_IO_WRITE)
			new_access = ACCESS_TYPE_BYTE;
		else
			new_access = ACCESS_TYPE_LONG_AUTO_INCREMENT;

		if (new_access != access ||
		    access != ACCESS_TYPE_LONG_AUTO_INCREMENT) {
			access = new_access;
			cros_ec_lpc_mec_emi_write_address(offset, access);
		}

		/* Access [B0, B3] on each loop pass */
		io_addr = MEC_EMI_EC_DATA_B0(mec_emi_base);
	}

done:
	ret = cros_ec_lpc_mec_unlock();
	if (ret)
		return ret;

	return sum;
}
EXPORT_SYMBOL(cros_ec_lpc_io_bytes_mec);

void cros_ec_lpc_mec_init(unsigned int base, unsigned int end)
{
	mec_emi_base = base;
	mec_emi_end = end;
}
EXPORT_SYMBOL(cros_ec_lpc_mec_init);

int cros_ec_lpc_mec_acpi_mutex(struct acpi_device *adev, const char *pathname)
{
	int status;

	if (!adev)
		return -ENOENT;

	status = acpi_get_handle(adev->handle, pathname, &aml_mutex);
	if (ACPI_FAILURE(status))
		return -ENOENT;

	return 0;
}
EXPORT_SYMBOL(cros_ec_lpc_mec_acpi_mutex);

Annotation

Implementation Notes