Skip to content

Conversation

@diegosueiro
Copy link
Contributor

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.

@codecov-io
Copy link

codecov-io commented May 9, 2018

Codecov Report

Merging #7424 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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     2066

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a7e2c58...84b5445. Read the comment docs.

galak
galak previously requested changes May 9, 2018
Copy link
Contributor

@galak galak left a 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.

Copy link
Contributor

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)

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

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

Copy link
Contributor

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?

Copy link
Contributor

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";

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@galak,

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.

Copy link
Contributor

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";

Copy link
Contributor Author

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.

Copy link
Contributor Author

@diegosueiro diegosueiro May 9, 2018

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?

Copy link
Contributor

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.

Copy link
Contributor Author

@diegosueiro diegosueiro May 9, 2018

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.

Copy link
Member

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

@dbkinder dbkinder left a 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

@diegosueiro diegosueiro force-pushed the imx7d_i2c branch 2 times, most recently from bfe050a to 0799657 Compare May 11, 2018 21:21
@diegosueiro
Copy link
Contributor Author

@galak and @MaureenHelm ,

Are you expecting to merge this before the merge window close?

@diegosueiro
Copy link
Contributor Author

@galak and @MaureenHelm,

Should I rebase this PR to get it merged?

Copy link
Member

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)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@galak,

What should I do with the HAS_DTS_I2C selection?

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaureenHelm and @galak ,

Done.

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I2C4, not I2C3

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MaureenHelm ,

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@diegosueiro diegosueiro force-pushed the imx7d_i2c branch 2 times, most recently from 8a15094 to 6e96a7b Compare July 2, 2018 05:48
Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line

Copy link
Contributor Author

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]>
@MaureenHelm MaureenHelm merged commit 618209a into zephyrproject-rtos:master Jul 6, 2018
@diegosueiro diegosueiro deleted the imx7d_i2c branch July 19, 2018 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants