drivers: i2s: drop DEV_DATA/DEV_CFG usage

Stop using redundant DEV_DATA/DEV_CFG macros and use dev->data and
dev->config instead.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-01-18 16:08:54 +01:00 committed by Carles Cufí
parent be32e33774
commit 72a0d68284
5 changed files with 63 additions and 76 deletions

View file

@ -86,10 +86,6 @@ struct i2s_cavs_dev_data {
};
#define DEV_NAME(dev) ((dev)->name)
#define DEV_CFG(dev) \
((const struct i2s_cavs_config *const)(dev)->config)
#define DEV_DATA(dev) \
((struct i2s_cavs_dev_data *const)(dev)->data)
static void i2s_dma_tx_callback(const struct device *, void *, uint32_t, int);
static void i2s_tx_stream_disable(struct i2s_cavs_dev_data *,
@ -115,8 +111,8 @@ static void i2s_dma_tx_callback(const struct device *dma_dev, void *arg,
uint32_t channel, int status)
{
const struct device *dev = (const struct device *)arg;
const struct i2s_cavs_config *const dev_cfg = DEV_CFG(dev);
struct i2s_cavs_dev_data *const dev_data = DEV_DATA(dev);
const struct i2s_cavs_config *const dev_cfg = dev->config;
struct i2s_cavs_dev_data *const dev_data = dev->data;
volatile struct i2s_cavs_ssp *const ssp = dev_cfg->regs;
struct stream *strm = &dev_data->tx;
@ -171,8 +167,8 @@ static void i2s_dma_rx_callback(const struct device *dma_dev, void *arg,
uint32_t channel, int status)
{
const struct device *dev = (const struct device *)arg;
const struct i2s_cavs_config *const dev_cfg = DEV_CFG(dev);
struct i2s_cavs_dev_data *const dev_data = DEV_DATA(dev);
const struct i2s_cavs_config *const dev_cfg = dev->config;
struct i2s_cavs_dev_data *const dev_data = dev->data;
volatile struct i2s_cavs_ssp *const ssp = dev_cfg->regs;
struct stream *strm = &dev_data->rx;
void *buffer;
@ -229,8 +225,8 @@ static void i2s_dma_rx_callback(const struct device *dma_dev, void *arg,
static int i2s_cavs_configure(const struct device *dev, enum i2s_dir dir,
const struct i2s_config *i2s_cfg)
{
const struct i2s_cavs_config *const dev_cfg = DEV_CFG(dev);
struct i2s_cavs_dev_data *const dev_data = DEV_DATA(dev);
const struct i2s_cavs_config *const dev_cfg = dev->config;
struct i2s_cavs_dev_data *const dev_data = dev->data;
volatile struct i2s_cavs_ssp *const ssp = dev_cfg->regs;
volatile struct i2s_cavs_mn_div *const mn_div = dev_cfg->mn_regs;
struct dma_block_config *dma_block;
@ -635,8 +631,8 @@ static void i2s_rx_stream_disable(struct i2s_cavs_dev_data *dev_data,
static int i2s_cavs_trigger(const struct device *dev, enum i2s_dir dir,
enum i2s_trigger_cmd cmd)
{
const struct i2s_cavs_config *const dev_cfg = DEV_CFG(dev);
struct i2s_cavs_dev_data *const dev_data = DEV_DATA(dev);
const struct i2s_cavs_config *const dev_cfg = dev->config;
struct i2s_cavs_dev_data *const dev_data = dev->data;
volatile struct i2s_cavs_ssp *const ssp = dev_cfg->regs;
struct stream *strm;
unsigned int key;
@ -699,7 +695,7 @@ static int i2s_cavs_trigger(const struct device *dev, enum i2s_dir dir,
static int i2s_cavs_read(const struct device *dev, void **mem_block,
size_t *size)
{
struct i2s_cavs_dev_data *const dev_data = DEV_DATA(dev);
struct i2s_cavs_dev_data *const dev_data = dev->data;
struct stream *strm = &dev_data->rx;
void *buffer;
int ret = 0;
@ -723,7 +719,7 @@ static int i2s_cavs_read(const struct device *dev, void **mem_block,
static int i2s_cavs_write(const struct device *dev, void *mem_block,
size_t size)
{
struct i2s_cavs_dev_data *const dev_data = DEV_DATA(dev);
struct i2s_cavs_dev_data *const dev_data = dev->data;
struct stream *strm = &dev_data->tx;
int ret;
@ -748,9 +744,9 @@ static int i2s_cavs_write(const struct device *dev, void *mem_block,
/* clear IRQ sources atm */
static void i2s_cavs_isr(const struct device *dev)
{
const struct i2s_cavs_config *const dev_cfg = DEV_CFG(dev);
const struct i2s_cavs_config *const dev_cfg = dev->config;
volatile struct i2s_cavs_ssp *const ssp = dev_cfg->regs;
struct i2s_cavs_dev_data *const dev_data = DEV_DATA(dev);
struct i2s_cavs_dev_data *const dev_data = dev->data;
uint32_t status;
/* clear interrupts */
@ -771,8 +767,8 @@ static void i2s_cavs_isr(const struct device *dev)
static int i2s_cavs_initialize(const struct device *dev)
{
const struct i2s_cavs_config *const dev_cfg = DEV_CFG(dev);
struct i2s_cavs_dev_data *const dev_data = DEV_DATA(dev);
const struct i2s_cavs_config *const dev_cfg = dev->config;
struct i2s_cavs_dev_data *const dev_data = dev->data;
if (!device_is_ready(dev_cfg->dev_dma)) {
LOG_ERR("%s device not ready", dev_cfg->dev_dma->name);

View file

@ -14,8 +14,6 @@
#include <logging/log.h>
LOG_MODULE_REGISTER(i2s_litex);
#define DEV_CFG(dev) ((struct i2s_litex_cfg *const)(dev)->config)
#define DEV_DATA(dev) ((struct i2s_litex_data *const)(dev)->data)
#define MODULO_INC(val, max) \
{ \
@ -308,8 +306,8 @@ static int queue_put(struct ring_buf *rb, void *mem_block, size_t size)
static int i2s_litex_initialize(const struct device *dev)
{
struct i2s_litex_cfg *cfg = DEV_CFG(dev);
struct i2s_litex_data *const dev_data = DEV_DATA(dev);
struct i2s_litex_cfg *cfg = dev->config;
struct i2s_litex_data *const dev_data = dev->data;
k_sem_init(&dev_data->rx.sem, 0, CONFIG_I2S_LITEX_RX_BLOCK_COUNT);
k_sem_init(&dev_data->tx.sem, CONFIG_I2S_LITEX_TX_BLOCK_COUNT - 1,
@ -322,8 +320,8 @@ static int i2s_litex_initialize(const struct device *dev)
static int i2s_litex_configure(const struct device *dev, enum i2s_dir dir,
const struct i2s_config *i2s_cfg)
{
struct i2s_litex_data *const dev_data = DEV_DATA(dev);
const struct i2s_litex_cfg *const cfg = DEV_CFG(dev);
struct i2s_litex_data *const dev_data = dev->data;
const struct i2s_litex_cfg *const cfg = dev->config;
struct stream *stream;
int channels_concatenated;
int dev_audio_freq = i2s_get_audio_freq(cfg->base);
@ -431,7 +429,7 @@ static int i2s_litex_configure(const struct device *dev, enum i2s_dir dir,
static int i2s_litex_read(const struct device *dev, void **mem_block,
size_t *size)
{
struct i2s_litex_data *const dev_data = DEV_DATA(dev);
struct i2s_litex_data *const dev_data = dev->data;
int ret;
if (dev_data->rx.state == I2S_STATE_NOT_READY) {
@ -451,8 +449,8 @@ static int i2s_litex_read(const struct device *dev, void **mem_block,
static int i2s_litex_write(const struct device *dev, void *mem_block,
size_t size)
{
struct i2s_litex_data *const dev_data = DEV_DATA(dev);
const struct i2s_litex_cfg *cfg = DEV_CFG(dev);
struct i2s_litex_data *const dev_data = dev->data;
const struct i2s_litex_cfg *cfg = dev->config;
int ret;
if (dev_data->tx.state != I2S_STATE_RUNNING &&
@ -482,8 +480,8 @@ static int i2s_litex_write(const struct device *dev, void *mem_block,
static int i2s_litex_trigger(const struct device *dev, enum i2s_dir dir,
enum i2s_trigger_cmd cmd)
{
struct i2s_litex_data *const dev_data = DEV_DATA(dev);
const struct i2s_litex_cfg *const cfg = DEV_CFG(dev);
struct i2s_litex_data *const dev_data = dev->data;
const struct i2s_litex_cfg *const cfg = dev->config;
struct stream *stream;
if (dir == I2S_DIR_RX) {
@ -540,8 +538,9 @@ static inline void clear_rx_fifo(const struct i2s_litex_cfg *cfg)
static void i2s_litex_isr_rx(void *arg)
{
const struct device *dev = (const struct device *)arg;
const struct i2s_litex_cfg *cfg = DEV_CFG(dev);
struct stream *stream = &DEV_DATA(dev)->rx;
const struct i2s_litex_cfg *cfg = dev->config;
struct i2s_litex_data *data = dev->data;
struct stream *stream = &data->rx;
int ret;
/* Prepare to receive the next data block */
@ -571,9 +570,10 @@ static void i2s_litex_isr_rx(void *arg)
static void i2s_litex_isr_tx(void *arg)
{
const struct device *dev = (const struct device *)arg;
const struct i2s_litex_cfg *cfg = DEV_CFG(dev);
const struct i2s_litex_cfg *cfg = dev->config;
struct i2s_litex_data *data = dev->data;
size_t mem_block_size;
struct stream *stream = &DEV_DATA(dev)->tx;
struct stream *stream = &data->tx;
int ret;
ret = queue_get(&stream->mem_block_queue, &stream->mem_block,

View file

@ -96,7 +96,7 @@ static int queue_put(struct ring_buf *rb, void *mem_block, size_t size)
static int i2s_stm32_enable_clock(const struct device *dev)
{
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
const struct i2s_stm32_cfg *cfg = dev->config;
const struct device *clk;
int ret;
@ -122,7 +122,7 @@ static uint16_t plli2s_ms_count;
static int i2s_stm32_set_clock(const struct device *dev,
uint32_t bit_clk_freq)
{
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
const struct i2s_stm32_cfg *cfg = dev->config;
uint32_t pll_src = LL_RCC_PLL_GetMainSource();
int freq_in;
uint8_t i2s_div, i2s_odd;
@ -183,8 +183,8 @@ static int i2s_stm32_set_clock(const struct device *dev,
static int i2s_stm32_configure(const struct device *dev, enum i2s_dir dir,
const struct i2s_config *i2s_cfg)
{
const struct i2s_stm32_cfg *const cfg = DEV_CFG(dev);
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
const struct i2s_stm32_cfg *const cfg = dev->config;
struct i2s_stm32_data *const dev_data = dev->data;
struct stream *stream;
uint32_t bit_clk_freq;
int ret;
@ -289,7 +289,7 @@ static int i2s_stm32_configure(const struct device *dev, enum i2s_dir dir,
static int i2s_stm32_trigger(const struct device *dev, enum i2s_dir dir,
enum i2s_trigger_cmd cmd)
{
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
struct i2s_stm32_data *const dev_data = dev->data;
struct stream *stream;
unsigned int key;
int ret;
@ -382,7 +382,7 @@ static int i2s_stm32_trigger(const struct device *dev, enum i2s_dir dir,
static int i2s_stm32_read(const struct device *dev, void **mem_block,
size_t *size)
{
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
struct i2s_stm32_data *const dev_data = dev->data;
int ret;
if (dev_data->rx.state == I2S_STATE_NOT_READY) {
@ -410,7 +410,7 @@ static int i2s_stm32_read(const struct device *dev, void **mem_block,
static int i2s_stm32_write(const struct device *dev, void *mem_block,
size_t size)
{
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
struct i2s_stm32_data *const dev_data = dev->data;
int ret;
if (dev_data->tx.state != I2S_STATE_RUNNING &&
@ -505,8 +505,8 @@ static void dma_rx_callback(const struct device *dma_dev, void *arg,
uint32_t channel, int status)
{
const struct device *dev = get_dev_from_rx_dma_channel(channel);
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
const struct i2s_stm32_cfg *cfg = dev->config;
struct i2s_stm32_data *const dev_data = dev->data;
struct stream *stream = &dev_data->rx;
void *mblk_tmp;
int ret;
@ -572,8 +572,8 @@ static void dma_tx_callback(const struct device *dma_dev, void *arg,
uint32_t channel, int status)
{
const struct device *dev = get_dev_from_tx_dma_channel(channel);
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
const struct i2s_stm32_cfg *cfg = dev->config;
struct i2s_stm32_data *const dev_data = dev->data;
struct stream *stream = &dev_data->tx;
size_t mem_block_size;
int ret;
@ -639,8 +639,8 @@ static uint32_t i2s_stm32_irq_ovr_count;
static void i2s_stm32_isr(const struct device *dev)
{
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
const struct i2s_stm32_cfg *cfg = dev->config;
struct i2s_stm32_data *const dev_data = dev->data;
struct stream *stream = &dev_data->rx;
LOG_ERR("%s: err=%d", __func__, (int)LL_I2S_ReadReg(cfg->i2s, SR));
@ -657,8 +657,8 @@ static void i2s_stm32_isr(const struct device *dev)
static int i2s_stm32_initialize(const struct device *dev)
{
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
struct i2s_stm32_data *const dev_data = DEV_DATA(dev);
const struct i2s_stm32_cfg *cfg = dev->config;
struct i2s_stm32_data *const dev_data = dev->data;
int ret, i;
/* Enable I2S clock propagation */
@ -703,7 +703,7 @@ static int i2s_stm32_initialize(const struct device *dev)
static int rx_stream_start(struct stream *stream, const struct device *dev)
{
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
const struct i2s_stm32_cfg *cfg = dev->config;
int ret;
ret = k_mem_slab_alloc(stream->cfg.mem_slab, &stream->mem_block,
@ -742,7 +742,7 @@ static int rx_stream_start(struct stream *stream, const struct device *dev)
static int tx_stream_start(struct stream *stream, const struct device *dev)
{
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
const struct i2s_stm32_cfg *cfg = dev->config;
size_t mem_block_size;
int ret;
@ -786,7 +786,7 @@ static int tx_stream_start(struct stream *stream, const struct device *dev)
static void rx_stream_disable(struct stream *stream, const struct device *dev)
{
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
const struct i2s_stm32_cfg *cfg = dev->config;
LL_I2S_DisableDMAReq_RX(cfg->i2s);
LL_I2S_DisableIT_ERR(cfg->i2s);
@ -804,7 +804,7 @@ static void rx_stream_disable(struct stream *stream, const struct device *dev)
static void tx_stream_disable(struct stream *stream, const struct device *dev)
{
const struct i2s_stm32_cfg *cfg = DEV_CFG(dev);
const struct i2s_stm32_cfg *cfg = dev->config;
LL_I2S_DisableDMAReq_TX(cfg->i2s);
LL_I2S_DisableIT_ERR(cfg->i2s);

View file

@ -49,11 +49,6 @@
#endif /* CONFIG_I2S_STM32_USE_PLLI2S_ENABLE */
#define DEV_CFG(dev) \
(const struct i2s_stm32_cfg * const)((dev)->config)
#define DEV_DATA(dev) \
((struct i2s_stm32_data *const)(dev)->data)
struct queue_item {
void *mem_block;
size_t size;

View file

@ -99,10 +99,6 @@ struct i2s_sam_dev_data {
};
#define DEV_NAME(dev) ((dev)->name)
#define DEV_CFG(dev) \
((const struct i2s_sam_dev_cfg *const)(dev)->config)
#define DEV_DATA(dev) \
((struct i2s_sam_dev_data *const)(dev)->data)
#define MODULO_INC(val, max) { val = (++val < max) ? val : 0; }
@ -210,8 +206,8 @@ static void dma_rx_callback(const struct device *dma_dev, void *user_data,
uint32_t channel, int status)
{
const struct device *dev = get_dev_from_dma_channel(channel);
const struct i2s_sam_dev_cfg *const dev_cfg = DEV_CFG(dev);
struct i2s_sam_dev_data *const dev_data = DEV_DATA(dev);
const struct i2s_sam_dev_cfg *const dev_cfg = dev->config;
struct i2s_sam_dev_data *const dev_data = dev->data;
Ssc *const ssc = dev_cfg->regs;
struct stream *stream = &dev_data->rx;
int ret;
@ -270,8 +266,8 @@ static void dma_tx_callback(const struct device *dma_dev, void *user_data,
uint32_t channel, int status)
{
const struct device *dev = get_dev_from_dma_channel(channel);
const struct i2s_sam_dev_cfg *const dev_cfg = DEV_CFG(dev);
struct i2s_sam_dev_data *const dev_data = DEV_DATA(dev);
const struct i2s_sam_dev_cfg *const dev_cfg = dev->config;
struct i2s_sam_dev_data *const dev_data = dev->data;
Ssc *const ssc = dev_cfg->regs;
struct stream *stream = &dev_data->tx;
size_t mem_block_size;
@ -534,7 +530,7 @@ static int bit_clock_set(Ssc *const ssc, uint32_t bit_clk_freq)
static const struct i2s_config *i2s_sam_config_get(const struct device *dev,
enum i2s_dir dir)
{
struct i2s_sam_dev_data *const dev_data = DEV_DATA(dev);
struct i2s_sam_dev_data *const dev_data = dev->data;
struct stream *stream;
if (dir == I2S_DIR_RX) {
@ -553,8 +549,8 @@ static const struct i2s_config *i2s_sam_config_get(const struct device *dev,
static int i2s_sam_configure(const struct device *dev, enum i2s_dir dir,
const struct i2s_config *i2s_cfg)
{
const struct i2s_sam_dev_cfg *const dev_cfg = DEV_CFG(dev);
struct i2s_sam_dev_data *const dev_data = DEV_DATA(dev);
const struct i2s_sam_dev_cfg *const dev_cfg = dev->config;
struct i2s_sam_dev_data *const dev_data = dev->data;
Ssc *const ssc = dev_cfg->regs;
uint8_t num_words = i2s_cfg->channels;
uint8_t word_size_bits = i2s_cfg->word_size;
@ -788,8 +784,8 @@ static void tx_queue_drop(struct stream *stream)
static int i2s_sam_trigger(const struct device *dev, enum i2s_dir dir,
enum i2s_trigger_cmd cmd)
{
const struct i2s_sam_dev_cfg *const dev_cfg = DEV_CFG(dev);
struct i2s_sam_dev_data *const dev_data = DEV_DATA(dev);
const struct i2s_sam_dev_cfg *const dev_cfg = dev->config;
struct i2s_sam_dev_data *const dev_data = dev->data;
Ssc *const ssc = dev_cfg->regs;
struct stream *stream;
unsigned int key;
@ -878,7 +874,7 @@ static int i2s_sam_trigger(const struct device *dev, enum i2s_dir dir,
static int i2s_sam_read(const struct device *dev, void **mem_block,
size_t *size)
{
struct i2s_sam_dev_data *const dev_data = DEV_DATA(dev);
struct i2s_sam_dev_data *const dev_data = dev->data;
int ret;
if (dev_data->rx.state == I2S_STATE_NOT_READY) {
@ -906,7 +902,7 @@ static int i2s_sam_read(const struct device *dev, void **mem_block,
static int i2s_sam_write(const struct device *dev, void *mem_block,
size_t size)
{
struct i2s_sam_dev_data *const dev_data = DEV_DATA(dev);
struct i2s_sam_dev_data *const dev_data = dev->data;
int ret;
if (dev_data->tx.state != I2S_STATE_RUNNING &&
@ -929,8 +925,8 @@ static int i2s_sam_write(const struct device *dev, void *mem_block,
static void i2s_sam_isr(const struct device *dev)
{
const struct i2s_sam_dev_cfg *const dev_cfg = DEV_CFG(dev);
struct i2s_sam_dev_data *const dev_data = DEV_DATA(dev);
const struct i2s_sam_dev_cfg *const dev_cfg = dev->config;
struct i2s_sam_dev_data *const dev_data = dev->data;
Ssc *const ssc = dev_cfg->regs;
uint32_t isr_status;
@ -955,8 +951,8 @@ static void i2s_sam_isr(const struct device *dev)
static int i2s_sam_initialize(const struct device *dev)
{
const struct i2s_sam_dev_cfg *const dev_cfg = DEV_CFG(dev);
struct i2s_sam_dev_data *const dev_data = DEV_DATA(dev);
const struct i2s_sam_dev_cfg *const dev_cfg = dev->config;
struct i2s_sam_dev_data *const dev_data = dev->data;
Ssc *const ssc = dev_cfg->regs;
/* Configure interrupts */