forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
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 }
....@@ -1913,14 +1892,21 @@
19131892 break;
19141893 }
19151894
1916
- ret = sony_call_snc_handle(handle, probe_base, &result);
1917
- if (ret)
1918
- return ret;
1895
+ /*
1896
+ * Only probe if there is a separate probe_base, otherwise the probe call
1897
+ * is equivalent to __sony_nc_kbd_backlight_mode_set(0), resulting in
1898
+ * the keyboard backlight being turned off.
1899
+ */
1900
+ if (probe_base) {
1901
+ ret = sony_call_snc_handle(handle, probe_base, &result);
1902
+ if (ret)
1903
+ return ret;
19191904
1920
- if ((handle == 0x0137 && !(result & 0x02)) ||
1921
- !(result & 0x01)) {
1922
- dprintk("no backlight keyboard found\n");
1923
- return 0;
1905
+ if ((handle == 0x0137 && !(result & 0x02)) ||
1906
+ !(result & 0x01)) {
1907
+ dprintk("no backlight keyboard found\n");
1908
+ return 0;
1909
+ }
19241910 }
19251911
19261912 kbdbl_ctl = kzalloc(sizeof(*kbdbl_ctl), GFP_KERNEL);
....@@ -2201,10 +2187,10 @@
22012187
22022188 for (cnt = 0; cnt < THM_PROFILE_MAX; cnt++) {
22032189 if (!cnt || (th_handle->profiles & cnt))
2204
- idx += snprintf(buffer + idx, PAGE_SIZE - idx, "%s ",
2190
+ idx += scnprintf(buffer + idx, PAGE_SIZE - idx, "%s ",
22052191 snc_thermal_profiles[cnt]);
22062192 }
2207
- idx += snprintf(buffer + idx, PAGE_SIZE - idx, "\n");
2193
+ idx += scnprintf(buffer + idx, PAGE_SIZE - idx, "\n");
22082194
22092195 return idx;
22102196 }
....@@ -2309,7 +2295,12 @@
23092295 #ifdef CONFIG_PM_SLEEP
23102296 static void sony_nc_thermal_resume(void)
23112297 {
2312
- unsigned int status = sony_nc_thermal_mode_get();
2298
+ int status;
2299
+
2300
+ if (!th_handle)
2301
+ return;
2302
+
2303
+ status = sony_nc_thermal_mode_get();
23132304
23142305 if (status != th_handle->mode)
23152306 sony_nc_thermal_mode_set(th_handle->mode);
....@@ -4392,7 +4383,7 @@
43924383 list_add(&interrupt->list, &dev->interrupts);
43934384 interrupt->irq.triggering = p->triggering;
43944385 interrupt->irq.polarity = p->polarity;
4395
- interrupt->irq.sharable = p->sharable;
4386
+ interrupt->irq.shareable = p->shareable;
43964387 interrupt->irq.interrupt_count = 1;
43974388 interrupt->irq.interrupts[0] = p->interrupts[i];
43984389 }
....@@ -4548,7 +4539,7 @@
45484539 memcpy(&resource->res3.data.irq, &irq->irq,
45494540 sizeof(struct acpi_resource_irq));
45504541 /* we requested a shared irq */
4551
- resource->res3.data.irq.sharable = ACPI_SHARED;
4542
+ resource->res3.data.irq.shareable = ACPI_SHARED;
45524543
45534544 resource->res4.type = ACPI_RESOURCE_TYPE_END_TAG;
45544545 resource->res4.length = sizeof(struct acpi_resource);
....@@ -4567,7 +4558,7 @@
45674558 memcpy(&resource->res2.data.irq, &irq->irq,
45684559 sizeof(struct acpi_resource_irq));
45694560 /* we requested a shared irq */
4570
- resource->res2.data.irq.sharable = ACPI_SHARED;
4561
+ resource->res2.data.irq.shareable = ACPI_SHARED;
45714562
45724563 resource->res3.type = ACPI_RESOURCE_TYPE_END_TAG;
45734564 resource->res3.length = sizeof(struct acpi_resource);
....@@ -4781,7 +4772,7 @@
47814772 irq->irq.interrupts[0],
47824773 irq->irq.triggering,
47834774 irq->irq.polarity,
4784
- irq->irq.sharable);
4775
+ irq->irq.shareable);
47854776 spic_dev.cur_irq = irq;
47864777 break;
47874778 }