-
Notifications
You must be signed in to change notification settings - Fork 8.3k
drivers/mfd: it8801: Implement ITE IT8801 mfd drivers #79416
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
Conversation
eaac9c2 to
372ce90
Compare
keith-zephyr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also consider running clang-format on all the files.
drivers/mfd/mfd_ite_it8801.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This driver supports multiple instances, but this this assumes that there is only one IT8801 defined.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, use multiple instances.
drivers/mfd/mfd_ite_it8801.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function isn't available in this commit. Each commit should build on it's own. Add this support with the KBD driver commit.
You could have the child drivers register an alert callback. Then MFD driver doesn't need to know the type of each child.
If you wanted the alert callbacks to be configured at build time, you could define an iterable section per it8801 instance.
See INPUT_CALL_DEFINE for an example of creating an iterable section for a specific device instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to respective driver.
Because the KBD and GPIO devices of IT8801 share the gpio irq. Consider that if IT8801 is connected to the EC, the GPIO interrupt is enabled in the interrupt configuration using irq_connect_dynamic.
Repeated registration of gpio irq will cause Assert problem, so here we only register it once in mfd_ite_it8801.
dts/riscv/ite/it8801-mfd-gpiocr.dtsi
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nodename gpio0 is likely to conflict the the GPIO controller on the SoC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed.
drivers/input/input_ite_it8801_kbd.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This assumes only one KBD driver installed. This should be calculated on each KBD instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, use multiple instances.
drivers/input/input_ite_it8801_kbd.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drivers should support multiple instances.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, use multiple instances.
drivers/pwm/pwm_ite_it8801.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a BUILD_ASSERT that the init priority is lower (higher number) than the MFD parent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested in a separate comment that this could all use the same priority, then the sub priority would take care of sequencing the init correctly, I think it's a better approach, less options kicking around. Build asserts should not be needed anymore since the build priorites are checked at build time btw.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything I can refer to here? I'm encountering a build error when using CONFIG_MFD_INIT_PRIORITY + 1 in Kconfig or here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use CONFIG_MFD_INIT_PRIORITY on all the child devices.
drivers/gpio/Kconfig.it8801
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a BUILD_ASSERT to check the init priority.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use CONFIG_MFD_INIT_PRIORITY on all the child devices.
fabiobaltieri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just an quick initial, pass, noticed some comments of mine overlaps with Keith.
Hey is there a board where you could add this? I'm a bit confused by the dtsi file you have in one of the commits, would be nice to have build testing in CI as well.
drivers/mfd/Kconfig.it8801
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hey can you try to initialize all the sub devices at CONFIG_MFD_INIT_PRIORITY? the sub-priority should take care of the sequencing, less priority options kicking around... you can check the output with west build -t initlevels
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything I can refer to here? I'm encountering a build error when using CONFIG_MFD_INIT_PRIORITY + 1 here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah just use CONFIG_MFD_INIT_PRIORITY on all the child devices, then the effective initialization number is going to be a concatenation of CONFIG_MFD_INIT_PRIORITY and the ordinal that the device gets [1][2], and since the childs are under the parent the child ordinal is going to be higher than the parent which is going to result in the correct initialization sequence.
[1] https://github.com/zephyrproject-rtos/zephyr/blob/main/include/zephyr/device.h#L1112
[2] https://github.com/zephyrproject-rtos/zephyr/blob/main/include/zephyr/init.h#L150C43-L150C51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the information, fixed.
drivers/pwm/pwm_ite_it8801.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggested in a separate comment that this could all use the same priority, then the sub priority would take care of sequencing the init correctly, I think it's a better approach, less options kicking around. Build asserts should not be needed anymore since the build priorites are checked at build time btw.
2d60741 to
71000b0
Compare
I have created a test program to connect with it8xxx2_evb as shown in the link |
This is very strange. When using ./scripts/ci/check_compliance.py locally, there is a prompt such as: But after I upload the program, I get the following error: |
f1393fc to
895308e
Compare
|
Rebase and resolve conflicting files. |
|
Hi @fabiobaltieri, @keith-zephyr, If there’s any further feedback on the updates I made. Thanks! |
dts/riscv/ite/it8801-mfd-gpiocr.dtsi
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Node names should use dashes instead of underscores.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the relative path necessary? Does #include <ite/it8801-mfd-map.dtsi> work instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed to #include <ite/it8801-mfd-map.dtsi>
drivers/mfd/mfd_ite_it8801.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option here. The children devices already have a reference to the parent mfd. The MFD driver could add an API to register an interrupt callback.
mfd_it8801_register_interrupt_callback(const struct device *mfd,
const struct device *child,
callback_function);
Then you could also drop sub_mfd_dev array, and you could drop the if (dev != data->gpio_dev) checks in the child drivers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion! It really helped simplify the code.
895308e to
4e9db70
Compare
drivers/mfd/mfd_ite_it8801.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should check that mfd_cb has been assigned.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
drivers/mfd/mfd_ite_it8801.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there always a 1:1 relationship from the MFD parent to the child that needs an interrupt callback?
Or does the MFD need to maintain a list of callbacks registered?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the MFD needs to maintain a list of registered callbacks, and I have made the modifications.
4e9db70 to
6023ee2
Compare
drivers/mfd/mfd_ite_it8801.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is still more complicated than needed. The MFD parent doesn't need to know if the child is a KBD, GPIO, or PWM.
You should create a structure that each child is responsible for allocating:
struct mfd_callback {
it8801_callback_handler_t cb;
const struct device *dev;
};
Then the mfd_it8801_register_interrupt_callback() routine needs to just add the mfd_callback allocated by the child to a linked list. You can use the the gpio_manage_callback() for creating the linked list.
Then when dispatching the interrupt in it8801_gpio_alert_worker, you only need to iterate over the linked list. No special checks for KBD vs GPIO are needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
6023ee2 to
b7af79e
Compare
fabiobaltieri
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, few more comments, sorry for the delay this fell of my radar
b7af79e to
f35f465
Compare
f35f465 to
05012bf
Compare
|
Rebased. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cool, couple missing static qualifiers, rest is good, great job, Keith is out for the next couple of weeks I think it's fine to wait for him?
drivers/mfd/mfd_ite_it8801.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
drivers/input/input_ite_it8801_kbd.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
drivers/gpio/gpio_ite_it8801.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
static
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
05012bf to
20f495b
Compare
OKey, thank you for your feedback! |
drivers/gpio/gpio_ite_it8801.c
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The GPISR documentation in the IT8801 datasheet indicates:
"When GPIO Direction is 0, and the state of the corresponding pin matches the interrupt triggered condition, the corresponding bit will be set to 1."
The level_high_trig and level_low_trig fields don't seem necessary. Does the driver need to track level triggered interrupts separate from the IT8801?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The IT8801 already supports level-triggered interrupts internally. Therefore, the level_high_trig and level_low_trig fields are redundant and have been removed.
The IT8801 is an I/O expander that provides GPIO, PWM, Keyboard functions via the I2C bus. Signed-off-by: Tim Lin <[email protected]>
IT8801 support GPIO alternate function switching. Some GPIO pins can be switched as KSO or PWM function. Signed-off-by: Tim Lin <[email protected]>
Add I2C-based keyboard matrix scan device driver. IT8801 support 8 KSI pins and 19 KSO pins [22:11] [6:0]. Signed-off-by: Tim Lin <[email protected]>
Add I2C-based PWM device driver. Supports 7 open-drain/push-pull outputs. Signed-off-by: Tim Lin <[email protected]>
Add I2C-based GPIO device driver. Supports 16-port GPIO divided into 3 groups. Signed-off-by: Tim Lin <[email protected]>
Add build tests for the IT8801 MFD drivers, including GPIO, Input and PWM functionalities. GPIO, Input test: west build -p always -b native_sim PWM test: west build -p always -b it82xx2_evb Signed-off-by: Tim Lin <[email protected]>
20f495b to
ef15c0e
Compare
This PR Implements the ITE IT8801 IO expander multi-function device driver. The IO expander provides GPIO, PWM, and keyboard functions via the I2C bus.