1 /*
2  * arch/sh64/kernel/led.c
3  *
4  * Copyright (C) 2002 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  * Flash the LEDs
10  */
11 #include <linux/config.h>
12 #include <linux/stddef.h>
13 #include <linux/sched.h>
14 
15 void mach_alphanum(int pos, unsigned char val);
16 void mach_led(int pos, int val);
17 
print_seg(char * file,int line)18 void print_seg(char *file, int line)
19 {
20 	int i;
21 	unsigned int nibble;
22 
23 	for (i = 0; i < 5; i++) {
24 		mach_alphanum(i, file[i]);
25 	}
26 
27 	for (i = 0; i < 3; i++) {
28 		nibble = ((line >> (i * 4)) & 0xf);
29 		mach_alphanum(7 - i, nibble + ((nibble > 9) ? 55 : 48));
30 	}
31 }
32 
print_seg_num(unsigned num)33 void print_seg_num(unsigned num)
34 {
35 	int i;
36 	unsigned int nibble;
37 
38 	for (i = 0; i < 8; i++) {
39 		nibble = ((num >> (i * 4)) & 0xf);
40 
41 		mach_alphanum(7 - i, nibble + ((nibble > 9) ? 55 : 48));
42 	}
43 }
44 
45 /* acts like an actual heart beat -- ie thump-thump-pause... */
heartbeat(void)46 void heartbeat(void)
47 {
48 	static unsigned int cnt = 0, period = 0, dist = 0;
49 
50 	if (cnt == 0 || cnt == dist) {
51 		mach_led(-1, 1);
52 	} else if (cnt == 7 || cnt == dist + 7) {
53 		mach_led(-1, 0);
54 	}
55 
56 	if (++cnt > period) {
57 		cnt = 0;
58 
59 		/*
60 		 * The hyperbolic function below modifies the heartbeat period
61 		 * length in dependency of the current (5min) load. It goes
62 		 * through the points f(0)=126, f(1)=86, f(5)=51, f(inf)->30.
63 		 */
64 		period = ((672 << FSHIFT) / (5 * avenrun[0] +
65 					    (7 << FSHIFT))) + 30;
66 		dist = period / 4;
67 	}
68 }
69 
70