ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / um / drivers / hostaudio_user.c
1 /* 
2  * Copyright (C) 2002 Steve Schmidtke 
3  * Licensed under the GPL
4  */
5
6 #include <sys/types.h>
7 #include <sys/stat.h>
8 #include <sys/ioctl.h>
9 #include <fcntl.h>
10 #include <unistd.h>
11 #include <errno.h>
12 #include "hostaudio.h"
13 #include "user_util.h"
14 #include "kern_util.h"
15 #include "user.h"
16 #include "os.h"
17
18 /* /dev/dsp file operations */
19
20 ssize_t hostaudio_read_user(struct hostaudio_state *state, char *buffer, 
21                             size_t count, loff_t *ppos)
22 {
23         ssize_t ret;
24
25 #ifdef DEBUG
26         printk("hostaudio: read_user called, count = %d\n", count);
27 #endif
28
29         ret = read(state->fd, buffer, count);
30
31         if(ret < 0) return(-errno);
32         return(ret);
33 }
34
35 ssize_t hostaudio_write_user(struct hostaudio_state *state, const char *buffer,
36                              size_t count, loff_t *ppos)
37 {
38         ssize_t ret;
39
40 #ifdef DEBUG
41         printk("hostaudio: write_user called, count = %d\n", count);
42 #endif
43
44         ret = write(state->fd, buffer, count);
45
46         if(ret < 0) return(-errno);
47         return(ret);
48 }
49
50 int hostaudio_ioctl_user(struct hostaudio_state *state, unsigned int cmd, 
51                          unsigned long arg)
52 {
53         int ret;
54 #ifdef DEBUG
55         printk("hostaudio: ioctl_user called, cmd = %u\n", cmd);
56 #endif
57
58         ret = ioctl(state->fd, cmd, arg);
59         
60         if(ret < 0) return(-errno);
61         return(ret);
62 }
63
64 int hostaudio_open_user(struct hostaudio_state *state, int r, int w, char *dsp)
65 {
66 #ifdef DEBUG
67         printk("hostaudio: open_user called\n");
68 #endif
69
70         state->fd = os_open_file(dsp, of_set_rw(OPENFLAGS(), r, w), 0);
71
72         if(state->fd >= 0) return(0);
73
74         printk("hostaudio_open_user failed to open '%s', errno = %d\n",
75                dsp, errno);
76         
77         return(-errno); 
78 }
79
80 int hostaudio_release_user(struct hostaudio_state *state)
81 {
82 #ifdef DEBUG
83         printk("hostaudio: release called\n");
84 #endif
85         if(state->fd >= 0){
86                 close(state->fd);
87                 state->fd=-1;
88         }
89
90         return(0);
91 }
92
93 /* /dev/mixer file operations */
94
95 int hostmixer_ioctl_mixdev_user(struct hostmixer_state *state, 
96                                 unsigned int cmd, unsigned long arg)
97 {
98         int ret;
99 #ifdef DEBUG
100         printk("hostmixer: ioctl_user called cmd = %u\n",cmd);
101 #endif
102
103         ret = ioctl(state->fd, cmd, arg);
104         if(ret < 0) 
105                 return(-errno);
106         return(ret);
107 }
108
109 int hostmixer_open_mixdev_user(struct hostmixer_state *state, int r, int w,
110                                char *mixer)
111 {
112 #ifdef DEBUG
113         printk("hostmixer: open_user called\n");
114 #endif
115
116         state->fd = os_open_file(mixer, of_set_rw(OPENFLAGS(), r, w), 0);
117
118         if(state->fd >= 0) return(0);
119
120         printk("hostaudio_open_mixdev_user failed to open '%s', errno = %d\n",
121                mixer, errno);
122         
123         return(-errno); 
124 }
125
126 int hostmixer_release_mixdev_user(struct hostmixer_state *state)
127 {
128 #ifdef DEBUG
129         printk("hostmixer: release_user called\n");
130 #endif
131
132         if(state->fd >= 0){
133                 close(state->fd);
134                 state->fd = -1;
135         }
136
137         return 0;
138 }
139
140 /*
141  * Overrides for Emacs so that we follow Linus's tabbing style.
142  * Emacs will notice this stuff at the end of the file and automatically
143  * adjust the settings for this buffer only.  This must remain at the end
144  * of the file.
145  * ---------------------------------------------------------------------------
146  * Local variables:
147  * c-file-style: "linux"
148  * End:
149  */