159
case A_I2CS_INTR_CTRL:
160
case A_I2CS_DMA_LEN_STS:
161
case A_I2CS_INTR_STS:
162
+ case A_I2CC_VERSION_CTRL:
163
value = bus->regs[offset / sizeof(*bus->regs)];
164
break;
165
case A_I2CC_DMA_ADDR:
296
return 0;
297
}
298
299
+/*
300
+ * In AST2700 buffer mode the master DMA command bits (TX/RX_DMA_EN) and the
301
+ * DMA length registers are reused, but data is moved through the controller
302
+ * internal SRAM pool at the offset programmed in I2CM_DMA_TX/RX_ADDR instead
303
+ * of DRAM. FUNC_CFG_DMA_EN selects between the two (set = DRAM).
304
+ */
305
+static bool aspeed_i2c_bus_dma_to_pool(AspeedI2CBus *bus)
306
+{
307
+ return aspeed_i2c_is_new_mode(bus->controller) &&
308
+ !ARRAY_FIELD_EX32(bus->regs, I2CC_VERSION_CTRL, FUNC_CFG_DMA_EN);
309
+}
310
+
311
+static int aspeed_i2c_bus_send_dma_pool(AspeedI2CBus *bus)
312
+{
313
+ AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
314
+ uint32_t reg_dma_len = aspeed_i2c_bus_dma_len_offset(bus);
315
+ uint32_t reg_cmd = aspeed_i2c_bus_cmd_offset(bus);
316
+ uint32_t offset = bus->regs[R_I2CM_DMA_TX_ADDR];
317
+ uint8_t *pool_base = aic->bus_pool_base(bus);
318
+ int ret = -1;
319
+ int i;
320
+
321
+ ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, TX_LEN, 0);
322
+ for (i = 0; bus->regs[reg_dma_len] &&
323
+ offset + i < ASPEED_I2C_BUS_POOL_SIZE; i++) {
324
+ trace_aspeed_i2c_bus_send("BUFF", i + 1, bus->regs[reg_dma_len],
325
+ pool_base[offset + i]);
326
+ ret = i2c_send(bus->bus, pool_base[offset + i]);
327
+ bus->regs[reg_dma_len]--;
328
+ ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, TX_LEN, i + 1);
329
+ if (ret) {
330
+ break;
331
+ }
332
+ }
333
+ SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, TX_DMA_EN, 0);
334
+ return ret;
335
+}
336
+
337
+static void aspeed_i2c_bus_recv_dma_pool(AspeedI2CBus *bus)
338
+{
339
+ AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
340
+ uint32_t reg_dma_len = aspeed_i2c_bus_dma_len_offset(bus);
341
+ uint32_t reg_cmd = aspeed_i2c_bus_cmd_offset(bus);
342
+ uint32_t offset = bus->regs[R_I2CM_DMA_RX_ADDR];
343
+ uint8_t *pool_base = aic->bus_pool_base(bus);
344
+ int i;
345
+
346
+ ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, RX_LEN, 0);
347
+ for (i = 0; bus->regs[reg_dma_len] &&
348
+ offset + i < ASPEED_I2C_BUS_POOL_SIZE; i++) {
349
+ pool_base[offset + i] = i2c_recv(bus->bus);
350
+ trace_aspeed_i2c_bus_recv("BUFF", i + 1, bus->regs[reg_dma_len],
351
+ pool_base[offset + i]);
352
+ bus->regs[reg_dma_len]--;
353
+ ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, RX_LEN, i + 1);
354
+ }
355
+ SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, RX_DMA_EN, 0);
356
+}
357
+
358
static int aspeed_i2c_bus_send(AspeedI2CBus *bus)
359
{
360
AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller);
380
}
381
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, TX_BUFF_EN, 0);
382
} else if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_DMA_EN)) {
383
+ /* In buffer mode the DMA moves data through the pool, not DRAM */
384
+ if (aspeed_i2c_bus_dma_to_pool(bus)) {
385
+ return aspeed_i2c_bus_send_dma_pool(bus);
386
+ }
387
/* In new mode, clear how many bytes we TXed */
388
if (aspeed_i2c_is_new_mode(bus->controller)) {
389
ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, TX_LEN, 0);
449
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_pool_ctrl, RX_COUNT, i & 0xff);
450
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, RX_BUFF_EN, 0);
451
} else if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, RX_DMA_EN)) {
452
+ /* In buffer mode the DMA moves data through the pool, not DRAM */
453
+ if (aspeed_i2c_bus_dma_to_pool(bus)) {
454
+ aspeed_i2c_bus_recv_dma_pool(bus);
455
+ return;
456
+ }
457
/* In new mode, clear how many bytes we RXed */
458
if (aspeed_i2c_is_new_mode(bus->controller)) {
459
ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS, RX_LEN, 0);
923
I2CS_DMA_RX_ADDR_HI,
924
ADDR_HI);
925
break;
926
+ case A_I2CC_VERSION_CTRL:
927
+ bus->regs[R_I2CC_VERSION_CTRL] = value;
928
+ break;
929
default:
930
qemu_log_mask(LOG_GUEST_ERROR, "%s: Bad offset 0x%" HWADDR_PRIx "\n",
931
__func__, offset);
1569
memset(s->regs, 0, sizeof(s->regs));
1570
s->pending_intr_sts = 0;
1571
i2c_end_transfer(s->bus);
1572
+ /*
1573
+ * I2CC_VERSION_CTRL resets to all-ones. FUNC_CFG_DMA_EN is therefore set,
1574
+ * so master DMA targets DRAM unless the guest clears it to select buffer
1575
+ * mode. Guests unaware of buffer mode never touch this register and keep
1576
+ * doing DRAM DMA.
1577
+ */
1578
+ s->regs[R_I2CC_VERSION_CTRL] = 0xffffffff;
1579
}
1580
1581
static void aspeed_i2c_bus_realize(DeviceState *dev, Error **errp)