Path: blob/master/arch/microblaze/kernel/heartbeat.c
10817 views
/*1* Copyright (C) 2007-2009 Michal Simek <[email protected]>2* Copyright (C) 2007-2009 PetaLogix3* Copyright (C) 2006 Atmark Techno, Inc.4*5* This file is subject to the terms and conditions of the GNU General Public6* License. See the file "COPYING" in the main directory of this archive7* for more details.8*/910#include <linux/sched.h>11#include <linux/io.h>1213#include <asm/setup.h>14#include <asm/page.h>15#include <asm/prom.h>1617static unsigned int base_addr;1819void heartbeat(void)20{21static unsigned int cnt, period, dist;2223if (base_addr) {24if (cnt == 0 || cnt == dist)25out_be32(base_addr, 1);26else if (cnt == 7 || cnt == dist + 7)27out_be32(base_addr, 0);2829if (++cnt > period) {30cnt = 0;31/*32* The hyperbolic function below modifies the heartbeat33* period length in dependency of the current (5min)34* load. It goes through the points f(0)=126, f(1)=86,35* f(5)=51, f(inf)->30.36*/37period = ((672 << FSHIFT) / (5 * avenrun[0] +38(7 << FSHIFT))) + 30;39dist = period / 4;40}41}42}4344void setup_heartbeat(void)45{46struct device_node *gpio = NULL;47int *prop;48int j;49const char * const gpio_list[] = {50"xlnx,xps-gpio-1.00.a",51NULL52};5354for (j = 0; gpio_list[j] != NULL; j++) {55gpio = of_find_compatible_node(NULL, NULL, gpio_list[j]);56if (gpio)57break;58}5960if (gpio) {61base_addr = be32_to_cpup(of_get_property(gpio, "reg", NULL));62base_addr = (unsigned long) ioremap(base_addr, PAGE_SIZE);63printk(KERN_NOTICE "Heartbeat GPIO at 0x%x\n", base_addr);6465/* GPIO is configured as output */66prop = (int *) of_get_property(gpio, "xlnx,is-bidir", NULL);67if (prop)68out_be32(base_addr + 4, 0);69}70}717273