From: Chris Laplante <chris@laplante.io>
To: qemu-devel@nongnu.org
Cc: Joel Stanley <joel@jms.id.au>,
Peter Maydell <peter.maydell@linaro.org>,
qemu-arm@nongnu.org, Chris Laplante <chris@laplante.io>
Subject: [PATCH 1/6] hw/gpio/nrf51: implement DETECT signal
Date: Fri, 14 Jul 2023 23:27:15 +0000 [thread overview]
Message-ID: <20230714232659.76434-2-chris@laplante.io> (raw)
In-Reply-To: <20230714232659.76434-1-chris@laplante.io>
Implement nRF51 DETECT signal in the GPIO peripheral.
The reference manual makes mention of a per-pin DETECT signal, but these
are not exposed to the user. See https://devzone.nordicsemi.com/f/nordic-q-a/39858/gpio-per-pin-detect-signal-available
for more information. Currently, I don't see a reason to model these.
Signed-off-by: Chris Laplante <chris@laplante.io>
---
hw/arm/nrf51_soc.c | 1 +
hw/gpio/nrf51_gpio.c | 14 +++++++++++++-
include/hw/gpio/nrf51_gpio.h | 1 +
3 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/hw/arm/nrf51_soc.c b/hw/arm/nrf51_soc.c
index 34da0d62f0..7ae54e18be 100644
--- a/hw/arm/nrf51_soc.c
+++ b/hw/arm/nrf51_soc.c
@@ -150,6 +150,7 @@ static void nrf51_soc_realize(DeviceState *dev_soc, Error **errp)
/* Pass all GPIOs to the SOC layer so they are available to the board */
qdev_pass_gpios(DEVICE(&s->gpio), dev_soc, NULL);
+ qdev_pass_gpios(DEVICE(&s->gpio), dev_soc, "detect");
/* TIMER */
for (i = 0; i < NRF51_NUM_TIMERS; i++) {
diff --git a/hw/gpio/nrf51_gpio.c b/hw/gpio/nrf51_gpio.c
index b47fddf4ed..08396c69a4 100644
--- a/hw/gpio/nrf51_gpio.c
+++ b/hw/gpio/nrf51_gpio.c
@@ -78,6 +78,7 @@ static void update_state(NRF51GPIOState *s)
int pull;
size_t i;
bool connected_out, dir, connected_in, out, in, input;
+ bool assert_detect = false;
for (i = 0; i < NRF51_GPIO_PINS; i++) {
pull = pull_value(s->cnf[i]);
@@ -99,7 +100,15 @@ static void update_state(NRF51GPIOState *s)
qemu_log_mask(LOG_GUEST_ERROR,
"GPIO pin %zu short circuited\n", i);
}
- if (!connected_in) {
+ if (connected_in) {
+ uint32_t detect_config = extract32(s->cnf[i], 16, 2);
+ if ((detect_config == 2) && (in == 1)) {
+ assert_detect = true;
+ }
+ if ((detect_config == 3) && (in == 0)) {
+ assert_detect = true;
+ }
+ } else {
/*
* Floating input: the output stimulates IN if connected,
* otherwise pull-up/pull-down resistors put a value on both
@@ -116,6 +125,8 @@ static void update_state(NRF51GPIOState *s)
}
update_output_irq(s, i, connected_out, out);
}
+
+ qemu_set_irq(s->detect, assert_detect);
}
/*
@@ -291,6 +302,7 @@ static void nrf51_gpio_init(Object *obj)
qdev_init_gpio_in(DEVICE(s), nrf51_gpio_set, NRF51_GPIO_PINS);
qdev_init_gpio_out(DEVICE(s), s->output, NRF51_GPIO_PINS);
+ qdev_init_gpio_out_named(DEVICE(s), &s->detect, "detect", 1);
}
static void nrf51_gpio_class_init(ObjectClass *klass, void *data)
diff --git a/include/hw/gpio/nrf51_gpio.h b/include/hw/gpio/nrf51_gpio.h
index 8f9c2f86da..fcfa2bac17 100644
--- a/include/hw/gpio/nrf51_gpio.h
+++ b/include/hw/gpio/nrf51_gpio.h
@@ -64,6 +64,7 @@ struct NRF51GPIOState {
uint32_t old_out_connected;
qemu_irq output[NRF51_GPIO_PINS];
+ qemu_irq detect;
};
--
2.39.2
next prev parent reply other threads:[~2023-07-14 23:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-14 23:27 [PATCH 0/6] Add nRF51 DETECT signal with test Chris Laplante
2023-07-14 23:27 ` Chris Laplante [this message]
2023-07-24 16:10 ` [PATCH 1/6] hw/gpio/nrf51: implement DETECT signal Peter Maydell
2023-07-14 23:27 ` [PATCH 2/6] qtest: implement named interception of out-GPIO Chris Laplante
2023-07-14 23:27 ` [PATCH 3/6] qtest: bail from irq_intercept_in if name is specified Chris Laplante
2023-07-24 16:17 ` Peter Maydell
2023-07-14 23:27 ` [PATCH 4/6] qtest: factor out qtest_install_gpio_out_intercepts Chris Laplante
2023-07-24 16:18 ` Peter Maydell
2023-07-14 23:27 ` [PATCH 5/6] qtest: irq_intercept_[out/in]: return FAIL if no intercepts are installed Chris Laplante
2023-07-24 16:19 ` Peter Maydell
2023-07-25 4:03 ` Chris Laplante
2023-07-14 23:27 ` [PATCH 6/6] qtest: microbit-test: add tests for nRF51 DETECT Chris Laplante
2023-07-24 16:24 ` Peter Maydell
2023-07-24 16:27 ` [PATCH 0/6] Add nRF51 DETECT signal with test Peter Maydell
2023-07-25 3:24 ` Chris Laplante
2023-07-25 9:23 ` Peter Maydell
2023-07-26 2:58 ` Chris Laplante
2023-07-27 22:51 ` Chris Laplante
2023-07-28 9:32 ` Peter Maydell
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230714232659.76434-2-chris@laplante.io \
--to=chris@laplante.io \
--cc=joel@jms.id.au \
--cc=peter.maydell@linaro.org \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).