Skip to content

Commit 8de5348

Browse files
author
Boris Brezillon
committed
Merge branch 'mtd-nand-trigger' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds into nand/next
Pull leds-trigger changes from Jacek Anaszewski. Create a generic mtd led-trigger to replace the exisitng nand led-trigger implementation. * 'mtd-nand-trigger' of git://git.kernel.org/pub/scm/linux/kernel/git/j.anaszewski/linux-leds: mtd: Hook I/O activity to the MTD LED trigger mtd: nand: Remove the "nand-disk" LED trigger leds: trigger: Introduce a MTD (NAND/NOR) trigger mtd: Uninline mtd_write_oob and move it to mtdcore.c leds: trigger: Introduce a kernel panic LED trigger
2 parents 4217ff3 + fea728c commit 8de5348

8 files changed

Lines changed: 119 additions & 39 deletions

File tree

‎drivers/leds/trigger/Kconfig‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,14 @@ config LEDS_TRIGGER_IDE_DISK
4141
This allows LEDs to be controlled by IDE disk activity.
4242
If unsure, say Y.
4343

44+
config LEDS_TRIGGER_MTD
45+
bool "LED MTD (NAND/NOR) Trigger"
46+
depends on MTD
47+
depends on LEDS_TRIGGERS
48+
help
49+
This allows LEDs to be controlled by MTD activity.
50+
If unsure, say N.
51+
4452
config LEDS_TRIGGER_HEARTBEAT
4553
tristate "LED Heartbeat Trigger"
4654
depends on LEDS_TRIGGERS
@@ -108,4 +116,11 @@ config LEDS_TRIGGER_CAMERA
108116
This enables direct flash/torch on/off by the driver, kernel space.
109117
If unsure, say Y.
110118

119+
config LEDS_TRIGGER_PANIC
120+
bool "LED Panic Trigger"
121+
depends on LEDS_TRIGGERS
122+
help
123+
This allows LEDs to be configured to blink on a kernel panic.
124+
If unsure, say Y.
125+
111126
endif # LEDS_TRIGGERS

‎drivers/leds/trigger/Makefile‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o
22
obj-$(CONFIG_LEDS_TRIGGER_ONESHOT) += ledtrig-oneshot.o
33
obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o
4+
obj-$(CONFIG_LEDS_TRIGGER_MTD) += ledtrig-mtd.o
45
obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o
56
obj-$(CONFIG_LEDS_TRIGGER_BACKLIGHT) += ledtrig-backlight.o
67
obj-$(CONFIG_LEDS_TRIGGER_GPIO) += ledtrig-gpio.o
78
obj-$(CONFIG_LEDS_TRIGGER_CPU) += ledtrig-cpu.o
89
obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o
910
obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT) += ledtrig-transient.o
1011
obj-$(CONFIG_LEDS_TRIGGER_CAMERA) += ledtrig-camera.o
12+
obj-$(CONFIG_LEDS_TRIGGER_PANIC) += ledtrig-panic.o

