blob: 2022130139d2dea3a2b1241c3675dbd3cb32b6ff [file] [log] [blame]
Michal Simekecc6dfc2009-03-27 14:25:24 +01001/*
2 * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2007-2009 PetaLogix
4 * Copyright (C) 2006 Atmark Techno, Inc.
5 *
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10
11#include <linux/sched.h>
Ingo Molnarbadaff82017-02-08 08:45:17 +010012#include <linux/sched/loadavg.h>
Michal Simekecc6dfc2009-03-27 14:25:24 +010013#include <linux/io.h>
14
15#include <asm/setup.h>
16#include <asm/page.h>
17#include <asm/prom.h>
18
19static unsigned int base_addr;
20
Guenter Roeck79c157a2014-02-17 22:46:54 -080021void microblaze_heartbeat(void)
Michal Simekecc6dfc2009-03-27 14:25:24 +010022{
23 static unsigned int cnt, period, dist;
24
25 if (base_addr) {
26 if (cnt == 0 || cnt == dist)
27 out_be32(base_addr, 1);
28 else if (cnt == 7 || cnt == dist + 7)
29 out_be32(base_addr, 0);
30
31 if (++cnt > period) {
32 cnt = 0;
33 /*
34 * The hyperbolic function below modifies the heartbeat
35 * period length in dependency of the current (5min)
36 * load. It goes through the points f(0)=126, f(1)=86,
37 * f(5)=51, f(inf)->30.
38 */
39 period = ((672 << FSHIFT) / (5 * avenrun[0] +
40 (7 << FSHIFT))) + 30;
41 dist = period / 4;
42 }
43 }
44}
45
Guenter Roeck79c157a2014-02-17 22:46:54 -080046void microblaze_setup_heartbeat(void)
Michal Simekecc6dfc2009-03-27 14:25:24 +010047{
48 struct device_node *gpio = NULL;
John Linn6d858532009-06-05 11:36:31 -060049 int *prop;
Michal Simekecc6dfc2009-03-27 14:25:24 +010050 int j;
Joe Perches92ee8bd42010-09-13 21:23:49 -070051 const char * const gpio_list[] = {
52 "xlnx,xps-gpio-1.00.a",
Joe Perches92ee8bd42010-09-13 21:23:49 -070053 NULL
54 };
Michal Simekecc6dfc2009-03-27 14:25:24 +010055
56 for (j = 0; gpio_list[j] != NULL; j++) {
57 gpio = of_find_compatible_node(NULL, NULL, gpio_list[j]);
58 if (gpio)
59 break;
60 }
61
John Linn6d858532009-06-05 11:36:31 -060062 if (gpio) {
Michal Simek02b08042010-09-28 16:04:14 +100063 base_addr = be32_to_cpup(of_get_property(gpio, "reg", NULL));
John Linn6d858532009-06-05 11:36:31 -060064 base_addr = (unsigned long) ioremap(base_addr, PAGE_SIZE);
Michal Simek6bd55f02012-12-27 10:40:38 +010065 pr_notice("Heartbeat GPIO at 0x%x\n", base_addr);
Michal Simekecc6dfc2009-03-27 14:25:24 +010066
John Linn6d858532009-06-05 11:36:31 -060067 /* GPIO is configured as output */
68 prop = (int *) of_get_property(gpio, "xlnx,is-bidir", NULL);
69 if (prop)
70 out_be32(base_addr + 4, 0);
71 }
Michal Simekecc6dfc2009-03-27 14:25:24 +010072}