aboutsummaryrefslogtreecommitdiff
path: root/SOURCES/v0-oxp-sensors.patch
blob: 4b42d511561ade6e3a3ff06b87787250e83d27aa (plain)
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
From b75680974fe91faa5fcc1bbe39156b1e2e134238 Mon Sep 17 00:00:00 2001
From: "Derek J. Clark" <derekjohn.clark@gmail.com>
Date: Wed, 27 Mar 2024 18:47:00 -0700
Subject: [PATCH 1/4] oxp-sensors: hwmon: Add OrangePi Neo PWM fan control

Add OrangePi NEO handheld device. The OrangePi Neo uses different registers
for PWM manual mode, set PWM, and read fan speed than previous devices. Valid
PWM input and duty cycle is 1-244, we scale this to 1-155 to maintain
compatibility with existing userspace tools.
---
 drivers/hwmon/oxp-sensors.c | 112 ++++++++++++++++++++++++++++++++----
 1 file changed, 100 insertions(+), 12 deletions(-)

diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c
index 8d3b0f86c..ebca28b4a 100644
--- a/drivers/hwmon/oxp-sensors.c
+++ b/drivers/hwmon/oxp-sensors.c
@@ -46,6 +46,7 @@ enum oxp_board {
 	aya_neo_air_plus_mendo,
 	aya_neo_air_pro,
 	aya_neo_geek,
+	orange_pi_neo,
 	oxp_mini_amd,
 	oxp_mini_amd_a07,
 	oxp_mini_amd_pro,
@@ -54,10 +55,16 @@ enum oxp_board {
 static enum oxp_board board;
 
 /* Fan reading and PWM */
-#define OXP_SENSOR_FAN_REG		0x76 /* Fan reading is 2 registers long */
-#define OXP_SENSOR_PWM_ENABLE_REG	0x4A /* PWM enable is 1 register long */
-#define OXP_SENSOR_PWM_REG		0x4B /* PWM reading is 1 register long */
+#define OXP_SENSOR_FAN_REG              0x76 /* Fan reading is 2 registers long */
+#define OXP_SENSOR_PWM_ENABLE_REG       0x4A /* PWM enable is 1 register long */
+#define OXP_SENSOR_PWM_REG              0x4B /* PWM reading is 1 register long */
 
+#define ORANGEPI_SENSOR_FAN_REG         0x78 /* Fan reading is 2 registers long */
+#define ORANGEPI_SENSOR_PWM_ENABLE_REG  0x40 /* PWM enable is 1 register long */
+#define ORANGEPI_SENSOR_PWM_REG         0x38 /* PWM reading is 1 register long */
+
+#define PWM_MODE_AUTO                   0x00
+#define PWM_MODE_MANUAL                 0x01
 /* Turbo button takeover function
  * Older boards have different values and EC registers
  * for the same function
@@ -120,6 +127,13 @@ static const struct dmi_system_id dmi_table[] = {
 		},
 		.driver_data = (void *)aya_neo_geek,
 	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_BOARD_VENDOR, "OrangePi"),
+			DMI_EXACT_MATCH(DMI_BOARD_NAME, "NEO-01"),
+		},
+		.driver_data = (void *)orange_pi_neo,
+	},
 	{
 		.matches = {
 			DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"),
@@ -295,12 +309,42 @@ static DEVICE_ATTR_RW(tt_toggle);
 /* PWM enable/disable functions */
 static int oxp_pwm_enable(void)
 {
-	return write_to_ec(OXP_SENSOR_PWM_ENABLE_REG, 0x01);
+	switch (board) {
+	case orange_pi_neo:
+		return write_to_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, PWM_MODE_MANUAL);
+	case aok_zoe_a1:
+	case aya_neo_2:
+	case aya_neo_air:
+	case aya_neo_air_plus_mendo:
+	case aya_neo_air_pro:
+	case aya_neo_geek:
+	case oxp_mini_amd:
+	case oxp_mini_amd_a07:
+	case oxp_mini_amd_pro:
+		return write_to_ec(OXP_SENSOR_PWM_ENABLE_REG, PWM_MODE_MANUAL);
+	default:
+		return -EINVAL;
+	}
 }
 
 static int oxp_pwm_disable(void)
 {
-	return write_to_ec(OXP_SENSOR_PWM_ENABLE_REG, 0x00);
+	switch (board) {
+	case orange_pi_neo:
+		return write_to_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, PWM_MODE_AUTO);
+	case aok_zoe_a1:
+	case aya_neo_2:
+	case aya_neo_air:
+	case aya_neo_air_plus_mendo:
+	case aya_neo_air_pro:
+	case aya_neo_geek:
+	case oxp_mini_amd:
+	case oxp_mini_amd_a07:
+	case oxp_mini_amd_pro:
+		return write_to_ec(OXP_SENSOR_PWM_ENABLE_REG, PWM_MODE_AUTO);
+	default:
+		return -EINVAL;
+	}
 }
 
 /* Callbacks for hwmon interface */
