summaryrefslogtreecommitdiffstats
path: root/qemu/roms/u-boot/board/cogent/dipsw.c
diff options
context:
space:
mode:
authorYang Zhang <yang.z.zhang@intel.com>2015-08-28 09:58:54 +0800
committerYang Zhang <yang.z.zhang@intel.com>2015-09-01 12:44:00 +0800
commite44e3482bdb4d0ebde2d8b41830ac2cdb07948fb (patch)
tree66b09f592c55df2878107a468a91d21506104d3f /qemu/roms/u-boot/board/cogent/dipsw.c
parent9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (diff)
Add qemu 2.4.0
Change-Id: Ic99cbad4b61f8b127b7dc74d04576c0bcbaaf4f5 Signed-off-by: Yang Zhang <yang.z.zhang@intel.com>
Diffstat (limited to 'qemu/roms/u-boot/board/cogent/dipsw.c')
-rw-r--r--qemu/roms/u-boot/board/cogent/dipsw.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/qemu/roms/u-boot/board/cogent/dipsw.c b/qemu/roms/u-boot/board/cogent/dipsw.c
new file mode 100644
index 000000000..ecfbc2598
--- /dev/null
+++ b/qemu/roms/u-boot/board/cogent/dipsw.c
@@ -0,0 +1,50 @@
+#include <common.h>
+#include "dipsw.h"
+
+unsigned char
+dipsw_raw(void)
+{
+ return cma_mb_reg_read(&((cma_mb_dipsw *)CMA_MB_DIPSW_BASE)->dip_val);
+}
+
+unsigned char
+dipsw_cooked(void)
+{
+ unsigned char val1, val2, mask1, mask2;
+
+ val1 = dipsw_raw();
+
+ /*
+ * we want to mirror the bits because the low bit is switch 1 and high
+ * bit is switch 8 and also invert them because 1=off and 0=on, according
+ * to manual.
+ *
+ * this makes the value more intuitive i.e.
+ * - left most, or high, or top, bit is left most switch (1);
+ * - right most, or low, or bottom, bit is right most switch (8)
+ * - a set bit means "on" and a clear bit means "off"
+ */
+
+ val2 = 0;
+ for (mask1 = 1 << 7, mask2 = 1; mask1 > 0; mask1 >>= 1, mask2 <<= 1)
+ if ((val1 & mask1) == 0)
+ val2 |= mask2;
+
+ return (val2);
+}
+
+void
+dipsw_init(void)
+{
+ unsigned char val, mask;
+
+ val = dipsw_cooked();
+
+ printf("|");
+ for (mask = 1 << 7; mask > 0; mask >>= 1)
+ if (val & mask)
+ printf("on |");
+ else
+ printf("off|");
+ printf("\n");
+}