2 * admtek pegasus driver copy-pasted from bill paul's
3 * openbsd/freebsd aue(4) driver, with help
4 * from the datasheet and petko manolov's linux
5 * drivers/net/usb/pegasus.c driver
21 C0stopbackoff = 1 << 2,
22 C0rxstatappend = 1 << 3,
40 C2eepromwren = 1 << 4,
41 C2eepromload = 1 << 5,
76 static int csr8r(Dev *, int);
77 static int csr16r(Dev *, int);
78 static int csr8w(Dev *, int, int);
79 static int eeprom16r(Dev *, int);
80 static void reset(Dev *);
83 csr8r(Dev *d, int reg)
88 rc = usbcmd(d, Rd2h|Rvendor|Rdev, Readreg,
89 0, reg, &v, sizeof v);
91 fprint(2, "%s: csr8r(%#x): %r\n",
99 csr16r(Dev *d, int reg)
104 rc = usbcmd(d, Rd2h|Rvendor|Rdev, Readreg,
105 0, reg, v, sizeof v);
107 fprint(2, "%s: csr16r(%#x): %r\n",
115 csr8w(Dev *d, int reg, int val)
121 rc = usbcmd(d, Rh2d|Rvendor|Rdev, Writereg,
122 val&0xff, reg, &v, sizeof v);
124 fprint(2, "%s: csr8w(%#x, %#x): %r\n",
131 eeprom16r(Dev *d, int off)
135 csr8w(d, Eereg, off);
136 csr8w(d, Eectl, Eectlrd);
137 for(i = 0; i < Timeout; i++) {
138 if(csr8r(d, Eectl) & Eectldn)
142 fprint(2, "%s: EEPROM read timed out\n",
145 return csr16r(d, Eedata);
153 csr8w(d, Ctl1, csr8r(d, Ctl1)|C1resetmac);
154 for(i = 0; i < Timeout; i++) {
155 if(!(csr8r(d, Ctl1) & C1resetmac))
159 fprint(2, "%s: reset failed\n", argv0);
160 csr8w(d, Gpio0, Gpiosel0|Gpiosel1);
161 csr8w(d, Gpio0, Gpiosel0|Gpiosel1|Gpioout0);
172 b = allocb(Maxpkt+4);
173 if((n = read(ep->dfd, b->wp, b->lim - b->base)) < 0){
184 if((hd & Rxerror) != 0 || n > BLEN(b)){
194 auetransmit(Dev *ep, Block *b)
201 write(ep->dfd, b->rp, BLEN(b));
212 for(i = 0, p = macaddr; i < 3; i++, p += 2) {
216 for(i = 0; i < sizeof macaddr; i++)
217 csr8w(d, Par+i, macaddr[i]);
218 csr8w(d, Ctl2, csr8r(d, Ctl2)&~C2prom);
219 csr8w(d, Ctl0, C0rxstatappend|C0rxen);
220 csr8w(d, Ctl0, csr8r(d, Ctl0)|C0txen);
221 csr8w(d, Ctl2, csr8r(d, Ctl2)|C2ep3clr);
222 epreceive = auereceive;
223 eptransmit = auetransmit;