Skip to content
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

nxp: Add SAI driver with the DAI interface #65187

Merged
merged 4 commits into from
Dec 20, 2023

Conversation

LaurentiuM1234
Copy link
Collaborator

For now, this PR shall remain a draft until all NXP HAL PRs are ready.

An example DTS node can be found below (i.MX93, SOF usage):

sai3: dai@42660000 {
    compatible = "nxp,dai-sai";
    reg = <0x42660000 DT_SIZE_K(64)>;
    mclk-is-output;
    clocks = <&ccm IMX_CCM_SAI3_CLK 0x0 0x0>;
    clock-names = "mclk1";
    rx-fifo-watermark = <96>;
    tx-fifo-watermark = <1>;
    fifo-depth = <96>;
    interrupt-parent = <&gic>;
    interrupts = <GIC_SPI 171 IRQ_TYPE_LEVEL IRQ_DEFAULT_PRIORITY>;
 };

The additional configurations required to get the driver working are (i.MX93):

CONFIG_DAI=y
CONFIG_SAI_HAS_MCLK_CONFIG_OPTION=y
CONFIG_SAI_HAS_XCR4_CHMOD=y

Tagging @dbaluta and @iuliana-prodan for initial comments.

@LaurentiuM1234 LaurentiuM1234 force-pushed the sai_to_upstream branch 3 times, most recently from 300c574 to 7525186 Compare November 15, 2023 12:23
@LaurentiuM1234 LaurentiuM1234 marked this pull request as ready for review November 15, 2023 12:24
@zephyrbot zephyrbot added area: Clock Control area: DAI area: ARM64 ARM (64-bit) Architecture area: Devicetree Binding PR modifies or adds a Device Tree binding platform: NXP NXP labels Nov 15, 2023
@zephyrbot
Copy link
Collaborator

zephyrbot commented Nov 15, 2023

The following west manifest projects have been modified in this Pull Request:

Name Old Revision New Revision Diff
hal_nxp zephyrproject-rtos/hal_nxp@2a294b5 zephyrproject-rtos/hal_nxp@ed3efff (master) zephyrproject-rtos/[email protected]

Note: This message is automatically posted and updated by the Manifest GitHub Action.

Copy link
Collaborator

@danieldegrasse danieldegrasse left a comment

Choose a reason for hiding this comment

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

A very broad comment- based on the dai_protocol enum, it sort of looks like these formats are just the same as those we support in I2S today: https://docs.zephyrproject.org/latest/hardware/peripherals/audio/i2s.html. Given that, is there any reason this DAI driver could not be written to use the I2S API itself, instead of the SAI peripheral? It seems like the DAI API is intended as a superset of the I2S API, but maybe I'm missing some advantage here.

@danieldegrasse
Copy link
Collaborator

If we'd use I2S interface here, SOF application code would require a target/hw based separate code path to talk to I2S driver interface in case of this NXP target, and this is what we wanted to avoid

Absolutely- I don't think we should change SOF application code. What I'm wondering is if it would be possible to create a DAI driver (say dai_i2s.c) that implements the DAI interface by calling the I2S APIs, essentially as a wrapper layer. This way there is no change needed to the SOF application layer, and we reuse the existing code in I2S drivers.

@dbaluta
Copy link
Collaborator

dbaluta commented Nov 22, 2023

Absolutely- I don't think we should change SOF application code. What I'm wondering is if it would be possible to create a DAI driver (say dai_i2s.c) that implements the DAI interface by calling the I2S APIs, essentially as a wrapper layer. This way there is no change needed to the SOF application layer, and we reuse the existing code in I2S drivers.

Although an interesting idea I think that would be an overkill. Sometimes there will be functions that could be imported from i2s but sometimes not. So, I think we complicate things unnecessary. Maybe after we get this in and have it in a stable form we could reduce code duplication by looking at this.

@danieldegrasse
Copy link
Collaborator

Although an interesting idea I think that would be an overkill. Sometimes there will be functions that could be imported from i2s but sometimes not. So, I think we complicate things unnecessary. Maybe after we get this in and have it in a stable form we could reduce code duplication by looking at this.

Understood- you're the expert here, this was just a passing thought :) If it doesn't make sense than no worries

