leds.c 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* leds.c: ASB2364 peripheral 7seg LEDs x4 support
  2. *
  3. * Copyright (C) 2002 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 License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, 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. #if MN10300_USE_7SEGLEDS
  20. static const u8 asb2364_led_hex_tbl[16] = {
  21. 0x80, 0xf2, 0x48, 0x60, 0x32, 0x24, 0x04, 0xf0,
  22. 0x00, 0x20, 0x10, 0x06, 0x8c, 0x42, 0x0c, 0x1c
  23. };
  24. static const u32 asb2364_led_chase_tbl[6] = {
  25. ~0x02020202, /* top - segA */
  26. ~0x04040404, /* right top - segB */
  27. ~0x08080808, /* right bottom - segC */
  28. ~0x10101010, /* bottom - segD */
  29. ~0x20202020, /* left bottom - segE */
  30. ~0x40404040, /* left top - segF */
  31. };
  32. static unsigned asb2364_led_chase;
  33. void peripheral_leds7x4_display_dec(unsigned int val, unsigned int points)
  34. {
  35. u32 leds;
  36. leds = asb2364_led_hex_tbl[(val/1000) % 10];
  37. leds <<= 8;
  38. leds |= asb2364_led_hex_tbl[(val/100) % 10];
  39. leds <<= 8;
  40. leds |= asb2364_led_hex_tbl[(val/10) % 10];
  41. leds <<= 8;
  42. leds |= asb2364_led_hex_tbl[val % 10];
  43. leds |= points^0x01010101;
  44. ASB2364_7SEGLEDS = leds;
  45. }
  46. void peripheral_leds7x4_display_hex(unsigned int val, unsigned int points)
  47. {
  48. u32 leds;
  49. leds = asb2364_led_hex_tbl[(val/1000) % 10];
  50. leds <<= 8;
  51. leds |= asb2364_led_hex_tbl[(val/100) % 10];
  52. leds <<= 8;
  53. leds |= asb2364_led_hex_tbl[(val/10) % 10];
  54. leds <<= 8;
  55. leds |= asb2364_led_hex_tbl[val % 10];
  56. leds |= points^0x01010101;
  57. ASB2364_7SEGLEDS = leds;
  58. }
  59. /* display triple horizontal bar and exception code */
  60. void peripheral_leds_display_exception(enum exception_code code)
  61. {
  62. u32 leds;
  63. leds = asb2364_led_hex_tbl[(code/0x100) % 0x10];
  64. leds <<= 8;
  65. leds |= asb2364_led_hex_tbl[(code/0x10) % 0x10];
  66. leds <<= 8;
  67. leds |= asb2364_led_hex_tbl[code % 0x10];
  68. leds |= 0x6d010101;
  69. ASB2364_7SEGLEDS = leds;
  70. }
  71. void peripheral_leds_led_chase(void)
  72. {
  73. ASB2364_7SEGLEDS = asb2364_led_chase_tbl[asb2364_led_chase];
  74. asb2364_led_chase++;
  75. if (asb2364_led_chase >= 6)
  76. asb2364_led_chase = 0;
  77. }
  78. #else /* MN10300_USE_7SEGLEDS */
  79. void peripheral_leds7x4_display_dec(unsigned int val, unsigned int points) { }
  80. void peripheral_leds7x4_display_hex(unsigned int val, unsigned int points) { }
  81. void peripheral_leds_display_exception(enum exception_code code) { }
  82. void peripheral_leds_led_chase(void) { }
  83. #endif /* MN10300_USE_7SEGLEDS */