-
Notifications
You must be signed in to change notification settings - Fork 8.2k
drivers: add imx7d i2c driver #7424
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
Codecov Report
@@ Coverage Diff @@
## master #7424 +/- ##
=======================================
Coverage 52.24% 52.24%
=======================================
Files 195 195
Lines 24655 24655
Branches 5123 5123
=======================================
Hits 12880 12880
Misses 9709 9709
Partials 2066 2066Continue to review full report at Codecov.
|
galak
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.
See comments, also need to add device tree support.
drivers/i2c/CMakeLists.txt
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.
Seems like we should keep this the same as the other lines:
zephyr_source_ifdef(CONFIG_I2C_IMX . i2c_imx.c)
drivers/i2c/Kconfig.imx
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.
Don't add a new Kconfig file, please model this off of what is done for i2c_mcux, use CONFIG_I2C_1, CONFIG_I2C_2, etc.
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.
For imx we have the hardware mapped from I2C_1 to I2C_4 and in the Kconfig we have I2C_0 to I2C_3.
What is your suggestion, add the I2C_4 option to Kconfig or use 0 to 3 and consider 0 as 1, 1 as 2 and so on, for the imx?
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'm saying add I2C_4 to Kconfig, and just use I2C_1..I2C_4
drivers/i2c/i2c_imx.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.
Shouldn't this be your copyright?
dts/bindings/i2c/nxp,imx-i2c.yaml
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.
should be compatible = "fsl,imx7d-i2c";
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 binding can be used by other imx cores (ie. imx6sx_m4). I believe that it is the same situation of nxp,imx-gpio.yaml, that shares the same dts binding and gpio driver shim.
I even think that they can share the same i2c driver shim. Maybe @stanislav-poboril can help us in checking this.
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.
So technically I think it should be: "fsl,imx21-i2c", this is based on the device tree used in Linux for i.mx. We should using the same compats / bindings for devices that already have one's defined by Linux.
So if you look at the imx dts you'll see something like:
compatible = "fsl,imx7d-i2c", "fsl,imx21-i2c";
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.
So, do you think we have to change in nxp,imx-i2c.yaml to constraint: "fsl,imx7d-i2c", "fsl,imx21-i2c" and on nxp_imx7d_m4.dtsi compatible = "fsl,imx7d-i2c"?
Sorry but I got a little bit confused what needs to be changed.
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.
If I change from "nxp,imx-i2c" to "fsl,imx21-i2c" I'll have to change NXP_IMX_I2C to FSL_IMX21_I2C in the dts.fixup file which will not follow the definition pattern of the other devices like UART and GPIO and looks strange to me.
I would like to keep the same pattern for easy maintenance.
@MaureenHelm ,
What do you think?
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.
So, do you think we have to change in nxp,imx-i2c.yaml to constraint: "fsl,imx7d-i2c", "fsl,imx21-i2c" and on nxp_imx7d_m4.dtsi compatible = "fsl,imx7d-i2c"?
Sorry but I got a little bit confused what needs to be changed.
So we don't handle multiple compats well today with regards to the binding files. So I'm saying we use 'fsl,imx7d-i2c' so that we are matching linux (at least partially).
I understand that the pattern will differ from other items, but that is ok. This is what should be in the DTS for the i2c controller.
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.
Ok. But when the imx6sx will be added it will have to duplicate the fsl,imx7d-i2c.yaml to fsl,imx6sl-i2c.yaml and the compatible string as well.
In the Linux kernel the common denominator for both platforms is "fsl,imx21-i2c", why we can't use "nxp,imx-i2c" as a common denominator for Zephyr?
Don't get me wrong, but I'm just trying to keep things simple, concise and avoid unnecessary code duplication.
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.
So we don't handle multiple compats well today with regards to the binding files.
Does this mean we can define exactly one constraint in a given yaml file, but we can define multiple compatibles in the dts?
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.
Does this mean we can define exactly one constraint in a given yaml file, but we can define multiple compatibles in the dts?
Correct, the dts is happy to have multiple compats. The yaml for the binding don't handle this well. Right now there is an expectation of 1:1 yaml to compat.
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.
@galak ,
Devicetree compatible string suggestion addressed.
dbkinder
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.
+1 for doc changes
bfe050a to
0799657
Compare
|
@galak and @MaureenHelm , Are you expecting to merge this before the merge window close? |
|
@galak and @MaureenHelm, Should I rebase this PR to get it merged? |
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.
@galak, should this select get moved to the driver? We're inconsistent about where HAS_DTS_I2C gets selected. In some cases (NXP and STM), it's selected by the driver, in other cases it's selected by the board (Nordic, x86)
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.
What should I do with the HAS_DTS_I2C selection?
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.
Seems like the driver should select this, not the board.
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.
@MaureenHelm and @galak ,
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.
Replace the underscore with a hyphen
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.
I2C4, not I2C3
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/i2c/CMakeLists.txt
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.
Please move this below i2c_gpio to maintain alpha order
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/i2c/i2c_imx.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.
I2C_MSG_RESTART applies to the current message, not the next one, so I don't think it's correct to preserve the restart flag here. Look at how it's used in i2c_burst_read in include/i2c.h
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've followed the same approach implemented in i2c_bitbang.c and tested with different i2c messages combinations and it worked without any issues.Preserving the restart flag is used to decide if it needs to send and start (by setting the appropriate mode according to the data sheet) or repeat start on the bus.
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.
8a15094 to
6e96a7b
Compare
drivers/i2c/i2c_imx.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 condition will only be satisfied on the first iteration and doesn't need to be inside the do/while loop. If you move it out, then you can move flags |= msgs->flags to the beginning of the loop, and use flags consistently throughout the loop. The current mix of flags and msgs->flags is confusing.
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/i2c/Kconfig
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.
Remove this line. See #8586
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
ext/hal/nxp/imx/Kconfig
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.
Remove this line
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
Adds a shim layer around the imx i2c driver to adapt it to the Zephyr i2c master interface. Signed-off-by: Diego Sueiro <[email protected]>
Adds all necessary i2c definitions and configurations for imx7d_m4 soc. Signed-off-by: Diego Sueiro <[email protected]>
Adds definitions, configurations and device tree entries for colibri_imx7d_m4 board. Signed-off-by: Diego Sueiro <[email protected]>
This pull request is to add i2c driver for mcimx7_m4 arch and colibri_imx7d_m4 board.
The implementation was tested on the colibri_imx7d_m4 board by compiling and running the samples/grove/lcd application (extra delays between messages have to be added because of the grove lcd module restrictions) using the I2C_4 bus. Another validation was made with a simple application performing reads and writes to an RTC (m41t0) located in the Toradex Colibri Evaluation board.