Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DNM] soc: arm: cypress: psoc6: Introduce pinctrl #28645

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,7 @@
/dts/arm/atmel/samv71* @nandojve
/dts/arm/atmel/ @galak
/dts/arm/broadcom/ @sbranden
/dts/arm/cypress/ @nandojve
/dts/arm/infineon/ @parthitce
/dts/arm/qemu-virt/ @carlocaione
/dts/arm/quicklogic/ @wtatarski @kowalewskijan @kgugala
Expand Down Expand Up @@ -318,6 +319,7 @@
/dts/bindings/i2c/zephyr*i2c-emul.yaml @sjg20
/dts/bindings/iio/adc/st*stm32-adc.yaml @cybertale
/dts/bindings/serial/ns16550.yaml @andrewboie
/dts/bindings/*/cypress* @nandojve
/dts/bindings/*/nordic* @anangl
/dts/bindings/*/nxp* @MaureenHelm
/dts/bindings/*/openisa* @MaureenHelm
Expand Down
100 changes: 100 additions & 0 deletions dts/arm/cypress/pinctrl_cypress_psoc6.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
/*
* Copyright (c) 2020 Linaro Limited
* Copyright (c) 2020 ATL Electronics
* SPDX-License-Identifier: Apache-2.0
*/

#ifndef PINCTRL_CYPRESS_PSOC6_H_
#define PINCTRL_CYPRESS_PSOC6_H_

#include <sys/util_macro.h>

/**
* Functions are defined using HSIOM SEL
*/

#define HSIOM_SEL_gpio 0
#define HSIOM_SEL_gpio_dsi 1
#define HSIOM_SEL_dsi_dsi 2
#define HSIOM_SEL_dsi_gpio 3
#define HSIOM_SEL_amuxa 4
#define HSIOM_SEL_amuxb 5
#define HSIOM_SEL_amuxa_dsi 6
#define HSIOM_SEL_amuxb_dsi 7
#define HSIOM_SEL_act_0 8
#define HSIOM_SEL_act_1 9
#define HSIOM_SEL_act_2 10
#define HSIOM_SEL_act_3 11
#define HSIOM_SEL_ds_0 12
#define HSIOM_SEL_ds_1 13
#define HSIOM_SEL_ds_2 14
#define HSIOM_SEL_ds_3 15
#define HSIOM_SEL_act_4 16
#define HSIOM_SEL_act_5 17
#define HSIOM_SEL_act_6 18
#define HSIOM_SEL_act_7 19
#define HSIOM_SEL_act_8 20
#define HSIOM_SEL_act_9 21
#define HSIOM_SEL_act_10 22
#define HSIOM_SEL_act_11 23
#define HSIOM_SEL_act_12 24
#define HSIOM_SEL_act_13 25
#define HSIOM_SEL_act_14 26
#define HSIOM_SEL_act_15 27
#define HSIOM_SEL_ds_4 28
#define HSIOM_SEL_ds_5 29
#define HSIOM_SEL_ds_6 30
#define HSIOM_SEL_ds_7 31


/* Create a pincfg device tree node:
*
* The node name and nodelabel will be of the form:
*
* NODE = p<port>_<pin>_<inst>_<signal>
*
* NODE: NODE {
* cypress,pins = < &p<port> <port> <pin> HSIOM_SEL_<hsiom> >;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if pin information can be encoded into an uint32, similar to what we do on STM32: https:/zephyrproject-rtos/zephyr/blob/master/include/dt-bindings/pinctrl/stm32-pinctrl.h#L42

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it already is at end:

This is the structure that will handle:

struct soc_gpio_pin {
	GPIO_PRT_Type *regs; /** pointer to registers of the GPIO controller */
	uint32_t pinum;      /** pin number */
	uint32_t flags;      /** pin flags/attributes */
};

The soc/arm/cypress/common/cypress_psoc6_dt.h have a macro CY_PSOC6_DT_PIN that will collect from DT and create above structure at driver level at build time.

