#define UART16550_READ(y) ar7240_reg_rd((AR7240_UART_BASE+y))\r
#define UART16550_WRITE(x, z) ar7240_reg_wr((AR7240_UART_BASE+x), z)\r
\r
+/*\r
+ * This is taken from [Linux]/include/linux/kernel.h\r
+ * Keep the name unchanged here\r
+ * When this project decides to include that kernel.h some time,\r
+ * this would be found "automatically" and be removed hopefully\r
+ */\r
+#define DIV_ROUND_CLOSEST(x, divisor)( \\r
+{ \\r
+ typeof(divisor) __divisor = divisor; \\r
+ (((x) + ((__divisor) / 2)) / (__divisor)); \\r
+} \\r
+)\r
+\r
/*\r
* Get CPU, RAM and AHB clocks\r
* Based on: Linux/arch/mips/ath79/clock.c\r
val = ar7240_reg_rd(WASP_BOOTSTRAP_REG);\r
\r
if((val & WASP_REF_CLK_25) == 0){\r
- div = (25 * 1000000) / (16 * CONFIG_BAUDRATE);\r
+ div = DIV_ROUND_CLOSEST((25 * 1000000), (16 * CONFIG_BAUDRATE));\r
} else {\r
- div = (40 * 1000000) / (16 * CONFIG_BAUDRATE);\r
+ div = DIV_ROUND_CLOSEST((40 * 1000000), (16 * CONFIG_BAUDRATE));\r
}\r
#else\r
u32 ahb_freq, ddr_freq, cpu_freq;\r
\r
ar7240_sys_frequency(&cpu_freq, &ddr_freq, &ahb_freq);\r
\r
- div = ahb_freq/(16 * CONFIG_BAUDRATE);\r
+ div = DIV_ROUND_CLOSEST(ahb_freq, (16 * CONFIG_BAUDRATE));\r
\r
MY_WRITE(0xb8040000, 0xcff);\r
MY_WRITE(0xb8040008, 0x3b);\r