blob: 8080cbf7b105e340fc46dfc9fc62f88aa1a724de [file] [log] [blame]
Alexandru Gagniuc359501a2013-05-21 12:17:58 -05001/*
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 Gagniuc359501a2013-05-21 12:17:58 -050015 */
16
17/**
Martin Roth25078202015-01-06 21:05:23 -070018 * @file device/early_smbus.h
Alexandru Gagniuc359501a2013-05-21 12:17:58 -050019 *
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 Rothc4e49f62015-07-11 13:42:54 -060055#if IS_ENABLED(CONFIG_DEBUG_SMBUS)
Alexandru Gagniuc359501a2013-05-21 12:17:58 -050056#define printsmbus(x, ...) printk(BIOS_DEBUG, x, ##__VA_ARGS__)
57#else
58#define printsmbus(x, ...)
59#endif
60
61u32 smbus_get_device(void);
62void smbus_reset(u32 smbus_dev);
63int smbus_print_error(u32 smbus_dev, u8 host_status, int loops);
64int smbus_is_busy(u32 smbus_dev);
65int smbus_wait_until_ready(u32 smbus_dev);
66u8 smbus_read_byte(u32 smbus_dev, u8 addr, u8 offset);
67
68void smbus_delay(void);
69
70#endif /* DEVICE_EARLY_SMBUS_H */