-
Notifications
You must be signed in to change notification settings - Fork 24
/
fbink_device_id.c
1847 lines (1789 loc) · 85.9 KB
/
fbink_device_id.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
/*
FBInk: FrameBuffer eInker, a library to print text & images to an eInk Linux framebuffer
Copyright (C) 2018-2024 NiLuJe <ninuje@gmail.com>
SPDX-License-Identifier: GPL-3.0-or-later
----
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#ifndef FBINK_FOR_LINUX
# include "fbink_device_id.h"
# if defined(FBINK_FOR_KINDLE)
// NOTE: This is adapted from KindleTool,
// c.f., https://github.com/NiLuJe/KindleTool/blob/master/KindleTool/kindle_tool.h#L189
static bool
is_kindle_device(uint32_t dev)
{
switch (dev) {
case 0x01u: // K1
deviceQuirks.isKindleLegacy = true;
strtcpy(deviceQuirks.deviceName, "1", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Fiona", sizeof(deviceQuirks.deviceCodename));
// NOTE: Possibly Fiona, too, as ADS was a proto.
// But later models have shown than a proto's board name often ends up naming the platform...
strtcpy(deviceQuirks.devicePlatform, "ADS", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x02u: // K2
case 0x03u:
deviceQuirks.isKindleLegacy = true;
strtcpy(deviceQuirks.deviceName, "2", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Turing", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mario", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x04u: // KDX
case 0x05u:
case 0x09u:
deviceQuirks.isKindleLegacy = true;
deviceQuirks.screenDPI = 150U;
strtcpy(deviceQuirks.deviceName, "DX", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Nell", sizeof(deviceQuirks.deviceCodename));
// NOTE: Possibly Banjo? Never figured out if that platform ever saw the light of day...
strtcpy(deviceQuirks.devicePlatform, "Mario", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x08u: // K3
case 0x06u:
case 0x0Au:
deviceQuirks.isKindleLegacy = true;
strtcpy(deviceQuirks.deviceName, "3", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Shasta", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Luigi", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x0Eu: // K4
deviceQuirks.isKindleLegacy = true;
strtcpy(deviceQuirks.deviceName, "4", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Tequila", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Yoshi", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x0Fu: // K5
case 0x11u:
case 0x10u:
case 0x12u:
deviceQuirks.isKindlePearlScreen = true;
strtcpy(deviceQuirks.deviceName, "Touch", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Whitney", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Yoshi", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x23u: // K4b
deviceQuirks.isKindleLegacy = true;
strtcpy(deviceQuirks.deviceName, "4", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Sauza", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Yoshi", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x24u: // PW1
case 0x1Bu:
case 0x1Cu:
case 0x1Du:
case 0x1Fu:
case 0x20u:
deviceQuirks.isKindlePearlScreen = true;
deviceQuirks.screenDPI = 212U;
strtcpy(deviceQuirks.deviceName, "PaperWhite", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Celeste", sizeof(deviceQuirks.deviceCodename));
// NOTE: AKA Yoshime3
strtcpy(deviceQuirks.devicePlatform, "Yoshime", sizeof(deviceQuirks.devicePlatform));
return true;
case 0xD4u: // PW2
case 0x5Au:
case 0xD5u:
case 0xD6u:
case 0xD7u:
case 0xD8u:
case 0xF2u:
case 0x17u:
case 0x60u:
case 0xF4u:
case 0xF9u:
case 0x62u:
case 0x61u:
case 0x5Fu:
deviceQuirks.screenDPI = 212U;
strtcpy(deviceQuirks.deviceName, "PaperWhite 2", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Pinot", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Wario", sizeof(deviceQuirks.devicePlatform));
return true;
case 0xC6u: // KT2
strtcpy(deviceQuirks.deviceName, "Basic", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Bourbon", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Wario", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x13u: // KV
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Voyage", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Icewine", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Wario", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x16u: // ??
case 0x21u:
return true;
case 0x54u: // KV
case 0x2Au:
case 0x4Fu:
case 0x52u:
case 0x53u:
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Voyage", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Icewine", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Wario", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x07u: // ??
case 0x0Bu:
case 0x0Cu:
case 0x0Du:
case 0x99u:
return true;
case 0xDDu: // KT2 AUS
strtcpy(deviceQuirks.deviceName, "Basic", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Bourbon", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Wario", sizeof(deviceQuirks.devicePlatform));
return true;
default:
return false;
}
}
static bool
is_kindle_device_new(uint32_t dev)
{
switch (dev) {
case 0x201u: // PW3
case 0x202u:
case 0x204u:
case 0x205u:
case 0x206u:
case 0x207u:
case 0x26Bu:
case 0x26Cu:
case 0x26Du:
case 0x26Eu:
case 0x26Fu:
case 0x270u:
case 0x293u:
case 0x294u:
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "PaperWhite 3", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Muscat", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Wario", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x20Cu: // KOA
case 0x20Du:
case 0x219u:
case 0x21Au:
case 0x21Bu:
case 0x21Cu:
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Oasis", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Whisky", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Duet", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x1BCu: // KT3
case 0x269u:
case 0x26Au:
strtcpy(deviceQuirks.deviceName, "Basic 2", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Eanab", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Heisenberg", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x295u: // KOA2
case 0x296u:
case 0x297u:
case 0x298u:
case 0x2E1u:
case 0x2E2u:
case 0x2E6u:
case 0x2E7u:
case 0x2E8u:
case 0x341u:
case 0x342u:
case 0x343u:
case 0x344u:
case 0x347u:
case 0x34Au:
deviceQuirks.isKindleZelda = true;
deviceQuirks.hasEclipseWfm = true;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Oasis 2", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Cognac", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Zelda", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x2F7u: // PW4
case 0x361u:
case 0x362u:
case 0x363u:
case 0x364u:
case 0x365u:
case 0x366u:
case 0x367u:
case 0x372u:
case 0x373u:
case 0x374u:
case 0x375u:
case 0x376u:
case 0x402u:
case 0x403u:
case 0x4D8u:
case 0x4D9u:
case 0x4DAu:
case 0x4DBu:
case 0x4DCu:
case 0x4DDu:
deviceQuirks.isKindleRex = true;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "PaperWhite 4", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Moonshine", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Rex", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x414u: // KT4
case 0x3CFu:
case 0x3D0u:
case 0x3D1u:
case 0x3D2u:
case 0x3ABu:
deviceQuirks.isKindleRex = true;
strtcpy(deviceQuirks.deviceName, "Basic 3", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Jaeger", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Rex", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x434u: // KOA3
case 0x3D8u:
case 0x3D7u:
case 0x3D6u:
case 0x3D5u:
case 0x3D4u:
deviceQuirks.isKindleZelda = true;
deviceQuirks.hasEclipseWfm = true;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Oasis 3", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Stinger", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Zelda", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x690u: // PW5
case 0x700u:
case 0x6FFu:
case 0x7ADu:
case 0x829u:
case 0x82Au:
case 0x971u:
case 0x972u:
case 0x9B3u:
deviceQuirks.isMTK = true;
deviceQuirks.hasEclipseWfm = true;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "PaperWhite 5", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Malbec", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Bellatrix", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x84Du: // KT5
case 0x8BBu:
case 0x86Au:
case 0x958u:
case 0x957u:
case 0x7F1u:
case 0x84Cu:
deviceQuirks.isMTK = true;
deviceQuirks.hasEclipseWfm = true;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Basic 4", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Cava", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Bellatrix", sizeof(deviceQuirks.devicePlatform));
return true;
case 0x8F2u:
case 0x974u:
case 0x8C3u:
case 0x847u:
case 0x975u:
case 0x874u:
case 0x875u:
case 0x8E0u:
deviceQuirks.isMTK = true;
deviceQuirks.hasEclipseWfm = true;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Scribe", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Barolo", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Bellatrix3", sizeof(deviceQuirks.devicePlatform));
return true;
default:
strtcpy(deviceQuirks.deviceName, "Unknown!", sizeof(deviceQuirks.deviceName));
return false;
}
}
// NOTE: This is from KindleTool,
// c.f., https://github.com/NiLuJe/KindleTool/blob/master/KindleTool/convert.c#L82
static uint32_t
from_base(const char* num, uint8_t base)
{
// NOTE: Crockford's Base32, but with the "L" & "U" re-added in?
const char tbl[] = "0123456789ABCDEFGHJKLMNPQRSTUVWX";
uint32_t result = 0U;
if (base >= sizeof(tbl)) {
WARN("base %hhu is unsupported (too large)", base);
return 0;
}
// Hi, my name is Neo. I know pointers! (Or not.)
for (const char* restrict p = num; *p != '\0'; p++) {
bool match = false;
for (uint8_t i = 0; tbl[i] != '\0'; i++) {
if (*p == tbl[i]) {
match = true;
result = result * base + i;
break;
}
}
// If we reach this, we ran through the full Base32 table without a match, this is bad!
if (!match) {
WARN("Input character '%c' is out of range", *p);
return 0;
}
}
return result;
}
// NOTE: This is from KindleTool,
// c.f., https://github.com/NiLuJe/KindleTool/blob/master/KindleTool/convert.c#L51
// Pilfered from http://rosettacode.org/wiki/Non-decimal_radices/Convert#C
static char*
to_base(int64_t num, uint8_t base, size_t min_output_columns)
{
// NOTE: Crockford's Base32, but with the "L" & "U" re-added in?
const char tbl[] = "0123456789ABCDEFGHJKLMNPQRSTUVWX";
char buf[66] = { 0 };
char* out = NULL;
uint64_t n;
size_t len = 0U;
size_t padding = 0U;
bool neg = false;
if (base >= sizeof(tbl)) {
WARN("base %hhu is unsupported (too large).", base);
return NULL;
}
// safe against most negative integer
n = (neg = (num < 0)) ? (uint64_t) (~num) + 1 : (uint64_t) num;
do {
buf[len++] = tbl[n % base];
} while (n /= base);
// Ensure we pad with at least min_output_columns zeroes
if (len < min_output_columns) {
padding = min_output_columns - len;
}
out = calloc(len + padding + neg + 1U, sizeof(*out));
if (out == NULL) {
PFWARN("Error allocating base32 output string buffer: %m");
return NULL;
}
for (size_t i = neg + padding; len > 0U; i++) {
out[i] = buf[--len];
}
while (padding) {
out[neg + --padding] = '0';
}
if (neg) {
out[0] = '-';
}
return out;
}
// NOTE: This is adapted from KindleTool,
// c.f., https://github.com/NiLuJe/KindleTool/blob/master/KindleTool/create.c#L1915
static void
identify_kindle(void)
{
FILE* fp = fopen("/proc/usid", "r" STDIO_CLOEXEC);
if (!fp) {
PFWARN("Cannot open /proc/usid (%m). Not running on a Kindle?");
} else {
unsigned char serial_no[KINDLE_SERIAL_NO_LENGTH] = { 0 };
if (fread(serial_no, sizeof(unsigned char), KINDLE_SERIAL_NO_LENGTH, fp) < KINDLE_SERIAL_NO_LENGTH ||
ferror(fp) != 0) {
WARN("Error reading /proc/usid (unexpected length)");
}
fclose(fp);
// Get the device code...
char device_code[3 + 1] = { 0 };
uint32_t dev = 0U;
// NOTE: If the S/N starts with B or 9, assume it's an older device with an hexadecimal device code
if (serial_no[0] == 'B' || serial_no[0] == '9') {
// NOTE: Slice the bracketed section out of the S/N: B0[17]NNNNNNNNNNNN
snprintf(device_code, 2 + 1, "%.*s", 2, serial_no + 2);
// It's in hex, easy peasy.
dev = (uint32_t) strtoul(device_code, NULL, 16);
// Check if that looks like a known id in the old device id scheme...
if (!is_kindle_device(dev)) {
WARN("Unidentified Kindle device %s (0x%02X) [%.6s]", device_code, dev, serial_no);
}
} else {
// Otherwise, assume it's the new base32-ish format (so far, all of those S/N start with a 'G').
// NOTE: Slice the bracketed section out of the S/N: (G09[0G1]NNNNNNNNNN)
snprintf(device_code, 3 + 1, "%.*s", 3, serial_no + 3);
// (these ones are encoded in a slightly custom base 32)
dev = from_base(device_code, 32U);
// Check if that looks like a known id in the new device id scheme...
if (!is_kindle_device_new(dev)) {
WARN("Unidentified Kindle device %s (0x%03X) [%.6s]", device_code, dev, serial_no);
}
}
// Store the device ID...
deviceQuirks.deviceId = (unsigned short int) dev;
// HW invert should be safe on Kindle, so just blacklist einkfb devices
if (deviceQuirks.isKindleLegacy) {
deviceQuirks.canHWInvert = false;
} else {
deviceQuirks.canHWInvert = true;
}
}
}
# elif defined(FBINK_FOR_CERVANTES)
// Read pcb id from NTX_HWCONFIG for BQ/Fnac devices, adapted from OKreader's kobo_hwconfig:
// https://github.com/lgeek/okreader/blob/master/src/kobo_hwconfig/kobo_hwconfig.c
static void
identify_cervantes(void)
{
FILE* fp = fopen(HWCONFIG_DEVICE, "re");
if (!fp) {
PFWARN("Couldn't read from `%s` (%m), unable to identify the Cervantes model", HWCONFIG_DEVICE);
} else {
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wmissing-braces"
NTXHWConfig config = { 0 };
# pragma GCC diagnostic pop
if (fseek(fp, HWCONFIG_OFFSET, SEEK_SET) != 0) {
PFWARN("Failed to seek to position 0x%p in `%s`: %m", (void*) HWCONFIG_OFFSET, HWCONFIG_DEVICE);
} else {
if (fread(&config, sizeof(config), 1, fp) < 1 || ferror(fp) != 0) {
WARN("Failed to read the NTX HWConfig entry on `%s`", HWCONFIG_DEVICE);
fclose(fp);
return;
}
}
fclose(fp);
// NOTE: This slice will NOT be NULL-terminated,
// so we have to chop the terminating NULL from the string literal's size.
if (memcmp(config.magic, HWCONFIG_MAGIC, sizeof(HWCONFIG_MAGIC) - 1U) != 0) {
WARN("Block device `%s` does not appear to contain an NTX HWConfig entry", HWCONFIG_DEVICE);
return;
}
// Store the device ID...
deviceQuirks.deviceId = config.pcb_id;
// Some devices *may* be based on the same board as the Kobo Aura, so, let's be cautious...
deviceQuirks.canHWInvert = false;
// NOTE: See the comments in set_kobo_quirks about this.
// I'm hoping there aren't any special snowflakes in the lineup...
deviceQuirks.ntxBootRota = FB_ROTATE_UD;
// Standard NTX rotation quirks...
deviceQuirks.ntxRotaQuirk = NTX_ROTA_STRAIGHT;
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_UD;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_CCW;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_UR;
deviceQuirks.touchSwapAxes = true;
deviceQuirks.touchMirrorX = true;
// List of supported devices,
// c.f., https://github.com/bq/cervantes/blob/master/bqHAL/Devices/mx508/src/DeviceInfoMx508.cpp#L33-L37
switch (config.pcb_id) {
case DEVICE_CERVANTES_TOUCH: // BQ Cervantes Touch - Fnac Touch (2012-2013)
deviceQuirks.screenDPI = 167U;
strtcpy(deviceQuirks.deviceName, "Touch", sizeof(deviceQuirks.deviceName));
break;
case DEVICE_CERVANTES_TOUCHLIGHT: // BQ Cervantes TouchLight - Fnac Touch Plus (2012-2013)
deviceQuirks.screenDPI = 167U;
strtcpy(deviceQuirks.deviceName, "TouchLight", sizeof(deviceQuirks.deviceName));
break;
case DEVICE_CERVANTES_2013: // BQ Cervantes 2013 - Fnac Touch Light (2013)
deviceQuirks.screenDPI = 212U;
strtcpy(deviceQuirks.deviceName, "2013", sizeof(deviceQuirks.deviceName));
break;
case DEVICE_CERVANTES_3: // BQ Cervantes 3 - Fnac Touch Light 2 (2016)
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "3", sizeof(deviceQuirks.deviceName));
break;
case DEVICE_CERVANTES_4: // BQ Cervantes 4
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "4", sizeof(deviceQuirks.deviceName));
break;
default:
WARN("Unidentified Cervantes device (%hhu)", config.pcb_id);
strtcpy(deviceQuirks.deviceName, "Unknown!", sizeof(deviceQuirks.deviceName));
break;
}
}
}
# elif defined(FBINK_FOR_KOBO)
static void
set_kobo_quirks(unsigned short int kobo_id)
{
// Attempt to discriminate between the Touch A & B variants...
// NOTE: This will only happen if we actually found a Nickel version tag,
// the other detection methods will simply report DEVICE_UNKNOWN on a A.
if (unlikely(kobo_id == DEVICE_KOBO_TOUCH_B)) {
const char* platform = getenv("PLATFORM");
if (likely(platform)) {
// The A is *not* an NTX board
if (strcmp(platform, "freescale") == 0) {
kobo_id = DEVICE_KOBO_TOUCH_A;
}
} else {
// If our env doesn't provide PLATFORM, check for the NTX HWConfig block ourselves,
// with a bit of code duplication from identify_kobo...
FILE* fp = fopen(HWCONFIG_DEVICE, "re");
if (!fp) {
PFWARN("Couldn't read from `%s` (%m)", HWCONFIG_DEVICE);
kobo_id = DEVICE_UNKNOWN;
} else {
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wmissing-braces"
NTXHWConfig config = { 0 };
# pragma GCC diagnostic pop
if (fseek(fp, HWCONFIG_OFFSET, SEEK_SET) != 0) {
PFWARN("Failed to seek to position 0x%p in `%s`: %m",
(void*) HWCONFIG_OFFSET,
HWCONFIG_DEVICE);
kobo_id = DEVICE_UNKNOWN;
} else {
if (fread(&config, sizeof(config), 1, fp) < 1 || ferror(fp) != 0) {
WARN("Failed to read the NTX HWConfig entry on `%s`", HWCONFIG_DEVICE);
kobo_id = DEVICE_UNKNOWN;
}
if (memcmp(config.magic, HWCONFIG_MAGIC, sizeof(HWCONFIG_MAGIC) - 1U) != 0) {
WARN("Block device `%s` does not appear to contain an NTX HWConfig entry",
HWCONFIG_DEVICE);
// Not an NTX board, it's a A :)
kobo_id = DEVICE_KOBO_TOUCH_A;
}
}
fclose(fp);
}
}
}
// Store the device ID...
deviceQuirks.deviceId = kobo_id;
// HW invert should *generally* be safe on Kobo, with a few exceptions...
deviceQuirks.canHWInvert = true;
// NOTE: Shaky assumption that almost everything follows the same rotation scheme, with:
// Boot rotation is FB_ROTATE_UD, pickel is FB_ROTATE_UR, nickel is FB_ROTATE_CCW
// With the exception of the Aura HD and the H2O.
// As usual, the H2O² is a mystery, the Rev 1 *may* follow this pattern too...
// Or that might be the Rev 2 only, but that would make it diverge from other Mk7, which is weirder.
// c.f., the relevant bit of fbink_init for more details...
// NOTE: On my Forma, pickel behaves a bit differently: it still drops to 16bpp, but appears to prefer FB_ROTATE_CCW,
// as does nickel in the default Portrait orientation (buttons on the right).
// I *think* the boot rota is FB_ROTATE_UR,
// but detecting it as pickel instead appears to do the right thing right now, so I'm not going to mess with it...
deviceQuirks.ntxBootRota = FB_ROTATE_UD;
// NOTE: Most kernels thankfully don't resort to weird rotation quirks ;).
// c.f., mxc_epdc_fb_check_var @ drivers/video/fbdev/mxc/mxc_epdc_v2_fb.c
deviceQuirks.ntxRotaQuirk = NTX_ROTA_STRAIGHT;
// NOTE: As far as handling touch coordinates translation, ntxBootRota & ntxRotaQuirk should be considered *deprecated*,
// rotationMap, paired with touchSwapAxes & touchMirrorX/touchMirrorY all paint a much clearer picture...
// Most common native -> canonical rotation mapping; {1, 2, 3, 0}
// (index is native, value is canonical; beware of that because most custom maps happen to match both ways!)
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_UD;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_CCW;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_UR;
// Most common touch panel setup (while the swap is currently a constant, the mirroring varies on a few devices).
// NOTE: This one *happens* to match a sane orientation (touch panel is oriented CCW, i.e., origin at the top-right corner),
// but this isn't always the case!
// This is why we break it down in terms of swap & mirror flags, instead of a simple "touch-to-UR" offset in units of 90° rotations.
deviceQuirks.touchSwapAxes = true;
deviceQuirks.touchMirrorX = true;
// NOTE: Device code list pilfered from
// https://github.com/pgaskin/KoboStuff/blob/gh-pages/kobofirmware.js#L11
// See also https://github.com/pgaskin/koboutils/pull/1 and the links referenced there
// for all you ever wanted to know about Kobo codenames ;).
switch (kobo_id) {
case DEVICE_KOBO_TOUCH_A: // Touch A (trilogy, freescale)
deviceQuirks.isKoboNonMT = true;
strtcpy(deviceQuirks.deviceName, "Touch A", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.deviceCodename, "Trilogy", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 3", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_TOUCH_B: // Touch B (trilogy)
deviceQuirks.isKoboNonMT = true;
strtcpy(deviceQuirks.deviceName, "Touch B", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Trilogy", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 3", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_TOUCH_C: // Touch C (trilogy)
deviceQuirks.isKoboNonMT = true;
strtcpy(deviceQuirks.deviceName, "Touch C", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Trilogy", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 4", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_MINI: // Mini (pixie)
deviceQuirks.isKoboNonMT = true;
deviceQuirks.screenDPI = 200U;
strtcpy(deviceQuirks.deviceName, "Mini", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Pixie", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 4", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_GLO: // Glo (kraken)
deviceQuirks.isKoboNonMT = true;
// {3, 2, 1, 0}, but no ioctl quirks
deviceQuirks.ntxRotaQuirk = NTX_ROTA_CCW_TOUCH;
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_CCW;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_UD;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_UR;
deviceQuirks.screenDPI = 212U;
strtcpy(deviceQuirks.deviceName, "Glo", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Kraken", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 4", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_GLO_HD: // Glo HD (alyssum)
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Glo HD", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Alyssum", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 6", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_TOLINO_SHINE_2HD: // Tolino Shine 2HD (shine2) (~ Glo HD)
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Shine 2HD", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Shine2", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 6", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_TOUCH_2: // Touch 2.0 (pika)
strtcpy(deviceQuirks.deviceName, "Touch 2.0", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Pika", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 6", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_AURA: // Aura (phoenix)
// NOTE: The bottom 10 pixels are blacked out by Nickel (behind the bezel)
deviceQuirks.koboVertOffset = -10;
// NOTE: According to the nightmode hack, the Aura's kernel *may* be crashy w/ PxP inversion...
deviceQuirks.canHWInvert = false;
deviceQuirks.screenDPI = 212U;
strtcpy(deviceQuirks.deviceName, "Aura", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Phoenix", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 5", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_AURA_HD: // Aura HD (dragon)
deviceQuirks.isKoboNonMT = true;
// NOTE: Boot rotation is FB_ROTATE_UR, pickel is FB_ROTATE_UD, nickel is FB_ROTATE_CW
deviceQuirks.ntxBootRota = FB_ROTATE_UR;
deviceQuirks.ntxRotaQuirk = NTX_ROTA_ALL_INVERTED;
// {1, 0, 3, 2}
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_UR;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_CCW;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_UD;
deviceQuirks.screenDPI = 265U;
strtcpy(deviceQuirks.deviceName, "Aura HD", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Dragon", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 4", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_AURA_H2O: // Aura H2O (dahlia)
// NOTE: The top 11 pixels are blacked out by Nickel (behind the bezel)
deviceQuirks.koboVertOffset = 11;
// NOTE: Boot rotation is FB_ROTATE_UR, pickel is FB_ROTATE_UD, nickel is FB_ROTATE_CW
deviceQuirks.ntxBootRota = FB_ROTATE_UR;
// Canonical -> native rotation mapping: { UR: 1, CW: 0, UD: 3, CCW: 2 }
deviceQuirks.ntxRotaQuirk = NTX_ROTA_ALL_INVERTED;
// {1, 0, 3, 2}
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_UR;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_CCW;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_UD;
deviceQuirks.screenDPI = 265U;
strtcpy(deviceQuirks.deviceName, "Aura H2O", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Dahlia", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 5", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_AURA_H2O_2: // Aura H2O² (snow)
// NOTE: *Might* be UD like the other ROTA_STRAIGHT devices
deviceQuirks.ntxBootRota = FB_ROTATE_UR;
// NOTE: Is indeed NTX_ROTA_STRAIGHT
// {3, 0, 1, 2}
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_CCW;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_UR;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_UD;
// Beware, this touch panel quirk *only* applies to r1 devices!
deviceQuirks.touchMirrorX = false;
deviceQuirks.screenDPI = 265U;
strtcpy(deviceQuirks.deviceName, "Aura H2O²", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Snow", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 6", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_AURA_H2O_2_R2: // Aura H2O² r2 (snow)
deviceQuirks.isKoboMk7 = true;
deviceQuirks.ntxBootRota = FB_ROTATE_UR;
// NOTE: *Might* be NTX_ROTA_ODD_INVERTED
// {3, 0, 1, 2}
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_CCW;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_UR;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_UD;
deviceQuirks.screenDPI = 265U;
strtcpy(deviceQuirks.deviceName, "Aura H2O² r2", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Snow", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 7", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_AURA_ONE: // Aura ONE (daylight)
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Aura One", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Daylight", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 6", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_AURA_ONE_LE: // Aura ONE LE (daylight)
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Aura One LE", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Daylight", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 6", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_AURA_SE: // Aura SE (star)
deviceQuirks.screenDPI = 212U;
strtcpy(deviceQuirks.deviceName, "Aura SE", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Star", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 6", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_TOLINO_VISION: // Tolino Vision (vision) (~ Aura SE)
deviceQuirks.screenDPI = 212U;
strtcpy(deviceQuirks.deviceName, "Tolino Vision", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Vision", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 6", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_AURA_SE_R2: // Aura SE r2 (star)
deviceQuirks.isKoboMk7 = true;
// NOTE: *Might* be NTX_ROTA_ODD_INVERTED
deviceQuirks.screenDPI = 212U;
strtcpy(deviceQuirks.deviceName, "Aura SE r2", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Star", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 7", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_CLARA_HD: // Clara HD (nova)
deviceQuirks.isKoboMk7 = true;
// NOTE: Is indeed NTX_ROTA_STRAIGHT
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Clara HD", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Nova", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 7", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_TOLINO_SHINE_3: // Shine 3 (loki) (~ Clara HD)
deviceQuirks.isKoboMk7 = true;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Shine 3", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Loki", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 7", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_FORMA: // Forma (frost)
deviceQuirks.isKoboMk7 = true;
deviceQuirks.canRotate = true;
// NOTE: Because Mk.7 and KOBO_HWCFG_DisplayBusWidth (35) is "16Bits_mirror" (3)
// Canonical -> native rotation mapping: { UR: 3, CW: 2, UD: 1, CCW: 0 }
deviceQuirks.ntxRotaQuirk = NTX_ROTA_ODD_INVERTED;
// {3, 2, 1, 0}
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_CCW;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_UD;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_UR;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Forma", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Frost", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 7", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_FORMA_32GB: // Forma 32GB (frost)
deviceQuirks.isKoboMk7 = true;
deviceQuirks.canRotate = true;
// NOTE: Because Mk.7 and KOBO_HWCFG_DisplayBusWidth (35) is "16Bits_mirror" (3)
deviceQuirks.ntxRotaQuirk = NTX_ROTA_ODD_INVERTED;
// {3, 2, 1, 0}
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_CCW;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_UD;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_UR;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Forma 32GB", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Frost", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 7", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_TOLINO_EPOS_2: // Epos 2 (freya) (~ Forma @ 16GB)
deviceQuirks.isKoboMk7 = true;
deviceQuirks.canRotate = true;
deviceQuirks.ntxRotaQuirk = NTX_ROTA_ODD_INVERTED;
// {3, 2, 1, 0}
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_CCW;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_UD;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_UR;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Epos 2", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Freya", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 7", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_LIBRA_H2O: // Libra H2O (storm)
deviceQuirks.isKoboMk7 = true;
// NOTE: Boot rotation is FB_ROTATE_UR, pickel is FB_ROTATE_UR, nickel is FB_ROTATE_UR
// And panel is *actually* in Portrait. Finally!
// Despite this, the kernel explicitly mangles the touch translation to match the "usual" layout.
deviceQuirks.ntxBootRota = FB_ROTATE_UR;
deviceQuirks.canRotate = true;
// NOTE: This one deserves a specific entry, because the H2O² also happens to be UR + STRAIGHT,
// but it is decidedly *NOT* sane ;).
deviceQuirks.ntxRotaQuirk = NTX_ROTA_SANE;
// {0, 1, 2, 3}
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_UR;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_UD;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_CCW;
// NOTE: The Libra was the first device to exhibit weirdly broken MXCFB_WAIT_FOR_UPDATE_COMPLETE behavior,
// where the ioctl would apparently randomly timeout after the full 5s for no reason...
// This can be reproduced in Nickel.
// In KOReader, we just sleep for a few ms instead as a workaround, c.f.,
// https://github.com/koreader/koreader-base/blob/21f4b974c7ab64a149075adc32318f87bf71dcdc/ffi/framebuffer_mxcfb.lua#L230-L235
deviceQuirks.unreliableWaitFor = true;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Libra H2O", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Storm", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 7", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_TOLINO_VISION_5: // Tolino Vision 5 (arya) (~ Libra H2O)
deviceQuirks.isKoboMk7 = true;
deviceQuirks.ntxBootRota = FB_ROTATE_UR;
deviceQuirks.canRotate = true;
deviceQuirks.ntxRotaQuirk = NTX_ROTA_SANE;
// {0, 1, 2, 3}
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_UR;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_UD;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_CCW;
deviceQuirks.unreliableWaitFor = true;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Vision 5", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Arya", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 7", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_NIA: // Nia (luna)
deviceQuirks.isKoboMk7 = true;
// The board is similar to the Libra 2, so assume it suffers from the same quirks.
deviceQuirks.unreliableWaitFor = true;
deviceQuirks.screenDPI = 212U;
strtcpy(deviceQuirks.deviceName, "Nia", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Luna", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 7", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_ELIPSA: // Elipsa (Europa)
deviceQuirks.isSunxi = true;
deviceQuirks.hasEclipseWfm = true;
// Sunxi means no HW inversion :'(.
// (And the nightmode_test flag toggled via the debugfs nightenable/nightdisable command doesn't count,
// it just flips the buffer in C, and forces the *K waveform modes (dubbed "eclipse" mode)).
deviceQuirks.canHWInvert = false;
// Has an accelerometer, but Nickel doesn't update the rotate flag, as it's meaningless.
// That said, "native" rotation still matches the usual layout, as does the touch panel translation.
deviceQuirks.ntxBootRota = FB_ROTATE_CCW; // e.g., fat bezel side UP.
deviceQuirks.canRotate = true;
deviceQuirks.ntxRotaQuirk = NTX_ROTA_SUNXI;
// There's no real linuxfb rotation support, so, {0, 1, 2, 3}
// In practice, kobo_sunxi_fb_fixup ensures that the rotate flag returned by fbink_get_state is canonical,
// despite what the actual, unused/unsupported by the driver value is...
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_UR;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_UD;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_CCW;
deviceQuirks.screenDPI = 227U;
strtcpy(deviceQuirks.deviceName, "Elipsa", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Europa", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 8", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_LIBRA_2: // Libra 2 (Io)
deviceQuirks.hasEclipseWfm = true;
deviceQuirks.isKoboMk7 = true; // Same MXCFB API ;).
// Both pickel & nickel then jump to FB_ROTATE_CW...
deviceQuirks.ntxBootRota = FB_ROTATE_UR;
// ...KOBO_HWCFG_DisplayBusWidth (35) is "16Bits" (1),
// meaning it is indeed NTX_ROTA_STRAIGHT (-ish) ;).
// NOTE: Touch panel seems to have forgone part of the usual translation, though,
// it's UR-ish (x & y swapped as usual, but no mirroring at all).
deviceQuirks.canRotate = true;
// Canonical -> native rotation mapping: { UR: 1, CW: 0, UD: 3, CCW: 2 }
deviceQuirks.ntxRotaQuirk = NTX_ROTA_CW_TOUCH; // c.f., above, don't trust the name
// {1, 0, 3, 2}
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_UR;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_CCW;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_UD;
// Same touch panel quirk as the H2O²r1
deviceQuirks.touchMirrorX = false;
// It apparently inherited its ancestor's issues...
deviceQuirks.unreliableWaitFor = true;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Libra 2", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Io", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 9", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_SAGE: // Sage (Cadmus)
deviceQuirks.isSunxi = true;
deviceQuirks.hasEclipseWfm = true;
// NOTE: The EINK_NEGATIVE_MODE flag just does a software inversion
// (pixel by pixel, in plain C, in the eink_image_process kthread).
deviceQuirks.canHWInvert = false;
deviceQuirks.ntxBootRota = FB_ROTATE_CW; // e.g., fat bezel side DOWN.
deviceQuirks.canRotate = true;
deviceQuirks.ntxRotaQuirk = NTX_ROTA_SUNXI;
// There's no real linuxfb rotation support, so, {0, 1, 2, 3}
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_UR;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_UD;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_CCW;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Sage", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Cadmus", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 8", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_TOLINO_EPOS_3: // Epos 3 (rigel) (~ Sage)
deviceQuirks.isSunxi = true;
deviceQuirks.hasEclipseWfm = true;
deviceQuirks.canHWInvert = false;
deviceQuirks.ntxBootRota = FB_ROTATE_CW; // e.g., fat bezel side DOWN.
deviceQuirks.canRotate = true;
deviceQuirks.ntxRotaQuirk = NTX_ROTA_SUNXI;
// There's no real linuxfb rotation support, so, {0, 1, 2, 3}
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_UR;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_UD;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_CCW;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Epos 3", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Rigel", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 8", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_CLARA_2E: // Clara 2E (Goldfinch)
deviceQuirks.hasEclipseWfm = true;
deviceQuirks.isKoboMk7 = true; // Same MXCFB API ;).
// NOTE: Touch panel's native orientation is the usual CCW, i.e., origin on the top-right corner.
// NOTE: NTXHWConfig says there ought to be a KX122 gyro, but apparently not?
// NOTE: ioctls are straightforward (DisplayBusWidth is 8Bits),
// but it appears that landscape orientations are inverted nonetheless?
// Either NTX_ROTA_ODD_INVERTED or NTX_ROTA_CW_TOUCH would behave,
// but their description doesn't actually match what's happening...
// Canonical -> native rotation mapping: { UR: 3, CW: 2, UD: 1, CCW: 0 }
deviceQuirks.ntxRotaQuirk = NTX_ROTA_CCW_TOUCH;
// {3, 2, 1, 0}
deviceQuirks.rotationMap[FB_ROTATE_UR] = FB_ROTATE_CCW;
deviceQuirks.rotationMap[FB_ROTATE_CW] = FB_ROTATE_UD;
deviceQuirks.rotationMap[FB_ROTATE_UD] = FB_ROTATE_CW;
deviceQuirks.rotationMap[FB_ROTATE_CCW] = FB_ROTATE_UR;
// The board is nearly identical to the Libra 2, and as such, exhibits the same quirks...
deviceQuirks.unreliableWaitFor = true;
deviceQuirks.screenDPI = 300U;
strtcpy(deviceQuirks.deviceName, "Clara 2E", sizeof(deviceQuirks.deviceName));
strtcpy(deviceQuirks.deviceCodename, "Goldfinch", sizeof(deviceQuirks.deviceCodename));
strtcpy(deviceQuirks.devicePlatform, "Mark 10", sizeof(deviceQuirks.devicePlatform));
break;
case DEVICE_KOBO_ELIPSA_2E: // Elipsa 2E (Condor)