dipsw.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include <common.h>
  2. #include <board/cogent/dipsw.h>
  3. unsigned char
  4. dipsw_raw(void)
  5. {
  6. return cma_mb_reg_read(&((cma_mb_dipsw *)CMA_MB_DIPSW_BASE)->dip_val);
  7. }
  8. unsigned char
  9. dipsw_cooked(void)
  10. {
  11. unsigned char val1, val2, mask1, mask2;
  12. val1 = dipsw_raw();
  13. /*
  14. * we want to mirror the bits because the low bit is switch 1 and high
  15. * bit is switch 8 and also invert them because 1=off and 0=on, according
  16. * to manual.
  17. *
  18. * this makes the value more intuitive i.e.
  19. * - left most, or high, or top, bit is left most switch (1);
  20. * - right most, or low, or bottom, bit is right most switch (8)
  21. * - a set bit means "on" and a clear bit means "off"
  22. */
  23. val2 = 0;
  24. for (mask1 = 1 << 7, mask2 = 1; mask1 > 0; mask1 >>= 1, mask2 <<= 1)
  25. if ((val1 & mask1) == 0)
  26. val2 |= mask2;
  27. return (val2);
  28. }
  29. void
  30. dipsw_init(void)
  31. {
  32. unsigned char val, mask;
  33. val = dipsw_cooked();
  34. printf("|");
  35. for (mask = 1 << 7; mask > 0; mask >>= 1)
  36. if (val & mask)
  37. printf("on |");
  38. else
  39. printf("off|");
  40. printf("\n");
  41. }