[v6,008/102] i2c: designware: Avoid using static data
diff mbox series

Message ID 20191206213936.v6.8.I0ca3df8c37005f3314cc4231c4131cb607c4643f@changeid
State Accepted
Delegated to: Bin Meng
Headers show
Series
  • x86: Add initial support for apollolake
Related show

Commit Message

Simon Glass Dec. 7, 2019, 4:41 a.m. UTC
Drivers are not allowed to use static data since they may be used in SPL
where BSS is not available.

It is possible that driver model may provide support for numbering devices
in the future. But for now, move this to global_data.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v6: None
Changes in v5: None
Changes in v4:
- Add new patch to drop static data in designware i2c driver

Changes in v3: None
Changes in v2: None

 arch/x86/include/asm/global_data.h | 1 +
 drivers/i2c/designware_i2c_pci.c   | 9 ++++++---
 2 files changed, 7 insertions(+), 3 deletions(-)

Comments

Bin Meng Dec. 8, 2019, 1:54 a.m. UTC | #1
On Sat, Dec 7, 2019 at 12:46 PM Simon Glass <sjg@chromium.org> wrote:
>
> Drivers are not allowed to use static data since they may be used in SPL
> where BSS is not available.
>
> It is possible that driver model may provide support for numbering devices
> in the future. But for now, move this to global_data.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v6: None
> Changes in v5: None
> Changes in v4:
> - Add new patch to drop static data in designware i2c driver
>
> Changes in v3: None
> Changes in v2: None
>
>  arch/x86/include/asm/global_data.h | 1 +
>  drivers/i2c/designware_i2c_pci.c   | 9 ++++++---
>  2 files changed, 7 insertions(+), 3 deletions(-)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Bin Meng Dec. 8, 2019, 1:59 a.m. UTC | #2
On Sun, Dec 8, 2019 at 9:54 AM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> On Sat, Dec 7, 2019 at 12:46 PM Simon Glass <sjg@chromium.org> wrote:
> >
> > Drivers are not allowed to use static data since they may be used in SPL
> > where BSS is not available.
> >
> > It is possible that driver model may provide support for numbering devices
> > in the future. But for now, move this to global_data.
> >
> > Signed-off-by: Simon Glass <sjg@chromium.org>
> > ---
> >
> > Changes in v6: None
> > Changes in v5: None
> > Changes in v4:
> > - Add new patch to drop static data in designware i2c driver
> >
> > Changes in v3: None
> > Changes in v2: None
> >
> >  arch/x86/include/asm/global_data.h | 1 +
> >  drivers/i2c/designware_i2c_pci.c   | 9 ++++++---
> >  2 files changed, 7 insertions(+), 3 deletions(-)
> >
>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

applied to u-boot-x86/next, thanks!

Patch
diff mbox series

diff --git a/arch/x86/include/asm/global_data.h b/arch/x86/include/asm/global_data.h
index 7f3ada06f6..0e7b946205 100644
--- a/arch/x86/include/asm/global_data.h
+++ b/arch/x86/include/asm/global_data.h
@@ -96,6 +96,7 @@  struct arch_global_data {
 	ulong table;			/* Table pointer from previous loader */
 	int turbo_state;		/* Current turbo state */
 	struct irq_routing_table *pirq_routing_table;
+	int dw_i2c_num_cards;		/* Used by designware i2c driver */
 #ifdef CONFIG_SEABIOS
 	u32 high_table_ptr;
 	u32 high_table_limit;
diff --git a/drivers/i2c/designware_i2c_pci.c b/drivers/i2c/designware_i2c_pci.c
index e8fc6f2a90..8d6bb37f5c 100644
--- a/drivers/i2c/designware_i2c_pci.c
+++ b/drivers/i2c/designware_i2c_pci.c
@@ -34,7 +34,6 @@  static int designware_i2c_pci_probe(struct udevice *dev)
 
 static int designware_i2c_pci_bind(struct udevice *dev)
 {
-	static int num_cards;
 	char name[20];
 
 	/*
@@ -45,9 +44,13 @@  static int designware_i2c_pci_bind(struct udevice *dev)
 	 * using this driver is impossible for PCIe I2C devices.
 	 * This can be removed, once a better (correct) way for this
 	 * is found and implemented.
+	 *
+	 * TODO(sjg@chromium.org): Perhaps if uclasses had platdata this would
+	 * be possible. We cannot use static data in drivers since they may be
+	 * used in SPL or before relocation.
 	 */
-	dev->req_seq = num_cards;
-	sprintf(name, "i2c_designware#%u", num_cards++);
+	dev->req_seq = gd->arch.dw_i2c_num_cards++;
+	sprintf(name, "i2c_designware#%u", dev->req_seq);
 	device_set_name(dev, name);
 
 	return 0;