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