From patchwork Wed Jun 22 17:33:03 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 906492 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by demeter1.kernel.org (8.14.4/8.14.4) with ESMTP id p5MHcJHF028994 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 22 Jun 2011 17:38:40 GMT Received: from canuck.infradead.org ([2001:4978:20e::1]) by merlin.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QZRNR-0006mA-8H; Wed, 22 Jun 2011 17:38:09 +0000 Received: from localhost ([127.0.0.1] helo=canuck.infradead.org) by canuck.infradead.org with esmtp (Exim 4.76 #1 (Red Hat Linux)) id 1QZRNQ-0005gs-Sv; Wed, 22 Jun 2011 17:38:08 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1QZRNO-0005gn-7a for linux-arm-kernel@canuck.infradead.org; Wed, 22 Jun 2011 17:38:06 +0000 Received: from eu1sys200aog107.obsmtp.com ([207.126.144.123]) by casper.infradead.org with smtps (Exim 4.76 #1 (Red Hat Linux)) id 1QZRNK-0006MW-Uw for linux-arm-kernel@lists.infradead.org; Wed, 22 Jun 2011 17:38:04 +0000 Received: from beta.dmz-eu.st.com ([164.129.1.35]) (using TLSv1) by eu1sys200aob107.postini.com ([207.126.147.11]) with SMTP ID DSNKTgInVVpvhgeMTZx3OS/i3FH5OmT4CYpD@postini.com; Wed, 22 Jun 2011 17:38:02 UTC Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 22222D3; Wed, 22 Jun 2011 17:33:08 +0000 (GMT) Received: from relay2.stm.gmessaging.net (unknown [10.230.100.18]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id C8769485E; Wed, 22 Jun 2011 17:33:07 +0000 (GMT) Received: from exdcvycastm003.EQ1STM.local (alteon-source-exch [10.230.100.61]) (using TLSv1 with cipher RC4-MD5 (128/128 bits)) (Client CN "exdcvycastm003", Issuer "exdcvycastm003" (not verified)) by relay2.stm.gmessaging.net (Postfix) with ESMTPS id 90784A8074; Wed, 22 Jun 2011 19:33:00 +0200 (CEST) Received: from localhost.localdomain (10.230.100.153) by smtp.stericsson.com (10.230.100.1) with Microsoft SMTP Server (TLS) id 8.3.83.0; Wed, 22 Jun 2011 19:33:07 +0200 From: Linus Walleij To: Subject: [PATCH 1/3] leds: create a trigger for ARM CPU activity Date: Wed, 22 Jun 2011 19:33:03 +0200 Message-ID: <1308763983-24749-1-git-send-email-linus.walleij@stericsson.com> X-Mailer: git-send-email 1.7.3.2 MIME-Version: 1.0 X-CRM114-Version: 20090807-BlameThorstenAndJenny ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20110622_183803_082293_C1C2BC09 X-CRM114-Status: GOOD ( 27.76 ) X-Spam-Score: -4.2 (----) X-Spam-Report: SpamAssassin version 3.3.2-r929478 on casper.infradead.org summary: Content analysis details: (-4.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at http://www.dnswl.org/, medium trust [207.126.144.123 listed in list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Richard Purdie , Linus Walleij , Lee Jones , Bryan Wu X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linux-arm-kernel-bounces@lists.infradead.org Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Greylist: IP, sender and recipient auto-whitelisted, not delayed by milter-greylist-4.2.6 (demeter1.kernel.org [140.211.167.41]); Wed, 22 Jun 2011 17:38:41 +0000 (UTC) From: Linus Walleij Attempting to consolidate the ARM LED code, this removes the custom RealView LED trigger code to turn LEDs on and off in response to CPU activity and replace it with a standard trigger. It uses the existing kernel hooks deep inside to get CPU activity. Cc: Bryan Wu Cc: Richard Purdie Signed-off-by: Linus Walleij Acked-by: Nicolas Pitre --- drivers/leds/Kconfig | 15 +++++ drivers/leds/Makefile | 1 + drivers/leds/ledtrig-arm-cpu.c | 114 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 130 insertions(+), 0 deletions(-) create mode 100644 drivers/leds/ledtrig-arm-cpu.c diff --git a/drivers/leds/Kconfig b/drivers/leds/Kconfig index 713d43b..f725ae2 100644 --- a/drivers/leds/Kconfig +++ b/drivers/leds/Kconfig @@ -446,6 +446,21 @@ config LEDS_TRIGGER_BACKLIGHT If unsure, say N. +# Notice that this uses the CONFIG_LEDS i.e. the "old" LEDS +config LEDS_TRIGGER_ARM_CPU + bool "LED ARM CPU Trigger" + depends on LEDS_TRIGGERS && ARM + select LEDS + select LEDS_CPU + default y if ARCH_REALVIEW + default y if ARCH_VERSATILE + help + This allows LEDs to be controlled by active ARM CPUs. This + shows the active CPUs across an array of LEDs so you can see + what CPUs are active on the system at any given moment. + + If unsure, say N. + config LEDS_TRIGGER_GPIO tristate "LED GPIO Trigger" depends on LEDS_TRIGGERS diff --git a/drivers/leds/Makefile b/drivers/leds/Makefile index bbfd2e3..a32a99c 100644 --- a/drivers/leds/Makefile +++ b/drivers/leds/Makefile @@ -53,4 +53,5 @@ obj-$(CONFIG_LEDS_TRIGGER_IDE_DISK) += ledtrig-ide-disk.o obj-$(CONFIG_LEDS_TRIGGER_HEARTBEAT) += ledtrig-heartbeat.o obj-$(CONFIG_LEDS_TRIGGER_BACKLIGHT) += ledtrig-backlight.o obj-$(CONFIG_LEDS_TRIGGER_GPIO) += ledtrig-gpio.o +obj-$(CONFIG_LEDS_TRIGGER_ARM_CPU) += ledtrig-arm-cpu.o obj-$(CONFIG_LEDS_TRIGGER_DEFAULT_ON) += ledtrig-default-on.o diff --git a/drivers/leds/ledtrig-arm-cpu.c b/drivers/leds/ledtrig-arm-cpu.c new file mode 100644 index 0000000..7776d61 --- /dev/null +++ b/drivers/leds/ledtrig-arm-cpu.c @@ -0,0 +1,114 @@ +/* + * ledtrig-arm-cpu.c - LED trigger based on ARM CPU activity + * + * Copyright 2011 Linus Walleij + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "leds.h" + +struct arm_cpu_trig_data { + struct led_classdev *led; +}; + +static DEFINE_PER_CPU(struct arm_cpu_trig_data *, arm_cpu_triggers); + +void arm_cpu_leds_event(led_event_t ledevt) +{ + struct arm_cpu_trig_data *trigdata = __get_cpu_var(arm_cpu_triggers); + + if (!trigdata) + return; + + /* Locate the correct CPU LED */ + + switch (ledevt) { + case led_halted: + case led_idle_start: + /* Will turn the LED off */ + if (trigdata->led) + led_set_brightness(trigdata->led, LED_OFF); + break; + + case led_idle_end: + /* Will turn the LED on, max brightness */ + if (trigdata->led) + led_set_brightness(trigdata->led, + trigdata->led->max_brightness); + break; + + default: + /* Will leave the LED as it is */ + break; + } +} + +static void arm_cpu_trig_activate_cpu(void *data) +{ + struct arm_cpu_trig_data *arm_cpu_data; + struct led_classdev *led = data; + int my_cpu = smp_processor_id(); + unsigned long target_cpu = (unsigned long) led->trigger_data; + + if (target_cpu != my_cpu) + return; + + arm_cpu_data = kzalloc(sizeof(*arm_cpu_data), GFP_KERNEL); + if (!arm_cpu_data) + return; + + dev_info(led->dev, "led %s indicate activity on CPU %d\n", + led->name, my_cpu); + + arm_cpu_data->led = led; + __get_cpu_var(arm_cpu_triggers) = arm_cpu_data; +} + +static void arm_cpu_trig_activate(struct led_classdev *led) +{ + on_each_cpu(arm_cpu_trig_activate_cpu, led, 1); + + /* Hook into ARM core kernel event callback */ + leds_event = arm_cpu_leds_event; +} + +static void arm_cpu_trig_deactivate(struct led_classdev *led) +{ + struct arm_cpu_trig_data *arm_cpu_data = led->trigger_data; + + if (arm_cpu_data) + kfree(arm_cpu_data); +} + +static struct led_trigger arm_cpu_led_trigger = { + .name = "arm-cpu", + .activate = arm_cpu_trig_activate, + .deactivate = arm_cpu_trig_deactivate, +}; + +static int __init arm_cpu_trig_init(void) +{ + return led_trigger_register(&arm_cpu_led_trigger); +} +module_init(arm_cpu_trig_init); + +static void __exit arm_cpu_trig_exit(void) +{ + led_trigger_unregister(&arm_cpu_led_trigger); +} +module_exit(arm_cpu_trig_exit); + +MODULE_AUTHOR("Linus Walleij "); +MODULE_DESCRIPTION("ARM CPU LED trigger"); +MODULE_LICENSE("GPL");