Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753950Ab0BIUrf (ORCPT ); Tue, 9 Feb 2010 15:47:35 -0500 Received: from mail-ew0-f228.google.com ([209.85.219.228]:57612 "EHLO mail-ew0-f228.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753299Ab0BIUqg (ORCPT ); Tue, 9 Feb 2010 15:46:36 -0500 From: Bill Gatliff To: linux-embedded@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Bill Gatliff Subject: [PWM PATCH 5/7] LED "dim" trigger based on PWM control of the LED Date: Tue, 9 Feb 2010 14:46:32 -0600 Message-Id: X-Mailer: git-send-email 1.6.5 In-Reply-To: <0b1e9d2f93d366f003348f4d31fdfbf8da4594b2.1265748264.git.bgat@billgatliff.com> References: <7178097a5a8af15f61656f11b6bef68b0da71498.1265748264.git.bgat@billgatliff.com> <6ba8043e7749806f88b685ecd5ad7c4e1062bc91.1265748264.git.bgat@billgatliff.com> <0b1e9d2f93d366f003348f4d31fdfbf8da4594b2.1265748264.git.bgat@billgatliff.com> In-Reply-To: References: Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 2817 Lines: 116 Signed-off-by: Bill Gatliff --- drivers/leds/ledtrig-dim.c | 95 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 95 insertions(+), 0 deletions(-) create mode 100644 drivers/leds/ledtrig-dim.c diff --git a/drivers/leds/ledtrig-dim.c b/drivers/leds/ledtrig-dim.c new file mode 100644 index 0000000..299865b --- /dev/null +++ b/drivers/leds/ledtrig-dim.c @@ -0,0 +1,95 @@ +/* + * LED Dim Trigger + * + * Copyright (C) 2008 Bill Gatliff + * + * "Dims" an LED based on system load. Derived from Atsushi Nemoto's + * ledtrig-heartbeat.c. + * + * 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 "leds.h" + +struct dim_trig_data { + struct timer_list timer; +}; + + +static void +led_dim_function(unsigned long data) +{ + struct led_classdev *led_cdev = (struct led_classdev *)data; + struct dim_trig_data *dim_data = led_cdev->trigger_data; + unsigned int brightness; + + brightness = ((LED_FULL - LED_OFF) * avenrun[0]) / EXP_1; + if (brightness > LED_FULL) + brightness = LED_FULL; + + led_set_brightness(led_cdev, brightness); + mod_timer(&dim_data->timer, jiffies + msecs_to_jiffies(500)); +} + + +static void +dim_trig_activate(struct led_classdev *led_cdev) +{ + struct dim_trig_data *dim_data; + + dim_data = kzalloc(sizeof(*dim_data), GFP_KERNEL); + if (!dim_data) + return; + + led_cdev->trigger_data = dim_data; + setup_timer(&dim_data->timer, + led_dim_function, (unsigned long)led_cdev); + led_dim_function(dim_data->timer.data); +} + + +static void +dim_trig_deactivate(struct led_classdev *led_cdev) +{ + struct dim_trig_data *dim_data = led_cdev->trigger_data; + + if (dim_data) { + del_timer_sync(&dim_data->timer); + kfree(dim_data); + } +} + + +static struct led_trigger dim_led_trigger = { + .name = "dim", + .activate = dim_trig_activate, + .deactivate = dim_trig_deactivate, +}; + + +static int __init dim_trig_init(void) +{ + return led_trigger_register(&dim_led_trigger); +} +module_init(dim_trig_init); + + +static void __exit dim_trig_exit(void) +{ + led_trigger_unregister(&dim_led_trigger); +} +module_exit(dim_trig_exit); + + +MODULE_AUTHOR("Bill Gatliff "); +MODULE_DESCRIPTION("Dim LED trigger"); +MODULE_LICENSE("GPL"); -- 1.6.5 -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/