Added 32 bits property for ASPEED GPIO with updated qtests. This change gives ASPEED GPIO similar behavior as Nuvoton.
PATCH 2/2 tests/qtest: Add qtest for for ASPEED GPIO gpio-set property
In reply to Jingbo WuFrom: Felix Wu <[email protected]>
- Added qtests to test gpio-set property for ASPEED.
- Added function to get uint in qdict.
--- include/qapi/qmp/qdict.h | 1 + qobject/qdict.c | 13 ++++ tests/qtest/aspeed_gpio-test.c | 105 ++++++++++++++++++++++++++++++--- 3 files changed, 110 insertions(+), 9 deletions(-)
include/qapi/qmp/qdict.h +1 -0
@@ -57,6 +57,7 @@ void qdict_put_str(QDict *qdict, const char *key, const char *value);double qdict_get_double (const QDict *qdict,const char *key);int64_t qdict_get_int (const QDict *qdict,const char *key); +uint64_t qdict_get_uint (const QDict *qdict,const char *key);bool qdict_get_bool (const QDict *qdict,const char *key);QList *qdict_get_qlist (const QDict *qdict,const char *key);QDict *qdict_get_qdict (const QDict *qdict,const char *key);
qobject/qdict.c +13 -0
@@ -209,6 +209,19 @@ int64_t qdict_get_int(const QDict *qdict, const char *key)return qnum_get_int (qobject_to (QNum,qdict_get (qdict, key))); } +/** +* qdict_get_uint(): Get an unsigned integer mapped by 'key' +* +* This function assumes that 'key' exists and it stores a +* QNum representable as uint. +* +* Return unsigned integer mapped by 'key'. +*/ +uint64_t qdict_get_uint (const QDict *qdict,const char *key) +{ +return qnum_get_uint (qobject_to (QNum,qdict_get (qdict, key))); +} +/** * qdict_get_bool(): Get a bool mapped by 'key' *
tests/qtest/aspeed_gpio-test.c +96 -9
124 lines not on this page · raw message
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
PATCH 1/2 hw/gpio: Add property for ASPEED GPIO in 32 bits basis
In reply to Jingbo WuFrom: Felix Wu <[email protected]>
Added 32 bits property for ASPEED GPIO. Previously it can only be access in bitwise manner.
This change gives ASPEED similar behavior as Nuvoton.
--- hw/gpio/aspeed_gpio.c | 56 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+)
hw/gpio/aspeed_gpio.c +56 -0
@@ -951,6 +951,56 @@ static void aspeed_gpio_set_pin(Object *obj, Visitor *v, const char *name,aspeed_gpio_set_pin_level (s, set_idx, pin, level); } +static void aspeed_gpio_set_set (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +uint32_t set_val =0 ; +AspeedGPIOState *s =ASPEED_GPIO (obj); +AspeedGPIOClass *agc =ASPEED_GPIO_GET_CLASS (s); +int set_idx =0 ; + +if (!visit_type_uint32 (v, name, &set_val, errp)) { +return ; + } + +if (sscanf (name,"gpio-set[%d]" , &set_idx) !=1 ) { +error_setg (errp,"%s: error reading %s" , __func__, name); +return ; + } + +if (set_idx >= agc->nr_gpio_sets || set_idx <0 ) { +error_setg (errp,"%s: invalid set_idx %s" , __func__, name); +return ; + } + +aspeed_gpio_update (s, &s->sets[set_idx], set_val, + ~s->sets[set_idx].direction); +} + +static void aspeed_gpio_get_set (Object *obj,Visitor *v, +const char *name,void *opaque, +Error **errp) +{ +uint32_t set_val =0 ; +AspeedGPIOState *s =ASPEED_GPIO (obj); +AspeedGPIOClass *agc =ASPEED_GPIO_GET_CLASS (s); +int set_idx =0 ; + +if (sscanf (name,"gpio-set[%d]" , &set_idx) !=1 ) { +error_setg (errp,"%s: error reading %s" , __func__, name); +return ; + } + +if (set_idx >= agc->nr_gpio_sets || set_idx <0 ) { +error_setg (errp,"%s: invalid set_idx %s" , __func__, name); +return ; + } + + set_val = s->sets[set_idx].data_value; +visit_type_uint32 (v, name, &set_val, errp); +} +/****************** Setup functions ******************/ static const GPIOSetProperties ast2400_set_props[ASPEED_GPIO_MAX_NR_SETS ] = { [0 ] = {0xffffffff ,0xffffffff , {"A" ,"B" ,"C" ,"D" } },
@@ -1061,6 +1111,12 @@ static void aspeed_gpio_init(Object *obj)g_free (name); } } + +for (int i =0 ; i < agc->nr_gpio_sets; i++) { +char *name =g_strdup_printf ("gpio-set[%d]" , i); +object_property_add (obj, name,"uint32" , aspeed_gpio_get_set, + aspeed_gpio_set_set,NULL ,NULL ); + } }static const VMStateDescription vmstate_gpio_regs = {
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
cover Added 32 bits property for ASPEED GPIO with updated qtests. This change gives ASPEED GPIO similar behavior as Nuvoton.
From: Felix Wu <[email protected]>
Felix Wu (2):
hw/gpio: Add property for ASPEED GPIO in 32 bits basis tests/qtest: Add qtest for for ASPEED GPIO gpio-set property
hw/gpio/aspeed_gpio.c | 56 ++++++++++++++++++ include/qapi/qmp/qdict.h | 1 + qobject/qdict.c | 13 ++++ tests/qtest/aspeed_gpio-test.c | 105 ++++++++++++++++++++++++++++++--- 4 files changed, 166 insertions(+), 9 deletions(-)
Signature · 1 line
2.41.0.rc0.172.g3f132b7071-goog
Quoted 1 line · Jingbo Wu
From: Felix Wu <[email protected]>
Hello Felix,
Thanks for the extension. It could be useful in some situations but it seems also dangerous to set all lines controlled by a register at once. The same comment applies to Nuvoton [1].
C.
Quoted 11 lines
Felix Wu (2):
hw/gpio: Add property for ASPEED GPIO in 32 bits basis tests/qtest: Add qtest for for ASPEED GPIO gpio-set propertyhw/gpio/aspeed_gpio.c | 56 ++++++++++++++++++ include/qapi/qmp/qdict.h | 1 + qobject/qdict.c | 13 ++++ tests/qtest/aspeed_gpio-test.c | 105 ++++++++++++++++++++++++++++++--- 4 files changed, 166 insertions(+), 9 deletions(-)