Guest User

Untitled

a guest
Dec 10th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. /** Read one byte from the intel i2c, used for reading SPD on intel chipsets only. */
  2. unsigned char smb_read_byte_intel(uint32_t base, uint8_t adr, uint8_t cmd)
  3. {
  4. int l1, h1, l2, h2;
  5. unsigned long long t;
  6. outb(base + SMBHSTSTS, 0x1f); // reset SMBus Controller
  7. outb(base + SMBHSTDAT, 0xff);
  8.  
  9. rdtsc(l1, h1);
  10. while ( inb(base + SMBHSTSTS) & 0x01) // wait until read
  11. {
  12. rdtsc(l2, h2);
  13. t = ((h2 - h1) * 0xffffffff + (l2 - l1)) / (Platform.CPU.TSCFrequency / 100);
  14. if (t > 5)
  15. return 0xFF; // break after 5ms
  16. }
  17.  
  18. outb(base + SMBHSTCMD, cmd);
  19. outb(base + SMBHSTADD, (adr << 1) | 0x01 );
  20. outb(base + SMBHSTCNT, 0x48 );
  21.  
  22. rdtsc(l1, h1);
  23. while (!( inb(base + SMBHSTSTS) & 0x02)) // wait til command finished
  24. {
  25. rdtsc(l2, h2);
  26. t = ((h2 - h1) * 0xffffffff + (l2 - l1)) / (Platform.CPU.TSCFrequency / 100);
  27. if (t > 5)
  28. return 0xFF; // break after 5ms
  29. }
  30. return inb(base + SMBHSTDAT);
  31. }
Add Comment
Please, Sign In to add comment