heartbeat.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  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. #include <linux/sched.h>
  11. #include <linux/io.h>
  12. #include <asm/setup.h>
  13. #include <asm/page.h>
  14. #include <asm/prom.h>
  15. static unsigned int base_addr;
  16. void microblaze_heartbeat(void)
  17. {
  18. static unsigned int cnt, period, dist;
  19. if (base_addr) {
  20. if (cnt == 0 || cnt == dist)
  21. out_be32(base_addr, 1);
  22. else if (cnt == 7 || cnt == dist + 7)
  23. out_be32(base_addr, 0);
  24. if (++cnt > period) {
  25. cnt = 0;
  26. /*
  27. * The hyperbolic function below modifies the heartbeat
  28. * period length in dependency of the current (5min)
  29. * load. It goes through the points f(0)=126, f(1)=86,
  30. * f(5)=51, f(inf)->30.
  31. */
  32. period = ((672 << FSHIFT) / (5 * avenrun[0] +
  33. (7 << FSHIFT))) + 30;
  34. dist = period / 4;
  35. }
  36. }
  37. }
  38. void microblaze_setup_heartbeat(void)
  39. {
  40. struct device_node *gpio = NULL;
  41. int *prop;
  42. int j;
  43. const char * const gpio_list[] = {
  44. "xlnx,xps-gpio-1.00.a",
  45. NULL
  46. };
  47. for (j = 0; gpio_list[j] != NULL; j++) {
  48. gpio = of_find_compatible_node(NULL, NULL, gpio_list[j]);
  49. if (gpio)
  50. break;
  51. }
  52. if (gpio) {
  53. base_addr = be32_to_cpup(of_get_property(gpio, "reg", NULL));
  54. base_addr = (unsigned long) ioremap(base_addr, PAGE_SIZE);
  55. pr_notice("Heartbeat GPIO at 0x%x\n", base_addr);
  56. /* GPIO is configured as output */
  57. prop = (int *) of_get_property(gpio, "xlnx,is-bidir", NULL);
  58. if (prop)
  59. out_be32(base_addr + 4, 0);
  60. }
  61. }