Skip to content

Commit abc285d

Browse files
committed
[nrf noup] drivers: i2s: nrfx: Align to driver without cb
Align SHIM to nrfx_i2s driver version without cb. Signed-off-by: Jakub Zymelka <[email protected]>
1 parent e5b62c0 commit abc285d

File tree

1 file changed

+74
-83
lines changed

1 file changed

+74
-83
lines changed

drivers/i2s/i2s_nrfx.c

Lines changed: 74 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,20 @@ struct i2s_nrfx_drv_data {
3333
struct k_msgq tx_queue;
3434
struct stream_cfg rx;
3535
struct k_msgq rx_queue;
36-
const nrfx_i2s_t *p_i2s;
36+
nrfx_i2s_t i2s;
3737
const uint32_t *last_tx_buffer;
3838
enum i2s_state state;
3939
enum i2s_dir active_dir;
4040
bool stop; /* stop after the current (TX or RX) block */
4141
bool discard_rx; /* discard further RX blocks */
4242
volatile bool next_tx_buffer_needed;
43-
bool tx_configured : 1;
44-
bool rx_configured : 1;
45-
bool request_clock : 1;
43+
bool tx_configured: 1;
44+
bool rx_configured: 1;
45+
bool request_clock: 1;
4646
};
4747

4848
struct i2s_nrfx_drv_cfg {
4949
nrfx_i2s_data_handler_t data_handler;
50-
nrfx_i2s_t i2s;
5150
nrfx_i2s_config_t nrfx_def_cfg;
5251
const struct pinctrl_dev_config *pcfg;
5352
enum clock_source {
@@ -81,7 +80,7 @@ static void find_suitable_clock(const struct i2s_nrfx_drv_cfg *drv_cfg,
8180
.allow_bypass = IS_ENABLED(CONFIG_I2S_NRFX_ALLOW_MCK_BYPASS),
8281
};
8382

84-
if (nrfx_i2s_prescalers_calc(&clk_params, &config->prescalers) != NRFX_SUCCESS) {
83+
if (nrfx_i2s_prescalers_calc(&clk_params, &config->prescalers)) {
8584
LOG_ERR("Failed to find suitable I2S clock configuration.");
8685
}
8786
}
@@ -134,7 +133,7 @@ static bool supply_next_buffers(struct i2s_nrfx_drv_data *drv_data,
134133
if (drv_data->active_dir != I2S_DIR_TX) { /* -> RX active */
135134
if (!get_next_rx_buffer(drv_data, next)) {
136135
drv_data->state = I2S_STATE_ERROR;
137-
nrfx_i2s_stop(drv_data->p_i2s);
136+
nrfx_i2s_stop(&drv_data->i2s);
138137
return false;
139138
}
140139
/* Set buffer size if there is no TX buffer (which effectively
@@ -149,7 +148,7 @@ static bool supply_next_buffers(struct i2s_nrfx_drv_data *drv_data,
149148
drv_data->last_tx_buffer = next->p_tx_buffer;
150149

151150
LOG_DBG("Next buffers: %p/%p", next->p_tx_buffer, next->p_rx_buffer);
152-
nrfx_i2s_next_buffers_set(drv_data->p_i2s, next);
151+
nrfx_i2s_next_buffers_set(&drv_data->i2s, next);
153152
return true;
154153
}
155154

@@ -181,7 +180,7 @@ static void data_handler(const struct device *dev,
181180
}
182181
drv_data->last_tx_buffer = NULL;
183182
}
184-
nrfx_i2s_uninit(drv_data->p_i2s);
183+
nrfx_i2s_uninit(&drv_data->i2s);
185184
if (drv_data->request_clock) {
186185
(void)onoff_release(drv_data->clk_mgr);
187186
}
@@ -198,7 +197,7 @@ static void data_handler(const struct device *dev,
198197
LOG_ERR("Next buffers not supplied on time");
199198
drv_data->state = I2S_STATE_ERROR;
200199
}
201-
nrfx_i2s_stop(drv_data->p_i2s);
200+
nrfx_i2s_stop(&drv_data->i2s);
202201
return;
203202
}
204203

@@ -248,7 +247,7 @@ static void data_handler(const struct device *dev,
248247
}
249248

250249
if (stop_transfer) {
251-
nrfx_i2s_stop(drv_data->p_i2s);
250+
nrfx_i2s_stop(&drv_data->i2s);
252251
} else if (status & NRFX_I2S_STATUS_NEXT_BUFFERS_NEEDED) {
253252
nrfx_i2s_buffers_t next = { 0 };
254253

@@ -419,8 +418,8 @@ static int i2s_nrfx_configure(const struct device *dev, enum i2s_dir dir,
419418
* the MCK output is used), find a suitable clock configuration for it.
420419
*/
421420
if (nrfx_cfg.mode == NRF_I2S_MODE_MASTER ||
422-
(nrf_i2s_mck_pin_get(drv_cfg->i2s.p_reg) & I2S_PSEL_MCK_CONNECT_Msk)
423-
== I2S_PSEL_MCK_CONNECT_Connected << I2S_PSEL_MCK_CONNECT_Pos) {
421+
(nrf_i2s_mck_pin_get(drv_data->i2s.p_reg) & I2S_PSEL_MCK_CONNECT_Msk) ==
422+
I2S_PSEL_MCK_CONNECT_Connected << I2S_PSEL_MCK_CONNECT_Pos) {
424423
find_suitable_clock(drv_cfg, &nrfx_cfg, i2s_cfg);
425424
/* Unless the PCLK32M source is used with the HFINT oscillator
426425
* (which is always available without any additional actions),
@@ -578,7 +577,7 @@ static int start_transfer(struct i2s_nrfx_drv_data *drv_data)
578577
/* Failed to allocate next RX buffer */
579578
ret = -ENOMEM;
580579
} else {
581-
nrfx_err_t err;
580+
int err;
582581

583582
/* It is necessary to set buffer size here only for I2S_DIR_RX,
584583
* because only then the get_next_tx_buffer() call in the if
@@ -591,16 +590,16 @@ static int start_transfer(struct i2s_nrfx_drv_data *drv_data)
591590

592591
drv_data->last_tx_buffer = initial_buffers.p_tx_buffer;
593592

594-
err = nrfx_i2s_start(drv_data->p_i2s, &initial_buffers, 0);
595-
if (err == NRFX_SUCCESS) {
593+
err = nrfx_i2s_start(&drv_data->i2s, &initial_buffers, 0);
594+
if (err == 0) {
596595
return 0;
597596
}
598597

599-
LOG_ERR("Failed to start I2S transfer: 0x%08x", err);
598+
LOG_ERR("Failed to start I2S transfer: %d", err);
600599
ret = -EIO;
601600
}
602601

603-
nrfx_i2s_uninit(drv_data->p_i2s);
602+
nrfx_i2s_uninit(&drv_data->i2s);
604603
if (drv_data->request_clock) {
605604
(void)onoff_release(drv_data->clk_mgr);
606605
}
@@ -629,7 +628,7 @@ static void clock_started_callback(struct onoff_manager *mgr,
629628
* the actual transfer in such case.
630629
*/
631630
if (drv_data->state == I2S_STATE_READY) {
632-
nrfx_i2s_uninit(drv_data->p_i2s);
631+
nrfx_i2s_uninit(&drv_data->i2s);
633632
(void)onoff_release(drv_data->clk_mgr);
634633
} else {
635634
(void)start_transfer(drv_data);
@@ -640,22 +639,22 @@ static int trigger_start(const struct device *dev)
640639
{
641640
struct i2s_nrfx_drv_data *drv_data = dev->data;
642641
const struct i2s_nrfx_drv_cfg *drv_cfg = dev->config;
643-
nrfx_err_t err;
642+
int err;
644643
int ret;
645644
const nrfx_i2s_config_t *nrfx_cfg = (drv_data->active_dir == I2S_DIR_TX)
646645
? &drv_data->tx.nrfx_cfg
647646
: &drv_data->rx.nrfx_cfg;
648647

649-
err = nrfx_i2s_init(drv_data->p_i2s, nrfx_cfg, drv_cfg->data_handler);
650-
if (err != NRFX_SUCCESS) {
651-
LOG_ERR("Failed to initialize I2S: 0x%08x", err);
648+
err = nrfx_i2s_init(&drv_data->i2s, nrfx_cfg, drv_cfg->data_handler);
649+
if (err != 0) {
650+
LOG_ERR("Failed to initialize I2S: %d", err);
652651
return -EIO;
653652
}
654653

655654
drv_data->state = I2S_STATE_RUNNING;
656655

657656
#if NRF_I2S_HAS_CLKCONFIG
658-
nrf_i2s_clk_configure(drv_cfg->i2s.p_reg,
657+
nrf_i2s_clk_configure(drv_data->i2s.p_reg,
659658
drv_cfg->clk_src == ACLK ? NRF_I2S_CLKSRC_ACLK
660659
: NRF_I2S_CLKSRC_PCLK32M,
661660
nrfx_cfg->prescalers.enable_bypass);
@@ -669,7 +668,7 @@ static int trigger_start(const struct device *dev)
669668
clock_started_callback);
670669
ret = onoff_request(drv_data->clk_mgr, &drv_data->clk_cli);
671670
if (ret < 0) {
672-
nrfx_i2s_uninit(drv_data->p_i2s);
671+
nrfx_i2s_uninit(&drv_data->i2s);
673672
drv_data->state = I2S_STATE_READY;
674673

675674
LOG_ERR("Failed to request clock: %d", ret);
@@ -776,7 +775,7 @@ static int i2s_nrfx_trigger(const struct device *dev,
776775
case I2S_TRIGGER_DROP:
777776
if (drv_data->state != I2S_STATE_READY) {
778777
drv_data->discard_rx = true;
779-
nrfx_i2s_stop(drv_data->p_i2s);
778+
nrfx_i2s_stop(&drv_data->i2s);
780779
}
781780
purge_queue(dev, dir);
782781
drv_data->state = I2S_STATE_READY;
@@ -824,63 +823,55 @@ static DEVICE_API(i2s, i2s_nrf_drv_api) = {
824823
#define I2S(idx) DT_NODELABEL(i2s##idx)
825824
#define I2S_CLK_SRC(idx) DT_STRING_TOKEN(I2S(idx), clock_source)
826825

827-
#define I2S_NRFX_DEVICE(idx) \
828-
static struct i2s_buf tx_msgs##idx[CONFIG_I2S_NRFX_TX_BLOCK_COUNT]; \
829-
static struct i2s_buf rx_msgs##idx[CONFIG_I2S_NRFX_RX_BLOCK_COUNT]; \
830-
static void data_handler##idx(nrfx_i2s_buffers_t const *p_released, \
831-
uint32_t status) \
832-
{ \
833-
data_handler(DEVICE_DT_GET(I2S(idx)), p_released, status); \
834-
} \
835-
PINCTRL_DT_DEFINE(I2S(idx)); \
836-
static const struct i2s_nrfx_drv_cfg i2s_nrfx_cfg##idx = { \
837-
.data_handler = data_handler##idx, \
838-
.i2s = NRFX_I2S_INSTANCE(idx), \
839-
.nrfx_def_cfg = NRFX_I2S_DEFAULT_CONFIG( \
840-
NRF_I2S_PIN_NOT_CONNECTED, \
841-
NRF_I2S_PIN_NOT_CONNECTED, \
842-
NRF_I2S_PIN_NOT_CONNECTED, \
843-
NRF_I2S_PIN_NOT_CONNECTED, \
844-
NRF_I2S_PIN_NOT_CONNECTED), \
845-
.nrfx_def_cfg.skip_gpio_cfg = true, \
846-
.nrfx_def_cfg.skip_psel_cfg = true, \
847-
.pcfg = PINCTRL_DT_DEV_CONFIG_GET(I2S(idx)), \
848-
.clk_src = I2S_CLK_SRC(idx), \
849-
}; \
850-
static struct i2s_nrfx_drv_data i2s_nrfx_data##idx = { \
851-
.state = I2S_STATE_READY, \
852-
.p_i2s = &i2s_nrfx_cfg##idx.i2s \
853-
}; \
854-
static int i2s_nrfx_init##idx(const struct device *dev) \
855-
{ \
856-
IRQ_CONNECT(DT_IRQN(I2S(idx)), DT_IRQ(I2S(idx), priority), \
857-
nrfx_isr, nrfx_i2s_##idx##_irq_handler, 0); \
858-
const struct i2s_nrfx_drv_cfg *drv_cfg = dev->config; \
859-
int err = pinctrl_apply_state(drv_cfg->pcfg, \
860-
PINCTRL_STATE_DEFAULT); \
861-
if (err < 0) { \
862-
return err; \
863-
} \
864-
k_msgq_init(&i2s_nrfx_data##idx.tx_queue, \
865-
(char *)tx_msgs##idx, sizeof(struct i2s_buf), \
866-
ARRAY_SIZE(tx_msgs##idx)); \
867-
k_msgq_init(&i2s_nrfx_data##idx.rx_queue, \
868-
(char *)rx_msgs##idx, sizeof(struct i2s_buf), \
869-
ARRAY_SIZE(rx_msgs##idx)); \
870-
init_clock_manager(dev); \
871-
return 0; \
872-
} \
873-
BUILD_ASSERT(I2S_CLK_SRC(idx) != ACLK || \
874-
(NRF_I2S_HAS_CLKCONFIG && NRF_CLOCK_HAS_HFCLKAUDIO), \
875-
"Clock source ACLK is not available."); \
876-
BUILD_ASSERT(I2S_CLK_SRC(idx) != ACLK || \
877-
DT_NODE_HAS_PROP(DT_NODELABEL(clock), \
878-
hfclkaudio_frequency), \
879-
"Clock source ACLK requires the hfclkaudio-frequency " \
880-
"property to be defined in the nordic,nrf-clock node."); \
881-
DEVICE_DT_DEFINE(I2S(idx), i2s_nrfx_init##idx, NULL, \
882-
&i2s_nrfx_data##idx, &i2s_nrfx_cfg##idx, \
883-
POST_KERNEL, CONFIG_I2S_INIT_PRIORITY, \
826+
#define I2S_NRFX_DEVICE(idx) \
827+
static struct i2s_buf tx_msgs##idx[CONFIG_I2S_NRFX_TX_BLOCK_COUNT]; \
828+
static struct i2s_buf rx_msgs##idx[CONFIG_I2S_NRFX_RX_BLOCK_COUNT]; \
829+
static void data_handler##idx(nrfx_i2s_buffers_t const *p_released, uint32_t status) \
830+
{ \
831+
data_handler(DEVICE_DT_GET(I2S(idx)), p_released, status); \
832+
} \
833+
PINCTRL_DT_DEFINE(I2S(idx)); \
834+
static const struct i2s_nrfx_drv_cfg i2s_nrfx_cfg##idx = { \
835+
.data_handler = data_handler##idx, \
836+
.nrfx_def_cfg = NRFX_I2S_DEFAULT_CONFIG( \
837+
NRF_I2S_PIN_NOT_CONNECTED, NRF_I2S_PIN_NOT_CONNECTED, \
838+
NRF_I2S_PIN_NOT_CONNECTED, NRF_I2S_PIN_NOT_CONNECTED, \
839+
NRF_I2S_PIN_NOT_CONNECTED), \
840+
.nrfx_def_cfg.skip_gpio_cfg = true, \
841+
.nrfx_def_cfg.skip_psel_cfg = true, \
842+
.pcfg = PINCTRL_DT_DEV_CONFIG_GET(I2S(idx)), \
843+
.clk_src = I2S_CLK_SRC(idx), \
844+
}; \
845+
static struct i2s_nrfx_drv_data i2s_nrfx_data##idx = { \
846+
.state = I2S_STATE_READY, \
847+
.i2s = NRFX_I2S_INSTANCE(NRF_I2S##idx), \
848+
}; \
849+
NRFX_INSTANCE_IRQ_HANDLER_DEFINE(i2s, idx, &i2s_nrfx_data##idx.i2s); \
850+
static int i2s_nrfx_init##idx(const struct device *dev) \
851+
{ \
852+
IRQ_CONNECT(DT_IRQN(I2S(idx)), DT_IRQ(I2S(idx), priority), nrfx_isr, \
853+
nrfx_i2s_##idx##_irq_handler, 0); \
854+
const struct i2s_nrfx_drv_cfg *drv_cfg = dev->config; \
855+
int err = pinctrl_apply_state(drv_cfg->pcfg, PINCTRL_STATE_DEFAULT); \
856+
if (err < 0) { \
857+
return err; \
858+
} \
859+
k_msgq_init(&i2s_nrfx_data##idx.tx_queue, (char *)tx_msgs##idx, \
860+
sizeof(struct i2s_buf), ARRAY_SIZE(tx_msgs##idx)); \
861+
k_msgq_init(&i2s_nrfx_data##idx.rx_queue, (char *)rx_msgs##idx, \
862+
sizeof(struct i2s_buf), ARRAY_SIZE(rx_msgs##idx)); \
863+
init_clock_manager(dev); \
864+
return 0; \
865+
} \
866+
BUILD_ASSERT(I2S_CLK_SRC(idx) != ACLK || \
867+
(NRF_I2S_HAS_CLKCONFIG && NRF_CLOCK_HAS_HFCLKAUDIO), \
868+
"Clock source ACLK is not available."); \
869+
BUILD_ASSERT(I2S_CLK_SRC(idx) != ACLK || \
870+
DT_NODE_HAS_PROP(DT_NODELABEL(clock), hfclkaudio_frequency), \
871+
"Clock source ACLK requires the hfclkaudio-frequency " \
872+
"property to be defined in the nordic,nrf-clock node."); \
873+
DEVICE_DT_DEFINE(I2S(idx), i2s_nrfx_init##idx, NULL, &i2s_nrfx_data##idx, \
874+
&i2s_nrfx_cfg##idx, POST_KERNEL, CONFIG_I2S_INIT_PRIORITY, \
884875
&i2s_nrf_drv_api);
885876

886877
#ifdef CONFIG_HAS_HW_NRF_I2S0

0 commit comments

Comments
 (0)