Re: [U-Boot] [PATCH v2 45/55] x86: ivybridge: Convert SDRAM init to use driver model

2016-01-21 Thread Bin Meng
On Mon, Jan 18, 2016 at 7:11 AM, Simon Glass  wrote:
> SDRAM init needs access to the Northbridge controller and the Intel
> Management Engine device. Add the latter to the device tree and convert all
> of this code to driver model.
>
> Signed-off-by: Simon Glass 
> Reviewed-by: Bin Meng 
> ---
>
> Changes in v2: None
>
>  arch/x86/cpu/ivybridge/early_me.c| 68 
> 
>  arch/x86/cpu/ivybridge/sdram.c   | 20 ++
>  arch/x86/dts/chromebook_link.dts |  6 +++
>  arch/x86/include/asm/arch-ivybridge/me.h | 45 ++---
>  4 files changed, 101 insertions(+), 38 deletions(-)
>

applied to u-boot-x86/master, thanks!
___
U-Boot mailing list
U-Boot@lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot


[U-Boot] [PATCH v2 45/55] x86: ivybridge: Convert SDRAM init to use driver model

2016-01-17 Thread Simon Glass
SDRAM init needs access to the Northbridge controller and the Intel
Management Engine device. Add the latter to the device tree and convert all
of this code to driver model.

Signed-off-by: Simon Glass 
Reviewed-by: Bin Meng 
---

Changes in v2: None

 arch/x86/cpu/ivybridge/early_me.c| 68 
 arch/x86/cpu/ivybridge/sdram.c   | 20 ++
 arch/x86/dts/chromebook_link.dts |  6 +++
 arch/x86/include/asm/arch-ivybridge/me.h | 45 ++---
 4 files changed, 101 insertions(+), 38 deletions(-)

diff --git a/arch/x86/cpu/ivybridge/early_me.c 
b/arch/x86/cpu/ivybridge/early_me.c
index 711470f..612c910 100644
--- a/arch/x86/cpu/ivybridge/early_me.c
+++ b/arch/x86/cpu/ivybridge/early_me.c
@@ -7,6 +7,7 @@
  */
 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -25,33 +26,36 @@ static const char *const me_ack_values[] = {
[ME_HFS_ACK_CONTINUE]   = "Continue to boot"
 };
 
-static inline void pci_read_dword_ptr(void *ptr, int offset)
+static inline void pci_read_dword_ptr(struct udevice *me_dev, void *ptr,
+ int offset)
 {
u32 dword;
 
-   dword = x86_pci_read_config32(PCH_ME_DEV, offset);
+   dm_pci_read_config32(me_dev, offset, &dword);
memcpy(ptr, &dword, sizeof(dword));
 }
 
-static inline void pci_write_dword_ptr(void *ptr, int offset)
+static inline void pci_write_dword_ptr(struct udevice *me_dev, void *ptr,
+  int offset)
 {
u32 dword = 0;
+
memcpy(&dword, ptr, sizeof(dword));
-   x86_pci_write_config32(PCH_ME_DEV, offset, dword);
+   dm_pci_write_config32(me_dev, offset, dword);
 }
 
-void intel_early_me_status(void)
+void intel_early_me_status(struct udevice *me_dev)
 {
struct me_hfs hfs;
struct me_gmes gmes;
 
-   pci_read_dword_ptr(&hfs, PCI_ME_HFS);
-   pci_read_dword_ptr(&gmes, PCI_ME_GMES);
+   pci_read_dword_ptr(me_dev, &hfs, PCI_ME_HFS);
+   pci_read_dword_ptr(me_dev, &gmes, PCI_ME_GMES);
 
intel_me_status(&hfs, &gmes);
 }
 
-int intel_early_me_init(void)
+int intel_early_me_init(struct udevice *me_dev)
 {
int count;
struct me_uma uma;
@@ -61,7 +65,7 @@ int intel_early_me_init(void)
 
/* Wait for ME UMA SIZE VALID bit to be set */
for (count = ME_RETRY; count > 0; --count) {
-   pci_read_dword_ptr(&uma, PCI_ME_UMA);
+   pci_read_dword_ptr(me_dev, &uma, PCI_ME_UMA);
if (uma.valid)
break;
udelay(ME_DELAY);
@@ -72,7 +76,7 @@ int intel_early_me_init(void)
}
 
/* Check for valid firmware */
-   pci_read_dword_ptr(&hfs, PCI_ME_HFS);
+   pci_read_dword_ptr(me_dev, &hfs, PCI_ME_HFS);
if (hfs.fpt_bad) {
printf("WARNING: ME has bad firmware\n");
return -EBADF;
@@ -83,11 +87,11 @@ int intel_early_me_init(void)
return 0;
 }
 
-int intel_early_me_uma_size(void)
+int intel_early_me_uma_size(struct udevice *me_dev)
 {
struct me_uma uma;
 
-   pci_read_dword_ptr(&uma, PCI_ME_UMA);
+   pci_read_dword_ptr(me_dev, &uma, PCI_ME_UMA);
if (uma.valid) {
debug("ME: Requested %uMB UMA\n", uma.size);
return uma.size;
@@ -97,11 +101,11 @@ int intel_early_me_uma_size(void)
return -EINVAL;
 }
 
-static inline void set_global_reset(int enable)
+static inline void set_global_reset(struct udevice *dev, int enable)
 {
u32 etr3;
 
-   etr3 = x86_pci_read_config32(PCH_LPC_DEV, ETR3);
+   dm_pci_read_config32(dev, ETR3, &etr3);
 
/* Clear CF9 Without Resume Well Reset Enable */
etr3 &= ~ETR3_CWORWRE;
@@ -112,10 +116,11 @@ static inline void set_global_reset(int enable)
else
etr3 &= ~ETR3_CF9GR;
 
-   x86_pci_write_config32(PCH_LPC_DEV, ETR3, etr3);
+   dm_pci_write_config32(dev, ETR3, etr3);
 }
 
-int intel_early_me_init_done(u8 status)
+int intel_early_me_init_done(struct udevice *dev, struct udevice *me_dev,
+uint status)
 {
int count;
u32 mebase_l, mebase_h;
@@ -126,8 +131,8 @@ int intel_early_me_init_done(u8 status)
};
 
/* MEBASE from MESEG_BASE[35:20] */
-   mebase_l = x86_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_L);
-   mebase_h = x86_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_H);
+   dm_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_L, &mebase_l);
+   dm_pci_read_config32(PCH_DEV, PCI_CPU_MEBASE_H, &mebase_h);
mebase_h &= 0xf;
did.uma_base = (mebase_l >> 20) | (mebase_h << 12);
 
@@ -135,25 +140,25 @@ int intel_early_me_init_done(u8 status)
debug("ME: Sending Init Done with status: %d, UMA base: 0x%04x\n",
  status, did.uma_base);
 
-   pci_write_dword_ptr(&did, PCI_ME_H_GS);
+   pci_write_dword_ptr(me_dev, &did, PCI_ME_H_GS);
 
/* Must wait for ME acknowledgeme