reset.c 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * Reset a Jazz machine.
  4. *
  5. * We don't trust the firmware so we do it the classic way by poking and
  6. * stabbing at the keyboard controller ...
  7. */
  8. #include <linux/jiffies.h>
  9. #include <asm/jazz.h>
  10. #define KBD_STAT_IBF 0x02 /* Keyboard input buffer full */
  11. static void jazz_write_output(unsigned char val)
  12. {
  13. int status;
  14. do {
  15. status = jazz_kh->command;
  16. } while (status & KBD_STAT_IBF);
  17. jazz_kh->data = val;
  18. }
  19. static void jazz_write_command(unsigned char val)
  20. {
  21. int status;
  22. do {
  23. status = jazz_kh->command;
  24. } while (status & KBD_STAT_IBF);
  25. jazz_kh->command = val;
  26. }
  27. static unsigned char jazz_read_status(void)
  28. {
  29. return jazz_kh->command;
  30. }
  31. static inline void kb_wait(void)
  32. {
  33. unsigned long start = jiffies;
  34. unsigned long timeout = start + HZ/2;
  35. do {
  36. if (! (jazz_read_status() & 0x02))
  37. return;
  38. } while (time_before_eq(jiffies, timeout));
  39. }
  40. void jazz_machine_restart(char *command)
  41. {
  42. while(1) {
  43. kb_wait();
  44. jazz_write_command(0xd1);
  45. kb_wait();
  46. jazz_write_output(0x00);
  47. }
  48. }