Skip to content

Commit 804e3f6

Browse files
tswaehnkartben
authored andcommitted
soc: sensry: add pinctrl
Add pin control support for the sy1xx soc. Signed-off-by: Sven Ginka <[email protected]>
1 parent 910ec59 commit 804e3f6

File tree

7 files changed

+286
-0
lines changed

7 files changed

+286
-0
lines changed

drivers/pinctrl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ zephyr_library_sources_ifdef(CONFIG_PINCTRL_MAX32 pinctrl_max32.c)
4242
zephyr_library_sources_ifdef(CONFIG_PINCTRL_IMX_SCMI pinctrl_imx_scmi.c)
4343
zephyr_library_sources_ifdef(CONFIG_PINCTRL_MCHP_MEC5 pinctrl_mchp_mec5.c)
4444
zephyr_library_sources_ifdef(CONFIG_PINCTRL_WCH_AFIO pinctrl_wch_afio.c)
45+
zephyr_library_sources_ifdef(CONFIG_PINCTRL_SY1XX pinctrl_sy1xx.c)
4546

4647
add_subdirectory(renesas)

drivers/pinctrl/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ source "drivers/pinctrl/Kconfig.zynqmp"
6969
source "drivers/pinctrl/Kconfig.max32"
7070
source "drivers/pinctrl/Kconfig.mec5"
7171
source "drivers/pinctrl/Kconfig.wch_afio"
72+
source "drivers/pinctrl/Kconfig.sy1xx"
7273

7374
rsource "renesas/Kconfig"
7475

drivers/pinctrl/Kconfig.sy1xx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-License-Identifier: Apache-2.0
2+
# Copyright (c) 2024 sensry.io
3+
4+
config PINCTRL_SY1XX
5+
bool "Sensry sy1xx pin controller driver"
6+
default y
7+
depends on DT_HAS_SENSRY_SY1XX_PINCTRL_ENABLED
8+
help
9+
Sensry pin controller driver is used on sy1xx SoC series

