NXP i.MX RT595
v2 cover NXP i.MX RT595
This patch set adds support for NXP's RT500 MCU [1] and the RT595 EVK[2]. More RT500 device models will be submitted in future patch sets.
This is a minimal patch set that allows running the NXP MCU SDK hello world example[4].
The patch set introduces a (python) tool that generates C header files from ARM SVD files[3]. This significantly reduces the effort to write a new device model by automatically generating: register definitions and layout (including bit fields), register names for easier debugging and tracing, reset register values, register write masks, etc.
The generated files are commited and not generated at compile time. Build targets are created so that they can be easily regenerated if needed.
Changes since v1:
* svd_gen_header: remove field values generation for 1 bit fields, add options to control which registers and fields to be generated, switch to using defines instead of enums for field values with more than 1 bit
* i2c-tester: document the rationale and basic functionality in the header
Changes since RFC v3:
* rewrite the flexcomm devices to take advantage of QEMU's object model / class inheritance and overlapped memory region and remove the adhoc flexcomm APIs
* remove code duplication by using common fifo functions for USART and SPI
* fix copyright in one of the headers
* remove hw/registerfields.h from generated headers as hw/register.h is already included
* fix signed off email address for the qtests API patches
* fix description (tests/unit -> tests/qtest) for RT500 clock controller tests
* convert devices to use the Resettable interfaces
* add support for migration
* rework the fifo32 tests on top of Mark's and Phillippe's work
Changes since RFC v2:
* convert tests from unit to qtest
* move i2c and spi testers from unit tests to hw/misc devices
* switch to using RegisterAccessInfo to generate register information like register names, reset values, or read-only mask
* use register_write instead of adding a new reg32_write API
* remove reg32_aligned_access completly and rely on memops access constraints and size of access for alignment checks
* add qtest APIs for checking memory access faulires
* add qtest APIs for accessing the device clock frequency
* fix bugs detected by address sanitizers
Changes since RFC v1:
* setup scripts/git.orderfile
* svd_gen_header: add support for multi line comments
* svd_gen_header: use qemu register fields instead of bitfields
* svd_gen_header: generate register write mask array
* add mcux-soc-svd as a subproject instead of commiting the rt595 SVD file directly
* svd generated headers: don't generate them at compile time, instead commit the generated headers and create compile targets so that it is easy to regenerate them
* remove pysvd dependency; developers who need to (re)generate svd headers need to have it installed on the host machine
* use DEFINE_TYPES where possible
* use g_strdup_printf where possible
* reduce iterator variables scopes
* hard code rt500 to use the cortex-m33
* use static for local arrays initializers
* remove rt500 properties as they are not yet used
* drop private/public comments
* remove unused headers
* free rt500 mem regions in rt500_unrealize() instead of rt500_finalize
* use memops access constraints where possible instead of reg32_aligned_access
* flexspi: use 64bit properties for mmap_size property
* rstctl: use a generic abstract type and remove the "num" property
* flexspi: don't call get_system_memory() directly and remove mmap_base property
[1] https://www.nxp.com/docs/en/data-sheet/IMXRT500EC.pdf
[2] https://www.nxp.com/webapp/Download?colCode=MIMXRT595EVKHUG
[3] https://arm-software.github.io/CMSIS_5/SVD/html/index.html
[4] Building and running the NXP MCU SDK hello world example
Clone the following git repos:
https://github.com/nxp-mcuxpresso/cmsis.git,
https://github.com/nxp-mcuxpresso/mcux-sdk.git
https://github.com/nxp-mcuxpresso/mcux-sdk-examples.git
in the following directories: CMSIS, core, examples.
cd examples/evkmimxrt595/demo_apps/hello_world/armgcc
ARMGCC_DIR=/usr CFLAGS=-I../../../../../CMSIS/CMSIS/Core/Include \
sh build_flash_debug.sh
qemu-system-arm --machine rt595-evk -kernel flash_debug/hello_world.elf \
-global armv7m.init-nsvtor=0x08001000 -global armv7m.init-svtor=0x08001000 \
-chardev stdio,id=flexcomm0Octavian Purdila (22):
fifo32: add peek function
tests/unit: add fifo32 tests
Add mcux-soc-svd subproject
hw/misc: add support for flexcomm hw/misc/flexcomm.c: add common fifo functionality hw/char: add support for flexcomm usart
hw/i2c: add support for flexcomm i2c
hw/misc: add support for RT500's clock controller hw/ssi: add support for flexspi
hw/misc: add support for RT500's reset controller hw/arm: add basic support for the RT500 SoC hw/arm: add RT595-EVK board
tests/qtest: add register access macros and functions system/qtest: add APIS to check for memory access failures tests/qtest: add flexcomm tests
tests/qtest: add flexcomm usart tests
hw/misc: add i2c-tester
tests/qtest: add tests for flexcomm i2c
hw/ssi: allow NULL realize callbacks for peripherals hw/misc: add spi-tester
systems/qtest: add device clock APIs tests/qtest: add tests for RT500's clock controller
Sebastian Ene (2):
hw/ssi: add support for flexcomm spi
tests/qtest: add tests for flexcomm spi
Stefan Stanacar (1):
scripts: add script to generate C header files from SVD XML files
meson.build | 4 + include/hw/arm/rt500.h | 44 + include/hw/arm/svd/flexcomm.h | 70 ++ include/hw/arm/svd/flexcomm_i2c.h | 229 ++++ include/hw/arm/svd/flexcomm_spi.h | 327 +++++ include/hw/arm/svd/flexcomm_usart.h | 294 +++++ include/hw/arm/svd/flexspi.h | 1085 +++++++++++++++++ include/hw/arm/svd/rt500.h | 63 + include/hw/arm/svd/rt500_clkctl0.h | 509 ++++++++ include/hw/arm/svd/rt500_clkctl1.h | 675 ++++++++++ include/hw/arm/svd/rt500_rstctl0.h | 110 ++ include/hw/arm/svd/rt500_rstctl1.h | 110 ++ include/hw/char/flexcomm_usart.h | 33 + include/hw/i2c/flexcomm_i2c.h | 40 + include/hw/misc/flexcomm.h | 57 + include/hw/misc/flexcomm_function.h | 55 + include/hw/misc/i2c_tester.h | 43 + include/hw/misc/rt500_clk_freqs.h | 18 + include/hw/misc/rt500_clkctl0.h | 35 + include/hw/misc/rt500_clkctl1.h | 36 + include/hw/misc/rt500_rstctl.h | 32 + include/hw/misc/spi_tester.h | 32 + include/hw/qdev-clock.h | 10 + include/hw/ssi/flexcomm_spi.h | 36 + include/hw/ssi/flexspi.h | 31 + include/qemu/fifo32.h | 28 + tests/qtest/libqtest-single.h | 116 ++ tests/qtest/libqtest.h | 98 ++ tests/qtest/reg-utils.h | 70 ++ hw/arm/rt500.c | 329 +++++ hw/arm/rt595-evk.c | 64 + hw/char/flexcomm_usart.c | 288 +++++ hw/core/qdev-clock.c | 2 +- hw/i2c/flexcomm_i2c.c | 250 ++++ hw/misc/flexcomm.c | 411 +++++++ hw/misc/i2c_tester.c | 109 ++ hw/misc/rt500_clkctl0.c | 253 ++++ hw/misc/rt500_clkctl1.c | 238 ++++ hw/misc/rt500_rstctl.c | 258 ++++ hw/misc/spi_tester.c | 67 + hw/ssi/flexcomm_spi.c | 422 +++++++ hw/ssi/flexspi.c | 181 +++ hw/ssi/ssi.c | 4 +- system/qtest.c | 95 +- tests/qtest/flexcomm-i2c-test.c | 170 +++ tests/qtest/flexcomm-spi-test.c | 145 +++ tests/qtest/flexcomm-test.c | 82 ++ tests/qtest/flexcomm-usart-test.c | 316 +++++ tests/qtest/libqtest.c | 102 +- tests/qtest/rt500-clkctl-test.c | 195 +++ tests/unit/test-fifo.c | 50 + hw/arm/Kconfig | 12 + hw/arm/meson.build | 4 + hw/arm/svd/meson.build | 43 + hw/char/meson.build | 1 + hw/char/trace-events | 8 + hw/i2c/meson.build | 1 + hw/i2c/trace-events | 10 + hw/misc/Kconfig | 21 + hw/misc/meson.build | 7 + hw/misc/trace-events | 18 + hw/ssi/Kconfig | 4 + hw/ssi/meson.build | 2 + hw/ssi/trace-events | 9 + meson_options.txt | 3 + scripts/meson-buildoptions.sh | 4 + scripts/svd-gen-header.py | 415 +++++++ subprojects/.gitignore | 1 + subprojects/mcux-soc-svd.wrap | 5 + .../packagefiles/mcux-soc-svd/meson.build | 5 + tests/qtest/meson.build | 3 + 71 files changed, 8875 insertions(+), 22 deletions(-) create mode 100644 include/hw/arm/rt500.h create mode 100644 include/hw/arm/svd/flexcomm.h create mode 100644 include/hw/arm/svd/flexcomm_i2c.h create mode 100644 include/hw/arm/svd/flexcomm_spi.h create mode 100644 include/hw/arm/svd/flexcomm_usart.h create mode 100644 include/hw/arm/svd/flexspi.h create mode 100644 include/hw/arm/svd/rt500.h create mode 100644 include/hw/arm/svd/rt500_clkctl0.h create mode 100644 include/hw/arm/svd/rt500_clkctl1.h create mode 100644 include/hw/arm/svd/rt500_rstctl0.h create mode 100644 include/hw/arm/svd/rt500_rstctl1.h create mode 100644 include/hw/char/flexcomm_usart.h create mode 100644 include/hw/i2c/flexcomm_i2c.h create mode 100644 include/hw/misc/flexcomm.h create mode 100644 include/hw/misc/flexcomm_function.h create mode 100644 include/hw/misc/i2c_tester.h create mode 100644 include/hw/misc/rt500_clk_freqs.h create mode 100644 include/hw/misc/rt500_clkctl0.h create mode 100644 include/hw/misc/rt500_clkctl1.h create mode 100644 include/hw/misc/rt500_rstctl.h create mode 100644 include/hw/misc/spi_tester.h create mode 100644 include/hw/ssi/flexcomm_spi.h create mode 100644 include/hw/ssi/flexspi.h create mode 100644 tests/qtest/reg-utils.h create mode 100644 hw/arm/rt500.c create mode 100644 hw/arm/rt595-evk.c create mode 100644 hw/char/flexcomm_usart.c create mode 100644 hw/i2c/flexcomm_i2c.c create mode 100644 hw/misc/flexcomm.c create mode 100644 hw/misc/i2c_tester.c create mode 100644 hw/misc/rt500_clkctl0.c create mode 100644 hw/misc/rt500_clkctl1.c create mode 100644 hw/misc/rt500_rstctl.c create mode 100644 hw/misc/spi_tester.c create mode 100644 hw/ssi/flexcomm_spi.c create mode 100644 hw/ssi/flexspi.c create mode 100644 tests/qtest/flexcomm-i2c-test.c create mode 100644 tests/qtest/flexcomm-spi-test.c create mode 100644 tests/qtest/flexcomm-test.c create mode 100644 tests/qtest/flexcomm-usart-test.c create mode 100644 tests/qtest/rt500-clkctl-test.c create mode 100644 hw/arm/svd/meson.build create mode 100755 scripts/svd-gen-header.py create mode 100644 subprojects/mcux-soc-svd.wrap create mode 100644 subprojects/packagefiles/mcux-soc-svd/meson.build
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 1/25 fifo32: add peek function
Add fifo32_peek() that returns the first element from the queue without popping it.
--- include/qemu/fifo32.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
include/qemu/fifo32.h +28 -0
@@ -140,6 +140,34 @@ static inline uint32_t fifo32_pop(Fifo32 *fifo)return ret; } +/** +* fifo32_peek: +* @fifo: fifo to peek at +* +* Returns the value from the FIFO's head without poping it. Behaviour +* is undefined if the FIFO is empty. Clients are responsible for +* checking for emptiness using fifo32_is_empty(). +* +* Returns: the value from the FIFO's head +*/ + +static inline uint32_t fifo32_peek (Fifo32 *fifo) +{ +uint32_t ret =0 , num; +const uint8_t *buf; + + buf =fifo8_peek_bufptr (&fifo->fifo,4 , &num); +if (num !=4 ) { +return ret; + } + +for (int i =0 ; i <sizeof (uint32_t ); i++) { + ret |= buf[i] << (i *8 ); + } + +return ret; +} +/** * There is no fifo32_pop_buf() because the data is not stored in the buffer * as a set of native-order words.
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
Re: [PATCH v2 01/25] fifo32: add peek function
Quoted 23 lines · Octavian Purdila
Add
fifo32_peek()that returns the first element from the queue without popping it.Signed-off-by Octavian Purdila <[email protected]>--- include/qemu/fifo32.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)include/qemu/fifo32.h +7
-0@@ -140,6 +140,34 @@ static inline uint32_t fifo32_pop(Fifo32 *fifo)return ret; } +/** +* fifo32_peek: +* @fifo: fifo to peek at +* +* Returns the value from the FIFO's head without poping it. Behaviour +* is undefined if the FIFO is empty. Clients are responsible for +* checking for emptiness using fifo32_is_empty().
include/qemu/fifo32.h static inline uint32_t fifo32_pop(Fifo32 *fifo) · line 159
Quoted 10 lines
include/qemu/fifo32.h +10
-0+* +* Returns: the value from the FIFO's head +*/ + +static inline uint32_t fifo32_peek (Fifo32 *fifo) +{ +uint32_t ret =0 , num; +const uint8_t *buf; + + buf =fifo8_peek_bufptr (&fifo->fifo,4 , &num);
Are you sure that you want to use fifo8_peek_bufptr() as opposed to fifo8_peek_buf() here? The reason for using the latter function (and why fifo8_*_bufptr() functions are not generally recommended) is that they will correctly handle the FIFO wraparound caused by the drifting head pointer which can occur if you don't empty the entire FIFO contents in a single *_pop() or *_pop_buf() operation.
Quoted 4 lines
include/qemu/fifo32.h +4
-0+if (num !=4 ) { +return ret; + } +
include/qemu/fifo32.h static inline uint32_t fifo32_pop(Fifo32 *fifo) · line 173
Quoted 10 lines
include/qemu/fifo32.h +7
-0+for (int i =0 ; i <sizeof (uint32_t ); i++) { + ret |= buf[i] << (i *8 ); + } + +return ret; +} +/** * There is no fifo32_pop_buf() because the data is not stored in the buffer * as a set of native-order words.
ATB,
Mark.
Re: [PATCH v2 01/25] fifo32: add peek function
Quoted 34 lines · Mark Cave-Ayland
Quoted 31 lines · Octavian Purdila
Add
fifo32_peek()that returns the first element from the queue without popping it.Signed-off-by Octavian Purdila <[email protected]>--- include/qemu/fifo32.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)include/qemu/fifo32.h +15
-0@@ -140,6 +140,34 @@ static inline uint32_t fifo32_pop(Fifo32 *fifo)return ret; } +/** +* fifo32_peek: +* @fifo: fifo to peek at +* +* Returns the value from the FIFO's head without poping it. Behaviour +* is undefined if the FIFO is empty. Clients are responsible for +* checking for emptiness using fifo32_is_empty(). +* +* Returns: the value from the FIFO's head +*/ + +static inline uint32_t fifo32_peek (Fifo32 *fifo) +{ +uint32_t ret =0 , num; +const uint8_t *buf;
Quoted 9 lines
include/qemu/fifo32.h static inline uint32_t fifo32_pop(Fifo32 *fifo) · line 159
Quoted 2 lines
include/qemu/fifo32.h +2
-0+ + buf =fifo8_peek_bufptr (&fifo->fifo,4 , &num);Are you sure that you want to use
fifo8_peek_bufptr()as opposed tofifo8_peek_buf()here? The reason for using the latter function (and why fifo8_*_bufptr() functions are not generally recommended) is that they will correctly handle the FIFO wraparound caused by the drifting head pointer which can occur if you don't empty the entire FIFO contents in a single*_pop()or*_pop_buf()operation.
I don't think that it matters in this case because the size of the FIFO is always going to be a multiple of 4 and all push and pop operations happen with 4 bytes as well. Am I missing something?
In any case, if it makes things more clear / consistent I can switch to fifo8_peek_buf.
Quoted 20 lines
Quoted 4 lines
include/qemu/fifo32.h +4
-0+if (num !=4 ) { +return ret; + } +include/qemu/fifo32.h static inline uint32_t fifo32_pop(Fifo32 *fifo) · line 173
Quoted 10 lines
include/qemu/fifo32.h +7
-0+for (int i =0 ; i <sizeof (uint32_t ); i++) { + ret |= buf[i] << (i *8 ); + } + +return ret; +} +/** * There is no fifo32_pop_buf() because the data is not stored in the buffer * as a set of native-order words. ATB,
Mark.
Re: [PATCH v2 01/25] fifo32: add peek function
Quoted 46 lines · Octavian Purdila
Quoted 34 lines · Mark Cave-Ayland
Quoted 31 lines · Octavian Purdila
Add
fifo32_peek()that returns the first element from the queue without popping it.Signed-off-by Octavian Purdila <[email protected]>--- include/qemu/fifo32.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)include/qemu/fifo32.h +15
-0@@ -140,6 +140,34 @@ static inline uint32_t fifo32_pop(Fifo32 *fifo)return ret; } +/** +* fifo32_peek: +* @fifo: fifo to peek at +* +* Returns the value from the FIFO's head without poping it. Behaviour +* is undefined if the FIFO is empty. Clients are responsible for +* checking for emptiness using fifo32_is_empty(). +* +* Returns: the value from the FIFO's head +*/ + +static inline uint32_t fifo32_peek (Fifo32 *fifo) +{ +uint32_t ret =0 , num; +const uint8_t *buf;Quoted 9 lines
include/qemu/fifo32.h static inline uint32_t fifo32_pop(Fifo32 *fifo) · line 159
Quoted 2 lines
include/qemu/fifo32.h +2
-0+ + buf =fifo8_peek_bufptr (&fifo->fifo,4 , &num);Are you sure that you want to use
fifo8_peek_bufptr()as opposed tofifo8_peek_buf()here? The reason for using the latter function (and why fifo8_*_bufptr() functions are not generally recommended) is that they will correctly handle the FIFO wraparound caused by the drifting head pointer which can occur if you don't empty the entire FIFO contents in a single*_pop()or*_pop_buf()operation.
Quoted 6 lines
I don't think that it matters in this case because the size of the FIFO is always going to be a multiple of 4 and all push and pop operations happen with 4 bytes as well. Am I missing something?
In any case, if it makes things more clear / consistent I can switch to
fifo8_peek_buf.
I'm guess I'm just a little bit wary of the Fifo32 API since it appears that fifo32_num_used(), fifo32_num_free() and fifo32_is_full() are written in a way that suggests unaligned accesses can occur.
Given that fifo8_push() and fifo8_pop() should assert() upon failure I don't think that's possible for Fifo32, but then all my test cases use Fifo8.
If you're confident from your tests that this can't happen then we can leave it as-is.
ATB,
Mark.
PATCH v2 2/25 tests/unit: add fifo32 tests
In reply to Octavian PurdilaAdd push/pop and peek tests for fifo32.
--- tests/unit/test-fifo.c | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
tests/unit/test-fifo.c +50 -0
@@ -13,6 +13,7 @@#include "qemu/osdep.h" #include "migration/vmstate.h" #include "qemu/fifo8.h" +#include "qemu/fifo32.h" const VMStateInfo vmstate_info_uint32;const VMStateInfo vmstate_info_buffer;
@@ -432,6 +433,53 @@ static void test_fifo8_pushpop(void)fifo8_destroy (&fifo); } +static void test_fifo32_pushpop (void ) +{ +Fifo32 fifo; +uint32_t e; + +fifo32_create (&fifo,2 ); +fifo32_push (&fifo,0x11121314 ); +fifo32_push (&fifo,0x21222324 ); +g_assert (fifo32_num_used (&fifo) ==2 ); + + e =fifo32_pop (&fifo); +g_assert (e ==0x11121314 ); +g_assert (fifo32_num_used (&fifo) ==1 ); + + e =fifo32_peek (&fifo); +g_assert (e ==0x21222324 ); + +g_assert (fifo32_num_used (&fifo) ==1 ); +fifo32_destroy (&fifo); +} + +static void test_fifo32_peek (void ) +{ +Fifo32 fifo; +uint32_t e; + +fifo32_create (&fifo,2 ); +fifo32_push (&fifo,0x11121314 ); +fifo32_push (&fifo,0x21222324 ); +g_assert (fifo32_num_used (&fifo) ==2 ); + + e =fifo32_peek (&fifo); +g_assert (e ==0x11121314 ); +g_assert (fifo32_num_used (&fifo) ==2 ); + + e =fifo32_pop (&fifo); +g_assert (e ==0x11121314 ); +g_assert (fifo32_num_used (&fifo) ==1 ); + + e =fifo32_peek (&fifo); +g_assert (e ==0x21222324 ); +g_assert (fifo32_num_used (&fifo) ==1 ); + +fifo32_destroy (&fifo); +} + +int main (int argc,char *argv[]) {g_test_init (&argc, &argv,NULL );
@@ -445,5 +493,7 @@ int main(int argc, char *argv[])g_test_add_func ("/fifo8/peek_bufptr_wrap" , test_fifo8_peek_bufptr_wrap);g_test_add_func ("/fifo8/pop_bufptr" , test_fifo8_pop_bufptr);g_test_add_func ("/fifo8/pop_bufptr_wrap" , test_fifo8_pop_bufptr_wrap); +g_test_add_func ("/fifo32/pushpop" , test_fifo32_pushpop); +g_test_add_func ("/fifo32/peek" , test_fifo32_peek);return g_test_run (); }
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 3/25 scripts: add script to generate C header files from SVD XML files
In reply to Octavian PurdilaFrom: Stefan Stanacar <[email protected]>
The CMSIS System View Description format(CMSIS-SVD) is an XML based description of Arm Cortex-M microcontrollers provided and maintained by sillicon vendors. It includes details such as peripherals registers (down to bitfields), peripheral register block addresses, reset values, etc.
This script uses this information to create header files that makes it easier to emulate peripherals.
The script can be used to create either peripheral specific headers or board / system specific information.
Peripheral specific headers contains information such as register layout (using the qemu register fields infrastructure), register names, register write masks and register reset values, the latter using RegisterAccessInfo.
Here is an excerpt from a generated header:
#pragma once
#include "hw/registerfields.h"
/* Flexcomm */
#define FLEXCOMM_REGS_NO (1024)
/* Peripheral Select and Flexcomm module ID */
REG32(FLEXCOMM_PSELID, 4088);
/* Peripheral Select */
FIELD(FLEXCOMM_PSELID, PERSEL, 0, 3);
/* No peripheral selected. */
#define FLEXCOMM_PSELID_PERSEL_NO_PERIPH_SELECTED 0
/* USART function selected */
#define FLEXCOMM_PSELID_PERSEL_USART 1
/* SPI function selected */
#define FLEXCOMM_PSELID_PERSEL_SPI 2
/* I2C */
#define FLEXCOMM_PSELID_PERSEL_I2C 3
/* I2S Transmit */
#define FLEXCOMM_PSELID_PERSEL_I2S_TRANSMIT 4
/* I2S Receive */
#define FLEXCOMM_PSELID_PERSEL_I2S_RECEIVE 5
...
#define FLEXCOMM_REGISTER_ACCESS_INFO_ARRAY(_name) \
struct RegisterAccessInfo _name[FLEXCOMM_REGS_NO] = { \
[0 ... FLEXCOMM_REGS_NO -1] = { \
.name = "", \
.addr = -1, \
}, \
[0x3FE] = { \
.name = "PSELID", \
.addr = 0xFF8, \
.ro = 0xFFFFFFF0, \
.reset = 0x101000, \
}, \
[0x3FF] = { \
.name = "PID", \
.addr = 0xFFC, \
.ro = 0xFFFFFFFF, \
.reset = 0x0, \
}, \
}The script has options to control which registers and fields should be generated.
Board specific headers contains information about peripheral base register addresses.
[tavip: pylint fixes, generate layout with qemu register fields instead of bitfields, generate register names, romask and reset values, add options to control which register and fields are generated]
--- meson.build | 4 + scripts/svd-gen-header.py | 415 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 419 insertions(+) create mode 100755 scripts/svd-gen-header.py
meson.build +4 -0
@@ -3330,6 +3330,10 @@ tracetool_depends = files( 'scripts/tracetool/__init__.py', ) +svd_gen_header = [ + python, files('scripts/svd-gen-header.py') +] + qemu_version_cmd = [find_program('scripts/qemu-version.sh'), meson.current_source_dir(), get_option('pkgversion'), meson.project_version()]
scripts/svd-gen-header.py new file +415 -0
415 lines not on this page · raw message
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 4/25 Add mcux-soc-svd subproject
In reply to Octavian PurdilaAdd mcux-soc-svd subproject that contains SVD files that are going to be used to generate C header with register layout definitions and other helpers to create device models.
Guard the subproject by a configuration option since it is rarely going to be used - whenever new headers will be generated. It is unlikely that already generated headers will be updated, with the exception of minor hardware revisions.
Also export the rt595 SVD file which is going to be used by subsequent patches.
TBD: switch to a qemu gitlab fork before merge
--- hw/arm/svd/meson.build | 4 ++++ meson_options.txt | 3 +++ scripts/meson-buildoptions.sh | 4 ++++ subprojects/.gitignore | 1 + subprojects/mcux-soc-svd.wrap | 5 +++++ subprojects/packagefiles/mcux-soc-svd/meson.build | 5 +++++ 6 files changed, 22 insertions(+) create mode 100644 hw/arm/svd/meson.build create mode 100644 subprojects/mcux-soc-svd.wrap create mode 100644 subprojects/packagefiles/mcux-soc-svd/meson.build
hw/arm/svd/meson.build new file +4 -0
@@ -0,0 +1,4 @@ +if get_option('mcux-soc-svd') + mcux_soc_svd = subproject('mcux-soc-svd') + rt595 = mcux_soc_svd.get_variable('rt595') +endif
meson_options.txt +3 -0
@@ -373,3 +373,6 @@ option('hexagon_idef_parser', type : 'boolean', value : true, option('x86_version', type : 'combo', choices : ['0', '1', '2', '3', '4'], value: '1', description: 'tweak required x86_64 architecture version beyond compiler default') + +option('mcux-soc-svd', type : 'boolean', value : false, + description: 'enable targets to generate C headers from mcux-soc-svd')
scripts/meson-buildoptions.sh +4 -0
@@ -41,6 +41,8 @@ meson_options_help() { printf "%s\n" ' --enable-lto Use link time optimization' printf "%s\n" ' --enable-malloc=CHOICE choose memory allocator to use [system] (choices:' printf "%s\n" ' jemalloc/system/tcmalloc)' + printf "%s\n" ' --enable-mcux-soc-svd enable targets to generate C headers from mcux-' + printf "%s\n" ' soc-svd' printf "%s\n" ' --enable-module-upgrades try to load modules from alternate paths for' printf "%s\n" ' upgrades' printf "%s\n" ' --enable-rng-none dummy RNG, avoid using /dev/(u)random and'
@@ -393,6 +395,8 @@ _meson_option_parse() { --enable-malloc-trim) printf "%s" -Dmalloc_trim=enabled ;; --disable-malloc-trim) printf "%s" -Dmalloc_trim=disabled ;; --mandir=*) quote_sh "-Dmandir=$2" ;; + --enable-mcux-soc-svd) printf "%s" -Dmcux-soc-svd=true ;; + --disable-mcux-soc-svd) printf "%s" -Dmcux-soc-svd=false ;; --enable-membarrier) printf "%s" -Dmembarrier=enabled ;; --disable-membarrier) printf "%s" -Dmembarrier=disabled ;; --enable-module-upgrades) printf "%s" -Dmodule_upgrades=true ;;
subprojects/.gitignore +1 -0
@@ -6,3 +6,4 @@ /keycodemapdb /libvfio-user /slirp +/mcux-soc-svd
subprojects/mcux-soc-svd.wrap new file +5 -0
@@ -0,0 +1,5 @@ +[wrap-git] +url = https://github.com/nxp-mcuxpresso/mcux-soc-svd/ +revision = 7f6f9ef7420144fe14cd9bc4d8e0e3523232da04 +patch_directory = mcux-soc-svd +depth = 1
subprojects/packagefiles/mcux-soc-svd/meson.build new file +5 -0
@@ -0,0 +1,5 @@ +project('mcux-soc-svd') + +fs = import('fs') + +rt595 = fs.copyfile('MIMXRT595S/MIMXRT595S_cm33.xml')
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 5/25 hw/misc: add support for flexcomm
In reply to Octavian PurdilaAdd support for NXP's FLEXCOMM device model.
FLEXCOMM is a generic serial communication module which support multiple functions: UART, SPI and I2C. These are configurable at runtime.
An abstract FlexcomFunction class is created that will be extended for specific functions. Each function has a dedicated overlapped MemoryRegion that it is going to be activated when that particular function is selected.
A generic MemoryRegion is used to map generic registers (PSELID, PID) that is always active but has a lower priority. The function memory region is trimed to not include the generic registers.
The FlexcommFunction object also gets access to the (non-concurrently) shared register backstore.
The patch includes an automatically generated header which contains the register layout and helpers.
The header can be regenerated with the svd-flexcomm target when the build is configured with --enable-mcux-soc-svd.
--- include/hw/arm/svd/flexcomm.h | 70 ++++++ include/hw/misc/flexcomm.h | 49 +++++ include/hw/misc/flexcomm_function.h | 47 ++++ hw/misc/flexcomm.c | 319 ++++++++++++++++++++++++++++ hw/arm/meson.build | 2 + hw/arm/svd/meson.build | 3 + hw/misc/Kconfig | 3 + hw/misc/meson.build | 2 + hw/misc/trace-events | 5 + 9 files changed, 500 insertions(+) create mode 100644 include/hw/arm/svd/flexcomm.h create mode 100644 include/hw/misc/flexcomm.h create mode 100644 include/hw/misc/flexcomm_function.h create mode 100644 hw/misc/flexcomm.c
include/hw/arm/svd/flexcomm.h new file +70 -0
@@ -0,0 +1,70 @@ +/* +* Copyright 2016-2023 NXP SPDX-License-Identifier: BSD-3-Clause +* +* Automatically generated by svd-gen-header.py from MIMXRT595S_cm33.xml +*/ +#pragma once + +#include "hw/register.h" + +/* Flexcomm */ +#define FLEXCOMM_REGS_NO (1024) + +/* Peripheral Select and Flexcomm module ID */ +REG32 (FLEXCOMM_PSELID ,0xFF8 ); +/* Peripheral Select */ +FIELD (FLEXCOMM_PSELID ,PERSEL ,0 ,3 ); +/* No peripheral selected. */ +#define FLEXCOMM_PSELID_PERSEL_NO_PERIPH_SELECTED 0 +/* USART function selected */ +#define FLEXCOMM_PSELID_PERSEL_USART 1 +/* SPI function selected */ +#define FLEXCOMM_PSELID_PERSEL_SPI 2 +/* I2C */ +#define FLEXCOMM_PSELID_PERSEL_I2C 3 +/* I2S Transmit */ +#define FLEXCOMM_PSELID_PERSEL_I2S_TRANSMIT 4 +/* I2S Receive */ +#define FLEXCOMM_PSELID_PERSEL_I2S_RECEIVE 5 +/* Lock the peripheral select */ +FIELD (FLEXCOMM_PSELID ,LOCK ,3 ,1 ); +/* USART present indicator */ +FIELD (FLEXCOMM_PSELID ,USARTPRESENT ,4 ,1 ); +/* SPI present indicator */ +FIELD (FLEXCOMM_PSELID ,SPIPRESENT ,5 ,1 ); +/* I2C present indicator */ +FIELD (FLEXCOMM_PSELID ,I2CPRESENT ,6 ,1 ); +/* I2S Present */ +FIELD (FLEXCOMM_PSELID ,I2SPRESENT ,7 ,1 ); +/* Flexcomm ID */ +FIELD (FLEXCOMM_PSELID ,ID ,12 ,20 ); + +/* Peripheral Identification */ +REG32 (FLEXCOMM_PID ,0xFFC ); +/* Minor revision of module implementation */ +FIELD (FLEXCOMM_PID , Minor_Rev,8 ,4 ); +/* Major revision of module implementation */ +FIELD (FLEXCOMM_PID , Major_Rev,12 ,4 ); +/* Module identifier for the selected function */ +FIELD (FLEXCOMM_PID ,ID ,16 ,16 ); + + +#define FLEXCOMM_REGISTER_ACCESS_INFO_ARRAY (_name) \ + struct RegisterAccessInfo _name[FLEXCOMM_REGS_NO] = { \ + [0 ... FLEXCOMM_REGS_NO - 1] = { \ + .name = "", \ + .addr = -1, \ + }, \ + [0x3FE] = { \ + .name = "PSELID", \ + .addr = 0xFF8, \ + .ro = 0xFFFFFFF0, \ + .reset = 0x101000, \ + }, \ + [0x3FF] = { \ + .name = "PID", \ + .addr = 0xFFC, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + }
include/hw/misc/flexcomm.h new file +49 -0
49 lines not on this page · raw message
include/hw/misc/flexcomm_function.h new file +47 -0
47 lines not on this page · raw message
hw/misc/flexcomm.c new file +319 -0
319 lines not on this page · raw message
hw/arm/meson.build +2 -0
@@ -73,3 +73,5 @@ system_ss.add(when: 'CONFIG_VERSATILE', if_true: files('versatilepb.c')) system_ss.add(when: 'CONFIG_VEXPRESS', if_true: files('vexpress.c')) hw_arch += {'arm': arm_ss} + +subdir('svd')
hw/arm/svd/meson.build +3 -0
@@ -1,4 +1,7 @@ if get_option('mcux-soc-svd') mcux_soc_svd = subproject('mcux-soc-svd') rt595 = mcux_soc_svd.get_variable('rt595') + run_target('svd-flexcomm', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm.h', + '-p', 'FLEXCOMM0', '-t', 'FLEXCOMM']) endif
hw/misc/Kconfig +3 -0
@@ -213,4 +213,7 @@ config IOSB config XLNX_VERSAL_TRNG bool +config FLEXCOMM + bool + source macio/Kconfig
hw/misc/meson.build +2 -0
@@ -151,3 +151,5 @@ system_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa_ec.c')) # HPPA devices system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) + +system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm.c'))
hw/misc/trace-events +5 -0
@@ -362,3 +362,8 @@ aspeed_sli_read(uint64_t offset, unsigned int size, uint32_t data) "To 0x%" PRIx aspeed_sliio_write(uint64_t offset, unsigned int size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32 aspeed_sliio_read(uint64_t offset, unsigned int size, uint32_t data) "To 0x%" PRIx64 " of size %u: 0x%" PRIx32 +# flexcomm +flexcomm_reset(void) "" +flexcomm_irq(const char *id, uint8_t irq) "%s %d" +flexcomm_reg_read(const char *devname, const char *regname, uint32_t addr, uint32_t val) "%s: %s[0x%04x] -> 0x%08x" +flexcomm_reg_write(const char *dename, const char *regname, uint32_t addr, uint32_t val) "%s: %s[0x%04x] <- 0x%08x"
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 6/25 hw/misc/flexcomm.c: add common fifo functionality
In reply to Octavian PurdilaFLEXCOMM SPI and USART share FIFO functionality. Add common helper functions to avoid code duplication.
--- include/hw/misc/flexcomm.h | 2 + include/hw/misc/flexcomm_function.h | 8 +++ hw/misc/flexcomm.c | 83 +++++++++++++++++++++++++++++ hw/misc/trace-events | 1 + 4 files changed, 94 insertions(+)
include/hw/misc/flexcomm.h +2 -0
@@ -44,6 +44,8 @@ struct FlexcommState {uint32_t functions;qemu_irq irq;bool irq_state; +Fifo32 rx_fifo; + Fifo32 tx_fifo; };#endif /* HW_FLEXCOMM_H */
include/hw/misc/flexcomm_function.h +8 -0
@@ -23,6 +23,8 @@ struct FlexcommFunction {MemoryRegion mmio;uint32_t *regs; +Fifo32 *tx_fifo; +Fifo32 *rx_fifo; };typedef void (*FlexcommFunctionSelect )(FlexcommFunction *f,bool selected);
@@ -32,6 +34,7 @@ struct FlexcommFunctionClass {const MemoryRegionOps *mmio_ops;const char *name; +bool has_fifos;FlexcommFunctionSelect select; };
@@ -43,5 +46,10 @@ static inline void flexcomm_select(FlexcommFunction *obj, bool selected) }void flexcomm_set_irq (FlexcommFunction *f,bool irq); +void flexcomm_update_fifostat (FlexcommFunction *f); +void flexcomm_clear_fifostat (FlexcommFunction *f,uint64_t value); +void flexcomm_init_fifos (FlexcommFunction *f,unsigned num); +void flexcomm_cleanup_fifos (FlexcommFunction *f); +void flexcomm_reset_fifos (FlexcommFunction *f);#endif /* HW_FLEXCOMM_FUNCTION_H */
hw/misc/flexcomm.c +83 -0
118 lines not on this page · raw message
hw/misc/trace-events +1 -0
@@ -367,3 +367,4 @@ flexcomm_reset(void) "" flexcomm_irq(const char *id, uint8_t irq) "%s %d" flexcomm_reg_read(const char *devname, const char *regname, uint32_t addr, uint32_t val) "%s: %s[0x%04x] -> 0x%08x" flexcomm_reg_write(const char *dename, const char *regname, uint32_t addr, uint32_t val) "%s: %s[0x%04x] <- 0x%08x" +flexcomm_fifostat(const char *id, uint32_t fifostat, uint32_t fifoinstat) "%s: %08x %08x"
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 7/25 hw/char: add support for flexcomm usart
In reply to Octavian PurdilaAdd support for NXP's flexcomm usart. It supports interupts and FIFO access but no DMA.
The patch includes an automatically generated header which contains the register layout and helpers.
The header can be regenerated with the svd-flexcomm-usart target when the build is configured with --enable-mcux-soc-svd.
--- include/hw/arm/svd/flexcomm_usart.h | 294 ++++++++++++++++++++++++++++ include/hw/char/flexcomm_usart.h | 33 ++++ include/hw/misc/flexcomm.h | 2 + hw/char/flexcomm_usart.c | 288 +++++++++++++++++++++++++++ hw/misc/flexcomm.c | 3 + hw/arm/svd/meson.build | 4 + hw/char/meson.build | 1 + hw/char/trace-events | 8 + 8 files changed, 633 insertions(+) create mode 100644 include/hw/arm/svd/flexcomm_usart.h create mode 100644 include/hw/char/flexcomm_usart.h create mode 100644 hw/char/flexcomm_usart.c
include/hw/arm/svd/flexcomm_usart.h new file +294 -0
@@ -0,0 +1,294 @@ +/* +* Copyright 2016-2023 NXP SPDX-License-Identifier: BSD-3-Clause +* +* Automatically generated by svd-gen-header.py from MIMXRT595S_cm33.xml +*/ +#pragma once + +#include "hw/register.h" + +/* Flexcomm USART */ +#define FLEXCOMM_USART_REGS_NO (1024) + +/* USART Configuration */ +REG32 (FLEXCOMM_USART_CFG ,0x0 ); +/* USART Enable */ +FIELD (FLEXCOMM_USART_CFG ,ENABLE ,0 ,1 ); + +/* USART Control */ +REG32 (FLEXCOMM_USART_CTL ,0x4 ); + +/* USART Status */ +REG32 (FLEXCOMM_USART_STAT ,0x8 ); + +/* Interrupt Enable Read and Set for USART (not FIFO) Status */ +REG32 (FLEXCOMM_USART_INTENSET ,0xC ); + +/* Interrupt Enable Clear */ +REG32 (FLEXCOMM_USART_INTENCLR ,0x10 ); + +/* Baud Rate Generator */ +REG32 (FLEXCOMM_USART_BRG ,0x20 ); + +/* Interrupt Status */ +REG32 (FLEXCOMM_USART_INTSTAT ,0x24 ); + +/* Oversample Selection Register for Asynchronous Communication */ +REG32 (FLEXCOMM_USART_OSR ,0x28 ); + +/* Address Register for Automatic Address Matching */ +REG32 (FLEXCOMM_USART_ADDR ,0x2C ); + +/* FIFO Configuration */ +REG32 (FLEXCOMM_USART_FIFOCFG ,0xE00 ); +/* Enable the Transmit FIFO. */ +FIELD (FLEXCOMM_USART_FIFOCFG ,ENABLETX ,0 ,1 ); +/* Enable the Receive FIFO */ +FIELD (FLEXCOMM_USART_FIFOCFG ,ENABLERX ,1 ,1 ); +/* Empty Command for the Transmit FIFO */ +FIELD (FLEXCOMM_USART_FIFOCFG ,EMPTYTX ,16 ,1 ); +/* Empty Command for the Receive FIFO */ +FIELD (FLEXCOMM_USART_FIFOCFG ,EMPTYRX ,17 ,1 ); + +/* FIFO Status */ +REG32 (FLEXCOMM_USART_FIFOSTAT ,0xE04 ); +/* TX FIFO Error */ +FIELD (FLEXCOMM_USART_FIFOSTAT ,TXERR ,0 ,1 ); +/* RX FIFO Error */ +FIELD (FLEXCOMM_USART_FIFOSTAT ,RXERR ,1 ,1 ); +/* Peripheral Interrupt */ +FIELD (FLEXCOMM_USART_FIFOSTAT ,PERINT ,3 ,1 ); +/* Transmit FIFO Empty */ +FIELD (FLEXCOMM_USART_FIFOSTAT ,TXEMPTY ,4 ,1 ); +/* Transmit FIFO is Not Full */ +FIELD (FLEXCOMM_USART_FIFOSTAT ,TXNOTFULL ,5 ,1 ); +/* Receive FIFO is Not Empty */ +FIELD (FLEXCOMM_USART_FIFOSTAT ,RXNOTEMPTY ,6 ,1 ); +/* Receive FIFO is Full */ +FIELD (FLEXCOMM_USART_FIFOSTAT ,RXFULL ,7 ,1 ); +/* Transmit FIFO Current Level */ +FIELD (FLEXCOMM_USART_FIFOSTAT ,TXLVL ,8 ,5 ); +/* Receive FIFO Current Level */ +FIELD (FLEXCOMM_USART_FIFOSTAT ,RXLVL ,16 ,5 ); + +/* FIFO Trigger Settings for Interrupt and DMA Request */ +REG32 (FLEXCOMM_USART_FIFOTRIG ,0xE08 ); +/* Transmit FIFO Level Trigger Enable. */ +FIELD (FLEXCOMM_USART_FIFOTRIG ,TXLVLENA ,0 ,1 ); +/* Receive FIFO Level Trigger Enable */ +FIELD (FLEXCOMM_USART_FIFOTRIG ,RXLVLENA ,1 ,1 ); +/* Transmit FIFO Level Trigger Point */ +FIELD (FLEXCOMM_USART_FIFOTRIG ,TXLVL ,8 ,4 ); +/* Trigger when the TX FIFO becomes empty */ +#define FLEXCOMM_USART_FIFOTRIG_TXLVL_TXLVL0 0 +/* Trigger when the TX FIFO level decreases to 1 entry */ +#define FLEXCOMM_USART_FIFOTRIG_TXLVL_TXLVL1 1 +/* Trigger when the TX FIFO level decreases to 15 entries (is no longer full) */ +#define FLEXCOMM_USART_FIFOTRIG_TXLVL_TXLVL15 15 +/* Receive FIFO Level Trigger Point */ +FIELD (FLEXCOMM_USART_FIFOTRIG ,RXLVL ,16 ,4 ); +/* Trigger when the RX FIFO has received 1 entry (is no longer empty) */ +#define FLEXCOMM_USART_FIFOTRIG_RXLVL_RXLVL1 0 +/* Trigger when the RX FIFO has received 2 entries */ +#define FLEXCOMM_USART_FIFOTRIG_RXLVL_RXLVL2 1 +/* Trigger when the RX FIFO has received 16 entries (has become full) */ +#define FLEXCOMM_USART_FIFOTRIG_RXLVL_RXLVL15 15 + +/* FIFO Interrupt Enable */ +REG32 (FLEXCOMM_USART_FIFOINTENSET ,0xE10 ); +/* Transmit Error Interrupt Enable */ +FIELD (FLEXCOMM_USART_FIFOINTENSET ,TXERR ,0 ,1 ); +/* Receive Error Interrupt Enable */ +FIELD (FLEXCOMM_USART_FIFOINTENSET ,RXERR ,1 ,1 ); +/* Transmit FIFO Level Interrupt Enable */ +FIELD (FLEXCOMM_USART_FIFOINTENSET ,TXLVL ,2 ,1 ); +/* Receive FIFO Level Interrupt Enable */ +FIELD (FLEXCOMM_USART_FIFOINTENSET ,RXLVL ,3 ,1 ); + +/* FIFO Interrupt Enable Clear */ +REG32 (FLEXCOMM_USART_FIFOINTENCLR ,0xE14 ); +/* Transmit Error Interrupt Enable */ +FIELD (FLEXCOMM_USART_FIFOINTENCLR ,TXERR ,0 ,1 ); +/* Receive Error Interrupt Enable */ +FIELD (FLEXCOMM_USART_FIFOINTENCLR ,RXERR ,1 ,1 ); +/* Transmit FIFO Level Interrupt Enable */ +FIELD (FLEXCOMM_USART_FIFOINTENCLR ,TXLVL ,2 ,1 ); +/* Receive FIFO Level Interrupt Enable */ +FIELD (FLEXCOMM_USART_FIFOINTENCLR ,RXLVL ,3 ,1 ); + +/* FIFO Interrupt Status */ +REG32 (FLEXCOMM_USART_FIFOINTSTAT ,0xE18 ); +/* TX FIFO Error Interrupt Status */ +FIELD (FLEXCOMM_USART_FIFOINTSTAT ,TXERR ,0 ,1 ); +/* RX FIFO Error Interrupt Status */ +FIELD (FLEXCOMM_USART_FIFOINTSTAT ,RXERR ,1 ,1 ); +/* Transmit FIFO Level Interrupt Status */ +FIELD (FLEXCOMM_USART_FIFOINTSTAT ,TXLVL ,2 ,1 ); +/* Receive FIFO Level Interrupt Status */ +FIELD (FLEXCOMM_USART_FIFOINTSTAT ,RXLVL ,3 ,1 ); +/* Peripheral Interrupt Status */ +FIELD (FLEXCOMM_USART_FIFOINTSTAT ,PERINT ,4 ,1 ); + +/* FIFO Write Data */ +REG32 (FLEXCOMM_USART_FIFOWR ,0xE20 ); +/* Transmit data to the FIFO */ +FIELD (FLEXCOMM_USART_FIFOWR ,TXDATA ,0 ,9 ); + +/* FIFO Read Data */ +REG32 (FLEXCOMM_USART_FIFORD ,0xE30 ); +/* Received Data from the FIFO */ +FIELD (FLEXCOMM_USART_FIFORD ,RXDATA ,0 ,9 ); +/* Framing Error Status Flag */ +FIELD (FLEXCOMM_USART_FIFORD ,FRAMERR ,13 ,1 ); +/* Parity Error Status Flag */ +FIELD (FLEXCOMM_USART_FIFORD ,PARITYERR ,14 ,1 ); +/* Received Noise Flag */ +FIELD (FLEXCOMM_USART_FIFORD ,RXNOISE ,15 ,1 ); + +/* FIFO Data Read with No FIFO Pop */ +REG32 (FLEXCOMM_USART_FIFORDNOPOP ,0xE40 ); +/* Received Data from the FIFO */ +FIELD (FLEXCOMM_USART_FIFORDNOPOP ,RXDATA ,0 ,9 ); +/* Framing Error Status Flag */ +FIELD (FLEXCOMM_USART_FIFORDNOPOP ,FRAMERR ,13 ,1 ); +/* Parity Error Status Flag */ +FIELD (FLEXCOMM_USART_FIFORDNOPOP ,PARITYERR ,14 ,1 ); +/* Received Noise Flag */ +FIELD (FLEXCOMM_USART_FIFORDNOPOP ,RXNOISE ,15 ,1 ); + +/* FIFO Size */ +REG32 (FLEXCOMM_USART_FIFOSIZE ,0xE48 ); +/* FIFO Size */ +FIELD (FLEXCOMM_USART_FIFOSIZE ,FIFOSIZE ,0 ,5 ); + +/* Peripheral Identification */ +REG32 (FLEXCOMM_USART_ID ,0xFFC ); + + +#define FLEXCOMM_USART_REGISTER_ACCESS_INFO_ARRAY (_name) \ + struct RegisterAccessInfo _name[FLEXCOMM_USART_REGS_NO] = { \ + [0 ... FLEXCOMM_USART_REGS_NO - 1] = { \ + .name = "", \ + .addr = -1, \ + }, \ + [0x0] = { \ + .name = "CFG", \ + .addr = 0x0, \ + .ro = 0xFF032402, \ + .reset = 0x0, \ + }, \ + [0x1] = { \ + .name = "CTL", \ + .addr = 0x4, \ + .ro = 0xFFFEFCB9, \ + .reset = 0x0, \ + }, \ + [0x2] = { \ + .name = "STAT", \ + .addr = 0x8, \ + .ro = 0xFFFE07DF, \ + .reset = 0xA, \ + }, \ + [0x3] = { \ + .name = "INTENSET", \ + .addr = 0xC, \ + .ro = 0xFFFE0797, \ + .reset = 0x0, \ + }, \ + [0x4] = { \ + .name = "INTENCLR", \ + .addr = 0x10, \ + .ro = 0xFFFE0797, \ + .reset = 0x0, \ + }, \ + [0x8] = { \ + .name = "BRG", \ + .addr = 0x20, \ + .ro = 0xFFFF0000, \ + .reset = 0x0, \ + }, \ + [0x9] = { \ + .name = "INTSTAT", \ + .addr = 0x24, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0xA] = { \ + .name = "OSR", \ + .addr = 0x28, \ + .ro = 0xFFFFFFF0, \ + .reset = 0xF, \ + }, \ + [0xB] = { \ + .name = "ADDR", \ + .addr = 0x2C, \ + .ro = 0xFFFFFF00, \ + .reset = 0x0, \ + }, \ + [0x380] = { \ + .name = "FIFOCFG", \ + .addr = 0xE00, \ + .ro = 0xFFF80FFC, \ + .reset = 0x0, \ + }, \ + [0x381] = { \ + .name = "FIFOSTAT", \ + .addr = 0xE04, \ + .ro = 0xFFFFFFFC, \ + .reset = 0x30, \ + }, \ + [0x382] = { \ + .name = "FIFOTRIG", \ + .addr = 0xE08, \ + .ro = 0xFFF0F0FC, \ + .reset = 0x0, \ + }, \ + [0x384] = { \ + .name = "FIFOINTENSET", \ + .addr = 0xE10, \ + .ro = 0xFFFFFFF0, \ + .reset = 0x0, \ + }, \ + [0x385] = { \ + .name = "FIFOINTENCLR", \ + .addr = 0xE14, \ + .ro = 0xFFFFFFF0, \ + .reset = 0x0, \ + }, \ + [0x386] = { \ + .name = "FIFOINTSTAT", \ + .addr = 0xE18, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x388] = { \ + .name = "FIFOWR", \ + .addr = 0xE20, \ + .ro = 0xFFFFFE00, \ + .reset = 0x0, \ + }, \ + [0x38C] = { \ + .name = "FIFORD", \ + .addr = 0xE30, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x390] = { \ + .name = "FIFORDNOPOP", \ + .addr = 0xE40, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x392] = { \ + .name = "FIFOSIZE", \ + .addr = 0xE48, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x10, \ + }, \ + [0x3FF] = { \ + .name = "ID", \ + .addr = 0xFFC, \ + .ro = 0xFFFFFFFF, \ + .reset = 0xE0102100, \ + }, \ + }
include/hw/char/flexcomm_usart.h new file +33 -0
@@ -0,0 +1,33 @@ +/* +* QEMU model for NXP's FLEXCOMM USART +* +* Copyright (c) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef HW_FLEXCOMM_USART_H +#define HW_FLEXCOMM_USART_H + +#include "hw/misc/flexcomm_function.h" +#include "chardev/char-fe.h" + +#define TYPE_FLEXCOMM_USART "flexcomm-usart" +OBJECT_DECLARE_TYPE (FlexcommUsartState, FlexcommUsartClass,FLEXCOMM_USART ); + +struct FlexcommUsartState { +FlexcommFunction parent_obj; + +CharBackend chr; +}; + +struct FlexcommUsartClass { +FlexcommFunctionClass parent_obj; + +FlexcommFunctionSelect select; +}; + +#endif /* HW_FLEXCOMM_USART_H */
include/hw/misc/flexcomm.h +2 -0
@@ -15,6 +15,7 @@#include "hw/sysbus.h" #include "hw/arm/svd/flexcomm.h" #include "qemu/fifo32.h" +#include "hw/char/flexcomm_usart.h" #define FLEXCOMM_FUNC_USART 0#define FLEXCOMM_FUNC_SPI 1
@@ -46,6 +47,7 @@ struct FlexcommState {bool irq_state;Fifo32 rx_fifo;Fifo32 tx_fifo; + FlexcommUsartState usart; };#endif /* HW_FLEXCOMM_H */
hw/char/flexcomm_usart.c new file +288 -0
288 lines not on this page · raw message
hw/misc/flexcomm.c +3 -0
@@ -23,6 +23,7 @@#include "migration/vmstate.h" #include "hw/misc/flexcomm.h" #include "hw/arm/svd/flexcomm_usart.h" +#include "hw/char/flexcomm_usart.h" #define REG (s, reg) (s->regs[R_FLEXCOMM_##reg])#define RF_WR (s, reg, field, val) \
@@ -218,6 +219,7 @@ static void flexcomm_init(Object *obj) TYPE_FLEXCOMM, sizeof(s->regs));sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->container);sysbus_init_irq (sbd, &s->irq); +object_initialize_child (obj,"usart" , &s->usart,TYPE_FLEXCOMM_USART ); }static void flexcomm_finalize (Object *obj)
@@ -247,6 +249,7 @@ static void flexcomm_realize(DeviceState *dev, Error **errp)FlexcommState *s =FLEXCOMM (dev);memory_region_add_subregion_overlap (&s->container,0 , &s->mmio,-1 ); +flexcomm_func_realize_and_unref (FLEXCOMM_FUNCTION (&s->usart), errp); }static const VMStateDescription vmstate_flexcomm = {
hw/arm/svd/meson.build +4 -0
@@ -4,4 +4,8 @@ if get_option('mcux-soc-svd') run_target('svd-flexcomm', command: svd_gen_header + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm.h', '-p', 'FLEXCOMM0', '-t', 'FLEXCOMM']) + run_target('svd-flexcomm-usart', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm_usart.h', + '-p', 'USART0', '-t', 'FLEXCOMM_USART', + '--fields', 'CFG:ENABLE FIFOCFG:ENABLE*,EMPTY* FIFO*:* *:']) endif
hw/char/meson.build +1 -0
@@ -39,3 +39,4 @@ system_ss.add(when: 'CONFIG_GOLDFISH_TTY', if_true: files('goldfish_tty.c')) specific_ss.add(when: 'CONFIG_TERMINAL3270', if_true: files('terminal3270.c')) specific_ss.add(when: 'CONFIG_VIRTIO', if_true: files('virtio-serial-bus.c')) specific_ss.add(when: 'CONFIG_PSERIES', if_true: files('spapr_vty.c')) +system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm_usart.c'))
hw/char/trace-events +8 -0
@@ -125,3 +125,11 @@ xen_console_unrealize(unsigned int idx) "idx %u" xen_console_realize(unsigned int idx, const char *chrdev) "idx %u chrdev %s" xen_console_device_create(unsigned int idx) "idx %u" xen_console_device_destroy(unsigned int idx) "idx %u" + +# flexcomm_usart.c +flexcomm_usart_reg_read(const char *id, const char *reg_name, uint32_t addr, uint32_t val) " %s: %s[0x%04x] -> 0x%08x" +flexcomm_usart_reg_write(const char *id, const char *reg_name, uint32_t addr, uint32_t val) "%s: %s[0x%04x] <- 0x%08x" +flexcomm_usart_rx_space(const char *id, uint32_t rx) "%s: %d" +flexcomm_usart_rx(const char *id) "%s" +flexcomm_usart_tx(const char *id) "%s" +flexcomm_usart_irq(const char *id, bool irq, bool fifoirqs, bool perirqs, bool enabled) "%s: %d %d %d %d"
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 8/25 hw/i2c: add support for flexcomm i2c
In reply to Octavian PurdilaAdd support for NXP's flexcomm i2c. It does not support slave mode or DMA.
The patch includes an automatically generated header which contains the register layout and helpers.
The header can be regenerated with the svd-flexcomm-i2c target when the build is configured with --enable-mcux-soc-svd.
--- include/hw/arm/svd/flexcomm_i2c.h | 229 +++++++++++++++++++++++++++ include/hw/i2c/flexcomm_i2c.h | 40 +++++ include/hw/misc/flexcomm.h | 2 + hw/i2c/flexcomm_i2c.c | 250 ++++++++++++++++++++++++++++++ hw/misc/flexcomm.c | 3 + hw/arm/svd/meson.build | 4 + hw/i2c/meson.build | 1 + hw/i2c/trace-events | 10 ++ hw/misc/Kconfig | 1 + 9 files changed, 540 insertions(+) create mode 100644 include/hw/arm/svd/flexcomm_i2c.h create mode 100644 include/hw/i2c/flexcomm_i2c.h create mode 100644 hw/i2c/flexcomm_i2c.c
include/hw/arm/svd/flexcomm_i2c.h new file +229 -0
@@ -0,0 +1,229 @@ +/* +* Copyright 2016-2023 NXP SPDX-License-Identifier: BSD-3-Clause +* +* Automatically generated by svd-gen-header.py from MIMXRT595S_cm33.xml +*/ +#pragma once + +#include "hw/register.h" + +/* I2C Bus Interface */ +#define FLEXCOMM_I2C_REGS_NO (1024) + +/* Configuration Register */ +REG32 (FLEXCOMM_I2C_CFG ,0x800 ); +/* Master Enable */ +FIELD (FLEXCOMM_I2C_CFG ,MSTEN ,0 ,1 ); +/* Slave Enable */ +FIELD (FLEXCOMM_I2C_CFG ,SLVEN ,1 ,1 ); +/* Monitor Enable */ +FIELD (FLEXCOMM_I2C_CFG ,MONEN ,2 ,1 ); +/* I2C bus Time-out Enable */ +FIELD (FLEXCOMM_I2C_CFG ,TIMEOUTEN ,3 ,1 ); +/* Monitor function Clock Stretching */ +FIELD (FLEXCOMM_I2C_CFG ,MONCLKSTR ,4 ,1 ); +/* High Speed mode Capable enable */ +FIELD (FLEXCOMM_I2C_CFG ,HSCAPABLE ,5 ,1 ); + +/* Status Register */ +REG32 (FLEXCOMM_I2C_STAT ,0x804 ); +/* Master Pending */ +FIELD (FLEXCOMM_I2C_STAT ,MSTPENDING ,0 ,1 ); +/* Master State code */ +FIELD (FLEXCOMM_I2C_STAT ,MSTSTATE ,1 ,3 ); +/* Idle. The Master function is available to be used for a new transaction. */ +#define FLEXCOMM_I2C_STAT_MSTSTATE_IDLE 0 +/* +* Receive ready. Received data is available (in Master Receiver mode). Address +* plus Read was previously sent and Acknowledged by a slave. +*/ +#define FLEXCOMM_I2C_STAT_MSTSTATE_RECEIVE_READY 1 +/* +* Transmit ready. Data can be transmitted (in Master Transmitter mode). +* Address plus Write was previously sent and Acknowledged by a slave. +*/ +#define FLEXCOMM_I2C_STAT_MSTSTATE_TRANSMIT_READY 2 +/* NACK Address. Slave NACKed address. */ +#define FLEXCOMM_I2C_STAT_MSTSTATE_NACK_ADDRESS 3 +/* NACK Data. Slave NACKed transmitted data. */ +#define FLEXCOMM_I2C_STAT_MSTSTATE_NACK_DATA 4 + +/* Interrupt Enable Set Register */ +REG32 (FLEXCOMM_I2C_INTENSET ,0x808 ); +/* Master Pending interrupt Enable */ +FIELD (FLEXCOMM_I2C_INTENSET ,MSTPENDINGEN ,0 ,1 ); + +/* Interrupt Enable Clear Register */ +REG32 (FLEXCOMM_I2C_INTENCLR ,0x80C ); +/* Master Pending interrupt clear */ +FIELD (FLEXCOMM_I2C_INTENCLR ,MSTPENDINGCLR ,0 ,1 ); + +/* Time-out Register */ +REG32 (FLEXCOMM_I2C_TIMEOUT ,0x810 ); +/* Time-out time value, the bottom 4 bits */ +FIELD (FLEXCOMM_I2C_TIMEOUT ,TOMIN ,0 ,4 ); + +/* Interrupt Status Register */ +REG32 (FLEXCOMM_I2C_INTSTAT ,0x818 ); +/* Master Pending */ +FIELD (FLEXCOMM_I2C_INTSTAT ,MSTPENDING ,0 ,1 ); + +/* Master Control Register */ +REG32 (FLEXCOMM_I2C_MSTCTL ,0x820 ); +/* Master Continue(write-only) */ +FIELD (FLEXCOMM_I2C_MSTCTL ,MSTCONTINUE ,0 ,1 ); +/* Master Start control(write-only) */ +FIELD (FLEXCOMM_I2C_MSTCTL ,MSTSTART ,1 ,1 ); +/* Master Stop control(write-only) */ +FIELD (FLEXCOMM_I2C_MSTCTL ,MSTSTOP ,2 ,1 ); +/* Master DMA enable */ +FIELD (FLEXCOMM_I2C_MSTCTL ,MSTDMA ,3 ,1 ); + +/* Master Data Register */ +REG32 (FLEXCOMM_I2C_MSTDAT ,0x828 ); +/* Master function data register */ +FIELD (FLEXCOMM_I2C_MSTDAT ,DATA ,0 ,8 ); + +/* Slave Control Register */ +REG32 (FLEXCOMM_I2C_SLVCTL ,0x840 ); + +/* Slave Data Register */ +REG32 (FLEXCOMM_I2C_SLVDAT ,0x844 ); + +/* Slave Address Register */ +REG32 (FLEXCOMM_I2C_SLVADR0 ,0x848 ); + +/* Slave Address Register */ +REG32 (FLEXCOMM_I2C_SLVADR1 ,0x84C ); + +/* Slave Address Register */ +REG32 (FLEXCOMM_I2C_SLVADR2 ,0x850 ); + +/* Slave Address Register */ +REG32 (FLEXCOMM_I2C_SLVADR3 ,0x854 ); + +/* Slave Qualification for Address 0 Register */ +REG32 (FLEXCOMM_I2C_SLVQUAL0 ,0x858 ); + + +#define FLEXCOMM_I2C_REGISTER_ACCESS_INFO_ARRAY (_name) \ + struct RegisterAccessInfo _name[FLEXCOMM_I2C_REGS_NO] = { \ + [0 ... FLEXCOMM_I2C_REGS_NO - 1] = { \ + .name = "", \ + .addr = -1, \ + }, \ + [0x200] = { \ + .name = "CFG", \ + .addr = 0x800, \ + .ro = 0xFFFFFFC0, \ + .reset = 0x0, \ + }, \ + [0x201] = { \ + .name = "STAT", \ + .addr = 0x804, \ + .ro = 0xFCF57FAF, \ + .reset = 0x801, \ + }, \ + [0x202] = { \ + .name = "INTENSET", \ + .addr = 0x808, \ + .ro = 0xFCF476AE, \ + .reset = 0x0, \ + }, \ + [0x203] = { \ + .name = "INTENCLR", \ + .addr = 0x80C, \ + .ro = 0xFCF476AE, \ + .reset = 0x0, \ + }, \ + [0x204] = { \ + .name = "TIMEOUT", \ + .addr = 0x810, \ + .ro = 0xFFFF0000, \ + .reset = 0xFFFF, \ + }, \ + [0x205] = { \ + .name = "CLKDIV", \ + .addr = 0x814, \ + .ro = 0xFFFF0000, \ + .reset = 0x0, \ + }, \ + [0x206] = { \ + .name = "INTSTAT", \ + .addr = 0x818, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x801, \ + }, \ + [0x208] = { \ + .name = "MSTCTL", \ + .addr = 0x820, \ + .ro = 0xFFFFFFF0, \ + .reset = 0x0, \ + }, \ + [0x209] = { \ + .name = "MSTTIME", \ + .addr = 0x824, \ + .ro = 0xFFFFFF88, \ + .reset = 0x77, \ + }, \ + [0x20A] = { \ + .name = "MSTDAT", \ + .addr = 0x828, \ + .ro = 0xFFFFFF00, \ + .reset = 0x0, \ + }, \ + [0x210] = { \ + .name = "SLVCTL", \ + .addr = 0x840, \ + .ro = 0xFFFFFCF4, \ + .reset = 0x0, \ + }, \ + [0x211] = { \ + .name = "SLVDAT", \ + .addr = 0x844, \ + .ro = 0xFFFFFF00, \ + .reset = 0x0, \ + }, \ + [0x212] = { \ + .name = "SLVADR0", \ + .addr = 0x848, \ + .ro = 0xFFFF7F00, \ + .reset = 0x1, \ + }, \ + [0x213] = { \ + .name = "SLVADR1", \ + .addr = 0x84C, \ + .ro = 0xFFFF7F00, \ + .reset = 0x1, \ + }, \ + [0x214] = { \ + .name = "SLVADR2", \ + .addr = 0x850, \ + .ro = 0xFFFF7F00, \ + .reset = 0x1, \ + }, \ + [0x215] = { \ + .name = "SLVADR3", \ + .addr = 0x854, \ + .ro = 0xFFFF7F00, \ + .reset = 0x1, \ + }, \ + [0x216] = { \ + .name = "SLVQUAL0", \ + .addr = 0x858, \ + .ro = 0xFFFFFF00, \ + .reset = 0x0, \ + }, \ + [0x220] = { \ + .name = "MONRXDAT", \ + .addr = 0x880, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x3FF] = { \ + .name = "ID", \ + .addr = 0xFFC, \ + .ro = 0xFFFFFFFF, \ + .reset = 0xE0301300, \ + }, \ + }
include/hw/i2c/flexcomm_i2c.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* QEMU model for NXP's FLEXCOMM I2C +* +* Copyright (c) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef HW_FLEXCOMM_I2C_H +#define HW_FLEXCOMM_I2C_H + +#include "hw/i2c/i2c.h" +#include "hw/misc/flexcomm_function.h" + +#define TYPE_FLEXCOMM_I2C "flexcomm-i2c" +OBJECT_DECLARE_TYPE (FlexcommI2cState, FlexcommI2cClass,FLEXCOMM_I2C ); + +struct FlexcommI2cState { +FlexcommFunction parent_obj; + +I2CBus *bus; +}; + +struct FlexcommI2cClass { +FlexcommFunctionClass parent_obj; + +FlexcommFunctionSelect select; +}; + +#define MSTSTATE_IDLE 0 +#define MSTSTATE_RXRDY 1 +#define MSTSTATE_TXRDY 2 +#define MSTSTATE_NAKADR 3 +#define MSTSTATE_NAKDAT 4 + + +#endif /* HW_FLEXCOMM_I2C_H */
include/hw/misc/flexcomm.h +2 -0
@@ -16,6 +16,7 @@#include "hw/arm/svd/flexcomm.h" #include "qemu/fifo32.h" #include "hw/char/flexcomm_usart.h" +#include "hw/i2c/flexcomm_i2c.h" #define FLEXCOMM_FUNC_USART 0#define FLEXCOMM_FUNC_SPI 1
@@ -48,6 +49,7 @@ struct FlexcommState {Fifo32 rx_fifo;Fifo32 tx_fifo;FlexcommUsartState usart; + FlexcommI2cState i2c; };#endif /* HW_FLEXCOMM_H */
hw/i2c/flexcomm_i2c.c new file +250 -0
250 lines not on this page · raw message
hw/misc/flexcomm.c +3 -0
@@ -24,6 +24,7 @@#include "hw/misc/flexcomm.h" #include "hw/arm/svd/flexcomm_usart.h" #include "hw/char/flexcomm_usart.h" +#include "hw/i2c/flexcomm_i2c.h" #define REG (s, reg) (s->regs[R_FLEXCOMM_##reg])#define RF_WR (s, reg, field, val) \
@@ -220,6 +221,7 @@ static void flexcomm_init(Object *obj)sysbus_init_mmio (SYS_BUS_DEVICE (obj), &s->container);sysbus_init_irq (sbd, &s->irq);object_initialize_child (obj,"usart" , &s->usart,TYPE_FLEXCOMM_USART ); +object_initialize_child (obj,"i2c" , &s->i2c,TYPE_FLEXCOMM_I2C ); }static void flexcomm_finalize (Object *obj)
@@ -250,6 +252,7 @@ static void flexcomm_realize(DeviceState *dev, Error **errp)memory_region_add_subregion_overlap (&s->container,0 , &s->mmio,-1 );flexcomm_func_realize_and_unref (FLEXCOMM_FUNCTION (&s->usart), errp); +flexcomm_func_realize_and_unref (FLEXCOMM_FUNCTION (&s->i2c), errp); }static const VMStateDescription vmstate_flexcomm = {
hw/arm/svd/meson.build +4 -0
@@ -8,4 +8,8 @@ if get_option('mcux-soc-svd') [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm_usart.h', '-p', 'USART0', '-t', 'FLEXCOMM_USART', '--fields', 'CFG:ENABLE FIFOCFG:ENABLE*,EMPTY* FIFO*:* *:']) + run_target('svd-flexcomm-i2c', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm_i2c.h', + '-p', 'I2C0', '-t', 'FLEXCOMM_I2C', + '--fields', 'CFG TIMEOUT:TOMIN MSTCTL MSTDAT STAT:MSTPENDING,MSTSTATE INT*:MSTPENDING* SLV*:']) endif
hw/i2c/meson.build +1 -0
@@ -18,4 +18,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_FLEXCOMM', if_true: files('flexcomm_i2c.c')) system_ss.add_all(when: 'CONFIG_I2C', if_true: i2c_ss)
hw/i2c/trace-events +10 -0
@@ -51,3 +51,13 @@ npcm7xx_smbus_recv_fifo(const char *id, uint8_t received, uint8_t expected) "%s pca954x_write_bytes(uint8_t value) "PCA954X write data: 0x%02x" pca954x_read_data(uint8_t value) "PCA954X read data: 0x%02x" + +# flexcomm_i2c.c + +flexcomm_i2c_reg_read(const char *id, const char *reg_name, uint32_t addr, uint32_t val) " %s: %s[0x%04x] -> 0x%08x" +flexcomm_i2c_reg_write(const char *id, const char *reg_name, uint32_t addr, uint32_t val) "%s: %s[0x%04x] <- 0x%08x" +flexcomm_i2c_start(const char *id, uint8_t addr, uint8_t recv) "%s: 0x%02x %d" +flexcomm_i2c_rx(const char *id, uint8_t data) "%s: <- 0x%02x" +flexcomm_i2c_tx(const char *id, uint8_t data) "%s: -> 0x%02x" +flexcomm_i2c_nak(const char *id) "%s: <- nak" +flexcomm_i2c_irq(const char *id, bool irq, bool perirqs, bool enabled) "%s: %d %d %d"
hw/misc/Kconfig +1 -0
@@ -215,5 +215,6 @@ config XLNX_VERSAL_TRNG config FLEXCOMM bool + select I2C source macio/Kconfig
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 9/25 hw/ssi: add support for flexcomm spi
In reply to Octavian PurdilaFrom: Sebastian Ene <[email protected]>
Add support for NXP's flexcomm spi. It supports FIFO access, interrupts and master mode only. It does not support DMA.
The patch includes an automatically generated header which contains the register layout and helpers.
The header can be regenerated with the svd-flexcomm-spi target when the build is configured with --enable-mcux-soc-svd.
[tavip: add suport for CFG.SPOL, CFG.LSBF, TX control flags per FIFO entry and 8/16 bit access to FIFORD and FIFOWR, convert to Resettable interface, add support for migration]
--- include/hw/arm/svd/flexcomm_spi.h | 327 +++++++++++++++++++++++ include/hw/misc/flexcomm.h | 2 + include/hw/ssi/flexcomm_spi.h | 36 +++ hw/misc/flexcomm.c | 3 + hw/ssi/flexcomm_spi.c | 422 ++++++++++++++++++++++++++++++ hw/arm/svd/meson.build | 4 + hw/misc/Kconfig | 1 + hw/ssi/meson.build | 1 + hw/ssi/trace-events | 5 + 9 files changed, 801 insertions(+) create mode 100644 include/hw/arm/svd/flexcomm_spi.h create mode 100644 include/hw/ssi/flexcomm_spi.h create mode 100644 hw/ssi/flexcomm_spi.c
include/hw/arm/svd/flexcomm_spi.h new file +327 -0
@@ -0,0 +1,327 @@ +/* +* Copyright 2016-2023 NXP SPDX-License-Identifier: BSD-3-Clause +* +* Automatically generated by svd-gen-header.py from MIMXRT595S_cm33.xml +*/ +#pragma once + +#include "hw/register.h" + +/* Serial Peripheral Interfaces (SPI) */ +#define FLEXCOMM_SPI_REGS_NO (1024) + +/* Configuration Register */ +REG32 (FLEXCOMM_SPI_CFG ,0x400 ); +/* SPI Enable */ +FIELD (FLEXCOMM_SPI_CFG ,ENABLE ,0 ,1 ); +/* Master Mode Select */ +FIELD (FLEXCOMM_SPI_CFG ,MASTER ,2 ,1 ); +/* LSB First Mode Enable */ +FIELD (FLEXCOMM_SPI_CFG ,LSBF ,3 ,1 ); +/* Clock Phase Select */ +FIELD (FLEXCOMM_SPI_CFG ,CPHA ,4 ,1 ); +/* Clock Polarity Select */ +FIELD (FLEXCOMM_SPI_CFG ,CPOL ,5 ,1 ); +/* Loopback Mode Enable */ +FIELD (FLEXCOMM_SPI_CFG ,LOOP ,7 ,1 ); +/* SSEL0 Polarity Select */ +FIELD (FLEXCOMM_SPI_CFG ,SPOL0 ,8 ,1 ); +/* SSEL1 Polarity Select */ +FIELD (FLEXCOMM_SPI_CFG ,SPOL1 ,9 ,1 ); +/* SSEL2 Polarity Select */ +FIELD (FLEXCOMM_SPI_CFG ,SPOL2 ,10 ,1 ); +/* SSEL3 Polarity Select */ +FIELD (FLEXCOMM_SPI_CFG ,SPOL3 ,11 ,1 ); + +/* Status Register */ +REG32 (FLEXCOMM_SPI_STAT ,0x408 ); +/* Slave Select Assert */ +FIELD (FLEXCOMM_SPI_STAT ,SSA ,4 ,1 ); +/* Slave Select Deassert */ +FIELD (FLEXCOMM_SPI_STAT ,SSD ,5 ,1 ); +/* Stalled Status Flag */ +FIELD (FLEXCOMM_SPI_STAT ,STALLED ,6 ,1 ); +/* End Transfer Control */ +FIELD (FLEXCOMM_SPI_STAT ,ENDTRANSFER ,7 ,1 ); +/* Master Idle Status Flag */ +FIELD (FLEXCOMM_SPI_STAT ,MSTIDLE ,8 ,1 ); + +/* Interrupt Enable Register */ +REG32 (FLEXCOMM_SPI_INTENSET ,0x40C ); + +/* Interrupt Enable Clear Register */ +REG32 (FLEXCOMM_SPI_INTENCLR ,0x410 ); + +/* Interrupt Status Register */ +REG32 (FLEXCOMM_SPI_INTSTAT ,0x428 ); + +/* FIFO Configuration Register */ +REG32 (FLEXCOMM_SPI_FIFOCFG ,0xE00 ); +/* Enable the Transmit FIFO */ +FIELD (FLEXCOMM_SPI_FIFOCFG ,ENABLETX ,0 ,1 ); +/* Enable the Receive FIFO */ +FIELD (FLEXCOMM_SPI_FIFOCFG ,ENABLERX ,1 ,1 ); +/* Empty Command for the Transmit FIFO */ +FIELD (FLEXCOMM_SPI_FIFOCFG ,EMPTYTX ,16 ,1 ); +/* Empty Command for the Receive FIFO */ +FIELD (FLEXCOMM_SPI_FIFOCFG ,EMPTYRX ,17 ,1 ); + +/* FIFO Status Register */ +REG32 (FLEXCOMM_SPI_FIFOSTAT ,0xE04 ); +/* TX FIFO Error */ +FIELD (FLEXCOMM_SPI_FIFOSTAT ,TXERR ,0 ,1 ); +/* RX FIFO Error */ +FIELD (FLEXCOMM_SPI_FIFOSTAT ,RXERR ,1 ,1 ); +/* Peripheral Interrupt */ +FIELD (FLEXCOMM_SPI_FIFOSTAT ,PERINT ,3 ,1 ); +/* Transmit FIFO Empty */ +FIELD (FLEXCOMM_SPI_FIFOSTAT ,TXEMPTY ,4 ,1 ); +/* Transmit FIFO is Not Full */ +FIELD (FLEXCOMM_SPI_FIFOSTAT ,TXNOTFULL ,5 ,1 ); +/* Receive FIFO is Not Empty */ +FIELD (FLEXCOMM_SPI_FIFOSTAT ,RXNOTEMPTY ,6 ,1 ); +/* Receive FIFO is Full */ +FIELD (FLEXCOMM_SPI_FIFOSTAT ,RXFULL ,7 ,1 ); +/* Transmit FIFO Current Level */ +FIELD (FLEXCOMM_SPI_FIFOSTAT ,TXLVL ,8 ,5 ); +/* Receive FIFO Current Level */ +FIELD (FLEXCOMM_SPI_FIFOSTAT ,RXLVL ,16 ,5 ); + +/* FIFO Trigger Register */ +REG32 (FLEXCOMM_SPI_FIFOTRIG ,0xE08 ); +/* Transmit FIFO Level Trigger Enable */ +FIELD (FLEXCOMM_SPI_FIFOTRIG ,TXLVLENA ,0 ,1 ); +/* Receive FIFO Level Trigger Enable */ +FIELD (FLEXCOMM_SPI_FIFOTRIG ,RXLVLENA ,1 ,1 ); +/* Transmit FIFO Level Trigger Point */ +FIELD (FLEXCOMM_SPI_FIFOTRIG ,TXLVL ,8 ,4 ); +/* Trigger when the TX FIFO becomes empty */ +#define FLEXCOMM_SPI_FIFOTRIG_TXLVL_TXLVL0 0 +/* Trigger when the TX FIFO level decreases to 1 entry */ +#define FLEXCOMM_SPI_FIFOTRIG_TXLVL_TXLVL1 1 +/* Trigger when the TX FIFO level decreases to 15 entries (is no longer full) */ +#define FLEXCOMM_SPI_FIFOTRIG_TXLVL_TXLVL15 15 +/* Receive FIFO Level Trigger Point */ +FIELD (FLEXCOMM_SPI_FIFOTRIG ,RXLVL ,16 ,4 ); +/* Trigger when the RX FIFO has received 1 entry (is no longer empty) */ +#define FLEXCOMM_SPI_FIFOTRIG_RXLVL_RXLVL1 0 +/* Trigger when the RX FIFO has received 2 entries */ +#define FLEXCOMM_SPI_FIFOTRIG_RXLVL_RXLVL2 1 +/* Trigger when the RX FIFO has received 16 entries (has become full) */ +#define FLEXCOMM_SPI_FIFOTRIG_RXLVL_RXLVL15 15 + +/* FIFO Interrupt Enable Register */ +REG32 (FLEXCOMM_SPI_FIFOINTENSET ,0xE10 ); +/* TX Error Interrupt Enable */ +FIELD (FLEXCOMM_SPI_FIFOINTENSET ,TXERR ,0 ,1 ); +/* Receive Error Interrupt Enable */ +FIELD (FLEXCOMM_SPI_FIFOINTENSET ,RXERR ,1 ,1 ); +/* Transmit FIFO Level Interrupt Enable */ +FIELD (FLEXCOMM_SPI_FIFOINTENSET ,TXLVL ,2 ,1 ); +/* Receive FIFO Level Interrupt Enable */ +FIELD (FLEXCOMM_SPI_FIFOINTENSET ,RXLVL ,3 ,1 ); + +/* FIFO Interrupt Enable Clear Register */ +REG32 (FLEXCOMM_SPI_FIFOINTENCLR ,0xE14 ); +/* TX Error Interrupt Enable */ +FIELD (FLEXCOMM_SPI_FIFOINTENCLR ,TXERR ,0 ,1 ); +/* Receive Error Interrupt Enable */ +FIELD (FLEXCOMM_SPI_FIFOINTENCLR ,RXERR ,1 ,1 ); +/* Transmit FIFO Level Interrupt Enable */ +FIELD (FLEXCOMM_SPI_FIFOINTENCLR ,TXLVL ,2 ,1 ); +/* Receive FIFO Level Interrupt Enable */ +FIELD (FLEXCOMM_SPI_FIFOINTENCLR ,RXLVL ,3 ,1 ); + +/* FIFO Interrupt Status Register */ +REG32 (FLEXCOMM_SPI_FIFOINTSTAT ,0xE18 ); +/* TX FIFO Error Interrupt Status */ +FIELD (FLEXCOMM_SPI_FIFOINTSTAT ,TXERR ,0 ,1 ); +/* RX FIFO Error Interrupt Status */ +FIELD (FLEXCOMM_SPI_FIFOINTSTAT ,RXERR ,1 ,1 ); +/* Transmit FIFO Level Interrupt Status */ +FIELD (FLEXCOMM_SPI_FIFOINTSTAT ,TXLVL ,2 ,1 ); +/* Receive FIFO Level Interrupt Status */ +FIELD (FLEXCOMM_SPI_FIFOINTSTAT ,RXLVL ,3 ,1 ); +/* Peripheral Interrupt Status */ +FIELD (FLEXCOMM_SPI_FIFOINTSTAT ,PERINT ,4 ,1 ); + +/* FIFO Write Data Register */ +REG32 (FLEXCOMM_SPI_FIFOWR ,0xE20 ); +/* Transmit Data to the FIFO */ +FIELD (FLEXCOMM_SPI_FIFOWR ,TXDATA ,0 ,16 ); +/* Transmit Slave Select 0 */ +FIELD (FLEXCOMM_SPI_FIFOWR ,TXSSEL0_N ,16 ,1 ); +/* Transmit Slave Select 1 */ +FIELD (FLEXCOMM_SPI_FIFOWR ,TXSSEL1_N ,17 ,1 ); +/* Transmit Slave Select 2 */ +FIELD (FLEXCOMM_SPI_FIFOWR ,TXSSEL2_N ,18 ,1 ); +/* Transmit Slave Select 3 */ +FIELD (FLEXCOMM_SPI_FIFOWR ,TXSSEL3_N ,19 ,1 ); +/* End of Transfer */ +FIELD (FLEXCOMM_SPI_FIFOWR ,EOT ,20 ,1 ); +/* End of Frame */ +FIELD (FLEXCOMM_SPI_FIFOWR ,EOF ,21 ,1 ); +/* Receive Ignore */ +FIELD (FLEXCOMM_SPI_FIFOWR ,RXIGNORE ,22 ,1 ); +/* Transmit Ignore */ +FIELD (FLEXCOMM_SPI_FIFOWR ,TXIGNORE ,23 ,1 ); +/* Data Length */ +FIELD (FLEXCOMM_SPI_FIFOWR ,LEN ,24 ,4 ); +/* Data transfer is 4 bits in length */ +#define FLEXCOMM_SPI_FIFOWR_LEN_LEN_4BITS 3 +/* Data transfer is 5 bits in length */ +#define FLEXCOMM_SPI_FIFOWR_LEN_LEN_5BITS 4 +/* Data transfer is 16 bits in length */ +#define FLEXCOMM_SPI_FIFOWR_LEN_LEN_16BITS 15 + +/* FIFO Read Data Register */ +REG32 (FLEXCOMM_SPI_FIFORD ,0xE30 ); +/* Received Data from the FIFO */ +FIELD (FLEXCOMM_SPI_FIFORD ,RXDATA ,0 ,16 ); +/* Slave Select 0 for Receive */ +FIELD (FLEXCOMM_SPI_FIFORD ,RXSSEL0_N ,16 ,1 ); +/* Slave Select 1 for Receive */ +FIELD (FLEXCOMM_SPI_FIFORD ,RXSSEL1_N ,17 ,1 ); +/* Slave Select 2 for Receive */ +FIELD (FLEXCOMM_SPI_FIFORD ,RXSSEL2_N ,18 ,1 ); +/* Slave Select 3 for Receive */ +FIELD (FLEXCOMM_SPI_FIFORD ,RXSSEL3_N ,19 ,1 ); +/* Start of Transfer Flag */ +FIELD (FLEXCOMM_SPI_FIFORD ,SOT ,20 ,1 ); + +/* FIFO Data Read with no FIFO Pop Register */ +REG32 (FLEXCOMM_SPI_FIFORDNOPOP ,0xE40 ); +/* Received Data from the FIFO */ +FIELD (FLEXCOMM_SPI_FIFORDNOPOP ,RXDATA ,0 ,16 ); +/* Slave Select 0 for Receive */ +FIELD (FLEXCOMM_SPI_FIFORDNOPOP ,RXSSEL0_N ,16 ,1 ); +/* Slave Select 1 for Receive */ +FIELD (FLEXCOMM_SPI_FIFORDNOPOP ,RXSSEL1_N ,17 ,1 ); +/* Slave Select 2 for Receive */ +FIELD (FLEXCOMM_SPI_FIFORDNOPOP ,RXSSEL2_N ,18 ,1 ); +/* Slave Select 3 for Receive */ +FIELD (FLEXCOMM_SPI_FIFORDNOPOP ,RXSSEL3_N ,19 ,1 ); +/* Start of Transfer Flag */ +FIELD (FLEXCOMM_SPI_FIFORDNOPOP ,SOT ,20 ,1 ); + +/* FIFO Size Register */ +REG32 (FLEXCOMM_SPI_FIFOSIZE ,0xE48 ); +/* FIFO Size */ +FIELD (FLEXCOMM_SPI_FIFOSIZE ,FIFOSIZE ,0 ,5 ); + + +#define FLEXCOMM_SPI_REGISTER_ACCESS_INFO_ARRAY (_name) \ + struct RegisterAccessInfo _name[FLEXCOMM_SPI_REGS_NO] = { \ + [0 ... FLEXCOMM_SPI_REGS_NO - 1] = { \ + .name = "", \ + .addr = -1, \ + }, \ + [0x100] = { \ + .name = "CFG", \ + .addr = 0x400, \ + .ro = 0xFFFFF042, \ + .reset = 0x0, \ + }, \ + [0x101] = { \ + .name = "DLY", \ + .addr = 0x404, \ + .ro = 0xFFFF0000, \ + .reset = 0x0, \ + }, \ + [0x102] = { \ + .name = "STAT", \ + .addr = 0x408, \ + .ro = 0xFFFFFF4F, \ + .reset = 0x100, \ + }, \ + [0x103] = { \ + .name = "INTENSET", \ + .addr = 0x40C, \ + .ro = 0xFFFFFECF, \ + .reset = 0x0, \ + }, \ + [0x104] = { \ + .name = "INTENCLR", \ + .addr = 0x410, \ + .ro = 0xFFFFFECF, \ + .reset = 0x0, \ + }, \ + [0x109] = { \ + .name = "DIV", \ + .addr = 0x424, \ + .ro = 0xFFFF0000, \ + .reset = 0x0, \ + }, \ + [0x10A] = { \ + .name = "INTSTAT", \ + .addr = 0x428, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x380] = { \ + .name = "FIFOCFG", \ + .addr = 0xE00, \ + .ro = 0xFFF80FFC, \ + .reset = 0x0, \ + }, \ + [0x381] = { \ + .name = "FIFOSTAT", \ + .addr = 0xE04, \ + .ro = 0xFFFFFFFC, \ + .reset = 0x30, \ + }, \ + [0x382] = { \ + .name = "FIFOTRIG", \ + .addr = 0xE08, \ + .ro = 0xFFF0F0FC, \ + .reset = 0x0, \ + }, \ + [0x384] = { \ + .name = "FIFOINTENSET", \ + .addr = 0xE10, \ + .ro = 0xFFFFFFF0, \ + .reset = 0x0, \ + }, \ + [0x385] = { \ + .name = "FIFOINTENCLR", \ + .addr = 0xE14, \ + .ro = 0xFFFFFFF0, \ + .reset = 0x0, \ + }, \ + [0x386] = { \ + .name = "FIFOINTSTAT", \ + .addr = 0xE18, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x388] = { \ + .name = "FIFOWR", \ + .addr = 0xE20, \ + .ro = 0xF0000000, \ + .reset = 0x0, \ + }, \ + [0x38C] = { \ + .name = "FIFORD", \ + .addr = 0xE30, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x390] = { \ + .name = "FIFORDNOPOP", \ + .addr = 0xE40, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x392] = { \ + .name = "FIFOSIZE", \ + .addr = 0xE48, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x3FF] = { \ + .name = "ID", \ + .addr = 0xFFC, \ + .ro = 0xFFFFFFFF, \ + .reset = 0xE0201200, \ + }, \ + }
include/hw/misc/flexcomm.h +2 -0
@@ -17,6 +17,7 @@#include "qemu/fifo32.h" #include "hw/char/flexcomm_usart.h" #include "hw/i2c/flexcomm_i2c.h" +#include "hw/ssi/flexcomm_spi.h" #define FLEXCOMM_FUNC_USART 0#define FLEXCOMM_FUNC_SPI 1
@@ -50,6 +51,7 @@ struct FlexcommState {Fifo32 tx_fifo;FlexcommUsartState usart;FlexcommI2cState i2c; + FlexcommSpiState spi; };#endif /* HW_FLEXCOMM_H */
include/hw/ssi/flexcomm_spi.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* QEMU model for NXP's FLEXCOMM SPI +* +* Copyright (c) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef HW_FLEXCOMM_SPI_H +#define HW_FLEXCOMM_SPI_H + +#include "hw/misc/flexcomm_function.h" +#include "hw/ssi/ssi.h" + +#define TYPE_FLEXCOMM_SPI "flexcomm-spi" +OBJECT_DECLARE_TYPE (FlexcommSpiState, FlexcommSpiClass,FLEXCOMM_SPI ); + +struct FlexcommSpiState { +FlexcommFunction parent_obj; + +SSIBus *bus; +qemu_irq cs[4 ]; +bool cs_asserted[4 ]; +uint32_t tx_ctrl; +}; + +struct FlexcommSpiClass { +FlexcommFunctionClass parent_obj; + +FlexcommFunctionSelect select; +}; + +#endif /* HW_FLEXCOMM_SPI_H */
hw/misc/flexcomm.c +3 -0
@@ -25,6 +25,7 @@#include "hw/arm/svd/flexcomm_usart.h" #include "hw/char/flexcomm_usart.h" #include "hw/i2c/flexcomm_i2c.h" +#include "hw/ssi/flexcomm_spi.h" #define REG (s, reg) (s->regs[R_FLEXCOMM_##reg])#define RF_WR (s, reg, field, val) \
@@ -222,6 +223,7 @@ static void flexcomm_init(Object *obj)sysbus_init_irq (sbd, &s->irq);object_initialize_child (obj,"usart" , &s->usart,TYPE_FLEXCOMM_USART );object_initialize_child (obj,"i2c" , &s->i2c,TYPE_FLEXCOMM_I2C ); +object_initialize_child (obj,"spi" , &s->spi,TYPE_FLEXCOMM_SPI ); }static void flexcomm_finalize (Object *obj)
@@ -253,6 +255,7 @@ static void flexcomm_realize(DeviceState *dev, Error **errp)memory_region_add_subregion_overlap (&s->container,0 , &s->mmio,-1 );flexcomm_func_realize_and_unref (FLEXCOMM_FUNCTION (&s->usart), errp);flexcomm_func_realize_and_unref (FLEXCOMM_FUNCTION (&s->i2c), errp); +flexcomm_func_realize_and_unref (FLEXCOMM_FUNCTION (&s->spi), errp); }static const VMStateDescription vmstate_flexcomm = {
hw/ssi/flexcomm_spi.c new file +422 -0
422 lines not on this page · raw message
hw/arm/svd/meson.build +4 -0
@@ -12,4 +12,8 @@ if get_option('mcux-soc-svd') [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm_i2c.h', '-p', 'I2C0', '-t', 'FLEXCOMM_I2C', '--fields', 'CFG TIMEOUT:TOMIN MSTCTL MSTDAT STAT:MSTPENDING,MSTSTATE INT*:MSTPENDING* SLV*:']) + run_target('svd-flexcomm-spi', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm_spi.h', + '-p', 'SPI0', '-t', 'FLEXCOMM_SPI', + '--fields', 'CFG FIFOCFG:ENABLE*,EMPTY* FIFO*:* INT*: STAT']) endif
hw/misc/Kconfig +1 -0
@@ -216,5 +216,6 @@ config XLNX_VERSAL_TRNG config FLEXCOMM bool select I2C + select SSI source macio/Kconfig
hw/ssi/meson.build +1 -0
@@ -12,3 +12,4 @@ system_ss.add(when: 'CONFIG_IMX', if_true: files('imx_spi.c')) system_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_spi_host.c')) system_ss.add(when: 'CONFIG_BCM2835_SPI', if_true: files('bcm2835_spi.c')) system_ss.add(when: 'CONFIG_PNV_SPI', if_true: files('pnv_spi.c')) +system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm_spi.c'))
hw/ssi/trace-events +5 -0
@@ -53,3 +53,8 @@ pnv_spi_rx_read_N2frame(void) "" pnv_spi_shift_rx(uint8_t byte, uint32_t index) "byte = 0x%2.2x into RDR from payload index %d" pnv_spi_sequencer_stop_requested(const char* reason) "due to %s" pnv_spi_RDR_match(const char* result) "%s" + +# flexcomm_spi.c +flexcomm_spi_reg_read(const char *id, const char *reg_name, uint32_t addr, uint32_t val) " %s: %s[0x%04x] -> 0x%08x" +flexcomm_spi_reg_write(const char *id, const char *reg_name, uint32_t addr, uint32_t val) "%s: %s[0x%04x] <- 0x%08x" +flexcomm_spi_irq(const char *id, bool irq, bool fifoirqs, bool perirqs, bool enabled) "%s: %d %d %d %d"
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 10/25 hw/misc: add support for RT500's clock controller
In reply to Octavian PurdilaIt supports system and audio PLL initialization and SYSTICK and OSTIMER clock source selection.
The patch includes automatically generated headers which contains the register layout and helpers.
The headers can be regenerated with the svd-rt500-clkctl0 and svd-rt500-clkctl1 targets when the build is configured with --enable-mcux-soc-svd.
--- include/hw/arm/svd/rt500_clkctl0.h | 509 ++++++++++++++++++++++ include/hw/arm/svd/rt500_clkctl1.h | 675 +++++++++++++++++++++++++++++ include/hw/misc/rt500_clk_freqs.h | 18 + include/hw/misc/rt500_clkctl0.h | 35 ++ include/hw/misc/rt500_clkctl1.h | 36 ++ hw/misc/rt500_clkctl0.c | 253 +++++++++++ hw/misc/rt500_clkctl1.c | 238 ++++++++++ hw/arm/Kconfig | 5 + hw/arm/svd/meson.build | 8 + hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/trace-events | 8 + 12 files changed, 1789 insertions(+) create mode 100644 include/hw/arm/svd/rt500_clkctl0.h create mode 100644 include/hw/arm/svd/rt500_clkctl1.h create mode 100644 include/hw/misc/rt500_clk_freqs.h create mode 100644 include/hw/misc/rt500_clkctl0.h create mode 100644 include/hw/misc/rt500_clkctl1.h create mode 100644 hw/misc/rt500_clkctl0.c create mode 100644 hw/misc/rt500_clkctl1.c
include/hw/arm/svd/rt500_clkctl0.h new file +509 -0
@@ -0,0 +1,509 @@ +/* +* Copyright 2016-2023 NXP SPDX-License-Identifier: BSD-3-Clause +* +* Automatically generated by svd-gen-header.py from MIMXRT595S_cm33.xml +*/ +#pragma once + +#include "hw/register.h" + +/* Clock Controller 0 */ +#define RT500_CLKCTL0_REGS_NO (490) + +/* Clock Control 0 */ +REG32 (RT500_CLKCTL0_PSCCTL0 ,0x10 ); +/* DSP clock control */ +FIELD (RT500_CLKCTL0_PSCCTL0 ,DSP_CLK ,1 ,1 ); +/* 128KB ROM Controller clock control */ +FIELD (RT500_CLKCTL0_PSCCTL0 ,ROM_CTRLR_CLK ,2 ,1 ); + +/* Clock Control 1 */ +REG32 (RT500_CLKCTL0_PSCCTL1 ,0x14 ); + +/* Clock Control 2 */ +REG32 (RT500_CLKCTL0_PSCCTL2 ,0x18 ); + +/* Clock Control 0 Set */ +REG32 (RT500_CLKCTL0_PSCCTL0_SET ,0x40 ); +/* DSP clock set */ +FIELD (RT500_CLKCTL0_PSCCTL0_SET ,DSP_CLK ,1 ,1 ); +/* 128KB ROM Controller clock set */ +FIELD (RT500_CLKCTL0_PSCCTL0_SET ,ROM_CTRLR_CLK ,2 ,1 ); + +/* Clock Control 1 Set */ +REG32 (RT500_CLKCTL0_PSCCTL1_SET ,0x44 ); + +/* Clock Control 2 Set */ +REG32 (RT500_CLKCTL0_PSCCTL2_SET ,0x48 ); + +/* Clock Control 0 Clear */ +REG32 (RT500_CLKCTL0_PSCCTL0_CLR ,0x70 ); +/* DSP clock clear */ +FIELD (RT500_CLKCTL0_PSCCTL0_CLR ,DSP_CLK ,1 ,1 ); +/* 128KB ROM Controller clock clear */ +FIELD (RT500_CLKCTL0_PSCCTL0_CLR ,ROM_CTRLR_CLK ,2 ,1 ); + +/* Clock Control 1 Clear */ +REG32 (RT500_CLKCTL0_PSCCTL1_CLR ,0x74 ); + +/* Clock Control 2 Clear */ +REG32 (RT500_CLKCTL0_PSCCTL2_CLR ,0x78 ); + +/* FRO Clock Status */ +REG32 (RT500_CLKCTL0_FROCLKSTATUS ,0x10C ); + +/* System PLL0 PFD */ +REG32 (RT500_CLKCTL0_SYSPLL0PFD ,0x218 ); +/* PLL Fractional Divider 0 */ +FIELD (RT500_CLKCTL0_SYSPLL0PFD ,PFD0 ,0 ,6 ); +/* PFD0 Clock Ready Status Flag */ +FIELD (RT500_CLKCTL0_SYSPLL0PFD ,PFD0_CLKRDY ,6 ,1 ); +/* PFD0 Clock Gate */ +FIELD (RT500_CLKCTL0_SYSPLL0PFD ,PFD0_CLKGATE ,7 ,1 ); +/* PLL Fractional Divider 1 */ +FIELD (RT500_CLKCTL0_SYSPLL0PFD ,PFD1 ,8 ,6 ); +/* PFD1 Clock Ready Status Flag */ +FIELD (RT500_CLKCTL0_SYSPLL0PFD ,PFD1_CLKRDY ,14 ,1 ); +/* PFD1 Clock Gate */ +FIELD (RT500_CLKCTL0_SYSPLL0PFD ,PFD1_CLKGATE ,15 ,1 ); +/* PLL Fractional Divider 2 */ +FIELD (RT500_CLKCTL0_SYSPLL0PFD ,PFD2 ,16 ,6 ); +/* PFD2 Clock Ready Status Flag */ +FIELD (RT500_CLKCTL0_SYSPLL0PFD ,PFD2_CLKRDY ,22 ,1 ); +/* PFD2 Clock Gate */ +FIELD (RT500_CLKCTL0_SYSPLL0PFD ,PFD2_CLKGATE ,23 ,1 ); +/* PLL Fractional Divider 3 */ +FIELD (RT500_CLKCTL0_SYSPLL0PFD ,PFD3 ,24 ,6 ); +/* PFD3 Clock Ready Status Flag */ +FIELD (RT500_CLKCTL0_SYSPLL0PFD ,PFD3_CLKRDY ,30 ,1 ); +/* PFD3 Clock Gate */ +FIELD (RT500_CLKCTL0_SYSPLL0PFD ,PFD3_CLKGATE ,31 ,1 ); + +/* SYSTICK Functional Clock Select */ +REG32 (RT500_CLKCTL0_SYSTICKFCLKSEL ,0x760 ); +/* Select Clock Source */ +FIELD (RT500_CLKCTL0_SYSTICKFCLKSEL ,SEL ,0 ,3 ); +/* Systick Divider Output Clock */ +#define RT500_CLKCTL0_SYSTICKFCLKSEL_SEL_SYSTICK_DIV_OUTPUT 0 +/* Low Power Oscillator Clock (LPOSC) */ +#define RT500_CLKCTL0_SYSTICKFCLKSEL_SEL_LPOSC 1 +/* 32 KHz RTC Clock */ +#define RT500_CLKCTL0_SYSTICKFCLKSEL_SEL_A32KHZ_RTC 2 +/* None; this may be selected to reduce power when no output is needed. */ +#define RT500_CLKCTL0_SYSTICKFCLKSEL_SEL_NONE 7 + +/* SYSTICK Functional Clock Divider */ +REG32 (RT500_CLKCTL0_SYSTICKFCLKDIV ,0x764 ); +/* Clock Divider Value Selection */ +FIELD (RT500_CLKCTL0_SYSTICKFCLKDIV ,DIV ,0 ,8 ); +/* Reset the Divider Counter */ +FIELD (RT500_CLKCTL0_SYSTICKFCLKDIV ,RESET ,29 ,1 ); +/* Halt the Divider Counter */ +FIELD (RT500_CLKCTL0_SYSTICKFCLKDIV ,HALT ,30 ,1 ); +/* Divider status flag */ +FIELD (RT500_CLKCTL0_SYSTICKFCLKDIV ,REQFLAG ,31 ,1 ); + + +#define RT500_CLKCTL0_REGISTER_ACCESS_INFO_ARRAY (_name) \ + struct RegisterAccessInfo _name[RT500_CLKCTL0_REGS_NO] = { \ + [0 ... RT500_CLKCTL0_REGS_NO - 1] = { \ + .name = "", \ + .addr = -1, \ + }, \ + [0x4] = { \ + .name = "PSCCTL0", \ + .addr = 0x10, \ + .ro = 0xA208E0E1, \ + .reset = 0x5, \ + }, \ + [0x5] = { \ + .name = "PSCCTL1", \ + .addr = 0x14, \ + .ro = 0xFEFE7FF3, \ + .reset = 0x0, \ + }, \ + [0x6] = { \ + .name = "PSCCTL2", \ + .addr = 0x18, \ + .ro = 0xDFFFFFFC, \ + .reset = 0x0, \ + }, \ + [0x10] = { \ + .name = "PSCCTL0_SET", \ + .addr = 0x40, \ + .ro = 0xA208E0E1, \ + .reset = 0x0, \ + }, \ + [0x11] = { \ + .name = "PSCCTL1_SET", \ + .addr = 0x44, \ + .ro = 0xFEFE7FF3, \ + .reset = 0x0, \ + }, \ + [0x12] = { \ + .name = "PSCCTL2_SET", \ + .addr = 0x48, \ + .ro = 0xDFFFFFFC, \ + .reset = 0x0, \ + }, \ + [0x1C] = { \ + .name = "PSCCTL0_CLR", \ + .addr = 0x70, \ + .ro = 0xA208E0E1, \ + .reset = 0x0, \ + }, \ + [0x1D] = { \ + .name = "PSCCTL1_CLR", \ + .addr = 0x74, \ + .ro = 0xFEFE7FF3, \ + .reset = 0x0, \ + }, \ + [0x1E] = { \ + .name = "PSCCTL2_CLR", \ + .addr = 0x78, \ + .ro = 0xDFFFFFFC, \ + .reset = 0x0, \ + }, \ + [0x20] = { \ + .name = "FRO_CONTROL", \ + .addr = 0x80, \ + .ro = 0x7C000000, \ + .reset = 0x0, \ + }, \ + [0x21] = { \ + .name = "FRO_CAPVAL", \ + .addr = 0x84, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x23] = { \ + .name = "FRO_RDTRIM", \ + .addr = 0x8C, \ + .ro = 0xFFFFF800, \ + .reset = 0x3BF, \ + }, \ + [0x24] = { \ + .name = "FRO_SCTRIM", \ + .addr = 0x90, \ + .ro = 0xFFFFFFC0, \ + .reset = 0x20, \ + }, \ + [0x42] = { \ + .name = "FRODIVSEL", \ + .addr = 0x108, \ + .ro = 0xFFFFFFFC, \ + .reset = 0x0, \ + }, \ + [0x43] = { \ + .name = "FROCLKSTATUS", \ + .addr = 0x10C, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x44] = { \ + .name = "FRODIVOEN", \ + .addr = 0x110, \ + .ro = 0xFFFFFFE0, \ + .reset = 0x0, \ + }, \ + [0x4C] = { \ + .name = "LOWFREQCLKDIV", \ + .addr = 0x130, \ + .ro = 0x1FFFFF00, \ + .reset = 0x0, \ + }, \ + [0x58] = { \ + .name = "SYSOSCCTL0", \ + .addr = 0x160, \ + .ro = 0xFFFFFFFC, \ + .reset = 0x0, \ + }, \ + [0x5A] = { \ + .name = "SYSOSCBYPASS", \ + .addr = 0x168, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x0, \ + }, \ + [0x64] = { \ + .name = "LPOSCCTL0", \ + .addr = 0x190, \ + .ro = 0x7FFFFFFF, \ + .reset = 0x807BC4D4, \ + }, \ + [0x70] = { \ + .name = "OSC32KHZCTL0", \ + .addr = 0x1C0, \ + .ro = 0xFFFFFFFE, \ + .reset = 0x0, \ + }, \ + [0x80] = { \ + .name = "SYSPLL0CLKSEL", \ + .addr = 0x200, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x81] = { \ + .name = "SYSPLL0CTL0", \ + .addr = 0x204, \ + .ro = 0xFF00DFFC, \ + .reset = 0x160002, \ + }, \ + [0x83] = { \ + .name = "SYSPLL0LOCKTIMEDIV2", \ + .addr = 0x20C, \ + .ro = 0xFFFF0000, \ + .reset = 0xCAFE, \ + }, \ + [0x84] = { \ + .name = "SYSPLL0NUM", \ + .addr = 0x210, \ + .ro = 0xC0000000, \ + .reset = 0x4DD2F15, \ + }, \ + [0x85] = { \ + .name = "SYSPLL0DENOM", \ + .addr = 0x214, \ + .ro = 0xC0000000, \ + .reset = 0x1FFFFFDB, \ + }, \ + [0x86] = { \ + .name = "SYSPLL0PFD", \ + .addr = 0x218, \ + .ro = 0x0, \ + .reset = 0x80808080, \ + }, \ + [0x90] = { \ + .name = "MAINPLLCLKDIV", \ + .addr = 0x240, \ + .ro = 0x1FFFFF00, \ + .reset = 0x0, \ + }, \ + [0x91] = { \ + .name = "DSPPLLCLKDIV", \ + .addr = 0x244, \ + .ro = 0x1FFFFF00, \ + .reset = 0x0, \ + }, \ + [0x92] = { \ + .name = "AUX0PLLCLKDIV", \ + .addr = 0x248, \ + .ro = 0x1FFFFF00, \ + .reset = 0x0, \ + }, \ + [0x93] = { \ + .name = "AUX1PLLCLKDIV", \ + .addr = 0x24C, \ + .ro = 0x1FFFFF00, \ + .reset = 0x0, \ + }, \ + [0x100] = { \ + .name = "SYSCPUAHBCLKDIV", \ + .addr = 0x400, \ + .ro = 0x7FFFFF00, \ + .reset = 0x0, \ + }, \ + [0x10C] = { \ + .name = "MAINCLKSELA", \ + .addr = 0x430, \ + .ro = 0xFFFFFFFC, \ + .reset = 0x0, \ + }, \ + [0x10D] = { \ + .name = "MAINCLKSELB", \ + .addr = 0x434, \ + .ro = 0xFFFFFFFC, \ + .reset = 0x0, \ + }, \ + [0x140] = { \ + .name = "PFC0DIV", \ + .addr = 0x500, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000000, \ + }, \ + [0x141] = { \ + .name = "PFC1DIV", \ + .addr = 0x504, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000000, \ + }, \ + [0x188] = { \ + .name = "FLEXSPI0FCLKSEL", \ + .addr = 0x620, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x189] = { \ + .name = "FLEXSPI0FCLKDIV", \ + .addr = 0x624, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000000, \ + }, \ + [0x18C] = { \ + .name = "FLEXSPI1FCLKSEL", \ + .addr = 0x630, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x18D] = { \ + .name = "FLEXSPI1FCLKDIV", \ + .addr = 0x634, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000000, \ + }, \ + [0x190] = { \ + .name = "SCTFCLKSEL", \ + .addr = 0x640, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x191] = { \ + .name = "SCTIN7CLKDIV", \ + .addr = 0x644, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000000, \ + }, \ + [0x198] = { \ + .name = "USBHSFCLKSEL", \ + .addr = 0x660, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x199] = { \ + .name = "USBHSFCLKDIV", \ + .addr = 0x664, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000000, \ + }, \ + [0x1A0] = { \ + .name = "SDIO0FCLKSEL", \ + .addr = 0x680, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x1A1] = { \ + .name = "SDIO0FCLKDIV", \ + .addr = 0x684, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000000, \ + }, \ + [0x1A4] = { \ + .name = "SDIO1FCLKSEL", \ + .addr = 0x690, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x1A5] = { \ + .name = "SDIO1FCLKDIV", \ + .addr = 0x694, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000000, \ + }, \ + [0x1B4] = { \ + .name = "ADC0FCLKSEL0", \ + .addr = 0x6D0, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x1B5] = { \ + .name = "ADC0FCLKSEL1", \ + .addr = 0x6D4, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x1B6] = { \ + .name = "ADC0FCLKDIV", \ + .addr = 0x6D8, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000000, \ + }, \ + [0x1C0] = { \ + .name = "UTICKFCLKSEL", \ + .addr = 0x700, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x1C8] = { \ + .name = "WDT0FCLKSEL", \ + .addr = 0x720, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x0, \ + }, \ + [0x1CC] = { \ + .name = "A32KHZWAKECLKSEL", \ + .addr = 0x730, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x1, \ + }, \ + [0x1CD] = { \ + .name = "A32KHZWAKECLKDIV", \ + .addr = 0x734, \ + .ro = 0x1FFFFF00, \ + .reset = 0x1F, \ + }, \ + [0x1D8] = { \ + .name = "SYSTICKFCLKSEL", \ + .addr = 0x760, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x1D9] = { \ + .name = "SYSTICKFCLKDIV", \ + .addr = 0x764, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000000, \ + }, \ + [0x1DC] = { \ + .name = "DPHYCLKSEL", \ + .addr = 0x770, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x1DD] = { \ + .name = "DPHYCLKDIV", \ + .addr = 0x774, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000000, \ + }, \ + [0x1DE] = { \ + .name = "DPHYESCCLKSEL", \ + .addr = 0x778, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x1DF] = { \ + .name = "DPHYESCRXCLKDIV", \ + .addr = 0x77C, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000010, \ + }, \ + [0x1E0] = { \ + .name = "DPHYESCTXCLKDIV", \ + .addr = 0x780, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000011, \ + }, \ + [0x1E4] = { \ + .name = "GPUCLKSEL", \ + .addr = 0x790, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x1E5] = { \ + .name = "GPUCLKDIV", \ + .addr = 0x794, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000000, \ + }, \ + [0x1E8] = { \ + .name = "DCPIXELCLKSEL", \ + .addr = 0x7A0, \ + .ro = 0xFFFFFFF8, \ + .reset = 0x7, \ + }, \ + [0x1E9] = { \ + .name = "DCPIXELCLKDIV", \ + .addr = 0x7A4, \ + .ro = 0x1FFFFF00, \ + .reset = 0x40000000, \ + }, \ + }
include/hw/arm/svd/rt500_clkctl1.h new file +675 -0
675 lines not on this page · raw message
include/hw/misc/rt500_clk_freqs.h new file +18 -0
@@ -0,0 +1,18 @@ +/* +* QEMU model for RT500 Clock Controller +* +* Copyright (c) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef HW_MISC_RT500_CLK_FREQS_H +#define HW_MISC_RT500_CLK_FREQS_H + +#define RTC32KHZ_CLK_HZ 32000 +#define LPOSC_CLK_HZ 1000000 + +#endif /* HW_MISC_RT500_CLK_FREQS_H */
include/hw/misc/rt500_clkctl0.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* QEMU model for RT500 Clock Controller +* +* Copyright (c) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef HW_MISC_RT500_CLKCTL0_H +#define HW_MISC_RT500_CLKCTL0_H + +#include "hw/arm/svd/rt500_clkctl0.h" +#include "hw/sysbus.h" + +#define TYPE_RT500_CLKCTL0 "rt500-clkctl0" +#define RT500_CLKCTL0 (o) OBJECT_CHECK(RT500ClkCtl0State, o, TYPE_RT500_CLKCTL0) + +#define SYSTICKFCLKSEL_DIVOUT 0 +#define SYSTICKFCLKSEL_LPOSC 1 +#define SYSTICKFCLKSEL_32KHZRTC 2 +#define SYSTICKFCLKSEL_NONE 7 + +typedef struct { +SysBusDevice parent_obj; + +MemoryRegion mmio; +uint32_t regs[RT500_CLKCTL0_REGS_NO ]; +Clock *systick_clk; +Clock *sysclk; +}RT500ClkCtl0State ; + +#endif /* HW_MISC_RT500_CLKCTL0_H */
include/hw/misc/rt500_clkctl1.h new file +36 -0
@@ -0,0 +1,36 @@ +/* +* QEMU model for RT500 Clock Controller +* +* Copyright (c) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + + +#ifndef HW_MISC_RT500_CLKCTL1_H +#define HW_MISC_RT500_CLKCTL1_H + +#include "hw/arm/svd/rt500_clkctl1.h" +#include "hw/sysbus.h" + +#define TYPE_RT500_CLKCTL1 "rt500-clkctl1" +#define RT500_CLKCTL1 (o) OBJECT_CHECK(RT500ClkCtl1State, o, TYPE_RT500_CLKCTL1) + +#define OSEVENTTFCLKSEL_LPOSC 0 +#define OSEVENTTFCLKSEL_32KHZRTC 1 +#define OSEVENTTFCLKSEL_HCLK 2 +#define OSEVENTTFCLKSEL_NONE 7 + +typedef struct { +SysBusDevice parent_obj; + +MemoryRegion mmio; +uint32_t regs[RT500_CLKCTL1_REGS_NO ]; +Clock *sysclk; +Clock *ostimer_clk; +}RT500ClkCtl1State ; + +#endif /* HW_MISC_RT500_CLKCTL1_H */
hw/misc/rt500_clkctl0.c new file +253 -0
253 lines not on this page · raw message
hw/misc/rt500_clkctl1.c new file +238 -0
238 lines not on this page · raw message
hw/arm/Kconfig +5 -0
@@ -629,3 +629,8 @@ config ARMSSE select UNIMP select SSE_COUNTER select SSE_TIMER + +config RT500 + bool + select FLEXCOMM + select RT500_CLKCTL
hw/arm/svd/meson.build +8 -0
@@ -16,4 +16,12 @@ if get_option('mcux-soc-svd') [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexcomm_spi.h', '-p', 'SPI0', '-t', 'FLEXCOMM_SPI', '--fields', 'CFG FIFOCFG:ENABLE*,EMPTY* FIFO*:* INT*: STAT']) + run_target('svd-rt500-clkctl0', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500_clkctl0.h', + '-p', 'CLKCTL0', '-t', 'RT500_CLKCTL0', + '--fields', 'PSCCTL*:ROM_CTRLR_CLK,DSP_CLK SYSPLL0PFD SYSTICKFCLKSEL SYSTICKFCLKDIV FROCLKSTATUS:']) + run_target('svd-rt500-clkctl1', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500_clkctl1.h', + '-p', 'CLKCTL1', '-t', 'RT500_CLKCTL1', + '--fields', 'PSCCTL*:FlexIO AUDIOPLL0PFD OSEVENTTFCLKSEL']) endif
hw/misc/Kconfig +3 -0
@@ -218,4 +218,7 @@ config FLEXCOMM select I2C select SSI +config RT500_CLKCTL + bool + source macio/Kconfig
hw/misc/meson.build +1 -0
@@ -153,3 +153,4 @@ system_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa_ec.c')) system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm.c')) +system_ss.add(when: 'CONFIG_RT500_CLKCTL', if_true: files('rt500_clkctl0.c', 'rt500_clkctl1.c'))
hw/misc/trace-events +8 -0
@@ -368,3 +368,11 @@ flexcomm_irq(const char *id, uint8_t irq) "%s %d" flexcomm_reg_read(const char *devname, const char *regname, uint32_t addr, uint32_t val) "%s: %s[0x%04x] -> 0x%08x" flexcomm_reg_write(const char *dename, const char *regname, uint32_t addr, uint32_t val) "%s: %s[0x%04x] <- 0x%08x" flexcomm_fifostat(const char *id, uint32_t fifostat, uint32_t fifoinstat) "%s: %08x %08x" + +# rt500_clkctl0.c +rt500_clkctl0_reg_read(const char *regname, uint32_t addr, uint32_t val) "%s[0x%04x] -> 0x%08x" +rt500_clkctl0_reg_write(const char *regname, uint32_t addr, uint32_t val) "%s[0x%04x] <- 0x%08x" + +# rt500_clkctl1.c +rt500_clkctl1_reg_read(const char *regname, uint32_t addr, uint32_t val) "%s[0x%04x] -> 0x%08x" +rt500_clkctl1_reg_write(const char *regname, uint32_t addr, uint32_t val) "%s[0x%04x] <- 0x%08x"
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 11/25 hw/ssi: add support for flexspi
In reply to Octavian PurdilaThis is mostly a stub which completes SPI transactions as noops by masking out the error interrupts and never clearing the IPCMDDONE interrupt.
Although incomplete, this allows software that uses NXP's mcuxpresso SDK to run the SDK board initialization functions.
It also supports AHB memory access, aka XIP, for now as simple RAM memory regions.
The patch includes an automatically generated header which contains the register layout and helpers.
The header can be regenerated with the svd-flexspi target when the build is configured with --enable-mcux-soc-svd.
--- include/hw/arm/svd/flexspi.h | 1085 ++++++++++++++++++++++++++++++++++ include/hw/ssi/flexspi.h | 31 + hw/ssi/flexspi.c | 181 ++++++ hw/arm/svd/meson.build | 4 + hw/ssi/Kconfig | 4 + hw/ssi/meson.build | 1 + hw/ssi/trace-events | 4 + 7 files changed, 1310 insertions(+) create mode 100644 include/hw/arm/svd/flexspi.h create mode 100644 include/hw/ssi/flexspi.h create mode 100644 hw/ssi/flexspi.c
include/hw/arm/svd/flexspi.h new file +1085 -0
@@ -0,0 +1,1085 @@ +/* +* Copyright 2016-2023 NXP SPDX-License-Identifier: BSD-3-Clause +* +* Automatically generated by svd-gen-header.py from MIMXRT595S_cm33.xml +*/ +#pragma once + +#include "hw/register.h" + +/* FlexSPI */ +#define FLEXSPI_REGS_NO (267) + +/* Module Control Register 0 */ +REG32 (FLEXSPI_MCR0 ,0x0 ); +/* Software Reset */ +FIELD (FLEXSPI_MCR0 ,SWRESET ,0 ,1 ); + +/* Interrupt Register */ +REG32 (FLEXSPI_INTR ,0x14 ); +/* +* IP triggered Command Sequences Execution finished interrupt. This interrupt +* is also generated when there is IPCMDGE or IPCMDERR interrupt generated. +*/ +FIELD (FLEXSPI_INTR ,IPCMDDONE ,0 ,1 ); + +/* Status Register 0 */ +REG32 (FLEXSPI_STS0 ,0xE0 ); +/* +* This status bit indicates the state machine in SEQ_CTL is idle and there is +* command sequence executing on FlexSPI interface. +*/ +FIELD (FLEXSPI_STS0 ,SEQIDLE ,0 ,1 ); + + +#define FLEXSPI_REGISTER_ACCESS_INFO_ARRAY (_name) \ + struct RegisterAccessInfo _name[FLEXSPI_REGS_NO] = { \ + [0 ... FLEXSPI_REGS_NO - 1] = { \ + .name = "", \ + .addr = -1, \ + }, \ + [0x0] = { \ + .name = "MCR0", \ + .addr = 0x0, \ + .ro = 0x20CC, \ + .reset = 0xFFFF80C2, \ + }, \ + [0x1] = { \ + .name = "MCR1", \ + .addr = 0x4, \ + .ro = 0x0, \ + .reset = 0xFFFFFFFF, \ + }, \ + [0x2] = { \ + .name = "MCR2", \ + .addr = 0x8, \ + .ro = 0xFF37FF, \ + .reset = 0x200081F7, \ + }, \ + [0x3] = { \ + .name = "AHBCR", \ + .addr = 0xC, \ + .ro = 0xFFFFFB02, \ + .reset = 0x18, \ + }, \ + [0x4] = { \ + .name = "INTEN", \ + .addr = 0x10, \ + .ro = 0xFFFFC000, \ + .reset = 0x0, \ + }, \ + [0x5] = { \ + .name = "INTR", \ + .addr = 0x14, \ + .ro = 0xFFFFE000, \ + .reset = 0x0, \ + }, \ + [0x6] = { \ + .name = "LUTKEY", \ + .addr = 0x18, \ + .ro = 0x0, \ + .reset = 0x5AF05AF0, \ + }, \ + [0x7] = { \ + .name = "LUTCR", \ + .addr = 0x1C, \ + .ro = 0xFFFFFFFC, \ + .reset = 0x2, \ + }, \ + [0x8] = { \ + .name = "AHBRXBUF0CR0", \ + .addr = 0x20, \ + .ro = 0x78F0FF00, \ + .reset = 0x80000010, \ + }, \ + [0x9] = { \ + .name = "AHBRXBUF1CR0", \ + .addr = 0x24, \ + .ro = 0x78F0FF00, \ + .reset = 0x80010010, \ + }, \ + [0xA] = { \ + .name = "AHBRXBUF2CR0", \ + .addr = 0x28, \ + .ro = 0x78F0FF00, \ + .reset = 0x80020010, \ + }, \ + [0xB] = { \ + .name = "AHBRXBUF3CR0", \ + .addr = 0x2C, \ + .ro = 0x78F0FF00, \ + .reset = 0x80030010, \ + }, \ + [0xC] = { \ + .name = "AHBRXBUF4CR0", \ + .addr = 0x30, \ + .ro = 0x78F0FF00, \ + .reset = 0x80040010, \ + }, \ + [0xD] = { \ + .name = "AHBRXBUF5CR0", \ + .addr = 0x34, \ + .ro = 0x78F0FF00, \ + .reset = 0x80050010, \ + }, \ + [0xE] = { \ + .name = "AHBRXBUF6CR0", \ + .addr = 0x38, \ + .ro = 0x78F0FF00, \ + .reset = 0x80060010, \ + }, \ + [0xF] = { \ + .name = "AHBRXBUF7CR0", \ + .addr = 0x3C, \ + .ro = 0x78F0FF00, \ + .reset = 0x80070010, \ + }, \ + [0x18] = { \ + .name = "FLSHA1CR0", \ + .addr = 0x60, \ + .ro = 0xFF800000, \ + .reset = 0x10000, \ + }, \ + [0x19] = { \ + .name = "FLSHA2CR0", \ + .addr = 0x64, \ + .ro = 0xFF800000, \ + .reset = 0x10000, \ + }, \ + [0x1A] = { \ + .name = "FLSHB1CR0", \ + .addr = 0x68, \ + .ro = 0xFF800000, \ + .reset = 0x10000, \ + }, \ + [0x1B] = { \ + .name = "FLSHB2CR0", \ + .addr = 0x6C, \ + .ro = 0xFF800000, \ + .reset = 0x10000, \ + }, \ + [0x1C] = { \ + .name = "FLSHCR1A1", \ + .addr = 0x70, \ + .ro = 0x0, \ + .reset = 0x63, \ + }, \ + [0x1D] = { \ + .name = "FLSHCR1A2", \ + .addr = 0x74, \ + .ro = 0x0, \ + .reset = 0x63, \ + }, \ + [0x1E] = { \ + .name = "FLSHCR1B1", \ + .addr = 0x78, \ + .ro = 0x0, \ + .reset = 0x63, \ + }, \ + [0x1F] = { \ + .name = "FLSHCR1B2", \ + .addr = 0x7C, \ + .ro = 0x0, \ + .reset = 0x63, \ + }, \ + [0x20] = { \ + .name = "FLSHCR2A1", \ + .addr = 0x80, \ + .ro = 0x1010, \ + .reset = 0x0, \ + }, \ + [0x21] = { \ + .name = "FLSHCR2A2", \ + .addr = 0x84, \ + .ro = 0x1010, \ + .reset = 0x0, \ + }, \ + [0x22] = { \ + .name = "FLSHCR2B1", \ + .addr = 0x88, \ + .ro = 0x1010, \ + .reset = 0x0, \ + }, \ + [0x23] = { \ + .name = "FLSHCR2B2", \ + .addr = 0x8C, \ + .ro = 0x1010, \ + .reset = 0x0, \ + }, \ + [0x25] = { \ + .name = "FLSHCR4", \ + .addr = 0x94, \ + .ro = 0xFFFFFFFA, \ + .reset = 0x0, \ + }, \ + [0x28] = { \ + .name = "IPCR0", \ + .addr = 0xA0, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x29] = { \ + .name = "IPCR1", \ + .addr = 0xA4, \ + .ro = 0x78F00000, \ + .reset = 0x0, \ + }, \ + [0x2C] = { \ + .name = "IPCMD", \ + .addr = 0xB0, \ + .ro = 0xFFFFFFFE, \ + .reset = 0x0, \ + }, \ + [0x2D] = { \ + .name = "DLPR", \ + .addr = 0xB4, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x2E] = { \ + .name = "IPRXFCR", \ + .addr = 0xB8, \ + .ro = 0xFFFFFE00, \ + .reset = 0x0, \ + }, \ + [0x2F] = { \ + .name = "IPTXFCR", \ + .addr = 0xBC, \ + .ro = 0xFFFFFE00, \ + .reset = 0x0, \ + }, \ + [0x30] = { \ + .name = "DLLCRA", \ + .addr = 0xC0, \ + .ro = 0xFFFF8084, \ + .reset = 0x100, \ + }, \ + [0x31] = { \ + .name = "DLLCRB", \ + .addr = 0xC4, \ + .ro = 0xFFFF8084, \ + .reset = 0x100, \ + }, \ + [0x38] = { \ + .name = "STS0", \ + .addr = 0xE0, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x2, \ + }, \ + [0x39] = { \ + .name = "STS1", \ + .addr = 0xE4, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x3A] = { \ + .name = "STS2", \ + .addr = 0xE8, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x1000100, \ + }, \ + [0x3B] = { \ + .name = "AHBSPNDSTS", \ + .addr = 0xEC, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x3C] = { \ + .name = "IPRXFSTS", \ + .addr = 0xF0, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x3D] = { \ + .name = "IPTXFSTS", \ + .addr = 0xF4, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x40] = { \ + .name = "RFDR0", \ + .addr = 0x100, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x41] = { \ + .name = "RFDR1", \ + .addr = 0x104, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x42] = { \ + .name = "RFDR2", \ + .addr = 0x108, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x43] = { \ + .name = "RFDR3", \ + .addr = 0x10C, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x44] = { \ + .name = "RFDR4", \ + .addr = 0x110, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x45] = { \ + .name = "RFDR5", \ + .addr = 0x114, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x46] = { \ + .name = "RFDR6", \ + .addr = 0x118, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x47] = { \ + .name = "RFDR7", \ + .addr = 0x11C, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x48] = { \ + .name = "RFDR8", \ + .addr = 0x120, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x49] = { \ + .name = "RFDR9", \ + .addr = 0x124, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x4A] = { \ + .name = "RFDR10", \ + .addr = 0x128, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x4B] = { \ + .name = "RFDR11", \ + .addr = 0x12C, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x4C] = { \ + .name = "RFDR12", \ + .addr = 0x130, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x4D] = { \ + .name = "RFDR13", \ + .addr = 0x134, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x4E] = { \ + .name = "RFDR14", \ + .addr = 0x138, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x4F] = { \ + .name = "RFDR15", \ + .addr = 0x13C, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x50] = { \ + .name = "RFDR16", \ + .addr = 0x140, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x51] = { \ + .name = "RFDR17", \ + .addr = 0x144, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x52] = { \ + .name = "RFDR18", \ + .addr = 0x148, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x53] = { \ + .name = "RFDR19", \ + .addr = 0x14C, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x54] = { \ + .name = "RFDR20", \ + .addr = 0x150, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x55] = { \ + .name = "RFDR21", \ + .addr = 0x154, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x56] = { \ + .name = "RFDR22", \ + .addr = 0x158, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x57] = { \ + .name = "RFDR23", \ + .addr = 0x15C, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x58] = { \ + .name = "RFDR24", \ + .addr = 0x160, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x59] = { \ + .name = "RFDR25", \ + .addr = 0x164, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x5A] = { \ + .name = "RFDR26", \ + .addr = 0x168, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x5B] = { \ + .name = "RFDR27", \ + .addr = 0x16C, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x5C] = { \ + .name = "RFDR28", \ + .addr = 0x170, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x5D] = { \ + .name = "RFDR29", \ + .addr = 0x174, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x5E] = { \ + .name = "RFDR30", \ + .addr = 0x178, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x5F] = { \ + .name = "RFDR31", \ + .addr = 0x17C, \ + .ro = 0xFFFFFFFF, \ + .reset = 0x0, \ + }, \ + [0x60] = { \ + .name = "TFDR0", \ + .addr = 0x180, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x61] = { \ + .name = "TFDR1", \ + .addr = 0x184, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x62] = { \ + .name = "TFDR2", \ + .addr = 0x188, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x63] = { \ + .name = "TFDR3", \ + .addr = 0x18C, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x64] = { \ + .name = "TFDR4", \ + .addr = 0x190, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x65] = { \ + .name = "TFDR5", \ + .addr = 0x194, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x66] = { \ + .name = "TFDR6", \ + .addr = 0x198, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x67] = { \ + .name = "TFDR7", \ + .addr = 0x19C, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x68] = { \ + .name = "TFDR8", \ + .addr = 0x1A0, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x69] = { \ + .name = "TFDR9", \ + .addr = 0x1A4, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x6A] = { \ + .name = "TFDR10", \ + .addr = 0x1A8, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x6B] = { \ + .name = "TFDR11", \ + .addr = 0x1AC, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x6C] = { \ + .name = "TFDR12", \ + .addr = 0x1B0, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x6D] = { \ + .name = "TFDR13", \ + .addr = 0x1B4, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x6E] = { \ + .name = "TFDR14", \ + .addr = 0x1B8, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x6F] = { \ + .name = "TFDR15", \ + .addr = 0x1BC, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x70] = { \ + .name = "TFDR16", \ + .addr = 0x1C0, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x71] = { \ + .name = "TFDR17", \ + .addr = 0x1C4, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x72] = { \ + .name = "TFDR18", \ + .addr = 0x1C8, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x73] = { \ + .name = "TFDR19", \ + .addr = 0x1CC, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x74] = { \ + .name = "TFDR20", \ + .addr = 0x1D0, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x75] = { \ + .name = "TFDR21", \ + .addr = 0x1D4, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x76] = { \ + .name = "TFDR22", \ + .addr = 0x1D8, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x77] = { \ + .name = "TFDR23", \ + .addr = 0x1DC, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x78] = { \ + .name = "TFDR24", \ + .addr = 0x1E0, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x79] = { \ + .name = "TFDR25", \ + .addr = 0x1E4, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x7A] = { \ + .name = "TFDR26", \ + .addr = 0x1E8, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x7B] = { \ + .name = "TFDR27", \ + .addr = 0x1EC, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x7C] = { \ + .name = "TFDR28", \ + .addr = 0x1F0, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x7D] = { \ + .name = "TFDR29", \ + .addr = 0x1F4, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x7E] = { \ + .name = "TFDR30", \ + .addr = 0x1F8, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x7F] = { \ + .name = "TFDR31", \ + .addr = 0x1FC, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x80] = { \ + .name = "LUT0", \ + .addr = 0x200, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x81] = { \ + .name = "LUT1", \ + .addr = 0x204, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x82] = { \ + .name = "LUT2", \ + .addr = 0x208, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x83] = { \ + .name = "LUT3", \ + .addr = 0x20C, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x84] = { \ + .name = "LUT4", \ + .addr = 0x210, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x85] = { \ + .name = "LUT5", \ + .addr = 0x214, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x86] = { \ + .name = "LUT6", \ + .addr = 0x218, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x87] = { \ + .name = "LUT7", \ + .addr = 0x21C, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x88] = { \ + .name = "LUT8", \ + .addr = 0x220, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x89] = { \ + .name = "LUT9", \ + .addr = 0x224, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x8A] = { \ + .name = "LUT10", \ + .addr = 0x228, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x8B] = { \ + .name = "LUT11", \ + .addr = 0x22C, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x8C] = { \ + .name = "LUT12", \ + .addr = 0x230, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x8D] = { \ + .name = "LUT13", \ + .addr = 0x234, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x8E] = { \ + .name = "LUT14", \ + .addr = 0x238, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x8F] = { \ + .name = "LUT15", \ + .addr = 0x23C, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x90] = { \ + .name = "LUT16", \ + .addr = 0x240, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x91] = { \ + .name = "LUT17", \ + .addr = 0x244, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x92] = { \ + .name = "LUT18", \ + .addr = 0x248, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x93] = { \ + .name = "LUT19", \ + .addr = 0x24C, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x94] = { \ + .name = "LUT20", \ + .addr = 0x250, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x95] = { \ + .name = "LUT21", \ + .addr = 0x254, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x96] = { \ + .name = "LUT22", \ + .addr = 0x258, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x97] = { \ + .name = "LUT23", \ + .addr = 0x25C, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x98] = { \ + .name = "LUT24", \ + .addr = 0x260, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x99] = { \ + .name = "LUT25", \ + .addr = 0x264, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x9A] = { \ + .name = "LUT26", \ + .addr = 0x268, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x9B] = { \ + .name = "LUT27", \ + .addr = 0x26C, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x9C] = { \ + .name = "LUT28", \ + .addr = 0x270, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x9D] = { \ + .name = "LUT29", \ + .addr = 0x274, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x9E] = { \ + .name = "LUT30", \ + .addr = 0x278, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x9F] = { \ + .name = "LUT31", \ + .addr = 0x27C, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xA0] = { \ + .name = "LUT32", \ + .addr = 0x280, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xA1] = { \ + .name = "LUT33", \ + .addr = 0x284, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xA2] = { \ + .name = "LUT34", \ + .addr = 0x288, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xA3] = { \ + .name = "LUT35", \ + .addr = 0x28C, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xA4] = { \ + .name = "LUT36", \ + .addr = 0x290, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xA5] = { \ + .name = "LUT37", \ + .addr = 0x294, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xA6] = { \ + .name = "LUT38", \ + .addr = 0x298, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xA7] = { \ + .name = "LUT39", \ + .addr = 0x29C, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xA8] = { \ + .name = "LUT40", \ + .addr = 0x2A0, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xA9] = { \ + .name = "LUT41", \ + .addr = 0x2A4, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xAA] = { \ + .name = "LUT42", \ + .addr = 0x2A8, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xAB] = { \ + .name = "LUT43", \ + .addr = 0x2AC, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xAC] = { \ + .name = "LUT44", \ + .addr = 0x2B0, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xAD] = { \ + .name = "LUT45", \ + .addr = 0x2B4, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xAE] = { \ + .name = "LUT46", \ + .addr = 0x2B8, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xAF] = { \ + .name = "LUT47", \ + .addr = 0x2BC, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xB0] = { \ + .name = "LUT48", \ + .addr = 0x2C0, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xB1] = { \ + .name = "LUT49", \ + .addr = 0x2C4, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xB2] = { \ + .name = "LUT50", \ + .addr = 0x2C8, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xB3] = { \ + .name = "LUT51", \ + .addr = 0x2CC, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xB4] = { \ + .name = "LUT52", \ + .addr = 0x2D0, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xB5] = { \ + .name = "LUT53", \ + .addr = 0x2D4, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xB6] = { \ + .name = "LUT54", \ + .addr = 0x2D8, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xB7] = { \ + .name = "LUT55", \ + .addr = 0x2DC, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xB8] = { \ + .name = "LUT56", \ + .addr = 0x2E0, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xB9] = { \ + .name = "LUT57", \ + .addr = 0x2E4, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xBA] = { \ + .name = "LUT58", \ + .addr = 0x2E8, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xBB] = { \ + .name = "LUT59", \ + .addr = 0x2EC, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xBC] = { \ + .name = "LUT60", \ + .addr = 0x2F0, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xBD] = { \ + .name = "LUT61", \ + .addr = 0x2F4, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xBE] = { \ + .name = "LUT62", \ + .addr = 0x2F8, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0xBF] = { \ + .name = "LUT63", \ + .addr = 0x2FC, \ + .ro = 0x0, \ + .reset = 0x0, \ + }, \ + [0x108] = { \ + .name = "HADDRSTART", \ + .addr = 0x420, \ + .ro = 0xFFE, \ + .reset = 0x0, \ + }, \ + [0x109] = { \ + .name = "HADDREND", \ + .addr = 0x424, \ + .ro = 0xFFF, \ + .reset = 0x0, \ + }, \ + [0x10A] = { \ + .name = "HADDROFFSET", \ + .addr = 0x428, \ + .ro = 0xFFF, \ + .reset = 0x0, \ + }, \ + }
include/hw/ssi/flexspi.h new file +31 -0
@@ -0,0 +1,31 @@ +/* +* QEMU model for FLEXSPI +* +* Copyright (c) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef HW_RT500_FLEXSPI_H +#define HW_RT500_FLEXSPI_H + +#include "hw/sysbus.h" +#include "hw/ssi/ssi.h" +#include "hw/arm/svd/flexspi.h" + +#define TYPE_FLEXSPI "flexspi" +#define FLEXSPI (obj) OBJECT_CHECK(FlexSpiState, (obj), TYPE_FLEXSPI) + +typedef struct { +SysBusDevice parent_obj; + +MemoryRegion mmio; +uint32_t regs[FLEXSPI_REGS_NO ]; +MemoryRegion mem; +uint64_t mmap_size; +}FlexSpiState ; + +#endif /* HW_RT500_FLEXSPI_H */
hw/ssi/flexspi.c new file +181 -0
181 lines not on this page · raw message
hw/arm/svd/meson.build +4 -0
@@ -24,4 +24,8 @@ if get_option('mcux-soc-svd') [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500_clkctl1.h', '-p', 'CLKCTL1', '-t', 'RT500_CLKCTL1', '--fields', 'PSCCTL*:FlexIO AUDIOPLL0PFD OSEVENTTFCLKSEL']) + run_target('svd-flexspi', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexspi.h', + '-p', 'FLEXSPI0', '-t', 'FLEXSPI', + '--fields', 'STS0:SEQIDLE MCR0:SWRESET INTR:IPCMDDONE']) endif
hw/ssi/Kconfig +4 -0
@@ -28,3 +28,7 @@ config BCM2835_SPI config PNV_SPI bool select SSI + +config FLEXSPI + bool + select SSI
hw/ssi/meson.build +1 -0
@@ -13,3 +13,4 @@ system_ss.add(when: 'CONFIG_IBEX', if_true: files('ibex_spi_host.c')) system_ss.add(when: 'CONFIG_BCM2835_SPI', if_true: files('bcm2835_spi.c')) system_ss.add(when: 'CONFIG_PNV_SPI', if_true: files('pnv_spi.c')) system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm_spi.c')) +system_ss.add(when: 'CONFIG_FLEXSPI', if_true: files('flexspi.c'))
hw/ssi/trace-events +4 -0
@@ -58,3 +58,7 @@ pnv_spi_RDR_match(const char* result) "%s" flexcomm_spi_reg_read(const char *id, const char *reg_name, uint32_t addr, uint32_t val) " %s: %s[0x%04x] -> 0x%08x" flexcomm_spi_reg_write(const char *id, const char *reg_name, uint32_t addr, uint32_t val) "%s: %s[0x%04x] <- 0x%08x" flexcomm_spi_irq(const char *id, bool irq, bool fifoirqs, bool perirqs, bool enabled) "%s: %d %d %d %d" + +# flexspi.c +flexspi_reg_read(const char *id, const char *reg_name, uint32_t addr, uint32_t val) " %s: %s[0x%04x] -> 0x%08x" +flexspi_reg_write(const char *id, const char *reg_name, uint32_t addr, uint32_t val) "%s: %s[0x%04x] <- 0x%08x"
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 12/25 hw/misc: add support for RT500's reset controller
In reply to Octavian PurdilaThe RT500 reset controller has two instances that have the same register layout but with different fields for some registers.
The model only provides set and clear functionality for the various reset lines which is common for both instances. Because of that only one type is implemented for both controllers.
The patch includes automatically generated headers which contains the register layout and helpers.
The header can be regenerated with the svd-rstctl0 and svd-rstctl1 targets when the build is configured with --enable-mcux-soc-svd.
--- include/hw/arm/svd/rt500_rstctl0.h | 110 ++++++++++++ include/hw/arm/svd/rt500_rstctl1.h | 110 ++++++++++++ include/hw/misc/rt500_rstctl.h | 32 ++++ hw/misc/rt500_rstctl.c | 258 +++++++++++++++++++++++++++++ hw/arm/svd/meson.build | 8 + hw/misc/Kconfig | 3 + hw/misc/meson.build | 1 + hw/misc/trace-events | 4 + 8 files changed, 526 insertions(+) create mode 100644 include/hw/arm/svd/rt500_rstctl0.h create mode 100644 include/hw/arm/svd/rt500_rstctl1.h create mode 100644 include/hw/misc/rt500_rstctl.h create mode 100644 hw/misc/rt500_rstctl.c
include/hw/arm/svd/rt500_rstctl0.h new file +110 -0
@@ -0,0 +1,110 @@ +/* +* Copyright 2016-2023 NXP SPDX-License-Identifier: BSD-3-Clause +* +* Automatically generated by svd-gen-header.py from MIMXRT595S_cm33.xml +*/ +#pragma once + +#include "hw/register.h" + +/* Reset Controller 0 */ +#define RT500_RSTCTL0_REGS_NO (31) + +/* System Reset Status Register */ +REG32 (RT500_RSTCTL0_SYSRSTSTAT ,0x0 ); + +/* Peripheral Reset Control Register 0 */ +REG32 (RT500_RSTCTL0_PRSTCTL0 ,0x10 ); + +/* Peripheral Reset Control Register 1 */ +REG32 (RT500_RSTCTL0_PRSTCTL1 ,0x14 ); + +/* Peripheral Reset Control Register 2 */ +REG32 (RT500_RSTCTL0_PRSTCTL2 ,0x18 ); + +/* Peripheral Reset Control Register 0 SET */ +REG32 (RT500_RSTCTL0_PRSTCTL0_SET ,0x40 ); + +/* Peripheral Reset Control Register 1 SET */ +REG32 (RT500_RSTCTL0_PRSTCTL1_SET ,0x44 ); + +/* Peripheral Reset Control Register 2 SET */ +REG32 (RT500_RSTCTL0_PRSTCTL2_SET ,0x48 ); + +/* Peripheral Reset Control Register 0 CLR */ +REG32 (RT500_RSTCTL0_PRSTCTL0_CLR ,0x70 ); + +/* Peripheral Reset Control Register 1 CLR */ +REG32 (RT500_RSTCTL0_PRSTCTL1_CLR ,0x74 ); + +/* Peripheral Reset Control Register 2 CLR */ +REG32 (RT500_RSTCTL0_PRSTCTL2_CLR ,0x78 ); + + +#define RT500_RSTCTL0_REGISTER_ACCESS_INFO_ARRAY (_name) \ + struct RegisterAccessInfo _name[RT500_RSTCTL0_REGS_NO] = { \ + [0 ... RT500_RSTCTL0_REGS_NO - 1] = { \ + .name = "", \ + .addr = -1, \ + }, \ + [0x0] = { \ + .name = "SYSRSTSTAT", \ + .addr = 0x0, \ + .ro = 0xFFFFFF0E, \ + .reset = 0x1, \ + }, \ + [0x4] = { \ + .name = "PRSTCTL0", \ + .addr = 0x10, \ + .ro = 0x820AE0F5, \ + .reset = 0x7DF51F0A, \ + }, \ + [0x5] = { \ + .name = "PRSTCTL1", \ + .addr = 0x14, \ + .ro = 0xFEFE7FF3, \ + .reset = 0x101800C, \ + }, \ + [0x6] = { \ + .name = "PRSTCTL2", \ + .addr = 0x18, \ + .ro = 0xFFFFFFFC, \ + .reset = 0x1C000001, \ + }, \ + [0x10] = { \ + .name = "PRSTCTL0_SET", \ + .addr = 0x40, \ + .ro = 0x820AE0F5, \ + .reset = 0x0, \ + }, \ + [0x11] = { \ + .name = "PRSTCTL1_SET", \ + .addr = 0x44, \ + .ro = 0xFEFE7FF3, \ + .reset = 0x0, \ + }, \ + [0x12] = { \ + .name = "PRSTCTL2_SET", \ + .addr = 0x48, \ + .ro = 0xFFFFFFFC, \ + .reset = 0x0, \ + }, \ + [0x1C] = { \ + .name = "PRSTCTL0_CLR", \ + .addr = 0x70, \ + .ro = 0x820AE0F5, \ + .reset = 0x0, \ + }, \ + [0x1D] = { \ + .name = "PRSTCTL1_CLR", \ + .addr = 0x74, \ + .ro = 0xFEFE7FF3, \ + .reset = 0x0, \ + }, \ + [0x1E] = { \ + .name = "PRSTCTL2_CLR", \ + .addr = 0x78, \ + .ro = 0xFFFFFFFC, \ + .reset = 0x0, \ + }, \ + }
include/hw/arm/svd/rt500_rstctl1.h new file +110 -0
110 lines not on this page · raw message
include/hw/misc/rt500_rstctl.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* QEMU model for RT500 Reset Controller +* +* Copyright (c) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef HW_MISC_RT500_RSTCTL_H +#define HW_MISC_RT500_RSTCTL_H + +#include "hw/arm/svd/rt500_rstctl0.h" +#include "hw/arm/svd/rt500_rstctl1.h" +#include "hw/sysbus.h" + +#define TYPE_RT500_RSTCTL "rt500-rstctl" +#define RT500_RSTCTL (o) OBJECT_CHECK(RT500RstCtlState, o, TYPE_RT500_RSTCTL) + +#define TYPE_RT500_RSTCTL0 "rt500-rstctl0" +#define TYPE_RT500_RSTCTL1 "rt500-rstctl1" + +typedef struct { +SysBusDevice parent_obj; + +MemoryRegion mmio; +uint32_t regs[RT500_RSTCTL1_REGS_NO ]; +}RT500RstCtlState ; + +#endif /* HW_MISC_RT500_RSTCTL_H */
hw/misc/rt500_rstctl.c new file +258 -0
258 lines not on this page · raw message
hw/arm/svd/meson.build +8 -0
@@ -28,4 +28,12 @@ if get_option('mcux-soc-svd') [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/flexspi.h', '-p', 'FLEXSPI0', '-t', 'FLEXSPI', '--fields', 'STS0:SEQIDLE MCR0:SWRESET INTR:IPCMDDONE']) + run_target('svd-rt500-rstctl0', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500_rstctl0.h', + '-p', 'RSTCTL0', '-t', 'RT500_RSTCTL0', + '--fields', 'SYSRSTSTAT: PRSTCTL*:']) + run_target('svd-rt500-rstctl1', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500_rstctl1.h', + '-p', 'RSTCTL1', '-t', 'RT500_RSTCTL1', + '--fields', 'SYSRSTSTAT: PRSTCTL*:']) endif
hw/misc/Kconfig +3 -0
@@ -221,4 +221,7 @@ config FLEXCOMM config RT500_CLKCTL bool +config RT500_RSTCTL + bool + source macio/Kconfig
hw/misc/meson.build +1 -0
@@ -154,3 +154,4 @@ system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm.c')) system_ss.add(when: 'CONFIG_RT500_CLKCTL', if_true: files('rt500_clkctl0.c', 'rt500_clkctl1.c')) +system_ss.add(when: 'CONFIG_RT500_RSTCTL', if_true: files('rt500_rstctl.c'))
hw/misc/trace-events +4 -0
@@ -376,3 +376,7 @@ rt500_clkctl0_reg_write(const char *regname, uint32_t addr, uint32_t val) "%s[0x # rt500_clkctl1.c rt500_clkctl1_reg_read(const char *regname, uint32_t addr, uint32_t val) "%s[0x%04x] -> 0x%08x" rt500_clkctl1_reg_write(const char *regname, uint32_t addr, uint32_t val) "%s[0x%04x] <- 0x%08x" + +# rt500_rstctl.c +rt500_rstctl_reg_read(const char *id, const char *regname, uint32_t addr, uint32_t val) "%s: %s[0x%04x] -> 0x%08x" +rt500_rstctl_reg_write(const char *id, const char *regname, uint32_t addr, uint32_t val) "%s: %s[0x%04x] <- 0x%08x"
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 13/25 hw/arm: add basic support for the RT500 SoC
In reply to Octavian PurdilaAdd basic support for the RT500 SoC. It supports enough peripherals to run the NXP's microXpresso SDK hello world example.
The patch includes an automatically generated header which contains peripheral base addreses and interrupt numbers.
The header can be regenerated with the svd-rt500 target when the build is configured with --enable-mcux-soc-svd.
--- include/hw/arm/rt500.h | 44 +++++ include/hw/arm/svd/rt500.h | 63 +++++++ hw/arm/rt500.c | 329 +++++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 2 + hw/arm/meson.build | 1 + hw/arm/svd/meson.build | 4 + 6 files changed, 443 insertions(+) create mode 100644 include/hw/arm/rt500.h create mode 100644 include/hw/arm/svd/rt500.h create mode 100644 hw/arm/rt500.c
include/hw/arm/rt500.h new file +44 -0
@@ -0,0 +1,44 @@ +/* +* i.MX RT500 platforms. +* +* Copyright (c) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef HW_ARM_RT500_H +#define HW_ARM_RT500_H + +#include "hw/arm/armv7m.h" +#include "hw/misc/flexcomm.h" +#include "hw/misc/rt500_clkctl0.h" +#include "hw/misc/rt500_clkctl1.h" +#include "hw/ssi/flexspi.h" +#include "hw/misc/rt500_rstctl.h" + +#define TYPE_RT500 "rt500" +#define RT500 (obj) OBJECT_CHECK(RT500State, (obj), TYPE_RT500) + +#define RT500_FLEXCOMM_NUM (17) +#define RT500_FLEXSPI_NUM (2) +#define RT500_RSTCTL_NUM (2) + +typedef struct RT500State { +SysBusDevice parent_obj; + +ARMv7MState armv7m; +MemoryRegion *mem; +FlexcommState flexcomm[RT500_FLEXCOMM_NUM ]; +RT500ClkCtl0State clkctl0; +RT500ClkCtl1State clkctl1; +FlexSpiState flexspi[RT500_FLEXSPI_NUM ]; +RT500RstCtlState rstctl[RT500_RSTCTL_NUM ]; + +Clock *sysclk; +Clock *refclk; +}RT500State ; + +#endif /* HW_ARM_RT500_H */
include/hw/arm/svd/rt500.h new file +63 -0
63 lines not on this page · raw message
hw/arm/rt500.c new file +329 -0
329 lines not on this page · raw message
hw/arm/Kconfig +2 -0
@@ -634,3 +634,5 @@ config RT500 bool select FLEXCOMM select RT500_CLKCTL + select FLEXSPI + select RT500_RSTCTL
hw/arm/meson.build +1 -0
@@ -60,6 +60,7 @@ arm_ss.add(when: 'CONFIG_XEN', if_true: files( 'xen-stubs.c', 'xen-pvh.c', )) +arm_ss.add(when: 'CONFIG_RT500', if_true: files('rt500.c')) system_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmu-common.c')) system_ss.add(when: 'CONFIG_COLLIE', if_true: files('collie.c'))
hw/arm/svd/meson.build +4 -0
@@ -36,4 +36,8 @@ if get_option('mcux-soc-svd') [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500_rstctl1.h', '-p', 'RSTCTL1', '-t', 'RT500_RSTCTL1', '--fields', 'SYSRSTSTAT: PRSTCTL*:']) + run_target('svd-rt500', command: svd_gen_header + + [ '-i', rt595, '-o', '@SOURCE_ROOT@/include/hw/arm/svd/rt500.h', + '-s', 'RT500', '-p', 'FLEXCOMM0', '-p', 'CLKCTL0', '-p', 'CLKCTL1', + '-p', 'FLEXSPI0', '-p', 'FLEXSPI1', '-p', 'RSTCTL0', '-p', 'RSTCTL1']) endif
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 14/25 hw/arm: add RT595-EVK board
In reply to Octavian PurdilaAdd basic support for the RT595-EVK board, enough to be able to run the NXP's microXpresso SDK hello world example.
--- hw/arm/rt595-evk.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++ hw/arm/Kconfig | 5 ++++ hw/arm/meson.build | 1 + 3 files changed, 70 insertions(+) create mode 100644 hw/arm/rt595-evk.c
hw/arm/rt595-evk.c new file +64 -0
@@ -0,0 +1,64 @@ +/* +* i.MX RT595 EVK +* +* Copyright (c) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "elf.h" +#include "exec/address-spaces.h" +#include "hw/loader.h" +#include "hw/sysbus.h" +#include "hw/boards.h" +#include "qemu/log.h" +#include "hw/arm/armv7m.h" +#include "hw/arm/boot.h" +#include "qapi/error.h" +#include "hw/arm/rt500.h" +#include "hw/qdev-clock.h" +#include "sysemu/reset.h" + +static void rt595_evk_reset (MachineState *ms,ResetType reason) +{ +/* +* CPU reset is not done by default, we need to do it manually when the +* machine is reset. +*/ +cpu_reset (first_cpu); + +qemu_devices_reset (reason); +} + +static void rt595_evk_init (MachineState *ms) +{ +RT500State *s; +Clock *sysclk; + + sysclk =clock_new (OBJECT (ms),"SYSCLK" ); +clock_set_hz (sysclk,200000000 ); + + s =RT500 (object_new (TYPE_RT500 )); +qdev_connect_clock_in (DEVICE (s),"sysclk" , sysclk); +object_property_add_child (OBJECT (ms),"soc" ,OBJECT (s)); +sysbus_realize_and_unref (SYS_BUS_DEVICE (s), &error_fatal); + +if (ms->kernel_filename) { +armv7m_load_kernel (ARM_CPU (first_cpu), ms->kernel_filename,0 ,0 ); + } +} + +static void rt595_evk_machine_init (MachineClass *mc) +{ + mc->desc ="RT595 EVK Machine (ARM Cortex-M33)" ; + mc->init = rt595_evk_init; + mc->reset = rt595_evk_reset; + + mc->ignore_memory_transaction_failures = true; +} + +DEFINE_MACHINE ("rt595-evk" , rt595_evk_machine_init);
hw/arm/Kconfig +5 -0
@@ -636,3 +636,8 @@ config RT500 select RT500_CLKCTL select FLEXSPI select RT500_RSTCTL + +config RT595_EVK + bool + default y + select RT500
hw/arm/meson.build +1 -0
@@ -61,6 +61,7 @@ arm_ss.add(when: 'CONFIG_XEN', if_true: files( 'xen-pvh.c', )) arm_ss.add(when: 'CONFIG_RT500', if_true: files('rt500.c')) +arm_ss.add(when: 'CONFIG_RT595_EVK', if_true: files('rt595-evk.c')) system_ss.add(when: 'CONFIG_ARM_SMMUV3', if_true: files('smmu-common.c')) system_ss.add(when: 'CONFIG_COLLIE', if_true: files('collie.c'))
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 15/25 tests/qtest: add register access macros and functions
In reply to Octavian PurdilaAdd utility macros for accessing register or register bit fields in tests, e.g.:
REG32_WRITE(FLEXCOMM, PSELID, persel); g_assert(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL) == persel);
--- tests/qtest/reg-utils.h | 70 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 tests/qtest/reg-utils.h
tests/qtest/reg-utils.h new file +70 -0
@@ -0,0 +1,70 @@ +/* +* Register access utilities for device tests. +* +* Copyright (C) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#ifndef _REG_UTILS_H +#define _REG_UTILS_H + +#include "libqtest-single.h" +#include "hw/registerfields.h" + +#ifdef DEBUG_REG +#define debug(fmt, args...) fprintf(stderr, fmt, ## args) +#else +#define debug(fmt, args...) +#endif + +#define _REG_OFF (mod, reg) (A_##mod##_##reg) + +#define REG32_READ (mod, reg) \ + ({ \ + uint32_t value; \ + value = readl(mod##_BASE + _REG_OFF(mod, reg)); \ + debug("[%s] -> %08x\n", #reg, value); \ + value; \ + }) + +#define REG32_WRITE (mod, reg, value) \ + do { \ + debug("[%s] <- %08x\n", #reg, value); \ + writel(mod##_BASE + _REG_OFF(mod, reg), value); \ + } while (0) + +#define REG_FIELD_VAL (v, mod, reg, field) \ + FIELD_EX32(v, mod##_##reg, field) \ + +#define REG32_READ_FIELD (mod, reg, field) \ + REG_FIELD_VAL(REG32_READ(mod, reg), mod, reg, field) + +#define REG32_WRITE_FIELD (mod, reg, field, val) \ + do { \ + uint32_t _tmp = REG32_READ(mod, reg); \ + _tmp = FIELD_DP32(_tmp, mod##_##reg, field, val); \ + REG32_WRITE(mod, reg, _tmp); \ + } while (0) + +#define REG32_WRITE_FIELD_NOUPDATE (mod, reg, field, val) \ + do { \ + uint32_t _tmp = FIELD_DP32(0, mod##_##reg, field, val); \ + REG32_WRITE(mod, reg, _tmp); \ + } while (0) + +#define WAIT_REG32_FIELD (ns, mod, reg, field, val) \ + do { \ + clock_step(ns); \ + g_assert_cmpuint(REG32_READ_FIELD(mod, reg, field), ==, val); \ + } while (0) + +#define REG32_READ_FAIL (mod, reg) \ + readl_fail(mod##_BASE + _REG_OFF(mod, reg)) + +#define REG32_WRITE_FAIL (mod, reg, value) \ + writel_fail(mod##_BASE + _REG_OFF(mod, reg), value) + +#endif /* _REG_UTILS_H */
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 16/25 system/qtest: add APIS to check for memory access failures
In reply to Octavian PurdilaAdd read*/write*_fail qtest APIs to check for memory access failures.
--- tests/qtest/libqtest-single.h | 92 +++++++++++++++++++++++++++++++++++ tests/qtest/libqtest.h | 76 +++++++++++++++++++++++++++++ system/qtest.c | 44 ++++++++++------- tests/qtest/libqtest.c | 73 ++++++++++++++++++++++++++- 4 files changed, 265 insertions(+), 20 deletions(-)
tests/qtest/libqtest-single.h +92 -0
@@ -265,6 +265,98 @@ static inline uint64_t readq(uint64_t addr)return qtest_readq (global_qtest, addr); } +/** +* writeb_fail: +* @addr: Guest address to write to. +* @value: Value being written. +* +* Writes an 8-bit value to memory expecting a failure. +*/ +static inline void writeb_fail (uint64_t addr,uint8_t value) +{ +qtest_writeb_fail (global_qtest, addr, value); +} + +/** +* writew_fail: +* @addr: Guest address to write to. +* @value: Value being written. +* +* Writes a 16-bit value to memory expecting a failure. +*/ +static inline void writew_fail (uint64_t addr,uint16_t value) +{ +qtest_writew_fail (global_qtest, addr, value); +} + +/** +* writel_fail: +* @addr: Guest address to write to. +* @value: Value being written. +* +* Writes a 32-bit value to memory expecting a failure. +*/ +static inline void writel_fail (uint64_t addr,uint32_t value) +{ +qtest_writel_fail (global_qtest, addr, value); +} + +/** +* writeq_fail: +* @addr: Guest address to write to. +* @value: Value being written. +* +* Writes a 64-bit value to memory expecting a failure. +*/ +static inline void writeq_fail (uint64_t addr,uint64_t value) +{ +qtest_writeq_fail (global_qtest, addr, value); +} + +/** +* readb_fail: +* @addr: Guest address to read from. +* +* Reads an 8-bit value from memory expecting a failure. +*/ +static inline void readb_fail (uint64_t addr) +{ +qtest_readb_fail (global_qtest, addr); +} + +/** +* readw_fail: +* @addr: Guest address to read from. +* +* Reads a 16-bit value from memory expecting a failure. +*/ +static inline void readw_fail (uint64_t addr) +{ +qtest_readw_fail (global_qtest, addr); +} + +/** +* readl_fail: +* @addr: Guest address to read from. +* +* Reads a 32-bit value from memory expecting a failure. +*/ +static inline void readl_fail (uint64_t addr) +{ +qtest_readl_fail (global_qtest, addr); +} + +/** +* readq_fail: +* @addr: Guest address to read from. +* +* Reads a 64-bit value from memory expecting a failure. +*/ +static inline void readq_fail (uint64_t addr) +{ +qtest_readq_fail (global_qtest, addr); +} +/** * memread: * @addr: Guest address to read from.
tests/qtest/libqtest.h +76 -0
82 lines not on this page · raw message
system/qtest.c +26 -18
78 lines not on this page · raw message
tests/qtest/libqtest.c +71 -2
121 lines not on this page · raw message
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 17/25 tests/qtest: add flexcomm tests
In reply to Octavian PurdilaAdd flexcomm function selection unit tests.
--- tests/qtest/flexcomm-test.c | 82 +++++++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 2 files changed, 83 insertions(+) create mode 100644 tests/qtest/flexcomm-test.c
tests/qtest/flexcomm-test.c new file +82 -0
@@ -0,0 +1,82 @@ +/* +* Copyright (C) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/main-loop.h" +#include "exec/memory.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" + +#include "hw/misc/flexcomm.h" +#include "hw/arm/svd/flexcomm.h" +#include "hw/arm/svd/rt500.h" +#include "reg-utils.h" + +#define FLEXCOMM_BASE RT500_FLEXCOMM0_BASE + +static void select_test (gconstpointer data) +{ +static const unsigned persel[] = { +FLEXCOMM_PERSEL_USART , +FLEXCOMM_PERSEL_SPI , +FLEXCOMM_PERSEL_I2C , + }; + +g_assert (REG32_READ_FIELD (FLEXCOMM ,PSELID ,PERSEL ) ==0 ); + +/* no register access until a function is selected */ +readl_fail (FLEXCOMM_BASE ); +writel_fail (FLEXCOMM_BASE ,0 ); + +for (int i =0 ; i <ARRAY_SIZE (persel); i++) { + +REG32_WRITE (FLEXCOMM ,PSELID , persel[i]); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL), ==, + persel[i]); + +/* test that we can access function registers */ +writel (FLEXCOMM_BASE ,0xabcd ); +readl (FLEXCOMM_BASE ); + } + +/* try to select something invalid */ +REG32_WRITE (FLEXCOMM ,PSELID ,7 ); +/* check for no function selected */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL), ==, 0); + +/* now select and lock USART */ +REG32_WRITE (FLEXCOMM ,PSELID , +FIELD_DP32 (FLEXCOMM_PERSEL_USART ,FLEXCOMM_PSELID ,LOCK ,1 )); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL), ==, +FLEXCOMM_PERSEL_USART ); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, LOCK), ==, 1); + +/* try to change the selection to spi */ +REG32_WRITE (FLEXCOMM ,PSELID ,FLEXCOMM_PERSEL_SPI ); +/* it should still be locked USART */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, PERSEL), ==, +FLEXCOMM_PERSEL_USART ); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM, PSELID, LOCK), ==, 1); +} + +int main (int argc,char **argv) +{ +int ret; + +g_test_init (&argc, &argv,NULL ); + +qtest_add_data_func ("/flexcomm/select" ,NULL , select_test); +qtest_start ("-M rt595-evk" ); + ret =g_test_run (); +qtest_end (); + +return ret; +}
tests/qtest/meson.build +1 -0
@@ -233,6 +233,7 @@ qtests_arm = \ (config_all_devices.has_key('CONFIG_FSI_APB2OPB_ASPEED') ? ['aspeed_fsi-test'] : []) + \ (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \ + (config_all_devices.has_key('CONFIG_FLEXCOMM')? ['flexcomm-test'] : []) + \ ['arm-cpu-features', 'boot-serial-test']
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 18/25 tests/qtest: add flexcomm usart tests
In reply to Octavian PurdilaAdd flexcomm usart polling and irq unit tests.
--- tests/qtest/flexcomm-usart-test.c | 316 ++++++++++++++++++++++++++++++ tests/qtest/meson.build | 3 +- 2 files changed, 318 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/flexcomm-usart-test.c
tests/qtest/flexcomm-usart-test.c new file +316 -0
@@ -0,0 +1,316 @@ +/* +* Copyright (C) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include <glib/gstdio.h> + +#include "io/channel-socket.h" +#include "qemu/config-file.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "sysemu/sysemu.h" +#include "qemu/main-loop.h" +#include "qemu/option.h" +#include "exec/memory.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" + +#include "hw/misc/flexcomm.h" +#include "hw/arm/svd/flexcomm_usart.h" +#include "hw/arm/svd/rt500.h" +#include "reg-utils.h" + +#define FLEXCOMM_BASE RT500_FLEXCOMM0_BASE +#define FLEXCOMM_USART_BASE RT500_FLEXCOMM0_BASE +#define DEVICE_NAME "/machine/soc/flexcomm0" + +struct TestState { +QTestState *qtest; +QIOChannel *ioc; +}; + +static void polling_test (gconstpointer user_data) +{ +struct TestState *t = (struct TestState *)user_data; +uint32_t tmp; +char byte; +int fifo_size; +QDict *resp; + + resp =qmp ("{\"execute\": \"system_reset\"}" ); +qdict_unref (resp); + +/* select and lock USART */ + tmp =FIELD_DP32 (FLEXCOMM_PERSEL_USART ,FLEXCOMM_PSELID ,LOCK ,1 ); +REG32_WRITE (FLEXCOMM ,PSELID , tmp); + + fifo_size =REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSIZE ,FIFOSIZE ); + +/* enable USART */ +REG32_WRITE_FIELD (FLEXCOMM_USART ,CFG ,ENABLE ,1 ); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, CFG, ENABLE), ==, 1); + +/* enable TX and RX FIFO */ +REG32_WRITE_FIELD (FLEXCOMM_USART ,FIFOCFG ,ENABLETX ,1 ); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOCFG ,ENABLETX ), + ==, 1); +REG32_WRITE_FIELD (FLEXCOMM_USART ,FIFOCFG ,ENABLERX ,1 ); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOCFG ,ENABLERX ), + ==, 1); + +/* test writes and fifo counters wrap */ +for (int i =0 ; i < fifo_size /2 ; i++) { +/* check fifostat */ +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,RXFULL ), + ==, 0); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,RXNOTEMPTY ), + ==, 0); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,TXNOTFULL ), + ==, 1); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,TXEMPTY ), + ==, 1); + +REG32_WRITE (FLEXCOMM_USART ,FIFOWR ,'a' + i); +qio_channel_read (t->ioc, &byte,1 , &error_abort); + g_assert_cmpuint(byte, ==, 'a' + i); + } + +/* test reads and fifo level */ + +for (int i =0 ; i < fifo_size /2 ; i++) { + byte ='A' + i; +g_assert_cmpuint (qio_channel_write (t->ioc, &byte,1 , &error_abort), + ==, 1); + } + +/* wait for the RXLVL to update */ +WAIT_REG32_FIELD (1000 ,FLEXCOMM_USART ,FIFOSTAT ,RXLVL , + fifo_size /2 ); + +/* check fifo stat */ +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,RXFULL ), + ==, 0); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,RXNOTEMPTY ), + ==, 1); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,TXNOTFULL ), + ==, 1); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,TXEMPTY ), + ==, 1); + +/* send until FIFO is full */ +for (int i = fifo_size /2 ; i < fifo_size; i++) { + byte ='A' + i; +g_assert_cmpuint (qio_channel_write (t->ioc, &byte,1 , &error_abort), + ==, 1); + } + +/* wait for the RXLVL to update */ +WAIT_REG32_FIELD (1000 ,FLEXCOMM_USART ,FIFOSTAT ,RXLVL , fifo_size); + +/* check fifo stat */ +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,RXFULL ), + ==, 1); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,RXNOTEMPTY ), + ==, 1); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,TXNOTFULL ), + ==, 1); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,TXEMPTY ), + ==, 1); + +/* check read no pop */ +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFORDNOPOP ,RXDATA ), + ==, 'A'); + +/* now read from the fifo */ +for (int i =0 ; i < fifo_size; i++) { +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFORD ,RXDATA ), + ==, 'A' + i); + } + +/* check fifostat */ + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_USART, FIFOSTAT, RXFULL), ==, 0); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,RXNOTEMPTY ), + ==, 0); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,TXNOTFULL ), + ==, 1); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,TXEMPTY ), + ==, 1); +} + +static void irq_test (gconstpointer user_data) +{ +struct TestState *t = (struct TestState *)user_data; +char buf[256 ] = {0 , }; +uint32_t tmp; +QDict *resp; + + resp =qmp ("{\"execute\": \"system_reset\"}" ); +qdict_unref (resp); + +qtest_irq_intercept_out_named (t->qtest,DEVICE_NAME , +SYSBUS_DEVICE_GPIO_IRQ ); + +/* select and lock FLEXCOMM_USART */ + tmp =FIELD_DP32 (FLEXCOMM_PERSEL_USART ,FLEXCOMM_PSELID ,LOCK ,1 ); +REG32_WRITE (FLEXCOMM ,PSELID , tmp); + +/* +* set RX IRQ/DMA trigger level to 4 bytes - value 3 in FIFOTRIG +* +* 0000 - Trigger when the RX FIFO has received 1 entry (is no longer empty) +* 0001 - Trigger when the RX FIFO has received 2 entries +* 1111 - Trigger when the RX FIFO has received 16 entries (has become full) +*/ +REG32_WRITE_FIELD (FLEXCOMM_USART ,FIFOTRIG ,RXLVL ,3 ); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOTRIG ,RXLVL ), + ==, 3); + +/* enable RX trigger for IRQ/DMA */ +REG32_WRITE_FIELD (FLEXCOMM_USART ,FIFOTRIG ,RXLVLENA ,1 ); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOTRIG ,RXLVLENA ), + ==, 1); + +/* enable RXLVL interrupt */ +REG32_WRITE_FIELD (FLEXCOMM_USART ,FIFOINTENSET ,RXLVL ,1 ); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOINTENSET ,RXLVL ), + ==, 1); + +/* enable FLEXCOMM_USART */ +REG32_WRITE_FIELD (FLEXCOMM_USART ,CFG ,ENABLE ,1 ); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,CFG ,ENABLE ), + ==, 1); + +/* enable TX and RX FIFO */ +REG32_WRITE_FIELD (FLEXCOMM_USART ,FIFOCFG ,ENABLETX ,1 ); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOCFG ,ENABLETX ), + ==, 1); +REG32_WRITE_FIELD (FLEXCOMM_USART ,FIFOCFG ,ENABLERX ,1 ); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOCFG ,ENABLERX ), + ==, 1); + +/* check interrupt status */ +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOINTSTAT ,RXLVL ), + ==, 0); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOINTSTAT ,TXLVL ), + ==, 0); +g_assert_false (get_irq (0 )); + +/* enable TX trigger for IRQ/DMA */ +REG32_WRITE_FIELD (FLEXCOMM_USART ,FIFOTRIG ,TXLVLENA ,1 ); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOTRIG ,TXLVLENA ), + ==, 1); + +/* enable irq for TX */ +REG32_WRITE_FIELD (FLEXCOMM_USART ,FIFOINTENSET ,TXLVL ,1 ); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOINTENSET ,TXLVL ), + ==, 1); + +/* check TX irq */ +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOINTSTAT ,TXLVL ), + ==, 1); +g_assert_true (get_irq (0 )); + +/* disable irq for TX */ +REG32_WRITE_FIELD (FLEXCOMM_USART ,FIFOTRIG ,TXLVLENA ,0 ); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOTRIG ,TXLVLENA ), + ==, 0); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOINTSTAT ,TXLVL ), + ==, 0); +g_assert_false (get_irq (0 )); + +/* send 3 bytes */ +g_assert_cmpuint (qio_channel_write (t->ioc, buf,3 , &error_abort), + ==, 3); + +/* check that we have 3 bytes in the fifo */ +WAIT_REG32_FIELD (1000 ,FLEXCOMM_USART ,FIFOSTAT ,RXLVL ,3 ); + +/* and no interrupt has been triggered yet */ +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOINTSTAT ,RXLVL ), + ==, 0); +g_assert_false (get_irq (0 )); + +/* push it over the edge */ + g_assert_cmpuint(qio_channel_write(t->ioc, buf, 1, &error_abort), ==, 1); + +/* check that we have 4 bytes in the fifo */ +WAIT_REG32_FIELD (1000 ,FLEXCOMM_USART ,FIFOSTAT ,RXLVL ,4 ); + +/* and the interrupt has been triggered */ +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOINTSTAT ,RXLVL ), + ==, 1); +g_assert_true (get_irq (0 )); + +/* read one byte from the fifo */ +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFORD ,RXDATA ), + ==, 0); + +/* we should have 3 bytes in the FIFO */ +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOSTAT ,RXLVL ), + ==, 3); + +/* and no interrupts active */ +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_USART ,FIFOINTSTAT ,RXLVL ), + ==, 0); +g_assert_false (get_irq (0 )); +} + +static void close_ioc (void *ioc) +{ +qio_channel_close (ioc,NULL ); +} + +int main (int argc,char **argv) +{ +int ret; +struct TestState test; +char *tmp_path =g_dir_make_tmp ("qemu-flexcomm-usart-test.XXXXXX" ,NULL ); +SocketAddress addr = { + .type =SOCKET_ADDRESS_TYPE_UNIX , + .u.q_unix.path =g_build_filename (tmp_path,"sock" ,NULL ), + }; +char *args; +QIOChannelSocket *lioc; + +module_call_init (MODULE_INIT_QOM ); +g_test_init (&argc, &argv,NULL ); + + lioc =qio_channel_socket_new (); +qio_channel_socket_listen_sync (lioc, &addr,1 , &error_abort); + +qtest_add_data_func ("/flexcomm-usart/polling" , &test, polling_test); +qtest_add_data_func ("/flexcomm-usart/irq" , &test, irq_test); + + args =g_strdup_printf ("-M rt595-evk " +"-chardev socket,id=flexcomm0-usart,path=%s" , + addr.u.q_unix.path); + test.qtest =qtest_start (args); + +qio_channel_wait (QIO_CHANNEL (lioc),G_IO_IN ); + test.ioc =QIO_CHANNEL (qio_channel_socket_accept (lioc, &error_abort)); +g_assert (test.ioc); +qtest_add_abrt_handler (close_ioc, test.ioc); + + ret =g_test_run (); + +qtest_end (); + +qtest_remove_abrt_handler (test.ioc); +g_unlink (addr.u.q_unix.path); +g_free (addr.u.q_unix.path); +g_rmdir (tmp_path); +g_free (tmp_path); +g_free (args); +object_unref (OBJECT (test.ioc)); +object_unref (OBJECT (lioc)); + +return ret; +}
tests/qtest/meson.build +2 -1
@@ -233,7 +233,7 @@ qtests_arm = \ (config_all_devices.has_key('CONFIG_FSI_APB2OPB_ASPEED') ? ['aspeed_fsi-test'] : []) + \ (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \ - (config_all_devices.has_key('CONFIG_FLEXCOMM')? ['flexcomm-test'] : []) + \ + (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flexcomm-usart-test'] : []) + \ ['arm-cpu-features', 'boot-serial-test']
@@ -350,6 +350,7 @@ qtests = { 'virtio-net-failover': files('migration-helpers.c'), 'vmgenid-test': files('boot-sector.c', 'acpi-utils.c'), 'netdev-socket': files('netdev-socket.c', '../unit/socket-helpers.c'), + 'flexcomm-usart-test': [io], } if vnc.found()
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 19/25 hw/misc: add i2c-tester
In reply to Octavian PurdilaAdd a simple i2c peripheral to be used for testing I2C device models. The peripheral has a fixed number of registers that can be read and written.
--- include/hw/misc/i2c_tester.h | 43 ++++++++++++++ hw/misc/i2c_tester.c | 109 +++++++++++++++++++++++++++++++++++ hw/misc/Kconfig | 5 ++ hw/misc/meson.build | 2 + 4 files changed, 159 insertions(+) create mode 100644 include/hw/misc/i2c_tester.h create mode 100644 hw/misc/i2c_tester.c
include/hw/misc/i2c_tester.h new file +43 -0
@@ -0,0 +1,43 @@ +/* +* Simple I2C peripheral for testing I2C device models. +* +* At the moment of introducing this not all of the functionality can be tested +* with an existing QEMU peripheral device, notably error paths such as when a +* peripheral device responds with an I2C_NACK during a transaction. +* +* It also provides a place where new future functionality can be added to help +* with more kinds of tests rather than trying to hack it in a real device where +* it might not even be possible. +* +* The peripheral allows reading and writing to a fixed number of registers. +* The first transmitted byte in a transaction sets the index register. Note +* that the index register is not auto-incremented on neither reads nor writes. +* +* Copyright (c) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef HW_I2C_TESTER_H +#define HW_I2C_TESTER_H + +#include "qemu/osdep.h" +#include "hw/i2c/i2c.h" +#include "hw/irq.h" + +#define I2C_TESTER_NUM_REGS 0x31 + +#define TYPE_I2C_TESTER "i2c-tester" +#define I2C_TESTER (obj) OBJECT_CHECK(I2cTesterState, (obj), TYPE_I2C_TESTER) + +typedef struct { +I2CSlave i2c; +bool set_reg_idx; +uint8_t reg_idx; +uint8_t regs[I2C_TESTER_NUM_REGS ]; +}I2cTesterState ; + +#endif /* HW_I2C_TESTER_H */
hw/misc/i2c_tester.c new file +109 -0
109 lines not on this page · raw message
hw/misc/Kconfig +5 -0
@@ -213,6 +213,11 @@ config IOSB config XLNX_VERSAL_TRNG bool +config I2C_TESTER + bool + default y if TEST_DEVICES + depends on I2C + config FLEXCOMM bool select I2C
hw/misc/meson.build +2 -0
@@ -152,6 +152,8 @@ system_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa_ec.c')) # HPPA devices system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) +system_ss.add(when: 'CONFIG_I2C_TESTER', if_true: files('i2c_tester.c')) + system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm.c')) system_ss.add(when: 'CONFIG_RT500_CLKCTL', if_true: files('rt500_clkctl0.c', 'rt500_clkctl1.c')) system_ss.add(when: 'CONFIG_RT500_RSTCTL', if_true: files('rt500_rstctl.c'))
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 20/25 tests/qtest: add tests for flexcomm i2c
In reply to Octavian PurdilaAdd master mode tests for flexcomm i2c.
--- tests/qtest/flexcomm-i2c-test.c | 170 ++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 2 files changed, 171 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/flexcomm-i2c-test.c
tests/qtest/flexcomm-i2c-test.c new file +170 -0
@@ -0,0 +1,170 @@ +/* +* Copyright (c) 2024 Google LLC. +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" + +#include "qemu/config-file.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "sysemu/sysemu.h" +#include "qemu/main-loop.h" +#include "qemu/option.h" +#include "exec/memory.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-core.h" + +#include "hw/misc/flexcomm.h" +#include "hw/arm/svd/flexcomm_i2c.h" +#include "hw/arm/svd/rt500.h" +#include "hw/misc/i2c_tester.h" +#include "reg-utils.h" + +#define PERIPH_ADDR (0x50) +#define INVALID_ADDR (0x10) + +#define REG_ADDR 11 +#define REG_VALUE 0xAA + +#define FLEXCOMM_BASE RT500_FLEXCOMM0_BASE +#define FLEXCOMM_I2C_BASE RT500_FLEXCOMM0_BASE +#define DEVICE_NAME "/machine/soc/flexcomm0" + +struct TestState { +QTestState *qtest; +}; + +static void master_test (gconstpointer user_data) +{ +struct TestState *t = (struct TestState *)user_data; +uint32_t tmp; + +qtest_irq_intercept_out_named (t->qtest,DEVICE_NAME , +SYSBUS_DEVICE_GPIO_IRQ ); + +/* Select and lock I2C */ + tmp =FLEXCOMM_PERSEL_I2C ; +FIELD_DP32 (tmp,FLEXCOMM_PSELID ,LOCK ,1 ); +REG32_WRITE (FLEXCOMM ,PSELID , tmp); + +/* Enable master mode */ +REG32_WRITE_FIELD (FLEXCOMM_I2C ,CFG ,MSTEN ,1 ); +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,CFG ,MSTEN ) ==1 ); + +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTPENDING ) ==1 ); +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTSTATE ) == +MSTSTATE_IDLE ); + +/* Enable interrupts */ +REG32_WRITE_FIELD (FLEXCOMM_I2C ,INTENSET ,MSTPENDINGEN ,1 ); +g_assert_true (get_irq (0 )); + +/* start for invalid address */ +REG32_WRITE (FLEXCOMM_I2C ,MSTDAT ,INVALID_ADDR ); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTSTART ,1 ); +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTSTATE ) == +MSTSTATE_NAKADR ); +g_assert_true (get_irq (0 )); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTSTOP ,1 ); + +/* write past the last register */ +REG32_WRITE_FIELD (FLEXCOMM_I2C ,MSTDAT ,DATA ,PERIPH_ADDR ); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTSTART ,1 ); +g_assert_true (get_irq (0 )); +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTSTATE ) == +MSTSTATE_TXRDY ); +REG32_WRITE_FIELD (FLEXCOMM_I2C ,MSTDAT ,DATA ,I2C_TESTER_NUM_REGS +10 ); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTCONTINUE ,1 ); +g_assert_true (get_irq (0 )); +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTSTATE ) == +MSTSTATE_TXRDY ); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTCONTINUE ,1 ); +g_assert_true (get_irq (0 )); +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTSTATE ) == +MSTSTATE_NAKDAT ); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTSTOP ,1 ); + +/* write value to register */ +REG32_WRITE_FIELD (FLEXCOMM_I2C ,MSTDAT ,DATA ,PERIPH_ADDR ); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTSTART ,1 ); +g_assert_true (get_irq (0 )); +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTSTATE ) == +MSTSTATE_TXRDY ); +REG32_WRITE_FIELD (FLEXCOMM_I2C ,MSTDAT ,DATA ,REG_ADDR ); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTCONTINUE ,1 ); +g_assert_true (get_irq (0 )); +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTSTATE ) == +MSTSTATE_TXRDY ); +REG32_WRITE_FIELD (FLEXCOMM_I2C ,MSTDAT ,DATA ,REG_VALUE ); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTCONTINUE ,1 ); +g_assert_true (get_irq (0 )); +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTSTATE ) == +MSTSTATE_TXRDY ); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTSTOP ,1 ); +g_assert_true (get_irq (0 )); +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTSTATE ) == +MSTSTATE_IDLE ); + +/* read value back from register */ +REG32_WRITE_FIELD (FLEXCOMM_I2C ,MSTDAT ,DATA ,PERIPH_ADDR ); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTSTART ,1 ); +g_assert_true (get_irq (0 )); +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTSTATE ) == +MSTSTATE_TXRDY ); +REG32_WRITE_FIELD (FLEXCOMM_I2C ,MSTDAT ,DATA ,REG_ADDR ); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTCONTINUE ,1 ); +g_assert_true (get_irq (0 )); +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTSTATE ) == +MSTSTATE_TXRDY ); +REG32_WRITE_FIELD (FLEXCOMM_I2C ,MSTDAT ,DATA , (PERIPH_ADDR +1 )); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTSTART ,1 ); +g_assert_true (get_irq (0 )); +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTSTATE ) == +MSTSTATE_RXRDY ); + g_assert_cmpuint(REG32_READ_FIELD(FLEXCOMM_I2C, MSTDAT, DATA), ==, +REG_VALUE ); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTSTOP ,1 ); + +/* +* Check that the master ended the transaction (i.e. i2c_end_transfer was +* called). If the master does not properly end the transaction this would +* be seen as a restart and it would not be NACKed. +*/ +REG32_WRITE_FIELD (FLEXCOMM_I2C ,MSTDAT ,DATA ,INVALID_ADDR ); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTSTART ,1 ); + +g_assert (REG32_READ_FIELD (FLEXCOMM_I2C ,STAT ,MSTSTATE ) == +MSTSTATE_NAKADR ); +g_assert_true (get_irq (0 )); +REG32_WRITE_FIELD_NOUPDATE (FLEXCOMM_I2C ,MSTCTL ,MSTSTOP ,1 ); + +/* Disable interrupts */ +REG32_WRITE_FIELD (FLEXCOMM_I2C ,INTENCLR ,MSTPENDINGCLR ,1 ); +g_assert_false (get_irq (0 )); +} + +int main (int argc,char **argv) +{ +int ret; +struct TestState test; + +module_call_init (MODULE_INIT_QOM ); +g_test_init (&argc, &argv,NULL ); + +qtest_add_data_func ("/flexcomm-i2c/master" , &test, master_test); + + test.qtest =qtest_start ("-M rt595-evk " +"-device i2c-tester,address=0x50,bus=/flexcomm0-i2c" ); + ret =g_test_run (); +qtest_end (); + +return ret; +}
tests/qtest/meson.build +1 -1
@@ -233,7 +233,7 @@ qtests_arm = \ (config_all_devices.has_key('CONFIG_FSI_APB2OPB_ASPEED') ? ['aspeed_fsi-test'] : []) + \ (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \ - (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flexcomm-usart-test'] : []) + \ + (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flexcomm-usart-test', 'flexcomm-i2c-test'] : []) + \ ['arm-cpu-features', 'boot-serial-test']
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 21/25 hw/ssi: allow NULL realize callbacks for peripherals
In reply to Octavian Purdila--- hw/ssi/ssi.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
hw/ssi/ssi.c +3 -1
@@ -105,7 +105,9 @@ static void ssi_peripheral_realize(DeviceState *dev, Error **errp) } s->spc = ssc; - ssc->realize (s, errp); +if (ssc->realize) { + ssc->realize (s, errp); + } }static Property ssi_peripheral_properties[] = {
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 22/25 hw/misc: add spi-tester
In reply to Octavian PurdilaAdd a simple SPI peripheral that echoes back received data. Useful for testing SPI controllers.
--- include/hw/misc/spi_tester.h | 32 +++++++++++++++++ hw/misc/spi_tester.c | 67 ++++++++++++++++++++++++++++++++++++ hw/misc/Kconfig | 5 +++ hw/misc/meson.build | 1 + 4 files changed, 105 insertions(+) create mode 100644 include/hw/misc/spi_tester.h create mode 100644 hw/misc/spi_tester.c
include/hw/misc/spi_tester.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Simple SPI peripheral device used for SPI controller testing. +* +* Copyright (c) 2024 Google LLC. +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#ifndef HW_SPI_TESTER_H +#define HW_SPI_TESTER_H + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/bswap.h" +#include "hw/irq.h" +#include "hw/ssi/ssi.h" +#include "qemu/timer.h" +#include "hw/qdev-properties.h" + +#define TYPE_SPI_TESTER "spi-tester" +#define SPI_TESTER (obj) OBJECT_CHECK(SpiTesterState, (obj), TYPE_SPI_TESTER) + +typedef struct { +SSIPeripheral ssidev; +bool cs; +}SpiTesterState ; + +#endif /* HW_SPI_TESTER_H */
hw/misc/spi_tester.c new file +67 -0
67 lines not on this page · raw message
hw/misc/Kconfig +5 -0
@@ -218,6 +218,11 @@ config I2C_TESTER default y if TEST_DEVICES depends on I2C +config SPI_TESTER + bool + default y if TEST_DEVICES + depends on SSI + config FLEXCOMM bool select I2C
hw/misc/meson.build +1 -0
@@ -153,6 +153,7 @@ system_ss.add(when: 'CONFIG_SBSA_REF', if_true: files('sbsa_ec.c')) system_ss.add(when: 'CONFIG_LASI', if_true: files('lasi.c')) system_ss.add(when: 'CONFIG_I2C_TESTER', if_true: files('i2c_tester.c')) +system_ss.add(when: 'CONFIG_SPI_TESTER', if_true: files('spi_tester.c')) system_ss.add(when: 'CONFIG_FLEXCOMM', if_true: files('flexcomm.c')) system_ss.add(when: 'CONFIG_RT500_CLKCTL', if_true: files('rt500_clkctl0.c', 'rt500_clkctl1.c'))
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 23/25 tests/qtest: add tests for flexcomm spi
In reply to Octavian PurdilaFrom: Sebastian Ene <[email protected]>
Add master and loopback tests for flexcomm spi.
--- tests/qtest/flexcomm-spi-test.c | 145 ++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 2 +- 2 files changed, 146 insertions(+), 1 deletion(-) create mode 100644 tests/qtest/flexcomm-spi-test.c
tests/qtest/flexcomm-spi-test.c new file +145 -0
@@ -0,0 +1,145 @@ +/* +* Copyright (c) 2024 Google LLC. +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" + +#include "qemu/config-file.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qapi/error.h" +#include "qemu/sockets.h" +#include "sysemu/sysemu.h" +#include "qemu/main-loop.h" +#include "qemu/option.h" +#include "exec/memory.h" +#include "hw/irq.h" +#include "hw/qdev-properties.h" +#include "hw/qdev-core.h" + +#include "hw/misc/flexcomm.h" +#include "hw/arm/svd/flexcomm_spi.h" +#include "hw/arm/svd/rt500.h" +#include "reg-utils.h" + +/* The number of words sent on the SPI in loopback mode. */ +#define SEQ_LOOPBACK_MODE (8) + +/* This value is used to set the cycle counter for the spi tester */ +#define SPI_TESTER_CONFIG (0x10) + +#define FLEXCOMM_BASE RT500_FLEXCOMM0_BASE +#define FLEXCOMM_SPI_BASE RT500_FLEXCOMM0_BASE +#define DEVICE_NAME "/machine/soc/flexcomm0" + +static void configure_spi (bool master,bool is_loopback_mode) +{ +uint32_t tmp; + +/* Select and lock SPI */ + tmp =FLEXCOMM_PERSEL_SPI ; +FIELD_DP32 (tmp,FLEXCOMM_PSELID ,LOCK ,1 ); +REG32_WRITE (FLEXCOMM ,PSELID , tmp); + +/* Disable the FIFO */ +REG32_WRITE_FIELD (FLEXCOMM_SPI ,CFG ,ENABLE ,0 ); +REG32_WRITE_FIELD (FLEXCOMM_SPI ,FIFOCFG ,ENABLETX ,0 ); +REG32_WRITE_FIELD (FLEXCOMM_SPI ,FIFOCFG ,ENABLERX ,0 ); + +if (is_loopback_mode) { +/* Set up SPI interface - loop mode, master mode */ +REG32_WRITE_FIELD (FLEXCOMM_SPI ,CFG ,LOOP ,1 ); +g_assert (REG32_READ_FIELD (FLEXCOMM_SPI ,CFG ,LOOP ) ==1 ); + } + +if (master) { +REG32_WRITE_FIELD (FLEXCOMM_SPI ,CFG ,MASTER ,1 ); +g_assert (REG32_READ_FIELD (FLEXCOMM_SPI ,CFG ,MASTER ) ==1 ); + }else { +REG32_WRITE_FIELD (FLEXCOMM_SPI ,CFG ,MASTER ,0 ); +g_assert (REG32_READ_FIELD (FLEXCOMM_SPI ,CFG ,MASTER ) ==0 ); + } + +/* Enable the FIFO */ +REG32_WRITE_FIELD (FLEXCOMM_SPI ,FIFOCFG ,ENABLETX ,1 ); +REG32_WRITE_FIELD (FLEXCOMM_SPI ,FIFOCFG ,ENABLERX ,1 ); + +/* Enable the SPI */ +REG32_WRITE_FIELD (FLEXCOMM_SPI ,CFG ,ENABLE ,1 ); +g_assert (REG32_READ_FIELD (FLEXCOMM_SPI ,CFG ,ENABLE ) ==1 ); +} + +/* The SPI controller running in master mode can run in loopback mode for */ +/* internal testing. Transmit and receive lines are connected together. */ +static void loopback_test (gconstpointer user_data) +{ +configure_spi (true, true); + +/* Write a sequence */ +for (int i =0 ; i <SEQ_LOOPBACK_MODE ; i++) { +REG32_WRITE (FLEXCOMM_SPI ,FIFOWR , i); + } + +/* Read the sequence back */ +for (int i =0 ; i <SEQ_LOOPBACK_MODE ; i++) { +g_assert (REG32_READ_FIELD (FLEXCOMM_SPI ,FIFORD ,RXDATA ) == i); + } +} + +static void master_test (gconstpointer user_data) +{ +uint32_t tmp; + +configure_spi (true, false); + +REG32_WRITE_FIELD (FLEXCOMM_SPI ,CFG ,LSBF ,1 ); + +/* single 16bit word transfer */ + + tmp =FIELD_DP32 (0x1122 ,FLEXCOMM_SPI_FIFOWR ,EOT ,1 ); + tmp =FIELD_DP32 (tmp,FLEXCOMM_SPI_FIFOWR ,TXSSEL0_N ,1 ); + tmp =FIELD_DP32 (tmp,FLEXCOMM_SPI_FIFOWR ,LEN ,0xF ); +REG32_WRITE (FLEXCOMM_SPI ,FIFOWR , tmp); +g_assert (REG32_READ_FIELD (FLEXCOMM_SPI ,FIFOSTAT ,RXNOTEMPTY ) ==1 ); +g_assert_cmpuint (REG32_READ_FIELD (FLEXCOMM_SPI ,FIFORD ,RXDATA ), + ==, 0x1122); +g_assert (REG32_READ_FIELD (FLEXCOMM_SPI ,FIFOSTAT ,RXNOTEMPTY ) ==0 ); + +/* multi word 8 bits transfer */ + + tmp =FIELD_DP32 (0x11 ,FLEXCOMM_SPI_FIFOWR ,TXSSEL0_N ,1 ); + tmp =FIELD_DP32 (tmp,FLEXCOMM_SPI_FIFOWR ,LEN ,0x7 ); +REG32_WRITE (FLEXCOMM_SPI ,FIFOWR , tmp); + tmp =0x22 ; +FIELD_DP32 (tmp,FLEXCOMM_SPI_FIFOWR ,EOT ,1 ); +FIELD_DP32 (tmp,FLEXCOMM_SPI_FIFOWR ,TXSSEL0_N ,1 ); +FIELD_DP32 (tmp,FLEXCOMM_SPI_FIFOWR ,LEN ,0x7 ); +REG32_WRITE (FLEXCOMM_SPI ,FIFOWR , tmp); +g_assert (REG32_READ_FIELD (FLEXCOMM_SPI ,FIFOSTAT ,RXNOTEMPTY ) ==1 ); +g_assert (REG32_READ_FIELD (FLEXCOMM_SPI ,FIFORD ,RXDATA ) ==0x11 ); +g_assert (REG32_READ_FIELD (FLEXCOMM_SPI ,FIFOSTAT ,RXNOTEMPTY ) ==1 ); +g_assert (REG32_READ_FIELD (FLEXCOMM_SPI ,FIFORD ,RXDATA ) ==0x22 ); +g_assert (REG32_READ_FIELD (FLEXCOMM_SPI ,FIFOSTAT ,RXNOTEMPTY ) ==0 ); +} + +int main (int argc,char **argv) +{ +int ret; + +module_call_init (MODULE_INIT_QOM ); +g_test_init (&argc, &argv,NULL ); + +qtest_add_data_func ("/flexcomm-spi/loopack" ,NULL , loopback_test); +qtest_add_data_func ("/flexcomm-spi/master" ,NULL , master_test); + +qtest_start ("-M rt595-evk -device spi-tester,bus=/flexcomm0-spi" ); + ret =g_test_run (); +qtest_end (); + +return ret; +}
tests/qtest/meson.build +1 -1
@@ -233,7 +233,7 @@ qtests_arm = \ (config_all_devices.has_key('CONFIG_FSI_APB2OPB_ASPEED') ? ['aspeed_fsi-test'] : []) + \ (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \ - (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flexcomm-usart-test', 'flexcomm-i2c-test'] : []) + \ + (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flexcomm-usart-test', 'flexcomm-i2c-test', 'flexcomm-spi-test'] : []) + \ ['arm-cpu-features', 'boot-serial-test']
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 24/25 systems/qtest: add device clock APIs
In reply to Octavian PurdilaAdd qtest APIs to check the device clock frequency.
--- include/hw/qdev-clock.h | 10 +++++++ tests/qtest/libqtest-single.h | 24 +++++++++++++++++ tests/qtest/libqtest.h | 22 +++++++++++++++ hw/core/qdev-clock.c | 2 +- system/qtest.c | 51 +++++++++++++++++++++++++++++++++++ tests/qtest/libqtest.c | 29 ++++++++++++++++++++ 6 files changed, 137 insertions(+), 1 deletion(-)
include/hw/qdev-clock.h +10 -0
@@ -15,6 +15,7 @@#define QDEV_CLOCK_H #include "hw/clock.h" +#include "hw/qdev-core.h" /** * qdev_init_clock_in:
@@ -161,4 +162,13 @@ typedef struct ClockPortInitElem ClockPortInitArray[];*/ void qdev_init_clocks (DeviceState *dev,const ClockPortInitArray clocks); +/** +* qdev_get_clocklist: +* @dev: the device to find clock for +* @name: clock name +* +* Returns: a named clock list entry or NULL if the clock was not found +*/ +NamedClockList *qdev_get_clocklist (DeviceState *dev,const char *name); +#endif /* QDEV_CLOCK_H */
tests/qtest/libqtest-single.h +24 -0
@@ -408,4 +408,28 @@ static inline int64_t clock_step(int64_t step) return qtest_clock_step(global_qtest, step); } +/** +* qtest_qdev_clock_in_get_hz: +* @path: QOM path of a device. +* @name: Clock name. +* +* Returns: device clock frequency in HZ +*/ +static inline uint64_t dev_clock_in_get_hz (const char *path,const char *name) +{ +return qtest_dev_clock_in_get_hz (global_qtest, path, name); +} + +/** +* qtest_qdev_clock_out_get_hz: +* @path: QOM path of a device. +* @name: Clock name. +* +* Returns: device clock frequency in HZ +*/ +static inline uint64_t dev_clock_out_get_hz (const char *path,const char *name) +{ +return qtest_dev_clock_out_get_hz (global_qtest, path, name); +} +#endif
tests/qtest/libqtest.h +22 -0
@@ -1169,4 +1169,26 @@ bool have_qemu_img(void);*/ bool mkimg (const char *file,const char *fmt,unsigned size_mb); +/** +* qtest_qdev_clock_in_get_hz: +* @s: #QTestState instance to operate on. +* @path: QOM path of a device. +* @name: Clock name. +* +* Returns: device clock frequency in HZ +*/ +uint64_t qtest_dev_clock_in_get_hz (QTestState *s,const char *path, +const char *name); + +/** +* qtest_qdev_clock_out_get_hz: +* @s: #QTestState instance to operate on. +* @path: QOM path of a device. +* @name: Clock name. +* +* Returns: device clock frequency in HZ +*/ +uint64_t qtest_dev_clock_out_get_hz (QTestState *s,const char *path, +const char *name); +#endif
hw/core/qdev-clock.c +1 -1
@@ -144,7 +144,7 @@ void qdev_init_clocks(DeviceState *dev, const ClockPortInitArray clocks) } } -static NamedClockList *qdev_get_clocklist (DeviceState *dev,const char *name) +NamedClockList *qdev_get_clocklist (DeviceState *dev,const char *name) {NamedClockList *ncl;
system/qtest.c +51 -0
69 lines not on this page · raw message
tests/qtest/libqtest.c +29 -0
@@ -2065,3 +2065,32 @@ bool mkimg(const char *file, const char *fmt, unsigned size_mb)return ret && !err; } + +static uint64_t qtest_dev_clock_get_hz (QTestState *s,const char *path, +const char *name,bool out) +{ +gchar **args; +int ret; +uint64_t value; + +qtest_sendf (s,"qdev_clock_%s_get_hz %s %s\n" , out ?"out" :"in" , + path, name); + args =qtest_rsp_args (s,2 ); + ret =qemu_strtou64 (args[1 ],NULL ,0 , &value); +g_assert (!ret); +g_strfreev (args); + +return value; +} + +uint64_t qtest_dev_clock_out_get_hz (QTestState *s,const char *path, +const char *name) +{ +return qtest_dev_clock_get_hz (s, path, name, true); +} + +uint64_t qtest_dev_clock_in_get_hz (QTestState *s,const char *path, +const char *name) +{ +return qtest_dev_clock_get_hz (s, path, name, false); +}
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog
PATCH v2 25/25 tests/qtest: add tests for RT500's clock controller
In reply to Octavian PurdilaAdd test to exercise clocks set and clear, system PLL initialization, audio PLL initialization, systick and ostimer clock source selection.
--- tests/qtest/rt500-clkctl-test.c | 195 ++++++++++++++++++++++++++++++++ tests/qtest/meson.build | 1 + 2 files changed, 196 insertions(+) create mode 100644 tests/qtest/rt500-clkctl-test.c
tests/qtest/rt500-clkctl-test.c new file +195 -0
@@ -0,0 +1,195 @@ +/* +* Copyright (c) 2024 Google LLC +* +* SPDX-License-Identifier: GPL-2.0-or-later +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ + +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "qemu/module.h" +#include "qemu/main-loop.h" +#include "exec/memory.h" +#include "hw/clock.h" +#include "hw/irq.h" +#include "hw/qdev-clock.h" +#include "hw/qdev-properties.h" + +#include "hw/misc/rt500_clkctl0.h" +#include "hw/misc/rt500_clkctl1.h" +#include "hw/misc/rt500_clk_freqs.h" +#include "hw/arm/svd/rt500.h" +#include "reg-utils.h" + +#define SYSCLK_HZ 200000000 +#define CLKCTL0_NAME "/machine/soc/clkctl0" +#define CLKCTL1_NAME "/machine/soc/clkctl1" + +static void pscctl_test (gconstpointer user_data) +{ +/* rom controller clock should be enabled at reset */ +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,PSCCTL0 ,ROM_CTRLR_CLK ) ==1 ); + +/* DSP clk is disabled at reset */ +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,PSCCTL0 ,DSP_CLK ) ==0 ); + +/* check PSCTL_SET functionality */ +REG32_WRITE_FIELD_NOUPDATE (RT500_CLKCTL0 ,PSCCTL0_SET ,DSP_CLK ,1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,PSCCTL0 ,DSP_CLK ) ==1 ); + +/* check PSCTL_CLR functionality */ +REG32_WRITE_FIELD_NOUPDATE (RT500_CLKCTL0 ,PSCCTL0_CLR ,DSP_CLK ,1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,PSCCTL0 ,DSP_CLK ) ==0 ); + +/* FLEXIO clk is disabled at reset */ +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,PSCCTL0 , FlexIO) ==0 ); + +/* check PSCTL_SET functionality */ +REG32_WRITE_FIELD_NOUPDATE (RT500_CLKCTL1 ,PSCCTL0_SET , FlexIO,1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,PSCCTL0 , FlexIO) ==1 ); + +/* check PSCTL_CLR functionality */ +REG32_WRITE_FIELD_NOUPDATE (RT500_CLKCTL1 ,PSCCTL0_CLR , FlexIO,1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,PSCCTL0 , FlexIO) ==0 ); +} + +static void audiopll0pfd_test (gconstpointer user_data) +{ +/* audio plls are gated at boot */ +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD3_CLKGATE ) ==1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD2_CLKGATE ) ==1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD1_CLKGATE ) ==1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD0_CLKGATE ) ==1 ); + +/* ,,, and clocks are not ready */ +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD3_CLKRDY ) ==0 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD2_CLKRDY ) ==0 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD1_CLKRDY ) ==0 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD0_CLKRDY ) ==0 ); + +/* ungate all plls and check that clocks are ready */ +REG32_WRITE_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD3_CLKGATE ,0 ); +REG32_WRITE_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD2_CLKGATE ,0 ); +REG32_WRITE_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD1_CLKGATE ,0 ); +REG32_WRITE_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD0_CLKGATE ,0 ); + +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD3_CLKRDY ) ==1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD2_CLKRDY ) ==1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD1_CLKRDY ) ==1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL1 ,AUDIOPLL0PFD ,PFD0_CLKRDY ) ==1 ); +} + +static void syspll0pfd_test (gconstpointer user_data) +{ +/* system plls are gated at boot */ +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD3_CLKGATE ) ==1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD2_CLKGATE ) ==1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD1_CLKGATE ) ==1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD0_CLKGATE ) ==1 ); + +/* ,,, and clocks are not ready */ +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD3_CLKRDY ) ==0 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD2_CLKRDY ) ==0 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD1_CLKRDY ) ==0 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD0_CLKRDY ) ==0 ); + +/* ungate all plls and check that clocks are ready */ +REG32_WRITE_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD3_CLKGATE ,0 ); +REG32_WRITE_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD2_CLKGATE ,0 ); +REG32_WRITE_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD1_CLKGATE ,0 ); +REG32_WRITE_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD0_CLKGATE ,0 ); + +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD3_CLKRDY ) ==1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD2_CLKRDY ) ==1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD1_CLKRDY ) ==1 ); +g_assert (REG32_READ_FIELD (RT500_CLKCTL0 ,SYSPLL0PFD ,PFD0_CLKRDY ) ==1 ); +} + +static void systick_clk_test (gconstpointer user_data) +{ +/* systick is not running at reset */ + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL0_NAME, "systick_clk"), ==, 0); + +/* select divout no divisor */ +REG32_WRITE_FIELD (RT500_CLKCTL0 ,SYSTICKFCLKSEL ,SEL , +SYSTICKFCLKSEL_DIVOUT ); +g_assert_cmpuint (dev_clock_out_get_hz (CLKCTL0_NAME ,"systick_clk" ), + ==, SYSCLK_HZ); + +/* change divisor to 2 */ +REG32_WRITE_FIELD (RT500_CLKCTL0 ,SYSTICKFCLKDIV ,DIV ,1 ); +g_assert_cmpuint (dev_clock_out_get_hz (CLKCTL0_NAME ,"systick_clk" ), + ==, SYSCLK_HZ / 2); + +/* select lpsoc */ +REG32_WRITE_FIELD (RT500_CLKCTL0 ,SYSTICKFCLKSEL ,SEL , +SYSTICKFCLKSEL_LPOSC ); +g_assert_cmpuint (dev_clock_out_get_hz (CLKCTL0_NAME ,"systick_clk" ), + ==, LPOSC_CLK_HZ); + +/* select lpsoc */ +REG32_WRITE_FIELD (RT500_CLKCTL0 ,SYSTICKFCLKSEL ,SEL , +SYSTICKFCLKSEL_32KHZRTC ); +g_assert_cmpuint (dev_clock_out_get_hz (CLKCTL0_NAME ,"systick_clk" ), + ==, RTC32KHZ_CLK_HZ); + +/* disable clock */ +REG32_WRITE_FIELD (RT500_CLKCTL0 ,SYSTICKFCLKSEL ,SEL , +SYSTICKFCLKSEL_NONE ); +g_assert_cmpuint (dev_clock_out_get_hz (CLKCTL0_NAME ,"systick_clk" ), + ==, 0); +} + +static void ostimer_clk_test (gconstpointer user_data) +{ +/* systick is not running at reset */ + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL1_NAME, "ostimer_clk"), ==, 0); + +/* select lpsoc */ +REG32_WRITE_FIELD (RT500_CLKCTL1 ,OSEVENTTFCLKSEL ,SEL , +OSEVENTTFCLKSEL_LPOSC ); + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL1_NAME, "ostimer_clk"), ==, +LPOSC_CLK_HZ ); + +/* select 32khz RTC */ +REG32_WRITE_FIELD (RT500_CLKCTL1 ,OSEVENTTFCLKSEL ,SEL , +OSEVENTTFCLKSEL_32KHZRTC ); + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL1_NAME, "ostimer_clk"), ==, +RTC32KHZ_CLK_HZ ); + +/* select hclk */ +REG32_WRITE_FIELD (RT500_CLKCTL1 ,OSEVENTTFCLKSEL ,SEL , +OSEVENTTFCLKSEL_HCLK ); + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL1_NAME, "ostimer_clk"), ==, +SYSCLK_HZ ); + +/* disable clock */ +REG32_WRITE_FIELD (RT500_CLKCTL1 ,OSEVENTTFCLKSEL ,SEL , +OSEVENTTFCLKSEL_NONE ); + g_assert_cmpuint(dev_clock_out_get_hz(CLKCTL1_NAME, "ostimer_clk"), ==, 0); +} + +int main (int argc,char **argv) +{ +int ret; + +g_test_init (&argc, &argv,NULL ); + +qtest_add_data_func ("/rt500-clkctl/pscctl-test" ,NULL , pscctl_test); +qtest_add_data_func ("/rt500-clkctl/syspll0pfd-test" ,NULL , + syspll0pfd_test); +qtest_add_data_func ("/rt500-clkctl/audiopll0pfd-test" ,NULL , + audiopll0pfd_test); +g_test_add_data_func ("/rt500-clkctl/systick-test" ,NULL , + systick_clk_test); +g_test_add_data_func ("/rt500-clkctl/ostimer-clk-test" ,NULL , + ostimer_clk_test); + +qtest_start ("-M rt595-evk" ); + ret =g_test_run (); +qtest_end (); + +return ret; +}
tests/qtest/meson.build +1 -0
@@ -234,6 +234,7 @@ qtests_arm = \ (config_all_devices.has_key('CONFIG_STM32L4X5_SOC') and config_all_devices.has_key('CONFIG_DM163')? ['dm163-test'] : []) + \ (config_all_devices.has_key('CONFIG_FLEXCOMM') ? ['flexcomm-test', 'flexcomm-usart-test', 'flexcomm-i2c-test', 'flexcomm-spi-test'] : []) + \ + (config_all_devices.has_key('CONFIG_RT500_CLKCTL') ? ['rt500-clkctl-test'] : []) + \ ['arm-cpu-features', 'boot-serial-test']
Signature · 1 line
2.47.0.rc0.187.ge670bccf7e-goog