forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-09 95099d4622f8cb224d94e314c7a8e0df60b13f87
kernel/drivers/platform/x86/sony-laptop.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * ACPI Sony Notebook Control Driver (SNC and SPIC)
34 *
....@@ -25,21 +26,6 @@
2526 * Copyright (C) 2000 Andrew Tridgell <tridge@valinux.com>
2627 *
2728 * Earlier work by Werner Almesberger, Paul `Rusty' Russell and Paul Mackerras.
28
- *
29
- * This program is free software; you can redistribute it and/or modify
30
- * it under the terms of the GNU General Public License as published by
31
- * the Free Software Foundation; either version 2 of the License, or
32
- * (at your option) any later version.
33
- *
34
- * This program is distributed in the hope that it will be useful,
35
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
36
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
37
- * GNU General Public License for more details.
38
- *
39
- * You should have received a copy of the GNU General Public License
40
- * along with this program; if not, write to the Free Software
41
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
42
- *
4329 */
4430
4531 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
....@@ -771,33 +757,6 @@
771757 return result;
772758 }
773759
774
-static int sony_nc_int_call(acpi_handle handle, char *name, int *value,
775
- int *result)
776
-{
777
- union acpi_object *object = NULL;
778
- if (value) {
779
- u64 v = *value;
780
- object = __call_snc_method(handle, name, &v);
781
- } else
782
- object = __call_snc_method(handle, name, NULL);
783
-
784
- if (!object)
785
- return -EINVAL;
786
-
787
- if (object->type != ACPI_TYPE_INTEGER) {
788
- pr_warn("Invalid acpi_object: expected 0x%x got 0x%x\n",
789
- ACPI_TYPE_INTEGER, object->type);
790
- kfree(object);
791
- return -EINVAL;
792
- }
793
-
794
- if (result)
795
- *result = object->integer.value;
796
-
797
- kfree(object);
798
- return 0;
799
-}
800
-
801760 #define MIN(a, b) (a > b ? b : a)
802761 static int sony_nc_buffer_call(acpi_handle handle, char *name, u64 *value,
803762 void *buffer, size_t buflen)
....@@ -809,21 +768,41 @@
809768 if (!object)
810769 return -EINVAL;
811770
812
- if (object->type == ACPI_TYPE_BUFFER) {
771
+ if (!buffer) {
772
+ /* do nothing */
773
+ } else if (object->type == ACPI_TYPE_BUFFER) {
813774 len = MIN(buflen, object->buffer.length);
775
+ memset(buffer, 0, buflen);
814776 memcpy(buffer, object->buffer.pointer, len);
815777
816778 } else if (object->type == ACPI_TYPE_INTEGER) {
817779 len = MIN(buflen, sizeof(object->integer.value));
780
+ memset(buffer, 0, buflen);
818781 memcpy(buffer, &object->integer.value, len);
819782
820783 } else {
821
- pr_warn("Invalid acpi_object: expected 0x%x got 0x%x\n",
822
- ACPI_TYPE_BUFFER, object->type);
784
+ pr_warn("Unexpected acpi_object: 0x%x\n", object->type);
823785 ret = -EINVAL;
824786 }
825787
826788 kfree(object);
789
+ return ret;
790
+}
791
+
792
+static int sony_nc_int_call(acpi_handle handle, char *name, int *value, int
793
+ *result)
794
+{
795
+ int ret;
796
+
797
+ if (value) {
798
+ u64 v = *value;
799
+
800
+ ret = sony_nc_buffer_call(handle, name, &v, result,
801
+ sizeof(*result));
802
+ } else {
803
+ ret = sony_nc_buffer_call(handle, name, NULL, result,
804
+ sizeof(*result));
805
+ }
827806 return ret;
828807 }
829808
....@@ -841,10 +820,10 @@
841820 int i;
842821
843822 for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
844
- len += snprintf(buffer + len, PAGE_SIZE - len, "0x%.4x ",
823
+ len += scnprintf(buffer + len, PAGE_SIZE - len, "0x%.4x ",
845824 handles->cap[i]);
846825 }
847
- len += snprintf(buffer + len, PAGE_SIZE - len, "\n");
826
+ len += scnprintf(buffer + len, PAGE_SIZE - len, "\n");
848827
849828 return len;
850829 }
....@@ -2201,10 +2180,10 @@
22012180
22022181 for (cnt = 0; cnt < THM_PROFILE_MAX; cnt++) {
22032182 if (!cnt || (th_handle->profiles & cnt))
2204
- idx += snprintf(buffer + idx, PAGE_SIZE - idx, "%s ",
2183
+ idx += scnprintf(buffer + idx, PAGE_SIZE - idx, "%s ",
22052184 snc_thermal_profiles[cnt]);
22062185 }
2207
- idx += snprintf(buffer + idx, PAGE_SIZE - idx, "\n");
2186
+ idx += scnprintf(buffer + idx, PAGE_SIZE - idx, "\n");
22082187
22092188 return idx;
22102189 }
....@@ -2309,7 +2288,12 @@
23092288 #ifdef CONFIG_PM_SLEEP
23102289 static void sony_nc_thermal_resume(void)
23112290 {
2312
- unsigned int status = sony_nc_thermal_mode_get();
2291
+ int status;
2292
+
2293
+ if (!th_handle)
2294
+ return;
2295
+
2296
+ status = sony_nc_thermal_mode_get();
23132297
23142298 if (status != th_handle->mode)
23152299 sony_nc_thermal_mode_set(th_handle->mode);
....@@ -4392,7 +4376,7 @@
43924376 list_add(&interrupt->list, &dev->interrupts);
43934377 interrupt->irq.triggering = p->triggering;
43944378 interrupt->irq.polarity = p->polarity;
4395
- interrupt->irq.sharable = p->sharable;
4379
+ interrupt->irq.shareable = p->shareable;
43964380 interrupt->irq.interrupt_count = 1;
43974381 interrupt->irq.interrupts[0] = p->interrupts[i];
43984382 }
....@@ -4548,7 +4532,7 @@
45484532 memcpy(&resource->res3.data.irq, &irq->irq,
45494533 sizeof(struct acpi_resource_irq));
45504534 /* we requested a shared irq */
4551
- resource->res3.data.irq.sharable = ACPI_SHARED;
4535
+ resource->res3.data.irq.shareable = ACPI_SHARED;
45524536
45534537 resource->res4.type = ACPI_RESOURCE_TYPE_END_TAG;
45544538 resource->res4.length = sizeof(struct acpi_resource);
....@@ -4567,7 +4551,7 @@
45674551 memcpy(&resource->res2.data.irq, &irq->irq,
45684552 sizeof(struct acpi_resource_irq));
45694553 /* we requested a shared irq */
4570
- resource->res2.data.irq.sharable = ACPI_SHARED;
4554
+ resource->res2.data.irq.shareable = ACPI_SHARED;
45714555
45724556 resource->res3.type = ACPI_RESOURCE_TYPE_END_TAG;
45734557 resource->res3.length = sizeof(struct acpi_resource);
....@@ -4781,7 +4765,7 @@
47814765 irq->irq.interrupts[0],
47824766 irq->irq.triggering,
47834767 irq->irq.polarity,
4784
- irq->irq.sharable);
4768
+ irq->irq.shareable);
47854769 spic_dev.cur_irq = irq;
47864770 break;
47874771 }