<div dir="ltr">Ping</div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 3, 2016 at 11:55 AM,  <span dir="ltr"><<a href="mailto:maxims@google.com" target="_blank">maxims@google.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">From: Maxim Sloyko <<a href="mailto:maxims@google.com">maxims@google.com</a>><br>
<br>
SCU helper functions for configuring I2C pins and accessing APB clock.<br>
---<br>
 arch/arm/include/asm/arch-<wbr>aspeed/ast_scu.h  |  6 +++++<br>
 arch/arm/include/asm/arch-<wbr>aspeed/regs-scu.h |  8 ++++++<br>
</span> arch/arm/mach-aspeed/ast-scu.c              | 38 +++++++++++++++++++++++++++++<br>
 3 files changed, 52 insertions(+)<br>
<div><div class="h5"><br>
diff --git a/arch/arm/include/asm/arch-<wbr>aspeed/ast_scu.h b/arch/arm/include/asm/arch-<wbr>aspeed/ast_scu.h<br>
index d248416..80ebd6f 100644<br>
--- a/arch/arm/include/asm/arch-<wbr>aspeed/ast_scu.h<br>
+++ b/arch/arm/include/asm/arch-<wbr>aspeed/ast_scu.h<br>
@@ -38,6 +38,7 @@ extern void ast_scu_get_who_init_dram(<wbr>void);<br>
 extern u32 ast_get_clk_source(void);<br>
 extern u32 ast_get_h_pll_clk(void);<br>
 extern u32 ast_get_ahbclk(void);<br>
+extern u32 ast_get_apbclk(void);<br>
<br>
 extern u32 ast_scu_get_vga_memsize(void);<br>
<br>
@@ -45,4 +46,9 @@ extern void ast_scu_init_eth(u8 num);<br>
 extern void ast_scu_multi_func_eth(u8 num);<br>
 extern void ast_scu_multi_func_romcs(u8 num);<br>
<br>
+/* Enable I2C controller and pins for a particular device.<br>
+ * Device numbering starts at 1<br>
+ */<br>
+extern void ast_scu_enable_i2c(u8 num);<br>
+<br>
 #endif<br>
diff --git a/arch/arm/include/asm/arch-<wbr>aspeed/regs-scu.h b/arch/arm/include/asm/arch-<wbr>aspeed/regs-scu.h<br>
index aab032a..4c869c1 100644<br>
--- a/arch/arm/include/asm/arch-<wbr>aspeed/regs-scu.h<br>
+++ b/arch/arm/include/asm/arch-<wbr>aspeed/regs-scu.h<br>
@@ -915,6 +915,11 @@<br>
 #define SCU_FUN_PIN_ROMA4              (0x1 << 18)<br>
 #define SCU_FUN_PIN_ROMA3              (0x1 << 17)<br>
 #define SCU_FUN_PIN_ROMA2              (0x1 << 16)<br>
+/* AST2500 only */<br>
+#define SCU_FUN_PIN_SDA2               (0x1 << 15)<br>
+#define SCU_FUN_PIN_SCL2               (0x1 << 14)<br>
+#define SCU_FUN_PIN_SDA1               (0x1 << 13)<br>
+#define SCU_FUN_PIN_SCL1               (0x1 << 12)<br>
<br>
 /* AST_SCU_FUN_PIN_CTRL9               0xA8 - Multi-function Pin Control#9 */<br>
 #define SCU_FUN_PIN_ROMA21             (0x1 << 3)<br>
@@ -950,4 +955,7 @@<br>
 /* AST_SCU_BMC_CLASS                   0x19C - BMC device class code and revision ID */<br>
 /* AST_SCU_BMC_DEV_ID                  0x1A4 - BMC device ID */<br>
<br>
+#define SCU_I2C_MIN_BUS_NUM                    (1)<br>
+#define SCU_I2C_MAX_BUS_NUM                    (14)<br>
+<br>
 #endif<br>
diff --git a/arch/arm/mach-aspeed/ast-<wbr>scu.c b/arch/arm/mach-aspeed/ast-<wbr>scu.c<br>
</div></div>index 280c421..1dbd667 100644<br>
<span class="">--- a/arch/arm/mach-aspeed/ast-<wbr>scu.c<br>
+++ b/arch/arm/mach-aspeed/ast-<wbr>scu.c<br>
@@ -318,6 +318,17 @@ u32 ast_get_ahbclk(void)<br>
<br>
 #endif /* AST_SOC_G5 */<br>
<br>
+u32 ast_get_apbclk(void)<br>
+{<br>
+       u32 h_pll = ast_get_h_pll_clk();<br>
+       /* The formula for converting the bit pattern to divisor is<br>
+        * (4 + 4 * DIV), according to datasheet<br>
+        */<br>
+       u32 apb_div = 4 + 4 * SCU_GET_PCLK_DIV(ast_scu_read(<wbr>AST_SCU_CLK_SEL));<br>
+       return h_pll / apb_div;<br>
+}<br>
+<br>
+<br>
 void ast_scu_show_system_info(void)<br>
 {<br>
<br>
</span>@@ -496,3 +507,30 @@ void ast_scu_get_who_init_dram(<wbr>void)<br>
<span class="">                break;<br>
        }<br>
 }<br>
+<br>
+void ast_scu_enable_i2c(u8 bus_num)<br>
+{<br>
+       if (bus_num < SCU_I2C_MIN_BUS_NUM || bus_num > SCU_I2C_MAX_BUS_NUM) {<br>
+               debug("%s: bus_num is out of range, must be [%d - %d]\n", __func__,<br>
+                         SCU_I2C_MIN_BUS_NUM, SCU_I2C_MAX_BUS_NUM);<br>
+               return;<br>
+       }<br>
+<br>
+       /* Enable I2C Controllers */<br>
+       clrbits_le32(AST_SCU_BASE + AST_SCU_RESET, SCU_RESET_I2C);<br>
+<br>
+       if (bus_num >= 3) {<br>
+               setbits_le32(AST_SCU_BASE + AST_SCU_FUN_PIN_CTRL5,<br>
+                                        SCU_FUN_PIN_I2C(bus_num));<br>
+#ifdef AST_SOC_G5<br>
</span>+       /* In AST2400 aka AST_SOC_G4 SDA{1,2}/SCL{1,2} are fixed function pins,<br>
+        * so no need to change their function. */<br>
<div class="HOEnZb"><div class="h5">+       } else if (bus_num == 1) {<br>
+               setbits_le32(AST_SCU_BASE + AST_SCU_FUN_PIN_CTRL8,<br>
+                                        SCU_FUN_PIN_SDA1 | SCU_FUN_PIN_SCL1);<br>
+       } else if (bus_num == 2) {<br>
+               setbits_le32(AST_SCU_BASE + AST_SCU_FUN_PIN_CTRL8,<br>
+                                        SCU_FUN_PIN_SDA2 | SCU_FUN_PIN_SCL2);<br>
+#endif<br>
+       }<br>
+}<br>
--<br>
2.8.0.rc3.226.g39d4020<br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature" data-smartmail="gmail_signature"><div><b>M</b>axim <b>S</b>loyko</div></div>
</div>