leds.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /* ASB2305 Peripheral 7-segment LEDs x4 support
  2. *
  3. * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
  4. * Written by David Howells (dhowells@redhat.com)
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public Licence
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the Licence, or (at your option) any later version.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/param.h>
  13. #include <linux/init.h>
  14. #include <asm/io.h>
  15. #include <asm/processor.h>
  16. #include <asm/intctl-regs.h>
  17. #include <asm/rtc-regs.h>
  18. #include <unit/leds.h>
  19. static const u8 asb2305_led_hex_tbl[16] = {
  20. 0x80, 0xf2, 0x48, 0x60, 0x32, 0x24, 0x04, 0xf0,
  21. 0x00, 0x20, 0x10, 0x06, 0x8c, 0x42, 0x0c, 0x1c
  22. };
  23. static const u32 asb2305_led_chase_tbl[6] = {
  24. ~0x02020202, /* top - segA */
  25. ~0x04040404, /* right top - segB */
  26. ~0x08080808, /* right bottom - segC */
  27. ~0x10101010, /* bottom - segD */
  28. ~0x20202020, /* left bottom - segE */
  29. ~0x40404040, /* left top - segF */
  30. };
  31. static unsigned asb2305_led_chase;
  32. void peripheral_leds7x4_display_dec(unsigned int val, unsigned int points)
  33. {
  34. u32 leds;
  35. leds = asb2305_led_hex_tbl[(val/1000) % 10];
  36. leds <<= 8;
  37. leds |= asb2305_led_hex_tbl[(val/100) % 10];
  38. leds <<= 8;
  39. leds |= asb2305_led_hex_tbl[(val/10) % 10];
  40. leds <<= 8;
  41. leds |= asb2305_led_hex_tbl[val % 10];
  42. leds |= points^0x01010101;
  43. ASB2305_7SEGLEDS = leds;
  44. }
  45. void peripheral_leds7x4_display_hex(unsigned int val, unsigned int points)
  46. {
  47. u32 leds;
  48. leds = asb2305_led_hex_tbl[(val/1000) % 10];
  49. leds <<= 8;
  50. leds |= asb2305_led_hex_tbl[(val/100) % 10];
  51. leds <<= 8;
  52. leds |= asb2305_led_hex_tbl[(val/10) % 10];
  53. leds <<= 8;
  54. leds |= asb2305_led_hex_tbl[val % 10];
  55. leds |= points^0x01010101;
  56. ASB2305_7SEGLEDS = leds;
  57. }
  58. void peripheral_leds_display_exception(enum exception_code code)
  59. {
  60. u32 leds;
  61. leds = asb2305_led_hex_tbl[(code/0x100) % 0x10];
  62. leds <<= 8;
  63. leds |= asb2305_led_hex_tbl[(code/0x10) % 0x10];
  64. leds <<= 8;
  65. leds |= asb2305_led_hex_tbl[code % 0x10];
  66. leds |= 0x6d010101;
  67. ASB2305_7SEGLEDS = leds;
  68. }
  69. void peripheral_leds7x4_display_minssecs(unsigned int time, unsigned int points)
  70. {
  71. u32 leds;
  72. leds = asb2305_led_hex_tbl[(time/600) % 6];
  73. leds <<= 8;
  74. leds |= asb2305_led_hex_tbl[(time/60) % 10];
  75. leds <<= 8;
  76. leds |= asb2305_led_hex_tbl[(time/10) % 6];
  77. leds <<= 8;
  78. leds |= asb2305_led_hex_tbl[time % 10];
  79. leds |= points^0x01010101;
  80. ASB2305_7SEGLEDS = leds;
  81. }
  82. void peripheral_leds7x4_display_rtc(void)
  83. {
  84. unsigned int clock;
  85. u8 mins, secs;
  86. mins = RTMCR;
  87. secs = RTSCR;
  88. clock = ((mins & 0xf0) >> 4);
  89. clock *= 10;
  90. clock += (mins & 0x0f);
  91. clock *= 6;
  92. clock += ((secs & 0xf0) >> 4);
  93. clock *= 10;
  94. clock += (secs & 0x0f);
  95. peripheral_leds7x4_display_minssecs(clock, 0);
  96. }
  97. void peripheral_leds_led_chase(void)
  98. {
  99. ASB2305_7SEGLEDS = asb2305_led_chase_tbl[asb2305_led_chase];
  100. asb2305_led_chase++;
  101. if (asb2305_led_chase >= 6)
  102. asb2305_led_chase = 0;
  103. }