public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Heiko Schocher <hs@denx.de>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 03/12] 83xx, kmeter1: add I2C, dtt, eeprom support
Date: Wed, 11 Feb 2009 19:25:49 +0100	[thread overview]
Message-ID: <4993182D.2030003@denx.de> (raw)

This patch adds I2C support for the Keymile kmeter1 board.
It uses the First I2C Controller from the CPU, for
accessing 4 temperature sensors, an eeprom with IVM data
and the booteeprom over a pca9547 mux.

Signed-off-by: Heiko Schocher <hs@denx.de>
---
 board/keymile/common/common.c   |    2 +-
 board/keymile/kmeter1/kmeter1.c |   32 ++++++++++++++++++++++++++++++++
 drivers/hwmon/lm75.c            |   14 +++++++++++++-
 include/configs/kmeter1.h       |   22 ++++++++++++++++++++++
 4 files changed, 68 insertions(+), 2 deletions(-)

diff --git a/board/keymile/common/common.c b/board/keymile/common/common.c
index 1338950..48ce613 100644
--- a/board/keymile/common/common.c
+++ b/board/keymile/common/common.c
@@ -318,7 +318,7 @@ int ivm_read_eeprom (void)
 	if (buf != NULL)
 		dev_addr = simple_strtoul ((char *)buf, NULL, 16);

