Skip to content

Commit d415543

Browse files
MyGh64605Michael Sherwood
authored andcommitted
drivers: pinctrl Addition of pic32cxsg pin control
Addition of pic32cxsg pin control including yaml, bindings, Kconfig, Signed-off-by: Michael D Sherwood <[email protected]>
1 parent e3ee532 commit d415543

File tree

6 files changed

+251
-0
lines changed

6 files changed

+251
-0
lines changed

drivers/pinctrl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ zephyr_library_sources_ifdef(CONFIG_PINCTRL_NRF pinctrl_nrf.c)
1919
zephyr_library_sources_ifdef(CONFIG_PINCTRL_RPI_PICO pinctrl_rpi_pico.c)
2020
zephyr_library_sources_ifdef(CONFIG_PINCTRL_SAM pinctrl_sam.c)
2121
zephyr_library_sources_ifdef(CONFIG_PINCTRL_SAM0 pinctrl_sam0.c)
22+
zephyr_library_sources_ifdef(CONFIG_PINCTRL_PIC32CXSG pinctrl_sam0.c)
2223
zephyr_library_sources_ifdef(CONFIG_PINCTRL_STM32 pinctrl_stm32.c)
2324
zephyr_library_sources_ifdef(CONFIG_PINCTRL_NXP_PORT pinctrl_nxp_port.c)
2425
zephyr_library_sources_ifdef(CONFIG_PINCTRL_MCHP_XEC pinctrl_mchp_xec.c)

drivers/pinctrl/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ source "drivers/pinctrl/Kconfig.nrf"
4848
source "drivers/pinctrl/Kconfig.rpi_pico"
4949
source "drivers/pinctrl/Kconfig.sam"
5050
source "drivers/pinctrl/Kconfig.sam0"
51+
source "drivers/pinctrl/Kconfig.pic32cxsg"
5152
source "drivers/pinctrl/Kconfig.stm32"
5253
source "drivers/pinctrl/Kconfig.nxp_port"
5354
source "drivers/pinctrl/Kconfig.xec"

