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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions boards/arm/qomu/CMakeLists.txt

This file was deleted.

28 changes: 0 additions & 28 deletions boards/arm/qomu/board.c

This file was deleted.

25 changes: 0 additions & 25 deletions boards/arm/qomu/board.h

This file was deleted.

33 changes: 33 additions & 0 deletions boards/arm/qomu/qomu.dts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/dts-v1/;
#include <quicklogic/quicklogic_eos_s3.dtsi>
#include <zephyr/dt-bindings/pinctrl/quicklogic-eos-s3-pinctrl.h>

/ {
model = "QuickLogic Qomu board";
Expand Down Expand Up @@ -56,6 +57,35 @@
};
};

&pinctrl {
uart1_rx_default: uart1_rx_default {
pinmux = <UART_RX_PAD45>;
input-enable;
};
uart1_tx_default: uart1_tx_default {
pinmux = <UART_TX_PAD44>;
output-enable;
};
usb_pu_default: usb_pu_default {
pinmux = <USB_PU_CTRL_PAD23>;
bias-high-impedance;
quicklogic,control-selection = "fabric";
output-enable;
};
usb_dn_default: usb_dn_default {
pinmux = <USB_DN_PAD28>;
bias-high-impedance;
quicklogic,control-selection = "fabric";
output-enable;
};
usb_dp_default: usb_dp_default {
pinmux = <USB_DP_PAD31>;
bias-high-impedance;
quicklogic,control-selection = "fabric";
output-enable;
};
};

&cpu0 {
clock-frequency = <61440000>;
};
Expand All @@ -71,4 +101,7 @@
&uart1 {
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&uart1_rx_default &uart1_tx_default
&usb_pu_default &usb_dn_default &usb_dp_default>;
pinctrl-names = "default";
};
5 changes: 0 additions & 5 deletions boards/arm/quick_feather/CMakeLists.txt

This file was deleted.

23 changes: 0 additions & 23 deletions boards/arm/quick_feather/board.c

This file was deleted.

19 changes: 0 additions & 19 deletions boards/arm/quick_feather/board.h

This file was deleted.

14 changes: 14 additions & 0 deletions boards/arm/quick_feather/quick_feather.dts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

/dts-v1/;
#include <quicklogic/quicklogic_eos_s3.dtsi>
#include <zephyr/dt-bindings/pinctrl/quicklogic-eos-s3-pinctrl.h>

/ {
model = "QuickLogic Quick Feather board";
Expand Down Expand Up @@ -56,6 +57,17 @@
};
};

&pinctrl {
uart_rx_default: uart_rx_default {
pinmux = <UART_RX_PAD45>;
input-enable;
};
uart_tx_default: uart_tx_default {
pinmux = <UART_TX_PAD44>;
output-enable;
};
};

&cpu0 {
clock-frequency = <61440000>;
};
Expand All @@ -67,4 +79,6 @@
&uart0 {
status = "okay";
current-speed = <115200>;
pinctrl-0 = <&uart_rx_default &uart_tx_default>;
pinctrl-names = "default";
};
1 change: 1 addition & 0 deletions drivers/pinctrl/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,4 @@ zephyr_library_sources_ifdef(CONFIG_PINCTRL_TI_K3 pinctrl_ti_k3.c)
zephyr_library_sources_ifdef(CONFIG_PINCTRL_EMSDP pinctrl_emsdp.c)
zephyr_library_sources_ifdef(CONFIG_PINCTRL_TI_CC32XX pinctrl_ti_cc32xx.c)
zephyr_library_sources_ifdef(CONFIG_PINCTRL_NUMAKER pinctrl_numaker.c)
zephyr_library_sources_ifdef(CONFIG_PINCTRL_QUICKLOGIC_EOS_S3 pinctrl_eos_s3.c)
1 change: 1 addition & 0 deletions drivers/pinctrl/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ source "drivers/pinctrl/Kconfig.ti_k3"
source "drivers/pinctrl/Kconfig.emsdp"
source "drivers/pinctrl/Kconfig.ti_cc32xx"
source "drivers/pinctrl/Kconfig.numaker"
source "drivers/pinctrl/Kconfig.eos_s3"

endif # PINCTRL
9 changes: 9 additions & 0 deletions drivers/pinctrl/Kconfig.eos_s3
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) 2023 Antmicro <www.antmicro.com>
# SPDX-License-Identifier: Apache-2.0

config PINCTRL_QUICKLOGIC_EOS_S3
bool "QuickLogic EOS S3 SoC pinctrl driver"
default y
depends on DT_HAS_QUICKLOGIC_EOS_S3_PINCTRL_ENABLED
help
Enable driver for the QuickLogic EOS S3 SoC pinctrl driver
128 changes: 128 additions & 0 deletions drivers/pinctrl/pinctrl_eos_s3.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
/*
* Copyright (c) 2023 Antmicro <www.antmicro.com>
*
* SPDX-License-Identifier: Apache-2.0
*/

#define DT_DRV_COMPAT quicklogic_eos_s3_pinctrl

#include <zephyr/arch/cpu.h>
#include <zephyr/devicetree.h>
#include <zephyr/drivers/pinctrl.h>
#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);
Comment on lines +12 to +16
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.