The DT_CYPRESS_HSIOM is a variable length argument list that accept flags:
First 5 parameters are mandatory, than flags are added one by one with commas.
DT_CYPRESS_HSIOM(uart5, rx, 5, 0, act_6);
DT_CYPRESS_HSIOM(uart5, rx, 5, 0, act_6, bias-pull-up);
DT_CYPRESS_HSIOM(uart5, rx, 5, 0, act_6, bias-pull-up, input-enable [, etc]);

Above all entries are valid and create a node like:

 p5_0_uart5_rx: p5_0_uart5_rx {
    cypress,pins = <&p5 0x5 0x0 0x12 >;
    bias-pull-up;
    input-enable;
}

The CY_PSOC6_DT_PIN will combine 0x12 (function) + bias-pull-up + input-enable as flags. From &p5 we get reg addr and 0x0 is the pin itself at p5. The remaining 0x5 is the uart instance number and doesn't have nothing to do with pinctrl and probably will be dropped. It was necessary to solve the chicken and egg problem when platform doesn't have nothing.

* flags_1;
* ...
* flags_N;
* }
*
* So for example:
*
* DT_CYPRESS_PIN(uart5, rx, 5, 0, act_6);
*
* Will become:
*
* p5_0_uart5_rx: p5_0_uart5_rx {
* cypress,pins = <&p5 0x5 0x0 0x12 >;
* }
*
* Flags are optional and should be pass one by one as arguments:
*
* DT_CYPRESS_PIN(uart5, rx, 5, 0, act_6, bias-pull-up, input-enable);
*
* Will become:
*
* p5_0_uart5_rx: p5_0_uart5_rx {
* cypress,pins = <&p5 0x5 0x0 0x12 >;
* bias-pull-up;
* input-enable;
* }
*
* For the complete list of flags see cypress,psoc6-pinctrl.yaml
*
*/

#define DT_CYPRESS_HSIOM_FLAG(flag) flag;
#define DT_CYPRESS_HSIOM_FLAGS(...) \
MACRO_MAP_CAT(DT_CYPRESS_HSIOM_FLAG __VA_OPT__(,) __VA_ARGS__)

#define DT_CYPRESS_HSIOM(inst, signal, port, pin, hsiom, ...) \
p##port##_##pin##_##inst##_##signal: \
p##port##_##pin##_##inst##_##signal { \
cypress,pins = < &p##port port pin HSIOM_SEL_##hsiom > ; \
DT_CYPRESS_HSIOM_FLAGS(__VA_ARGS__) \
}

#endif /* PINCTRL_CYPRESS_PSOC6_H_ */
19 changes: 19 additions & 0 deletions dts/arm/cypress/psoc6-pinctrl.dtsi
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2020 ATL Electronics
*
* SPDX-License-Identifier: Apache-2.0
*/

#include "pinctrl_cypress_psoc6.h"

