Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add pinctrl driver for Quicklogic EOS S3 #60095

Merged
merged 4 commits into from
Jul 26, 2023

Conversation

wsipak
Copy link
Contributor

@wsipak wsipak commented Jul 6, 2023

This PR adds a new driver for the Quicklogic EOS S3 SoC.
Currently, there are two boards that do pinmuxing in their board.c files: quick_feather and qomu.
The legacy code is removed and now the driver does all the pinmuxing.

Fixes #59186.

@zephyrbot zephyrbot added area: Devicetree Binding PR modifies or adds a Device Tree binding area: Pinctrl area: UART Universal Asynchronous Receiver-Transmitter labels Jul 6, 2023
@zephyrbot zephyrbot requested a review from dcpleung July 6, 2023 12:52
Comment on lines 21 to 22
pinmux = <QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD_CFG
QUICKLOGIC_EOS_S3_PINMUX_FUNC_SEL_UART_RX>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need 3 macros here? can't a single one be used to specify the UART RX functionality?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In order to select an input function, one must first program IOMUX_PAD_x_CTRL register,
and then route the signal to functional block using IOMUX_<function>_SEL.

The second element in the DTS is used to set proper function to a physical pad.
The third element in the DTS is used for selecting proper IOMUX_<function_SEL register, where the pad number must be written.
These values are independent and one cannot be deduced using the other.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, can't this all be encoded in 32-bit + dt props?

By looking at e.g. the RX case we have:

#define QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD		45

#define QUICKLOGIC_EOS_S3_PINMUX_FUNC_SEL_UART_RX 77

#define QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD_CFG \
	(EOS_S3_UART_RXD_SEL_PAD45 | EOS_S3_PAD_OEN_DISABLE \
	 | EOS_S3_PAD_E_4MA | EOS_S3_PAD_REN_ENABLE)

PAD 45 is duplicated, for example. And what do all flags like OEN, REN, etc mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason it's done this way is related to the code that uses the HAL and was used for IO MUX:

	eos_s3_io_mux(UART_TX_PAD, UART_TX_PAD_CFG);
	eos_s3_io_mux(UART_RX_PAD, UART_RX_PAD_CFG);
	IO_MUX->UART_rxd_SEL = UART_RX_SEL;

In order to do the same thing in the driver as depicted in the third line, one must deduce that the input function for UART_rxd is being set.
However, for different pads that can serve for the same function, the function values differ:

HAL/inc/eoss3_dev.h
1451:#define UART_RXD_SEL_PAD16                          ((uint32_t) (0x00000002))
1452:#define UART_RXD_SEL_PAD45                          ((uint32_t) (0x00000004))

Knowing that the function is 0x4 is not enough to conclude that the function of UART_RX is being set here.
Therefore, to ascertain this, we would need to map each (PAD, FUNCTION) pair to a register in IO_MUX.
The value assigned would correspond to the shift to this field in the struct:
https://github.com/zephyrproject-rtos/hal_quicklogic/blob/ba7e35f175fcd28199de11f955cb995e1ef20c73/HAL/inc/eoss3_dev.h#L469

The flags used in the code here are utilized to configure active low output, drive strength and receive enable respectively.
The second value provided in the DTS configures the pad as input using these parameters.
While it's a 32-bit value, based on the S3 TRM (pp. 204-205), it appears that only bits [12:0] are actually used. We could pass some information on the more siginifant bits to the driver.

I can see that passing 3 32-bit values seems a bit much as for an IO multiplexer, and I'm sure I can add a mapping of (PAD, FUNCTION) -> register (Is this the preferred way?).

Considering the perspecive of both the TRM of EOS S3 and the HAL, it seemed logical to me that the configuration of inputs would require the pad number and two other values. Also, the current solution doesn't add any layer of mapping values between Zephyr and the HAL.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: Devicetree can’t be influenced by HALs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All right, I've addressed this issue.

Comment on lines 21 to 22
pinmux = <QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD_CFG
QUICKLOGIC_EOS_S3_PINMUX_FUNC_SEL_UART_RX>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean, can't this all be encoded in 32-bit + dt props?

By looking at e.g. the RX case we have:

#define QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD		45

#define QUICKLOGIC_EOS_S3_PINMUX_FUNC_SEL_UART_RX 77

#define QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD_CFG \
	(EOS_S3_UART_RXD_SEL_PAD45 | EOS_S3_PAD_OEN_DISABLE \
	 | EOS_S3_PAD_E_4MA | EOS_S3_PAD_REN_ENABLE)

PAD 45 is duplicated, for example. And what do all flags like OEN, REN, etc mean?

@wsipak wsipak force-pushed the wsip/eos_s3_pinctrl branch 4 times, most recently from f48b282 to d3363f3 Compare July 14, 2023 09:37
@wsipak wsipak requested a review from gmarull July 14, 2023 14:59
Comment on lines 31 to 41
#define QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD 45

#define UART_RX_SEL EOS_S3_UART_RXD_SEL_PAD45

#define QUICKLOGIC_EOS_S3_PINMUX_FUNC_SEL_NONE 0
#define QUICKLOGIC_EOS_S3_PINMUX_FUNC_SEL_UART_RX (77 << 13)

