Alexandru Gagniuc | ee2bc27 | 2013-05-21 12:35:08 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Alexandru Gagniuc <mr.nuke.me@gmail.com> |
| 5 | * |
| 6 | * This program is free software: you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation, either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
Alexandru Gagniuc | ee2bc27 | 2013-05-21 12:35:08 -0500 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include "via_early_smbus.h" |
| 18 | #include <console/console.h> |
| 19 | |
| 20 | /** |
| 21 | * \brief Wait for the SMBus to become ready to process a new transaction. |
| 22 | * |
| 23 | * @param smbus_dev The base SMBus IO port |
| 24 | */ |
| 25 | int smbus_wait_until_ready(u32 smbus_dev) |
| 26 | { |
| 27 | int loops; |
| 28 | |
| 29 | printsmbus("Waiting until SMBus ready\n"); |
| 30 | |
| 31 | /* Loop up to SMBUS_TIMEOUT times, waiting for bit 0 of the |
| 32 | * SMBus Host Status register to go to 0, indicating the operation |
| 33 | * was completed successfully. I don't remember why I did it this way, |
| 34 | * but I think it was because ROMCC was running low on registers */ |
| 35 | loops = 0; |
| 36 | while (smbus_is_busy(smbus_dev) && loops < SMBUS_TIMEOUT) |
| 37 | ++loops; |
| 38 | |
| 39 | return smbus_print_error(smbus_dev, inb(SMBHSTSTAT(smbus_dev)), loops); |
| 40 | } |