diff options
author | Roman Kiryanov <rkir@google.com> | 2018-06-04 14:08:19 -0700 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2018-06-17 09:05:14 +0200 |
commit | a75647d1e72f0af686b19940b864f35b9be631d6 (patch) | |
tree | 1453f948a8aabb333bdb6f23bad370b0575177e3 /drivers/staging/goldfish | |
parent | 5df204016c36a175829e6579f01244a8e2351480 (diff) |
staging: goldfish: Replace read and write macros with functions
Functions are less error-prone and generate cleaner compilation.
Signed-off-by: Roman Kiryanov <rkir@google.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/staging/goldfish')
-rw-r--r-- | drivers/staging/goldfish/goldfish_audio.c | 46 |
1 files changed, 30 insertions, 16 deletions
diff --git a/drivers/staging/goldfish/goldfish_audio.c b/drivers/staging/goldfish/goldfish_audio.c index bd559956f199..3a4715cd362b 100644 --- a/drivers/staging/goldfish/goldfish_audio.c +++ b/drivers/staging/goldfish/goldfish_audio.c @@ -61,11 +61,6 @@ struct goldfish_audio { #define COMBINED_BUFFER_SIZE ((2 * READ_BUFFER_SIZE) + \ (2 * WRITE_BUFFER_SIZE)) -#define AUDIO_READ(data, addr) (readl(data->reg_base + addr)) -#define AUDIO_WRITE(data, addr, x) (writel(x, data->reg_base + addr)) -#define AUDIO_WRITE64(data, addr, addr2, x) \ - (gf_write_dma_addr((x), data->reg_base + addr, data->reg_base + addr2)) - /* * temporary variable used between goldfish_audio_probe() and * goldfish_audio_open() @@ -112,6 +107,25 @@ enum { static atomic_t open_count = ATOMIC_INIT(0); +static unsigned int audio_read(const struct goldfish_audio *data, int addr) +{ + return readl(data->reg_base + addr); +} + +static void audio_write(const struct goldfish_audio *data, + int addr, unsigned int x) +{ + writel(x, data->reg_base + addr); +} + +static void audio_write64(const struct goldfish_audio *data, + int addr_lo, int addr_hi, unsigned int x) +{ + char __iomem *reg_base = data->reg_base; + + gf_write_dma_addr(x, reg_base + addr_lo, reg_base + addr_hi); +} + static ssize_t goldfish_audio_read(struct file *fp, char __user *buf, size_t count, loff_t *pos) { @@ -124,12 +138,12 @@ static ssize_t goldfish_audio_read(struct file *fp, char __user *buf, while (count > 0) { length = (count > READ_BUFFER_SIZE ? READ_BUFFER_SIZE : count); - AUDIO_WRITE(data, AUDIO_START_READ, length); + audio_write(data, AUDIO_START_READ, length); wait_event_interruptible(data->wait, data->buffer_status & AUDIO_INT_READ_BUFFER_FULL); - length = AUDIO_READ(data, AUDIO_READ_BUFFER_AVAILABLE); + length = audio_read(data, AUDIO_READ_BUFFER_AVAILABLE); /* copy data to user space */ if (copy_to_user(buf, data->read_buffer, length)) @@ -177,10 +191,10 @@ static ssize_t goldfish_audio_write(struct file *fp, const char __user *buf, */ if (kbuf == data->write_buffer1) { data->buffer_status &= ~AUDIO_INT_WRITE_BUFFER_1_EMPTY; - AUDIO_WRITE(data, AUDIO_WRITE_BUFFER_1, copy); + audio_write(data, AUDIO_WRITE_BUFFER_1, copy); } else { data->buffer_status &= ~AUDIO_INT_WRITE_BUFFER_2_EMPTY; - AUDIO_WRITE(data, AUDIO_WRITE_BUFFER_2, copy); + audio_write(data, AUDIO_WRITE_BUFFER_2, copy); } spin_unlock_irqrestore(&data->lock, irq_flags); @@ -200,7 +214,7 @@ static int goldfish_audio_open(struct inode *ip, struct file *fp) fp->private_data = audio_data; audio_data->buffer_status = (AUDIO_INT_WRITE_BUFFER_1_EMPTY | AUDIO_INT_WRITE_BUFFER_2_EMPTY); - AUDIO_WRITE(audio_data, AUDIO_INT_ENABLE, AUDIO_INT_MASK); + audio_write(audio_data, AUDIO_INT_ENABLE, AUDIO_INT_MASK); return 0; } @@ -212,7 +226,7 @@ static int goldfish_audio_release(struct inode *ip, struct file *fp) { atomic_dec(&open_count); /* FIXME: surely this is wrong for the multi-opened case */ - AUDIO_WRITE(audio_data, AUDIO_INT_ENABLE, 0); + audio_write(audio_data, AUDIO_INT_ENABLE, 0); return 0; } @@ -235,7 +249,7 @@ static irqreturn_t goldfish_audio_interrupt(int irq, void *dev_id) spin_lock_irqsave(&data->lock, irq_flags); /* read buffer status flags */ - status = AUDIO_READ(data, AUDIO_INT_STATUS); + status = audio_read(data, AUDIO_INT_STATUS); status &= AUDIO_INT_MASK; /* * if buffers are newly empty, wake up blocked @@ -320,18 +334,18 @@ static int goldfish_audio_probe(struct platform_device *pdev) return ret; } - AUDIO_WRITE64(data, AUDIO_SET_WRITE_BUFFER_1, + audio_write64(data, AUDIO_SET_WRITE_BUFFER_1, AUDIO_SET_WRITE_BUFFER_1_HIGH, buf_addr); buf_addr += WRITE_BUFFER_SIZE; - AUDIO_WRITE64(data, AUDIO_SET_WRITE_BUFFER_2, + audio_write64(data, AUDIO_SET_WRITE_BUFFER_2, AUDIO_SET_WRITE_BUFFER_2_HIGH, buf_addr); buf_addr += WRITE_BUFFER_SIZE; - data->read_supported = AUDIO_READ(data, AUDIO_READ_SUPPORTED); + data->read_supported = audio_read(data, AUDIO_READ_SUPPORTED); if (data->read_supported) - AUDIO_WRITE64(data, AUDIO_SET_READ_BUFFER, + audio_write64(data, AUDIO_SET_READ_BUFFER, AUDIO_SET_READ_BUFFER_HIGH, buf_addr); audio_data = data; |