Skip to content

Commit 338c505

Browse files
xodus7dkalowsk
authored andcommitted
drivers: gpio: gpio_dw: add custom flag to set data and control source
If supported, the data and control source for a signal can come from either software or hardware. This change adds a custom configuration flag to set this for a specific pin. Signed-off-by: Corey Wharton <xodus7@cwharton.com>
1 parent e92468c commit 338c505

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

drivers/gpio/gpio_dw.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,35 @@ static inline void dw_pin_config(const struct device *port,
265265
}
266266
}
267267

268+
static void gpio_dw_set_hw_mode(const struct device *port, gpio_pin_t pin, bool hw_mode)
269+
{
270+
struct gpio_dw_runtime *context = port->data;
271+
__unused const struct gpio_driver_config *const cfg =
272+
(const struct gpio_driver_config *)port->config;
273+
uint32_t base_addr = dw_base_to_block_base(context->base_addr);
274+
uint32_t port_id = dw_derive_port_from_base(context->base_addr);
275+
uint32_t ctl_port;
276+
277+
/* 4-port GPIO implementation translates from base address to port */
278+
switch (port_id) {
279+
case 1:
280+
ctl_port = SWPORTB_CTL;
281+
break;
282+
case 2:
283+
ctl_port = SWPORTC_CTL;
284+
break;
285+
case 3:
286+
ctl_port = SWPORTD_CTL;
287+
break;
288+
case 0:
289+
default:
290+
ctl_port = SWPORTA_CTL;
291+
break;
292+
}
293+
294+
dw_set_bit(base_addr, ctl_port, pin, hw_mode);
295+
}
296+
268297
static inline int gpio_dw_config(const struct device *port,
269298
gpio_pin_t pin,
270299
gpio_flags_t flags)
@@ -277,6 +306,11 @@ static inline int gpio_dw_config(const struct device *port,
277306
return -EINVAL;
278307
}
279308

309+
if ((flags & DW_GPIO_HW_MODE) != 0U) {
310+
gpio_dw_set_hw_mode(port, pin, true);
311+
return 0;
312+
}
313+
280314
/* Does not support disconnected pin, and
281315
* not supporting both input/output at same time.
282316
*/
@@ -296,6 +330,8 @@ static inline int gpio_dw_config(const struct device *port,
296330
return -ENOTSUP;
297331
}
298332

333+
gpio_dw_set_hw_mode(port, pin, false);
334+
299335
dw_pin_config(port, pin, flags);
300336

301337
return 0;

include/zephyr/dt-bindings/gpio/snps-designware-gpio.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,12 @@
1515
*/
1616
#define DW_GPIO_DEBOUNCE (1U << 8)
1717

18+
/**
19+
* @brief Enable hardware control/data source for a pin.
20+
*
21+
* Configures a pin to be controlled by a hardware data source (if
22+
* supported).
23+
*/
24+
#define DW_GPIO_HW_MODE (1U << 9)
25+
1826
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_GPIO_SNPS_DESIGNWARE_GPIO_H_ */

0 commit comments

Comments
 (0)