drivers/pinctrl/pinctrl_sy1xx.c

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright (c) 2024 sensry.io
4+
*/
5+
6+
#define DT_DRV_COMPAT sensry_sy1xx_pinctrl
7+
8+
#include <zephyr/drivers/pinctrl.h>
9+
#include <zephyr/device.h>
10+
#include <zephyr/devicetree.h>
11+
12+
#include <zephyr/arch/common/sys_io.h>
13+
14+
static uint32_t pinctrl0_base_addr = DT_REG_ADDR(DT_NODELABEL(pinctrl));
15+
static uint32_t pinctrl0_base_mask = DT_REG_SIZE(DT_NODELABEL(pinctrl)) - 1;
16+
17+
/**
18+
* @brief Configure a pin.
19+
*
20+
* @param pin The pin to configure.
21+
*/
22+
static int pinctrl_configure_pin(const pinctrl_soc_pin_t *pin)
23+
{
24+
uint32_t addr = (pin->addr & pinctrl0_base_mask) | pinctrl0_base_addr;
25+
26+
switch (pin->iro) {
27+
case 0:
28+
case 8:
29+
case 16:
30+
case 24:
31+
/* fall through */
32+
break;
33+
default:
34+
/* invalid inter address offset */
35+
return -EINVAL;
36+
}
37+
38+
uint32_t reg = ~(0xFFUL << pin->iro) & sys_read32(addr);
39+
40+
reg |= FIELD_PREP((0xFFUL << pin->iro), pin->cfg);
41+
sys_write32(reg, addr);
42+
43+
return 0;
44+
}
45+
46+
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg)
47+
{
48+
ARG_UNUSED(reg);
49+
50+
for (uint8_t i = 0U; i < pin_cnt; i++) {
51+
int ret = pinctrl_configure_pin(pins++);
52+
53+
if (ret < 0) {
54+
return ret;
55+
}
56+
}
57+
58+
return 0;
59+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# Copyright (c) 2024 sensry.io
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
The sensry SY1xx pin controller is a single node responsible for controlling
6+
pin configuration, such as pull-up, pull-down, tri-state, ...
7+
8+
The node has the 'pinctrl0' node label set in your SoC's devicetree,
9+
so you can modify it like this:
10+
11+
&pinctrl0 {
12+
/* your modifications go here */
13+
};
14+
15+
For example:
16+
&pinctrl0 {
17+
18+
/* UART0 */
19+
uart0_tx: uart0_tx {
20+
pinmux = <SY1XX_UART0_PAD_CFG0 SY1XX_PAD(0)>;
21+
};
22+
23+
uart0_rx: uart0_rx {
24+
pinmux = <SY1XX_UART0_PAD_CFG0 SY1XX_PAD(1)>;
25+
input-enable;
26+
};
27+
}
28+
29+
Then define the uart:
30+
&uart0 {
31+
pinctrl-0 = <&uart0_tx &uart0_rx>;
32+
pinctrl-names = "default";
33+
};
34+
35+
Every pin configuration will be configured in a 32bit register. The configuration
36+
itself is 8bit wide. So we have a number of 4 pin configurations per 32bit register.
37+
38+
The pinmux describes the registers address and the offset [0, 8, 16, 24] for
39+
the individual configuration.
40+
41+
Allowed modifiers for each pin are:
42+
- bias-high-impedance
43+
- bias-pull-down
44+
- bias-pull-up
45+
- input-enable
46+
- input-schmitt-enable
47+
48+
compatible: "sensry,sy1xx-pinctrl"
49+
50+
include: base.yaml
51+
52+
properties:
53+
reg:
54+
required: true
55+
56+
child-binding:
57+
description: Each child node defines the configuration of a particular state.
58+
59+
include:
60+
- name: pincfg-node.yaml
61+
property-allowlist:
62+
- bias-high-impedance
63+
- bias-pull-down
64+
- bias-pull-up
65+
- input-enable
66+
- input-schmitt-enable
67+
68+
properties:
69+
pinmux:
70+
required: true
71+
type: array
72+
description: |
73+
Pin mux selection. See the SOC level pinctrl header
74+
for a defined list of these options.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright (c) 2024 sensry.io
4+
*/
5+
6+
#ifndef _ZEPHYR_DT_BINDINGS_PINCTRL_SY1XX_PINCTRL_
7+
#define _ZEPHYR_DT_BINDINGS_PINCTRL_SY1XX_PINCTRL_
8+
9+
#define SY1XX_PAD(pad) (pad * 8)
10+
11+
#define SY1XX_UART0_PAD_CFG0 0x0020
12+
#define SY1XX_UART1_PAD_CFG0 0x0024
13+
#define SY1XX_UART2_PAD_CFG0 0x0028
14+
15+
#define SY1XX_SPI0_PAD_CFG0 0x002c
16+
#define SY1XX_SPI0_PAD_CFG1 0x0030
17+
18+
#define SY1XX_SPI1_PAD_CFG0 0x0034
19+
#define SY1XX_SPI1_PAD_CFG1 0x0038
20+
21+
#define SY1XX_SPI2_PAD_CFG0 0x003c
22+
#define SY1XX_SPI2_PAD_CFG1 0x0040
23+
24+
#define SY1XX_SPI3_PAD_CFG0 0x0044
25+
#define SY1XX_SPI3_PAD_CFG1 0x0048
26+
27+
#define SY1XX_SPI4_PAD_CFG0 0x004c
28+
#define SY1XX_SPI4_PAD_CFG1 0x0050
29+
30+
#define SY1XX_SPI5_PAD_CFG0 0x0054
31+
#define SY1XX_SPI5_PAD_CFG1 0x0058
32+
33+
#define SY1XX_SPI6_PAD_CFG0 0x005c
34+
#define SY1XX_SPI6_PAD_CFG1 0x0060
35+
36+
#define SY1XX_I2C0_PAD_CFG0 0x0100
37+
#define SY1XX_I2C1_PAD_CFG0 0x0104
38+
#define SY1XX_I2C2_PAD_CFG0 0x0108
39+
#define SY1XX_I2C3_PAD_CFG0 0x010c
40+
41+
#define SY1XX_GPIO0_PAD_CFG0 0x0110
42+
#define SY1XX_GPIO0_PAD_CFG1 0x0114
43+
#define SY1XX_GPIO0_PAD_CFG2 0x0118
44+
#define SY1XX_GPIO0_PAD_CFG3 0x011c
45+
#define SY1XX_GPIO0_PAD_CFG4 0x0120
46+
#define SY1XX_GPIO0_PAD_CFG5 0x0124
47+
#define SY1XX_GPIO0_PAD_CFG6 0x0128
48+
#define SY1XX_GPIO0_PAD_CFG7 0x012c
49+
50+
#define SY1XX_RGMII0_PAD_CFG0 0x0130
51+
#define SY1XX_RGMII0_PAD_CFG1 0x0134
52+
#define SY1XX_RGMII0_PAD_CFG2 0x0138
53+
#define SY1XX_RGMII0_PAD_CFG3 0x013c
54+
55+
#define SY1XX_CAN0_PAD_CFG0 0x0140
56+
57+
#define SY1XX_I2S0_PAD_CFG0 0x0144
58+
#define SY1XX_I2S1_PAD_CFG0 0x0148
59+
#define SY1XX_I2S2_PAD_CFG0 0x014c
60+
#define SY1XX_I2S3_PAD_CFG0 0x0150
61+
62+
#define SY1XX_HBUS0_PAD_CFG0 0x0154
63+
#define SY1XX_HBUS0_PAD_CFG1 0x0158
64+
#define SY1XX_HBUS0_PAD_CFG2 0x015c
65+
#define SY1XX_HBUS0_PAD_CFG3 0x0160
66+
67+
#define SY1XX_QSPI0_PAD_CFG0 0x0164
68+
#define SY1XX_QSPI0_PAD_CFG1 0x0168
69+
70+
#endif /* _ZEPHYR_DT_BINDINGS_PINCTRL_SY1XX_PINCTRL_ */
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright (c) 2024 sensry.io
4+
*/
5+
6+
#ifndef GANYMED_SY1XX_PINCTRL_SOC_H
7+
#define GANYMED_SY1XX_PINCTRL_SOC_H
8+
9+
#include <stdint.h>
10+
11+
#include <zephyr/devicetree.h>
12+
13+
#ifdef __cplusplus
14+
extern "C" {
15+
#endif
16+
17+
#define SY1XX_SCHMITT_ENABLE 1U
18+
#define SY1XX_PULL_UP_ENABLE 1U
19+
#define SY1XX_PULL_DOWN_ENABLE 1U
20+
#define SY1XX_TRISTATE_ENABLE 1U
21+
#define SY1XX_OUTPUT_ENABLE 1U
22+
23+
#define SY1XX_PAD_SCHMITT_OFFS 7
24+
#define SY1XX_PAD_PULL_UP_OFFS 5
25+
#define SY1XX_PAD_PULL_DOWN_OFFS 4
26+
#define SY1XX_PAD_DRIVE_OFFS 2
27+
#define SY1XX_PAD_TRISTATE_OFFS 1
28+
#define SY1XX_PAD_DIR_OFFS 0
29+
30+
/** Type for SY1XX pin. */
31+
typedef struct {
32+
/** address of pin config register */
33+
uint32_t addr;
34+
/** intra register offset (8bit cfg per pin) */
35+
uint32_t iro;
36+
/** config for pin (8bit), describes pull-up/down, ... */
37+
uint32_t cfg;
38+
} pinctrl_soc_pin_t;
39+
40+
#define Z_PINCTRL_CFG(node) \
41+
( \
42+
\
43+
(SY1XX_SCHMITT_ENABLE * DT_PROP(node, input_schmitt_enable)) \
44+
<< SY1XX_PAD_SCHMITT_OFFS | \
45+
(SY1XX_PULL_UP_ENABLE * DT_PROP(node, bias_pull_up)) << SY1XX_PAD_PULL_UP_OFFS | \
46+
(SY1XX_PULL_DOWN_ENABLE * DT_PROP(node, bias_pull_down)) \
47+
<< SY1XX_PAD_PULL_DOWN_OFFS | \
48+
(SY1XX_TRISTATE_ENABLE * DT_PROP(node, bias_high_impedance)) \
49+
<< SY1XX_PAD_TRISTATE_OFFS | \
50+
(SY1XX_OUTPUT_ENABLE & (1 - DT_PROP(node, input_enable))) << SY1XX_PAD_DIR_OFFS \
51+
\
52+
)
53+
54+
#define Z_PINCTRL_STATE_PIN_INIT(node, pr, idx) \
55+
{ \
56+
\
57+
.addr = DT_PROP_BY_IDX(DT_PHANDLE_BY_IDX(node, pr, idx), pinmux, 0), \
58+
.iro = DT_PROP_BY_IDX(DT_PHANDLE_BY_IDX(node, pr, idx), pinmux, 1), \
59+
.cfg = Z_PINCTRL_CFG(DT_PHANDLE_BY_IDX(node, pr, idx)) \
60+
\
61+
},
62+
63+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
64+
{ \
65+
DT_FOREACH_PROP_ELEM(node_id, prop, Z_PINCTRL_STATE_PIN_INIT) \
66+
}
67+
68+
#ifdef __cplusplus
69+
}
70+
#endif
71+
72+
#endif /* GANYMED_SY1XX_PINCTRL_SOC_H */

0 commit comments

Comments
 (0)