‎drivers/leds/trigger/ledtrig-mtd.c‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
/*
2+
* LED MTD trigger
3+
*
4+
* Copyright 2016 Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
5+
*
6+
* Based on LED IDE-Disk Activity Trigger
7+
*
8+
* Copyright 2006 Openedhand Ltd.
9+
*
10+
* Author: Richard Purdie <rpurdie@openedhand.com>
11+
*
12+
* This program is free software; you can redistribute it and/or modify
13+
* it under the terms of the GNU General Public License version 2 as
14+
* published by the Free Software Foundation.
15+
*
16+
*/
17+
18+
#include <linux/kernel.h>
19+
#include <linux/init.h>
20+
#include <linux/leds.h>
21+
22+
#define BLINK_DELAY 30
23+
24+
DEFINE_LED_TRIGGER(ledtrig_mtd);
25+
DEFINE_LED_TRIGGER(ledtrig_nand);
26+
27+
void ledtrig_mtd_activity(void)
28+
{
29+
unsigned long blink_delay = BLINK_DELAY;
30+
31+
led_trigger_blink_oneshot(ledtrig_mtd,
32+
&blink_delay, &blink_delay, 0);
33+
led_trigger_blink_oneshot(ledtrig_nand,
34+
&blink_delay, &blink_delay, 0);
35+
}
36+
EXPORT_SYMBOL(ledtrig_mtd_activity);
37+
38+
static int __init ledtrig_mtd_init(void)
39+
{
40+
led_trigger_register_simple("mtd", &ledtrig_mtd);
41+
led_trigger_register_simple("nand-disk", &ledtrig_nand);
42+
43+
return 0;
44+
}
45+
device_initcall(ledtrig_mtd_init);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Kernel Panic LED Trigger
3+
*
4+
* Copyright 2016 Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
5+
*
6+
* This program is free software; you can redistribute it and/or modify
7+
* it under the terms of the GNU General Public License version 2 as
8+
* published by the Free Software Foundation.
9+
*
10+
*/
11+
12+
#include <linux/kernel.h>
13+
#include <linux/init.h>
14+
#include <linux/leds.h>
15+
16+
static struct led_trigger *trigger;
17+
18+
static long led_panic_blink(int state)
19+
{
20+
led_trigger_event(trigger, state ? LED_FULL : LED_OFF);
21+
return 0;
22+
}
23+
24+
static int __init ledtrig_panic_init(void)
25+
{
26+
led_trigger_register_simple("panic", &trigger);
27+
panic_blink = led_panic_blink;
28+
return 0;
29+
}
30+
device_initcall(ledtrig_panic_init);

‎drivers/mtd/mtdcore.c‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <linux/slab.h>
4141
#include <linux/reboot.h>
4242
#include <linux/kconfig.h>
43+
#include <linux/leds.h>
4344

4445
#include <linux/mtd/mtd.h>
4546
#include <linux/mtd/partitions.h>
@@ -862,6 +863,7 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr)
862863
mtd_erase_callback(instr);
863864
return 0;
864865
}
866+
ledtrig_mtd_activity();
865867
return mtd->_erase(mtd, instr);
866868
}
867869
EXPORT_SYMBOL_GPL(mtd_erase);
@@ -925,6 +927,7 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen,
925927
if (!len)
926928
return 0;
927929

930+
ledtrig_mtd_activity();
928931
/*
929932
* In the absence of an error, drivers return a non-negative integer
930933
* representing the maximum number of bitflips that were corrected on
@@ -949,6 +952,7 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
949952
return -EROFS;
950953
if (!len)
951954
return 0;
955+
ledtrig_mtd_activity();
952956
return mtd->_write(mtd, to, len, retlen, buf);
953957
}
954958
EXPORT_SYMBOL_GPL(mtd_write);
@@ -982,6 +986,8 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
982986
ops->retlen = ops->oobretlen = 0;
983987
if (!mtd->_read_oob)
984988
return -EOPNOTSUPP;
989+
990+
ledtrig_mtd_activity();
985991
/*
986992
* In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics
987993
* similar to mtd->_read(), returning a non-negative integer
@@ -997,6 +1003,19 @@ int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops)
9971003
}
9981004
EXPORT_SYMBOL_GPL(mtd_read_oob);
9991005

1006+
int mtd_write_oob(struct mtd_info *mtd, loff_t to,
1007+
struct mtd_oob_ops *ops)
1008+
{
1009+
ops->retlen = ops->oobretlen = 0;
1010+
if (!mtd->_write_oob)
1011+
return -EOPNOTSUPP;
1012+
if (!(mtd->flags & MTD_WRITEABLE))
1013+
return -EROFS;
1014+
ledtrig_mtd_activity();
1015+
return mtd->_write_oob(mtd, to, ops);
1016+
}
1017+
EXPORT_SYMBOL_GPL(mtd_write_oob);
1018+
10001019
/*
10011020
* Method to access the protection register area, present in some flash
10021021
* devices. The user data is one time programmable but the factory data is read

‎drivers/mtd/nand/nand_base.c‎

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include <linux/mtd/nand_bch.h>
4444
#include <linux/interrupt.h>
4545
#include <linux/bitops.h>
46-
#include <linux/leds.h>
4746
#include <linux/io.h>
4847
#include <linux/mtd/partitions.h>
4948
#include <linux/of_mtd.h>
@@ -97,12 +96,6 @@ static int nand_get_device(struct mtd_info *mtd, int new_state);
9796
static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
9897
struct mtd_oob_ops *ops);
9998

100-
/*
101-
* For devices which display every fart in the system on a separate LED. Is
102-
* compiled away when LED support is disabled.
103-
*/
104-
DEFINE_LED_TRIGGER(nand_led_trigger);
105-
10699
static int check_offs_len(struct mtd_info *mtd,
107100
loff_t ofs, uint64_t len)
108101
{
@@ -540,19 +533,16 @@ void nand_wait_ready(struct mtd_info *mtd)
540533
if (in_interrupt() || oops_in_progress)
541534
return panic_nand_wait_ready(mtd, timeo);
542535

543-
led_trigger_event(nand_led_trigger, LED_FULL);
544536
/* Wait until command is processed or timeout occurs */
545537
timeo = jiffies + msecs_to_jiffies(timeo);
546538
do {
547539
if (chip->dev_ready(mtd))
548-
goto out;
540+
return;
549541
cond_resched();
550542
} while (time_before(jiffies, timeo));
551543

552544
if (!chip->dev_ready(mtd))
553545
pr_warn_ratelimited("timeout while waiting for chip to become ready\n");
554-
out:
555-
led_trigger_event(nand_led_trigger, LED_OFF);
556546
}
557547
EXPORT_SYMBOL_GPL(nand_wait_ready);
558548

