]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blame - src/patches/linux/linux-4.14-apu_leds.patch
kernel: apu leds: add more id's
[people/pmueller/ipfire-2.x.git] / src / patches / linux / linux-4.14-apu_leds.patch
CommitLineData
6957b699
AF
1diff -Naur linux-4.14.102.org/arch/x86/Kconfig linux-4.14.102/arch/x86/Kconfig
2--- linux-4.14.102.org/arch/x86/Kconfig 2019-02-20 10:20:56.000000000 +0100
3+++ linux-4.14.102/arch/x86/Kconfig 2019-02-22 17:56:37.185202293 +0100
17872019 4@@ -2715,6 +2715,7 @@
e583643a
AF
5 - AC adapter status updates
6 - Battery status updates
7
4d4f36ef
AF
8+
9 config ALIX
10 bool "PCEngines ALIX System Support (LED setup)"
11 select GPIOLIB
17872019 12@@ -2753,6 +2754,18 @@
4d4f36ef
AF
13
14 endif # X86_32
15
e583643a
AF
16+config APULED
17+ bool "PCEngines APU Led Support"
18+ depends on DMI
19+ ---help---
545c15b0
AF
20+ This option enables system support for the PCEngines APU1.
21+
22+config APU2LED
17872019 23+ bool "PCEngines APU2/3/4 Led Support"
545c15b0
AF
24+ depends on DMI
25+ ---help---
17872019 26+ This option enables system support for the PCEngines APU2/3/4.
e583643a 27+
4d4f36ef
AF
28 config AMD_NB
29 def_bool y
30 depends on CPU_SUP_AMD && PCI
6957b699
AF
31diff -Naur linux-4.14.102.org/arch/x86/platform/apu/apu2-led.c linux-4.14.102/arch/x86/platform/apu/apu2-led.c
32--- linux-4.14.102.org/arch/x86/platform/apu/apu2-led.c 1970-01-01 01:00:00.000000000 +0100
33+++ linux-4.14.102/arch/x86/platform/apu/apu2-led.c 2019-02-22 17:58:52.795665744 +0100
34@@ -0,0 +1,185 @@
545c15b0 35+/*
17872019 36+ * LEDs driver for PCEngines apu2/3/4
545c15b0
AF
37+ *
38+ * this basic driver only set the output, configuration
39+ * has already done by bios/coreboot.
40+ * suspend/resume was not tested because IPFire not use it.
41+ *
42+ * Copyright (C) 2016 Arne Fitzenreiter <arne_f@ipfire.org> ,
43+ * based on Christian Herzog's apu_led.
44+ *
45+ * This program is free software; you can redistribute it and/or modify
46+ * it under the terms of the GNU General Public License version 2 as
47+ * published by the Free Software Foundation.
48+ */
49+
50+#include <linux/kernel.h>
51+#include <linux/module.h>
52+#include <linux/init.h>
53+#include <linux/platform_device.h>
54+#include <linux/leds.h>
55+#include <linux/err.h>
56+#include <asm/io.h>
57+#include <linux/dmi.h>
58+
59+#define DRVNAME "apu2-led"
60+#define BASEADDR (0xFED81610)
61+
62+static struct platform_device *pdev;
63+unsigned int *apu2_led_p1;
64+unsigned int *apu2_led_p2;
65+unsigned int *apu2_led_p3;
66+
67+static void apu2_led_set_1(struct led_classdev *led_cdev,
68+ enum led_brightness value) {
69+ if (value)
70+ iowrite32((ioread32(apu2_led_p1)&~BIT(22)), apu2_led_p1);
71+ else
72+ iowrite32((ioread32(apu2_led_p1)|BIT(22)), apu2_led_p1);
73+}
74+
75+static void apu2_led_set_2(struct led_classdev *led_cdev,
76+ enum led_brightness value) {
77+ if (value)
78+ iowrite32((ioread32(apu2_led_p2)&~BIT(22)), apu2_led_p2);
79+ else
80+ iowrite32((ioread32(apu2_led_p2)|BIT(22)), apu2_led_p2);
81+}
82+
83+static void apu2_led_set_3(struct led_classdev *led_cdev,
84+ enum led_brightness value) {
85+ if (value)
86+ iowrite32((ioread32(apu2_led_p3)&~BIT(22)), apu2_led_p3);
87+ else
88+ iowrite32((ioread32(apu2_led_p3)|BIT(22)), apu2_led_p3);
89+}
90+
91+static struct led_classdev apu2_led_1 = {
92+ .name = "apu:1",
93+ .brightness_set = apu2_led_set_1,
94+};
95+
96+static struct led_classdev apu2_led_2 = {
97+ .name = "apu:2",
98+ .brightness_set = apu2_led_set_2,
99+};
100+
101+static struct led_classdev apu2_led_3 = {
102+ .name = "apu:3",
103+ .brightness_set = apu2_led_set_3,
104+};
105+
106+
107+#ifdef CONFIG_PM
108+static int apu2_led_suspend(struct platform_device *dev,
109+ pm_message_t state)
110+{
111+ led_classdev_suspend(&apu2_led_1);
112+ led_classdev_suspend(&apu2_led_2);
113+ led_classdev_suspend(&apu2_led_3);
114+ return 0;
115+}
116+
117+static int apu2_led_resume(struct platform_device *dev)
118+{
119+ led_classdev_resume(&apu2_led_1);
120+ led_classdev_resume(&apu2_led_2);
121+ led_classdev_resume(&apu2_led_3);
122+ return 0;
123+}
124+#else
125+#define apu2_led_suspend NULL
126+#define apu2_led_resume NULL
127+#endif
128+
129+static int apu2_led_probe(struct platform_device *pdev)
130+{
131+ int ret;
132+
133+ ret = led_classdev_register(&pdev->dev, &apu2_led_1);
134+ if (ret == 0)
135+ {
136+ ret = led_classdev_register(&pdev->dev, &apu2_led_2);
137+ if (ret >= 0)
138+ {
139+ ret = led_classdev_register(&pdev->dev, &apu2_led_3);
140+ if (ret < 0)
141+ led_classdev_unregister(&apu2_led_2);
142+ }
143+ if (ret < 0)
144+ led_classdev_unregister(&apu2_led_1);
145+ }
146+ return ret;
147+}
148+
149+static int apu2_led_remove(struct platform_device *pdev)
150+{
151+ led_classdev_unregister(&apu2_led_1);
152+ led_classdev_unregister(&apu2_led_2);
153+ led_classdev_unregister(&apu2_led_3);
154+ return 0;
155+}
156+
157+static struct platform_driver apu2_led_driver = {
158+ .probe = apu2_led_probe,
159+ .remove = apu2_led_remove,
160+ .suspend = apu2_led_suspend,
161+ .resume = apu2_led_resume,
162+ .driver = {
163+ .name = DRVNAME,
164+ .owner = THIS_MODULE,
165+ },
166+};
167+
168+static int __init apu2_led_init(void)
169+{
170+ int ret=0;
171+ const char *vendor, *product;
172+
173+ vendor = dmi_get_system_info(DMI_SYS_VENDOR);
174+ if (!vendor || strcmp(vendor, "PC Engines"))
175+ goto out;
176+
177+ product = dmi_get_system_info(DMI_PRODUCT_NAME);
17872019
AF
178+ if (!product || ( strcmp(product, "PC Engines apu2") &&
179+ strcmp(product, "PC Engines apu3") &&
180+ strcmp(product, "PC Engines apu4") &&
6957b699
AF
181+ strcmp(product, "apu2") &&
182+ strcmp(product, "apu3") &&
183+ strcmp(product, "apu4") ) )
545c15b0
AF
184+ goto out;
185+
186+ printk(KERN_INFO "%s: system is recognized as \"%s %s\"\n",
187+ KBUILD_MODNAME, vendor, product);
188+
189+ ret = platform_driver_register(&apu2_led_driver);
190+ if (ret < 0)
191+ goto out;
192+
193+ pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
194+ if (IS_ERR(pdev)) {
195+ ret = PTR_ERR(pdev);
196+ platform_driver_unregister(&apu2_led_driver);
197+ goto out;
198+ }
199+
200+ apu2_led_p1 = ioremap(BASEADDR, 4);
201+ apu2_led_p2 = ioremap(BASEADDR+4, 4);
202+ apu2_led_p3 = ioremap(BASEADDR+8, 4);
203+
204+out:
205+ return ret;
206+}
207+
208+static void __exit apu2_led_exit(void)
209+{
210+ platform_device_unregister(pdev);
211+ platform_driver_unregister(&apu2_led_driver);
212+}
213+
214+module_init(apu2_led_init);
215+module_exit(apu2_led_exit);
216+
217+MODULE_AUTHOR("Arne Fitzenreiter");
17872019 218+MODULE_DESCRIPTION("PCEngines apu2/3/4 LED driver");
545c15b0 219+MODULE_LICENSE("GPL");
6957b699
AF
220diff -Naur linux-4.14.102.org/arch/x86/platform/apu/apu-led.c linux-4.14.102/arch/x86/platform/apu/apu-led.c
221--- linux-4.14.102.org/arch/x86/platform/apu/apu-led.c 1970-01-01 01:00:00.000000000 +0100
222+++ linux-4.14.102/arch/x86/platform/apu/apu-led.c 2019-02-22 17:57:45.062504777 +0100
223@@ -0,0 +1,183 @@
e583643a
AF
224+/*
225+ * LEDs driver for PCEngines apu
226+ *
227+ * Copyright (C) 2013 Christian Herzog <daduke@daduke.org>, based on
228+ * Petr Leibman's leds-alix
229+ * Hardware presence check added by Arne Fitzenreiter <arne_f@ipfire.org>
230+ * Based on leds-wrap.c
231+ * Hardware info taken from http://www.dpie.com/manuals/miniboards/kontron/KTD-S0043-0_KTA55_SoftwareGuide.pdf
232+ *
233+ * This program is free software; you can redistribute it and/or modify
234+ * it under the terms of the GNU General Public License version 2 as
235+ * published by the Free Software Foundation.
236+ */
237+
238+#include <linux/kernel.h>
239+#include <linux/module.h>
240+#include <linux/init.h>
241+#include <linux/platform_device.h>
242+#include <linux/leds.h>
243+#include <linux/err.h>
244+#include <asm/io.h>
245+#include <linux/dmi.h>
246+
247+#define DRVNAME "apu-led"
248+#define BASEADDR (0xFED801BD)
249+#define LEDON (0x8)
250+#define LEDOFF (0xC8)
251+
252+static struct platform_device *pdev;
545c15b0
AF
253+unsigned int *apu_led_p1;
254+unsigned int *apu_led_p2;
255+unsigned int *apu_led_p3;
e583643a
AF
256+
257+static void apu_led_set_1(struct led_classdev *led_cdev,
258+ enum led_brightness value) {
259+ if (value)
545c15b0 260+ iowrite8(LEDON, apu_led_p1);
e583643a 261+ else
545c15b0 262+ iowrite8(LEDOFF, apu_led_p1);
e583643a
AF
263+}
264+
265+static void apu_led_set_2(struct led_classdev *led_cdev,
266+ enum led_brightness value) {
267+ if (value)
545c15b0 268+ iowrite8(LEDON, apu_led_p2);
e583643a 269+ else
545c15b0 270+ iowrite8(LEDOFF, apu_led_p2);
e583643a
AF
271+}
272+
273+static void apu_led_set_3(struct led_classdev *led_cdev,
274+ enum led_brightness value) {
275+ if (value)
545c15b0 276+ iowrite8(LEDON, apu_led_p3);
e583643a 277+ else
545c15b0 278+ iowrite8(LEDOFF, apu_led_p3);
e583643a
AF
279+}
280+
281+static struct led_classdev apu_led_1 = {
282+ .name = "apu:1",
283+ .brightness_set = apu_led_set_1,
284+};
285+
286+static struct led_classdev apu_led_2 = {
287+ .name = "apu:2",
288+ .brightness_set = apu_led_set_2,
289+};
290+
291+static struct led_classdev apu_led_3 = {
292+ .name = "apu:3",
293+ .brightness_set = apu_led_set_3,
294+};
295+
296+
297+#ifdef CONFIG_PM
298+static int apu_led_suspend(struct platform_device *dev,
299+ pm_message_t state)
300+{
301+ led_classdev_suspend(&apu_led_1);
302+ led_classdev_suspend(&apu_led_2);
303+ led_classdev_suspend(&apu_led_3);
304+ return 0;
305+}
306+
307+static int apu_led_resume(struct platform_device *dev)
308+{
309+ led_classdev_resume(&apu_led_1);
310+ led_classdev_resume(&apu_led_2);
311+ led_classdev_resume(&apu_led_3);
312+ return 0;
313+}
314+#else
315+#define apu_led_suspend NULL
316+#define apu_led_resume NULL
317+#endif
318+
319+static int apu_led_probe(struct platform_device *pdev)
320+{
321+ int ret;
322+
323+ ret = led_classdev_register(&pdev->dev, &apu_led_1);
324+ if (ret == 0)
325+ {
326+ ret = led_classdev_register(&pdev->dev, &apu_led_2);
327+ if (ret >= 0)
328+ {
329+ ret = led_classdev_register(&pdev->dev, &apu_led_3);
330+ if (ret < 0)
331+ led_classdev_unregister(&apu_led_2);
332+ }
333+ if (ret < 0)
334+ led_classdev_unregister(&apu_led_1);
335+ }
336+ return ret;
337+}
338+
339+static int apu_led_remove(struct platform_device *pdev)
340+{
341+ led_classdev_unregister(&apu_led_1);
342+ led_classdev_unregister(&apu_led_2);
343+ led_classdev_unregister(&apu_led_3);
344+ return 0;
345+}
346+
347+static struct platform_driver apu_led_driver = {
348+ .probe = apu_led_probe,
349+ .remove = apu_led_remove,
350+ .suspend = apu_led_suspend,
351+ .resume = apu_led_resume,
352+ .driver = {
353+ .name = DRVNAME,
354+ .owner = THIS_MODULE,
355+ },
356+};
357+
358+static int __init apu_led_init(void)
359+{
360+ int ret=0;
361+ const char *vendor, *product;
362+
363+ vendor = dmi_get_system_info(DMI_SYS_VENDOR);
364+ if (!vendor || strcmp(vendor, "PC Engines"))
365+ goto out;
366+
367+ product = dmi_get_system_info(DMI_PRODUCT_NAME);
6957b699
AF
368+ if (!product || ( strcmp(product, "APU") &&
369+ strcmp(product, "apu1") &&
370+ strcmp(product, "PC Engines apu1") ))
e583643a
AF
371+ goto out;
372+
373+ printk(KERN_INFO "%s: system is recognized as \"%s %s\"\n",
374+ KBUILD_MODNAME, vendor, product);
375+
376+ ret = platform_driver_register(&apu_led_driver);
377+ if (ret < 0)
378+ goto out;
379+
380+ pdev = platform_device_register_simple(DRVNAME, -1, NULL, 0);
381+ if (IS_ERR(pdev)) {
382+ ret = PTR_ERR(pdev);
383+ platform_driver_unregister(&apu_led_driver);
384+ goto out;
385+ }
386+
545c15b0
AF
387+ apu_led_p1 = ioremap(BASEADDR, 1);
388+ apu_led_p2 = ioremap(BASEADDR+1, 1);
389+ apu_led_p3 = ioremap(BASEADDR+2, 1);
e583643a
AF
390+
391+out:
392+ return ret;
393+}
394+
395+static void __exit apu_led_exit(void)
396+{
397+ platform_device_unregister(pdev);
398+ platform_driver_unregister(&apu_led_driver);
399+}
400+
401+module_init(apu_led_init);
402+module_exit(apu_led_exit);
403+
404+MODULE_AUTHOR("Christian Herzog");
405+MODULE_DESCRIPTION("PCEngines apu LED driver");
406+MODULE_LICENSE("GPL");
6957b699
AF
407diff -Naur linux-4.14.102.org/arch/x86/platform/apu/Makefile linux-4.14.102/arch/x86/platform/apu/Makefile
408--- linux-4.14.102.org/arch/x86/platform/apu/Makefile 1970-01-01 01:00:00.000000000 +0100
409+++ linux-4.14.102/arch/x86/platform/apu/Makefile 2019-02-22 17:56:37.185202293 +0100
545c15b0 410@@ -0,0 +1,2 @@
e583643a 411+obj-$(CONFIG_APULED) += apu-led.o
545c15b0 412+obj-$(CONFIG_APU2LED) += apu2-led.o
6957b699
AF
413diff -Naur linux-4.14.102.org/arch/x86/platform/Makefile linux-4.14.102/arch/x86/platform/Makefile
414--- linux-4.14.102.org/arch/x86/platform/Makefile 2019-02-20 10:20:56.000000000 +0100
415+++ linux-4.14.102/arch/x86/platform/Makefile 2019-02-22 17:56:37.185202293 +0100
17872019
AF
416@@ -1,5 +1,6 @@
417 # SPDX-License-Identifier: GPL-2.0
e583643a
AF
418 # Platform specific code goes here
419+obj-y += apu/
91648bd1 420 obj-y += atom/
e583643a
AF
421 obj-y += ce4100/
422 obj-y += efi/