^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) * IEEE-1284 implementation for parport.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Authors: Phil Blundell <philb@gnu.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Carsten Gross <carsten@sol.wohnheim.uni-ulm.de>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Jose Renau <renau@acm.org>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Tim Waugh <tim@cyberelk.demon.co.uk> (largely rewritten)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * This file is responsible for IEEE 1284 negotiation, and for handing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * read/write requests to low-level drivers.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Any part of this program may be used in documents licensed under
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) * the GNU Free Documentation License, Version 1.1 or any later version
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) * published by the Free Software Foundation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) * Various hacks, Fred Barnes <frmb2@ukc.ac.uk>, 04/2000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/threads.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/parport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #include <linux/sched/signal.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #undef DEBUG /* undef me for production */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #ifdef CONFIG_LP_CONSOLE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #undef DEBUG /* Don't want a garbled console */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) /* Make parport_wait_peripheral wake up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) * It will be useful to call this from an interrupt handler. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) static void parport_ieee1284_wakeup (struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) up (&port->physport->ieee1284.irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) static void timeout_waiting_on_port (struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) struct parport *port = from_timer(port, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) parport_ieee1284_wakeup (port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) * parport_wait_event - wait for an event on a parallel port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) * @port: port to wait on
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) * @timeout: time to wait (in jiffies)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) * This function waits for up to @timeout jiffies for an
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) * interrupt to occur on a parallel port. If the port timeout is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) * set to zero, it returns immediately.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) * If an interrupt occurs before the timeout period elapses, this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) * function returns zero immediately. If it times out, it returns
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) * one. An error code less than zero indicates an error (most
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) * likely a pending signal), and the calling code should finish
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) * what it's doing as soon as it can.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) int parport_wait_event (struct parport *port, signed long timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) if (!port->physport->cad->timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) /* Zero timeout is special, and we can't down() the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) semaphore. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) timer_setup(&port->timer, timeout_waiting_on_port, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) mod_timer(&port->timer, jiffies + timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) ret = down_interruptible (&port->physport->ieee1284.irq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) if (!del_timer_sync(&port->timer) && !ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) /* Timed out. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * parport_poll_peripheral - poll status lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * @port: port to watch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) * @mask: status lines to watch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) * @result: desired values of chosen status lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * @usec: timeout
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) * This function busy-waits until the masked status lines have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) * the desired values, or until the timeout period elapses. The
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) * @mask and @result parameters are bitmasks, with the bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * defined by the constants in parport.h: %PARPORT_STATUS_BUSY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * and so on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) * This function does not call schedule(); instead it busy-waits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) * using udelay(). It currently has a resolution of 5usec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) * If the status lines take on the desired values before the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * timeout period elapses, parport_poll_peripheral() returns zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * immediately. A return value greater than zero indicates
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * a timeout. An error code (less than zero) indicates an error,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) * most likely a signal that arrived, and the caller should
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) * finish what it is doing as soon as possible.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) int parport_poll_peripheral(struct parport *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) unsigned char mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) unsigned char result,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int usec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) /* Zero return code is success, >0 is timeout. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) int count = usec / 5 + 2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) unsigned char status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) for (i = 0; i < count; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) status = parport_read_status (port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) if ((status & mask) == result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) if (signal_pending (current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (need_resched())
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) if (i >= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) udelay (5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) * parport_wait_peripheral - wait for status lines to change in 35ms
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) * @port: port to watch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * @mask: status lines to watch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * @result: desired values of chosen status lines
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) * This function waits until the masked status lines have the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) * desired values, or until 35ms have elapsed (see IEEE 1284-1994
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) * page 24 to 25 for why this value in particular is hardcoded).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) * The @mask and @result parameters are bitmasks, with the bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) * defined by the constants in parport.h: %PARPORT_STATUS_BUSY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) * and so on.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) * The port is polled quickly to start off with, in anticipation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) * of a fast response from the peripheral. This fast polling
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) * time is configurable (using /proc), and defaults to 500usec.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * If the timeout for this port (see parport_set_timeout()) is
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) * zero, the fast polling time is 35ms, and this function does
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) * not call schedule().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) * If the timeout for this port is non-zero, after the fast
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) * polling fails it uses parport_wait_event() to wait for up to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) * 10ms, waking up if an interrupt occurs.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) int parport_wait_peripheral(struct parport *port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) unsigned char mask,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) unsigned char result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) int usec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) unsigned long deadline;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) unsigned char status;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) usec = port->physport->spintime; /* usecs of fast polling */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) if (!port->physport->cad->timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) /* A zero timeout is "special": busy wait for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) entire 35ms. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) usec = 35000;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) /* Fast polling.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) * This should be adjustable.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) * How about making a note (in the device structure) of how long
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) * it takes, so we know for next time?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) ret = parport_poll_peripheral (port, mask, result, usec);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) if (ret != 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (!port->physport->cad->timeout)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) /* We may be in an interrupt handler, so we can't poll
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) * slowly anyway. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) /* 40ms of slow polling. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) deadline = jiffies + msecs_to_jiffies(40);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) while (time_before (jiffies, deadline)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) if (signal_pending (current))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) return -EINTR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* Wait for 10ms (or until an interrupt occurs if
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * the handler is set) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) if ((ret = parport_wait_event (port, msecs_to_jiffies(10))) < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) status = parport_read_status (port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) if ((status & mask) == result)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (!ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) /* parport_wait_event didn't time out, but the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) * peripheral wasn't actually ready either.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) * Wait for another 10ms. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) schedule_timeout_interruptible(msecs_to_jiffies(10));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) #ifdef CONFIG_PARPORT_1284
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) /* Terminate a negotiated mode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) static void parport_ieee1284_terminate (struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) port = port->physport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /* EPP terminates differently. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) switch (port->ieee1284.mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) case IEEE1284_MODE_EPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) case IEEE1284_MODE_EPPSL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) case IEEE1284_MODE_EPPSWE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) /* Terminate from EPP mode. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) /* Event 68: Set nInit low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) parport_frob_control (port, PARPORT_CONTROL_INIT, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) udelay (50);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) /* Event 69: Set nInit high, nSelectIn low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) parport_frob_control (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) PARPORT_CONTROL_SELECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) | PARPORT_CONTROL_INIT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) PARPORT_CONTROL_SELECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) | PARPORT_CONTROL_INIT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) case IEEE1284_MODE_ECP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) case IEEE1284_MODE_ECPRLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) case IEEE1284_MODE_ECPSWE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) /* In ECP we can only terminate from fwd idle phase. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) /* Event 47: Set nInit high */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) parport_frob_control (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) PARPORT_CONTROL_INIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) | PARPORT_CONTROL_AUTOFD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) PARPORT_CONTROL_INIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) | PARPORT_CONTROL_AUTOFD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /* Event 49: PError goes high */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) r = parport_wait_peripheral (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) PARPORT_STATUS_PAPEROUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) PARPORT_STATUS_PAPEROUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) pr_debug("%s: Timeout at event 49\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) parport_data_forward (port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) pr_debug("%s: ECP direction: forward\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) /* Terminate from all other modes. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) /* Event 22: Set nSelectIn low, nAutoFd high */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) parport_frob_control (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) PARPORT_CONTROL_SELECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) | PARPORT_CONTROL_AUTOFD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) PARPORT_CONTROL_SELECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /* Event 24: nAck goes low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) pr_debug("%s: Timeout at event 24\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* Event 25: Set nAutoFd low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) parport_frob_control (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) PARPORT_CONTROL_AUTOFD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) PARPORT_CONTROL_AUTOFD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) /* Event 27: nAck goes high */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) r = parport_wait_peripheral (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) PARPORT_STATUS_ACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) PARPORT_STATUS_ACK);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) if (r)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) pr_debug("%s: Timeout at event 27\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) /* Event 29: Set nAutoFd high */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) port->ieee1284.mode = IEEE1284_MODE_COMPAT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) pr_debug("%s: In compatibility (forward idle) mode\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) #endif /* IEEE1284 support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * parport_negotiate - negotiate an IEEE 1284 mode
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) * @port: port to use
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * @mode: mode to negotiate to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) * Use this to negotiate to a particular IEEE 1284 transfer mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) * The @mode parameter should be one of the constants in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) * parport.h starting %IEEE1284_MODE_xxx.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) * The return value is 0 if the peripheral has accepted the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) * negotiation to the mode specified, -1 if the peripheral is not
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) * IEEE 1284 compliant (or not present), or 1 if the peripheral
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) * has rejected the negotiation.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) int parport_negotiate (struct parport *port, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) #ifndef CONFIG_PARPORT_1284
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) if (mode == IEEE1284_MODE_COMPAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) pr_err("parport: IEEE1284 not supported in this kernel\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) int m = mode & ~IEEE1284_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) int r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) unsigned char xflag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) port = port->physport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) /* Is there anything to do? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) if (port->ieee1284.mode == mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /* Is the difference just an address-or-not bit? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) if ((port->ieee1284.mode & ~IEEE1284_ADDR) == (mode & ~IEEE1284_ADDR)){
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) port->ieee1284.mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) /* Go to compatibility forward idle mode */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) if (port->ieee1284.mode != IEEE1284_MODE_COMPAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) parport_ieee1284_terminate (port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (mode == IEEE1284_MODE_COMPAT)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* Compatibility mode: no negotiation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) case IEEE1284_MODE_ECPSWE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) m = IEEE1284_MODE_ECP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) case IEEE1284_MODE_EPPSL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) case IEEE1284_MODE_EPPSWE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) m = IEEE1284_MODE_EPP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) case IEEE1284_MODE_BECP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) return -ENOSYS; /* FIXME (implement BECP) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) if (mode & IEEE1284_EXT_LINK)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) m = 1<<7; /* request extensibility link */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) port->ieee1284.phase = IEEE1284_PH_NEGOTIATION;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) /* Start off with nStrobe and nAutoFd high, and nSelectIn low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) parport_frob_control (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) PARPORT_CONTROL_STROBE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) | PARPORT_CONTROL_AUTOFD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) | PARPORT_CONTROL_SELECT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) PARPORT_CONTROL_SELECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) udelay(1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) /* Event 0: Set data */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) parport_data_forward (port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) parport_write_data (port, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) udelay (400); /* Shouldn't need to wait this long. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) /* Event 1: Set nSelectIn high, nAutoFd low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) parport_frob_control (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) PARPORT_CONTROL_SELECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) | PARPORT_CONTROL_AUTOFD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) PARPORT_CONTROL_AUTOFD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) /* Event 2: PError, Select, nFault go high, nAck goes low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) if (parport_wait_peripheral (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) PARPORT_STATUS_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) | PARPORT_STATUS_SELECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) | PARPORT_STATUS_PAPEROUT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) | PARPORT_STATUS_ACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) PARPORT_STATUS_ERROR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) | PARPORT_STATUS_SELECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) | PARPORT_STATUS_PAPEROUT)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /* Timeout */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) parport_frob_control (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) PARPORT_CONTROL_SELECT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) | PARPORT_CONTROL_AUTOFD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) PARPORT_CONTROL_SELECT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) pr_debug("%s: Peripheral not IEEE1284 compliant (0x%02X)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400) port->name, parport_read_status (port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) return -1; /* Not IEEE1284 compliant */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) /* Event 3: Set nStrobe low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) parport_frob_control (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) PARPORT_CONTROL_STROBE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) PARPORT_CONTROL_STROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) /* Event 4: Set nStrobe and nAutoFd high */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) udelay (5);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) parport_frob_control (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) PARPORT_CONTROL_STROBE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) | PARPORT_CONTROL_AUTOFD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) /* Event 6: nAck goes high */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) if (parport_wait_peripheral (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) PARPORT_STATUS_ACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) PARPORT_STATUS_ACK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) /* This shouldn't really happen with a compliant device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) pr_debug("%s: Mode 0x%02x not supported? (0x%02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) port->name, mode, port->ops->read_status (port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) parport_ieee1284_terminate (port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) xflag = parport_read_status (port) & PARPORT_STATUS_SELECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) /* xflag should be high for all modes other than nibble (0). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) if (mode && !xflag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) /* Mode not supported. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) pr_debug("%s: Mode 0x%02x rejected by peripheral\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) port->name, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) parport_ieee1284_terminate (port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) /* More to do if we've requested extensibility link. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) if (mode & IEEE1284_EXT_LINK) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) m = mode & 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) udelay (1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) parport_write_data (port, m);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) udelay (1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) /* Event 51: Set nStrobe low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) parport_frob_control (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) PARPORT_CONTROL_STROBE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) PARPORT_CONTROL_STROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) /* Event 52: nAck goes low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) if (parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) /* This peripheral is _very_ slow. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) pr_debug("%s: Event 52 didn't happen\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) parport_ieee1284_terminate (port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) /* Event 53: Set nStrobe high */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) parport_frob_control (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) PARPORT_CONTROL_STROBE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) /* Event 55: nAck goes high */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) if (parport_wait_peripheral (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) PARPORT_STATUS_ACK,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) PARPORT_STATUS_ACK)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) /* This shouldn't really happen with a compliant
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) * device. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) pr_debug("%s: Mode 0x%02x not supported? (0x%02x)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) port->name, mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) port->ops->read_status(port));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) parport_ieee1284_terminate (port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) /* Event 54: Peripheral sets XFlag to reflect support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) xflag = parport_read_status (port) & PARPORT_STATUS_SELECT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /* xflag should be high. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) if (!xflag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) /* Extended mode not supported. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) pr_debug("%s: Extended mode 0x%02x not supported\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) port->name, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) parport_ieee1284_terminate (port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) return 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) /* Any further setup is left to the caller. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) /* Mode is supported */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) pr_debug("%s: In mode 0x%02x\n", port->name, mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) port->ieee1284.mode = mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) /* But ECP is special */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) if (!(mode & IEEE1284_EXT_LINK) && (m & IEEE1284_MODE_ECP)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) port->ieee1284.phase = IEEE1284_PH_ECP_SETUP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) /* Event 30: Set nAutoFd low */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) parport_frob_control (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) PARPORT_CONTROL_AUTOFD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) PARPORT_CONTROL_AUTOFD);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) /* Event 31: PError goes high. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) r = parport_wait_peripheral (port,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) PARPORT_STATUS_PAPEROUT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) PARPORT_STATUS_PAPEROUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) if (r) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) pr_debug("%s: Timeout at event 31\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) pr_debug("%s: ECP direction: forward\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) } else switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) case IEEE1284_MODE_NIBBLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) case IEEE1284_MODE_BYTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) port->ieee1284.phase = IEEE1284_PH_REV_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) port->ieee1284.phase = IEEE1284_PH_FWD_IDLE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) #endif /* IEEE1284 support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) /* Acknowledge that the peripheral has data available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) * Events 18-20, in order to get from Reverse Idle phase
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) * to Host Busy Data Available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) * This will most likely be called from an interrupt.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) * Returns zero if data was available.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) #ifdef CONFIG_PARPORT_1284
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) static int parport_ieee1284_ack_data_avail (struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) if (parport_read_status (port) & PARPORT_STATUS_ERROR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) /* Event 18 didn't happen. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) /* Event 20: nAutoFd goes high. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) port->ops->frob_control (port, PARPORT_CONTROL_AUTOFD, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) #endif /* IEEE1284 support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) /* Handle an interrupt. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) void parport_ieee1284_interrupt (void *handle)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 552) struct parport *port = handle;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 553) parport_ieee1284_wakeup (port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 554)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 555) #ifdef CONFIG_PARPORT_1284
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 556) if (port->ieee1284.phase == IEEE1284_PH_REV_IDLE) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 557) /* An interrupt in this phase means that data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 558) * is now available. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 559) pr_debug("%s: Data available\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 560) parport_ieee1284_ack_data_avail (port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 561) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 562) #endif /* IEEE1284 support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 563) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 564)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 565) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 566) * parport_write - write a block of data to a parallel port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 567) * @port: port to write to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 568) * @buffer: data buffer (in kernel space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 569) * @len: number of bytes of data to transfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 570) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 571) * This will write up to @len bytes of @buffer to the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 572) * specified, using the IEEE 1284 transfer mode most recently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 573) * negotiated to (using parport_negotiate()), as long as that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 574) * mode supports forward transfers (host to peripheral).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 575) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 576) * It is the caller's responsibility to ensure that the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 577) * @len bytes of @buffer are valid.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 578) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 579) * This function returns the number of bytes transferred (if zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 580) * or positive), or else an error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 581) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 582)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 583) ssize_t parport_write (struct parport *port, const void *buffer, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 584) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 585) #ifndef CONFIG_PARPORT_1284
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 586) return port->ops->compat_write_data (port, buffer, len, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 587) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 588) ssize_t retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 589) int mode = port->ieee1284.mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 590) int addr = mode & IEEE1284_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 591) size_t (*fn) (struct parport *, const void *, size_t, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 592)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 593) /* Ignore the device-ID-request bit and the address bit. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 594) mode &= ~(IEEE1284_DEVICEID | IEEE1284_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 595)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 596) /* Use the mode we're in. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 597) switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 598) case IEEE1284_MODE_NIBBLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 599) case IEEE1284_MODE_BYTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 600) parport_negotiate (port, IEEE1284_MODE_COMPAT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 601) fallthrough;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 602) case IEEE1284_MODE_COMPAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 603) pr_debug("%s: Using compatibility mode\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 604) fn = port->ops->compat_write_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 605) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 606)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 607) case IEEE1284_MODE_EPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 608) pr_debug("%s: Using EPP mode\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 609) if (addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 610) fn = port->ops->epp_write_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 611) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 612) fn = port->ops->epp_write_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 613) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 614) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 615) case IEEE1284_MODE_EPPSWE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 616) pr_debug("%s: Using software-emulated EPP mode\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 617) if (addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 618) fn = parport_ieee1284_epp_write_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 619) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 620) fn = parport_ieee1284_epp_write_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 621) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 622) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 623) case IEEE1284_MODE_ECP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 624) case IEEE1284_MODE_ECPRLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 625) pr_debug("%s: Using ECP mode\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 626) if (addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 627) fn = port->ops->ecp_write_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 628) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 629) fn = port->ops->ecp_write_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 630) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 631) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 632)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 633) case IEEE1284_MODE_ECPSWE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 634) pr_debug("%s: Using software-emulated ECP mode\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 635) /* The caller has specified that it must be emulated,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 636) * even if we have ECP hardware! */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 637) if (addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 638) fn = parport_ieee1284_ecp_write_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 639) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 640) fn = parport_ieee1284_ecp_write_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 641) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 642) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 643)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 644) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 645) pr_debug("%s: Unknown mode 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 646) port->name, port->ieee1284.mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 647) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 648) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 649)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 650) retval = (*fn) (port, buffer, len, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 651) pr_debug("%s: wrote %zd/%zu bytes\n", port->name, retval, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 652) return retval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 653) #endif /* IEEE1284 support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 654) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 655)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 656) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 657) * parport_read - read a block of data from a parallel port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 658) * @port: port to read from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 659) * @buffer: data buffer (in kernel space)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 660) * @len: number of bytes of data to transfer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 661) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 662) * This will read up to @len bytes of @buffer to the port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 663) * specified, using the IEEE 1284 transfer mode most recently
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 664) * negotiated to (using parport_negotiate()), as long as that
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 665) * mode supports reverse transfers (peripheral to host).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 666) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 667) * It is the caller's responsibility to ensure that the first
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 668) * @len bytes of @buffer are available to write to.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 669) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 670) * This function returns the number of bytes transferred (if zero
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 671) * or positive), or else an error code.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 672) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 673)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 674) ssize_t parport_read (struct parport *port, void *buffer, size_t len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 675) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 676) #ifndef CONFIG_PARPORT_1284
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 677) pr_err("parport: IEEE1284 not supported in this kernel\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 678) return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 679) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 680) int mode = port->physport->ieee1284.mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 681) int addr = mode & IEEE1284_ADDR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 682) size_t (*fn) (struct parport *, void *, size_t, int);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 683)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 684) /* Ignore the device-ID-request bit and the address bit. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 685) mode &= ~(IEEE1284_DEVICEID | IEEE1284_ADDR);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 686)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 687) /* Use the mode we're in. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 688) switch (mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 689) case IEEE1284_MODE_COMPAT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 690) /* if we can tri-state use BYTE mode instead of NIBBLE mode,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 691) * if that fails, revert to NIBBLE mode -- ought to store somewhere
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 692) * the device's ability to do BYTE mode reverse transfers, so we don't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 693) * end up needlessly calling negotiate(BYTE) repeately.. (fb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 694) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 695) if ((port->physport->modes & PARPORT_MODE_TRISTATE) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 696) !parport_negotiate (port, IEEE1284_MODE_BYTE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 697) /* got into BYTE mode OK */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 698) pr_debug("%s: Using byte mode\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 699) fn = port->ops->byte_read_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 700) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 701) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 702) if (parport_negotiate (port, IEEE1284_MODE_NIBBLE)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 703) return -EIO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 704) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 705) fallthrough; /* to NIBBLE */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 706) case IEEE1284_MODE_NIBBLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 707) pr_debug("%s: Using nibble mode\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 708) fn = port->ops->nibble_read_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 709) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 710)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 711) case IEEE1284_MODE_BYTE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 712) pr_debug("%s: Using byte mode\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 713) fn = port->ops->byte_read_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 714) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 715)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 716) case IEEE1284_MODE_EPP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 717) pr_debug("%s: Using EPP mode\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 718) if (addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 719) fn = port->ops->epp_read_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 720) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 721) fn = port->ops->epp_read_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 722) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 723) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 724) case IEEE1284_MODE_EPPSWE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 725) pr_debug("%s: Using software-emulated EPP mode\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 726) if (addr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 727) fn = parport_ieee1284_epp_read_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 728) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 729) fn = parport_ieee1284_epp_read_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 730) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 731) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 732) case IEEE1284_MODE_ECP:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 733) case IEEE1284_MODE_ECPRLE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 734) pr_debug("%s: Using ECP mode\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 735) fn = port->ops->ecp_read_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 736) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 737)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 738) case IEEE1284_MODE_ECPSWE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 739) pr_debug("%s: Using software-emulated ECP mode\n", port->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 740) fn = parport_ieee1284_ecp_read_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 741) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 742)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 743) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 744) pr_debug("%s: Unknown mode 0x%02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 745) port->name, port->physport->ieee1284.mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 746) return -ENOSYS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 747) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 748)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 749) return (*fn) (port, buffer, len, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 750) #endif /* IEEE1284 support */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 751) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 752)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 753) /**
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 754) * parport_set_timeout - set the inactivity timeout for a device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 755) * @dev: device on a port
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 756) * @inactivity: inactivity timeout (in jiffies)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 757) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 758) * This sets the inactivity timeout for a particular device on a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 759) * port. This affects functions like parport_wait_peripheral().
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 760) * The special value 0 means not to call schedule() while dealing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 761) * with this device.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 762) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 763) * The return value is the previous inactivity timeout.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 764) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 765) * Any callers of parport_wait_event() for this device are woken
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 766) * up.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 767) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 768)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 769) long parport_set_timeout (struct pardevice *dev, long inactivity)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 770) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 771) long int old = dev->timeout;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 772)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 773) dev->timeout = inactivity;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 774)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 775) if (dev->port->physport->cad == dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 776) parport_ieee1284_wakeup (dev->port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 777)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 778) return old;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 779) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 780)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 781) /* Exported symbols for modules. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 782)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 783) EXPORT_SYMBOL(parport_negotiate);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 784) EXPORT_SYMBOL(parport_write);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 785) EXPORT_SYMBOL(parport_read);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 786) EXPORT_SYMBOL(parport_wait_peripheral);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 787) EXPORT_SYMBOL(parport_wait_event);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 788) EXPORT_SYMBOL(parport_set_timeout);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 789) EXPORT_SYMBOL(parport_ieee1284_interrupt);