From 4e101ada37c10282030729f4a03fd505bd4f526d Mon Sep 17 00:00:00 2001 From: Marshall Dawson Date: Thu, 15 Jun 2017 12:17:38 -0600 Subject: soc/amd/stoneyridge: Fix most checkpatch errors Correct the majority of reported errors and mark most of the remaining ones as todo. (Some of the lines requiring a >80 break are indented too much currently.) Some of the alignment in hudson.h still causes checkpatch errors, but this is intentionally left as-is. Also make other misc. changes, e.g. consistency in lower-case for hex values, using defined values, etc. These changes were confirmed to cause no changes in a Gardenia build. No other improvements were made, e.g. changing to helper functions, or converting functions like __outbyte(). BUG=chrome-os-partner:622407746 Change-Id: I768884a4c4b9505e77f5d6bfde37797520878912 Signed-off-by: Marshall Dawson Reviewed-on: https://review.coreboot.org/19986 Tested-by: build bot (Jenkins) Reviewed-by: Martin Roth --- src/soc/amd/stoneyridge/smbus_spd.c | 101 +++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 48 deletions(-) (limited to 'src/soc/amd/stoneyridge/smbus_spd.c') diff --git a/src/soc/amd/stoneyridge/smbus_spd.c b/src/soc/amd/stoneyridge/smbus_spd.c index 863631a586..73e67024c8 100644 --- a/src/soc/amd/stoneyridge/smbus_spd.c +++ b/src/soc/amd/stoneyridge/smbus_spd.c @@ -20,39 +20,42 @@ #include #include #include +#include #include /*----------------------------------------------------------------------------- * * readSmbusByteData - read a single SPD byte from any offset */ - -static int readSmbusByteData (int iobase, int address, char *buffer, int offset) +static int readSmbusByteData(int iobase, int address, char *buffer, int offset) { unsigned int status; UINT64 limit; address |= 1; // set read bit - __outbyte (iobase + 0, 0xFF); // clear error status - __outbyte (iobase + 1, 0x1F); // clear error status - __outbyte (iobase + 3, offset); // offset in eeprom - __outbyte (iobase + 4, address); // slave address and read bit - __outbyte (iobase + 2, 0x48); // read byte command - - // time limit to avoid hanging for unexpected error status (should never happen) - limit = __rdtsc () + 2000000000 / 10; - for (;;) - { - status = __inbyte (iobase); - if (__rdtsc () > limit) break; - if ((status & 2) == 0) continue; // SMBusInterrupt not set, keep waiting - if ((status & 1) == 1) continue; // HostBusy set, keep waiting + __outbyte(iobase + 0, 0xff); // clear error status + __outbyte(iobase + 1, 0x1f); // clear error status + __outbyte(iobase + 3, offset); // offset in eeprom + __outbyte(iobase + 4, address); // slave address and read bit + __outbyte(iobase + 2, 0x48); // read byte command + + // time limit to avoid hanging for unexpected error status + limit = __rdtsc() + 2000000000 / 10; + for (;;) { + status = __inbyte(iobase); + if (__rdtsc() > limit) + break; + if ((status & 2) == 0) + continue; // SMBusInterrupt not set, keep waiting + if ((status & 1) == 1) + continue; // HostBusy set, keep waiting break; } - buffer [0] = __inbyte (iobase + 5); - if (status == 2) status = 0; // check for done with no errors + buffer[0] = __inbyte(iobase + 5); + if (status == 2) + status = 0; // check for done with no errors return status; } @@ -61,28 +64,30 @@ static int readSmbusByteData (int iobase, int address, char *buffer, int offset) * readSmbusByte - read a single SPD byte from the default offset * this function is faster function readSmbusByteData */ - -static int readSmbusByte (int iobase, int address, char *buffer) +static int readSmbusByte(int iobase, int address, char *buffer) { unsigned int status; UINT64 limit; - __outbyte (iobase + 0, 0xFF); // clear error status - __outbyte (iobase + 2, 0x44); // read command + __outbyte(iobase + 0, 0xff); // clear error status + __outbyte(iobase + 2, 0x44); // read command // time limit to avoid hanging for unexpected error status - limit = __rdtsc () + 2000000000 / 10; - for (;;) - { - status = __inbyte (iobase); - if (__rdtsc () > limit) break; - if ((status & 2) == 0) continue; // SMBusInterrupt not set, keep waiting - if ((status & 1) == 1) continue; // HostBusy set, keep waiting + limit = __rdtsc() + 2000000000 / 10; + for (;;) { + status = __inbyte(iobase); + if (__rdtsc() > limit) + break; + if ((status & 2) == 0) + continue; // SMBusInterrupt not set, keep waiting + if ((status & 1) == 1) + continue; // HostBusy set, keep waiting break; } - buffer [0] = __inbyte (iobase + 5); - if (status == 2) status = 0; // check for done with no errors + buffer[0] = __inbyte(iobase + 5); + if (status == 2) + status = 0; // check for done with no errors return status; } @@ -94,17 +99,16 @@ static int readSmbusByte (int iobase, int address, char *buffer) * sending offset for every byte. * Reads 128 bytes in 7-8 ms at 400 KHz. */ - -static int readspd (int iobase, int SmbusSlaveAddress, char *buffer, int count) +static int readspd(int iobase, int SmbusSlaveAddress, char *buffer, int count) { int index, error; printk(BIOS_SPEW, "-------------READING SPD-----------\n"); printk(BIOS_SPEW, "iobase: 0x%08X, SmbusSlave: 0x%08X, count: %d\n", - iobase, SmbusSlaveAddress, count); + iobase, SmbusSlaveAddress, count); /* read the first byte using offset zero */ - error = readSmbusByteData (iobase, SmbusSlaveAddress, buffer, 0); + error = readSmbusByteData(iobase, SmbusSlaveAddress, buffer, 0); if (error) { printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n"); @@ -112,9 +116,9 @@ static int readspd (int iobase, int SmbusSlaveAddress, char *buffer, int count) } /* read the remaining bytes using auto-increment for speed */ - for (index = 1; index < count; index++) - { - error = readSmbusByte (iobase, SmbusSlaveAddress, &buffer [index]); + for (index = 1 ; index < count ; index++) { + error = readSmbusByte(iobase, SmbusSlaveAddress, + &buffer[index]); if (error) { printk(BIOS_ERR, "-------------SPD READ ERROR-----------\n"); return error; @@ -126,22 +130,23 @@ static int readspd (int iobase, int SmbusSlaveAddress, char *buffer, int count) return 0; } -static void writePmReg (int reg, int data) +static void writePmReg(int reg, int data) { - __outbyte (0xCD6, reg); - __outbyte (0xCD7, data); + __outbyte(PM_INDEX, reg); + __outbyte(PM_DATA, data); } -static void setupFch (int ioBase) +static void setupFch(int ioBase) { - writePmReg (0x2D, ioBase >> 8); - writePmReg (0x2C, ioBase | 1); - __outbyte (ioBase + 0x0E, 66000000 / 400000 / 4); // set SMBus clock to 400 KHz + writePmReg(0x2d, ioBase >> 8); + writePmReg(0x2c, ioBase | 1); + /* set SMBus clock to 400 KHz */ + __outbyte(ioBase + 0x0e, 66000000 / 400000 / 4); } int hudson_readSpd(int spdAddress, char *buf, size_t len) { - int ioBase = 0xB00; - setupFch (ioBase); - return readspd (ioBase, spdAddress, buf, len); + int ioBase = 0xb00; + setupFch(ioBase); + return readspd(ioBase, spdAddress, buf, len); } -- cgit v1.2.3