From patchwork Sun Jun 2 15:53:13 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jens Renner X-Patchwork-Id: 248132 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:770:15f::2]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id E43A22C009D for ; Mon, 3 Jun 2013 01:54:01 +1000 (EST) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UjAb4-00008N-Se; Sun, 02 Jun 2013 15:53:31 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1UjAb1-0005lh-9Q; Sun, 02 Jun 2013 15:53:27 +0000 Received: from moutng.kundenserver.de ([212.227.126.187]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1UjAau-0005l3-GN for linux-mtd@lists.infradead.org; Sun, 02 Jun 2013 15:53:21 +0000 Received: from [192.168.0.18] (dslb-178-004-230-032.pools.arcor-ip.net [178.4.230.32]) by mrelayeu.kundenserver.de (node=mreu3) with ESMTP (Nemesis) id 0MGt1h-1UeTlG3jRB-00DW5E; Sun, 02 Jun 2013 17:52:56 +0200 Message-ID: <51AB6A69.9080004@efe-gmbh.de> Date: Sun, 02 Jun 2013 17:53:13 +0200 From: "Jens Renner (EFE)" Organization: EFE GmbH User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130509 Thunderbird/17.0.6 MIME-Version: 1.0 To: linux-mtd@lists.infradead.org Subject: [PATCH v2] mtd: Add LED trigger support "mtd-disk" to indicate activity X-Enigmail-Version: 1.5.1 X-Provags-ID: V02:K0:XSQqoPCNxjig4wdzMt8uk5wIkYeWgTRgVdhxq3FiqLb 2CtgLNBaNYl7q/OpQAisb9BS/Yde0824JYjmscEhTPJU8f6PwR MgR0cg9TLsxUpJARf7zigXB2vAxkZUxg1MwPjDXuCLdBXoeBMm sAYclCEqpk1A9UoiMdLM6vkaDeen2yA3d8TQWQiblNiaI7E8+G NseBHLpHGudTPfkiUb6oc7lR71L7fEDEyl8RHH2d+ZkPGQj5U/ e/BMOtSDUqXYaQtIZMzHfL3iubFkt3OskITDWzXFg0t7EDjTc0 +uF0IUxo8QKVNGFWAO07nDWaQ2TskIOiNh/c9LTRGer/+MH0Js aVj5OULf9mOL+1cvoBs4= X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130602_115320_765261_BF001E16 X-CRM114-Status: GOOD ( 19.88 ) X-Spam-Score: -1.9 (-) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-1.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [212.227.126.187 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Register a MTD LED trigger called "mtd-disk" (similar to the "ide-disk" and "nand-disk" triggers) to indicate read / write / erase acitivity. Panic writes and OOB reads / writes are not covered as of now. The trigger is global as it does not discriminate between individual devices or partitions. The patch uses the generic LED trigger interface which can be configured via SYSFS (/sys/class/leds//trigger) or DTS file entry for "gpio-leds" (linux,default-trigger = "mtd-disk"). Since the MTD framework is independant of the memory devices, driver-specific LED triggers like "nand-disk" will indicate a subset of all MTD activity. Tested on Microblaze architecture with Micron N25Q256A serial flash. Added a bit of documentation (including other new LED triggers). Signed-off-by: Jens Renner --- Changes in v2: - fix whitespace problem drivers/mtd/mtdcore.c | 25 ++++++++++++++++++-- Documentation/devicetree/bindings/leds/common.txt | 4 ++++ 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index c400c57..fbf1ed8 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -100,6 +101,8 @@ static LIST_HEAD(mtd_notifiers); #define MTD_DEVT(index) MKDEV(MTD_CHAR_MAJOR, (index)*2) +DEFINE_LED_TRIGGER(mtd_led_trigger); + /* REVISIT once MTD uses the driver model better, whoever allocates * the mtd_info will probably want to use the release() hook... */ @@ -727,6 +730,7 @@ EXPORT_SYMBOL_GPL(__put_mtd_device); */ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr) { + int ret_code; if (instr->addr > mtd->size || instr->len > mtd->size - instr->addr) return -EINVAL; if (!(mtd->flags & MTD_WRITEABLE)) @@ -737,7 +741,11 @@ int mtd_erase(struct mtd_info *mtd, struct erase_info *instr) mtd_erase_callback(instr); return 0; } - return mtd->_erase(mtd, instr); + led_trigger_event(mtd_led_trigger, LED_FULL); + ret_code = mtd->_erase(mtd, instr); + led_trigger_event(mtd_led_trigger, LED_OFF); + + return ret_code; } EXPORT_SYMBOL_GPL(mtd_erase); @@ -800,12 +808,17 @@ int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, if (!len) return 0; + led_trigger_event(mtd_led_trigger, LED_FULL); + /* * In the absence of an error, drivers return a non-negative integer * representing the maximum number of bitflips that were corrected on * any one ecc region (if applicable; zero otherwise). */ ret_code = mtd->_read(mtd, from, len, retlen, buf); + + led_trigger_event(mtd_led_trigger, LED_OFF); + if (unlikely(ret_code < 0)) return ret_code; if (mtd->ecc_strength == 0) @@ -817,6 +830,7 @@ EXPORT_SYMBOL_GPL(mtd_read); int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { + int ret_code; *retlen = 0; if (to < 0 || to > mtd->size || len > mtd->size - to) return -EINVAL; @@ -824,7 +838,11 @@ int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, return -EROFS; if (!len) return 0; - return mtd->_write(mtd, to, len, retlen, buf); + led_trigger_event(mtd_led_trigger, LED_FULL); + ret_code = mtd->_write(mtd, to, len, retlen, buf); + led_trigger_event(mtd_led_trigger, LED_OFF); + + return ret_code; } EXPORT_SYMBOL_GPL(mtd_write); @@ -1187,6 +1205,8 @@ static int __init init_mtd(void) if (ret) goto out_procfs; + led_trigger_register_simple("mtd-disk", &mtd_led_trigger); + return 0; out_procfs: @@ -1205,6 +1225,7 @@ err_reg: static void __exit cleanup_mtd(void) { + led_trigger_unregister_simple(mtd_led_trigger); cleanup_mtdchar(); if (proc_mtd) remove_proc_entry("mtd", NULL); diff --git a/Documentation/devicetree/bindings/leds/common.txt b/Documentation/devicetree/bindings/leds/common.txt index 2d88816..9875cd2 100644 --- a/Documentation/devicetree/bindings/leds/common.txt +++ b/Documentation/devicetree/bindings/leds/common.txt @@ -12,6 +12,10 @@ Optional properties for child nodes: property in Documentation/devicetree/bindings/gpio/led.txt) "heartbeat" - LED "double" flashes at a load average based rate "ide-disk" - LED indicates disk activity + "mtd-disk" - LED indicates MTD activity + "nand-disk" - LED indicates NAND activity + "mmc" - LED indicates activity of SD/MMC #n (e.g. "mmc0") + "cpu" - LED indicates activity of CPU #n (e.g. "cpu0") "timer" - LED flashes at a fixed, configurable rate Examples: