The PCA/PCAL series I2C GPIO expanders have a polarity inversion
register on every supported part, but the driver has it fully
commented out ("unused, omitted") in the register tables, cache maps
and reg_type enum, so it was never wired up.
Add a polarity-inversion devicetree property (32b, default 0, covering
up to 4 ports / p3.7..p0.0) and write it to the polarity inversion
register during reset, alongside the existing output_port/configuration
reset writes. The value is converted with sys_cpu_to_le32() before the
write, matching how every other multi-byte register write in this
driver already handles byteorder (e.g. the 2b_interrupt_edge write),
since the register spans up to 4 bytes depending on part_cfg->port_no.
Enabling the register also makes it cacheable like output_port and
configuration, so the cache-map arrays for all three register table
families (pca953x, pcal953x, pcal65xx) have every subsequent cache
slot index shifted by one, and the base cache-size count used by
GPIO_PCA_GET_CACHE_SIZE_BY_PART_NO_NO_INT goes from 2 to 3. The
per-part register address tables only needed the already-documented
address uncommented, since those are fixed hardware addresses.
Verified by hand that the cache-size formula still matches the
highest cache-map index for both the smallest (pca953x, no latch/pull)
and largest (pcal65xx, latch+pull+int_extend, up to 4 ports) part
families after the shift.
Signed-off-by: Jens Korinth <jnsk@tuta.io>
The init function rejected any ngpios above 4 with -EINVAL, so a wider
GPIO block failed to initialise. The Sapphire IP offers widths of 1, 2,
4, 8, 16 or 32.
Restrict ngpios to those values in the binding, drop BIT_MASK() from
the latch read-modify-write as BIT_MASK(32) shifts by 32, and remove the
empty init function.
Not tested on silicon.
Assisted-by: Claude:claude-sonnet-5-5
Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
port_get_raw read the OUTPUT register at offset 0x04. That register is
the output latch and returns what was last written, so an external
signal on an input pin was never seen.
Read the INPUT register at offset 0x00 instead, masked to the port pin
mask.
Not tested on hardware.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Arkadiusz Grzelka <devitwise@gmail.com>
Implement port_get_direction for the it82xx2 GPIO drivers.
Report input and output pins from the GPIO control registers while
excluding disconnected pins.
test:
west build -p -b it82xx2_evb tests/drivers/gpio/gpio_get_direction/
Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
The Kinetis PORT clock gate is opened by the pinctrl driver. The gpio
nodes have no clocks property, so gpio_mcux never enables the gate but
writes PORTx->PCR when it configures a pin. Once the UART driver is
disabled nothing else selects PINCTRL and the gate stays closed. On
frdm_k64f an application that only uses a button and an LED does not
work then.
Select PINCTRL like the other mcux GPIO drivers do.
Assisted-by: Claude:claude-sonnet-5.5
Signed-off-by: Johann Fischer <johann.fischer@nordicsemi.no>
Add an I2C emulator for the ITE IT8300 GPIO expander. Model register reads
and writes, output data mirroring, write-one-to-clear interrupt status,
global interrupt status, and the active-low ALERT signal.
Expose helpers to reset the emulated device, inject GPIO input changes,
and access registers so tests can validate driver behavior.
Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
Add GPIO driver and devicetree bindings for the ITE IT8300 GPIO
expander.
The IT8300 provides 34 GPIO pins divided into five GPIO groups. Each
group is represented by an ite,it8300-gpio child node, while the parent
ite,it8300 node manages the shared I2C connection and optional active-low
ALERT# interrupt.
The device only reports that a pin has changed and does not provide
per-pin edge polarity information. Cache the previous input state and
filter the latched changes in the alert work handler to provide rising,
falling, and both-edge interrupt support.
The driver was tested with the IT8300 connected to it51xxx_evb and
passed the following Zephyr GPIO test suites:
- drivers/gpio/basic_api
- drivers/gpio/get_direction
- drivers/gpio/gpio_hogs
Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
gpio_ite_isr() and gpio_ite_pin_interrupt_configure() previously
submitted data->interrupt_worker to k_sys_work_q unconditionally on
every GPIO interrupt and configuration call, even when only
edge-triggered interrupts were enabled on the port. Under high-rate
edge interrupts, this floods k_sys_work_q with hundreds of no-op work
submissions per second.
Only submit data->interrupt_worker when the pin is configured for
level-triggered interrupts, clear level_isr_low and level_isr_high
when disabling a pin's interrupt with GPIO_INT_MODE_DISABLED, and skip
pins with disabled IRQs in gpio_ite_interrupt_worker().
TEST=./twister -s drivers.gpio.ite_it8xxx2_v2
TEST=Boot hylia and verify k_sys_work_q is not flooded by edge IRQs
Signed-off-by: Rob Barnes <robbarnes@google.com>
Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
Filter GPIO callbacks against the programmed edge direction so spurious
level samples do not fire handlers. On Apollo3, track output-enabled
pins and mask port writes / combine read status accordingly. Enable the
IRQ only after interrupt setup succeeds.
Signed-off-by: Richard Wheatley <richard.wheatley@ambiq.com>
The open-drain implementation keeps the output latch low and controls
the output enable bit. A logical high must disable the output and a
logical low must enable it.
Correct initial output state and masked, set and clear writes to match
those semantics. Push-pull output behavior is unchanged.
The OpenSiFli downstream driver already implements this polarity;
apply the equivalent fix to the mainline register-access implementation.
Link: 679c245711
Assisted-by: Codex:GPT-6
Signed-off-by: Shawn Yang <y810004@gmail.com>
Clearing pending bits after invoking callbacks loses an edge that
arrives during a callback on the same pin. Acknowledge the captured
pending bits first, then dispatch callbacks for enabled pins.
Limit the acknowledged snapshot to this port so that another port
sharing the bank keeps its pending events.
Assisted-by: Codex:GPT-6
Signed-off-by: Shawn Yang <y810004@gmail.com>
gpio_emul_output_get_masked() validates its mask and then never applies
it: the value it stores is every output pin on the port, while the
doxygen says it holds the value of the pins asked for.
Nothing in tree reads a wrong value today, because the only caller is
gpio_emul_output_get(), which applies BIT(pin) to the result itself. A
test reading several lines back through the masked getter does see the
other outputs, which is how this turned up.
The regression test drives one pin high and asks for a different one.
It fails on the unfixed driver, reporting 0x1 outside the mask, and
passes with the fix. gpio_basic_api and the gpio_kbd_matrix input test,
which uses the single-pin wrapper, both still pass.
Signed-off-by: Hsiu-Chi Tsai <hctsai@linux.com>
Remove the static inline function gpio_sifive_plic_to_pin() from the
SiFive GPIO driver, as it is no longer called anywhere in the codebase.
The pin calculation is now handled directly within the interrupt
handler, making this legacy function dead code.
Signed-off-by: Chingbin Li <liqb365@163.com>
The implementation of WKUP event dispatch as GPIO interrupts had a small
flaw: any pin that gets configured as wake-up pin would implcitly have
interrupt dispatch enabled for it, even if the pin was never explicitly
configured as interrupt source. This would most likely have no nefarious
effect since it wouldn't make sense to register GPIO callbacks for a pin
which is known to not be used for interrupts, but it was a possibility
nevertheless. A more realistic case where this causes issues is that if
interrupts were really enabled for the pin, but disabled later on, we
would still dispatch a WKUP event for that pin even though interrupts
were explicitly disabled.
Separate enablement of a pin as wake-up line source from enablement of
interrupt dispatching, and modify the GPIO driver such that it enables
the dispatch from gpio_pin_interrupt_configure() at the same time that
the regular interrupt is also enabled (ditto for disable).
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
The MFXSTM32L152 dependency is the availability of the i2c so
set its init priority to I2C_INIT_PRIORITY instead of having
an hardcoded value as before.
Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
Update the Infineon GPIO driver to use the standard
CONFIG_GPIO_INIT_PRIORITY instead of the generic
CONFIG_KERNEL_INIT_PRIORITY_DEVICE. This ensures the GPIO driver
initializes before peripherals that depend on it.
Signed-off-by: Vignesh Pandian <vignesh@aerlync.com>
Add a GPIO driver for the NXP i.MX GPIO controller used on RT266x, with
the new compatible nxp,imx-gpio-v2.
The driver (gpio_mcux_gpio.c) handles:
- Combined IOMUXC PIO pad register, where mux selector and pad
attributes (pull enable/select, input buffer, open-drain) share one
read-modify-write register. The driver sets the attribute bits and
delegates the mux write to pinctrl_configure_pins().
- Optional LPCG clock gate at init. Instances without a gate (always-
on power domains) simply omit the clocks property.
- Per-pin TrustZone access control via PCNS, granting non-secure access
before configuring each pin.
- Dual-channel interrupt routing: GICLR/GICHR direct each pin's
interrupt to one of the two NVIC lines, selected by irq-output-select.
The binding nxp,imx-gpio-v2 follows the same property set as other NXP
IOMUXC-based GPIO bindings: pinmux phandle list, optional clocks, and
irq-output-select.
Signed-off-by: Lucien Zhao <lucien.zhao@nxp.com>
Now that wake-up pins can be used for something other than poweroff,
drop the wake-up configuration path's dependency on CONFIG_POWEROFF.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
The function exported by this module was branded as `gpioport` and its
signature was in `stm32_gpio_shared.h`, even though the function can
work with all GPIO port controllers disabled since it only operates
on PWRC registers.
Rebrand the function as `pwrc` instead of `gpioport` and move it to the
`stm32_common.h` header instead, for lack of a better location...
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Create a dedicated Kconfig option which controls compilation of the
STM32 GPIO port manager module, and select this option explicitly in
the Kconfig for the STM32 GPIO and PINCTRL drivers which require this
module.
This replaces the previous approach where the SoC common CMakeLists
would add the GPIO port manage module to the build automatically if
either of the STM32 GPIO or PINCTRL module was enabled; an explicit
select at Kconfig level makes the dependency more visible.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
This property is now defined on the parent MFD device. Having
it in the GPIO driver means that other MFD children may inadvertently
be reset.
Signed-off-by: James Bennion-Pedley <James.Bennion-Pedley@thinksmartbox.com>
Add SAM0_GPIO_DRIVE_STRONG, a SAM0 specific GPIO devicetree flag that
sets PORT PINCFG.DRVSTR on pins configured as outputs.
gpio_sam0_config() rebuilds PINCFG from zero on every call, so a drive
strength selected through pinctrl is cleared as soon as the pin is
configured through the GPIO API. Carrying it on the gpios specifier
selects the stronger driver where the pin is declared, alongside the
existing SAM0_GPIO_DEBOUNCE.
On SAM D5x/E5x this raises the rated output current from 2 mA to 8 mA
at VDD >= 3.0 V (DS60001507, Table 54-13).
Assisted-by: Claude:claude-opus-5
Signed-off-by: Thomas Chiantia <thomas.chiantia@proton.me>
The STM32WL3 series uses the same implementation as STM32WB0 series and
thus supports level-triggered interrupts. Enable the capability at
driver level by loosening the allowlist.
Signed-off-by: Mathieu Choplain <mathieu.choplain-ext@st.com>
Add a GPIO driver for the two 16-pin GPIO controllers on the C-DAC
THEJAS32 SoC. Pin data is accessed through address masking, where bits
[17:2] of the address select the pins a data access operates on, so
individual pins are set and cleared without read-modify-write. The
direction register sits above the data window at offset 0x40000.
The controllers have no pull resistors and pin interrupts are not yet
wired to the SoC interrupt controller, so both are reported as
unsupported.
Signed-off-by: Anuj Deshpande <anuj@makerville.io>
This commit enables the new clock managers by switching the device
tree to use the new bindings. It also moves some initialization code
from the old clock manager to soc_early_init_hook() since some clocks
configuration needs to be done before the clock drivers are initialized.
Signed-off-by: Martin Hoff <martin.hoff@silabs.com>
Enclose the GPIO_INT_MODE_EDGE case logic within a block to fix a
compilation failure caused by case label being directly followed
by a variable declaration.
Signed-off-by: Vivian Pais <v-pais@ti.com>
mcux_rgpio_port_set_masked_raw() and the pin direction update in
mcux_rgpio_configure() both perform a read-modify-write of a
port-wide register (PDOR, PDDR) without any protection. If a second
thread or an ISR touches the same port concurrently, the write can
land between the read and the write-back, and its effect is silently
lost: bits outside the caller's own mask/pin can be reverted to a
stale value.
Fix mcux_rgpio_port_set_masked_raw() by using the RGPIO peripheral's
dedicated set/clear registers (PSOR/PCOR) instead of a
read-modify-write on PDOR. These registers only ever affect bits
explicitly set in their argument, so the operation is atomic without
needing to disable interrupts.
PDDR has no equivalent set/clear alias, so protect the pin direction
update in mcux_rgpio_configure() with a per-device k_spinlock.
Convert the irq_lock()/irq_unlock() pair already guarding interrupt
configuration in mcux_rgpio_pin_interrupt_configure() to the same
spinlock, since irq_lock() only masks interrupts on the local core
and does not prevent a second core from touching the same register
concurrently on SMP platforms.
Signed-off-by: John Moore <john.moore@amulethotkey.com>
pin_interrupt_configure() cleared the configured pin's stale edge with
WRITE_BIT(base->ISR, pin, 1), which expands to base->ISR |= BIT(pin).
ISR is write-1-to-clear, so that read returns every latched flag on the
port and writing the value back clears them all, discarding the pending
interrupts of every other pin on the same port.
Clear the single flag with a plain write.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Marvin Gnad <marvin.gnad@gmail.com>
GPIO_OPEN_DRAIN and GPIO_OPEN_SOURCE share the GPIO_SINGLE_ENDED bit and
differ only in GPIO_LINE_OPEN_DRAIN. The open-source rejection test
masked with GPIO_OPEN_SOURCE, which also matches open-drain, so any
attempt to configure a pin as open-drain wrongly returned -ENOTSUP.
Detect open-source on the GPIO_LINE_OPEN_DRAIN bit instead so open-drain
is accepted, and reject open-drain only on RTL8752H: open-drain is
supported on all current and future Bee ICs, and RTL8752H is the sole
older part without a hardware open-drain output mode, so a blacklist is
intentional here.
Signed-off-by: Yuzhuo Liu <yuzhuo_liu@realsil.com.cn>
Add DEVICE_DT_INST_GET_COMMA helper macro to include/zephyr/device.h to
easily get a device pointer followed by a comma when expanding
devicetree foreach iterators like DT_INST_FOREACH_STATUS_OKAY.
Update drivers, soc, subsys, and tests to use the common definition.
Signed-off-by: Fabio Baltieri <fabiobaltieri@google.com>
Assisted-by: Antigravity:gemini-1.5-pro
The gpio and pinctrl drivers each open-coded the split of an
absolute pad number into a Zephyr gpio port and pin index. Move
it into one header in the common soc folder and use it from
both, so the next pad user cannot get the split wrong. The
pinctrl copy was a no-op because its pad numbers are already
absolute, so it is dropped.
Assisted-by: Claude:opus-5
Signed-off-by: Sylvio Alves <sylvio.alves@espressif.com>
The interrupt mask register uses active-low polarity: a bit value of 0
enables the interrupt on the corresponding pin, while 1 masks it
(per PCAL9539A datasheet section 6.2.10).
The standard interrupt configure function was computing:
int_mask = int_fall | int_rise;
This set bits to 1 for every interrupt-enabled pin, which masked all
interrupts rather than enabling them. Fixed by computing the input latch
first, then deriving the mask by inversion:
input_latch = int_fall | int_rise;
int_mask = ~input_latch;
Signed-off-by: Christoph Baechler <cbaechler@gmail.com>
Replace direct NVIC pending-state calls with k_irq_set_pending()/
k_irq_is_pending()/k_irq_clear_pending(), dropping the dependency on
cmsis_core.h where nothing else needed it.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Use controller/peripheral and SDO/SDI terminology in the remaining
SPI-using drivers (audio, auxdisplay, bluetooth HCI, dac, eeprom,
ethernet, flash, fpga, gpio, haptics, hdlc_rcp_if, ieee802154,
input, led, led_strip, lora, mfd, misc, mux, rtc, sdhc, stepper,
video, watchdog, wifi) and the ec_host_cmd SPI STM32 backend,
following coding guideline rule A.2: switch to
SPI_OP_MODE_CONTROLLER/PERIPHERAL and SPI_SDO_OVERRUN_DT, rename
Zephyr-owned identifiers (the HCI SPI header buffers, the winc1500
bus wrapper transfer parameters), and update comments, log messages
and Kconfig help prose.
Vendor and out-of-scope identifiers keep their names: STM32
LL_SPI_MODE_SLAVE in the ec_host_cmd backend, the ATWINC1500 SDK I2C
SLAVE_ADDRESS definition, and the I2S codec clock-role variable in
tlv320aic26.
Assisted-by: Claude:fable-5
Signed-off-by: Benjamin Cabé <benjamin@zephyrproject.org>
Two-line copyright notices were wrapped in the SPDX "<text>...</text>"
construct, which is only valid in an SPDX document, not a file header.
The REUSE tool then folds the literal "<text>" into the holder name
and drops the second line from the SBOM.
Remove the markers and tag the continuation line. Holder, year and
e-mail are left unchanged; only the syntax is fixed.
Signed-off-by: Parthiban Nallathambi <parthiban@linumiz.com>
Validate pin against the controller's port_pin_mask before entering the
API, and return -EINVAL for anything the controller does not support.
Signed-off-by: Flavio Ceolin <flavio@hubble.com>
Replace the direct NVIC_ClearPendingIRQ() call with
k_irq_clear_pending() and drop the cmsis_core.h include.
Assisted-by: Claude:claude-opus-5
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Centralise the GPIO arbitration and remove duplication. Add initial value
setting based on provided flags.
Signed-off-by: Sergei Ovchinnikov <sergei.ovchinnikov@nordicsemi.no>
Implement the optional gpio_pin_get_config callback for the CAT1
(gpio_infineon) and PSoC 6 (gpio_psoc6) drivers. The PDL drive mode read
back with Cy_GPIO_GetDrivemode(), together with the HSIOM selection and
the output data register, is translated into the corresponding
gpio_flags_t so a configured pin round-trips through pin_get_config().
Assisted-by: AI (GitHub Copilot)
Signed-off-by: Bill Waters <bill.waters@infineon.com>
A single-ended output ignored GPIO_OUTPUT_INIT_HIGH/LOW and always came
up at the released level. Select the initial level from the requested
init flag and fall back to the released level only when neither is set.
Assisted-by: AI (GitHub Copilot)
Signed-off-by: Bill Waters <bill.waters@infineon.com>
gpio_psoc6_config() formed BIT(pin) without validating pin, so an
out-of-range or absent pin could shift past the port-pin mask. Reject
pin >= the mask width and pins not present in port_pin_mask with
-EINVAL before the mask is used.
Assisted-by: AI (GitHub Copilot)
Signed-off-by: Bill Waters <bill.waters@infineon.com>