status-led.c 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * U-boot - status leds
  3. *
  4. * Copyright (c) 2005-2009 Analog Devices Inc.
  5. *
  6. * Licensed under the GPL-2 or later.
  7. */
  8. #include <common.h>
  9. #include <config.h>
  10. #include <command.h>
  11. #include <status_led.h>
  12. static void set_led_f(int pf, int state)
  13. {
  14. switch (state) {
  15. case STATUS_LED_OFF: bfin_write_PORTFIO_CLEAR(pf); break;
  16. case STATUS_LED_BLINKING: bfin_write_PORTFIO_TOGGLE(pf); break;
  17. case STATUS_LED_ON: bfin_write_PORTFIO_SET(pf); break;
  18. }
  19. }
  20. static void set_led_g(int pf, int state)
  21. {
  22. switch (state) {
  23. case STATUS_LED_OFF: bfin_write_PORTGIO_CLEAR(pf); break;
  24. case STATUS_LED_BLINKING: bfin_write_PORTGIO_TOGGLE(pf); break;
  25. case STATUS_LED_ON: bfin_write_PORTGIO_SET(pf); break;
  26. }
  27. }
  28. static void set_leds(led_id_t mask, int state)
  29. {
  30. if (mask & 0x1) set_led_f(PF8, state);
  31. if (mask & 0x2) set_led_g(PG11, state);
  32. if (mask & 0x4) set_led_g(PG12, state);
  33. }
  34. void __led_init(led_id_t mask, int state)
  35. {
  36. bfin_write_PORTF_FER(bfin_read_PORTF_FER() & ~(PF8));
  37. bfin_write_PORTG_FER(bfin_read_PORTG_FER() & ~(PG11 | PG12));
  38. bfin_write_PORTFIO_INEN(bfin_read_PORTFIO_INEN() & ~(PF8));
  39. bfin_write_PORTGIO_INEN(bfin_read_PORTGIO_INEN() & ~(PG11 | PG12));
  40. bfin_write_PORTFIO_DIR(bfin_read_PORTFIO_DIR() | (PF8));
  41. bfin_write_PORTGIO_DIR(bfin_read_PORTGIO_DIR() | (PG11 | PG12));
  42. }
  43. void __led_set(led_id_t mask, int state)
  44. {
  45. set_leds(mask, state);
  46. }
  47. void __led_toggle(led_id_t mask)
  48. {
  49. set_leds(mask, STATUS_LED_BLINKING);
  50. }