All of lore.kernel.org
 help / color / mirror / Atom feed
From: York Sun <yorksun@freescale.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] driver/mxc_i2c: Move static data structure to global_data
Date: Mon, 10 Feb 2014 14:02:52 -0800	[thread overview]
Message-ID: <1392069772-24742-1-git-send-email-yorksun@freescale.com> (raw)

This driver needs a data structure in SRAM before SDRAM is available.
This is not alway the case using .data section. Moving this data
structure to global_data guarantees it is writable.

Signed-off-by: York Sun <yorksun@freescale.com>
CC: Troy Kisky <troy.kisky@boundarydevices.com>
---
 drivers/i2c/mxc_i2c.c             |   18 ++++++++----------
 include/asm-generic/global_data.h |    3 +++
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/i2c/mxc_i2c.c b/drivers/i2c/mxc_i2c.c
index 595019b..48468d7 100644
--- a/drivers/i2c/mxc_i2c.c
+++ b/drivers/i2c/mxc_i2c.c
@@ -22,6 +22,8 @@
 #include <i2c.h>
 #include <watchdog.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 #ifdef I2C_QUIRK_REG
 struct mxc_i2c_regs {
 	uint8_t		iadr;
@@ -411,12 +413,6 @@ struct sram_data {
 	struct i2c_parms i2c_data[3];
 };
 
-/*
- * For SPL boot some boards need i2c before SDRAM is initialized so force
- * variables to live in SRAM
- */
-static struct sram_data __attribute__((section(".data"))) srdata;
-
 static void * const i2c_bases[] = {
 #if defined(CONFIG_MX25)
 	(void *)IMX_I2C_BASE,
@@ -445,9 +441,10 @@ void *i2c_get_base(struct i2c_adapter *adap)
 
 static struct i2c_parms *i2c_get_parms(void *base)
 {
+	struct sram_data *srdata = (void *)gd->srdata;
 	int i = 0;
-	struct i2c_parms *p = srdata.i2c_data;
-	while (i < ARRAY_SIZE(srdata.i2c_data)) {
+	struct i2c_parms *p = srdata->i2c_data;
+	while (i < ARRAY_SIZE(srdata->i2c_data)) {
 		if (p->base == base)
 			return p;
 		p++;
@@ -490,8 +487,9 @@ static int mxc_i2c_probe(struct i2c_adapter *adap, uint8_t chip)
 void bus_i2c_init(void *base, int speed, int unused,
 		int (*idle_bus_fn)(void *p), void *idle_bus_data)
 {
+	struct sram_data *srdata = (void *)gd->srdata;
 	int i = 0;
-	struct i2c_parms *p = srdata.i2c_data;
+	struct i2c_parms *p = srdata->i2c_data;
 	if (!base)
 		return;
 	for (;;) {
@@ -505,7 +503,7 @@ void bus_i2c_init(void *base, int speed, int unused,
 		}
 		p++;
 		i++;
-		if (i >= ARRAY_SIZE(srdata.i2c_data))
+		if (i >= ARRAY_SIZE(srdata->i2c_data))
 			return;
 	}
 	bus_i2c_set_bus_speed(base, speed);
diff --git a/include/asm-generic/global_data.h b/include/asm-generic/global_data.h
index 0de0bea..cc62861 100644
--- a/include/asm-generic/global_data.h
+++ b/include/asm-generic/global_data.h
@@ -72,6 +72,9 @@ typedef struct global_data {
 #if defined(CONFIG_SYS_I2C)
 	int		cur_i2c_bus;	/* current used i2c bus */
 #endif
+#ifdef CONFIG_SYS_I2C_MXC
+	void *srdata[10];
+#endif
 	unsigned long timebase_h;
 	unsigned long timebase_l;
 	struct arch_global_data arch;	/* architecture-specific data */
-- 
1.7.9.5

             reply	other threads:[~2014-02-10 22:02 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-10 22:02 York Sun [this message]
2014-02-10 22:10 ` [U-Boot] [PATCH] driver/mxc_i2c: Move static data structure to global_data Tom Rini
2014-02-10 22:28   ` York Sun
2014-02-10 22:45     ` Tom Rini
2014-02-10 22:47       ` York Sun
2014-02-11 18:01       ` York Sun
2014-02-11 21:46         ` York Sun
2014-02-12 14:41           ` Tom Rini
2014-02-11  2:34 ` York Sun
2014-02-11 19:25   ` Troy Kisky
2014-02-11 19:46     ` York Sun
2014-02-11 19:59       ` Wolfgang Denk
2014-02-11 20:03         ` York Sun
2014-02-11 20:57           ` Wolfgang Denk
2014-02-11 21:02             ` York Sun
2014-02-11 22:12               ` Wolfgang Denk
2014-02-11 22:20                 ` York Sun
2014-02-12 14:27                   ` Wolfgang Denk
2014-02-12 14:43                     ` Tom Rini
2014-02-12 17:56                       ` York Sun

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=1392069772-24742-1-git-send-email-yorksun@freescale.com \
    --to=yorksun@freescale.com \
    --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 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.