-	if (eeprom_read (dev_addr, 0, i2c_buffer, CONFIG_SYS_IVM_EEPROM_MAX_LEN) != 0) {
+	if (i2c_read(dev_addr, 0, 1, i2c_buffer, CONFIG_SYS_IVM_EEPROM_MAX_LEN) != 0) {
 		printf ("Error reading EEprom\n");
 		return -2;
 	}
diff --git a/board/keymile/kmeter1/kmeter1.c b/board/keymile/kmeter1/kmeter1.c
index f04a57a..c2df432 100644
--- a/board/keymile/kmeter1/kmeter1.c
+++ b/board/keymile/kmeter1/kmeter1.c
@@ -59,6 +59,23 @@ const qe_iop_conf_t qe_iop_conf_tab[] = {
 	{0,  0, 0, 0, QE_IOP_TAB_END},
 };

+static int board_init_i2c_busses (void)
+{
+	I2C_MUX_DEVICE *dev = NULL;
+	uchar	*buf;
+
+	/* Set up the Bus for the DTTs */
+	buf = (unsigned char *) getenv ("dtt_bus");
+	if (buf != NULL)
+		dev = i2c_mux_ident_muxstring (buf);
+	if (dev == NULL) {
+		printf ("Error couldn't add Bus for DTT\n");
+		printf ("please setup dtt_bus to where your\n");
+		printf ("DTT is found.\n");
+	}
+	return 0;
+}
+
 int board_early_init_r (void)
 {
 	void *reg = (void *)(CONFIG_SYS_IMMR + 0x14a8);
@@ -80,6 +97,12 @@ int board_early_init_r (void)
 	return 0;
 }

+int misc_init_r (void)
+{
+	board_init_i2c_busses ();
+	return 0;
+}
+
 int fixed_sdram(void)
 {
 	volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR;
@@ -156,3 +179,12 @@ void ft_board_setup (void *blob, bd_t *bd)
 	ft_cpu_setup (blob, bd);
 }
 #endif
+
+#if defined(CONFIG_HUSH_INIT_VAR)
+extern int ivm_read_eeprom (void);
+int hush_init_var (void)
+{
+	ivm_read_eeprom ();
+	return 0;
+}
+#endif
diff --git a/drivers/hwmon/lm75.c b/drivers/hwmon/lm75.c
index 8119821..ecfc345 100644
--- a/drivers/hwmon/lm75.c
+++ b/drivers/hwmon/lm75.c
@@ -42,6 +42,8 @@
 #define DTT_TEMP_HYST		0x2
 #define DTT_TEMP_SET		0x3

+DECLARE_GLOBAL_DATA_PTR;
+
 int dtt_read(int sensor, int reg)
 {
 	int dlen;
@@ -157,7 +159,17 @@ int dtt_init (void)

 	/* switch to correct I2C bus */
 	old_bus = I2C_GET_BUS();
-	I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
+	if ((gd->flags & GD_FLG_RELOC) != GD_FLG_RELOC) {
+		uchar *tmp = (uchar *)getenv("dtt_bus");
+		if (tmp == NULL)
+			printf("FAILED: dtt_bus not defined\n");
+		else {
+			if (i2c_mux_ident_muxstring_f(tmp))
+				printf("FAILED: couldnt switch to bus\n");
+		}
+	} else {
+		I2C_SET_BUS(CONFIG_SYS_DTT_BUS_NUM);
+	}

 	for (i = 0; i < sizeof(sensors); i++) {
 	if (_dtt_init(sensors[i]) != 0)
diff --git a/include/configs/kmeter1.h b/include/configs/kmeter1.h
index 25b1c17..0980eec 100644
--- a/include/configs/kmeter1.h
+++ b/include/configs/kmeter1.h
@@ -32,6 +32,7 @@
 /* include common defines/options for all Keymile boards */
 #include "keymile-common.h"

+#define CONFIG_MISC_INIT_R	1
 /*
  * System Clock Setup
  */
@@ -300,6 +301,25 @@
 #define CONFIG_ENV_SIZE		0x2000
 #endif /* CFG_RAMBOOT */

+/* I2C */
+#define CONFIG_HARD_I2C		/* I2C with hardware support */
+#undef	CONFIG_SOFT_I2C		/* I2C bit-banged */
+#define CONFIG_FSL_I2C
+#define CONFIG_SYS_I2C_SPEED	200000	/* I2C speed and slave address */
+#define CONFIG_SYS_I2C_SLAVE	0x7F
+#define CONFIG_SYS_I2C_OFFSET	0x3000
+
+/* I2C SYSMON (LM75, AD7414 is almost compatible)			*/
+#define CONFIG_DTT_LM75		1	/* ON Semi's LM75		*/
+#define CONFIG_DTT_SENSORS	{0, 1, 2, 3}	/* Sensor addresses		*/
+#define CONFIG_SYS_DTT_MAX_TEMP	70
+#define CONFIG_SYS_DTT_LOW_TEMP	-30
+#define CONFIG_SYS_DTT_HYSTERESIS	3
+#define CONFIG_SYS_DTT_BUS_NUM		(2)
+#define CONFIG_SYS_DTT_BOARD_INIT	1
+
+#define CONFIG_SYS_I2C_EEPROM_ADDR_LEN	2
+
 #if defined(CONFIG_PCI)
 #define CONFIG_CMD_PCI
 #endif
@@ -452,6 +472,8 @@
 	"loadfdt=tftp ${fdt_addr_r} ${fdt_file}\0"			\
 	"loadkernel=tftp ${kernel_addr_r} ${boot_file}\0"		\
 	"unlock=yes\0"							\
+	"EEprom_ivm=pca9547:70:9\0"					\
+	"dtt_bus=pca9547:70:a\0"					\
    ""

 #endif /* __CONFIG_H */
-- 
1.6.0.6

-- 
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany

             reply	other threads:[~2009-02-11 18:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-11 18:25 Heiko Schocher [this message]
2009-02-17  1:36 ` [U-Boot] [PATCH 03/12] 83xx, kmeter1: add I2C, dtt, eeprom support Kim Phillips
2009-02-17  6:03   ` Heiko Schocher
2009-02-18  1:22     ` Kim Phillips
2009-02-18  8:14       ` Heiko Schocher
2009-02-19  0:55         ` Kim Phillips
2009-02-19  8:10           ` Heiko Schocher

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=4993182D.2030003@denx.de \
    --to=hs@denx.de \
    --cc=u-boot@lists.denx.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox