From 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 Mon Sep 17 00:00:00 2001 From: Linus Torvalds Date: Sat, 16 Apr 2005 15:20:36 -0700 Subject: Linux-2.6.12-rc2 Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip! --- drivers/parport/BUGS-parport | 9 + drivers/parport/ChangeLog | 583 +++++++ drivers/parport/Kconfig | 145 ++ drivers/parport/Makefile | 19 + drivers/parport/TODO-parport | 20 + drivers/parport/daisy.c | 512 ++++++ drivers/parport/ieee1284.c | 819 +++++++++ drivers/parport/ieee1284_ops.c | 921 ++++++++++ drivers/parport/multiface.h | 20 + drivers/parport/parport_amiga.c | 293 ++++ drivers/parport/parport_arc.c | 139 ++ drivers/parport/parport_atari.c | 240 +++ drivers/parport/parport_cs.c | 397 +++++ drivers/parport/parport_gsc.c | 437 +++++ drivers/parport/parport_gsc.h | 222 +++ drivers/parport/parport_mfc3.c | 404 +++++ drivers/parport/parport_pc.c | 3415 ++++++++++++++++++++++++++++++++++++++ drivers/parport/parport_serial.c | 485 ++++++ drivers/parport/parport_sunbpp.c | 412 +++++ drivers/parport/probe.c | 224 +++ drivers/parport/procfs.c | 533 ++++++ drivers/parport/share.c | 1014 +++++++++++ 22 files changed, 11263 insertions(+) create mode 100644 drivers/parport/BUGS-parport create mode 100644 drivers/parport/ChangeLog create mode 100644 drivers/parport/Kconfig create mode 100644 drivers/parport/Makefile create mode 100644 drivers/parport/TODO-parport create mode 100644 drivers/parport/daisy.c create mode 100644 drivers/parport/ieee1284.c create mode 100644 drivers/parport/ieee1284_ops.c create mode 100644 drivers/parport/multiface.h create mode 100644 drivers/parport/parport_amiga.c create mode 100644 drivers/parport/parport_arc.c create mode 100644 drivers/parport/parport_atari.c create mode 100644 drivers/parport/parport_cs.c create mode 100644 drivers/parport/parport_gsc.c create mode 100644 drivers/parport/parport_gsc.h create mode 100644 drivers/parport/parport_mfc3.c create mode 100644 drivers/parport/parport_pc.c create mode 100644 drivers/parport/parport_serial.c create mode 100644 drivers/parport/parport_sunbpp.c create mode 100644 drivers/parport/probe.c create mode 100644 drivers/parport/procfs.c create mode 100644 drivers/parport/share.c (limited to 'drivers/parport') diff --git a/drivers/parport/BUGS-parport b/drivers/parport/BUGS-parport new file mode 100644 index 000000000000..622ca3cc7fa0 --- /dev/null +++ b/drivers/parport/BUGS-parport @@ -0,0 +1,9 @@ +Currently known (or at least suspected) bugs in parport: + +o lp doesn't allow you to read status while printing is in progress (is + this still true?). + +o parport_pc_ecp_read_block_pio() is broken. parport will revert to the + software-driven mode in ieee1284_ops.c + +See . diff --git a/drivers/parport/ChangeLog b/drivers/parport/ChangeLog new file mode 100644 index 000000000000..db717c1d62a5 --- /dev/null +++ b/drivers/parport/ChangeLog @@ -0,0 +1,583 @@ +2001-10-11 Tim Waugh + * parport_pc.c, parport_serial.c: Support for NetMos cards. + + Patch originally from Michael Reinelt . + +2002-04-25 Tim Waugh + + * parport_serial.c, parport_pc.c: Move some SIIG cards around. + Patch from Andrey Panin. + +2002-01-20 Tim Waugh + + * parport_pc.c (parport_pc_compat_write_block_pio, + parport_pc_ecp_write_block_pio, parport_pc_ecp_read_block_pio): + Use the default implementations if the caller wants to use + O_NONBLOCK. + +2002-02-25 Tim Waugh + + * parport_pc.c: Make sure that priv->ctr_writable includes IntEn + even if IRQ is given as a parameter. + +2002-01-21 Tim Waugh + + * daisy.c: Apply patch from Max Vorobiev to make parport_daisy_select + work for ECP/EPP modes. + +2002-01-13 Niels Kristian Bech Jensen + + * parport_pc.c: Change some occurrences of frob_set_mode to + ECR_WRITE. This fixes PLIP. + +2002-01-04 Tim Waugh + + * share.c (parport_claim_or_block): Sleep interruptibly to prevent + a possible deadlock. + +2001-12-07 Damian Gruszka + + * parport_pc.c (ECR_WRITE): Define. If there are forbidden bits + in the ECR register for some chips, this will be a useful place to + put that knowledge. + (change_mode): Use ECR_WRITE. + (parport_pc_restore_state): Likewise. + (parport_ECPPS2_supported): Likewise. + (parport_ECPEPP_supported): Likewise. + (irq_probe_EPP): Likewise. + (programmable_irq_support): Likewise. + (programmable_dma_support): Likewise. + (parport_pc_probe_port): Likewise. + + (frob_set_mode): New function. Set the mode bits of the ECR. + (get_fifo_residue): Use frob_set_mode. + (parport_pc_ecpepp_read_data): Likewise. + (parport_pc_ecpepp_write_data): Likewise. + (parport_pc_ecpepp_read_addr): Likewise. + (parport_pc_ecpepp_write_addr): Likewise. + (parport_pc_compat_write_block_pio): Likewise. + (parport_pc_ecp_write_block_pio): Likewise. + (parport_ECR_present): Likewise. + (parport_ECP_supported): Likewise. + (parport_EPP_supported): Likewise. + (parport_ECPEPP_supported): Likewise. + (programmable_irq_support): Likewise. + (irq_probe_ECP): Likewise. + (programmable_dma_support): Likewise. + + (parport_pc_enable_irq): Only enable interrupts if we know which + IRQ line they will come from. + (parport_pc_init_state): Set nErrIntrEn at initialisation. + (parport_pc_restore_state): Only write writable bits of CTR. + (parport_irq_probe): If no IRQ is found, take ackIntEn out of the + writable bit set. + +2001-12-07 Tim Waugh + + * parport_pc.c (parport_pc_fifo_write_block_pio): Correct typo. + (parport_pc_init_state): Only set ackIntEn if we know which IRQ + line the interrupts will come from. + +2001-12-07 Tim Waugh + + * ieee1284_ops.c (parport_ieee1284_epp_write_addr, + parport_ieee1284_epp_read_addr): Actually do something useful. + +2001-12-07 Tim Waugh + + * parport_pc.c (dmaval): Don't use DMA by default. It seems to be + too buggy at the moment. Use 'dma=auto' to restore the previous + behaviour. + +2001-12-07 Tim Waugh + + * daisy.c (DEBUG): Undefine. + +2001-12-06 Tim Waugh + + * ieee1284_ops.c (parport_ieee1284_ecp_read_data): Mask off + PARPORT_CONTROL_AUTOFD as well. Bug spotted by Joe + . + +2001-12-03 Rich Liu + + * parport_pc.c (sio_ite_8872_probe): ITE8873 is a single-port + serial board, not a serial+parallel. + +2001-11-30 Niels Kristian Bech Jensen + + * parport_pc.c: Fix compiler warning. + +2001-11-14 Tim Waugh + + * parport_pc.c (parport_pc_pci_probe): Hooks for PCI cards before + and after probing for ports. + * parport_serial.c (parport_register): Likewise. + +2001-11-12 Tim Waugh + + * parport_pc.c (init_module): Warn when parameters are ignored. + +2001-11-01 Damian Gruszka + + * parport_serial.c (serial_register): Set base_baud before + calling register_serial. + +2001-10-26 Tim Waugh + + * parport_pc.c (parport_irq_probe): When ECR programmable IRQ + support fails, generate interrupts using the FIFO even if we don't + want to use the FIFO for real data transfers. + (parport_pc_probe_port): Display the ECR address if we have an + ECR, not just if we will use the FIFO. + +2001-10-24 Dave Strauss + + * parport_pc.c (parport_pc_compat_write_block_pio, + parport_pc_ecp_write_block_pio): Allow a few seconds for an ECP + transfer to finish up. + +2001-10-11 Tim Waugh + + * parport_pc (sio_ite_8872_probe): New function, submitted by Rich + Liu from ITE. Cleaned up, removed bogus phys_to_virt calls. + +2001-10-24 Tim Waugh + + * parport_pc.c: Support for AKS AladdinCARD. Patch from + Aladdin Knowledge Systems (Christian Groessler). + +2001-10-24 Tim Waugh + + * ieee1284_ops.c (parport_ieee1284_ecp_read_data): Try to minimise + turnaround time. + + * ieee1284.c (parport_poll_peripheral): Try a couple of times + first without delaying. + +2001-10-10 Tim Waugh + + * parport_pc.c: Support for OX16PCI954 PCI card. + +2001-10-10 Tim Waugh + + * parport_pc.c: Support for OX12PCI840 PCI card (reported by + mk@daveg.com). Lock-ups diagnosed by Ronnie Arosa (and now we + just don't trust its ECR). + +2001-10-10 Gunther Mayer + + * parport_pc.c: Support for AVLAB cards. + +2001-10-10 Tim Waugh + + * ieee1284_ops.c (ecp_forward_to_reverse, ecp_reverse_to_forward): + Remember to retry direction switch if it fails. Patch from David + Lambert. + +2001-10-08 David C. Hansen + + * share.c: Make driverlist_lock and parportlist_lock static. + +2001-10-08 Philip Blundell + + * parport_pc.c: New modular parameter verbose_logging. + Make port->modes indicate the modes that we are prepared to use, + rather than the modes that are available. + +2001-10-07 Tim Waugh + + * parport_pc.c (parport_pc_probe_port): Fix memory leak spotted by + Kipp Cannon. + +2001-10-07 Tim Waugh + + * parport_serial.c: Remove NetMos support, since it causes problems + for some people. + +2001-08-30 Tim Waugh + + * parport_serial.c (parport_serial_pci_probe): Clean-up on partial + registration failure. + +2001-08-14 Tim Waugh + + * parport_pc.c (parport_pc_init_superio): Allow for more than one + SuperIO device. Patch from Rich Lio (ITE). + +2001-08-11 Tim Waugh + + * parport_pc.c: Support for Titan Electronics cards. + +2001-08-08 Tim Waugh + + * share.c (parport_unregister_device): Remove device from wait list + too. + +2001-06-20 Tim Waugh + + * parport_pc.c: Make 'io_hi=0' work. + +2001-05-31 Tim Waugh + + * parport_serial.c: New file. + +2001-06-05 Tim Waugh + + * parport_pc.c (parport_pc_unregister_port): New exported function. + Do the opposite of parport_pc_probe_port. + (cleanup_module): Use it. + +2001-05-22 Juan Quintela + + * parport_amiga.c: Set printk levels. + * parport_gsc.c: Likewise. + * parport_mfc3.c: Likewise. + * parport_pc.c: Likewise. + * parport_sunbpp.c: Likewise. + * probe.c: Likewise. + * share.c: Likewise. + +2001-05-10 Fred Barnes + + * parport_pc.c (parport_pc_epp_read_data): added support for + reading from a w91284pic peripheral, flag is PARPORT_W91284PIC. + +2001-05-07 Fred Barnes + + * parport_pc.c (parport_pc_epp_read_data, + parport_pc_epp_write_data, parport_pc_epp_read_addr, + parport_pc_epp_write_addr): support for fast reads/writes using + the PARPORT_EPP_FAST flag. + + * ieee1284.c (parport_read, parport_write): added code to handle + software EPP mode (IEEE1284_MODE_EPPSWE). Added code to allow + BYTE mode reverse transfers (previously always went for NIBBLE + mode). + + * ieee1284_ops.c (parport_ieee1284_epp_read_data, + parport_ieee1284_epp_write_data): fixed various polarity problems. + Also (theoretically) fixed address versions (.._addr), but no + hardware to test this on. + + * parport_pc.h: added parport_dump_state() function for debugging. + Needs to have DEBUG_PARPORT to be defined for it to be included. + +2001-05-03 Tim Waugh + + * parport_pc.c: Fix the compile problem I introduce from the last + change. + +2001-04-20 Paul Gortmaker + + * parport_pc.c: Cut down the size quite a bit (more than 4k off + the object, about 1k off the zImage) for the older non-PCI + machines which are typically resource starved anyway... + +2001-03-26 R Horn + + * parport_pc.c: Some commentary changes. + +2001-04-19 Tim Waugh + + * parport_pc.c (parport_pc_probe_port): Remove __devinit + attribute. Export unconditionally. + +2001-04-14 Jeff Garzik + + Merged: 2001-03-30 Tim Waugh + + * drivers/parport/parport_pc.c: Make Via SuperIO chipsets behave + like everything else with respect to irq= and dma= parameters. + +2001-04-08 Tim Waugh + + * parport_pc.c (parport_pc_save_state): Read from the soft copy of + the control port. + (parport_pc_restore_state): Update the soft copy of the control + port. + +2001-03-26 Tim Waugh + + * share.c (parport_find_number, parport_find_base): Trigger + a lowlevel driver load if there are no ports yet. + +2001-03-26 Tim Waugh + + * parport_pc.c (parport_ECP_supported): Remove the IRQ conflict + check since it seems totally unreliable. + +2001-03-02 Tim Waugh + + * ieee1284_ops.c (parport_ieee1284_read_nibble): Reset nAutoFd + on timeout. Matches 2.2.x behaviour. + +2001-03-02 Andrew Morton + + * parport_pc.c (registered_parport): New static variable. + (parport_pc_find_ports): Set it when we register PCI driver. + (init_module): Unregister PCI driver if necessary when we + fail. + +2001-03-02 Tim Waugh + + * ieee1284_ops.c (parport_ieee1284_write_compat): Don't use + down_trylock to reset the IRQ count. Don't even use sema_init, + because it's not even necessary to reset the count. I can't + remember why we ever did. + +2001-01-04 Peter Osterlund + + * ieee1284.c (parport_negotiate): Fix missing printk argument. + +2001-01-03 Paul Schleger + + * probe.c (parse_data): Get rid of trailing blanks in values. + Needed for XEROX XJ8C printer. + +2001-01-03 Tim Waugh + + * parport_pc.c (parport_pc_probe_port): Say something when probes + are omitted. + +2001-01-03 Tim Waugh + + * parport_pc.c (sio_via_686a_probe): Correct dma=255 fix. + +2000-11-21 Tim Waugh + + * parport_pc.c (parport_pc_ecp_write_block_pio): Fix + reverse-to-forward logic. Spotted by Roland Kuck + . + +2000-09-16 Cesar Eduardo Barros + + * parport_pc.c (sio_via_686a_probe): Handle case + where hardware returns 255 for IRQ or DMA. + +2000-07-20 Eddie C. Dost + + * share.c (attach_driver_chain): attach[i](port) needs to be + replaced by attach[count](port). + +2000-07-20 Eddie C. Dost + + * daisy.c (add_dev): kmalloc args are in wrong order. + +2000-07-12 Tim Waugh + + * share.c: Documentation for parport_{get,port}_port, + parport_find_{number,base}. + +2000-07-12 Tim Waugh + + * share.c (parport_unregister_device): Remove unneeded locking + (test cad==dev). + (parport_claim): Likewise. + (parport_find_number): New function. + +2000-07-12 Tim Waugh + + * share.c (parport_register_port): Hold the parportlist_lock while + looking for a free parport number. + (parport_register_driver): Make sure that attach can block. + (attach_driver_chain): Likewise. + +2000-07-12 Tim Waugh + + * share.c (call_driver_chain): Do reference counting things. + (parport_get_port): New function. + (parport_put_port): New function. + (parport_register_port): Initialise reference count to zero. + (parport_unregister_port): Check reference count rather than + driver list to see if we can free the port. + +2000-07-12 Tim Waugh + + * share.c: Clarifications in doc comments. + +2000-07-12 Tim Waugh + + * share.c (parport_unregister_port): Fix typo in comment. + +2000-07-11 Gunther Mayer + + * parport_pc.c: Support for the full range of Timedia cards. + +2000-07-08 Tim Waugh + + * daisy.c: License block comments as part of parportbook. + * ieee1284.c: Likewise. + * share.c: Likewise. + +2000-06-30 Petr Vandrovec + + * procfs.c (do_hardware_modes): Generated string can be up to 34 + chars long. + +2000-06-20 Gunther Mayer + + * parport_pc.c (parport_pc_compat_write_block_pio): Warn about + change_mode failures. + (parport_pc_ecp_write_block_pio): Likewise. + (parport_pc_ecp_read_block_pio): Likewise. + +2000-06-20 Gunther Mayer + + * parport_pc.c (parport_SPP_supported): Warn more about possibly + incorrect parameters. + +2000-06-15 Tim Waugh + + * parport_pc.c (parport_ECP_supported): Set PARPORT_MODE_COMPAT + for ECP ports, since they can all do hardware accelerated + compatibility mode (I assume). + +2000-06-13 Tim Waugh + + * parport_pc.c (cleanup_module): Remark about possible bugs. + +2000-06-13 Tim Waugh + + * procfs.c: Break 'hardware' out into separate files. + +2000-05-28 Gunther Mayer + + * Fix PCI ID printk for non-superio PCI cards. + +2000-05-28 Tim Waugh + + * share.c (call_driver_chain): Get the driverlist_lock. + (parport_register_device): Make sure that port->devices always + looks consistent. + (parport_register_driver): Ensure that parport drivers are given + parameters that are valid for the duration of the callback by + locking the portlist against changes. + (parport_unregister_driver): Likewise. + (parport_claim): Don't overwrite flags. + +2000-05-28 Tim Waugh + + * daisy.c (assign_addrs): Avoid double-probing daisy-chain devices + if the first probe succeeds. + +2000-05-16 Tim Waugh + + * share.c (parport_claim): Fix SMP race. + +2000-05-15 Gunther Mayer + + * parport_pc.c (parport_pc_compat_write_block_pio): Check for + timeouts. + (parport_pc_ecp_write_block_pio): Likewise. + (parport_pc_ecp_read_block_pio): Likewise. + +2000-05-02 Gunther Mayer + + * parport_pc.c: PCI SYBA patch and verbose PCI detection. + +2000-05-02 Gunther Mayer + + * parport_pc.c (decode_smsc): Fix SMSC 665/666 identification. + +2000-04-28 Tim Waugh + + * ieee1284.c: Short function descriptions can't be multiline. + + * daisy.c: Short function descriptions can't be multiline. + +2000-04-19 Tim Waugh + + * parport_pc.c (parport_pc_fifo_write_block_dma): Make maxlen + calculation a bit clearer. + + * ieee1284.c (parport_negotiate): Turn on data line drivers. + + * ieee1284_ops.c (parport_ieee1284_read_byte): Turn off data line + drivers. + (parport_ieee1284_write_compat): Turn on data line drivers. + + * daisy.c (assign_addrs): Turn on data line drivers. + (cpp_mux): Likewise. + (cpp_daisy): Likewise. + +2000-04-04 Tim Waugh + + * parport_pc.c: Add support for another PCI card. + +2000-04-04 Tim Waugh + + * daisy.c: Documentation in kernel-doc format. + + * ieee1284.c: Likewise. + + * share.c: Likewise. + +2000-04-01 Tim Waugh + + * share.c (parport_register_device): Need to hold the module + reference counts before sleeping. + +2000-03-27 Tim Waugh + + * parport_pc.c (parport_pc_ecp_read_block_pio): Correct operation + when peripheral is trying to send data when we stop listening. + +2000-03-22 Tim Waugh + + * init.c (parport_setup): Fix return value. + +2000-03-21 Tim Waugh + + * parport_pc.c (parport_pc_pci_probe): Fix return value; call + pci_enable_device. + +2000-03-16 Tim Waugh + + * parport_pc.c (parport_ECP_supported): This seems to trigger on + machines that don't have an IRQ conflict; toned down the warning + message accordingly. + +2000-03-16 Gunther Mayer + + * parport_pc.c (show_parconfig_smsc37c669): Fix typo. + (decode_winbond): More IDs. + (winbond_check): Protect against false positives. + (winbond_check2): Likewise. + (smsc_check): Likewise. + +2000-03-15 Tim Waugh + + * parport_pc.c (cleanup_module): Don't call pci_unregister_driver + if we didn't call pci_register_driver first. + +2000-03-13 Tim Waugh + + * parport_pc.c (parport_pc_init): Moved from asm/parport.h. + + * Config.in: CONFIG_PARPORT_PC_SUPERIO: new option. + + * parport_pc.c (show_parconfig_smsc37c669): Make __devinit. + (show_parconfig_winbond): Likewise. + (decode_winbond): Likewise. + (decode_smsc): Likewise. + (winbond_check): Likewise. + (winbond_check2): Likewise. + (smsc_check): Likewise. + (detect_and_report_winbond): Likewise. + (detect_and_report_smsc): Likewise. + (get_superio_dma): Likewise. + (get_superio_irq): Likewise. + (parport_pc_find_isa_ports): New function. + (parport_pc_find_ports): New function. + (init_module): Make superio a config option, not a parameter. + +2000-03-10 Tim Waugh + + * parport_pc.c (decode_winbond): Use correct 83877ATF chip ID. + (decode_winbond): Fix typo. + +2000-03-09 Tim Waugh + + * parport_pc.c: Integrate SuperIO PCI probe with normal PCI card + probe, so that the MODULE_DEVICE_TABLE is complete. + diff --git a/drivers/parport/Kconfig b/drivers/parport/Kconfig new file mode 100644 index 000000000000..731010e0e6f6 --- /dev/null +++ b/drivers/parport/Kconfig @@ -0,0 +1,145 @@ +# +# For a description of the syntax of this configuration file, +# see Documentation/kbuild/kconfig-language.txt. +# +# Parport configuration. +# + +menu "Parallel port support" + +config PARPORT + tristate "Parallel port support" + ---help--- + If you want to use devices connected to your machine's parallel port + (the connector at the computer with 25 holes), e.g. printer, ZIP + drive, PLIP link (Parallel Line Internet Protocol is mainly used to + create a mini network by connecting the parallel ports of two local + machines) etc., then you need to say Y here; please read + and + . + + For extensive information about drivers for many devices attaching + to the parallel port see on + the WWW. + + It is possible to share a single parallel port among several devices + and it is safe to compile all the corresponding drivers into the + kernel. To compile parallel port support as a module, choose M here: + the module will be called parport. + If you have more than one parallel port and want to specify which + port and IRQ to be used by this driver at module load time, take a + look at . + + If unsure, say Y. + +config PARPORT_PC + tristate "PC-style hardware" + depends on PARPORT && (!SPARC64 || PCI) && (!SPARC32 || BROKEN) + ---help--- + You should say Y here if you have a PC-style parallel port. All + IBM PC compatible computers and some Alphas have PC-style + parallel ports. PA-RISC owners should only say Y here if they + have a SuperIO parallel port. + + To compile this driver as a module, choose M here: the + module will be called parport_pc. + + If unsure, say Y. + +config PARPORT_SERIAL + tristate "Multi-IO cards (parallel and serial)" + depends on SERIAL_8250 && PARPORT_PC && PCI + help + This adds support for multi-IO PCI cards that have parallel and + serial ports. You should say Y or M here. If you say M, the module + will be called parport_serial. + +config PARPORT_PC_FIFO + bool "Use FIFO/DMA if available (EXPERIMENTAL)" + depends on PARPORT_PC && EXPERIMENTAL + help + Many parallel port chipsets provide hardware that can speed up + printing. Say Y here if you want to take advantage of that. + + As well as actually having a FIFO, or DMA capability, the kernel + will need to know which IRQ the parallel port has. By default, + parallel port interrupts will not be used, and so neither will the + FIFO. See to find out how to + specify which IRQ/DMA to use. + +config PARPORT_PC_SUPERIO + bool "SuperIO chipset support (EXPERIMENTAL)" + depends on PARPORT_PC && EXPERIMENTAL + help + Saying Y here enables some probes for Super-IO chipsets in order to + find out things like base addresses, IRQ lines and DMA channels. It + is safe to say N. + +config PARPORT_PC_PCMCIA + tristate "Support for PCMCIA management for PC-style ports" + depends on PARPORT!=n && (PCMCIA!=n && PARPORT_PC=m && PARPORT_PC || PARPORT_PC=y && PCMCIA) + help + Say Y here if you need PCMCIA support for your PC-style parallel + ports. If unsure, say N. + +config PARPORT_NOT_PC + bool + +config PARPORT_ARC + tristate "Archimedes hardware" + depends on ARM && PARPORT + select PARPORT_NOT_PC + +config PARPORT_AMIGA + tristate "Amiga builtin port" + depends on AMIGA && PARPORT + select PARPORT_NOT_PC + help + Say Y here if you need support for the parallel port hardware on + Amiga machines. This code is also available as a module (say M), + called parport_amiga. If in doubt, saying N is the safe plan. + +config PARPORT_MFC3 + tristate "Multiface III parallel port" + depends on ZORRO && PARPORT + select PARPORT_NOT_PC + help + Say Y here if you need parallel port support for the MFC3 card. + This code is also available as a module (say M), called + parport_mfc3. If in doubt, saying N is the safe plan. + +config PARPORT_ATARI + tristate "Atari hardware" + depends on ATARI && PARPORT + select PARPORT_NOT_PC + help + Say Y here if you need support for the parallel port hardware on + Atari machines. This code is also available as a module (say M), + called parport_atari. If in doubt, saying N is the safe plan. + +config PARPORT_GSC + tristate + default GSC + depends on PARPORT + +config PARPORT_SUNBPP + tristate "Sparc hardware (EXPERIMENTAL)" + depends on SBUS && PARPORT && EXPERIMENTAL + select PARPORT_NOT_PC + help + This driver provides support for the bidirectional parallel port + found on many Sun machines. Note that many of the newer Ultras + actually have pc style hardware instead. + +config PARPORT_1284 + bool "IEEE 1284 transfer modes" + depends on PARPORT + help + If you have a printer that supports status readback or device ID, or + want to use a device that uses enhanced parallel port transfer modes + such as EPP and ECP, say Y here to enable advanced IEEE 1284 + transfer modes. Also say Y if you want device ID information to + appear in /proc/sys/dev/parport/*/autoprobe*. It is safe to say N. + +endmenu + diff --git a/drivers/parport/Makefile b/drivers/parport/Makefile new file mode 100644 index 000000000000..5372212bb9d9 --- /dev/null +++ b/drivers/parport/Makefile @@ -0,0 +1,19 @@ +# +# Makefile for the kernel Parallel port device drivers. +# + +parport-objs := share.o ieee1284.o ieee1284_ops.o procfs.o + +ifeq ($(CONFIG_PARPORT_1284),y) + parport-objs += daisy.o probe.o +endif + +obj-$(CONFIG_PARPORT) += parport.o +obj-$(CONFIG_PARPORT_PC) += parport_pc.o +obj-$(CONFIG_PARPORT_SERIAL) += parport_serial.o +obj-$(CONFIG_PARPORT_PC_PCMCIA) += parport_cs.o +obj-$(CONFIG_PARPORT_AMIGA) += parport_amiga.o +obj-$(CONFIG_PARPORT_MFC3) += parport_mfc3.o +obj-$(CONFIG_PARPORT_ATARI) += parport_atari.o +obj-$(CONFIG_PARPORT_SUNBPP) += parport_sunbpp.o +obj-$(CONFIG_PARPORT_GSC) += parport_gsc.o diff --git a/drivers/parport/TODO-parport b/drivers/parport/TODO-parport new file mode 100644 index 000000000000..089b14ee446f --- /dev/null +++ b/drivers/parport/TODO-parport @@ -0,0 +1,20 @@ +Things to be done. + +0. Fix the bugs (see BUGS-parport). + +1. Proper documentation. + +2. A better lp.c: + + a) ECP support would be nice. This can only work if both the port and + the printer support it. + + b) Handle status readback automatically. IEEE1284 printers can post status + bits when they have something to say. We should read out and deal + with (maybe just log) whatever the printer wants to tell the world. + +3. Support more hardware (eg m68k, Sun bpp). + +4. A better PLIP (make use of bidirectional/ECP/EPP ports). + +See . diff --git a/drivers/parport/daisy.c b/drivers/parport/daisy.c new file mode 100644 index 000000000000..075c7eb5c85d --- /dev/null +++ b/drivers/parport/daisy.c @@ -0,0 +1,512 @@ +/* + * IEEE 1284.3 Parallel port daisy chain and multiplexor code + * + * Copyright (C) 1999, 2000 Tim Waugh + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + * + * ??-12-1998: Initial implementation. + * 31-01-1999: Make port-cloning transparent. + * 13-02-1999: Move DeviceID technique from parport_probe. + * 13-03-1999: Get DeviceID from non-IEEE 1284.3 devices too. + * 22-02-2000: Count devices that are actually detected. + * + * Any part of this program may be used in documents licensed under + * the GNU Free Documentation License, Version 1.1 or any later version + * published by the Free Software Foundation. + */ + +#include +#include +#include +#include + +#include +#include + +#undef DEBUG + +#ifdef DEBUG +#define DPRINTK(stuff...) printk (stuff) +#else +#define DPRINTK(stuff...) +#endif + +static struct daisydev { + struct daisydev *next; + struct parport *port; + int daisy; + int devnum; +} *topology = NULL; +static DEFINE_SPINLOCK(topology_lock); + +static int numdevs = 0; + +/* Forward-declaration of lower-level functions. */ +static int mux_present (struct parport *port); +static int num_mux_ports (struct parport *port); +static int select_port (struct parport *port); +static int assign_addrs (struct parport *port); + +/* Add a device to the discovered topology. */ +static void add_dev (int devnum, struct parport *port, int daisy) +{ + struct daisydev *newdev, **p; + newdev = kmalloc (sizeof (struct daisydev), GFP_KERNEL); + if (newdev) { + newdev->port = port; + newdev->daisy = daisy; + newdev->devnum = devnum; + spin_lock(&topology_lock); + for (p = &topology; *p && (*p)->devnumnext) + ; + newdev->next = *p; + *p = newdev; + spin_unlock(&topology_lock); + } +} + +/* Clone a parport (actually, make an alias). */ +static struct parport *clone_parport (struct parport *real, int muxport) +{ + struct parport *extra = parport_register_port (real->base, + real->irq, + real->dma, + real->ops); + if (extra) { + extra->portnum = real->portnum; + extra->physport = real; + extra->muxport = muxport; + real->slaves[muxport-1] = extra; + } + + return extra; +} + +/* Discover the IEEE1284.3 topology on a port -- muxes and daisy chains. + * Return value is number of devices actually detected. */ +int parport_daisy_init (struct parport *port) +{ + int detected = 0; + char *deviceid; + static const char *th[] = { /*0*/"th", "st", "nd", "rd", "th" }; + int num_ports; + int i; + int last_try = 0; + +again: + /* Because this is called before any other devices exist, + * we don't have to claim exclusive access. */ + + /* If mux present on normal port, need to create new + * parports for each extra port. */ + if (port->muxport < 0 && mux_present (port) && + /* don't be fooled: a mux must have 2 or 4 ports. */ + ((num_ports = num_mux_ports (port)) == 2 || num_ports == 4)) { + /* Leave original as port zero. */ + port->muxport = 0; + printk (KERN_INFO + "%s: 1st (default) port of %d-way multiplexor\n", + port->name, num_ports); + for (i = 1; i < num_ports; i++) { + /* Clone the port. */ + struct parport *extra = clone_parport (port, i); + if (!extra) { + if (signal_pending (current)) + break; + + schedule (); + continue; + } + + printk (KERN_INFO + "%s: %d%s port of %d-way multiplexor on %s\n", + extra->name, i + 1, th[i + 1], num_ports, + port->name); + + /* Analyse that port too. We won't recurse + forever because of the 'port->muxport < 0' + test above. */ + parport_daisy_init(extra); + } + } + + if (port->muxport >= 0) + select_port (port); + + parport_daisy_deselect_all (port); + detected += assign_addrs (port); + + /* Count the potential legacy device at the end. */ + add_dev (numdevs++, port, -1); + + /* Find out the legacy device's IEEE 1284 device ID. */ + deviceid = kmalloc (1000, GFP_KERNEL); + if (deviceid) { + if (parport_device_id (numdevs - 1, deviceid, 1000) > 2) + detected++; + + kfree (deviceid); + } + + if (!detected && !last_try) { + /* No devices were detected. Perhaps they are in some + funny state; let's try to reset them and see if + they wake up. */ + parport_daisy_fini (port); + parport_write_control (port, PARPORT_CONTROL_SELECT); + udelay (50); + parport_write_control (port, + PARPORT_CONTROL_SELECT | + PARPORT_CONTROL_INIT); + udelay (50); + last_try = 1; + goto again; + } + + return detected; +} + +/* Forget about devices on a physical port. */ +void parport_daisy_fini (struct parport *port) +{ + struct daisydev **p; + + spin_lock(&topology_lock); + p = &topology; + while (*p) { + struct daisydev *dev = *p; + if (dev->port != port) { + p = &dev->next; + continue; + } + *p = dev->next; + kfree(dev); + } + + /* Gaps in the numbering could be handled better. How should + someone enumerate through all IEEE1284.3 devices in the + topology?. */ + if (!topology) numdevs = 0; + spin_unlock(&topology_lock); + return; +} + +/** + * parport_open - find a device by canonical device number + * @devnum: canonical device number + * @name: name to associate with the device + * @pf: preemption callback + * @kf: kick callback + * @irqf: interrupt handler + * @flags: registration flags + * @handle: driver data + * + * This function is similar to parport_register_device(), except + * that it locates a device by its number rather than by the port + * it is attached to. + * + * All parameters except for @devnum are the same as for + * parport_register_device(). The return value is the same as + * for parport_register_device(). + **/ + +struct pardevice *parport_open (int devnum, const char *name, + int (*pf) (void *), void (*kf) (void *), + void (*irqf) (int, void *, struct pt_regs *), + int flags, void *handle) +{ + struct daisydev *p = topology; + struct parport *port; + struct pardevice *dev; + int daisy; + + spin_lock(&topology_lock); + while (p && p->devnum != devnum) + p = p->next; + + if (!p) { + spin_unlock(&topology_lock); + return NULL; + } + + daisy = p->daisy; + port = parport_get_port(p->port); + spin_unlock(&topology_lock); + + dev = parport_register_device (port, name, pf, kf, + irqf, flags, handle); + parport_put_port(port); + if (!dev) + return NULL; + + dev->daisy = daisy; + + /* Check that there really is a device to select. */ + if (daisy >= 0) { + int selected; + parport_claim_or_block (dev); + selected = port->daisy; + parport_release (dev); + + if (selected != port->daisy) { + /* No corresponding device. */ + parport_unregister_device (dev); + return NULL; + } + } + + return dev; +} + +/** + * parport_close - close a device opened with parport_open() + * @dev: device to close + * + * This is to parport_open() as parport_unregister_device() is to + * parport_register_device(). + **/ + +void parport_close (struct pardevice *dev) +{ + parport_unregister_device (dev); +} + +/** + * parport_device_num - convert device coordinates + * @parport: parallel port number + * @mux: multiplexor port number (-1 for no multiplexor) + * @daisy: daisy chain address (-1 for no daisy chain address) + * + * This tries to locate a device on the given parallel port, + * multiplexor port and daisy chain address, and returns its + * device number or -NXIO if no device with those coordinates + * exists. + **/ + +int parport_device_num (int parport, int mux, int daisy) +{ + int res = -ENXIO; + struct daisydev *dev; + + spin_lock(&topology_lock); + dev = topology; + while (dev && dev->port->portnum != parport && + dev->port->muxport != mux && dev->daisy != daisy) + dev = dev->next; + if (dev) + res = dev->devnum; + spin_unlock(&topology_lock); + + return res; +} + +/* Send a daisy-chain-style CPP command packet. */ +static int cpp_daisy (struct parport *port, int cmd) +{ + unsigned char s; + + parport_data_forward (port); + parport_write_data (port, 0xaa); udelay (2); + parport_write_data (port, 0x55); udelay (2); + parport_write_data (port, 0x00); udelay (2); + parport_write_data (port, 0xff); udelay (2); + s = parport_read_status (port) & (PARPORT_STATUS_BUSY + | PARPORT_STATUS_PAPEROUT + | PARPORT_STATUS_SELECT + | PARPORT_STATUS_ERROR); + if (s != (PARPORT_STATUS_BUSY + | PARPORT_STATUS_PAPEROUT + | PARPORT_STATUS_SELECT + | PARPORT_STATUS_ERROR)) { + DPRINTK (KERN_DEBUG "%s: cpp_daisy: aa5500ff(%02x)\n", + port->name, s); + return -ENXIO; + } + + parport_write_data (port, 0x87); udelay (2); + s = parport_read_status (port) & (PARPORT_STATUS_BUSY + | PARPORT_STATUS_PAPEROUT + | PARPORT_STATUS_SELECT + | PARPORT_STATUS_ERROR); + if (s != (PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR)) { + DPRINTK (KERN_DEBUG "%s: cpp_daisy: aa5500ff87(%02x)\n", + port->name, s); + return -ENXIO; + } + + parport_write_data (port, 0x78); udelay (2); + parport_write_data (port, cmd); udelay (2); + parport_frob_control (port, + PARPORT_CONTROL_STROBE, + PARPORT_CONTROL_STROBE); + udelay (1); + parport_frob_control (port, PARPORT_CONTROL_STROBE, 0); + udelay (1); + s = parport_read_status (port); + parport_write_data (port, 0xff); udelay (2); + + return s; +} + +/* Send a mux-style CPP command packet. */ +static int cpp_mux (struct parport *port, int cmd) +{ + unsigned char s; + int rc; + + parport_data_forward (port); + parport_write_data (port, 0xaa); udelay (2); + parport_write_data (port, 0x55); udelay (2); + parport_write_data (port, 0xf0); udelay (2); + parport_write_data (port, 0x0f); udelay (2); + parport_write_data (port, 0x52); udelay (2); + parport_write_data (port, 0xad); udelay (2); + parport_write_data (port, cmd); udelay (2); + + s = parport_read_status (port); + if (!(s & PARPORT_STATUS_ACK)) { + DPRINTK (KERN_DEBUG "%s: cpp_mux: aa55f00f52ad%02x(%02x)\n", + port->name, cmd, s); + return -EIO; + } + + rc = (((s & PARPORT_STATUS_SELECT ? 1 : 0) << 0) | + ((s & PARPORT_STATUS_PAPEROUT ? 1 : 0) << 1) | + ((s & PARPORT_STATUS_BUSY ? 0 : 1) << 2) | + ((s & PARPORT_STATUS_ERROR ? 0 : 1) << 3)); + + return rc; +} + +void parport_daisy_deselect_all (struct parport *port) +{ + cpp_daisy (port, 0x30); +} + +int parport_daisy_select (struct parport *port, int daisy, int mode) +{ + switch (mode) + { + // For these modes we should switch to EPP mode: + case IEEE1284_MODE_EPP: + case IEEE1284_MODE_EPPSL: + case IEEE1284_MODE_EPPSWE: + return (cpp_daisy (port, 0x20 + daisy) & + PARPORT_STATUS_ERROR); + + // For these modes we should switch to ECP mode: + case IEEE1284_MODE_ECP: + case IEEE1284_MODE_ECPRLE: + case IEEE1284_MODE_ECPSWE: + return (cpp_daisy (port, 0xd0 + daisy) & + PARPORT_STATUS_ERROR); + + // Nothing was told for BECP in Daisy chain specification. + // May be it's wise to use ECP? + case IEEE1284_MODE_BECP: + // Others use compat mode + case IEEE1284_MODE_NIBBLE: + case IEEE1284_MODE_BYTE: + case IEEE1284_MODE_COMPAT: + default: + return (cpp_daisy (port, 0xe0 + daisy) & + PARPORT_STATUS_ERROR); + } +} + +static int mux_present (struct parport *port) +{ + return cpp_mux (port, 0x51) == 3; +} + +static int num_mux_ports (struct parport *port) +{ + return cpp_mux (port, 0x58); +} + +static int select_port (struct parport *port) +{ + int muxport = port->muxport; + return cpp_mux (port, 0x60 + muxport) == muxport; +} + +static int assign_addrs (struct parport *port) +{ + unsigned char s, last_dev; + unsigned char daisy; + int thisdev = numdevs; + int detected; + char *deviceid; + + parport_data_forward (port); + parport_write_data (port, 0xaa); udelay (2); + parport_write_data (port, 0x55); udelay (2); + parport_write_data (port, 0x00); udelay (2); + parport_write_data (port, 0xff); udelay (2); + s = parport_read_status (port) & (PARPORT_STATUS_BUSY + | PARPORT_STATUS_PAPEROUT + | PARPORT_STATUS_SELECT + | PARPORT_STATUS_ERROR); + if (s != (PARPORT_STATUS_BUSY + | PARPORT_STATUS_PAPEROUT + | PARPORT_STATUS_SELECT + | PARPORT_STATUS_ERROR)) { + DPRINTK (KERN_DEBUG "%s: assign_addrs: aa5500ff(%02x)\n", + port->name, s); + return 0; + } + + parport_write_data (port, 0x87); udelay (2); + s = parport_read_status (port) & (PARPORT_STATUS_BUSY + | PARPORT_STATUS_PAPEROUT + | PARPORT_STATUS_SELECT + | PARPORT_STATUS_ERROR); + if (s != (PARPORT_STATUS_SELECT | PARPORT_STATUS_ERROR)) { + DPRINTK (KERN_DEBUG "%s: assign_addrs: aa5500ff87(%02x)\n", + port->name, s); + return 0; + } + + parport_write_data (port, 0x78); udelay (2); + last_dev = 0; /* We've just been speaking to a device, so we + know there must be at least _one_ out there. */ + + for (daisy = 0; daisy < 4; daisy++) { + parport_write_data (port, daisy); + udelay (2); + parport_frob_control (port, + PARPORT_CONTROL_STROBE, + PARPORT_CONTROL_STROBE); + udelay (1); + parport_frob_control (port, PARPORT_CONTROL_STROBE, 0); + udelay (1); + + if (last_dev) + /* No more devices. */ + break; + + last_dev = !(parport_read_status (port) + & PARPORT_STATUS_BUSY); + + add_dev (numdevs++, port, daisy); + } + + parport_write_data (port, 0xff); udelay (2); + detected = numdevs - thisdev; + DPRINTK (KERN_DEBUG "%s: Found %d daisy-chained devices\n", port->name, + detected); + + /* Ask the new devices to introduce themselves. */ + deviceid = kmalloc (1000, GFP_KERNEL); + if (!deviceid) return 0; + + for (daisy = 0; thisdev < numdevs; thisdev++, daisy++) + parport_device_id (thisdev, deviceid, 1000); + + kfree (deviceid); + return detected; +} diff --git a/drivers/parport/ieee1284.c b/drivers/parport/ieee1284.c new file mode 100644 index 000000000000..694bae162fed --- /dev/null +++ b/drivers/parport/ieee1284.c @@ -0,0 +1,819 @@ +/* $Id: parport_ieee1284.c,v 1.4 1997/10/19 21:37:21 philip Exp $ + * IEEE-1284 implementation for parport. + * + * Authors: Phil Blundell + * Carsten Gross + * Jose Renau + * Tim Waugh (largely rewritten) + * + * This file is responsible for IEEE 1284 negotiation, and for handing + * read/write requests to low-level drivers. + * + * Any part of this program may be used in documents licensed under + * the GNU Free Documentation License, Version 1.1 or any later version + * published by the Free Software Foundation. + * + * Various hacks, Fred Barnes , 04/2000 + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#undef DEBUG /* undef me for production */ + +#ifdef CONFIG_LP_CONSOLE +#undef DEBUG /* Don't want a garbled console */ +#endif + +#ifdef DEBUG +#define DPRINTK(stuff...) printk (stuff) +#else +#define DPRINTK(stuff...) +#endif + +/* Make parport_wait_peripheral wake up. + * It will be useful to call this from an interrupt handler. */ +static void parport_ieee1284_wakeup (struct parport *port) +{ + up (&port->physport->ieee1284.irq); +} + +static struct parport *port_from_cookie[PARPORT_MAX]; +static void timeout_waiting_on_port (unsigned long cookie) +{ + parport_ieee1284_wakeup (port_from_cookie[cookie % PARPORT_MAX]); +} + +/** + * parport_wait_event - wait for an event on a parallel port + * @port: port to wait on + * @timeout: time to wait (in jiffies) + * + * This function waits for up to @timeout jiffies for an + * interrupt to occur on a parallel port. If the port timeout is + * set to zero, it returns immediately. + * + * If an interrupt occurs before the timeout period elapses, this + * function returns one immediately. If it times out, it returns + * a value greater than zero. An error code less than zero + * indicates an error (most likely a pending signal), and the + * calling code should finish what it's doing as soon as it can. + */ + +int parport_wait_event (struct parport *port, signed long timeout) +{ + int ret; + struct timer_list timer; + + if (!port->physport->cad->timeout) + /* Zero timeout is special, and we can't down() the + semaphore. */ + return 1; + + init_timer (&timer); + timer.expires = jiffies + timeout; + timer.function = timeout_waiting_on_port; + port_from_cookie[port->number % PARPORT_MAX] = port; + timer.data = port->number; + + add_timer (&timer); + ret = down_interruptible (&port->physport->ieee1284.irq); + if (!del_timer (&timer) && !ret) + /* Timed out. */ + ret = 1; + + return ret; +} + +/** + * parport_poll_peripheral - poll status lines + * @port: port to watch + * @mask: status lines to watch + * @result: desired values of chosen status lines + * @usec: timeout + * + * This function busy-waits until the masked status lines have + * the desired values, or until the timeout period elapses. The + * @mask and @result parameters are bitmasks, with the bits + * defined by the constants in parport.h: %PARPORT_STATUS_BUSY, + * and so on. + * + * This function does not call schedule(); instead it busy-waits + * using udelay(). It currently has a resolution of 5usec. + * + * If the status lines take on the desired values before the + * timeout period elapses, parport_poll_peripheral() returns zero + * immediately. A zero return value greater than zero indicates + * a timeout. An error code (less than zero) indicates an error, + * most likely a signal that arrived, and the caller should + * finish what it is doing as soon as possible. +*/ + +int parport_poll_peripheral(struct parport *port, + unsigned char mask, + unsigned char result, + int usec) +{ + /* Zero return code is success, >0 is timeout. */ + int count = usec / 5 + 2; + int i; + unsigned char status; + for (i = 0; i < count; i++) { + status = parport_read_status (port); + if ((status & mask) == result) + return 0; + if (signal_pending (current)) + return -EINTR; + if (need_resched()) + break; + if (i >= 2) + udelay (5); + } + + return 1; +} + +/** + * parport_wait_peripheral - wait for status lines to change in 35ms + * @port: port to watch + * @mask: status lines to watch + * @result: desired values of chosen status lines + * + * This function waits until the masked status lines have the + * desired values, or until 35ms have elapsed (see IEEE 1284-1994 + * page 24 to 25 for why this value in particular is hardcoded). + * The @mask and @result parameters are bitmasks, with the bits + * defined by the constants in parport.h: %PARPORT_STATUS_BUSY, + * and so on. + * + * The port is polled quickly to start off with, in anticipation + * of a fast response from the peripheral. This fast polling + * time is configurable (using /proc), and defaults to 500usec. + * If the timeout for this port (see parport_set_timeout()) is + * zero, the fast polling time is 35ms, and this function does + * not call schedule(). + * + * If the timeout for this port is non-zero, after the fast + * polling fails it uses parport_wait_event() to wait for up to + * 10ms, waking up if an interrupt occurs. + */ + +int parport_wait_peripheral(struct parport *port, + unsigned char mask, + unsigned char result) +{ + int ret; + int usec; + unsigned long deadline; + unsigned char status; + + usec = port->physport->spintime; /* usecs of fast polling */ + if (!port->physport->cad->timeout) + /* A zero timeout is "special": busy wait for the + entire 35ms. */ + usec = 35000; + + /* Fast polling. + * + * This should be adjustable. + * How about making a note (in the device structure) of how long + * it takes, so we know for next time? + */ + ret = parport_poll_peripheral (port, mask, result, usec); + if (ret != 1) + return ret; + + if (!port->physport->cad->timeout) + /* We may be in an interrupt handler, so we can't poll + * slowly anyway. */ + return 1; + + /* 40ms of slow polling. */ + deadline = jiffies + (HZ + 24) / 25; + while (time_before (jiffies, deadline)) { + int ret; + + if (signal_pending (current)) + return -EINTR; + + /* Wait for 10ms (or until an interrupt occurs if + * the handler is set) */ + if ((ret = parport_wait_event (port, (HZ + 99) / 100)) < 0) + return ret; + + status = parport_read_status (port); + if ((status & mask) == result) + return 0; + + if (!ret) { + /* parport_wait_event didn't time out, but the + * peripheral wasn't actually ready either. + * Wait for another 10ms. */ + __set_current_state (TASK_INTERRUPTIBLE); + schedule_timeout ((HZ+ 99) / 100); + } + } + + return 1; +} + +#ifdef CONFIG_PARPORT_1284 +/* Terminate a negotiated mode. */ +static void parport_ieee1284_terminate (struct parport *port) +{ + int r; + port = port->physport; + + /* EPP terminates differently. */ + switch (port->ieee1284.mode) { + case IEEE1284_MODE_EPP: + case IEEE1284_MODE_EPPSL: + case IEEE1284_MODE_EPPSWE: + /* Terminate from EPP mode. */ + + /* Event 68: Set nInit low */ + parport_frob_control (port, PARPORT_CONTROL_INIT, 0); + udelay (50); + + /* Event 69: Set nInit high, nSelectIn low */ + parport_frob_control (port, + PARPORT_CONTROL_SELECT + | PARPORT_CONTROL_INIT, + PARPORT_CONTROL_SELECT + | PARPORT_CONTROL_INIT); + break; + + case IEEE1284_MODE_ECP: + case IEEE1284_MODE_ECPRLE: + case IEEE1284_MODE_ECPSWE: + /* In ECP we can only terminate from fwd idle phase. */ + if (port->ieee1284.phase != IEEE1284_PH_FWD_IDLE) { + /* Event 47: Set nInit high */ + parport_frob_control (port, + PARPORT_CONTROL_INIT + | PARPORT_CONTROL_AUTOFD, + PARPORT_CONTROL_INIT + | PARPORT_CONTROL_AUTOFD); + + /* Event 49: PError goes high */ + r = parport_wait_peripheral (port, + PARPORT_STATUS_PAPEROUT, + PARPORT_STATUS_PAPEROUT); + if (r) + DPRINTK (KERN_INFO "%s: Timeout at event 49\n", + port->name); + + parport_data_forward (port); + DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n", + port->name); + port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; + } + + /* fall-though.. */ + + default: + /* Terminate from all other modes. */ + + /* Event 22: Set nSelectIn low, nAutoFd high */ + parport_frob_control (port, + PARPORT_CONTROL_SELECT + | PARPORT_CONTROL_AUTOFD, + PARPORT_CONTROL_SELECT); + + /* Event 24: nAck goes low */ + r = parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0); + if (r) + DPRINTK (KERN_INFO "%s: Timeout at event 24\n", + port->name); + + /* Event 25: Set nAutoFd low */ + parport_frob_control (port, + PARPORT_CONTROL_AUTOFD, + PARPORT_CONTROL_AUTOFD); + + /* Event 27: nAck goes high */ + r = parport_wait_peripheral (port, + PARPORT_STATUS_ACK, + PARPORT_STATUS_ACK); + if (r) + DPRINTK (KERN_INFO "%s: Timeout at event 27\n", + port->name); + + /* Event 29: Set nAutoFd high */ + parport_frob_control (port, PARPORT_CONTROL_AUTOFD, 0); + } + + port->ieee1284.mode = IEEE1284_MODE_COMPAT; + port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; + + DPRINTK (KERN_DEBUG "%s: In compatibility (forward idle) mode\n", + port->name); +} +#endif /* IEEE1284 support */ + +/** + * parport_negotiate - negotiate an IEEE 1284 mode + * @port: port to use + * @mode: mode to negotiate to + * + * Use this to negotiate to a particular IEEE 1284 transfer mode. + * The @mode parameter should be one of the constants in + * parport.h starting %IEEE1284_MODE_xxx. + * + * The return value is 0 if the peripheral has accepted the + * negotiation to the mode specified, -1 if the peripheral is not + * IEEE 1284 compliant (or not present), or 1 if the peripheral + * has rejected the negotiation. + */ + +int parport_negotiate (struct parport *port, int mode) +{ +#ifndef CONFIG_PARPORT_1284 + if (mode == IEEE1284_MODE_COMPAT) + return 0; + printk (KERN_ERR "parport: IEEE1284 not supported in this kernel\n"); + return -1; +#else + int m = mode & ~IEEE1284_ADDR; + int r; + unsigned char xflag; + + port = port->physport; + + /* Is there anything to do? */ + if (port->ieee1284.mode == mode) + return 0; + + /* Is the difference just an address-or-not bit? */ + if ((port->ieee1284.mode & ~IEEE1284_ADDR) == (mode & ~IEEE1284_ADDR)){ + port->ieee1284.mode = mode; + return 0; + } + + /* Go to compability forward idle mode */ + if (port->ieee1284.mode != IEEE1284_MODE_COMPAT) + parport_ieee1284_terminate (port); + + if (mode == IEEE1284_MODE_COMPAT) + /* Compatibility mode: no negotiation. */ + return 0; + + switch (mode) { + case IEEE1284_MODE_ECPSWE: + m = IEEE1284_MODE_ECP; + break; + case IEEE1284_MODE_EPPSL: + case IEEE1284_MODE_EPPSWE: + m = IEEE1284_MODE_EPP; + break; + case IEEE1284_MODE_BECP: + return -ENOSYS; /* FIXME (implement BECP) */ + } + + if (mode & IEEE1284_EXT_LINK) + m = 1<<7; /* request extensibility link */ + + port->ieee1284.phase = IEEE1284_PH_NEGOTIATION; + + /* Start off with nStrobe and nAutoFd high, and nSelectIn low */ + parport_frob_control (port, + PARPORT_CONTROL_STROBE + | PARPORT_CONTROL_AUTOFD + | PARPORT_CONTROL_SELECT, + PARPORT_CONTROL_SELECT); + udelay(1); + + /* Event 0: Set data */ + parport_data_forward (port); + parport_write_data (port, m); + udelay (400); /* Shouldn't need to wait this long. */ + + /* Event 1: Set nSelectIn high, nAutoFd low */ + parport_frob_control (port, + PARPORT_CONTROL_SELECT + | PARPORT_CONTROL_AUTOFD, + PARPORT_CONTROL_AUTOFD); + + /* Event 2: PError, Select, nFault go high, nAck goes low */ + if (parport_wait_peripheral (port, + PARPORT_STATUS_ERROR + | PARPORT_STATUS_SELECT + | PARPORT_STATUS_PAPEROUT + | PARPORT_STATUS_ACK, + PARPORT_STATUS_ERROR + | PARPORT_STATUS_SELECT + | PARPORT_STATUS_PAPEROUT)) { + /* Timeout */ + parport_frob_control (port, + PARPORT_CONTROL_SELECT + | PARPORT_CONTROL_AUTOFD, + PARPORT_CONTROL_SELECT); + DPRINTK (KERN_DEBUG + "%s: Peripheral not IEEE1284 compliant (0x%02X)\n", + port->name, parport_read_status (port)); + port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; + return -1; /* Not IEEE1284 compliant */ + } + + /* Event 3: Set nStrobe low */ + parport_frob_control (port, + PARPORT_CONTROL_STROBE, + PARPORT_CONTROL_STROBE); + + /* Event 4: Set nStrobe and nAutoFd high */ + udelay (5); + parport_frob_control (port, + PARPORT_CONTROL_STROBE + | PARPORT_CONTROL_AUTOFD, + 0); + + /* Event 6: nAck goes high */ + if (parport_wait_peripheral (port, + PARPORT_STATUS_ACK, + PARPORT_STATUS_ACK)) { + /* This shouldn't really happen with a compliant device. */ + DPRINTK (KERN_DEBUG + "%s: Mode 0x%02x not supported? (0x%02x)\n", + port->name, mode, port->ops->read_status (port)); + parport_ieee1284_terminate (port); + return 1; + } + + xflag = parport_read_status (port) & PARPORT_STATUS_SELECT; + + /* xflag should be high for all modes other than nibble (0). */ + if (mode && !xflag) { + /* Mode not supported. */ + DPRINTK (KERN_DEBUG "%s: Mode 0x%02x rejected by peripheral\n", + port->name, mode); + parport_ieee1284_terminate (port); + return 1; + } + + /* More to do if we've requested extensibility link. */ + if (mode & IEEE1284_EXT_LINK) { + m = mode & 0x7f; + udelay (1); + parport_write_data (port, m); + udelay (1); + + /* Event 51: Set nStrobe low */ + parport_frob_control (port, + PARPORT_CONTROL_STROBE, + PARPORT_CONTROL_STROBE); + + /* Event 52: nAck goes low */ + if (parport_wait_peripheral (port, PARPORT_STATUS_ACK, 0)) { + /* This peripheral is _very_ slow. */ + DPRINTK (KERN_DEBUG + "%s: Event 52 didn't happen\n", + port->name); + parport_ieee1284_terminate (port); + return 1; + } + + /* Event 53: Set nStrobe high */ + parport_frob_control (port, + PARPORT_CONTROL_STROBE, + 0); + + /* Event 55: nAck goes high */ + if (parport_wait_peripheral (port, + PARPORT_STATUS_ACK, + PARPORT_STATUS_ACK)) { + /* This shouldn't really happen with a compliant + * device. */ + DPRINTK (KERN_DEBUG + "%s: Mode 0x%02x not supported? (0x%02x)\n", + port->name, mode, + port->ops->read_status (port)); + parport_ieee1284_terminate (port); + return 1; + } + + /* Event 54: Peripheral sets XFlag to reflect support */ + xflag = parport_read_status (port) & PARPORT_STATUS_SELECT; + + /* xflag should be high. */ + if (!xflag) { + /* Extended mode not supported. */ + DPRINTK (KERN_DEBUG "%s: Extended mode 0x%02x not " + "supported\n", port->name, mode); + parport_ieee1284_terminate (port); + return 1; + } + + /* Any further setup is left to the caller. */ + } + + /* Mode is supported */ + DPRINTK (KERN_DEBUG "%s: In mode 0x%02x\n", port->name, mode); + port->ieee1284.mode = mode; + + /* But ECP is special */ + if (!(mode & IEEE1284_EXT_LINK) && (m & IEEE1284_MODE_ECP)) { + port->ieee1284.phase = IEEE1284_PH_ECP_SETUP; + + /* Event 30: Set nAutoFd low */ + parport_frob_control (port, + PARPORT_CONTROL_AUTOFD, + PARPORT_CONTROL_AUTOFD); + + /* Event 31: PError goes high. */ + r = parport_wait_peripheral (port, + PARPORT_STATUS_PAPEROUT, + PARPORT_STATUS_PAPEROUT); + if (r) { + DPRINTK (KERN_INFO "%s: Timeout at event 31\n", + port->name); + } + + port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; + DPRINTK (KERN_DEBUG "%s: ECP direction: forward\n", + port->name); + } else switch (mode) { + case IEEE1284_MODE_NIBBLE: + case IEEE1284_MODE_BYTE: + port->ieee1284.phase = IEEE1284_PH_REV_IDLE; + break; + default: + port->ieee1284.phase = IEEE1284_PH_FWD_IDLE; + } + + + return 0; +#endif /* IEEE1284 support */ +} + +/* Acknowledge that the peripheral has data available. + * Events 18-20, in order to get from Reverse Idle phase + * to Host Busy Data Available. + * This will most likely be called from an interrupt. + * Returns zero if data was available. + */ +#ifdef CONFIG_PARPORT_1284 +static int parport_ieee1284_ack_data_avail (struct parport *port) +{ + if (parport_read_status (port) & PARPORT_STATUS_ERROR) + /* Event 18 didn't happen. */ + return -1; + + /* Event 20: nAutoFd goes high. */ + port->ops->frob_control (port, PARPORT_CONTROL_AUTOFD, 0); + port->ieee1284.phase = IEEE1284_PH_HBUSY_DAVAIL; + return 0; +} +#endif /* IEEE1284 support */ + +/* Handle an interrupt. */ +void parport_ieee1284_interrupt (int which, void *handle, struct pt_regs *regs) +{ + struct parport *port = handle; + parport_ieee1284_wakeup (port); + +#ifdef CONFIG_PARPORT_1284 + if (port->ieee1284.phase == IEEE1284_PH_REV_IDLE) { + /* An interrupt in this phase means that data + * is now available. */ + DPRINTK (KERN_DEBUG "%s: Data available\n", port->name); + parport_ieee1284_ack_data_avail (port); + } +#endif /* IEEE1284 support */ +} + +/** + * parport_write - write a block of data to a parallel port + * @port: port to write to + * @buffer: data buffer (in kernel space) + * @len: number of bytes of data to transfer + * + * This will write up to @len bytes of @buffer to the port + * specified, using the IEEE 1284 transfer mode most recently + * negotiated to (using parport_negotiate()), as long as that + * mode supports forward transfers (host to peripheral). + * + * It is the caller's responsibility to ensure that the first + * @len bytes of @buffer are valid. + * + * This function returns the number of bytes transferred (if zero + * or positive), or else an error code. + */ + +ssize_t parport_write (struct parport *port, const void *buffer, size_t len) +{ +#ifndef CONFIG_PARPORT_1284 + return port->ops->compat_write_data (port, buffer, len, 0); +#else + ssize_t retval; + int mode = port->ieee1284.mode; + int addr = mode & IEEE1284_ADDR; + size_t (*fn) (struct parport *, const void *, size_t, int); + + /* Ignore the device-ID-request bit and the address bit. */ + mode &= ~(IEEE1284_DEVICEID | IEEE1284_ADDR); + + /* Use the mode we're in. */ + switch (mode) { + case IEEE1284_MODE_NIBBLE: + case IEEE1284_MODE_BYTE: + parport_negotiate (port, IEEE1284_MODE_COMPAT); + case IEEE1284_MODE_COMPAT: + DPRINTK (KERN_DEBUG "%s: Using compatibility mode\n", + port->name); + fn = port->ops->compat_write_data; + break; + + case IEEE1284_MODE_EPP: + DPRINTK (KERN_DEBUG "%s: Using EPP mode\n", port->name); + if (addr) { + fn = port->ops->epp_write_addr; + } else { + fn = port->ops->epp_write_data; + } + break; + case IEEE1284_MODE_EPPSWE: + DPRINTK (KERN_DEBUG "%s: Using software-emulated EPP mode\n", + port->name); + if (addr) { + fn = parport_ieee1284_epp_write_addr; + } else { + fn = parport_ieee1284_epp_write_data; + } + break; + case IEEE1284_MODE_ECP: + case IEEE1284_MODE_ECPRLE: + DPRINTK (KERN_DEBUG "%s: Using ECP mode\n", port->name); + if (addr) { + fn = port->ops->ecp_write_addr; + } else { + fn = port->ops->ecp_write_data; + } + break; + + case IEEE1284_MODE_ECPSWE: + DPRINTK (KERN_DEBUG "%s: Using software-emulated ECP mode\n", + port->name); + /* The caller has specified that it must be emulated, + * even if we have ECP hardware! */ + if (addr) { + fn = parport_ieee1284_ecp_write_addr; + } else { + fn = parport_ieee1284_ecp_write_data; + } + break; + + default: + DPRINTK (KERN_DEBUG "%s: Unknown mode 0x%02x\n", port->name, + port->ieee1284.mode); + return -ENOSYS; + } + + retval = (*fn) (port, buffer, len, 0); + DPRINTK (KERN_DEBUG "%s: wrote %d/%d bytes\n", port->name, retval, len); + return retval; +#endif /* IEEE1284 support */ +} + +/** + * parport_read - read a block of data from a parallel port + * @port: port to read from + * @buffer: data buffer (in kernel space) + * @len: number of bytes of data to transfer + * + * This will read up to @len bytes of @buffer to the port + * specified, using the IEEE 1284 transfer mode most recently + * negotiated to (using parport_negotiate()), as long as that + * mode supports reverse transfers (peripheral to host). + * + * It is the caller's responsibility to ensure that the first + * @len bytes of @buffer are available to write to. + * + * This function returns the number of bytes transferred (if zero + * or positive), or else an error code. + */ + +ssize_t parport_read (struct parport *port, void *buffer, size_t len) +{ +#ifndef CONFIG_PARPORT_1284 + printk (KERN_ERR "parport: IEEE1284 not supported in this kernel\n"); + return -ENODEV; +#else + int mode = port->physport->ieee1284.mode; + int addr = mode & IEEE1284_ADDR; + size_t (*fn) (struct parport *, void *, size_t, int); + + /* Ignore the device-ID-request bit and the address bit. */ + mode &= ~(IEEE1284_DEVICEID | IEEE1284_ADDR); + + /* Use the mode we're in. */ + switch (mode) { + case IEEE1284_MODE_COMPAT: + /* if we can tri-state use BYTE mode instead of NIBBLE mode, + * if that fails, revert to NIBBLE mode -- ought to store somewhere + * the device's ability to do BYTE mode reverse transfers, so we don't + * end up needlessly calling negotiate(BYTE) repeately.. (fb) + */ + if ((port->physport->modes & PARPORT_MODE_TRISTATE) && + !parport_negotiate (port, IEEE1284_MODE_BYTE)) { + /* got into BYTE mode OK */ + DPRINTK (KERN_DEBUG "%s: Using byte mode\n", port->name); + fn = port->ops->byte_read_data; + break; + } + if (parport_negotiate (port, IEEE1284_MODE_NIBBLE)) { + return -EIO; + } + /* fall through to NIBBLE */ + case IEEE1284_MODE_NIBBLE: + DPRINTK (KERN_DEBUG "%s: Using nibble mode\n", port->name);