drivers: spi: drop get_dev_data/get_dev_config usage

Replace all get_dev_data()/get_dev_config() accessor utilities with
dev->data and dev->config.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-01-19 16:25:52 +01:00 committed by Carles Cufí
commit 468de7eb29
4 changed files with 56 additions and 84 deletions

View file

@ -37,22 +37,12 @@ struct spi_cc13xx_cc26xx_data {
#define CPU_FREQ DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency) #define CPU_FREQ DT_PROP(DT_PATH(cpus, cpu_0), clock_frequency)
static inline struct spi_cc13xx_cc26xx_data *get_dev_data(const struct device *dev)
{
return dev->data;
}
static inline const struct spi_cc13xx_cc26xx_config *
get_dev_config(const struct device *dev)
{
return dev->config;
}
static int spi_cc13xx_cc26xx_configure(const struct device *dev, static int spi_cc13xx_cc26xx_configure(const struct device *dev,
const struct spi_config *config) const struct spi_config *config)
{ {
const struct spi_cc13xx_cc26xx_config *cfg = get_dev_config(dev); const struct spi_cc13xx_cc26xx_config *cfg = dev->config;
struct spi_context *ctx = &get_dev_data(dev)->ctx; struct spi_cc13xx_cc26xx_data *data = dev->data;
struct spi_context *ctx = &data->ctx;
uint32_t prot; uint32_t prot;
if (spi_context_configured(ctx, config)) { if (spi_context_configured(ctx, config)) {
@ -143,8 +133,9 @@ static int spi_cc13xx_cc26xx_transceive(const struct device *dev,
const struct spi_buf_set *tx_bufs, const struct spi_buf_set *tx_bufs,
const struct spi_buf_set *rx_bufs) const struct spi_buf_set *rx_bufs)
{ {
const struct spi_cc13xx_cc26xx_config *cfg = get_dev_config(dev); const struct spi_cc13xx_cc26xx_config *cfg = dev->config;
struct spi_context *ctx = &get_dev_data(dev)->ctx; struct spi_cc13xx_cc26xx_data *data = dev->data;
struct spi_context *ctx = &data->ctx;
uint32_t txd, rxd; uint32_t txd, rxd;
int err; int err;
@ -196,13 +187,15 @@ done:
static int spi_cc13xx_cc26xx_release(const struct device *dev, static int spi_cc13xx_cc26xx_release(const struct device *dev,
const struct spi_config *config) const struct spi_config *config)
{ {
struct spi_context *ctx = &get_dev_data(dev)->ctx; const struct spi_cc13xx_cc26xx_config *cfg = dev->config;
struct spi_cc13xx_cc26xx_data *data = dev->data;
struct spi_context *ctx = &data->ctx;
if (!spi_context_configured(ctx, config)) { if (!spi_context_configured(ctx, config)) {
return -EINVAL; return -EINVAL;
} }
if (SSIBusy(get_dev_config(dev)->base)) { if (SSIBusy(cfg->base)) {
return -EBUSY; return -EBUSY;
} }
@ -215,20 +208,22 @@ static int spi_cc13xx_cc26xx_release(const struct device *dev,
static int spi_cc13xx_cc26xx_pm_action(const struct device *dev, static int spi_cc13xx_cc26xx_pm_action(const struct device *dev,
enum pm_device_action action) enum pm_device_action action)
{ {
const struct spi_cc13xx_cc26xx_config *config = dev->config;
switch (action) { switch (action) {
case PM_DEVICE_ACTION_RESUME: case PM_DEVICE_ACTION_RESUME:
if (get_dev_config(dev)->base == DT_INST_REG_ADDR(0)) { if (config->base == DT_INST_REG_ADDR(0)) {
Power_setDependency(PowerCC26XX_PERIPH_SSI0); Power_setDependency(PowerCC26XX_PERIPH_SSI0);
} else { } else {
Power_setDependency(PowerCC26XX_PERIPH_SSI1); Power_setDependency(PowerCC26XX_PERIPH_SSI1);
} }
break; break;
case PM_DEVICE_ACTION_SUSPEND: case PM_DEVICE_ACTION_SUSPEND:
SSIDisable(get_dev_config(dev)->base); SSIDisable(config->base);
/* /*
* Release power dependency * Release power dependency
*/ */
if (get_dev_config(dev)->base == DT_INST_REG_ADDR(0)) { if (config->base == DT_INST_REG_ADDR(0)) {
Power_releaseDependency(PowerCC26XX_PERIPH_SSI0); Power_releaseDependency(PowerCC26XX_PERIPH_SSI0);
} else { } else {
Power_releaseDependency(PowerCC26XX_PERIPH_SSI1); Power_releaseDependency(PowerCC26XX_PERIPH_SSI1);
@ -306,15 +301,16 @@ static const struct spi_driver_api spi_cc13xx_cc26xx_driver_api = {
#define SPI_CC13XX_CC26XX_INIT_FUNC(n) \ #define SPI_CC13XX_CC26XX_INIT_FUNC(n) \
static int spi_cc13xx_cc26xx_init_##n(const struct device *dev) \ static int spi_cc13xx_cc26xx_init_##n(const struct device *dev) \
{ \ { \
struct spi_cc13xx_cc26xx_data *data = dev->data; \
int err; \ int err; \
SPI_CC13XX_CC26XX_POWER_SPI(n); \ SPI_CC13XX_CC26XX_POWER_SPI(n); \
\ \
err = spi_context_cs_configure_all(&get_dev_data(dev)->ctx); \ err = spi_context_cs_configure_all(&data->ctx); \
if (err < 0) { \ if (err < 0) { \
return err; \ return err; \
} \ } \
\ \
spi_context_unlock_unconditionally(&get_dev_data(dev)->ctx); \ spi_context_unlock_unconditionally(&data->ctx); \
\ \
return 0; \ return 0; \
} }

View file

@ -30,16 +30,6 @@ struct spi_nrfx_config {
static void event_handler(const nrfx_spi_evt_t *p_event, void *p_context); static void event_handler(const nrfx_spi_evt_t *p_event, void *p_context);
static inline struct spi_nrfx_data *get_dev_data(const struct device *dev)
{
return dev->data;
}
static inline const struct spi_nrfx_config *get_dev_config(const struct device *dev)
{
return dev->config;
}
static inline nrf_spi_frequency_t get_nrf_spi_frequency(uint32_t frequency) static inline nrf_spi_frequency_t get_nrf_spi_frequency(uint32_t frequency)
{ {
/* Get the highest supported frequency not exceeding the requested one. /* Get the highest supported frequency not exceeding the requested one.
@ -90,8 +80,8 @@ static inline nrf_spi_bit_order_t get_nrf_spi_bit_order(uint16_t operation)
static int configure(const struct device *dev, static int configure(const struct device *dev,
const struct spi_config *spi_cfg) const struct spi_config *spi_cfg)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = dev->data;
const struct spi_nrfx_config *dev_config = get_dev_config(dev); const struct spi_nrfx_config *dev_config = dev->config;
struct spi_context *ctx = &dev_data->ctx; struct spi_context *ctx = &dev_data->ctx;
nrfx_spi_config_t config; nrfx_spi_config_t config;
nrfx_err_t result; nrfx_err_t result;
@ -159,7 +149,8 @@ static int configure(const struct device *dev,
static void transfer_next_chunk(const struct device *dev) static void transfer_next_chunk(const struct device *dev)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); const struct spi_nrfx_config *config = dev->config;
struct spi_nrfx_data *dev_data = dev->data;
struct spi_context *ctx = &dev_data->ctx; struct spi_context *ctx = &dev_data->ctx;
int error = 0; int error = 0;
@ -175,7 +166,7 @@ static void transfer_next_chunk(const struct device *dev)
xfer.tx_length = spi_context_tx_buf_on(ctx) ? chunk_len : 0; xfer.tx_length = spi_context_tx_buf_on(ctx) ? chunk_len : 0;
xfer.p_rx_buffer = ctx->rx_buf; xfer.p_rx_buffer = ctx->rx_buf;
xfer.rx_length = spi_context_rx_buf_on(ctx) ? chunk_len : 0; xfer.rx_length = spi_context_rx_buf_on(ctx) ? chunk_len : 0;
result = nrfx_spi_xfer(&get_dev_config(dev)->spi, &xfer, 0); result = nrfx_spi_xfer(&config->spi, &xfer, 0);
if (result == NRFX_SUCCESS) { if (result == NRFX_SUCCESS) {
return; return;
} }
@ -210,7 +201,7 @@ static int transceive(const struct device *dev,
bool asynchronous, bool asynchronous,
struct k_poll_signal *signal) struct k_poll_signal *signal)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = dev->data;
int error; int error;
spi_context_lock(&dev_data->ctx, asynchronous, signal, spi_cfg); spi_context_lock(&dev_data->ctx, asynchronous, signal, spi_cfg);
@ -254,7 +245,7 @@ static int spi_nrfx_transceive_async(const struct device *dev,
static int spi_nrfx_release(const struct device *dev, static int spi_nrfx_release(const struct device *dev,
const struct spi_config *spi_cfg) const struct spi_config *spi_cfg)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = dev->data;
if (!spi_context_configured(&dev_data->ctx, spi_cfg)) { if (!spi_context_configured(&dev_data->ctx, spi_cfg)) {
return -EINVAL; return -EINVAL;
@ -283,8 +274,8 @@ static int spi_nrfx_pm_action(const struct device *dev,
enum pm_device_action action) enum pm_device_action action)
{ {
int ret = 0; int ret = 0;
struct spi_nrfx_data *data = get_dev_data(dev); struct spi_nrfx_data *data = dev->data;
const struct spi_nrfx_config *config = get_dev_config(dev); const struct spi_nrfx_config *config = dev->config;
switch (action) { switch (action) {
case PM_DEVICE_ACTION_RESUME: case PM_DEVICE_ACTION_RESUME:
@ -333,14 +324,15 @@ static int spi_nrfx_pm_action(const struct device *dev,
": cannot enable both pull-up and pull-down on MISO line"); \ ": cannot enable both pull-up and pull-down on MISO line"); \
static int spi_##idx##_init(const struct device *dev) \ static int spi_##idx##_init(const struct device *dev) \
{ \ { \
struct spi_nrfx_data *data = dev->data; \
int err; \ int err; \
IRQ_CONNECT(DT_IRQN(SPI(idx)), DT_IRQ(SPI(idx), priority), \ IRQ_CONNECT(DT_IRQN(SPI(idx)), DT_IRQ(SPI(idx), priority), \
nrfx_isr, nrfx_spi_##idx##_irq_handler, 0); \ nrfx_isr, nrfx_spi_##idx##_irq_handler, 0); \
err = spi_context_cs_configure_all(&get_dev_data(dev)->ctx); \ err = spi_context_cs_configure_all(&data->ctx); \
if (err < 0) { \ if (err < 0) { \
return err; \ return err; \
} \ } \
spi_context_unlock_unconditionally(&get_dev_data(dev)->ctx); \ spi_context_unlock_unconditionally(&data->ctx); \
return 0; \ return 0; \
} \ } \
static struct spi_nrfx_data spi_##idx##_data = { \ static struct spi_nrfx_data spi_##idx##_data = { \

View file

@ -49,16 +49,6 @@ struct spi_nrfx_config {
static void event_handler(const nrfx_spim_evt_t *p_event, void *p_context); static void event_handler(const nrfx_spim_evt_t *p_event, void *p_context);
static inline struct spi_nrfx_data *get_dev_data(const struct device *dev)
{
return dev->data;
}
static inline const struct spi_nrfx_config *get_dev_config(const struct device *dev)
{
return dev->config;
}
static inline nrf_spim_frequency_t get_nrf_spim_frequency(uint32_t frequency) static inline nrf_spim_frequency_t get_nrf_spim_frequency(uint32_t frequency)
{ {
/* Get the highest supported frequency not exceeding the requested one. /* Get the highest supported frequency not exceeding the requested one.
@ -121,8 +111,8 @@ static inline nrf_spim_bit_order_t get_nrf_spim_bit_order(uint16_t operation)
static int configure(const struct device *dev, static int configure(const struct device *dev,
const struct spi_config *spi_cfg) const struct spi_config *spi_cfg)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = dev->data;
const struct spi_nrfx_config *dev_config = get_dev_config(dev); const struct spi_nrfx_config *dev_config = dev->config;
struct spi_context *ctx = &dev_data->ctx; struct spi_context *ctx = &dev_data->ctx;
uint32_t max_freq = dev_config->max_freq; uint32_t max_freq = dev_config->max_freq;
nrfx_spim_config_t config; nrfx_spim_config_t config;
@ -217,8 +207,8 @@ static int configure(const struct device *dev,
*/ */
static void anomaly_58_workaround_setup(const struct device *dev) static void anomaly_58_workaround_setup(const struct device *dev)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = dev->data;
const struct spi_nrfx_config *dev_config = get_dev_config(dev); const struct spi_nrfx_config *dev_config = dev->config;
NRF_SPIM_Type *spim = dev_config->spim.p_reg; NRF_SPIM_Type *spim = dev_config->spim.p_reg;
uint32_t ppi_ch = dev_data->ppi_ch; uint32_t ppi_ch = dev_data->ppi_ch;
uint32_t gpiote_ch = dev_data->gpiote_ch; uint32_t gpiote_ch = dev_data->gpiote_ch;
@ -257,8 +247,8 @@ static void anomaly_58_workaround_clear(struct spi_nrfx_data *dev_data)
static int anomaly_58_workaround_init(const struct device *dev) static int anomaly_58_workaround_init(const struct device *dev)
{ {
struct spi_nrfx_data *data = get_dev_data(dev); struct spi_nrfx_data *data = dev->data;
const struct spi_nrfx_config *config = get_dev_config(dev); const struct spi_nrfx_config *config = dev->config;
nrfx_err_t err_code; nrfx_err_t err_code;
data->anomaly_58_workaround_active = false; data->anomaly_58_workaround_active = false;
@ -285,8 +275,8 @@ static int anomaly_58_workaround_init(const struct device *dev)
static void transfer_next_chunk(const struct device *dev) static void transfer_next_chunk(const struct device *dev)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = dev->data;
const struct spi_nrfx_config *dev_config = get_dev_config(dev); const struct spi_nrfx_config *dev_config = dev->config;
struct spi_context *ctx = &dev_data->ctx; struct spi_context *ctx = &dev_data->ctx;
int error = 0; int error = 0;
@ -370,7 +360,7 @@ static int transceive(const struct device *dev,
bool asynchronous, bool asynchronous,
struct k_poll_signal *signal) struct k_poll_signal *signal)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = dev->data;
int error; int error;
spi_context_lock(&dev_data->ctx, asynchronous, signal, spi_cfg); spi_context_lock(&dev_data->ctx, asynchronous, signal, spi_cfg);
@ -414,7 +404,7 @@ static int spi_nrfx_transceive_async(const struct device *dev,
static int spi_nrfx_release(const struct device *dev, static int spi_nrfx_release(const struct device *dev,
const struct spi_config *spi_cfg) const struct spi_config *spi_cfg)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = dev->data;
if (!spi_context_configured(&dev_data->ctx, spi_cfg)) { if (!spi_context_configured(&dev_data->ctx, spi_cfg)) {
return -EINVAL; return -EINVAL;
@ -442,8 +432,8 @@ static int spim_nrfx_pm_action(const struct device *dev,
enum pm_device_action action) enum pm_device_action action)
{ {
int ret = 0; int ret = 0;
struct spi_nrfx_data *data = get_dev_data(dev); struct spi_nrfx_data *data = dev->data;
const struct spi_nrfx_config *config = get_dev_config(dev); const struct spi_nrfx_config *config = dev->config;
switch (action) { switch (action) {
case PM_DEVICE_ACTION_RESUME: case PM_DEVICE_ACTION_RESUME:
@ -500,15 +490,16 @@ static int spim_nrfx_pm_action(const struct device *dev,
": cannot enable both pull-up and pull-down on MISO line"); \ ": cannot enable both pull-up and pull-down on MISO line"); \
static int spi_##idx##_init(const struct device *dev) \ static int spi_##idx##_init(const struct device *dev) \
{ \ { \
struct spi_nrfx_data *data = dev->data; \
int err; \ int err; \
IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_SPIM##idx), \ IRQ_CONNECT(NRFX_IRQ_NUMBER_GET(NRF_SPIM##idx), \
DT_IRQ(SPIM(idx), priority), \ DT_IRQ(SPIM(idx), priority), \
nrfx_isr, nrfx_spim_##idx##_irq_handler, 0); \ nrfx_isr, nrfx_spim_##idx##_irq_handler, 0); \
err = spi_context_cs_configure_all(&get_dev_data(dev)->ctx); \ err = spi_context_cs_configure_all(&data->ctx); \
if (err < 0) { \ if (err < 0) { \
return err; \ return err; \
} \ } \
spi_context_unlock_unconditionally(&get_dev_data(dev)->ctx); \ spi_context_unlock_unconditionally(&data->ctx); \
COND_CODE_1(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58, \ COND_CODE_1(CONFIG_SOC_NRF52832_ALLOW_SPIM_DESPITE_PAN_58, \
(return anomaly_58_workaround_init(dev);), \ (return anomaly_58_workaround_init(dev);), \
(return 0;)) \ (return 0;)) \

View file

@ -23,16 +23,6 @@ struct spi_nrfx_config {
size_t max_buf_len; size_t max_buf_len;
}; };
static inline struct spi_nrfx_data *get_dev_data(const struct device *dev)
{
return dev->data;
}
static inline const struct spi_nrfx_config *get_dev_config(const struct device *dev)
{
return dev->config;
}
static inline nrf_spis_mode_t get_nrf_spis_mode(uint16_t operation) static inline nrf_spis_mode_t get_nrf_spis_mode(uint16_t operation)
{ {
if (SPI_MODE_GET(operation) & SPI_MODE_CPOL) { if (SPI_MODE_GET(operation) & SPI_MODE_CPOL) {
@ -62,7 +52,9 @@ static inline nrf_spis_bit_order_t get_nrf_spis_bit_order(uint16_t operation)
static int configure(const struct device *dev, static int configure(const struct device *dev,
const struct spi_config *spi_cfg) const struct spi_config *spi_cfg)
{ {
struct spi_context *ctx = &get_dev_data(dev)->ctx; const struct spi_nrfx_config *config = dev->config;
struct spi_nrfx_data *data = dev->data;
struct spi_context *ctx = &data->ctx;
if (spi_context_configured(ctx, spi_cfg)) { if (spi_context_configured(ctx, spi_cfg)) {
/* Already configured. No need to do it again. */ /* Already configured. No need to do it again. */
@ -102,7 +94,7 @@ static int configure(const struct device *dev,
ctx->config = spi_cfg; ctx->config = spi_cfg;
nrf_spis_configure(get_dev_config(dev)->spis.p_reg, nrf_spis_configure(config->spis.p_reg,
get_nrf_spis_mode(spi_cfg->operation), get_nrf_spis_mode(spi_cfg->operation),
get_nrf_spis_bit_order(spi_cfg->operation)); get_nrf_spis_bit_order(spi_cfg->operation));
@ -113,8 +105,8 @@ static void prepare_for_transfer(const struct device *dev,
const uint8_t *tx_buf, size_t tx_buf_len, const uint8_t *tx_buf, size_t tx_buf_len,
uint8_t *rx_buf, size_t rx_buf_len) uint8_t *rx_buf, size_t rx_buf_len)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = dev->data;
const struct spi_nrfx_config *dev_config = get_dev_config(dev); const struct spi_nrfx_config *dev_config = dev->config;
int status; int status;
if (tx_buf_len > dev_config->max_buf_len || if (tx_buf_len > dev_config->max_buf_len ||
@ -146,7 +138,7 @@ static int transceive(const struct device *dev,
bool asynchronous, bool asynchronous,
struct k_poll_signal *signal) struct k_poll_signal *signal)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = dev->data;
int error; int error;
spi_context_lock(&dev_data->ctx, asynchronous, signal, spi_cfg); spi_context_lock(&dev_data->ctx, asynchronous, signal, spi_cfg);
@ -199,7 +191,7 @@ static int spi_nrfx_transceive_async(const struct device *dev,
static int spi_nrfx_release(const struct device *dev, static int spi_nrfx_release(const struct device *dev,
const struct spi_config *spi_cfg) const struct spi_config *spi_cfg)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); struct spi_nrfx_data *dev_data = dev->data;
if (!spi_context_configured(&dev_data->ctx, spi_cfg)) { if (!spi_context_configured(&dev_data->ctx, spi_cfg)) {
return -EINVAL; return -EINVAL;
@ -231,11 +223,12 @@ static void event_handler(const nrfx_spis_evt_t *p_event, void *p_context)
static int init_spis(const struct device *dev, static int init_spis(const struct device *dev,
const nrfx_spis_config_t *config) const nrfx_spis_config_t *config)
{ {
struct spi_nrfx_data *dev_data = get_dev_data(dev); const struct spi_nrfx_config *dev_config = dev->config;
struct spi_nrfx_data *dev_data = dev->data;
/* This sets only default values of mode and bit order. The ones to be /* This sets only default values of mode and bit order. The ones to be
* actually used are set in configure() when a transfer is prepared. * actually used are set in configure() when a transfer is prepared.
*/ */
nrfx_err_t result = nrfx_spis_init(&get_dev_config(dev)->spis, nrfx_err_t result = nrfx_spis_init(&dev_config->spis,
config, config,
event_handler, event_handler,
dev_data); dev_data);