drivers: serial: Update sam drivers to use pinctrl

This update Atmel sam serial drivers to use pinctrl driver and API. It
updates all boards with new pinctrl groups format.

Signed-off-by: Gerson Fernando Budke <nandojve@gmail.com>
This commit is contained in:
Gerson Fernando Budke 2022-03-10 22:16:26 -03:00 committed by Marti Bolivar
commit bfaf027dde
23 changed files with 379 additions and 71 deletions

View file

@ -0,0 +1,42 @@
/*
* Copyright (c) 2022, Gerson Fernando Budke <nandojve@gmail.com>
* SPDX-License-Identifier: Apache-2.0
*/
#include <dt-bindings/pinctrl/sam3XXh-pinctrl.h>
&pinctrl {
uart_default: uart_default {
group1 {
pinmux = <PA8A_UART_RXD>;
bias-pull-up;
};
group2 {
pinmux = <PA9A_UART_TXD>;
};
};
usart0_default: usart0_default {
group1 {
pinmux = <PA10A_USART0_RXD>,
<PA11A_USART0_TXD>;
};
};
usart1_default: usart1_default {
group1 {
pinmux = <PA12A_USART1_RXD>,
<PA13A_USART1_TXD>;
};
};
usart2_default: usart2_default {
group1 {
pinmux = <PB21A_USART2_RXD>,
<PB20A_USART2_TXD>;
};
};
usart3_default: usart3_default {
group1 {
pinmux = <PD5B_USART3_RXD>,
<PD4B_USART3_TXD>;
};
};
};

View file

