Skip to content

Commit 521e093

Browse files
NickolasLappdleach02
authored andcommitted
I2S_MCUX: Fixup I2S MCUX Audio PLL Rate Calculation and Reg Writes
This PR Fixes the Audio PLL Rate Calculation (there was an additional divide / 8 which is not necessary and does not appear in similar calculations in example code from the SDK). Additionally, it adjusts the SAI .dtsi to more correctly configure the mclk rate, and adds comments specifying what the regististers mean. Signed-off-by: Nickolas Lapp <[email protected]>
1 parent 2dc866f commit 521e093

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

drivers/clock_control/clock_control_mcux_ccm.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -176,17 +176,17 @@ static int mcux_ccm_get_subsys_rate(const struct device *dev,
176176

177177
#ifdef CONFIG_I2S_MCUX_SAI
178178
case IMX_CCM_SAI1_CLK:
179-
*rate = CLOCK_GetFreq(kCLOCK_AudioPllClk) / 8
179+
*rate = CLOCK_GetFreq(kCLOCK_AudioPllClk)
180180
/ (CLOCK_GetDiv(kCLOCK_Sai1PreDiv) + 1)
181181
/ (CLOCK_GetDiv(kCLOCK_Sai1Div) + 1);
182182
break;
183183
case IMX_CCM_SAI2_CLK:
184-
*rate = CLOCK_GetFreq(kCLOCK_AudioPllClk) / 8
184+
*rate = CLOCK_GetFreq(kCLOCK_AudioPllClk)
185185
/ (CLOCK_GetDiv(kCLOCK_Sai2PreDiv) + 1)
186186
/ (CLOCK_GetDiv(kCLOCK_Sai2Div) + 1);
187187
break;
188188
case IMX_CCM_SAI3_CLK:
189-
*rate = CLOCK_GetFreq(kCLOCK_AudioPllClk) / 8
189+
*rate = CLOCK_GetFreq(kCLOCK_AudioPllClk)
190190
/ (CLOCK_GetDiv(kCLOCK_Sai3PreDiv) + 1)
191191
/ (CLOCK_GetDiv(kCLOCK_Sai3Div) + 1);
192192
break;

dts/arm/nxp/nxp_rt.dtsi

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -937,19 +937,32 @@
937937
#pinmux-cells = <2>;
938938
reg = <0x40384000 0x4000>;
939939
clocks = <&ccm IMX_CCM_SAI1_CLK 0x7C 2>;
940-
pre-div = <0>;
941-
podf = <63>;
942-
pll-clocks = <&anatop 0x70 0xC000 0>,
943-
<&anatop 0x70 0x7F 32>,
944-
<&anatop 0x70 0x18 1>,
945-
<&anatop 0x80 0x3FFFFFFF 77>,
946-
<&anatop 0x90 0x3FFFFFFF 100>;
940+
/* Audio PLL Output Frequency is determined by:
941+
* (Fref * (DIV_SELECT + NUM/DENOM)) / POST_DIV
942+
* = (24MHz * (32 + 77 / 100)) / 1 = 786.48 MHz
943+
*/
944+
pll-clocks = <&anatop 0x70 0xC000 0>,
945+
<&anatop 0x70 0x7F 32>,
946+
<&anatop 0x70 0x180000 1>,
947+
<&anatop 0x80 0x3FFFFFFF 77>,
948+
<&anatop 0x90 0x3FFFFFFF 100>;
947949
pll-clock-names = "src", "lp", "pd", "num", "den";
950+
/* The maximum input frequency into the SAI mclk input is 300MHz
951+
* Based on this requirement, pre-div must be at least 3
952+
* The pre-div and post-div are one less than the actual divide-by amount.
953+
* A pre-div value of 0x1 results in a pre-divider of
954+
* (1+1) = 2
955+
*/
956+
pre-div = <0x3>;
957+
podf = <0x0F>;
948958
pinmuxes = <&iomuxcgpr 0x4 0x80000>;
949959
interrupts = <56 0>;
950960
dmas = <&edma0 0 19>, <&edma0 0 20>;
951961
dma-names = "rx", "tx";
952-
nxp,tx-channel = <0>;
962+
/* This translates to SAIChannelMask (fsl_sai.c) and
963+
* cannot be 0
964+
*/
965+
nxp,tx-channel = <1>;
953966
nxp,tx-dma-channel = <0>;
954967
nxp,rx-dma-channel = <1>;
955968
status = "disabled";
@@ -965,11 +978,11 @@
965978
clocks = <&ccm IMX_CCM_SAI2_CLK 0x7C 2>;
966979
pre-div = <0>;
967980
podf = <63>;
968-
pll-clocks = <&anatop 0x70 0xC000 0>,
969-
<&anatop 0x70 0x7F 32>,
970-
<&anatop 0x70 0x18 1>,
971-
<&anatop 0x80 0x3FFFFFFF 77>,
972-
<&anatop 0x90 0x3FFFFFFF 100>;
981+
pll-clocks = <&anatop 0x70 0xC000 0x0>,
982+
<&anatop 0x70 0x7F 32>,
983+
<&anatop 0x70 0x180000 1>,
984+
<&anatop 0x80 0x3FFFFFFF 77>,
985+
<&anatop 0x90 0x3FFFFFFF 100>;
973986
pll-clock-names = "src", "lp", "pd", "num", "den";
974987
pinmuxes = <&iomuxcgpr 0x4 0x100000>;
975988
interrupts = <57 0>;
@@ -993,7 +1006,7 @@
9931006
podf = <63>;
9941007
pll-clocks = <&anatop 0x70 0xC000 0>,
9951008
<&anatop 0x70 0x7F 32>,
996-
<&anatop 0x70 0x18 1>,
1009+
<&anatop 0x70 0x180000 1>,
9971010
<&anatop 0x80 0x3FFFFFFF 77>,
9981011
<&anatop 0x90 0x3FFFFFFF 100>;
9991012
pll-clock-names = "src", "lp", "pd", "num", "den";

0 commit comments

Comments
 (0)