-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Reset Controller Driver #43073
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 12 commits into
zephyrproject-rtos:main
from
andrei-edward-popa:reset_controller
Mar 23, 2022
Merged
Reset Controller Driver #43073
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
5a97251
include: drivers: added header file for Reset Controller Driver
andrei-edward-popa 1b455d1
dts: bindings: added bindings for Reset Controller Driver
andrei-edward-popa fc7c0f6
dts: bindings: test: added bindings for devicetree test reset
andrei-edward-popa cdbe341
tests: lib: devicetree: api: added test for reset public API
andrei-edward-popa d9aeb65
drivers: added file structure for Reset Controller Driver
andrei-edward-popa 1c53cb5
doc: reference: added documentation for Reset Controller
andrei-edward-popa 3156a9e
dts: bindings: reset: added bindings for Raspberry Pi Pico
andrei-edward-popa ce45f7c
drivers: reset: added Reset Controller for Raspberry Pi Pico
andrei-edward-popa 507a1cf
dts: bindings: serial: added reset bindings for Raspberry Pi Pico
andrei-edward-popa dd5e809
dts: arm: rpi_pico: added reset controller node
andrei-edward-popa 8bf33dc
dts: arm: rpi_pico: added resets for UART instances
andrei-edward-popa 799bfee
drivers: serial: rpi_pico: added reset support for UART devices
andrei-edward-popa 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
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 |
|---|---|---|
|
|
@@ -29,6 +29,7 @@ Peripherals | |
| ps2.rst | ||
| peci.rst | ||
| regulators.rst | ||
| reset.rst | ||
| rtc.rst | ||
| sensor.rst | ||
| spi.rst | ||
|
|
||
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,28 @@ | ||
| .. _reset_api: | ||
|
|
||
| Reset Controller | ||
| ################ | ||
|
|
||
| Overview | ||
| ******** | ||
|
|
||
| Reset controllers are units that control the reset signals to multiple | ||
| peripherals. The reset controller API allows peripheral drivers to request | ||
| control over their reset input signals, including the ability to assert, | ||
| deassert and toggle those signals. Also, the reset status of the reset input | ||
| signal can be checked. | ||
|
|
||
| Mainly, the assert and deassert API functions are optional because in most | ||
| cases we want to toggle the reset signals. | ||
|
|
||
| Configuration Options | ||
| ********************* | ||
|
|
||
| Related configuration options: | ||
|
|
||
| * :kconfig:option:`CONFIG_RESET` | ||
|
|
||
| API Reference | ||
| ************* | ||
|
|
||
| .. doxygengroup:: reset_controller_interface |
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 |
|---|---|---|
|
|
@@ -133,4 +133,6 @@ source "drivers/power_domain/Kconfig" | |
|
|
||
| source "drivers/usbc/Kconfig" | ||
|
|
||
| source "drivers/reset/Kconfig" | ||
|
|
||
| endmenu | ||
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,4 @@ | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| zephyr_library() | ||
| zephyr_library_sources_ifdef(CONFIG_RESET_RPI_PICO reset_rpi_pico.c) |
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,32 @@ | ||
| # Reset Controller driver configuration options | ||
|
|
||
| # Copyright (c) 2022 Andrei-Edward Popa <[email protected]> | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # | ||
| # Reset Controller options | ||
| # | ||
| menuconfig RESET | ||
| bool "Reset Controller drivers" | ||
| help | ||
| Reset Controller drivers. Reset node represents a region containing | ||
| information about reset controller device. The typical use-case is | ||
| for some other node's drivers to acquire a reference to the reset | ||
| controller node together with some reset information. | ||
|
|
||
| if RESET | ||
|
|
||
| config RESET_INIT_PRIORITY | ||
| int "Reset Controller driver init priority" | ||
| default 40 | ||
| help | ||
| This option controls the priority of the reset controller device | ||
| initialization. Higher priority ensures that the device is | ||
| initialized earlier in the startup cycle. If unsure, leave at default | ||
| value | ||
|
|
||
| comment "Reset Controller Drivers" | ||
|
|
||
| rsource "Kconfig.rpi_pico" | ||
|
|
||
| endif # RESET | ||
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,9 @@ | ||
| # Copyright (c) 2022 Andrei-Edward Popa | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| # Workaround for not being able to have commas in macro arguments | ||
| DT_COMPAT_RPI_PICO_RESET := raspberrypi,pico-reset | ||
|
|
||
| config RESET_RPI_PICO | ||
| bool "Raspberry Pi Reset Controller driver" | ||
| default $(dt_compat_enabled,$(DT_COMPAT_RPI_PICO_RESET)) |
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,159 @@ | ||
| /* | ||
| * Copyright (c) 2022 Andrei-Edward Popa | ||
| * | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| #define DT_DRV_COMPAT raspberrypi_pico_reset | ||
|
|
||
| #include <device.h> | ||
| #include <drivers/reset.h> | ||
|
|
||
| struct reset_rpi_config { | ||
| DEVICE_MMIO_ROM; | ||
| uint8_t reg_width; | ||
| uint8_t active_low; | ||
| uintptr_t base_address; | ||
| }; | ||
|
|
||
| static int reset_rpi_read_register(const struct device *dev, uint16_t offset, uint32_t *value) | ||
| { | ||
| const struct reset_rpi_config *config = dev->config; | ||
| uint32_t base_address = config->base_address; | ||
|
|
||
| switch (config->reg_width) { | ||
| case 1: | ||
| *value = sys_read8(base_address + offset); | ||
| break; | ||
| case 2: | ||
| *value = sys_read16(base_address + offset); | ||
| break; | ||
| case 4: | ||
| *value = sys_read32(base_address + offset); | ||
| break; | ||
| default: | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int reset_rpi_write_register(const struct device *dev, uint16_t offset, uint32_t value) | ||
| { | ||
| const struct reset_rpi_config *config = dev->config; | ||
| uint32_t base_address = config->base_address; | ||
|
|
||
| switch (config->reg_width) { | ||
| case 1: | ||
| sys_write8(value, base_address + offset); | ||
| break; | ||
| case 2: | ||
| sys_write16(value, base_address + offset); | ||
| break; | ||
| case 4: | ||
| sys_write32(value, base_address + offset); | ||
| break; | ||
| default: | ||
| return -EINVAL; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static int reset_rpi_status(const struct device *dev, uint32_t id, uint8_t *status) | ||
| { | ||
| const struct reset_rpi_config *config = dev->config; | ||
| uint16_t offset; | ||
| uint32_t value; | ||
| uint8_t regbit; | ||
| int ret; | ||
|
|
||
| offset = id / (config->reg_width * CHAR_BIT); | ||
| regbit = id % (config->reg_width * CHAR_BIT); | ||
|
|
||
| ret = reset_rpi_read_register(dev, offset, &value); | ||
| if (ret) { | ||
| return ret; | ||
| } | ||
|
|
||
| *status = !(value & BIT(regbit)) ^ !config->active_low; | ||
|
|
||
| return ret; | ||
| } | ||
|
|
||
| static int reset_rpi_update(const struct device *dev, uint32_t id, uint8_t assert) | ||
| { | ||
| const struct reset_rpi_config *config = dev->config; | ||
| uint16_t offset; | ||
| uint32_t value; | ||
| uint8_t regbit; | ||
| int ret; | ||
|
|
||
| offset = id / (config->reg_width * CHAR_BIT); | ||
| regbit = id % (config->reg_width * CHAR_BIT); | ||
|
|
||
| ret = reset_rpi_read_register(dev, offset, &value); | ||
| if (ret) { | ||
| return ret; | ||
| } | ||
|
|
||
| if (assert ^ config->active_low) { | ||
| value |= BIT(regbit); | ||
| } else { | ||
| value &= ~BIT(regbit); | ||
| } | ||
|
|
||
| return reset_rpi_write_register(dev, offset, value); | ||
| } | ||
|
|
||
| static int reset_rpi_assert(const struct device *dev, uint32_t id) | ||
| { | ||
| return reset_rpi_update(dev, id, 1); | ||
| } | ||
|
|
||
| static int reset_rpi_deassert(const struct device *dev, uint32_t id) | ||
| { | ||
| return reset_rpi_update(dev, id, 0); | ||
| } | ||
|
|
||
| static int reset_rpi_toggle(const struct device *dev, uint32_t id) | ||
| { | ||
| int ret; | ||
|
|
||
| ret = reset_rpi_assert(dev, id); | ||
| if (ret) { | ||
| return ret; | ||
| } | ||
|
|
||
| return reset_rpi_deassert(dev, id); | ||
| } | ||
|
|
||
| static int reset_rpi_init(const struct device *dev) | ||
| { | ||
| DEVICE_MMIO_MAP(dev, K_MEM_CACHE_NONE); | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| static const struct reset_driver_api reset_rpi_driver_api = { | ||
| .status = reset_rpi_status, | ||
| .assert = reset_rpi_assert, | ||
| .deassert = reset_rpi_deassert, | ||
| .toggle = reset_rpi_toggle, | ||
| }; | ||
|
|
||
| #define RPI_RESET_INIT(idx) \ | ||
| static const struct reset_rpi_config reset_rpi_config_##idx = { \ | ||
| DEVICE_MMIO_ROM_INIT(DT_DRV_INST(idx)), \ | ||
| .reg_width = DT_INST_PROP_OR(idx, reg_width, 4), \ | ||
| .active_low = DT_INST_PROP_OR(idx, active_low, 0), \ | ||
| .base_address = DT_INST_REG_ADDR(idx), \ | ||
| }; \ | ||
| \ | ||
| DEVICE_DT_INST_DEFINE(idx, reset_rpi_init, \ | ||
| NULL, NULL, \ | ||
| &reset_rpi_config_##idx, PRE_KERNEL_1, \ | ||
| CONFIG_RESET_INIT_PRIORITY, \ | ||
| &reset_rpi_driver_api); | ||
|
|
||
| DT_INST_FOREACH_STATUS_OKAY(RPI_RESET_INIT); |
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
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
Oops, something went wrong.
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.