-
Notifications
You must be signed in to change notification settings - Fork 3
/
ayn-platform.c
765 lines (668 loc) · 22.8 KB
/
ayn-platform.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
// SPDX-License-Identifier: GPL-2.0
/*
* Platform driver for Ayn x86 Handhelds that expose fan reading and
* control, as well as temperature sensor readings exposed by the EC
* via hwmon sysfs.
*
* Fan control is provided via pwm interface in the range [0-255].
* Ayn use [0-128] as the range in the EC, the written value is
* scaled to accommodate. The EC also provides a configurable fan
* curve with five set points that associate a temperature [0-100]
* in Celcius with a fan speed [0-128]. The auto_point fan speeds
* are scaled from the range [0-255]. Temperature readings are
* scaled from the hwmon expected millidegrees to degrees when read.
*
* Copyright (C) 2023-2024 Derek J. Clark <derekjohn.clark@gmail.com>
*/
#include <linux/acpi.h>
#include <linux/dmi.h>
#include <linux/hwmon-sysfs.h>
#include <linux/hwmon.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/led-class-multicolor.h>
#include <linux/leds.h>
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/processor.h>
/* Handle ACPI lock mechanism */
static u32 ayn_mutex;
#define ACPI_LOCK_DELAY_MS 500
static bool lock_global_acpi_lock(void) {
return ACPI_SUCCESS(acpi_acquire_global_lock(ACPI_LOCK_DELAY_MS, &ayn_mutex));
}
static bool unlock_global_acpi_lock(void) {
return ACPI_SUCCESS(acpi_release_global_lock(ayn_mutex));
}
enum ayn_model {
ayn_loki_max = 1,
ayn_loki_minipro,
ayn_loki_zero,
};
static enum ayn_model model;
/* EC Teperature Sensors */
#define AYN_SENSOR_BAT_TEMP_REG 0x04 /* Battery */
#define AYN_SENSOR_CHARGE_TEMP_REG 0x07 /* Charger IC */
#define AYN_SENSOR_MB_TEMP_REG 0x05 /* Motherboard */
#define AYN_SENSOR_PROC_TEMP_REG 0x09 /* CPU Core */
#define AYN_SENSOR_VCORE_TEMP_REG 0x08 /* vCore */
/* Fan reading and PWM */
#define AYN_SENSOR_PWM_FAN_ENABLE_REG 0x10 /* PWM operating mode */
#define AYN_SENSOR_PWM_FAN_SET_REG 0x11 /* PWM duty cycle */
#define AYN_SENSOR_PWM_FAN_SPEED_REG 0x20 /* Fan speed */
/* EC controlled fan curve registers */
#define AYN_SENSOR_PWM_FAN_SPEED_1_REG 0x12
#define AYN_SENSOR_PWM_FAN_SPEED_2_REG 0x14
#define AYN_SENSOR_PWM_FAN_SPEED_3_REG 0x16
#define AYN_SENSOR_PWM_FAN_SPEED_4_REG 0x18
#define AYN_SENSOR_PWM_FAN_SPEED_5_REG 0x1A
#define AYN_SENSOR_PWM_FAN_TEMP_1_REG 0x13
#define AYN_SENSOR_PWM_FAN_TEMP_2_REG 0x15
#define AYN_SENSOR_PWM_FAN_TEMP_3_REG 0x17
#define AYN_SENSOR_PWM_FAN_TEMP_4_REG 0x19
#define AYN_SENSOR_PWM_FAN_TEMP_5_REG 0x1B
/* EC Controlled RGB registers */
#define AYN_LED_MC_B_REG 0xB2 /* Blue, range 0x00-0xFF */
#define AYN_LED_MC_G_REG 0xB1 /* Green, range 0x00-0xFF */
#define AYN_LED_MC_R_REG 0xB0 /* Red, range 0x00-0xFF */
#define AYN_LED_MODE_REG 0xB3 /* RGB Mode */
/* RGB Mode values */
#define AYN_LED_MODE_BREATH 0x00 /* Default breathing mode */
#define AYN_LED_MODE_WRITE 0xAA /* User defined mode */
#define AYN_LED_MODE_WRITE_ENABLED 0x55 /* Return value when probed */
enum led_mode {
breath = 0,
write,
};
static const struct dmi_system_id dmi_table[] = {
{
.matches =
{
DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "ayn"),
DMI_EXACT_MATCH(DMI_BOARD_NAME, "Loki Max"),
},
.driver_data = (void *)ayn_loki_max,
},
{
.matches =
{
DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "ayn"),
DMI_EXACT_MATCH(DMI_BOARD_NAME, "Loki MiniPro"),
},
.driver_data = (void *)ayn_loki_minipro,
},
{
.matches =
{
DMI_EXACT_MATCH(DMI_BOARD_VENDOR, "ayn"),
DMI_EXACT_MATCH(DMI_BOARD_NAME, "Loki Zero"),
},
.driver_data = (void *)ayn_loki_zero,
},
{},
};
/* Helper functions to handle EC read/write */
static int read_from_ec(u8 reg, int size, long *val)
{
int i;
int ret;
u8 buffer;
if (!lock_global_acpi_lock())
return -EBUSY;
*val = 0;
for (i = 0; i < size; i++) {
ret = ec_read(reg + i, &buffer);
if (ret)
return ret;
*val <<= i * 8;
*val += buffer;
}
if (!unlock_global_acpi_lock())
return -EBUSY;
return 0;
}
static int write_to_ec(u8 reg, u8 val)
{
int ret;
if (!lock_global_acpi_lock())
return -EBUSY;
ret = ec_write(reg, val);
if (!unlock_global_acpi_lock())
return -EBUSY;
return ret;
}
/* Thermal Sensor Functions*/
struct thermal_sensor {
char *name;
int reg;
};
static struct thermal_sensor thermal_sensors[] = {
{"Battery", AYN_SENSOR_BAT_TEMP_REG},
{"Motherboard", AYN_SENSOR_MB_TEMP_REG},
{"Charger IC", AYN_SENSOR_CHARGE_TEMP_REG},
{"vCore", AYN_SENSOR_VCORE_TEMP_REG},
{"CPU Core", AYN_SENSOR_PROC_TEMP_REG},
{0,}
};
static long thermal_sensor_temp(u8 reg, long *val)
{
long retval;
retval = read_from_ec(reg, 1, val);
if (retval)
return retval;
*val = *val * (long)1000; // convert from hwmon expected millidegree to degree
return retval;
};
static ssize_t thermal_sensor_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
int index;
long retval;
long val;
index = to_sensor_dev_attr(attr)->index;
retval = thermal_sensor_temp(thermal_sensors[index].reg, &val);
if (retval)
return retval;
return sprintf(buf, "%ld\n", val);
}
static ssize_t thermal_sensor_label(struct device *dev,
struct device_attribute *attr, char *buf)
{
int index;
index = to_sensor_dev_attr(attr)->index;
return sprintf(buf, "%s\n", thermal_sensors[index].name);
}
/* PWM mode functions */
/* Callbacks for pwm_auto_point attributes */
static ssize_t pwm_curve_store(struct device *dev,
struct device_attribute *attr, const char *buf,
size_t count)
{
int index;
int retval;
int val;
u8 reg;
retval = kstrtoint(buf, 0, &val);
if (retval)
return retval;
index = to_sensor_dev_attr(attr)->index;
switch (index) {
case 0:
reg = AYN_SENSOR_PWM_FAN_SPEED_1_REG;
break;
case 1:
reg = AYN_SENSOR_PWM_FAN_SPEED_2_REG;
break;
case 2:
reg = AYN_SENSOR_PWM_FAN_SPEED_3_REG;
break;
case 3:
reg = AYN_SENSOR_PWM_FAN_SPEED_4_REG;
break;
case 4:
reg = AYN_SENSOR_PWM_FAN_SPEED_5_REG;
break;
case 5:
reg = AYN_SENSOR_PWM_FAN_TEMP_1_REG;
break;
case 6:
reg = AYN_SENSOR_PWM_FAN_TEMP_2_REG;
break;
case 7:
reg = AYN_SENSOR_PWM_FAN_TEMP_3_REG;
break;
case 8:
reg = AYN_SENSOR_PWM_FAN_TEMP_4_REG;
break;
case 9:
reg = AYN_SENSOR_PWM_FAN_TEMP_5_REG;
break;
default:
return -EINVAL;
}
switch (index) {
case 0:
case 1:
case 2:
case 3:
case 4:
if (val < 0 || val > 255)
return -EINVAL;
val = val >> 1;
break;
case 5:
case 6:
case 7:
case 8:
case 9:
if (val < 0 || val > 100)
return -EINVAL;
break;
default:
return -EINVAL;
}
retval = write_to_ec(reg, val);
if (retval)
return retval;
return count;
}
static ssize_t pwm_curve_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
int index;
int retval;
long val;
u8 reg;
index = to_sensor_dev_attr(attr)->index;
switch (index) {
case 0:
reg = AYN_SENSOR_PWM_FAN_SPEED_1_REG;
break;
case 1:
reg = AYN_SENSOR_PWM_FAN_SPEED_2_REG;
break;
case 2:
reg = AYN_SENSOR_PWM_FAN_SPEED_3_REG;
break;
case 3:
reg = AYN_SENSOR_PWM_FAN_SPEED_4_REG;
break;
case 4:
reg = AYN_SENSOR_PWM_FAN_SPEED_5_REG;
break;
case 5:
reg = AYN_SENSOR_PWM_FAN_TEMP_1_REG;
break;
case 6:
reg = AYN_SENSOR_PWM_FAN_TEMP_2_REG;
break;
case 7:
reg = AYN_SENSOR_PWM_FAN_TEMP_3_REG;
break;
case 8:
reg = AYN_SENSOR_PWM_FAN_TEMP_4_REG;
break;
case 9:
reg = AYN_SENSOR_PWM_FAN_TEMP_5_REG;
break;
default:
return -EINVAL;
}
retval = read_from_ec(reg, 1, &val);
if (retval)
return retval;
switch (index) {
case 0:
case 1:
case 2:
case 3:
case 4:
val = val << 1;
break;
default:
break;
}
return sysfs_emit(buf, "%ld\n", val);
}
/* Manual provides direct control of the PWM */
static int ayn_pwm_manual(void)
{
return write_to_ec(AYN_SENSOR_PWM_FAN_ENABLE_REG, 0x00);
}
/* Auto provides EC full control of the PWM */
static int ayn_pwm_auto(void)
{
return write_to_ec(AYN_SENSOR_PWM_FAN_ENABLE_REG, 0x01);
}
/* User defined mode allows users to set a custom 5 point
* fan curve in the EC which uses the CPU temperature. */
static int ayn_pwm_user(void)
{
return write_to_ec(AYN_SENSOR_PWM_FAN_ENABLE_REG, 0x02);
}
/* Temperature sensor and fan curve attributes */
static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, thermal_sensor_show, NULL, 0);
static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, thermal_sensor_label, NULL, 0);
static SENSOR_DEVICE_ATTR(temp2_input, S_IRUGO, thermal_sensor_show, NULL, 1);
static SENSOR_DEVICE_ATTR(temp2_label, S_IRUGO, thermal_sensor_label, NULL, 1);
static SENSOR_DEVICE_ATTR(temp3_input, S_IRUGO, thermal_sensor_show, NULL, 2);
static SENSOR_DEVICE_ATTR(temp3_label, S_IRUGO, thermal_sensor_label, NULL, 2);
static SENSOR_DEVICE_ATTR(temp4_input, S_IRUGO, thermal_sensor_show, NULL, 3);
static SENSOR_DEVICE_ATTR(temp4_label, S_IRUGO, thermal_sensor_label, NULL, 3);
static SENSOR_DEVICE_ATTR(temp5_input, S_IRUGO, thermal_sensor_show, NULL, 4);
static SENSOR_DEVICE_ATTR(temp5_label, S_IRUGO, thermal_sensor_label, NULL, 4);
static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point1_pwm, pwm_curve, 0);
static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point2_pwm, pwm_curve, 1);
static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point3_pwm, pwm_curve, 2);
static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point4_pwm, pwm_curve, 3);
static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point5_pwm, pwm_curve, 4);
static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point1_temp, pwm_curve, 5);
static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point2_temp, pwm_curve, 6);
static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point3_temp, pwm_curve, 7);
static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point4_temp, pwm_curve, 8);
static SENSOR_DEVICE_ATTR_RW(pwm1_auto_point5_temp, pwm_curve, 9);
static struct attribute *ayn_sensors_attrs[] = {
&sensor_dev_attr_temp1_input.dev_attr.attr,
&sensor_dev_attr_temp1_label.dev_attr.attr,
&sensor_dev_attr_temp2_input.dev_attr.attr,
&sensor_dev_attr_temp2_label.dev_attr.attr,
&sensor_dev_attr_temp3_input.dev_attr.attr,
&sensor_dev_attr_temp3_label.dev_attr.attr,
&sensor_dev_attr_temp4_input.dev_attr.attr,
&sensor_dev_attr_temp4_label.dev_attr.attr,
&sensor_dev_attr_temp5_input.dev_attr.attr,
&sensor_dev_attr_temp5_label.dev_attr.attr,
&sensor_dev_attr_pwm1_auto_point1_pwm.dev_attr.attr,
&sensor_dev_attr_pwm1_auto_point2_pwm.dev_attr.attr,
&sensor_dev_attr_pwm1_auto_point3_pwm.dev_attr.attr,
&sensor_dev_attr_pwm1_auto_point4_pwm.dev_attr.attr,
&sensor_dev_attr_pwm1_auto_point5_pwm.dev_attr.attr,
&sensor_dev_attr_pwm1_auto_point1_temp.dev_attr.attr,
&sensor_dev_attr_pwm1_auto_point2_temp.dev_attr.attr,
&sensor_dev_attr_pwm1_auto_point3_temp.dev_attr.attr,
&sensor_dev_attr_pwm1_auto_point4_temp.dev_attr.attr,
&sensor_dev_attr_pwm1_auto_point5_temp.dev_attr.attr,
NULL,
};
ATTRIBUTE_GROUPS(ayn_sensors);
/* Callbacks for fan1/pwm attributes */
static umode_t ayn_ec_hwmon_is_visible(const void *drvdata,
enum hwmon_sensor_types type, u32 attr,
int channel)
{
switch (type) {
case hwmon_fan:
return 0444;
case hwmon_pwm:
return 0644;
default:
return 0;
}
}
static int ayn_platform_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *val)
{
int ret;
switch (type) {
case hwmon_fan:
switch (attr) {
case hwmon_fan_input:
return read_from_ec(AYN_SENSOR_PWM_FAN_SPEED_REG, 2, val);
default:
break;
}
break;
case hwmon_pwm:
switch (attr) {
case hwmon_pwm_enable:
ret = read_from_ec(AYN_SENSOR_PWM_FAN_ENABLE_REG, 1, val);
switch (*val) {
/* EC uses 0 for manual and 1 for automatic,
reflect hwmon usage instead */
case 0:
*val = 1;
break;
case 1:
*val = 0;
break;
default:
break;
}
return ret;
case hwmon_pwm_input:
ret = read_from_ec(AYN_SENSOR_PWM_FAN_SET_REG, 1, val);
if (ret)
return ret;
switch (model) {
case ayn_loki_max:
case ayn_loki_minipro:
case ayn_loki_zero:
*val = *val << 1; /* EC max value is 128 */
break;
default:
break;
}
return 0;
default:
break;
}
break;
default:
break;
}
return -EOPNOTSUPP;
}
static int ayn_platform_write(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long val)
{
switch (type) {
case hwmon_pwm:
switch (attr) {
case hwmon_pwm_enable:
if (val == 1)
return ayn_pwm_manual();
else if (val == 2)
return ayn_pwm_user();
else if (val == 0)
return ayn_pwm_auto();
return -EINVAL;
case hwmon_pwm_input:
if (val < 0 || val > 255)
return -EINVAL;
switch (model) {
case ayn_loki_max:
case ayn_loki_minipro:
case ayn_loki_zero:
val = val >> 1; /* EC max value is 128 */
break;
default:
break;
}
return write_to_ec(AYN_SENSOR_PWM_FAN_SET_REG, val);
default:
break;
}
break;
default:
break;
}
return -EOPNOTSUPP;
}
/* RGB LED Logic */
static int led_mode_write(int mode)
{
return write_to_ec(AYN_LED_MODE_REG, mode);
};
static ssize_t led_mode_store(struct device *dev, struct device_attribute *attr,
const char *buf, size_t count)
{
int val;
int retval;
int mode;
retval = kstrtoint(buf, 0, &val);
if (retval)
return retval;
if (val) {
mode = AYN_LED_MODE_WRITE;
} else {
mode = AYN_LED_MODE_BREATH;
}
retval = led_mode_write(mode);
if (retval)
return retval;
return count;
};
static ssize_t led_mode_show(struct device *dev, struct device_attribute *attr,
char *buf)
{
long mode;
int val;
int retval;
retval = read_from_ec(AYN_LED_MODE_REG, 1, &mode);
if (retval)
return retval;
switch (mode) {
case AYN_LED_MODE_BREATH:
val = breath;
break;
case AYN_LED_MODE_WRITE:
case AYN_LED_MODE_WRITE_ENABLED:
val = write;
break;
default:
break;
}
return sysfs_emit(buf, "%d\n", val);
};
static DEVICE_ATTR_RW(led_mode);
static int ayn_led_mc_brightness_write(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
struct led_classdev_mc *mc_cdev = lcdev_to_mccdev(led_cdev);
struct mc_subled s_led;
int i;
int retval;
int val;
for (i = 0; i < mc_cdev->num_colors; i++) {
s_led = mc_cdev->subled_info[i];
val = brightness * s_led.intensity / led_cdev->max_brightness;
retval = write_to_ec(s_led.channel, val);
if (retval)
return retval;
}
return write_to_ec(AYN_LED_MODE_REG, AYN_LED_MODE_WRITE);
};
static void ayn_led_mc_brightness_set(struct led_classdev *led_cdev,
enum led_brightness brightness)
{
long mode;
int retval;
retval = read_from_ec(AYN_LED_MODE_REG, 1, &mode);
if (retval)
return;
switch (mode) {
case AYN_LED_MODE_WRITE:
case AYN_LED_MODE_WRITE_ENABLED:
break;
default:
return;
}
led_cdev->brightness = brightness;
ayn_led_mc_brightness_write(led_cdev, brightness);
};
static enum led_brightness
ayn_led_mc_brightness_get(struct led_classdev *led_cdev)
{
return led_cdev->brightness;
};
static struct attribute *ayn_led_mc_attrs[] = {
&dev_attr_led_mode.attr,
NULL,
};
ATTRIBUTE_GROUPS(ayn_led_mc);
/* Initialization logic */
static const struct hwmon_channel_info *ayn_platform_sensors[] = {
HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT),
HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE),
NULL,
};
static const struct hwmon_ops ayn_ec_hwmon_ops = {
.is_visible = ayn_ec_hwmon_is_visible,
.read = ayn_platform_read,
.write = ayn_platform_write,
};
static const struct hwmon_chip_info ayn_ec_chip_info = {
.ops = &ayn_ec_hwmon_ops,
.info = ayn_platform_sensors,
};
struct mc_subled ayn_led_mc_subled_info[] = {
{
.color_index = LED_COLOR_ID_RED,
.brightness = 0,
.intensity = 0,
.channel = AYN_LED_MC_R_REG,
},
{
.color_index = LED_COLOR_ID_GREEN,
.brightness = 0,
.intensity = 0,
.channel = AYN_LED_MC_G_REG,
},
{
.color_index = LED_COLOR_ID_BLUE,
.brightness = 0,
.intensity = 0,
.channel = AYN_LED_MC_B_REG,
},
};
struct led_classdev_mc ayn_led_mc = {
.led_cdev = {
.name = "multicolor:chassis",
.brightness = 0,
.max_brightness = 255,
.brightness_set = ayn_led_mc_brightness_set,
.brightness_get = ayn_led_mc_brightness_get,
},
.num_colors = ARRAY_SIZE(ayn_led_mc_subled_info),
.subled_info = ayn_led_mc_subled_info,
};
static int ayn_platform_resume(struct platform_device *pdev)
{
struct led_classdev *led_cdev = &ayn_led_mc.led_cdev;
int retval;
retval = led_mode_write(AYN_LED_MODE_WRITE);
if (retval)
return retval;
retval = ayn_led_mc_brightness_write(led_cdev, led_cdev->brightness);
if (retval)
return retval;
return 0;
}
static int ayn_platform_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct device *hwdev;
int retval;
retval = devm_led_classdev_multicolor_register(dev, &ayn_led_mc);
if (retval)
return retval;
struct led_classdev *led_cdev = &ayn_led_mc.led_cdev;
retval = devm_device_add_group(ayn_led_mc.led_cdev.dev, *ayn_led_mc_groups);
if (retval)
return retval;
retval = led_mode_write(AYN_LED_MODE_WRITE);
if (retval)
return retval;
retval = ayn_led_mc_brightness_write(led_cdev, 0);
if (retval)
return retval;
hwdev = devm_hwmon_device_register_with_info(
dev, "aynec", NULL, &ayn_ec_chip_info, ayn_sensors_groups);
return PTR_ERR_OR_ZERO(hwdev);
}
static struct platform_driver ayn_platform_driver = {
.driver = {
.name = "ayn-platform",
},
.probe = ayn_platform_probe,
.resume = ayn_platform_resume,
};
static struct platform_device *ayn_platform_device;
static int __init ayn_platform_init(void)
{
ayn_platform_device = platform_create_bundle(
&ayn_platform_driver, ayn_platform_probe, NULL, 0, NULL, 0);
return PTR_ERR_OR_ZERO(ayn_platform_device);
}
static void __exit ayn_platform_exit(void)
{
platform_device_unregister(ayn_platform_device);
platform_driver_unregister(&ayn_platform_driver);
}
MODULE_DEVICE_TABLE(dmi, dmi_table);
module_init(ayn_platform_init);
module_exit(ayn_platform_exit);
MODULE_AUTHOR("Derek John Clark <derekjohn.clark@gmail.com>");
MODULE_DESCRIPTION(
"Platform driver that handles EC sensors of Ayn x86 devices");
MODULE_LICENSE("GPL");