This source file includes following definitions.
- acpi_lpat_raw_to_temp
- acpi_lpat_temp_to_raw
- acpi_lpat_get_conversion_table
- acpi_lpat_free_conversion_table
1
2
3
4
5
6
7
8 #include <linux/export.h>
9 #include <linux/acpi.h>
10 #include <acpi/acpi_lpat.h>
11
12
13
14
15
16
17
18
19
20
21
22
23 int acpi_lpat_raw_to_temp(struct acpi_lpat_conversion_table *lpat_table,
24 int raw)
25 {
26 int i, delta_temp, delta_raw, temp;
27 struct acpi_lpat *lpat = lpat_table->lpat;
28
29 for (i = 0; i < lpat_table->lpat_count - 1; i++) {
30 if ((raw >= lpat[i].raw && raw <= lpat[i+1].raw) ||
31 (raw <= lpat[i].raw && raw >= lpat[i+1].raw))
32 break;
33 }
34
35 if (i == lpat_table->lpat_count - 1)
36 return -ENOENT;
37
38 delta_temp = lpat[i+1].temp - lpat[i].temp;
39 delta_raw = lpat[i+1].raw - lpat[i].raw;
40 temp = lpat[i].temp + (raw - lpat[i].raw) * delta_temp / delta_raw;
41
42 return temp;
43 }
44 EXPORT_SYMBOL_GPL(acpi_lpat_raw_to_temp);
45
46
47
48
49
50
51
52
53
54
55
56
57 int acpi_lpat_temp_to_raw(struct acpi_lpat_conversion_table *lpat_table,
58 int temp)
59 {
60 int i, delta_temp, delta_raw, raw;
61 struct acpi_lpat *lpat = lpat_table->lpat;
62
63 for (i = 0; i < lpat_table->lpat_count - 1; i++) {
64 if (temp >= lpat[i].temp && temp <= lpat[i+1].temp)
65 break;
66 }
67
68 if (i == lpat_table->lpat_count - 1)
69 return -ENOENT;
70
71 delta_temp = lpat[i+1].temp - lpat[i].temp;
72 delta_raw = lpat[i+1].raw - lpat[i].raw;
73 raw = lpat[i].raw + (temp - lpat[i].temp) * delta_raw / delta_temp;
74
75 return raw;
76 }
77 EXPORT_SYMBOL_GPL(acpi_lpat_temp_to_raw);
78
79
80
81
82
83
84
85
86
87
88
89 struct acpi_lpat_conversion_table *acpi_lpat_get_conversion_table(acpi_handle
90 handle)
91 {
92 struct acpi_lpat_conversion_table *lpat_table = NULL;
93 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
94 union acpi_object *obj_p, *obj_e;
95 int *lpat, i;
96 acpi_status status;
97
98 status = acpi_evaluate_object(handle, "LPAT", NULL, &buffer);
99 if (ACPI_FAILURE(status))
100 return NULL;
101
102 obj_p = (union acpi_object *)buffer.pointer;
103 if (!obj_p || (obj_p->type != ACPI_TYPE_PACKAGE) ||
104 (obj_p->package.count % 2) || (obj_p->package.count < 4))
105 goto out;
106
107 lpat = kcalloc(obj_p->package.count, sizeof(int), GFP_KERNEL);
108 if (!lpat)
109 goto out;
110
111 for (i = 0; i < obj_p->package.count; i++) {
112 obj_e = &obj_p->package.elements[i];
113 if (obj_e->type != ACPI_TYPE_INTEGER) {
114 kfree(lpat);
115 goto out;
116 }
117 lpat[i] = (s64)obj_e->integer.value;
118 }
119
120 lpat_table = kzalloc(sizeof(*lpat_table), GFP_KERNEL);
121 if (!lpat_table) {
122 kfree(lpat);
123 goto out;
124 }
125
126 lpat_table->lpat = (struct acpi_lpat *)lpat;
127 lpat_table->lpat_count = obj_p->package.count / 2;
128
129 out:
130 kfree(buffer.pointer);
131 return lpat_table;
132 }
133 EXPORT_SYMBOL_GPL(acpi_lpat_get_conversion_table);
134
135
136
137
138
139
140
141
142
143 void acpi_lpat_free_conversion_table(struct acpi_lpat_conversion_table
144 *lpat_table)
145 {
146 if (lpat_table) {
147 kfree(lpat_table->lpat);
148 kfree(lpat_table);
149 }
150 }
151 EXPORT_SYMBOL_GPL(acpi_lpat_free_conversion_table);