Skip to content

Commit e2ed8cf

Browse files
vaishnavachathcfriedt
authored andcommitted
drivers: pinctrl: add CC13XX/CC26XX pinctrl driver
Add pinctrl driver for CC13XX/CC26XX family of SoCs to facilitate transition from pinmux to pinctrl. `IOCPortConfigureSet()` from TI hal driverlib used to implement the generic pinctrl driver. Signed-off-by: Vaishnav Achath <[email protected]>
1 parent bb98bd6 commit e2ed8cf

File tree

7 files changed

+256
-0
lines changed

7 files changed

+256
-0
lines changed

drivers/pinctrl/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ zephyr_library_sources_ifdef(CONFIG_PINCTRL_MCHP_XEC pinctrl_mchp_xec.c)
1717
zephyr_library_sources_ifdef(CONFIG_PINCTRL_MCUX_RT pinctrl_mcux_rt.c)
1818
zephyr_library_sources_ifdef(CONFIG_PINCTRL_SIFIVE pinctrl_sifive.c)
1919
zephyr_library_sources_ifdef(CONFIG_PINCTRL_NXP_IOCON pinctrl_lpc_iocon.c)
20+
zephyr_library_sources_ifdef(CONFIG_PINCTRL_CC13XX_CC26XX pinctrl_cc13xx_cc26xx.c)

drivers/pinctrl/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,6 @@ source "drivers/pinctrl/Kconfig.xec"
4242
source "drivers/pinctrl/Kconfig.mcux"
4343
source "drivers/pinctrl/Kconfig.sifive"
4444
source "drivers/pinctrl/Kconfig.lpc_iocon"
45+
source "drivers/pinctrl/Kconfig.cc13xx_cc26xx"
4546

