All of lore.kernel.org
 help / color / mirror / Atom feed
From: maxims@google.com
To: openbmc@lists.ozlabs.org
Subject: [PATCH] aspeed: SCU helper functions for I2C.
Date: Mon,  3 Oct 2016 11:55:57 -0700	[thread overview]
Message-ID: <1475520957-78581-1-git-send-email-maxims@google.com> (raw)
In-Reply-To: <1475184427-144121-3-git-send-email-maxims@google.com>

From: Maxim Sloyko <maxims@google.com>

SCU helper functions for configuring I2C pins and accessing APB clock.
---
 arch/arm/include/asm/arch-aspeed/ast_scu.h  |  6 +++++
 arch/arm/include/asm/arch-aspeed/regs-scu.h |  8 ++++++
 arch/arm/mach-aspeed/ast-scu.c              | 38 +++++++++++++++++++++++++++++
 3 files changed, 52 insertions(+)

diff --git a/arch/arm/include/asm/arch-aspeed/ast_scu.h b/arch/arm/include/asm/arch-aspeed/ast_scu.h
index d248416..80ebd6f 100644
--- a/arch/arm/include/asm/arch-aspeed/ast_scu.h
+++ b/arch/arm/include/asm/arch-aspeed/ast_scu.h
@@ -38,6 +38,7 @@ extern void ast_scu_get_who_init_dram(void);
 extern u32 ast_get_clk_source(void);
 extern u32 ast_get_h_pll_clk(void);
 extern u32 ast_get_ahbclk(void);
+extern u32 ast_get_apbclk(void);
 
 extern u32 ast_scu_get_vga_memsize(void);
 
@@ -45,4 +46,9 @@ extern void ast_scu_init_eth(u8 num);
 extern void ast_scu_multi_func_eth(u8 num);
 extern void ast_scu_multi_func_romcs(u8 num);
 
+/* Enable I2C controller and pins for a particular device.
+ * Device numbering starts at 1
+ */
+extern void ast_scu_enable_i2c(u8 num);
+
 #endif
diff --git a/arch/arm/include/asm/arch-aspeed/regs-scu.h b/arch/arm/include/asm/arch-aspeed/regs-scu.h
index aab032a..4c869c1 100644
--- a/arch/arm/include/asm/arch-aspeed/regs-scu.h
+++ b/arch/arm/include/asm/arch-aspeed/regs-scu.h
@@ -915,6 +915,11 @@
 #define SCU_FUN_PIN_ROMA4		(0x1 << 18)
 #define SCU_FUN_PIN_ROMA3		(0x1 << 17)
 #define SCU_FUN_PIN_ROMA2		(0x1 << 16)
+/* AST2500 only */
+#define SCU_FUN_PIN_SDA2		(0x1 << 15)
+#define SCU_FUN_PIN_SCL2		(0x1 << 14)
+#define SCU_FUN_PIN_SDA1		(0x1 << 13)
+#define SCU_FUN_PIN_SCL1		(0x1 << 12)
 
 /* AST_SCU_FUN_PIN_CTRL9		0xA8 - Multi-function Pin Control#9 */
 #define SCU_FUN_PIN_ROMA21		(0x1 << 3)
@@ -950,4 +955,7 @@
 /* AST_SCU_BMC_CLASS			0x19C - BMC device class code and revision ID */
 /* AST_SCU_BMC_DEV_ID			0x1A4 - BMC device ID */
 
+#define SCU_I2C_MIN_BUS_NUM			(1)
+#define SCU_I2C_MAX_BUS_NUM			(14)
+
 #endif
diff --git a/arch/arm/mach-aspeed/ast-scu.c b/arch/arm/mach-aspeed/ast-scu.c
index 280c421..1dbd667 100644
--- a/arch/arm/mach-aspeed/ast-scu.c
+++ b/arch/arm/mach-aspeed/ast-scu.c
@@ -318,6 +318,17 @@ u32 ast_get_ahbclk(void)
 
 #endif /* AST_SOC_G5 */
 
+u32 ast_get_apbclk(void)
+{
+	u32 h_pll = ast_get_h_pll_clk();
+	/* The formula for converting the bit pattern to divisor is
+	 * (4 + 4 * DIV), according to datasheet
+	 */
+	u32 apb_div = 4 + 4 * SCU_GET_PCLK_DIV(ast_scu_read(AST_SCU_CLK_SEL));
+	return h_pll / apb_div;
+}
+
+
 void ast_scu_show_system_info(void)
 {
 
@@ -496,3 +507,30 @@ void ast_scu_get_who_init_dram(void)
 		break;
 	}
 }
