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
|
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* This driver implements the WMI AB device found on TUXEDO notebooks with board
* vendor NB04.
*
* Copyright (C) 2024-2025 Werner Sembach <wse@tuxedocomputers.com>
*/
#include <linux/dmi.h>
#include <linux/hid.h>
#include <linux/minmax.h>
#include <linux/module.h>
#include <linux/wmi.h>
#include "wmi_util.h"
static const struct wmi_device_id tuxedo_nb04_wmi_ab_device_ids[] = {
{ .guid_string = "80C9BAA6-AC48-4538-9234-9F81A55E7C85" },
{ }
};
MODULE_DEVICE_TABLE(wmi, tuxedo_nb04_wmi_ab_device_ids);
enum {
LAMP_ARRAY_ATTRIBUTES_REPORT_ID = 0x01,
LAMP_ATTRIBUTES_REQUEST_REPORT_ID = 0x02,
LAMP_ATTRIBUTES_RESPONSE_REPORT_ID = 0x03,
LAMP_MULTI_UPDATE_REPORT_ID = 0x04,
LAMP_RANGE_UPDATE_REPORT_ID = 0x05,
LAMP_ARRAY_CONTROL_REPORT_ID = 0x06,
};
static u8 tux_report_descriptor[327] = {
0x05, 0x59, // Usage Page (Lighting and Illumination)
0x09, 0x01, // Usage (Lamp Array)
0xa1, 0x01, // Collection (Application)
0x85, LAMP_ARRAY_ATTRIBUTES_REPORT_ID, // Report ID (1)
0x09, 0x02, // Usage (Lamp Array Attributes Report)
0xa1, 0x02, // Collection (Logical)
0x09, 0x03, // Usage (Lamp Count)
0x15, 0x00, // Logical Minimum (0)
0x27, 0xff, 0xff, 0x00, 0x00, // Logical Maximum (65535)
0x75, 0x10, // Report Size (16)
0x95, 0x01, // Report Count (1)
0xb1, 0x03, // Feature (Cnst,Var,Abs)
0x09, 0x04, // Usage (Bounding Box Width In Micrometers)
0x09, 0x05, // Usage (Bounding Box Height In Micrometers)
0x09, 0x06, // Usage (Bounding Box Depth In Micrometers)
0x09, 0x07, // Usage (Lamp Array Kind)
0x09, 0x08, // Usage (Min Update Interval In Microseconds)
0x15, 0x00, // Logical Minimum (0)
0x27, 0xff, 0xff, 0xff, 0x7f, // Logical Maximum (2147483647)
0x75, 0x20, // Report Size (32)
0x95, 0x05, // Report Count (5)
0xb1, 0x03, // Feature (Cnst,Var,Abs)
0xc0, // End Collection
0x85, LAMP_ATTRIBUTES_REQUEST_REPORT_ID, // Report ID (2)
0x09, 0x20, // Usage (Lamp Attributes Request Report)
0xa1, 0x02, // Collection (Logical)
0x09, 0x21, // Usage (Lamp Id)
0x15, 0x00, // Logical Minimum (0)
0x27, 0xff, 0xff, 0x00, 0x00, // Logical Maximum (65535)
0x75, 0x10, // Report Size (16)
0x95, 0x01, // Report Count (1)
0xb1, 0x02, // Feature (Data,Var,Abs)
0xc0, // End Collection
0x85, LAMP_ATTRIBUTES_RESPONSE_REPORT_ID, // Report ID (3)
0x09, 0x22, // Usage (Lamp Attributes Response Report)
0xa1, 0x02, // Collection (Logical)
0x09, 0x21, // Usage (Lamp Id)
0x15, 0x00, // Logical Minimum (0)
0x27, 0xff, 0xff, 0x00, 0x00, // Logical Maximum (65535)
0x75, 0x10, // Report Size (16)
0x95, 0x01, // Report Count (1)
0xb1, 0x02, // Feature (Data,Var,Abs)
0x09, 0x23, // Usage (Position X In Micrometers)
0x09, 0x24, // Usage (Position Y In Micrometers)
0x09, 0x25, // Usage (Position Z In Micrometers)
0x09, 0x27, // Usage (Update Latency In Microseconds)
0x09, 0x26, // Usage (Lamp Purposes)
0x15, 0x00, // Logical Minimum (0)
0x27, 0xff, 0xff, 0xff, 0x7f, // Logical Maximum (2147483647)
0x75, 0x20, // Report Size (32)
0x95, 0x05, // Report Count (5)
0xb1, 0x02, // Feature (Data,Var,Abs)
0x09, 0x28, // Usage (Red Level Count)
0x09, 0x29, // Usage (Green Level Count)
0x09, 0x2a, // Usage (Blue Level Count)
0x09, 0x2b, // Usage (Intensity Level Count)
0x09, 0x2c, // Usage (Is Programmable)
0x09, 0x2d, // Usage (Input Binding)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xff, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x06, // Report Count (6)
0xb1, 0x02, // Feature (Data,Var,Abs)
0xc0, // End Collection
0x85, LAMP_MULTI_UPDATE_REPORT_ID, // Report ID (4)
0x09, 0x50, // Usage (Lamp Multi Update Report)
0xa1, 0x02, // Collection (Logical)
0x09, 0x03, // Usage (Lamp Count)
0x09, 0x55, // Usage (Lamp Update Flags)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x08, // Logical Maximum (8)
0x75, 0x08, // Report Size (8)
0x95, 0x02, // Report Count (2)
0xb1, 0x02, // Feature (Data,Var,Abs)
0x09, 0x21, // Usage (Lamp Id)
0x15, 0x00, // Logical Minimum (0)
0x27, 0xff, 0xff, 0x00, 0x00, // Logical Maximum (65535)
0x75, 0x10, // Report Size (16)
0x95, 0x08, // Report Count (8)
0xb1, 0x02, // Feature (Data,Var,Abs)
0x09, 0x51, // Usage (Red Update Channel)
0x09, 0x52, // Usage (Green Update Channel)
0x09, 0x53, // Usage (Blue Update Channel)
0x09, 0x54, // Usage (Intensity Update Channel)
0x09, 0x51, // Usage (Red Update Channel)
0x09, 0x52, // Usage (Green Update Channel)
0x09, 0x53, // Usage (Blue Update Channel)
0x09, 0x54, // Usage (Intensity Update Channel)
0x09, 0x51, // Usage (Red Update Channel)
0x09, 0x52, // Usage (Green Update Channel)
0x09, 0x53, // Usage (Blue Update Channel)
0x09, 0x54, // Usage (Intensity Update Channel)
0x09, 0x51, // Usage (Red Update Channel)
0x09, 0x52, // Usage (Green Update Channel)
0x09, 0x53, // Usage (Blue Update Channel)
0x09, 0x54, // Usage (Intensity Update Channel)
0x09, 0x51, // Usage (Red Update Channel)
0x09, 0x52, // Usage (Green Update Channel)
0x09, 0x53, // Usage (Blue Update Channel)
0x09, 0x54, // Usage (Intensity Update Channel)
0x09, 0x51, // Usage (Red Update Channel)
0x09, 0x52, // Usage (Green Update Channel)
0x09, 0x53, // Usage (Blue Update Channel)
0x09, 0x54, // Usage (Intensity Update Channel)
0x09, 0x51, // Usage (Red Update Channel)
0x09, 0x52, // Usage (Green Update Channel)
0x09, 0x53, // Usage (Blue Update Channel)
0x09, 0x54, // Usage (Intensity Update Channel)
0x09, 0x51, // Usage (Red Update Channel)
0x09, 0x52, // Usage (Green Update Channel)
0x09, 0x53, // Usage (Blue Update Channel)
0x09, 0x54, // Usage (Intensity Update Channel)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xff, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x20, // Report Count (32)
0xb1, 0x02, // Feature (Data,Var,Abs)
0xc0, // End Collection
0x85, LAMP_RANGE_UPDATE_REPORT_ID, // Report ID (5)
0x09, 0x60, // Usage (Lamp Range Update Report)
0xa1, 0x02, // Collection (Logical)
0x09, 0x55, // Usage (Lamp Update Flags)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x08, // Logical Maximum (8)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0xb1, 0x02, // Feature (Data,Var,Abs)
0x09, 0x61, // Usage (Lamp Id Start)
0x09, 0x62, // Usage (Lamp Id End)
0x15, 0x00, // Logical Minimum (0)
0x27, 0xff, 0xff, 0x00, 0x00, // Logical Maximum (65535)
0x75, 0x10, // Report Size (16)
0x95, 0x02, // Report Count (2)
0xb1, 0x02, // Feature (Data,Var,Abs)
0x09, 0x51, // Usage (Red Update Channel)
0x09, 0x52, // Usage (Green Update Channel)
0x09, 0x53, // Usage (Blue Update Channel)
0x09, 0x54, // Usage (Intensity Update Channel)
0x15, 0x00, // Logical Minimum (0)
0x26, 0xff, 0x00, // Logical Maximum (255)
0x75, 0x08, // Report Size (8)
0x95, 0x04, // Report Count (4)
0xb1, 0x02, // Feature (Data,Var,Abs)
0xc0, // End Collection
0x85, LAMP_ARRAY_CONTROL_REPORT_ID, // Report ID (6)
0x09, 0x70, // Usage (Lamp Array Control Report)
0xa1, 0x02, // Collection (Logical)
0x09, 0x71, // Usage (Autonomous Mode)
0x15, 0x00, // Logical Minimum (0)
0x25, 0x01, // Logical Maximum (1)
0x75, 0x08, // Report Size (8)
0x95, 0x01, // Report Count (1)
0xb1, 0x02, // Feature (Data,Var,Abs)
0xc0, // End Collection
0xc0 // End Collection
};
struct tux_kbl_map_entry_t {
u8 code;
struct {
u32 x;
u32 y;
u32 z;
} pos;
};
static const struct tux_kbl_map_entry_t sirius_16_ansii_kbl_map[] = {
{ 0x29, { 25000, 53000, 5000 } },
{ 0x3a, { 41700, 53000, 5000 } },
{ 0x3b, { 58400, 53000, 5000 } },
{ 0x3c, { 75100, 53000, 5000 } },
{ 0x3d, { 91800, 53000, 5000 } },
{ 0x3e, { 108500, 53000, 5000 } },
{ 0x3f, { 125200, 53000, 5000 } },
{ 0x40, { 141900, 53000, 5000 } },
{ 0x41, { 158600, 53000, 5000 } },
{ 0x42, { 175300, 53000, 5000 } },
{ 0x43, { 192000, 53000, 5000 } },
{ 0x44, { 208700, 53000, 5000 } },
{ 0x45, { 225400, 53000, 5000 } },
{ 0xf1, { 242100, 53000, 5000 } },
{ 0x46, { 258800, 53000, 5000 } },
{ 0x4c, { 275500, 53000, 5000 } },
{ 0x4a, { 294500, 53000, 5000 } },
{ 0x4d, { 311200, 53000, 5000 } },
{ 0x4b, { 327900, 53000, 5000 } },
{ 0x4e, { 344600, 53000, 5000 } },
{ 0x35, { 24500, 67500, 5250 } },
{ 0x1e, { 42500, 67500, 5250 } },
{ 0x1f, { 61000, 67500, 5250 } },
{ 0x20, { 79500, 67500, 5250 } },
{ 0x21, { 98000, 67500, 5250 } },
{ 0x22, { 116500, 67500, 5250 } },
{ 0x23, { 135000, 67500, 5250 } },
{ 0x24, { 153500, 67500, 5250 } },
{ 0x25, { 172000, 67500, 5250 } },
{ 0x26, { 190500, 67500, 5250 } },
{ 0x27, { 209000, 67500, 5250 } },
{ 0x2d, { 227500, 67500, 5250 } },
{ 0x2e, { 246000, 67500, 5250 } },
{ 0x2a, { 269500, 67500, 5250 } },
{ 0x53, { 294500, 67500, 5250 } },
{ 0x55, { 311200, 67500, 5250 } },
{ 0x54, { 327900, 67500, 5250 } },
{ 0x56, { 344600, 67500, 5250 } },
{ 0x2b, { 31000, 85500, 5500 } },
{ 0x14, { 51500, 85500, 5500 } },
{ 0x1a, { 70000, 85500, 5500 } },
{ 0x08, { 88500, 85500, 5500 } },
{ 0x15, { 107000, 85500, 5500 } },
{ 0x17, { 125500, 85500, 5500 } },
{ 0x1c, { 144000, 85500, 5500 } },
{ 0x18, { 162500, 85500, 5500 } },
{ 0x0c, { 181000, 85500, 5500 } },
{ 0x12, { 199500, 85500, 5500 } },
{ 0x13, { 218000, 85500, 5500 } },
{ 0x2f, { 236500, 85500, 5500 } },
{ 0x30, { 255000, 85500, 5500 } },
{ 0x31, { 273500, 85500, 5500 } },
{ 0x5f, { 294500, 85500, 5500 } },
{ 0x60, { 311200, 85500, 5500 } },
{ 0x61, { 327900, 85500, 5500 } },
{ 0x39, { 33000, 103500, 5750 } },
{ 0x04, { 57000, 103500, 5750 } },
{ 0x16, { 75500, 103500, 5750 } },
{ 0x07, { 94000, 103500, 5750 } },
{ 0x09, { 112500, 103500, 5750 } },
{ 0x0a, { 131000, 103500, 5750 } },
{ 0x0b, { 149500, 103500, 5750 } },
{ 0x0d, { 168000, 103500, 5750 } },
{ 0x0e, { 186500, 103500, 5750 } },
{ 0x0f, { 205000, 103500, 5750 } },
{ 0x33, { 223500, 103500, 5750 } },
{ 0x34, { 242000, 103500, 5750 } },
{ 0x28, { 267500, 103500, 5750 } },
{ 0x5c, { 294500, 103500, 5750 } },
{ 0x5d, { 311200, 103500, 5750 } },
{ 0x5e, { 327900, 103500, 5750 } },
{ 0x57, { 344600, 94500, 5625 } },
{ 0xe1, { 37000, 121500, 6000 } },
{ 0x1d, { 66000, 121500, 6000 } },
{ 0x1b, { 84500, 121500, 6000 } },
{ 0x06, { 103000, 121500, 6000 } },
{ 0x19, { 121500, 121500, 6000 } },
{ 0x05, { 140000, 121500, 6000 } },
{ 0x11, { 158500, 121500, 6000 } },
{ 0x10, { 177000, 121500, 6000 } },
{ 0x36, { 195500, 121500, 6000 } },
{ 0x37, { 214000, 121500, 6000 } },
{ 0x38, { 232500, 121500, 6000 } },
{ 0xe5, { 251500, 121500, 6000 } },
{ 0x52, { 273500, 129000, 6125 } },
{ 0x59, { 294500, 121500, 6000 } },
{ 0x5a, { 311200, 121500, 6000 } },
{ 0x5b, { 327900, 121500, 6000 } },
{ 0xe0, { 28000, 139500, 6250 } },
{ 0xfe, { 47500, 139500, 6250 } },
{ 0xe3, { 66000, 139500, 6250 } },
{ 0xe2, { 84500, 139500, 6250 } },
{ 0x2c, { 140000, 139500, 6250 } },
{ 0xe6, { 195500, 139500, 6250 } },
{ 0x65, { 214000, 139500, 6250 } },
{ 0xe4, { 234000, 139500, 6250 } },
{ 0x50, { 255000, 147000, 6375 } },
{ 0x51, { 273500, 147000, 6375 } },
{ 0x4f, { 292000, 147000, 6375 } },
{ 0x62, { 311200, 139500, 6250 } },
{ 0x63, { 327900, 139500, 6250 } },
{ 0x58, { 344600, 130500, 6125 } },
};
static const struct tux_kbl_map_entry_t sirius_16_iso_kbl_map[] = {
{ 0x29, { 25000, 53000, 5000 } },
{ 0x3a, { 41700, 53000, 5000 } },
{ 0x3b, { 58400, 53000, 5000 } },
{ 0x3c, { 75100, 53000, 5000 } },
{ 0x3d, { 91800, 53000, 5000 } },
{ 0x3e, { 108500, 53000, 5000 } },
{ 0x3f, { 125200, 53000, 5000 } },
{ 0x40, { 141900, 53000, 5000 } },
{ 0x41, { 158600, 53000, 5000 } },
{ 0x42, { 175300, 53000, 5000 } },
{ 0x43, { 192000, 53000, 5000 } },
{ 0x44, { 208700, 53000, 5000 } },
{ 0x45, { 225400, 53000, 5000 } },
{ 0xf1, { 242100, 53000, 5000 } },
{ 0x46, { 258800, 53000, 5000 } },
{ 0x4c, { 275500, 53000, 5000 } },
{ 0x4a, { 294500, 53000, 5000 } },
{ 0x4d, { 311200, 53000, 5000 } },
{ 0x4b, { 327900, 53000, 5000 } },
{ 0x4e, { 344600, 53000, 5000 } },
{ 0x35, { 24500, 67500, 5250 } },
{ 0x1e, { 42500, 67500, 5250 } },
{ 0x1f, { 61000, 67500, 5250 } },
{ 0x20, { 79500, 67500, 5250 } },
{ 0x21, { 98000, 67500, 5250 } },
{ 0x22, { 116500, 67500, 5250 } },
{ 0x23, { 135000, 67500, 5250 } },
{ 0x24, { 153500, 67500, 5250 } },
{ 0x25, { 172000, 67500, 5250 } },
{ 0x26, { 190500, 67500, 5250 } },
{ 0x27, { 209000, 67500, 5250 } },
{ 0x2d, { 227500, 67500, 5250 } },
{ 0x2e, { 246000, 67500, 5250 } },
{ 0x2a, { 269500, 67500, 5250 } },
{ 0x53, { 294500, 67500, 5250 } },
{ 0x55, { 311200, 67500, 5250 } },
{ 0x54, { 327900, 67500, 5250 } },
{ 0x56, { 344600, 67500, 5250 } },
{ 0x2b, { 31000, 85500, 5500 } },
{ 0x14, { 51500, 85500, 5500 } },
{ 0x1a, { 70000, 85500, 5500 } },
{ 0x08, { 88500, 85500, 5500 } },
{ 0x15, { 107000, 85500, 5500 } },
{ 0x17, { 125500, 85500, 5500 } },
{ 0x1c, { 144000, 85500, 5500 } },
{ 0x18, { 162500, 85500, 5500 } },
{ 0x0c, { 181000, 85500, 5500 } },
{ 0x12, { 199500, 85500, 5500 } },
{ 0x13, { 218000, 85500, 5500 } },
{ 0x2f, { 234500, 85500, 5500 } },
{ 0x30, { 251000, 85500, 5500 } },
{ 0x5f, { 294500, 85500, 5500 } },
{ 0x60, { 311200, 85500, 5500 } },
{ 0x61, { 327900, 85500, 5500 } },
{ 0x39, { 33000, 103500, 5750 } },
{ 0x04, { 57000, 103500, 5750 } },
{ 0x16, { 75500, 103500, 5750 } },
{ 0x07, { 94000, 103500, 5750 } },
{ 0x09, { 112500, 103500, 5750 } },
{ 0x0a, { 131000, 103500, 5750 } },
{ 0x0b, { 149500, 103500, 5750 } },
{ 0x0d, { 168000, 103500, 5750 } },
{ 0x0e, { 186500, 103500, 5750 } },
{ 0x0f, { 205000, 103500, 5750 } },
{ 0x33, { 223500, 103500, 5750 } },
{ 0x34, { 240000, 103500, 5750 } },
{ 0x32, { 256500, 103500, 5750 } },
{ 0x28, { 271500, 94500, 5750 } },
{ 0x5c, { 294500, 103500, 5750 } },
{ 0x5d, { 311200, 103500, 5750 } },
{ 0x5e, { 327900, 103500, 5750 } },
{ 0x57, { 344600, 94500, 5625 } },
{ 0xe1, { 28000, 121500, 6000 } },
{ 0x64, { 47500, 121500, 6000 } },
{ 0x1d, { 66000, 121500, 6000 } },
{ 0x1b, { 84500, 121500, 6000 } },
{ 0x06, { 103000, 121500, 6000 } },
{ 0x19, { 121500, 121500, 6000 } },
{ 0x05, { 140000, 121500, 6000 } },
{ 0x11, { 158500, 121500, 6000 } },
{ 0x10, { 177000, 121500, 6000 } },
{ 0x36, { 195500, 121500, 6000 } },
{ 0x37, { 214000, 121500, 6000 } },
{ 0x38, { 232500, 121500, 6000 } },
{ 0xe5, { 251500, 121500, 6000 } },
{ 0x52, { 273500, 129000, 6125 } },
{ 0x59, { 294500, 121500, 6000 } },
{ 0x5a, { 311200, 121500, 6000 } },
{ 0x5b, { 327900, 121500, 6000 } },
{ 0xe0, { 28000, 139500, 6250 } },
{ 0xfe, { 47500, 139500, 6250 } },
{ 0xe3, { 66000, 139500, 6250 } },
{ 0xe2, { 84500, 139500, 6250 } },
{ 0x2c, { 140000, 139500, 6250 } },
{ 0xe6, { 195500, 139500, 6250 } },
{ 0x65, { 214000, 139500, 6250 } },
{ 0xe4, { 234000, 139500, 6250 } },
{ 0x50, { 255000, 147000, 6375 } },
{ 0x51, { 273500, 147000, 6375 } },
{ 0x4f, { 292000, 147000, 6375 } },
{ 0x62, { 311200, 139500, 6250 } },
{ 0x63, { 327900, 139500, 6250 } },
{ 0x58, { 344600, 130500, 6125 } },
};
struct tux_driver_data_t {
struct hid_device *hdev;
};
struct tux_hdev_driver_data_t {
u8 lamp_count;
const struct tux_kbl_map_entry_t *kbl_map;
u8 next_lamp_id;
union tux_wmi_xx_496in_80out_in_t next_kbl_set_multiple_keys_in;
};
static int tux_ll_start(struct hid_device *hdev)
{
struct wmi_device *wdev = to_wmi_device(hdev->dev.parent);
struct tux_hdev_driver_data_t *driver_data;
union tux_wmi_xx_8in_80out_out_t out;
union tux_wmi_xx_8in_80out_in_t in;
u8 keyboard_type;
int ret;
driver_data = devm_kzalloc(&hdev->dev, sizeof(*driver_data), GFP_KERNEL);
if (!driver_data)
return -ENOMEM;
in.get_device_status_in.device_type = TUX_GET_DEVICE_STATUS_DEVICE_ID_KEYBOARD;
ret = tux_wmi_xx_8in_80out(wdev, TUX_GET_DEVICE_STATUS, &in, &out);
if (ret)
return ret;
keyboard_type = out.get_device_status_out.keyboard_physical_layout;
if (keyboard_type == TUX_GET_DEVICE_STATUS_KEYBOARD_LAYOUT_ANSII) {
driver_data->lamp_count = ARRAY_SIZE(sirius_16_ansii_kbl_map);
driver_data->kbl_map = sirius_16_ansii_kbl_map;
} else if (keyboard_type == TUX_GET_DEVICE_STATUS_KEYBOARD_LAYOUT_ISO) {
driver_data->lamp_count = ARRAY_SIZE(sirius_16_iso_kbl_map);
driver_data->kbl_map = sirius_16_iso_kbl_map;
} else {
return -EINVAL;
}
driver_data->next_lamp_id = 0;
dev_set_drvdata(&hdev->dev, driver_data);
return ret;
}
static void tux_ll_stop(struct hid_device *hdev __always_unused)
{
}
static int tux_ll_open(struct hid_device *hdev __always_unused)
{
return 0;
}
static void tux_ll_close(struct hid_device *hdev __always_unused)
{
}
static int tux_ll_parse(struct hid_device *hdev)
{
return hid_parse_report(hdev, tux_report_descriptor,
sizeof(tux_report_descriptor));
}
struct __packed lamp_array_attributes_report_t {
const u8 report_id;
u16 lamp_count;
u32 bounding_box_width_in_micrometers;
u32 bounding_box_height_in_micrometers;
u32 bounding_box_depth_in_micrometers;
u32 lamp_array_kind;
u32 min_update_interval_in_microseconds;
};
static int handle_lamp_array_attributes_report(struct hid_device *hdev,
struct lamp_array_attributes_report_t *rep)
{
struct tux_hdev_driver_data_t *driver_data = dev_get_drvdata(&hdev->dev);
rep->lamp_count = driver_data->lamp_count;
rep->bounding_box_width_in_micrometers = 368000;
rep->bounding_box_height_in_micrometers = 266000;
rep->bounding_box_depth_in_micrometers = 30000;
/*
* LampArrayKindKeyboard, see "26.2.1 LampArrayKind Values" of
* "HID Usage Tables v1.5"
*/
rep->lamp_array_kind = 1;
// Some guessed value for interval microseconds
rep->min_update_interval_in_microseconds = 500;
return sizeof(*rep);
}
struct __packed lamp_attributes_request_report_t {
const u8 report_id;
u16 lamp_id;
};
static int handle_lamp_attributes_request_report(struct hid_device *hdev,
struct lamp_attributes_request_report_t *rep)
{
struct tux_hdev_driver_data_t *driver_data = dev_get_drvdata(&hdev->dev);
if (rep->lamp_id < driver_data->lamp_count)
driver_data->next_lamp_id = rep->lamp_id;
else
driver_data->next_lamp_id = 0;
return sizeof(*rep);
}
struct __packed lamp_attributes_response_report_t {
const u8 report_id;
u16 lamp_id;
u32 position_x_in_micrometers;
u32 position_y_in_micrometers;
u32 position_z_in_micrometers;
u32 update_latency_in_microseconds;
u32 lamp_purpose;
u8 red_level_count;
u8 green_level_count;
u8 blue_level_count;
u8 intensity_level_count;
u8 is_programmable;
u8 input_binding;
};
static int handle_lamp_attributes_response_report(struct hid_device *hdev,
struct lamp_attributes_response_report_t *rep)
{
struct tux_hdev_driver_data_t *driver_data = dev_get_drvdata(&hdev->dev);
u16 lamp_id = driver_data->next_lamp_id;
rep->lamp_id = lamp_id;
// Some guessed value for latency microseconds
rep->update_latency_in_microseconds = 100;
/*
* LampPurposeControl, see "26.3.1 LampPurposes Flags" of
* "HID Usage Tables v1.5"
*/
rep->lamp_purpose = 1;
rep->red_level_count = 0xff;
rep->green_level_count = 0xff;
rep->blue_level_count = 0xff;
rep->intensity_level_count = 0xff;
rep->is_programmable = 1;
if (driver_data->kbl_map[lamp_id].code <= 0xe8) {
rep->input_binding = driver_data->kbl_map[lamp_id].code;
} else {
/*
* Everything bigger is reserved/undefined, see
* "10 Keyboard/Keypad Page (0x07)" of "HID Usage Tables v1.5"
* and should return 0, see "26.8.3 Lamp Attributes" of the same
* document.
*/
rep->input_binding = 0;
}
rep->position_x_in_micrometers = driver_data->kbl_map[lamp_id].pos.x;
rep->position_y_in_micrometers = driver_data->kbl_map[lamp_id].pos.y;
rep->position_z_in_micrometers = driver_data->kbl_map[lamp_id].pos.z;
driver_data->next_lamp_id = (driver_data->next_lamp_id + 1) % driver_data->lamp_count;
return sizeof(*rep);
}
#define LAMP_UPDATE_FLAGS_LAMP_UPDATE_COMPLETE BIT(0)
struct __packed lamp_rgbi_tuple_t {
u8 red;
u8 green;
u8 blue;
u8 intensity;
};
#define LAMP_MULTI_UPDATE_REPORT_LAMP_COUNT_MAX 8
struct __packed lamp_multi_update_report_t {
const u8 report_id;
u8 lamp_count;
u8 lamp_update_flags;
u16 lamp_id[LAMP_MULTI_UPDATE_REPORT_LAMP_COUNT_MAX];
struct lamp_rgbi_tuple_t update_channels[LAMP_MULTI_UPDATE_REPORT_LAMP_COUNT_MAX];
};
static int handle_lamp_multi_update_report(struct hid_device *hdev,
struct lamp_multi_update_report_t *rep)
{
struct tux_hdev_driver_data_t *driver_data = dev_get_drvdata(&hdev->dev);
union tux_wmi_xx_496in_80out_in_t *next = &driver_data->next_kbl_set_multiple_keys_in;
struct tux_kbl_set_multiple_keys_in_rgb_config_t *rgb_configs_j;
struct wmi_device *wdev = to_wmi_device(hdev->dev.parent);
union tux_wmi_xx_496in_80out_out_t out;
u8 key_id, key_id_j, intensity_i, red_i, green_i, blue_i;
int ret;
/*
* Catching misformatted lamp_multi_update_report and fail silently
* according to "HID Usage Tables v1.5"
*/
for (unsigned int i = 0; i < rep->lamp_count; ++i) {
if (rep->lamp_id[i] > driver_data->lamp_count) {
hid_dbg(hdev, "Out of bounds lamp_id in lamp_multi_update_report. Skipping whole report!\n");
return sizeof(*rep);
}
for (unsigned int j = i + 1; j < rep->lamp_count; ++j) {
if (rep->lamp_id[i] == rep->lamp_id[j]) {
hid_dbg(hdev, "Duplicate lamp_id in lamp_multi_update_report. Skipping whole report!\n");
return sizeof(*rep);
}
}
}
for (unsigned int i = 0; i < rep->lamp_count; ++i) {
key_id = driver_data->kbl_map[rep->lamp_id[i]].code;
for (unsigned int j = 0;
j < TUX_KBL_SET_MULTIPLE_KEYS_LIGHTING_SETTINGS_COUNT_MAX;
++j) {
rgb_configs_j = &next->kbl_set_multiple_keys_in.rgb_configs[j];
key_id_j = rgb_configs_j->key_id;
if (key_id_j != 0x00 && key_id_j != key_id)
continue;
if (key_id_j == 0x00)
next->kbl_set_multiple_keys_in.rgb_configs_cnt =
j + 1;
rgb_configs_j->key_id = key_id;
/*
* While this driver respects update_channel.intensity
* according to "HID Usage Tables v1.5" also on RGB
* leds, the Microsoft MacroPad reference implementation
* (https://github.com/microsoft/RP2040MacropadHidSample
* 1d6c3ad) does not and ignores it. If it turns out
* that Windows writes intensity = 0 for RGB leds
* instead of intensity = 255, this driver should also
* ignore the update_channel.intensity.
*/
intensity_i = rep->update_channels[i].intensity;
red_i = rep->update_channels[i].red;
green_i = rep->update_channels[i].green;
blue_i = rep->update_channels[i].blue;
rgb_configs_j->red = red_i * intensity_i / 0xff;
rgb_configs_j->green = green_i * intensity_i / 0xff;
rgb_configs_j->blue = blue_i * intensity_i / 0xff;
break;
}
}
if (rep->lamp_update_flags & LAMP_UPDATE_FLAGS_LAMP_UPDATE_COMPLETE) {
ret = tux_wmi_xx_496in_80out(wdev, TUX_KBL_SET_MULTIPLE_KEYS,
next, &out);
memset(next, 0, sizeof(*next));
if (ret)
return ret;
}
return sizeof(*rep);
}
struct __packed lamp_range_update_report_t {
const u8 report_id;
u8 lamp_update_flags;
u16 lamp_id_start;
u16 lamp_id_end;
struct lamp_rgbi_tuple_t update_channel;
};
static int handle_lamp_range_update_report(struct hid_device *hdev,
struct lamp_range_update_report_t *rep)
{
struct tux_hdev_driver_data_t *driver_data = dev_get_drvdata(&hdev->dev);
struct lamp_multi_update_report_t lamp_multi_update_report = {
.report_id = LAMP_MULTI_UPDATE_REPORT_ID,
};
struct lamp_rgbi_tuple_t *update_channels_j;
int ret;
/*
* Catching misformatted lamp_range_update_report and fail silently
* according to "HID Usage Tables v1.5"
*/
if (rep->lamp_id_start > rep->lamp_id_end) {
hid_dbg(hdev, "lamp_id_start > lamp_id_end in lamp_range_update_report. Skipping whole report!\n");
return sizeof(*rep);
}
if (rep->lamp_id_end > driver_data->lamp_count - 1) {
hid_dbg(hdev, "Out of bounds lamp_id_end in lamp_range_update_report. Skipping whole report!\n");
return sizeof(*rep);
}
/*
* Break handle_lamp_range_update_report call down to multiple
* handle_lamp_multi_update_report calls to easily ensure that mixing
* handle_lamp_range_update_report and handle_lamp_multi_update_report
* does not break things.
*/
for (unsigned int i = rep->lamp_id_start; i < rep->lamp_id_end + 1;
i = i + LAMP_MULTI_UPDATE_REPORT_LAMP_COUNT_MAX) {
lamp_multi_update_report.lamp_count =
min(rep->lamp_id_end + 1 - i,
LAMP_MULTI_UPDATE_REPORT_LAMP_COUNT_MAX);
lamp_multi_update_report.lamp_update_flags =
i + LAMP_MULTI_UPDATE_REPORT_LAMP_COUNT_MAX >=
rep->lamp_id_end + 1 ?
LAMP_UPDATE_FLAGS_LAMP_UPDATE_COMPLETE : 0;
for (unsigned int j = 0; j < lamp_multi_update_report.lamp_count; ++j) {
lamp_multi_update_report.lamp_id[j] = i + j;
update_channels_j =
&lamp_multi_update_report.update_channels[j];
update_channels_j->red = rep->update_channel.red;
update_channels_j->green = rep->update_channel.green;
update_channels_j->blue = rep->update_channel.blue;
update_channels_j->intensity = rep->update_channel.intensity;
}
ret = handle_lamp_multi_update_report(hdev, &lamp_multi_update_report);
if (ret < 0)
return ret;
if (ret != sizeof(lamp_multi_update_report))
return -EIO;
}
return sizeof(*rep);
}
struct __packed lamp_array_control_report_t {
const u8 report_id;
u8 autonomous_mode;
};
static int handle_lamp_array_control_report(struct hid_device *hdev __always_unused,
struct lamp_array_control_report_t *rep)
{
/*
* The keyboards firmware doesn't have any built in controls and the
* built in effects are not implemented so this is a NOOP.
* According to the HID Documentation (HID Usage Tables v1.5) this
* function is optional and can be removed from the HID Report
* Descriptor, but it should first be confirmed that userspace respects
* this possibility too. The Microsoft MacroPad reference implementation
* (https://github.com/microsoft/RP2040MacropadHidSample 1d6c3ad)
* already deviates from the spec at another point, see
* handle_lamp_*_update_report.
*/
return sizeof(*rep);
}
static int tux_ll_raw_request(struct hid_device *hdev, u8 reportnum, u8 *buf,
size_t len, unsigned char rtype, int reqtype)
{
if (rtype != HID_FEATURE_REPORT)
return -EINVAL;
switch (reqtype) {
case HID_REQ_GET_REPORT:
switch (reportnum) {
case LAMP_ARRAY_ATTRIBUTES_REPORT_ID:
if (len != sizeof(struct lamp_array_attributes_report_t))
return -EINVAL;
return handle_lamp_array_attributes_report(hdev,
(struct lamp_array_attributes_report_t *)buf);
case LAMP_ATTRIBUTES_RESPONSE_REPORT_ID:
if (len != sizeof(struct lamp_attributes_response_report_t))
return -EINVAL;
return handle_lamp_attributes_response_report(hdev,
(struct lamp_attributes_response_report_t *)buf);
}
break;
case HID_REQ_SET_REPORT:
switch (reportnum) {
case LAMP_ATTRIBUTES_REQUEST_REPORT_ID:
if (len != sizeof(struct lamp_attributes_request_report_t))
return -EINVAL;
return handle_lamp_attributes_request_report(hdev,
(struct lamp_attributes_request_report_t *)buf);
case LAMP_MULTI_UPDATE_REPORT_ID:
if (len != sizeof(struct lamp_multi_update_report_t))
return -EINVAL;
return handle_lamp_multi_update_report(hdev,
(struct lamp_multi_update_report_t *)buf);
case LAMP_RANGE_UPDATE_REPORT_ID:
if (len != sizeof(struct lamp_range_update_report_t))
return -EINVAL;
return handle_lamp_range_update_report(hdev,
(struct lamp_range_update_report_t *)buf);
case LAMP_ARRAY_CONTROL_REPORT_ID:
if (len != sizeof(struct lamp_array_control_report_t))
return -EINVAL;
return handle_lamp_array_control_report(hdev,
(struct lamp_array_control_report_t *)buf);
}
break;
}
return -EINVAL;
}
static const struct hid_ll_driver tux_ll_driver = {
.start = &tux_ll_start,
.stop = &tux_ll_stop,
.open = &tux_ll_open,
.close = &tux_ll_close,
.parse = &tux_ll_parse,
.raw_request = &tux_ll_raw_request,
};
static int tux_virt_lamparray_add_device(struct wmi_device *wdev,
struct hid_device **hdev_out)
{
struct hid_device *hdev;
int ret;
dev_dbg(&wdev->dev, "Adding TUXEDO NB04 Virtual LampArray device.\n");
hdev = hid_allocate_device();
if (IS_ERR(hdev))
return PTR_ERR(hdev);
*hdev_out = hdev;
strscpy(hdev->name, "TUXEDO NB04 RGB Lighting", sizeof(hdev->name));
hdev->ll_driver = &tux_ll_driver;
hdev->bus = BUS_VIRTUAL;
hdev->vendor = 0x21ba;
hdev->product = 0x0400;
hdev->dev.parent = &wdev->dev;
ret = hid_add_device(hdev);
if (ret)
hid_destroy_device(hdev);
return ret;
}
static int tux_probe(struct wmi_device *wdev, const void *context __always_unused)
{
struct tux_driver_data_t *driver_data;
driver_data = devm_kzalloc(&wdev->dev, sizeof(*driver_data), GFP_KERNEL);
if (!driver_data)
return -ENOMEM;
dev_set_drvdata(&wdev->dev, driver_data);
return tux_virt_lamparray_add_device(wdev, &driver_data->hdev);
}
static void tux_remove(struct wmi_device *wdev)
{
struct tux_driver_data_t *driver_data = dev_get_drvdata(&wdev->dev);
hid_destroy_device(driver_data->hdev);
}
static struct wmi_driver tuxedo_nb04_wmi_tux_driver = {
.driver = {
.name = "tuxedo_nb04_wmi_ab",
.probe_type = PROBE_PREFER_ASYNCHRONOUS,
},
.id_table = tuxedo_nb04_wmi_ab_device_ids,
.probe = tux_probe,
.remove = tux_remove,
.no_singleton = true,
};
/*
* We don't know if the WMI API is stable and how unique the GUID is for this
* ODM. To be on the safe side we therefore only run this driver on tested
* devices defined by this list.
*/
static const struct dmi_system_id tested_devices_dmi_table[] __initconst = {
{
// TUXEDO Sirius 16 Gen1
.matches = {
DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
DMI_EXACT_MATCH(DMI_BOARD_NAME, "APX958"),
},
},
{
// TUXEDO Sirius 16 Gen2
.matches = {
DMI_EXACT_MATCH(DMI_SYS_VENDOR, "TUXEDO"),
DMI_EXACT_MATCH(DMI_BOARD_NAME, "AHP958"),
},
},
{ }
};
static int __init tuxedo_nb04_wmi_tux_init(void)
{
if (!dmi_check_system(tested_devices_dmi_table))
return -ENODEV;
return wmi_driver_register(&tuxedo_nb04_wmi_tux_driver);
}
module_init(tuxedo_nb04_wmi_tux_init);
static void __exit tuxedo_nb04_wmi_tux_exit(void)
{
return wmi_driver_unregister(&tuxedo_nb04_wmi_tux_driver);
}
module_exit(tuxedo_nb04_wmi_tux_exit);
MODULE_DESCRIPTION("Virtual HID LampArray interface for TUXEDO NB04 devices");
MODULE_AUTHOR("Werner Sembach <wse@tuxedocomputers.com>");
MODULE_LICENSE("GPL");
|