Skip to content

Commit 72d8b79

Browse files
committed
drivers: pinctrl: add amebad pin controller driver
add amebad pin controller driver Signed-off-by: zjian zhang <zjian_zhang@realsil.com.cn>
1 parent 02d943f commit 72d8b79

File tree

7 files changed

+292
-0
lines changed

7 files changed

+292
-0
lines changed

drivers/pinctrl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ zephyr_library_sources_ifdef(CONFIG_PINCTRL_EMSDP pinctrl_emsdp.c)
4545
zephyr_library_sources_ifdef(CONFIG_PINCTRL_TI_CC32XX pinctrl_ti_cc32xx.c)
4646
zephyr_library_sources_ifdef(CONFIG_PINCTRL_NUMAKER pinctrl_numaker.c)
4747
zephyr_library_sources_ifdef(CONFIG_PINCTRL_QUICKLOGIC_EOS_S3 pinctrl_eos_s3.c)
48+
zephyr_library_sources_ifdef(CONFIG_PINCTRL_AMEBA pinctrl_ameba.c)
4849
zephyr_library_sources_ifdef(CONFIG_PINCTRL_MCI_IO_MUX pinctrl_mci_io_mux.c)
4950
zephyr_library_sources_ifdef(CONFIG_PINCTRL_ENE_KB1200 pinctrl_ene_kb1200.c)
5051
zephyr_library_sources_ifdef(CONFIG_PINCTRL_IMX_SCU pinctrl_imx_scu.c)

drivers/pinctrl/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ source "drivers/pinctrl/Kconfig.emsdp"
7272
source "drivers/pinctrl/Kconfig.ti_cc32xx"
7373
source "drivers/pinctrl/Kconfig.numaker"
7474
source "drivers/pinctrl/Kconfig.eos_s3"
75+
source "drivers/pinctrl/Kconfig.ameba"
7576
source "drivers/pinctrl/Kconfig.mci_io_mux"
7677
source "drivers/pinctrl/Kconfig.ene"
7778
source "drivers/pinctrl/Kconfig.zynqmp"

drivers/pinctrl/Kconfig.ameba

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2024 Realtek Semiconductor Corp.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config PINCTRL_AMEBA
5+
bool "Pin controller driver for Realtek Ameba series SoC"
6+
default y
7+
depends on DT_HAS_REALTEK_AMEBA_PINCTRL_ENABLED
8+
help
9+
Enable pin controller driver for Realtek Ameba series SoC