+
+void ast_scu_enable_i2c(u8 bus_num)
+{
+	if (bus_num < SCU_I2C_MIN_BUS_NUM || bus_num > SCU_I2C_MAX_BUS_NUM) {
+		debug("%s: bus_num is out of range, must be [%d - %d]\n", __func__,
+			  SCU_I2C_MIN_BUS_NUM, SCU_I2C_MAX_BUS_NUM);
+		return;
+	}
+
+	/* Enable I2C Controllers */
+	clrbits_le32(AST_SCU_BASE + AST_SCU_RESET, SCU_RESET_I2C);
+
+	if (bus_num >= 3) {
+		setbits_le32(AST_SCU_BASE + AST_SCU_FUN_PIN_CTRL5,
+					 SCU_FUN_PIN_I2C(bus_num));
+#ifdef AST_SOC_G5
+	/* In AST2400 aka AST_SOC_G4 SDA{1,2}/SCL{1,2} are fixed function pins,
+	 * so no need to change their function. */
+	} else if (bus_num == 1) {
+		setbits_le32(AST_SCU_BASE + AST_SCU_FUN_PIN_CTRL8,
+					 SCU_FUN_PIN_SDA1 | SCU_FUN_PIN_SCL1);
+	} else if (bus_num == 2) {
+		setbits_le32(AST_SCU_BASE + AST_SCU_FUN_PIN_CTRL8,
+					 SCU_FUN_PIN_SDA2 | SCU_FUN_PIN_SCL2);
+#endif
+	}
+}
-- 
2.8.0.rc3.226.g39d4020

  reply	other threads:[~2016-10-03 18:56 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-19 17:26 [PATCH] aspeed/g5: Device Tree for ast2500 and eval board, I2C driver maxims
2016-09-22 18:40 ` Maxim Sloyko
2016-09-23  1:59 ` Joel Stanley
2016-09-27 17:48   ` Maxim Sloyko
2016-09-27 17:43 ` [PATCH 1/3] aspeed/g5: Device Tree for ast2500, copied from openbmc/linux (include file), plus minimal device tree configuration for ast2500 eval board maxims
2016-09-27 17:43   ` [PATCH 2/3] aspeed/g5: helper SCU functions for configuring aspeed I2C maxims
2016-09-29  1:03     ` Joel Stanley
2016-09-29 18:23       ` Maxim Sloyko
2016-09-30  1:49         ` Andrew Jeffery
2016-10-03 18:57           ` Maxim Sloyko
2016-09-29 21:27     ` [PATCH 1/3] aspeed: Fix regs-scu.h and ast_scu.h incompatibility maxims
2016-09-29 21:27       ` [PATCH 2/3] aspeed: Fixed FUC -> FUN typo in SCU maxims
2016-10-05 16:17         ` Maxim Sloyko
2016-10-14  0:07         ` Joel Stanley
2016-10-17 17:57           ` Maxim Sloyko
2016-10-18  6:36             ` Joel Stanley
2016-10-27 18:52               ` Maxim Sloyko
2016-09-29 21:27       ` [PATCH 3/3] aspeed: SCU helper functions for I2C maxims
2016-10-03 18:55         ` maxims [this message]
2016-10-05 16:16           ` [PATCH] " Maxim Sloyko
2016-10-14  0:06           ` Joel Stanley
2016-09-27 17:43   ` [PATCH 3/3] aspeed/g5: I2C driver maxims
2016-09-29  1:27     ` Joel Stanley
2016-10-03 20:41       ` Maxim Sloyko
2016-10-10  7:19         ` Joel Stanley
2016-10-10 16:20           ` Maxim Sloyko
2016-10-03 20:42     ` [PATCH] aspeed/g5,g4: " maxims
2016-10-04 20:59       ` Cédric Le Goater
2016-10-05  0:15         ` Maxim Sloyko
2016-10-05  2:33           ` Joel Stanley
2016-10-05  3:10           ` Andrew Jeffery
2016-09-29  1:29   ` [PATCH 1/3] aspeed/g5: Device Tree for ast2500, copied from openbmc/linux (include file), plus minimal device tree configuration for ast2500 eval board Joel Stanley
2016-09-29 17:02     ` Maxim Sloyko
2016-09-29 18:32   ` [PATCH] aspeed/g5: Device Tree for ast2500 maxims
2016-10-05 16:16     ` Maxim Sloyko
2016-10-06 17:16       ` Maxim Sloyko
2016-10-14  0:14         ` Joel Stanley
2016-10-14 16:40           ` Maxim Sloyko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1475520957-78581-1-git-send-email-maxims@google.com \
    --to=maxims@google.com \
    --cc=openbmc@lists.ozlabs.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.