drivers/i2c/generic: Add support for i2c device detection

Add 'detect' flag which can be attached to devices which may or may not
be present at runtime, and for which coreboot should probe the i2c bus
to confirm device presence prior to adding an entry for it in the SSDT.

This is useful for boards which may utilize touchpads/touchscreens from
multiple vendors, so that only the device(s) present are added to the
SSDT. This relieves the burden from the OS to detect/probe if a device
is actually present and allows the OS to trust the ACPI _STA value.

Change-Id: I1a4169ed6416d544773a37d29cdcc154d3c28519
Signed-off-by: Matt DeVillier <matt.devillier@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/63211
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Martin L Roth <gaumless@tutanota.com>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
This commit is contained in:
Matt DeVillier 2022-03-28 22:35:42 -05:00 committed by Paul Fagerburg
parent ee849ba625
commit c636142b02
2 changed files with 23 additions and 0 deletions

View File

@ -31,6 +31,17 @@ struct drivers_i2c_generic_config {
*/
int probed;
/*
* This flag will add a device property which will indicate
* that coreboot should attempt to detect the device on the i2c
* bus before generating a device entry in the SSDT.
*
* This can be used to declare a device that may not exist on
* the board, for example to support multiple touchpads and/or
* touchscreens.
*/
int detect;
/* GPIO used to indicate if this device is present */
unsigned int device_present_gpio;
unsigned int device_present_gpio_invert;

View File

@ -3,6 +3,7 @@
#include <acpi/acpi_device.h>
#include <acpi/acpigen.h>
#include <console/console.h>
#include <device/i2c_bus.h>
#include <device/i2c_simple.h>
#include <device/device.h>
#include <device/path.h>
@ -65,6 +66,17 @@ void i2c_generic_fill_ssdt(const struct device *dev,
return;
}
if (config->detect) {
struct device *const busdev = i2c_busdev(dev);
if (!i2c_dev_detect(busdev, dev->path.i2c.device)) {
printk(BIOS_SPEW, "%s: %s at %s -- NOT FOUND, skipping\n",
path,
config->desc ? : dev->chip_ops->name,
dev_path(dev));
return;
}
}
/* Device */
acpigen_write_scope(scope);
acpigen_write_device(acpi_device_name(dev));