@@ -207,6 +207,32 @@ static uint32_t gpio_rpi_get_pending_int(const struct device *dev)
207207 return 0 ;
208208}
209209
210+ #ifdef CONFIG_GPIO_GET_DIRECTION
211+ static int gpio_rpi_port_get_direction (const struct device * port , gpio_port_pins_t map ,
212+ gpio_port_pins_t * inputs , gpio_port_pins_t * outputs )
213+ {
214+ /* The Zephyr API considers a disconnected pin to be neither an input nor output.
215+ * Since we disable both OE and IE for disconnected pins clear the mask bits.
216+ */
217+ for (int pin = 0 ; pin < NUM_BANK0_GPIOS ; pin ++ ) {
218+ if (pads_bank0_hw -> io [pin ] & PADS_BANK0_GPIO0_OD_BITS ) {
219+ map &= ~BIT (pin );
220+ }
221+ if (inputs && (pads_bank0_hw -> io [pin ] & PADS_BANK0_GPIO0_IE_BITS )) {
222+ * inputs |= BIT (pin );
223+ }
224+ }
225+ if (inputs ) {
226+ * inputs &= map ;
227+ }
228+ if (outputs ) {
229+ * outputs = sio_hw -> gpio_oe & map ;
230+ }
231+
232+ return 0 ;
233+ }
234+ #endif
235+
210236static DEVICE_API (gpio , gpio_rpi_driver_api ) = {
211237 .pin_configure = gpio_rpi_configure ,
212238 .port_get_raw = gpio_rpi_port_get_raw ,
@@ -217,6 +243,9 @@ static DEVICE_API(gpio, gpio_rpi_driver_api) = {
217243 .pin_interrupt_configure = gpio_rpi_pin_interrupt_configure ,
218244 .manage_callback = gpio_rpi_manage_callback ,
219245 .get_pending_int = gpio_rpi_get_pending_int ,
246+ #ifdef CONFIG_GPIO_GET_DIRECTION
247+ .port_get_direction = gpio_rpi_port_get_direction ,
248+ #endif
220249};
221250
222251static void gpio_rpi_isr (const struct device * dev )
0 commit comments