#define QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD_CFG \
(QUICKLOGIC_EOS_S3_PINMUX_FUNC_SEL_UART_RX \
| EOS_S3_UART_RXD_SEL_PAD45 | EOS_S3_PAD_OEN_DISABLE \
| EOS_S3_PAD_E_4MA | EOS_S3_PAD_REN_ENABLE)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this continues to duplicate info, PAD45 is in both places.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reworked the driver, this is done.

Comment on lines 45 to 48
#define QUICKLOGIC_EOS_S3_PINMUX_USB_PAD_CFG (EOS_S3_PAD_E_4MA | EOS_S3_PAD_P_Z \
| EOS_S3_PAD_OEN_NORMAL | EOS_S3_PAD_SMT_DISABLE \
| EOS_S3_PAD_REN_DISABLE \
| EOS_S3_PAD_SR_SLOW | EOS_S3_PAD_CTRL_SEL_FPGA)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please use standard properties, 4MA looks like a drive strength...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reworked the driver so that it utilizes properties from the DTS. Could you take a look at the current implementation? Thanks!

@wsipak wsipak force-pushed the wsip/eos_s3_pinctrl branch 3 times, most recently from ede1061 to b6a53a8 Compare July 20, 2023 15:22
@wsipak wsipak requested a review from gmarull July 20, 2023 16:35
Comment on lines 22 to 27
#define QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD 45

#define QUICKLOGIC_EOS_S3_PINMUX_FUNC_SEL_UART_RX (77 << 13)

#define QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD_CFG (QUICKLOGIC_EOS_S3_PINMUX_FUNC_SEL_UART_RX \
| QUICKLOGIC_EOS_S3_UART_RXD_SEL_PAD45)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is selection related to pad?

why not something like #define UART_TX_PAD44 QUICKLOGIC_EOS_S3_PINMUX(44, 0x3)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*_FUNC_SEL* is related to the function and the function is UART_rxd in this case.
I've implemented the macro you suggested and reworked the driver. I think the DTS looks much simpler now. Thank you.

@wsipak wsipak force-pushed the wsip/eos_s3_pinctrl branch 2 times, most recently from 4dc348a to 587d867 Compare July 24, 2023 15:14
@wsipak wsipak requested a review from gmarull July 24, 2023 18:31
Comment on lines +12 to +16
#include <zephyr/logging/log.h>
#include <zephyr/dt-bindings/pinctrl/quicklogic-eos-s3-pinctrl.h>
#include <soc.h>

LOG_MODULE_REGISTER(pinctrl_eos_s3, CONFIG_PINCTRL_LOG_LEVEL);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logging not used

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOG_MODULE_REGISTER(pinctrl_eos_s3, CONFIG_PINCTRL_LOG_LEVEL);

#define FUNCTION_REGISTER(func) (func >> 13)
#define PAD_FUNC_SEL_MASK (BIT(0) | BIT(1) | BIT(2))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe use GENMASK?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've modified this to use GENMASK.

Comment on lines 17 to 21
pinmux = <QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD QUICKLOGIC_EOS_S3_PINMUX_UART_RX_PAD_CFG>;
input-enable;
};
uart0_tx_default: uart0_tx_default {
pinmux = <QUICKLOGIC_EOS_S3_PINMUX_UART_TX_PAD QUICKLOGIC_EOS_S3_PINMUX_UART_TX_PAD_CFG>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs update

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the bindings file.

enum:
- "slow"
- "fast"
control-selection:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: quicklogic,control-selection (vendor specific prop)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

- "slow"
- "fast"
control-selection:
default: "a0registers"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default needs justification, per guidelines

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added proper descriptions.

description: |
Quicklogic EOS S3 pin's configuration (pin, IO function).
slew-rate:
default: "slow"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto for default

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@wsipak wsipak force-pushed the wsip/eos_s3_pinctrl branch 2 times, most recently from 1fe4949 to b103e74 Compare July 26, 2023 11:18
This adds a new pinctrl driver for Quicklogic EOS S3 SoC

Signed-off-by: Wojciech Sipak <wsipak@antmicro.com>
Pinmuxing was previously done in the board.c file.
Now it is done by the pinctrl driver.

Signed-off-by: Wojciech Sipak <wsipak@antmicro.com>
Pinmuxing was previously done in the board.c file.
Now it is done by the pinctrl driver.

Signed-off-by: Wojciech Sipak <wsipak@antmicro.com>
Pinmuxing is now done by a pinctrl driver, not by board.c,
so the code used previously for pinmuxing can be removed.

Fixes zephyrproject-rtos#59186.

Signed-off-by: Wojciech Sipak <wsipak@antmicro.com>
Copy link
Member

@gmarull gmarull left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks for the continued effort!

@carlescufi carlescufi merged commit 69d0f03 into zephyrproject-rtos:main Jul 26, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Devicetree Binding PR modifies or adds a Device Tree binding area: Pinctrl area: UART Universal Asynchronous Receiver-Transmitter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

boards: quick_feather/qomu: uses custom pinmux scheme
4 participants