forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 6778948f9de86c3cfaf36725a7c87dcff9ba247f
kernel/drivers/hid/i2c-hid/i2c-hid-core.c
....@@ -26,7 +26,6 @@
2626 #include <linux/delay.h>
2727 #include <linux/slab.h>
2828 #include <linux/pm.h>
29
-#include <linux/pm_runtime.h>
3029 #include <linux/device.h>
3130 #include <linux/wait.h>
3231 #include <linux/err.h>
....@@ -48,11 +47,10 @@
4847 /* quirks to control the device */
4948 #define I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV BIT(0)
5049 #define I2C_HID_QUIRK_NO_IRQ_AFTER_RESET BIT(1)
51
-#define I2C_HID_QUIRK_NO_RUNTIME_PM BIT(2)
52
-#define I2C_HID_QUIRK_DELAY_AFTER_SLEEP BIT(3)
5350 #define I2C_HID_QUIRK_BOGUS_IRQ BIT(4)
5451 #define I2C_HID_QUIRK_RESET_ON_RESUME BIT(5)
5552 #define I2C_HID_QUIRK_BAD_INPUT_SIZE BIT(6)
53
+#define I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET BIT(7)
5654
5755
5856 /* flags */
....@@ -163,8 +161,6 @@
163161
164162 bool irq_wake_enabled;
165163 struct mutex reset_lock;
166
-
167
- unsigned long sleep_delay;
168164 };
169165
170166 static const struct i2c_hid_quirks {
....@@ -172,25 +168,26 @@
172168 __u16 idProduct;
173169 __u32 quirks;
174170 } i2c_hid_quirks[] = {
175
- { USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8752,
176
- I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
177
- { USB_VENDOR_ID_WEIDA, USB_DEVICE_ID_WEIDA_8755,
171
+ { USB_VENDOR_ID_WEIDA, HID_ANY_ID,
178172 I2C_HID_QUIRK_SET_PWR_WAKEUP_DEV },
179173 { I2C_VENDOR_ID_HANTICK, I2C_PRODUCT_ID_HANTICK_5288,
180
- I2C_HID_QUIRK_NO_IRQ_AFTER_RESET |
181
- I2C_HID_QUIRK_NO_RUNTIME_PM },
182
- { I2C_VENDOR_ID_RAYDIUM, I2C_PRODUCT_ID_RAYDIUM_4B33,
183
- I2C_HID_QUIRK_DELAY_AFTER_SLEEP },
184
- { USB_VENDOR_ID_LG, I2C_DEVICE_ID_LG_8001,
185
- I2C_HID_QUIRK_NO_RUNTIME_PM },
186
- { USB_VENDOR_ID_ELAN, HID_ANY_ID,
187
- I2C_HID_QUIRK_BOGUS_IRQ },
174
+ I2C_HID_QUIRK_NO_IRQ_AFTER_RESET },
175
+ { I2C_VENDOR_ID_ITE, I2C_DEVICE_ID_ITE_VOYO_WINPAD_A15,
176
+ I2C_HID_QUIRK_NO_IRQ_AFTER_RESET },
177
+ { I2C_VENDOR_ID_RAYDIUM, I2C_PRODUCT_ID_RAYDIUM_3118,
178
+ I2C_HID_QUIRK_NO_IRQ_AFTER_RESET },
188179 { USB_VENDOR_ID_ALPS_JP, HID_ANY_ID,
189180 I2C_HID_QUIRK_RESET_ON_RESUME },
190181 { I2C_VENDOR_ID_SYNAPTICS, I2C_PRODUCT_ID_SYNAPTICS_SYNA2393,
191182 I2C_HID_QUIRK_RESET_ON_RESUME },
192183 { USB_VENDOR_ID_ITE, I2C_DEVICE_ID_ITE_LENOVO_LEGION_Y720,
193184 I2C_HID_QUIRK_BAD_INPUT_SIZE },
185
+ /*
186
+ * Sending the wakeup after reset actually break ELAN touchscreen controller
187
+ */
188
+ { USB_VENDOR_ID_ELAN, HID_ANY_ID,
189
+ I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET |
190
+ I2C_HID_QUIRK_BOGUS_IRQ },
194191 { 0, 0 }
195192 };
196193
....@@ -333,7 +330,7 @@
333330 * @reportType: 0x03 for HID_FEATURE_REPORT ; 0x02 for HID_OUTPUT_REPORT
334331 * @reportID: the report ID
335332 * @buf: the actual data to transfer, without the report ID
336
- * @len: size of buf
333
+ * @data_len: size of buf
337334 * @use_data: true: use SET_REPORT HID command, false: send plain OUTPUT report
338335 */
339336 static int i2c_hid_set_or_send_report(struct i2c_client *client, u8 reportType,
....@@ -406,7 +403,6 @@
406403 {
407404 struct i2c_hid *ihid = i2c_get_clientdata(client);
408405 int ret;
409
- unsigned long now, delay;
410406
411407 i2c_hid_dbg(ihid, "%s\n", __func__);
412408
....@@ -424,21 +420,8 @@
424420 goto set_pwr_exit;
425421 }
426422
427
- if (ihid->quirks & I2C_HID_QUIRK_DELAY_AFTER_SLEEP &&
428
- power_state == I2C_HID_PWR_ON) {
429
- now = jiffies;
430
- if (time_after(ihid->sleep_delay, now)) {
431
- delay = jiffies_to_usecs(ihid->sleep_delay - now);
432
- usleep_range(delay, delay + 1);
433
- }
434
- }
435
-
436423 ret = __i2c_hid_command(client, &hid_set_power_cmd, power_state,
437424 0, NULL, 0, NULL, 0);
438
-
439
- if (ihid->quirks & I2C_HID_QUIRK_DELAY_AFTER_SLEEP &&
440
- power_state == I2C_HID_PWR_SLEEP)
441
- ihid->sleep_delay = jiffies + msecs_to_jiffies(20);
442425
443426 if (ret)
444427 dev_err(&client->dev, "failed to change power setting.\n");
....@@ -484,7 +467,12 @@
484467 if (ret) {
485468 dev_err(&client->dev, "failed to reset device.\n");
486469 i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
470
+ goto out_unlock;
487471 }
472
+
473
+ /* At least some SIS devices need this after reset */
474
+ if (!(ihid->quirks & I2C_HID_QUIRK_NO_WAKEUP_AFTER_RESET))
475
+ ret = i2c_hid_set_power(client, I2C_HID_PWR_ON);
488476
489477 out_unlock:
490478 mutex_unlock(&ihid->reset_lock);
....@@ -632,6 +620,17 @@
632620 if (report_type == HID_OUTPUT_REPORT)
633621 return -EINVAL;
634622
623
+ /*
624
+ * In case of unnumbered reports the response from the device will
625
+ * not have the report ID that the upper layers expect, so we need
626
+ * to stash it the buffer ourselves and adjust the data size.
627
+ */
628
+ if (!report_number) {
629
+ buf[0] = 0;
630
+ buf++;
631
+ count--;
632
+ }
633
+
635634 /* +2 bytes to include the size of the reply in the query buffer */
636635 ask_count = min(count + 2, (size_t)ihid->bufsize);
637636
....@@ -653,6 +652,9 @@
653652 count = min(count, ret_count - 2);
654653 memcpy(buf, ihid->rawbuf + 2, count);
655654
655
+ if (!report_number)
656
+ count++;
657
+
656658 return count;
657659 }
658660
....@@ -669,17 +671,19 @@
669671
670672 mutex_lock(&ihid->reset_lock);
671673
672
- if (report_id) {
673
- buf++;
674
- count--;
675
- }
676
-
674
+ /*
675
+ * Note that both numbered and unnumbered reports passed here
676
+ * are supposed to have report ID stored in the 1st byte of the
677
+ * buffer, so we strip it off unconditionally before passing payload
678
+ * to i2c_hid_set_or_send_report which takes care of encoding
679
+ * everything properly.
680
+ */
677681 ret = i2c_hid_set_or_send_report(client,
678682 report_type == HID_FEATURE_REPORT ? 0x03 : 0x02,
679
- report_id, buf, count, use_data);
683
+ report_id, buf + 1, count - 1, use_data);
680684
681
- if (report_id && ret >= 0)
682
- ret++; /* add report_id to the number of transfered bytes */
685
+ if (ret >= 0)
686
+ ret++; /* add report_id to the number of transferred bytes */
683687
684688 mutex_unlock(&ihid->reset_lock);
685689
....@@ -810,11 +814,6 @@
810814 {
811815 struct i2c_client *client = hid->driver_data;
812816 struct i2c_hid *ihid = i2c_get_clientdata(client);
813
- int ret = 0;
814
-
815
- ret = pm_runtime_get_sync(&client->dev);
816
- if (ret < 0)
817
- return ret;
818817
819818 set_bit(I2C_HID_STARTED, &ihid->flags);
820819 return 0;
....@@ -826,27 +825,6 @@
826825 struct i2c_hid *ihid = i2c_get_clientdata(client);
827826
828827 clear_bit(I2C_HID_STARTED, &ihid->flags);
829
-
830
- /* Save some power */
831
- pm_runtime_put(&client->dev);
832
-}
833
-
834
-static int i2c_hid_power(struct hid_device *hid, int lvl)
835
-{
836
- struct i2c_client *client = hid->driver_data;
837
- struct i2c_hid *ihid = i2c_get_clientdata(client);
838
-
839
- i2c_hid_dbg(ihid, "%s lvl:%d\n", __func__, lvl);
840
-
841
- switch (lvl) {
842
- case PM_HINT_FULLON:
843
- pm_runtime_get_sync(&client->dev);
844
- break;
845
- case PM_HINT_NORMAL:
846
- pm_runtime_put(&client->dev);
847
- break;
848
- }
849
- return 0;
850828 }
851829
852830 struct hid_ll_driver i2c_hid_ll_driver = {
....@@ -855,7 +833,6 @@
855833 .stop = i2c_hid_stop,
856834 .open = i2c_hid_open,
857835 .close = i2c_hid_close,
858
- .power = i2c_hid_power,
859836 .output_report = i2c_hid_output_report,
860837 .raw_request = i2c_hid_raw_request,
861838 };
....@@ -982,6 +959,19 @@
982959 acpi_device_fix_up_power(adev);
983960 }
984961
962
+static void i2c_hid_acpi_enable_wakeup(struct device *dev)
963
+{
964
+ if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0) {
965
+ device_set_wakeup_capable(dev, true);
966
+ device_set_wakeup_enable(dev, false);
967
+ }
968
+}
969
+
970
+static void i2c_hid_acpi_shutdown(struct device *dev)
971
+{
972
+ acpi_device_set_power(ACPI_COMPANION(dev), ACPI_STATE_D3_COLD);
973
+}
974
+
985975 static const struct acpi_device_id i2c_hid_acpi_match[] = {
986976 {"ACPI0C50", 0 },
987977 {"PNP0C50", 0 },
....@@ -996,6 +986,10 @@
996986 }
997987
998988 static inline void i2c_hid_acpi_fix_up_power(struct device *dev) {}
989
+
990
+static inline void i2c_hid_acpi_enable_wakeup(struct device *dev) {}
991
+
992
+static inline void i2c_hid_acpi_shutdown(struct device *dev) {}
999993 #endif
1000994
1001995 #ifdef CONFIG_OF
....@@ -1123,9 +1117,8 @@
11231117
11241118 i2c_hid_acpi_fix_up_power(&client->dev);
11251119
1126
- pm_runtime_get_noresume(&client->dev);
1127
- pm_runtime_set_active(&client->dev);
1128
- pm_runtime_enable(&client->dev);
1120
+ i2c_hid_acpi_enable_wakeup(&client->dev);
1121
+
11291122 device_enable_async_suspend(&client->dev);
11301123
11311124 /* Make sure there is something at this address */
....@@ -1133,16 +1126,16 @@
11331126 if (ret < 0) {
11341127 dev_dbg(&client->dev, "nothing at this address: %d\n", ret);
11351128 ret = -ENXIO;
1136
- goto err_pm;
1129
+ goto err_regulator;
11371130 }
11381131
11391132 ret = i2c_hid_fetch_hid_descriptor(ihid);
11401133 if (ret < 0)
1141
- goto err_pm;
1134
+ goto err_regulator;
11421135
11431136 ret = i2c_hid_init_irq(client);
11441137 if (ret < 0)
1145
- goto err_pm;
1138
+ goto err_regulator;
11461139
11471140 hid = hid_allocate_device();
11481141 if (IS_ERR(hid)) {
....@@ -1173,9 +1166,6 @@
11731166 goto err_mem_free;
11741167 }
11751168
1176
- if (!(ihid->quirks & I2C_HID_QUIRK_NO_RUNTIME_PM))
1177
- pm_runtime_put(&client->dev);
1178
-
11791169 return 0;
11801170
11811171 err_mem_free:
....@@ -1183,10 +1173,6 @@
11831173
11841174 err_irq:
11851175 free_irq(client->irq, ihid);
1186
-
1187
-err_pm:
1188
- pm_runtime_put_noidle(&client->dev);
1189
- pm_runtime_disable(&client->dev);
11901176
11911177 err_regulator:
11921178 regulator_bulk_disable(ARRAY_SIZE(ihid->pdata.supplies),
....@@ -1199,12 +1185,6 @@
11991185 {
12001186 struct i2c_hid *ihid = i2c_get_clientdata(client);
12011187 struct hid_device *hid;
1202
-
1203
- if (!(ihid->quirks & I2C_HID_QUIRK_NO_RUNTIME_PM))
1204
- pm_runtime_get_sync(&client->dev);
1205
- pm_runtime_disable(&client->dev);
1206
- pm_runtime_set_suspended(&client->dev);
1207
- pm_runtime_put_noidle(&client->dev);
12081188
12091189 hid = ihid->hid;
12101190 hid_destroy_device(hid);
....@@ -1226,6 +1206,8 @@
12261206
12271207 i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
12281208 free_irq(client->irq, ihid);
1209
+
1210
+ i2c_hid_acpi_shutdown(&client->dev);
12291211 }
12301212
12311213 #ifdef CONFIG_PM_SLEEP
....@@ -1238,25 +1220,15 @@
12381220 int wake_status;
12391221
12401222 if (hid->driver && hid->driver->suspend) {
1241
- /*
1242
- * Wake up the device so that IO issues in
1243
- * HID driver's suspend code can succeed.
1244
- */
1245
- ret = pm_runtime_resume(dev);
1246
- if (ret < 0)
1247
- return ret;
1248
-
12491223 ret = hid->driver->suspend(hid, PMSG_SUSPEND);
12501224 if (ret < 0)
12511225 return ret;
12521226 }
12531227
1254
- if (!pm_runtime_suspended(dev)) {
1255
- /* Save some power */
1256
- i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
1228
+ /* Save some power */
1229
+ i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
12571230
1258
- disable_irq(client->irq);
1259
- }
1231
+ disable_irq(client->irq);
12601232
12611233 if (device_may_wakeup(&client->dev)) {
12621234 wake_status = enable_irq_wake(client->irq);
....@@ -1298,11 +1270,6 @@
12981270 wake_status);
12991271 }
13001272
1301
- /* We'll resume to full power */
1302
- pm_runtime_disable(dev);
1303
- pm_runtime_set_active(dev);
1304
- pm_runtime_enable(dev);
1305
-
13061273 enable_irq(client->irq);
13071274
13081275 /* Instead of resetting device, simply powers the device on. This
....@@ -1330,30 +1297,8 @@
13301297 }
13311298 #endif
13321299
1333
-#ifdef CONFIG_PM
1334
-static int i2c_hid_runtime_suspend(struct device *dev)
1335
-{
1336
- struct i2c_client *client = to_i2c_client(dev);
1337
-
1338
- i2c_hid_set_power(client, I2C_HID_PWR_SLEEP);
1339
- disable_irq(client->irq);
1340
- return 0;
1341
-}
1342
-
1343
-static int i2c_hid_runtime_resume(struct device *dev)
1344
-{
1345
- struct i2c_client *client = to_i2c_client(dev);
1346
-
1347
- enable_irq(client->irq);
1348
- i2c_hid_set_power(client, I2C_HID_PWR_ON);
1349
- return 0;
1350
-}
1351
-#endif
1352
-
13531300 static const struct dev_pm_ops i2c_hid_pm = {
13541301 SET_SYSTEM_SLEEP_PM_OPS(i2c_hid_suspend, i2c_hid_resume)
1355
- SET_RUNTIME_PM_OPS(i2c_hid_runtime_suspend, i2c_hid_runtime_resume,
1356
- NULL)
13571302 };
13581303
13591304 static const struct i2c_device_id i2c_hid_id_table[] = {
....@@ -1368,6 +1313,7 @@
13681313 .driver = {
13691314 .name = "i2c_hid",
13701315 .pm = &i2c_hid_pm,
1316
+ .probe_type = PROBE_PREFER_ASYNCHRONOUS,
13711317 .acpi_match_table = ACPI_PTR(i2c_hid_acpi_match),
13721318 .of_match_table = of_match_ptr(i2c_hid_of_match),
13731319 },