Repository navigation
novatek: pad-mux, reginfo and GPIO for NA51089 (#237) #239
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
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,5 @@ | ||
| src/hal/sstar_padmux\.h | ||
| src/hal/ingenic_padmux\.h | ||
| src/hal/novatek_padmux\.h | ||
| src/padmux_names\.h | ||
| src/padmux_names\.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
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 |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* The NA51089 GPIO controller, as the vendor's gpio-nvt-na51089.c drives it. | ||
| * | ||
| * Four banks of eight words at 0xF0070000: DATA, DIR, SET and CLR, one word | ||
| * per pad group, so a pad's bit is its Linux GPIO number modulo 32 in word | ||
| * number / 32. SET and CLR are write-one aliases, which is how the kernel | ||
| * changes a level without a read-modify-write of the other pads; only DIR is | ||
| * read-modified-written, under the kernel's spinlock there and under the | ||
| * single-threaded contract of mem_reg() here. | ||
| * | ||
| * The per-group counts are nvt-gpio.h's *_GPIO_NUM: what the package bonds | ||
| * out, and so what the gpiochip accepts. */ | ||
|
|
||
| #include "hal/novatek_gpio.h" | ||
|
|
||
| #include "chipid.h" | ||
| #include "hal/novatek.h" | ||
| #include "tools.h" | ||
|
|
||
| static const uint8_t group_pads[8] = { | ||
| 23, /* C_GPIO, the "MC" pads */ | ||
| 26, /* P_GPIO */ | ||
| 9, /* S_GPIO */ | ||
| 10, /* L_GPIO */ | ||
| 8, /* D_GPIO */ | ||
| 12, /* H_GPIO, the HSI pads */ | ||
| 3, /* A_GPIO */ | ||
| 11, /* DSI_GPIO */ | ||
| }; | ||
|
|
||
| bool novatek_gpio_supported(void) { return chip_generation == CHIP_NA51089; } | ||
|
|
||
| bool novatek_gpio_valid(int pad) { | ||
| if (!novatek_gpio_supported() || pad < 0 || pad >= NVT_GPIO_NPADS) | ||
| return false; | ||
| return (pad & 31) < group_pads[pad >> 5]; | ||
| } | ||
|
|
||
| uint32_t novatek_gpio_reg(int pad, unsigned bank) { | ||
| if (!novatek_gpio_valid(pad) || bank > NVT_GPIO_CLR || bank % 0x20) | ||
| return 0; | ||
| return NVT_GPIO_BASE + bank + (uint32_t)(pad >> 5) * 4; | ||
| } | ||
|
|
||
| bool novatek_gpio_window(uint32_t *base, uint32_t *len) { | ||
| if (!novatek_gpio_supported()) | ||
| return false; | ||
| *base = NVT_GPIO_BASE; | ||
| *len = NVT_GPIO_CLR + 0x20; | ||
| return true; | ||
| } | ||
|
|
||
| bool novatek_gpio_read(int pad, bool *output, bool *level) { | ||
| uint32_t dir, data; | ||
| if (!novatek_gpio_valid(pad) || | ||
| !mem_reg(novatek_gpio_reg(pad, NVT_GPIO_DIR), &dir, OP_READ) || | ||
| !mem_reg(novatek_gpio_reg(pad, NVT_GPIO_DATA), &data, OP_READ)) | ||
| return false; | ||
|
|
||
| uint32_t bit = 1u << (pad & 31); | ||
| *output = (dir & bit) != 0; | ||
| *level = (data & bit) != 0; | ||
| return true; | ||
| } | ||
|
|
||
| bool novatek_gpio_write(int pad, bool level) { | ||
| uint32_t dir; | ||
| uint32_t bit = 1u << (pad & 31); | ||
| if (!novatek_gpio_valid(pad) || | ||
| !mem_reg(novatek_gpio_reg(pad, NVT_GPIO_DIR), &dir, OP_READ)) | ||
| return false; | ||
| if (!(dir & bit)) { | ||
| dir |= bit; | ||
| if (!mem_reg(novatek_gpio_reg(pad, NVT_GPIO_DIR), &dir, OP_WRITE)) | ||
| return false; | ||
| } | ||
| return mem_reg(novatek_gpio_reg(pad, level ? NVT_GPIO_SET : NVT_GPIO_CLR), | ||
| &bit, OP_WRITE); | ||
| } |
Oops, something went wrong.
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.