#define FUNCTION_REGISTER(func) (func >> 13)
#define PAD_FUNC_SEL_MASK GENMASK(2, 0)
#define PAD_CTRL_SEL_BIT0 3
#define PAD_CTRL_SEL_BIT1 4
#define PAD_OUTPUT_EN_BIT 5
#define PAD_PULL_UP_BIT 6
#define PAD_PULL_DOWN_BIT 7
#define PAD_DRIVE_STRENGTH_BIT0 8
#define PAD_DRIVE_STRENGTH_BIT1 9
#define PAD_SLEW_RATE_BIT 10
#define PAD_INPUT_EN_BIT 11
#define PAD_SCHMITT_EN_BIT 12

/*
* Program IOMUX_func_SEL register.
*/
static int pinctrl_eos_s3_input_selection(uint32_t pin, uint32_t sel_reg)
{
volatile uint32_t *reg = (uint32_t *)IO_MUX_BASE;

if (sel_reg <= IO_MUX_MAX_PAD_NR || sel_reg > IO_MUX_REG_MAX_OFFSET) {
return -EINVAL;
}
reg += sel_reg;
*reg = pin;

return 0;
}

/*
* Program IOMUX_PAD_x_CTRL register.
*/
static int pinctrl_eos_s3_set(uint32_t pin, uint32_t func)
{
volatile uint32_t *reg = (uint32_t *)IO_MUX_BASE;

if (pin > IO_MUX_REG_MAX_OFFSET) {
return -EINVAL;
}
reg += pin;
*reg = func;

return 0;
}

static int pinctrl_eos_s3_configure_pin(const pinctrl_soc_pin_t *pin)
{
uint32_t reg_value = 0;

/* Set function. */
reg_value |= (pin->iof & PAD_FUNC_SEL_MASK);

/* Output enable is active low. */
WRITE_BIT(reg_value, PAD_OUTPUT_EN_BIT, pin->output_enable ? 0 : 1);

/* These are active high. */
WRITE_BIT(reg_value, PAD_INPUT_EN_BIT, pin->input_enable);
WRITE_BIT(reg_value, PAD_SLEW_RATE_BIT, pin->slew_rate);
WRITE_BIT(reg_value, PAD_SCHMITT_EN_BIT, pin->schmitt_enable);
WRITE_BIT(reg_value, PAD_CTRL_SEL_BIT0, pin->control_selection & BIT(0));
WRITE_BIT(reg_value, PAD_CTRL_SEL_BIT1, pin->control_selection & BIT(1));

switch (pin->drive_strength) {
case 2:
WRITE_BIT(reg_value, PAD_DRIVE_STRENGTH_BIT0, 0);
WRITE_BIT(reg_value, PAD_DRIVE_STRENGTH_BIT1, 0);
break;
case 4:
WRITE_BIT(reg_value, PAD_DRIVE_STRENGTH_BIT0, 1);
WRITE_BIT(reg_value, PAD_DRIVE_STRENGTH_BIT1, 0);
break;
case 8:
WRITE_BIT(reg_value, PAD_DRIVE_STRENGTH_BIT0, 0);
WRITE_BIT(reg_value, PAD_DRIVE_STRENGTH_BIT1, 1);
break;
case 12:
WRITE_BIT(reg_value, PAD_DRIVE_STRENGTH_BIT0, 1);
WRITE_BIT(reg_value, PAD_DRIVE_STRENGTH_BIT1, 1);
break;
default:
LOG_ERR("Selected drive-strength is not supported: %d\n", pin->drive_strength);
}

/* Enable pull-up by default; overwrite if any setting was chosen. */
WRITE_BIT(reg_value, PAD_PULL_UP_BIT, 1);
WRITE_BIT(reg_value, PAD_PULL_DOWN_BIT, 0);
if (pin->high_impedance) {
WRITE_BIT(reg_value, PAD_PULL_UP_BIT, 0);
} else if (pin->pull_up | pin->pull_down) {
WRITE_BIT(reg_value, PAD_PULL_UP_BIT, pin->pull_up);
WRITE_BIT(reg_value, PAD_PULL_DOWN_BIT, pin->pull_down);
}

/* Program registers. */
pinctrl_eos_s3_set(pin->pin, reg_value);
if (pin->input_enable && FUNCTION_REGISTER(pin->iof)) {
pinctrl_eos_s3_input_selection(pin->pin, FUNCTION_REGISTER(pin->iof));
}
return 0;
}

int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg)
{
ARG_UNUSED(reg);

for (int i = 0; i < pin_cnt; i++) {
pinctrl_eos_s3_configure_pin(&pins[i]);
}

return 0;
}
1 change: 1 addition & 0 deletions drivers/serial/Kconfig.pl011
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ menuconfig UART_PL011
depends on DT_HAS_ARM_PL011_ENABLED || DT_HAS_ARM_SBSA_UART_ENABLED
select SERIAL_HAS_DRIVER
select SERIAL_SUPPORT_INTERRUPT
select PINCTRL if SOC_EOS_S3
help
This option enables the UART driver for the PL011

Expand Down
1 change: 1 addition & 0 deletions drivers/serial/Kconfig.ql_usbserialport_s3b
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ config UART_QUICKLOGIC_USBSERIALPORT_S3B
default y
depends on DT_HAS_QUICKLOGIC_USBSERIALPORT_S3B_ENABLED
select SERIAL_HAS_DRIVER
select PINCTRL
help
This option enables the QuickLogic USBserialport_S3B serial driver.
5 changes: 5 additions & 0 deletions dts/arm/quicklogic/quicklogic_eos_s3.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@
pin-secondary-config = <0x00>;
gpio-controller;
};

pinctrl: pinctrl@40004c00 {
compatible = "quicklogic,eos-s3-pinctrl";
reg = <0x40004c00 0x1b0>;
};
};
};

Expand Down
Loading
Loading