1616#include <device.h>
1717#include <init.h>
1818#include <drivers/dma.h>
19-
2019#include <drivers/i2s.h>
20+ #ifdef CONFIG_PINCTRL
21+ #include <drivers/pinctrl.h>
22+ #endif
2123#include <drivers/clock_control.h>
2224#include <dt-bindings/clock/imx_ccm.h>
2325#include <soc.h>
@@ -78,6 +80,9 @@ struct i2s_mcux_config {
7880 uint32_t tx_channel ;
7981 clock_control_subsys_t clk_sub_sys ;
8082 const struct device * ccm_dev ;
83+ #ifdef CONFIG_PINCTRL
84+ const struct pinctrl_dev_config * pinctrl ;
85+ #endif
8186 void (* irq_connect )(const struct device * dev );
8287 bool rx_sync_mode ;
8388 bool tx_sync_mode ;
@@ -335,7 +340,6 @@ static void enable_mclk_direction(const struct device *dev, bool dir)
335340 } else {
336341 * gpr &= ~mask ;
337342 }
338-
339343}
340344
341345static void get_mclk_rate (const struct device * dev , uint32_t * mclk )
@@ -969,6 +973,9 @@ static int i2s_mcux_initialize(const struct device *dev)
969973 I2S_Type * base = (I2S_Type * )dev_cfg -> base ;
970974 struct i2s_dev_data * dev_data = dev -> data ;
971975 uint32_t mclk ;
976+ #ifdef CONFIG_PINCTRL
977+ int err ;
978+ #endif
972979
973980 if (!dev_data -> dev_dma ) {
974981 LOG_ERR ("DMA device not found" );
@@ -987,6 +994,14 @@ static int i2s_mcux_initialize(const struct device *dev)
987994
988995 /* register ISR */
989996 dev_cfg -> irq_connect (dev );
997+ /* pinctrl */
998+ #ifdef CONFIG_PINCTRL
999+ err = pinctrl_apply_state (dev_cfg -> pinctrl , PINCTRL_STATE_DEFAULT );
1000+ if (err ) {
1001+ LOG_ERR ("mclk pinctrl setup failed (%d)" , err );
1002+ return err ;
1003+ }
1004+ #endif
9901005
9911006 /*clock configuration*/
9921007 audio_clock_settings (dev );
@@ -1036,9 +1051,19 @@ static const struct i2s_driver_api i2s_mcux_driver_api = {
10361051 .trigger = i2s_mcux_trigger ,
10371052};
10381053
1054+ #ifdef CONFIG_PINCTRL
1055+ #define PINCTRL_DEFINE (i2s_id ) PINCTRL_DT_INST_DEFINE(i2s_id);
1056+ #define PINCTRL_INIT (i2s_id ) .pinctrl = PINCTRL_DT_INST_DEV_CONFIG_GET(i2s_id),
1057+ #else
1058+ #define PINCTRL_DEFINE (i2s_id )
1059+ #define PINCTRL_INIT (i2s_id )
1060+ #endif
1061+
10391062#define I2S_MCUX_INIT (i2s_id ) \
10401063 static void i2s_irq_connect_##i2s_id(const struct device *dev); \
10411064 \
1065+ PINCTRL_DEFINE(i2s_id) \
1066+ \
10421067 static const struct i2s_mcux_config i2s_##i2s_id##_config = { \
10431068 .base = (I2S_Type *)DT_INST_REG_ADDR(i2s_id), \
10441069 .clk_src = \
@@ -1071,6 +1096,7 @@ static const struct i2s_driver_api i2s_mcux_driver_api = {
10711096 DT_INST_CLOCKS_CELL_BY_IDX(i2s_id, 0, name), \
10721097 .ccm_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(i2s_id)), \
10731098 .irq_connect = i2s_irq_connect_##i2s_id, \
1099+ PINCTRL_INIT(i2s_id) \
10741100 .tx_sync_mode = \
10751101 DT_INST_PROP(i2s_id, nxp_tx_sync_mode), \
10761102 .rx_sync_mode = \
0 commit comments