| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * linux/arch/sh/overdrive/led.c | 
|  | 3 | * | 
|  | 4 | * Copyright (C) 1999 Stuart Menefy <stuart.menefy@st.com> | 
|  | 5 | * | 
|  | 6 | * May be copied or modified under the terms of the GNU General Public | 
|  | 7 | * License.  See linux/COPYING for more information. | 
|  | 8 | * | 
|  | 9 | * This file contains an Overdrive specific LED feature. | 
|  | 10 | */ | 
|  | 11 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <asm/system.h> | 
|  | 13 | #include <asm/io.h> | 
|  | 14 | #include <asm/overdrive/overdrive.h> | 
|  | 15 |  | 
|  | 16 | static void mach_led(int position, int value) | 
|  | 17 | { | 
|  | 18 | unsigned long flags; | 
|  | 19 | unsigned long reg; | 
|  | 20 |  | 
|  | 21 | local_irq_save(flags); | 
|  | 22 |  | 
|  | 23 | reg = readl(OVERDRIVE_CTRL); | 
|  | 24 | if (value) { | 
|  | 25 | reg |= (1<<3); | 
|  | 26 | } else { | 
|  | 27 | reg &= ~(1<<3); | 
|  | 28 | } | 
|  | 29 | writel(reg, OVERDRIVE_CTRL); | 
|  | 30 |  | 
|  | 31 | local_irq_restore(flags); | 
|  | 32 | } | 
|  | 33 |  | 
|  | 34 | #ifdef CONFIG_HEARTBEAT | 
|  | 35 |  | 
|  | 36 | #include <linux/sched.h> | 
|  | 37 |  | 
|  | 38 | /* acts like an actual heart beat -- ie thump-thump-pause... */ | 
|  | 39 | void heartbeat_od(void) | 
|  | 40 | { | 
|  | 41 | static unsigned cnt = 0, period = 0, dist = 0; | 
|  | 42 |  | 
|  | 43 | if (cnt == 0 || cnt == dist) | 
|  | 44 | mach_led( -1, 1); | 
|  | 45 | else if (cnt == 7 || cnt == dist+7) | 
|  | 46 | mach_led( -1, 0); | 
|  | 47 |  | 
|  | 48 | if (++cnt > period) { | 
|  | 49 | cnt = 0; | 
|  | 50 | /* The hyperbolic function below modifies the heartbeat period | 
|  | 51 | * length in dependency of the current (5min) load. It goes | 
|  | 52 | * through the points f(0)=126, f(1)=86, f(5)=51, | 
|  | 53 | * f(inf)->30. */ | 
|  | 54 | period = ((672<<FSHIFT)/(5*avenrun[0]+(7<<FSHIFT))) + 30; | 
|  | 55 | dist = period / 4; | 
|  | 56 | } | 
|  | 57 | } | 
|  | 58 | #endif /* CONFIG_HEARTBEAT */ |