0f2dd1eff9
Split `i2c.h` into three pieces to ease reuse of the generic defi- nitions. No code is changed. * `i2c.h` - keeps the generic definitions * `i2c_simple.h` - holds the current, limited to one controller driver per board, devicetree independent I2C interface * `i2c_bus.h` - will become the devicetree compatible interface for native I2C (e.g. non-SMBus) controllers Change-Id: I382d45c70f9314588663e1284f264f877469c74d Signed-off-by: Nico Huber <nico.huber@secunet.com> Reviewed-on: https://review.coreboot.org/20845 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Aaron Durbin <adurbin@chromium.org>
69 lines
2.6 KiB
C
69 lines
2.6 KiB
C
/*
|
|
* This file is part of the coreboot project.
|
|
*
|
|
* Copyright (C) 2014 Google, Inc.
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; version 2 of the License.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*/
|
|
|
|
#ifndef _DEVICE_I2C_H_
|
|
#define _DEVICE_I2C_H_
|
|
|
|
#include <stdint.h>
|
|
|
|
/**
|
|
* struct i2c_msg - an I2C transaction segment beginning with START
|
|
* @addr: Slave address, either seven or ten bits. When this is a ten
|
|
* bit address, I2C_M_TEN must be set in @flags.
|
|
* @flags: I2C_M_RD is handled by all adapters.
|
|
* @len: Number of data bytes in @buf being read from or written to the
|
|
* I2C slave address. For read transactions where I2C_M_RECV_LEN
|
|
* is set, the caller guarantees that this buffer can hold up to
|
|
* 32 bytes in addition to the initial length byte sent by the
|
|
* slave (plus, if used, the SMBus PEC).
|
|
* @buf: The buffer into which data is read, or from which it's written.
|
|
*
|
|
* An i2c_msg is the low level representation of one segment of an I2C
|
|
* transaction. It is visible to drivers in the @i2c_transfer() procedure.
|
|
*
|
|
* All I2C adapters implement the standard rules for I2C transactions. Each
|
|
* transaction begins with a START. That is followed by the slave address,
|
|
* and a bit encoding read versus write. Then follow all the data bytes,
|
|
* possibly including a byte with SMBus PEC. The transfer terminates with
|
|
* a NAK, or when all those bytes have been transferred and ACKed. If this
|
|
* is the last message in a group, it is followed by a STOP. Otherwise it
|
|
* is followed by the next @i2c_msg transaction segment, beginning with a
|
|
* (repeated) START.
|
|
*/
|
|
struct i2c_msg {
|
|
uint16_t flags;
|
|
#define I2C_M_RD 0x0001 /* read data, from slave to master */
|
|
#define I2C_M_TEN 0x0010 /* this is a ten bit chip address */
|
|
#define I2C_M_RECV_LEN 0x0400 /* length will be first received byte */
|
|
#define I2C_M_NOSTART 0x4000 /* don't send a repeated START */
|
|
uint16_t slave; /* slave address */
|
|
uint16_t len; /* msg length */
|
|
uint8_t *buf; /* pointer to msg data */
|
|
};
|
|
|
|
enum i2c_speed {
|
|
I2C_SPEED_STANDARD = 100000,
|
|
I2C_SPEED_FAST = 400000,
|
|
I2C_SPEED_FAST_PLUS = 1000000,
|
|
I2C_SPEED_HIGH = 3400000,
|
|
I2C_SPEED_FAST_ULTRA = 5000000,
|
|
};
|
|
|
|
enum i2c_address_mode {
|
|
I2C_MODE_7_BIT,
|
|
I2C_MODE_10_BIT
|
|
};
|
|
|
|
#endif /* _DEVICE_I2C_H_ */
|