treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 155
[linux-block.git] / sound / drivers / opl4 / opl4_proc.c
CommitLineData
1da177e4
LT
1/*
2 * Functions for the OPL4 proc file
3 * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */
19
20#include "opl4_local.h"
21#include <linux/vmalloc.h>
d81a6d71 22#include <linux/export.h>
1da177e4
LT
23#include <sound/info.h>
24
a42dd420 25static int snd_opl4_mem_proc_open(struct snd_info_entry *entry,
1da177e4
LT
26 unsigned short mode, void **file_private_data)
27{
a42dd420 28 struct snd_opl4 *opl4 = entry->private_data;
1da177e4 29
ef9f0a42 30 mutex_lock(&opl4->access_mutex);
1da177e4 31 if (opl4->memory_access) {
ef9f0a42 32 mutex_unlock(&opl4->access_mutex);
1da177e4
LT
33 return -EBUSY;
34 }
35 opl4->memory_access++;
ef9f0a42 36 mutex_unlock(&opl4->access_mutex);
1da177e4
LT
37 return 0;
38}
39
a42dd420 40static int snd_opl4_mem_proc_release(struct snd_info_entry *entry,
1da177e4
LT
41 unsigned short mode, void *file_private_data)
42{
a42dd420 43 struct snd_opl4 *opl4 = entry->private_data;
1da177e4 44
ef9f0a42 45 mutex_lock(&opl4->access_mutex);
1da177e4 46 opl4->memory_access--;
ef9f0a42 47 mutex_unlock(&opl4->access_mutex);
1da177e4
LT
48 return 0;
49}
50
24e4a121
TI
51static ssize_t snd_opl4_mem_proc_read(struct snd_info_entry *entry,
52 void *file_private_data,
53 struct file *file, char __user *_buf,
54 size_t count, loff_t pos)
1da177e4 55{
a42dd420 56 struct snd_opl4 *opl4 = entry->private_data;
1da177e4
LT
57 char* buf;
58
d97e1b78
TI
59 buf = vmalloc(count);
60 if (!buf)
61 return -ENOMEM;
62 snd_opl4_read_memory(opl4, buf, pos, count);
63 if (copy_to_user(_buf, buf, count)) {
1da177e4 64 vfree(buf);
d97e1b78 65 return -EFAULT;
1da177e4 66 }
d97e1b78
TI
67 vfree(buf);
68 return count;
1da177e4
LT
69}
70
24e4a121
TI
71static ssize_t snd_opl4_mem_proc_write(struct snd_info_entry *entry,
72 void *file_private_data,
73 struct file *file,
74 const char __user *_buf,
670ff6ab 75 size_t count, loff_t pos)
1da177e4 76{
a42dd420 77 struct snd_opl4 *opl4 = entry->private_data;
1da177e4
LT
78 char *buf;
79
d97e1b78
TI
80 buf = vmalloc(count);
81 if (!buf)
82 return -ENOMEM;
83 if (copy_from_user(buf, _buf, count)) {
1da177e4 84 vfree(buf);
d97e1b78 85 return -EFAULT;
1da177e4 86 }
d97e1b78
TI
87 snd_opl4_write_memory(opl4, buf, pos, count);
88 vfree(buf);
89 return count;
1da177e4
LT
90}
91
1da177e4
LT
92static struct snd_info_entry_ops snd_opl4_mem_proc_ops = {
93 .open = snd_opl4_mem_proc_open,
94 .release = snd_opl4_mem_proc_release,
95 .read = snd_opl4_mem_proc_read,
96 .write = snd_opl4_mem_proc_write,
1da177e4
LT
97};
98
a42dd420 99int snd_opl4_create_proc(struct snd_opl4 *opl4)
1da177e4 100{
a42dd420 101 struct snd_info_entry *entry;
1da177e4
LT
102
103 entry = snd_info_create_card_entry(opl4->card, "opl4-mem", opl4->card->proc_root);
104 if (entry) {
105 if (opl4->hardware < OPL3_HW_OPL4_ML) {
106 /* OPL4 can access 4 MB external ROM/SRAM */
6a73cf46 107 entry->mode |= 0200;
1da177e4
LT
108 entry->size = 4 * 1024 * 1024;
109 } else {
110 /* OPL4-ML has 1 MB internal ROM */
111 entry->size = 1 * 1024 * 1024;
112 }
113 entry->content = SNDRV_INFO_CONTENT_DATA;
114 entry->c.ops = &snd_opl4_mem_proc_ops;
115 entry->module = THIS_MODULE;
116 entry->private_data = opl4;
1da177e4
LT
117 }
118 opl4->proc_entry = entry;
119 return 0;
120}
121
a42dd420 122void snd_opl4_free_proc(struct snd_opl4 *opl4)
1da177e4 123{
746d4a02 124 snd_info_free_entry(opl4->proc_entry);
1da177e4 125}