Commit 00270d0d authored by Aksel Skauge Mellbye's avatar Aksel Skauge Mellbye Committed by Fabio Baltieri
Browse files

drivers: serial: gecko: Use clock control on Series 2

Use clock control driver to configure peripheral clock on
Series 2 devices.

Signed-off-by: default avatarAksel Skauge Mellbye <aksel.mellbye@silabs.com>
parent bda8ae8c
Loading
Loading
Loading
Loading
+1 −0
Changes for drivers/serial/Kconfig.gecko: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -11,5 +11,6 @@ config UART_GECKO
	select SERIAL_SUPPORT_INTERRUPT
	select SOC_GECKO_USART
	select PINCTRL if SOC_FAMILY_SILABS_S1
	select CLOCK_CONTROL if SOC_FAMILY_SILABS_S2
	help
	  Enable the Gecko uart driver.
+31 −12
Changes for drivers/serial/uart_gecko.c: 31 added lines, 12 removed lines.
Original line number Diff line number Diff line
@@ -18,13 +18,21 @@
#include <em_gpio.h>
#endif /* CONFIG_PINCTRL */

#if DT_NODE_HAS_PROP(id, peripheral_id)
#ifdef CONFIG_CLOCK_CONTROL
#include <zephyr/drivers/clock_control.h>
#include <zephyr/drivers/clock_control/clock_control_silabs.h>
#define GET_GECKO_USART_CLOCK(idx)                            \
	.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(idx)), \
	.clock_cfg = SILABS_DT_INST_CLOCK_CFG(idx),
#elif DT_NODE_HAS_PROP(id, peripheral_id)
#define USART_PREFIX cmuClock_USART
#define UART_PREFIX cmuClock_UART
#define CLOCK_USART(id) _CONCAT(USART_PREFIX, id)
#define CLOCK_UART(id) _CONCAT(UART_PREFIX, id)
#define GET_GECKO_USART_CLOCK(id) CLOCK_USART(DT_INST_PROP(id, peripheral_id))
#define GET_GECKO_UART_CLOCK(id) CLOCK_UART(DT_INST_PROP(id, peripheral_id))
#define GET_GECKO_USART_CLOCK(id) \
	.clock = CLOCK_USART(DT_INST_PROP(id, peripheral_id)),
#define GET_GECKO_UART_CLOCK(id) \
	.clock = CLOCK_UART(DT_INST_PROP(id, peripheral_id)),
#else
#if (USART_COUNT == 1)
#define CLOCK_USART(ref)	(((ref) == USART0) ? cmuClock_USART0 \
@@ -66,8 +74,10 @@
#define CLOCK_UART(ref)		(((ref) == UART0) ? cmuClock_UART0  \
			       : ((ref) == UART1) ? cmuClock_UART1  \
			       : -1)
#define GET_GECKO_USART_CLOCK(id) CLOCK_USART((USART_TypeDef *)DT_INST_REG_ADDR(id))
#define GET_GECKO_UART_CLOCK(id) CLOCK_UART((USART_TypeDef *)DT_INST_REG_ADDR(id))
#define GET_GECKO_USART_CLOCK(id) \
	.clock = CLOCK_USART((USART_TypeDef *)DT_INST_REG_ADDR(id)),
#define GET_GECKO_UART_CLOCK(id) \
	.clock = CLOCK_UART((USART_TypeDef *)DT_INST_REG_ADDR(id)),
#endif /* DT_NODE_HAS_PROP(id, peripheral_id) */

/* Helper define to determine if SOC supports hardware flow control */
@@ -119,7 +129,12 @@ struct uart_gecko_config {
	const struct pinctrl_dev_config *pcfg;
#endif /* CONFIG_PINCTRL */
	USART_TypeDef *base;
#ifdef CONFIG_CLOCK_CONTROL
	const struct device *clock_dev;
	const struct silabs_clock_control_cmu_config clock_cfg;
#else
	CMU_Clock_TypeDef clock;
#endif
	uint32_t baud_rate;
#ifndef CONFIG_PINCTRL
#ifdef UART_GECKO_HW_FLOW_CONTROL
@@ -437,12 +452,16 @@ static int uart_gecko_init(const struct device *dev)

	USART_InitAsync_TypeDef usartInit = USART_INITASYNC_DEFAULT;

	/* The peripheral and gpio clock are already enabled from soc and gpio
	 * driver
	 */

	/* The peripheral and gpio clock are already enabled from soc and gpio driver */
	/* Enable USART clock */
#ifdef CONFIG_CLOCK_CONTROL
	err = clock_control_on(config->clock_dev, (clock_control_subsys_t)&config->clock_cfg);
	if (err < 0) {
		return err;
	}
#else
	CMU_ClockEnable(config->clock, true);
#endif

	/* Init USART */
	usartInit.baudrate = config->baud_rate;
@@ -613,7 +632,7 @@ static const struct uart_driver_api uart_gecko_driver_api = {
									       \
	static const struct uart_gecko_config uart_gecko_cfg_##idx = {	       \
		.base = (USART_TypeDef *)DT_INST_REG_ADDR(idx),		       \
		.clock = GET_GECKO_UART_CLOCK(idx),			       \
		GET_GECKO_UART_CLOCK(idx)				       \
		.baud_rate = DT_INST_PROP(idx, current_speed),		       \
		GECKO_UART_HW_FLOW_CONTROL(idx)				       \
		GECKO_UART_RX_TX_PINS(idx)				       \
@@ -671,7 +690,7 @@ DT_INST_FOREACH_STATUS_OKAY(GECKO_UART_INIT)
	static const struct uart_gecko_config usart_gecko_cfg_##idx = {        \
		.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(idx),		       \
		.base = (USART_TypeDef *)DT_INST_REG_ADDR(idx),		       \
		.clock = GET_GECKO_USART_CLOCK(idx),			       \
		GET_GECKO_USART_CLOCK(idx)				       \
		.baud_rate = DT_INST_PROP(idx, current_speed),		       \
		GECKO_USART_IRQ_HANDLER_FUNC(idx)			       \
		};							       \
@@ -694,7 +713,7 @@ DT_INST_FOREACH_STATUS_OKAY(GECKO_UART_INIT)
									       \
	static const struct uart_gecko_config usart_gecko_cfg_##idx = {        \
		.base = (USART_TypeDef *)DT_INST_REG_ADDR(idx),		       \
		.clock = GET_GECKO_USART_CLOCK(idx),			       \
		GET_GECKO_USART_CLOCK(idx)				       \
		.baud_rate = DT_INST_PROP(idx, current_speed),		       \
		GECKO_UART_HW_FLOW_CONTROL(idx)				       \
		GECKO_UART_RX_TX_PINS(idx)				       \