/ {
soc {
pinctrl@40310000 {
/* instance, signal, port, pin, hsiom [, flag1, ... ] */
DT_CYPRESS_HSIOM(uart5, rx, 5, 0, act_6, input-enable);
DT_CYPRESS_HSIOM(uart5, tx, 5, 1, act_6, drive-push-pull);
DT_CYPRESS_HSIOM(uart6, rx, 13, 0, act_6, input-enable);
DT_CYPRESS_HSIOM(uart6, tx, 13, 1, act_6, drive-push-pull);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with this SoC, but if the number of pinctrl options is large, you may consider making pinctrl part of the SoC HAL as we've done for ST.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have intention to move this to HAL and mix Zephyr with Cypress.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't have to be in PDL directly. It could be inside a dts/ at cypress module root.

};
};
};
154 changes: 153 additions & 1 deletion dts/arm/cypress/psoc6.dtsi
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
/*
* Copyright (c) 2018, Cypress
* Copyright (c) 2020, ATL Electronics
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <mem.h>

#include "psoc6-pinctrl.dtsi"

/ {
cpus {
#address-cells = <1>;
Expand Down Expand Up @@ -63,14 +66,163 @@
};

soc {
pinctrl@40310000 {
compatible = "cypress,psoc6-pinctrl";
#address-cells = <1>;
#size-cells = <1>;
ranges = <0x40310000 0x40310000 0x2024>;

hsiom: hsiom@40310000 {
compatible = "cypress,psoc6-hsiom";
reg = <0x40310000 0x2024>;
interrupts = <15 1>, <16 1>;
label = "HSIOM";
};

p0: gpio@40320000 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320000 0x80>;
interrupts = <0 1>;
label = "P0";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p1: gpio@40320080 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320080 0x80>;
interrupts = <1 1>;
label = "P1";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p2: gpio@40320100 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320100 0x80>;
interrupts = <2 1>;
label = "P2";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p3: gpio@40320180 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320180 0x80>;
interrupts = <3 1>;
label = "P3";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p4: gpio@40320200 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320200 0x80>;
interrupts = <4 1>;
label = "P4";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p5: gpio@40320280 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320280 0x80>;
interrupts = <5 1>;
label = "P5";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p6: gpio@40320300 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320300 0x80>;
interrupts = <6 1>;
label = "P6";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p7: gpio@40320380 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320380 0x80>;
interrupts = <7 1>;
label = "P7";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p8: gpio@40320400 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320400 0x80>;
interrupts = <8 1>;
label = "P8";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p9: gpio@40320480 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320480 0x80>;
interrupts = <9 1>;
label = "P9";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p10: gpio@40320500 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320500 0x80>;
interrupts = <10 1>;
label = "P10";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p11: gpio@40320580 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320580 0x80>;
interrupts = <11 1>;
label = "P11";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p12: gpio@40320600 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320600 0x80>;
interrupts = <12 1>;
label = "P12";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p13: gpio@40320680 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320680 0x80>;
interrupts = <13 1>;
label = "P13";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
p14: gpio@40320700 {
compatible = "cypress,psoc6-gpio";
reg = <0x40320700 0x80>;
interrupts = <14 1>;
label = "P14";
gpio-controller;
#gpio-cells = <2>;
#cypress,pin-cells = <3>;
};
};

uart5: uart@40660000 {
compatible = "cypress,psoc6-uart";
reg = <0x40660000 0x10000>;
interrupts = <2 1>;
status = "disabled";
label = "uart_5";
};

uart6: uart@40670000 {
compatible = "cypress,psoc6-uart";
reg = <0x40670000 0x10000>;
Expand Down
36 changes: 36 additions & 0 deletions dts/bindings/gpio/cypress,psoc6-gpio.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Copyright (c) 2020 ATL Electronics
# SPDX-License-Identifier: Apache-2.0

description: Cypress GPIO PORT node

compatible: "cypress,psoc6-gpio"

include: [gpio-controller.yaml, base.yaml]

properties:
reg:
required: true

interrupts:
required: true

label:
required: true

"#gpio-cells":
const: 2

"#cypress,pin-cells":
type: int
required: true
const: 3
description: Number of items to expect in a cypress,pins specifier

gpio-cells:
- pin
- flags

cypress,pin-cells:
- port
- pin
- hsiom
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this commit introduce gpio bindings? Shouldn't it be pinctrl stuff only? I think it's better to split gpio and pinctrl stuff, they are in principle orthogonal things.

Copy link
Member Author

@nandojve nandojve Oct 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not right, To solve IRQ, GPIO, PINCTRL and noted that the right sequence is:

dt-bindings/dt-util.h: #28779
IRQ: #29459
GPIO: #29489
PINCTRL: This PR

18 changes: 18 additions & 0 deletions dts/bindings/gpio/cypress,psoc6-hsiom.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright (c) 2020 ATL Electronics
# SPDX-License-Identifier: Apache-2.0

description: Cypress High Speed I/O Matrix

compatible: "cypress,psoc6-hsiom"

include: base.yaml

properties:
reg:
required: true

interrupts:
required: true

label:
required: true
11 changes: 11 additions & 0 deletions dts/bindings/interrupt-controller/cypress,psoc6-int-mux.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright (c) 2020 ATL Electronics
# SPDX-License-Identifier: Apache-2.0

properties:
map-nvic:
type: int
required: false
description: |
Cortex-M0+ NVIC user defined interrupt line. The PSoC-6 SoC needs that
user select which interrupts Cortex-M0+ will handle and this map the
peripheral interrupt to be bind at driver initialization.
Loading