This source file includes following definitions.
- we_getconf
- we_setconf
- we_open
- we_close
- we_ioctl
- we8003_init
1
2
3
4
5
6
7
8 #include <linux/config.h>
9 #include <linux/kernel.h>
10 #include <linux/sched.h>
11 #include <linux/fs.h>
12 #include <linux/tty.h>
13 #include <linux/types.h>
14 #include <linux/ptrace.h>
15 #include <linux/string.h>
16 #include <linux/ddi.h>
17 #include <asm/system.h>
18 #include <asm/segment.h>
19 #include <asm/io.h>
20 #include <errno.h>
21 #include <linux/fcntl.h>
22 #include <netinet/in.h>
23 #include "we8003.h"
24
25
26 #define VERSION "1.0.0"
27
28
29 struct ddi_device *we_ptrs[NR_WE8003];
30
31
32 static int
33 we_getconf(struct ddi_device *dev, struct ddconf *cp)
34 {
35 cp->ioaddr = dev->config.ioaddr;
36 cp->ioaux = 0;
37 cp->irq = dev->config.irq;
38 cp->dma = 0;
39 cp->memaddr = dev->config.memaddr;
40 cp->memsize = dev->config.memsize;
41 return(0);
42 }
43
44
45 static int
46 we_setconf(struct ddi_device *dev, struct ddconf *cp)
47 {
48 dev->config.ioaddr = cp->ioaddr;
49 dev->config.irq = cp->irq;
50 dev->config.memaddr = cp->memaddr;
51 dev->config.memsize = cp->memsize;
52 PRINTK (("%s: IO=0x%X IRQ=%d MEM=0x%X(%d)\n",
53 dev->name, dev->config.ioaddr, dev->config.irq,
54 dev->config.memaddr, dev->config.memsize));
55
56
57
58 return(0);
59 }
60
61
62 static int
63 we_open(struct inode * inode, struct file * file)
64 {
65 int minor;
66 struct ddi_device *dev;
67
68 minor = MINOR(inode->i_rdev);
69 if (minor < 0 || minor >= NR_WE8003) return(-ENODEV);
70 dev = we_ptrs[minor];
71 if (dev == NULL || (dev->flags & DDI_FREADY) == 0) return(-ENODEV);
72
73 return(0);
74 }
75
76
77 static void
78 we_close(struct inode * inode, struct file * file)
79 {
80 int minor;
81 struct ddi_device *dev;
82
83 minor = MINOR(inode->i_rdev);
84 if (minor < 0 || minor >= NR_WE8003) return;
85 dev = we_ptrs[minor];
86 if (dev == NULL || (dev->flags & DDI_FREADY) == 0) return;
87 }
88
89
90 static int
91 we_ioctl(struct inode *inode, struct file *file,
92 unsigned int cmd, unsigned long arg)
93 {
94 int minor, ret;
95 struct ddi_device *dev;
96 struct ddconf conf;
97
98 minor = MINOR(inode->i_rdev);
99 if (minor < 0 || minor >= NR_WE8003) return(-ENODEV);
100 dev = we_ptrs[minor];
101 if (dev == NULL || (dev->flags & DDI_FREADY) == 0) return(-ENODEV);
102
103 ret = -EINVAL;
104 switch(cmd) {
105 case DDIOCGNAME:
106 memcpy_tofs((void *)arg, dev->name, DDI_MAXNAME);
107 ret = 0;
108 break;
109 case DDIOCGCONF:
110 ret = we_getconf(dev, &conf);
111 memcpy_tofs((void *)arg, &conf, sizeof(conf));
112 break;
113 case DDIOCSCONF:
114 memcpy_fromfs(&conf, (void *)arg, sizeof(conf));
115 ret = we_setconf(dev, &conf);
116 break;
117 default:
118 break;
119 }
120 return(ret);
121 }
122
123
124 static struct file_operations we_fops = {
125 NULL,
126 NULL,
127 NULL,
128 NULL,
129 NULL,
130 we_ioctl,
131 NULL,
132 we_open,
133 we_close
134 };
135
136
137
138 int
139 we8003_init(struct ddi_device *dev)
140 {
141 static int unit_nr = 0;
142 int i;
143
144
145 if (unit_nr == 0) {
146 for(i = 0; i < NR_WE8003; i++) we_ptrs[i] = NULL;
147 }
148
149
150 we_ptrs[unit_nr] = dev;
151 dev->unit = unit_nr++;
152 sprintf(dev->name, WE_NAME, dev->unit);
153 dev->flags |= DDI_FREADY;
154
155
156 PRINTK (("%s: version %s: ", dev->title, VERSION));
157 (void) we_setconf(dev, &dev->config);
158
159
160 if (dev->major != 0) {
161 if (dev->flags & DDI_FBLKDEV) {
162 if (register_blkdev(dev->major, "WE8003", &we_fops) < 0) {
163 printk("%s: cannot register block device %d!\n",
164 dev->name, dev->major);
165 return(-EINVAL);
166 }
167 }
168 if (dev->flags & DDI_FCHRDEV) {
169 if (register_chrdev(dev->major, "WE8003", &we_fops) < 0) {
170 printk("%s: cannot register character device %d!\n",
171 dev->name, dev->major);
172 return(-EINVAL);
173 }
174 }
175 }
176
177
178 return(0);
179 }