1 // SPDX-License-Identifier: GPL-2.0
4 #include <linux/acpi.h>
5 #include <linux/slab.h>
9 union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev, char *id)
11 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
12 acpi_handle handle = adev->handle;
13 union acpi_object *obj;
16 status = acpi_evaluate_object(handle, id, NULL, &buffer);
17 if (ACPI_FAILURE(status))
18 return ERR_PTR(-ENODEV);
22 return ERR_PTR(-ENODEV);
24 if (obj->type != ACPI_TYPE_BUFFER) {
25 acpi_handle_err(handle, "%s object is not an ACPI buffer\n", id);
27 return ERR_PTR(-EINVAL);
33 int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb)
35 union acpi_object *obj;
38 obj = skl_int3472_get_acpi_buffer(adev, "CLDB");
42 if (obj->buffer.length > sizeof(*cldb)) {
43 acpi_handle_err(adev->handle, "The CLDB buffer is too large\n");
48 memcpy(cldb, obj->buffer.pointer, obj->buffer.length);
56 /* sensor_adev_ret may be NULL, name_ret must not be NULL */
57 int skl_int3472_get_sensor_adev_and_name(struct device *dev,
58 struct acpi_device **sensor_adev_ret,
59 const char **name_ret)
61 struct acpi_device *adev = ACPI_COMPANION(dev);
62 struct acpi_device *sensor;
65 sensor = acpi_dev_get_next_consumer_dev(adev, NULL);
67 dev_err(dev, "INT3472 seems to have no dependents.\n");
71 *name_ret = devm_kasprintf(dev, GFP_KERNEL, I2C_DEV_NAME_FORMAT,
72 acpi_dev_name(sensor));
76 if (ret == 0 && sensor_adev_ret)
77 *sensor_adev_ret = sensor;