Thread (14 messages) flat view 14 messages, 5 authors, 2005-02-19
STALE7869d

[PATCH] Heartbeat LED for iBook

From: Joerg Dorchain <hidden>
Date: 2005-01-18 09:42:28

Hi all,

after looking at the ide driver (see previous post) and with references
to my good old A4000, I felt inspired to do this little hack.

It is in works-for-me state (iBook G4), but as the actual code is
shamelessly taken from the ide driver, I suppose it to work on all the
machines where the IDE driver can blink the led.

You can use it together with the ide blinking option, although the
heartbeat will look bumpy when the hd is active (don't worry, no heart
attack ;-)

There is further optimization possible on the ppc_md.heartbeat_count
and the cnt variables.

Oh, this patch is against vanilla 2.6.10.

Bye,

Joerg
--- ./arch/ppc/platforms/pmac_setup.c.hb	2005-01-17 22:39:08.000000000 +0100
+++ ./arch/ppc/platforms/pmac_setup.c	2005-01-18 01:09:08.325332888 +0100
@@ -240,6 +240,37 @@
 
 static volatile u32 *sysctrl_regs;
 
+#ifdef CONFIG_HEARTBEAT
+static struct adb_request pmu_blink_on, pmu_blink_off;
+
+/* adapted from arch_m68k */
+static void pb_heartbeat(void)
+{
+	static unsigned cnt = 0, period = 0, dist = 0;
+
+	if (cnt == 0 || cnt == dist) {
+		if (pmu_blink_on.complete)
+			pmu_request(&pmu_blink_on, NULL, 4, 0xee, 4, 0, 1);
+	} else if (cnt == 7 || cnt == dist + 7 ) {
+		if (pmu_blink_off.complete)
+			pmu_request(&pmu_blink_off, NULL, 4, 0xee, 4, 0, 0);
+	}
+
+	if (++cnt > period) {
+                cnt = 0;
+                /* The hyperbolic function below modifies the heartbeat period
+                 * length in dependency of the current (5min) load. It goes
+                 * through the points f(0)=126, f(1)=86, f(5)=51,
+                 * f(inf)->30. */
+                period = ((672<<FSHIFT)/(5*avenrun[0]+(7<<FSHIFT))) + 30;
+                dist = period / 4;
+	}
+
+	/* keep on going on ppc and account for HZ value */
+	ppc_md.heartbeat_count = HZ/100;
+}
+#endif /* CONFIG_HEARTBEAT */
+
 void __init
 pmac_setup_arch(void)
 {
@@ -333,6 +364,26 @@
 		ppc_md.smp_ops = &psurge_smp_ops;
 #endif /* CONFIG_SMP */
 
+#ifdef CONFIG_HEARTBEAT
+	/* Copied from the IDE blinking code */
+	if (pmu_get_model() == PMU_KEYLARGO_BASED) {
+		struct device_node *dt;
+		const char *model;
+
+		if ((dt = find_devices("device-tree")) != NULL) {
+			if ((model = (const char *)get_property(dt, "model", NULL)) != NULL) {
+				if (!strncmp(model, "PowerBook", strlen("PowerBook")) ||
+				    !strncmp(model, "iBook", strlen("iBook")) ) {
+					pmu_blink_on.complete = 1;
+					pmu_blink_off.complete = 1;
+					ppc_md.heartbeat = pb_heartbeat;
+					ppc_md.heartbeat_count = 1;
+				}
+			}
+		}
+	}
+#endif /* CONFIG_HEARTBEAT */
+
 	pci_create_OF_bus_map();
 }
 
--- ./arch/ppc/Kconfig.hb	2005-01-17 23:57:40.000000000 +0100
+++ ./arch/ppc/Kconfig	2005-01-18 00:09:14.000000000 +0100
@@ -954,7 +954,7 @@
 
 config HEARTBEAT
 	bool "Use power LED as a heartbeat"
-	depends on APUS
+	depends on APUS || (PPC_PMAC && ADB_PMU)
 	help
 	  Use the power-on LED on your machine as a load meter.  The exact
 	  behavior is platform-dependent, but normally the flash frequency is

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help