Skip to content

Commit 2a87e04

Browse files
ananglcarlescufi
authored andcommitted
drivers: spi: nrfx: Clean up code
- clean up registration of the drivers with the logging subsystem - use consistent naming of local variables accessing configuration and runtime data of driver instances, for easier code maintenance Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent fa22634 commit 2a87e04

File tree

3 files changed

+40
-46
lines changed

3 files changed

+40
-46
lines changed

drivers/spi/spi_nrfx_spi.c

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
#include <pm/device.h>
99
#include <nrfx_spi.h>
1010

11-
#define LOG_DOMAIN "spi_nrfx_spi"
12-
#define LOG_LEVEL CONFIG_SPI_LOG_LEVEL
1311
#include <logging/log.h>
14-
LOG_MODULE_REGISTER(spi_nrfx_spi);
12+
LOG_MODULE_REGISTER(spi_nrfx_spi, CONFIG_SPI_LOG_LEVEL);
1513

1614
#include "spi_context.h"
1715

@@ -149,7 +147,7 @@ static int configure(const struct device *dev,
149147

150148
static void transfer_next_chunk(const struct device *dev)
151149
{
152-
const struct spi_nrfx_config *config = dev->config;
150+
const struct spi_nrfx_config *dev_config = dev->config;
153151
struct spi_nrfx_data *dev_data = dev->data;
154152
struct spi_context *ctx = &dev_data->ctx;
155153
int error = 0;
@@ -166,7 +164,7 @@ static void transfer_next_chunk(const struct device *dev)
166164
xfer.tx_length = spi_context_tx_buf_on(ctx) ? chunk_len : 0;
167165
xfer.p_rx_buffer = ctx->rx_buf;
168166
xfer.rx_length = spi_context_rx_buf_on(ctx) ? chunk_len : 0;
169-
result = nrfx_spi_xfer(&config->spi, &xfer, 0);
167+
result = nrfx_spi_xfer(&dev_config->spi, &xfer, 0);
170168
if (result == NRFX_SUCCESS) {
171169
return;
172170
}
@@ -274,8 +272,8 @@ static int spi_nrfx_pm_action(const struct device *dev,
274272
enum pm_device_action action)
275273
{
276274
int ret = 0;
277-
struct spi_nrfx_data *data = dev->data;
278-
const struct spi_nrfx_config *config = dev->config;
275+
struct spi_nrfx_data *dev_data = dev->data;
276+
const struct spi_nrfx_config *dev_config = dev->config;
279277

280278
switch (action) {
281279
case PM_DEVICE_ACTION_RESUME:
@@ -285,9 +283,9 @@ static int spi_nrfx_pm_action(const struct device *dev,
285283
break;
286284

287285
case PM_DEVICE_ACTION_SUSPEND:
288-
if (data->initialized) {
289-
nrfx_spi_uninit(&config->spi);
290-
data->initialized = false;
286+
if (dev_data->initialized) {
287+
nrfx_spi_uninit(&dev_config->spi);
288+
dev_data->initialized = false;
291289
}
292290
break;
293291

@@ -326,15 +324,15 @@ static int spi_nrfx_pm_action(const struct device *dev,
326324
": cannot enable both pull-up and pull-down on MISO line"); \
327325
static int spi_##idx##_init(const struct device *dev) \
328326
{ \
329-
struct spi_nrfx_data *data = dev->data; \
330-
int err; \
327+
struct spi_nrfx_data *dev_data = dev->data; \
328+
int err; \
331329
IRQ_CONNECT(DT_IRQN(SPI(idx)), DT_IRQ(SPI(idx), priority), \
332330
nrfx_isr, nrfx_spi_##idx##_irq_handler, 0); \
333-
err = spi_context_cs_configure_all(&data->ctx); \
334-
if (err < 0) { \
335-
return err; \
336-
} \
337-
spi_context_unlock_unconditionally(&data->ctx); \
331+
err = spi_context_cs_configure_all(&dev_data->ctx); \
332+
if (err < 0) { \
333+
return err; \
334+
} \
335+
spi_context_unlock_unconditionally(&dev_data->ctx); \
338336
return 0; \
339337
} \
340338
static struct spi_nrfx_data spi_##idx##_data = { \

drivers/spi/spi_nrfx_spim.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
#include <hal/nrf_clock.h>
1515
#include <string.h>
1616

17-
#define LOG_DOMAIN "spi_nrfx_spim"
18-
#define LOG_LEVEL CONFIG_SPI_LOG_LEVEL
1917
#include <logging/log.h>
20-
LOG_MODULE_REGISTER(spi_nrfx_spim);
18+
LOG_MODULE_REGISTER(spi_nrfx_spim, CONFIG_SPI_LOG_LEVEL);
2119

2220
#include "spi_context.h"
2321

@@ -247,26 +245,26 @@ static void anomaly_58_workaround_clear(struct spi_nrfx_data *dev_data)
247245

248246
static int anomaly_58_workaround_init(const struct device *dev)
249247
{
250-
struct spi_nrfx_data *data = dev->data;
251-
const struct spi_nrfx_config *config = dev->config;
248+
struct spi_nrfx_data *dev_data = dev->data;
249+
const struct spi_nrfx_config *dev_config = dev->config;
252250
nrfx_err_t err_code;
253251

254-
data->anomaly_58_workaround_active = false;
252+
dev_data->anomaly_58_workaround_active = false;
255253

256-
if (config->anomaly_58_workaround) {
257-
err_code = nrfx_ppi_channel_alloc(&data->ppi_ch);
254+
if (dev_config->anomaly_58_workaround) {
255+
err_code = nrfx_ppi_channel_alloc(&dev_data->ppi_ch);
258256
if (err_code != NRFX_SUCCESS) {
259257
LOG_ERR("Failed to allocate PPI channel");
260258
return -ENODEV;
261259
}
262260

263-
err_code = nrfx_gpiote_channel_alloc(&data->gpiote_ch);
261+
err_code = nrfx_gpiote_channel_alloc(&dev_data->gpiote_ch);
264262
if (err_code != NRFX_SUCCESS) {
265263
LOG_ERR("Failed to allocate GPIOTE channel");
266264
return -ENODEV;
267265
}
268266
LOG_DBG("PAN 58 workaround enabled for %s: ppi %u, gpiote %u",
269-
dev->name, data->ppi_ch, data->gpiote_ch);
267+
dev->name, dev_data->ppi_ch, dev_data->gpiote_ch);
270268
}
271269

272270
return 0;
@@ -432,8 +430,8 @@ static int spim_nrfx_pm_action(const struct device *dev,
432430
enum pm_device_action action)
433431
{
434432
int ret = 0;
435-
struct spi_nrfx_data *data = dev->data;
436-
const struct spi_nrfx_config *config = dev->config;
433+
struct spi_nrfx_data *dev_data = dev->data;
434+
const struct spi_nrfx_config *dev_config = dev->config;
437435

438436
switch (action) {
439437
case PM_DEVICE_ACTION_RESUME:
@@ -443,9 +441,9 @@ static int spim_nrfx_pm_action(const struct device *dev,
443441
break;
444442

445443
case PM_DEVICE_ACTION_SUSPEND:
446-
if (data->initialized) {
447-
nrfx_spim_uninit(&config->spim);
448-
data->initialized = false;
444+
if (dev_data->initialized) {
445+
nrfx_spim_uninit(&dev_config->spim);
446+
dev_data->initialized = false;
449447
}
450448
break;
451449

@@ -492,16 +490,16 @@ static int spim_nrfx_pm_action(const struct device *dev,
492490
": cannot enable both pull-up and pull-down on MISO line"); \
493491
static int spi_##idx##_init(const struct device *dev) \
494492
{ \
495-
struct spi_nrfx_data *data = dev->data; \
496-
int err; \
493+
struct spi_nrfx_data *dev_data = dev->data; \
494+
int err; \
497495
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_SPIM##idx), \
498496
DT_IRQ(SPIM(idx), priority), \
499497
nrfx_isr, nrfx_spim_##idx##_irq_handler, 0); \
500-
err = spi_context_cs_configure_all(&data->ctx); \
501-
if (err < 0) { \
502-
return err; \
503-
} \
504-
spi_context_unlock_unconditionally(&data->ctx); \
498+
err = spi_context_cs_configure_all(&dev_data->ctx); \
499+
if (err < 0) { \
500+
return err; \
501+
} \
502+
spi_context_unlock_unconditionally(&dev_data->ctx); \
505503
COND_CODE_1(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58, \
506504
(return anomaly_58_workaround_init(dev);), \
507505
(return 0;)) \

drivers/spi/spi_nrfx_spis.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
#include <drivers/spi.h>
88
#include <nrfx_spis.h>
99

10-
#define LOG_DOMAIN "spi_nrfx_spis"
11-
#define LOG_LEVEL CONFIG_SPI_LOG_LEVEL
1210
#include <logging/log.h>
13-
LOG_MODULE_REGISTER(spi_nrfx_spis);
11+
LOG_MODULE_REGISTER(spi_nrfx_spis, CONFIG_SPI_LOG_LEVEL);
1412

1513
#include "spi_context.h"
1614

@@ -52,9 +50,9 @@ static inline nrf_spis_bit_order_t get_nrf_spis_bit_order(uint16_t operation)
5250
static int configure(const struct device *dev,
5351
const struct spi_config *spi_cfg)
5452
{
55-
const struct spi_nrfx_config *config = dev->config;
56-
struct spi_nrfx_data *data = dev->data;
57-
struct spi_context *ctx = &data->ctx;
53+
const struct spi_nrfx_config *dev_config = dev->config;
54+
struct spi_nrfx_data *dev_data = dev->data;
55+
struct spi_context *ctx = &dev_data->ctx;
5856

5957
if (spi_context_configured(ctx, spi_cfg)) {
6058
/* Already configured. No need to do it again. */
@@ -94,7 +92,7 @@ static int configure(const struct device *dev,
9492

9593
ctx->config = spi_cfg;
9694

97-
nrf_spis_configure(config->spis.p_reg,
95+
nrf_spis_configure(dev_config->spis.p_reg,
9896
get_nrf_spis_mode(spi_cfg->operation),
9997
get_nrf_spis_bit_order(spi_cfg->operation));
10098

0 commit comments

Comments
 (0)