drivers/dai/CMakeLists.txt Outdated Show resolved Hide resolved
drivers/dai/nxp/sai.h Outdated Show resolved Hide resolved
drivers/dai/nxp/sai.h Outdated Show resolved Hide resolved
drivers/dai/nxp/sai.h Outdated Show resolved Hide resolved
drivers/dai/nxp/sai.h Outdated Show resolved Hide resolved
drivers/dai/nxp/sai.c Outdated Show resolved Hide resolved
drivers/dai/nxp/sai.c Outdated Show resolved Hide resolved
drivers/dai/nxp/sai.c Outdated Show resolved Hide resolved
drivers/dai/nxp/sai.c Outdated Show resolved Hide resolved
drivers/dai/nxp/sai.c Outdated Show resolved Hide resolved
@LaurentiuM1234
Copy link
Collaborator Author

V2 updates

  1. sai_trigger() now only allows COPY and PRE_START operations (apart from those which are already supported and translate to a trigger function). The rest of the trigger commands will be treated as errors. If there's ever such a trigger causing an error we're going to have to decide between adding support for it or marking it as success if the SAI doesn't need to implement it.
  2. Fixed typo inside SAI_TX_RX_SW_RESET().
  3. CONFIG_SAI_HAS_XCR4_CHMOD has been entirely removed and replaced by FSL_FEATURE_SAI_HAS_CHANNEL_MODE.
  4. Removed comment regarding READY->READY state transition (a.k.a doing a config_set after a config_set). This transition should be allowed since re-configuring the SAI immediately after a configuration isn't illogical and won't break anything. As far as I can tell, the double set_config() call from SOF still happens. Not sure why (perhaps it's done for every direction?)
  5. Added explanation about why we're going to keep data->cfg.rate = bespoke->fsync_rate; and where it's used.
  6. sai_tx_rx_disable() now uses WAIT_FOR(). The timeout value has been determined empirically. The core problem (the fac that we shouldn't be doing busy waiting) wasn't solved.

Hopefully I didn't miss anything

@LaurentiuM1234 LaurentiuM1234 force-pushed the sai_to_upstream branch 2 times, most recently from 2830367 to 4e91fde Compare December 4, 2023 11:12
@LaurentiuM1234
Copy link
Collaborator Author

V3 updates

  1. Moved initialization to POST_KERNEL and removed stage check from sai_tx_rx_disable().
  2. SAI-related files are now found under dai/nxp/sai.

iuliana-prodan
iuliana-prodan previously approved these changes Dec 4, 2023
@dbaluta
Copy link
Collaborator

dbaluta commented Dec 4, 2023

Looks good to me. Now we need to merge dependencies and then we are good to go.

Thanks @LaurentiuM1234 !

@LaurentiuM1234
Copy link
Collaborator Author

LaurentiuM1234 commented Dec 6, 2023

V4 updates

  1. The number of channels from struct dai_config, kept inside struct sai_data is now set to the number of TDM slots via sai_config_set(). See comment from line 374 (in sai.c) for explanation.
  2. Removed the cfg->channels > bespoke->tdm_slots check from sai_config_set(). The number of channels is set via bespoke configuration's tdm_slots field. Also, SOF doesn't set cfg->channels. Instead, it expects the DAI driver to do so. This means that cfg->channels is 0 so the check is useless.

west.yml Outdated Show resolved Hide resolved
@zephyrbot zephyrbot removed the DNM This PR should not be merged (Do Not Merge) label Dec 14, 2023
Bump up hal_nxp revision to contain the latest SAI-related
changes from NXP HAL side.

Signed-off-by: Laurentiu Mihalcea <[email protected]>
This commit introduces some macros and enums which can
be used to parse struct dai_config's format field. This is
required by the SAI driver since it uses dai_config's format
field to select the protocol, clock configuration and clock
inversion. This is added to the dai.h header to avoid having
to define these macros/enums in each of the DAI drivers.

Signed-off-by: Laurentiu Mihalcea <[email protected]>
This commit introduces a new DAI driver used for NXP'S SAI IP.

Signed-off-by: Laurentiu Mihalcea <[email protected]>
This commit introduces support for querying
i.MX93's SAI clocks.

Signed-off-by: Laurentiu Mihalcea <[email protected]>
@LaurentiuM1234
Copy link
Collaborator Author

@kv2019i @lgirdwood could you please take a look at the changes to dai.h? Would like to have at least one approval from Intel's side on this. Thanks!

@dbaluta
Copy link
Collaborator

dbaluta commented Dec 20, 2023

All good!

@lgirdwood @kv2019i can you please review commit modifying dai.h common part: 7a9401d

@carlescufi carlescufi merged commit 52deadd into zephyrproject-rtos:main Dec 20, 2023
21 of 22 checks passed
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.

8 participants