@@ -326,7 +370,22 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 	case hwmon_fan:
 		switch (attr) {
 		case hwmon_fan_input:
-			return read_from_ec(OXP_SENSOR_FAN_REG, 2, val);
+			switch (board) {
+			case orange_pi_neo:
+				return read_from_ec(ORANGEPI_SENSOR_FAN_REG, 2, val);
+			case aok_zoe_a1:
+			case aya_neo_2:
+			case aya_neo_air:
+			case aya_neo_air_plus_mendo:
+			case aya_neo_air_pro:
+			case aya_neo_geek:
+			case oxp_mini_amd:
+			case oxp_mini_amd_a07:
+			case oxp_mini_amd_pro:
+				return read_from_ec(OXP_SENSOR_FAN_REG, 2, val);
+			default:
+				break;
+			}
 		default:
 			break;
 		}
@@ -334,10 +393,14 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 	case hwmon_pwm:
 		switch (attr) {
 		case hwmon_pwm_input:
-			ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val);
-			if (ret)
-				return ret;
 			switch (board) {
+			case orange_pi_neo:
+				ret = read_from_ec(ORANGEPI_SENSOR_PWM_REG, 1, val);
+				if (ret)
+					return ret;
+				/* scale from range [1-244] */
+				*val = ((*val - 1) * 254 / 243) + 1;
+				break;
 			case aya_neo_2:
 			case aya_neo_air:
 			case aya_neo_air_plus_mendo:
@@ -345,16 +408,37 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 			case aya_neo_geek:
 			case oxp_mini_amd:
 			case oxp_mini_amd_a07:
+				ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val);
+				if (ret)
+					return ret;
 				*val = (*val * 255) / 100;
 				break;
 			case oxp_mini_amd_pro:
 			case aok_zoe_a1:
 			default:
+				ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val);
+				if (ret)
+					return ret;
 				break;
 			}
 			return 0;
 		case hwmon_pwm_enable:
-			return read_from_ec(OXP_SENSOR_PWM_ENABLE_REG, 1, val);
+			switch (board) {
+			case orange_pi_neo:
+				return read_from_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, 1, val);
+			case aok_zoe_a1:
+			case aya_neo_2:
+			case aya_neo_air:
+			case aya_neo_air_plus_mendo:
+			case aya_neo_air_pro:
+			case aya_neo_geek:
+			case oxp_mini_amd:
+			case oxp_mini_amd_a07:
+			case oxp_mini_amd_pro:
+				return read_from_ec(OXP_SENSOR_PWM_ENABLE_REG, 1, val);
+			default:
+				break;
+			}
 		default:
 			break;
 		}
@@ -381,6 +465,10 @@ static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type,
 			if (val < 0 || val > 255)
 				return -EINVAL;
 			switch (board) {
+			case orange_pi_neo:
+				/* scale to range [1-244] */
+				val = ((val - 1) * 243 / 254) + 1;
+				return write_to_ec(ORANGEPI_SENSOR_PWM_REG, val);
 			case aya_neo_2:
 			case aya_neo_air:
 			case aya_neo_air_plus_mendo:
@@ -389,13 +477,13 @@ static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type,
 			case oxp_mini_amd:
 			case oxp_mini_amd_a07:
 				val = (val * 100) / 255;
-				break;
+				return write_to_ec(OXP_SENSOR_PWM_REG, val);
 			case aok_zoe_a1:
 			case oxp_mini_amd_pro:
+				return write_to_ec(OXP_SENSOR_PWM_REG, val);
 			default:
 				break;
 			}
