hw/i2c: support multiple masters

Allow slaves to master the bus by registering a bottom halve. If the bus
is busy, the bottom half is queued up. When a slave has succesfully
mastered the bus, the bottom half is scheduled.

Signed-off-by: Klaus Jensen <k.jensen@samsung.com>
[ clg : - fixed typos in commit log ]
Message-Id: <20220601210831.67259-4-its@irrelevant.dk>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
Message-Id: <20220630045133.32251-5-me@pjd.dev>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
This commit is contained in:
Klaus Jensen 2022-06-30 09:21:14 +02:00 committed by Cédric Le Goater
parent 0c0f1bee6a
commit 37fa5ca426
2 changed files with 47 additions and 1 deletions

View file

@ -69,13 +69,25 @@ struct I2CNode {
QLIST_ENTRY(I2CNode) next;
};
typedef struct I2CPendingMaster I2CPendingMaster;
struct I2CPendingMaster {
QEMUBH *bh;
QSIMPLEQ_ENTRY(I2CPendingMaster) entry;
};
typedef QLIST_HEAD(I2CNodeList, I2CNode) I2CNodeList;
typedef QSIMPLEQ_HEAD(I2CPendingMasters, I2CPendingMaster) I2CPendingMasters;
struct I2CBus {
BusState qbus;
I2CNodeList current_devs;
I2CPendingMasters pending_masters;
uint8_t saved_address;
bool broadcast;
/* Set from slave currently mastering the bus. */
QEMUBH *bh;
};
I2CBus *i2c_init_bus(DeviceState *parent, const char *name);
@ -117,6 +129,8 @@ int i2c_start_send(I2CBus *bus, uint8_t address);
void i2c_end_transfer(I2CBus *bus);
void i2c_nack(I2CBus *bus);
void i2c_bus_master(I2CBus *bus, QEMUBH *bh);
void i2c_bus_release(I2CBus *bus);
int i2c_send(I2CBus *bus, uint8_t data);
uint8_t i2c_recv(I2CBus *bus);
bool i2c_scan_bus(I2CBus *bus, uint8_t address, bool broadcast,