2331e29fd803e66236b2ad4f3848a09da1811052
[openwrt/staging/nbd.git] /
1 From eb25cb9956cc9384b7fa0d75dec908c9fac8c444 Mon Sep 17 00:00:00 2001
2 From: Stephan Linz <linz@li-pro.net>
3 Date: Fri, 10 Jun 2016 07:59:56 +0200
4 Subject: [PATCH] leds: convert IDE trigger to common disk trigger
5 MIME-Version: 1.0
6 Content-Type: text/plain; charset=UTF-8
7 Content-Transfer-Encoding: 8bit
8
9 This patch converts the IDE specific LED trigger to a generic disk
10 activity LED trigger. The libata core is now a trigger source just
11 like before the IDE disk driver. It's merely a replacement of the
12 string ide by disk.
13
14 The patch is taken from http://dev.gentoo.org/~josejx/ata.patch and is
15 widely used by any ibook/powerbook owners with great satisfaction.
16 Likewise, it is very often used successfully on different ARM platforms.
17
18 Unlike the original patch, the existing 'ide-disk' trigger is still
19 available for backward compatibility. That reduce the amount of patches
20 in affected device trees out of the mainline kernel. For further
21 development, the new name 'disk-activity' should be used.
22
23 Cc: Joseph Jezak <josejx@gentoo.org>
24 Cc: Jörg Sommer <joerg@alea.gnuu.de>
25 Cc: Richard Purdie <rpurdie@rpsys.net>
26 Signed-off-by: Stephan Linz <linz@li-pro.net>
27 Signed-off-by: Jacek Anaszewski <j.anaszewski@samsung.com>
28 ---
29 drivers/ata/libata-core.c | 4 ++++
30 drivers/ide/ide-disk.c | 2 +-
31 drivers/leds/trigger/Kconfig | 8 +++----
32 drivers/leds/trigger/Makefile | 2 +-
33 drivers/leds/trigger/ledtrig-disk.c | 41 +++++++++++++++++++++++++++++++++
34 drivers/leds/trigger/ledtrig-ide-disk.c | 36 -----------------------------
35 include/linux/leds.h | 6 ++---
36 8 files changed, 55 insertions(+), 46 deletions(-)
37 create mode 100644 drivers/leds/trigger/ledtrig-disk.c
38 delete mode 100644 drivers/leds/trigger/ledtrig-ide-disk.c
39
40 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
41 index 6be7770..2eca572 100644
42 --- a/drivers/ata/libata-core.c
43 +++ b/drivers/ata/libata-core.c
44 @@ -69,6 +69,7 @@
45 #include <asm/unaligned.h>
46 #include <linux/cdrom.h>
47 #include <linux/ratelimit.h>
48 +#include <linux/leds.h>
49 #include <linux/pm_runtime.h>
50 #include <linux/platform_device.h>
51
52 @@ -5072,6 +5073,9 @@ void ata_qc_complete(struct ata_queued_cmd *qc)
53 {
54 struct ata_port *ap = qc->ap;
55
56 + /* Trigger the LED (if available) */
57 + ledtrig_disk_activity();
58 +
59 /* XXX: New EH and old EH use different mechanisms to
60 * synchronize EH with regular execution path.
61 *
62 diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
63 index 05dbcce..5ceb176 100644
64 --- a/drivers/ide/ide-disk.c
65 +++ b/drivers/ide/ide-disk.c
66 @@ -186,7 +186,7 @@ static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
67 BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED);
68 BUG_ON(rq->cmd_type != REQ_TYPE_FS);
69
70 - ledtrig_ide_activity();
71 + ledtrig_disk_activity();
72
73 pr_debug("%s: %sing: block=%llu, sectors=%u\n",
74 drive->name, rq_data_dir(rq) == READ ? "read" : "writ",
75 diff --git a/drivers/leds/trigger/Kconfig b/drivers/leds/trigger/Kconfig
76 index 9893d91..3f9ddb9 100644
77 --- a/drivers/leds/trigger/Kconfig
78 +++ b/drivers/leds/trigger/Kconfig
79 @@ -33,12 +33,12 @@ config LEDS_TRIGGER_ONESHOT
80
81 If unsure, say Y.
82
83 -config LEDS_TRIGGER_IDE_DISK
84 - bool "LED IDE Disk Trigger"
85 - depends on IDE_GD_ATA
86 +config LEDS_TRIGGER_DISK
87 + bool "LED Disk Trigger"
88 + depends on IDE_GD_ATA || ATA
89 depends on LEDS_TRIGGERS
90 help
91 - This allows LEDs to be controlled by IDE disk activity.
92 + This allows LEDs to be controlled by disk activity.
93 If unsure, say Y.
94
95 config LEDS_TRIGGER_MTD
96 diff --git a/drivers/leds/trigger/Makefile b/drivers/leds/trigger/Makefile
97 index 8cc64a4..a72c43c 100644
98 --- a/drivers/leds/trigger/Makefile
99 +++ b/drivers/leds/trigger/Makefile
100 @@ -1,6 +1,6 @@
101 obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
102 obj-$(CONFIG_LEDS_TRIGGER_ONESHOT) += ledtrig-oneshot.o
103 -obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
104 +obj-$(CONFIG_LEDS_TRIGGER_DISK) += ledtrig-disk.o
105 obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
106 obj-$(CONFIG_LEDS_TRIGGER_BACKLIGHT) += ledtrig-backlight.o
107 obj-$(CONFIG_LEDS_TRIGGER_GPIO) += ledtrig-gpio.o
108 diff --git a/drivers/leds/trigger/ledtrig-disk.c b/drivers/leds/trigger/ledtrig-disk.c
109 new file mode 100644
110 index 0000000..cd525b4
111 --- /dev/null
112 +++ b/drivers/leds/trigger/ledtrig-disk.c
113 @@ -0,0 +1,41 @@
114 +/*
115 + * LED Disk Activity Trigger
116 + *
117 + * Copyright 2006 Openedhand Ltd.
118 + *
119 + * Author: Richard Purdie <rpurdie@openedhand.com>
120 + *
121 + * This program is free software; you can redistribute it and/or modify
122 + * it under the terms of the GNU General Public License version 2 as
123 + * published by the Free Software Foundation.
124 + *
125 + */
126 +
127 +#include <linux/kernel.h>
128 +#include <linux/init.h>
129 +#include <linux/leds.h>
130 +
131 +#define BLINK_DELAY 30
132 +
133 +DEFINE_LED_TRIGGER(ledtrig_disk);
134 +DEFINE_LED_TRIGGER(ledtrig_ide);
135 +
136 +void ledtrig_disk_activity(void)
137 +{
138 + unsigned long blink_delay = BLINK_DELAY;
139 +
140 + led_trigger_blink_oneshot(ledtrig_disk,
141 + &blink_delay, &blink_delay, 0);
142 + led_trigger_blink_oneshot(ledtrig_ide,
143 + &blink_delay, &blink_delay, 0);
144 +}
145 +EXPORT_SYMBOL(ledtrig_disk_activity);
146 +
147 +static int __init ledtrig_disk_init(void)
148 +{
149 + led_trigger_register_simple("disk-activity", &ledtrig_disk);
150 + led_trigger_register_simple("ide-disk", &ledtrig_ide);
151 +
152 + return 0;
153 +}
154 +device_initcall(ledtrig_disk_init);
155 diff --git a/drivers/leds/trigger/ledtrig-ide-disk.c b/drivers/leds/trigger/ledtrig-ide-disk.c
156 deleted file mode 100644
157 index 15123d3..0000000
158 --- a/drivers/leds/trigger/ledtrig-ide-disk.c 2016-07-11 18:31:24.000000000 +0200
159 +++ /dev/null 2016-08-08 12:56:55.887448160 +0200
160 @@ -1,47 +0,0 @@
161 -/*
162 - * LED IDE-Disk Activity Trigger
163 - *
164 - * Copyright 2006 Openedhand Ltd.
165 - *
166 - * Author: Richard Purdie <rpurdie@openedhand.com>
167 - *
168 - * This program is free software; you can redistribute it and/or modify
169 - * it under the terms of the GNU General Public License version 2 as
170 - * published by the Free Software Foundation.
171 - *
172 - */
173 -
174 -#include <linux/module.h>
175 -#include <linux/kernel.h>
176 -#include <linux/init.h>
177 -#include <linux/leds.h>
178 -
179 -#define BLINK_DELAY 30
180 -
181 -DEFINE_LED_TRIGGER(ledtrig_ide);
182 -static unsigned long ide_blink_delay = BLINK_DELAY;
183 -
184 -void ledtrig_ide_activity(void)
185 -{
186 - led_trigger_blink_oneshot(ledtrig_ide,
187 - &ide_blink_delay, &ide_blink_delay, 0);
188 -}
189 -EXPORT_SYMBOL(ledtrig_ide_activity);
190 -
191 -static int __init ledtrig_ide_init(void)
192 -{
193 - led_trigger_register_simple("ide-disk", &ledtrig_ide);
194 - return 0;
195 -}
196 -
197 -static void __exit ledtrig_ide_exit(void)
198 -{
199 - led_trigger_unregister_simple(ledtrig_ide);
200 -}
201 -
202 -module_init(ledtrig_ide_init);
203 -module_exit(ledtrig_ide_exit);
204 -
205 -MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>");
206 -MODULE_DESCRIPTION("LED IDE Disk Activity Trigger");
207 -MODULE_LICENSE("GPL");
208 diff --git a/include/linux/leds.h b/include/linux/leds.h
209 index e5e7f2e..0aa3701 100644
210 --- a/include/linux/leds.h
211 +++ b/include/linux/leds.h
212 @@ -325,10 +325,10 @@ static inline void *led_get_trigger_data(struct led_classdev *led_cdev)
213 #endif /* CONFIG_LEDS_TRIGGERS */
214
215 /* Trigger specific functions */
216 -#ifdef CONFIG_LEDS_TRIGGER_IDE_DISK
217 -extern void ledtrig_ide_activity(void);
218 +#ifdef CONFIG_LEDS_TRIGGER_DISK
219 +extern void ledtrig_disk_activity(void);
220 #else
221 -static inline void ledtrig_ide_activity(void) {}
222 +static inline void ledtrig_disk_activity(void) {}
223 #endif
224
225 #ifdef CONFIG_LEDS_TRIGGER_MTD
226 --
227 2.8.1
228