1/*- 2 * Copyright (c) 1997 Nicolas Souchu 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * 27 */ 28 29#include <sys/cdefs.h>
| 1/*- 2 * Copyright (c) 1997 Nicolas Souchu 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 * 26 * 27 */ 28 29#include <sys/cdefs.h>
|
30__FBSDID("$FreeBSD: head/sys/dev/ppbus/ppb_1284.c 119418 2003-08-24 17:55:58Z obrien $");
| 30__FBSDID("$FreeBSD: head/sys/dev/ppbus/ppb_1284.c 185003 2008-11-16 17:42:02Z jhb $");
|
31 32/* 33 * General purpose routines for the IEEE1284-1994 Standard 34 */ 35 36#include "opt_ppb_1284.h" 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/bus.h> 41 42 43#include <dev/ppbus/ppbconf.h> 44#include <dev/ppbus/ppb_1284.h> 45 46#include "ppbus_if.h" 47 48#include <dev/ppbus/ppbio.h> 49 50#define DEVTOSOFTC(dev) ((struct ppb_data *)device_get_softc(dev)) 51 52/* 53 * do_1284_wait() 54 * 55 * Wait for the peripherial up to 40ms 56 */ 57static int 58do_1284_wait(device_t bus, char mask, char status) 59{ 60 return (ppb_poll_bus(bus, 4, mask, status, PPB_NOINTR | PPB_POLL)); 61} 62 63static int 64do_peripheral_wait(device_t bus, char mask, char status) 65{ 66 return (ppb_poll_bus(bus, 100, mask, status, PPB_NOINTR | PPB_POLL)); 67} 68 69#define nibble2char(s) (((s & ~nACK) >> 3) | (~s & nBUSY) >> 4) 70 71/* 72 * ppb_1284_reset_error() 73 * 74 * Unconditionaly reset the error field 75 */ 76static int 77ppb_1284_reset_error(device_t bus, int state) 78{ 79 struct ppb_data *ppb = DEVTOSOFTC(bus); 80 81 ppb->error = PPB_NO_ERROR; 82 ppb->state = state; 83 84 return (0); 85} 86 87/* 88 * ppb_1284_get_state() 89 * 90 * Get IEEE1284 state 91 */ 92int 93ppb_1284_get_state(device_t bus) 94{
| 31 32/* 33 * General purpose routines for the IEEE1284-1994 Standard 34 */ 35 36#include "opt_ppb_1284.h" 37 38#include <sys/param.h> 39#include <sys/systm.h> 40#include <sys/bus.h> 41 42 43#include <dev/ppbus/ppbconf.h> 44#include <dev/ppbus/ppb_1284.h> 45 46#include "ppbus_if.h" 47 48#include <dev/ppbus/ppbio.h> 49 50#define DEVTOSOFTC(dev) ((struct ppb_data *)device_get_softc(dev)) 51 52/* 53 * do_1284_wait() 54 * 55 * Wait for the peripherial up to 40ms 56 */ 57static int 58do_1284_wait(device_t bus, char mask, char status) 59{ 60 return (ppb_poll_bus(bus, 4, mask, status, PPB_NOINTR | PPB_POLL)); 61} 62 63static int 64do_peripheral_wait(device_t bus, char mask, char status) 65{ 66 return (ppb_poll_bus(bus, 100, mask, status, PPB_NOINTR | PPB_POLL)); 67} 68 69#define nibble2char(s) (((s & ~nACK) >> 3) | (~s & nBUSY) >> 4) 70 71/* 72 * ppb_1284_reset_error() 73 * 74 * Unconditionaly reset the error field 75 */ 76static int 77ppb_1284_reset_error(device_t bus, int state) 78{ 79 struct ppb_data *ppb = DEVTOSOFTC(bus); 80 81 ppb->error = PPB_NO_ERROR; 82 ppb->state = state; 83 84 return (0); 85} 86 87/* 88 * ppb_1284_get_state() 89 * 90 * Get IEEE1284 state 91 */ 92int 93ppb_1284_get_state(device_t bus) 94{
|
95 return (DEVTOSOFTC(bus)->state);
| 95 96 return (DEVTOSOFTC(bus)->state);
|
96} 97 98/* 99 * ppb_1284_set_state() 100 * 101 * Change IEEE1284 state if no error occured 102 */ 103int 104ppb_1284_set_state(device_t bus, int state) 105{ 106 struct ppb_data *ppb = DEVTOSOFTC(bus); 107 108 /* call ppb_1284_reset_error() if you absolutly want to change 109 * the state from PPB_ERROR to another */ 110 if ((ppb->state != PPB_ERROR) && 111 (ppb->error == PPB_NO_ERROR)) { 112 ppb->state = state; 113 ppb->error = PPB_NO_ERROR; 114 } 115 116 return (0); 117} 118 119static int 120ppb_1284_set_error(device_t bus, int error, int event) 121{ 122 struct ppb_data *ppb = DEVTOSOFTC(bus); 123 124 /* do not accumulate errors */ 125 if ((ppb->error == PPB_NO_ERROR) && 126 (ppb->state != PPB_ERROR)) { 127 ppb->error = error; 128 ppb->state = PPB_ERROR; 129 } 130 131#ifdef DEBUG_1284 132 printf("ppb1284: error=%d status=0x%x event=%d\n", error, 133 ppb_rstr(bus) & 0xff, event); 134#endif 135 136 return (0); 137} 138 139/* 140 * ppb_request_mode() 141 * 142 * Converts mode+options into ext. value 143 */ 144static int 145ppb_request_mode(int mode, int options) 146{ 147 int request_mode = 0; 148 149 if (options & PPB_EXTENSIBILITY_LINK) { 150 request_mode = EXT_LINK_1284_NORMAL; 151 152 } else { 153 switch (mode) { 154 case PPB_NIBBLE: 155 request_mode = (options & PPB_REQUEST_ID) ? 156 NIBBLE_1284_REQUEST_ID : 157 NIBBLE_1284_NORMAL; 158 break; 159 case PPB_PS2: 160 request_mode = (options & PPB_REQUEST_ID) ? 161 BYTE_1284_REQUEST_ID : 162 BYTE_1284_NORMAL; 163 break; 164 case PPB_ECP: 165 if (options & PPB_USE_RLE) 166 request_mode = (options & PPB_REQUEST_ID) ? 167 ECP_1284_RLE_REQUEST_ID : 168 ECP_1284_RLE; 169 else 170 request_mode = (options & PPB_REQUEST_ID) ? 171 ECP_1284_REQUEST_ID : 172 ECP_1284_NORMAL; 173 break; 174 case PPB_EPP: 175 request_mode = EPP_1284_NORMAL; 176 break; 177 default: 178 panic("%s: unsupported mode %d\n", __func__, mode); 179 } 180 } 181 182 return (request_mode); 183} 184 185/* 186 * ppb_peripheral_negociate() 187 * 188 * Negociate the peripheral side 189 */ 190int 191ppb_peripheral_negociate(device_t bus, int mode, int options) 192{ 193 int spin, request_mode, error = 0; 194 char r; 195 196 ppb_set_mode(bus, PPB_COMPATIBLE); 197 ppb_1284_set_state(bus, PPB_PERIPHERAL_NEGOCIATION); 198 199 /* compute ext. value */ 200 request_mode = ppb_request_mode(mode, options); 201 202 /* wait host */ 203 spin = 10; 204 while (spin-- && (ppb_rstr(bus) & nBUSY)) 205 DELAY(1); 206 207 /* check termination */ 208 if (!(ppb_rstr(bus) & SELECT) || !spin) { 209 error = ENODEV; 210 goto error; 211 } 212 213 /* Event 4 - read ext. value */ 214 r = ppb_rdtr(bus); 215 216 /* nibble mode is not supported */ 217 if ((r == (char)request_mode) || 218 (r == NIBBLE_1284_NORMAL)) { 219 220 /* Event 5 - restore direction bit, no data avail */ 221 ppb_wctr(bus, (STROBE | nINIT) & ~(SELECTIN)); 222 DELAY(1); 223 224 /* Event 6 */ 225 ppb_wctr(bus, (nINIT) & ~(SELECTIN | STROBE)); 226 227 if (r == NIBBLE_1284_NORMAL) { 228#ifdef DEBUG_1284 229 printf("R"); 230#endif 231 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 4); 232 error = EINVAL; 233 goto error; 234 } else { 235 ppb_1284_set_state(bus, PPB_PERIPHERAL_IDLE); 236 switch (r) { 237 case BYTE_1284_NORMAL: 238 ppb_set_mode(bus, PPB_BYTE); 239 break; 240 default: 241 break; 242 } 243#ifdef DEBUG_1284 244 printf("A"); 245#endif 246 /* negociation succeeds */ 247 } 248 } else { 249 /* Event 5 - mode not supported */ 250 ppb_wctr(bus, SELECTIN); 251 DELAY(1); 252 253 /* Event 6 */ 254 ppb_wctr(bus, (SELECTIN) & ~(STROBE | nINIT)); 255 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 4); 256 257#ifdef DEBUG_1284 258 printf("r"); 259#endif 260 error = EINVAL; 261 goto error; 262 } 263 264 return (0); 265 266error: 267 ppb_peripheral_terminate(bus, PPB_WAIT); 268 return (error); 269} 270 271/* 272 * ppb_peripheral_terminate() 273 * 274 * Terminate peripheral transfer side 275 * 276 * Always return 0 in compatible mode 277 */ 278int 279ppb_peripheral_terminate(device_t bus, int how) 280{ 281 int error = 0; 282 283#ifdef DEBUG_1284 284 printf("t"); 285#endif 286 287 ppb_1284_set_state(bus, PPB_PERIPHERAL_TERMINATION); 288 289 /* Event 22 - wait up to host response time (1s) */ 290 if ((error = do_peripheral_wait(bus, SELECT | nBUSY, 0))) { 291 ppb_1284_set_error(bus, PPB_TIMEOUT, 22); 292 goto error; 293 } 294 295 /* Event 24 */
| 97} 98 99/* 100 * ppb_1284_set_state() 101 * 102 * Change IEEE1284 state if no error occured 103 */ 104int 105ppb_1284_set_state(device_t bus, int state) 106{ 107 struct ppb_data *ppb = DEVTOSOFTC(bus); 108 109 /* call ppb_1284_reset_error() if you absolutly want to change 110 * the state from PPB_ERROR to another */ 111 if ((ppb->state != PPB_ERROR) && 112 (ppb->error == PPB_NO_ERROR)) { 113 ppb->state = state; 114 ppb->error = PPB_NO_ERROR; 115 } 116 117 return (0); 118} 119 120static int 121ppb_1284_set_error(device_t bus, int error, int event) 122{ 123 struct ppb_data *ppb = DEVTOSOFTC(bus); 124 125 /* do not accumulate errors */ 126 if ((ppb->error == PPB_NO_ERROR) && 127 (ppb->state != PPB_ERROR)) { 128 ppb->error = error; 129 ppb->state = PPB_ERROR; 130 } 131 132#ifdef DEBUG_1284 133 printf("ppb1284: error=%d status=0x%x event=%d\n", error, 134 ppb_rstr(bus) & 0xff, event); 135#endif 136 137 return (0); 138} 139 140/* 141 * ppb_request_mode() 142 * 143 * Converts mode+options into ext. value 144 */ 145static int 146ppb_request_mode(int mode, int options) 147{ 148 int request_mode = 0; 149 150 if (options & PPB_EXTENSIBILITY_LINK) { 151 request_mode = EXT_LINK_1284_NORMAL; 152 153 } else { 154 switch (mode) { 155 case PPB_NIBBLE: 156 request_mode = (options & PPB_REQUEST_ID) ? 157 NIBBLE_1284_REQUEST_ID : 158 NIBBLE_1284_NORMAL; 159 break; 160 case PPB_PS2: 161 request_mode = (options & PPB_REQUEST_ID) ? 162 BYTE_1284_REQUEST_ID : 163 BYTE_1284_NORMAL; 164 break; 165 case PPB_ECP: 166 if (options & PPB_USE_RLE) 167 request_mode = (options & PPB_REQUEST_ID) ? 168 ECP_1284_RLE_REQUEST_ID : 169 ECP_1284_RLE; 170 else 171 request_mode = (options & PPB_REQUEST_ID) ? 172 ECP_1284_REQUEST_ID : 173 ECP_1284_NORMAL; 174 break; 175 case PPB_EPP: 176 request_mode = EPP_1284_NORMAL; 177 break; 178 default: 179 panic("%s: unsupported mode %d\n", __func__, mode); 180 } 181 } 182 183 return (request_mode); 184} 185 186/* 187 * ppb_peripheral_negociate() 188 * 189 * Negociate the peripheral side 190 */ 191int 192ppb_peripheral_negociate(device_t bus, int mode, int options) 193{ 194 int spin, request_mode, error = 0; 195 char r; 196 197 ppb_set_mode(bus, PPB_COMPATIBLE); 198 ppb_1284_set_state(bus, PPB_PERIPHERAL_NEGOCIATION); 199 200 /* compute ext. value */ 201 request_mode = ppb_request_mode(mode, options); 202 203 /* wait host */ 204 spin = 10; 205 while (spin-- && (ppb_rstr(bus) & nBUSY)) 206 DELAY(1); 207 208 /* check termination */ 209 if (!(ppb_rstr(bus) & SELECT) || !spin) { 210 error = ENODEV; 211 goto error; 212 } 213 214 /* Event 4 - read ext. value */ 215 r = ppb_rdtr(bus); 216 217 /* nibble mode is not supported */ 218 if ((r == (char)request_mode) || 219 (r == NIBBLE_1284_NORMAL)) { 220 221 /* Event 5 - restore direction bit, no data avail */ 222 ppb_wctr(bus, (STROBE | nINIT) & ~(SELECTIN)); 223 DELAY(1); 224 225 /* Event 6 */ 226 ppb_wctr(bus, (nINIT) & ~(SELECTIN | STROBE)); 227 228 if (r == NIBBLE_1284_NORMAL) { 229#ifdef DEBUG_1284 230 printf("R"); 231#endif 232 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 4); 233 error = EINVAL; 234 goto error; 235 } else { 236 ppb_1284_set_state(bus, PPB_PERIPHERAL_IDLE); 237 switch (r) { 238 case BYTE_1284_NORMAL: 239 ppb_set_mode(bus, PPB_BYTE); 240 break; 241 default: 242 break; 243 } 244#ifdef DEBUG_1284 245 printf("A"); 246#endif 247 /* negociation succeeds */ 248 } 249 } else { 250 /* Event 5 - mode not supported */ 251 ppb_wctr(bus, SELECTIN); 252 DELAY(1); 253 254 /* Event 6 */ 255 ppb_wctr(bus, (SELECTIN) & ~(STROBE | nINIT)); 256 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 4); 257 258#ifdef DEBUG_1284 259 printf("r"); 260#endif 261 error = EINVAL; 262 goto error; 263 } 264 265 return (0); 266 267error: 268 ppb_peripheral_terminate(bus, PPB_WAIT); 269 return (error); 270} 271 272/* 273 * ppb_peripheral_terminate() 274 * 275 * Terminate peripheral transfer side 276 * 277 * Always return 0 in compatible mode 278 */ 279int 280ppb_peripheral_terminate(device_t bus, int how) 281{ 282 int error = 0; 283 284#ifdef DEBUG_1284 285 printf("t"); 286#endif 287 288 ppb_1284_set_state(bus, PPB_PERIPHERAL_TERMINATION); 289 290 /* Event 22 - wait up to host response time (1s) */ 291 if ((error = do_peripheral_wait(bus, SELECT | nBUSY, 0))) { 292 ppb_1284_set_error(bus, PPB_TIMEOUT, 22); 293 goto error; 294 } 295 296 /* Event 24 */
|
296 ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
| 297 ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN));
|
297 298 /* Event 25 - wait up to host response time (1s) */ 299 if ((error = do_peripheral_wait(bus, nBUSY, nBUSY))) { 300 ppb_1284_set_error(bus, PPB_TIMEOUT, 25); 301 goto error; 302 } 303 304 /* Event 26 */
| 298 299 /* Event 25 - wait up to host response time (1s) */ 300 if ((error = do_peripheral_wait(bus, nBUSY, nBUSY))) { 301 ppb_1284_set_error(bus, PPB_TIMEOUT, 25); 302 goto error; 303 } 304 305 /* Event 26 */
|
305 ppb_wctr(bus, (SELECTIN | nINIT | STROBE) & ~(AUTOFEED));
| 306 ppb_wctr(bus, (SELECTIN | nINIT | STROBE) & ~(AUTOFEED));
|
306 DELAY(1); 307 /* Event 27 */
| 307 DELAY(1); 308 /* Event 27 */
|
308 ppb_wctr(bus, (SELECTIN | nINIT) & ~(STROBE | AUTOFEED));
| 309 ppb_wctr(bus, (SELECTIN | nINIT) & ~(STROBE | AUTOFEED));
|
309 310 /* Event 28 - wait up to host response time (1s) */ 311 if ((error = do_peripheral_wait(bus, nBUSY, 0))) { 312 ppb_1284_set_error(bus, PPB_TIMEOUT, 28); 313 goto error; 314 }
| 310 311 /* Event 28 - wait up to host response time (1s) */ 312 if ((error = do_peripheral_wait(bus, nBUSY, 0))) { 313 ppb_1284_set_error(bus, PPB_TIMEOUT, 28); 314 goto error; 315 }
|
315
| 316
|
316error: 317 ppb_set_mode(bus, PPB_COMPATIBLE); 318 ppb_1284_set_state(bus, PPB_FORWARD_IDLE); 319 320 return (0); 321} 322 323/* 324 * byte_peripheral_outbyte() 325 * 326 * Write 1 byte in BYTE mode 327 */ 328static int 329byte_peripheral_outbyte(device_t bus, char *buffer, int last) 330{ 331 int error = 0; 332 333 /* Event 7 */ 334 if ((error = do_1284_wait(bus, nBUSY, nBUSY))) { 335 ppb_1284_set_error(bus, PPB_TIMEOUT, 7); 336 goto error; 337 } 338 339 /* check termination */ 340 if (!(ppb_rstr(bus) & SELECT)) { 341 ppb_peripheral_terminate(bus, PPB_WAIT); 342 goto error; 343 } 344 345 /* Event 15 - put byte on data lines */ 346#ifdef DEBUG_1284 347 printf("B"); 348#endif 349 ppb_wdtr(bus, *buffer); 350 351 /* Event 9 */ 352 ppb_wctr(bus, (AUTOFEED | STROBE) & ~(nINIT | SELECTIN)); 353 354 /* Event 10 - wait data read */ 355 if ((error = do_peripheral_wait(bus, nBUSY, 0))) { 356 ppb_1284_set_error(bus, PPB_TIMEOUT, 16); 357 goto error; 358 } 359 360 /* Event 11 */ 361 if (!last) { 362 ppb_wctr(bus, (AUTOFEED) & ~(nINIT | STROBE | SELECTIN)); 363 } else { 364 ppb_wctr(bus, (nINIT) & ~(STROBE | SELECTIN | AUTOFEED)); 365 } 366 367#if 0 368 /* Event 16 - wait strobe */ 369 if ((error = do_peripheral_wait(bus, nACK | nBUSY, 0))) { 370 ppb_1284_set_error(bus, PPB_TIMEOUT, 16); 371 goto error; 372 } 373#endif 374 375 /* check termination */ 376 if (!(ppb_rstr(bus) & SELECT)) { 377 ppb_peripheral_terminate(bus, PPB_WAIT); 378 goto error; 379 } 380 381error: 382 return (error); 383} 384 385/* 386 * byte_peripheral_write() 387 * 388 * Write n bytes in BYTE mode 389 */ 390int 391byte_peripheral_write(device_t bus, char *buffer, int len, int *sent) 392{ 393 int error = 0, i; 394 char r; 395 396 ppb_1284_set_state(bus, PPB_PERIPHERAL_TRANSFER); 397 398 /* wait forever, the remote host is master and should initiate 399 * termination 400 */ 401 for (i=0; i<len; i++) { 402 /* force remote nFAULT low to release the remote waiting 403 * process, if any 404 */ 405 r = ppb_rctr(bus); 406 ppb_wctr(bus, r & ~nINIT); 407 408#ifdef DEBUG_1284 409 printf("y"); 410#endif 411 /* Event 7 */ 412 error = ppb_poll_bus(bus, PPB_FOREVER, nBUSY, nBUSY, 413 PPB_INTR); 414 415 if (error && error != EWOULDBLOCK) 416 goto error; 417 418#ifdef DEBUG_1284 419 printf("b"); 420#endif 421 if ((error = byte_peripheral_outbyte(bus, buffer+i, (i == len-1)))) 422 goto error; 423 } 424error: 425 if (!error) 426 ppb_1284_set_state(bus, PPB_PERIPHERAL_IDLE); 427 428 *sent = i; 429 return (error); 430} 431 432/* 433 * byte_1284_inbyte() 434 * 435 * Read 1 byte in BYTE mode 436 */ 437int 438byte_1284_inbyte(device_t bus, char *buffer) 439{ 440 int error = 0; 441 442 /* Event 7 - ready to take data (nAUTO low) */ 443 ppb_wctr(bus, (PCD | nINIT | AUTOFEED) & ~(STROBE | SELECTIN)); 444 445 /* Event 9 - peripheral set nAck low */ 446 if ((error = do_1284_wait(bus, nACK, 0))) { 447 ppb_1284_set_error(bus, PPB_TIMEOUT, 9); 448 goto error; 449 } 450 451 /* read the byte */ 452 *buffer = ppb_rdtr(bus); 453 454 /* Event 10 - data received, can't accept more */ 455 ppb_wctr(bus, (nINIT) & ~(AUTOFEED | STROBE | SELECTIN)); 456 457 /* Event 11 - peripheral ack */ 458 if ((error = do_1284_wait(bus, nACK, nACK))) { 459 ppb_1284_set_error(bus, PPB_TIMEOUT, 11); 460 goto error; 461 } 462 463 /* Event 16 - strobe */ 464 ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN)); 465 DELAY(3); 466 ppb_wctr(bus, (nINIT) & ~(AUTOFEED | STROBE | SELECTIN)); 467 468error: 469 return (error); 470} 471 472/* 473 * nibble_1284_inbyte() 474 * 475 * Read 1 byte in NIBBLE mode 476 */ 477int 478nibble_1284_inbyte(device_t bus, char *buffer) 479{ 480 char nibble[2]; 481 int i, error; 482 483 for (i = 0; i < 2; i++) { 484 485 /* Event 7 - ready to take data (nAUTO low) */ 486 ppb_wctr(bus, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN)); 487 488 /* Event 8 - peripheral writes the first nibble */ 489 490 /* Event 9 - peripheral set nAck low */ 491 if ((error = do_1284_wait(bus, nACK, 0))) { 492 ppb_1284_set_error(bus, PPB_TIMEOUT, 9); 493 goto error; 494 } 495 496 /* read nibble */ 497 nibble[i] = ppb_rstr(bus); 498 499 /* Event 10 - ack, nibble received */ 500 ppb_wctr(bus, nINIT & ~(AUTOFEED | STROBE | SELECTIN)); 501 502 /* Event 11 - wait ack from peripherial */ 503 if ((error = do_1284_wait(bus, nACK, nACK))) { 504 ppb_1284_set_error(bus, PPB_TIMEOUT, 11); 505 goto error; 506 } 507 } 508 509 *buffer = ((nibble2char(nibble[1]) << 4) & 0xf0) | 510 (nibble2char(nibble[0]) & 0x0f); 511 512error: 513 return (error); 514} 515 516/* 517 * spp_1284_read() 518 * 519 * Read in IEEE1284 NIBBLE/BYTE mode 520 */ 521int 522spp_1284_read(device_t bus, int mode, char *buffer, int max, int *read) 523{ 524 int error = 0, len = 0; 525 int terminate_after_transfer = 1; 526 int state; 527 528 *read = len = 0; 529 530 state = ppb_1284_get_state(bus); 531 532 switch (state) { 533 case PPB_FORWARD_IDLE: 534 if ((error = ppb_1284_negociate(bus, mode, 0))) 535 return (error); 536 break; 537 538 case PPB_REVERSE_IDLE: 539 terminate_after_transfer = 0; 540 break;
| 317error: 318 ppb_set_mode(bus, PPB_COMPATIBLE); 319 ppb_1284_set_state(bus, PPB_FORWARD_IDLE); 320 321 return (0); 322} 323 324/* 325 * byte_peripheral_outbyte() 326 * 327 * Write 1 byte in BYTE mode 328 */ 329static int 330byte_peripheral_outbyte(device_t bus, char *buffer, int last) 331{ 332 int error = 0; 333 334 /* Event 7 */ 335 if ((error = do_1284_wait(bus, nBUSY, nBUSY))) { 336 ppb_1284_set_error(bus, PPB_TIMEOUT, 7); 337 goto error; 338 } 339 340 /* check termination */ 341 if (!(ppb_rstr(bus) & SELECT)) { 342 ppb_peripheral_terminate(bus, PPB_WAIT); 343 goto error; 344 } 345 346 /* Event 15 - put byte on data lines */ 347#ifdef DEBUG_1284 348 printf("B"); 349#endif 350 ppb_wdtr(bus, *buffer); 351 352 /* Event 9 */ 353 ppb_wctr(bus, (AUTOFEED | STROBE) & ~(nINIT | SELECTIN)); 354 355 /* Event 10 - wait data read */ 356 if ((error = do_peripheral_wait(bus, nBUSY, 0))) { 357 ppb_1284_set_error(bus, PPB_TIMEOUT, 16); 358 goto error; 359 } 360 361 /* Event 11 */ 362 if (!last) { 363 ppb_wctr(bus, (AUTOFEED) & ~(nINIT | STROBE | SELECTIN)); 364 } else { 365 ppb_wctr(bus, (nINIT) & ~(STROBE | SELECTIN | AUTOFEED)); 366 } 367 368#if 0 369 /* Event 16 - wait strobe */ 370 if ((error = do_peripheral_wait(bus, nACK | nBUSY, 0))) { 371 ppb_1284_set_error(bus, PPB_TIMEOUT, 16); 372 goto error; 373 } 374#endif 375 376 /* check termination */ 377 if (!(ppb_rstr(bus) & SELECT)) { 378 ppb_peripheral_terminate(bus, PPB_WAIT); 379 goto error; 380 } 381 382error: 383 return (error); 384} 385 386/* 387 * byte_peripheral_write() 388 * 389 * Write n bytes in BYTE mode 390 */ 391int 392byte_peripheral_write(device_t bus, char *buffer, int len, int *sent) 393{ 394 int error = 0, i; 395 char r; 396 397 ppb_1284_set_state(bus, PPB_PERIPHERAL_TRANSFER); 398 399 /* wait forever, the remote host is master and should initiate 400 * termination 401 */ 402 for (i=0; i<len; i++) { 403 /* force remote nFAULT low to release the remote waiting 404 * process, if any 405 */ 406 r = ppb_rctr(bus); 407 ppb_wctr(bus, r & ~nINIT); 408 409#ifdef DEBUG_1284 410 printf("y"); 411#endif 412 /* Event 7 */ 413 error = ppb_poll_bus(bus, PPB_FOREVER, nBUSY, nBUSY, 414 PPB_INTR); 415 416 if (error && error != EWOULDBLOCK) 417 goto error; 418 419#ifdef DEBUG_1284 420 printf("b"); 421#endif 422 if ((error = byte_peripheral_outbyte(bus, buffer+i, (i == len-1)))) 423 goto error; 424 } 425error: 426 if (!error) 427 ppb_1284_set_state(bus, PPB_PERIPHERAL_IDLE); 428 429 *sent = i; 430 return (error); 431} 432 433/* 434 * byte_1284_inbyte() 435 * 436 * Read 1 byte in BYTE mode 437 */ 438int 439byte_1284_inbyte(device_t bus, char *buffer) 440{ 441 int error = 0; 442 443 /* Event 7 - ready to take data (nAUTO low) */ 444 ppb_wctr(bus, (PCD | nINIT | AUTOFEED) & ~(STROBE | SELECTIN)); 445 446 /* Event 9 - peripheral set nAck low */ 447 if ((error = do_1284_wait(bus, nACK, 0))) { 448 ppb_1284_set_error(bus, PPB_TIMEOUT, 9); 449 goto error; 450 } 451 452 /* read the byte */ 453 *buffer = ppb_rdtr(bus); 454 455 /* Event 10 - data received, can't accept more */ 456 ppb_wctr(bus, (nINIT) & ~(AUTOFEED | STROBE | SELECTIN)); 457 458 /* Event 11 - peripheral ack */ 459 if ((error = do_1284_wait(bus, nACK, nACK))) { 460 ppb_1284_set_error(bus, PPB_TIMEOUT, 11); 461 goto error; 462 } 463 464 /* Event 16 - strobe */ 465 ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN)); 466 DELAY(3); 467 ppb_wctr(bus, (nINIT) & ~(AUTOFEED | STROBE | SELECTIN)); 468 469error: 470 return (error); 471} 472 473/* 474 * nibble_1284_inbyte() 475 * 476 * Read 1 byte in NIBBLE mode 477 */ 478int 479nibble_1284_inbyte(device_t bus, char *buffer) 480{ 481 char nibble[2]; 482 int i, error; 483 484 for (i = 0; i < 2; i++) { 485 486 /* Event 7 - ready to take data (nAUTO low) */ 487 ppb_wctr(bus, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN)); 488 489 /* Event 8 - peripheral writes the first nibble */ 490 491 /* Event 9 - peripheral set nAck low */ 492 if ((error = do_1284_wait(bus, nACK, 0))) { 493 ppb_1284_set_error(bus, PPB_TIMEOUT, 9); 494 goto error; 495 } 496 497 /* read nibble */ 498 nibble[i] = ppb_rstr(bus); 499 500 /* Event 10 - ack, nibble received */ 501 ppb_wctr(bus, nINIT & ~(AUTOFEED | STROBE | SELECTIN)); 502 503 /* Event 11 - wait ack from peripherial */ 504 if ((error = do_1284_wait(bus, nACK, nACK))) { 505 ppb_1284_set_error(bus, PPB_TIMEOUT, 11); 506 goto error; 507 } 508 } 509 510 *buffer = ((nibble2char(nibble[1]) << 4) & 0xf0) | 511 (nibble2char(nibble[0]) & 0x0f); 512 513error: 514 return (error); 515} 516 517/* 518 * spp_1284_read() 519 * 520 * Read in IEEE1284 NIBBLE/BYTE mode 521 */ 522int 523spp_1284_read(device_t bus, int mode, char *buffer, int max, int *read) 524{ 525 int error = 0, len = 0; 526 int terminate_after_transfer = 1; 527 int state; 528 529 *read = len = 0; 530 531 state = ppb_1284_get_state(bus); 532 533 switch (state) { 534 case PPB_FORWARD_IDLE: 535 if ((error = ppb_1284_negociate(bus, mode, 0))) 536 return (error); 537 break; 538 539 case PPB_REVERSE_IDLE: 540 terminate_after_transfer = 0; 541 break;
|
541
| 542
|
542 default: 543 ppb_1284_terminate(bus); 544 if ((error = ppb_1284_negociate(bus, mode, 0))) 545 return (error); 546 break; 547 } 548 549 while ((len < max) && !(ppb_rstr(bus) & (nFAULT))) { 550 551 ppb_1284_set_state(bus, PPB_REVERSE_TRANSFER); 552 553#ifdef DEBUG_1284 554 printf("B"); 555#endif 556 557 switch (mode) { 558 case PPB_NIBBLE: 559 /* read a byte, error means no more data */ 560 if (nibble_1284_inbyte(bus, buffer+len)) 561 goto end_while; 562 break; 563 case PPB_BYTE: 564 if (byte_1284_inbyte(bus, buffer+len)) 565 goto end_while; 566 break; 567 default: 568 error = EINVAL; 569 goto end_while; 570 } 571 len ++; 572 } 573end_while: 574 575 if (!error) 576 ppb_1284_set_state(bus, PPB_REVERSE_IDLE); 577 578 *read = len; 579 580 if (terminate_after_transfer || error) 581 ppb_1284_terminate(bus); 582 583 return (error); 584} 585 586/* 587 * ppb_1284_read_id() 588 * 589 */ 590int 591ppb_1284_read_id(device_t bus, int mode, char *buffer, 592 int max, int *read) 593{ 594 int error = 0; 595 596 /* fill the buffer with 0s */ 597 bzero(buffer, max); 598 599 switch (mode) { 600 case PPB_NIBBLE: 601 case PPB_ECP: 602 if ((error = ppb_1284_negociate(bus, PPB_NIBBLE, PPB_REQUEST_ID))) 603 return (error); 604 error = spp_1284_read(bus, PPB_NIBBLE, buffer, max, read); 605 break; 606 case PPB_BYTE: 607 if ((error = ppb_1284_negociate(bus, PPB_BYTE, PPB_REQUEST_ID))) 608 return (error); 609 error = spp_1284_read(bus, PPB_BYTE, buffer, max, read); 610 break; 611 default: 612 panic("%s: unsupported mode %d\n", __func__, mode); 613 } 614 615 ppb_1284_terminate(bus); 616 return (error); 617} 618 619/* 620 * ppb_1284_read() 621 * 622 * IEEE1284 read 623 */ 624int 625ppb_1284_read(device_t bus, int mode, char *buffer, 626 int max, int *read) 627{ 628 int error = 0; 629 630 switch (mode) { 631 case PPB_NIBBLE: 632 case PPB_BYTE: 633 error = spp_1284_read(bus, mode, buffer, max, read); 634 break; 635 default: 636 return (EINVAL); 637 } 638 639 return (error); 640} 641 642/* 643 * ppb_1284_negociate() 644 * 645 * IEEE1284 negociation phase 646 * 647 * Normal nibble mode or request device id mode (see ppb_1284.h) 648 * 649 * After negociation, nFAULT is low if data is available 650 */ 651int 652ppb_1284_negociate(device_t bus, int mode, int options) 653{ 654 int error; 655 int request_mode; 656 657#ifdef DEBUG_1284 658 printf("n"); 659#endif 660 661 if (ppb_1284_get_state(bus) >= PPB_PERIPHERAL_NEGOCIATION) 662 ppb_peripheral_terminate(bus, PPB_WAIT); 663 664 if (ppb_1284_get_state(bus) != PPB_FORWARD_IDLE) 665 ppb_1284_terminate(bus); 666 667#ifdef DEBUG_1284 668 printf("%d", mode); 669#endif 670 671 /* ensure the host is in compatible mode */ 672 ppb_set_mode(bus, PPB_COMPATIBLE); 673 674 /* reset error to catch the actual negociation error */ 675 ppb_1284_reset_error(bus, PPB_FORWARD_IDLE); 676 677 /* calculate ext. value */ 678 request_mode = ppb_request_mode(mode, options); 679 680 /* default state */ 681 ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED)); 682 DELAY(1); 683 684 /* enter negociation phase */ 685 ppb_1284_set_state(bus, PPB_NEGOCIATION); 686 687 /* Event 0 - put the exten. value on the data lines */ 688 ppb_wdtr(bus, request_mode); 689 690#ifdef PERIPH_1284 691 /* request remote host attention */
| 543 default: 544 ppb_1284_terminate(bus); 545 if ((error = ppb_1284_negociate(bus, mode, 0))) 546 return (error); 547 break; 548 } 549 550 while ((len < max) && !(ppb_rstr(bus) & (nFAULT))) { 551 552 ppb_1284_set_state(bus, PPB_REVERSE_TRANSFER); 553 554#ifdef DEBUG_1284 555 printf("B"); 556#endif 557 558 switch (mode) { 559 case PPB_NIBBLE: 560 /* read a byte, error means no more data */ 561 if (nibble_1284_inbyte(bus, buffer+len)) 562 goto end_while; 563 break; 564 case PPB_BYTE: 565 if (byte_1284_inbyte(bus, buffer+len)) 566 goto end_while; 567 break; 568 default: 569 error = EINVAL; 570 goto end_while; 571 } 572 len ++; 573 } 574end_while: 575 576 if (!error) 577 ppb_1284_set_state(bus, PPB_REVERSE_IDLE); 578 579 *read = len; 580 581 if (terminate_after_transfer || error) 582 ppb_1284_terminate(bus); 583 584 return (error); 585} 586 587/* 588 * ppb_1284_read_id() 589 * 590 */ 591int 592ppb_1284_read_id(device_t bus, int mode, char *buffer, 593 int max, int *read) 594{ 595 int error = 0; 596 597 /* fill the buffer with 0s */ 598 bzero(buffer, max); 599 600 switch (mode) { 601 case PPB_NIBBLE: 602 case PPB_ECP: 603 if ((error = ppb_1284_negociate(bus, PPB_NIBBLE, PPB_REQUEST_ID))) 604 return (error); 605 error = spp_1284_read(bus, PPB_NIBBLE, buffer, max, read); 606 break; 607 case PPB_BYTE: 608 if ((error = ppb_1284_negociate(bus, PPB_BYTE, PPB_REQUEST_ID))) 609 return (error); 610 error = spp_1284_read(bus, PPB_BYTE, buffer, max, read); 611 break; 612 default: 613 panic("%s: unsupported mode %d\n", __func__, mode); 614 } 615 616 ppb_1284_terminate(bus); 617 return (error); 618} 619 620/* 621 * ppb_1284_read() 622 * 623 * IEEE1284 read 624 */ 625int 626ppb_1284_read(device_t bus, int mode, char *buffer, 627 int max, int *read) 628{ 629 int error = 0; 630 631 switch (mode) { 632 case PPB_NIBBLE: 633 case PPB_BYTE: 634 error = spp_1284_read(bus, mode, buffer, max, read); 635 break; 636 default: 637 return (EINVAL); 638 } 639 640 return (error); 641} 642 643/* 644 * ppb_1284_negociate() 645 * 646 * IEEE1284 negociation phase 647 * 648 * Normal nibble mode or request device id mode (see ppb_1284.h) 649 * 650 * After negociation, nFAULT is low if data is available 651 */ 652int 653ppb_1284_negociate(device_t bus, int mode, int options) 654{ 655 int error; 656 int request_mode; 657 658#ifdef DEBUG_1284 659 printf("n"); 660#endif 661 662 if (ppb_1284_get_state(bus) >= PPB_PERIPHERAL_NEGOCIATION) 663 ppb_peripheral_terminate(bus, PPB_WAIT); 664 665 if (ppb_1284_get_state(bus) != PPB_FORWARD_IDLE) 666 ppb_1284_terminate(bus); 667 668#ifdef DEBUG_1284 669 printf("%d", mode); 670#endif 671 672 /* ensure the host is in compatible mode */ 673 ppb_set_mode(bus, PPB_COMPATIBLE); 674 675 /* reset error to catch the actual negociation error */ 676 ppb_1284_reset_error(bus, PPB_FORWARD_IDLE); 677 678 /* calculate ext. value */ 679 request_mode = ppb_request_mode(mode, options); 680 681 /* default state */ 682 ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED)); 683 DELAY(1); 684 685 /* enter negociation phase */ 686 ppb_1284_set_state(bus, PPB_NEGOCIATION); 687 688 /* Event 0 - put the exten. value on the data lines */ 689 ppb_wdtr(bus, request_mode); 690 691#ifdef PERIPH_1284 692 /* request remote host attention */
|
692 ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN)); 693 DELAY(1); 694 ppb_wctr(bus, (nINIT) & ~(STROBE | AUTOFEED | SELECTIN));
| 693 ppb_wctr(bus, (nINIT | STROBE) & ~(AUTOFEED | SELECTIN)); 694 DELAY(1); 695 ppb_wctr(bus, (nINIT) & ~(STROBE | AUTOFEED | SELECTIN));
|
695#else 696 DELAY(1); 697 698#endif /* !PERIPH_1284 */ 699 700 /* Event 1 - enter IEEE1284 mode */ 701 ppb_wctr(bus, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN)); 702 703#ifdef PERIPH_1284
| 696#else 697 DELAY(1); 698 699#endif /* !PERIPH_1284 */ 700 701 /* Event 1 - enter IEEE1284 mode */ 702 ppb_wctr(bus, (nINIT | AUTOFEED) & ~(STROBE | SELECTIN)); 703 704#ifdef PERIPH_1284
|
704 /* ignore the PError line, wait a bit more, remote host's
| 705 /* ignore the PError line, wait a bit more, remote host's
|
705 * interrupts don't respond fast enough */ 706 if (ppb_poll_bus(bus, 40, nACK | SELECT | nFAULT, 707 SELECT | nFAULT, PPB_NOINTR | PPB_POLL)) {
| 706 * interrupts don't respond fast enough */ 707 if (ppb_poll_bus(bus, 40, nACK | SELECT | nFAULT, 708 SELECT | nFAULT, PPB_NOINTR | PPB_POLL)) {
|
708 ppb_1284_set_error(bus, PPB_NOT_IEEE1284, 2); 709 error = ENODEV; 710 goto error; 711 }
| 709 ppb_1284_set_error(bus, PPB_NOT_IEEE1284, 2); 710 error = ENODEV; 711 goto error; 712 }
|
712#else 713 /* Event 2 - trying IEEE1284 dialog */ 714 if (do_1284_wait(bus, nACK | PERROR | SELECT | nFAULT, 715 PERROR | SELECT | nFAULT)) { 716 ppb_1284_set_error(bus, PPB_NOT_IEEE1284, 2); 717 error = ENODEV; 718 goto error; 719 } 720#endif /* !PERIPH_1284 */ 721 722 /* Event 3 - latch the ext. value to the peripheral */ 723 ppb_wctr(bus, (nINIT | STROBE | AUTOFEED) & ~SELECTIN); 724 DELAY(1); 725 726 /* Event 4 - IEEE1284 device recognized */ 727 ppb_wctr(bus, nINIT & ~(SELECTIN | AUTOFEED | STROBE)); 728 729 /* Event 6 - waiting for status lines */ 730 if (do_1284_wait(bus, nACK, nACK)) { 731 ppb_1284_set_error(bus, PPB_TIMEOUT, 6); 732 error = EBUSY; 733 goto error; 734 } 735 736 /* Event 7 - quering result consider nACK not to misunderstand 737 * a remote computer terminate sequence */ 738 if (options & PPB_EXTENSIBILITY_LINK) { 739 740 /* XXX not fully supported yet */ 741 ppb_1284_terminate(bus); 742 return (0); 743 744 } 745 if (request_mode == NIBBLE_1284_NORMAL) { 746 if (do_1284_wait(bus, nACK | SELECT, nACK)) { 747 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 7); 748 error = ENODEV; 749 goto error; 750 } 751 } else { 752 if (do_1284_wait(bus, nACK | SELECT, SELECT | nACK)) { 753 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 7); 754 error = ENODEV; 755 goto error; 756 } 757 } 758 759 switch (mode) { 760 case PPB_NIBBLE: 761 case PPB_PS2: 762 /* enter reverse idle phase */ 763 ppb_1284_set_state(bus, PPB_REVERSE_IDLE); 764 break; 765 case PPB_ECP: 766 /* negociation ok, now setup the communication */ 767 ppb_1284_set_state(bus, PPB_SETUP); 768 ppb_wctr(bus, (nINIT | AUTOFEED) & ~(SELECTIN | STROBE)); 769 770#ifdef PERIPH_1284 771 /* ignore PError line */ 772 if (do_1284_wait(bus, nACK | SELECT | nBUSY,
| 713#else 714 /* Event 2 - trying IEEE1284 dialog */ 715 if (do_1284_wait(bus, nACK | PERROR | SELECT | nFAULT, 716 PERROR | SELECT | nFAULT)) { 717 ppb_1284_set_error(bus, PPB_NOT_IEEE1284, 2); 718 error = ENODEV; 719 goto error; 720 } 721#endif /* !PERIPH_1284 */ 722 723 /* Event 3 - latch the ext. value to the peripheral */ 724 ppb_wctr(bus, (nINIT | STROBE | AUTOFEED) & ~SELECTIN); 725 DELAY(1); 726 727 /* Event 4 - IEEE1284 device recognized */ 728 ppb_wctr(bus, nINIT & ~(SELECTIN | AUTOFEED | STROBE)); 729 730 /* Event 6 - waiting for status lines */ 731 if (do_1284_wait(bus, nACK, nACK)) { 732 ppb_1284_set_error(bus, PPB_TIMEOUT, 6); 733 error = EBUSY; 734 goto error; 735 } 736 737 /* Event 7 - quering result consider nACK not to misunderstand 738 * a remote computer terminate sequence */ 739 if (options & PPB_EXTENSIBILITY_LINK) { 740 741 /* XXX not fully supported yet */ 742 ppb_1284_terminate(bus); 743 return (0); 744 745 } 746 if (request_mode == NIBBLE_1284_NORMAL) { 747 if (do_1284_wait(bus, nACK | SELECT, nACK)) { 748 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 7); 749 error = ENODEV; 750 goto error; 751 } 752 } else { 753 if (do_1284_wait(bus, nACK | SELECT, SELECT | nACK)) { 754 ppb_1284_set_error(bus, PPB_MODE_UNSUPPORTED, 7); 755 error = ENODEV; 756 goto error; 757 } 758 } 759 760 switch (mode) { 761 case PPB_NIBBLE: 762 case PPB_PS2: 763 /* enter reverse idle phase */ 764 ppb_1284_set_state(bus, PPB_REVERSE_IDLE); 765 break; 766 case PPB_ECP: 767 /* negociation ok, now setup the communication */ 768 ppb_1284_set_state(bus, PPB_SETUP); 769 ppb_wctr(bus, (nINIT | AUTOFEED) & ~(SELECTIN | STROBE)); 770 771#ifdef PERIPH_1284 772 /* ignore PError line */ 773 if (do_1284_wait(bus, nACK | SELECT | nBUSY,
|
773 nACK | SELECT | nBUSY)) { 774 ppb_1284_set_error(bus, PPB_TIMEOUT, 30); 775 error = ENODEV; 776 goto error; 777 }
| 774 nACK | SELECT | nBUSY)) { 775 ppb_1284_set_error(bus, PPB_TIMEOUT, 30); 776 error = ENODEV; 777 goto error; 778 }
|
778#else 779 if (do_1284_wait(bus, nACK | SELECT | PERROR | nBUSY, 780 nACK | SELECT | PERROR | nBUSY)) { 781 ppb_1284_set_error(bus, PPB_TIMEOUT, 30); 782 error = ENODEV; 783 goto error; 784 } 785#endif /* !PERIPH_1284 */ 786 787 /* ok, the host enters the ForwardIdle state */ 788 ppb_1284_set_state(bus, PPB_ECP_FORWARD_IDLE); 789 break; 790 case PPB_EPP: 791 ppb_1284_set_state(bus, PPB_EPP_IDLE); 792 break; 793 794 default: 795 panic("%s: unknown mode (%d)!", __func__, mode); 796 } 797 ppb_set_mode(bus, mode); 798 799 return (0); 800 801error: 802 ppb_1284_terminate(bus); 803 804 return (error); 805} 806 807/* 808 * ppb_1284_terminate() 809 * 810 * IEEE1284 termination phase, return code should ignored since the host 811 * is _always_ in compatible mode after ppb_1284_terminate() 812 */ 813int 814ppb_1284_terminate(device_t bus) 815{ 816 817#ifdef DEBUG_1284 818 printf("T"); 819#endif 820 821 /* do not reset error here to keep the error that 822 * may occured before the ppb_1284_terminate() call */ 823 ppb_1284_set_state(bus, PPB_TERMINATION); 824 825#ifdef PERIPH_1284 826 /* request remote host attention */
| 779#else 780 if (do_1284_wait(bus, nACK | SELECT | PERROR | nBUSY, 781 nACK | SELECT | PERROR | nBUSY)) { 782 ppb_1284_set_error(bus, PPB_TIMEOUT, 30); 783 error = ENODEV; 784 goto error; 785 } 786#endif /* !PERIPH_1284 */ 787 788 /* ok, the host enters the ForwardIdle state */ 789 ppb_1284_set_state(bus, PPB_ECP_FORWARD_IDLE); 790 break; 791 case PPB_EPP: 792 ppb_1284_set_state(bus, PPB_EPP_IDLE); 793 break; 794 795 default: 796 panic("%s: unknown mode (%d)!", __func__, mode); 797 } 798 ppb_set_mode(bus, mode); 799 800 return (0); 801 802error: 803 ppb_1284_terminate(bus); 804 805 return (error); 806} 807 808/* 809 * ppb_1284_terminate() 810 * 811 * IEEE1284 termination phase, return code should ignored since the host 812 * is _always_ in compatible mode after ppb_1284_terminate() 813 */ 814int 815ppb_1284_terminate(device_t bus) 816{ 817 818#ifdef DEBUG_1284 819 printf("T"); 820#endif 821 822 /* do not reset error here to keep the error that 823 * may occured before the ppb_1284_terminate() call */ 824 ppb_1284_set_state(bus, PPB_TERMINATION); 825 826#ifdef PERIPH_1284 827 /* request remote host attention */
|
827 ppb_wctr(bus, (nINIT | STROBE | SELECTIN) & ~(AUTOFEED)); 828 DELAY(1);
| 828 ppb_wctr(bus, (nINIT | STROBE | SELECTIN) & ~(AUTOFEED)); 829 DELAY(1);
|
829#endif /* PERIPH_1284 */ 830 831 /* Event 22 - set nSelectin low and nAutoFeed high */ 832 ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED)); 833 834 /* Event 24 - waiting for peripheral, Xflag ignored */ 835 if (do_1284_wait(bus, nACK | nBUSY | nFAULT, nFAULT)) { 836 ppb_1284_set_error(bus, PPB_TIMEOUT, 24); 837 goto error; 838 } 839 840 /* Event 25 - set nAutoFd low */ 841 ppb_wctr(bus, (nINIT | SELECTIN | AUTOFEED) & ~STROBE); 842 843 /* Event 26 - compatible mode status is set */ 844 845 /* Event 27 - peripheral set nAck high */ 846 if (do_1284_wait(bus, nACK, nACK)) { 847 ppb_1284_set_error(bus, PPB_TIMEOUT, 27); 848 } 849 850 /* Event 28 - end termination, return to idle phase */ 851 ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED)); 852 853error: 854 /* return to compatible mode */ 855 ppb_set_mode(bus, PPB_COMPATIBLE); 856 ppb_1284_set_state(bus, PPB_FORWARD_IDLE); 857 858 return (0); 859}
| 830#endif /* PERIPH_1284 */ 831 832 /* Event 22 - set nSelectin low and nAutoFeed high */ 833 ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED)); 834 835 /* Event 24 - waiting for peripheral, Xflag ignored */ 836 if (do_1284_wait(bus, nACK | nBUSY | nFAULT, nFAULT)) { 837 ppb_1284_set_error(bus, PPB_TIMEOUT, 24); 838 goto error; 839 } 840 841 /* Event 25 - set nAutoFd low */ 842 ppb_wctr(bus, (nINIT | SELECTIN | AUTOFEED) & ~STROBE); 843 844 /* Event 26 - compatible mode status is set */ 845 846 /* Event 27 - peripheral set nAck high */ 847 if (do_1284_wait(bus, nACK, nACK)) { 848 ppb_1284_set_error(bus, PPB_TIMEOUT, 27); 849 } 850 851 /* Event 28 - end termination, return to idle phase */ 852 ppb_wctr(bus, (nINIT | SELECTIN) & ~(STROBE | AUTOFEED)); 853 854error: 855 /* return to compatible mode */ 856 ppb_set_mode(bus, PPB_COMPATIBLE); 857 ppb_1284_set_state(bus, PPB_FORWARD_IDLE); 858 859 return (0); 860}
|