Skip to content

Commit f300ff4

Browse files
hakehuangdanieldegrasse
authored andcommitted
driver: sai: add pinctrl support in mcux sai
enable i2s pinctrl Signed-off-by: Hake Huang <[email protected]>
1 parent 7160d4f commit f300ff4

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

drivers/i2s/i2s_mcux_sai.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616
#include <device.h>
1717
#include <init.h>
1818
#include <drivers/dma.h>
19-
2019
#include <drivers/i2s.h>
20+
#include <drivers/pinctrl.h>
2121
#include <drivers/clock_control.h>
2222
#include <dt-bindings/clock/imx_ccm.h>
2323
#include <soc.h>
@@ -78,6 +78,7 @@ struct i2s_mcux_config {
7878
uint32_t tx_channel;
7979
clock_control_subsys_t clk_sub_sys;
8080
const struct device *ccm_dev;
81+
const struct pinctrl_dev_config *pinctrl;
8182
void (*irq_connect)(const struct device *dev);
8283
bool rx_sync_mode;
8384
bool tx_sync_mode;
@@ -328,15 +329,24 @@ static void enable_mclk_direction(const struct device *dev, bool dir)
328329
const struct i2s_mcux_config *dev_cfg = dev->config;
329330
uint32_t offset = dev_cfg->mclk_pin_offset;
330331
uint32_t mask = dev_cfg->mclk_pin_mask;
331-
uint32_t value = 0;
332332
uint32_t *gpr = (uint32_t *)DT_REG_ADDR(DT_NODELABEL(iomuxcgpr)) + offset;
333333

334334
if (dir) {
335335
*gpr |= mask;
336336
} else {
337337
*gpr &= ~mask;
338338
}
339+
}
340+
341+
static void mcux_rt_sai_pin_init(void)
342+
{
343+
int err;
339344

345+
err = pinctrl_apply_state(dev_cfg->pinctrl, PINCTRL_STATE_DEFAULT);
346+
if (err < 0) {
347+
LOG_ERR("mclk pinctrl setup failed (%d)", err);
348+
return err;
349+
}
340350
}
341351

342352
static void get_mclk_rate(const struct device *dev, uint32_t *mclk)
@@ -989,6 +999,9 @@ static int i2s_mcux_initialize(const struct device *dev)
989999
/* register ISR */
9901000
dev_cfg->irq_connect(dev);
9911001

1002+
/* pinctrl */
1003+
mcux_rt_sai_pin_init();
1004+
9921005
/*clock configuration*/
9931006
audio_clock_settings(dev);
9941007

@@ -1040,6 +1053,8 @@ static const struct i2s_driver_api i2s_mcux_driver_api = {
10401053
#define I2S_MCUX_INIT(i2s_id) \
10411054
static void i2s_irq_connect_##i2s_id(const struct device *dev); \
10421055
\
1056+
PINCTRL_DT_INST_DEFINE(i2s_id); \
1057+
\
10431058
static const struct i2s_mcux_config i2s_##i2s_id##_config = { \
10441059
.base = (I2S_Type *)DT_INST_REG_ADDR(i2s_id), \
10451060
.clk_src = \
@@ -1071,6 +1086,7 @@ static const struct i2s_driver_api i2s_mcux_driver_api = {
10711086
.clk_sub_sys = (clock_control_subsys_t) \
10721087
DT_INST_CLOCKS_CELL_BY_IDX(i2s_id, 0, name), \
10731088
.ccm_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(i2s_id)), \
1089+
.pinctrl = PINCTRL_DT_INST_DEV_CONFIG_GET(i2s_id), \
10741090
.irq_connect = i2s_irq_connect_##i2s_id, \
10751091
.tx_sync_mode = \
10761092
DT_INST_PROP(i2s_id, nxp_tx_sync_mode), \

0 commit comments

Comments
 (0)