hw/i2c/aspeed: fix non-packet buffer and DMA transfer modes
Subsystems (2)
v2 cover hw/i2c/aspeed: fix non-packet buffer and DMA transfer modes
In non-packet mode, buffer and DMA modes are broken in the Aspeed I2C controller,
probably because no available driver currently uses them. This patch fixes them, so byte, buffer, and DMA transfer modes now work correctly for both register modes, old and new ones. Tests are provided to prevent possible regressions.
---
Changes in v2:
- Fix commits description format. Some of them are reordered and clarified.
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]
---
Timur Maksimov (6):
hw/i2c: add dummy device
hw/i2c/aspeed: fix BUSY status reading in new register mode hw/i2c/aspeed: fix I2CD_CMD register reading hw/i2c/aspeed: fix buffer transfer in non-packet mode hw/i2c/aspeed: fix DMA transfer in non-packet mode tests/qtest: Add cases for 32-bit Aspeed I2C controllers
hw/i2c/Kconfig | 5 + hw/i2c/aspeed_i2c.c | 23 +- hw/i2c/i2c-dummy-device.c | 168 +++++++++ hw/i2c/meson.build | 3 +- tests/qtest/aspeed_i2c-test.c | 836 ++++++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 + 6 files changed, 1029 insertions(+), 8 deletions(-)
---
base-commit: 9b77fa7a4fe86c80d1ff526769c61ada7d28666a
change-id: 20261025-aspeed-i2c-nonpkt-fix-89b852b5c84a
Signature · 1 line
Timur Maksimov <[email protected]>
PATCH v2 1/6 hw/i2c: add dummy device
Simple I2C device with QOM properties to access
transmit and receive buffers.
Can be used for testing or prototyping.
--- hw/i2c/Kconfig | 5 ++ hw/i2c/i2c-dummy-device.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++ hw/i2c/meson.build | 3 +- 3 files changed, 175 insertions(+), 1 deletion(-)
hw/i2c/Kconfig +5 -0
@@ -6,6 +6,11 @@ config I2C_DEVICES # to any board's i2c bus bool +config I2C_DUMMY_DEVICE + bool + default y if TEST_DEVICES + depends on I2C + config SMBUS bool select I2C
hw/i2c/i2c-dummy-device.c new file +168 -0
168 lines not on this page · raw message
hw/i2c/meson.build +2 -1
@@ -1,5 +1,5 @@ i2c_ss = ss.source_set() -i2c_ss.add(when: 'CONFIG_I2C', if_true: files('core.c')) +i2c_ss.add(when: 'CONFIG_I2C', if_true: files('core.c', 'i2c-dummy-device.c')) i2c_ss.add(when: 'CONFIG_SMBUS', if_true: files('smbus_slave.c', 'smbus_master.c')) i2c_ss.add(when: 'CONFIG_ACPI_SMBUS', if_true: files('pm_smbus.c')) i2c_ss.add(when: 'CONFIG_ACPI_ICH9', if_true: files('smbus_ich9.c'))
@@ -19,4 +19,5 @@ i2c_ss.add(when: 'CONFIG_PPC4XX', if_true: files('ppc4xx_i2c.c')) i2c_ss.add(when: 'CONFIG_PCA954X', if_true: files('i2c_mux_pca954x.c')) i2c_ss.add(when: 'CONFIG_PMBUS', if_true: files('pmbus_device.c')) i2c_ss.add(when: 'CONFIG_BCM2835_I2C', if_true: files('bcm2835_i2c.c')) +i2c_ss.add(when: 'CONFIG_I2C_DUMMY_DEVICE', if_true: files('i2c-dummy-device.c')) system_ss.add_all(when: 'CONFIG_I2C', if_true: i2c_ss)
Signature · 1 line
2.53.0
Re: [PATCH v2 1/6] hw/i2c: add dummy device
+ Corey for I2C feed back.
+ Markus for QOM
The brute-force solution to expose the contents of the device array with 128 properties has a slight AI smell. I find it ugly but I am human :) That said I don't know if there are better alternatives.
My approach would have been to use a string property :
object_property_add_str(obj, "tx",
i2c_dummy_device_get_tx, NULL);
object_property_add_str(obj, "rx",
i2c_dummy_device_get_rx,
i2c_dummy_device_set_rx);Any better ideas ?
Quoted 8 lines · Timur Maksimov
Simple I2C device with QOM properties to access
transmit and receive buffers.
Can be used for testing or prototyping.Signed-off-by Timur Maksimov <[email protected]>--- hw/i2c/Kconfig | 5 ++ hw/i2c/i2c-dummy-device.c | 168 ++++++++++++++++++++++++++++++++++++++++++++++
MAINTAINERS need updating.
Quoted 134 lines
hw/i2c/meson.build | 3 +- 3 files changed, 175 insertions(+), 1 deletion(-)hw/i2c/Kconfig +5
-0@@ -6,6 +6,11 @@ config I2C_DEVICES # to any board's i2c bus bool +config I2C_DUMMY_DEVICE + bool + default y if TEST_DEVICES + depends on I2C + config SMBUS bool select I2Chw/i2c/i2c-dummy-device.c new file +108
-0@@ -0,0 +1,168 @@ +/* +* QEMU I2C Dummy Device +* +* Copyright (c) 2026 Timur Maksimov <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "hw/i2c/i2c.h" +#include "hw/core/qdev-properties.h" +#include "migration/vmstate.h" + +#define TYPE_I2C_DUMMY_DEVICE "i2c-dummy-device" +OBJECT_DECLARE_SIMPLE_TYPE(I2CDummyDeviceState, I2C_DUMMY_DEVICE) + +#define I2C_DUMMY_ARRAY_SIZE 64 + +struct I2CDummyDeviceState { +I2CSlave parent_obj; + +uint8_t tx[I2C_DUMMY_ARRAY_SIZE ]; +uint8_t rx[I2C_DUMMY_ARRAY_SIZE ]; + +uint8_t tx_pos; +uint8_t rx_pos; +uint8_t event; +}; + +static void i2c_dummy_device_reset (DeviceState *dev) +{ +I2CDummyDeviceState *s =I2C_DUMMY_DEVICE (dev); + + s->tx_pos =0 ; + s->rx_pos =0 ; + s->event =I2C_FINISH ; +memset (s->tx,0 ,sizeof s->tx); +/* Don't reset rx as it is a readonly parameter for the model */ +} + +static int i2c_dummy_device_event (I2CSlave *i2c,enum i2c_event event) +{ +I2CDummyDeviceState *s =I2C_DUMMY_DEVICE (i2c); + +switch (event) { +case I2C_START_SEND : + s->tx_pos =0 ; +break ; + +case I2C_START_RECV : + s->rx_pos =0 ; +break ; + +default : +break ; + } + + s->event = event; +return 0 ; +} + +static int i2c_dummy_device_send (I2CSlave *i2c,uint8_t data) +{ +I2CDummyDeviceState *s =I2C_DUMMY_DEVICE (i2c); + +if (s->tx_pos >=I2C_DUMMY_ARRAY_SIZE ) { +/* +* The TX buffer is full. NACK the byte. +*/ +return 1 ; + } + +if (s->event ==I2C_START_SEND ) { + s->tx[s->tx_pos++] = data; + } + +return 0 ; +} + +static uint8_t i2c_dummy_device_recv (I2CSlave *i2c) +{ +I2CDummyDeviceState *s =I2C_DUMMY_DEVICE (i2c); + +if (s->rx_pos >=I2C_DUMMY_ARRAY_SIZE || s->event !=I2C_START_RECV ) { +/* +* There is no more data available. +*/ +return 0xff ; + } + +return s->rx[s->rx_pos++]; +} + +static void i2c_dummy_device_init (Object *obj) +{ +I2CDummyDeviceState *s =I2C_DUMMY_DEVICE (obj); +for (int i =0 ; i <I2C_DUMMY_ARRAY_SIZE ; i++) { + g_autofree char *name = g_strdup_printf("tx[%d]", i); + +object_property_add_uint8_ptr ( + obj, name, &s->tx[i], +OBJ_PROP_FLAG_READWRITE ); + } + +for (int i =0 ; i <I2C_DUMMY_ARRAY_SIZE ; i++) { + g_autofree char *name = g_strdup_printf("rx[%d]", i); + + object_property_add_uint8_ptr(
hw/i2c/i2c-dummy-device.c line 119
Quoted 10 lines
hw/i2c/i2c-dummy-device.c new file +10
-0+ obj, name, &s->rx[i], + OBJ_PROP_FLAG_READWRITE); + } + +object_property_add_uint8_ptr ( + obj,"tx-pos" , &s->tx_pos, +OBJ_PROP_FLAG_READWRITE ); +object_property_add_uint8_ptr ( + obj,"rx-pos" , &s->rx_pos, +OBJ_PROP_FLAG_READWRITE );
alignment could be improved.
Quoted 20 lines
hw/i2c/i2c-dummy-device.c new file +20
-0+} + +static const VMStateDescription vmstate_i2c_dummy_device = { + .name =TYPE_I2C_DUMMY_DEVICE , + .version_id =1 , + .minimum_version_id =1 , + + .fields = (const VMStateField []) { +VMSTATE_I2C_SLAVE (parent_obj, I2CDummyDeviceState), + +VMSTATE_UINT8_ARRAY (tx, I2CDummyDeviceState, +I2C_DUMMY_ARRAY_SIZE ), + +VMSTATE_UINT8_ARRAY (rx, I2CDummyDeviceState, +I2C_DUMMY_ARRAY_SIZE ), + +VMSTATE_UINT8 (tx_pos, I2CDummyDeviceState), +VMSTATE_UINT8 (rx_pos, I2CDummyDeviceState), +VMSTATE_UINT8 (event, I2CDummyDeviceState), +
hw/i2c/i2c-dummy-device.c line 149
Quoted 10 lines
hw/i2c/i2c-dummy-device.c new file +10
-0+VMSTATE_END_OF_LIST () + }, +}; + +static void i2c_dummy_device_class_init (ObjectClass *klass,const void *data) +{ +DeviceClass *dc =DEVICE_CLASS (klass); +I2CSlaveClass *isc =I2C_SLAVE_CLASS (klass); + +device_class_set_legacy_reset (dc, i2c_dummy_device_reset);
Please use Resettable phases for new devices.
Quoted 24 lines
hw/i2c/i2c-dummy-device.c new file +19
-0+ + dc->vmsd = &vmstate_i2c_dummy_device; + + isc->event = i2c_dummy_device_event; + isc->send = i2c_dummy_device_send; + isc->recv = i2c_dummy_device_recv; +} + +static const TypeInfo i2c_dummy_device_info[] = { + { + .name =TYPE_I2C_DUMMY_DEVICE , + .parent =TYPE_I2C_SLAVE , + .instance_size =sizeof (I2CDummyDeviceState), + .instance_init = i2c_dummy_device_init, + .class_init = i2c_dummy_device_class_init, + } +}; + +DEFINE_TYPES (i2c_dummy_device_info)hw/i2c/meson.build +0
-0
hw/i2c/meson.build line 2
Quoted 3 lines
hw/i2c/meson.build +1
-1@@ -1,5 +1,5 @@ i2c_ss = ss.source_set() -i2c_ss.add(when: 'CONFIG_I2C', if_true: files('core.c')) +i2c_ss.add(when: 'CONFIG_I2C', if_true: files('core.c', 'i2c-dummy-device.c'))
Please drop this change.
Config I2C_DUMMY_DEVICE which defaults to y when TEST_DEVICES is set should be enough.
hw/i2c/meson.build i2c_ss.add(when: 'CONFIG_PPC4XX', if_true: files('ppc4xx_i2c.c')) · line 23
Quoted 10 lines
hw/i2c/meson.build +1
-0i2c_ss.add(when: 'CONFIG_SMBUS', if_true: files('smbus_slave.c', 'smbus_master.c')) i2c_ss.add(when: 'CONFIG_ACPI_SMBUS', if_true: files('pm_smbus.c')) i2c_ss.add(when: 'CONFIG_ACPI_ICH9', if_true: files('smbus_ich9.c'))@@ -19,4 +19,5 @@ i2c_ss.add(when: 'CONFIG_PPC4XX', if_true: files('ppc4xx_i2c.c')) i2c_ss.add(when: 'CONFIG_PCA954X', if_true: files('i2c_mux_pca954x.c')) i2c_ss.add(when: 'CONFIG_PMBUS', if_true: files('pmbus_device.c')) i2c_ss.add(when: 'CONFIG_BCM2835_I2C', if_true: files('bcm2835_i2c.c')) +i2c_ss.add(when: 'CONFIG_I2C_DUMMY_DEVICE', if_true: files('i2c-dummy-device.c')) system_ss.add_all(when: 'CONFIG_I2C', if_true: i2c_ss)
Thanks,
C.
Re: [PATCH v2 1/6] hw/i2c: add dummy device
Quoted 7 lines · Cédric Le Goater
+ Corey for I2C feed back.
+ Markus for QOM
The brute-force solution to expose the contents of the device array with 128 properties has a slight AI smell. I find it ugly but I am human :)
Timur, have you read docs/devel/code-provenance.rst section "Use of AI-generated content"?
Quoted 9 lines
That said I don't know if there are better alternatives.
My approach would have been to use a string property :object_property_add_str(obj, "tx", i2c_dummy_device_get_tx, NULL); object_property_add_str(obj, "rx", i2c_dummy_device_get_rx, i2c_dummy_device_set_rx);Any better ideas ?
I believe you're talking about this function:
[...]
Quoted 20 lines
Quoted 20 lines
hw/i2c/i2c-dummy-device.c new file +19
-0+static void i2c_dummy_device_init (Object *obj) +{ +I2CDummyDeviceState *s =I2C_DUMMY_DEVICE (obj); +for (int i =0 ; i <I2C_DUMMY_ARRAY_SIZE ; i++) { + g_autofree char *name = g_strdup_printf("tx[%d]", i); + +object_property_add_uint8_ptr ( + obj, name, &s->tx[i], +OBJ_PROP_FLAG_READWRITE ); + } + +for (int i =0 ; i <I2C_DUMMY_ARRAY_SIZE ; i++) { + g_autofree char *name = g_strdup_printf("rx[%d]", i); + +object_property_add_uint8_ptr ( + obj, name, &s->rx[i], +OBJ_PROP_FLAG_READWRITE ); + } +
Quoted 8 lines
hw/i2c/i2c-dummy-device.c line 119
Quoted 6 lines
hw/i2c/i2c-dummy-device.c new file +6
-0+object_property_add_uint8_ptr ( + obj,"tx-pos" , &s->tx_pos, +OBJ_PROP_FLAG_READWRITE ); +object_property_add_uint8_ptr ( + obj,"rx-pos" , &s->rx_pos, +OBJ_PROP_FLAG_READWRITE );alignment could be improved.
Yes, this style is unusual in QEMU, and should therefore be avoided.
Quoted 1 line
Quoted 1 line
+}
The function adds properties "tx-pos", "tx[0]", ... "tx[63]", and same for rx.
The commit message tells us this is a "Simple I2C device with QOM properties to access transmit and receive buffers [...] for testing or prototyping." It doesn't tell us how it could be used, and I can't see any documentation, either. So let's start right there: please show us how this device could be used. This should help me understand what the properties are for. Only then can I advise on proper QOM usage.
[...]
Re: [PATCH v2 1/6] hw/i2c: add dummy device
Quoted 8 lines
The commit message tells us this is a "Simple I2C device with QOM properties to access transmit and receive buffers [...] for testing or prototyping." It doesn't tell us how it could be used, and I can't see any documentation, either. So let's start right there: please show us how this device could be used. This should help me understand what the properties are for. Only then can I advise on proper QOM usage.
[...]
sorry, I should have added the link to the test case where these properties are used :
https://lore.kernel.org/qemu-devel/[email protected]/
Thanks,
C.
Re: [PATCH v2 1/6] hw/i2c: add dummy device
Quoted 8 lines · Cédric Le Goater
Quoted 7 lines
The commit message tells us this is a "Simple I2C device with QOM properties to access transmit and receive buffers [...] for testing or prototyping." It doesn't tell us how it could be used, and I can't see any documentation, either. So let's start right there: please show us how this device could be used. This should help me understand what the properties are for. Only then can I advise on proper QOM usage. [...]
Quoted 4 lines
sorry, I should have added the link to the test case where these properties are used :
Uh, that's a bit much for me to read. Timur, please answer my question.
Re: [PATCH v2 1/6] hw/i2c: add dummy device
In reply to Markus ArmbrusterHi, thanks for the review.
It was my decision to use such API, I thought it would be okay for a test device. I don't think there is a way to expose integer array as a single QOM property.
Actually, we can go without this model. I suppose I will rewrite tests so they don't use it.
Quoted 76 lines · Markus Armbruster
Quoted 7 lines · Cédric Le Goater
+ Corey for I2C feed back.
+ Markus for QOM
The brute-force solution to expose the contents of the device array with 128 properties has a slight AI smell. I find it ugly but I am human :)
Timur, have you read
docs/devel/code-provenance.rstsection "Use of AI-generated content"?Quoted 9 lines
That said I don't know if there are better alternatives. My approach would have been to use a string property :
object_property_add_str(obj, "tx", i2c_dummy_device_get_tx, NULL);object_property_add_str(obj, "rx", i2c_dummy_device_get_rx, i2c_dummy_device_set_rx); Any better ideas ?I believe you're talking about this function:
[...]
Quoted 20 lines
Quoted 20 lines
hw/i2c/i2c-dummy-device.c new file +19
-0+static void i2c_dummy_device_init (Object *obj) +{ + I2CDummyDeviceState *s = I2C_DUMMY_DEVICE(obj); + for (int i = 0; i < I2C_DUMMY_ARRAY_SIZE; i++) { + g_autofree char *name = g_strdup_printf("tx[%d]", i); + + object_property_add_uint8_ptr( + obj, name, &s->tx[i], + OBJ_PROP_FLAG_READWRITE); + } + + for (int i = 0; i < I2C_DUMMY_ARRAY_SIZE; i++) { + g_autofree char *name = g_strdup_printf("rx[%d]", i); + + object_property_add_uint8_ptr( + obj, name, &s->rx[i], + OBJ_PROP_FLAG_READWRITE); + } +Quoted 8 lines
Quoted 6 lines
+ object_property_add_uint8_ptr(
+ obj, "tx-pos",&s->tx_pos,
+OBJ_PROP_FLAG_READWRITE);
+ object_property_add_uint8_ptr(
+ obj, "rx-pos",&s->rx_pos,
+OBJ_PROP_FLAG_READWRITE);alignment could be improved.
Yes, this style is unusual in QEMU, and should therefore be avoided.
Quoted 1 line
Quoted 1 line
+}
The function adds properties "tx-pos", "tx[0]", ... "tx[63]", and same
for rx.The commit message tells us this is a "Simple I2C device with QOM properties to access transmit and receive buffers [...] for testing or
prototyping." It doesn't tell us how it could be used, and I can't see
any documentation, either. So let's start right there: please show us
how this device could be used. This should help me understand what the
properties are for. Only then can I advise on proper QOM usage.[...]
Re: [PATCH v2 1/6] hw/i2c: add dummy device
Quoted 5 lines · Timur Maksimov
Hi, thanks for the review.
It was my decision to use such API, I thought it would be okay for a test device. I don't think there is a way to expose integer array as a single QOM property.
There are ways, but I need to know what you're trying to accomplish to be able to provide guidance.
Quoted 2 lines
Actually, we can go without this model. I suppose I will rewrite tests so they don't use it.
You haven't answered my question on code-provenance.rst.
Quoted 15 lines · Markus Armbruster
Quoted 14 lines
Quoted 7 lines · Cédric Le Goater
+ Corey for I2C feed back.
+ Markus for QOM
The brute-force solution to expose the contents of the device array with 128 properties has a slight AI smell. I find it ugly but I am human :)
Timur, have you read
docs/devel/code-provenance.rstsection "Use of AI-generated content"?Quoted 1 line
That said I don't know if there are better alternatives.
[...]
Re: [PATCH v2 1/6] hw/i2c: add dummy device
Hi, Markus
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Timur Maksimov
Hi, thanks for the review.
It was my decision to use such API, I thought it would be okay for a
test device. I don't think there is a way to expose integer array as a
single QOM property.
Quoted 3 lines
There are ways, but I need to know what you're trying to accomplish to
be able to provide guidance.
We need to access the transfer buffer array with QOM. Actually, I have a few ideas on how to do this without cluttering the QOM with properties, such as using a FIFO interface.
Quoted 20 lines
Quoted 4 lines
Actually, we can go without this model. I suppose I will rewrite tests
so they don't use it.You haven't answered my question on
code-provenance.rst.Quoted 13 lines · Markus Armbruster
Quoted 12 lines
Quoted 9 lines · Cédric Le Goater
+ Corey for I2C feed back.
+ Markus for QOM
The brute-force solution to expose the contents of the device array
with 128 properties has a slight AI smell. I find it ugly but I am
human :)
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Timur, have you read
docs/devel/code-provenance.rstsection "Use of
AI-generated content"?Quoted 2 lines
That said I don't know if there are better alternatives.
[...]
Sorry. Yes, I have read it. This is solely my work, no AI was used to write it.
I also have a question about MAINTAINERS file. If we keep this device, where should I put this file?
Re: [PATCH v2 1/6] hw/i2c: add dummy device
Quoted 47 lines · Timur Maksimov
Hi, Markus
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Timur Maksimov
Hi, thanks for the review.
It was my decision to use such API, I thought it would be okay for a
test device. I don't think there is a way to expose integer array as a
single QOM property.Quoted 3 lines
There are ways, but I need to know what you're trying to accomplish to
be able to provide guidance.We need to access the transfer buffer array with QOM. Actually, I have a few ideas on how to do this without cluttering the QOM with properties, such as using a FIFO interface.
Quoted 27 lines
Quoted 4 lines
Actually, we can go without this model. I suppose I will rewrite tests
so they don't use it.You haven't answered my question on
code-provenance.rst.Quoted 19 lines · Markus Armbruster
Quoted 18 lines
Quoted 9 lines · Cédric Le Goater
+ Corey for I2C feed back.
+ Markus for QOM
The brute-force solution to expose the contents of the device array
with 128 properties has a slight AI smell. I find it ugly but I am
human :)Timur, have you read
docs/devel/code-provenance.rstsection "Use of
AI-generated content"?Quoted 2 lines
That said I don't know if there are better
alternatives.
Quoted 7 lines
Quoted 1 line
[...]
Sorry. Yes, I have read it. This is solely my work, no AI was used to write it.
I also have a question about
MAINTAINERSfile. If we keep this device, where should I put this file?
You can put it under Aspeed for now, since it will be only used by Aspeed machines for tests. If it grows, I guess we should move it under "I2C and SMBus" if Corey agrees.
Thanks,
C.
Re: [PATCH v2 1/6] hw/i2c: add dummy device
Quoted 53 lines · Cédric Le Goater
Quoted 52 lines · Timur Maksimov
Hi, Markus
Quoted 10 lines · Markus Armbruster
Quoted 7 lines · Timur Maksimov
Hi, thanks for the review.
It was my decision to use such API, I thought it would be okay for a
test device. I don't think there is a way to expose integer array as a
single QOM property.Quoted 3 lines
There are ways, but I need to know what you're trying to accomplish to
be able to provide guidance.We need to access the transfer buffer array with QOM. Actually, I have a few ideas on how to do this without cluttering the QOM with properties, such as using a FIFO interface.
Quoted 20 lines
Quoted 4 lines
Actually, we can go without this model. I suppose I will rewrite tests
so they don't use it.You haven't answered my question on
code-provenance.rst.Quoted 13 lines · Markus Armbruster
Quoted 12 lines
Quoted 9 lines · Cédric Le Goater
+ Corey for I2C feed back.
+ Markus for QOM
The brute-force solution to expose the contents of the device array
with 128 properties has a slight AI smell. I find it ugly but I am
human :)Quoted 8 lines
Quoted 6 lines
Quoted 6 lines
Timur, have you read
docs/devel/code-provenance.rstsection "Use of
AI-generated content"?Quoted 2 lines
That said I don't know if there are better
alternatives.[...]
Sorry. Yes, I have read it. This is solely my work, no AI was used to write it.
Quoted 6 lines
Quoted 2 lines
I also have a question about
MAINTAINERSfile. If we keep this device, where should I put this file?You can put it under Aspeed for now, since it will be only used by Aspeed machines for tests. If it grows, I guess we should move it under "I2C and SMBus" if Corey agrees.
This seems pretty generic, so I think it makes more sense under the I2C directory. But I'm fine either way.
-corey
Quoted 4 lines
Thanks,
C.
Re: [PATCH v2 1/6] hw/i2c: add dummy device
Quoted 10 lines
Quoted 7 lines
Quoted 3 lines
I also have a question about
MAINTAINERSfile. If we keep this device, where should I put this file?You can put it under Aspeed for now, since it will be only used by Aspeed machines for tests. If it grows, I guess we should move it under "I2C and SMBus" if Corey agrees.
This seems pretty generic, so I think it makes more sense under the I2C directory. But I'm fine either way.
Under the I2C directory then. Fine with me. There is nothing specific to aspeed about it.
Thanks,
C.
Re: [PATCH v2 1/6] hw/i2c: add dummy device
Quoted 8 lines · Cédric Le Goater
Quoted 8 lines
Quoted 7 lines
Quoted 3 lines
I also have a question about
MAINTAINERSfile. If we keep this device, where should I put this file?You can put it under Aspeed for now, since it will be only used by Aspeed machines for tests. If it grows, I guess we should move it under "I2C and SMBus" if Corey agrees.
Quoted 5 lines
Quoted 2 lines
This seems pretty generic, so I think it makes more sense under the I2C directory. But I'm fine either way.
Under the I2C directory then. Fine with me. There is nothing specific to aspeed about it.
Sounds good. The change seems ok. I'll wait for the changes based on comments.
-corey
Quoted 5 lines
Thanks,
C.
PATCH v2 2/6 hw/i2c/aspeed: fix BUSY status reading in new register mode
In reply to Timur MaksimovIn new register mode, BUS_BUSY_STS is bit 16 of I2CC_MS_TXRX_BYTE_BUF; bit 16 of I2CM_CMD is PKT_OP_EN. Report the bus busy state in the correct register.
--- hw/i2c/aspeed_i2c.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
hw/i2c/aspeed_i2c.c +3 -2
@@ -146,7 +146,7 @@ static uint64_t aspeed_i2c_bus_new_read(AspeedI2CBus *bus, hwaddr offset,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_CMD :case A_I2CM_DMA_LEN :case A_I2CM_DMA_TX_ADDR :case A_I2CM_DMA_RX_ADDR :
@@ -166,7 +166,8 @@ static uint64_t aspeed_i2c_bus_new_read(AspeedI2CBus *bus, hwaddr offset,case A_I2CC_DMA_ADDR : value =extract64 (bus->dma_dram_offset,0 ,32 );break ; -case A_I2CM_CMD : +case A_I2CC_MS_TXRX_BYTE_BUF : + value = bus->regs[offset /sizeof (*bus->regs)]; value =SHARED_FIELD_DP32 (value,BUS_BUSY_STS ,i2c_bus_busy (bus->bus));break ;case A_I2CM_DMA_TX_ADDR_HI :
Signature · 1 line
2.53.0
Re: [PATCH v2 2/6] hw/i2c/aspeed: fix BUSY status reading in new register mode
Quoted 5 lines · Timur Maksimov
In new register mode,
BUS_BUSY_STSis bit 16 ofI2CC_MS_TXRX_BYTE_BUF; bit 16 ofI2CM_CMDisPKT_OP_EN. Report the bus busy state in the correct register.Signed-off-by Timur Maksimov <[email protected]>
Could you provide a Fixes tag please ?
Thanks,
C.
Quoted 28 lines
--- hw/i2c/aspeed_i2c.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/i2c/aspeed_i2c.c +3
-2@@ -146,7 +146,7 @@ static uint64_t aspeed_i2c_bus_new_read(AspeedI2CBus *bus, hwaddr offset,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_CMD :case A_I2CM_DMA_LEN :case A_I2CM_DMA_TX_ADDR :case A_I2CM_DMA_RX_ADDR :@@ -166,7 +166,8 @@ static uint64_t aspeed_i2c_bus_new_read(AspeedI2CBus *bus, hwaddr offset,case A_I2CC_DMA_ADDR : value =extract64 (bus->dma_dram_offset,0 ,32 );break ; -case A_I2CM_CMD : +case A_I2CC_MS_TXRX_BYTE_BUF : + value = bus->regs[offset /sizeof (*bus->regs)]; value =SHARED_FIELD_DP32 (value,BUS_BUSY_STS ,i2c_bus_busy (bus->bus));break ;case A_I2CM_DMA_TX_ADDR_HI :
Re: [PATCH v2 2/6] hw/i2c/aspeed: fix BUSY status reading in new register mode
In reply to Timur MaksimovQuoted 3 lines · Timur Maksimov
In new register mode,
BUS_BUSY_STSis bit 16 ofI2CC_MS_TXRX_BYTE_BUF; bit 16 ofI2CM_CMDisPKT_OP_EN. Report the bus busy state in the correct register.
Quoted 29 lines
Signed-off-by Timur Maksimov <[email protected]>--- hw/i2c/aspeed_i2c.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/i2c/aspeed_i2c.c +3
-2@@ -146,7 +146,7 @@ static uint64_t aspeed_i2c_bus_new_read(AspeedI2CBus *bus, hwaddr offset,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_CMD :case A_I2CM_DMA_LEN :case A_I2CM_DMA_TX_ADDR :case A_I2CM_DMA_RX_ADDR :@@ -166,7 +166,8 @@ static uint64_t aspeed_i2c_bus_new_read(AspeedI2CBus *bus, hwaddr offset,case A_I2CC_DMA_ADDR : value =extract64 (bus->dma_dram_offset,0 ,32 );break ; -case A_I2CM_CMD : +case A_I2CC_MS_TXRX_BYTE_BUF : + value = bus->regs[offset /sizeof (*bus->regs)]; value =SHARED_FIELD_DP32 (value,BUS_BUSY_STS ,i2c_bus_busy (bus->bus));break ;case A_I2CM_DMA_TX_ADDR_HI :
RE: [PATCH v2 2/6] hw/i2c/aspeed: fix BUSY status reading in new register mode
In reply to Timur MaksimovQuoted 39 lines
Subject: [PATCH v2 2/6] hw/i2c/aspeed: fix BUSY status reading in new register mode
In new register mode,
BUS_BUSY_STSis bit 16 ofI2CC_MS_TXRX_BYTE_BUF; bit 16 ofI2CM_CMDisPKT_OP_EN. Report the bus busy state in the correct register.Signed-off-by Timur Maksimov <[email protected]>--- hw/i2c/aspeed_i2c.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)hw/i2c/aspeed_i2c.c index renamed from hw/i2c/aspeed_i2c.c +0
-0
0bc4bb6fbe..fb6d19c37b100644hw/i2c/aspeed_i2c.c +1
-1@@ -146,7 +146,7 @@ static uint64_t aspeed_i2c_bus_new_read(AspeedI2CBus *bus, hwaddr offset, 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_CMD: case A_I2CM_DMA_LEN: case A_I2CM_DMA_TX_ADDR:case
A_I2CM_DMA_RX_ADDR:hw/i2c/aspeed_i2c.c +2
-1@@ -166,7 +166,8 @@ static uint64_t aspeed_i2c_bus_new_read(AspeedI2CBus *bus, hwaddr offset, case A_I2CC_DMA_ADDR: value = extract64(bus->dma_dram_offset, 0, 32);break ; -case A_I2CM_CMD : +case A_I2CC_MS_TXRX_BYTE_BUF : + value = bus->regs[offset /sizeof (*bus->regs)]; value =SHARED_FIELD_DP32 (value,BUS_BUSY_STS ,i2c_bus_busy (bus->bus));break; case A_I2CM_DMA_TX_ADDR_HI:
Quoted 2 lines
--
2.53.0
Thanks,
Jamin
PATCH v2 3/6 hw/i2c/aspeed: fix I2CD_CMD register reading
In reply to Timur MaksimovThe I2CD_CMD register now returns a valid value in old register mode.
--- hw/i2c/aspeed_i2c.c | 1 + 1 file changed, 1 insertion(+)
hw/i2c/aspeed_i2c.c +1 -0
@@ -108,6 +108,7 @@ static uint64_t aspeed_i2c_bus_old_read(AspeedI2CBus *bus, hwaddr offset, value = bus->regs[offset /sizeof (*bus->regs)];break ;case A_I2CD_CMD : + value = bus->regs[offset /sizeof (*bus->regs)]; value =SHARED_FIELD_DP32 (value,BUS_BUSY_STS ,i2c_bus_busy (bus->bus));break ;case A_I2CD_DMA_ADDR :
Signature · 1 line
2.53.0
RE: [PATCH v2 3/6] hw/i2c/aspeed: fix I2CD_CMD register reading
Quoted 26 lines
Subject: [PATCH v2 3/6] hw/i2c/aspeed: fix
I2CD_CMDregister readingThe
I2CD_CMDregister now returns a valid value in old register mode.Fixes c2c5beec42bf ("hw/i2c/aspeed_i2c: Fix out-of-bounds read in I2C MMIOhandlers")
Signed-off-by Timur Maksimov <[email protected]>--- hw/i2c/aspeed_i2c.c | 1 + 1 file changed, 1 insertion(+)hw/i2c/aspeed_i2c.c index renamed from hw/i2c/aspeed_i2c.c +0
-0
fb6d19c37b..ff6ef6d23a100644hw/i2c/aspeed_i2c.c +1
-0@@ -108,6 +108,7 @@ static uint64_t aspeed_i2c_bus_old_read(AspeedI2CBus *bus, hwaddr offset, value = bus->regs[offset / sizeof(*bus->regs)];break ;case A_I2CD_CMD : + value = bus->regs[offset /sizeof (*bus->regs)]; value =SHARED_FIELD_DP32 (value,BUS_BUSY_STS ,i2c_bus_busy (bus->bus));break; case A_I2CD_DMA_ADDR:
Quoted 2 lines
--
2.53.0
Thanks,
Jamin
PATCH v2 4/6 hw/i2c/aspeed: fix buffer transfer in non-packet mode
In reply to Timur MaksimovIn non-packet mode, the first byte of the tx buffer pool contains a device address, so avoid sending it as a data byte.
--- hw/i2c/aspeed_i2c.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)
hw/i2c/aspeed_i2c.c +7 -4
@@ -382,7 +382,7 @@ static void aspeed_i2c_bus_recv_dma_pool(AspeedI2CBus *bus)SHARED_ARRAY_FIELD_DP32 (bus->regs, reg_cmd,RX_DMA_EN ,0 ); } -static int aspeed_i2c_bus_send (AspeedI2CBus *bus) +static int aspeed_i2c_bus_send (AspeedI2CBus *bus,bool send_addr) {AspeedI2CClass *aic =ASPEED_I2C_GET_CLASS (bus->controller);int ret =-1 ;
@@ -391,11 +391,12 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *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); +uint8_t pool_offset = send_addr ?1 :0 ;int pool_tx_count =SHARED_ARRAY_FIELD_EX32 (bus->regs, reg_pool_ctrl,TX_COUNT ) +1 ;if (SHARED_ARRAY_FIELD_EX32 (bus->regs, reg_cmd,TX_BUFF_EN )) { -for (i =0 ; i < pool_tx_count; i++) { +for (i = pool_offset; i < pool_tx_count; i++) {uint8_t *pool_base = aic->bus_pool_base (bus); trace_aspeed_i2c_bus_send("BUF", i + 1, pool_tx_count,
@@ -633,6 +634,7 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value)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_dma_len =aspeed_i2c_bus_dma_len_offset (bus); +bool start_cmd =SHARED_ARRAY_FIELD_EX32 (bus->regs, reg_cmd,M_START_CMD );if (!aspeed_i2c_check_sram (bus)) {return ;
@@ -642,7 +644,7 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value)aspeed_i2c_bus_cmd_dump (bus); } -if (SHARED_ARRAY_FIELD_EX32 (bus->regs, reg_cmd,M_START_CMD )) { +if (start_cmd) {uint8_t state =aspeed_i2c_get_state (bus) &I2CD_MACTIVE ?I2CD_MSTARTR :I2CD_MSTART ;uint8_t addr;
@@ -686,7 +688,8 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value)if (SHARED_ARRAY_FIELD_EX32 (bus->regs, reg_cmd,M_TX_CMD )) {aspeed_i2c_set_state (bus,I2CD_MTXD ); -if (aspeed_i2c_bus_send (bus)) { +if (aspeed_i2c_bus_send (bus, start_cmd && + !aspeed_i2c_bus_pkt_mode_en (bus))) {SHARED_ARRAY_FIELD_DP32 (bus->regs, reg_intr_sts,TX_NAK ,1 );i2c_end_transfer (bus->bus); }else {
Signature · 1 line
2.53.0
RE: [PATCH v2 4/6] hw/i2c/aspeed: fix buffer transfer in non-packet mode
Hi Timur,
As far as I can see, no ASPEED Linux driver uses non-packet buffer or DMA mode for master transfers:
- i2c-aspeed.c (old register mode) only uses byte mode; the address is always written to the byte buffer register before START.
- i2c-ast2600.c in the ASPEED SDK kernel (new register mode) sets PKT_EN for every master transfer, and the address comes from PKT_ADDR.
Have you verified this behavior on real hardware? Which firmware are you running that uses non-packet buffer/DMA mode?
Thanks,
Jamin
Quoted 77 lines
Subject: [PATCH v2 4/6] hw/i2c/aspeed: fix buffer transfer in non-packet mode
In non-packet mode, the first byte of the tx buffer pool contains a device address, so avoid sending it as a data byte.
Fixes 961faf3ddbd8 ("hw/i2c/aspeed: Fix TXBUF transmission start positionerror")
Signed-off-by Timur Maksimov <[email protected]>--- hw/i2c/aspeed_i2c.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-)hw/i2c/aspeed_i2c.c index renamed from hw/i2c/aspeed_i2c.c +0
-0
ff6ef6d23a..510758fb7a100644hw/i2c/aspeed_i2c.c +3
-2@@ -382,7 +382,7 @@ static void aspeed_i2c_bus_recv_dma_pool(AspeedI2CBus *bus)SHARED_ARRAY_FIELD_DP32 (bus->regs, reg_cmd,RX_DMA_EN ,0 ); } -static int aspeed_i2c_bus_send (AspeedI2CBus *bus) +static int aspeed_i2c_bus_send (AspeedI2CBus *bus,bool send_addr) {AspeedI2CClass *aic =ASPEED_I2C_GET_CLASS (bus->controller);int ret =-1 ;@@ -391,11 +391,12 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *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); +uint8_t pool_offset = send_addr ?1 :0 ;int pool_tx_count =SHARED_ARRAY_FIELD_EX32 (bus->regs, reg_pool_ctrl,TX_COUNT ) +1 ;if (SHARED_ARRAY_FIELD_EX32 (bus->regs, reg_cmd,TX_BUFF_EN )) { -for (i =0 ; i < pool_tx_count; i++) { +for (i = pool_offset; i < pool_tx_count; i++) {uint8_t *pool_base = aic->bus_pool_base (bus);trace_aspeed_i2c_bus_send("BUF", i + 1, pool_tx_count, @@ -633,6 +634,7 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value) 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_dma_len = aspeed_i2c_bus_dma_len_offset(bus);hw/i2c/aspeed_i2c.c +3
-1+bool start_cmd =SHARED_ARRAY_FIELD_EX32 (bus->regs, reg_cmd, +M_START_CMD );if (!aspeed_i2c_check_sram (bus)) {return ;@@ -642,7 +644,7 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value)aspeed_i2c_bus_cmd_dump (bus); } -if (SHARED_ARRAY_FIELD_EX32 (bus->regs, reg_cmd,M_START_CMD )) { +if (start_cmd) {uint8_t state =aspeed_i2c_get_state (bus) &I2CD_MACTIVE ?I2CD_MSTARTR :I2CD_MSTART ;uint8_t addr;hw/i2c/aspeed_i2c.c +3
-1@@ -686,7 +688,8 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value)if (SHARED_ARRAY_FIELD_EX32 (bus->regs, reg_cmd,M_TX_CMD )) {aspeed_i2c_set_state (bus,I2CD_MTXD ); -if (aspeed_i2c_bus_send (bus)) { +if (aspeed_i2c_bus_send (bus, start_cmd && + !aspeed_i2c_bus_pkt_mode_en (bus))) + { SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, TX_NAK,1); i2c_end_transfer(bus->bus); } else {--
2.53.0
Re: [PATCH v2 4/6] hw/i2c/aspeed: fix buffer transfer in non-packet mode
Hi Jamin, you are right; no driver uses those modes, and I can't verify their work at the moment.
Do you suppose, that they don't work? Are there issues with them? We can exclude them from tests, but buffer mode is important for old chips like AST2500.
Quoted 100 lines · Jamin Lin
Hi Timur,
As far as I can see, no ASPEED Linux driver uses non-packet buffer or DMA mode for master transfers:
-i2c-aspeed.c(old register mode) only uses byte mode; the address is always written to the byte buffer register before START.
-i2c-ast2600.cin the ASPEED SDK kernel (new register mode) setsPKT_ENfor every master transfer, and the address comes fromPKT_ADDR.Have you verified this behavior on real hardware? Which firmware are you running that uses non-packet buffer/DMA mode?
Thanks,
JaminQuoted 84 lines
Subject: [PATCH v2 4/6] hw/i2c/aspeed: fix buffer transfer in non- packet mode
In non-packet mode, the first byte of the tx buffer pool contains a device
address, so avoid sending it as a data byte.Fixes 961faf3ddbd8 ("hw/i2c/aspeed: Fix TXBUF transmission startposition
error")Signed-off-by Timur Maksimov <[email protected]>---
hw/i2c/aspeed_i2c.c | 11 +++++++----1 file changed, 7 insertions(+), 4 deletions(-)hw/i2c/aspeed_i2c.c index renamed from hw/i2c/aspeed_i2c.c +0
-0
ff6ef6d23a..510758fb7a100644hw/i2c/aspeed_i2c.c +3
-2@@ -382,7 +382,7 @@ static void aspeed_i2c_bus_recv_dma_pool(AspeedI2CBus *bus) SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, RX_DMA_EN, 0); } -static int aspeed_i2c_bus_send (AspeedI2CBus *bus) +static int aspeed_i2c_bus_send (AspeedI2CBus *bus,bool send_addr) { AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller); int ret = -1;@@ -391,11 +391,12 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *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); + uint8_t pool_offset = send_addr ? 1 : 0; int pool_tx_count = SHARED_ARRAY_FIELD_EX32(bus->regs, reg_pool_ctrl, TX_COUNT) + 1; if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_BUFF_EN)) { - for (i = 0; i < pool_tx_count; i++) { + for (i = pool_offset; i < pool_tx_count; i++) { uint8_t *pool_base = aic->bus_pool_base(bus);trace_aspeed_i2c_bus_send("BUF", i + 1,
pool_tx_count, @@
-633,6 +634,7 @@ static voidaspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value)
uint32_treg_intr_sts=aspeed_i2c_bus_intr_sts_offset(bus);uint32_treg_cmd=aspeed_i2c_bus_cmd_offset(bus);uint32_treg_dma_len=aspeed_i2c_bus_dma_len_offset(bus); + boolstart_cmd= SHARED_ARRAY_FIELD_EX32(bus->regs,reg_cmd,
+M_START_CMD);if (!aspeed_i2c_check_sram(bus)) {
return;hw/i2c/aspeed_i2c.c +1
-1@@ -642,7 +644,7 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value) aspeed_i2c_bus_cmd_dump(bus); } - if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_START_CMD)) { + if (start_cmd) {
uint8_tstate =aspeed_i2c_get_state(bus)&I2CD_MACTIVE?I2CD_MSTARTR:I2CD_MSTART;
uint8_taddr;hw/i2c/aspeed_i2c.c +3
-1@@ -686,7 +688,8 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value) if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_TX_CMD)) { aspeed_i2c_set_state(bus, I2CD_MTXD); - if (aspeed_i2c_bus_send(bus)) { + if (aspeed_i2c_bus_send(bus, start_cmd && + !aspeed_i2c_bus_pkt_mode_en (bus))) + {SHARED_ARRAY_FIELD_DP32(bus->regs,
reg_intr_sts,TX_NAK,
1);
i2c_end_transfer(bus->bus);
} else {--
2.53.0
RE: [PATCH v2 4/6] hw/i2c/aspeed: fix buffer transfer in non-packet mode
Hi Timur,
I'm not saying they don't work.
My main concern is that we currently don't have firmware to test this mode on real hardware.
Although we can test it in QEMU using QTest, this does not guarantee that QEMU behaves the same way as real hardware. Without testing on real hardware, we cannot confirm that the behavior implemented by this patch matches the actual hardware behavior.
That said, I think the QTest in this series is very useful, as the functional tests don't cover all the I2C modes.
Thanks,
Jamin
Quoted 117 lines
Subject: Re: [PATCH v2 4/6] hw/i2c/aspeed: fix buffer transfer in non-packet mode
Hi Jamin, you are right; no driver uses those modes, and I can't verify their work at the moment.
Do you suppose, that they don't work? Are there issues with them? We can exclude them from tests, but buffer mode is important for old chips like AST2500.Quoted 30 lines · Jamin Lin
Hi Timur,
As far as I can see, no ASPEED Linux driver uses non-packet buffer or DMA mode for master transfers:
-i2c-aspeed.c(old register mode) only uses byte mode; the address is always written to the byte buffer register before START.
-i2c-ast2600.cin the ASPEED SDK kernel (new register mode) setsPKT_ENfor every master transfer, and the address comes fromPKT_ADDR.Have you verified this behavior on real hardware? Which firmware are you running that uses non-packet buffer/DMA mode?
Thanks,
JaminQuoted 14 lines
Subject: [PATCH v2 4/6] hw/i2c/aspeed: fix buffer transfer in non- packet mode
In non-packet mode, the first byte of the tx buffer pool contains a device address, so avoid sending it as a data byte.
Fixes 961faf3ddbd8 ("hw/i2c/aspeed: Fix TXBUF transmission startposition
error")Signed-off-by Timur Maksimov <[email protected]>---
hw/i2c/aspeed_i2c.c | 11 +++++++----1 file changed, 7 insertions(+), 4 deletions(-)Quoted 7 lines
hw/i2c/aspeed_i2c.c static void · line 383
Quoted 7 lines
hw/i2c/aspeed_i2c.c index renamed from hw/i2c/aspeed_i2c.c +0
-0
ff6ef6d23a..510758fb7a100644hw/i2c/aspeed_i2c.c +0
-0@@ -382,7 +382,7 @@ static void aspeed_i2c_bus_recv_dma_pool(AspeedI2CBus *bus) SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, RX_DMA_EN,0); }
Quoted 16 lines
Quoted 7 lines
hw/i2c/aspeed_i2c.c +1
-1-static int aspeed_i2c_bus_send (AspeedI2CBus *bus) +static int aspeed_i2c_bus_send (AspeedI2CBus *bus,bool send_addr) { AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus->controller); int ret = -1;hw/i2c/aspeed_i2c.c static int aspeed_i2c_bus_send(AspeedI2CBus · line 397
Quoted 7 lines
hw/i2c/aspeed_i2c.c +1
-0@@ -391,11 +391,12 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *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); + uint8_t pool_offset = send_addr ? 1 : 0; int pool_tx_count = SHARED_ARRAY_FIELD_EX32(bus->regs, reg_pool_ctrl,T
X_COUNT) + 1;Quoted 2 lines
hw/i2c/aspeed_i2c.c static int aspeed_i2c_bus_send(AspeedI2CBus · line 398
Quoted 2 lines
hw/i2c/aspeed_i2c.c +0
-0if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_BUFF_EN)){
Quoted 5 lines
hw/i2c/aspeed_i2c.c static int aspeed_i2c_bus_send(AspeedI2CBus *bus)
Quoted 5 lines
hw/i2c/aspeed_i2c.c +1
-1- for (i = 0; i < pool_tx_count; i++) { + for (i = pool_offset; i < pool_tx_count; i++) { uint8_t *pool_base = aic->bus_pool_base(bus); trace_aspeed_i2c_bus_send("BUF", i + 1,
pool_tx_count,Quoted 9 lines
Quoted 9 lines
@@
-633,6 +634,7 @@ static voidaspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value)
uint32_treg_intr_sts=aspeed_i2c_bus_intr_sts_offset(bus);uint32_treg_cmd=aspeed_i2c_bus_cmd_offset(bus);uint32_treg_dma_len=aspeed_i2c_bus_dma_len_offset(bus); + boolstart_cmd=SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, +M_START_CMD);Quoted 8 lines
hw/i2c/aspeed_i2c.c static void · line 646
Quoted 8 lines
if (!aspeed_i2c_check_sram(bus)) {
return;hw/i2c/aspeed_i2c.c +0
-1@@ -642,7 +644,7 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value) aspeed_i2c_bus_cmd_dump(bus); } - if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd,
M_START_CMD)) {Quoted 2 lines
Quoted 2 lines
hw/i2c/aspeed_i2c.c +1
-0+ if (start_cmd) {
uint8_tstate =aspeed_i2c_get_state(bus)&
I2CD_MACTIVE?Quoted 6 lines
hw/i2c/aspeed_i2c.c static void · line 690
Quoted 6 lines
I2CD_MSTARTR:I2CD_MSTART;
uint8_taddr;hw/i2c/aspeed_i2c.c +0
-0@@ -686,7 +688,8 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value) if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_TX_CMD)){
Quoted 4 lines
hw/i2c/aspeed_i2c.c static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value)
Quoted 4 lines
hw/i2c/aspeed_i2c.c +1
-1aspeed_i2c_set_state(bus, I2CD_MTXD); - if (aspeed_i2c_bus_send(bus)) { + if (aspeed_i2c_bus_send(bus, start_cmd &&+ !aspeed_i2c_bus_pkt
_mode_enQuoted 9 lines
Quoted 9 lines
hw/i2c/aspeed_i2c.c +1
-0(bus))) + {
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, TX_NAK, 1);
i2c_end_transfer(bus->bus);
} else {--
2.53.0
Re: [PATCH v2 4/6] hw/i2c/aspeed: fix buffer transfer in non-packet mode
Hi, Jamin.
Understood. I don’t planning to write a driver, but I might verify them if I have some time. Otherwise, let’s just skip them, as I am not sure that the current implementation is incorrect.
Quoted 152 lines · Jamin Lin
Hi Timur,
I'm not saying they don't work.
My main concern is that we currently don't have firmware to test this mode on real hardware.
Although we can test it in QEMU using QTest, this does not guarantee that QEMU behaves the same way as real hardware.
Without testing on real hardware, we cannot confirm that the behavior implemented by this patch matches the actual hardware behavior.That said, I think the QTest in this series is very useful, as the functional tests don't cover all the I2C modes.
Thanks,
JaminQuoted 135 lines
Subject: Re: [PATCH v2 4/6] hw/i2c/aspeed: fix buffer transfer in non-packet
modeHi Jamin, you are right; no driver uses those modes, and I can't verify their
work at the moment.
Do you suppose, that they don't work? Are there issues with them? We can exclude them from tests, but buffer mode is important for old chips
like AST2500.Quoted 36 lines · Jamin Lin
Hi Timur,
As far as I can see, no ASPEED Linux driver uses non-packet buffer or
DMA mode for master transfers:
-i2c-aspeed.c(old register mode) only uses byte mode; the address
is always written to the byte buffer register before START.
-i2c-ast2600.cin the ASPEED SDK kernel (new register mode) setsPKT_ENfor every master transfer, and the address comes fromPKT_ADDR.Have you verified this behavior on real hardware? Which firmware are
you running that uses non-packet buffer/DMA mode?Thanks,
JaminQuoted 17 lines
Subject: [PATCH v2 4/6] hw/i2c/aspeed: fix buffer transfer in non-
packet modeIn non-packet mode, the first byte of the tx buffer pool contains a
device address, so avoid sending it as a data byte.Fixes 961faf3ddbd8 ("hw/i2c/aspeed: Fix TXBUF transmissionstart
position
error")Signed-off-by Timur Maksimov <[email protected]>---
hw/i2c/aspeed_i2c.c | 11 +++++++----1 file changed, 7 insertions(+), 4 deletions(-)Quoted 7 lines
hw/i2c/aspeed_i2c.c static void · line 383
Quoted 7 lines
hw/i2c/aspeed_i2c.c index renamed from hw/i2c/aspeed_i2c.c +0
-0
ff6ef6d23a..510758fb7a100644hw/i2c/aspeed_i2c.c +0
-0@@ -382,7 +382,7 @@ static void aspeed_i2c_bus_recv_dma_pool(AspeedI2CBus *bus) SHARED_ARRAY_FIELD_DP32(bus->regs, reg_cmd, RX_DMA_EN,0); }
Quoted 7 lines
Quoted 7 lines
hw/i2c/aspeed_i2c.c +1
-1-static int aspeed_i2c_bus_send (AspeedI2CBus *bus) +static int aspeed_i2c_bus_send (AspeedI2CBus *bus,bool send_addr) {AspeedI2CClass *aic = ASPEED_I2C_GET_CLASS(bus-
Quoted 1 line
controller);
Quoted 14 lines
Quoted 4 lines
int ret = -1;
hw/i2c/aspeed_i2c.c +0
-0@@ -391,11 +391,12 @@ static intaspeed_i2c_bus_send(AspeedI2CBus
*bus)Quoted 8 lines
uint32_treg_pool_ctrl=aspeed_i2c_bus_pool_ctrl_offset(bus);
uint32_treg_byte_buf=aspeed_i2c_bus_byte_buf_offset(bus);
uint32_treg_dma_len=aspeed_i2c_bus_dma_len_offset(bus); +uint8_tpool_offset=send_addr? 1 : 0;
intpool_tx_count= SHARED_ARRAY_FIELD_EX32(bus->regs,reg_pool_ctrl,T
X_COUNT) + 1;Quoted 3 lines
Quoted 3 lines
if (
SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, TX_BUFF_EN)){
Quoted 5 lines
Quoted 5 lines
- for (i = 0; i <
pool_tx_count; i++) {
+ for (i =pool_offset; i <pool_tx_count; i++) {uint8_t*pool_base=aic->bus_pool_base(bus);trace_aspeed_i2c_bus_send("BUF", i + 1,
pool_tx_count,Quoted 12 lines
Quoted 12 lines
@@
-633,6 +634,7 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus
*bus,uint64_tvalue)
uint32_treg_intr_sts=aspeed_i2c_bus_intr_sts_offset(bus);
uint32_treg_cmd=aspeed_i2c_bus_cmd_offset(bus);uint32_treg_dma_len=aspeed_i2c_bus_dma_len_offset(bus); + boolstart_cmd= SHARED_ARRAY_FIELD_EX32(bus->regs,reg_cmd,
+M_START_CMD);Quoted 8 lines
hw/i2c/aspeed_i2c.c static void · line 646
Quoted 8 lines
if (!aspeed_i2c_check_sram(bus)) {
return;hw/i2c/aspeed_i2c.c +0
-1@@ -642,7 +644,7 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value) aspeed_i2c_bus_cmd_dump(bus); } - if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd,
M_START_CMD)) {Quoted 2 lines
Quoted 2 lines
hw/i2c/aspeed_i2c.c +1
-0+ if (start_cmd) {
uint8_tstate =aspeed_i2c_get_state(bus)&
I2CD_MACTIVE?Quoted 6 lines
hw/i2c/aspeed_i2c.c static void · line 690
Quoted 6 lines
I2CD_MSTARTR:I2CD_MSTART;
uint8_taddr;hw/i2c/aspeed_i2c.c +0
-0@@ -686,7 +688,8 @@ static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value) if (SHARED_ARRAY_FIELD_EX32(bus->regs, reg_cmd, M_TX_CMD)){
Quoted 4 lines
hw/i2c/aspeed_i2c.c static void aspeed_i2c_bus_handle_cmd(AspeedI2CBus *bus, uint64_t value)
Quoted 4 lines
hw/i2c/aspeed_i2c.c +1
-1aspeed_i2c_set_state(bus, I2CD_MTXD); - if (aspeed_i2c_bus_send(bus)) { + if (aspeed_i2c_bus_send(bus, start_cmd &&+ !aspeed_i2c_bus_pkt
_mode_enQuoted 9 lines
Quoted 9 lines
hw/i2c/aspeed_i2c.c +1
-0(bus))) + {
SHARED_ARRAY_FIELD_DP32(bus->regs, reg_intr_sts, TX_NAK, 1);
i2c_end_transfer(bus->bus);
} else {--
2.53.0
PATCH v2 5/6 hw/i2c/aspeed: fix DMA transfer in non-packet mode
In reply to Timur MaksimovAvoid calling aspeed_i2c_set_tx_dma_dram_offset twice in non-packet mode where this function is called first in aspeed_i2c_get_addr. Also fix writing to I2CD_DMA_ADDR in old register mode.
--- hw/i2c/aspeed_i2c.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
hw/i2c/aspeed_i2c.c +5 -1
@@ -416,7 +416,9 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, bool send_addr)if (aspeed_i2c_is_new_mode (bus->controller)) {ARRAY_FIELD_DP32 (bus->regs,I2CM_DMA_LEN_STS ,TX_LEN ,0 ); } -aspeed_i2c_set_tx_dma_dram_offset (bus); +if (!send_addr) { +aspeed_i2c_set_tx_dma_dram_offset (bus); + }while (bus->regs[reg_dma_len]) {uint8_t data; ret =aspeed_i2c_dma_read (bus, &data);
@@ -1070,11 +1072,13 @@ static void aspeed_i2c_bus_old_write(AspeedI2CBus *bus, hwaddr offset, bus->pending_intr_sts |= old_intr & cmd_intr;aspeed_i2c_bus_raise_interrupt (bus);break ; +case A_I2CD_DMA_ADDR :if (!aic->has_dma) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: No DMA support\n" , __func__);break ; } + bus->regs[R_I2CD_DMA_ADDR ] = value;break ;case A_I2CD_DMA_LEN :
Signature · 1 line
2.53.0
Re: [PATCH v2 5/6] hw/i2c/aspeed: fix DMA transfer in non-packet mode
Quoted 3 lines · Timur Maksimov
Avoid calling
aspeed_i2c_set_tx_dma_dram_offsettwice in non-packet mode where this function is called first inaspeed_i2c_get_addr. Also fix writing toI2CD_DMA_ADDRin old register mode.
This should be 2 changes.
Quoted 10 lines
Signed-off-by Timur Maksimov <[email protected]>--- hw/i2c/aspeed_i2c.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)hw/i2c/aspeed_i2c.c +0
-0
hw/i2c/aspeed_i2c.c static int aspeed_i2c_bus_send(AspeedI2CBus *bus, bool send_addr) · line 424
Quoted 10 lines
hw/i2c/aspeed_i2c.c +3
-1@@ -416,7 +416,9 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus, bool send_addr)if (aspeed_i2c_is_new_mode (bus->controller)) {ARRAY_FIELD_DP32 (bus->regs,I2CM_DMA_LEN_STS ,TX_LEN ,0 ); } -aspeed_i2c_set_tx_dma_dram_offset (bus); +if (!send_addr) { +aspeed_i2c_set_tx_dma_dram_offset (bus); + }while (bus->regs[reg_dma_len]) {uint8_t data; ret =aspeed_i2c_dma_read (bus, &data);
Quoted 5 lines
hw/i2c/aspeed_i2c.c +0
-0@@ -1070,11 +1072,13 @@ static void aspeed_i2c_bus_old_write(AspeedI2CBus *bus, hwaddr offset, bus->pending_intr_sts |= old_intr & cmd_intr;aspeed_i2c_bus_raise_interrupt (bus);break ;
hw/i2c/aspeed_i2c.c static void aspeed_i2c_bus_old_write(AspeedI2CBus *bus, hwaddr offset, · line 1084
Quoted 10 lines
hw/i2c/aspeed_i2c.c +2
-0+case A_I2CD_DMA_ADDR :if (!aic->has_dma) {qemu_log_mask (LOG_GUEST_ERROR ,"%s: No DMA support\n" , __func__);break ; } + bus->regs[R_I2CD_DMA_ADDR ] = value;break ;case A_I2CD_DMA_LEN :
and
Thanks,
C.
RE: [PATCH v2 5/6] hw/i2c/aspeed: fix DMA transfer in non-packet mode
Quoted 36 lines
Subject: Re: [PATCH v2 5/6] hw/i2c/aspeed: fix DMA transfer in non-packet mode
Quoted 3 lines · Timur Maksimov
Avoid calling
aspeed_i2c_set_tx_dma_dram_offsettwice in non-packet mode where this function is called first inaspeed_i2c_get_addr. Also fix writing toI2CD_DMA_ADDRin old register mode.This should be 2 changes.
hw/i2c/aspeed_i2c.c static int aspeed_i2c_bus_send(AspeedI2CBus *bus,
Quoted 10 lines
Signed-off-by Timur Maksimov <[email protected]>--- hw/i2c/aspeed_i2c.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)hw/i2c/aspeed_i2c.c index renamed from hw/i2c/aspeed_i2c.c +0
-0
510758fb7a..a2b4c8b576100644hw/i2c/aspeed_i2c.c +0
-0@@ -416,7 +416,9 @@ static int aspeed_i2c_bus_send(AspeedI2CBus *bus,bool
send_addr)hw/i2c/aspeed_i2c.c static int aspeed_i2c_bus_send(AspeedI2CBus *bus, · line 417
Quoted 2 lines
hw/i2c/aspeed_i2c.c +0
-0if (aspeed_i2c_is_new_mode (bus->controller)) { ARRAY_FIELD_DP32(bus->regs, I2CM_DMA_LEN_STS,
TX_LEN, 0);hw/i2c/aspeed_i2c.c static int aspeed_i2c_bus_send(AspeedI2CBus *bus, bool send_addr) · line 424
Quoted 8 lines
hw/i2c/aspeed_i2c.c +3
-1} -aspeed_i2c_set_tx_dma_dram_offset (bus); +if (!send_addr) { +aspeed_i2c_set_tx_dma_dram_offset (bus); + }while (bus->regs[reg_dma_len]) {uint8_t data; ret =aspeed_i2c_dma_read (bus, &data);
Quoted 3 lines
Fixes efea7ddb4689 ("hw/i2c/aspeed_i2c: Fix DMA moving data into incorrectaddress")
This please see my comments in patch 4.
Quoted 15 lines
hw/i2c/aspeed_i2c.c static void
Quoted 1 line
hw/i2c/aspeed_i2c.c +0
-0@@ -1070,11 +1072,13 @@ static voidaspeed_i2c_bus_old_write(AspeedI2CBus *bus, hwaddr offset,
hw/i2c/aspeed_i2c.c static void aspeed_i2c_bus_old_write(AspeedI2CBus *bus, hwaddr offset,
Quoted 7 lines
hw/i2c/aspeed_i2c.c +1
-0bus->pending_intr_sts |= old_intr & cmd_intr;aspeed_i2c_bus_raise_interrupt (bus);break ; +case A_I2CD_DMA_ADDR :if (!aic->has_dma) { qemu_log_mask(LOG_GUEST_ERROR, "%s: No DMAsupport\n",
__func__);Quoted 5 lines
hw/i2c/aspeed_i2c.c +1
-0break ; } + bus->regs[R_I2CD_DMA_ADDR ] = value;break ;
Quoted 7 lines
hw/i2c/aspeed_i2c.c static void aspeed_i2c_bus_old_write(AspeedI2CBus *bus, hwaddr offset, · line 1084
Quoted 2 lines
hw/i2c/aspeed_i2c.c +0
-0case A_I2CD_DMA_LEN :and
Fixes 2260fc6ff3ff ("aspeed: i2c: Use reg array instead of individual vars")
This looks good to me.
Quoted 3 lines
Thanks,
C.
PATCH v2 6/6 tests/qtest: Add cases for 32-bit Aspeed I2C controllers
In reply to Timur MaksimovTest all supported register and transfer modes.
--- tests/qtest/aspeed_i2c-test.c | 836 ++++++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 + 2 files changed, 838 insertions(+)
tests/qtest/aspeed_i2c-test.c new file +836 -0
@@ -0,0 +1,836 @@ +/* +* QTest testcase for Aspeed I2C controller +* +* Copyright (c) 2026 Timur Maksimov <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "libqtest-single.h" +#include "hw/i2c/aspeed_i2c.h" + +typedef enum TestAspeedI2CMode { +TEST_I2C_MODE_OLD , +TEST_I2C_MODE_NEW , +TEST_I2C_MODE_PKT , +}TestAspeedI2CMode ; + +typedef enum TestAspeedMachine { +TEST_MACHINE_AST2400 , +TEST_MACHINE_AST2500 , +TEST_MACHINE_AST2600 , +}TestAspeedMachine ; + +typedef struct TestData { +const char *name; +TestAspeedMachine machine; +TestAspeedI2CMode mode; +}TestData ; + +typedef struct TestFixture { +hwaddr base_addr; +hwaddr bus_offset; +int irq_no; +uint32_t pool_base; +}TestFixture ; + +static const uint8_t tx_data[] = {0x10 ,0x11 ,0x12 }; +static const uint8_t rx_data[] = {0x30 ,0x31 ,0x32 }; + +#define DRAM_BASE 0x80000000 +#define DRAM_TX_OFFSET 0x1000 +#define DRAM_RX_OFFSET 0x2000 + +static void aspeed_i2c_write (TestFixture *f,uint32_t offset,uint32_t val) +{ +qtest_writel (global_qtest, f->base_addr + f->bus_offset + offset, val); +} + +static void aspeed_i2c_write_pool (TestFixture *f,uint32_t offset,uint8_t val) +{ +qtest_writeb (global_qtest, f->base_addr + f->pool_base + offset, val); +} + +static void aspeed_i2c_write_dma (TestFixture *f,uint32_t offset,uint8_t val) +{ +qtest_writeb (global_qtest,DRAM_BASE + offset, val); +} + +static uint32_t aspeed_i2c_read (TestFixture *f,uint32_t offset) +{ +return qtest_readl (global_qtest, f->base_addr + f->bus_offset + offset); +} + +static uint8_t aspeed_i2c_read_pool (TestFixture *f,uint32_t offset) +{ +return qtest_readb (global_qtest, f->base_addr + f->pool_base + offset); +} + +static uint8_t aspeed_i2c_read_dma (TestFixture *f,uint32_t offset) +{ +return qtest_readb (global_qtest,DRAM_BASE + offset); +} + +static bool aspeed_i2c_irq (TestFixture *f) +{ +return qtest_get_irq (global_qtest, f->irq_no); +} + +static uint32_t aspeed_i2c_ctrl_offset (const TestData *td) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +return A_I2CD_FUN_CTRL ; + }else { +return A_I2CC_FUN_CTRL ; + } +} + +static uint32_t aspeed_i2c_cmd_offset (const TestData *td) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +return A_I2CD_CMD ; + }else { +return A_I2CM_CMD ; + } +} + + +static uint32_t aspeed_i2c_intr_ctrl_offset (const TestData *td) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +return A_I2CD_INTR_CTRL ; + }else { +return A_I2CM_INTR_CTRL ; + } +} + +static uint32_t aspeed_i2c_intr_sts_offset (const TestData *td) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +return A_I2CD_INTR_STS ; + }else { +return A_I2CM_INTR_STS ; + } +} + +static uint32_t aspeed_i2c_pool_ctrl_offset (const TestData *td) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +return A_I2CD_POOL_CTRL ; + }else { +return A_I2CC_POOL_CTRL ; + } +} + +static uint32_t aspeed_i2c_byte_buf_offset (const TestData *td) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +return A_I2CD_BYTE_BUF ; + }else { +return A_I2CC_MS_TXRX_BYTE_BUF ; + } +} + +static void aspeed_i2c_write_slave_addr (TestFixture *f,const TestData *td, +uint8_t addr) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +aspeed_i2c_write (f,A_I2CD_DEV_ADDR , addr); + }else { +aspeed_i2c_write (f,A_I2CS_DEV_ADDR , addr); + } +} + +static void aspeed_i2c_write_dma_addr (TestFixture *f,const TestData *td, +uint32_t val,bool rx) +{ +uint32_t offset; + +if (td->mode ==TEST_I2C_MODE_OLD ) { + offset =A_I2CD_DMA_ADDR ; + }else { + offset = rx ?A_I2CM_DMA_RX_ADDR :A_I2CM_DMA_TX_ADDR ; + } +aspeed_i2c_write (f, offset, val); +} + +static void aspeed_i2c_write_dma_len (TestFixture *f,const TestData *td, +uint16_t val,bool rx) +{ +uint32_t reg; + +if (td->mode ==TEST_I2C_MODE_OLD ) { +aspeed_i2c_write (f,A_I2CD_DMA_LEN , val +1 ); +return ; + } + +if (rx) { + reg =FIELD_DP32 (0 ,I2CM_DMA_LEN ,RX_BUF_LEN_W1T ,1 ); + reg =FIELD_DP32 (reg,I2CM_DMA_LEN ,RX_BUF_LEN , val); + }else { + reg =FIELD_DP32 (0 ,I2CM_DMA_LEN ,TX_BUF_LEN_W1T ,1 ); + reg =FIELD_DP32 (reg,I2CM_DMA_LEN ,TX_BUF_LEN , val); + } +aspeed_i2c_write (f,A_I2CM_DMA_LEN , reg); +} + +static uint8_t aspeed_i2c_get_txstate (TestFixture *f,const TestData *td) +{ +uint32_t offset; + +if (td->mode ==TEST_I2C_MODE_OLD ) { + offset =A_I2CD_CMD ; + }else { + offset =A_I2CC_MS_TXRX_BYTE_BUF ; + } +return SHARED_FIELD_EX32 (aspeed_i2c_read (f, offset),TX_STATE ); +} + +static bool aspeed_i2c_get_busy_sts (TestFixture *f,const TestData *td) +{ +uint32_t offset; + +if (td->mode ==TEST_I2C_MODE_OLD ) { + offset =A_I2CD_CMD ; + }else { + offset =A_I2CC_MS_TXRX_BYTE_BUF ; + } +return SHARED_FIELD_EX32 (aspeed_i2c_read (f, offset),BUS_BUSY_STS ); +} + +/* Write a data byte in a byte mode transfer */ +static +void aspeed_i2c_write_byte (TestFixture *f,const TestData *td,uint8_t val) +{ +aspeed_i2c_write (f,aspeed_i2c_byte_buf_offset (td), +SHARED_FIELD_DP32 (0 ,TX_BUF , val)); +} + +/* Read a data byte in a byte mode transfer */ +static uint8_t aspeed_i2c_read_byte (TestFixture *f,const TestData *td) +{ +uint32_t reg; + + reg =aspeed_i2c_read (f,aspeed_i2c_byte_buf_offset (td)); +return SHARED_FIELD_EX32 (reg,RX_BUF ); +} + +static void aspeed_i2c_send_start (TestFixture *f,const TestData *td, +uint32_t cmd) +{ + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +} + +static uint8_t qom_i2c_dummy_get_uint8 (const char *prop) +{ +QDict *r; +uint8_t u; + + r =qtest_qmp (global_qtest, +"{ 'execute': 'qom-get', 'arguments': " +"{ 'path': 'i2c-dummy', 'property': %s } }" , + prop); + u =qdict_get_uint (r,"return" ); +qobject_unref (r); +return u; +} + +static void qom_i2c_dummy_set_uint8 (const char *prop,uint8_t data) +{ +QDict *r; + + r =qtest_qmp (global_qtest, +"{ 'execute': 'qom-set', 'arguments': " +"{ 'path': 'i2c-dummy', 'property': %s, 'value': %d } }" , + prop, data); +qobject_unref (r); +} + +static void qom_i2c_dummy_set_rx (uint8_t idx,uint8_t data) +{ + g_autofree char *prop = g_strdup_printf("rx[%d]", idx); + +qom_i2c_dummy_set_uint8 (prop, data); +} + +static uint8_t qom_i2c_dummy_get_tx (int8_t idx) +{ + g_autofree char *prop = g_strdup_printf("tx[%d]", idx); + +return qom_i2c_dummy_get_uint8 (prop); +} + +#define I2C_ADDR_NACK 0x10 +#define I2C_ADDR_DUMMY 0x20 +#define I2C_ADDR_ECHO 0x30 +#define I2C_ADDR_SLAVE 0x40 + +#define CHECK_I2C_IDLE (f, td) do { \ + g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_IDLE); \ + g_assert_false(aspeed_i2c_get_busy_sts(f, td)); \ + g_assert_cmphex(aspeed_i2c_read(f, aspeed_i2c_intr_sts_offset(td)), ==, \ + 0); \ + g_assert_false(aspeed_i2c_irq(f)); \ +} while (0) + +#define CHECK_I2C_INTR (f, td, reg) do { \ + g_assert_true(aspeed_i2c_irq(f)); \ + g_assert_cmphex(aspeed_i2c_read(f, aspeed_i2c_intr_sts_offset(td)), ==, \ + reg); \ +} while (0) + +#define CHECK_I2C_BUS_ACTIVE (f, td) do { \ + g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MACTIVE); \ + g_assert_true(aspeed_i2c_get_busy_sts(f, td)); \ +} while (0) + +#define CHECK_I2C_ACK (f, td) do { \ + g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MACTIVE); \ + g_assert_true(aspeed_i2c_get_busy_sts(f, td)); \ + CLEAR_I2C_INTR(f, td, SHARED_FIELD_DP32(0, TX_ACK, 1)); \ +} while (0) + +#define CLEAR_I2C_INTR (f, td, reg) do { \ + CHECK_I2C_INTR(f, td, reg); \ + aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), reg); \ + g_assert_cmphex(aspeed_i2c_read(f, aspeed_i2c_intr_sts_offset(td)), ==, \ + 0); \ +} while (0) + +#define SEND_I2C_STOP (f, td) do { \ + aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), \ + SHARED_FIELD_DP32(0, M_STOP_CMD, 1)); \ + CLEAR_I2C_INTR(f, td, SHARED_FIELD_DP32(0, NORMAL_STOP, 1)); \ + CHECK_I2C_IDLE(f, td); \ +} while (0) + +#define CHECK_I2C_DUMMY_DEVICE () do { \ + for (uint8_t i = 0; i < ARRAY_SIZE(tx_data); i++) { \ + g_assert_cmphex(qom_i2c_dummy_get_tx(i), ==, tx_data[i]); \ + } \ + g_assert_cmphex(qom_i2c_dummy_get_uint8("tx-pos"), ==, \ + ARRAY_SIZE(tx_data)); \ + g_assert_cmphex(qom_i2c_dummy_get_uint8("rx-pos"), ==, \ + ARRAY_SIZE(rx_data)); \ +} while (0) + +static void aspeed_i2c_init (TestFixture *f,const TestData *td) +{ +uint32_t reg; + +qtest_qmp (global_qtest,"{ 'execute': 'system_reset' }" ); + +aspeed_i2c_write_slave_addr (f, td,I2C_ADDR_SLAVE ); + + reg =FIELD_DP32 (0 ,I2C_CTRL_GLOBAL ,SRAM_EN ,1 ); +if (td->mode !=TEST_I2C_MODE_OLD ) { + reg =FIELD_DP32 (reg,I2C_CTRL_GLOBAL ,REG_MODE ,1 ); + } +qtest_writel (global_qtest, f->base_addr +A_I2C_CTRL_GLOBAL , reg); + + reg =SHARED_FIELD_DP32 (0 ,MASTER_EN ,1 ); + reg =SHARED_FIELD_DP32 (reg,SLAVE_EN ,1 ); +aspeed_i2c_write (f,aspeed_i2c_ctrl_offset (td), reg); + +/* Enable all interrupts */ + reg =SHARED_FIELD_DP32 (0 ,TX_ACK ,1 ); + reg =SHARED_FIELD_DP32 (reg,TX_NAK ,1 ); + reg =SHARED_FIELD_DP32 (reg,RX_DONE ,1 ); + reg =SHARED_FIELD_DP32 (reg,ARBIT_LOSS ,1 ); + reg =SHARED_FIELD_DP32 (reg,NORMAL_STOP ,1 ); + reg =SHARED_FIELD_DP32 (reg,ABNORMAL ,1 ); +if (td->mode !=TEST_I2C_MODE_OLD ) { + reg =FIELD_DP32 (reg,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + reg =FIELD_DP32 (reg,I2CM_INTR_STS ,PKT_CMD_FAIL ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_intr_ctrl_offset (td), reg); + +for (uint8_t i =0 ; i <ARRAY_SIZE (rx_data); i++) { +qom_i2c_dummy_set_rx (i, rx_data[i]); + } +} + +static uint32_t aspeed_i2c_pkt_set_addr_cmd (const TestData *td,uint8_t addr) +{ +uint32_t cmd; + + cmd =FIELD_DP32 (0 ,I2CM_CMD ,PKT_OP_EN ,1 ); + cmd =FIELD_DP32 (cmd,I2CM_CMD ,PKT_DEV_ADDR , addr); +return cmd; +} + +static +uint32_t aspeed_i2c_byte_set_addr_cmd (TestFixture *f,const TestData *td, +uint8_t addr,bool is_recv) +{ +if (td->mode ==TEST_I2C_MODE_PKT ) { +return aspeed_i2c_pkt_set_addr_cmd (td, addr); + }else { +aspeed_i2c_write_byte (f, td, addr <<1 | (is_recv ?1 :0 )); +return SHARED_FIELD_DP32 (0 ,M_TX_CMD ,1 ); + } +} + +static +uint32_t aspeed_i2c_buf_set_addr_cmd (TestFixture *f,const TestData *td, +uint8_t addr,bool is_recv) +{ +if (td->mode ==TEST_I2C_MODE_PKT ) { +return aspeed_i2c_pkt_set_addr_cmd (td, addr); + }else { +aspeed_i2c_write_pool (f,0 , addr <<1 | (is_recv ?1 :0 )); +return SHARED_FIELD_DP32 (0 ,M_TX_CMD ,1 ); + } +} + +static +uint32_t aspeed_i2c_dma_set_addr_cmd (TestFixture *f,const TestData *td, +uint8_t addr,bool is_recv) +{ +if (td->mode ==TEST_I2C_MODE_PKT ) { +return aspeed_i2c_pkt_set_addr_cmd (td, addr); + }else { +aspeed_i2c_write_dma (f,DRAM_TX_OFFSET , addr <<1 | (is_recv ?1 :0 )); +return SHARED_FIELD_DP32 (0 ,M_TX_CMD ,1 ); + } +} + + +static uint32_t aspeed_i2c_send_addr_status (TestFixture *f,const TestData *td) +{ +uint32_t sts; + +if (td->mode ==TEST_I2C_MODE_PKT ) { + sts =FIELD_DP32 (0 ,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + }else { + sts =SHARED_FIELD_DP32 (0 ,TX_ACK ,1 ); + } +return sts; +} + +/* +* Send an address byte to a non existing device. +* The TX_NAK interrupt should be raised. +*/ +static void test_nack (TestFixture *f,gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; +uint32_t sts, cmd; + + cmd =aspeed_i2c_byte_set_addr_cmd (f, td,I2C_ADDR_NACK , false); +aspeed_i2c_send_start (f, td, cmd); + + g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MSTART); +g_assert_false (aspeed_i2c_get_busy_sts (f, td)); + sts =SHARED_FIELD_DP32 (0 ,TX_NAK ,1 ); +if (td->mode ==TEST_I2C_MODE_PKT ) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_FAIL ,1 ); + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + } +CLEAR_I2C_INTR (f, td, sts); + +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), +SHARED_FIELD_DP32 (0 ,M_STOP_CMD ,1 )); +CLEAR_I2C_INTR (f, td,SHARED_FIELD_DP32 (0 ,NORMAL_STOP ,1 )); +CHECK_I2C_IDLE (f, td); +qtest_hmp (global_qtest,"system_reset" ); +} + + +static void test_dummy_byte (TestFixture *f,gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; +uint32_t cmd, sts; +bool pkt_mode = td->mode ==TEST_I2C_MODE_PKT ; + +/* Write device address (Write) */ + cmd =aspeed_i2c_byte_set_addr_cmd (f, td,I2C_ADDR_DUMMY , false); +aspeed_i2c_send_start (f, td, cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td,aspeed_i2c_send_addr_status (f, td)); + +/* Write data */ + sts =SHARED_FIELD_DP32 (0 ,TX_ACK ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + cmd =aspeed_i2c_pkt_set_addr_cmd (td,I2C_ADDR_DUMMY ); + }else { + cmd =0 ; + } + cmd =SHARED_FIELD_DP32 (cmd,M_TX_CMD ,1 ); +for (uint8_t i =0 ; i <ARRAY_SIZE (tx_data); i++) { +aspeed_i2c_write_byte (f, td, tx_data[i]); +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td, sts); + } + +/* Read data */ + cmd =aspeed_i2c_byte_set_addr_cmd (f, td,I2C_ADDR_DUMMY , true); + cmd =SHARED_FIELD_DP32 (cmd,M_RX_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); + sts =aspeed_i2c_send_addr_status (f, td); + +for (uint8_t i =0 ; i <ARRAY_SIZE (rx_data); i++) { + cmd =SHARED_FIELD_DP32 (cmd,M_RX_CMD ,1 ); +if (i ==ARRAY_SIZE (rx_data) -1 ) { + cmd =SHARED_FIELD_DP32 (cmd,M_S_RX_CMD_LAST ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); + sts =SHARED_FIELD_DP32 (sts,RX_DONE ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + cmd =aspeed_i2c_pkt_set_addr_cmd (td,I2C_ADDR_DUMMY ); + }else { + cmd =0 ; + } +CLEAR_I2C_INTR (f, td, sts); + g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, rx_data[i]); + sts =0 ; + } + +SEND_I2C_STOP (f, td); +CHECK_I2C_DUMMY_DEVICE (); +qtest_hmp (global_qtest,"system_reset" ); +} + +static void test_dummy_buf (TestFixture *f,gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; +uint32_t cmd, sts, pool_ctrl; +bool pkt_mode = td->mode ==TEST_I2C_MODE_PKT ; + +/* Write data with device address */ +for (uint8_t i =0 ; i <ARRAY_SIZE (tx_data); i++) { +aspeed_i2c_write_pool (f, i + (pkt_mode ?0 :1 ), tx_data[i]); + } + pool_ctrl =SHARED_FIELD_DP32 (0 ,TX_COUNT , +ARRAY_SIZE (tx_data) - (pkt_mode ?1 :0 )); +aspeed_i2c_write (f,aspeed_i2c_pool_ctrl_offset (td), pool_ctrl); + cmd =aspeed_i2c_buf_set_addr_cmd (f, td,I2C_ADDR_DUMMY , false); + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,M_TX_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,TX_BUFF_EN ,1 ); + sts =SHARED_FIELD_DP32 (0 ,TX_ACK ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td, sts); + +/* Write device address (Read) in non packet mde */ +if (pkt_mode) { + cmd =aspeed_i2c_pkt_set_addr_cmd (td,I2C_ADDR_DUMMY ); + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); + }else { +aspeed_i2c_write_byte (f, td, (I2C_ADDR_DUMMY <<1 ) |1 ); +aspeed_i2c_send_start (f, td,SHARED_FIELD_DP32 (0 ,M_TX_CMD ,1 )); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td,aspeed_i2c_send_addr_status (f, td)); + cmd =0 ; + } + +/* Read data */ + pool_ctrl =SHARED_FIELD_DP32 (0 ,RX_SIZE , +ARRAY_SIZE (rx_data) -1 ); +aspeed_i2c_write (f,aspeed_i2c_pool_ctrl_offset (td), pool_ctrl); + cmd =SHARED_FIELD_DP32 (cmd,M_RX_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,M_S_RX_CMD_LAST ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,RX_BUFF_EN ,1 ); + sts =SHARED_FIELD_DP32 (0 ,RX_DONE ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td, sts); +for (uint8_t i =0 ; i <ARRAY_SIZE (rx_data); i++) { + g_assert_cmphex(aspeed_i2c_read_pool(f, i), ==, rx_data[i]); + } + +SEND_I2C_STOP (f, td); +CHECK_I2C_DUMMY_DEVICE (); +qtest_hmp (global_qtest,"system_reset" ); +} + +static void test_dummy_dma (TestFixture *f,gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; +uint32_t cmd, sts; +bool pkt_mode = td->mode ==TEST_I2C_MODE_PKT ; + +/* Write data with device address*/ +for (uint8_t i =0 ; i <ARRAY_SIZE (tx_data); i++) { +aspeed_i2c_write_dma (f,DRAM_TX_OFFSET + (pkt_mode ?0 :1 ) + i, + tx_data[i]); + } +aspeed_i2c_write_dma_addr (f, td,DRAM_TX_OFFSET , false); +aspeed_i2c_write_dma_len (f, td, +ARRAY_SIZE (tx_data) - (pkt_mode ?1 :0 ), false); + cmd =aspeed_i2c_dma_set_addr_cmd (f, td,I2C_ADDR_DUMMY , false); + + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,M_TX_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,TX_DMA_EN ,1 ); + sts =SHARED_FIELD_DP32 (0 ,TX_ACK ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td, sts); + +/* Write device address (Read) in non packet mode */ +if (pkt_mode) { + cmd =aspeed_i2c_pkt_set_addr_cmd (td,I2C_ADDR_DUMMY ); + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); + }else { +aspeed_i2c_write_byte (f, td, (I2C_ADDR_DUMMY <<1 ) |1 ); +aspeed_i2c_send_start (f, td,SHARED_FIELD_DP32 (0 ,M_TX_CMD ,1 )); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td,aspeed_i2c_send_addr_status (f, td)); + cmd =0 ; + } + +/* Read data */ +aspeed_i2c_write_dma_addr (f, td,DRAM_RX_OFFSET , true); +aspeed_i2c_write_dma_len (f, td,ARRAY_SIZE (rx_data) -1 , true); + cmd =SHARED_FIELD_DP32 (cmd,M_RX_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,M_S_RX_CMD_LAST ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,RX_DMA_EN ,1 ); + sts =SHARED_FIELD_DP32 (0 ,RX_DONE ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td, sts); +for (uint8_t i =0 ; i <ARRAY_SIZE (rx_data); i++) { + g_assert_cmphex(aspeed_i2c_read_dma(f, DRAM_RX_OFFSET + i), ==, + rx_data[i]); + } + +SEND_I2C_STOP (f, td); +CHECK_I2C_DUMMY_DEVICE (); +qtest_hmp (global_qtest,"system_reset" ); +} + +static void test_slave (TestFixture *f,gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; +uint32_t cmd, sts, tmp; +bool pkt_mode = td->mode ==TEST_I2C_MODE_PKT ; +uint8_t offset = pkt_mode ?0 :1 ; + +aspeed_i2c_write_pool (f, offset +0 ,I2C_ADDR_SLAVE ); +aspeed_i2c_write_pool (f, offset +1 , tx_data[0 ]); +aspeed_i2c_write_pool (f, offset +2 , tx_data[1 ]); + + tmp =SHARED_FIELD_DP32 (0 ,TX_COUNT , pkt_mode ?2 :3 ); +aspeed_i2c_write (f,aspeed_i2c_pool_ctrl_offset (td), tmp); + + cmd =aspeed_i2c_buf_set_addr_cmd (f, td,I2C_ADDR_ECHO , false); + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,M_TX_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,TX_BUFF_EN ,1 ); + sts =SHARED_FIELD_DP32 (0 ,TX_ACK ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td, sts); + +/* Send stop and handle i2c-echo response as a slave */ +if (td->mode ==TEST_I2C_MODE_OLD ) { +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), +SHARED_FIELD_DP32 (0 ,M_STOP_CMD ,1 )); +clock_step (1 ); + g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, I2C_ADDR_SLAVE << 1); + sts =SHARED_FIELD_DP32 (0 ,NORMAL_STOP ,1 ); + sts =SHARED_FIELD_DP32 (sts,RX_DONE ,1 ); + sts =FIELD_DP32 (sts,I2CD_INTR_STS ,SLAVE_ADDR_RX_MATCH ,1 ); +CHECK_I2C_INTR (f, td, sts); +aspeed_i2c_write (f,aspeed_i2c_intr_sts_offset (td), sts); + + g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, tx_data[0]); + sts =SHARED_FIELD_DP32 (0 ,RX_DONE ,1 ); +CHECK_I2C_INTR (f, td, sts); +aspeed_i2c_write (f,aspeed_i2c_intr_sts_offset (td), sts); + + g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, tx_data[1]); + sts =SHARED_FIELD_DP32 (0 ,RX_DONE ,1 ); +CHECK_I2C_INTR (f, td, sts); +aspeed_i2c_write (f,aspeed_i2c_intr_sts_offset (td), sts); + }else { +aspeed_i2c_write (f,A_I2CS_DMA_RX_ADDR ,DRAM_RX_OFFSET ); + tmp =SHARED_FIELD_DP32 (0 ,RX_DMA_EN ,1 ); +aspeed_i2c_write (f,A_I2CS_CMD , tmp); + +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), +SHARED_FIELD_DP32 (0 ,M_STOP_CMD ,1 )); +clock_step (1 ); + + tmp =FIELD_DP32 (0 ,I2CS_DMA_LEN_STS ,RX_LEN ,2 ); + g_assert_cmphex(aspeed_i2c_read(f, A_I2CS_DMA_LEN_STS), ==, tmp); +for (uint8_t i =0 ; i <2 ; i++) { + g_assert_cmphex(aspeed_i2c_read_dma(f, DRAM_RX_OFFSET + i), ==, + tx_data[i]); + } + } + + sts =SHARED_FIELD_DP32 (0 ,NORMAL_STOP ,1 ); +CLEAR_I2C_INTR (f, td, sts); +CHECK_I2C_IDLE (f, td); + +qtest_hmp (global_qtest,"system_reset" ); +} + +static void aspeed_i2c_init_fixture (TestFixture *fixture,const TestData *td) +{ +switch (td->machine) { +case TEST_MACHINE_AST2400 : + fixture->base_addr =0x1E78A000 ; + fixture->bus_offset =0x40 ; + fixture->irq_no =12 ; + fixture->pool_base =0x800 ; +break ; +case TEST_MACHINE_AST2500 : + fixture->base_addr =0x1E78A000 ; + fixture->bus_offset =0x40 ; + fixture->irq_no =12 ; + fixture->pool_base =0x200 ; +break ; +case TEST_MACHINE_AST2600 : + fixture->base_addr =0x1E78A000 ; + fixture->bus_offset =0x80 ; + fixture->irq_no =110 ; + fixture->pool_base =0xC00 ; +break ; +default : +return ; + } +} + +static void aspeed_i2c_init_test (TestFixture *fixture,const TestData *td) +{ +aspeed_i2c_init (fixture, td); +CHECK_I2C_IDLE (fixture, td); +} + +static void aspeed_i2c_init_new_machine (TestFixture *fixture, +gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; +const char *machine; +const char *irq_dev; + +aspeed_i2c_init_fixture (fixture, td); + +if (global_qtest) { +qtest_quit (global_qtest); + } + +switch (td->machine) { +case TEST_MACHINE_AST2400 : + machine ="palmetto-bmc" ; + irq_dev ="/machine/soc/vic" ; +break ; +case TEST_MACHINE_AST2500 : + machine ="ast2500-evb" ; + irq_dev ="/machine/soc/vic" ; +break ; +case TEST_MACHINE_AST2600 : + machine ="ast2600-evb" ; + irq_dev ="/machine/soc/a7mpcore/gic" ; +break ; +default : +g_test_fail (); +return ; + } + + global_qtest =qtest_initf ( +"-machine %s -nographic " +"-device i2c-echo,id=i2c-echo,bus=aspeed.i2c.bus.0,address=%d " +"-device i2c-dummy-device,id=i2c-dummy,bus=aspeed.i2c.bus.0,address=%d" , + machine,I2C_ADDR_ECHO ,I2C_ADDR_DUMMY ); +qtest_irq_intercept_in (global_qtest, irq_dev); + +aspeed_i2c_init_test (fixture, td); +} + +static void aspeed_i2c_init_machine (TestFixture *fixture, +gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; + +aspeed_i2c_init_fixture (fixture, td); +aspeed_i2c_init_test (fixture, td); +} + +static void add_test (const TestData *td,const char *name, +void (*func)(TestFixture *,const void *), +bool setup) +{ + g_autofree char *test_name; + + test_name =g_strdup_printf ("%s/%s" , td->name, name); + +qtest_add (test_name, TestFixture, td, + setup ? aspeed_i2c_init_new_machine : aspeed_i2c_init_machine, + func,NULL ); +} + +#define ADD_TEST (td, test, new) add_test(td, #test, test_##test, new) + +static const TestData test_data[] = { + { + .name ="ast2400" , + .machine =TEST_MACHINE_AST2400 , + }, + { + .name ="ast2500" , + .machine =TEST_MACHINE_AST2500 , + }, + { + .name ="ast2600" , + .machine =TEST_MACHINE_AST2600 , + }, + { + .name ="ast2600-new" , + .machine =TEST_MACHINE_AST2600 , + .mode =TEST_I2C_MODE_NEW , + }, + { + .name ="ast2600-packet" , + .machine =TEST_MACHINE_AST2600 , + .mode =TEST_I2C_MODE_PKT , + }, +}; + +int main (int argc,char **argv) +{ +int ret; +bool setup; + +g_test_init (&argc, &argv,NULL ); + +for (int i =0 ; i <ARRAY_SIZE (test_data); i++) { + setup = i ==0 || test_data[i].machine != test_data[i -1 ].machine; +ADD_TEST (&test_data[i], nack, setup); +ADD_TEST (&test_data[i], dummy_byte, false); +ADD_TEST (&test_data[i], dummy_buf, false); +if (test_data[i].machine !=TEST_MACHINE_AST2400 ) { +ADD_TEST (&test_data[i], dummy_dma, false); + } +ADD_TEST (&test_data[i], slave, false); + } + + ret =g_test_run (); +qtest_quit (global_qtest); +return ret; +}
tests/qtest/meson.build +2 -0
@@ -233,12 +233,14 @@ qtests_aspeed = \ ['aspeed-acry-test', 'aspeed_gpio-test', 'aspeed_hace-test', + 'aspeed_i2c-test', 'aspeed-sbc-test', 'aspeed_scu-test', 'aspeed_smc-test'] qtests_aspeed64 = \ ['ast2700-gpio-test', 'ast2700-hace-test', + 'aspeed_i2c-test', 'ast2700-sgpio-test', 'ast2700-smc-test']
Signature · 1 line
2.53.0
Re: [PATCH v2 6/6] tests/qtest: Add cases for 32-bit Aspeed I2C controllers
Quoted 26 lines · Timur Maksimov
Test all supported register and transfer modes.
Signed-off-by Timur Maksimov <[email protected]>--- tests/qtest/aspeed_i2c-test.c | 836 ++++++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 + 2 files changed, 838 insertions(+)tests/qtest/aspeed_i2c-test.c new file +12
-0@@ -0,0 +1,836 @@ +/* +* QTest testcase for Aspeed I2C controller +* +* Copyright (c) 2026 Timur Maksimov <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "libqtest-single.h" +#include "hw/i2c/aspeed_i2c.h" +
tests/qtest/aspeed_i2c-test.c line 22
Quoted 10 lines
tests/qtest/aspeed_i2c-test.c new file +10
-0+typedef enum TestAspeedI2CMode { +TEST_I2C_MODE_OLD , +TEST_I2C_MODE_NEW , +TEST_I2C_MODE_PKT , +}TestAspeedI2CMode ; + +typedef enum TestAspeedMachine { + TEST_MACHINE_AST2400, + TEST_MACHINE_AST2500, + TEST_MACHINE_AST2600,
Do you have plans to add AST2700 support ? This is the current focus now days.
Thanks,
C.
Quoted 834 lines
tests/qtest/aspeed_i2c-test.c new file +814
-0+} TestAspeedMachine; + +typedef struct TestData { +const char *name; +TestAspeedMachine machine; +TestAspeedI2CMode mode; +}TestData ; + +typedef struct TestFixture { +hwaddr base_addr; +hwaddr bus_offset; +int irq_no; +uint32_t pool_base; +}TestFixture ; + +static const uint8_t tx_data[] = {0x10 ,0x11 ,0x12 }; +static const uint8_t rx_data[] = {0x30 ,0x31 ,0x32 }; + +#define DRAM_BASE 0x80000000 +#define DRAM_TX_OFFSET 0x1000 +#define DRAM_RX_OFFSET 0x2000 + +static void aspeed_i2c_write (TestFixture *f,uint32_t offset,uint32_t val) +{ +qtest_writel (global_qtest, f->base_addr + f->bus_offset + offset, val); +} + +static void aspeed_i2c_write_pool (TestFixture *f,uint32_t offset,uint8_t val) +{ +qtest_writeb (global_qtest, f->base_addr + f->pool_base + offset, val); +} + +static void aspeed_i2c_write_dma (TestFixture *f,uint32_t offset,uint8_t val) +{ +qtest_writeb (global_qtest,DRAM_BASE + offset, val); +} + +static uint32_t aspeed_i2c_read (TestFixture *f,uint32_t offset) +{ +return qtest_readl (global_qtest, f->base_addr + f->bus_offset + offset); +} + +static uint8_t aspeed_i2c_read_pool (TestFixture *f,uint32_t offset) +{ +return qtest_readb (global_qtest, f->base_addr + f->pool_base + offset); +} + +static uint8_t aspeed_i2c_read_dma (TestFixture *f,uint32_t offset) +{ +return qtest_readb (global_qtest,DRAM_BASE + offset); +} + +static bool aspeed_i2c_irq (TestFixture *f) +{ +return qtest_get_irq (global_qtest, f->irq_no); +} + +static uint32_t aspeed_i2c_ctrl_offset (const TestData *td) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +return A_I2CD_FUN_CTRL ; + }else { +return A_I2CC_FUN_CTRL ; + } +} + +static uint32_t aspeed_i2c_cmd_offset (const TestData *td) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +return A_I2CD_CMD ; + }else { +return A_I2CM_CMD ; + } +} + + +static uint32_t aspeed_i2c_intr_ctrl_offset (const TestData *td) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +return A_I2CD_INTR_CTRL ; + }else { +return A_I2CM_INTR_CTRL ; + } +} + +static uint32_t aspeed_i2c_intr_sts_offset (const TestData *td) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +return A_I2CD_INTR_STS ; + }else { +return A_I2CM_INTR_STS ; + } +} + +static uint32_t aspeed_i2c_pool_ctrl_offset (const TestData *td) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +return A_I2CD_POOL_CTRL ; + }else { +return A_I2CC_POOL_CTRL ; + } +} + +static uint32_t aspeed_i2c_byte_buf_offset (const TestData *td) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +return A_I2CD_BYTE_BUF ; + }else { +return A_I2CC_MS_TXRX_BYTE_BUF ; + } +} + +static void aspeed_i2c_write_slave_addr (TestFixture *f,const TestData *td, +uint8_t addr) +{ +if (td->mode ==TEST_I2C_MODE_OLD ) { +aspeed_i2c_write (f,A_I2CD_DEV_ADDR , addr); + }else { +aspeed_i2c_write (f,A_I2CS_DEV_ADDR , addr); + } +} + +static void aspeed_i2c_write_dma_addr (TestFixture *f,const TestData *td, +uint32_t val,bool rx) +{ +uint32_t offset; + +if (td->mode ==TEST_I2C_MODE_OLD ) { + offset =A_I2CD_DMA_ADDR ; + }else { + offset = rx ?A_I2CM_DMA_RX_ADDR :A_I2CM_DMA_TX_ADDR ; + } +aspeed_i2c_write (f, offset, val); +} + +static void aspeed_i2c_write_dma_len (TestFixture *f,const TestData *td, +uint16_t val,bool rx) +{ +uint32_t reg; + +if (td->mode ==TEST_I2C_MODE_OLD ) { +aspeed_i2c_write (f,A_I2CD_DMA_LEN , val +1 ); +return ; + } + +if (rx) { + reg =FIELD_DP32 (0 ,I2CM_DMA_LEN ,RX_BUF_LEN_W1T ,1 ); + reg =FIELD_DP32 (reg,I2CM_DMA_LEN ,RX_BUF_LEN , val); + }else { + reg =FIELD_DP32 (0 ,I2CM_DMA_LEN ,TX_BUF_LEN_W1T ,1 ); + reg =FIELD_DP32 (reg,I2CM_DMA_LEN ,TX_BUF_LEN , val); + } +aspeed_i2c_write (f,A_I2CM_DMA_LEN , reg); +} + +static uint8_t aspeed_i2c_get_txstate (TestFixture *f,const TestData *td) +{ +uint32_t offset; + +if (td->mode ==TEST_I2C_MODE_OLD ) { + offset =A_I2CD_CMD ; + }else { + offset =A_I2CC_MS_TXRX_BYTE_BUF ; + } +return SHARED_FIELD_EX32 (aspeed_i2c_read (f, offset),TX_STATE ); +} + +static bool aspeed_i2c_get_busy_sts (TestFixture *f,const TestData *td) +{ +uint32_t offset; + +if (td->mode ==TEST_I2C_MODE_OLD ) { + offset =A_I2CD_CMD ; + }else { + offset =A_I2CC_MS_TXRX_BYTE_BUF ; + } +return SHARED_FIELD_EX32 (aspeed_i2c_read (f, offset),BUS_BUSY_STS ); +} + +/* Write a data byte in a byte mode transfer */ +static +void aspeed_i2c_write_byte (TestFixture *f,const TestData *td,uint8_t val) +{ +aspeed_i2c_write (f,aspeed_i2c_byte_buf_offset (td), +SHARED_FIELD_DP32 (0 ,TX_BUF , val)); +} + +/* Read a data byte in a byte mode transfer */ +static uint8_t aspeed_i2c_read_byte (TestFixture *f,const TestData *td) +{ +uint32_t reg; + + reg =aspeed_i2c_read (f,aspeed_i2c_byte_buf_offset (td)); +return SHARED_FIELD_EX32 (reg,RX_BUF ); +} + +static void aspeed_i2c_send_start (TestFixture *f,const TestData *td, +uint32_t cmd) +{ + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +} + +static uint8_t qom_i2c_dummy_get_uint8 (const char *prop) +{ +QDict *r; +uint8_t u; + + r =qtest_qmp (global_qtest, +"{ 'execute': 'qom-get', 'arguments': " +"{ 'path': 'i2c-dummy', 'property': %s } }" , + prop); + u =qdict_get_uint (r,"return" ); +qobject_unref (r); +return u; +} + +static void qom_i2c_dummy_set_uint8 (const char *prop,uint8_t data) +{ +QDict *r; + + r =qtest_qmp (global_qtest, +"{ 'execute': 'qom-set', 'arguments': " +"{ 'path': 'i2c-dummy', 'property': %s, 'value': %d } }" , + prop, data); +qobject_unref (r); +} + +static void qom_i2c_dummy_set_rx (uint8_t idx,uint8_t data) +{ + g_autofree char *prop = g_strdup_printf("rx[%d]", idx); + +qom_i2c_dummy_set_uint8 (prop, data); +} + +static uint8_t qom_i2c_dummy_get_tx (int8_t idx) +{ + g_autofree char *prop = g_strdup_printf("tx[%d]", idx); + +return qom_i2c_dummy_get_uint8 (prop); +} + +#define I2C_ADDR_NACK 0x10 +#define I2C_ADDR_DUMMY 0x20 +#define I2C_ADDR_ECHO 0x30 +#define I2C_ADDR_SLAVE 0x40 + +#define CHECK_I2C_IDLE (f, td) do { \ + g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_IDLE); \ + g_assert_false(aspeed_i2c_get_busy_sts(f, td)); \ + g_assert_cmphex(aspeed_i2c_read(f, aspeed_i2c_intr_sts_offset(td)), ==, \ + 0); \ + g_assert_false(aspeed_i2c_irq(f)); \ +} while (0) + +#define CHECK_I2C_INTR (f, td, reg) do { \ + g_assert_true(aspeed_i2c_irq(f)); \ + g_assert_cmphex(aspeed_i2c_read(f, aspeed_i2c_intr_sts_offset(td)), ==, \ + reg); \ +} while (0) + +#define CHECK_I2C_BUS_ACTIVE (f, td) do { \ + g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MACTIVE); \ + g_assert_true(aspeed_i2c_get_busy_sts(f, td)); \ +} while (0) + +#define CHECK_I2C_ACK (f, td) do { \ + g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MACTIVE); \ + g_assert_true(aspeed_i2c_get_busy_sts(f, td)); \ + CLEAR_I2C_INTR(f, td, SHARED_FIELD_DP32(0, TX_ACK, 1)); \ +} while (0) + +#define CLEAR_I2C_INTR (f, td, reg) do { \ + CHECK_I2C_INTR(f, td, reg); \ + aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), reg); \ + g_assert_cmphex(aspeed_i2c_read(f, aspeed_i2c_intr_sts_offset(td)), ==, \ + 0); \ +} while (0) + +#define SEND_I2C_STOP (f, td) do { \ + aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), \ + SHARED_FIELD_DP32(0, M_STOP_CMD, 1)); \ + CLEAR_I2C_INTR(f, td, SHARED_FIELD_DP32(0, NORMAL_STOP, 1)); \ + CHECK_I2C_IDLE(f, td); \ +} while (0) + +#define CHECK_I2C_DUMMY_DEVICE () do { \ + for (uint8_t i = 0; i < ARRAY_SIZE(tx_data); i++) { \ + g_assert_cmphex(qom_i2c_dummy_get_tx(i), ==, tx_data[i]); \ + } \ + g_assert_cmphex(qom_i2c_dummy_get_uint8("tx-pos"), ==, \ + ARRAY_SIZE(tx_data)); \ + g_assert_cmphex(qom_i2c_dummy_get_uint8("rx-pos"), ==, \ + ARRAY_SIZE(rx_data)); \ +} while (0) + +static void aspeed_i2c_init (TestFixture *f,const TestData *td) +{ +uint32_t reg; + +qtest_qmp (global_qtest,"{ 'execute': 'system_reset' }" ); + +aspeed_i2c_write_slave_addr (f, td,I2C_ADDR_SLAVE ); + + reg =FIELD_DP32 (0 ,I2C_CTRL_GLOBAL ,SRAM_EN ,1 ); +if (td->mode !=TEST_I2C_MODE_OLD ) { + reg =FIELD_DP32 (reg,I2C_CTRL_GLOBAL ,REG_MODE ,1 ); + } +qtest_writel (global_qtest, f->base_addr +A_I2C_CTRL_GLOBAL , reg); + + reg =SHARED_FIELD_DP32 (0 ,MASTER_EN ,1 ); + reg =SHARED_FIELD_DP32 (reg,SLAVE_EN ,1 ); +aspeed_i2c_write (f,aspeed_i2c_ctrl_offset (td), reg); + +/* Enable all interrupts */ + reg =SHARED_FIELD_DP32 (0 ,TX_ACK ,1 ); + reg =SHARED_FIELD_DP32 (reg,TX_NAK ,1 ); + reg =SHARED_FIELD_DP32 (reg,RX_DONE ,1 ); + reg =SHARED_FIELD_DP32 (reg,ARBIT_LOSS ,1 ); + reg =SHARED_FIELD_DP32 (reg,NORMAL_STOP ,1 ); + reg =SHARED_FIELD_DP32 (reg,ABNORMAL ,1 ); +if (td->mode !=TEST_I2C_MODE_OLD ) { + reg =FIELD_DP32 (reg,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + reg =FIELD_DP32 (reg,I2CM_INTR_STS ,PKT_CMD_FAIL ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_intr_ctrl_offset (td), reg); + +for (uint8_t i =0 ; i <ARRAY_SIZE (rx_data); i++) { +qom_i2c_dummy_set_rx (i, rx_data[i]); + } +} + +static uint32_t aspeed_i2c_pkt_set_addr_cmd (const TestData *td,uint8_t addr) +{ +uint32_t cmd; + + cmd =FIELD_DP32 (0 ,I2CM_CMD ,PKT_OP_EN ,1 ); + cmd =FIELD_DP32 (cmd,I2CM_CMD ,PKT_DEV_ADDR , addr); +return cmd; +} + +static +uint32_t aspeed_i2c_byte_set_addr_cmd (TestFixture *f,const TestData *td, +uint8_t addr,bool is_recv) +{ +if (td->mode ==TEST_I2C_MODE_PKT ) { +return aspeed_i2c_pkt_set_addr_cmd (td, addr); + }else { +aspeed_i2c_write_byte (f, td, addr <<1 | (is_recv ?1 :0 )); +return SHARED_FIELD_DP32 (0 ,M_TX_CMD ,1 ); + } +} + +static +uint32_t aspeed_i2c_buf_set_addr_cmd (TestFixture *f,const TestData *td, +uint8_t addr,bool is_recv) +{ +if (td->mode ==TEST_I2C_MODE_PKT ) { +return aspeed_i2c_pkt_set_addr_cmd (td, addr); + }else { +aspeed_i2c_write_pool (f,0 , addr <<1 | (is_recv ?1 :0 )); +return SHARED_FIELD_DP32 (0 ,M_TX_CMD ,1 ); + } +} + +static +uint32_t aspeed_i2c_dma_set_addr_cmd (TestFixture *f,const TestData *td, +uint8_t addr,bool is_recv) +{ +if (td->mode ==TEST_I2C_MODE_PKT ) { +return aspeed_i2c_pkt_set_addr_cmd (td, addr); + }else { +aspeed_i2c_write_dma (f,DRAM_TX_OFFSET , addr <<1 | (is_recv ?1 :0 )); +return SHARED_FIELD_DP32 (0 ,M_TX_CMD ,1 ); + } +} + + +static uint32_t aspeed_i2c_send_addr_status (TestFixture *f,const TestData *td) +{ +uint32_t sts; + +if (td->mode ==TEST_I2C_MODE_PKT ) { + sts =FIELD_DP32 (0 ,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + }else { + sts =SHARED_FIELD_DP32 (0 ,TX_ACK ,1 ); + } +return sts; +} + +/* +* Send an address byte to a non existing device. +* The TX_NAK interrupt should be raised. +*/ +static void test_nack (TestFixture *f,gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; +uint32_t sts, cmd; + + cmd =aspeed_i2c_byte_set_addr_cmd (f, td,I2C_ADDR_NACK , false); +aspeed_i2c_send_start (f, td, cmd); + + g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MSTART); +g_assert_false (aspeed_i2c_get_busy_sts (f, td)); + sts =SHARED_FIELD_DP32 (0 ,TX_NAK ,1 ); +if (td->mode ==TEST_I2C_MODE_PKT ) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_FAIL ,1 ); + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + } +CLEAR_I2C_INTR (f, td, sts); + +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), +SHARED_FIELD_DP32 (0 ,M_STOP_CMD ,1 )); +CLEAR_I2C_INTR (f, td,SHARED_FIELD_DP32 (0 ,NORMAL_STOP ,1 )); +CHECK_I2C_IDLE (f, td); +qtest_hmp (global_qtest,"system_reset" ); +} + + +static void test_dummy_byte (TestFixture *f,gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; +uint32_t cmd, sts; +bool pkt_mode = td->mode ==TEST_I2C_MODE_PKT ; + +/* Write device address (Write) */ + cmd =aspeed_i2c_byte_set_addr_cmd (f, td,I2C_ADDR_DUMMY , false); +aspeed_i2c_send_start (f, td, cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td,aspeed_i2c_send_addr_status (f, td)); + +/* Write data */ + sts =SHARED_FIELD_DP32 (0 ,TX_ACK ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + cmd =aspeed_i2c_pkt_set_addr_cmd (td,I2C_ADDR_DUMMY ); + }else { + cmd =0 ; + } + cmd =SHARED_FIELD_DP32 (cmd,M_TX_CMD ,1 ); +for (uint8_t i =0 ; i <ARRAY_SIZE (tx_data); i++) { +aspeed_i2c_write_byte (f, td, tx_data[i]); +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td, sts); + } + +/* Read data */ + cmd =aspeed_i2c_byte_set_addr_cmd (f, td,I2C_ADDR_DUMMY , true); + cmd =SHARED_FIELD_DP32 (cmd,M_RX_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); + sts =aspeed_i2c_send_addr_status (f, td); + +for (uint8_t i =0 ; i <ARRAY_SIZE (rx_data); i++) { + cmd =SHARED_FIELD_DP32 (cmd,M_RX_CMD ,1 ); +if (i ==ARRAY_SIZE (rx_data) -1 ) { + cmd =SHARED_FIELD_DP32 (cmd,M_S_RX_CMD_LAST ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); + sts =SHARED_FIELD_DP32 (sts,RX_DONE ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + cmd =aspeed_i2c_pkt_set_addr_cmd (td,I2C_ADDR_DUMMY ); + }else { + cmd =0 ; + } +CLEAR_I2C_INTR (f, td, sts); + g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, rx_data[i]); + sts =0 ; + } + +SEND_I2C_STOP (f, td); +CHECK_I2C_DUMMY_DEVICE (); +qtest_hmp (global_qtest,"system_reset" ); +} + +static void test_dummy_buf (TestFixture *f,gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; +uint32_t cmd, sts, pool_ctrl; +bool pkt_mode = td->mode ==TEST_I2C_MODE_PKT ; + +/* Write data with device address */ +for (uint8_t i =0 ; i <ARRAY_SIZE (tx_data); i++) { +aspeed_i2c_write_pool (f, i + (pkt_mode ?0 :1 ), tx_data[i]); + } + pool_ctrl =SHARED_FIELD_DP32 (0 ,TX_COUNT , +ARRAY_SIZE (tx_data) - (pkt_mode ?1 :0 )); +aspeed_i2c_write (f,aspeed_i2c_pool_ctrl_offset (td), pool_ctrl); + cmd =aspeed_i2c_buf_set_addr_cmd (f, td,I2C_ADDR_DUMMY , false); + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,M_TX_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,TX_BUFF_EN ,1 ); + sts =SHARED_FIELD_DP32 (0 ,TX_ACK ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td, sts); + +/* Write device address (Read) in non packet mde */ +if (pkt_mode) { + cmd =aspeed_i2c_pkt_set_addr_cmd (td,I2C_ADDR_DUMMY ); + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); + }else { +aspeed_i2c_write_byte (f, td, (I2C_ADDR_DUMMY <<1 ) |1 ); +aspeed_i2c_send_start (f, td,SHARED_FIELD_DP32 (0 ,M_TX_CMD ,1 )); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td,aspeed_i2c_send_addr_status (f, td)); + cmd =0 ; + } + +/* Read data */ + pool_ctrl =SHARED_FIELD_DP32 (0 ,RX_SIZE , +ARRAY_SIZE (rx_data) -1 ); +aspeed_i2c_write (f,aspeed_i2c_pool_ctrl_offset (td), pool_ctrl); + cmd =SHARED_FIELD_DP32 (cmd,M_RX_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,M_S_RX_CMD_LAST ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,RX_BUFF_EN ,1 ); + sts =SHARED_FIELD_DP32 (0 ,RX_DONE ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td, sts); +for (uint8_t i =0 ; i <ARRAY_SIZE (rx_data); i++) { + g_assert_cmphex(aspeed_i2c_read_pool(f, i), ==, rx_data[i]); + } + +SEND_I2C_STOP (f, td); +CHECK_I2C_DUMMY_DEVICE (); +qtest_hmp (global_qtest,"system_reset" ); +} + +static void test_dummy_dma (TestFixture *f,gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; +uint32_t cmd, sts; +bool pkt_mode = td->mode ==TEST_I2C_MODE_PKT ; + +/* Write data with device address*/ +for (uint8_t i =0 ; i <ARRAY_SIZE (tx_data); i++) { +aspeed_i2c_write_dma (f,DRAM_TX_OFFSET + (pkt_mode ?0 :1 ) + i, + tx_data[i]); + } +aspeed_i2c_write_dma_addr (f, td,DRAM_TX_OFFSET , false); +aspeed_i2c_write_dma_len (f, td, +ARRAY_SIZE (tx_data) - (pkt_mode ?1 :0 ), false); + cmd =aspeed_i2c_dma_set_addr_cmd (f, td,I2C_ADDR_DUMMY , false); + + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,M_TX_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,TX_DMA_EN ,1 ); + sts =SHARED_FIELD_DP32 (0 ,TX_ACK ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td, sts); + +/* Write device address (Read) in non packet mode */ +if (pkt_mode) { + cmd =aspeed_i2c_pkt_set_addr_cmd (td,I2C_ADDR_DUMMY ); + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); + }else { +aspeed_i2c_write_byte (f, td, (I2C_ADDR_DUMMY <<1 ) |1 ); +aspeed_i2c_send_start (f, td,SHARED_FIELD_DP32 (0 ,M_TX_CMD ,1 )); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td,aspeed_i2c_send_addr_status (f, td)); + cmd =0 ; + } + +/* Read data */ +aspeed_i2c_write_dma_addr (f, td,DRAM_RX_OFFSET , true); +aspeed_i2c_write_dma_len (f, td,ARRAY_SIZE (rx_data) -1 , true); + cmd =SHARED_FIELD_DP32 (cmd,M_RX_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,M_S_RX_CMD_LAST ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,RX_DMA_EN ,1 ); + sts =SHARED_FIELD_DP32 (0 ,RX_DONE ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td, sts); +for (uint8_t i =0 ; i <ARRAY_SIZE (rx_data); i++) { + g_assert_cmphex(aspeed_i2c_read_dma(f, DRAM_RX_OFFSET + i), ==, + rx_data[i]); + } + +SEND_I2C_STOP (f, td); +CHECK_I2C_DUMMY_DEVICE (); +qtest_hmp (global_qtest,"system_reset" ); +} + +static void test_slave (TestFixture *f,gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; +uint32_t cmd, sts, tmp; +bool pkt_mode = td->mode ==TEST_I2C_MODE_PKT ; +uint8_t offset = pkt_mode ?0 :1 ; + +aspeed_i2c_write_pool (f, offset +0 ,I2C_ADDR_SLAVE ); +aspeed_i2c_write_pool (f, offset +1 , tx_data[0 ]); +aspeed_i2c_write_pool (f, offset +2 , tx_data[1 ]); + + tmp =SHARED_FIELD_DP32 (0 ,TX_COUNT , pkt_mode ?2 :3 ); +aspeed_i2c_write (f,aspeed_i2c_pool_ctrl_offset (td), tmp); + + cmd =aspeed_i2c_buf_set_addr_cmd (f, td,I2C_ADDR_ECHO , false); + cmd =SHARED_FIELD_DP32 (cmd,M_START_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,M_TX_CMD ,1 ); + cmd =SHARED_FIELD_DP32 (cmd,TX_BUFF_EN ,1 ); + sts =SHARED_FIELD_DP32 (0 ,TX_ACK ,1 ); +if (pkt_mode) { + sts =FIELD_DP32 (sts,I2CM_INTR_STS ,PKT_CMD_DONE ,1 ); + } +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), cmd); +CHECK_I2C_BUS_ACTIVE (f, td); +CLEAR_I2C_INTR (f, td, sts); + +/* Send stop and handle i2c-echo response as a slave */ +if (td->mode ==TEST_I2C_MODE_OLD ) { +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), +SHARED_FIELD_DP32 (0 ,M_STOP_CMD ,1 )); +clock_step (1 ); + g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, I2C_ADDR_SLAVE << 1); + sts =SHARED_FIELD_DP32 (0 ,NORMAL_STOP ,1 ); + sts =SHARED_FIELD_DP32 (sts,RX_DONE ,1 ); + sts =FIELD_DP32 (sts,I2CD_INTR_STS ,SLAVE_ADDR_RX_MATCH ,1 ); +CHECK_I2C_INTR (f, td, sts); +aspeed_i2c_write (f,aspeed_i2c_intr_sts_offset (td), sts); + + g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, tx_data[0]); + sts =SHARED_FIELD_DP32 (0 ,RX_DONE ,1 ); +CHECK_I2C_INTR (f, td, sts); +aspeed_i2c_write (f,aspeed_i2c_intr_sts_offset (td), sts); + + g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, tx_data[1]); + sts =SHARED_FIELD_DP32 (0 ,RX_DONE ,1 ); +CHECK_I2C_INTR (f, td, sts); +aspeed_i2c_write (f,aspeed_i2c_intr_sts_offset (td), sts); + }else { +aspeed_i2c_write (f,A_I2CS_DMA_RX_ADDR ,DRAM_RX_OFFSET ); + tmp =SHARED_FIELD_DP32 (0 ,RX_DMA_EN ,1 ); +aspeed_i2c_write (f,A_I2CS_CMD , tmp); + +aspeed_i2c_write (f,aspeed_i2c_cmd_offset (td), +SHARED_FIELD_DP32 (0 ,M_STOP_CMD ,1 )); +clock_step (1 ); + + tmp =FIELD_DP32 (0 ,I2CS_DMA_LEN_STS ,RX_LEN ,2 ); + g_assert_cmphex(aspeed_i2c_read(f, A_I2CS_DMA_LEN_STS), ==, tmp); +for (uint8_t i =0 ; i <2 ; i++) { + g_assert_cmphex(aspeed_i2c_read_dma(f, DRAM_RX_OFFSET + i), ==, + tx_data[i]); + } + } + + sts =SHARED_FIELD_DP32 (0 ,NORMAL_STOP ,1 ); +CLEAR_I2C_INTR (f, td, sts); +CHECK_I2C_IDLE (f, td); + +qtest_hmp (global_qtest,"system_reset" ); +} + +static void aspeed_i2c_init_fixture (TestFixture *fixture,const TestData *td) +{ +switch (td->machine) { +case TEST_MACHINE_AST2400 : + fixture->base_addr =0x1E78A000 ; + fixture->bus_offset =0x40 ; + fixture->irq_no =12 ; + fixture->pool_base =0x800 ; +break ; +case TEST_MACHINE_AST2500 : + fixture->base_addr =0x1E78A000 ; + fixture->bus_offset =0x40 ; + fixture->irq_no =12 ; + fixture->pool_base =0x200 ; +break ; +case TEST_MACHINE_AST2600 : + fixture->base_addr =0x1E78A000 ; + fixture->bus_offset =0x80 ; + fixture->irq_no =110 ; + fixture->pool_base =0xC00 ; +break ; +default : +return ; + } +} + +static void aspeed_i2c_init_test (TestFixture *fixture,const TestData *td) +{ +aspeed_i2c_init (fixture, td); +CHECK_I2C_IDLE (fixture, td); +} + +static void aspeed_i2c_init_new_machine (TestFixture *fixture, +gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; +const char *machine; +const char *irq_dev; + +aspeed_i2c_init_fixture (fixture, td); + +if (global_qtest) { +qtest_quit (global_qtest); + } + +switch (td->machine) { +case TEST_MACHINE_AST2400 : + machine ="palmetto-bmc" ; + irq_dev ="/machine/soc/vic" ; +break ; +case TEST_MACHINE_AST2500 : + machine ="ast2500-evb" ; + irq_dev ="/machine/soc/vic" ; +break ; +case TEST_MACHINE_AST2600 : + machine ="ast2600-evb" ; + irq_dev ="/machine/soc/a7mpcore/gic" ; +break ; +default : +g_test_fail (); +return ; + } + + global_qtest =qtest_initf ( +"-machine %s -nographic " +"-device i2c-echo,id=i2c-echo,bus=aspeed.i2c.bus.0,address=%d " +"-device i2c-dummy-device,id=i2c-dummy,bus=aspeed.i2c.bus.0,address=%d" , + machine,I2C_ADDR_ECHO ,I2C_ADDR_DUMMY ); +qtest_irq_intercept_in (global_qtest, irq_dev); + +aspeed_i2c_init_test (fixture, td); +} + +static void aspeed_i2c_init_machine (TestFixture *fixture, +gconstpointer p_data) +{ +const TestData *td = (const TestData *)p_data; + +aspeed_i2c_init_fixture (fixture, td); +aspeed_i2c_init_test (fixture, td); +} + +static void add_test (const TestData *td,const char *name, +void (*func)(TestFixture *,const void *), +bool setup) +{ + g_autofree char *test_name; + + test_name =g_strdup_printf ("%s/%s" , td->name, name); + +qtest_add (test_name, TestFixture, td, + setup ? aspeed_i2c_init_new_machine : aspeed_i2c_init_machine, + func,NULL ); +} + +#define ADD_TEST (td, test, new) add_test(td, #test, test_##test, new) + +static const TestData test_data[] = { + { + .name ="ast2400" , + .machine =TEST_MACHINE_AST2400 , + }, + { + .name ="ast2500" , + .machine =TEST_MACHINE_AST2500 , + }, + { + .name ="ast2600" , + .machine =TEST_MACHINE_AST2600 , + }, + { + .name ="ast2600-new" , + .machine =TEST_MACHINE_AST2600 , + .mode =TEST_I2C_MODE_NEW , + }, + { + .name ="ast2600-packet" , + .machine =TEST_MACHINE_AST2600 , + .mode =TEST_I2C_MODE_PKT , + }, +}; + +int main (int argc,char **argv) +{ +int ret; +bool setup; + +g_test_init (&argc, &argv,NULL ); + +for (int i =0 ; i <ARRAY_SIZE (test_data); i++) { + setup = i ==0 || test_data[i].machine != test_data[i -1 ].machine; +ADD_TEST (&test_data[i], nack, setup); +ADD_TEST (&test_data[i], dummy_byte, false); +ADD_TEST (&test_data[i], dummy_buf, false); +if (test_data[i].machine !=TEST_MACHINE_AST2400 ) { +ADD_TEST (&test_data[i], dummy_dma, false); + } +ADD_TEST (&test_data[i], slave, false); + } + + ret =g_test_run (); +qtest_quit (global_qtest); +return ret; +}tests/qtest/meson.build +2
-0@@ -233,12 +233,14 @@ qtests_aspeed = \ ['aspeed-acry-test', 'aspeed_gpio-test', 'aspeed_hace-test', + 'aspeed_i2c-test', 'aspeed-sbc-test', 'aspeed_scu-test', 'aspeed_smc-test'] qtests_aspeed64 = \ ['ast2700-gpio-test', 'ast2700-hace-test', + 'aspeed_i2c-test', 'ast2700-sgpio-test', 'ast2700-smc-test']
Re: [PATCH v2 6/6] tests/qtest: Add cases for 32-bit Aspeed I2C controllers
Hi, I thought about that, but I'm not sure how to do it because I haven't found previous examples in QEMU.
I guess there should be two test suites for ARM and AArch64 targets. But AArch64 also supports 32-bit ARM SoCs, so I'm not sure whether we should test them with the AArch64 target as well or if testing with the ARM target is enough.
Quoted 984 lines · Cédric Le Goater
Quoted 28 lines · Timur Maksimov
Test all supported register and transfer modes.
Signed-off-by Timur Maksimov <[email protected]>---
tests/qtest/aspeed_i2c-test.c| 836
++++++++++++++++++++++++++++++++++++++++++
tests/qtest/meson.build | 2 +2 files changed, 838 insertions(+)tests/qtest/aspeed_i2c-test.c new file +12
-0@@ -0,0 +1,836 @@ +/* +* QTest testcase for Aspeed I2C controller +* +* Copyright (c) 2026 Timur Maksimov <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later +*/ + +#include "qemu/osdep.h" +#include "libqtest-single.h" +#include "hw/i2c/aspeed_i2c.h" +tests/qtest/aspeed_i2c-test.c line 22
Quoted 10 lines
tests/qtest/aspeed_i2c-test.c new file +10
-0+typedef enum TestAspeedI2CMode { + TEST_I2C_MODE_OLD, + TEST_I2C_MODE_NEW, + TEST_I2C_MODE_PKT, +}TestAspeedI2CMode ; + +typedef enum TestAspeedMachine { + TEST_MACHINE_AST2400, + TEST_MACHINE_AST2500, + TEST_MACHINE_AST2600,Do you have plans to add AST2700 support ? This is the current focus now days.
Thanks,
C.
Quoted 934 lines
tests/qtest/aspeed_i2c-test.c new file +23
-0+} TestAspeedMachine; + +typedef struct TestData { + const char *name; + TestAspeedMachine machine; + TestAspeedI2CMode mode; +}TestData ; + +typedef struct TestFixture { + hwaddr base_addr; + hwaddr bus_offset; + int irq_no; + uint32_t pool_base; +}TestFixture ; + +static const uint8_t tx_data[] = {0x10 ,0x11 ,0x12 }; +static const uint8_t rx_data[] = {0x30 ,0x31 ,0x32 }; + +#define DRAM_BASE 0x80000000 +#define DRAM_TX_OFFSET 0x1000 +#define DRAM_RX_OFFSET 0x2000 + +static void aspeed_i2c_write(TestFixture *f, uint32_t offset,
uint32_tval)
+{
+qtest_writel(global_qtest, f->base_addr + f->bus_offset + offset, val);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static void aspeed_i2c_write_pool(TestFixture *f, uint32_t offset,
uint8_tval)
+{
+qtest_writeb(global_qtest, f->base_addr + f->pool_base + offset, val);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static void aspeed_i2c_write_dma(TestFixture *f, uint32_t offset,
uint8_tval)tests/qtest/aspeed_i2c-test.c new file +11
-0+{ + qtest_writeb(global_qtest, DRAM_BASE + offset, val); +} + +static uint32_t aspeed_i2c_read (TestFixture *f,uint32_t offset) +{ + return qtest_readl(global_qtest, f->base_addr + f->bus_offset + offset); +} + +static uint8_t aspeed_i2c_read_pool(TestFixture *f, uint32_toffset)
+{
+ returnqtest_readb(global_qtest, f->base_addr + f->pool_base + offset);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static uint8_t aspeed_i2c_read_dma(TestFixture *f, uint32_toffset)
tests/qtest/aspeed_i2c-test.c new file +65
-0+{ + return qtest_readb(global_qtest, DRAM_BASE + offset); +} + +static bool aspeed_i2c_irq (TestFixture *f) +{ + return qtest_get_irq(global_qtest, f->irq_no); +} + +static uint32_t aspeed_i2c_ctrl_offset (const TestData *td) +{ + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_FUN_CTRL; + } else { + return A_I2CC_FUN_CTRL; + } +} + +static uint32_t aspeed_i2c_cmd_offset (const TestData *td) +{ + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_CMD; + } else { + return A_I2CM_CMD; + } +} + + +static uint32_t aspeed_i2c_intr_ctrl_offset (const TestData *td) +{ + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_INTR_CTRL; + } else { + return A_I2CM_INTR_CTRL; + } +} + +static uint32_t aspeed_i2c_intr_sts_offset (const TestData *td) +{ + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_INTR_STS; + } else { + return A_I2CM_INTR_STS; + } +} + +static uint32_t aspeed_i2c_pool_ctrl_offset (const TestData *td) +{ + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_POOL_CTRL; + } else { + return A_I2CC_POOL_CTRL; + } +} + +static uint32_t aspeed_i2c_byte_buf_offset (const TestData *td) +{ + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_BYTE_BUF; + } else { + return A_I2CC_MS_TXRX_BYTE_BUF; + } +} + +static void aspeed_i2c_write_slave_addr(TestFixture *f, constTestData *td,
+uint8_taddr)tests/qtest/aspeed_i2c-test.c new file +9
-0+{ + if (td->mode == TEST_I2C_MODE_OLD) { + aspeed_i2c_write(f, A_I2CD_DEV_ADDR, addr); + } else { + aspeed_i2c_write(f, A_I2CS_DEV_ADDR, addr); + } +} + +static void aspeed_i2c_write_dma_addr(TestFixture *f, constTestData *td,
+uint32_tval, bool rx)tests/qtest/aspeed_i2c-test.c new file +12
-0+{ + uint32_t offset; + + if (td->mode == TEST_I2C_MODE_OLD) { + offset = A_I2CD_DMA_ADDR; + } else { + offset = rx ? A_I2CM_DMA_RX_ADDR : A_I2CM_DMA_TX_ADDR; + } + aspeed_i2c_write(f, offset, val); +} + +static void aspeed_i2c_write_dma_len(TestFixture *f, constTestData *td,
+uint16_tval, bool rx)tests/qtest/aspeed_i2c-test.c new file +19
-0+{ + uint32_t reg; + + if (td->mode == TEST_I2C_MODE_OLD) { + aspeed_i2c_write(f, A_I2CD_DMA_LEN, val + 1); + return; + } + + if (rx) { + reg = FIELD_DP32(0, I2CM_DMA_LEN, RX_BUF_LEN_W1T, 1); + reg = FIELD_DP32(reg, I2CM_DMA_LEN, RX_BUF_LEN, val); + } else { + reg = FIELD_DP32(0, I2CM_DMA_LEN, TX_BUF_LEN_W1T, 1); + reg = FIELD_DP32(reg, I2CM_DMA_LEN, TX_BUF_LEN, val); + } + aspeed_i2c_write(f, A_I2CM_DMA_LEN, reg); +} + +static uint8_t aspeed_i2c_get_txstate(TestFixture *f, constTestData *td)
tests/qtest/aspeed_i2c-test.c new file +9
-0+{ + uint32_t offset; + + if (td->mode == TEST_I2C_MODE_OLD) { + offset = A_I2CD_CMD; + } else { + offset = A_I2CC_MS_TXRX_BYTE_BUF; + } + return SHARED_FIELD_EX32(aspeed_i2c_read(f, offset),
TX_STATE);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static bool aspeed_i2c_get_busy_sts(TestFixture *f, const TestData*td)
tests/qtest/aspeed_i2c-test.c new file +9
-0+{ + uint32_t offset; + + if (td->mode == TEST_I2C_MODE_OLD) { + offset = A_I2CD_CMD; + } else { + offset = A_I2CC_MS_TXRX_BYTE_BUF; + } + return SHARED_FIELD_EX32(aspeed_i2c_read(f, offset),
BUS_BUSY_STS);tests/qtest/aspeed_i2c-test.c new file +5
-0+} + +/* Write a data byte in a byte mode transfer */ +static +void aspeed_i2c_write_byte(TestFixture *f, const TestData *td,
uint8_tval)tests/qtest/aspeed_i2c-test.c new file +7
-0+{ + aspeed_i2c_write(f, aspeed_i2c_byte_buf_offset(td), + SHARED_FIELD_DP32(0, TX_BUF, val)); +} + +/* Read a data byte in a byte mode transfer */ +static uint8_t aspeed_i2c_read_byte(TestFixture *f, const TestData*td)
tests/qtest/aspeed_i2c-test.c new file +8
-0+{ + uint32_t reg; + + reg = aspeed_i2c_read(f, aspeed_i2c_byte_buf_offset(td)); + return SHARED_FIELD_EX32(reg, RX_BUF); +} + +static void aspeed_i2c_send_start(TestFixture *f, const TestData*td,
+uint32_tcmd)tests/qtest/aspeed_i2c-test.c new file +20
-0+{ + cmd = SHARED_FIELD_DP32(cmd, M_START_CMD, 1); + aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +} + +static uint8_t qom_i2c_dummy_get_uint8 (const char *prop) +{ + QDict *r; + uint8_t u; + + r = qtest_qmp(global_qtest, + "{ 'execute': 'qom-get', 'arguments': " + "{ 'path': 'i2c-dummy', 'property': %s } }", + prop); + u = qdict_get_uint(r, "return"); + qobject_unref(r); + return u; +} + +static void qom_i2c_dummy_set_uint8(const char *prop, uint8_tdata)
tests/qtest/aspeed_i2c-test.c new file +6
-0+{ + QDict *r; + + r = qtest_qmp(global_qtest, + "{ 'execute': 'qom-set', 'arguments': " + "{ 'path': 'i2c-dummy', 'property': %s, 'value':%d } }",
+ prop, data);
+qobject_unref(r);tests/qtest/aspeed_i2c-test.c new file +22
-0+} + +static void qom_i2c_dummy_set_rx (uint8_t idx,uint8_t data) +{ + g_autofree char *prop = g_strdup_printf("rx[%d]", idx); + + qom_i2c_dummy_set_uint8(prop, data); +} + +static uint8_t qom_i2c_dummy_get_tx (int8_t idx) +{ + g_autofree char *prop = g_strdup_printf("tx[%d]", idx); + + return qom_i2c_dummy_get_uint8(prop); +} + +#define I2C_ADDR_NACK 0x10 +#define I2C_ADDR_DUMMY 0x20 +#define I2C_ADDR_ECHO 0x30 +#define I2C_ADDR_SLAVE 0x40 + +#define CHECK_I2C_IDLE (f, td) do{ \
+g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_IDLE); \
+g_assert_false(aspeed_i2c_get_busy_sts(f, td)); \
+ g_assert_cmphex(aspeed_i2c_read(f,aspeed_i2c_intr_sts_offset(td)), ==, \
+
0); \
+
g_assert_false(aspeed_i2c_irq(f));
\tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CHECK_I2C_INTR (f, td, reg) do{ \
+
g_assert_true(aspeed_i2c_irq(f));
\
+ g_assert_cmphex(aspeed_i2c_read(f,aspeed_i2c_intr_sts_offset(td)), ==, \
+
reg); \tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CHECK_I2C_BUS_ACTIVE (f, td) do{ \
+g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MACTIVE); \
+g_assert_true(aspeed_i2c_get_busy_sts(f, td)); \tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CHECK_I2C_ACK (f, td) do{ \
+g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MACTIVE); \
+g_assert_true(aspeed_i2c_get_busy_sts(f, td)); \
+CLEAR_I2C_INTR(f, td, SHARED_FIELD_DP32(0, TX_ACK, 1)); \tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CLEAR_I2C_INTR (f, td, reg) do{ \
+ CHECK_I2C_INTR(f, td,
reg); \
+aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), reg); \
+ g_assert_cmphex(aspeed_i2c_read(f,aspeed_i2c_intr_sts_offset(td)), ==, \
+
0); \tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define SEND_I2C_STOP (f, td) do{ \
+ aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), \
+SHARED_FIELD_DP32(0, M_STOP_CMD, 1)); \
+CLEAR_I2C_INTR(f, td, SHARED_FIELD_DP32(0, NORMAL_STOP, 1)); \
+ CHECK_I2C_IDLE(f,
td); \tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CHECK_I2C_DUMMY_DEVICE () do{ \
+ for (uint8_ti = 0; i <ARRAY_SIZE(tx_data); i++) { \
+g_assert_cmphex(qom_i2c_dummy_get_tx(i), ==, tx_data[i]); \
+
}
\
+ g_assert_cmphex(qom_i2c_dummy_get_uint8("tx-pos"), ==, \
+
ARRAY_SIZE(tx_data)); \
+ g_assert_cmphex(qom_i2c_dummy_get_uint8("rx-pos"), ==, \
+
ARRAY_SIZE(rx_data)); \tests/qtest/aspeed_i2c-test.c new file +15
-0+}while (0 ) + +static void aspeed_i2c_init(TestFixture *f, const TestData *td) +{ + uint32_t reg; + + qtest_qmp(global_qtest, "{ 'execute': 'system_reset' }"); + + aspeed_i2c_write_slave_addr(f, td, I2C_ADDR_SLAVE); + + reg = FIELD_DP32(0, I2C_CTRL_GLOBAL, SRAM_EN, 1); + if (td->mode != TEST_I2C_MODE_OLD) { + reg = FIELD_DP32(reg, I2C_CTRL_GLOBAL, REG_MODE, 1); + } + qtest_writel(global_qtest, f->base_addr + A_I2C_CTRL_GLOBAL,reg);
tests/qtest/aspeed_i2c-test.c new file +24
-0+ + reg = SHARED_FIELD_DP32(0, MASTER_EN, 1); + reg = SHARED_FIELD_DP32(reg, SLAVE_EN, 1); + aspeed_i2c_write(f, aspeed_i2c_ctrl_offset(td), reg); + + /* Enable all interrupts */ + reg = SHARED_FIELD_DP32(0, TX_ACK, 1); + reg = SHARED_FIELD_DP32(reg, TX_NAK, 1); + reg = SHARED_FIELD_DP32(reg, RX_DONE, 1); + reg = SHARED_FIELD_DP32(reg, ARBIT_LOSS, 1); + reg = SHARED_FIELD_DP32(reg, NORMAL_STOP, 1); + reg = SHARED_FIELD_DP32(reg, ABNORMAL, 1); + if (td->mode != TEST_I2C_MODE_OLD) { + reg = FIELD_DP32(reg, I2CM_INTR_STS, PKT_CMD_DONE, 1); + reg = FIELD_DP32(reg, I2CM_INTR_STS, PKT_CMD_FAIL, 1); + } + aspeed_i2c_write(f, aspeed_i2c_intr_ctrl_offset(td), reg); + + for (uint8_t i = 0; i < ARRAY_SIZE(rx_data); i++) { + qom_i2c_dummy_set_rx(i, rx_data[i]); + } +} + +static uint32_t aspeed_i2c_pkt_set_addr_cmd(const TestData *td,
uint8_taddr)tests/qtest/aspeed_i2c-test.c new file +10
-0+{ + uint32_t cmd; + + cmd = FIELD_DP32(0, I2CM_CMD, PKT_OP_EN, 1); + cmd = FIELD_DP32(cmd, I2CM_CMD, PKT_DEV_ADDR, addr); + return cmd; +} + +static +uint32_t aspeed_i2c_byte_set_addr_cmd(TestFixture *f, constTestData *td,
+uint8_taddr, boolis_recv) +{
+ if (td->mode==TEST_I2C_MODE_PKT) {
+ returnaspeed_i2c_pkt_set_addr_cmd(td, addr); + } else {
+ aspeed_i2c_write_byte(f, td, addr << 1 | (is_recv? 1 :
0));
+ returnSHARED_FIELD_DP32(0, M_TX_CMD, 1);
+ }tests/qtest/aspeed_i2c-test.c new file +4
-0+} + +static +uint32_t aspeed_i2c_buf_set_addr_cmd(TestFixture *f, constTestData *td,
+uint8_taddr, boolis_recv) +{
+ if (td->mode==TEST_I2C_MODE_PKT) {
+ returnaspeed_i2c_pkt_set_addr_cmd(td, addr); + } else {
+ aspeed_i2c_write_pool(f, 0, addr << 1 | (is_recv? 1 :
0));
+ returnSHARED_FIELD_DP32(0, M_TX_CMD, 1);
+ }tests/qtest/aspeed_i2c-test.c new file +4
-0+} + +static +uint32_t aspeed_i2c_dma_set_addr_cmd(TestFixture *f, constTestData *td,
+uint8_taddr, boolis_recv) +{
+ if (td->mode==TEST_I2C_MODE_PKT) {
+ returnaspeed_i2c_pkt_set_addr_cmd(td, addr); + } else {
+aspeed_i2c_write_dma(f, DRAM_TX_OFFSET, addr << 1 | (is_recv ? 1 : 0));
+ returnSHARED_FIELD_DP32(0, M_TX_CMD, 1);
+ }tests/qtest/aspeed_i2c-test.c new file +4
-0+} + + +static uint32_t aspeed_i2c_send_addr_status(TestFixture *f, constTestData *td)
tests/qtest/aspeed_i2c-test.c new file +21
-0+{ + uint32_t sts; + + if (td->mode == TEST_I2C_MODE_PKT) { + sts = FIELD_DP32(0, I2CM_INTR_STS, PKT_CMD_DONE, 1); + } else { + sts = SHARED_FIELD_DP32(0, TX_ACK, 1); + } + return sts; +} + +/* +* Send an address byte to a non existing device. +* The TX_NAK interrupt should be raised. +*/ +static void test_nack (TestFixture *f,gconstpointer p_data) +{ + const TestData *td = (const TestData *)p_data; + uint32_t sts, cmd; + + cmd = aspeed_i2c_byte_set_addr_cmd(f, td, I2C_ADDR_NACK,false);
+aspeed_i2c_send_start(f, td, cmd);
+
+g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MSTART);
+g_assert_false(aspeed_i2c_get_busy_sts(f, td)); + sts =SHARED_FIELD_DP32(0, TX_NAK, 1);
+ if (td->mode==TEST_I2C_MODE_PKT) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_FAIL, 1); + sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + }
+CLEAR_I2C_INTR(f, td, sts);tests/qtest/aspeed_i2c-test.c new file +17
-0+ + aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), + SHARED_FIELD_DP32(0, M_STOP_CMD, 1)); + CLEAR_I2C_INTR(f, td, SHARED_FIELD_DP32(0, NORMAL_STOP, 1)); + CHECK_I2C_IDLE(f, td); + qtest_hmp(global_qtest, "system_reset"); +} + + +static void test_dummy_byte (TestFixture *f,gconstpointer p_data) +{ + const TestData *td = (const TestData *)p_data; + uint32_t cmd, sts; + bool pkt_mode = td->mode == TEST_I2C_MODE_PKT; + + /* Write device address (Write) */ + cmd = aspeed_i2c_byte_set_addr_cmd(f, td, I2C_ADDR_DUMMY,false);
+aspeed_i2c_send_start(f, td, cmd);
+CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, aspeed_i2c_send_addr_status(f, td));tests/qtest/aspeed_i2c-test.c new file +19
-0+ + /* Write data */ + sts = SHARED_FIELD_DP32(0, TX_ACK, 1); + if (pkt_mode) { + sts = FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + cmd = aspeed_i2c_pkt_set_addr_cmd(td, I2C_ADDR_DUMMY); + } else { + cmd = 0; + } + cmd = SHARED_FIELD_DP32(cmd, M_TX_CMD, 1); + for (uint8_t i = 0; i < ARRAY_SIZE(tx_data); i++) { + aspeed_i2c_write_byte(f, td, tx_data[i]); + aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); + CHECK_I2C_BUS_ACTIVE(f, td); + CLEAR_I2C_INTR(f, td, sts); + } + + /* Read data */ + cmd = aspeed_i2c_byte_set_addr_cmd(f, td, I2C_ADDR_DUMMY,true);
+ cmd =SHARED_FIELD_DP32(cmd, M_RX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1);
+ sts =aspeed_i2c_send_addr_status(f, td);
+
+ for (uint8_ti = 0; i <ARRAY_SIZE(rx_data); i++) { + cmd =SHARED_FIELD_DP32(cmd, M_RX_CMD, 1);
+ if (i ==ARRAY_SIZE(rx_data)- 1) {
+ cmd =SHARED_FIELD_DP32(cmd, M_S_RX_CMD_LAST, 1); + }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+ sts =SHARED_FIELD_DP32(sts, RX_DONE, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + cmd =aspeed_i2c_pkt_set_addr_cmd(td, I2C_ADDR_DUMMY); + } else {
+ cmd = 0;
+ }
+CLEAR_I2C_INTR(f, td, sts);
+g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, rx_data[i]);
+ sts = 0;
+ }tests/qtest/aspeed_i2c-test.c new file +15
-0+ + SEND_I2C_STOP(f, td); + CHECK_I2C_DUMMY_DEVICE(); + qtest_hmp(global_qtest, "system_reset"); +} + +static void test_dummy_buf (TestFixture *f,gconstpointer p_data) +{ + const TestData *td = (const TestData *)p_data; + uint32_t cmd, sts, pool_ctrl; + bool pkt_mode = td->mode == TEST_I2C_MODE_PKT; + + /* Write data with device address */ + for (uint8_t i = 0; i < ARRAY_SIZE(tx_data); i++) { + aspeed_i2c_write_pool(f, i + (pkt_mode ? 0 : 1),tx_data[i]);
+ }
+pool_ctrl= SHARED_FIELD_DP32(0,TX_COUNT,
+ARRAY_SIZE(tx_data)- (pkt_mode? 1 : 0));
+aspeed_i2c_write(f, aspeed_i2c_pool_ctrl_offset(td), pool_ctrl);
+ cmd =aspeed_i2c_buf_set_addr_cmd(f, td, I2C_ADDR_DUMMY, false);
+ cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_TX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, TX_BUFF_EN, 1);
+ sts =SHARED_FIELD_DP32(0, TX_ACK, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+
+ /* Write device address (Read) in non packet mde */ + if (pkt_mode) {
+ cmd =aspeed_i2c_pkt_set_addr_cmd(td, I2C_ADDR_DUMMY); + cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1);
+ } else {
+aspeed_i2c_write_byte(f, td, (I2C_ADDR_DUMMY << 1) | 1); +aspeed_i2c_send_start(f, td, SHARED_FIELD_DP32(0, M_TX_CMD, 1));
+CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, aspeed_i2c_send_addr_status(f, td)); + cmd = 0;
+ }
+
+ /* Read data */
+pool_ctrl= SHARED_FIELD_DP32(0,RX_SIZE,
+ARRAY_SIZE(rx_data)- 1); +aspeed_i2c_write(f, aspeed_i2c_pool_ctrl_offset(td), pool_ctrl);
+ cmd =SHARED_FIELD_DP32(cmd, M_RX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_S_RX_CMD_LAST, 1);
+ cmd =SHARED_FIELD_DP32(cmd, RX_BUFF_EN, 1);
+ sts =SHARED_FIELD_DP32(0, RX_DONE, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+ for (uint8_ti = 0; i <ARRAY_SIZE(rx_data); i++) { +g_assert_cmphex(aspeed_i2c_read_pool(f, i), ==, rx_data[i]);
+ }tests/qtest/aspeed_i2c-test.c new file +15
-0+ + SEND_I2C_STOP(f, td); + CHECK_I2C_DUMMY_DEVICE(); + qtest_hmp(global_qtest, "system_reset"); +} + +static void test_dummy_dma (TestFixture *f,gconstpointer p_data) +{ + const TestData *td = (const TestData *)p_data; + uint32_t cmd, sts; + bool pkt_mode = td->mode == TEST_I2C_MODE_PKT; + + /* Write data with device address*/ + for (uint8_t i = 0; i < ARRAY_SIZE(tx_data); i++) { + aspeed_i2c_write_dma(f, DRAM_TX_OFFSET + (pkt_mode ? 0 :1) + i,
+ tx_data[i]);
+ }
+aspeed_i2c_write_dma_addr(f, td, DRAM_TX_OFFSET, false); + aspeed_i2c_write_dma_len(f, td,
+ARRAY_SIZE(tx_data)- (pkt_mode? 1 :
0), false);
+ cmd =aspeed_i2c_dma_set_addr_cmd(f, td, I2C_ADDR_DUMMY, false);tests/qtest/aspeed_i2c-test.c new file +19
-0+ + cmd = SHARED_FIELD_DP32(cmd, M_START_CMD, 1); + cmd = SHARED_FIELD_DP32(cmd, M_TX_CMD, 1); + cmd = SHARED_FIELD_DP32(cmd, TX_DMA_EN, 1); + sts = SHARED_FIELD_DP32(0, TX_ACK, 1); + if (pkt_mode) { + sts = FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + } + aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); + CHECK_I2C_BUS_ACTIVE(f, td); + CLEAR_I2C_INTR(f, td, sts); + + /* Write device address (Read) in non packet mode */ + if (pkt_mode) { + cmd = aspeed_i2c_pkt_set_addr_cmd(td, I2C_ADDR_DUMMY); + cmd = SHARED_FIELD_DP32(cmd, M_START_CMD, 1); + } else { + aspeed_i2c_write_byte(f, td, (I2C_ADDR_DUMMY << 1) | 1); + aspeed_i2c_send_start(f, td, SHARED_FIELD_DP32(0,
M_TX_CMD, 1));
+CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, aspeed_i2c_send_addr_status(f, td)); + cmd = 0;
+ }
+
+ /* Read data */
+aspeed_i2c_write_dma_addr(f, td, DRAM_RX_OFFSET, true); +aspeed_i2c_write_dma_len(f, td, ARRAY_SIZE(rx_data) - 1, true);
+ cmd =SHARED_FIELD_DP32(cmd, M_RX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_S_RX_CMD_LAST, 1);
+ cmd =SHARED_FIELD_DP32(cmd, RX_DMA_EN, 1);
+ sts =SHARED_FIELD_DP32(0, RX_DONE, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+ for (uint8_ti = 0; i <ARRAY_SIZE(rx_data); i++) { + g_assert_cmphex(aspeed_i2c_read_dma(f,DRAM_RX_OFFSET+ i), ==,
+ rx_data[i]);
+ }tests/qtest/aspeed_i2c-test.c new file +21
-0+ + SEND_I2C_STOP(f, td); + CHECK_I2C_DUMMY_DEVICE(); + qtest_hmp(global_qtest, "system_reset"); +} + +static void test_slave (TestFixture *f,gconstpointer p_data) +{ + const TestData *td = (const TestData *)p_data; + uint32_t cmd, sts, tmp; + bool pkt_mode = td->mode == TEST_I2C_MODE_PKT; + uint8_t offset = pkt_mode ? 0 : 1; + + aspeed_i2c_write_pool(f, offset + 0, I2C_ADDR_SLAVE); + aspeed_i2c_write_pool(f, offset + 1, tx_data[0]); + aspeed_i2c_write_pool(f, offset + 2, tx_data[1]); + + tmp = SHARED_FIELD_DP32(0, TX_COUNT, pkt_mode ? 2 : 3); + aspeed_i2c_write(f, aspeed_i2c_pool_ctrl_offset(td), tmp); + + cmd = aspeed_i2c_buf_set_addr_cmd(f, td, I2C_ADDR_ECHO,false);
+ cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_TX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, TX_BUFF_EN, 1);
+ sts =SHARED_FIELD_DP32(0, TX_ACK, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+
+ /* Send stop and handle i2c-echo response as a slave */ + if (td->mode==TEST_I2C_MODE_OLD) {
+ aspeed_i2c_write(f,aspeed_i2c_cmd_offset(td), +SHARED_FIELD_DP32(0, M_STOP_CMD, 1)); +clock_step(1);
+g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, I2C_ADDR_SLAVE << 1);
+ sts =SHARED_FIELD_DP32(0, NORMAL_STOP, 1);
+ sts =SHARED_FIELD_DP32(sts, RX_DONE, 1);
+ sts =FIELD_DP32(sts, I2CD_INTR_STS, SLAVE_ADDR_RX_MATCH, 1);
+CHECK_I2C_INTR(f, td, sts);
+aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), sts); +
+g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, tx_data[0]);
+ sts =SHARED_FIELD_DP32(0, RX_DONE, 1);
+CHECK_I2C_INTR(f, td, sts);
+aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), sts); +
+g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, tx_data[1]);
+ sts =SHARED_FIELD_DP32(0, RX_DONE, 1);
+CHECK_I2C_INTR(f, td, sts);
+aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), sts); + } else {
+aspeed_i2c_write(f, A_I2CS_DMA_RX_ADDR, DRAM_RX_OFFSET); + tmp =SHARED_FIELD_DP32(0, RX_DMA_EN, 1);
+aspeed_i2c_write(f, A_I2CS_CMD, tmp);tests/qtest/aspeed_i2c-test.c new file +7
-0+ + aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), + SHARED_FIELD_DP32(0, M_STOP_CMD, 1)); + clock_step(1); + + tmp = FIELD_DP32(0, I2CS_DMA_LEN_STS, RX_LEN, 2); + g_assert_cmphex(aspeed_i2c_read(f, A_I2CS_DMA_LEN_STS),==, tmp);
+ for (uint8_ti = 0; i < 2; i++) {
+ g_assert_cmphex(aspeed_i2c_read_dma(f,DRAM_RX_OFFSET
+ i), ==,
+ tx_data[i]);
+ }
+ }tests/qtest/aspeed_i2c-test.c new file +9
-0+ + sts = SHARED_FIELD_DP32(0, NORMAL_STOP, 1); + CLEAR_I2C_INTR(f, td, sts); + CHECK_I2C_IDLE(f, td); + + qtest_hmp(global_qtest, "system_reset"); +} + +static void aspeed_i2c_init_fixture(TestFixture *fixture, constTestData *td)
tests/qtest/aspeed_i2c-test.c new file +26
-0+{ + switch (td->machine) { + case TEST_MACHINE_AST2400: + fixture->base_addr = 0x1E78A000; + fixture->bus_offset = 0x40; + fixture->irq_no = 12; + fixture->pool_base = 0x800; + break; + case TEST_MACHINE_AST2500: + fixture->base_addr = 0x1E78A000; + fixture->bus_offset = 0x40; + fixture->irq_no = 12; + fixture->pool_base = 0x200; + break; + case TEST_MACHINE_AST2600: + fixture->base_addr = 0x1E78A000; + fixture->bus_offset = 0x80; + fixture->irq_no = 110; + fixture->pool_base = 0xC00; + break; + default: + return; + } +} + +static void aspeed_i2c_init_test(TestFixture *fixture, constTestData *td)
tests/qtest/aspeed_i2c-test.c new file +39
-0+{ + aspeed_i2c_init(fixture, td); + CHECK_I2C_IDLE(fixture, td); +} + +static void aspeed_i2c_init_new_machine(TestFixture *fixture, + gconstpointer p_data) +{ + const TestData *td = (const TestData *)p_data; + const char *machine; + const char *irq_dev; + + aspeed_i2c_init_fixture(fixture, td); + + if (global_qtest) { + qtest_quit(global_qtest); + } + + switch (td->machine) { + case TEST_MACHINE_AST2400: + machine = "palmetto-bmc"; + irq_dev = "/machine/soc/vic"; + break; + case TEST_MACHINE_AST2500: + machine = "ast2500-evb"; + irq_dev = "/machine/soc/vic"; + break; + case TEST_MACHINE_AST2600: + machine = "ast2600-evb"; + irq_dev = "/machine/soc/a7mpcore/gic"; + break; + default: + g_test_fail(); + return; + } + + global_qtest = qtest_initf( + "-machine %s -nographic " + "-device i2c-echo,id=i2c-echo,bus=aspeed.i2c.bus.0,address=%d "
+ "-device i2c-dummy-device,id=i2c- dummy,bus=aspeed.i2c.bus.0,address=%d",
+ machine,I2C_ADDR_ECHO,I2C_ADDR_DUMMY); +qtest_irq_intercept_in(global_qtest, irq_dev);tests/qtest/aspeed_i2c-test.c new file +23
-0+ + aspeed_i2c_init_test(fixture, td); +} + +static void aspeed_i2c_init_machine (TestFixture *fixture, + gconstpointer p_data) +{ + const TestData *td = (const TestData *)p_data; + + aspeed_i2c_init_fixture(fixture, td); + aspeed_i2c_init_test(fixture, td); +} + +static void add_test (const TestData *td,const char *name, + void (*func)(TestFixture *, const void *), + bool setup) +{ + g_autofree char *test_name; + + test_name = g_strdup_printf("%s/%s", td->name, name); + + qtest_add(test_name, TestFixture, td, + setup ? aspeed_i2c_init_new_machine :
aspeed_i2c_init_machine,
+ func, NULL);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +#define ADD_TEST (td, test, new) add_test(td, #test, test_##test,new)
tests/qtest/aspeed_i2c-test.c new file +35
-0+ +static const TestData test_data[] = { + { + .name = "ast2400", + .machine = TEST_MACHINE_AST2400, + }, + { + .name = "ast2500", + .machine = TEST_MACHINE_AST2500, + }, + { + .name = "ast2600", + .machine = TEST_MACHINE_AST2600, + }, + { + .name = "ast2600-new", + .machine = TEST_MACHINE_AST2600, + .mode = TEST_I2C_MODE_NEW, + }, + { + .name = "ast2600-packet", + .machine = TEST_MACHINE_AST2600, + .mode = TEST_I2C_MODE_PKT, + }, +}; + +int main (int argc,char **argv) +{ + int ret; + bool setup; + + g_test_init(&argc, &argv, NULL); + + for (int i = 0; i < ARRAY_SIZE(test_data); i++) { + setup = i == 0 || test_data[i].machine != test_data[i -1].machine;
+ADD_TEST(&test_data[i], nack, setup);
+ADD_TEST(&test_data[i], dummy_byte, false); +ADD_TEST(&test_data[i], dummy_buf, false); + if (test_data[i].machine !=TEST_MACHINE_AST2400) { +ADD_TEST(&test_data[i], dummy_dma, false); + }
+ADD_TEST(&test_data[i], slave, false);
+ }tests/qtest/aspeed_i2c-test.c new file +5
-0+ + ret = g_test_run(); + qtest_quit(global_qtest); + return ret; +}tests/qtest/meson.build +1
-0@@ -233,12 +233,14 @@ qtests_aspeed = \ ['aspeed-acry-test', 'aspeed_gpio-test', 'aspeed_hace-test', + 'aspeed_i2c-test', 'aspeed-sbc-test', 'aspeed_scu-test','aspeed_smc-test']
qtests_aspeed64= \
['ast2700-gpio-test',
'ast2700-hace-test',
+ 'aspeed_i2c-test',
'ast2700-sgpio-test',
'ast2700-smc-test']
RE: [PATCH v2 6/6] tests/qtest: Add cases for 32-bit Aspeed I2C controllers
Quoted 7 lines
Hi, I thought about that, but I'm not sure how to do it because I haven't found previous examples in QEMU.
I guess there should be two test suites for ARM and AArch64 targets. But AArch64 also supports 32-bit ARM SoCs, so I'm not sure whether we should test them with the AArch64 target as well or if testing with the ARM target is enough.
Please refer to ast2700-hace-test.c, aspeed-hace-utils.c, and aspeed_hace-test.c as examples of HACE tests for AArch64 (AST2700) and ARM32 (AST2500, AST2600, and AST1030).
Quoted 286 lines · Cédric Le Goater
Quoted 152 lines · Timur Maksimov
Quoted 26 lines
Test all supported register and transfer modes.
Signed-off-by Timur Maksimov <[email protected]>---
tests/qtest/aspeed_i2c-test.c| 836
++++++++++++++++++++++++++++++++++++++++++
tests/qtest/meson.build | 2 +2 files changed, 838 insertions(+)(quoted diff) +0
-0
b/tests/qtest/aspeed_i2c-test.cnew file mode 100644 index 0000000000..7fb1debb56tests/qtest/aspeed_i2c-test.c new file +11
-0@@ -0,0 +1,836 @@ +/* +* QTest testcase for Aspeed I2C controller +* +* Copyright (c) 2026 Timur Maksimov <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" +#include "libqtest-single.h" +#include "hw/i2c/aspeed_i2c.h" +tests/qtest/aspeed_i2c-test.c line 21
Quoted 10 lines
tests/qtest/aspeed_i2c-test.c new file +10
-0+typedef enum TestAspeedI2CMode { + TEST_I2C_MODE_OLD, + TEST_I2C_MODE_NEW, + TEST_I2C_MODE_PKT, +}TestAspeedI2CMode ; + +typedef enum TestAspeedMachine { + TEST_MACHINE_AST2400, + TEST_MACHINE_AST2500, + TEST_MACHINE_AST2600,Do you have plans to add AST2700 support ? This is the current focus now days.
Thanks,
C.
Quoted 104 lines
tests/qtest/aspeed_i2c-test.c new file +23
-0+} TestAspeedMachine; + +typedef struct TestData { + const char *name; + TestAspeedMachine machine; + TestAspeedI2CMode mode; +}TestData ; + +typedef struct TestFixture { + hwaddr base_addr; + hwaddr bus_offset; + int irq_no; + uint32_t pool_base; +}TestFixture ; + +static const uint8_t tx_data[] = {0x10 ,0x11 ,0x12 };static const +uint8_t rx_data[] = {0x30 ,0x31 ,0x32 }; + +#define DRAM_BASE 0x80000000 +#define DRAM_TX_OFFSET 0x1000 +#define DRAM_RX_OFFSET 0x2000 + +static void aspeed_i2c_write(TestFixture *f, uint32_t offset,
uint32_tval)
+{
+qtest_writel(global_qtest, f->base_addr + f->bus_offset + offset, val);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static void aspeed_i2c_write_pool(TestFixture *f, uint32_t offset,
uint8_tval)
+{
+qtest_writeb(global_qtest, f->base_addr + f->pool_base + offset, val);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static void aspeed_i2c_write_dma(TestFixture *f, uint32_t offset,
uint8_tval)tests/qtest/aspeed_i2c-test.c new file +8
-0+{ + qtest_writeb(global_qtest, DRAM_BASE + offset, val); } + +static uint32_t aspeed_i2c_read (TestFixture *f,uint32_t offset) { + return qtest_readl(global_qtest, f->base_addr + f->bus_offset +offset); } + +static uint8_t aspeed_i2c_read_pool(TestFixture *f, uint32_toffset)
+{
+ returnqtest_readb(global_qtest, f->base_addr + f->pool_base + offset);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static uint8_t aspeed_i2c_read_dma(TestFixture *f, uint32_toffset)
tests/qtest/aspeed_i2c-test.c new file +50
-0+{ + return qtest_readb(global_qtest, DRAM_BASE + offset); } + +static bool aspeed_i2c_irq (TestFixture *f) { + return qtest_get_irq(global_qtest, f->irq_no); } + +static uint32_t aspeed_i2c_ctrl_offset (const TestData *td) { + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_FUN_CTRL; + } else { + return A_I2CC_FUN_CTRL; + } +} + +static uint32_t aspeed_i2c_cmd_offset (const TestData *td) { + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_CMD; + } else { + return A_I2CM_CMD; + } +} + + +static uint32_t aspeed_i2c_intr_ctrl_offset (const TestData *td) { + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_INTR_CTRL; + } else { + return A_I2CM_INTR_CTRL; + } +} + +static uint32_t aspeed_i2c_intr_sts_offset (const TestData *td) { + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_INTR_STS; + } else { + return A_I2CM_INTR_STS; + } +} + +static uint32_t aspeed_i2c_pool_ctrl_offset (const TestData *td) { + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_POOL_CTRL; + } else { + return A_I2CC_POOL_CTRL; + } +} + +static uint32_t aspeed_i2c_byte_buf_offset (const TestData *td) { + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_BYTE_BUF;Quoted 8 lines
Quoted 8 lines
+ } else {
+ returnA_I2CC_MS_TXRX_BYTE_BUF;
+ }tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static void aspeed_i2c_write_slave_addr(TestFixture *f, constTestData *td,
+uint8_taddr){
Quoted 10 lines
Quoted 10 lines
+ if (
td->mode==TEST_I2C_MODE_OLD) {
+aspeed_i2c_write(f, A_I2CD_DEV_ADDR, addr); + } else {
+aspeed_i2c_write(f, A_I2CS_DEV_ADDR, addr); + }tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static void aspeed_i2c_write_dma_addr(TestFixture *f, constTestData *td,
+uint32_tval, boolrx) {
Quoted 6 lines
Quoted 6 lines
+
uint32_toffset;
+
+ if (td->mode==TEST_I2C_MODE_OLD) {
+ offset =A_I2CD_DMA_ADDR;
+ } else {
+ offset = rx ?A_I2CM_DMA_RX_ADDR:
A_I2CM_DMA_TX_ADDR;Quoted 6 lines
Quoted 6 lines
+ }
+aspeed_i2c_write(f, offset, val); }tests/qtest/aspeed_i2c-test.c new file +2
-0+ +static void aspeed_i2c_write_dma_len(TestFixture *f, constTestData *td,
+uint16_tval, boolrx) {
Quoted 99 lines
Quoted 99 lines
+
uint32_treg;tests/qtest/aspeed_i2c-test.c new file +16
-0+ + if (td->mode == TEST_I2C_MODE_OLD) { + aspeed_i2c_write(f, A_I2CD_DMA_LEN, val + 1); + return; + } + + if (rx) { + reg = FIELD_DP32(0, I2CM_DMA_LEN, RX_BUF_LEN_W1T, 1); + reg = FIELD_DP32(reg, I2CM_DMA_LEN, RX_BUF_LEN, val); + } else { + reg = FIELD_DP32(0, I2CM_DMA_LEN, TX_BUF_LEN_W1T, 1); + reg = FIELD_DP32(reg, I2CM_DMA_LEN, TX_BUF_LEN, val); + } + aspeed_i2c_write(f, A_I2CM_DMA_LEN, reg); } + +static uint8_t aspeed_i2c_get_txstate(TestFixture *f, constTestData *td)
tests/qtest/aspeed_i2c-test.c new file +9
-0+{ + uint32_t offset; + + if (td->mode == TEST_I2C_MODE_OLD) { + offset = A_I2CD_CMD; + } else { + offset = A_I2CC_MS_TXRX_BYTE_BUF; + } + return SHARED_FIELD_EX32(aspeed_i2c_read(f, offset),
TX_STATE);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static bool aspeed_i2c_get_busy_sts(TestFixture *f, const TestData*td)
tests/qtest/aspeed_i2c-test.c new file +9
-0+{ + uint32_t offset; + + if (td->mode == TEST_I2C_MODE_OLD) { + offset = A_I2CD_CMD; + } else { + offset = A_I2CC_MS_TXRX_BYTE_BUF; + } + return SHARED_FIELD_EX32(aspeed_i2c_read(f, offset),
BUS_BUSY_STS);tests/qtest/aspeed_i2c-test.c new file +4
-0+} + +/* Write a data byte in a byte mode transfer */ static void +aspeed_i2c_write_byte(TestFixture *f, const TestData *td,
uint8_tval)tests/qtest/aspeed_i2c-test.c new file +6
-0+{ + aspeed_i2c_write(f, aspeed_i2c_byte_buf_offset(td), + SHARED_FIELD_DP32(0, TX_BUF, val)); } + +/* Read a data byte in a byte mode transfer */ static uint8_t +aspeed_i2c_read_byte(TestFixture *f, const TestData*td)
tests/qtest/aspeed_i2c-test.c new file +7
-0+{ + uint32_t reg; + + reg = aspeed_i2c_read(f, aspeed_i2c_byte_buf_offset(td)); + return SHARED_FIELD_EX32(reg, RX_BUF); } + +static void aspeed_i2c_send_start(TestFixture *f, const TestData*td,
+uint32_tcmd) { + cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1); +aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); }tests/qtest/aspeed_i2c-test.c new file +15
-0+ +static uint8_t qom_i2c_dummy_get_uint8 (const char *prop) { + QDict *r; + uint8_t u; + + r = qtest_qmp(global_qtest, + "{ 'execute': 'qom-get', 'arguments': " + "{ 'path': 'i2c-dummy', 'property': %s } }", + prop); + u = qdict_get_uint(r, "return"); + qobject_unref(r); + return u; +} + +static void qom_i2c_dummy_set_uint8(const char *prop, uint8_tdata)
tests/qtest/aspeed_i2c-test.c new file +6
-0+{ + QDict *r; + + r = qtest_qmp(global_qtest, + "{ 'execute': 'qom-set', 'arguments': " + "{ 'path': 'i2c-dummy', 'property': %s, 'value':%d } }",
+ prop, data);
+qobject_unref(r);tests/qtest/aspeed_i2c-test.c new file +9
-0+} + +static void qom_i2c_dummy_set_rx (uint8_t idx,uint8_t data) { + g_autofree char *prop = g_strdup_printf("rx[%d]", idx); + + qom_i2c_dummy_set_uint8(prop, data); } + +static uint8_t qom_i2c_dummy_get_tx (int8_t idx) { + g_autofree char *prop = g_strdup_printf("tx[%d]", idx);
Quoted 8 lines
Quoted 8 lines
tests/qtest/aspeed_i2c-test.c line 269
Quoted 8 lines
tests/qtest/aspeed_i2c-test.c new file +8
-0+ + return qom_i2c_dummy_get_uint8(prop); } + +#define I2C_ADDR_NACK 0x10 +#define I2C_ADDR_DUMMY 0x20 +#define I2C_ADDR_ECHO 0x30 +#define I2C_ADDR_SLAVE 0x40 +
Could these be static helper functions instead of multi-line macros? They do not need anything a function cannot do, and functions would be easier to read and type-checked. I understand the macros make g_assert report the caller's line, but the qtest path and the tap output already tell us which test failed.
Also, CHECK_I2C_ACK() is not used anywhere, so it can be dropped.
Quoted 95 lines
Quoted 10 lines
Quoted 10 lines
+#define
CHECK_I2C_IDLE(f, td)do
{ \
+g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_IDLE); \
+g_assert_false(aspeed_i2c_get_busy_sts(f, td)); \
+ g_assert_cmphex(aspeed_i2c_read(f,aspeed_i2c_intr_sts_offset(td)), ==, \
+0);
\Quoted 6 lines
Quoted 6 lines
+
g_assert_false(aspeed_i2c_irq(f));
\tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CHECK_I2C_INTR (f, td, reg) doQuoted 8 lines
Quoted 8 lines
{ \
+
g_assert_true(aspeed_i2c_irq(f));
\
+ g_assert_cmphex(aspeed_i2c_read(f,aspeed_i2c_intr_sts_offset(td)), ==, \
+reg);
\Quoted 22 lines
Quoted 22 lines
tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CHECK_I2C_BUS_ACTIVE (f, td) do{ \
+g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MACTIVE); \
+g_assert_true(aspeed_i2c_get_busy_sts(f, td)); \tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CHECK_I2C_ACK (f, td) do{ \
+g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MACTIVE); \
+g_assert_true(aspeed_i2c_get_busy_sts(f, td)); \
+CLEAR_I2C_INTR(f, td, SHARED_FIELD_DP32(0, TX_ACK, 1)); \tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CLEAR_I2C_INTR (f, td, reg) do{ \
Quoted 8 lines
Quoted 8 lines
+ CHECK_I2C_INTR(f, td,
reg); \
+aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), reg); \
+ g_assert_cmphex(aspeed_i2c_read(f,aspeed_i2c_intr_sts_offset(td)), ==, \
+0);
\Quoted 4 lines
Quoted 4 lines
tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define SEND_I2C_STOP (f, td) do{ \
Quoted 8 lines
Quoted 8 lines
+ aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), \
+SHARED_FIELD_DP32(0, M_STOP_CMD, 1)); \
+CLEAR_I2C_INTR(f, td, SHARED_FIELD_DP32(0, NORMAL_STOP, 1)); \
+ CHECK_I2C_IDLE(f,td);
\Quoted 7 lines
Quoted 7 lines
tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CHECK_I2C_DUMMY_DEVICE () do{ \
+ for (uint8_ti = 0; i <ARRAY_SIZE(tx_data); i++) { \
+ g_assert_cmphex(qom_i2c_dummy_get_tx(i), ==,Quoted 8 lines
Quoted 8 lines
tx_data[i]); \
+
}
\
+ g_assert_cmphex(qom_i2c_dummy_get_uint8("tx-pos"), ==, \
+ARRAY_SIZE(tx_data)); \
Quoted 4 lines
Quoted 4 lines
+ g_assert_cmphex(qom_i2c_dummy_get_uint8("rx-pos"), ==, \
+ARRAY_SIZE(rx_data)); \
Quoted 9 lines
Quoted 9 lines
tests/qtest/aspeed_i2c-test.c line 326
Quoted 9 lines
tests/qtest/aspeed_i2c-test.c new file +9
-0+}while (0 ) + +static void aspeed_i2c_init(TestFixture *f, const TestData *td) { + uint32_t reg; + + qtest_qmp(global_qtest, "{ 'execute': 'system_reset' }"); + + aspeed_i2c_write_slave_addr(f, td, I2C_ADDR_SLAVE); +
The slave address is written before the register
mode is switched:
For the new register mode tests, aspeed_i2c_write_slave_addr() writes I2CS_DEV_ADDR (offset 0x40), but the controller is still in old register mode at that point, so the write is dropped as a bad offset. The slave address is never programmed, and the slave test only passes because an earlier test left the controller in new register mode.
Running the slave test on its own fails every time:
QTEST_QEMU_BINARY=./qemu-system-arm ./tests/qtest/aspeed_i2c-test \
-p /arm/ast2600/nack -p /arm/ast2600-new/slave ERROR: test_slave: assertion failed
(aspeed_i2c_read(f, A_I2CS_DMA_LEN_STS) == tmp): (0x00000000 == 0x00020000)
(/arm/ast2600/nack is only there to start the machine.)
Thanks,
Jamin
Quoted 578 lines
Quoted 35 lines
Quoted 35 lines
+ reg =
FIELD_DP32(0, I2C_CTRL_GLOBAL, SRAM_EN, 1); + if (td->mode!=TEST_I2C_MODE_OLD) {
+ reg =FIELD_DP32(reg, I2C_CTRL_GLOBAL, REG_MODE, 1); + }
+qtest_writel(global_qtest, f->base_addr + A_I2C_CTRL_GLOBAL, reg);tests/qtest/aspeed_i2c-test.c new file +24
-0+ + reg = SHARED_FIELD_DP32(0, MASTER_EN, 1); + reg = SHARED_FIELD_DP32(reg, SLAVE_EN, 1); + aspeed_i2c_write(f, aspeed_i2c_ctrl_offset(td), reg); + + /* Enable all interrupts */ + reg = SHARED_FIELD_DP32(0, TX_ACK, 1); + reg = SHARED_FIELD_DP32(reg, TX_NAK, 1); + reg = SHARED_FIELD_DP32(reg, RX_DONE, 1); + reg = SHARED_FIELD_DP32(reg, ARBIT_LOSS, 1); + reg = SHARED_FIELD_DP32(reg, NORMAL_STOP, 1); + reg = SHARED_FIELD_DP32(reg, ABNORMAL, 1); + if (td->mode != TEST_I2C_MODE_OLD) { + reg = FIELD_DP32(reg, I2CM_INTR_STS, PKT_CMD_DONE, 1); + reg = FIELD_DP32(reg, I2CM_INTR_STS, PKT_CMD_FAIL, 1); + } + aspeed_i2c_write(f, aspeed_i2c_intr_ctrl_offset(td), reg); + + for (uint8_t i = 0; i < ARRAY_SIZE(rx_data); i++) { + qom_i2c_dummy_set_rx(i, rx_data[i]); + } +} + +static uint32_t aspeed_i2c_pkt_set_addr_cmd(const TestData *td,
uint8_taddr)tests/qtest/aspeed_i2c-test.c new file +4
-0+{ + uint32_t cmd; + + cmd = FIELD_DP32(0, I2CM_CMD, PKT_OP_EN, 1);Quoted 8 lines
Quoted 8 lines
+ cmd =
FIELD_DP32(cmd, I2CM_CMD, PKT_DEV_ADDR, addr); + return cmd;tests/qtest/aspeed_i2c-test.c new file +4
-0+} + +static +uint32_t aspeed_i2c_byte_set_addr_cmd(TestFixture *f, constTestData *td,
+uint8_taddr,bool
is_recv) {Quoted 5 lines
Quoted 5 lines
+ if (
td->mode==TEST_I2C_MODE_PKT) {
+ returnaspeed_i2c_pkt_set_addr_cmd(td, addr); + } else {
+ aspeed_i2c_write_byte(f, td, addr << 1 | (is_recv? 1 :
0));Quoted 8 lines
Quoted 8 lines
+ return
SHARED_FIELD_DP32(0, M_TX_CMD, 1); + }tests/qtest/aspeed_i2c-test.c new file +4
-0+} + +static +uint32_t aspeed_i2c_buf_set_addr_cmd(TestFixture *f, constTestData *td,
+uint8_taddr,bool
is_recv) {Quoted 5 lines
Quoted 5 lines
+ if (
td->mode==TEST_I2C_MODE_PKT) {
+ returnaspeed_i2c_pkt_set_addr_cmd(td, addr); + } else {
+ aspeed_i2c_write_pool(f, 0, addr << 1 | (is_recv? 1 :
0));Quoted 8 lines
Quoted 8 lines
+ return
SHARED_FIELD_DP32(0, M_TX_CMD, 1); + }tests/qtest/aspeed_i2c-test.c new file +4
-0+} + +static +uint32_t aspeed_i2c_dma_set_addr_cmd(TestFixture *f, constTestData *td,
+uint8_taddr,bool
is_recv) {Quoted 39 lines
Quoted 39 lines
+ if (
td->mode==TEST_I2C_MODE_PKT) {
+ returnaspeed_i2c_pkt_set_addr_cmd(td, addr); + } else {
+aspeed_i2c_write_dma(f, DRAM_TX_OFFSET, addr << 1 | (is_recv ? 1 : 0));
+ returnSHARED_FIELD_DP32(0, M_TX_CMD, 1); + }tests/qtest/aspeed_i2c-test.c new file +4
-0+} + + +static uint32_t aspeed_i2c_send_addr_status(TestFixture *f, constTestData *td)
tests/qtest/aspeed_i2c-test.c new file +20
-0+{ + uint32_t sts; + + if (td->mode == TEST_I2C_MODE_PKT) { + sts = FIELD_DP32(0, I2CM_INTR_STS, PKT_CMD_DONE, 1); + } else { + sts = SHARED_FIELD_DP32(0, TX_ACK, 1); + } + return sts; +} + +/* +* Send an address byte to a non existing device. +* The TX_NAK interrupt should be raised. +*/ +static void test_nack (TestFixture *f,gconstpointer p_data) { + const TestData *td = (const TestData *)p_data; + uint32_t sts, cmd; + + cmd = aspeed_i2c_byte_set_addr_cmd(f, td, I2C_ADDR_NACK,false);
+aspeed_i2c_send_start(f, td, cmd);
+
+g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MSTART);
+g_assert_false(aspeed_i2c_get_busy_sts(f, td)); + sts =SHARED_FIELD_DP32(0, TX_NAK, 1);Quoted 8 lines
Quoted 8 lines
+ if (
td->mode==TEST_I2C_MODE_PKT) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_FAIL, 1); + sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + }
+CLEAR_I2C_INTR(f, td, sts);
+
+ aspeed_i2c_write(f,aspeed_i2c_cmd_offset(td),
+ SHARED_FIELD_DP32(0,M_STOP_CMD,1));
Quoted 14 lines
Quoted 14 lines
+
CLEAR_I2C_INTR(f, td, SHARED_FIELD_DP32(0, NORMAL_STOP, 1)); +CHECK_I2C_IDLE(f, td);
+qtest_hmp(global_qtest, "system_reset"); }tests/qtest/aspeed_i2c-test.c new file +9
-0+ + +static void test_dummy_byte (TestFixture *f,gconstpointer p_data) { + const TestData *td = (const TestData *)p_data; + uint32_t cmd, sts; + bool pkt_mode = td->mode == TEST_I2C_MODE_PKT; + + /* Write device address (Write) */ + cmd = aspeed_i2c_byte_set_addr_cmd(f, td, I2C_ADDR_DUMMY,false);
+aspeed_i2c_send_start(f, td, cmd);Quoted 8 lines
Quoted 8 lines
+
CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, aspeed_i2c_send_addr_status(f, td)); +
+ /* Write data */
+ sts =SHARED_FIELD_DP32(0, TX_ACK, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + cmd = aspeed_i2c_pkt_set_addr_cmd(td,
I2C_ADDR_DUMMY);Quoted 14 lines
Quoted 14 lines
+ } else {
+ cmd = 0;
+ }
+ cmd =SHARED_FIELD_DP32(cmd, M_TX_CMD, 1);
+ for (uint8_ti = 0; i <ARRAY_SIZE(tx_data); i++) { +aspeed_i2c_write_byte(f, td, tx_data[i]);
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+ }
+
+ /* Read data */
+ cmd =aspeed_i2c_byte_set_addr_cmd(f, td, I2C_ADDR_DUMMY, true);Quoted 8 lines
Quoted 8 lines
+ cmd =
SHARED_FIELD_DP32(cmd, M_RX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1); + sts =aspeed_i2c_send_addr_status(f, td);
+
+ for (uint8_ti = 0; i <ARRAY_SIZE(rx_data); i++) { + cmd =SHARED_FIELD_DP32(cmd, M_RX_CMD, 1); + if (i ==ARRAY_SIZE(rx_data)- 1) {
+ cmd = SHARED_FIELD_DP32(cmd,M_S_RX_CMD_LAST,1);
Quoted 6 lines
Quoted 6 lines
+ }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+ sts =SHARED_FIELD_DP32(sts, RX_DONE, 1); + if (pkt_mode) {
+ sts = FIELD_DP32(sts,I2CM_INTR_STS,
PKT_CMD_DONE, 1);Quoted 1 line
Quoted 1 line
+ cmd = aspeed_i2c_pkt_set_addr_cmd(td,
I2C_ADDR_DUMMY);Quoted 17 lines
Quoted 17 lines
+ } else {
+ cmd = 0;
+ }
+CLEAR_I2C_INTR(f, td, sts);
+g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, rx_data[i]);
+ sts = 0;
+ }tests/qtest/aspeed_i2c-test.c new file +9
-0+ + SEND_I2C_STOP(f, td); + CHECK_I2C_DUMMY_DEVICE(); + qtest_hmp(global_qtest, "system_reset"); } + +static void test_dummy_buf (TestFixture *f,gconstpointer p_data) { + const TestData *td = (const TestData *)p_data; + uint32_t cmd, sts, pool_ctrl; + bool pkt_mode = td->mode == TEST_I2C_MODE_PKT;Quoted 8 lines
Quoted 8 lines
+
+ /* Write data with device address */
+ for (uint8_ti = 0; i <ARRAY_SIZE(tx_data); i++) { +aspeed_i2c_write_pool(f, i + (pkt_mode ? 0 : 1), tx_data[i]);
+ }
+pool_ctrl= SHARED_FIELD_DP32(0,TX_COUNT, +ARRAY_SIZE(tx_data)- (
pkt_modeQuoted 11 lines
Quoted 11 lines
? 1 : 0));
+aspeed_i2c_write(f, aspeed_i2c_pool_ctrl_offset(td), pool_ctrl);
+ cmd =aspeed_i2c_buf_set_addr_cmd(f, td, I2C_ADDR_DUMMY, false);
+ cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_TX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, TX_BUFF_EN, 1);
+ sts =SHARED_FIELD_DP32(0, TX_ACK, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1);Quoted 8 lines
Quoted 8 lines
+ }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+
+ /* Write device address (Read) in non packet mde */ + if (pkt_mode) {
+ cmd = aspeed_i2c_pkt_set_addr_cmd(td,
I2C_ADDR_DUMMY);Quoted 5 lines
Quoted 5 lines
+ cmd =
SHARED_FIELD_DP32(cmd, M_START_CMD, 1); + } else {
+aspeed_i2c_write_byte(f, td, (I2C_ADDR_DUMMY << 1) | 1); +aspeed_i2c_send_start(f, td, SHARED_FIELD_DP32(0, M_TX_CMD, 1));Quoted 8 lines
Quoted 8 lines
+
CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, aspeed_i2c_send_addr_status(f, td)); + cmd = 0;
+ }
+
+ /* Read data */
+pool_ctrl= SHARED_FIELD_DP32(0,RX_SIZE,
+ARRAY_SIZE(rx_data)- 1);
Quoted 21 lines
Quoted 21 lines
+
aspeed_i2c_write(f, aspeed_i2c_pool_ctrl_offset(td), pool_ctrl);
+ cmd =SHARED_FIELD_DP32(cmd, M_RX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_S_RX_CMD_LAST, 1); + cmd =SHARED_FIELD_DP32(cmd, RX_BUFF_EN, 1);
+ sts =SHARED_FIELD_DP32(0, RX_DONE, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+ for (uint8_ti = 0; i <ARRAY_SIZE(rx_data); i++) { +g_assert_cmphex(aspeed_i2c_read_pool(f, i), ==, rx_data[i]);
+ }tests/qtest/aspeed_i2c-test.c new file +5
-0+ + SEND_I2C_STOP(f, td); + CHECK_I2C_DUMMY_DEVICE(); + qtest_hmp(global_qtest, "system_reset"); } +Quoted 8 lines
tests/qtest/aspeed_i2c-test.c
Quoted 8 lines
tests/qtest/aspeed_i2c-test.c new file +8
-0+static void test_dummy_dma (TestFixture *f,gconstpointer p_data) { + const TestData *td = (const TestData *)p_data; + uint32_t cmd, sts; + bool pkt_mode = td->mode == TEST_I2C_MODE_PKT; + + /* Write data with device address*/ + for (uint8_t i = 0; i < ARRAY_SIZE(tx_data); i++) { + aspeed_i2c_write_dma(f, DRAM_TX_OFFSET + (pkt_mode ?0 :
Quoted 6 lines
Quoted 6 lines
1) + i,
+ tx_data[i]);
+ }
+aspeed_i2c_write_dma_addr(f, td, DRAM_TX_OFFSET, false); + aspeed_i2c_write_dma_len(f, td,
+ARRAY_SIZE(tx_data)-(
pkt_mode? 1 :Quoted 10 lines
Quoted 10 lines
0), false);
+ cmd =aspeed_i2c_dma_set_addr_cmd(f, td, I2C_ADDR_DUMMY, false);
+
+ cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_TX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, TX_DMA_EN, 1);
+ sts =SHARED_FIELD_DP32(0, TX_ACK, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1);Quoted 8 lines
Quoted 8 lines
+ }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+
+ /* Write device address (Read) in non packet mode */ + if (pkt_mode) {
+ cmd = aspeed_i2c_pkt_set_addr_cmd(td,
I2C_ADDR_DUMMY);Quoted 18 lines
Quoted 18 lines
+ cmd =
SHARED_FIELD_DP32(cmd, M_START_CMD, 1);
+ } else {
+aspeed_i2c_write_byte(f, td, (I2C_ADDR_DUMMY << 1) | 1); +aspeed_i2c_send_start(f, td, SHARED_FIELD_DP32(0, M_TX_CMD, 1));
+CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, aspeed_i2c_send_addr_status(f, td)); + cmd = 0;
+ }
+
+ /* Read data */
+aspeed_i2c_write_dma_addr(f, td, DRAM_RX_OFFSET, true); +aspeed_i2c_write_dma_len(f, td, ARRAY_SIZE(rx_data) - 1, true);
+ cmd =SHARED_FIELD_DP32(cmd, M_RX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_S_RX_CMD_LAST, 1);
+ cmd =SHARED_FIELD_DP32(cmd, RX_DMA_EN, 1);
+ sts =SHARED_FIELD_DP32(0, RX_DONE, 1);Quoted 8 lines
Quoted 8 lines
+ if (
pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+ for (uint8_ti = 0; i <ARRAY_SIZE(rx_data); i++) { + g_assert_cmphex(aspeed_i2c_read_dma(f,
DRAM_RX_OFFSET+Quoted 30 lines
Quoted 30 lines
i), ==,
+ rx_data[i]);
+ }tests/qtest/aspeed_i2c-test.c new file +19
-0+ + SEND_I2C_STOP(f, td); + CHECK_I2C_DUMMY_DEVICE(); + qtest_hmp(global_qtest, "system_reset"); } + +static void test_slave (TestFixture *f,gconstpointer p_data) { + const TestData *td = (const TestData *)p_data; + uint32_t cmd, sts, tmp; + bool pkt_mode = td->mode == TEST_I2C_MODE_PKT; + uint8_t offset = pkt_mode ? 0 : 1; + + aspeed_i2c_write_pool(f, offset + 0, I2C_ADDR_SLAVE); + aspeed_i2c_write_pool(f, offset + 1, tx_data[0]); + aspeed_i2c_write_pool(f, offset + 2, tx_data[1]); + + tmp = SHARED_FIELD_DP32(0, TX_COUNT, pkt_mode ? 2 : 3); + aspeed_i2c_write(f, aspeed_i2c_pool_ctrl_offset(td), tmp); + + cmd = aspeed_i2c_buf_set_addr_cmd(f, td, I2C_ADDR_ECHO,false);
+ cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_TX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, TX_BUFF_EN, 1);
+ sts =SHARED_FIELD_DP32(0, TX_ACK, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + }Quoted 8 lines
Quoted 8 lines
+
aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+
+ /* Send stop and handle i2c-echo response as a slave */ + if (td->mode==TEST_I2C_MODE_OLD) {
+ aspeed_i2c_write(f,aspeed_i2c_cmd_offset(td), + SHARED_FIELD_DP32(0,
M_STOP_CMD, 1));Quoted 6 lines
Quoted 6 lines
+
clock_step(1);
+g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, I2C_ADDR_SLAVE << 1);
+ sts =SHARED_FIELD_DP32(0, NORMAL_STOP, 1); + sts =SHARED_FIELD_DP32(sts, RX_DONE, 1); + sts = FIELD_DP32(sts,I2CD_INTR_STS,
SLAVE_ADDR_RX_MATCH,Quoted 9 lines
Quoted 9 lines
1);
+CHECK_I2C_INTR(f, td, sts);
+aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), sts); +
+g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, tx_data[0]);
+ sts =SHARED_FIELD_DP32(0, RX_DONE, 1);
+CHECK_I2C_INTR(f, td, sts);
+aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), sts);Quoted 8 lines
Quoted 8 lines
+
+g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, tx_data[1]);
+ sts =SHARED_FIELD_DP32(0, RX_DONE, 1);
+CHECK_I2C_INTR(f, td, sts);
+aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), sts); + } else {
+ aspeed_i2c_write(f,A_I2CS_DMA_RX_ADDR,
DRAM_RX_OFFSET);Quoted 5 lines
Quoted 5 lines
+ tmp =
SHARED_FIELD_DP32(0, RX_DMA_EN, 1); +aspeed_i2c_write(f, A_I2CS_CMD, tmp); +
+ aspeed_i2c_write(f,aspeed_i2c_cmd_offset(td), + SHARED_FIELD_DP32(0,
M_STOP_CMD, 1));Quoted 4 lines
Quoted 4 lines
+
clock_step(1);
+
+ tmp =FIELD_DP32(0, I2CS_DMA_LEN_STS, RX_LEN, 2); + g_assert_cmphex(aspeed_i2c_read(f,
A_I2CS_DMA_LEN_STS),Quoted 3 lines
Quoted 3 lines
==, tmp);
+ for (uint8_ti = 0; i < 2; i++) { + g_assert_cmphex(aspeed_i2c_read_dma(f,
DRAM_RX_OFFSETQuoted 39 lines
Quoted 39 lines
tests/qtest/aspeed_i2c-test.c new file +12
-0+i), ==, + tx_data[i]); + } + } + + sts = SHARED_FIELD_DP32(0, NORMAL_STOP, 1); + CLEAR_I2C_INTR(f, td, sts); + CHECK_I2C_IDLE(f, td); + + qtest_hmp(global_qtest, "system_reset"); } + +static void aspeed_i2c_init_fixture(TestFixture *fixture, constTestData *td)
tests/qtest/aspeed_i2c-test.c new file +26
-0+{ + switch (td->machine) { + case TEST_MACHINE_AST2400: + fixture->base_addr = 0x1E78A000; + fixture->bus_offset = 0x40; + fixture->irq_no = 12; + fixture->pool_base = 0x800; + break; + case TEST_MACHINE_AST2500: + fixture->base_addr = 0x1E78A000; + fixture->bus_offset = 0x40; + fixture->irq_no = 12; + fixture->pool_base = 0x200; + break; + case TEST_MACHINE_AST2600: + fixture->base_addr = 0x1E78A000; + fixture->bus_offset = 0x80; + fixture->irq_no = 110; + fixture->pool_base = 0xC00; + break; + default: + return; + } +} + +static void aspeed_i2c_init_test(TestFixture *fixture, constQuoted 8 lines
tests/qtest/aspeed_i2c-test.c line 725
Quoted 8 lines
TestData *td)
tests/qtest/aspeed_i2c-test.c new file +6
-0+{ + aspeed_i2c_init(fixture, td); + CHECK_I2C_IDLE(fixture, td); +} + +static void aspeed_i2c_init_new_machine(TestFixture *fixture,+ gconstpointer
p_data) {Quoted 33 lines
Quoted 33 lines
+ const TestData *td = (const TestData *)p_data; + const char *machine;
+ const char*irq_dev;tests/qtest/aspeed_i2c-test.c new file +28
-0+ + aspeed_i2c_init_fixture(fixture, td); + + if (global_qtest) { + qtest_quit(global_qtest); + } + + switch (td->machine) { + case TEST_MACHINE_AST2400: + machine = "palmetto-bmc"; + irq_dev = "/machine/soc/vic"; + break; + case TEST_MACHINE_AST2500: + machine = "ast2500-evb"; + irq_dev = "/machine/soc/vic"; + break; + case TEST_MACHINE_AST2600: + machine = "ast2600-evb"; + irq_dev = "/machine/soc/a7mpcore/gic"; + break; + default: + g_test_fail(); + return; + } + + global_qtest = qtest_initf( + "-machine %s -nographic " + "-device i2c-echo,id=i2c-echo,bus=aspeed.i2c.bus.0,address=%d "
+ "-device i2c-dummy-device,id=i2c-Quoted 8 lines
tests/qtest/aspeed_i2c-test.c
Quoted 8 lines
dummy,bus=aspeed.i2c.bus.0,address=%d",
+ machine,I2C_ADDR_ECHO,I2C_ADDR_DUMMY); +qtest_irq_intercept_in(global_qtest, irq_dev);tests/qtest/aspeed_i2c-test.c new file +5
-0+ + aspeed_i2c_init_test(fixture, td); } + +static void aspeed_i2c_init_machine (TestFixture *fixture, + gconstpointer
p_data) {Quoted 90 lines
Quoted 90 lines
+ const TestData *td = (const TestData *)p_data;
tests/qtest/aspeed_i2c-test.c new file +14
-0+ + aspeed_i2c_init_fixture(fixture, td); + aspeed_i2c_init_test(fixture, td); } + +static void add_test (const TestData *td,const char *name, + void (*func)(TestFixture *, const void *), + bool setup) +{ + g_autofree char *test_name; + + test_name = g_strdup_printf("%s/%s", td->name, name); + + qtest_add(test_name, TestFixture, td, + setup ? aspeed_i2c_init_new_machine :
aspeed_i2c_init_machine,
+ func, NULL);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +#define ADD_TEST (td, test, new) add_test(td, #test, test_##test,new)
tests/qtest/aspeed_i2c-test.c new file +35
-0+ +static const TestData test_data[] = { + { + .name = "ast2400", + .machine = TEST_MACHINE_AST2400, + }, + { + .name = "ast2500", + .machine = TEST_MACHINE_AST2500, + }, + { + .name = "ast2600", + .machine = TEST_MACHINE_AST2600, + }, + { + .name = "ast2600-new", + .machine = TEST_MACHINE_AST2600, + .mode = TEST_I2C_MODE_NEW, + }, + { + .name = "ast2600-packet", + .machine = TEST_MACHINE_AST2600, + .mode = TEST_I2C_MODE_PKT, + }, +}; + +int main (int argc,char **argv) +{ + int ret; + bool setup; + + g_test_init(&argc, &argv, NULL); + + for (int i = 0; i < ARRAY_SIZE(test_data); i++) { + setup = i == 0 || test_data[i].machine != test_data[i -1].machine;
+ADD_TEST(&test_data[i], nack, setup);
+ADD_TEST(&test_data[i], dummy_byte, false); +ADD_TEST(&test_data[i], dummy_buf, false); + if (test_data[i].machine !=TEST_MACHINE_AST2400) { +ADD_TEST(&test_data[i], dummy_dma, false); + }
+ADD_TEST(&test_data[i], slave, false);
+ }tests/qtest/aspeed_i2c-test.c new file +5
-0+ + ret = g_test_run(); + qtest_quit(global_qtest); + return ret; +}tests/qtest/meson.build index renamed from tests/qtest/meson.build +0
-0
46d4fc1d2b..c496b7c3a7100644tests/qtest/meson.build +1
-0@@ -233,12 +233,14 @@ qtests_aspeed = \ ['aspeed-acry-test', 'aspeed_gpio-test', 'aspeed_hace-test', + 'aspeed_i2c-test', 'aspeed-sbc-test', 'aspeed_scu-test','aspeed_smc-test']
qtests_aspeed64= \
['ast2700-gpio-test',
'ast2700-hace-test',
+ 'aspeed_i2c-test',
'ast2700-sgpio-test',
'ast2700-smc-test']
Re: [PATCH v2 6/6] tests/qtest: Add cases for 32-bit Aspeed I2C controllers
Thanks, I see it. I will add support for the ast2700.
Quoted 1,066 lines · Jamin Lin
Quoted 11 lines
Hi, I thought about that, but I'm not sure how to do it because I haven't found
previous examples in QEMU.
I guess there should be two test suites for ARM and AArch64 targets.
But AArch64 also supports 32-bit ARM SoCs, so I'm not sure whether we should
test them with the AArch64 target as well or if testing with the ARM target is
enough.Please refer to
ast2700-hace-test.c,aspeed-hace-utils.c, andaspeed_hace-test.cas examples of HACE tests for AArch64 (AST2700) and ARM32 (AST2500, AST2600, and AST1030).Quoted 300 lines · Cédric Le Goater
Quoted 163 lines · Timur Maksimov
Quoted 26 lines
Test all supported register and transfer modes.
Signed-off-by Timur Maksimov <[email protected]>---
tests/qtest/aspeed_i2c-test.c| 836
++++++++++++++++++++++++++++++++++++++++++
tests/qtest/meson.build | 2 +2 files changed, 838 insertions(+)(quoted diff) +0
-0
b/tests/qtest/aspeed_i2c-test.cnew file mode 100644 index 0000000000..7fb1debb56tests/qtest/aspeed_i2c-test.c new file +11
-0@@ -0,0 +1,836 @@ +/* +* QTest testcase for Aspeed I2C controller +* +* Copyright (c) 2026 Timur Maksimov <[email protected]> +* +* SPDX-License-Identifier: GPL-2.0-or-later */ + +#include "qemu/osdep.h" +#include "libqtest-single.h" +#include "hw/i2c/aspeed_i2c.h" +tests/qtest/aspeed_i2c-test.c line 21
Quoted 10 lines
tests/qtest/aspeed_i2c-test.c new file +10
-0+typedef enum TestAspeedI2CMode { + TEST_I2C_MODE_OLD, + TEST_I2C_MODE_NEW, + TEST_I2C_MODE_PKT, +}TestAspeedI2CMode ; + +typedef enum TestAspeedMachine { + TEST_MACHINE_AST2400, + TEST_MACHINE_AST2500, + TEST_MACHINE_AST2600,Do you have plans to add AST2700 support ? This is the current focus
now days.Thanks,
C.
Quoted 114 lines
tests/qtest/aspeed_i2c-test.c new file +16
-0+} TestAspeedMachine; + +typedef struct TestData { + const char *name; + TestAspeedMachine machine; + TestAspeedI2CMode mode; +}TestData ; + +typedef struct TestFixture { + hwaddr base_addr; + hwaddr bus_offset; + int irq_no; + uint32_t pool_base; +}TestFixture ; + +static const uint8_t tx_data[] = {0x10, 0x11, 0x12}; staticconst
tests/qtest/aspeed_i2c-test.c new file +7
-0+uint8_t rx_data[] = {0x30 ,0x31 ,0x32 }; + +#define DRAM_BASE 0x80000000 +#define DRAM_TX_OFFSET 0x1000 +#define DRAM_RX_OFFSET 0x2000 + +static void aspeed_i2c_write(TestFixture *f, uint32_t offset,
uint32_tval)
+{
+qtest_writel(global_qtest, f->base_addr + f->bus_offset + offset, val);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static void aspeed_i2c_write_pool(TestFixture *f, uint32_toffset,
uint8_tval)
+{
+qtest_writeb(global_qtest, f->base_addr + f->pool_base + offset, val);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static void aspeed_i2c_write_dma(TestFixture *f, uint32_toffset,
uint8_tval)tests/qtest/aspeed_i2c-test.c new file +4
-0+{ + qtest_writeb(global_qtest, DRAM_BASE + offset, val); } + +static uint32_t aspeed_i2c_read(TestFixture *f, uint32_toffset) {
+ return qtest_readl(global_qtest,f->base_addr+ f-Quoted 1 line
bus_offsettests/qtest/aspeed_i2c-test.c new file +3
-0+offset); } + +static uint8_t aspeed_i2c_read_pool(TestFixture *f, uint32_toffset)
+{
+ return qtest_readb(global_qtest,f->base_addr+ f-Quoted 1 line
pool_base+offset);
tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static uint8_t aspeed_i2c_read_dma(TestFixture *f, uint32_toffset)
tests/qtest/aspeed_i2c-test.c new file +24
-0+{ + return qtest_readb(global_qtest, DRAM_BASE + offset); } + +static bool aspeed_i2c_irq (TestFixture *f) { + return qtest_get_irq(global_qtest, f->irq_no); } + +static uint32_t aspeed_i2c_ctrl_offset (const TestData *td) { + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_FUN_CTRL; + } else { + return A_I2CC_FUN_CTRL; + } +} + +static uint32_t aspeed_i2c_cmd_offset (const TestData *td) { + if (td->mode == TEST_I2C_MODE_OLD) { + return A_I2CD_CMD; + } else { + return A_I2CM_CMD; + } +} + + +static uint32_t aspeed_i2c_intr_ctrl_offset(const TestData*td) {
+ if (td->mode==TEST_I2C_MODE_OLD) {
+ returnA_I2CD_INTR_CTRL;
+ } else {
+ returnA_I2CM_INTR_CTRL;
+ }tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static uint32_t aspeed_i2c_intr_sts_offset (const TestData *td){
+ if (td->mode==TEST_I2C_MODE_OLD) {
+ returnA_I2CD_INTR_STS;
+ } else {
+ returnA_I2CM_INTR_STS;
+ }tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static uint32_t aspeed_i2c_pool_ctrl_offset(const TestData*td) {
+ if (td->mode==TEST_I2C_MODE_OLD) {
+ returnA_I2CD_POOL_CTRL;
+ } else {
+ returnA_I2CC_POOL_CTRL;
+ }tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static uint32_t aspeed_i2c_byte_buf_offset (const TestData *td){
+ if (td->mode==TEST_I2C_MODE_OLD) {
+ returnA_I2CD_BYTE_BUF;Quoted 8 lines
Quoted 8 lines
+ } else {
+ returnA_I2CC_MS_TXRX_BYTE_BUF;
+ }tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static void aspeed_i2c_write_slave_addr(TestFixture *f, constTestData *td,
+uint8_taddr){
Quoted 10 lines
Quoted 10 lines
+ if (
td->mode==TEST_I2C_MODE_OLD) {
+aspeed_i2c_write(f, A_I2CD_DEV_ADDR, addr); + } else {
+aspeed_i2c_write(f, A_I2CS_DEV_ADDR, addr); + }tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static void aspeed_i2c_write_dma_addr(TestFixture *f, constTestData *td,
+uint32_tval, boolrx) {
Quoted 6 lines
Quoted 6 lines
+
uint32_toffset;
+
+ if (td->mode==TEST_I2C_MODE_OLD) {
+ offset =A_I2CD_DMA_ADDR;
+ } else {
+ offset = rx ?A_I2CM_DMA_RX_ADDR:
A_I2CM_DMA_TX_ADDR;Quoted 6 lines
Quoted 6 lines
+ }
+aspeed_i2c_write(f, offset, val); }tests/qtest/aspeed_i2c-test.c new file +2
-0+ +static void aspeed_i2c_write_dma_len(TestFixture *f, constTestData *td,
+uint16_tval, boolrx) {
Quoted 102 lines
Quoted 102 lines
+
uint32_treg;tests/qtest/aspeed_i2c-test.c new file +16
-0+ + if (td->mode == TEST_I2C_MODE_OLD) { + aspeed_i2c_write(f, A_I2CD_DMA_LEN, val + 1); + return; + } + + if (rx) { + reg = FIELD_DP32(0, I2CM_DMA_LEN, RX_BUF_LEN_W1T, 1); + reg = FIELD_DP32(reg, I2CM_DMA_LEN, RX_BUF_LEN, val); + } else { + reg = FIELD_DP32(0, I2CM_DMA_LEN, TX_BUF_LEN_W1T, 1); + reg = FIELD_DP32(reg, I2CM_DMA_LEN, TX_BUF_LEN, val); + } + aspeed_i2c_write(f, A_I2CM_DMA_LEN, reg); } + +static uint8_t aspeed_i2c_get_txstate(TestFixture *f, constTestData *td)
tests/qtest/aspeed_i2c-test.c new file +9
-0+{ + uint32_t offset; + + if (td->mode == TEST_I2C_MODE_OLD) { + offset = A_I2CD_CMD; + } else { + offset = A_I2CC_MS_TXRX_BYTE_BUF; + } + return SHARED_FIELD_EX32(aspeed_i2c_read(f, offset),
TX_STATE);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +static bool aspeed_i2c_get_busy_sts(TestFixture *f, constTestData
*td)tests/qtest/aspeed_i2c-test.c new file +9
-0+{ + uint32_t offset; + + if (td->mode == TEST_I2C_MODE_OLD) { + offset = A_I2CD_CMD; + } else { + offset = A_I2CC_MS_TXRX_BYTE_BUF; + } + return SHARED_FIELD_EX32(aspeed_i2c_read(f, offset),
BUS_BUSY_STS);tests/qtest/aspeed_i2c-test.c new file +4
-0+} + +/* Write a data byte in a byte mode transfer */ static void +aspeed_i2c_write_byte(TestFixture *f, const TestData *td,
uint8_tval)tests/qtest/aspeed_i2c-test.c new file +6
-0+{ + aspeed_i2c_write(f, aspeed_i2c_byte_buf_offset(td), + SHARED_FIELD_DP32(0, TX_BUF, val)); } + +/* Read a data byte in a byte mode transfer */ static uint8_t +aspeed_i2c_read_byte(TestFixture *f, const TestData*td)
tests/qtest/aspeed_i2c-test.c new file +7
-0+{ + uint32_t reg; + + reg = aspeed_i2c_read(f, aspeed_i2c_byte_buf_offset(td)); + return SHARED_FIELD_EX32(reg, RX_BUF); } + +static void aspeed_i2c_send_start(TestFixture *f, constTestData
*td,
+uint32_tcmd) { + cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1); +aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); }tests/qtest/aspeed_i2c-test.c new file +15
-0+ +static uint8_t qom_i2c_dummy_get_uint8 (const char *prop) { + QDict *r; + uint8_t u; + + r = qtest_qmp(global_qtest, + "{ 'execute': 'qom-get', 'arguments': " + "{ 'path': 'i2c-dummy', 'property': %s } }", + prop); + u = qdict_get_uint(r, "return"); + qobject_unref(r); + return u; +} + +static void qom_i2c_dummy_set_uint8(const char *prop, uint8_tdata)
tests/qtest/aspeed_i2c-test.c new file +6
-0+{ + QDict *r; + + r = qtest_qmp(global_qtest, + "{ 'execute': 'qom-set', 'arguments': " + "{ 'path': 'i2c-dummy', 'property': %s,'value':
%d } }",
+ prop, data);
+qobject_unref(r);tests/qtest/aspeed_i2c-test.c new file +9
-0+} + +static void qom_i2c_dummy_set_rx (uint8_t idx,uint8_t data) { + g_autofree char *prop = g_strdup_printf("rx[%d]", idx); + + qom_i2c_dummy_set_uint8(prop, data); } + +static uint8_t qom_i2c_dummy_get_tx (int8_t idx) { + g_autofree char *prop = g_strdup_printf("tx[%d]", idx);Quoted 8 lines
Quoted 8 lines
tests/qtest/aspeed_i2c-test.c line 269
Quoted 8 lines
tests/qtest/aspeed_i2c-test.c new file +8
-0+ + return qom_i2c_dummy_get_uint8(prop); } + +#define I2C_ADDR_NACK 0x10 +#define I2C_ADDR_DUMMY 0x20 +#define I2C_ADDR_ECHO 0x30 +#define I2C_ADDR_SLAVE 0x40 +Could these be static helper functions instead of multi-line macros? They do not need anything a function cannot do, and functions would be
easier to read and type-checked. I understand the macros makeg_assert
report the caller's line, but the qtest path and the tap output already
tell us which test failed.
Also,CHECK_I2C_ACK()is not used anywhere, so it can be dropped.Quoted 95 lines
Quoted 10 lines
Quoted 10 lines
+#define
CHECK_I2C_IDLE(f, td)do
{ \
+g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_IDLE); \
+g_assert_false(aspeed_i2c_get_busy_sts(f, td)); \
+ g_assert_cmphex(aspeed_i2c_read(f,aspeed_i2c_intr_sts_offset(td)), ==, \
+0);
\Quoted 6 lines
Quoted 6 lines
+
g_assert_false(aspeed_i2c_irq(f));
\tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CHECK_I2C_INTR (f, td, reg) doQuoted 8 lines
Quoted 8 lines
{ \
+
g_assert_true(aspeed_i2c_irq(f));
\
+ g_assert_cmphex(aspeed_i2c_read(f,aspeed_i2c_intr_sts_offset(td)), ==, \
+reg);
\Quoted 22 lines
Quoted 22 lines
tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CHECK_I2C_BUS_ACTIVE (f, td) do{ \
+g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MACTIVE); \
+g_assert_true(aspeed_i2c_get_busy_sts(f, td)); \tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CHECK_I2C_ACK (f, td) do{ \
+g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MACTIVE); \
+g_assert_true(aspeed_i2c_get_busy_sts(f, td)); \
+CLEAR_I2C_INTR(f, td, SHARED_FIELD_DP32(0, TX_ACK, 1)); \tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CLEAR_I2C_INTR (f, td, reg) do{ \
Quoted 8 lines
Quoted 8 lines
+ CHECK_I2C_INTR(f, td,
reg); \
+aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), reg); \
+ g_assert_cmphex(aspeed_i2c_read(f,aspeed_i2c_intr_sts_offset(td)), ==, \
+0);
\Quoted 4 lines
Quoted 4 lines
tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define SEND_I2C_STOP (f, td) do{ \
Quoted 8 lines
Quoted 8 lines
+ aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), \
+SHARED_FIELD_DP32(0, M_STOP_CMD, 1)); \
+CLEAR_I2C_INTR(f, td, SHARED_FIELD_DP32(0, NORMAL_STOP, 1)); \
+ CHECK_I2C_IDLE(f,td);
\Quoted 7 lines
Quoted 7 lines
tests/qtest/aspeed_i2c-test.c new file +3
-0+} while (0) + +#define CHECK_I2C_DUMMY_DEVICE () do{ \
+ for (uint8_ti = 0; i <ARRAY_SIZE(tx_data); i++) { \
+ g_assert_cmphex(qom_i2c_dummy_get_tx(i), ==,Quoted 8 lines
Quoted 8 lines
tx_data[i]); \
+
}
\
+ g_assert_cmphex(qom_i2c_dummy_get_uint8("tx-pos"), ==, \
+ARRAY_SIZE(tx_data)); \
Quoted 4 lines
Quoted 4 lines
+ g_assert_cmphex(qom_i2c_dummy_get_uint8("rx-pos"), ==, \
+ARRAY_SIZE(rx_data)); \
Quoted 10 lines
Quoted 10 lines
tests/qtest/aspeed_i2c-test.c line 326
Quoted 10 lines
tests/qtest/aspeed_i2c-test.c new file +3
-0+}while (0 ) + +static void aspeed_i2c_init(TestFixture *f, const TestData*td) {
+uint32_treg;tests/qtest/aspeed_i2c-test.c new file +5
-0+ + qtest_qmp(global_qtest, "{ 'execute': 'system_reset' }"); + + aspeed_i2c_write_slave_addr(f, td, I2C_ADDR_SLAVE); +The slave address is written before the register
mode is switched:For the new register mode tests,
aspeed_i2c_write_slave_addr()writesI2CS_DEV_ADDR(offset0x40), but the controller is still in old register
mode at that point, so the write is dropped as a bad offset. The slave
address is never programmed, and the slave test only passes because an
earlier test left the controller in new register mode.Running the slave test on its own fails every time:
QTEST_QEMU_BINARY=./qemu-system-arm ./tests/qtest/aspeed_i2c-test \
-p /arm/ast2600/nack -p /arm/ast2600-new/slaveERROR:
test_slave: assertion failed (aspeed_i2c_read(f, A_I2CS_DMA_LEN_STS)== tmp): (0x00000000==0x00020000)(/arm/ast2600/nack is only there to start the machine.)
Thanks,
JaminQuoted 598 lines
Quoted 37 lines
Quoted 37 lines
+ reg =
FIELD_DP32(0, I2C_CTRL_GLOBAL, SRAM_EN, 1); + if (td->mode!=TEST_I2C_MODE_OLD) {
+ reg =FIELD_DP32(reg, I2C_CTRL_GLOBAL, REG_MODE, 1); + }
+ qtest_writel(global_qtest,f->base_addr+A_I2C_CTRL_GLOBAL,
reg);tests/qtest/aspeed_i2c-test.c new file +24
-0+ + reg = SHARED_FIELD_DP32(0, MASTER_EN, 1); + reg = SHARED_FIELD_DP32(reg, SLAVE_EN, 1); + aspeed_i2c_write(f, aspeed_i2c_ctrl_offset(td), reg); + + /* Enable all interrupts */ + reg = SHARED_FIELD_DP32(0, TX_ACK, 1); + reg = SHARED_FIELD_DP32(reg, TX_NAK, 1); + reg = SHARED_FIELD_DP32(reg, RX_DONE, 1); + reg = SHARED_FIELD_DP32(reg, ARBIT_LOSS, 1); + reg = SHARED_FIELD_DP32(reg, NORMAL_STOP, 1); + reg = SHARED_FIELD_DP32(reg, ABNORMAL, 1); + if (td->mode != TEST_I2C_MODE_OLD) { + reg = FIELD_DP32(reg, I2CM_INTR_STS, PKT_CMD_DONE, 1); + reg = FIELD_DP32(reg, I2CM_INTR_STS, PKT_CMD_FAIL, 1); + } + aspeed_i2c_write(f, aspeed_i2c_intr_ctrl_offset(td), reg); + + for (uint8_t i = 0; i < ARRAY_SIZE(rx_data); i++) { + qom_i2c_dummy_set_rx(i, rx_data[i]); + } +} + +static uint32_t aspeed_i2c_pkt_set_addr_cmd(const TestData*td,
uint8_taddr)tests/qtest/aspeed_i2c-test.c new file +4
-0+{ + uint32_t cmd; + + cmd = FIELD_DP32(0, I2CM_CMD, PKT_OP_EN, 1);Quoted 8 lines
Quoted 8 lines
+ cmd =
FIELD_DP32(cmd, I2CM_CMD, PKT_DEV_ADDR, addr); + return cmd;tests/qtest/aspeed_i2c-test.c new file +4
-0+} + +static +uint32_t aspeed_i2c_byte_set_addr_cmd(TestFixture *f, constTestData *td,
+uint8_taddr,bool
is_recv) {Quoted 6 lines
Quoted 6 lines
+ if (
td->mode==TEST_I2C_MODE_PKT) {
+ returnaspeed_i2c_pkt_set_addr_cmd(td, addr); + } else {
+ aspeed_i2c_write_byte(f, td, addr << 1 | (is_recv? 1 :
0));Quoted 8 lines
Quoted 8 lines
+ return
SHARED_FIELD_DP32(0, M_TX_CMD, 1); + }tests/qtest/aspeed_i2c-test.c new file +4
-0+} + +static +uint32_t aspeed_i2c_buf_set_addr_cmd(TestFixture *f, constTestData *td,
+uint8_taddr,bool
is_recv) {Quoted 5 lines
Quoted 5 lines
+ if (
td->mode==TEST_I2C_MODE_PKT) {
+ returnaspeed_i2c_pkt_set_addr_cmd(td, addr); + } else {
+ aspeed_i2c_write_pool(f, 0, addr << 1 | (is_recv? 1 :
0));Quoted 8 lines
Quoted 8 lines
+ return
SHARED_FIELD_DP32(0, M_TX_CMD, 1); + }tests/qtest/aspeed_i2c-test.c new file +4
-0+} + +static +uint32_t aspeed_i2c_dma_set_addr_cmd(TestFixture *f, constTestData *td,
+uint8_taddr,bool
is_recv) {Quoted 40 lines
Quoted 40 lines
+ if (
td->mode==TEST_I2C_MODE_PKT) {
+ returnaspeed_i2c_pkt_set_addr_cmd(td, addr); + } else {
+aspeed_i2c_write_dma(f, DRAM_TX_OFFSET, addr << 1 | (is_recv ? 1 : 0));
+ returnSHARED_FIELD_DP32(0, M_TX_CMD, 1); + }tests/qtest/aspeed_i2c-test.c new file +4
-0+} + + +static uint32_t aspeed_i2c_send_addr_status(TestFixture *f,const
TestData *td)tests/qtest/aspeed_i2c-test.c new file +20
-0+{ + uint32_t sts; + + if (td->mode == TEST_I2C_MODE_PKT) { + sts = FIELD_DP32(0, I2CM_INTR_STS, PKT_CMD_DONE, 1); + } else { + sts = SHARED_FIELD_DP32(0, TX_ACK, 1); + } + return sts; +} + +/* +* Send an address byte to a non existing device. +* The TX_NAK interrupt should be raised. +*/ +static void test_nack (TestFixture *f,gconstpointer p_data) { + const TestData *td = (const TestData *)p_data; + uint32_t sts, cmd; + + cmd = aspeed_i2c_byte_set_addr_cmd(f, td, I2C_ADDR_NACK,false);
+aspeed_i2c_send_start(f, td, cmd);
+
+g_assert_cmphex(aspeed_i2c_get_txstate(f, td), ==, I2CD_MSTART);
+g_assert_false(aspeed_i2c_get_busy_sts(f, td)); + sts =SHARED_FIELD_DP32(0, TX_NAK, 1);Quoted 8 lines
Quoted 8 lines
+ if (
td->mode==TEST_I2C_MODE_PKT) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_FAIL, 1); + sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + }
+CLEAR_I2C_INTR(f, td, sts);
+
+ aspeed_i2c_write(f,aspeed_i2c_cmd_offset(td),
+ SHARED_FIELD_DP32(0,M_STOP_CMD,1));
Quoted 16 lines
Quoted 16 lines
+
CLEAR_I2C_INTR(f, td, SHARED_FIELD_DP32(0, NORMAL_STOP, 1));
+CHECK_I2C_IDLE(f, td);
+qtest_hmp(global_qtest, "system_reset"); }tests/qtest/aspeed_i2c-test.c new file +3
-0+ + +static void test_dummy_byte(TestFixture *f, gconstpointer
p_data) {
+ const TestData *td = (const TestData *)p_data; +uint32_tcmd, sts;
+ boolpkt_mode=td->mode==TEST_I2C_MODE_PKT; +
+ /* Write device address (Write) */
+ cmd =aspeed_i2c_byte_set_addr_cmd(f, td, I2C_ADDR_DUMMY, false);
+aspeed_i2c_send_start(f, td, cmd);Quoted 8 lines
Quoted 8 lines
+
CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, aspeed_i2c_send_addr_status(f, td)); +
+ /* Write data */
+ sts =SHARED_FIELD_DP32(0, TX_ACK, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + cmd = aspeed_i2c_pkt_set_addr_cmd(td,
I2C_ADDR_DUMMY);Quoted 14 lines
Quoted 14 lines
+ } else {
+ cmd = 0;
+ }
+ cmd =SHARED_FIELD_DP32(cmd, M_TX_CMD, 1);
+ for (uint8_ti = 0; i <ARRAY_SIZE(tx_data); i++) { +aspeed_i2c_write_byte(f, td, tx_data[i]);
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+ }
+
+ /* Read data */
+ cmd =aspeed_i2c_byte_set_addr_cmd(f, td, I2C_ADDR_DUMMY, true);Quoted 8 lines
Quoted 8 lines
+ cmd =
SHARED_FIELD_DP32(cmd, M_RX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1); + sts =aspeed_i2c_send_addr_status(f, td);
+
+ for (uint8_ti = 0; i <ARRAY_SIZE(rx_data); i++) { + cmd =SHARED_FIELD_DP32(cmd, M_RX_CMD, 1); + if (i ==ARRAY_SIZE(rx_data)- 1) {
+ cmd = SHARED_FIELD_DP32(cmd,M_S_RX_CMD_LAST,1);
Quoted 6 lines
Quoted 6 lines
+ }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+ sts =SHARED_FIELD_DP32(sts, RX_DONE, 1); + if (pkt_mode) {
+ sts = FIELD_DP32(sts,I2CM_INTR_STS,
PKT_CMD_DONE, 1);Quoted 1 line
Quoted 1 line
+ cmd = aspeed_i2c_pkt_set_addr_cmd(td,
I2C_ADDR_DUMMY);Quoted 18 lines
Quoted 18 lines
+ } else {
+ cmd = 0;
+ }
+CLEAR_I2C_INTR(f, td, sts);
+g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, rx_data[i]);
+ sts = 0;
+ }tests/qtest/aspeed_i2c-test.c new file +6
-0+ + SEND_I2C_STOP(f, td); + CHECK_I2C_DUMMY_DEVICE(); + qtest_hmp(global_qtest, "system_reset"); } + +static void test_dummy_buf(TestFixture *f, gconstpointer
p_data) {
+ const TestData *td = (const TestData *)p_data; +uint32_tcmd, sts,pool_ctrl;
+ boolpkt_mode=td->mode==TEST_I2C_MODE_PKT;Quoted 8 lines
Quoted 8 lines
+
+ /* Write data with device address */
+ for (uint8_ti = 0; i <ARRAY_SIZE(tx_data); i++) { +aspeed_i2c_write_pool(f, i + (pkt_mode ? 0 : 1), tx_data[i]);
+ }
+pool_ctrl= SHARED_FIELD_DP32(0,TX_COUNT, +ARRAY_SIZE(tx_data)- (
pkt_modeQuoted 11 lines
Quoted 11 lines
? 1 : 0));
+aspeed_i2c_write(f, aspeed_i2c_pool_ctrl_offset(td), pool_ctrl);
+ cmd =aspeed_i2c_buf_set_addr_cmd(f, td, I2C_ADDR_DUMMY, false);
+ cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_TX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, TX_BUFF_EN, 1);
+ sts =SHARED_FIELD_DP32(0, TX_ACK, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1);Quoted 8 lines
Quoted 8 lines
+ }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+
+ /* Write device address (Read) in non packet mde */ + if (pkt_mode) {
+ cmd = aspeed_i2c_pkt_set_addr_cmd(td,
I2C_ADDR_DUMMY);Quoted 7 lines
Quoted 7 lines
+ cmd =
SHARED_FIELD_DP32(cmd, M_START_CMD, 1); + } else {
+aspeed_i2c_write_byte(f, td, (I2C_ADDR_DUMMY << 1) | 1);
+aspeed_i2c_send_start(f, td, SHARED_FIELD_DP32(0, M_TX_CMD, 1));
+CHECK_I2C_BUS_ACTIVE(f, td);Quoted 8 lines
Quoted 8 lines
+
CLEAR_I2C_INTR(f, td, aspeed_i2c_send_addr_status(f, td));
+ cmd = 0;
+ }
+
+ /* Read data */
+pool_ctrl= SHARED_FIELD_DP32(0,RX_SIZE,
+ARRAY_SIZE(rx_data)- 1);
Quoted 22 lines
Quoted 22 lines
+
aspeed_i2c_write(f, aspeed_i2c_pool_ctrl_offset(td), pool_ctrl);
+ cmd =SHARED_FIELD_DP32(cmd, M_RX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_S_RX_CMD_LAST, 1); + cmd =SHARED_FIELD_DP32(cmd, RX_BUFF_EN, 1);
+ sts =SHARED_FIELD_DP32(0, RX_DONE, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+ for (uint8_ti = 0; i <ARRAY_SIZE(rx_data); i++) { +g_assert_cmphex(aspeed_i2c_read_pool(f, i), ==, rx_data[i]);
+ }tests/qtest/aspeed_i2c-test.c new file +6
-0+ + SEND_I2C_STOP(f, td); + CHECK_I2C_DUMMY_DEVICE(); + qtest_hmp(global_qtest, "system_reset"); } + +static void test_dummy_dma(TestFixture *f, gconstpointerQuoted 8 lines
Quoted 8 lines
p_data) {
+ const TestData *td = (const TestData *)p_data; +uint32_tcmd, sts;
+ boolpkt_mode=td->mode==TEST_I2C_MODE_PKT; +
+ /* Write data with device address*/
+ for (uint8_ti = 0; i <ARRAY_SIZE(tx_data); i++) { + aspeed_i2c_write_dma(f,DRAM_TX_OFFSET+ (pkt_mode?0 :
Quoted 6 lines
Quoted 6 lines
1) + i,
+ tx_data[i]);
+ }
+aspeed_i2c_write_dma_addr(f, td, DRAM_TX_OFFSET, false); + aspeed_i2c_write_dma_len(f, td,
+ARRAY_SIZE(tx_data)-(
pkt_mode? 1 :Quoted 10 lines
Quoted 10 lines
0), false);
+ cmd =aspeed_i2c_dma_set_addr_cmd(f, td, I2C_ADDR_DUMMY, false);
+
+ cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_TX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, TX_DMA_EN, 1);
+ sts =SHARED_FIELD_DP32(0, TX_ACK, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1);Quoted 8 lines
Quoted 8 lines
+ }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+
+ /* Write device address (Read) in non packet mode */ + if (pkt_mode) {
+ cmd = aspeed_i2c_pkt_set_addr_cmd(td,
I2C_ADDR_DUMMY);Quoted 20 lines
Quoted 20 lines
+ cmd =
SHARED_FIELD_DP32(cmd, M_START_CMD, 1); + } else {
+aspeed_i2c_write_byte(f, td, (I2C_ADDR_DUMMY << 1) | 1);
+aspeed_i2c_send_start(f, td, SHARED_FIELD_DP32(0, M_TX_CMD, 1));
+CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, aspeed_i2c_send_addr_status(f, td));
+ cmd = 0;
+ }
+
+ /* Read data */
+aspeed_i2c_write_dma_addr(f, td, DRAM_RX_OFFSET, true); +aspeed_i2c_write_dma_len(f, td, ARRAY_SIZE(rx_data) - 1, true);
+ cmd =SHARED_FIELD_DP32(cmd, M_RX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_S_RX_CMD_LAST, 1); + cmd =SHARED_FIELD_DP32(cmd, RX_DMA_EN, 1);
+ sts =SHARED_FIELD_DP32(0, RX_DONE, 1);Quoted 8 lines
Quoted 8 lines
+ if (
pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + }
+aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+ for (uint8_ti = 0; i <ARRAY_SIZE(rx_data); i++) { + g_assert_cmphex(aspeed_i2c_read_dma(f,
DRAM_RX_OFFSET+Quoted 30 lines
Quoted 30 lines
i), ==,
+ rx_data[i]);
+ }tests/qtest/aspeed_i2c-test.c new file +19
-0+ + SEND_I2C_STOP(f, td); + CHECK_I2C_DUMMY_DEVICE(); + qtest_hmp(global_qtest, "system_reset"); } + +static void test_slave (TestFixture *f,gconstpointer p_data) { + const TestData *td = (const TestData *)p_data; + uint32_t cmd, sts, tmp; + bool pkt_mode = td->mode == TEST_I2C_MODE_PKT; + uint8_t offset = pkt_mode ? 0 : 1; + + aspeed_i2c_write_pool(f, offset + 0, I2C_ADDR_SLAVE); + aspeed_i2c_write_pool(f, offset + 1, tx_data[0]); + aspeed_i2c_write_pool(f, offset + 2, tx_data[1]); + + tmp = SHARED_FIELD_DP32(0, TX_COUNT, pkt_mode ? 2 : 3); + aspeed_i2c_write(f, aspeed_i2c_pool_ctrl_offset(td), tmp); + + cmd = aspeed_i2c_buf_set_addr_cmd(f, td, I2C_ADDR_ECHO,false);
+ cmd =SHARED_FIELD_DP32(cmd, M_START_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, M_TX_CMD, 1);
+ cmd =SHARED_FIELD_DP32(cmd, TX_BUFF_EN, 1);
+ sts =SHARED_FIELD_DP32(0, TX_ACK, 1);
+ if (pkt_mode) {
+ sts =FIELD_DP32(sts, I2CM_INTR_STS, PKT_CMD_DONE, 1); + }Quoted 8 lines
Quoted 8 lines
+
aspeed_i2c_write(f, aspeed_i2c_cmd_offset(td), cmd); +CHECK_I2C_BUS_ACTIVE(f, td);
+CLEAR_I2C_INTR(f, td, sts);
+
+ /* Send stop and handle i2c-echo response as a slave */ + if (td->mode==TEST_I2C_MODE_OLD) {
+ aspeed_i2c_write(f,aspeed_i2c_cmd_offset(td), + SHARED_FIELD_DP32(0,
M_STOP_CMD, 1));Quoted 6 lines
Quoted 6 lines
+
clock_step(1);
+g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, I2C_ADDR_SLAVE << 1);
+ sts =SHARED_FIELD_DP32(0, NORMAL_STOP, 1); + sts =SHARED_FIELD_DP32(sts, RX_DONE, 1); + sts = FIELD_DP32(sts,I2CD_INTR_STS,
SLAVE_ADDR_RX_MATCH,Quoted 12 lines
Quoted 12 lines
1);
+CHECK_I2C_INTR(f, td, sts);
+aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), sts);
+
+g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, tx_data[0]);
+ sts =SHARED_FIELD_DP32(0, RX_DONE, 1);
+CHECK_I2C_INTR(f, td, sts);
+aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), sts);
+Quoted 8 lines
Quoted 8 lines
+
g_assert_cmphex(aspeed_i2c_read_byte(f, td), ==, tx_data[1]);
+ sts =SHARED_FIELD_DP32(0, RX_DONE, 1);
+CHECK_I2C_INTR(f, td, sts);
+aspeed_i2c_write(f, aspeed_i2c_intr_sts_offset(td), sts);
+ } else {
+ aspeed_i2c_write(f,A_I2CS_DMA_RX_ADDR,
DRAM_RX_OFFSET);Quoted 5 lines
Quoted 5 lines
+ tmp =
SHARED_FIELD_DP32(0, RX_DMA_EN, 1); +aspeed_i2c_write(f, A_I2CS_CMD, tmp); +
+ aspeed_i2c_write(f,aspeed_i2c_cmd_offset(td), + SHARED_FIELD_DP32(0,
M_STOP_CMD, 1));Quoted 4 lines
Quoted 4 lines
+
clock_step(1);
+
+ tmp =FIELD_DP32(0, I2CS_DMA_LEN_STS, RX_LEN, 2); + g_assert_cmphex(aspeed_i2c_read(f,
A_I2CS_DMA_LEN_STS),Quoted 3 lines
Quoted 3 lines
==, tmp);
+ for (uint8_ti = 0; i < 2; i++) { + g_assert_cmphex(aspeed_i2c_read_dma(f,
DRAM_RX_OFFSETQuoted 40 lines
Quoted 40 lines
tests/qtest/aspeed_i2c-test.c new file +12
-0+i), ==, + tx_data[i]); + } + } + + sts = SHARED_FIELD_DP32(0, NORMAL_STOP, 1); + CLEAR_I2C_INTR(f, td, sts); + CHECK_I2C_IDLE(f, td); + + qtest_hmp(global_qtest, "system_reset"); } + +static void aspeed_i2c_init_fixture(TestFixture *fixture,const
TestData *td)tests/qtest/aspeed_i2c-test.c new file +26
-0+{ + switch (td->machine) { + case TEST_MACHINE_AST2400: + fixture->base_addr = 0x1E78A000; + fixture->bus_offset = 0x40; + fixture->irq_no = 12; + fixture->pool_base = 0x800; + break; + case TEST_MACHINE_AST2500: + fixture->base_addr = 0x1E78A000; + fixture->bus_offset = 0x40; + fixture->irq_no = 12; + fixture->pool_base = 0x200; + break; + case TEST_MACHINE_AST2600: + fixture->base_addr = 0x1E78A000; + fixture->bus_offset = 0x80; + fixture->irq_no = 110; + fixture->pool_base = 0xC00; + break; + default: + return; + } +} + +static void aspeed_i2c_init_test(TestFixture *fixture, constQuoted 8 lines
tests/qtest/aspeed_i2c-test.c line 725
Quoted 8 lines
TestData *td)
tests/qtest/aspeed_i2c-test.c new file +6
-0+{ + aspeed_i2c_init(fixture, td); + CHECK_I2C_IDLE(fixture, td); +} + +static void aspeed_i2c_init_new_machine(TestFixture *fixture,+ gconstpointer
p_data) {Quoted 33 lines
Quoted 33 lines
+ const TestData *td = (const TestData *)p_data; + const char *machine;
+ const char*irq_dev;tests/qtest/aspeed_i2c-test.c new file +28
-0+ + aspeed_i2c_init_fixture(fixture, td); + + if (global_qtest) { + qtest_quit(global_qtest); + } + + switch (td->machine) { + case TEST_MACHINE_AST2400: + machine = "palmetto-bmc"; + irq_dev = "/machine/soc/vic"; + break; + case TEST_MACHINE_AST2500: + machine = "ast2500-evb"; + irq_dev = "/machine/soc/vic"; + break; + case TEST_MACHINE_AST2600: + machine = "ast2600-evb"; + irq_dev = "/machine/soc/a7mpcore/gic"; + break; + default: + g_test_fail(); + return; + } + + global_qtest = qtest_initf( + "-machine %s -nographic " + "-device i2c-echo,id=i2c-echo,bus=aspeed.i2c.bus.0,address=%d "
+ "-device i2c-dummy-device,id=i2c-Quoted 8 lines
tests/qtest/aspeed_i2c-test.c
Quoted 8 lines
dummy,bus=aspeed.i2c.bus.0,address=%d",
+ machine,I2C_ADDR_ECHO,I2C_ADDR_DUMMY); +qtest_irq_intercept_in(global_qtest, irq_dev);tests/qtest/aspeed_i2c-test.c new file +5
-0+ + aspeed_i2c_init_test(fixture, td); } + +static void aspeed_i2c_init_machine (TestFixture *fixture, + gconstpointer
p_data) {Quoted 94 lines
Quoted 94 lines
+ const TestData *td = (const TestData *)p_data;
tests/qtest/aspeed_i2c-test.c new file +6
-0+ + aspeed_i2c_init_fixture(fixture, td); + aspeed_i2c_init_test(fixture, td); } + +static void add_test(const TestData *td, const char *name, + void (*func)(TestFixture *, const void*),
+ bool setup)tests/qtest/aspeed_i2c-test.c new file +7
-0+{ + g_autofree char *test_name; + + test_name = g_strdup_printf("%s/%s", td->name, name); + + qtest_add(test_name, TestFixture, td, + setup ? aspeed_i2c_init_new_machine :
aspeed_i2c_init_machine,
+ func, NULL);tests/qtest/aspeed_i2c-test.c new file +3
-0+} + +#define ADD_TEST (td, test, new) add_test(td, #test,test_##test,
new)tests/qtest/aspeed_i2c-test.c new file +35
-1+ +static const TestData test_data[] = { + { + .name = "ast2400", + .machine = TEST_MACHINE_AST2400, + }, + { + .name = "ast2500", + .machine = TEST_MACHINE_AST2500, + }, + { + .name = "ast2600", + .machine = TEST_MACHINE_AST2600, + }, + { + .name = "ast2600-new", + .machine = TEST_MACHINE_AST2600, + .mode = TEST_I2C_MODE_NEW, + }, + { + .name = "ast2600-packet", + .machine = TEST_MACHINE_AST2600, + .mode = TEST_I2C_MODE_PKT, + }, +}; + +int main (int argc,char **argv) +{ + int ret; + bool setup; + + g_test_init(&argc, &argv, NULL); + + for (int i = 0; i < ARRAY_SIZE(test_data); i++) { + setup = i == 0 || test_data[i].machine != test_data[i -1].machine;
+ADD_TEST(&test_data[i], nack, setup);
+ADD_TEST(&test_data[i], dummy_byte, false); +ADD_TEST(&test_data[i], dummy_buf, false); + if (test_data[i].machine !=TEST_MACHINE_AST2400) { +ADD_TEST(&test_data[i], dummy_dma, false); + }
+ADD_TEST(&test_data[i], slave, false);
+ }tests/qtest/aspeed_i2c-test.c new file +5
-0+ + ret = g_test_run(); + qtest_quit(global_qtest); + return ret; +}tests/qtest/meson.build +0
-0index
46d4fc1d2b..c496b7c3a7100644tests/qtest/meson.build +1
-0@@ -233,12 +233,14 @@ qtests_aspeed = \ ['aspeed-acry-test', 'aspeed_gpio-test', 'aspeed_hace-test', + 'aspeed_i2c-test', 'aspeed-sbc-test', 'aspeed_scu-test','aspeed_smc-test']
qtests_aspeed64= \
['ast2700-gpio-test',
'ast2700-hace-test',
+ 'aspeed_i2c-test',
'ast2700-sgpio-test',
'ast2700-smc-test']
Jamin,
Could you please check the Fix changes, patch 2-5 ? They appear to be valid additions but I would like a second opinion.
Thanks,
C.
Quoted 33 lines · Timur Maksimov
In non-packet mode, buffer and DMA modes are broken in the Aspeed I2C controller,
probably because no available driver currently uses them. This patch fixes them, so byte, buffer, and DMA transfer modes now work correctly for both register modes, old and new ones. Tests are provided to prevent possible regressions.Signed-off-by Timur Maksimov <[email protected]>---
Changes in v2:
- Fix commits description format. Some of them are reordered and clarified.
- Link to v1: https://lore.kernel.org/qemu-devel/[email protected]---
Timur Maksimov (6):
hw/i2c: add dummy device
hw/i2c/aspeed: fix BUSY status reading in new register mode hw/i2c/aspeed: fixI2CD_CMDregister reading hw/i2c/aspeed: fix buffer transfer in non-packet mode hw/i2c/aspeed: fix DMA transfer in non-packet mode tests/qtest: Add cases for 32-bit Aspeed I2C controllershw/i2c/Kconfig | 5 + hw/i2c/aspeed_i2c.c | 23 +- hw/i2c/i2c-dummy-device.c | 168 +++++++++ hw/i2c/meson.build | 3 +- tests/qtest/aspeed_i2c-test.c | 836 ++++++++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 + 6 files changed, 1029 insertions(+), 8 deletions(-)---
base-commit:9b77fa7a4fe86c80d1ff526769c61ada7d28666a
change-id: 20261025-aspeed-i2c-nonpkt-fix-89b852b5c84a