@@ -885,8 +875,6 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
885875
int status;
886876
unsigned long timeo = 400;
887877

888-
led_trigger_event(nand_led_trigger, LED_FULL);
889-
890878
/*
891879
* Apply this short delay always to ensure that we do wait tWB in any
892880
* case on any machine.
@@ -910,7 +898,6 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
910898
cond_resched();
911899
} while (time_before(jiffies, timeo));
912900
}
913-
led_trigger_event(nand_led_trigger, LED_OFF);
914901

915902
status = (int)chip->read_byte(mtd);
916903
/* This can happen if in case of timeout or buggy dev_ready */
@@ -4474,20 +4461,6 @@ void nand_release(struct mtd_info *mtd)
44744461
}
44754462
EXPORT_SYMBOL_GPL(nand_release);
44764463

4477-
static int __init nand_base_init(void)
4478-
{
4479-
led_trigger_register_simple("nand-disk", &nand_led_trigger);
4480-
return 0;
4481-
}
4482-
4483-
static void __exit nand_base_exit(void)
4484-
{
4485-
led_trigger_unregister_simple(nand_led_trigger);
4486-
}
4487-
4488-
module_init(nand_base_init);
4489-
module_exit(nand_base_exit);
4490-
44914464
MODULE_LICENSE("GPL");
44924465
MODULE_AUTHOR("Steven J. Hill <sjhill@realitydiluted.com>");
44934466
MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");

‎include/linux/leds.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,12 @@ extern void ledtrig_ide_activity(void);
329329
static inline void ledtrig_ide_activity(void) {}
330330
#endif
331331

332+
#ifdef CONFIG_LEDS_TRIGGER_MTD
333+
extern void ledtrig_mtd_activity(void);
334+
#else
335+
static inline void ledtrig_mtd_activity(void) {}
336+
#endif
337+
332338
#if defined(CONFIG_LEDS_TRIGGER_CAMERA) || defined(CONFIG_LEDS_TRIGGER_CAMERA_MODULE)
333339
extern void ledtrig_flash_ctrl(bool on);
334340
extern void ledtrig_torch_ctrl(bool on);

‎include/linux/mtd/mtd.h‎

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -283,17 +283,7 @@ int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen,
283283
const u_char *buf);
284284

285285
int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops);
286-
287-
static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to,
288-
struct mtd_oob_ops *ops)
289-
{
290-
ops->retlen = ops->oobretlen = 0;
291-
if (!mtd->_write_oob)
292-
return -EOPNOTSUPP;
293-
if (!(mtd->flags & MTD_WRITEABLE))
294-
return -EROFS;
295-
return mtd->_write_oob(mtd, to, ops);
296-
}
286+
int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops);
297287

298288
int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen,
299289
struct otp_info *buf);

0 commit comments

Comments
 (0)