-
-
Notifications
You must be signed in to change notification settings - Fork 514
/
razermouse_driver.c
6595 lines (5791 loc) · 288 KB
/
razermouse_driver.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2015 Terry Cain <terrys-home.co.uk>
*/
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/module.h>
#include <linux/init.h>
#include <linux/usb/input.h>
#include <linux/hid.h>
#include <linux/hrtimer.h>
#include <linux/random.h>
#include "razermouse_driver.h"
#include "razercommon.h"
#include "razerchromacommon.h"
/*
* Version Information
*/
#define DRIVER_DESC "Razer Mouse Device Driver"
/* REL_HWHEEL_HI_RES was added in Linux 5.0, so define ourselves for older kernels
* See also https://git.kernel.org/torvalds/c/52ea899 */
#ifndef REL_HWHEEL_HI_RES
#define REL_HWHEEL_HI_RES 0x0c
#endif
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
MODULE_VERSION(DRIVER_VERSION);
MODULE_LICENSE(DRIVER_LICENSE);
/**
* Send report to the mouse
*/
static int razer_get_report(struct usb_device *usb_dev, struct razer_report *request, struct razer_report *response)
{
unsigned int index = 0;
switch (usb_dev->descriptor.idProduct) {
// These devices require longer waits to read their firmware, serial, and other setting values
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRELESS_RECEIVER:
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRELESS_WIRED:
case USB_DEVICE_ID_RAZER_MAMBA_WIRELESS_RECEIVER:
case USB_DEVICE_ID_RAZER_MAMBA_WIRELESS_WIRED:
case USB_DEVICE_ID_RAZER_BASILISK_X_HYPERSPEED:
case USB_DEVICE_ID_RAZER_BASILISK_ULTIMATE_RECEIVER:
case USB_DEVICE_ID_RAZER_BASILISK_ULTIMATE_WIRED:
case USB_DEVICE_ID_RAZER_PRO_CLICK_RECEIVER:
case USB_DEVICE_ID_RAZER_PRO_CLICK_WIRED:
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_X_HYPERSPEED:
case USB_DEVICE_ID_RAZER_VIPER_V2_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_VIPER_V2_PRO_WIRED:
case USB_DEVICE_ID_RAZER_COBRA_PRO:
case USB_DEVICE_ID_RAZER_DEATHADDER_V3_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_DEATHADDER_V3_PRO_WIRED:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRED:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_PRO_CLICK_MINI_RECEIVER:
case USB_DEVICE_ID_RAZER_NAGA_V2_HYPERSPEED_RECEIVER:
return razer_get_usb_response(usb_dev, index, request, index, response, RAZER_NEW_MOUSE_RECEIVER_WAIT_MIN_US, RAZER_NEW_MOUSE_RECEIVER_WAIT_MAX_US);
break;
case USB_DEVICE_ID_RAZER_ATHERIS_RECEIVER:
case USB_DEVICE_ID_RAZER_OROCHI_V2_RECEIVER:
case USB_DEVICE_ID_RAZER_OROCHI_V2_BLUETOOTH:
return razer_get_usb_response(usb_dev, index, request, index, response, RAZER_ATHERIS_RECEIVER_WAIT_MIN_US, RAZER_ATHERIS_RECEIVER_WAIT_MAX_US);
break;
case USB_DEVICE_ID_RAZER_VIPER_ULTIMATE_WIRELESS:
case USB_DEVICE_ID_RAZER_VIPER_ULTIMATE_WIRED:
case USB_DEVICE_ID_RAZER_VIPER_MINI_SE_WIRED:
case USB_DEVICE_ID_RAZER_VIPER_MINI_SE_WIRELESS:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_PRO_WIRED:
case USB_DEVICE_ID_RAZER_HYPERPOLLING_WIRELESS_DONGLE:
case USB_DEVICE_ID_RAZER_VIPER_V3_HYPERSPEED:
return razer_get_usb_response(usb_dev, index, request, index, response, RAZER_VIPER_MOUSE_RECEIVER_WAIT_MIN_US, RAZER_VIPER_MOUSE_RECEIVER_WAIT_MAX_US);
break;
case USB_DEVICE_ID_RAZER_NAGA_X:
case USB_DEVICE_ID_RAZER_BASILISK_V3:
index = 0x03;
return razer_get_usb_response(usb_dev, index, request, index, response, RAZER_MOUSE_WAIT_MIN_US, RAZER_MOUSE_WAIT_MAX_US);
break;
default:
return razer_get_usb_response(usb_dev, index, request, index, response, RAZER_MOUSE_WAIT_MIN_US, RAZER_MOUSE_WAIT_MAX_US);
}
}
/**
* Function to send to device, get response, and actually check the response
*/
static int razer_send_payload(struct razer_mouse_device *device, struct razer_report *request, struct razer_report *response)
{
int err;
request->crc = razer_calculate_crc(request);
mutex_lock(&device->lock);
err = razer_get_report(device->usb_dev, request, response);
mutex_unlock(&device->lock);
if (err) {
print_erroneous_report(response, "razermouse", "Invalid Report Length");
return err;
}
/* Check the packet number, class and command are the same */
if (response->remaining_packets != request->remaining_packets ||
response->command_class != request->command_class ||
response->command_id.id != request->command_id.id) {
print_erroneous_report(response, "razermouse", "Response doesn't match request");
return -EIO;
}
switch (response->status) {
case RAZER_CMD_BUSY:
// TODO: Check if this should be an error.
// print_erroneous_report(&response, "razermouse", "Device is busy");
break;
case RAZER_CMD_FAILURE:
print_erroneous_report(response, "razermouse", "Command failed");
return -EIO;
case RAZER_CMD_NOT_SUPPORTED:
print_erroneous_report(response, "razermouse", "Command not supported");
return -EIO;
case RAZER_CMD_TIMEOUT:
print_erroneous_report(response, "razermouse", "Command timed out");
return -EIO;
}
return 0;
}
/*
* Specific functions for ancient devices
*
*/
static int deathadder3_5g_set_led_state(struct razer_mouse_device *device, unsigned char led_id, bool enabled)
{
switch (led_id) {
case SCROLL_WHEEL_LED:
if (enabled) {
device->da3_5g.leds |= 0x02;
} else {
device->da3_5g.leds &= ~(0x02);
}
break;
case LOGO_LED:
if (enabled) {
device->da3_5g.leds |= 0x01;
} else {
device->da3_5g.leds &= ~(0x01);
}
break;
default:
printk(KERN_WARNING "razermouse: Invalid led_id on DeathAdder 3.5G\n");
return -EINVAL;
}
mutex_lock(&device->lock);
razer_send_control_msg_old_device(device->usb_dev, &device->da3_5g, 0x10, 0x00, 4, 3000, 3000);
mutex_unlock(&device->lock);
return 0;
}
static void deathadder3_5g_set_poll_rate(struct razer_mouse_device *device, unsigned short poll_rate)
{
switch(poll_rate) {
case 1000:
device->da3_5g.poll = 1;
break;
case 500:
device->da3_5g.poll = 2;
break;
case 125:
device->da3_5g.poll = 3;
break;
default: // 500
device->da3_5g.poll = 2;
break;
}
mutex_lock(&device->lock);
razer_send_control_msg_old_device(device->usb_dev, &device->da3_5g, 0x10, 0x00, 4, 3000, 3000);
mutex_unlock(&device->lock);
}
static void deathadder3_5g_set_dpi(struct razer_mouse_device *device, unsigned short dpi)
{
switch(dpi) {
case 450:
device->da3_5g.dpi = 4;
break;
case 900:
device->da3_5g.dpi = 3;
break;
case 1800:
device->da3_5g.dpi = 2;
break;
case 3500:
default:
device->da3_5g.dpi = 1;
break;
}
mutex_lock(&device->lock);
razer_send_control_msg_old_device(device->usb_dev, &device->da3_5g, 0x10, 0x00, 4, 3000, 3000);
mutex_unlock(&device->lock);
}
static int orochi_2011_set_led_state(struct razer_mouse_device *device, unsigned char led_id, bool enabled)
{
switch (led_id) {
case SCROLL_WHEEL_LED:
if (enabled) {
device->orochi2011.led |= 0b00000001;
} else {
device->orochi2011.led &= 0b11111110;
}
break;
case LOGO_LED:
if (enabled) {
device->orochi2011.led |= 0b00000010;
} else {
device->orochi2011.led &= 0b11111101;
}
break;
default:
printk(KERN_WARNING "razermouse: Invalid led_id on Orochi 2011\n");
return -EINVAL;
}
return 0;
}
/*
* New functions
*/
/**
* Read device file "version"
*
* Returns a string
*/
static ssize_t razer_attr_read_version(struct device *dev, struct device_attribute *attr, char *buf)
{
return sprintf(buf, "%s\n", DRIVER_VERSION);
}
/**
* Read device file "device_type"
*
* Returns friendly string of device type
*/
static ssize_t razer_attr_read_device_type(struct device *dev, struct device_attribute *attr, char *buf)
{
struct razer_mouse_device *device = dev_get_drvdata(dev);
char *device_type;
switch (device->usb_pid) {
case USB_DEVICE_ID_RAZER_DEATHADDER_3_5G:
device_type = "Razer DeathAdder 3.5G\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_3_5G_BLACK:
device_type = "Razer DeathAdder 3.5G Black\n";
break;
case USB_DEVICE_ID_RAZER_MAMBA_2012_WIRED:
device_type = "Razer Mamba 2012 (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_MAMBA_2012_WIRELESS:
device_type = "Razer Mamba 2012 (Wireless)\n";
break;
case USB_DEVICE_ID_RAZER_MAMBA_WIRED:
device_type = "Razer Mamba (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_MAMBA_WIRELESS:
device_type = "Razer Mamba (Wireless)\n";
break;
case USB_DEVICE_ID_RAZER_MAMBA_TE_WIRED:
device_type = "Razer Mamba Tournament Edition\n";
break;
case USB_DEVICE_ID_RAZER_ABYSSUS:
device_type = "Razer Abyssus 2014\n";
break;
case USB_DEVICE_ID_RAZER_ABYSSUS_1800:
device_type = "Razer Abyssus 1800\n";
break;
case USB_DEVICE_ID_RAZER_ABYSSUS_2000:
device_type = "Razer Abyssus 2000\n";
break;
case USB_DEVICE_ID_RAZER_IMPERATOR:
device_type = "Razer Imperator 2012\n";
break;
case USB_DEVICE_ID_RAZER_OUROBOROS:
device_type = "Razer Ouroboros\n";
break;
case USB_DEVICE_ID_RAZER_OROCHI_2011:
device_type = "Razer Orochi 2011\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_2013:
device_type = "Razer DeathAdder 2013\n";
break;
case USB_DEVICE_ID_RAZER_OROCHI_2013:
device_type = "Razer Orochi 2013\n";
break;
case USB_DEVICE_ID_RAZER_OROCHI_CHROMA:
device_type = "Razer Orochi (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_CHROMA:
device_type = "Razer DeathAdder Chroma\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_HEX_RED:
device_type = "Razer Naga Hex (Red)\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_HEX:
device_type = "Razer Naga Hex\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_2012:
device_type = "Razer Naga 2012\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_2014:
device_type = "Razer Naga 2014\n";
break;
case USB_DEVICE_ID_RAZER_TAIPAN:
device_type = "Razer Taipan\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_HEX_V2:
device_type = "Razer Naga Hex V2\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_CHROMA:
device_type = "Razer Naga Chroma\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_X:
device_type = "Razer Naga X\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_ELITE:
device_type = "Razer DeathAdder Elite\n";
break;
case USB_DEVICE_ID_RAZER_ABYSSUS_V2:
device_type = "Razer Abyssus V2\n";
break;
case USB_DEVICE_ID_RAZER_DIAMONDBACK_CHROMA:
device_type = "Razer Diamondback Chroma\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_3500:
device_type = "Razer DeathAdder 3500\n";
break;
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRED:
device_type = "Razer Lancehead (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRELESS:
device_type = "Razer Lancehead (Wireless)\n";
break;
case USB_DEVICE_ID_RAZER_LANCEHEAD_TE_WIRED:
device_type = "Razer Lancehead Tournament Edition\n";
break;
case USB_DEVICE_ID_RAZER_MAMBA_ELITE:
device_type = "Razer Mamba Elite\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_ESSENTIAL:
device_type = "Razer DeathAdder Essential\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_ESSENTIAL_2021:
device_type = "Razer DeathAdder Essential (2021)\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_TRINITY:
device_type = "Razer Naga Trinity\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_1800:
device_type = "Razer DeathAdder 1800\n";
break;
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRELESS_RECEIVER:
device_type = "Razer Lancehead Wireless (Receiver)\n";
break;
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRELESS_WIRED:
device_type = "Razer Lancehead Wireless (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_MAMBA_WIRELESS_RECEIVER:
device_type = "Razer Mamba Wireless (Receiver)\n";
break;
case USB_DEVICE_ID_RAZER_MAMBA_WIRELESS_WIRED:
device_type = "Razer Mamba Wireless (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_ABYSSUS_ELITE_DVA_EDITION:
device_type = "Razer Abyssus Elite (D.Va Edition)\n";
break;
case USB_DEVICE_ID_RAZER_ABYSSUS_ESSENTIAL:
device_type = "Razer Abyssus Essential\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_ESSENTIAL_WHITE_EDITION:
device_type = "Razer DeathAdder Essential (White Edition)\n";
break;
case USB_DEVICE_ID_RAZER_VIPER:
device_type = "Razer Viper\n";
break;
case USB_DEVICE_ID_RAZER_VIPER_MINI:
device_type = "Razer Viper Mini\n";
break;
case USB_DEVICE_ID_RAZER_VIPER_MINI_SE_WIRED:
device_type = "Razer Viper Mini Signature Edition (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_VIPER_MINI_SE_WIRELESS:
device_type = "Razer Viper Mini Signature Edition (Wireless)\n";
break;
case USB_DEVICE_ID_RAZER_VIPER_ULTIMATE_WIRED:
device_type = "Razer Viper Ultimate (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_VIPER_ULTIMATE_WIRELESS:
device_type = "Razer Viper Ultimate (Wireless)\n";
break;
case USB_DEVICE_ID_RAZER_VIPER_V2_PRO_WIRED:
device_type = "Razer Viper V2 Pro (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_VIPER_V2_PRO_WIRELESS:
device_type = "Razer Viper V2 Pro (Wireless)\n";
break;
case USB_DEVICE_ID_RAZER_BASILISK:
device_type = "Razer Basilisk\n";
break;
case USB_DEVICE_ID_RAZER_BASILISK_ESSENTIAL:
device_type = "Razer Basilisk Essential\n";
break;
case USB_DEVICE_ID_RAZER_BASILISK_ULTIMATE_WIRED:
device_type = "Razer Basilisk Ultimate (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_BASILISK_ULTIMATE_RECEIVER:
device_type = "Razer Basilisk Ultimate (Receiver)\n";
break;
case USB_DEVICE_ID_RAZER_BASILISK_V2:
device_type = "Razer Basilisk V2\n";
break;
case USB_DEVICE_ID_RAZER_BASILISK_V3:
device_type = "Razer Basilisk V3\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_V2:
device_type = "Razer DeathAdder V2\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_PRO_WIRED:
device_type = "Razer DeathAdder V2 Pro (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_PRO_WIRELESS:
device_type = "Razer DeathAdder V2 Pro (Wireless)\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_V3:
device_type = "Razer DeathAdder V3\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_V3_PRO_WIRED:
device_type = "Razer DeathAdder V3 Pro (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_V3_PRO_WIRELESS:
device_type = "Razer DeathAdder V3 Pro (Wireless)\n";
break;
case USB_DEVICE_ID_RAZER_HYPERPOLLING_WIRELESS_DONGLE:
device_type = "Razer HyperPolling Wireless Dongle\n";
break;
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRED:
device_type = "Razer Basilisk V3 Pro (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRELESS:
device_type = "Razer Basilisk V3 Pro (Wireless)\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_MINI:
device_type = "Razer DeathAdder V2 Mini\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_2000:
device_type = "Razer DeathAdder 2000\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_X_HYPERSPEED:
device_type = "Razer DeathAdder V2 X HyperSpeed\n";
break;
case USB_DEVICE_ID_RAZER_ATHERIS_RECEIVER:
device_type = "Razer Atheris (Receiver)\n";
break;
case USB_DEVICE_ID_RAZER_BASILISK_X_HYPERSPEED:
device_type = "Razer Basilisk X HyperSpeed\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_LEFT_HANDED_2020:
device_type = "Razer Naga Left-Handed Edition 2020\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRED:
device_type = "Razer Naga Pro (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRELESS:
device_type = "Razer Naga Pro (Wireless)\n";
break;
case USB_DEVICE_ID_RAZER_VIPER_8K:
device_type = "Razer Viper 8KHz\n";
break;
case USB_DEVICE_ID_RAZER_OROCHI_V2_RECEIVER:
device_type = "Razer Orochi V2 (Receiver)\n";
break;
case USB_DEVICE_ID_RAZER_OROCHI_V2_BLUETOOTH:
device_type = "Razer Orochi V2 (Bluetooth)\n";
break;
case USB_DEVICE_ID_RAZER_PRO_CLICK_RECEIVER:
device_type = "Razer Pro Click (Receiver)\n";
break;
case USB_DEVICE_ID_RAZER_PRO_CLICK_WIRED:
device_type = "Razer Pro Click (Wired)\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_EPIC_CHROMA:
device_type = "Razer Naga Epic Chroma\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_EPIC_CHROMA_DOCK:
device_type = "Razer Naga Epic Chroma Dock\n";
break;
case USB_DEVICE_ID_RAZER_PRO_CLICK_MINI_RECEIVER:
device_type = "Razer Pro Click Mini (Receiver)\n";
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_LITE:
device_type = "Razer DeathAdder V2 Lite\n";
break;
case USB_DEVICE_ID_RAZER_COBRA_PRO:
device_type = "Razer Cobra Pro\n";
break;
case USB_DEVICE_ID_RAZER_VIPER_V3_HYPERSPEED:
device_type = "Razer Viper V3 HyperSpeed\n";
break;
case USB_DEVICE_ID_RAZER_NAGA_V2_HYPERSPEED_RECEIVER:
device_type = "Razer Naga V2 HyperSpeed (Receiver)\n";
break;
default:
device_type = "Unknown Device\n";
}
return sprintf(buf, device_type);
}
/**
* Read device file "get_firmware_version"
*
* Returns a string
*/
static ssize_t razer_attr_read_firmware_version(struct device *dev, struct device_attribute *attr, char *buf)
{
struct razer_mouse_device *device = dev_get_drvdata(dev);
struct razer_report request = {0};
struct razer_report response = {0};
request = razer_chroma_standard_get_firmware_version();
switch(device->usb_pid) {
case USB_DEVICE_ID_RAZER_OROCHI_2011: // Orochi 2011 doesn't have FW
return sprintf(buf, "v%d.%d\n", 9, 99);
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_3_5G: // DA don't think supports fw, its proper old
case USB_DEVICE_ID_RAZER_DEATHADDER_3_5G_BLACK:
return sprintf(buf, "v%d.%d\n", 0x01, 0x00);
break;
case USB_DEVICE_ID_RAZER_NAGA_X:
case USB_DEVICE_ID_RAZER_NAGA_LEFT_HANDED_2020:
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRED:
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_MAMBA_ELITE:
case USB_DEVICE_ID_RAZER_ATHERIS_RECEIVER:
case USB_DEVICE_ID_RAZER_BASILISK_ULTIMATE_RECEIVER:
case USB_DEVICE_ID_RAZER_BASILISK_ULTIMATE_WIRED:
case USB_DEVICE_ID_RAZER_BASILISK_V2:
case USB_DEVICE_ID_RAZER_OROCHI_V2_RECEIVER:
case USB_DEVICE_ID_RAZER_OROCHI_V2_BLUETOOTH:
case USB_DEVICE_ID_RAZER_BASILISK_V3:
case USB_DEVICE_ID_RAZER_PRO_CLICK_RECEIVER:
case USB_DEVICE_ID_RAZER_PRO_CLICK_WIRED:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_X_HYPERSPEED:
case USB_DEVICE_ID_RAZER_VIPER_V2_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_VIPER_V2_PRO_WIRED:
case USB_DEVICE_ID_RAZER_COBRA_PRO:
case USB_DEVICE_ID_RAZER_DEATHADDER_V3:
case USB_DEVICE_ID_RAZER_VIPER_MINI_SE_WIRED:
case USB_DEVICE_ID_RAZER_VIPER_MINI_SE_WIRELESS:
case USB_DEVICE_ID_RAZER_DEATHADDER_V3_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_DEATHADDER_V3_PRO_WIRED:
case USB_DEVICE_ID_RAZER_HYPERPOLLING_WIRELESS_DONGLE:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRED:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_PRO_CLICK_MINI_RECEIVER:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_LITE:
case USB_DEVICE_ID_RAZER_NAGA_V2_HYPERSPEED_RECEIVER:
case USB_DEVICE_ID_RAZER_VIPER_V3_HYPERSPEED:
request.transaction_id.id = 0x1f;
break;
case USB_DEVICE_ID_RAZER_NAGA_HEX_V2:
case USB_DEVICE_ID_RAZER_DEATHADDER_ELITE:
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRED:
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRELESS:
case USB_DEVICE_ID_RAZER_LANCEHEAD_TE_WIRED:
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRELESS_RECEIVER:
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRELESS_WIRED:
case USB_DEVICE_ID_RAZER_MAMBA_WIRELESS_RECEIVER:
case USB_DEVICE_ID_RAZER_MAMBA_WIRELESS_WIRED:
case USB_DEVICE_ID_RAZER_BASILISK:
case USB_DEVICE_ID_RAZER_BASILISK_ESSENTIAL:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_PRO_WIRED:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_MINI:
request.transaction_id.id = 0x3f;
break;
default:
request.transaction_id.id = 0xFF;
break;
}
razer_send_payload(device, &request, &response);
return sprintf(buf, "v%d.%d\n", response.arguments[0], response.arguments[1]);
}
/**
* Write device file "test"
*
* Writes the colour segments on the mouse.
*/
static ssize_t razer_attr_write_test(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct razer_mouse_device *device = dev_get_drvdata(dev);
unsigned char enabled = (unsigned char)simple_strtoul(buf, NULL, 10);
struct razer_report request = {0};
struct razer_report response = {0};
request = razer_chroma_standard_set_led_state(VARSTORE, LOGO_LED, enabled);
request.transaction_id.id = 0xFF;
razer_send_payload(device, &request, &response);
return count;
}
/**
* Write device file "mode_none"
*
* No effect is activated whenever this file is written to
*/
static ssize_t razer_attr_write_matrix_effect_none(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct razer_mouse_device *device = dev_get_drvdata(dev);
struct razer_report request = {0};
struct razer_report response = {0};
switch (device->usb_pid) {
case USB_DEVICE_ID_RAZER_BASILISK_V3:
case USB_DEVICE_ID_RAZER_COBRA_PRO:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRED:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRELESS:
request = razer_chroma_extended_matrix_effect_none(VARSTORE, ZERO_LED);
request.transaction_id.id = 0x1f;
break;
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRELESS: // TODO: this is probably wrong?
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRED: // TODO: this is probably wrong?
request = razer_chroma_standard_matrix_effect_none();
request.transaction_id.id = 0xFF;
break;
default:
printk(KERN_WARNING "razermouse: matrix_effect_none not supported for this model\n");
return -EINVAL;
}
razer_send_payload(device, &request, &response);
return count;
}
/**
* Write device file "mode_custom"
*
* Sets the mouse to custom mode whenever the file is written to
*/
static ssize_t razer_attr_write_matrix_effect_custom(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct razer_mouse_device *device = dev_get_drvdata(dev);
struct razer_report request = {0};
struct razer_report response = {0};
switch (device->usb_pid) {
case USB_DEVICE_ID_RAZER_NAGA_HEX_V2: // TODO look into this think its extended effects
request = razer_chroma_standard_matrix_effect_custom_frame(NOSTORE);
request.transaction_id.id = 0x3f;
break;
case USB_DEVICE_ID_RAZER_DEATHADDER_ELITE:
case USB_DEVICE_ID_RAZER_NAGA_CHROMA:
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRED:
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRELESS:
case USB_DEVICE_ID_RAZER_LANCEHEAD_TE_WIRED:
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRELESS_RECEIVER:
case USB_DEVICE_ID_RAZER_LANCEHEAD_WIRELESS_WIRED:
case USB_DEVICE_ID_RAZER_MAMBA_WIRELESS_RECEIVER:
case USB_DEVICE_ID_RAZER_MAMBA_WIRELESS_WIRED:
case USB_DEVICE_ID_RAZER_BASILISK:
case USB_DEVICE_ID_RAZER_BASILISK_ESSENTIAL:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_PRO_WIRED:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_MINI:
case USB_DEVICE_ID_RAZER_VIPER:
case USB_DEVICE_ID_RAZER_VIPER_MINI:
case USB_DEVICE_ID_RAZER_VIPER_ULTIMATE_WIRED:
case USB_DEVICE_ID_RAZER_VIPER_ULTIMATE_WIRELESS:
request = razer_chroma_extended_matrix_effect_custom_frame();
request.transaction_id.id = 0x3F;
break;
case USB_DEVICE_ID_RAZER_NAGA_X:
case USB_DEVICE_ID_RAZER_NAGA_LEFT_HANDED_2020:
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRED:
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_MAMBA_ELITE:
case USB_DEVICE_ID_RAZER_BASILISK_ULTIMATE_RECEIVER:
case USB_DEVICE_ID_RAZER_BASILISK_ULTIMATE_WIRED:
case USB_DEVICE_ID_RAZER_BASILISK_V2:
case USB_DEVICE_ID_RAZER_BASILISK_V3:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRED:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_DEATHADDER_V2_LITE:
request = razer_chroma_extended_matrix_effect_custom_frame();
request.transaction_id.id = 0x1f;
break;
case USB_DEVICE_ID_RAZER_MAMBA_WIRELESS:
request = razer_chroma_standard_matrix_effect_custom_frame(NOSTORE);
request.transaction_id.id = 0x80;
break;
default:
request = razer_chroma_standard_matrix_effect_custom_frame(NOSTORE);
request.transaction_id.id = 0xFF;
break;
}
razer_send_payload(device, &request, &response);
return count;
}
/**
* Write device file "mode_static"
*
* Set the mouse to static mode when 3 RGB bytes are written
*/
static ssize_t razer_attr_write_matrix_effect_static(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct razer_mouse_device *device = dev_get_drvdata(dev);
struct razer_report request = {0};
struct razer_report response = {0};
if (count != 3) {
printk(KERN_WARNING "razermouse: Static mode only accepts RGB (3byte)\n");
return -EINVAL;
}
switch (device->usb_pid) {
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRED:
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRELESS:
case USB_DEVICE_ID_RAZER_NAGA_TRINITY:
// Some sort of mode switcher required after initialization and before color switching
request = get_razer_report(0x0f, 0x02, 0x06);
request.arguments[0] = 0x00;
request.arguments[1] = 0x00;
request.arguments[2] = 0x08;
request.arguments[3] = 0x00;
request.arguments[4] = 0x00;
request.arguments[5] = 0x00;
request.transaction_id.id = 0x1f;
razer_send_payload(device, &request, &response);
request = razer_naga_trinity_effect_static((struct razer_rgb*)&buf[0]);
request.transaction_id.id = 0x1f;
break;
case USB_DEVICE_ID_RAZER_BASILISK_V3:
case USB_DEVICE_ID_RAZER_COBRA_PRO:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRED:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRELESS:
request = razer_chroma_extended_matrix_effect_static(VARSTORE, ZERO_LED, (struct razer_rgb*)&buf[0]);
request.transaction_id.id = 0x1f;
break;
default:
printk(KERN_WARNING "razermouse: matrix_effect_static not supported for this model\n");
return -EINVAL;
}
razer_send_payload(device, &request, &response);
return count;
}
/**
* Write device file "mode_wave"
*
* When 1 is written (as a character, 0x31) the wave effect is displayed moving up the mouse
* if 2 is written (0x32) then the wave effect goes down
*/
static ssize_t razer_attr_write_matrix_effect_wave(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct razer_mouse_device *device = dev_get_drvdata(dev);
unsigned char direction = (unsigned char)simple_strtoul(buf, NULL, 10);
struct razer_report request = {0};
struct razer_report response = {0};
switch (device->usb_pid) {
case USB_DEVICE_ID_RAZER_BASILISK_V3:
case USB_DEVICE_ID_RAZER_COBRA_PRO:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRED:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRELESS:
request = razer_chroma_extended_matrix_effect_wave(VARSTORE, ZERO_LED, direction);
request.transaction_id.id = 0x1f;
break;
default:
printk(KERN_WARNING "razermouse: matrix_effect_wave not supported for this model\n");
return -EINVAL;
}
razer_send_payload(device, &request, &response);
return count;
}
/**
* Write device file "mode_spectrum"
*
* Spectrum effect mode is activated whenever the file is written to
*/
static ssize_t razer_attr_write_matrix_effect_spectrum(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct razer_mouse_device *device = dev_get_drvdata(dev);
struct razer_report request = {0};
struct razer_report response = {0};
switch (device->usb_pid) {
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRED:
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRELESS:
request = razer_chroma_mouse_extended_matrix_effect_spectrum(VARSTORE, BACKLIGHT_LED);
request.transaction_id.id = 0x1f;
break;
case USB_DEVICE_ID_RAZER_BASILISK_V3:
case USB_DEVICE_ID_RAZER_COBRA_PRO:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRED:
case USB_DEVICE_ID_RAZER_BASILISK_V3_PRO_WIRELESS:
request = razer_chroma_extended_matrix_effect_spectrum(VARSTORE, ZERO_LED);
request.transaction_id.id = 0x1f;
break;
default:
printk(KERN_WARNING "razermouse: matrix_effect_spectrum not supported for this model\n");
return -EINVAL;
}
razer_send_payload(device, &request, &response);
return count;
}
/**
* Write device file "mode_reactive"
*
* Sets reactive mode when this file is written to. A speed byte and 3 RGB bytes should be written
*/
static ssize_t razer_attr_write_matrix_effect_reactive(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{
struct razer_mouse_device *device = dev_get_drvdata(dev);
struct razer_report request = {0};
struct razer_report response = {0};
unsigned char speed;
if (count != 4) {
printk(KERN_WARNING "razermouse: Reactive only accepts Speed, RGB (4byte)\n");
return -EINVAL;
}
speed = (unsigned char)buf[0];
switch (device->usb_pid) {
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRED:
case USB_DEVICE_ID_RAZER_NAGA_PRO_WIRELESS:
request = razer_chroma_mouse_extended_matrix_effect_reactive(VARSTORE, BACKLIGHT_LED, speed, (struct razer_rgb*)&buf[1]);
request.transaction_id.id = 0x1f;
break;
default:
printk(KERN_WARNING "razermouse: matrix_effect_reactive not supported for this model\n");
return -EINVAL;
}
razer_send_payload(device, &request, &response);
return count;
}
/**
* Write device file "mode_breath"
*
* Sets breathing mode by writing 1, 3 or 6 bytes
*/
static ssize_t razer_attr_write_matrix_effect_breath(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
{