File Index
Files and directories
Sign in
FILE

common.c

File preview with syntax highlighting.

linux-6.19.14/drivers/platform/x86/intel/int3472/common.c C
 1// SPDX-License-Identifier: GPL-2.0
 2/* Author: Dan Scally <djrscally@gmail.com> */
 3
 4#include <linux/acpi.h>
 5#include <linux/platform_data/x86/int3472.h>
 6#include <linux/slab.h>
 7
 8union acpi_object *skl_int3472_get_acpi_buffer(struct acpi_device *adev, char *id)
 9{
10	struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
11	acpi_handle handle = adev->handle;
12	union acpi_object *obj;
13	acpi_status status;
14
15	status = acpi_evaluate_object(handle, id, NULL, &buffer);
16	if (ACPI_FAILURE(status))
17		return ERR_PTR(-ENODEV);
18
19	obj = buffer.pointer;
20	if (!obj)
21		return ERR_PTR(-ENODEV);
22
23	if (obj->type != ACPI_TYPE_BUFFER) {
24		acpi_handle_err(handle, "%s object is not an ACPI buffer\n", id);
25		kfree(obj);
26		return ERR_PTR(-EINVAL);
27	}
28
29	return obj;
30}
31EXPORT_SYMBOL_NS_GPL(skl_int3472_get_acpi_buffer, "INTEL_INT3472");
32
33int skl_int3472_fill_cldb(struct acpi_device *adev, struct int3472_cldb *cldb)
34{
35	union acpi_object *obj;
36	int ret;
37
38	obj = skl_int3472_get_acpi_buffer(adev, "CLDB");
39	if (IS_ERR(obj))
40		return PTR_ERR(obj);
41
42	if (obj->buffer.length > sizeof(*cldb)) {
43		acpi_handle_err(adev->handle, "The CLDB buffer is too large\n");
44		ret = -EINVAL;
45		goto out_free_obj;
46	}
47
48	memcpy(cldb, obj->buffer.pointer, obj->buffer.length);
49	ret = 0;
50
51out_free_obj:
52	kfree(obj);
53	return ret;
54}
55EXPORT_SYMBOL_NS_GPL(skl_int3472_fill_cldb, "INTEL_INT3472");
56
57/* sensor_adev_ret may be NULL, name_ret must not be NULL */
58int skl_int3472_get_sensor_adev_and_name(struct device *dev,
59					 struct acpi_device **sensor_adev_ret,
60					 const char **name_ret)
61{
62	struct acpi_device *adev = ACPI_COMPANION(dev);
63	struct acpi_device *sensor;
64	int ret = 0;
65
66	sensor = acpi_dev_get_next_consumer_dev(adev, NULL);
67	if (!sensor) {
68		dev_err(dev, "INT3472 seems to have no dependents.\n");
69		return -ENODEV;
70	}
71
72	dev_dbg(dev, "Sensor name %s\n", acpi_dev_name(sensor));
73
74	*name_ret = devm_kasprintf(dev, GFP_KERNEL, I2C_DEV_NAME_FORMAT,
75				   acpi_dev_name(sensor));
76	if (!*name_ret)
77		ret = -ENOMEM;
78
79	if (ret == 0 && sensor_adev_ret)
80		*sensor_adev_ret = sensor;
81	else
82		acpi_dev_put(sensor);
83
84	return ret;
85}
86EXPORT_SYMBOL_NS_GPL(skl_int3472_get_sensor_adev_and_name, "INTEL_INT3472");
87
88MODULE_DESCRIPTION("Intel SkyLake INT3472 ACPI Device Driver library");
89MODULE_AUTHOR("Daniel Scally <djrscally@gmail.com>");
90MODULE_LICENSE("GPL");
~/ Read-only file preview.