4647
endif # PINCTRL
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2022 Vaishnav Achath
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
DT_COMPAT_CC13XX_CC26XX_PINCTRL := ti,cc13xx-cc26xx-pinctrl
5+
6+
config PINCTRL_CC13XX_CC26XX
7+
bool "TI SimpleLink CC13xx / CC26xx pinctrl driver"
8+
depends on SOC_SERIES_CC13X2_CC26X2
9+
default $(dt_compat_enabled,$(DT_COMPAT_CC13XX_CC26XX_PINCTRL))
10+
help
11+
Enable the TI SimpleLink CC13xx / CC26xx pinctrl driver
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) 2022 Vaishnav Achath
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define DT_DRV_COMPAT ti_cc13xx_cc26xx_pinctrl
8+
9+
#include <drivers/pinctrl.h>
10+
11+
#include <driverlib/ioc.h>
12+
13+
static int pinctrl_c13xx_cc26xx_set(uint32_t pin, uint32_t func, uint32_t mode)
14+
{
15+
if (pin >= NUM_IO_MAX || func >= NUM_IO_PORTS) {
16+
return -EINVAL;
17+
}
18+
19+
IOCPortConfigureSet(pin, func, mode);
20+
21+
return 0;
22+
}
23+
24+
int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg)
25+
{
26+
ARG_UNUSED(reg);
27+
28+
for (uint8_t i = 0U; i < pin_cnt; i++) {
29+
pinctrl_c13xx_cc26xx_set(pins[i].pin, pins[i].iofunc, pins[i].iomode);
30+
}
31+
32+
return 0;
33+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Copyright (c) 2022 Vaishnav Achath
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
TI SimpleLink CC13xx / CC26xx pinctrl node.
6+
7+
Device pin configuration should be placed in the child nodes of this node.
8+
Populate the 'pinmux' field with a pair consisting of a pin number and its IO
9+
functions.
10+
11+
The node has the 'pinctrl' node label set in your SoC's devicetree,
12+
so you can modify it like this:
13+
14+
&pinctrl {
15+
/* your modifications go here */
16+
};
17+
18+
All device pin configurations should be placed in child nodes of the
19+
'pinctrl' node, as in the i2c0 example shown at the end.
20+
21+
Here is a list of
22+
supported standard pin properties:
23+
24+
- bias-disable: Disable pull-up/down.
25+
- bias-pull-down: Enable pull-down resistor.
26+
- bias-pull-up: Enable pull-up resistor.
27+
- drive-open-drain: Output driver is open-drain.
28+
- drive-open-drain: Output driver is open-source.
29+
- input-enable: enable input.
30+
- input-schmitt-enable: enable input schmitt circuit.
31+
32+
An example for CC13XX family, include the chip level pinctrl
33+
DTSI file in the board level DTS:
34+
35+
#include <dt-bindings/pinctrl/cc13xx_cc26xx-pinctrl.h>
36+
37+
We want to configure the I2C pins to open drain, with pullup enabled
38+
and input enabled.
39+
40+
To change a pin's pinctrl default properties add a reference to the
41+
pin in the board's DTS file and set the properties.
42+
43+
&i2c0 {
44+
pinctrl-0 = <&i2c0_scl_default &i2c0_sda_default>;
45+
pinctrl-1 = <&i2c0_scl_sleep &i2c0_sda_sleep>;
46+
pinctrl-names = "default", "sleep";
47+
}
48+
49+
The i2c0_scl_default corresponds to the following in the board dts file:
50+
51+
&pinctrl {
52+
i2c0_scl_default: i2c0_scl_default {
53+
pinmux = <4 IOC_PORT_MCU_I2C_MSSCL>;
54+
bias-pull-up;
55+
drive-open-drain;
56+
input-enable;
57+
};
58+
};
59+
60+
compatible: "ti,cc13xx-cc26xx-pinctrl"
61+
62+
include:
63+
- name: base.yaml
64+
- name: pincfg-node.yaml
65+
child-binding:
66+
property-allowlist:
67+
- bias-disable
68+
- bias-pull-down
69+
- bias-pull-up
70+
- drive-open-drain
71+
- drive-open-source
72+
- input-enable
73+
- input-schmitt-enable
74+
75+
properties:
76+
reg:
77+
required: true
78+
79+
child-binding:
80+
description: |
81+
This binding gives a base representation of the CC13XX/CC26XX
82+
pins configuration.
83+
properties:
84+
pinmux:
85+
required: true
86+
type: array
87+
description: |
88+
CC13XX/CC26XX pin's configuration (IO pin, IO function).
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*
2+
* Copyright (c) 2015 - 2017, Texas Instruments Incorporated
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef CC13XX_CC26XX_PINCTRL_COMMON_H_
8+
#define CC13XX_CC26XX_PINCTRL_COMMON_H_
9+
10+
/* Adapted from hal/ti/simplelink/source/ti/devices/cc13x2_cc26x2/driverlib/ioc.h */
11+
12+
/* IOC Peripheral Port Mapping */
13+
#define IOC_PORT_GPIO 0x00000000 /* Default general purpose IO usage */
14+
#define IOC_PORT_AON_CLK32K 0x00000007 /* AON External 32kHz clock */
15+
#define IOC_PORT_AUX_IO 0x00000008 /* AUX IO Pin */
16+
#define IOC_PORT_MCU_SSI0_RX 0x00000009 /* MCU SSI0 Receive Pin */
17+
#define IOC_PORT_MCU_SSI0_TX 0x0000000A /* MCU SSI0 Transmit Pin */
18+
#define IOC_PORT_MCU_SSI0_FSS 0x0000000B /* MCU SSI0 FSS Pin */
19+
#define IOC_PORT_MCU_SSI0_CLK 0x0000000C /* MCU SSI0 Clock Pin */
20+
#define IOC_PORT_MCU_I2C_MSSDA 0x0000000D /* MCU I2C Data Pin */
21+
#define IOC_PORT_MCU_I2C_MSSCL 0x0000000E /* MCU I2C Clock Pin */
22+
#define IOC_PORT_MCU_UART0_RX 0x0000000F /* MCU UART0 Receive Pin */
23+
#define IOC_PORT_MCU_UART0_TX 0x00000010 /* MCU UART0 Transmit Pin */
24+
#define IOC_PORT_MCU_UART0_CTS 0x00000011 /* MCU UART0 Clear To Send Pin */
25+
#define IOC_PORT_MCU_UART0_RTS 0x00000012 /* MCU UART0 Request To Send Pin */
26+
#define IOC_PORT_MCU_UART1_RX 0x00000013 /* MCU UART1 Receive Pin */
27+
#define IOC_PORT_MCU_UART1_TX 0x00000014 /* MCU UART1 Transmit Pin */
28+
#define IOC_PORT_MCU_UART1_CTS 0x00000015 /* MCU UART1 Clear To Send Pin */
29+
#define IOC_PORT_MCU_UART1_RTS 0x00000016 /* MCU UART1 Request To Send Pin */
30+
#define IOC_PORT_MCU_PORT_EVENT0 0x00000017 /* MCU PORT EVENT 0 */
31+
#define IOC_PORT_MCU_PORT_EVENT1 0x00000018 /* MCU PORT EVENT 1 */
32+
#define IOC_PORT_MCU_PORT_EVENT2 0x00000019 /* MCU PORT EVENT 2 */
33+
#define IOC_PORT_MCU_PORT_EVENT3 0x0000001A /* MCU PORT EVENT 3 */
34+
#define IOC_PORT_MCU_PORT_EVENT4 0x0000001B /* MCU PORT EVENT 4 */
35+
#define IOC_PORT_MCU_PORT_EVENT5 0x0000001C /* MCU PORT EVENT 5 */
36+
#define IOC_PORT_MCU_PORT_EVENT6 0x0000001D /* MCU PORT EVENT 6 */
37+
#define IOC_PORT_MCU_PORT_EVENT7 0x0000001E /* MCU PORT EVENT 7 */
38+
#define IOC_PORT_MCU_SWV 0x00000020 /* Serial Wire Viewer */
39+
#define IOC_PORT_MCU_SSI1_RX 0x00000021 /* MCU SSI1 Receive Pin */
40+
#define IOC_PORT_MCU_SSI1_TX 0x00000022 /* MCU SSI1 Transmit Pin */
41+
#define IOC_PORT_MCU_SSI1_FSS 0x00000023 /* MCU SSI1 FSS Pin */
42+
#define IOC_PORT_MCU_SSI1_CLK 0x00000024 /* MCU SSI1 Clock Pin */
43+
#define IOC_PORT_MCU_I2S_AD0 0x00000025 /* MCU I2S Data Pin 0 */
44+
#define IOC_PORT_MCU_I2S_AD1 0x00000026 /* MCU I2S Data Pin 1 */
45+
#define IOC_PORT_MCU_I2S_WCLK 0x00000027 /* MCU I2S Frame/Word Clock */
46+
#define IOC_PORT_MCU_I2S_BCLK 0x00000028 /* MCU I2S Bit Clock */
47+
#define IOC_PORT_MCU_I2S_MCLK 0x00000029 /* MCU I2S Master clock 2 */
48+
#define IOC_PORT_RFC_TRC 0x0000002E /* RF Core Tracer */
49+
#define IOC_PORT_RFC_GPO0 0x0000002F /* RC Core Data Out Pin 0 */
50+
#define IOC_PORT_RFC_GPO1 0x00000030 /* RC Core Data Out Pin 1 */
51+
#define IOC_PORT_RFC_GPO2 0x00000031 /* RC Core Data Out Pin 2 */
52+
#define IOC_PORT_RFC_GPO3 0x00000032 /* RC Core Data Out Pin 3 */
53+
#define IOC_PORT_RFC_GPI0 0x00000033 /* RC Core Data In Pin 0 */
54+
#define IOC_PORT_RFC_GPI1 0x00000034 /* RC Core Data In Pin 1 */
55+
#define IOC_PORT_RFC_SMI_DL_OUT 0x00000035 /* RF Core SMI Data Link Out */
56+
#define IOC_PORT_RFC_SMI_DL_IN 0x00000036 /* RF Core SMI Data Link in */
57+
#define IOC_PORT_RFC_SMI_CL_OUT 0x00000037 /* RF Core SMI Command Link Out */
58+
#define IOC_PORT_RFC_SMI_CL_IN 0x00000038 /* RF Core SMI Command Link In */
59+
60+
#endif /* CC13XX_CC26XX_PINCTRL_COMMON_H_ */
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* Copyright (c) 2022 Vaishnav Achath
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef TI_SIMPLELINK_CC13XX_CC26XX_SOC_PINCTRL_H_
8+
#define TI_SIMPLELINK_CC13XX_CC26XX_SOC_PINCTRL_H_
9+
10+
#include <zephyr/types.h>
11+
12+
/* Defines for enabling/disabling an IO */
13+
#define IOC_SLEW_ENABLE 0x00001000
14+
#define IOC_SLEW_DISABLE 0x00000000
15+
#define IOC_INPUT_ENABLE 0x20000000
16+
#define IOC_INPUT_DISABLE 0x00000000
17+
#define IOC_HYST_ENABLE 0x40000000
18+
#define IOC_HYST_DISABLE 0x00000000
19+
20+
/* Defines that can be used to set the IO Mode of an IO */
21+
#define IOC_IOMODE_NORMAL 0x00000000
22+
#define IOC_IOMODE_INV 0x01000000
23+
#define IOC_IOMODE_OPEN_DRAIN_NORMAL 0x04000000
24+
#define IOC_IOMODE_OPEN_DRAIN_INV 0x05000000
25+
#define IOC_IOMODE_OPEN_SRC_NORMAL 0x06000000
26+
#define IOC_IOMODE_OPEN_SRC_INV 0x07000000
27+
28+
/* Defines that can be used to set pull on an IO */
29+
#define IOC_NO_IOPULL 0x00006000
30+
#define IOC_IOPULL_UP 0x00004000
31+
#define IOC_IOPULL_DOWN 0x00002000
32+
33+
typedef struct pinctrl_soc_pin_t {
34+
uint32_t pin;
35+
uint32_t iofunc;
36+
uint32_t iomode;
37+
} pinctrl_soc_pin_t;
38+
39+
/* Convert DT flags to SoC flags */
40+
#define CC13XX_CC26XX_PIN_FLAGS(node_id) \
41+
(DT_PROP(node_id, bias_pull_up) * IOC_IOPULL_UP | \
42+
DT_PROP(node_id, bias_pull_down) * IOC_IOPULL_DOWN | \
43+
DT_PROP(node_id, bias_disable) * IOC_NO_IOPULL | \
44+
DT_PROP(node_id, drive_open_drain) * IOC_IOMODE_OPEN_DRAIN_NORMAL | \
45+
DT_PROP(node_id, drive_open_source) * IOC_IOMODE_OPEN_SRC_NORMAL | \
46+
DT_PROP(node_id, input_enable) * IOC_INPUT_ENABLE | \
47+
DT_PROP(node_id, input_schmitt_enable) * IOC_HYST_ENABLE)
48+
49+
#define CC13XX_CC26XX_DT_PIN(node_id) \
50+
{ \
51+
.pin = DT_PROP_BY_IDX(node_id, pinmux, 0), \
52+
.iofunc = DT_PROP_BY_IDX(node_id, pinmux, 1), \
53+
.iomode = CC13XX_CC26XX_PIN_FLAGS(node_id) \
54+
},
55+
56+
#define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) \
57+
CC13XX_CC26XX_DT_PIN(DT_PROP_BY_IDX(node_id, prop, idx))
58+
59+
#define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
60+
{ DT_FOREACH_PROP_ELEM(node_id, prop, Z_PINCTRL_STATE_PIN_INIT) }
61+
62+
#endif /* TI_SIMPLELINK_CC13XX_CC26XX_SOC_PINCTRL_H_ */

0 commit comments

Comments
 (0)