2016-06-06 17:59:29 +02:00
|
|
|
/*
|
|
|
|
* ARM Aspeed I2C controller
|
|
|
|
*
|
|
|
|
* Copyright (C) 2016 IBM Corp.
|
|
|
|
*
|
|
|
|
* 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; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "hw/sysbus.h"
|
2019-08-12 07:23:45 +02:00
|
|
|
#include "migration/vmstate.h"
|
2022-06-13 14:05:48 +02:00
|
|
|
#include "qemu/cutils.h"
|
2016-06-06 17:59:29 +02:00
|
|
|
#include "qemu/log.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2019-11-19 15:11:58 +01:00
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "qapi/error.h"
|
2016-06-06 17:59:29 +02:00
|
|
|
#include "hw/i2c/aspeed_i2c.h"
|
2019-08-12 07:23:42 +02:00
|
|
|
#include "hw/irq.h"
|
2019-11-19 15:11:58 +01:00
|
|
|
#include "hw/qdev-properties.h"
|
2022-06-13 14:05:48 +02:00
|
|
|
#include "hw/registerfields.h"
|
2019-11-19 15:11:59 +01:00
|
|
|
#include "trace.h"
|
2016-06-06 17:59:29 +02:00
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
/* Enable SLAVE_ADDR_RX_MATCH always */
|
|
|
|
#define R_I2CD_INTR_STS_ALWAYS_ENABLE R_I2CD_INTR_STS_SLAVE_ADDR_RX_MATCH_MASK
|
|
|
|
|
2016-06-06 17:59:29 +02:00
|
|
|
static inline void aspeed_i2c_bus_raise_interrupt(AspeedI2CBus *bus)
|
|
|
|
{
|
2019-09-25 16:32:41 +02:00
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
|
2022-06-13 14:05:48 +02:00
|
|
|
uint32_t reg_intr_sts = aspeed_i2c_bus_intr_sts_offset(bus);
|
|
|
|
uint32_t intr_ctrl_reg = aspeed_i2c_bus_intr_ctrl_offset(bus);
|
2022-06-13 14:05:48 +02:00
|
|
|
uint32_t intr_ctrl_mask = bus->regs[intr_ctrl_reg] |
|
|
|
|
R_I2CD_INTR_STS_ALWAYS_ENABLE;
|
2022-06-13 14:05:48 +02:00
|
|
|
bool raise_irq;
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
if (trace_event_get_state_backends(TRACE_ASPEED_I2C_BUS_RAISE_INTERRUPT)) {
|
2022-06-13 14:05:48 +02:00
|
|
|
g_autofree char *buf = g_strdup_printf("%s%s%s%s%s%s%s",
|
2022-06-13 14:05:48 +02:00
|
|
|
aspeed_i2c_bus_pkt_mode_en(bus) &&
|
|
|
|
ARRAY_FIELD_EX32(bus->regs, I2CM_INTR_STS, PKT_CMD_DONE) ?
|
|
|
|
"pktdone|" : "",
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_intr_sts, TX_NAK) ?
|
|
|
|
"nak|" : "",
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_intr_sts, TX_ACK) ?
|
|
|
|
"ack|" : "",
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_intr_sts, RX_DONE) ?
|
|
|
|
"done|" : "",
|
2022-06-13 14:05:48 +02:00
|
|
|
ARRAY_FIELD_EX32(bus->regs, I2CD_INTR_STS, SLAVE_ADDR_RX_MATCH) ?
|
|
|
|
"slave-match|" : "",
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_intr_sts, NORMAL_STOP) ?
|
2022-06-30 09:21:13 +02:00
|
|
|
"stop|" : "",
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_intr_sts, ABNORMAL) ?
|
|
|
|
"abnormal" : "");
|
|
|
|
|
|
|
|
trace_aspeed_i2c_bus_raise_interrupt(bus->regs[reg_intr_sts], buf);
|
|
|
|
}
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
raise_irq = bus->regs[reg_intr_sts] & intr_ctrl_mask ;
|
2022-06-13 14:05:48 +02:00
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
/* In packet mode we don't mask off INTR_STS */
|
|
|
|
if (!aspeed_i2c_bus_pkt_mode_en(bus)) {
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[reg_intr_sts] &= intr_ctrl_mask;
|
2022-06-13 14:05:48 +02:00
|
|
|
}
|
2022-06-13 14:05:48 +02:00
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
if (raise_irq) {
|
2016-06-06 17:59:29 +02:00
|
|
|
bus->controller->intr_status |= 1 << bus->id;
|
2019-09-25 16:32:41 +02:00
|
|
|
qemu_irq_raise(aic->bus_get_irq(bus));
|
2016-06-06 17:59:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
hw/i2c/aspeed: Add new-registers DMA slave mode RX support
This commit adds support for DMA RX in slave mode while using the new
register set in the AST2600 and AST1030. This patch also pretty much
assumes packet mode is enabled, I'm not sure if this will work in DMA
step mode.
This is particularly useful for testing IPMB exchanges between Zephyr
and external devices, which requires multi-master I2C support and DMA in
the new register mode, because the Zephyr drivers from Aspeed use DMA in
the new mode by default. The Zephyr drivers are also using packet mode.
The typical sequence of events for receiving data in DMA slave + packet
mode is that the Zephyr firmware will configure the slave address
register with an address to receive on and configure the bus's function
control register to enable master mode and slave mode simultaneously at
startup, before any transfers are initiated.
RX DMA is enabled in the slave mode command register, and the slave RX
DMA buffer address and slave RX DMA buffer length are set. TX DMA is not
covered in this patch.
When the Aspeed I2C controller receives data from some other I2C master,
it will reset the I2CS_DMA_LEN RX_LEN value to zero, then buffer
incoming data in the RX DMA buffer while incrementing the I2CC_DMA_ADDR
address counter and decrementing the I2CC_DMA_LEN counter. It will also
update the I2CS_DMA_LEN RX_LEN value along the way.
Once all the data has been received, the bus controller will raise an
interrupt indicating a packet command was completed, the slave address
matched, a normal stop condition was seen, and the transfer was an RX
operation.
If the master sent a NACK instead of a normal stop condition, or the
transfer timed out, then a slightly different set of interrupt status
values would be set. Those conditions are not handled in this commit.
The Zephyr firmware then collects data from the RX DMA buffer and clears
the status register by writing the PKT_MODE_EN bit to the status
register. In packet mode, clearing the packet mode interrupt enable bit
also clears most of the other interrupt bits automatically (except for a
few bits above it).
Note: if the master transmit or receive functions were in use
simultaneously with the slave mode receive functionality, then the
master mode functions may have raised the interrupt line for the bus
before the DMA slave transfer is complete. It's important to have the
slave's interrupt status register clear throughout the receive
operation, and if the slave attempts to raise the interrupt before the
master interrupt status is cleared, then it needs to re-raise the
interrupt once the master interrupt status is cleared. (And vice-versa).
That's why in this commit, when the master interrupt status is cleared
and the interrupt line is lowered, we call the slave interrupt _raise_
function, to see if the interrupt was pending. (And again, vice-versa).
Signed-off-by: Peter Delevoryas <pdel@fb.com>
Message-Id: <20220630045133.32251-8-me@pjd.dev>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
2022-06-30 09:21:14 +02:00
|
|
|
static inline void aspeed_i2c_bus_raise_slave_interrupt(AspeedI2CBus *bus)
|
|
|
|
{
|
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
|
|
|
|
|
|
|
|
if (!bus->regs[R_I2CS_INTR_STS]) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bus->controller->intr_status |= 1 << bus->id;
|
|
|
|
qemu_irq_raise(aic->bus_get_irq(bus));
|
|
|
|
}
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
static uint64_t aspeed_i2c_bus_old_read(AspeedI2CBus *bus, hwaddr offset,
|
|
|
|
unsigned size)
|
2016-06-06 17:59:29 +02:00
|
|
|
{
|
2019-11-19 15:11:58 +01:00
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
|
2022-06-13 14:05:48 +02:00
|
|
|
uint64_t value = bus->regs[offset / sizeof(*bus->regs)];
|
2016-06-06 17:59:29 +02:00
|
|
|
|
|
|
|
switch (offset) {
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_FUN_CTRL:
|
|
|
|
case A_I2CD_AC_TIMING1:
|
|
|
|
case A_I2CD_AC_TIMING2:
|
|
|
|
case A_I2CD_INTR_CTRL:
|
|
|
|
case A_I2CD_INTR_STS:
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_DEV_ADDR:
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_POOL_CTRL:
|
|
|
|
case A_I2CD_BYTE_BUF:
|
2022-06-13 14:05:48 +02:00
|
|
|
/* Value is already set, don't do anything. */
|
2019-11-19 15:11:59 +01:00
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_CMD:
|
2022-06-13 14:05:48 +02:00
|
|
|
value = SHARED_FIELD_DP32(value, BUS_BUSY_STS, i2c_bus_busy(bus->bus));
|
2019-11-19 15:11:59 +01:00
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_DMA_ADDR:
|
2019-11-19 15:11:58 +01:00
|
|
|
if (!aic->has_dma) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: No DMA support\n", __func__);
|
2022-06-13 14:05:48 +02:00
|
|
|
value = -1;
|
2019-11-19 15:11:58 +01:00
|
|
|
}
|
2019-11-19 15:11:59 +01:00
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_DMA_LEN:
|
2019-11-19 15:11:58 +01:00
|
|
|
if (!aic->has_dma) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: No DMA support\n", __func__);
|
2022-06-13 14:05:48 +02:00
|
|
|
value = -1;
|
2019-11-19 15:11:58 +01:00
|
|
|
}
|
2019-11-19 15:11:59 +01:00
|
|
|
break;
|
|
|
|
|
2016-06-06 17:59:29 +02:00
|
|
|
default:
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"%s: Bad offset 0x%" HWADDR_PRIx "\n", __func__, offset);
|
2019-11-19 15:11:59 +01:00
|
|
|
value = -1;
|
|
|
|
break;
|
2016-06-06 17:59:29 +02:00
|
|
|
}
|
2019-11-19 15:11:59 +01:00
|
|
|
|
|
|
|
trace_aspeed_i2c_bus_read(bus->id, offset, size, value);
|
|
|
|
return value;
|
2016-06-06 17:59:29 +02:00
|
|
|
}
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
static uint64_t aspeed_i2c_bus_new_read(AspeedI2CBus *bus, hwaddr offset,
|
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
uint64_t value = bus->regs[offset / sizeof(*bus->regs)];
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case A_I2CC_FUN_CTRL:
|
|
|
|
case A_I2CC_AC_TIMING:
|
|
|
|
case A_I2CC_POOL_CTRL:
|
|
|
|
case A_I2CM_INTR_CTRL:
|
|
|
|
case A_I2CM_INTR_STS:
|
|
|
|
case A_I2CC_MS_TXRX_BYTE_BUF:
|
|
|
|
case A_I2CM_DMA_LEN:
|
|
|
|
case A_I2CM_DMA_TX_ADDR:
|
|
|
|
case A_I2CM_DMA_RX_ADDR:
|
|
|
|
case A_I2CM_DMA_LEN_STS:
|
|
|
|
case A_I2CC_DMA_ADDR:
|
|
|
|
case A_I2CC_DMA_LEN:
|
hw/i2c/aspeed: Add new-registers DMA slave mode RX support
This commit adds support for DMA RX in slave mode while using the new
register set in the AST2600 and AST1030. This patch also pretty much
assumes packet mode is enabled, I'm not sure if this will work in DMA
step mode.
This is particularly useful for testing IPMB exchanges between Zephyr
and external devices, which requires multi-master I2C support and DMA in
the new register mode, because the Zephyr drivers from Aspeed use DMA in
the new mode by default. The Zephyr drivers are also using packet mode.
The typical sequence of events for receiving data in DMA slave + packet
mode is that the Zephyr firmware will configure the slave address
register with an address to receive on and configure the bus's function
control register to enable master mode and slave mode simultaneously at
startup, before any transfers are initiated.
RX DMA is enabled in the slave mode command register, and the slave RX
DMA buffer address and slave RX DMA buffer length are set. TX DMA is not
covered in this patch.
When the Aspeed I2C controller receives data from some other I2C master,
it will reset the I2CS_DMA_LEN RX_LEN value to zero, then buffer
incoming data in the RX DMA buffer while incrementing the I2CC_DMA_ADDR
address counter and decrementing the I2CC_DMA_LEN counter. It will also
update the I2CS_DMA_LEN RX_LEN value along the way.
Once all the data has been received, the bus controller will raise an
interrupt indicating a packet command was completed, the slave address
matched, a normal stop condition was seen, and the transfer was an RX
operation.
If the master sent a NACK instead of a normal stop condition, or the
transfer timed out, then a slightly different set of interrupt status
values would be set. Those conditions are not handled in this commit.
The Zephyr firmware then collects data from the RX DMA buffer and clears
the status register by writing the PKT_MODE_EN bit to the status
register. In packet mode, clearing the packet mode interrupt enable bit
also clears most of the other interrupt bits automatically (except for a
few bits above it).
Note: if the master transmit or receive functions were in use
simultaneously with the slave mode receive functionality, then the
master mode functions may have raised the interrupt line for the bus
before the DMA slave transfer is complete. It's important to have the
slave's interrupt status register clear throughout the receive
operation, and if the slave attempts to raise the interrupt before the
master interrupt status is cleared, then it needs to re-raise the
interrupt once the master interrupt status is cleared. (And vice-versa).
That's why in this commit, when the master interrupt status is cleared
and the interrupt line is lowered, we call the slave interrupt _raise_
function, to see if the interrupt was pending. (And again, vice-versa).
Signed-off-by: Peter Delevoryas <pdel@fb.com>
Message-Id: <20220630045133.32251-8-me@pjd.dev>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
2022-06-30 09:21:14 +02:00
|
|
|
|
|
|
|
case A_I2CS_DEV_ADDR:
|
|
|
|
case A_I2CS_DMA_RX_ADDR:
|
|
|
|
case A_I2CS_DMA_LEN:
|
|
|
|
case A_I2CS_CMD:
|
|
|
|
case A_I2CS_INTR_CTRL:
|
|
|
|
case A_I2CS_DMA_LEN_STS:
|
2022-06-13 14:05:48 +02:00
|
|
|
/* Value is already set, don't do anything. */
|
|
|
|
break;
|
hw/i2c/aspeed: Add new-registers DMA slave mode RX support
This commit adds support for DMA RX in slave mode while using the new
register set in the AST2600 and AST1030. This patch also pretty much
assumes packet mode is enabled, I'm not sure if this will work in DMA
step mode.
This is particularly useful for testing IPMB exchanges between Zephyr
and external devices, which requires multi-master I2C support and DMA in
the new register mode, because the Zephyr drivers from Aspeed use DMA in
the new mode by default. The Zephyr drivers are also using packet mode.
The typical sequence of events for receiving data in DMA slave + packet
mode is that the Zephyr firmware will configure the slave address
register with an address to receive on and configure the bus's function
control register to enable master mode and slave mode simultaneously at
startup, before any transfers are initiated.
RX DMA is enabled in the slave mode command register, and the slave RX
DMA buffer address and slave RX DMA buffer length are set. TX DMA is not
covered in this patch.
When the Aspeed I2C controller receives data from some other I2C master,
it will reset the I2CS_DMA_LEN RX_LEN value to zero, then buffer
incoming data in the RX DMA buffer while incrementing the I2CC_DMA_ADDR
address counter and decrementing the I2CC_DMA_LEN counter. It will also
update the I2CS_DMA_LEN RX_LEN value along the way.
Once all the data has been received, the bus controller will raise an
interrupt indicating a packet command was completed, the slave address
matched, a normal stop condition was seen, and the transfer was an RX
operation.
If the master sent a NACK instead of a normal stop condition, or the
transfer timed out, then a slightly different set of interrupt status
values would be set. Those conditions are not handled in this commit.
The Zephyr firmware then collects data from the RX DMA buffer and clears
the status register by writing the PKT_MODE_EN bit to the status
register. In packet mode, clearing the packet mode interrupt enable bit
also clears most of the other interrupt bits automatically (except for a
few bits above it).
Note: if the master transmit or receive functions were in use
simultaneously with the slave mode receive functionality, then the
master mode functions may have raised the interrupt line for the bus
before the DMA slave transfer is complete. It's important to have the
slave's interrupt status register clear throughout the receive
operation, and if the slave attempts to raise the interrupt before the
master interrupt status is cleared, then it needs to re-raise the
interrupt once the master interrupt status is cleared. (And vice-versa).
That's why in this commit, when the master interrupt status is cleared
and the interrupt line is lowered, we call the slave interrupt _raise_
function, to see if the interrupt was pending. (And again, vice-versa).
Signed-off-by: Peter Delevoryas <pdel@fb.com>
Message-Id: <20220630045133.32251-8-me@pjd.dev>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
2022-06-30 09:21:14 +02:00
|
|
|
case A_I2CS_INTR_STS:
|
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CM_CMD:
|
|
|
|
value = SHARED_FIELD_DP32(value, BUS_BUSY_STS, i2c_bus_busy(bus->bus));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"%s: Bad offset 0x%" HWADDR_PRIx "\n", __func__, offset);
|
|
|
|
value = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
trace_aspeed_i2c_bus_read(bus->id, offset, size, value);
|
|
|
|
return value;
|
|
|
|
}
|
|
|
|
|
|
|
|
static uint64_t aspeed_i2c_bus_read(void *opaque, hwaddr offset,
|
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
AspeedI2CBus *bus = opaque;
|
|
|
|
if (aspeed_i2c_is_new_mode(bus->controller)) {
|
|
|
|
return aspeed_i2c_bus_new_read(bus, offset, size);
|
|
|
|
}
|
|
|
|
return aspeed_i2c_bus_old_read(bus, offset, size);
|
|
|
|
}
|
|
|
|
|
2017-06-02 12:51:49 +02:00
|
|
|
static void aspeed_i2c_set_state(AspeedI2CBus *bus, uint8_t state)
|
|
|
|
{
|
2022-06-13 14:05:48 +02:00
|
|
|
if (aspeed_i2c_is_new_mode(bus->controller)) {
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, R_I2CC_MS_TXRX_BYTE_BUF, TX_STATE,
|
|
|
|
state);
|
|
|
|
} else {
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, R_I2CD_CMD, TX_STATE, state);
|
|
|
|
}
|
2017-06-02 12:51:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint8_t aspeed_i2c_get_state(AspeedI2CBus *bus)
|
|
|
|
{
|
2022-06-13 14:05:48 +02:00
|
|
|
if (aspeed_i2c_is_new_mode(bus->controller)) {
|
|
|
|
return SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CC_MS_TXRX_BYTE_BUF,
|
|
|
|
TX_STATE);
|
|
|
|
}
|
|
|
|
return SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CD_CMD, TX_STATE);
|
2017-06-02 12:51:49 +02:00
|
|
|
}
|
|
|
|
|
2019-11-19 15:11:58 +01:00
|
|
|
static int aspeed_i2c_dma_read(AspeedI2CBus *bus, uint8_t *data)
|
|
|
|
{
|
|
|
|
MemTxResult result;
|
|
|
|
AspeedI2CState *s = bus->controller;
|
2022-06-13 14:05:48 +02:00
|
|
|
uint32_t reg_dma_addr = aspeed_i2c_bus_dma_addr_offset(bus);
|
|
|
|
uint32_t reg_dma_len = aspeed_i2c_bus_dma_len_offset(bus);
|
2019-11-19 15:11:58 +01:00
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
result = address_space_read(&s->dram_as, bus->regs[reg_dma_addr],
|
2019-11-19 15:11:58 +01:00
|
|
|
MEMTXATTRS_UNSPECIFIED, data, 1);
|
|
|
|
if (result != MEMTX_OK) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: DRAM read failed @%08x\n",
|
2022-06-13 14:05:48 +02:00
|
|
|
__func__, bus->regs[reg_dma_addr]);
|
2019-11-19 15:11:58 +01:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[reg_dma_addr]++;
|
|
|
|
bus->regs[reg_dma_len]--;
|
2019-11-19 15:11:58 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-11-19 15:11:55 +01:00
|
|
|
static int aspeed_i2c_bus_send(AspeedI2CBus *bus, uint8_t pool_start)
|
|
|
|
{
|
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
|
|
|
|
int ret = -1;
|
|
|
|
int i;
|
2022-06-13 14:05:48 +02:00
|
|
|
uint32_t reg_cmd = aspeed_i2c_bus_cmd_offset(bus);
|
|
|
|
uint32_t reg_pool_ctrl = aspeed_i2c_bus_pool_ctrl_offset(bus);
|
|
|
|
uint32_t reg_byte_buf = aspeed_i2c_bus_byte_buf_offset(bus);
|
|
|
|
uint32_t reg_dma_len = aspeed_i2c_bus_dma_len_offset(bus);
|
|
|
|
int pool_tx_count = SHARED_ARRAY_FIELD_EX32(bus->regs, reg_pool_ctrl,
|
|
|
|
TX_COUNT);
|
|
|
|
|
|
|
|
if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_BUFF_EN)) {
|
2022-06-13 14:05:48 +02:00
|
|
|
for (i = pool_start; i < pool_tx_count; i++) {
|
2019-11-19 15:11:55 +01:00
|
|
|
uint8_t *pool_base = aic->bus_pool_base(bus);
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
trace_aspeed_i2c_bus_send("BUF", i + 1, pool_tx_count,
|
2019-11-19 15:11:59 +01:00
|
|
|
pool_base[i]);
|
2019-11-19 15:11:55 +01:00
|
|
|
ret = i2c_send(bus->bus, pool_base[i]);
|
|
|
|
if (ret) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, TX_BUFF_EN, 0);
|
|
|
|
} else if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_DMA_EN)) {
|
|
|
|
/* In new mode, clear how many bytes we TXed */
|
|
|
|
if (aspeed_i2c_is_new_mode(bus->controller)) {
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, TX_LEN, 0);
|
|
|
|
}
|
|
|
|
while (bus->regs[reg_dma_len]) {
|
2019-11-19 15:11:58 +01:00
|
|
|
uint8_t data;
|
|
|
|
aspeed_i2c_dma_read(bus, &data);
|
2022-06-13 14:05:48 +02:00
|
|
|
trace_aspeed_i2c_bus_send("DMA", bus->regs[reg_dma_len],
|
|
|
|
bus->regs[reg_dma_len], data);
|
2019-11-19 15:11:58 +01:00
|
|
|
ret = i2c_send(bus->bus, data);
|
|
|
|
if (ret) {
|
|
|
|
break;
|
|
|
|
}
|
2022-06-13 14:05:48 +02:00
|
|
|
/* In new mode, keep track of how many bytes we TXed */
|
|
|
|
if (aspeed_i2c_is_new_mode(bus->controller)) {
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, TX_LEN,
|
|
|
|
ARRAY_FIELD_EX32(bus->regs, I2CM_DMA_LEN_STS,
|
|
|
|
TX_LEN) + 1);
|
|
|
|
}
|
2019-11-19 15:11:58 +01:00
|
|
|
}
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, TX_DMA_EN, 0);
|
2019-11-19 15:11:55 +01:00
|
|
|
} else {
|
2022-06-13 14:05:48 +02:00
|
|
|
trace_aspeed_i2c_bus_send("BYTE", pool_start, 1,
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[reg_byte_buf]);
|
|
|
|
ret = i2c_send(bus->bus, bus->regs[reg_byte_buf]);
|
2019-11-19 15:11:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void aspeed_i2c_bus_recv(AspeedI2CBus *bus)
|
2018-09-25 15:02:31 +02:00
|
|
|
{
|
2019-11-19 15:11:55 +01:00
|
|
|
AspeedI2CState *s = bus->controller;
|
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(s);
|
|
|
|
uint8_t data;
|
|
|
|
int i;
|
2022-06-13 14:05:48 +02:00
|
|
|
uint32_t reg_cmd = aspeed_i2c_bus_cmd_offset(bus);
|
|
|
|
uint32_t reg_pool_ctrl = aspeed_i2c_bus_pool_ctrl_offset(bus);
|
|
|
|
uint32_t reg_byte_buf = aspeed_i2c_bus_byte_buf_offset(bus);
|
|
|
|
uint32_t reg_dma_len = aspeed_i2c_bus_dma_len_offset(bus);
|
|
|
|
uint32_t reg_dma_addr = aspeed_i2c_bus_dma_addr_offset(bus);
|
|
|
|
int pool_rx_count = SHARED_ARRAY_FIELD_EX32(bus->regs, reg_pool_ctrl,
|
|
|
|
RX_COUNT);
|
|
|
|
|
|
|
|
if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, RX_BUFF_EN)) {
|
2019-11-19 15:11:55 +01:00
|
|
|
uint8_t *pool_base = aic->bus_pool_base(bus);
|
2018-09-25 15:02:31 +02:00
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
for (i = 0; i < pool_rx_count; i++) {
|
2019-11-19 15:11:55 +01:00
|
|
|
pool_base[i] = i2c_recv(bus->bus);
|
2022-06-13 14:05:48 +02:00
|
|
|
trace_aspeed_i2c_bus_recv("BUF", i + 1, pool_rx_count,
|
2019-11-19 15:11:59 +01:00
|
|
|
pool_base[i]);
|
2019-11-19 15:11:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Update RX count */
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_pool_ctrl, RX_COUNT, i & 0xff);
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, RX_BUFF_EN, 0);
|
|
|
|
} else if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, RX_DMA_EN)) {
|
2019-11-19 15:11:58 +01:00
|
|
|
uint8_t data;
|
2022-06-13 14:05:48 +02:00
|
|
|
/* In new mode, clear how many bytes we RXed */
|
|
|
|
if (aspeed_i2c_is_new_mode(bus->controller)) {
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, RX_LEN, 0);
|
|
|
|
}
|
2019-11-19 15:11:58 +01:00
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
while (bus->regs[reg_dma_len]) {
|
2019-11-19 15:11:58 +01:00
|
|
|
MemTxResult result;
|
|
|
|
|
|
|
|
data = i2c_recv(bus->bus);
|
2022-06-13 14:05:48 +02:00
|
|
|
trace_aspeed_i2c_bus_recv("DMA", bus->regs[reg_dma_len],
|
|
|
|
bus->regs[reg_dma_len], data);
|
|
|
|
result = address_space_write(&s->dram_as, bus->regs[reg_dma_addr],
|
2019-11-19 15:11:58 +01:00
|
|
|
MEMTXATTRS_UNSPECIFIED, &data, 1);
|
|
|
|
if (result != MEMTX_OK) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: DRAM write failed @%08x\n",
|
2022-06-13 14:05:48 +02:00
|
|
|
__func__, bus->regs[reg_dma_addr]);
|
2019-11-19 15:11:58 +01:00
|
|
|
return;
|
|
|
|
}
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[reg_dma_addr]++;
|
|
|
|
bus->regs[reg_dma_len]--;
|
|
|
|
/* In new mode, keep track of how many bytes we RXed */
|
|
|
|
if (aspeed_i2c_is_new_mode(bus->controller)) {
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, RX_LEN,
|
|
|
|
ARRAY_FIELD_EX32(bus->regs, I2CM_DMA_LEN_STS,
|
|
|
|
RX_LEN) + 1);
|
|
|
|
}
|
2019-11-19 15:11:58 +01:00
|
|
|
}
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, RX_DMA_EN, 0);
|
2019-11-19 15:11:55 +01:00
|
|
|
} else {
|
|
|
|
data = i2c_recv(bus->bus);
|
2022-06-13 14:05:48 +02:00
|
|
|
trace_aspeed_i2c_bus_recv("BYTE", 1, 1, bus->regs[reg_byte_buf]);
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_byte_buf, RX_BUF, data);
|
2019-11-19 15:11:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void aspeed_i2c_handle_rx_cmd(AspeedI2CBus *bus)
|
|
|
|
{
|
2022-06-13 14:05:48 +02:00
|
|
|
uint32_t reg_cmd = aspeed_i2c_bus_cmd_offset(bus);
|
|
|
|
uint32_t reg_intr_sts = aspeed_i2c_bus_intr_sts_offset(bus);
|
|
|
|
|
2018-09-25 15:02:31 +02:00
|
|
|
aspeed_i2c_set_state(bus, I2CD_MRXD);
|
2019-11-19 15:11:55 +01:00
|
|
|
aspeed_i2c_bus_recv(bus);
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, RX_DONE, 1);
|
|
|
|
if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_S_RX_CMD_LAST)) {
|
2018-09-25 15:02:31 +02:00
|
|
|
i2c_nack(bus->bus);
|
|
|
|
}
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, M_RX_CMD, 0);
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, M_S_RX_CMD_LAST, 0);
|
2018-09-25 15:02:31 +02:00
|
|
|
aspeed_i2c_set_state(bus, I2CD_MACTIVE);
|
|
|
|
}
|
|
|
|
|
2019-11-19 15:11:55 +01:00
|
|
|
static uint8_t aspeed_i2c_get_addr(AspeedI2CBus *bus)
|
|
|
|
{
|
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
|
2022-06-13 14:05:48 +02:00
|
|
|
uint32_t reg_byte_buf = aspeed_i2c_bus_byte_buf_offset(bus);
|
|
|
|
uint32_t reg_cmd = aspeed_i2c_bus_cmd_offset(bus);
|
2019-11-19 15:11:55 +01:00
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
if (aspeed_i2c_bus_pkt_mode_en(bus)) {
|
|
|
|
return (ARRAY_FIELD_EX32(bus->regs, I2CM_CMD, PKT_DEV_ADDR) << 1) |
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_RX_CMD);
|
|
|
|
}
|
|
|
|
if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_BUFF_EN)) {
|
2019-11-19 15:11:55 +01:00
|
|
|
uint8_t *pool_base = aic->bus_pool_base(bus);
|
|
|
|
|
|
|
|
return pool_base[0];
|
2022-06-13 14:05:48 +02:00
|
|
|
} else if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_DMA_EN)) {
|
2019-11-19 15:11:58 +01:00
|
|
|
uint8_t data;
|
|
|
|
|
|
|
|
aspeed_i2c_dma_read(bus, &data);
|
|
|
|
return data;
|
2019-11-19 15:11:55 +01:00
|
|
|
} else {
|
2022-06-13 14:05:48 +02:00
|
|
|
return bus->regs[reg_byte_buf];
|
2019-11-19 15:11:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-19 15:11:56 +01:00
|
|
|
static bool aspeed_i2c_check_sram(AspeedI2CBus *bus)
|
|
|
|
{
|
|
|
|
AspeedI2CState *s = bus->controller;
|
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(s);
|
2022-06-13 14:05:48 +02:00
|
|
|
uint32_t reg_cmd = aspeed_i2c_bus_cmd_offset(bus);
|
|
|
|
bool dma_en = SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, RX_DMA_EN) ||
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_DMA_EN) ||
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, RX_BUFF_EN) ||
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_BUFF_EN);
|
2019-11-19 15:11:56 +01:00
|
|
|
if (!aic->check_sram) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* AST2500: SRAM must be enabled before using the Buffer Pool or
|
|
|
|
* DMA mode.
|
|
|
|
*/
|
2022-06-13 14:05:48 +02:00
|
|
|
if (!FIELD_EX32(s->ctrl_global, I2C_CTRL_GLOBAL, SRAM_EN) && dma_en) {
|
2019-11-19 15:11:56 +01:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: SRAM is not enabled\n", __func__);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-11-19 15:11:59 +01:00
|
|
|
static void aspeed_i2c_bus_cmd_dump(AspeedI2CBus *bus)
|
|
|
|
{
|
2020-01-21 10:28:14 +01:00
|
|
|
g_autofree char *cmd_flags = NULL;
|
2019-11-19 15:11:59 +01:00
|
|
|
uint32_t count;
|
2022-06-13 14:05:48 +02:00
|
|
|
uint32_t reg_cmd = aspeed_i2c_bus_cmd_offset(bus);
|
|
|
|
uint32_t reg_pool_ctrl = aspeed_i2c_bus_pool_ctrl_offset(bus);
|
|
|
|
uint32_t reg_intr_sts = aspeed_i2c_bus_intr_sts_offset(bus);
|
|
|
|
uint32_t reg_dma_len = aspeed_i2c_bus_dma_len_offset(bus);
|
|
|
|
if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, RX_BUFF_EN)) {
|
|
|
|
count = SHARED_ARRAY_FIELD_EX32(bus->regs, reg_pool_ctrl, TX_COUNT);
|
|
|
|
} else if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, RX_DMA_EN)) {
|
|
|
|
count = bus->regs[reg_dma_len];
|
2019-11-19 15:11:59 +01:00
|
|
|
} else { /* BYTE mode */
|
|
|
|
count = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd_flags = g_strdup_printf("%s%s%s%s%s%s%s%s%s",
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_START_CMD) ? "start|" : "",
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, RX_DMA_EN) ? "rxdma|" : "",
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_DMA_EN) ? "txdma|" : "",
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, RX_BUFF_EN) ? "rxbuf|" : "",
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_BUFF_EN) ? "txbuf|" : "",
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_TX_CMD) ? "tx|" : "",
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_RX_CMD) ? "rx|" : "",
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_S_RX_CMD_LAST) ? "last|" : "",
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_STOP_CMD) ? "stop|" : "");
|
|
|
|
|
|
|
|
trace_aspeed_i2c_bus_cmd(bus->regs[reg_cmd], cmd_flags, count,
|
|
|
|
bus->regs[reg_intr_sts]);
|
2019-11-19 15:11:59 +01:00
|
|
|
}
|
|
|
|
|
2017-06-02 12:51:49 +02:00
|
|
|
/*
|
|
|
|
* The state machine needs some refinement. It is only used to track
|
|
|
|
* invalid STOP commands for the moment.
|
|
|
|
*/
|
2016-06-06 17:59:29 +02:00
|
|
|
static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value)
|
|
|
|
{
|
2019-11-19 15:11:55 +01:00
|
|
|
uint8_t pool_start = 0;
|
2022-06-13 14:05:48 +02:00
|
|
|
uint32_t reg_intr_sts = aspeed_i2c_bus_intr_sts_offset(bus);
|
|
|
|
uint32_t reg_cmd = aspeed_i2c_bus_cmd_offset(bus);
|
|
|
|
uint32_t reg_pool_ctrl = aspeed_i2c_bus_pool_ctrl_offset(bus);
|
|
|
|
uint32_t reg_dma_len = aspeed_i2c_bus_dma_len_offset(bus);
|
2016-06-06 17:59:29 +02:00
|
|
|
|
2019-11-19 15:11:56 +01:00
|
|
|
if (!aspeed_i2c_check_sram(bus)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-11-19 15:11:59 +01:00
|
|
|
if (trace_event_get_state_backends(TRACE_ASPEED_I2C_BUS_CMD)) {
|
|
|
|
aspeed_i2c_bus_cmd_dump(bus);
|
|
|
|
}
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_START_CMD)) {
|
2017-06-02 12:51:49 +02:00
|
|
|
uint8_t state = aspeed_i2c_get_state(bus) & I2CD_MACTIVE ?
|
|
|
|
I2CD_MSTARTR : I2CD_MSTART;
|
2019-11-19 15:11:55 +01:00
|
|
|
uint8_t addr;
|
2017-06-02 12:51:49 +02:00
|
|
|
|
|
|
|
aspeed_i2c_set_state(bus, state);
|
|
|
|
|
2019-11-19 15:11:55 +01:00
|
|
|
addr = aspeed_i2c_get_addr(bus);
|
|
|
|
if (i2c_start_transfer(bus->bus, extract32(addr, 1, 7),
|
|
|
|
extract32(addr, 0, 1))) {
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, TX_NAK, 1);
|
|
|
|
if (aspeed_i2c_bus_pkt_mode_en(bus)) {
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CM_INTR_STS, PKT_CMD_FAIL, 1);
|
|
|
|
}
|
2016-06-06 17:59:29 +02:00
|
|
|
} else {
|
2022-06-13 14:05:48 +02:00
|
|
|
/* START doesn't set TX_ACK in packet mode */
|
|
|
|
if (!aspeed_i2c_bus_pkt_mode_en(bus)) {
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, TX_ACK, 1);
|
|
|
|
}
|
2016-06-06 17:59:29 +02:00
|
|
|
}
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, M_START_CMD, 0);
|
2019-11-19 15:11:55 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The START command is also a TX command, as the slave
|
|
|
|
* address is sent on the bus. Drop the TX flag if nothing
|
|
|
|
* else needs to be sent in this sequence.
|
|
|
|
*/
|
2022-06-13 14:05:48 +02:00
|
|
|
if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_BUFF_EN)) {
|
|
|
|
if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_pool_ctrl, TX_COUNT)
|
|
|
|
== 1) {
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, M_TX_CMD, 0);
|
2019-11-19 15:11:55 +01:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Increase the start index in the TX pool buffer to
|
|
|
|
* skip the address byte.
|
|
|
|
*/
|
|
|
|
pool_start++;
|
|
|
|
}
|
2022-06-13 14:05:48 +02:00
|
|
|
} else if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_DMA_EN)) {
|
|
|
|
if (bus->regs[reg_dma_len] == 0) {
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, M_TX_CMD, 0);
|
2019-11-19 15:11:58 +01:00
|
|
|
}
|
2019-11-19 15:11:55 +01:00
|
|
|
} else {
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, M_TX_CMD, 0);
|
2019-11-19 15:11:55 +01:00
|
|
|
}
|
2017-06-02 12:51:49 +02:00
|
|
|
|
|
|
|
/* No slave found */
|
|
|
|
if (!i2c_bus_busy(bus->bus)) {
|
2022-06-13 14:05:48 +02:00
|
|
|
if (aspeed_i2c_bus_pkt_mode_en(bus)) {
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CM_INTR_STS, PKT_CMD_FAIL, 1);
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CM_INTR_STS, PKT_CMD_DONE, 1);
|
|
|
|
}
|
2017-06-02 12:51:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2017-06-02 12:51:49 +02:00
|
|
|
aspeed_i2c_set_state(bus, I2CD_MACTIVE);
|
2017-06-02 12:51:49 +02:00
|
|
|
}
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_TX_CMD)) {
|
2017-06-02 12:51:49 +02:00
|
|
|
aspeed_i2c_set_state(bus, I2CD_MTXD);
|
2019-11-19 15:11:55 +01:00
|
|
|
if (aspeed_i2c_bus_send(bus, pool_start)) {
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, TX_NAK, 1);
|
2016-06-06 17:59:29 +02:00
|
|
|
i2c_end_transfer(bus->bus);
|
|
|
|
} else {
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, TX_ACK, 1);
|
2016-06-06 17:59:29 +02:00
|
|
|
}
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, M_TX_CMD, 0);
|
2017-06-02 12:51:49 +02:00
|
|
|
aspeed_i2c_set_state(bus, I2CD_MACTIVE);
|
2017-06-02 12:51:49 +02:00
|
|
|
}
|
2016-06-06 17:59:29 +02:00
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
if ((SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_RX_CMD) ||
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_S_RX_CMD_LAST)) &&
|
|
|
|
!SHARED_ARRAY_FIELD_EX32(bus->regs, reg_intr_sts, RX_DONE)) {
|
2018-09-25 15:02:31 +02:00
|
|
|
aspeed_i2c_handle_rx_cmd(bus);
|
2016-06-06 17:59:29 +02:00
|
|
|
}
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_STOP_CMD)) {
|
2017-06-02 12:51:49 +02:00
|
|
|
if (!(aspeed_i2c_get_state(bus) & I2CD_MACTIVE)) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: abnormal stop\n", __func__);
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, ABNORMAL, 1);
|
|
|
|
if (aspeed_i2c_bus_pkt_mode_en(bus)) {
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CM_INTR_STS, PKT_CMD_FAIL, 1);
|
|
|
|
}
|
2016-06-06 17:59:29 +02:00
|
|
|
} else {
|
2017-06-02 12:51:49 +02:00
|
|
|
aspeed_i2c_set_state(bus, I2CD_MSTOP);
|
2016-06-06 17:59:29 +02:00
|
|
|
i2c_end_transfer(bus->bus);
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, NORMAL_STOP, 1);
|
2016-06-06 17:59:29 +02:00
|
|
|
}
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, M_STOP_CMD, 0);
|
2017-06-02 12:51:49 +02:00
|
|
|
aspeed_i2c_set_state(bus, I2CD_IDLE);
|
2023-03-02 13:57:50 +01:00
|
|
|
|
|
|
|
i2c_schedule_pending_master(bus->bus);
|
2016-06-06 17:59:29 +02:00
|
|
|
}
|
2022-06-13 14:05:48 +02:00
|
|
|
|
|
|
|
if (aspeed_i2c_bus_pkt_mode_en(bus)) {
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CM_INTR_STS, PKT_CMD_DONE, 1);
|
|
|
|
}
|
2016-06-06 17:59:29 +02:00
|
|
|
}
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
static void aspeed_i2c_bus_new_write(AspeedI2CBus *bus, hwaddr offset,
|
|
|
|
uint64_t value, unsigned size)
|
|
|
|
{
|
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
|
|
|
|
bool handle_rx;
|
|
|
|
bool w1t;
|
|
|
|
|
|
|
|
trace_aspeed_i2c_bus_write(bus->id, offset, size, value);
|
|
|
|
|
|
|
|
switch (offset) {
|
|
|
|
case A_I2CC_FUN_CTRL:
|
hw/i2c/aspeed: Add new-registers DMA slave mode RX support
This commit adds support for DMA RX in slave mode while using the new
register set in the AST2600 and AST1030. This patch also pretty much
assumes packet mode is enabled, I'm not sure if this will work in DMA
step mode.
This is particularly useful for testing IPMB exchanges between Zephyr
and external devices, which requires multi-master I2C support and DMA in
the new register mode, because the Zephyr drivers from Aspeed use DMA in
the new mode by default. The Zephyr drivers are also using packet mode.
The typical sequence of events for receiving data in DMA slave + packet
mode is that the Zephyr firmware will configure the slave address
register with an address to receive on and configure the bus's function
control register to enable master mode and slave mode simultaneously at
startup, before any transfers are initiated.
RX DMA is enabled in the slave mode command register, and the slave RX
DMA buffer address and slave RX DMA buffer length are set. TX DMA is not
covered in this patch.
When the Aspeed I2C controller receives data from some other I2C master,
it will reset the I2CS_DMA_LEN RX_LEN value to zero, then buffer
incoming data in the RX DMA buffer while incrementing the I2CC_DMA_ADDR
address counter and decrementing the I2CC_DMA_LEN counter. It will also
update the I2CS_DMA_LEN RX_LEN value along the way.
Once all the data has been received, the bus controller will raise an
interrupt indicating a packet command was completed, the slave address
matched, a normal stop condition was seen, and the transfer was an RX
operation.
If the master sent a NACK instead of a normal stop condition, or the
transfer timed out, then a slightly different set of interrupt status
values would be set. Those conditions are not handled in this commit.
The Zephyr firmware then collects data from the RX DMA buffer and clears
the status register by writing the PKT_MODE_EN bit to the status
register. In packet mode, clearing the packet mode interrupt enable bit
also clears most of the other interrupt bits automatically (except for a
few bits above it).
Note: if the master transmit or receive functions were in use
simultaneously with the slave mode receive functionality, then the
master mode functions may have raised the interrupt line for the bus
before the DMA slave transfer is complete. It's important to have the
slave's interrupt status register clear throughout the receive
operation, and if the slave attempts to raise the interrupt before the
master interrupt status is cleared, then it needs to re-raise the
interrupt once the master interrupt status is cleared. (And vice-versa).
That's why in this commit, when the master interrupt status is cleared
and the interrupt line is lowered, we call the slave interrupt _raise_
function, to see if the interrupt was pending. (And again, vice-versa).
Signed-off-by: Peter Delevoryas <pdel@fb.com>
Message-Id: <20220630045133.32251-8-me@pjd.dev>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
2022-06-30 09:21:14 +02:00
|
|
|
bus->regs[R_I2CC_FUN_CTRL] = value;
|
2022-06-13 14:05:48 +02:00
|
|
|
break;
|
|
|
|
case A_I2CC_AC_TIMING:
|
|
|
|
bus->regs[R_I2CC_AC_TIMING] = value & 0x1ffff0ff;
|
|
|
|
break;
|
|
|
|
case A_I2CC_MS_TXRX_BYTE_BUF:
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, R_I2CC_MS_TXRX_BYTE_BUF, TX_BUF,
|
|
|
|
value);
|
|
|
|
break;
|
|
|
|
case A_I2CC_POOL_CTRL:
|
|
|
|
bus->regs[R_I2CC_POOL_CTRL] &= ~0xffffff;
|
|
|
|
bus->regs[R_I2CC_POOL_CTRL] |= (value & 0xffffff);
|
|
|
|
break;
|
|
|
|
case A_I2CM_INTR_CTRL:
|
|
|
|
bus->regs[R_I2CM_INTR_CTRL] = value & 0x0007f07f;
|
|
|
|
break;
|
|
|
|
case A_I2CM_INTR_STS:
|
|
|
|
handle_rx = SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CM_INTR_STS, RX_DONE)
|
|
|
|
&& SHARED_FIELD_EX32(value, RX_DONE);
|
|
|
|
|
|
|
|
/* In packet mode, clearing PKT_CMD_DONE clears other interrupts. */
|
|
|
|
if (aspeed_i2c_bus_pkt_mode_en(bus) &&
|
|
|
|
FIELD_EX32(value, I2CM_INTR_STS, PKT_CMD_DONE)) {
|
|
|
|
bus->regs[R_I2CM_INTR_STS] &= 0xf0001000;
|
|
|
|
if (!bus->regs[R_I2CM_INTR_STS]) {
|
|
|
|
bus->controller->intr_status &= ~(1 << bus->id);
|
|
|
|
qemu_irq_lower(aic->bus_get_irq(bus));
|
|
|
|
}
|
hw/i2c/aspeed: Add new-registers DMA slave mode RX support
This commit adds support for DMA RX in slave mode while using the new
register set in the AST2600 and AST1030. This patch also pretty much
assumes packet mode is enabled, I'm not sure if this will work in DMA
step mode.
This is particularly useful for testing IPMB exchanges between Zephyr
and external devices, which requires multi-master I2C support and DMA in
the new register mode, because the Zephyr drivers from Aspeed use DMA in
the new mode by default. The Zephyr drivers are also using packet mode.
The typical sequence of events for receiving data in DMA slave + packet
mode is that the Zephyr firmware will configure the slave address
register with an address to receive on and configure the bus's function
control register to enable master mode and slave mode simultaneously at
startup, before any transfers are initiated.
RX DMA is enabled in the slave mode command register, and the slave RX
DMA buffer address and slave RX DMA buffer length are set. TX DMA is not
covered in this patch.
When the Aspeed I2C controller receives data from some other I2C master,
it will reset the I2CS_DMA_LEN RX_LEN value to zero, then buffer
incoming data in the RX DMA buffer while incrementing the I2CC_DMA_ADDR
address counter and decrementing the I2CC_DMA_LEN counter. It will also
update the I2CS_DMA_LEN RX_LEN value along the way.
Once all the data has been received, the bus controller will raise an
interrupt indicating a packet command was completed, the slave address
matched, a normal stop condition was seen, and the transfer was an RX
operation.
If the master sent a NACK instead of a normal stop condition, or the
transfer timed out, then a slightly different set of interrupt status
values would be set. Those conditions are not handled in this commit.
The Zephyr firmware then collects data from the RX DMA buffer and clears
the status register by writing the PKT_MODE_EN bit to the status
register. In packet mode, clearing the packet mode interrupt enable bit
also clears most of the other interrupt bits automatically (except for a
few bits above it).
Note: if the master transmit or receive functions were in use
simultaneously with the slave mode receive functionality, then the
master mode functions may have raised the interrupt line for the bus
before the DMA slave transfer is complete. It's important to have the
slave's interrupt status register clear throughout the receive
operation, and if the slave attempts to raise the interrupt before the
master interrupt status is cleared, then it needs to re-raise the
interrupt once the master interrupt status is cleared. (And vice-versa).
That's why in this commit, when the master interrupt status is cleared
and the interrupt line is lowered, we call the slave interrupt _raise_
function, to see if the interrupt was pending. (And again, vice-versa).
Signed-off-by: Peter Delevoryas <pdel@fb.com>
Message-Id: <20220630045133.32251-8-me@pjd.dev>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
2022-06-30 09:21:14 +02:00
|
|
|
aspeed_i2c_bus_raise_slave_interrupt(bus);
|
2022-06-13 14:05:48 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
bus->regs[R_I2CM_INTR_STS] &= ~(value & 0xf007f07f);
|
|
|
|
if (!bus->regs[R_I2CM_INTR_STS]) {
|
|
|
|
bus->controller->intr_status &= ~(1 << bus->id);
|
|
|
|
qemu_irq_lower(aic->bus_get_irq(bus));
|
|
|
|
}
|
|
|
|
if (handle_rx && (SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CM_CMD,
|
|
|
|
M_RX_CMD) ||
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CM_CMD,
|
|
|
|
M_S_RX_CMD_LAST))) {
|
|
|
|
aspeed_i2c_handle_rx_cmd(bus);
|
|
|
|
aspeed_i2c_bus_raise_interrupt(bus);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case A_I2CM_CMD:
|
|
|
|
if (!aspeed_i2c_bus_is_enabled(bus)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aspeed_i2c_bus_is_master(bus)) {
|
2022-06-30 09:21:14 +02:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: Master mode is not enabled\n",
|
2022-06-13 14:05:48 +02:00
|
|
|
__func__);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aic->has_dma &&
|
|
|
|
(SHARED_FIELD_EX32(value, RX_DMA_EN) ||
|
|
|
|
SHARED_FIELD_EX32(value, TX_DMA_EN))) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: No DMA support\n", __func__);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (bus->regs[R_I2CM_INTR_STS] & 0xffff0000) {
|
|
|
|
qemu_log_mask(LOG_UNIMP, "%s: Packet mode is not implemented\n",
|
|
|
|
__func__);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
value &= 0xff0ffbfb;
|
|
|
|
if (ARRAY_FIELD_EX32(bus->regs, I2CM_CMD, W1_CTRL)) {
|
|
|
|
bus->regs[R_I2CM_CMD] |= value;
|
|
|
|
} else {
|
|
|
|
bus->regs[R_I2CM_CMD] = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
aspeed_i2c_bus_handle_cmd(bus, value);
|
|
|
|
aspeed_i2c_bus_raise_interrupt(bus);
|
|
|
|
break;
|
|
|
|
case A_I2CM_DMA_TX_ADDR:
|
|
|
|
bus->regs[R_I2CM_DMA_TX_ADDR] = FIELD_EX32(value, I2CM_DMA_TX_ADDR,
|
|
|
|
ADDR);
|
|
|
|
bus->regs[R_I2CC_DMA_ADDR] = FIELD_EX32(value, I2CM_DMA_TX_ADDR, ADDR);
|
|
|
|
bus->regs[R_I2CC_DMA_LEN] = ARRAY_FIELD_EX32(bus->regs, I2CM_DMA_LEN,
|
|
|
|
TX_BUF_LEN) + 1;
|
|
|
|
break;
|
|
|
|
case A_I2CM_DMA_RX_ADDR:
|
|
|
|
bus->regs[R_I2CM_DMA_RX_ADDR] = FIELD_EX32(value, I2CM_DMA_RX_ADDR,
|
|
|
|
ADDR);
|
|
|
|
bus->regs[R_I2CC_DMA_ADDR] = FIELD_EX32(value, I2CM_DMA_RX_ADDR, ADDR);
|
|
|
|
bus->regs[R_I2CC_DMA_LEN] = ARRAY_FIELD_EX32(bus->regs, I2CM_DMA_LEN,
|
|
|
|
RX_BUF_LEN) + 1;
|
|
|
|
break;
|
|
|
|
case A_I2CM_DMA_LEN:
|
2022-06-30 09:21:13 +02:00
|
|
|
w1t = FIELD_EX32(value, I2CM_DMA_LEN, RX_BUF_LEN_W1T) ||
|
|
|
|
FIELD_EX32(value, I2CM_DMA_LEN, TX_BUF_LEN_W1T);
|
2022-06-13 14:05:48 +02:00
|
|
|
/* If none of the w1t bits are set, just write to the reg as normal. */
|
|
|
|
if (!w1t) {
|
|
|
|
bus->regs[R_I2CM_DMA_LEN] = value;
|
|
|
|
break;
|
|
|
|
}
|
2022-06-30 09:21:13 +02:00
|
|
|
if (FIELD_EX32(value, I2CM_DMA_LEN, RX_BUF_LEN_W1T)) {
|
2022-06-13 14:05:48 +02:00
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN, RX_BUF_LEN,
|
|
|
|
FIELD_EX32(value, I2CM_DMA_LEN, RX_BUF_LEN));
|
|
|
|
}
|
2022-06-30 09:21:13 +02:00
|
|
|
if (FIELD_EX32(value, I2CM_DMA_LEN, TX_BUF_LEN_W1T)) {
|
2022-06-13 14:05:48 +02:00
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN, TX_BUF_LEN,
|
|
|
|
FIELD_EX32(value, I2CM_DMA_LEN, TX_BUF_LEN));
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case A_I2CM_DMA_LEN_STS:
|
|
|
|
/* Writes clear to 0 */
|
|
|
|
bus->regs[R_I2CM_DMA_LEN_STS] = 0;
|
|
|
|
break;
|
|
|
|
case A_I2CC_DMA_ADDR:
|
|
|
|
case A_I2CC_DMA_LEN:
|
|
|
|
/* RO */
|
|
|
|
break;
|
|
|
|
case A_I2CS_DEV_ADDR:
|
hw/i2c/aspeed: Add new-registers DMA slave mode RX support
This commit adds support for DMA RX in slave mode while using the new
register set in the AST2600 and AST1030. This patch also pretty much
assumes packet mode is enabled, I'm not sure if this will work in DMA
step mode.
This is particularly useful for testing IPMB exchanges between Zephyr
and external devices, which requires multi-master I2C support and DMA in
the new register mode, because the Zephyr drivers from Aspeed use DMA in
the new mode by default. The Zephyr drivers are also using packet mode.
The typical sequence of events for receiving data in DMA slave + packet
mode is that the Zephyr firmware will configure the slave address
register with an address to receive on and configure the bus's function
control register to enable master mode and slave mode simultaneously at
startup, before any transfers are initiated.
RX DMA is enabled in the slave mode command register, and the slave RX
DMA buffer address and slave RX DMA buffer length are set. TX DMA is not
covered in this patch.
When the Aspeed I2C controller receives data from some other I2C master,
it will reset the I2CS_DMA_LEN RX_LEN value to zero, then buffer
incoming data in the RX DMA buffer while incrementing the I2CC_DMA_ADDR
address counter and decrementing the I2CC_DMA_LEN counter. It will also
update the I2CS_DMA_LEN RX_LEN value along the way.
Once all the data has been received, the bus controller will raise an
interrupt indicating a packet command was completed, the slave address
matched, a normal stop condition was seen, and the transfer was an RX
operation.
If the master sent a NACK instead of a normal stop condition, or the
transfer timed out, then a slightly different set of interrupt status
values would be set. Those conditions are not handled in this commit.
The Zephyr firmware then collects data from the RX DMA buffer and clears
the status register by writing the PKT_MODE_EN bit to the status
register. In packet mode, clearing the packet mode interrupt enable bit
also clears most of the other interrupt bits automatically (except for a
few bits above it).
Note: if the master transmit or receive functions were in use
simultaneously with the slave mode receive functionality, then the
master mode functions may have raised the interrupt line for the bus
before the DMA slave transfer is complete. It's important to have the
slave's interrupt status register clear throughout the receive
operation, and if the slave attempts to raise the interrupt before the
master interrupt status is cleared, then it needs to re-raise the
interrupt once the master interrupt status is cleared. (And vice-versa).
That's why in this commit, when the master interrupt status is cleared
and the interrupt line is lowered, we call the slave interrupt _raise_
function, to see if the interrupt was pending. (And again, vice-versa).
Signed-off-by: Peter Delevoryas <pdel@fb.com>
Message-Id: <20220630045133.32251-8-me@pjd.dev>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
2022-06-30 09:21:14 +02:00
|
|
|
bus->regs[R_I2CS_DEV_ADDR] = value;
|
|
|
|
break;
|
|
|
|
case A_I2CS_DMA_RX_ADDR:
|
|
|
|
bus->regs[R_I2CS_DMA_RX_ADDR] = value;
|
|
|
|
break;
|
|
|
|
case A_I2CS_DMA_LEN:
|
|
|
|
assert(FIELD_EX32(value, I2CS_DMA_LEN, TX_BUF_LEN) == 0);
|
|
|
|
if (FIELD_EX32(value, I2CS_DMA_LEN, RX_BUF_LEN_W1T)) {
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CS_DMA_LEN, RX_BUF_LEN,
|
|
|
|
FIELD_EX32(value, I2CS_DMA_LEN, RX_BUF_LEN));
|
|
|
|
} else {
|
|
|
|
bus->regs[R_I2CS_DMA_LEN] = value;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case A_I2CS_CMD:
|
|
|
|
if (FIELD_EX32(value, I2CS_CMD, W1_CTRL)) {
|
|
|
|
bus->regs[R_I2CS_CMD] |= value;
|
|
|
|
} else {
|
|
|
|
bus->regs[R_I2CS_CMD] = value;
|
|
|
|
}
|
|
|
|
i2c_slave_set_address(bus->slave, bus->regs[R_I2CS_DEV_ADDR]);
|
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CS_INTR_CTRL:
|
hw/i2c/aspeed: Add new-registers DMA slave mode RX support
This commit adds support for DMA RX in slave mode while using the new
register set in the AST2600 and AST1030. This patch also pretty much
assumes packet mode is enabled, I'm not sure if this will work in DMA
step mode.
This is particularly useful for testing IPMB exchanges between Zephyr
and external devices, which requires multi-master I2C support and DMA in
the new register mode, because the Zephyr drivers from Aspeed use DMA in
the new mode by default. The Zephyr drivers are also using packet mode.
The typical sequence of events for receiving data in DMA slave + packet
mode is that the Zephyr firmware will configure the slave address
register with an address to receive on and configure the bus's function
control register to enable master mode and slave mode simultaneously at
startup, before any transfers are initiated.
RX DMA is enabled in the slave mode command register, and the slave RX
DMA buffer address and slave RX DMA buffer length are set. TX DMA is not
covered in this patch.
When the Aspeed I2C controller receives data from some other I2C master,
it will reset the I2CS_DMA_LEN RX_LEN value to zero, then buffer
incoming data in the RX DMA buffer while incrementing the I2CC_DMA_ADDR
address counter and decrementing the I2CC_DMA_LEN counter. It will also
update the I2CS_DMA_LEN RX_LEN value along the way.
Once all the data has been received, the bus controller will raise an
interrupt indicating a packet command was completed, the slave address
matched, a normal stop condition was seen, and the transfer was an RX
operation.
If the master sent a NACK instead of a normal stop condition, or the
transfer timed out, then a slightly different set of interrupt status
values would be set. Those conditions are not handled in this commit.
The Zephyr firmware then collects data from the RX DMA buffer and clears
the status register by writing the PKT_MODE_EN bit to the status
register. In packet mode, clearing the packet mode interrupt enable bit
also clears most of the other interrupt bits automatically (except for a
few bits above it).
Note: if the master transmit or receive functions were in use
simultaneously with the slave mode receive functionality, then the
master mode functions may have raised the interrupt line for the bus
before the DMA slave transfer is complete. It's important to have the
slave's interrupt status register clear throughout the receive
operation, and if the slave attempts to raise the interrupt before the
master interrupt status is cleared, then it needs to re-raise the
interrupt once the master interrupt status is cleared. (And vice-versa).
That's why in this commit, when the master interrupt status is cleared
and the interrupt line is lowered, we call the slave interrupt _raise_
function, to see if the interrupt was pending. (And again, vice-versa).
Signed-off-by: Peter Delevoryas <pdel@fb.com>
Message-Id: <20220630045133.32251-8-me@pjd.dev>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
2022-06-30 09:21:14 +02:00
|
|
|
bus->regs[R_I2CS_INTR_CTRL] = value;
|
|
|
|
break;
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CS_INTR_STS:
|
hw/i2c/aspeed: Add new-registers DMA slave mode RX support
This commit adds support for DMA RX in slave mode while using the new
register set in the AST2600 and AST1030. This patch also pretty much
assumes packet mode is enabled, I'm not sure if this will work in DMA
step mode.
This is particularly useful for testing IPMB exchanges between Zephyr
and external devices, which requires multi-master I2C support and DMA in
the new register mode, because the Zephyr drivers from Aspeed use DMA in
the new mode by default. The Zephyr drivers are also using packet mode.
The typical sequence of events for receiving data in DMA slave + packet
mode is that the Zephyr firmware will configure the slave address
register with an address to receive on and configure the bus's function
control register to enable master mode and slave mode simultaneously at
startup, before any transfers are initiated.
RX DMA is enabled in the slave mode command register, and the slave RX
DMA buffer address and slave RX DMA buffer length are set. TX DMA is not
covered in this patch.
When the Aspeed I2C controller receives data from some other I2C master,
it will reset the I2CS_DMA_LEN RX_LEN value to zero, then buffer
incoming data in the RX DMA buffer while incrementing the I2CC_DMA_ADDR
address counter and decrementing the I2CC_DMA_LEN counter. It will also
update the I2CS_DMA_LEN RX_LEN value along the way.
Once all the data has been received, the bus controller will raise an
interrupt indicating a packet command was completed, the slave address
matched, a normal stop condition was seen, and the transfer was an RX
operation.
If the master sent a NACK instead of a normal stop condition, or the
transfer timed out, then a slightly different set of interrupt status
values would be set. Those conditions are not handled in this commit.
The Zephyr firmware then collects data from the RX DMA buffer and clears
the status register by writing the PKT_MODE_EN bit to the status
register. In packet mode, clearing the packet mode interrupt enable bit
also clears most of the other interrupt bits automatically (except for a
few bits above it).
Note: if the master transmit or receive functions were in use
simultaneously with the slave mode receive functionality, then the
master mode functions may have raised the interrupt line for the bus
before the DMA slave transfer is complete. It's important to have the
slave's interrupt status register clear throughout the receive
operation, and if the slave attempts to raise the interrupt before the
master interrupt status is cleared, then it needs to re-raise the
interrupt once the master interrupt status is cleared. (And vice-versa).
That's why in this commit, when the master interrupt status is cleared
and the interrupt line is lowered, we call the slave interrupt _raise_
function, to see if the interrupt was pending. (And again, vice-versa).
Signed-off-by: Peter Delevoryas <pdel@fb.com>
Message-Id: <20220630045133.32251-8-me@pjd.dev>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
2022-06-30 09:21:14 +02:00
|
|
|
if (ARRAY_FIELD_EX32(bus->regs, I2CS_INTR_CTRL, PKT_CMD_DONE)) {
|
|
|
|
if (ARRAY_FIELD_EX32(bus->regs, I2CS_INTR_STS, PKT_CMD_DONE) &&
|
|
|
|
FIELD_EX32(value, I2CS_INTR_STS, PKT_CMD_DONE)) {
|
|
|
|
bus->regs[R_I2CS_INTR_STS] &= 0xfffc0000;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bus->regs[R_I2CS_INTR_STS] &= ~value;
|
|
|
|
}
|
|
|
|
if (!bus->regs[R_I2CS_INTR_STS]) {
|
|
|
|
bus->controller->intr_status &= ~(1 << bus->id);
|
|
|
|
qemu_irq_lower(aic->bus_get_irq(bus));
|
|
|
|
}
|
|
|
|
aspeed_i2c_bus_raise_interrupt(bus);
|
|
|
|
break;
|
|
|
|
case A_I2CS_DMA_LEN_STS:
|
|
|
|
bus->regs[R_I2CS_DMA_LEN_STS] = 0;
|
|
|
|
break;
|
|
|
|
case A_I2CS_DMA_TX_ADDR:
|
|
|
|
qemu_log_mask(LOG_UNIMP, "%s: Slave mode DMA TX is not implemented\n",
|
2022-06-13 14:05:48 +02:00
|
|
|
__func__);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
|
|
|
|
__func__, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void aspeed_i2c_bus_old_write(AspeedI2CBus *bus, hwaddr offset,
|
|
|
|
uint64_t value, unsigned size)
|
2016-06-06 17:59:29 +02:00
|
|
|
{
|
2019-09-25 16:32:41 +02:00
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
|
2018-09-25 15:02:31 +02:00
|
|
|
bool handle_rx;
|
2016-06-06 17:59:29 +02:00
|
|
|
|
2019-11-19 15:11:59 +01:00
|
|
|
trace_aspeed_i2c_bus_write(bus->id, offset, size, value);
|
|
|
|
|
2016-06-06 17:59:29 +02:00
|
|
|
switch (offset) {
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_FUN_CTRL:
|
2022-06-13 14:05:48 +02:00
|
|
|
if (SHARED_FIELD_EX32(value, SLAVE_EN)) {
|
2022-06-30 09:21:14 +02:00
|
|
|
i2c_slave_set_address(bus->slave, bus->regs[R_I2CD_DEV_ADDR]);
|
2016-06-06 17:59:29 +02:00
|
|
|
}
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[R_I2CD_FUN_CTRL] = value & 0x0071C3FF;
|
2016-06-06 17:59:29 +02:00
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_AC_TIMING1:
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[R_I2CD_AC_TIMING1] = value & 0xFFFFF0F;
|
2016-06-06 17:59:29 +02:00
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_AC_TIMING2:
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[R_I2CD_AC_TIMING2] = value & 0x7;
|
2016-06-06 17:59:29 +02:00
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_INTR_CTRL:
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[R_I2CD_INTR_CTRL] = value & 0x7FFF;
|
2016-06-06 17:59:29 +02:00
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_INTR_STS:
|
2022-06-13 14:05:48 +02:00
|
|
|
handle_rx = SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CD_INTR_STS, RX_DONE)
|
|
|
|
&& SHARED_FIELD_EX32(value, RX_DONE);
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[R_I2CD_INTR_STS] &= ~(value & 0x7FFF);
|
|
|
|
if (!bus->regs[R_I2CD_INTR_STS]) {
|
2018-09-25 15:02:31 +02:00
|
|
|
bus->controller->intr_status &= ~(1 << bus->id);
|
2019-09-25 16:32:41 +02:00
|
|
|
qemu_irq_lower(aic->bus_get_irq(bus));
|
2018-09-25 15:02:31 +02:00
|
|
|
}
|
2022-06-30 09:21:14 +02:00
|
|
|
if (handle_rx) {
|
|
|
|
if (SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CD_CMD, M_RX_CMD) ||
|
|
|
|
SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CD_CMD,
|
|
|
|
M_S_RX_CMD_LAST)) {
|
|
|
|
aspeed_i2c_handle_rx_cmd(bus);
|
|
|
|
aspeed_i2c_bus_raise_interrupt(bus);
|
|
|
|
} else if (aspeed_i2c_get_state(bus) == I2CD_STXD) {
|
|
|
|
i2c_ack(bus->bus);
|
|
|
|
}
|
2018-09-25 15:02:31 +02:00
|
|
|
}
|
2016-06-06 17:59:29 +02:00
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_DEV_ADDR:
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[R_I2CD_DEV_ADDR] = value;
|
2016-06-06 17:59:29 +02:00
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_POOL_CTRL:
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[R_I2CD_POOL_CTRL] &= ~0xffffff;
|
|
|
|
bus->regs[R_I2CD_POOL_CTRL] |= (value & 0xffffff);
|
2019-11-19 15:11:55 +01:00
|
|
|
break;
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_BYTE_BUF:
|
2022-06-13 14:05:48 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, R_I2CD_BYTE_BUF, TX_BUF, value);
|
2016-06-06 17:59:29 +02:00
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_CMD:
|
2016-06-06 17:59:29 +02:00
|
|
|
if (!aspeed_i2c_bus_is_enabled(bus)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!aspeed_i2c_bus_is_master(bus)) {
|
2022-06-30 09:21:14 +02:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: Master mode is not enabled\n",
|
2016-06-06 17:59:29 +02:00
|
|
|
__func__);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2019-11-19 15:11:58 +01:00
|
|
|
if (!aic->has_dma &&
|
2022-06-13 14:05:48 +02:00
|
|
|
(SHARED_FIELD_EX32(value, RX_DMA_EN) ||
|
|
|
|
SHARED_FIELD_EX32(value, TX_DMA_EN))) {
|
2019-11-19 15:11:58 +01:00
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: No DMA support\n", __func__);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[R_I2CD_CMD] &= ~0xFFFF;
|
|
|
|
bus->regs[R_I2CD_CMD] |= value & 0xFFFF;
|
|
|
|
|
2016-06-06 17:59:29 +02:00
|
|
|
aspeed_i2c_bus_handle_cmd(bus, value);
|
2017-06-02 12:51:49 +02:00
|
|
|
aspeed_i2c_bus_raise_interrupt(bus);
|
2016-06-06 17:59:29 +02:00
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_DMA_ADDR:
|
2019-11-19 15:11:58 +01:00
|
|
|
if (!aic->has_dma) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: No DMA support\n", __func__);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[R_I2CD_DMA_ADDR] = value & 0x3ffffffc;
|
2019-11-19 15:11:58 +01:00
|
|
|
break;
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2CD_DMA_LEN:
|
2019-11-19 15:11:58 +01:00
|
|
|
if (!aic->has_dma) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: No DMA support\n", __func__);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
bus->regs[R_I2CD_DMA_LEN] = value & 0xfff;
|
|
|
|
if (!bus->regs[R_I2CD_DMA_LEN]) {
|
2019-11-19 15:11:58 +01:00
|
|
|
qemu_log_mask(LOG_UNIMP, "%s: invalid DMA length\n", __func__);
|
|
|
|
}
|
|
|
|
break;
|
2016-06-06 17:59:29 +02:00
|
|
|
|
|
|
|
default:
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
|
|
|
|
__func__, offset);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
static void aspeed_i2c_bus_write(void *opaque, hwaddr offset,
|
|
|
|
uint64_t value, unsigned size)
|
|
|
|
{
|
|
|
|
AspeedI2CBus *bus = opaque;
|
|
|
|
if (aspeed_i2c_is_new_mode(bus->controller)) {
|
|
|
|
aspeed_i2c_bus_new_write(bus, offset, value, size);
|
|
|
|
} else {
|
|
|
|
aspeed_i2c_bus_old_write(bus, offset, value, size);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-06 17:59:29 +02:00
|
|
|
static uint64_t aspeed_i2c_ctrl_read(void *opaque, hwaddr offset,
|
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
AspeedI2CState *s = opaque;
|
|
|
|
|
|
|
|
switch (offset) {
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2C_CTRL_STATUS:
|
2016-06-06 17:59:29 +02:00
|
|
|
return s->intr_status;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2C_CTRL_GLOBAL:
|
2019-11-19 15:11:56 +01:00
|
|
|
return s->ctrl_global;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2C_CTRL_NEW_CLK_DIVIDER:
|
|
|
|
if (aspeed_i2c_is_new_mode(s)) {
|
|
|
|
return s->new_clk_divider;
|
|
|
|
}
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
|
|
|
|
__func__, offset);
|
|
|
|
break;
|
2016-06-06 17:59:29 +02:00
|
|
|
default:
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
|
|
|
|
__func__, offset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void aspeed_i2c_ctrl_write(void *opaque, hwaddr offset,
|
|
|
|
uint64_t value, unsigned size)
|
|
|
|
{
|
2019-11-19 15:11:56 +01:00
|
|
|
AspeedI2CState *s = opaque;
|
|
|
|
|
2016-06-06 17:59:29 +02:00
|
|
|
switch (offset) {
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2C_CTRL_GLOBAL:
|
2019-11-19 15:11:56 +01:00
|
|
|
s->ctrl_global = value;
|
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2C_CTRL_NEW_CLK_DIVIDER:
|
|
|
|
if (aspeed_i2c_is_new_mode(s)) {
|
|
|
|
s->new_clk_divider = value;
|
|
|
|
} else {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx
|
|
|
|
"\n", __func__, offset);
|
|
|
|
}
|
|
|
|
break;
|
2022-06-13 14:05:48 +02:00
|
|
|
case A_I2C_CTRL_STATUS:
|
2016-06-06 17:59:29 +02:00
|
|
|
default:
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
|
|
|
|
__func__, offset);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps aspeed_i2c_bus_ops = {
|
|
|
|
.read = aspeed_i2c_bus_read,
|
|
|
|
.write = aspeed_i2c_bus_write,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const MemoryRegionOps aspeed_i2c_ctrl_ops = {
|
|
|
|
.read = aspeed_i2c_ctrl_read,
|
|
|
|
.write = aspeed_i2c_ctrl_write,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
};
|
|
|
|
|
2019-11-19 15:11:55 +01:00
|
|
|
static uint64_t aspeed_i2c_pool_read(void *opaque, hwaddr offset,
|
|
|
|
unsigned size)
|
|
|
|
{
|
|
|
|
AspeedI2CState *s = opaque;
|
|
|
|
uint64_t ret = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
ret |= (uint64_t) s->pool[offset + i] << (8 * i);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void aspeed_i2c_pool_write(void *opaque, hwaddr offset,
|
|
|
|
uint64_t value, unsigned size)
|
|
|
|
{
|
|
|
|
AspeedI2CState *s = opaque;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
s->pool[offset + i] = (value >> (8 * i)) & 0xFF;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const MemoryRegionOps aspeed_i2c_pool_ops = {
|
|
|
|
.read = aspeed_i2c_pool_read,
|
|
|
|
.write = aspeed_i2c_pool_write,
|
|
|
|
.endianness = DEVICE_LITTLE_ENDIAN,
|
|
|
|
.valid = {
|
|
|
|
.min_access_size = 1,
|
|
|
|
.max_access_size = 4,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-06-06 17:59:29 +02:00
|
|
|
static const VMStateDescription aspeed_i2c_bus_vmstate = {
|
|
|
|
.name = TYPE_ASPEED_I2C,
|
2022-06-13 14:05:48 +02:00
|
|
|
.version_id = 5,
|
|
|
|
.minimum_version_id = 5,
|
2016-06-06 17:59:29 +02:00
|
|
|
.fields = (VMStateField[]) {
|
2022-06-13 14:05:48 +02:00
|
|
|
VMSTATE_UINT32_ARRAY(regs, AspeedI2CBus, ASPEED_I2C_NEW_NUM_REG),
|
2016-06-06 17:59:29 +02:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const VMStateDescription aspeed_i2c_vmstate = {
|
|
|
|
.name = TYPE_ASPEED_I2C,
|
2019-11-19 15:11:55 +01:00
|
|
|
.version_id = 2,
|
|
|
|
.minimum_version_id = 2,
|
2016-06-06 17:59:29 +02:00
|
|
|
.fields = (VMStateField[]) {
|
|
|
|
VMSTATE_UINT32(intr_status, AspeedI2CState),
|
|
|
|
VMSTATE_STRUCT_ARRAY(busses, AspeedI2CState,
|
|
|
|
ASPEED_I2C_NR_BUSSES, 1, aspeed_i2c_bus_vmstate,
|
|
|
|
AspeedI2CBus),
|
2019-11-19 15:11:55 +01:00
|
|
|
VMSTATE_UINT8_ARRAY(pool, AspeedI2CState, ASPEED_I2C_MAX_POOL_SIZE),
|
2016-06-06 17:59:29 +02:00
|
|
|
VMSTATE_END_OF_LIST()
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
static void aspeed_i2c_reset(DeviceState *dev)
|
|
|
|
{
|
|
|
|
AspeedI2CState *s = ASPEED_I2C(dev);
|
|
|
|
|
|
|
|
s->intr_status = 0;
|
2021-10-12 08:20:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static void aspeed_i2c_instance_init(Object *obj)
|
|
|
|
{
|
|
|
|
AspeedI2CState *s = ASPEED_I2C(obj);
|
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(s);
|
|
|
|
int i;
|
2016-06-06 17:59:29 +02:00
|
|
|
|
2019-09-25 16:32:40 +02:00
|
|
|
for (i = 0; i < aic->num_busses; i++) {
|
2021-10-12 08:20:08 +02:00
|
|
|
object_initialize_child(obj, "bus[*]", &s->busses[i],
|
|
|
|
TYPE_ASPEED_I2C_BUS);
|
2016-06-06 17:59:29 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2019-09-25 16:32:40 +02:00
|
|
|
* Address Definitions (AST2400 and AST2500)
|
2016-06-06 17:59:29 +02:00
|
|
|
*
|
|
|
|
* 0x000 ... 0x03F: Global Register
|
|
|
|
* 0x040 ... 0x07F: Device 1
|
|
|
|
* 0x080 ... 0x0BF: Device 2
|
|
|
|
* 0x0C0 ... 0x0FF: Device 3
|
|
|
|
* 0x100 ... 0x13F: Device 4
|
|
|
|
* 0x140 ... 0x17F: Device 5
|
|
|
|
* 0x180 ... 0x1BF: Device 6
|
|
|
|
* 0x1C0 ... 0x1FF: Device 7
|
|
|
|
* 0x200 ... 0x2FF: Buffer Pool (unused in linux driver)
|
|
|
|
* 0x300 ... 0x33F: Device 8
|
|
|
|
* 0x340 ... 0x37F: Device 9
|
|
|
|
* 0x380 ... 0x3BF: Device 10
|
|
|
|
* 0x3C0 ... 0x3FF: Device 11
|
|
|
|
* 0x400 ... 0x43F: Device 12
|
|
|
|
* 0x440 ... 0x47F: Device 13
|
|
|
|
* 0x480 ... 0x4BF: Device 14
|
|
|
|
* 0x800 ... 0xFFF: Buffer Pool (unused in linux driver)
|
|
|
|
*/
|
|
|
|
static void aspeed_i2c_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
SysBusDevice *sbd = SYS_BUS_DEVICE(dev);
|
|
|
|
AspeedI2CState *s = ASPEED_I2C(dev);
|
2019-09-25 16:32:40 +02:00
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(s);
|
2016-06-06 17:59:29 +02:00
|
|
|
|
|
|
|
sysbus_init_irq(sbd, &s->irq);
|
|
|
|
memory_region_init_io(&s->iomem, OBJECT(s), &aspeed_i2c_ctrl_ops, s,
|
|
|
|
"aspeed.i2c", 0x1000);
|
|
|
|
sysbus_init_mmio(sbd, &s->iomem);
|
|
|
|
|
2019-09-25 16:32:40 +02:00
|
|
|
for (i = 0; i < aic->num_busses; i++) {
|
2021-10-12 08:20:08 +02:00
|
|
|
Object *bus = OBJECT(&s->busses[i]);
|
2019-09-25 16:32:40 +02:00
|
|
|
int offset = i < aic->gap ? 1 : 5;
|
2019-09-25 16:32:41 +02:00
|
|
|
|
2021-10-12 08:20:08 +02:00
|
|
|
if (!object_property_set_link(bus, "controller", OBJECT(s), errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!object_property_set_uint(bus, "bus-id", i, errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!sysbus_realize(SYS_BUS_DEVICE(bus), errp)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-09-25 16:32:40 +02:00
|
|
|
memory_region_add_subregion(&s->iomem, aic->reg_size * (i + offset),
|
2016-06-06 17:59:29 +02:00
|
|
|
&s->busses[i].mr);
|
|
|
|
}
|
2019-11-19 15:11:55 +01:00
|
|
|
|
|
|
|
memory_region_init_io(&s->pool_iomem, OBJECT(s), &aspeed_i2c_pool_ops, s,
|
|
|
|
"aspeed.i2c-pool", aic->pool_size);
|
|
|
|
memory_region_add_subregion(&s->iomem, aic->pool_base, &s->pool_iomem);
|
2019-11-19 15:11:58 +01:00
|
|
|
|
|
|
|
if (aic->has_dma) {
|
|
|
|
if (!s->dram_mr) {
|
|
|
|
error_setg(errp, TYPE_ASPEED_I2C ": 'dram' link not set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-05-01 10:03:51 +02:00
|
|
|
address_space_init(&s->dram_as, s->dram_mr,
|
|
|
|
TYPE_ASPEED_I2C "-dma-dram");
|
2019-11-19 15:11:58 +01:00
|
|
|
}
|
2016-06-06 17:59:29 +02:00
|
|
|
}
|
|
|
|
|
2019-11-19 15:11:58 +01:00
|
|
|
static Property aspeed_i2c_properties[] = {
|
|
|
|
DEFINE_PROP_LINK("dram", AspeedI2CState, dram_mr,
|
|
|
|
TYPE_MEMORY_REGION, MemoryRegion *),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
2016-06-06 17:59:29 +02:00
|
|
|
static void aspeed_i2c_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
dc->vmsd = &aspeed_i2c_vmstate;
|
|
|
|
dc->reset = aspeed_i2c_reset;
|
2020-01-10 16:30:32 +01:00
|
|
|
device_class_set_props(dc, aspeed_i2c_properties);
|
2016-06-06 17:59:29 +02:00
|
|
|
dc->realize = aspeed_i2c_realize;
|
|
|
|
dc->desc = "Aspeed I2C Controller";
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo aspeed_i2c_info = {
|
|
|
|
.name = TYPE_ASPEED_I2C,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
2021-10-12 08:20:08 +02:00
|
|
|
.instance_init = aspeed_i2c_instance_init,
|
2016-06-06 17:59:29 +02:00
|
|
|
.instance_size = sizeof(AspeedI2CState),
|
|
|
|
.class_init = aspeed_i2c_class_init,
|
2019-09-25 16:32:40 +02:00
|
|
|
.class_size = sizeof(AspeedI2CClass),
|
|
|
|
.abstract = true,
|
|
|
|
};
|
|
|
|
|
hw/i2c/aspeed: Add new-registers DMA slave mode RX support
This commit adds support for DMA RX in slave mode while using the new
register set in the AST2600 and AST1030. This patch also pretty much
assumes packet mode is enabled, I'm not sure if this will work in DMA
step mode.
This is particularly useful for testing IPMB exchanges between Zephyr
and external devices, which requires multi-master I2C support and DMA in
the new register mode, because the Zephyr drivers from Aspeed use DMA in
the new mode by default. The Zephyr drivers are also using packet mode.
The typical sequence of events for receiving data in DMA slave + packet
mode is that the Zephyr firmware will configure the slave address
register with an address to receive on and configure the bus's function
control register to enable master mode and slave mode simultaneously at
startup, before any transfers are initiated.
RX DMA is enabled in the slave mode command register, and the slave RX
DMA buffer address and slave RX DMA buffer length are set. TX DMA is not
covered in this patch.
When the Aspeed I2C controller receives data from some other I2C master,
it will reset the I2CS_DMA_LEN RX_LEN value to zero, then buffer
incoming data in the RX DMA buffer while incrementing the I2CC_DMA_ADDR
address counter and decrementing the I2CC_DMA_LEN counter. It will also
update the I2CS_DMA_LEN RX_LEN value along the way.
Once all the data has been received, the bus controller will raise an
interrupt indicating a packet command was completed, the slave address
matched, a normal stop condition was seen, and the transfer was an RX
operation.
If the master sent a NACK instead of a normal stop condition, or the
transfer timed out, then a slightly different set of interrupt status
values would be set. Those conditions are not handled in this commit.
The Zephyr firmware then collects data from the RX DMA buffer and clears
the status register by writing the PKT_MODE_EN bit to the status
register. In packet mode, clearing the packet mode interrupt enable bit
also clears most of the other interrupt bits automatically (except for a
few bits above it).
Note: if the master transmit or receive functions were in use
simultaneously with the slave mode receive functionality, then the
master mode functions may have raised the interrupt line for the bus
before the DMA slave transfer is complete. It's important to have the
slave's interrupt status register clear throughout the receive
operation, and if the slave attempts to raise the interrupt before the
master interrupt status is cleared, then it needs to re-raise the
interrupt once the master interrupt status is cleared. (And vice-versa).
That's why in this commit, when the master interrupt status is cleared
and the interrupt line is lowered, we call the slave interrupt _raise_
function, to see if the interrupt was pending. (And again, vice-versa).
Signed-off-by: Peter Delevoryas <pdel@fb.com>
Message-Id: <20220630045133.32251-8-me@pjd.dev>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
2022-06-30 09:21:14 +02:00
|
|
|
static int aspeed_i2c_bus_new_slave_event(AspeedI2CBus *bus,
|
|
|
|
enum i2c_event event)
|
|
|
|
{
|
|
|
|
switch (event) {
|
|
|
|
case I2C_START_SEND_ASYNC:
|
|
|
|
if (!SHARED_ARRAY_FIELD_EX32(bus->regs, R_I2CS_CMD, RX_DMA_EN)) {
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR,
|
|
|
|
"%s: Slave mode RX DMA is not enabled\n", __func__);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CS_DMA_LEN_STS, RX_LEN, 0);
|
|
|
|
bus->regs[R_I2CC_DMA_ADDR] =
|
|
|
|
ARRAY_FIELD_EX32(bus->regs, I2CS_DMA_RX_ADDR, ADDR);
|
|
|
|
bus->regs[R_I2CC_DMA_LEN] =
|
|
|
|
ARRAY_FIELD_EX32(bus->regs, I2CS_DMA_LEN, RX_BUF_LEN) + 1;
|
|
|
|
i2c_ack(bus->bus);
|
|
|
|
break;
|
|
|
|
case I2C_FINISH:
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CS_INTR_STS, PKT_CMD_DONE, 1);
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CS_INTR_STS, SLAVE_ADDR_RX_MATCH, 1);
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, R_I2CS_INTR_STS, NORMAL_STOP, 1);
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, R_I2CS_INTR_STS, RX_DONE, 1);
|
|
|
|
aspeed_i2c_bus_raise_slave_interrupt(bus);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
qemu_log_mask(LOG_UNIMP, "%s: i2c event %d unimplemented\n",
|
|
|
|
__func__, event);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-06-30 09:21:14 +02:00
|
|
|
static int aspeed_i2c_bus_slave_event(I2CSlave *slave, enum i2c_event event)
|
|
|
|
{
|
|
|
|
BusState *qbus = qdev_get_parent_bus(DEVICE(slave));
|
|
|
|
AspeedI2CBus *bus = ASPEED_I2C_BUS(qbus->parent);
|
|
|
|
uint32_t reg_intr_sts = aspeed_i2c_bus_intr_sts_offset(bus);
|
|
|
|
uint32_t reg_byte_buf = aspeed_i2c_bus_byte_buf_offset(bus);
|
2022-10-24 11:20:15 +02:00
|
|
|
uint32_t reg_dev_addr = aspeed_i2c_bus_dev_addr_offset(bus);
|
|
|
|
uint32_t dev_addr = SHARED_ARRAY_FIELD_EX32(bus->regs, reg_dev_addr,
|
|
|
|
SLAVE_DEV_ADDR1);
|
2022-06-30 09:21:14 +02:00
|
|
|
|
hw/i2c/aspeed: Add new-registers DMA slave mode RX support
This commit adds support for DMA RX in slave mode while using the new
register set in the AST2600 and AST1030. This patch also pretty much
assumes packet mode is enabled, I'm not sure if this will work in DMA
step mode.
This is particularly useful for testing IPMB exchanges between Zephyr
and external devices, which requires multi-master I2C support and DMA in
the new register mode, because the Zephyr drivers from Aspeed use DMA in
the new mode by default. The Zephyr drivers are also using packet mode.
The typical sequence of events for receiving data in DMA slave + packet
mode is that the Zephyr firmware will configure the slave address
register with an address to receive on and configure the bus's function
control register to enable master mode and slave mode simultaneously at
startup, before any transfers are initiated.
RX DMA is enabled in the slave mode command register, and the slave RX
DMA buffer address and slave RX DMA buffer length are set. TX DMA is not
covered in this patch.
When the Aspeed I2C controller receives data from some other I2C master,
it will reset the I2CS_DMA_LEN RX_LEN value to zero, then buffer
incoming data in the RX DMA buffer while incrementing the I2CC_DMA_ADDR
address counter and decrementing the I2CC_DMA_LEN counter. It will also
update the I2CS_DMA_LEN RX_LEN value along the way.
Once all the data has been received, the bus controller will raise an
interrupt indicating a packet command was completed, the slave address
matched, a normal stop condition was seen, and the transfer was an RX
operation.
If the master sent a NACK instead of a normal stop condition, or the
transfer timed out, then a slightly different set of interrupt status
values would be set. Those conditions are not handled in this commit.
The Zephyr firmware then collects data from the RX DMA buffer and clears
the status register by writing the PKT_MODE_EN bit to the status
register. In packet mode, clearing the packet mode interrupt enable bit
also clears most of the other interrupt bits automatically (except for a
few bits above it).
Note: if the master transmit or receive functions were in use
simultaneously with the slave mode receive functionality, then the
master mode functions may have raised the interrupt line for the bus
before the DMA slave transfer is complete. It's important to have the
slave's interrupt status register clear throughout the receive
operation, and if the slave attempts to raise the interrupt before the
master interrupt status is cleared, then it needs to re-raise the
interrupt once the master interrupt status is cleared. (And vice-versa).
That's why in this commit, when the master interrupt status is cleared
and the interrupt line is lowered, we call the slave interrupt _raise_
function, to see if the interrupt was pending. (And again, vice-versa).
Signed-off-by: Peter Delevoryas <pdel@fb.com>
Message-Id: <20220630045133.32251-8-me@pjd.dev>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
2022-06-30 09:21:14 +02:00
|
|
|
if (aspeed_i2c_is_new_mode(bus->controller)) {
|
|
|
|
return aspeed_i2c_bus_new_slave_event(bus, event);
|
|
|
|
}
|
|
|
|
|
2022-06-30 09:21:14 +02:00
|
|
|
switch (event) {
|
|
|
|
case I2C_START_SEND_ASYNC:
|
2022-10-24 11:20:15 +02:00
|
|
|
/* Bit[0] == 0 indicates "send". */
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_byte_buf, RX_BUF, dev_addr << 1);
|
2022-06-30 09:21:14 +02:00
|
|
|
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CD_INTR_STS, SLAVE_ADDR_RX_MATCH, 1);
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, RX_DONE, 1);
|
|
|
|
|
|
|
|
aspeed_i2c_set_state(bus, I2CD_STXD);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case I2C_FINISH:
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, NORMAL_STOP, 1);
|
|
|
|
|
|
|
|
aspeed_i2c_set_state(bus, I2CD_IDLE);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
aspeed_i2c_bus_raise_interrupt(bus);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
hw/i2c/aspeed: Add new-registers DMA slave mode RX support
This commit adds support for DMA RX in slave mode while using the new
register set in the AST2600 and AST1030. This patch also pretty much
assumes packet mode is enabled, I'm not sure if this will work in DMA
step mode.
This is particularly useful for testing IPMB exchanges between Zephyr
and external devices, which requires multi-master I2C support and DMA in
the new register mode, because the Zephyr drivers from Aspeed use DMA in
the new mode by default. The Zephyr drivers are also using packet mode.
The typical sequence of events for receiving data in DMA slave + packet
mode is that the Zephyr firmware will configure the slave address
register with an address to receive on and configure the bus's function
control register to enable master mode and slave mode simultaneously at
startup, before any transfers are initiated.
RX DMA is enabled in the slave mode command register, and the slave RX
DMA buffer address and slave RX DMA buffer length are set. TX DMA is not
covered in this patch.
When the Aspeed I2C controller receives data from some other I2C master,
it will reset the I2CS_DMA_LEN RX_LEN value to zero, then buffer
incoming data in the RX DMA buffer while incrementing the I2CC_DMA_ADDR
address counter and decrementing the I2CC_DMA_LEN counter. It will also
update the I2CS_DMA_LEN RX_LEN value along the way.
Once all the data has been received, the bus controller will raise an
interrupt indicating a packet command was completed, the slave address
matched, a normal stop condition was seen, and the transfer was an RX
operation.
If the master sent a NACK instead of a normal stop condition, or the
transfer timed out, then a slightly different set of interrupt status
values would be set. Those conditions are not handled in this commit.
The Zephyr firmware then collects data from the RX DMA buffer and clears
the status register by writing the PKT_MODE_EN bit to the status
register. In packet mode, clearing the packet mode interrupt enable bit
also clears most of the other interrupt bits automatically (except for a
few bits above it).
Note: if the master transmit or receive functions were in use
simultaneously with the slave mode receive functionality, then the
master mode functions may have raised the interrupt line for the bus
before the DMA slave transfer is complete. It's important to have the
slave's interrupt status register clear throughout the receive
operation, and if the slave attempts to raise the interrupt before the
master interrupt status is cleared, then it needs to re-raise the
interrupt once the master interrupt status is cleared. (And vice-versa).
That's why in this commit, when the master interrupt status is cleared
and the interrupt line is lowered, we call the slave interrupt _raise_
function, to see if the interrupt was pending. (And again, vice-versa).
Signed-off-by: Peter Delevoryas <pdel@fb.com>
Message-Id: <20220630045133.32251-8-me@pjd.dev>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
2022-06-30 09:21:14 +02:00
|
|
|
static void aspeed_i2c_bus_new_slave_send_async(AspeedI2CBus *bus, uint8_t data)
|
|
|
|
{
|
|
|
|
assert(address_space_write(&bus->controller->dram_as,
|
|
|
|
bus->regs[R_I2CC_DMA_ADDR],
|
|
|
|
MEMTXATTRS_UNSPECIFIED, &data, 1) == MEMTX_OK);
|
|
|
|
|
|
|
|
bus->regs[R_I2CC_DMA_ADDR]++;
|
|
|
|
bus->regs[R_I2CC_DMA_LEN]--;
|
|
|
|
ARRAY_FIELD_DP32(bus->regs, I2CS_DMA_LEN_STS, RX_LEN,
|
|
|
|
ARRAY_FIELD_EX32(bus->regs, I2CS_DMA_LEN_STS, RX_LEN) + 1);
|
|
|
|
i2c_ack(bus->bus);
|
|
|
|
}
|
|
|
|
|
2022-06-30 09:21:14 +02:00
|
|
|
static void aspeed_i2c_bus_slave_send_async(I2CSlave *slave, uint8_t data)
|
|
|
|
{
|
|
|
|
BusState *qbus = qdev_get_parent_bus(DEVICE(slave));
|
|
|
|
AspeedI2CBus *bus = ASPEED_I2C_BUS(qbus->parent);
|
|
|
|
uint32_t reg_intr_sts = aspeed_i2c_bus_intr_sts_offset(bus);
|
|
|
|
uint32_t reg_byte_buf = aspeed_i2c_bus_byte_buf_offset(bus);
|
|
|
|
|
hw/i2c/aspeed: Add new-registers DMA slave mode RX support
This commit adds support for DMA RX in slave mode while using the new
register set in the AST2600 and AST1030. This patch also pretty much
assumes packet mode is enabled, I'm not sure if this will work in DMA
step mode.
This is particularly useful for testing IPMB exchanges between Zephyr
and external devices, which requires multi-master I2C support and DMA in
the new register mode, because the Zephyr drivers from Aspeed use DMA in
the new mode by default. The Zephyr drivers are also using packet mode.
The typical sequence of events for receiving data in DMA slave + packet
mode is that the Zephyr firmware will configure the slave address
register with an address to receive on and configure the bus's function
control register to enable master mode and slave mode simultaneously at
startup, before any transfers are initiated.
RX DMA is enabled in the slave mode command register, and the slave RX
DMA buffer address and slave RX DMA buffer length are set. TX DMA is not
covered in this patch.
When the Aspeed I2C controller receives data from some other I2C master,
it will reset the I2CS_DMA_LEN RX_LEN value to zero, then buffer
incoming data in the RX DMA buffer while incrementing the I2CC_DMA_ADDR
address counter and decrementing the I2CC_DMA_LEN counter. It will also
update the I2CS_DMA_LEN RX_LEN value along the way.
Once all the data has been received, the bus controller will raise an
interrupt indicating a packet command was completed, the slave address
matched, a normal stop condition was seen, and the transfer was an RX
operation.
If the master sent a NACK instead of a normal stop condition, or the
transfer timed out, then a slightly different set of interrupt status
values would be set. Those conditions are not handled in this commit.
The Zephyr firmware then collects data from the RX DMA buffer and clears
the status register by writing the PKT_MODE_EN bit to the status
register. In packet mode, clearing the packet mode interrupt enable bit
also clears most of the other interrupt bits automatically (except for a
few bits above it).
Note: if the master transmit or receive functions were in use
simultaneously with the slave mode receive functionality, then the
master mode functions may have raised the interrupt line for the bus
before the DMA slave transfer is complete. It's important to have the
slave's interrupt status register clear throughout the receive
operation, and if the slave attempts to raise the interrupt before the
master interrupt status is cleared, then it needs to re-raise the
interrupt once the master interrupt status is cleared. (And vice-versa).
That's why in this commit, when the master interrupt status is cleared
and the interrupt line is lowered, we call the slave interrupt _raise_
function, to see if the interrupt was pending. (And again, vice-versa).
Signed-off-by: Peter Delevoryas <pdel@fb.com>
Message-Id: <20220630045133.32251-8-me@pjd.dev>
Signed-off-by: Cédric Le Goater <clg@kaod.org>
2022-06-30 09:21:14 +02:00
|
|
|
if (aspeed_i2c_is_new_mode(bus->controller)) {
|
|
|
|
return aspeed_i2c_bus_new_slave_send_async(bus, data);
|
|
|
|
}
|
|
|
|
|
2022-06-30 09:21:14 +02:00
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_byte_buf, RX_BUF, data);
|
|
|
|
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, RX_DONE, 1);
|
|
|
|
|
|
|
|
aspeed_i2c_bus_raise_interrupt(bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void aspeed_i2c_bus_slave_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
I2CSlaveClass *sc = I2C_SLAVE_CLASS(klass);
|
|
|
|
|
|
|
|
dc->desc = "Aspeed I2C Bus Slave";
|
|
|
|
|
|
|
|
sc->event = aspeed_i2c_bus_slave_event;
|
|
|
|
sc->send_async = aspeed_i2c_bus_slave_send_async;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo aspeed_i2c_bus_slave_info = {
|
|
|
|
.name = TYPE_ASPEED_I2C_BUS_SLAVE,
|
|
|
|
.parent = TYPE_I2C_SLAVE,
|
|
|
|
.instance_size = sizeof(AspeedI2CBusSlave),
|
|
|
|
.class_init = aspeed_i2c_bus_slave_class_init,
|
|
|
|
};
|
|
|
|
|
2021-10-12 08:20:08 +02:00
|
|
|
static void aspeed_i2c_bus_reset(DeviceState *dev)
|
|
|
|
{
|
|
|
|
AspeedI2CBus *s = ASPEED_I2C_BUS(dev);
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
memset(s->regs, 0, sizeof(s->regs));
|
2021-10-12 08:20:08 +02:00
|
|
|
i2c_end_transfer(s->bus);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void aspeed_i2c_bus_realize(DeviceState *dev, Error **errp)
|
|
|
|
{
|
|
|
|
AspeedI2CBus *s = ASPEED_I2C_BUS(dev);
|
|
|
|
AspeedI2CClass *aic;
|
|
|
|
g_autofree char *name = g_strdup_printf(TYPE_ASPEED_I2C_BUS ".%d", s->id);
|
|
|
|
|
|
|
|
if (!s->controller) {
|
|
|
|
error_setg(errp, TYPE_ASPEED_I2C_BUS ": 'controller' link not set");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
aic = ASPEED_I2C_GET_CLASS(s->controller);
|
|
|
|
|
|
|
|
sysbus_init_irq(SYS_BUS_DEVICE(dev), &s->irq);
|
|
|
|
|
|
|
|
s->bus = i2c_init_bus(dev, name);
|
2022-06-30 09:21:14 +02:00
|
|
|
s->slave = i2c_slave_create_simple(s->bus, TYPE_ASPEED_I2C_BUS_SLAVE,
|
|
|
|
0xff);
|
2021-10-12 08:20:08 +02:00
|
|
|
|
|
|
|
memory_region_init_io(&s->mr, OBJECT(s), &aspeed_i2c_bus_ops,
|
|
|
|
s, name, aic->reg_size);
|
|
|
|
sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mr);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Property aspeed_i2c_bus_properties[] = {
|
|
|
|
DEFINE_PROP_UINT8("bus-id", AspeedI2CBus, id, 0),
|
|
|
|
DEFINE_PROP_LINK("controller", AspeedI2CBus, controller, TYPE_ASPEED_I2C,
|
|
|
|
AspeedI2CState *),
|
|
|
|
DEFINE_PROP_END_OF_LIST(),
|
|
|
|
};
|
|
|
|
|
|
|
|
static void aspeed_i2c_bus_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
|
|
|
|
dc->desc = "Aspeed I2C Bus";
|
|
|
|
dc->realize = aspeed_i2c_bus_realize;
|
|
|
|
dc->reset = aspeed_i2c_bus_reset;
|
|
|
|
device_class_set_props(dc, aspeed_i2c_bus_properties);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo aspeed_i2c_bus_info = {
|
|
|
|
.name = TYPE_ASPEED_I2C_BUS,
|
|
|
|
.parent = TYPE_SYS_BUS_DEVICE,
|
|
|
|
.instance_size = sizeof(AspeedI2CBus),
|
|
|
|
.class_init = aspeed_i2c_bus_class_init,
|
|
|
|
};
|
|
|
|
|
2019-09-25 16:32:41 +02:00
|
|
|
static qemu_irq aspeed_2400_i2c_bus_get_irq(AspeedI2CBus *bus)
|
|
|
|
{
|
|
|
|
return bus->controller->irq;
|
|
|
|
}
|
|
|
|
|
2019-11-19 15:11:55 +01:00
|
|
|
static uint8_t *aspeed_2400_i2c_bus_pool_base(AspeedI2CBus *bus)
|
|
|
|
{
|
|
|
|
uint8_t *pool_page =
|
2022-06-13 14:05:48 +02:00
|
|
|
&bus->controller->pool[ARRAY_FIELD_EX32(bus->regs, I2CD_FUN_CTRL,
|
|
|
|
POOL_PAGE_SEL) * 0x100];
|
2019-11-19 15:11:55 +01:00
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
return &pool_page[ARRAY_FIELD_EX32(bus->regs, I2CD_POOL_CTRL, OFFSET)];
|
2019-11-19 15:11:55 +01:00
|
|
|
}
|
|
|
|
|
2019-09-25 16:32:40 +02:00
|
|
|
static void aspeed_2400_i2c_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_CLASS(klass);
|
|
|
|
|
|
|
|
dc->desc = "ASPEED 2400 I2C Controller";
|
|
|
|
|
|
|
|
aic->num_busses = 14;
|
|
|
|
aic->reg_size = 0x40;
|
|
|
|
aic->gap = 7;
|
2019-09-25 16:32:41 +02:00
|
|
|
aic->bus_get_irq = aspeed_2400_i2c_bus_get_irq;
|
2019-11-19 15:11:55 +01:00
|
|
|
aic->pool_size = 0x800;
|
|
|
|
aic->pool_base = 0x800;
|
|
|
|
aic->bus_pool_base = aspeed_2400_i2c_bus_pool_base;
|
2019-09-25 16:32:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo aspeed_2400_i2c_info = {
|
|
|
|
.name = TYPE_ASPEED_2400_I2C,
|
|
|
|
.parent = TYPE_ASPEED_I2C,
|
|
|
|
.class_init = aspeed_2400_i2c_class_init,
|
|
|
|
};
|
|
|
|
|
2019-09-25 16:32:41 +02:00
|
|
|
static qemu_irq aspeed_2500_i2c_bus_get_irq(AspeedI2CBus *bus)
|
|
|
|
{
|
|
|
|
return bus->controller->irq;
|
|
|
|
}
|
|
|
|
|
2019-11-19 15:11:55 +01:00
|
|
|
static uint8_t *aspeed_2500_i2c_bus_pool_base(AspeedI2CBus *bus)
|
|
|
|
{
|
|
|
|
return &bus->controller->pool[bus->id * 0x10];
|
|
|
|
}
|
|
|
|
|
2019-09-25 16:32:40 +02:00
|
|
|
static void aspeed_2500_i2c_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_CLASS(klass);
|
|
|
|
|
|
|
|
dc->desc = "ASPEED 2500 I2C Controller";
|
|
|
|
|
|
|
|
aic->num_busses = 14;
|
|
|
|
aic->reg_size = 0x40;
|
|
|
|
aic->gap = 7;
|
2019-09-25 16:32:41 +02:00
|
|
|
aic->bus_get_irq = aspeed_2500_i2c_bus_get_irq;
|
2019-11-19 15:11:55 +01:00
|
|
|
aic->pool_size = 0x100;
|
|
|
|
aic->pool_base = 0x200;
|
|
|
|
aic->bus_pool_base = aspeed_2500_i2c_bus_pool_base;
|
2019-11-19 15:11:56 +01:00
|
|
|
aic->check_sram = true;
|
2019-11-19 15:11:58 +01:00
|
|
|
aic->has_dma = true;
|
2019-09-25 16:32:40 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo aspeed_2500_i2c_info = {
|
|
|
|
.name = TYPE_ASPEED_2500_I2C,
|
|
|
|
.parent = TYPE_ASPEED_I2C,
|
|
|
|
.class_init = aspeed_2500_i2c_class_init,
|
2016-06-06 17:59:29 +02:00
|
|
|
};
|
|
|
|
|
2019-09-25 16:32:41 +02:00
|
|
|
static qemu_irq aspeed_2600_i2c_bus_get_irq(AspeedI2CBus *bus)
|
|
|
|
{
|
|
|
|
return bus->irq;
|
|
|
|
}
|
|
|
|
|
2019-11-19 15:11:55 +01:00
|
|
|
static uint8_t *aspeed_2600_i2c_bus_pool_base(AspeedI2CBus *bus)
|
|
|
|
{
|
|
|
|
return &bus->controller->pool[bus->id * 0x20];
|
|
|
|
}
|
|
|
|
|
2019-09-25 16:32:41 +02:00
|
|
|
static void aspeed_2600_i2c_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_CLASS(klass);
|
|
|
|
|
|
|
|
dc->desc = "ASPEED 2600 I2C Controller";
|
|
|
|
|
|
|
|
aic->num_busses = 16;
|
|
|
|
aic->reg_size = 0x80;
|
|
|
|
aic->gap = -1; /* no gap */
|
|
|
|
aic->bus_get_irq = aspeed_2600_i2c_bus_get_irq;
|
2019-11-19 15:11:55 +01:00
|
|
|
aic->pool_size = 0x200;
|
|
|
|
aic->pool_base = 0xC00;
|
|
|
|
aic->bus_pool_base = aspeed_2600_i2c_bus_pool_base;
|
2019-11-19 15:11:58 +01:00
|
|
|
aic->has_dma = true;
|
2019-09-25 16:32:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo aspeed_2600_i2c_info = {
|
|
|
|
.name = TYPE_ASPEED_2600_I2C,
|
|
|
|
.parent = TYPE_ASPEED_I2C,
|
|
|
|
.class_init = aspeed_2600_i2c_class_init,
|
|
|
|
};
|
|
|
|
|
2022-06-13 14:05:48 +02:00
|
|
|
static void aspeed_1030_i2c_class_init(ObjectClass *klass, void *data)
|
|
|
|
{
|
|
|
|
DeviceClass *dc = DEVICE_CLASS(klass);
|
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_CLASS(klass);
|
|
|
|
|
|
|
|
dc->desc = "ASPEED 1030 I2C Controller";
|
|
|
|
|
|
|
|
aic->num_busses = 14;
|
|
|
|
aic->reg_size = 0x80;
|
|
|
|
aic->gap = -1; /* no gap */
|
|
|
|
aic->bus_get_irq = aspeed_2600_i2c_bus_get_irq;
|
|
|
|
aic->pool_size = 0x200;
|
|
|
|
aic->pool_base = 0xC00;
|
|
|
|
aic->bus_pool_base = aspeed_2600_i2c_bus_pool_base;
|
|
|
|
aic->has_dma = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const TypeInfo aspeed_1030_i2c_info = {
|
|
|
|
.name = TYPE_ASPEED_1030_I2C,
|
|
|
|
.parent = TYPE_ASPEED_I2C,
|
|
|
|
.class_init = aspeed_1030_i2c_class_init,
|
|
|
|
};
|
|
|
|
|
2016-06-06 17:59:29 +02:00
|
|
|
static void aspeed_i2c_register_types(void)
|
|
|
|
{
|
2021-10-12 08:20:08 +02:00
|
|
|
type_register_static(&aspeed_i2c_bus_info);
|
2022-06-30 09:21:14 +02:00
|
|
|
type_register_static(&aspeed_i2c_bus_slave_info);
|
2016-06-06 17:59:29 +02:00
|
|
|
type_register_static(&aspeed_i2c_info);
|
2019-09-25 16:32:40 +02:00
|
|
|
type_register_static(&aspeed_2400_i2c_info);
|
|
|
|
type_register_static(&aspeed_2500_i2c_info);
|
2019-09-25 16:32:41 +02:00
|
|
|
type_register_static(&aspeed_2600_i2c_info);
|
2022-06-13 14:05:48 +02:00
|
|
|
type_register_static(&aspeed_1030_i2c_info);
|
2016-06-06 17:59:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
type_init(aspeed_i2c_register_types)
|
|
|
|
|
|
|
|
|
2020-07-06 00:41:50 +02:00
|
|
|
I2CBus *aspeed_i2c_get_bus(AspeedI2CState *s, int busnr)
|
2016-06-06 17:59:29 +02:00
|
|
|
{
|
2019-09-25 16:32:40 +02:00
|
|
|
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(s);
|
2016-06-06 17:59:29 +02:00
|
|
|
I2CBus *bus = NULL;
|
|
|
|
|
2019-09-25 16:32:40 +02:00
|
|
|
if (busnr >= 0 && busnr < aic->num_busses) {
|
2016-06-06 17:59:29 +02:00
|
|
|
bus = s->busses[busnr].bus;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bus;
|
|
|
|
}
|