[OpenBIOS] [PATCHv2 3/6] escc.c: tidy-up legacy and non-legacy codepaths

Mark Cave-Ayland mark.cave-ayland at ilande.co.uk
Sat Feb 20 18:18:33 CET 2016


Now that the reg addresses are all table-driven, it is possible to
simplify and almost remove the legacy and non-legacy codepaths.

Signed-off-by: Mark Cave-Ayland <mark.cave-ayland at ilande.co.uk>
---
 openbios-devel/drivers/escc.c |   42 ++++++++++++++---------------------------
 1 file changed, 14 insertions(+), 28 deletions(-)

diff --git a/openbios-devel/drivers/escc.c b/openbios-devel/drivers/escc.c
index 44b73f0..c770e23 100644
--- a/openbios-devel/drivers/escc.c
+++ b/openbios-devel/drivers/escc.c
@@ -386,6 +386,7 @@ escc_add_channel(const char *path, const char *node, phys_addr_t addr,
     phandle_t dnode, aliases;
 
     cell props[10];
+    ucell offset;
     int index;
     int legacy;
     int reg_offsets[2][2][3] = {
@@ -438,28 +439,20 @@ escc_add_channel(const char *path, const char *node, phys_addr_t addr,
     set_property(dnode, "compatible", buf, 9);
 
     if (legacy) {
-        props[0] = IO_ESCC_LEGACY_OFFSET + reg_offsets[legacy][index][0];
-        props[1] = 0x1;
-        props[2] = IO_ESCC_LEGACY_OFFSET + reg_offsets[legacy][index][1];
-        props[3] = 0x1;
-        props[4] = IO_ESCC_LEGACY_OFFSET + reg_offsets[legacy][index][2];
-        props[5] = 0x1;
-        set_property(dnode, "reg", (char *)&props, 6 * sizeof(cell));
+        offset = IO_ESCC_LEGACY_OFFSET;
     } else {
-        props[0] = IO_ESCC_OFFSET + reg_offsets[legacy][index][0];
-        props[1] = 0x1;
-        props[2] = IO_ESCC_OFFSET + reg_offsets[legacy][index][1];
-        props[3] = 0x1;
-        props[4] = IO_ESCC_OFFSET + reg_offsets[legacy][index][2];
-        props[5] = 0x1;
-        set_property(dnode, "reg", (char *)&props, 6 * sizeof(cell));
+        offset = IO_ESCC_OFFSET;
     }
 
-    if (legacy) {
-        props[0] = addr + IO_ESCC_LEGACY_OFFSET + index * 0x4;
-    } else {
-        props[0] = addr + IO_ESCC_OFFSET + index * 0x20;
-    }
+    props[0] = offset + reg_offsets[legacy][index][0];
+    props[1] = 0x1;
+    props[2] = offset + reg_offsets[legacy][index][1];
+    props[3] = 0x1;
+    props[4] = offset + reg_offsets[legacy][index][2];
+    props[5] = 0x1;
+    set_property(dnode, "reg", (char *)&props, 6 * sizeof(cell));
+
+    props[0] = addr + offset + reg_offsets[legacy][index][0];
     OLDWORLD(set_property(dnode, "AAPL,address",
             (char *)&props, 1 * sizeof(cell)));
 
@@ -475,15 +468,8 @@ escc_add_channel(const char *path, const char *node, phys_addr_t addr,
 
     device_end();
 
-    if (legacy) {
-        uart_init_line(
-                (unsigned char*)addr + IO_ESCC_LEGACY_OFFSET + index * 0x4,
-                CONFIG_SERIAL_SPEED);
-    } else {
-        uart_init_line(
-                (unsigned char*)addr + IO_ESCC_OFFSET + index * 0x20,
-                CONFIG_SERIAL_SPEED);
-    }
+    uart_init_line((unsigned char*)addr + offset + reg_offsets[legacy][index][0],
+                   CONFIG_SERIAL_SPEED);
 }
 
 void
-- 
1.7.10.4




More information about the OpenBIOS mailing list