drivers/pinctrl/pinctrl_ameba.c

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (c) 2024 Realtek Semiconductor Corp.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* Include <soc.h> before <ameba_soc.h> to avoid redefining unlikely() macro */
8+
#include <soc.h>
9+
#include <ameba_soc.h>
10+
11+
#include <zephyr/drivers/pinctrl.h>
12+
13+
#define AMEBA_GET_PORT_NUM(pin_mux) ((pin_mux >> 13) & 0x03)
14+
#define AMEBA_GET_PIN_NUM(pin_mux) ((pin_mux >> 8) & 0x1f)
15+
#define AMEBA_GET_PIMNUX_ID(pin_mux) (pin_mux & 0xFF)
16+
17+
#define AMEBA_GPIO_PINNAME(PORT, PIN) (((PORT) << 5) | ((PIN) & 0x1F))
18+
19+
static int ameba_configure_pin(const pinctrl_soc_pin_t *pin)
20+
{
21+
uint32_t port_idx, pin_idx;
22+
uint8_t gpio_pin;
23+
uint32_t function_id;
24+
25+
port_idx = AMEBA_GET_PORT_NUM(pin->pinmux);
26+
pin_idx = AMEBA_GET_PIN_NUM(pin->pinmux);
27+
function_id = AMEBA_GET_PIMNUX_ID(pin->pinmux);
28+
gpio_pin = AMEBA_GPIO_PINNAME(port_idx, pin_idx);
29+
30+
Pinmux_Config(gpio_pin, function_id);
31+
32+
if (pin->pull_up) {
33+
PAD_PullCtrl(gpio_pin, GPIO_PuPd_UP);
34+
PAD_SleepPullCtrl(gpio_pin, GPIO_PuPd_UP);
35+
} else if (pin->pull_down) {
36+
PAD_PullCtrl(gpio_pin, GPIO_PuPd_DOWN);
37+
PAD_SleepPullCtrl(gpio_pin, GPIO_PuPd_DOWN);
38+
} else {
39+
PAD_PullCtrl(gpio_pin, GPIO_PuPd_NOPULL);
40+
PAD_SleepPullCtrl(gpio_pin, GPIO_PuPd_NOPULL);
41+
}
42+
43+
/* default slew rate fast */
44+
if (pin->slew_rate_slow) {
45+
PAD_SlewRateCtrl(gpio_pin, PAD_SlewRate_Slow);
46+
}
47+
48+
/* Set the PAD driving strength to PAD_DRV_ABILITITY_LOW, default PAD_DRV_ABILITITY_HIGH */
49+
if (pin->drive_strength_low) {
50+
PAD_DrvStrength(gpio_pin, PAD_DRV_ABILITITY_LOW);
51+
}
52+
53+
/* default enable digital path input. */
54+
if (pin->digital_input_disable) {
55+
PAD_InputCtrl(gpio_pin, DISABLE);
56+
}
57+
58+
/* default enable schmitt */
59+
if (pin->schmitt_disable) {
60+
PAD_SchmitCtrl(gpio_pin, DISABLE);
61+
}
62+
63+
if (pin->swd_off) {
64+
Pinmux_Swdoff();
65+
}
66+
67+
return 0;
68+
}
69+
70+
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg)
71+
{
72+
int ret = 0;
73+
74+
ARG_UNUSED(reg);
75+
76+
for (int i = 0; i < pin_cnt; i++) {
77+
ret = ameba_configure_pin(&pins[i]);
78+
79+
if (ret < 0) {
80+
return ret;
81+
}
82+
}
83+
84+
return 0;
85+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Copyright (c) 2024 Realtek Semiconductor Corp.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
Realtek Ameba pinctrl is a singleton node responsible for controlling pin function selection
6+
and pin properties. For example, you can use this node to route UART0 TX to pin PB_17
7+
and enable the pull-up resistor on the pin.
8+
9+
All device pin configurations should be placed in child nodes of the 'pinctrl' node,
10+
as shown in this example:
11+
/* put this example in places like a board-pinctrl.dtsi file in your board directory,
12+
* or a devicetree overlay in your application.
13+
*/
14+
&pinctrl {
15+
/* configuration for uart0 device, default state */
16+
uart0_default: uart0_default {
17+
/* 'group1' name is arbitrary, if pin's settings are not same,
18+
* add other group like group2 {}
19+
*/
20+
group1 {
21+
pinmux = <AMEBA_PINMUX('B', 17, AMEBA_UART2_TXD)>,
22+
<AMEBA_PINMUX('B', 18, AMEBA_UART2_RXD)>;
23+
bias-pull-up;
24+
};
25+
};
26+
};
27+
28+
The 'uart0_default' child node encodes the pin configurations for a particular state of a device;
29+
in this case, the default (that is, active) state. You would specify the low-power configuration
30+
for the same device in a separate child node.
31+
32+
As shown, pin configurations are organized in groups within each child node. Each group can
33+
specify a list of pin function selections in the 'pinmux' property. The AMEBA_PINMUX macro is
34+
used to specify a pin function selection and pin configuration. You could choose pinmux specified
35+
function to specified pin. And you could configure driver direction, driver state and pull state
36+
for the specified pad.
37+
38+
To link this pin configuration with a device, use a pinctrl-N property for some number N,
39+
like this example you could place in your board's DTS file:
40+
&uart0 {
41+
pinctrl-0 = <&uart0_default>;
42+
pinctrl-names = "default";
43+
};
44+
45+
compatible: "realtek,ameba-pinctrl"
46+
47+
include: base.yaml
48+
49+
properties:
50+
reg:
51+
required: true
52+
child-binding:
53+
description: |
54+
Realtek Ameba pin controller pin group for a pinctrl state.
55+
child-binding:
56+
description: |
57+
Realtek Ameba pin controller pin configuration node.
58+
include:
59+
- name: pincfg-node.yaml
60+
property-allowlist:
61+
- bias-disable
62+
- bias-pull-down
63+
- bias-pull-up
64+
- input-schmitt-disable
65+
properties:
66+
pinmux:
67+
required: true
68+
type: array
69+
description: |
70+
Pin mux selections for this group. An array of pins sharing the same group properties.
71+
Each element of the array is an integer constructed from the pin number and
72+
the alternative function of the pin.
73+
slew-rate-slow:
74+
type: boolean
75+
description: |
76+
Pin output slew rate.If not set, default value is fast.
77+
drive-strength-low:
78+
type: boolean
79+
description: |
80+
Drive strength of the output pin.If not set, default ability is high.
81+
digital-input-disable:
82+
type: boolean
83+
description: |
84+
Disable the digital input function.
85+
swd-off:
86+
type: boolean
87+
description: |
88+
Disable the SWD function.
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2024 Realtek Semiconductor Corp.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_AMEBAD_PINCTRL_H_
8+
#define ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_AMEBAD_PINCTRL_H_
9+
10+
/* PINMUX Function definitions */
11+
#define AMEBA_GPIO 0
12+
#define AMEBA_UART 1
13+
#define AMEBA_UART_RTSCTS 2
14+
#define AMEBA_LOGUART 2
15+
#define AMEBA_SPIM 3
16+
#define AMEBA_SPIS 3
17+
#define AMEBA_RTC 4
18+
#define AMEBA_TIMINPUT 4
19+
#define AMEBA_IR 5
20+
#define AMEBA_SPIF 6
21+
#define AMEBA_I2C 7
22+
#define AMEBA_SDIOD 8
23+
#define AMEBA_SDIOH 8
24+
#define AMEBA_PWM 9
25+
#define AMEBA_PWM_HS 9
26+
#define AMEBA_PWM_LP 10
27+
#define AMEBA_SWD 11
28+
#define AMEBA_I2S 12
29+
#define AMEBA_DMIC 12
30+
#define AMEBA_LCD 13
31+
#define AMEBA_USB 14
32+
#define AMEBA_QDEC 15
33+
#define AMEBA_SGPIO 16
34+
#define AMEBA_RFE 18
35+
#define AMEBA_BTCOEX 19
36+
#define AMEBA_WIFIFW 20
37+
#define AMEBA_EXT_PCM 20
38+
#define AMEBA_EXT_BT 20
39+
#define AMEBA_BB_PIN 21
40+
#define AMEBA_SIC 22
41+
#define AMEBA_TIMINPUT_HS 22
42+
#define AMEBA_DBGPORT 23
43+
#define AMEBA_BBDBG 25
44+
#define AMEBA_EXT32K 28
45+
#define AMEBA_RTCOUT 28
46+
#define AMEBA_KEYSCAN_ROW 29
47+
#define AMEBA_KEYSCAN_COL 30
48+
#define AMEBA_WAKEUP 31
49+
50+
/* Define pins number: bit[14:13] port, bit[12:8] pin, bit[7:0] function ID */
51+
#define AMEBA_PORT_PIN(port, line) ((((port) - 'A') << 5) + (line))
52+
#define AMEBA_PINMUX(port, line, funcid) (((AMEBA_PORT_PIN(port, line)) << 8) | (funcid))
53+
54+
#endif /* ZEPHYR_INCLUDE_DT_BINDINGS_PINCTRL_AMEBAD_PINCTRL_H_ */
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright (c) 2024 Realtek Semiconductor Corp.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef ZEPHYR_SOC_REALTEK_AMEBA_COMMON_PINCTRL_SOC_H_
8+
#define ZEPHYR_SOC_REALTEK_AMEBA_COMMON_PINCTRL_SOC_H_
9+
10+
#include <zephyr/devicetree.h>
11+
#include <zephyr/types.h>
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
struct pinctrl_soc_pin {
18+
uint32_t pinmux: 15;
19+
/* bit[14:13] port
20+
* bit[12:8] pin
21+
* bit[7:0] function ID
22+
*/
23+
uint32_t pull_down: 1;
24+
uint32_t pull_up: 1;
25+
uint32_t schmitt_disable: 1;
26+
uint32_t slew_rate_slow: 1;
27+
uint32_t drive_strength_low: 1;
28+
uint32_t digital_input_disable: 1;
29+
uint32_t swd_off: 1;
30+
};
31+
32+
typedef struct pinctrl_soc_pin pinctrl_soc_pin_t;
33+
34+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
35+
{ \
36+
.pinmux = DT_PROP_BY_IDX(node_id, prop, idx), \
37+
.pull_down = DT_PROP(node_id, bias_pull_down), \
38+
.pull_up = DT_PROP(node_id, bias_pull_up), \
39+
.schmitt_disable = DT_PROP(node_id, input_schmitt_disable), \
40+
.slew_rate_slow = DT_PROP(node_id, slew_rate_slow), \
41+
.drive_strength_low = DT_PROP(node_id, drive_strength_low), \
42+
.digital_input_disable = DT_PROP(node_id, digital_input_disable), \
43+
.swd_off = DT_PROP(node_id, swd_off), \
44+
},
45+
46+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
47+
{DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux, \
48+
Z_PINCTRL_STATE_PIN_INIT)}
49+
50+
#ifdef __cplusplus
51+
}
52+
#endif
53+
54+
#endif /* ZEPHYR_SOC_REALTEK_AMEBA_COMMON_PINCTRL_SOC_H_ */

0 commit comments

Comments
 (0)