time.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * linux/arch/m68k/sun3x/time.c
  4. *
  5. * Sun3x-specific time handling
  6. */
  7. #include <linux/types.h>
  8. #include <linux/kd.h>
  9. #include <linux/init.h>
  10. #include <linux/sched.h>
  11. #include <linux/kernel_stat.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/rtc.h>
  14. #include <linux/bcd.h>
  15. #include <asm/irq.h>
  16. #include <asm/io.h>
  17. #include <asm/machdep.h>
  18. #include <asm/traps.h>
  19. #include <asm/sun3x.h>
  20. #include <asm/sun3ints.h>
  21. #include "time.h"
  22. #define M_CONTROL 0xf8
  23. #define M_SEC 0xf9
  24. #define M_MIN 0xfa
  25. #define M_HOUR 0xfb
  26. #define M_DAY 0xfc
  27. #define M_DATE 0xfd
  28. #define M_MONTH 0xfe
  29. #define M_YEAR 0xff
  30. #define C_WRITE 0x80
  31. #define C_READ 0x40
  32. #define C_SIGN 0x20
  33. #define C_CALIB 0x1f
  34. int sun3x_hwclk(int set, struct rtc_time *t)
  35. {
  36. volatile struct mostek_dt *h =
  37. (struct mostek_dt *)(SUN3X_EEPROM+M_CONTROL);
  38. unsigned long flags;
  39. local_irq_save(flags);
  40. if(set) {
  41. h->csr |= C_WRITE;
  42. h->sec = bin2bcd(t->tm_sec);
  43. h->min = bin2bcd(t->tm_min);
  44. h->hour = bin2bcd(t->tm_hour);
  45. h->wday = bin2bcd(t->tm_wday);
  46. h->mday = bin2bcd(t->tm_mday);
  47. h->month = bin2bcd(t->tm_mon + 1);
  48. h->year = bin2bcd(t->tm_year % 100);
  49. h->csr &= ~C_WRITE;
  50. } else {
  51. h->csr |= C_READ;
  52. t->tm_sec = bcd2bin(h->sec);
  53. t->tm_min = bcd2bin(h->min);
  54. t->tm_hour = bcd2bin(h->hour);
  55. t->tm_wday = bcd2bin(h->wday);
  56. t->tm_mday = bcd2bin(h->mday);
  57. t->tm_mon = bcd2bin(h->month) - 1;
  58. t->tm_year = bcd2bin(h->year);
  59. h->csr &= ~C_READ;
  60. if (t->tm_year < 70)
  61. t->tm_year += 100;
  62. }
  63. local_irq_restore(flags);
  64. return 0;
  65. }
  66. #if 0
  67. static irqreturn_t sun3x_timer_tick(int irq, void *dev_id)
  68. {
  69. irq_handler_t timer_routine = dev_id;
  70. unsigned long flags;
  71. local_irq_save(flags);
  72. /* Clear the pending interrupt - pulse the enable line low */
  73. disable_irq(5);
  74. enable_irq(5);
  75. timer_routine(0, NULL);
  76. local_irq_restore(flags);
  77. return IRQ_HANDLED;
  78. }
  79. #endif
  80. void __init sun3x_sched_init(irq_handler_t vector)
  81. {
  82. sun3_disable_interrupts();
  83. /* Pulse enable low to get the clock started */
  84. sun3_disable_irq(5);
  85. sun3_enable_irq(5);
  86. sun3_enable_interrupts();
  87. }