-
Notifications
You must be signed in to change notification settings - Fork 6.7k
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
Convert GPIO drivers to new GPIO API #18530
Comments
@nategraff-sifive I assume you are good with looking to convert the sifive gpio driver to the new GPIO api? |
@henrikbrixandersen I assume you are good with looking to convert the ht16k33 to the new GPIO api? |
@galak Sure. |
Proposed Roadmap to GPIO Integration for #15611(Review the comment history for details of the changes to this process based on API meeting discussions.) This is a slightly edited description of stages originally proposed on slack. The goal is to do development and review work on a topic branch, but to merge pieces to master as soon as they are sufficiently ready that their presence will not break any tests or applications. At all points master is expected to build and pass CI/shippable; however in certain stages the topic branch may have deprecation warnings and build or runtime failures resulting from platforms and drivers that have not been converted. Content on the topic branch is expected to be refactored, reordered, and cherry-picked as necessary to ensure material merged to master has clean history. There are seven stages:
Material is merged to master at/during stages (2) and (4) through (6). During those stages the topic branch works for converted systems/applications, but may not build for others. Master should pass sanitycheck at all times and be bisectable except possibly between commits within a merge, just as is true for existing PRs. The topic branch is no longer used after stage (5). This approach requires active management: cherry-picking pieces from the topic branch into PRs that target master, and frequent rebasing of the topic branch. This is not technically difficult to do, and if this approach is approved I can take on that task. Success requires responsiveness from stakeholders who approve the topic-branch merge to quickly approve the master merge. It also requires responsiveness from stakeholders outside the API meeting participants: vendors to convert GPIO peripheral drivers in (4) and other codeowners to update and validate code that uses the GPIO API in (6). I would like to see us reach stage (4) no later than the end of September. I believe this is achievable. #18689 has been a prototype of this: it contains material that is similar to master at stage (4). sanitycheck will pass in that situation (as long as CI doesn't break, as it did in my last push). I've also got commits that verify subsequent when restricted to converted devices; they are currently not in that PR. |
Would be good to get a summary of changes that need to be made to the driver and dts files. |
IMO the best approach is to use the five existing conversions as examples, but: Essentially for the driver it's "implement the new functions in the API table, and make the tests pass". For the devicetree files it's minimally replace the deprecated macros and update the flags to be correct for the corresponding device (generally leave at 0 for active high, or change to |
I've added "Steps required to convert a GPIO driver to the new API" section directly to the issue description so it's easy to spot. Please let me know if there are parts which are not clear / should be extended. |
Proposed GPIO policies for interrupt use/safety, atomicity, etc. related to #18970Copied from slack, edited here based on feedback
|
The potential issue with the existing API is that the way to disable interrupts is Currently SX1509B doesn't support interrupts. If it were made to do so, it could still satisfy the above requirements because I carefully worded them to allow an implementation that flagged the interrupt, but didn't invoke the corresponding callback within the ISR. This could still cause functional problems: the situation where I usually want to disable interrupts in the callback is where I'm using a level trigger, and the callback can't perform the actions necessary to clear or change the input level. The questions are (a) do we care about interrupts from external GPIO devices, and (b) if we do is there any API change that would resolve this, e.g. defining I think the answer should be (a) yes, and (b) no, which leads to (c) we need to document that callbacks for some GPIO drivers may be invoked from a helper thread rather than within the ISR itself. |
@jenmwms any update on the intel-apl or pcal9535a drivers? |
@Kumar Gala<mailto:[email protected]> I am working on the intel-apl. It could help to have a pair programming sync with someone familiar with apl. I’ll reach out to those around today. I’m making progress though!
@leung, Daniel<mailto:[email protected]> is looking at the pcal9535a drivers.
From: Kumar Gala <[email protected]>
Sent: Monday, October 28, 2019 10:35 PM
To: zephyrproject-rtos/zephyr <[email protected]>
Cc: Williams, Jennifer M <[email protected]>; Mention <[email protected]>
Subject: Re: [zephyrproject-rtos/zephyr] Convert GPIO drivers to new GPIO API (#18530)
@jenmwms<https://github.com/jenmwms> any update on the intel-apl or pcal9535a drivers?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub<#18530?email_source=notifications&email_token=AL56SH25CVTVC7LHQ3DMXWDQQ7DOZA5CNFSM4INZ7ENKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOECPJK3Y#issuecomment-547263855>, or unsubscribe<https://github.com/notifications/unsubscribe-auth/AL56SH3GAQ52PMMPMQ5WOSDQQ7DOZANCNFSM4INZ7ENA>.
|
All drivers are converted on the topic branch. |
This is a tracking issue on process and status for converting GPIO drivers to support new GPIO API.
Driver Status
Steps required to convert a GPIO driver to the new API
Convert board .dts files
Before updating the driver source code it's best to start with updating all in-tree board .dts files (located in
boards/
folder) the driver depends on. All the GPIO_* flags currently present in the .dts files, such asGPIO_INT_ACTIVE_LOW
,GPIO_PUD_PULL_DOWN
,GPIO_DIR_OUT
are deprecated and should be removed. The newly introduced flags are compatible with Linux DT. They are located (and documented) ininclude/dt-bindings/gpio/gpio.h
. Their naming and purpose is similar, though not identical to the old flags. Rather than mechanically changing old flags to the matching new ones it's better to consult board's schematic. Pin with no flags defaults to active high and, in case it is configured as an output, to a push-pull mode. The dts files that have been converted so far avoid explicit usage ofGPIO_ACTIVE_HIGH
orGPIO_PUSH_PULL
flags.At present it's not possible to define pin as input/output in DTS. This is done in the application code. Similarly, no interrupt configuration is possible in DTS.
Update the driver
Several drivers have been updated already. Please use any of the commits as an example, e.g.
Adding the implementation of the new
port_get_raw, port_set_masked_raw, port_set_bits_raw, port_clear_bits_raw, port_toggle_bits,
functions is usually quite straightforward:get_raw(ptr)
=>*ptr = INPUT;
set_masked_raw(mask, value)
=>OUTPUT = (OUTPUT & ~mask) | (value & mask);
set_bits_raw(pins)
=>OUTPUT |= pins;
clear_bits_raw(pins)
=>OUTPUT &= ~pins;
toggle_bits(pins)
=>OUTPUT ^= pins;
The more complicated part is the implementation of
pin_interrupt_configure
function as well as updatingconfig
to support new flags.The old GPIO API configures interrupts via the
config
function. This is not supported by the new API, however to keep backward compatibility theconfig
function will callpin_interrupt_configure
. This call will be removed in the future.Support for all the flags defined in
include/dt-bindings/gpio/gpio.h
has to be implemented or the driver should return-ENOTSUP
. AlsoGPIO_OUTPUT_INIT_LOW
,GPIO_OUTPUT_INIT_HIGH
flags have to be implemented since misbehaving driver has a potential of destroying the board.The button sample located in
samples/basic/button/
is a very simple application that is able to test most of the new features. It's quite handy when starting to work on the new code. The app generates an interrupt the moment board's button is pressed (and displays a message on the console). Also, whenever the button is pressed the board's LED should be ON.The new GPIO API is not specifically designed to be fast, there is another API in the works which aims to achieve that goal. Nevertheless, once the driver is complete it's worth checking the generated assembly code of the new
port_*
functions. Following table shows typical length of theport_*
functions implemented on ARM Cortex-M4, -M7 architecture.Update *.c files in the board directory
A few boards require initial configuration of GPIO pins. This is done by a *.c file placed in the board directory. If the file contains any calls to the deprecated GPIO functions, e.g.
gpio_pin_write
or use any of the deprecated flags e.g.GPIO_DIR_OUT
they have to be replaced by the corresponding feature of the new API.Test the driver code
The initial driver development can be guided by
samples/basic/button/
sample project. Once the driver is working it should be tested withtests/drivers/gpio/gpio_api_1pin/
testcase. The testcase is using the pin where the board's LED0 is connected to run battery of tests. No hardware modifications to the board are required. However, it relies on the ability of the driver to configure the pin in input/output mode. If this is not supported by the driver the driver should return-ENOTSUP
. The testcase should still pass but is pretty useless in assessing quality of the code.The testcase which is using two (or more) different pins is not ready yet.
Steps required to convert samples / application code to the new API
@mnkp please fill in
List of users to convert: #20017
The text was updated successfully, but these errors were encountered: