From patchwork Wed Nov 3 14:13:52 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: simplify vt8237r_early_smbus.c (was: Re: [PATCH 3/7] ASUS M2V support (v2): simplify vt8237r_early_smbus.c (unchanged)) Date: Wed, 03 Nov 2010 14:13:52 -0000 From: Tobias Diedrich X-Patchwork-Id: 2234 Message-Id: <20101103141352.GA31684@yumi.tdiedrich.de> To: coreboot@coreboot.org Cc: Rudolf Marek Rudolf Marek wrote: > On 29.10.2010 13:59, Tobias Diedrich wrote: >> Instead of duplicating the pci_locate_device calls multiple times, >> add a get_vt8237_lpc() function. > > Yeah nice idea! Can I get separate patch for that? In the meanwhile do we > need to call the enablefidvid for "A" ? I think we dont scritly need > that. Maybe we can make it part of 2/7 and leave this just for the grand > get_vt8237_lpc() function? (and I can apply that before 2/7 so you don't > need to re-do the stuff) Here you go: Instead of duplicating the pci_locate_device calls multiple times, add a get_vt8237_lpc() function. The devid variable introduced to vt8237_sb_enable_fid_vid() in hunk 3 will come in handy in the patch adding vt8237a support. I think it also makes the logic a bit more clear. The other option would be to not use get_vt8237_lpc() in vt8237_sb_enable_fid_vid() and leave that bit to the vt8237a support patch. Signed-off-by: Tobias Diedrich --- Index: src/southbridge/via/vt8237r/vt8237r_early_smbus.c =================================================================== --- src/southbridge/via/vt8237r/vt8237r_early_smbus.c.orig 2010-11-03 14:54:54.000000000 +0100 +++ src/southbridge/via/vt8237r/vt8237r_early_smbus.c 2010-11-03 15:00:34.000000000 +0100 @@ -134,6 +134,21 @@ #define PSONREADY_TIMEOUT 0x7fffffff +static device_t get_vt8237_lpc(void) +{ + device_t dev; + + /* Power management controller */ + dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA, + PCI_DEVICE_ID_VIA_VT8237R_LPC), 0); + if (dev != PCI_DEV_INVALID) + return dev; + + dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA, + PCI_DEVICE_ID_VIA_VT8237S_LPC), 0); + return dev; +} + /** * Enable the SMBus on VT8237R-based systems. */ @@ -143,15 +158,9 @@ int loops; /* Power management controller */ - dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA, - PCI_DEVICE_ID_VIA_VT8237R_LPC), 0); - if (dev == PCI_DEV_INVALID) { - /* Power management controller */ - dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA, - PCI_DEVICE_ID_VIA_VT8237S_LPC), 0); - if (dev == PCI_DEV_INVALID) - die("Power management controller not found\n"); - } + dev = get_vt8237_lpc(); + if (dev == PCI_DEV_INVALID) + die("Power management controller not found\n"); /* Make sure the RTC power well is up before touching smbus. */ loops = 0; @@ -235,17 +244,15 @@ void vt8237_sb_enable_fid_vid(void) { device_t dev, devctl; + u16 devid; /* Power management controller */ - dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA, - PCI_DEVICE_ID_VIA_VT8237R_LPC), 0); - if (dev == PCI_DEV_INVALID) { - /* Power management controller */ - dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA, - PCI_DEVICE_ID_VIA_VT8237S_LPC), 0); - if (dev == PCI_DEV_INVALID) - return; + dev = get_vt8237_lpc(); + if (dev == PCI_DEV_INVALID) + return; + devid = pci_read_config16(dev, PCI_DEVICE_ID); + if (devid == PCI_DEVICE_ID_VIA_VT8237S_LPC) { devctl = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT8237_VLINK), 0); @@ -292,15 +292,9 @@ device_t dev; /* Power management controller */ - dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA, - PCI_DEVICE_ID_VIA_VT8237R_LPC), 0); - if (dev == PCI_DEV_INVALID) { - /* Power management controller */ - dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA, - PCI_DEVICE_ID_VIA_VT8237S_LPC), 0); - if (dev == PCI_DEV_INVALID) - return; - } + dev = get_vt8237_lpc(); + if (dev == PCI_DEV_INVALID) + return; /* ROM decode last 1MB FFC00000 - FFFFFFFF. */ pci_write_config8(dev, 0x41, 0x7f); @@ -316,15 +310,9 @@ print_debug("IN TEST WAKEUP\n"); /* Power management controller */ - dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA, - PCI_DEVICE_ID_VIA_VT8237R_LPC), 0); - if (dev == PCI_DEV_INVALID) { - /* Power management controller */ - dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA, - PCI_DEVICE_ID_VIA_VT8237S_LPC), 0); - if (dev == PCI_DEV_INVALID) - die("Power management controller not found\n"); - } + dev = get_vt8237_lpc(); + if (dev == PCI_DEV_INVALID) + die("Power management controller not found\n"); /* Set ACPI base address to I/O VT8237R_ACPI_IO_BASE. */ pci_write_config16(dev, 0x88, VT8237R_ACPI_IO_BASE | 0x1);