@ -3,6 +3,7 @@
/dts-v1/;
#include <atmel/sam3x.dtsi>
#include "arduino_due-pinctrl.dtsi"
/ {
model = "Arduino Due with an Atmel SAM3X8E SoC";
@ -51,10 +52,9 @@
&uart {
status = "okay";
current-speed = <115200>;
};
&pa8a_uart_urxd {
bias-pull-up;
pinctrl-0 = <&uart_default>;
pinctrl-names = "default";
};
arduino_i2c: &twi1 { };

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2022, Gerson Fernando Budke <nandojve@gmail.com>
* SPDX-License-Identifier: Apache-2.0
*/
#include <dt-bindings/pinctrl/sam4eXe-pinctrl.h>
&pinctrl {
uart0_default: uart0_default {
group1 {
pinmux = <PA9A_UART0_RXD>,
<PA10A_UART0_TXD>;
};
};
uart1_default: uart1_default {
group1 {
pinmux = <PA5C_UART1_RXD>,
<PA6C_UART1_TXD>;
};
};
usart1_default: usart1_default {
group1 {
pinmux = <PA21A_USART1_RXD>,
<PA24A_USART1_RTS>;
bias-pull-up;
};
group1 {
pinmux = <PA22A_USART1_TXD>,
<PA25A_USART1_CTS>;
};
};
};

View file

@ -7,6 +7,7 @@
/dts-v1/;
#include <atmel/sam4e16e.dtsi>
#include "sam4e_xpro-pinctrl.dtsi"
/ {
model = "Atmel SAM4E Xplained Pro Board with an Atmel SAM4E16E SoC";
@ -135,14 +136,24 @@
};
&uart0 {
current-speed = <115200>;
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&uart0_default>;
pinctrl-names = "default";
};
&uart1 {
pinctrl-0 = <&uart1_default>;
pinctrl-names = "default";
};
&usart1 {
pinctrl-0 = <&pa21a_usart1_rxd1 &pa22a_usart1_txd1>;
current-speed = <115200>;
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&usart1_default>;
pinctrl-names = "default";
};
&gmac {

View file

@ -0,0 +1,32 @@
/*
* Copyright (c) 2022, Gerson Fernando Budke <nandojve@gmail.com>
* SPDX-License-Identifier: Apache-2.0
*/
#include <dt-bindings/pinctrl/sam4lcXc-pinctrl.h>
&pinctrl {
usart0_default: usart0_default {
group1 {
pinmux = <PC2C_USART0_RXD>,
<PA7B_USART0_TXD>;
};
};
usart0_hw_ctrl_flow: usart0_hw_ctrl_flow {
group1 {
pinmux = <PC2C_USART0_RXD>,
<PC7B_USART2_RTS>;
bias-pull-up;
};
group1 {
pinmux = <PA7B_USART0_TXD>,
<PC8E_USART2_CTS>;
};
};
usart2_default: usart2_default {
group1 {
pinmux = <PC11B_USART2_RXD>,
<PC12B_USART2_TXD>;
};
};
};

View file

@ -6,6 +6,7 @@
/dts-v1/;
#include <atmel/sam4lx4.dtsi>
#include "sam4l_ek-pinctrl.dtsi"
/ {
model = "Atmel SAM4L-EK Board with an Atmel SAM4LC4C SoC";
@ -46,9 +47,11 @@
};
&usart2 {
current-speed = <115200>;
pinctrl-0 = <&pc11b_usart2_rxd2 &pc12b_usart2_txd2>;
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&usart2_default>;
pinctrl-names = "default";
};
&spi0 {

View file

@ -0,0 +1,27 @@
/*
* Copyright (c) 2022, Gerson Fernando Budke <nandojve@gmail.com>
* SPDX-License-Identifier: Apache-2.0
*/
#include <dt-bindings/pinctrl/sam4sXc-pinctrl.h>
&pinctrl {
uart0_default: uart0_default {
group1 {
pinmux = <PA9A_UART0_RXD>,
<PA10A_UART0_TXD>;
};
};
uart1_default: uart1_default {
group1 {
pinmux = <PB2A_UART1_RXD>,
<PB3A_UART1_TXD>;
};
};
usart1_default: usart1_default {
group1 {
pinmux = <PA21A_USART1_RXD>,
<PA22A_USART1_TXD>;
};
};
};

View file

@ -6,6 +6,7 @@
/dts-v1/;
#include <atmel/sam4s16c.dtsi>
#include "sam4s_xplained-pinctrl.dtsi"
/ {
model = "Atmel SAM4S Xplained Board with an Atmel SAM4S16C SoC";
@ -135,13 +136,19 @@
};
&uart0 {
current-speed = <115200>;
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&uart0_default>;
pinctrl-names = "default";
};
&uart1 {
current-speed = <115200>;
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&uart1_default>;
pinctrl-names = "default";
};
&wdt {

View file

@ -7,6 +7,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include "sam_e70_xplained-pinctrl.dtsi"
/ {
aliases {
i2c-0 = &twihs0;
@ -76,8 +78,11 @@
};
&usart1 {
current-speed = <115200>;
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&usart1_default>;
pinctrl-names = "default";
};
&wdt {

View file

@ -0,0 +1,74 @@
/*
* Copyright (c) 2022, Gerson Fernando Budke <nandojve@gmail.com>
* SPDX-License-Identifier: Apache-2.0
*/
#include <dt-bindings/pinctrl/same70q-pinctrl.h>
&pinctrl {
uart3_default: uart3_default {
group1 {
pinmux = <PD28A_UART3_RXD>,
<PD30A_UART3_TXD>;
};
};
uart4_default: uart4_default {
group1 {
pinmux = <PD19C_UART4_TXD>,
<PD18C_UART4_RXD>;
};
};
usart0_default: usart0_default {
group1 {
pinmux = <PB0C_USART0_RXD>,
<PB1C_USART0_TXD>;
};
};
usart0_hw_ctrl_flow_clk: usart0_hw_ctrl_flow_clk {
group1 {
pinmux = <PB0C_USART0_RXD>,
<PB3C_USART0_RTS>;
bias-pull-up;
};
group1 {
pinmux = <PB1C_USART0_TXD>,
<PB2C_USART0_CTS>,
<PB13C_USART0_SCK>;
};
};
usart1_default: usart1_default {
group1 {
pinmux = <PA21A_USART1_RXD>,
<PB4D_USART1_TXD>;
};
};
usart1_hw_ctrl_flow: usart1_hw_ctrl_flow {
group1 {
pinmux = <PA21A_USART1_RXD>,
<PA24A_USART1_RTS>;
bias-pull-up;
};
group1 {
pinmux = <PB4D_USART1_TXD>,
<PA25A_USART1_CTS>;
};
};
usart2_default: usart2_default {
group1 {
pinmux = <PD15B_USART2_RXD>,
<PD16B_USART2_TXD>;
};
};
usart2_hw_ctrl_flow_clk: usart2_hw_ctrl_flow_clk {
group1 {
pinmux = <PD15B_USART2_RXD>,
<PD18B_USART2_RTS>;
bias-pull-up;
};
group1 {
pinmux = <PD16B_USART2_TXD>,
<PD19B_USART2_CTS>,
<PD17B_USART2_SCK>;
};
};
};

View file

@ -1,12 +1,14 @@
/*
* Copyright (c) 2017 Piotr Mienkowski
* Copyright (c) 2017 Justin Watson
* Copyright (c) 2019-2020 Gerson Fernando Budke <nandojve@gmail.com>
* Copyright (c) 2020 Stephanos Ioannidis <root@stephanos.io>
* Copyright (c) 2019-2022 Gerson Fernando Budke <nandojve@gmail.com>
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "sam_v71_xult-pinctrl.dtsi"
/ {
aliases {
i2c-0 = &twihs0;
@ -183,15 +185,20 @@
};
&usart1 {
current-speed = <115200>;
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&usart1_default>;
pinctrl-names = "default";
};
&uart3 {
status = "okay";
pinctrl-0 = <&pd28a_uart3_urxd3 &pd30a_uart3_utxd3>;
current-speed = <115200>;
pinctrl-0 = <&uart3_default>;
pinctrl-names = "default";
};
&wdt {

View file

@ -0,0 +1,72 @@
/*
* Copyright (c) 2022, Gerson Fernando Budke <nandojve@gmail.com>
* SPDX-License-Identifier: Apache-2.0
*/
#include <dt-bindings/pinctrl/samv71q-pinctrl.h>
&pinctrl {
uart3_default: uart3_default {
group1 {
pinmux = <PD28A_UART3_RXD>,
<PD30A_UART3_TXD>;
};
};
uart4_default: uart4_default {
group1 {
pinmux = <PD19C_UART4_TXD>,
<PD18C_UART4_RXD>;
};
};
usart0_default: usart0_default {
group1 {
pinmux = <PB0C_USART0_RXD>,
<PB1C_USART0_TXD>;
};
};
usart0_hw_ctrl_flow: usart0_hw_ctrl_flow {
group1 {
pinmux = <PB0C_USART0_RXD>,
<PB3C_USART0_RTS>;
bias-pull-up;
};
group1 {
pinmux = <PB1C_USART0_TXD>,
<PB2C_USART0_CTS>;
};
};
usart1_default: usart1_default {
group1 {
pinmux = <PA21A_USART1_RXD>,
<PB4D_USART1_TXD>;
};
};
usart1_hw_ctrl_flow: usart1_hw_ctrl_flow {
group1 {
pinmux = <PA21A_USART1_RXD>,
<PA24A_USART1_RTS>;
bias-pull-up;
};
group1 {
pinmux = <PB4D_USART1_TXD>,
<PA25A_USART1_CTS>;
};
};
usart2_default: usart2_default {
group1 {
pinmux = <PD15B_USART2_RXD>,
<PD16B_USART2_TXD>;
};
};
usart2_hw_ctrl_flow: usart2_hw_ctrl_flow_clk {
group1 {
pinmux = <PD15B_USART2_RXD>,
<PD18B_USART2_RTS>;
bias-pull-up;
};
group1 {
pinmux = <PD16B_USART2_TXD>,
<PD19B_USART2_CTS>;
};
};
};

View file

@ -4,11 +4,21 @@
* SPDX-License-Identifier: Apache-2.0
*/
&pinctrl {
usart1_esp_wifi: usart1_esp_wifi {
group1 {
pinmux = <PA21A_USART1_RXD>,
<PA22A_USART1_TXD>;
};
};
};
&usart1 {
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&pa21a_usart1_rxd1 &pa22a_usart1_txd1>;
pinctrl-0 = <&usart1_esp_wifi>;
pinctrl-names = "default";
esp8266 {
compatible = "espressif,esp-at";

View file

@ -20,13 +20,13 @@
#include <init.h>
#include <soc.h>
#include <drivers/uart.h>
#include <drivers/pinctrl.h>
/* Device constant configuration parameters */
struct uart_sam_dev_cfg {
Uart *regs;
uint32_t periph_id;
struct soc_gpio_pin pin_rx;
struct soc_gpio_pin pin_tx;
const struct pinctrl_dev_config *pcfg;
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
uart_irq_config_func_t irq_config_func;
@ -58,8 +58,10 @@ static int uart_sam_init(const struct device *dev)
soc_pmc_peripheral_enable(cfg->periph_id);
/* Connect pins to the peripheral */
soc_gpio_configure(&cfg->pin_rx);
soc_gpio_configure(&cfg->pin_tx);
retval = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
if (retval < 0) {
return retval;
}
/* Reset and disable UART */
uart->UART_CR = UART_CR_RSTRX | UART_CR_RSTTX
@ -356,8 +358,7 @@ static const struct uart_driver_api uart_sam_driver_api = {
.regs = (Uart *)DT_INST_REG_ADDR(n), \
.periph_id = DT_INST_PROP(n, peripheral_id), \
\
.pin_rx = ATMEL_SAM_DT_INST_PIN(n, 0), \
.pin_tx = ATMEL_SAM_DT_INST_PIN(n, 1), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
\
IRQ_FUNC_INIT \
}
@ -384,6 +385,7 @@ static const struct uart_driver_api uart_sam_driver_api = {
#endif
#define UART_SAM_INIT(n) \
PINCTRL_DT_INST_DEFINE(n); \
static struct uart_sam_dev_data uart##n##_sam_data = { \
.baud_rate = DT_INST_PROP(n, current_speed), \
}; \

View file

@ -20,13 +20,13 @@
#include <init.h>
#include <soc.h>
#include <drivers/uart.h>
#include <drivers/pinctrl.h>
/* Device constant configuration parameters */
struct usart_sam_dev_cfg {
Usart *regs;
uint32_t periph_id;
struct soc_gpio_pin pin_rx;
struct soc_gpio_pin pin_tx;
const struct pinctrl_dev_config *pcfg;
#ifdef CONFIG_UART_INTERRUPT_DRIVEN
uart_irq_config_func_t irq_config_func;
@ -58,8 +58,10 @@ static int usart_sam_init(const struct device *dev)
soc_pmc_peripheral_enable(cfg->periph_id);
/* Connect pins to the peripheral */
soc_gpio_configure(&cfg->pin_rx);
soc_gpio_configure(&cfg->pin_tx);
retval = pinctrl_apply_state(cfg->pcfg, PINCTRL_STATE_DEFAULT);
if (retval < 0) {
return retval;
}
/* Reset and disable USART */
usart->US_CR = US_CR_RSTRX | US_CR_RSTTX
@ -357,8 +359,7 @@ static const struct uart_driver_api usart_sam_driver_api = {
.regs = (Usart *)DT_INST_REG_ADDR(n), \
.periph_id = DT_INST_PROP(n, peripheral_id), \
\
.pin_rx = ATMEL_SAM_DT_INST_PIN(n, 0), \
.pin_tx = ATMEL_SAM_DT_INST_PIN(n, 1), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(n), \
\
IRQ_FUNC_INIT \
}
@ -385,6 +386,7 @@ static const struct uart_driver_api usart_sam_driver_api = {
#endif
#define USART_SAM_INIT(n) \
PINCTRL_DT_INST_DEFINE(n); \
static struct usart_sam_dev_data usart##n##_sam_data = { \
.baud_rate = DT_INST_PROP(n, current_speed), \
}; \

View file

@ -96,7 +96,6 @@
peripheral-id = <8>;
status = "disabled";
label = "UART_0";
pinctrl-0 = <&pa8a_uart_urxd &pa9a_uart_utxd>;
};
usart0: usart@40098000 {
@ -135,7 +134,7 @@
label = "USART_3";
};
pinctrl@400e0e00 {
pinctrl: pinctrl@400e0e00 {
compatible = "atmel,sam-pinctrl";
#address-cells = <1>;
#size-cells = <1>;

View file

@ -115,7 +115,6 @@
peripheral-id = <7>;
status = "disabled";
label = "UART_0";
pinctrl-0 = <&pa9a_uart0_urxd0 &pa10a_uart0_utxd0>;
};
uart1: uart@40060600 {
@ -125,7 +124,6 @@
peripheral-id = <45>;
status = "disabled";
label = "UART_1";
pinctrl-0 = <&pa5c_uart1_urxd1 &pa6c_uart1_utxd1>;
};
usart0: usart@400a0000 {
@ -174,11 +172,13 @@
};
};
pinctrl@400e0e00 {
pinctrl: pinctrl@400e0e00 {
compatible = "atmel,sam-pinctrl";
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x400e0e00 0x400e0e00 0xa00>;
status = "okay";
label = "PINCTRL";
pioa: gpio@400e0e00 {
compatible = "atmel,sam-gpio";

View file

@ -177,7 +177,7 @@
pinctrl-0 = <&pa25a_usbc_dm &pa26a_usbc_dp>;
};
pinctrl@400e1000 {
pinctrl: pinctrl@400e1000 {
compatible = "atmel,sam-pinctrl";
#address-cells = <1>;
#size-cells = <1>;

View file

@ -116,7 +116,6 @@
peripheral-id = <8>;
status = "disabled";
label = "UART_0";
pinctrl-0 = <&pa9a_uart0_urxd0 &pa10a_uart0_utxd0>;
};
uart1: uart@400e0800 {
@ -126,7 +125,6 @@
peripheral-id = <9>;
status = "disabled";
label = "UART_1";
pinctrl-0 = <&pb2a_uart1_urxd1 &pb3a_uart1_utxd1>;
};
usart0: usart@40024000 {
@ -147,11 +145,13 @@
label = "USART_1";
};
pinctrl@400e0e00 {
pinctrl: pinctrl@400e0e00 {
compatible = "atmel,sam-pinctrl";
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x400e0e00 0x400e0e00 0x600>;
status = "okay";
label = "PINCTRL";
pioa: gpio@400e0e00 {
compatible = "atmel,sam-gpio";

View file

@ -147,7 +147,6 @@
peripheral-id = <7>;
status = "disabled";
label = "UART_0";
pinctrl-0 = <&pa9a_uart0_urxd0 &pa10a_uart0_utxd0>;
};
uart1: uart@400e0a00 {
@ -193,7 +192,6 @@
peripheral-id = <13>;
status = "disabled";
label = "USART_0";
pinctrl-0 = <&pb0c_usart0_rxd0 &pb1c_usart0_txd0>;
};
usart1: usart@40028000 {
@ -203,7 +201,6 @@
peripheral-id = <14>;
status = "disabled";
label = "USART_1";
pinctrl-0 = <&pa21a_usart1_rxd1 &pb4d_usart1_txd1>;
};
usart2: usart@4002c000 {
@ -213,7 +210,6 @@
peripheral-id = <15>;
status = "disabled";
label = "USART_2";
pinctrl-0 = <&pd15b_usart2_rxd2 &pd16b_usart2_txd2>;
};
afec0: adc@4003c000 {
@ -248,7 +244,7 @@
#io-channel-cells = <1>;
};
pinctrl@400e0e00 {
pinctrl: pinctrl@400e0e00 {
compatible = "atmel,sam-pinctrl";
#address-cells = <1>;
#size-cells = <1>;

View file

@ -2,7 +2,9 @@ description: SAM family UART
compatible: "atmel,sam-uart"
include: uart-controller.yaml
include:
- name: uart-controller.yaml
- name: pinctrl-device.yaml
properties:
reg:
@ -15,16 +17,3 @@ properties:
type: int
description: peripheral ID
required: true
pinctrl-0:
type: phandles
description: |
PIO pin configuration for URXD & UTRD signals. We expect that
the phandles will reference pinctrl nodes. These nodes will
have a nodelabel that matches the Atmel SoC HAL defines and
be of the form p<port><pin><periph>_<inst>_<signal>.
For example the UART on SAM3x would be
pinctrl-0 = <&pa8a_uart_urxd &pa9a_uart_utxd>;
required: true

View file

@ -2,7 +2,9 @@ description: Atmel SAM family USART
compatible: "atmel,sam-usart"
include: uart-controller.yaml
include:
- name: uart-controller.yaml
- name: pinctrl-device.yaml
properties:
reg:
@ -15,16 +17,3 @@ properties:
type: int
description: peripheral ID
required: true
pinctrl-0:
type: phandles
description: |
PIO pin configuration for RXD & TRD signals. We expect that
the phandles will reference pinctrl nodes. These nodes will
have a nodelabel that matches the Atmel SoC HAL defines and
be of the form p<port><pin><periph>_<inst>_<signal>.
For example the USART0 on SAME7x would be
pinctrl-0 = <&pb0c_usart0_rxd0 &pb1c_usart0_txd0>;
required: true

View file

@ -1,5 +1,13 @@
/* SPDX-License-Identifier: Apache-2.0 */
&pinctrl {
sercom3_loopback: sercom3_loopback {
group1 {
pinmux = <PA16D_SERCOM3_PAD0>;
};
};
};
&dmac {
status = "okay";
};
@ -20,7 +28,8 @@
txpo = <0>;
/* PAD0 must be configured to allow working loop-back */
pinctrl-0 = <&pa16d_sercom3_pad0>;
pinctrl-0 = <&sercom3_loopback>;
pinctrl-names = "default";
/* Configure DMA channels for async operation */
dmas = <&dmac 10 7>, <&dmac 11 8>;