Skip to content

Commit

Permalink
dts: esp32: Add GPIO support in DT
Browse files Browse the repository at this point in the history
Add GPIO support in DT

Signed-off-by: Yannis Damigos <[email protected]>
  • Loading branch information
ydamigos authored and carlescufi committed Sep 25, 2019
1 parent 0450263 commit efec7f7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 16 deletions.
11 changes: 1 addition & 10 deletions drivers/gpio/Kconfig.esp32
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
menuconfig GPIO_ESP32
bool "ESP32 GPIO"
depends on SOC_ESP32
select HAS_DTS_GPIO
help
Enables the ESP32 GPIO driver

Expand All @@ -24,20 +25,10 @@ config GPIO_ESP32_0
help
Include support for GPIO pins 0-31 on the ESP32.

config GPIO_ESP32_0_NAME
string "Driver name"
depends on GPIO_ESP32_0
default "GPIO_0"

config GPIO_ESP32_1
bool "ESP32 GPIO (pins 32-39)"
default y
help
Include support for GPIO pins 32-39 on the ESP32.

config GPIO_ESP32_1_NAME
string "Driver name"
depends on GPIO_ESP32_1
default "GPIO_1"

endif # GPIO_ESP32
4 changes: 2 additions & 2 deletions drivers/gpio/gpio_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,11 @@ static struct gpio_esp32_data gpio_data_pins_32_to_39 = {
* and the device has 40 GPIO pins.
*/
#if defined(CONFIG_GPIO_ESP32_0)
GPIO_DEVICE_INIT(CONFIG_GPIO_ESP32_0_NAME, 0_to_31);
GPIO_DEVICE_INIT(DT_INST_0_ESPRESSIF_ESP32_GPIO_LABEL, 0_to_31);
#endif

#if defined(CONFIG_GPIO_ESP32_1)
GPIO_DEVICE_INIT(CONFIG_GPIO_ESP32_1_NAME, 32_to_39);
GPIO_DEVICE_INIT(DT_INST_1_ESPRESSIF_ESP32_GPIO_LABEL, 32_to_39);
#endif

static void gpio_esp32_isr(void *param)
Expand Down
4 changes: 2 additions & 2 deletions drivers/pwm/pwm_led_esp32.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,14 @@ static const char *esp32_get_gpio_for_pin(int pin)
{
if (pin < 32) {
#if defined(CONFIG_GPIO_ESP32_0)
return CONFIG_GPIO_ESP32_0_NAME;
return DT_INST_0_ESPRESSIF_ESP32_GPIO_LABEL;
#else
return NULL;
#endif /* CONFIG_GPIO_ESP32_0 */
}

#if defined(CONFIG_GPIO_ESP32_1)
return CONFIG_GPIO_ESP32_1_NAME;
return DT_INST_1_ESPRESSIF_ESP32_GPIO_LABEL;
#else
return NULL;
#endif /* CONFIG_GPIO_ESP32_1 */
Expand Down
27 changes: 27 additions & 0 deletions dts/bindings/gpio/espressif,esp32-gpio.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#
# Copyright (c) 2019, Yannis Damigos
#
# SPDX-License-Identifier: Apache-2.0
#

title: ESP32 GPIO

description: >
This is a representation of the ESP32 GPIO nodes
inherits:
!include base.yaml

properties:
compatible:
constraint: "espressif,esp32-gpio"

reg:
category: required

label:
category: required

"#cells":
- pin
- flags
16 changes: 16 additions & 0 deletions dts/xtensa/espressif/esp32.dtsi
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* SPDX-License-Identifier: Apache-2.0
*/
#include <xtensa/xtensa.dtsi>
#include <dt-bindings/gpio/gpio.h>

/ {
cpus {
Expand Down Expand Up @@ -55,5 +56,20 @@
status = "disabled";
};

gpio0: gpio@3ff44000 {
compatible = "espressif,esp32-gpio";
gpio-controller;
#gpio-cells = <2>;
reg = <0x3ff44000 0x800>;
label = "GPIO_0";
};

gpio1: gpio@3ff44800 {
compatible = "espressif,esp32-gpio";
gpio-controller;
#gpio-cells = <2>;
reg = <0x3ff44800 0x800>;
label = "GPIO_1";
};
};
};
4 changes: 2 additions & 2 deletions include/drivers/gpio/gpio_esp32.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ static const char *gpio_esp32_get_gpio_for_pin(int pin)
{
if (pin < 32) {
#if defined(CONFIG_GPIO_ESP32_0)
return CONFIG_GPIO_ESP32_0_NAME;
return DT_INST_0_ESPRESSIF_ESP32_GPIO_LABEL;
#else
return NULL;
#endif /* CONFIG_GPIO_ESP32_0 */
}

#if defined(CONFIG_GPIO_ESP32_1)
return CONFIG_GPIO_ESP32_1_NAME;
return DT_INST_1_ESPRESSIF_ESP32_GPIO_LABEL;
#else
return NULL;
#endif /* CONFIG_GPIO_ESP32_1 */
Expand Down

0 comments on commit efec7f7

Please sign in to comment.