2 * Functions for the OPL4 proc file
3 * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
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.
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.
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
20 #include "opl4_local.h"
21 #include <linux/vmalloc.h>
22 #include <sound/info.h>
26 static int snd_opl4_mem_proc_open(snd_info_entry_t
*entry
,
27 unsigned short mode
, void **file_private_data
)
29 opl4_t
*opl4
= entry
->private_data
;
31 down(&opl4
->access_mutex
);
32 if (opl4
->memory_access
) {
33 up(&opl4
->access_mutex
);
36 opl4
->memory_access
++;
37 up(&opl4
->access_mutex
);
41 static int snd_opl4_mem_proc_release(snd_info_entry_t
*entry
,
42 unsigned short mode
, void *file_private_data
)
44 opl4_t
*opl4
= entry
->private_data
;
46 down(&opl4
->access_mutex
);
47 opl4
->memory_access
--;
48 up(&opl4
->access_mutex
);
52 static long snd_opl4_mem_proc_read(snd_info_entry_t
*entry
, void *file_private_data
,
53 struct file
*file
, char __user
*_buf
,
54 unsigned long count
, unsigned long pos
)
56 opl4_t
*opl4
= entry
->private_data
;
61 if (pos
+ size
> entry
->size
)
62 size
= entry
->size
- pos
;
67 snd_opl4_read_memory(opl4
, buf
, pos
, size
);
68 if (copy_to_user(_buf
, buf
, size
)) {
78 static long snd_opl4_mem_proc_write(snd_info_entry_t
*entry
, void *file_private_data
,
79 struct file
*file
, const char __user
*_buf
,
80 unsigned long count
, unsigned long pos
)
82 opl4_t
*opl4
= entry
->private_data
;
87 if (pos
+ size
> entry
->size
)
88 size
= entry
->size
- pos
;
93 if (copy_from_user(buf
, _buf
, size
)) {
97 snd_opl4_write_memory(opl4
, buf
, pos
, size
);
104 static long long snd_opl4_mem_proc_llseek(snd_info_entry_t
*entry
, void *file_private_data
,
105 struct file
*file
, long long offset
, int orig
)
108 case 0: /* SEEK_SET */
109 file
->f_pos
= offset
;
111 case 1: /* SEEK_CUR */
112 file
->f_pos
+= offset
;
114 case 2: /* SEEK_END, offset is negative */
115 file
->f_pos
= entry
->size
+ offset
;
120 if (file
->f_pos
> entry
->size
)
121 file
->f_pos
= entry
->size
;
125 static struct snd_info_entry_ops snd_opl4_mem_proc_ops
= {
126 .open
= snd_opl4_mem_proc_open
,
127 .release
= snd_opl4_mem_proc_release
,
128 .read
= snd_opl4_mem_proc_read
,
129 .write
= snd_opl4_mem_proc_write
,
130 .llseek
= snd_opl4_mem_proc_llseek
,
133 int snd_opl4_create_proc(opl4_t
*opl4
)
135 snd_info_entry_t
*entry
;
137 entry
= snd_info_create_card_entry(opl4
->card
, "opl4-mem", opl4
->card
->proc_root
);
139 if (opl4
->hardware
< OPL3_HW_OPL4_ML
) {
140 /* OPL4 can access 4 MB external ROM/SRAM */
141 entry
->mode
|= S_IWUSR
;
142 entry
->size
= 4 * 1024 * 1024;
144 /* OPL4-ML has 1 MB internal ROM */
145 entry
->size
= 1 * 1024 * 1024;
147 entry
->content
= SNDRV_INFO_CONTENT_DATA
;
148 entry
->c
.ops
= &snd_opl4_mem_proc_ops
;
149 entry
->module
= THIS_MODULE
;
150 entry
->private_data
= opl4
;
151 if (snd_info_register(entry
) < 0) {
152 snd_info_free_entry(entry
);
156 opl4
->proc_entry
= entry
;
160 void snd_opl4_free_proc(opl4_t
*opl4
)
162 if (opl4
->proc_entry
)
163 snd_info_unregister(opl4
->proc_entry
);
166 #endif /* CONFIG_PROC_FS */