Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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

+119 -39
+15
drivers/leds/trigger/Kconfig
··· 41 41 This allows LEDs to be controlled by IDE disk activity. 42 42 If unsure, say Y. 43 43 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 + 44 52 config LEDS_TRIGGER_HEARTBEAT 45 53 tristate "LED Heartbeat Trigger" 46 54 depends on LEDS_TRIGGERS ··· 114 106 help 115 107 This allows LEDs to be controlled as a camera flash/torch device. 116 108 This enables direct flash/torch on/off by the driver, kernel space. 109 + If unsure, say Y. 110 + 111 + config LEDS_TRIGGER_PANIC 112 + bool "LED Panic Trigger" 113 + depends on LEDS_TRIGGERS 114 + help 115 + This allows LEDs to be configured to blink on a kernel panic. 117 116 If unsure, say Y. 118 117 119 118 endif # LEDS_TRIGGERS
+2
drivers/leds/trigger/Makefile
··· 1 1 obj-$(CONFIG_LEDS_TRIGGER_TIMER) += ledtrig-timer.o 2 2 obj-$(CONFIG_LEDS_TRIGGER_ONESHOT) += ledtrig-oneshot.o 3 3 obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o 4 + obj-$(CONFIG_LEDS_TRIGGER_MTD) += ledtrig-mtd.o 4 5 obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o 5 6 obj-$(CONFIG_LEDS_TRIGGER_BACKLIGHT) += ledtrig-backlight.o 6 7 obj-$(CONFIG_LEDS_TRIGGER_GPIO) += ledtrig-gpio.o ··· 9 8 obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o 10 9 obj-$(CONFIG_LEDS_TRIGGER_TRANSIENT) += ledtrig-transient.o 11 10 obj-$(CONFIG_LEDS_TRIGGER_CAMERA) += ledtrig-camera.o 11 + obj-$(CONFIG_LEDS_TRIGGER_PANIC) += ledtrig-panic.o
+45
drivers/leds/trigger/ledtrig-mtd.c
··· 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);
+30
drivers/leds/trigger/ledtrig-panic.c
··· 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);
+19
drivers/mtd/mtdcore.c
··· 40 40 #include <linux/slab.h> 41 41 #include <linux/reboot.h> 42 42 #include <linux/kconfig.h> 43 + #include <linux/leds.h> 43 44 44 45 #include <linux/mtd/mtd.h> 45 46 #include <linux/mtd/partitions.h> ··· 863 862 mtd_erase_callback(instr); 864 863 return 0; 865 864 } 865 + ledtrig_mtd_activity(); 866 866 return mtd->_erase(mtd, instr); 867 867 } 868 868 EXPORT_SYMBOL_GPL(mtd_erase); ··· 927 925 if (!len) 928 926 return 0; 929 927 928 + ledtrig_mtd_activity(); 930 929 /* 931 930 * In the absence of an error, drivers return a non-negative integer 932 931 * representing the maximum number of bitflips that were corrected on ··· 952 949 return -EROFS; 953 950 if (!len) 954 951 return 0; 952 + ledtrig_mtd_activity(); 955 953 return mtd->_write(mtd, to, len, retlen, buf); 956 954 } 957 955 EXPORT_SYMBOL_GPL(mtd_write); ··· 986 982 ops->retlen = ops->oobretlen = 0; 987 983 if (!mtd->_read_oob) 988 984 return -EOPNOTSUPP; 985 + 986 + ledtrig_mtd_activity(); 989 987 /* 990 988 * In cases where ops->datbuf != NULL, mtd->_read_oob() has semantics 991 989 * similar to mtd->_read(), returning a non-negative integer ··· 1002 996 return ret_code >= mtd->bitflip_threshold ? -EUCLEAN : 0; 1003 997 } 1004 998 EXPORT_SYMBOL_GPL(mtd_read_oob); 999 + 1000 + int mtd_write_oob(struct mtd_info *mtd, loff_t to, 1001 + struct mtd_oob_ops *ops) 1002 + { 1003 + ops->retlen = ops->oobretlen = 0; 1004 + if (!mtd->_write_oob) 1005 + return -EOPNOTSUPP; 1006 + if (!(mtd->flags & MTD_WRITEABLE)) 1007 + return -EROFS; 1008 + ledtrig_mtd_activity(); 1009 + return mtd->_write_oob(mtd, to, ops); 1010 + } 1011 + EXPORT_SYMBOL_GPL(mtd_write_oob); 1005 1012 1006 1013 /* 1007 1014 * Method to access the protection register area, present in some flash
+1 -28
drivers/mtd/nand/nand_base.c
··· 43 43 #include <linux/mtd/nand_bch.h> 44 44 #include <linux/interrupt.h> 45 45 #include <linux/bitops.h> 46 - #include <linux/leds.h> 47 46 #include <linux/io.h> 48 47 #include <linux/mtd/partitions.h> 49 48 #include <linux/of_mtd.h> ··· 95 96 96 97 static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, 97 98 struct mtd_oob_ops *ops); 98 - 99 - /* 100 - * For devices which display every fart in the system on a separate LED. Is 101 - * compiled away when LED support is disabled. 102 - */ 103 - DEFINE_LED_TRIGGER(nand_led_trigger); 104 99 105 100 static int check_offs_len(struct mtd_info *mtd, 106 101 loff_t ofs, uint64_t len) ··· 533 540 if (in_interrupt() || oops_in_progress) 534 541 return panic_nand_wait_ready(mtd, timeo); 535 542 536 - led_trigger_event(nand_led_trigger, LED_FULL); 537 543 /* Wait until command is processed or timeout occurs */ 538 544 timeo = jiffies + msecs_to_jiffies(timeo); 539 545 do { 540 546 if (chip->dev_ready(mtd)) 541 - goto out; 547 + return; 542 548 cond_resched(); 543 549 } while (time_before(jiffies, timeo)); 544 550 545 551 if (!chip->dev_ready(mtd)) 546 552 pr_warn_ratelimited("timeout while waiting for chip to become ready\n"); 547 - out: 548 - led_trigger_event(nand_led_trigger, LED_OFF); 549 553 } 550 554 EXPORT_SYMBOL_GPL(nand_wait_ready); 551 555 ··· 875 885 int status; 876 886 unsigned long timeo = 400; 877 887 878 - led_trigger_event(nand_led_trigger, LED_FULL); 879 - 880 888 /* 881 889 * Apply this short delay always to ensure that we do wait tWB in any 882 890 * case on any machine. ··· 898 910 cond_resched(); 899 911 } while (time_before(jiffies, timeo)); 900 912 } 901 - led_trigger_event(nand_led_trigger, LED_OFF); 902 913 903 914 status = (int)chip->read_byte(mtd); 904 915 /* This can happen if in case of timeout or buggy dev_ready */ ··· 4460 4473 kfree(chip->badblock_pattern); 4461 4474 } 4462 4475 EXPORT_SYMBOL_GPL(nand_release); 4463 - 4464 - static int __init nand_base_init(void) 4465 - { 4466 - led_trigger_register_simple("nand-disk", &nand_led_trigger); 4467 - return 0; 4468 - } 4469 - 4470 - static void __exit nand_base_exit(void) 4471 - { 4472 - led_trigger_unregister_simple(nand_led_trigger); 4473 - } 4474 - 4475 - module_init(nand_base_init); 4476 - module_exit(nand_base_exit); 4477 4476 4478 4477 MODULE_LICENSE("GPL"); 4479 4478 MODULE_AUTHOR("Steven J. Hill <sjhill@realitydiluted.com>");
+6
include/linux/leds.h
··· 329 329 static inline void ledtrig_ide_activity(void) {} 330 330 #endif 331 331 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 + 332 338 #if defined(CONFIG_LEDS_TRIGGER_CAMERA) || defined(CONFIG_LEDS_TRIGGER_CAMERA_MODULE) 333 339 extern void ledtrig_flash_ctrl(bool on); 334 340 extern void ledtrig_torch_ctrl(bool on);
+1 -11
include/linux/mtd/mtd.h
··· 283 283 const u_char *buf); 284 284 285 285 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); 297 287 298 288 int mtd_get_fact_prot_info(struct mtd_info *mtd, size_t len, size_t *retlen, 299 289 struct otp_info *buf);