Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

i2c: acpi: Introduce i2c_acpi_get_i2c_resource() helper

Besides current two users one more is coming. Definitely makes sense to
introduce a helper.

No functional change intended.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Mika Westerberg <mika.westerberg@linux.intel.com>
Acked-by: Wolfram Sang <wsa@the-dreams.de>

+40 -12
+29 -12
drivers/i2c/i2c-core-acpi.c
··· 45 45 u32 min_speed; 46 46 }; 47 47 48 + /** 49 + * i2c_acpi_get_i2c_resource - Gets I2cSerialBus resource if type matches 50 + * @ares: ACPI resource 51 + * @i2c: Pointer to I2cSerialBus resource will be returned here 52 + * 53 + * Checks if the given ACPI resource is of type I2cSerialBus. 54 + * In this case, returns a pointer to it to the caller. 55 + * 56 + * Returns true if resource type is of I2cSerialBus, otherwise false. 57 + */ 58 + bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, 59 + struct acpi_resource_i2c_serialbus **i2c) 60 + { 61 + struct acpi_resource_i2c_serialbus *sb; 62 + 63 + if (ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) 64 + return false; 65 + 66 + sb = &ares->data.i2c_serial_bus; 67 + if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C) 68 + return false; 69 + 70 + *i2c = sb; 71 + return true; 72 + } 73 + EXPORT_SYMBOL_GPL(i2c_acpi_get_i2c_resource); 74 + 48 75 static int i2c_acpi_fill_info(struct acpi_resource *ares, void *data) 49 76 { 50 77 struct i2c_acpi_lookup *lookup = data; ··· 79 52 struct acpi_resource_i2c_serialbus *sb; 80 53 acpi_status status; 81 54 82 - if (info->addr || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) 83 - return 1; 84 - 85 - sb = &ares->data.i2c_serial_bus; 86 - if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C) 55 + if (info->addr || !i2c_acpi_get_i2c_resource(ares, &sb)) 87 56 return 1; 88 57 89 58 if (lookup->index != -1 && lookup->n++ != lookup->index) ··· 557 534 goto err; 558 535 } 559 536 560 - if (!value64 || ares->type != ACPI_RESOURCE_TYPE_SERIAL_BUS) { 561 - ret = AE_BAD_PARAMETER; 562 - goto err; 563 - } 564 - 565 - sb = &ares->data.i2c_serial_bus; 566 - if (sb->type != ACPI_RESOURCE_SERIAL_TYPE_I2C) { 537 + if (!value64 || !i2c_acpi_get_i2c_resource(ares, &sb)) { 567 538 ret = AE_BAD_PARAMETER; 568 539 goto err; 569 540 }
+11
include/linux/acpi.h
··· 1054 1054 } 1055 1055 #endif 1056 1056 1057 + #if defined(CONFIG_ACPI) && IS_ENABLED(CONFIG_I2C) 1058 + bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, 1059 + struct acpi_resource_i2c_serialbus **i2c); 1060 + #else 1061 + static inline bool i2c_acpi_get_i2c_resource(struct acpi_resource *ares, 1062 + struct acpi_resource_i2c_serialbus **i2c) 1063 + { 1064 + return false; 1065 + } 1066 + #endif 1067 + 1057 1068 /* Device properties */ 1058 1069 1059 1070 #ifdef CONFIG_ACPI