15 #define TIMEOUT_US 50000
17 #define spew(...) do { if (SPEW) printk(BIOS_SPEW, ##__VA_ARGS__); } while (0)
20 #define ERR_TIMEOUT -3
30 static int __wait(
unsigned int bus,
int timeout_us,
int for_scl)
46 spew(
"[SDA transitioned to %d after %dus] ",
sda, us);
48 spew(
"[SCL transitioned to %d after %dus] ",
scl, us);
65 "timeout %s!\n",
bus, error_context);
74 spew(
"software_i2c(%d): Sending start condition... ",
bus);
88 "to send start condition!\n",
bus);
100 spew(
"Start condition transmitted!\n");
106 spew(
"software_i2c(%d): Sending stop condition... ",
bus);
124 "stop condition... access by another master or line "
125 "stuck from faulty slave?\n",
bus);
129 spew(
"Stop condition transmitted\n");
135 spew(
"software_i2c(%d): Sending a %d bit... ",
bus, bit);
142 "by slave before clock pulse on transmit!\n",
bus);
155 "by slave after clock pulse on transmit!\n",
bus);
162 spew(
"%d bit sent!\n", bit);
170 spew(
"software_i2c(%d): Receiving a bit... ",
bus);
188 spew(
"Received a %d!\n", bit);
199 for (bit = 0; bit < 8; bit++)
200 if ((ret =
out_bit(
bus, (
byte >> (7 - bit)) & 0x1)) < 0)
205 if (
DEBUG && nack >= 0)
207 "received %s\n",
bus,
byte, nack ?
"NAK" :
"ACK");
216 for (i = 0; i < 8; ++i) {
220 byte = (
byte << 1) | bit;
228 "sent %s\n",
bus,
byte, ack ?
"ACK" :
"NAK");
238 for (seg = segments; seg - segments <
count; seg++) {
244 for (i = 0; i < seg->
len; i++) {
247 seg->
buf[i] = (
u8)ret;
270 for (i = 0; i < 8; ++i)
299 for (i = 0; i < bits; ++i)
322 for (i = 0; i < bits; ++i)
331 printk(
BIOS_INFO,
"software_i2c(%d): wedged data write after %d bits. "
#define assert(statement)
#define printk(level,...)
static int stop_cond(unsigned int bus)
void software_i2c_wedge_ack(unsigned int bus, u8 chip)
void software_i2c_wedge_read(unsigned int bus, u8 chip, u8 reg, int bits)
static int out_byte(unsigned int bus, u8 byte)
int software_i2c_transfer(unsigned int bus, struct i2c_msg *segments, int count)
static int __wait(unsigned int bus, int timeout_us, int for_scl)
static int in_bit(unsigned int bus)
struct software_i2c_ops * software_i2c[SOFTWARE_I2C_MAX_BUS]
static int wait_for_scl(unsigned int bus, const char *error_context)
static void wait(unsigned int bus)
static int out_bit(unsigned int bus, int bit)
static int in_byte(unsigned int bus, int ack)
static int start_cond(unsigned int bus)
void software_i2c_wedge_write(unsigned int bus, u8 chip, u8 reg, int bits)
static struct tpm_chip chip
#define SOFTWARE_I2C_MAX_BUS
static int stopwatch_expired(struct stopwatch *sw)
static long stopwatch_duration_usecs(struct stopwatch *sw)
static void stopwatch_init_usecs_expire(struct stopwatch *sw, long us)
#define BIOS_INFO
BIOS_INFO - Expected events.
#define BIOS_DEBUG
BIOS_DEBUG - Verbose output.
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
#define BIOS_WARNING
BIOS_WARNING - Bad configuration.
static int get_scl(unsigned int bus)
static int get_sda(unsigned int bus)
struct i2c_msg - an I2C transaction segment beginning with START @addr: Slave address,...
int(* get_scl)(unsigned int bus)
void(* set_scl)(unsigned int bus, int high)
int(* get_sda)(unsigned int bus)
void(* set_sda)(unsigned int bus, int high)