-			return write_to_ec(OXP_SENSOR_PWM_REG, val);
 		default:
 			break;
 		}
-- 
2.45.2


From 78c8501d4c2dc4dcc2125dcf130723b1fbe72e1c Mon Sep 17 00:00:00 2001
From: "Derek J. Clark" <derekjohn.clark@gmail.com>
Date: Wed, 27 Mar 2024 18:50:22 -0700
Subject: [PATCH 2/4] oxp-sensors: hwmon: Add OneXPlayer 2 and OneXFly

Add OneXPlayer 2 series and OneXFly handhelds. The 2 series uses a new register
for turbo button takeover. While at it, adjust formatting of some constants and
reorder all cases alphabetically for consistency. Rename some constants for
disambiguation.
---
 drivers/hwmon/oxp-sensors.c | 90 ++++++++++++++++++++++++++++++-------
 1 file changed, 74 insertions(+), 16 deletions(-)

diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c
index ebca28b4a..cf8ba1cc6 100644
--- a/drivers/hwmon/oxp-sensors.c
+++ b/drivers/hwmon/oxp-sensors.c
@@ -47,6 +47,8 @@ enum oxp_board {
 	aya_neo_air_pro,
 	aya_neo_geek,
 	orange_pi_neo,
+	oxp_2,
+	oxp_fly,
 	oxp_mini_amd,
 	oxp_mini_amd_a07,
 	oxp_mini_amd_pro,
@@ -66,16 +68,16 @@ static enum oxp_board board;
 #define PWM_MODE_AUTO                   0x00
 #define PWM_MODE_MANUAL                 0x01
 /* Turbo button takeover function
- * Older boards have different values and EC registers
+ * Different boards have different values and EC registers
  * for the same function
  */
-#define OXP_OLD_TURBO_SWITCH_REG	0x1E
-#define OXP_OLD_TURBO_TAKE_VAL		0x01
-#define OXP_OLD_TURBO_RETURN_VAL	0x00
+#define OXP_TURBO_SWITCH_REG            0xF1
+#define OXP_TURBO_TAKE_VAL              0x40
+#define OXP_TURBO_RETURN_VAL            0x00 /* Common return val */
 
-#define OXP_TURBO_SWITCH_REG		0xF1
-#define OXP_TURBO_TAKE_VAL		0x40
-#define OXP_TURBO_RETURN_VAL		0x00
+#define OXP_2_TURBO_SWITCH_REG          0xEB /* OXP2 and OXP2 Pro */
+#define OXP_MINI_TURBO_SWITCH_REG       0x1E /* Mini AO7 */
+#define OXP_MINI_TURBO_TAKE_VAL         0x01
 
 static const struct dmi_system_id dmi_table[] = {
 	{
@@ -141,6 +143,34 @@ static const struct dmi_system_id dmi_table[] = {
 		},
 		.driver_data = (void *)oxp_mini_amd,
 	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"),
+			DMI_EXACT_MATCH(DMI_BOARD_NAME, "ONEXPLAYER 2 ARP23"),
+		},
+		.driver_data = (void *)oxp_2,
+	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"),
+			DMI_EXACT_MATCH(DMI_BOARD_NAME, "ONEXPLAYER 2 PRO ARP23P"),
+		},
+		.driver_data = (void *)oxp_2,
+	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"),
+			DMI_EXACT_MATCH(DMI_BOARD_NAME, "ONEXPLAYER 2 PRO ARP23P EVA-01"),
+		},
+		.driver_data = (void *)oxp_2,
+	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"),
+			DMI_EXACT_MATCH(DMI_BOARD_NAME, "ONEXPLAYER F1"),
+		},
+		.driver_data = (void *)oxp_fly,
+	},
 	{
 		.matches = {
 			DMI_MATCH(DMI_BOARD_VENDOR, "ONE-NETBOOK"),
@@ -206,14 +236,19 @@ static int tt_toggle_enable(void)
 
 	switch (board) {
 	case oxp_mini_amd_a07:
-		reg = OXP_OLD_TURBO_SWITCH_REG;
-		val = OXP_OLD_TURBO_TAKE_VAL;
+		reg = OXP_MINI_TURBO_SWITCH_REG;
+		val = OXP_MINI_TURBO_TAKE_VAL;
 		break;
-	case oxp_mini_amd_pro:
 	case aok_zoe_a1:
+	case oxp_fly:
+	case oxp_mini_amd_pro:
 		reg = OXP_TURBO_SWITCH_REG;
 		val = OXP_TURBO_TAKE_VAL;
 		break;
+	case oxp_2:
+		reg = OXP_2_TURBO_SWITCH_REG;
+		val = OXP_TURBO_TAKE_VAL;
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -227,14 +262,19 @@ static int tt_toggle_disable(void)
 
 	switch (board) {
 	case oxp_mini_amd_a07:
-		reg = OXP_OLD_TURBO_SWITCH_REG;
-		val = OXP_OLD_TURBO_RETURN_VAL;
+		reg = OXP_MINI_TURBO_SWITCH_REG;
+		val = OXP_TURBO_RETURN_VAL;
 		break;
-	case oxp_mini_amd_pro:
 	case aok_zoe_a1:
+	case oxp_fly:
+	case oxp_mini_amd_pro:
 		reg = OXP_TURBO_SWITCH_REG;
 		val = OXP_TURBO_RETURN_VAL;
 		break;
+	case oxp_2:
+		reg = OXP_2_TURBO_SWITCH_REG;
+		val = OXP_TURBO_RETURN_VAL;
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -247,6 +287,8 @@ static umode_t tt_toggle_is_visible(struct kobject *kobj,
 {
 	switch (board) {
 	case aok_zoe_a1:
+	case oxp_2:
+	case oxp_fly:
 	case oxp_mini_amd_a07:
 	case oxp_mini_amd_pro:
 		return attr->mode;
@@ -287,12 +329,16 @@ static ssize_t tt_toggle_show(struct device *dev,
 
 	switch (board) {
 	case oxp_mini_amd_a07:
-		reg = OXP_OLD_TURBO_SWITCH_REG;
+		reg = OXP_MINI_TURBO_SWITCH_REG;
 		break;
-	case oxp_mini_amd_pro:
 	case aok_zoe_a1:
+	case oxp_fly:
+	case oxp_mini_amd_pro:
 		reg = OXP_TURBO_SWITCH_REG;
 		break;
+	case oxp_2:
+		reg = OXP_2_TURBO_SWITCH_REG;
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -320,6 +366,8 @@ static int oxp_pwm_enable(void)
 	case aya_neo_geek:
 	case oxp_mini_amd:
 	case oxp_mini_amd_a07:
+	case oxp_2:
+	case oxp_fly:
 	case oxp_mini_amd_pro:
 		return write_to_ec(OXP_SENSOR_PWM_ENABLE_REG, PWM_MODE_MANUAL);
 	default:
@@ -340,6 +388,8 @@ static int oxp_pwm_disable(void)
 	case aya_neo_geek:
 	case oxp_mini_amd:
 	case oxp_mini_amd_a07:
+	case oxp_2:
+	case oxp_fly:
 	case oxp_mini_amd_pro:
 		return write_to_ec(OXP_SENSOR_PWM_ENABLE_REG, PWM_MODE_AUTO);
 	default:
@@ -381,6 +431,8 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 			case aya_neo_geek:
 			case oxp_mini_amd:
 			case oxp_mini_amd_a07:
+			case oxp_2:
+			case oxp_fly:
 			case oxp_mini_amd_pro:
 				return read_from_ec(OXP_SENSOR_FAN_REG, 2, val);
 			default:
@@ -413,8 +465,10 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 					return ret;
 				*val = (*val * 255) / 100;
 				break;
-			case oxp_mini_amd_pro:
 			case aok_zoe_a1:
+			case oxp_2:
+			case oxp_fly:
+			case oxp_mini_amd_pro:
 			default:
 				ret = read_from_ec(OXP_SENSOR_PWM_REG, 1, val);
 				if (ret)
@@ -434,6 +488,8 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 			case aya_neo_geek:
 			case oxp_mini_amd:
 			case oxp_mini_amd_a07:
+			case oxp_2:
+			case oxp_fly:
 			case oxp_mini_amd_pro:
 				return read_from_ec(OXP_SENSOR_PWM_ENABLE_REG, 1, val);
 			default:
@@ -479,6 +535,8 @@ static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type,
 				val = (val * 100) / 255;
 				return write_to_ec(OXP_SENSOR_PWM_REG, val);
 			case aok_zoe_a1:
+			case oxp_2:
+			case oxp_fly:
 			case oxp_mini_amd_pro:
 				return write_to_ec(OXP_SENSOR_PWM_REG, val);
 			default:
-- 
2.45.2


From f12bdbb992c66b8f1320372892da116e95a7f104 Mon Sep 17 00:00:00 2001
From: "Derek J. Clark" <derekjohn.clark@gmail.com>
Date: Thu, 28 Mar 2024 19:50:40 +0100
Subject: [PATCH 3/4] oxp-sensors: hwmon: Add support for AYANEO 2s, air 1s,
 geek 1s and kun models

---
 drivers/hwmon/oxp-sensors.c | 48 +++++++++++++++++++++++++++++++++++++
 1 file changed, 48 insertions(+)

diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c
index cf8ba1cc6..e8d9fea9d 100644
--- a/drivers/hwmon/oxp-sensors.c
+++ b/drivers/hwmon/oxp-sensors.c
@@ -42,10 +42,14 @@ static bool unlock_global_acpi_lock(void)
 enum oxp_board {
 	aok_zoe_a1 = 1,
 	aya_neo_2,
+	aya_neo_2s,
 	aya_neo_air,
+	aya_neo_air_1s,
 	aya_neo_air_plus_mendo,
 	aya_neo_air_pro,
 	aya_neo_geek,
+	aya_neo_geek_1s,
+	aya_neo_kun,
 	orange_pi_neo,
 	oxp_2,
 	oxp_fly,
@@ -101,6 +105,13 @@ static const struct dmi_system_id dmi_table[] = {
 		},
 		.driver_data = (void *)aya_neo_2,
 	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_BOARD_VENDOR, "AYANEO"),
+			DMI_EXACT_MATCH(DMI_BOARD_NAME, "AYANEO 2S"),
+		},
+		.driver_data = (void *)aya_neo_2s,
+	},
 	{
 		.matches = {
 			DMI_MATCH(DMI_BOARD_VENDOR, "AYANEO"),
@@ -115,6 +126,13 @@ static const struct dmi_system_id dmi_table[] = {
 		},
 		.driver_data = (void *)aya_neo_air_plus_mendo,
 	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_BOARD_VENDOR, "AYANEO"),
+			DMI_EXACT_MATCH(DMI_BOARD_NAME, "AIR 1S"),
+		},
+		.driver_data = (void *)aya_neo_air_1s,
+	},
 	{
 		.matches = {
 			DMI_MATCH(DMI_BOARD_VENDOR, "AYANEO"),
@@ -129,6 +147,20 @@ static const struct dmi_system_id dmi_table[] = {
 		},
 		.driver_data = (void *)aya_neo_geek,
 	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_BOARD_VENDOR, "AYANEO"),
+			DMI_EXACT_MATCH(DMI_BOARD_NAME, "GEEK 1S"),
+		},
+		.driver_data = (void *)aya_neo_geek_1s,
+	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_BOARD_VENDOR, "AYANEO"),
+			DMI_EXACT_MATCH(DMI_BOARD_NAME, "KUN"),
+		},
+		.driver_data = (void *)aya_neo_kun,
+	},
 	{
 		.matches = {
 			DMI_MATCH(DMI_BOARD_VENDOR, "OrangePi"),
@@ -360,10 +392,14 @@ static int oxp_pwm_enable(void)
 		return write_to_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, PWM_MODE_MANUAL);
 	case aok_zoe_a1:
 	case aya_neo_2:
+	case aya_neo_2s:
 	case aya_neo_air:
+	case aya_neo_air_1s:
 	case aya_neo_air_plus_mendo:
 	case aya_neo_air_pro:
 	case aya_neo_geek:
+	case aya_neo_geek_1s:
+	case aya_neo_kun:
 	case oxp_mini_amd:
 	case oxp_mini_amd_a07:
 	case oxp_2:
@@ -382,10 +418,14 @@ static int oxp_pwm_disable(void)
 		return write_to_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, PWM_MODE_AUTO);
 	case aok_zoe_a1:
 	case aya_neo_2:
+	case aya_neo_2s:
 	case aya_neo_air:
+	case aya_neo_air_1s:
 	case aya_neo_air_plus_mendo:
 	case aya_neo_air_pro:
 	case aya_neo_geek:
+	case aya_neo_geek_1s:
+	case aya_neo_kun:
 	case oxp_mini_amd:
 	case oxp_mini_amd_a07:
 	case oxp_2:
@@ -425,10 +465,14 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 				return read_from_ec(ORANGEPI_SENSOR_FAN_REG, 2, val);
 			case aok_zoe_a1:
 			case aya_neo_2:
+			case aya_neo_2s:
 			case aya_neo_air:
+			case aya_neo_air_1s:
 			case aya_neo_air_plus_mendo:
 			case aya_neo_air_pro:
 			case aya_neo_geek:
+			case aya_neo_geek_1s:
+			case aya_neo_kun:
 			case oxp_mini_amd:
 			case oxp_mini_amd_a07:
 			case oxp_2:
@@ -482,10 +526,14 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 				return read_from_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, 1, val);
 			case aok_zoe_a1:
 			case aya_neo_2:
+			case aya_neo_2s:
 			case aya_neo_air:
+			case aya_neo_air_1s:
 			case aya_neo_air_plus_mendo:
 			case aya_neo_air_pro:
 			case aya_neo_geek:
+			case aya_neo_geek_1s:
+			case aya_neo_kun:
 			case oxp_mini_amd:
 			case oxp_mini_amd_a07:
 			case oxp_2:
-- 
2.45.2


From 61740ea3d49721fa86f6a0085029f8f4f68ae916 Mon Sep 17 00:00:00 2001
From: "Derek J. Clark" <derekjohn.clark@gmail.com>
Date: Wed, 27 Mar 2024 18:58:59 -0700
Subject: [PATCH 4/4] oxp-sensors: hwmon: Add GPD Win Mini

Add GPD Win Mini. GPD devices don't have a separate enable register, the PWM
register is used for this purpose. A write value of 0 puts the PWM into auto
mode, writing anything 1-244 puts the PWM into manual mode, and 245-255 are
undefined. We scale to 1-255 and handle manual by writing a value to 70% as a
common sense default.
---
 drivers/hwmon/oxp-sensors.c | 43 +++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

diff --git a/drivers/hwmon/oxp-sensors.c b/drivers/hwmon/oxp-sensors.c
index e8d9fea9d..11dec1b31 100644
--- a/drivers/hwmon/oxp-sensors.c
+++ b/drivers/hwmon/oxp-sensors.c
@@ -50,6 +50,7 @@ enum oxp_board {
 	aya_neo_geek,
 	aya_neo_geek_1s,
 	aya_neo_kun,
+	gpd_win_mini,
 	orange_pi_neo,
 	oxp_2,
 	oxp_fly,
@@ -69,8 +70,19 @@ static enum oxp_board board;
 #define ORANGEPI_SENSOR_PWM_ENABLE_REG  0x40 /* PWM enable is 1 register long */
 #define ORANGEPI_SENSOR_PWM_REG         0x38 /* PWM reading is 1 register long */
 
+/* GPD devices don't have a separate enable register for the fan.
+ * For the PWM register, 0 is auto, 1+ is a manual value, up to 255
+ * depending on the specific model. This driver will scale to 0-255
+ * and treat PWM enable without a value as "set to manual, 70%."
+ * The mini uses the same fan register as the OrangePi NEO.
+ */
+#define GPD_MINI_SENSOR_PWM_REG         0x7A /* PWM reading is 1 register long */
+/* Values for fan auto mode */
 #define PWM_MODE_AUTO                   0x00
+
+ /* Values for fan manual mode */
 #define PWM_MODE_MANUAL                 0x01
+#define GPD_MINI_PWM_MODE_MANUAL        0xAA /* 70% */
 /* Turbo button takeover function
  * Different boards have different values and EC registers
  * for the same function
@@ -161,6 +173,13 @@ static const struct dmi_system_id dmi_table[] = {
 		},
 		.driver_data = (void *)aya_neo_kun,
 	},
+	{
+		.matches = {
+			DMI_MATCH(DMI_BOARD_VENDOR, "GPD"),
+			DMI_EXACT_MATCH(DMI_BOARD_NAME, "G1617-01"),
+		},
+		.driver_data = (void *)gpd_win_mini,
+	},
 	{
 		.matches = {
 			DMI_MATCH(DMI_BOARD_VENDOR, "OrangePi"),
@@ -388,6 +407,11 @@ static DEVICE_ATTR_RW(tt_toggle);
 static int oxp_pwm_enable(void)
 {
 	switch (board) {
+	/* GPD has no separate enable register, instead, set the fan to
+	 * a safe default.
+	 */
+	case gpd_win_mini:
+		return write_to_ec(GPD_MINI_SENSOR_PWM_REG, GPD_MINI_PWM_MODE_MANUAL);
 	case orange_pi_neo:
 		return write_to_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, PWM_MODE_MANUAL);
 	case aok_zoe_a1:
@@ -414,6 +438,8 @@ static int oxp_pwm_enable(void)
 static int oxp_pwm_disable(void)
 {
 	switch (board) {
+	case gpd_win_mini:
+		return write_to_ec(GPD_MINI_SENSOR_PWM_REG, PWM_MODE_AUTO);
 	case orange_pi_neo:
 		return write_to_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, PWM_MODE_AUTO);
 	case aok_zoe_a1:
@@ -461,6 +487,7 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 		switch (attr) {
 		case hwmon_fan_input:
 			switch (board) {
+			case gpd_win_mini:
 			case orange_pi_neo:
 				return read_from_ec(ORANGEPI_SENSOR_FAN_REG, 2, val);
 			case aok_zoe_a1:
@@ -490,6 +517,14 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 		switch (attr) {
 		case hwmon_pwm_input:
 			switch (board) {
+			case gpd_win_mini:
+				ret = read_from_ec(GPD_MINI_SENSOR_PWM_REG, 1, val);
+				if (ret)
+					return ret;
+				if (*val != PWM_MODE_AUTO)
+					/* scale from range [1-244] */
+					*val = ((*val - 1) * 254 / 243) + 1;
+				break;
 			case orange_pi_neo:
 				ret = read_from_ec(ORANGEPI_SENSOR_PWM_REG, 1, val);
 				if (ret)
@@ -522,6 +557,10 @@ static int oxp_platform_read(struct device *dev, enum hwmon_sensor_types type,
 			return 0;
 		case hwmon_pwm_enable:
 			switch (board) {
+			case gpd_win_mini:
+				ret = read_from_ec(GPD_MINI_SENSOR_PWM_REG, 1, val);
+				*val = (*val != PWM_MODE_AUTO);
+				return ret;
 			case orange_pi_neo:
 				return read_from_ec(ORANGEPI_SENSOR_PWM_ENABLE_REG, 1, val);
 			case aok_zoe_a1:
@@ -569,6 +608,10 @@ static int oxp_platform_write(struct device *dev, enum hwmon_sensor_types type,
 			if (val < 0 || val > 255)
 				return -EINVAL;
 			switch (board) {
+			case gpd_win_mini:
+				/* scale to range [1-244] */
+				val = ((val - 1) * 243 / 254) + 1;
+				return write_to_ec(GPD_MINI_SENSOR_PWM_REG, val);
 			case orange_pi_neo:
 				/* scale to range [1-244] */
 				val = ((val - 1) * 243 / 254) + 1;
-- 
2.45.2