Sara Bird | ad28497 | 2013-05-20 15:32:49 -0400 | [diff] [blame] | 1 | /* |
| 2 | * drivers/misc/goldfish_audio.c |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2007 Google, Inc. |
| 5 | * Copyright (C) 2012 Intel, Inc. |
| 6 | * |
| 7 | * This software is licensed under the terms of the GNU General Public |
| 8 | * License version 2, as published by the Free Software Foundation, and |
| 9 | * may be copied, distributed, and modified under those terms. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | */ |
| 17 | |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/miscdevice.h> |
| 20 | #include <linux/fs.h> |
| 21 | #include <linux/platform_device.h> |
| 22 | #include <linux/types.h> |
| 23 | #include <linux/pci.h> |
| 24 | #include <linux/interrupt.h> |
| 25 | #include <linux/io.h> |
| 26 | #include <linux/sched.h> |
| 27 | #include <linux/dma-mapping.h> |
| 28 | #include <linux/uaccess.h> |
Greg Hackmann | 45321507 | 2016-02-26 19:00:18 +0000 | [diff] [blame] | 29 | #include <linux/slab.h> |
Alan | f627971 | 2014-05-12 16:56:56 +0100 | [diff] [blame] | 30 | #include <linux/goldfish.h> |
Yu Ning | 6ab8758 | 2015-03-31 14:41:48 +0800 | [diff] [blame] | 31 | #include <linux/acpi.h> |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 32 | |
| 33 | MODULE_AUTHOR("Google, Inc."); |
| 34 | MODULE_DESCRIPTION("Android QEMU Audio Driver"); |
| 35 | MODULE_LICENSE("GPL"); |
| 36 | MODULE_VERSION("1.0"); |
| 37 | |
| 38 | struct goldfish_audio { |
| 39 | char __iomem *reg_base; |
| 40 | int irq; |
Loic Pefferkorn | 9b61f08 | 2014-09-03 22:23:12 +0200 | [diff] [blame] | 41 | /* lock protects access to buffer_status and to device registers */ |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 42 | spinlock_t lock; |
| 43 | wait_queue_head_t wait; |
| 44 | |
Ricardo Ribalda Delgado | 82fdb8d | 2015-03-16 23:01:44 +0100 | [diff] [blame] | 45 | char *buffer_virt; /* combined buffer virtual address */ |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 46 | unsigned long buffer_phys; /* combined buffer physical address */ |
| 47 | |
Ricardo Ribalda Delgado | 82fdb8d | 2015-03-16 23:01:44 +0100 | [diff] [blame] | 48 | char *write_buffer1; /* write buffer 1 virtual address */ |
| 49 | char *write_buffer2; /* write buffer 2 virtual address */ |
| 50 | char *read_buffer; /* read buffer virtual address */ |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 51 | int buffer_status; |
| 52 | int read_supported; /* true if we have audio input support */ |
| 53 | }; |
| 54 | |
Sara Bird | ad28497 | 2013-05-20 15:32:49 -0400 | [diff] [blame] | 55 | /* |
| 56 | * We will allocate two read buffers and two write buffers. |
| 57 | * Having two read buffers facilitate stereo -> mono conversion. |
| 58 | * Having two write buffers facilitate interleaved IO. |
| 59 | */ |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 60 | #define READ_BUFFER_SIZE 16384 |
| 61 | #define WRITE_BUFFER_SIZE 16384 |
| 62 | #define COMBINED_BUFFER_SIZE ((2 * READ_BUFFER_SIZE) + \ |
| 63 | (2 * WRITE_BUFFER_SIZE)) |
| 64 | |
| 65 | #define AUDIO_READ(data, addr) (readl(data->reg_base + addr)) |
| 66 | #define AUDIO_WRITE(data, addr, x) (writel(x, data->reg_base + addr)) |
Alan | f627971 | 2014-05-12 16:56:56 +0100 | [diff] [blame] | 67 | #define AUDIO_WRITE64(data, addr, addr2, x) \ |
Christian Colic | 2ce601b | 2015-11-19 09:38:21 +0100 | [diff] [blame] | 68 | (gf_write_dma_addr((x), data->reg_base + addr, data->reg_base + addr2)) |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 69 | |
Sara Bird | ad28497 | 2013-05-20 15:32:49 -0400 | [diff] [blame] | 70 | /* |
| 71 | * temporary variable used between goldfish_audio_probe() and |
| 72 | * goldfish_audio_open() |
| 73 | */ |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 74 | static struct goldfish_audio *audio_data; |
| 75 | |
| 76 | enum { |
| 77 | /* audio status register */ |
| 78 | AUDIO_INT_STATUS = 0x00, |
| 79 | /* set this to enable IRQ */ |
| 80 | AUDIO_INT_ENABLE = 0x04, |
| 81 | /* set these to specify buffer addresses */ |
| 82 | AUDIO_SET_WRITE_BUFFER_1 = 0x08, |
| 83 | AUDIO_SET_WRITE_BUFFER_2 = 0x0C, |
| 84 | /* set number of bytes in buffer to write */ |
| 85 | AUDIO_WRITE_BUFFER_1 = 0x10, |
| 86 | AUDIO_WRITE_BUFFER_2 = 0x14, |
Jun Tian | c3c1ba6 | 2014-04-28 20:47:03 +0100 | [diff] [blame] | 87 | AUDIO_SET_WRITE_BUFFER_1_HIGH = 0x28, |
| 88 | AUDIO_SET_WRITE_BUFFER_2_HIGH = 0x30, |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 89 | |
| 90 | /* true if audio input is supported */ |
| 91 | AUDIO_READ_SUPPORTED = 0x18, |
| 92 | /* buffer to use for audio input */ |
| 93 | AUDIO_SET_READ_BUFFER = 0x1C, |
Jun Tian | c3c1ba6 | 2014-04-28 20:47:03 +0100 | [diff] [blame] | 94 | AUDIO_SET_READ_BUFFER_HIGH = 0x34, |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 95 | |
| 96 | /* driver writes number of bytes to read */ |
| 97 | AUDIO_START_READ = 0x20, |
| 98 | |
| 99 | /* number of bytes available in read buffer */ |
| 100 | AUDIO_READ_BUFFER_AVAILABLE = 0x24, |
| 101 | |
| 102 | /* AUDIO_INT_STATUS bits */ |
| 103 | |
| 104 | /* this bit set when it is safe to write more bytes to the buffer */ |
| 105 | AUDIO_INT_WRITE_BUFFER_1_EMPTY = 1U << 0, |
| 106 | AUDIO_INT_WRITE_BUFFER_2_EMPTY = 1U << 1, |
| 107 | AUDIO_INT_READ_BUFFER_FULL = 1U << 2, |
| 108 | |
| 109 | AUDIO_INT_MASK = AUDIO_INT_WRITE_BUFFER_1_EMPTY | |
| 110 | AUDIO_INT_WRITE_BUFFER_2_EMPTY | |
| 111 | AUDIO_INT_READ_BUFFER_FULL, |
| 112 | }; |
| 113 | |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 114 | static atomic_t open_count = ATOMIC_INIT(0); |
| 115 | |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 116 | static ssize_t goldfish_audio_read(struct file *fp, char __user *buf, |
Loic Pefferkorn | 8f52e26 | 2014-09-03 22:23:13 +0200 | [diff] [blame] | 117 | size_t count, loff_t *pos) |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 118 | { |
| 119 | struct goldfish_audio *data = fp->private_data; |
Joshua Lang | ebb099e | 2016-06-17 17:30:55 -0700 | [diff] [blame] | 120 | unsigned long irq_flags; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 121 | int length; |
| 122 | int result = 0; |
| 123 | |
| 124 | if (!data->read_supported) |
| 125 | return -ENODEV; |
| 126 | |
| 127 | while (count > 0) { |
| 128 | length = (count > READ_BUFFER_SIZE ? READ_BUFFER_SIZE : count); |
| 129 | AUDIO_WRITE(data, AUDIO_START_READ, length); |
| 130 | |
Aya Mahfouz | d7d3e89 | 2015-03-10 19:09:10 +0200 | [diff] [blame] | 131 | wait_event_interruptible(data->wait, data->buffer_status & |
| 132 | AUDIO_INT_READ_BUFFER_FULL); |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 133 | |
Joshua Lang | ebb099e | 2016-06-17 17:30:55 -0700 | [diff] [blame] | 134 | spin_lock_irqsave(&data->lock, irq_flags); |
| 135 | data->buffer_status &= ~AUDIO_INT_READ_BUFFER_FULL; |
| 136 | spin_unlock_irqrestore(&data->lock, irq_flags); |
| 137 | |
Loic Pefferkorn | 8f52e26 | 2014-09-03 22:23:13 +0200 | [diff] [blame] | 138 | length = AUDIO_READ(data, AUDIO_READ_BUFFER_AVAILABLE); |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 139 | |
| 140 | /* copy data to user space */ |
| 141 | if (copy_to_user(buf, data->read_buffer, length)) |
| 142 | return -EFAULT; |
| 143 | |
| 144 | result += length; |
| 145 | buf += length; |
| 146 | count -= length; |
| 147 | } |
| 148 | return result; |
| 149 | } |
| 150 | |
| 151 | static ssize_t goldfish_audio_write(struct file *fp, const char __user *buf, |
Loic Pefferkorn | 8f52e26 | 2014-09-03 22:23:13 +0200 | [diff] [blame] | 152 | size_t count, loff_t *pos) |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 153 | { |
| 154 | struct goldfish_audio *data = fp->private_data; |
| 155 | unsigned long irq_flags; |
| 156 | ssize_t result = 0; |
Ricardo Ribalda Delgado | 82fdb8d | 2015-03-16 23:01:44 +0100 | [diff] [blame] | 157 | char *kbuf; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 158 | |
| 159 | while (count > 0) { |
| 160 | ssize_t copy = count; |
Garret Kelly | ef32381 | 2014-04-06 23:47:31 -0400 | [diff] [blame] | 161 | |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 162 | if (copy > WRITE_BUFFER_SIZE) |
| 163 | copy = WRITE_BUFFER_SIZE; |
Aya Mahfouz | d7d3e89 | 2015-03-10 19:09:10 +0200 | [diff] [blame] | 164 | wait_event_interruptible(data->wait, data->buffer_status & |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 165 | (AUDIO_INT_WRITE_BUFFER_1_EMPTY | |
Aya Mahfouz | d7d3e89 | 2015-03-10 19:09:10 +0200 | [diff] [blame] | 166 | AUDIO_INT_WRITE_BUFFER_2_EMPTY)); |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 167 | |
| 168 | if ((data->buffer_status & AUDIO_INT_WRITE_BUFFER_1_EMPTY) != 0) |
| 169 | kbuf = data->write_buffer1; |
| 170 | else |
| 171 | kbuf = data->write_buffer2; |
| 172 | |
| 173 | /* copy from user space to the appropriate buffer */ |
| 174 | if (copy_from_user(kbuf, buf, copy)) { |
| 175 | result = -EFAULT; |
| 176 | break; |
| 177 | } |
| 178 | |
| 179 | spin_lock_irqsave(&data->lock, irq_flags); |
Sara Bird | ad28497 | 2013-05-20 15:32:49 -0400 | [diff] [blame] | 180 | /* |
| 181 | * clear the buffer empty flag, and signal the emulator |
| 182 | * to start writing the buffer |
| 183 | */ |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 184 | if (kbuf == data->write_buffer1) { |
| 185 | data->buffer_status &= ~AUDIO_INT_WRITE_BUFFER_1_EMPTY; |
| 186 | AUDIO_WRITE(data, AUDIO_WRITE_BUFFER_1, copy); |
| 187 | } else { |
| 188 | data->buffer_status &= ~AUDIO_INT_WRITE_BUFFER_2_EMPTY; |
| 189 | AUDIO_WRITE(data, AUDIO_WRITE_BUFFER_2, copy); |
| 190 | } |
| 191 | spin_unlock_irqrestore(&data->lock, irq_flags); |
| 192 | |
| 193 | buf += copy; |
| 194 | result += copy; |
| 195 | count -= copy; |
| 196 | } |
| 197 | return result; |
| 198 | } |
| 199 | |
| 200 | static int goldfish_audio_open(struct inode *ip, struct file *fp) |
| 201 | { |
| 202 | if (!audio_data) |
| 203 | return -ENODEV; |
| 204 | |
| 205 | if (atomic_inc_return(&open_count) == 1) { |
| 206 | fp->private_data = audio_data; |
| 207 | audio_data->buffer_status = (AUDIO_INT_WRITE_BUFFER_1_EMPTY | |
| 208 | AUDIO_INT_WRITE_BUFFER_2_EMPTY); |
| 209 | AUDIO_WRITE(audio_data, AUDIO_INT_ENABLE, AUDIO_INT_MASK); |
| 210 | return 0; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 211 | } |
Hoang Tran | 9227155 | 2014-06-16 15:18:37 +0800 | [diff] [blame] | 212 | |
| 213 | atomic_dec(&open_count); |
| 214 | return -EBUSY; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | static int goldfish_audio_release(struct inode *ip, struct file *fp) |
| 218 | { |
| 219 | atomic_dec(&open_count); |
| 220 | /* FIXME: surely this is wrong for the multi-opened case */ |
| 221 | AUDIO_WRITE(audio_data, AUDIO_INT_ENABLE, 0); |
| 222 | return 0; |
| 223 | } |
| 224 | |
| 225 | static long goldfish_audio_ioctl(struct file *fp, unsigned int cmd, |
Loic Pefferkorn | 8f52e26 | 2014-09-03 22:23:13 +0200 | [diff] [blame] | 226 | unsigned long arg) |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 227 | { |
| 228 | /* temporary workaround, until we switch to the ALSA API */ |
| 229 | if (cmd == 315) |
| 230 | return -1; |
Hoang Tran | 9227155 | 2014-06-16 15:18:37 +0800 | [diff] [blame] | 231 | |
| 232 | return 0; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 233 | } |
| 234 | |
| 235 | static irqreturn_t goldfish_audio_interrupt(int irq, void *dev_id) |
| 236 | { |
| 237 | unsigned long irq_flags; |
| 238 | struct goldfish_audio *data = dev_id; |
| 239 | u32 status; |
| 240 | |
| 241 | spin_lock_irqsave(&data->lock, irq_flags); |
| 242 | |
| 243 | /* read buffer status flags */ |
| 244 | status = AUDIO_READ(data, AUDIO_INT_STATUS); |
| 245 | status &= AUDIO_INT_MASK; |
Sara Bird | ad28497 | 2013-05-20 15:32:49 -0400 | [diff] [blame] | 246 | /* |
| 247 | * if buffers are newly empty, wake up blocked |
| 248 | * goldfish_audio_write() call |
| 249 | */ |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 250 | if (status) { |
| 251 | data->buffer_status = status; |
| 252 | wake_up(&data->wait); |
| 253 | } |
| 254 | |
| 255 | spin_unlock_irqrestore(&data->lock, irq_flags); |
| 256 | return status ? IRQ_HANDLED : IRQ_NONE; |
| 257 | } |
| 258 | |
| 259 | /* file operations for /dev/eac */ |
| 260 | static const struct file_operations goldfish_audio_fops = { |
| 261 | .owner = THIS_MODULE, |
| 262 | .read = goldfish_audio_read, |
| 263 | .write = goldfish_audio_write, |
| 264 | .open = goldfish_audio_open, |
| 265 | .release = goldfish_audio_release, |
| 266 | .unlocked_ioctl = goldfish_audio_ioctl, |
| 267 | }; |
| 268 | |
| 269 | static struct miscdevice goldfish_audio_device = { |
| 270 | .minor = MISC_DYNAMIC_MINOR, |
| 271 | .name = "eac", |
| 272 | .fops = &goldfish_audio_fops, |
| 273 | }; |
| 274 | |
| 275 | static int goldfish_audio_probe(struct platform_device *pdev) |
| 276 | { |
| 277 | int ret; |
| 278 | struct resource *r; |
| 279 | struct goldfish_audio *data; |
| 280 | dma_addr_t buf_addr; |
| 281 | |
Himangi Saraogi | 85f2833 | 2014-07-04 22:49:57 +0530 | [diff] [blame] | 282 | data = devm_kzalloc(&pdev->dev, sizeof(*data), GFP_KERNEL); |
Somya Anand | 6e3f3bb | 2015-03-16 19:34:09 +0530 | [diff] [blame] | 283 | if (!data) |
Himangi Saraogi | 85f2833 | 2014-07-04 22:49:57 +0530 | [diff] [blame] | 284 | return -ENOMEM; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 285 | spin_lock_init(&data->lock); |
| 286 | init_waitqueue_head(&data->wait); |
| 287 | platform_set_drvdata(pdev, data); |
| 288 | |
| 289 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Christian Colic | 269ad6e | 2015-11-19 09:47:24 +0100 | [diff] [blame] | 290 | if (!r) { |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 291 | dev_err(&pdev->dev, "platform_get_resource failed\n"); |
Himangi Saraogi | 85f2833 | 2014-07-04 22:49:57 +0530 | [diff] [blame] | 292 | return -ENODEV; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 293 | } |
Himangi Saraogi | 85f2833 | 2014-07-04 22:49:57 +0530 | [diff] [blame] | 294 | data->reg_base = devm_ioremap(&pdev->dev, r->start, PAGE_SIZE); |
Christian Colic | 269ad6e | 2015-11-19 09:47:24 +0100 | [diff] [blame] | 295 | if (!data->reg_base) |
Himangi Saraogi | 85f2833 | 2014-07-04 22:49:57 +0530 | [diff] [blame] | 296 | return -ENOMEM; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 297 | |
| 298 | data->irq = platform_get_irq(pdev, 0); |
| 299 | if (data->irq < 0) { |
| 300 | dev_err(&pdev->dev, "platform_get_irq failed\n"); |
Himangi Saraogi | 85f2833 | 2014-07-04 22:49:57 +0530 | [diff] [blame] | 301 | return -ENODEV; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 302 | } |
Himangi Saraogi | 85f2833 | 2014-07-04 22:49:57 +0530 | [diff] [blame] | 303 | data->buffer_virt = dmam_alloc_coherent(&pdev->dev, |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 304 | COMBINED_BUFFER_SIZE, &buf_addr, GFP_KERNEL); |
Christian Colic | 269ad6e | 2015-11-19 09:47:24 +0100 | [diff] [blame] | 305 | if (!data->buffer_virt) { |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 306 | dev_err(&pdev->dev, "allocate buffer failed\n"); |
Himangi Saraogi | 85f2833 | 2014-07-04 22:49:57 +0530 | [diff] [blame] | 307 | return -ENOMEM; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 308 | } |
| 309 | data->buffer_phys = buf_addr; |
| 310 | data->write_buffer1 = data->buffer_virt; |
| 311 | data->write_buffer2 = data->buffer_virt + WRITE_BUFFER_SIZE; |
| 312 | data->read_buffer = data->buffer_virt + 2 * WRITE_BUFFER_SIZE; |
| 313 | |
Himangi Saraogi | 85f2833 | 2014-07-04 22:49:57 +0530 | [diff] [blame] | 314 | ret = devm_request_irq(&pdev->dev, data->irq, goldfish_audio_interrupt, |
Loic Pefferkorn | 8f52e26 | 2014-09-03 22:23:13 +0200 | [diff] [blame] | 315 | IRQF_SHARED, pdev->name, data); |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 316 | if (ret) { |
| 317 | dev_err(&pdev->dev, "request_irq failed\n"); |
Himangi Saraogi | 85f2833 | 2014-07-04 22:49:57 +0530 | [diff] [blame] | 318 | return ret; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | ret = misc_register(&goldfish_audio_device); |
| 322 | if (ret) { |
| 323 | dev_err(&pdev->dev, |
| 324 | "misc_register returned %d in goldfish_audio_init\n", |
| 325 | ret); |
Himangi Saraogi | 85f2833 | 2014-07-04 22:49:57 +0530 | [diff] [blame] | 326 | return ret; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 327 | } |
| 328 | |
Alan | f627971 | 2014-05-12 16:56:56 +0100 | [diff] [blame] | 329 | AUDIO_WRITE64(data, AUDIO_SET_WRITE_BUFFER_1, |
Loic Pefferkorn | 8f52e26 | 2014-09-03 22:23:13 +0200 | [diff] [blame] | 330 | AUDIO_SET_WRITE_BUFFER_1_HIGH, buf_addr); |
Alan | f627971 | 2014-05-12 16:56:56 +0100 | [diff] [blame] | 331 | buf_addr += WRITE_BUFFER_SIZE; |
Jun Tian | c3c1ba6 | 2014-04-28 20:47:03 +0100 | [diff] [blame] | 332 | |
Alan | f627971 | 2014-05-12 16:56:56 +0100 | [diff] [blame] | 333 | AUDIO_WRITE64(data, AUDIO_SET_WRITE_BUFFER_2, |
Loic Pefferkorn | 8f52e26 | 2014-09-03 22:23:13 +0200 | [diff] [blame] | 334 | AUDIO_SET_WRITE_BUFFER_2_HIGH, buf_addr); |
Jun Tian | c3c1ba6 | 2014-04-28 20:47:03 +0100 | [diff] [blame] | 335 | |
Alan | f627971 | 2014-05-12 16:56:56 +0100 | [diff] [blame] | 336 | buf_addr += WRITE_BUFFER_SIZE; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 337 | |
| 338 | data->read_supported = AUDIO_READ(data, AUDIO_READ_SUPPORTED); |
| 339 | if (data->read_supported) |
Alan | f627971 | 2014-05-12 16:56:56 +0100 | [diff] [blame] | 340 | AUDIO_WRITE64(data, AUDIO_SET_READ_BUFFER, |
Loic Pefferkorn | 8f52e26 | 2014-09-03 22:23:13 +0200 | [diff] [blame] | 341 | AUDIO_SET_READ_BUFFER_HIGH, buf_addr); |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 342 | |
| 343 | audio_data = data; |
| 344 | return 0; |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | static int goldfish_audio_remove(struct platform_device *pdev) |
| 348 | { |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 349 | misc_deregister(&goldfish_audio_device); |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 350 | audio_data = NULL; |
| 351 | return 0; |
| 352 | } |
| 353 | |
Greg Hackmann | 283ded1 | 2016-02-26 19:00:03 +0000 | [diff] [blame] | 354 | static const struct of_device_id goldfish_audio_of_match[] = { |
| 355 | { .compatible = "google,goldfish-audio", }, |
| 356 | {}, |
| 357 | }; |
| 358 | MODULE_DEVICE_TABLE(of, goldfish_audio_of_match); |
| 359 | |
Yu Ning | 6ab8758 | 2015-03-31 14:41:48 +0800 | [diff] [blame] | 360 | static const struct acpi_device_id goldfish_audio_acpi_match[] = { |
| 361 | { "GFSH0005", 0 }, |
| 362 | { }, |
| 363 | }; |
| 364 | MODULE_DEVICE_TABLE(acpi, goldfish_audio_acpi_match); |
| 365 | |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 366 | static struct platform_driver goldfish_audio_driver = { |
| 367 | .probe = goldfish_audio_probe, |
| 368 | .remove = goldfish_audio_remove, |
| 369 | .driver = { |
Greg Hackmann | 283ded1 | 2016-02-26 19:00:03 +0000 | [diff] [blame] | 370 | .name = "goldfish_audio", |
| 371 | .of_match_table = goldfish_audio_of_match, |
Yu Ning | 6ab8758 | 2015-03-31 14:41:48 +0800 | [diff] [blame] | 372 | .acpi_match_table = ACPI_PTR(goldfish_audio_acpi_match), |
Alan Cox | 2e82b83 | 2013-01-23 14:13:52 +0000 | [diff] [blame] | 373 | } |
| 374 | }; |
| 375 | |
| 376 | module_platform_driver(goldfish_audio_driver); |