dm: acpi: Enhance acpi_get_name()
For many device types it is possible to figure out the name just by
looking at its uclass or parent. Add a function to handle this, since it
allows us to cover the vast majority of cases automatically.
However it is sometimes impossible to figure out an ACPI name for a device
just by looking at its uclass. For example a touch device may have a
vendor-specific name. Add a new "acpi,name" property to allow a custom
name to be created.
With this new feature we can drop the get_name() methods in the sandbox
I2C and SPI drivers. They were only added for testing purposes. Update the
tests to use the new values.
Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Wolfgang Wallner <wolfgang.wallner@br-automation.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
diff --git a/test/dm/acpi.c b/test/dm/acpi.c
index 1abde65..69ca090 100644
--- a/test/dm/acpi.c
+++ b/test/dm/acpi.c
@@ -124,12 +124,52 @@
static int dm_test_acpi_get_name(struct unit_test_state *uts)
{
char name[ACPI_NAME_MAX];
- struct udevice *dev;
+ struct udevice *dev, *dev2, *i2c, *spi, *serial, *timer, *sound;
+ struct udevice *pci, *root;
+ /* Test getting the name from the driver */
ut_assertok(uclass_first_device_err(UCLASS_TEST_ACPI, &dev));
ut_assertok(acpi_get_name(dev, name));
ut_asserteq_str(ACPI_TEST_DEV_NAME, name);
+ /* Test getting the name from the device tree */
+ ut_assertok(uclass_get_device_by_name(UCLASS_TEST_FDT, "a-test",
+ &dev2));
+ ut_assertok(acpi_get_name(dev2, name));
+ ut_asserteq_str("GHIJ", name);
+
+ /* Test getting the name from acpi_device_get_name() */
+ ut_assertok(uclass_first_device(UCLASS_I2C, &i2c));
+ ut_assertok(acpi_get_name(i2c, name));
+ ut_asserteq_str("I2C0", name);
+
+ ut_assertok(uclass_first_device(UCLASS_SPI, &spi));
+ ut_assertok(acpi_get_name(spi, name));
+ ut_asserteq_str("SPI0", name);
+
+ /* The uart has no sequence number, so this should fail */
+ ut_assertok(uclass_first_device(UCLASS_SERIAL, &serial));
+ ut_asserteq(-ENXIO, acpi_get_name(serial, name));
+
+ /* ACPI doesn't know about the timer */
+ ut_assertok(uclass_first_device(UCLASS_TIMER, &timer));
+ ut_asserteq(-ENOENT, acpi_get_name(timer, name));
+
+ /* May as well test the rest of the cases */
+ ut_assertok(uclass_first_device(UCLASS_SOUND, &sound));
+ ut_assertok(acpi_get_name(sound, name));
+ ut_asserteq_str("HDAS", name);
+
+ ut_assertok(uclass_first_device(UCLASS_PCI, &pci));
+ ut_assertok(acpi_get_name(pci, name));
+ ut_asserteq_str("PCI0", name);
+
+ ut_assertok(uclass_first_device(UCLASS_ROOT, &root));
+ ut_assertok(acpi_get_name(root, name));
+ ut_asserteq_str("\\_SB", name);
+
+ /* Note that we don't have tests for acpi_name_from_id() */
+
return 0;
}
DM_TEST(dm_test_acpi_get_name, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);