wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 1 | #include <common.h> |
Masahiro Yamada | 87109d4 | 2013-11-11 10:30:20 +0900 | [diff] [blame] | 2 | #include "dipsw.h" |
wdenk | affae2b | 2002-08-17 09:36:01 +0000 | [diff] [blame] | 3 | |
| 4 | unsigned char |
| 5 | dipsw_raw(void) |
| 6 | { |
| 7 | return cma_mb_reg_read(&((cma_mb_dipsw *)CMA_MB_DIPSW_BASE)->dip_val); |
| 8 | } |
| 9 | |
| 10 | unsigned char |
| 11 | dipsw_cooked(void) |
| 12 | { |
| 13 | unsigned char val1, val2, mask1, mask2; |
| 14 | |
| 15 | val1 = dipsw_raw(); |
| 16 | |
| 17 | /* |
| 18 | * we want to mirror the bits because the low bit is switch 1 and high |
| 19 | * bit is switch 8 and also invert them because 1=off and 0=on, according |
| 20 | * to manual. |
| 21 | * |
| 22 | * this makes the value more intuitive i.e. |
| 23 | * - left most, or high, or top, bit is left most switch (1); |
| 24 | * - right most, or low, or bottom, bit is right most switch (8) |
| 25 | * - a set bit means "on" and a clear bit means "off" |
| 26 | */ |
| 27 | |
| 28 | val2 = 0; |
| 29 | for (mask1 = 1 << 7, mask2 = 1; mask1 > 0; mask1 >>= 1, mask2 <<= 1) |
| 30 | if ((val1 & mask1) == 0) |
| 31 | val2 |= mask2; |
| 32 | |
| 33 | return (val2); |
| 34 | } |
| 35 | |
| 36 | void |
| 37 | dipsw_init(void) |
| 38 | { |
| 39 | unsigned char val, mask; |
| 40 | |
| 41 | val = dipsw_cooked(); |
| 42 | |
| 43 | printf("|"); |
| 44 | for (mask = 1 << 7; mask > 0; mask >>= 1) |
| 45 | if (val & mask) |
| 46 | printf("on |"); |
| 47 | else |
| 48 | printf("off|"); |
| 49 | printf("\n"); |
| 50 | } |