Alexandru Gagniuc | 359501a | 2013-05-21 12:17:58 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2011 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 | 359501a | 2013-05-21 12:17:58 -0500 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | /** |
Martin Roth | 2507820 | 2015-01-06 21:05:23 -0700 | [diff] [blame] | 18 | * @file device/early_smbus.h |
Alexandru Gagniuc | 359501a | 2013-05-21 12:17:58 -0500 | [diff] [blame] | 19 | * |
| 20 | * This file defines a common API for accessing the SMBus during early |
| 21 | * initialization. It defines the prototypes for common SMBus functions. The |
| 22 | * actual implementations are hardware-dependent. |
| 23 | * |
| 24 | * The first parameter of all SMBus functions take a u32 value smbus_dev which |
| 25 | * represents some information on how to access the device, and is |
| 26 | * implementation defined. Usually, it just contains the IO base for the smbus. |
| 27 | * To get this argument @ref smbus_get_device() can be used. |
| 28 | * |
| 29 | * The header only defines the prototypes. Several steps are needed to use |
| 30 | * these: |
| 31 | * |
| 32 | * 1. Include this header |
| 33 | * @code{.c} |
| 34 | * #include <device/early_smbus.h> |
| 35 | * @endcode |
| 36 | * |
| 37 | * 2. Implement early_smbus.c for the hardware, or find a compatible |
| 38 | * implementation. |
| 39 | * |
| 40 | * 3. Link against the file that implements these functions. In the Makefile.inc |
| 41 | * of the chipset, add: |
| 42 | * @code |
| 43 | * romstage-y += ./path/to/early_smbus.c |
| 44 | * @endcode |
| 45 | */ |
| 46 | |
| 47 | #ifndef DEVICE_EARLY_SMBUS_H |
| 48 | #define DEVICE_EARLY_SMBUS_H |
| 49 | |
| 50 | #include <stdint.h> |
| 51 | |
| 52 | /** |
| 53 | * \brief printk macro for SMBus debugging |
| 54 | */ |
Martin Roth | c4e49f6 | 2015-07-11 13:42:54 -0600 | [diff] [blame] | 55 | #if IS_ENABLED(CONFIG_DEBUG_SMBUS) |
Alexandru Gagniuc | 359501a | 2013-05-21 12:17:58 -0500 | [diff] [blame] | 56 | #define printsmbus(x, ...) printk(BIOS_DEBUG, x, ##__VA_ARGS__) |
| 57 | #else |
| 58 | #define printsmbus(x, ...) |
| 59 | #endif |
| 60 | |
| 61 | u32 smbus_get_device(void); |
| 62 | void smbus_reset(u32 smbus_dev); |
| 63 | int smbus_print_error(u32 smbus_dev, u8 host_status, int loops); |
| 64 | int smbus_is_busy(u32 smbus_dev); |
| 65 | int smbus_wait_until_ready(u32 smbus_dev); |
| 66 | u8 smbus_read_byte(u32 smbus_dev, u8 addr, u8 offset); |
| 67 | |
| 68 | void smbus_delay(void); |
| 69 | |
| 70 | #endif /* DEVICE_EARLY_SMBUS_H */ |