drivers/pinctrl/Kconfig.pic32cxsg

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2024, Microchip
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config PINCTRL_PIC32CXSG
5+
bool "Microchip PIC32CXSG pin controller driver"
6+
default y
7+
depends on DT_HAS_MICROCHIP_PIC32CXSG_PINCTRL_ENABLED
8+
help
9+
Microchip pin controller driver is used on PIC32CXSG SoC series
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Copyright (c) 2024 Microchip
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
Microchip PIC32CXSG Pinctrl container node
6+
7+
The Microchip PIC32CXSG pin controller is a singleton node responsible for controlling
8+
pin function selection and pin properties. For example, you can use this node
9+
to route SERCOM0 as UART were RX to pin PAD1 and enable the pull-up resistor
10+
on the pin.
11+
12+
The node has the 'pinctrl' node label set in your SoC's devicetree, so you can
13+
modify it like this:
14+
15+
&pinctrl {
16+
/* your modifications go here */
17+
};
18+
19+
All device pin configurations should be placed in child nodes of the 'pinctrl'
20+
node, as shown in this example:
21+
22+
/** You can put this in places like a <board>-pinctrl.dtsi file in
23+
* your board directory, or a devicetree overlay in your application.
24+
*/
25+
26+
/** include pre-defined combinations for the SoC variant used by the board */
27+
#include <dt-bindings/pinctrl/microchip_pic32cxsg_pinctrl.h>
28+
29+
&pinctrl {
30+
/* configuration for the usart0 "default" state */
31+
sercom0_uart_default: sercom0_uart_default {
32+
/* group 1 */
33+
group1 {
34+
/* configure PA6 as USART0 TX and PA8 as USART0 CTS */
35+
pinmux = <PA5D_SERCOM0_PAD1>, <PA6D_SERCOM0_PAD2>;
36+
};
37+
/* group 2 */
38+
group2 {
39+
/* configure PA5 as USART0 RX and PA7 as USART0 RTS */
40+
pinmux = <PA4D_SERCOM0_PAD0>, <PA7D_SERCOM0_PAD3>;
41+
/* both PA5 and PA7 have pull-up enabled */
42+
bias-pull-up;
43+
};
44+
};
45+
};
46+
47+
The 'usart0_default' child node encodes the pin configurations for a
48+
particular state of a device; in this case, the default (that is, active)
49+
state.
50+
51+
As shown, pin configurations are organized in groups within each child node.
52+
Each group can specify a list of pin function selections in the 'pinmux'
53+
property.
54+
55+
A group can also specify shared pin properties common to all the specified
56+
pins, such as the 'bias-pull-up' property in group 2. Here is a list of
57+
supported standard pin properties:
58+
59+
- bias-pull-up: Enable pull-up resistor.
60+
- bias-pull-down: Enable pull-down resistor.
61+
- drive-strength: Increase sink current.
62+
- input-enable: Enable input on pin.
63+
- output-enable: Enable output on a pin without actively driving it.
64+
65+
To link pin configurations with a device, use a pinctrl-N property for some
66+
number N, like this example you could place in your board's DTS file:
67+
68+
#include "board-pinctrl.dtsi"
69+
70+
&usart0 {
71+
pinctrl-0 = <&usart0_default>;
72+
pinctrl-names = "default";
73+
};
74+
75+
compatible: "microchip,pic32cxsg-pinctrl"
76+
77+
include: base.yaml
78+
79+
properties:
80+
"#address-cells":
81+
required: true
82+
const: 1
83+
"#size-cells":
84+
required: true
85+
const: 1
86+
87+
child-binding:
88+
description: |
89+
Each child node defines the configuration for a particular state.
90+
child-binding:
91+
description: |
92+
The grandchild nodes group pins that share the pic32cxsg pin configuration.
93+
94+
include:
95+
- name: pincfg-node.yaml
96+
property-allowlist:
97+
- bias-pull-up
98+
- bias-pull-down
99+
- drive-strength
100+
- input-enable
101+
- output-enable
102+
103+
properties:
104+
pinmux:
105+
required: true
106+
type: array
107+
description: |
108+
An array of pins sharing the pic32cxsg group properties. The pins should
109+
be defined using pre-defined macros or, alternatively, using the
110+
SAM_PINCTRL utility macros depending on the pinmux model used by the
111+
SoC series.
112+
drive-strength:
113+
enum:
114+
- 0
115+
- 1
116+
default: 0
117+
description: |
118+
The drive strength controls the output driver strength of an I/O pin
119+
configured as an output.
120+
0: Pin drive strength is set to normal drive strength.
121+
1: Pin drive strength is set to stronger drive strength.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
description: Microchip PIC32CXSG PINMUX
2+
3+
compatible: "microchip,pic32cxsg-pinmux"
4+
5+
include: base.yaml
6+
7+
properties:
8+
reg:
9+
required: true
10+
11+
pinmux-cells:
12+
- pin
13+
- function
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* Copyright (c) 2024 Microchip
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/**
8+
* @file
9+
* Microchip PIC32CXSG SoC specific helpers for pinctrl driver
10+
*/
11+
12+
#ifndef ZEPHYR_INCLUDE_DRIVERS_PINCTRL_PINCTRL_SOC_PIC32CXSG_COMMON_H_
13+
#define ZEPHYR_INCLUDE_DRIVERS_PINCTRL_PINCTRL_SOC_PIC32CXSG_COMMON_H_
14+
15+
#include <zephyr/devicetree.h>
16+
#include <zephyr/types.h>
17+
#include <dt-bindings/pinctrl/microchip_pic32cxsg_pinctrl.h>
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif
22+
23+
/** @cond INTERNAL_HIDDEN */
24+
25+
/** @brief Type for PIC32CXSG pin.
26+
*
27+
* Bits:
28+
* - 0-15: PIC32CXSG pinmux bit field (@ref SAM_PINMUX).
29+
* - 16-21: Pin flags bit field (@ref PIC32CXSG_PINFLAGS).
30+
* - 22-31: Reserved.
31+
*/
32+
typedef uint32_t pinctrl_soc_pin_t;
33+
34+
/**
35+
* @brief Utility macro to initialize each pin.
36+
*
37+
* @param node_id Node identifier.
38+
* @param prop Property name.
39+
* @param idx Property entry index.
40+
*/
41+
/* (CONFIG_SOC_FAMILY_MICROCHIP_PIC32CXSG) */
42+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
43+
((DT_PROP_BY_IDX(node_id, prop, idx) << SAM_PINCTRL_PINMUX_POS) \
44+
| (DT_PROP(node_id, bias_pull_up) << SAM_PINCTRL_PULLUP_POS) \
45+
| (DT_PROP(node_id, bias_pull_down) << SAM_PINCTRL_PULLDOWN_POS) \
46+
| (DT_PROP(node_id, input_enable) << SAM_PINCTRL_INPUTENABLE_POS) \
47+
| (DT_PROP(node_id, output_enable) << SAM_PINCTRL_OUTPUTENABLE_POS) \
48+
| (DT_ENUM_IDX(node_id, drive_strength) << SAM_PINCTRL_DRIVESTRENGTH_POS)\
49+
),
50+
51+
/**
52+
* @brief Utility macro to initialize state pins contained in a given property.
53+
*
54+
* @param node_id Node identifier.
55+
* @param prop Property name describing state pins.
56+
*/
57+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
58+
{DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), \
59+
DT_FOREACH_PROP_ELEM, pinmux, \
60+
Z_PINCTRL_STATE_PIN_INIT)}
61+
62+
/** @endcond */
63+
64+
/**
65+
* @brief Pin flags/attributes
66+
* @anchor PIC32CXSG_PINFLAGS
67+
*
68+
* @{
69+
*/
70+
71+
#define SAM_PINCTRL_FLAGS_DEFAULT (0U)
72+
#define SAM_PINCTRL_FLAGS_POS (0U)
73+
#define SAM_PINCTRL_FLAGS_MASK (0x3F << SAM_PINCTRL_FLAGS_POS)
74+
#define SAM_PINCTRL_FLAG_MASK (1U)
75+
#define SAM_PINCTRL_PULLUP_POS (SAM_PINCTRL_FLAGS_POS)
76+
#define SAM_PINCTRL_PULLUP (1U << SAM_PINCTRL_PULLUP_POS)
77+
#define SAM_PINCTRL_PULLDOWN_POS (SAM_PINCTRL_PULLUP_POS + 1U)
78+
#define SAM_PINCTRL_PULLDOWN (1U << SAM_PINCTRL_PULLDOWN_POS)
79+
#define SAM_PINCTRL_OPENDRAIN_POS (SAM_PINCTRL_PULLDOWN_POS + 1U)
80+
#define SAM_PINCTRL_OPENDRAIN (1U << SAM_PINCTRL_OPENDRAIN_POS)
81+
#define SAM_PINCTRL_INPUTENABLE_POS (SAM_PINCTRL_OPENDRAIN_POS + 1U)
82+
#define SAM_PINCTRL_INPUTENABLE (1U << SAM_PINCTRL_INPUTENABLE_POS)
83+
#define SAM_PINCTRL_OUTPUTENABLE_POS (SAM_PINCTRL_INPUTENABLE_POS + 1U)
84+
#define SAM_PINCTRL_OUTPUTENABLE (1U << SAM_PINCTRL_OUTPUTENABLE_POS)
85+
#define SAM_PINCTRL_DRIVESTRENGTH_POS (SAM_PINCTRL_OUTPUTENABLE_POS + 1U)
86+
#define SAM_PINCTRL_DRIVESTRENGTH (1U << SAM_PINCTRL_DRIVESTRENGTH_POS)
87+
88+
/** @} */
89+
90+
/**
91+
* Obtain Flag value from pinctrl_soc_pin_t configuration.
92+
*
93+
* @param pincfg pinctrl_soc_pin_t bit field value.
94+
* @param pos attribute/flags bit position (@ref PIC32CXSG_PINFLAGS).
95+
*/
96+
#define SAM_PINCTRL_FLAG_GET(pincfg, pos) \
97+
(((pincfg) >> pos) & SAM_PINCTRL_FLAG_MASK)
98+
99+
#define SAM_PINCTRL_FLAGS_GET(pincfg) \
100+
(((pincfg) >> SAM_PINCTRL_FLAGS_POS) & SAM_PINCTRL_FLAGS_MASK)
101+
102+
#ifdef __cplusplus
103+
}
104+
#endif
105+
106+
#endif /* ZEPHYR_INCLUDE_DRIVERS_PINCTRL_PINCTRL_SOC_PIC32CXSG_COMMON_H_ */

0 commit comments

Comments
 (0)