Skip to content

Commit 4197fee

Browse files
committed
drivers: pinctrl: sf32lb: Preserve the SR/IS definition for each register
Only modify the definitions that need to be changed in the pinmux register; SR/IS will retain their default values after reset. Signed-off-by: Haoran Jiang <[email protected]>
1 parent c89f271 commit 4197fee

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

drivers/pinctrl/pinctrl_sf32lb52x.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2025 Core Devices LLC
3+
* Copyright (c) 2025 SiFli Technologies(Nanjing) Co., Ltd
34
* SPDX-License-Identifier: Apache-2.0
45
*/
56

@@ -19,22 +20,29 @@ struct sf32lb52x_pinctrl_config {
1920
struct sf32lb_clock_dt_spec clock;
2021
};
2122

22-
#define SF32LB_PINMUX_MSK \
23-
SF32LB_FSEL_MSK | SF32LB_PE_MSK | SF32LB_PS_MSK | SF32LB_IE_MSK | SF32LB_IS_MSK | \
24-
SF32LB_SR_MSK | SF32LB_DS0_MSK
25-
2623
static int pinctrl_configure_pin(pinctrl_soc_pin_t pin)
2724
{
2825
const struct device *dev = DEVICE_DT_INST_GET(0);
2926
const struct sf32lb52x_pinctrl_config *config = dev->config;
3027
uintptr_t pad;
3128
uint8_t pinr_offset;
29+
uint32_t val;
30+
uint8_t port = FIELD_GET(SF32LB_PORT_MSK, pin);
31+
uint8_t pad_num = FIELD_GET(SF32LB_PAD_MSK, pin);
32+
uint8_t ds = FIELD_GET(SF32LB_DS_MSK, pin);
33+
34+
/*
35+
* PA39-PA42 only have DS1 bit (no DS0), drive-strength must be 0 or 1.
36+
* Check and return error if invalid configuration.
37+
*/
38+
if ((port == SF32LB_PORT_PA) && (pad_num >= 39U) && (pad_num <= 42U) && (ds > 1U)) {
39+
return -EINVAL;
40+
}
3241

3342
/* configure HPSYS_CFG *_PINR if applicable */
3443
pinr_offset = FIELD_GET(SF32LB_PINR_OFFSET_MSK, pin);
3544
if (pinr_offset != 0U) {
3645
uint32_t pinr_msk;
37-
uint32_t val;
3846

3947
pinr_msk = 0xFFU << (8U * FIELD_GET(SF32LB_PINR_FIELD_MSK, pin));
4048
val = sys_read32(config->cfg + pinr_offset);
@@ -57,7 +65,10 @@ static int pinctrl_configure_pin(pinctrl_soc_pin_t pin)
5765

5866
pad += FIELD_GET(SF32LB_PAD_MSK, pin) * 4U;
5967

60-
sys_write32(FIELD_GET(SF32LB_PINMUX_MSK, pin), pad);
68+
val = sys_read32(pad);
69+
val &= ~SF32LB_PINMUX_CFG_MSK;
70+
val |= (pin & SF32LB_PINMUX_CFG_MSK);
71+
sys_write32(val, pad);
6172

6273
return 0;
6374
}

0 commit comments

Comments
 (0)