-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers: gpio: Add Davinci gpio controller support #61316
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
Merged
carlescufi
merged 1 commit into
zephyrproject-rtos:main
from
slpp95prashanth:zephyr_gpio
Aug 31, 2023
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| # Copyright (C) 2023 BeagleBoard.org Foundation | ||
| # Copyright (C) 2023 S Prashanth | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| config GPIO_DAVINCI | ||
| bool "Davinci GPIO Driver" | ||
| default y | ||
| depends on DT_HAS_TI_DAVINCI_GPIO_ENABLED | ||
| help | ||
| Enable the Davinci GPIO controller support. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,199 @@ | ||
| /* | ||
| * Copyright (C) 2023 BeagleBoard.org Foundation | ||
| * Copyright (C) 2023 S Prashanth | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #define DT_DRV_COMPAT ti_davinci_gpio | ||
|
|
||
| #include <errno.h> | ||
|
|
||
| #include <zephyr/arch/common/sys_bitops.h> | ||
| #include <zephyr/device.h> | ||
| #include <zephyr/devicetree.h> | ||
| #include <zephyr/drivers/gpio.h> | ||
| #include <zephyr/drivers/gpio/gpio_utils.h> | ||
| #include <zephyr/init.h> | ||
| #include <zephyr/kernel.h> | ||
| #include <zephyr/sys/sys_io.h> | ||
|
|
||
| /* Helper Macros for GPIO */ | ||
| #define DEV_CFG(dev) \ | ||
| ((const struct gpio_davinci_config * const)((dev)->config)) | ||
| #define DEV_DATA(dev) ((struct gpio_davinci_data *)(dev)->data) | ||
gmarull marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #define DEV_GPIO_CFG_BASE(dev) \ | ||
slpp95prashanth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ((struct gpio_davinci_regs *)DEVICE_MMIO_NAMED_GET(dev, port_base)) | ||
|
|
||
| #define GPIO_DAVINCI_DIR_RESET_VAL (0xFFFFFFFF) | ||
|
|
||
| struct gpio_davinci_regs { | ||
| uint32_t dir; | ||
| uint32_t out_data; | ||
| uint32_t set_data; | ||
| uint32_t clr_data; | ||
| uint32_t in_data; | ||
| uint32_t set_ris_trig; | ||
| uint32_t clr_ris_trig; | ||
| uint32_t set_fal_trig; | ||
| uint32_t clr_fal_trig; | ||
| uint32_t intstat; | ||
| }; | ||
|
|
||
| struct gpio_davinci_data { | ||
| struct gpio_driver_data common; | ||
|
|
||
| DEVICE_MMIO_NAMED_RAM(port_base); | ||
|
|
||
| sys_slist_t cb; | ||
| }; | ||
|
|
||
| struct gpio_davinci_config { | ||
| void (*bank_config)(const struct device *dev); | ||
| struct gpio_driver_config common; | ||
|
|
||
| DEVICE_MMIO_NAMED_ROM(port_base); | ||
|
|
||
| uint32_t port_num; | ||
| }; | ||
|
|
||
slpp95prashanth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| static int gpio_davinci_configure(const struct device *dev, gpio_pin_t pin, | ||
| gpio_flags_t flags) | ||
| { | ||
| volatile struct gpio_davinci_regs *regs = DEV_GPIO_CFG_BASE(dev); | ||
|
|
||
| if ((flags & GPIO_SINGLE_ENDED) != 0) { | ||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| if ((flags & (GPIO_PULL_UP | GPIO_PULL_DOWN)) != 0) { | ||
| return -ENOTSUP; | ||
| } | ||
|
|
||
| if ((flags & GPIO_OUTPUT) != 0) { | ||
| if ((flags & GPIO_OUTPUT_INIT_HIGH) != 0) { | ||
| regs->set_data = BIT(pin); | ||
| } else { | ||
| regs->clr_data = BIT(pin); | ||
| } | ||
|
|
||
| regs->dir &= (~(BIT(pin))); | ||
|
|
||
| } else { | ||
| regs->dir |= (BIT(pin)); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int gpio_davinci_port_get_raw(const struct device *dev, | ||
| gpio_port_value_t *value) | ||
| { | ||
| volatile struct gpio_davinci_regs *regs = DEV_GPIO_CFG_BASE(dev); | ||
|
|
||
| *value = regs->in_data; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int gpio_davinci_port_set_masked_raw(const struct device *dev, | ||
slpp95prashanth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| gpio_port_pins_t mask, gpio_port_value_t value) | ||
| { | ||
| volatile struct gpio_davinci_regs *regs = DEV_GPIO_CFG_BASE(dev); | ||
|
|
||
| regs->out_data = (regs->out_data & (~mask)) | (mask & value); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int gpio_davinci_port_set_bits_raw(const struct device *dev, | ||
| gpio_port_pins_t mask) | ||
| { | ||
| volatile struct gpio_davinci_regs *regs = DEV_GPIO_CFG_BASE(dev); | ||
|
|
||
| regs->set_data |= mask; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int gpio_davinci_port_clear_bits_raw(const struct device *dev, | ||
| gpio_port_pins_t mask) | ||
| { | ||
| volatile struct gpio_davinci_regs *regs = DEV_GPIO_CFG_BASE(dev); | ||
|
|
||
| regs->clr_data |= mask; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int gpio_davinci_port_toggle_bits(const struct device *dev, | ||
| gpio_port_pins_t mask) | ||
| { | ||
| volatile struct gpio_davinci_regs *regs = DEV_GPIO_CFG_BASE(dev); | ||
|
|
||
| regs->out_data ^= mask; | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static const struct gpio_driver_api gpio_davinci_driver_api = { | ||
| .pin_configure = gpio_davinci_configure, | ||
| .port_get_raw = gpio_davinci_port_get_raw, | ||
| .port_set_masked_raw = gpio_davinci_port_set_masked_raw, | ||
| .port_set_bits_raw = gpio_davinci_port_set_bits_raw, | ||
| .port_clear_bits_raw = gpio_davinci_port_clear_bits_raw, | ||
| .port_toggle_bits = gpio_davinci_port_toggle_bits | ||
vaishnavachath marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| static int gpio_davinci_init(const struct device *dev) | ||
| { | ||
| const struct gpio_davinci_config *config = DEV_CFG(dev); | ||
| volatile struct gpio_davinci_regs *regs = DEV_GPIO_CFG_BASE(dev); | ||
|
|
||
| DEVICE_MMIO_NAMED_MAP(dev, port_base, K_MEM_CACHE_NONE); | ||
|
|
||
| regs->dir = GPIO_DAVINCI_DIR_RESET_VAL; | ||
|
|
||
| config->bank_config(dev); | ||
|
|
||
| return 0; | ||
slpp95prashanth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| #define GPIO_DAVINCI_INIT_FUNC(n) \ | ||
| static void gpio_davinci_bank_##n##_config(const struct device *dev) \ | ||
| { \ | ||
| volatile struct gpio_davinci_regs *regs = DEV_GPIO_CFG_BASE(dev); \ | ||
| ARG_UNUSED(regs); \ | ||
| } | ||
|
|
||
| #define GPIO_DAVINCI_DEVICE_INIT(n) \ | ||
| DEVICE_DT_INST_DEFINE(n, &gpio_davinci_##n##_init, \ | ||
| NULL, &gpio_davinci_##n##_data, \ | ||
| &gpio_davinci_##n##_config, \ | ||
| POST_KERNEL, CONFIG_GPIO_INIT_PRIORITY, \ | ||
| &api_funcs) | ||
|
|
||
| #define GPIO_DAVINCI_INIT(n) \ | ||
| \ | ||
| GPIO_DAVINCI_INIT_FUNC(n) \ | ||
| static const struct gpio_davinci_config gpio_davinci_##n##_config = { \ | ||
| .bank_config = gpio_davinci_bank_##n##_config, \ | ||
| .common = { \ | ||
| .port_pin_mask = GPIO_PORT_PIN_MASK_FROM_DT_INST(n), \ | ||
| }, \ | ||
| DEVICE_MMIO_NAMED_ROM_INIT(port_base, DT_DRV_INST(n)), \ | ||
| .port_num = n \ | ||
| }; \ | ||
| \ | ||
| static struct gpio_davinci_data gpio_davinci_##n##_data; \ | ||
| \ | ||
| DEVICE_DT_INST_DEFINE(n, \ | ||
| &gpio_davinci_init, \ | ||
| NULL, \ | ||
| &gpio_davinci_##n##_data, \ | ||
| &gpio_davinci_##n##_config, \ | ||
| PRE_KERNEL_2, \ | ||
| CONFIG_GPIO_INIT_PRIORITY, \ | ||
| &gpio_davinci_driver_api); | ||
|
|
||
| DT_INST_FOREACH_STATUS_OKAY(GPIO_DAVINCI_INIT) | ||
slpp95prashanth marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| # Copyright (C) 2023 BeagleBoard.org Foundation | ||
| # Copyright (C) 2023 S Prashanth | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| description: GPIO controller for Davinci and Keystone devices | ||
|
|
||
| compatible: "ti,davinci-gpio-nexus" | ||
|
|
||
| include: [base.yaml, gpio-nexus.yaml] | ||
|
|
||
| properties: | ||
| "#gpio-cells": | ||
| const: 2 | ||
|
|
||
| gpio-cells: | ||
| - pin | ||
| - flags |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Copyright (C) 2023 BeagleBoard.org Foundation | ||
| # Copyright (C) 2023 S Prashanth | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| description: GPIO controller for Davinci and Keystone devices. | ||
|
|
||
| compatible: "ti,davinci-gpio" | ||
|
|
||
| include: [gpio-controller.yaml, base.yaml] | ||
|
|
||
| properties: | ||
| reg: | ||
| required: true | ||
|
|
||
| "#gpio-cells": | ||
| const: 2 | ||
|
|
||
| gpio-cells: | ||
| - pin | ||
| - flags |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.