-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsdmixer.c
238 lines (201 loc) · 5.43 KB
/
sdmixer.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/*
* PlayStation 2 Mixer driver
*
* Copyright (C) 2000-2002 Sony Computer Entertainment Inc.
*
* This file is subject to the terms and conditions of the GNU General
* Public License Version 2. See the file "COPYING" in the main
* directory of this archive for more details.
*
* $Id: sdmixer.c,v 1.1.2.3 2002/04/18 05:47:22 takemura Exp $
*/
#define __NO_VERSION__
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include <linux/soundcard.h>
#include <asm/io.h>
#include <asm/addrspace.h>
#include <asm/uaccess.h>
#include <asm/ps2/sifdefs.h>
#include <asm/ps2/siflock.h>
#include "../sound/sound_config.h"
#include "sd.h"
#include "sdmacro.h"
#include "sdcall.h"
/*
* macro defines
*/
/*
* data types
*/
/*
* function prototypes
*/
static loff_t ps2sdmixer_llseek(struct file *, loff_t, int);
static int ps2sdmixer_open(struct inode *, struct file *);
static int ps2sdmixer_release(struct inode *, struct file *);
static int ps2sdmixer_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
/*
* variables and data
*/
struct file_operations ps2sd_mixer_fops = {
owner: THIS_MODULE,
llseek: ps2sdmixer_llseek,
ioctl: ps2sdmixer_ioctl,
open: ps2sdmixer_open,
release: ps2sdmixer_release,
};
/*
* function bodies
*/
static loff_t
ps2sdmixer_llseek(struct file *filp, loff_t offset, int origin)
{
return -ESPIPE;
}
int
ps2sdmixer_do_ioctl(struct ps2sd_mixer_context *mixer,
unsigned int cmd, unsigned long arg)
{
int i, res, val;
/*
* get device driver info
*/
if (cmd == SOUND_MIXER_INFO) {
mixer_info info;
strncpy(info.id, "PS2SPU", sizeof(info.id));
strncpy(info.name, "PS2 Sound Processing Unit",
sizeof(info.name));
info.modify_counter = mixer->modified;
if (copy_to_user((void *)arg, &info, sizeof(info)))
return -EFAULT;
return 0;
}
if (cmd == SOUND_OLD_MIXER_INFO) {
_old_mixer_info info;
strncpy(info.id, "PS2SPU", sizeof(info.id));
strncpy(info.name, "PS2 Sound Processing Unit",
sizeof(info.name));
if (copy_to_user((void *)arg, &info, sizeof(info)))
return -EFAULT;
return 0;
}
if (cmd == OSS_GETVERSION)
return put_user(SOUND_VERSION, (int *)arg);
if (_IOC_TYPE(cmd) != 'M' || _IOC_SIZE(cmd) != sizeof(int))
return -EINVAL;
/*
* get channel info
*/
if (_IOC_DIR(cmd) == _IOC_READ) {
switch (_IOC_NR(cmd)) {
case SOUND_MIXER_RECSRC:
/* SPU2 have no recording source */
return put_user(0, (int *)arg);
case SOUND_MIXER_DEVMASK:
/* supported devices */
return put_user(mixer->devmask, (int *)arg);
case SOUND_MIXER_RECMASK:
/* SPU2 have no recording input */
return put_user(0, (int *)arg);
case SOUND_MIXER_STEREODEVS:
/* Mixer channels supporting stereo */
return put_user(mixer->devmask, (int *)arg);
case SOUND_MIXER_CAPS:
return put_user(0, (int *)arg);
default:
/* get current volume */
i = _IOC_NR(cmd);
if (SOUND_MIXER_NRDEVICES <= i ||
mixer->channels[i] == NULL)
return -EINVAL;
return put_user(mixer->channels[i]->vol, (int *)arg);
}
}
if (_IOC_DIR(cmd) != (_IOC_READ|_IOC_WRITE))
return -EINVAL;
/*
* set channel info
*/
switch (_IOC_NR(cmd)) {
case SOUND_MIXER_RECSRC:
/* SPU2 have no recording source */
return 0;
default:
i = _IOC_NR(cmd);
if (SOUND_MIXER_NRDEVICES <= i ||
mixer->channels[i] == NULL)
return -EINVAL;
if (get_user(val, (int *)arg))
return (-EFAULT);
res = ps2sdmixer_setvol(mixer->channels[i],
(val >> 8) & 0xff, val & 0xff);
if (res < 0) return res;
return put_user(mixer->channels[i]->vol, (int *)arg);
}
}
static int
ps2sdmixer_open(struct inode *inode, struct file *filp)
{
int minor = MINOR(inode->i_rdev);
struct ps2sd_mixer_context *mixer;
DPRINT(DBG_INFO, "open: inode->i_rdev=0x%04x\n", inode->i_rdev);
mixer = ps2sd_lookup_mixer(minor);
if (mixer == NULL) return -ENODEV;
filp->private_data = mixer;
return 0;
}
static int
ps2sdmixer_release(struct inode *inode, struct file *filp)
{
return 0;
}
static int
ps2sdmixer_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long arg)
{
struct ps2sd_mixer_context *mixer;
mixer = (struct ps2sd_mixer_context *)filp->private_data;
return ps2sdmixer_do_ioctl(mixer, cmd, arg);
}
int
ps2sdmixer_setvol(struct ps2sd_mixer_channel *ch, int volr, int voll)
{
int res;
if (volr < 0) volr = 0;
if (100 < volr) volr = 100;
if (voll < 0) voll = 0;
if (100 < voll) voll = 100;
if (ch->mixer != NULL)
ch->mixer->modified++;
ch->volr = volr;
ch->voll = voll;
ch->vol = (volr << 8) | voll;
volr = volr * ch->scale / 100;
voll = voll * ch->scale / 100;
DPRINT(DBG_MIXER, "%14s R=%04x/L=%04x\n", ch->name, volr, voll);
res = ps2sif_lock_interruptible(ps2sd_mc.lock, "mixer volume");
if (res < 0)
return res;
if (ch->regr != -1) {
res = ps2sdcall_set_reg(ch->regr, volr);
if (res < 0) {
DPRINT(DBG_DIAG, "%s R=%04x/L=%04x: failed, res=%d\n",
ch->name, volr, voll, res);
goto unlock_and_return;
}
}
if (ch->regl != -1) {
res = ps2sdcall_set_reg(ch->regl, voll);
if (res < 0) {
DPRINT(DBG_DIAG, "%s R=%04x/L=%04x: failed, res=%d\n",
ch->name, volr, voll, res);
goto unlock_and_return;
}
}
unlock_and_return:
ps2sif_unlock(ps2sd_mc.lock);
return res;
}