2017-11-03 17:28:30 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2005-04-17 05:20:36 +07:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* uss720.c -- USS720 USB Parport Cable.
|
|
|
|
*
|
2010-12-14 22:04:05 +07:00
|
|
|
* Copyright (C) 1999, 2005, 2010
|
2005-09-09 15:43:50 +07:00
|
|
|
* Thomas Sailer (t.sailer@alumni.ethz.ch)
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
* Based on parport_pc.c
|
|
|
|
*
|
|
|
|
* History:
|
2005-09-09 15:43:50 +07:00
|
|
|
* 0.1 04.08.1999 Created
|
|
|
|
* 0.2 07.08.1999 Some fixes mainly suggested by Tim Waugh
|
|
|
|
* Interrupt handling currently disabled because
|
|
|
|
* usb_request_irq crashes somewhere within ohci.c
|
|
|
|
* for no apparent reason (that is for me, anyway)
|
|
|
|
* ECP currently untested
|
|
|
|
* 0.3 10.08.1999 fixing merge errors
|
|
|
|
* 0.4 13.08.1999 Added Vendor/Product ID of Brad Hard's cable
|
|
|
|
* 0.5 20.09.1999 usb_control_msg wrapper used
|
|
|
|
* Nov01.2000 usb_device_table support by Adam J. Richter
|
|
|
|
* 08.04.2001 Identify version on module load. gb
|
|
|
|
* 0.6 02.09.2005 Fix "scheduling in interrupt" problem by making save/restore
|
|
|
|
* context asynchronous
|
2005-04-17 05:20:36 +07:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/socket.h>
|
|
|
|
#include <linux/parport.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
#include <linux/delay.h>
|
2005-09-09 15:43:50 +07:00
|
|
|
#include <linux/completion.h>
|
|
|
|
#include <linux/kref.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 15:04:11 +07:00
|
|
|
#include <linux/slab.h>
|
2017-02-03 01:15:33 +07:00
|
|
|
#include <linux/sched/signal.h>
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-09-09 15:43:50 +07:00
|
|
|
#define DRIVER_AUTHOR "Thomas M. Sailer, t.sailer@alumni.ethz.ch"
|
2005-04-17 05:20:36 +07:00
|
|
|
#define DRIVER_DESC "USB Parport Cable driver for Cables using the Lucent Technologies USS720 Chip"
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
struct parport_uss720_private {
|
|
|
|
struct usb_device *usbdev;
|
2005-09-09 15:43:50 +07:00
|
|
|
struct parport *pp;
|
|
|
|
struct kref ref_count;
|
|
|
|
__u8 reg[7]; /* USB registers */
|
|
|
|
struct list_head asynclist;
|
|
|
|
spinlock_t asynclock;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uss720_async_request {
|
|
|
|
struct parport_uss720_private *priv;
|
|
|
|
struct kref ref_count;
|
|
|
|
struct list_head asynclist;
|
|
|
|
struct completion compl;
|
|
|
|
struct urb *urb;
|
2013-08-13 18:27:40 +07:00
|
|
|
struct usb_ctrlrequest *dr;
|
2005-09-09 15:43:50 +07:00
|
|
|
__u8 reg[7];
|
2005-04-17 05:20:36 +07:00
|
|
|
};
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2005-09-09 15:43:50 +07:00
|
|
|
static void destroy_priv(struct kref *kref)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-09-09 15:43:50 +07:00
|
|
|
struct parport_uss720_private *priv = container_of(kref, struct parport_uss720_private, ref_count);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-05-02 11:34:07 +07:00
|
|
|
dev_dbg(&priv->usbdev->dev, "destroying priv datastructure\n");
|
2005-09-09 15:43:50 +07:00
|
|
|
usb_put_dev(priv->usbdev);
|
|
|
|
kfree(priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void destroy_async(struct kref *kref)
|
|
|
|
{
|
|
|
|
struct uss720_async_request *rq = container_of(kref, struct uss720_async_request, ref_count);
|
|
|
|
struct parport_uss720_private *priv = rq->priv;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
if (likely(rq->urb))
|
|
|
|
usb_free_urb(rq->urb);
|
2013-08-13 18:27:40 +07:00
|
|
|
kfree(rq->dr);
|
2005-09-09 15:43:50 +07:00
|
|
|
spin_lock_irqsave(&priv->asynclock, flags);
|
|
|
|
list_del_init(&rq->asynclist);
|
|
|
|
spin_unlock_irqrestore(&priv->asynclock, flags);
|
|
|
|
kfree(rq);
|
|
|
|
kref_put(&priv->ref_count, destroy_priv);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
IRQ: Maintain regs pointer globally rather than passing to IRQ handlers
Maintain a per-CPU global "struct pt_regs *" variable which can be used instead
of passing regs around manually through all ~1800 interrupt handlers in the
Linux kernel.
The regs pointer is used in few places, but it potentially costs both stack
space and code to pass it around. On the FRV arch, removing the regs parameter
from all the genirq function results in a 20% speed up of the IRQ exit path
(ie: from leaving timer_interrupt() to leaving do_IRQ()).
Where appropriate, an arch may override the generic storage facility and do
something different with the variable. On FRV, for instance, the address is
maintained in GR28 at all times inside the kernel as part of general exception
handling.
Having looked over the code, it appears that the parameter may be handed down
through up to twenty or so layers of functions. Consider a USB character
device attached to a USB hub, attached to a USB controller that posts its
interrupts through a cascaded auxiliary interrupt controller. A character
device driver may want to pass regs to the sysrq handler through the input
layer which adds another few layers of parameter passing.
I've build this code with allyesconfig for x86_64 and i386. I've runtested the
main part of the code on FRV and i386, though I can't test most of the drivers.
I've also done partial conversion for powerpc and MIPS - these at least compile
with minimal configurations.
This will affect all archs. Mostly the changes should be relatively easy.
Take do_IRQ(), store the regs pointer at the beginning, saving the old one:
struct pt_regs *old_regs = set_irq_regs(regs);
And put the old one back at the end:
set_irq_regs(old_regs);
Don't pass regs through to generic_handle_irq() or __do_IRQ().
In timer_interrupt(), this sort of change will be necessary:
- update_process_times(user_mode(regs));
- profile_tick(CPU_PROFILING, regs);
+ update_process_times(user_mode(get_irq_regs()));
+ profile_tick(CPU_PROFILING);
I'd like to move update_process_times()'s use of get_irq_regs() into itself,
except that i386, alone of the archs, uses something other than user_mode().
Some notes on the interrupt handling in the drivers:
(*) input_dev() is now gone entirely. The regs pointer is no longer stored in
the input_dev struct.
(*) finish_unlinks() in drivers/usb/host/ohci-q.c needs checking. It does
something different depending on whether it's been supplied with a regs
pointer or not.
(*) Various IRQ handler function pointers have been moved to type
irq_handler_t.
Signed-Off-By: David Howells <dhowells@redhat.com>
(cherry picked from 1b16e7ac850969f38b375e511e3fa2f474a33867 commit)
2006-10-05 20:55:46 +07:00
|
|
|
static void async_complete(struct urb *urb)
|
2005-09-09 15:43:50 +07:00
|
|
|
{
|
|
|
|
struct uss720_async_request *rq;
|
|
|
|
struct parport *pp;
|
|
|
|
struct parport_uss720_private *priv;
|
2007-07-19 00:58:02 +07:00
|
|
|
int status = urb->status;
|
2005-09-09 15:43:50 +07:00
|
|
|
|
|
|
|
rq = urb->context;
|
|
|
|
priv = rq->priv;
|
|
|
|
pp = priv->pp;
|
2007-07-19 00:58:02 +07:00
|
|
|
if (status) {
|
2012-04-21 06:53:53 +07:00
|
|
|
dev_err(&urb->dev->dev, "async_complete: urb error %d\n",
|
|
|
|
status);
|
2013-08-13 18:27:40 +07:00
|
|
|
} else if (rq->dr->bRequest == 3) {
|
2005-09-09 15:43:50 +07:00
|
|
|
memcpy(priv->reg, rq->reg, sizeof(priv->reg));
|
2005-04-17 05:20:36 +07:00
|
|
|
#if 0
|
2014-12-29 19:35:29 +07:00
|
|
|
dev_dbg(&priv->usbdev->dev, "async_complete regs %7ph\n",
|
|
|
|
priv->reg);
|
2005-04-17 05:20:36 +07:00
|
|
|
#endif
|
|
|
|
/* if nAck interrupts are enabled and we have an interrupt, call the interrupt procedure */
|
2005-09-09 15:43:50 +07:00
|
|
|
if (rq->reg[2] & rq->reg[1] & 0x10 && pp)
|
2007-10-19 12:56:02 +07:00
|
|
|
parport_generic_irq(pp);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2005-09-09 15:43:50 +07:00
|
|
|
complete(&rq->compl);
|
|
|
|
kref_put(&rq->ref_count, destroy_async);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
2005-09-09 15:43:50 +07:00
|
|
|
static struct uss720_async_request *submit_async_request(struct parport_uss720_private *priv,
|
|
|
|
__u8 request, __u8 requesttype, __u16 value, __u16 index,
|
2005-10-21 14:21:58 +07:00
|
|
|
gfp_t mem_flags)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2005-09-09 15:43:50 +07:00
|
|
|
struct usb_device *usbdev;
|
|
|
|
struct uss720_async_request *rq;
|
|
|
|
unsigned long flags;
|
2005-04-17 05:20:36 +07:00
|
|
|
int ret;
|
|
|
|
|
2005-09-09 15:43:50 +07:00
|
|
|
if (!priv)
|
|
|
|
return NULL;
|
|
|
|
usbdev = priv->usbdev;
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!usbdev)
|
2005-09-09 15:43:50 +07:00
|
|
|
return NULL;
|
2013-08-13 18:27:40 +07:00
|
|
|
rq = kzalloc(sizeof(struct uss720_async_request), mem_flags);
|
2016-08-26 00:39:24 +07:00
|
|
|
if (!rq)
|
2005-09-09 15:43:50 +07:00
|
|
|
return NULL;
|
|
|
|
kref_init(&rq->ref_count);
|
|
|
|
INIT_LIST_HEAD(&rq->asynclist);
|
|
|
|
init_completion(&rq->compl);
|
|
|
|
kref_get(&priv->ref_count);
|
|
|
|
rq->priv = priv;
|
|
|
|
rq->urb = usb_alloc_urb(0, mem_flags);
|
|
|
|
if (!rq->urb) {
|
|
|
|
kref_put(&rq->ref_count, destroy_async);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-08-13 18:27:40 +07:00
|
|
|
rq->dr = kmalloc(sizeof(*rq->dr), mem_flags);
|
|
|
|
if (!rq->dr) {
|
|
|
|
kref_put(&rq->ref_count, destroy_async);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
rq->dr->bRequestType = requesttype;
|
|
|
|
rq->dr->bRequest = request;
|
|
|
|
rq->dr->wValue = cpu_to_le16(value);
|
|
|
|
rq->dr->wIndex = cpu_to_le16(index);
|
|
|
|
rq->dr->wLength = cpu_to_le16((request == 3) ? sizeof(rq->reg) : 0);
|
2005-09-09 15:43:50 +07:00
|
|
|
usb_fill_control_urb(rq->urb, usbdev, (requesttype & 0x80) ? usb_rcvctrlpipe(usbdev, 0) : usb_sndctrlpipe(usbdev, 0),
|
2013-08-13 18:27:40 +07:00
|
|
|
(unsigned char *)rq->dr,
|
2005-09-09 15:43:50 +07:00
|
|
|
(request == 3) ? rq->reg : NULL, (request == 3) ? sizeof(rq->reg) : 0, async_complete, rq);
|
|
|
|
/* rq->urb->transfer_flags |= URB_ASYNC_UNLINK; */
|
|
|
|
spin_lock_irqsave(&priv->asynclock, flags);
|
|
|
|
list_add_tail(&rq->asynclist, &priv->asynclist);
|
|
|
|
spin_unlock_irqrestore(&priv->asynclock, flags);
|
2011-03-19 00:47:44 +07:00
|
|
|
kref_get(&rq->ref_count);
|
2005-09-09 15:43:50 +07:00
|
|
|
ret = usb_submit_urb(rq->urb, mem_flags);
|
2011-03-19 00:47:44 +07:00
|
|
|
if (!ret)
|
2005-09-09 15:43:50 +07:00
|
|
|
return rq;
|
2011-03-19 00:47:44 +07:00
|
|
|
destroy_async(&rq->ref_count);
|
2012-04-21 06:53:53 +07:00
|
|
|
dev_err(&usbdev->dev, "submit_async_request submit_urb failed with %d\n", ret);
|
2005-09-09 15:43:50 +07:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned int kill_all_async_requests_priv(struct parport_uss720_private *priv)
|
|
|
|
{
|
|
|
|
struct uss720_async_request *rq;
|
|
|
|
unsigned long flags;
|
|
|
|
unsigned int ret = 0;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&priv->asynclock, flags);
|
|
|
|
list_for_each_entry(rq, &priv->asynclist, asynclist) {
|
|
|
|
usb_unlink_urb(rq->urb);
|
|
|
|
ret++;
|
|
|
|
}
|
|
|
|
spin_unlock_irqrestore(&priv->asynclock, flags);
|
2005-04-17 05:20:36 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2005-10-21 14:21:58 +07:00
|
|
|
static int get_1284_register(struct parport *pp, unsigned char reg, unsigned char *val, gfp_t mem_flags)
|
2005-09-09 15:43:50 +07:00
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv;
|
|
|
|
struct uss720_async_request *rq;
|
|
|
|
static const unsigned char regindex[9] = {
|
|
|
|
4, 0, 1, 5, 5, 0, 2, 3, 6
|
|
|
|
};
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!pp)
|
|
|
|
return -EIO;
|
|
|
|
priv = pp->private_data;
|
|
|
|
rq = submit_async_request(priv, 3, 0xc0, ((unsigned int)reg) << 8, 0, mem_flags);
|
|
|
|
if (!rq) {
|
2012-04-21 06:53:53 +07:00
|
|
|
dev_err(&priv->usbdev->dev, "get_1284_register(%u) failed",
|
|
|
|
(unsigned int)reg);
|
2005-09-09 15:43:50 +07:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
if (!val) {
|
|
|
|
kref_put(&rq->ref_count, destroy_async);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
if (wait_for_completion_timeout(&rq->compl, HZ)) {
|
|
|
|
ret = rq->urb->status;
|
|
|
|
*val = priv->reg[(reg >= 9) ? 0 : regindex[reg]];
|
|
|
|
if (ret)
|
2008-08-14 23:37:34 +07:00
|
|
|
printk(KERN_WARNING "get_1284_register: "
|
|
|
|
"usb error %d\n", ret);
|
2005-09-09 15:43:50 +07:00
|
|
|
kref_put(&rq->ref_count, destroy_async);
|
|
|
|
return ret;
|
|
|
|
}
|
2008-08-14 23:37:34 +07:00
|
|
|
printk(KERN_WARNING "get_1284_register timeout\n");
|
2005-09-09 15:43:50 +07:00
|
|
|
kill_all_async_requests_priv(priv);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
2005-10-21 14:21:58 +07:00
|
|
|
static int set_1284_register(struct parport *pp, unsigned char reg, unsigned char val, gfp_t mem_flags)
|
2005-09-09 15:43:50 +07:00
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv;
|
|
|
|
struct uss720_async_request *rq;
|
|
|
|
|
|
|
|
if (!pp)
|
|
|
|
return -EIO;
|
|
|
|
priv = pp->private_data;
|
|
|
|
rq = submit_async_request(priv, 4, 0x40, (((unsigned int)reg) << 8) | val, 0, mem_flags);
|
|
|
|
if (!rq) {
|
2012-04-21 06:53:53 +07:00
|
|
|
dev_err(&priv->usbdev->dev, "set_1284_register(%u,%u) failed",
|
|
|
|
(unsigned int)reg, (unsigned int)val);
|
2005-09-09 15:43:50 +07:00
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
kref_put(&rq->ref_count, destroy_async);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/* ECR modes */
|
|
|
|
#define ECR_SPP 00
|
|
|
|
#define ECR_PS2 01
|
|
|
|
#define ECR_PPF 02
|
|
|
|
#define ECR_ECP 03
|
|
|
|
#define ECR_EPP 04
|
|
|
|
|
|
|
|
/* Safely change the mode bits in the ECR */
|
|
|
|
static int change_mode(struct parport *pp, int m)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
int mode;
|
2005-09-09 15:43:50 +07:00
|
|
|
__u8 reg;
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2005-09-09 15:43:50 +07:00
|
|
|
if (get_1284_register(pp, 6, ®, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
return -EIO;
|
|
|
|
/* Bits <7:5> contain the mode. */
|
|
|
|
mode = (priv->reg[2] >> 5) & 0x7;
|
|
|
|
if (mode == m)
|
|
|
|
return 0;
|
|
|
|
/* We have to go through mode 000 or 001 */
|
|
|
|
if (mode > ECR_PS2 && m > ECR_PS2)
|
|
|
|
if (change_mode(pp, ECR_PS2))
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
if (m <= ECR_PS2 && !(priv->reg[1] & 0x20)) {
|
|
|
|
/* This mode resets the FIFO, so we may
|
|
|
|
* have to wait for it to drain first. */
|
|
|
|
unsigned long expire = jiffies + pp->physport->cad->timeout;
|
|
|
|
switch (mode) {
|
|
|
|
case ECR_PPF: /* Parallel Port FIFO mode */
|
|
|
|
case ECR_ECP: /* ECP Parallel Port mode */
|
|
|
|
/* Poll slowly. */
|
|
|
|
for (;;) {
|
2005-09-09 15:43:50 +07:00
|
|
|
if (get_1284_register(pp, 6, ®, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
return -EIO;
|
|
|
|
if (priv->reg[2] & 0x01)
|
|
|
|
break;
|
|
|
|
if (time_after_eq (jiffies, expire))
|
|
|
|
/* The FIFO is stuck. */
|
|
|
|
return -EBUSY;
|
|
|
|
msleep_interruptible(10);
|
|
|
|
if (signal_pending (current))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Set the mode. */
|
2005-09-09 15:43:50 +07:00
|
|
|
if (set_1284_register(pp, 6, m << 5, GFP_KERNEL))
|
|
|
|
return -EIO;
|
|
|
|
if (get_1284_register(pp, 6, ®, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
return -EIO;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear TIMEOUT BIT in EPP MODE
|
|
|
|
*/
|
|
|
|
static int clear_epp_timeout(struct parport *pp)
|
|
|
|
{
|
|
|
|
unsigned char stat;
|
|
|
|
|
2005-09-09 15:43:50 +07:00
|
|
|
if (get_1284_register(pp, 1, &stat, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
return 1;
|
|
|
|
return stat & 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Access functions.
|
|
|
|
*/
|
|
|
|
#if 0
|
|
|
|
static int uss720_irq(int usbstatus, void *buffer, int len, void *dev_id)
|
|
|
|
{
|
|
|
|
struct parport *pp = (struct parport *)dev_id;
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
|
|
|
|
if (usbstatus != 0 || len < 4 || !buffer)
|
|
|
|
return 1;
|
|
|
|
memcpy(priv->reg, buffer, 4);
|
|
|
|
/* if nAck interrupts are enabled and we have an interrupt, call the interrupt procedure */
|
|
|
|
if (priv->reg[2] & priv->reg[1] & 0x10)
|
2007-10-19 12:56:02 +07:00
|
|
|
parport_generic_irq(pp);
|
2005-04-17 05:20:36 +07:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static void parport_uss720_write_data(struct parport *pp, unsigned char d)
|
|
|
|
{
|
2005-09-09 15:43:50 +07:00
|
|
|
set_1284_register(pp, 0, d, GFP_KERNEL);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char parport_uss720_read_data(struct parport *pp)
|
|
|
|
{
|
|
|
|
unsigned char ret;
|
|
|
|
|
2005-09-09 15:43:50 +07:00
|
|
|
if (get_1284_register(pp, 0, &ret, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parport_uss720_write_control(struct parport *pp, unsigned char d)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
|
|
|
|
d = (d & 0xf) | (priv->reg[1] & 0xf0);
|
2005-09-09 15:43:50 +07:00
|
|
|
if (set_1284_register(pp, 2, d, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
priv->reg[1] = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char parport_uss720_read_control(struct parport *pp)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
return priv->reg[1] & 0xf; /* Use soft copy */
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char parport_uss720_frob_control(struct parport *pp, unsigned char mask, unsigned char val)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
unsigned char d;
|
|
|
|
|
|
|
|
mask &= 0x0f;
|
|
|
|
val &= 0x0f;
|
|
|
|
d = (priv->reg[1] & (~mask)) ^ val;
|
usb: misc: uss720: Fix two sleep-in-atomic-context bugs
async_complete() in uss720.c is a completion handler function for the
USB driver. So it should not sleep, but it is can sleep according to the
function call paths (from bottom to top) in Linux-4.16.
[FUNC] set_1284_register(GFP_KERNEL)
drivers/usb/misc/uss720.c, 372:
set_1284_register in parport_uss720_frob_control
drivers/parport/ieee1284.c, 560:
[FUNC_PTR]parport_uss720_frob_control in parport_ieee1284_ack_data_avail
drivers/parport/ieee1284.c, 577:
parport_ieee1284_ack_data_avail in parport_ieee1284_interrupt
./include/linux/parport.h, 474:
parport_ieee1284_interrupt in parport_generic_irq
drivers/usb/misc/uss720.c, 116:
parport_generic_irq in async_complete
[FUNC] get_1284_register(GFP_KERNEL)
drivers/usb/misc/uss720.c, 382:
get_1284_register in parport_uss720_read_status
drivers/parport/ieee1284.c, 555:
[FUNC_PTR]parport_uss720_read_status in parport_ieee1284_ack_data_avail
drivers/parport/ieee1284.c, 577:
parport_ieee1284_ack_data_avail in parport_ieee1284_interrupt
./include/linux/parport.h, 474:
parport_ieee1284_interrupt in parport_generic_irq
drivers/usb/misc/uss720.c, 116:
parport_generic_irq in async_complete
Note that [FUNC_PTR] means a function pointer call is used.
To fix these bugs, GFP_KERNEL is replaced with GFP_ATOMIC.
These bugs are found by my static analysis tool DSAC.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-01 15:25:08 +07:00
|
|
|
if (set_1284_register(pp, 2, d, GFP_ATOMIC))
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
priv->reg[1] = d;
|
|
|
|
return d & 0xf;
|
|
|
|
}
|
|
|
|
|
|
|
|
static unsigned char parport_uss720_read_status(struct parport *pp)
|
|
|
|
{
|
|
|
|
unsigned char ret;
|
|
|
|
|
usb: misc: uss720: Fix two sleep-in-atomic-context bugs
async_complete() in uss720.c is a completion handler function for the
USB driver. So it should not sleep, but it is can sleep according to the
function call paths (from bottom to top) in Linux-4.16.
[FUNC] set_1284_register(GFP_KERNEL)
drivers/usb/misc/uss720.c, 372:
set_1284_register in parport_uss720_frob_control
drivers/parport/ieee1284.c, 560:
[FUNC_PTR]parport_uss720_frob_control in parport_ieee1284_ack_data_avail
drivers/parport/ieee1284.c, 577:
parport_ieee1284_ack_data_avail in parport_ieee1284_interrupt
./include/linux/parport.h, 474:
parport_ieee1284_interrupt in parport_generic_irq
drivers/usb/misc/uss720.c, 116:
parport_generic_irq in async_complete
[FUNC] get_1284_register(GFP_KERNEL)
drivers/usb/misc/uss720.c, 382:
get_1284_register in parport_uss720_read_status
drivers/parport/ieee1284.c, 555:
[FUNC_PTR]parport_uss720_read_status in parport_ieee1284_ack_data_avail
drivers/parport/ieee1284.c, 577:
parport_ieee1284_ack_data_avail in parport_ieee1284_interrupt
./include/linux/parport.h, 474:
parport_ieee1284_interrupt in parport_generic_irq
drivers/usb/misc/uss720.c, 116:
parport_generic_irq in async_complete
Note that [FUNC_PTR] means a function pointer call is used.
To fix these bugs, GFP_KERNEL is replaced with GFP_ATOMIC.
These bugs are found by my static analysis tool DSAC.
Signed-off-by: Jia-Ju Bai <baijiaju1990@gmail.com>
Cc: stable <stable@vger.kernel.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-09-01 15:25:08 +07:00
|
|
|
if (get_1284_register(pp, 1, &ret, GFP_ATOMIC))
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
return ret & 0xf8;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parport_uss720_disable_irq(struct parport *pp)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
unsigned char d;
|
|
|
|
|
|
|
|
d = priv->reg[1] & ~0x10;
|
2005-09-09 15:43:50 +07:00
|
|
|
if (set_1284_register(pp, 2, d, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
priv->reg[1] = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parport_uss720_enable_irq(struct parport *pp)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
unsigned char d;
|
|
|
|
|
|
|
|
d = priv->reg[1] | 0x10;
|
2005-09-09 15:43:50 +07:00
|
|
|
if (set_1284_register(pp, 2, d, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
priv->reg[1] = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parport_uss720_data_forward (struct parport *pp)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
unsigned char d;
|
|
|
|
|
|
|
|
d = priv->reg[1] & ~0x20;
|
2005-09-09 15:43:50 +07:00
|
|
|
if (set_1284_register(pp, 2, d, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
priv->reg[1] = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parport_uss720_data_reverse (struct parport *pp)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
unsigned char d;
|
|
|
|
|
|
|
|
d = priv->reg[1] | 0x20;
|
2005-09-09 15:43:50 +07:00
|
|
|
if (set_1284_register(pp, 2, d, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
|
|
|
priv->reg[1] = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parport_uss720_init_state(struct pardevice *dev, struct parport_state *s)
|
|
|
|
{
|
|
|
|
s->u.pc.ctr = 0xc | (dev->irq_func ? 0x10 : 0x0);
|
|
|
|
s->u.pc.ecr = 0x24;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parport_uss720_save_state(struct parport *pp, struct parport_state *s)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
|
2005-09-09 15:43:50 +07:00
|
|
|
#if 0
|
|
|
|
if (get_1284_register(pp, 2, NULL, GFP_ATOMIC))
|
2005-04-17 05:20:36 +07:00
|
|
|
return;
|
2005-09-09 15:43:50 +07:00
|
|
|
#endif
|
2005-04-17 05:20:36 +07:00
|
|
|
s->u.pc.ctr = priv->reg[1];
|
|
|
|
s->u.pc.ecr = priv->reg[2];
|
|
|
|
}
|
|
|
|
|
|
|
|
static void parport_uss720_restore_state(struct parport *pp, struct parport_state *s)
|
|
|
|
{
|
2005-09-09 15:43:50 +07:00
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
|
|
|
|
set_1284_register(pp, 2, s->u.pc.ctr, GFP_ATOMIC);
|
|
|
|
set_1284_register(pp, 6, s->u.pc.ecr, GFP_ATOMIC);
|
|
|
|
get_1284_register(pp, 2, NULL, GFP_ATOMIC);
|
|
|
|
priv->reg[1] = s->u.pc.ctr;
|
|
|
|
priv->reg[2] = s->u.pc.ecr;
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static size_t parport_uss720_epp_read_data(struct parport *pp, void *buf, size_t length, int flags)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
size_t got = 0;
|
|
|
|
|
|
|
|
if (change_mode(pp, ECR_EPP))
|
|
|
|
return 0;
|
|
|
|
for (; got < length; got++) {
|
2005-09-09 15:43:50 +07:00
|
|
|
if (get_1284_register(pp, 4, (char *)buf, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
buf++;
|
|
|
|
if (priv->reg[0] & 0x01) {
|
|
|
|
clear_epp_timeout(pp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
change_mode(pp, ECR_PS2);
|
|
|
|
return got;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t parport_uss720_epp_write_data(struct parport *pp, const void *buf, size_t length, int flags)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
size_t written = 0;
|
|
|
|
|
|
|
|
if (change_mode(pp, ECR_EPP))
|
|
|
|
return 0;
|
|
|
|
for (; written < length; written++) {
|
2005-09-09 15:43:50 +07:00
|
|
|
if (set_1284_register(pp, 4, (char *)buf, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
((char*)buf)++;
|
2005-09-09 15:43:50 +07:00
|
|
|
if (get_1284_register(pp, 1, NULL, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
if (priv->reg[0] & 0x01) {
|
|
|
|
clear_epp_timeout(pp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
change_mode(pp, ECR_PS2);
|
|
|
|
return written;
|
|
|
|
#else
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
struct usb_device *usbdev = priv->usbdev;
|
|
|
|
int rlen;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!usbdev)
|
|
|
|
return 0;
|
|
|
|
if (change_mode(pp, ECR_EPP))
|
|
|
|
return 0;
|
|
|
|
i = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (void *)buf, length, &rlen, 20000);
|
|
|
|
if (i)
|
2017-02-28 05:30:02 +07:00
|
|
|
printk(KERN_ERR "uss720: sendbulk ep 1 buf %p len %zu rlen %u\n", buf, length, rlen);
|
2005-04-17 05:20:36 +07:00
|
|
|
change_mode(pp, ECR_PS2);
|
|
|
|
return rlen;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t parport_uss720_epp_read_addr(struct parport *pp, void *buf, size_t length, int flags)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
size_t got = 0;
|
|
|
|
|
|
|
|
if (change_mode(pp, ECR_EPP))
|
|
|
|
return 0;
|
|
|
|
for (; got < length; got++) {
|
2005-09-09 15:43:50 +07:00
|
|
|
if (get_1284_register(pp, 3, (char *)buf, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
buf++;
|
|
|
|
if (priv->reg[0] & 0x01) {
|
|
|
|
clear_epp_timeout(pp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
change_mode(pp, ECR_PS2);
|
|
|
|
return got;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t parport_uss720_epp_write_addr(struct parport *pp, const void *buf, size_t length, int flags)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
size_t written = 0;
|
|
|
|
|
|
|
|
if (change_mode(pp, ECR_EPP))
|
|
|
|
return 0;
|
|
|
|
for (; written < length; written++) {
|
2005-09-09 15:43:50 +07:00
|
|
|
if (set_1284_register(pp, 3, *(char *)buf, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
buf++;
|
2005-09-09 15:43:50 +07:00
|
|
|
if (get_1284_register(pp, 1, NULL, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
if (priv->reg[0] & 0x01) {
|
|
|
|
clear_epp_timeout(pp);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
change_mode(pp, ECR_PS2);
|
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t parport_uss720_ecp_write_data(struct parport *pp, const void *buffer, size_t len, int flags)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
struct usb_device *usbdev = priv->usbdev;
|
|
|
|
int rlen;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!usbdev)
|
|
|
|
return 0;
|
|
|
|
if (change_mode(pp, ECR_ECP))
|
|
|
|
return 0;
|
|
|
|
i = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (void *)buffer, len, &rlen, 20000);
|
|
|
|
if (i)
|
2017-02-28 05:30:02 +07:00
|
|
|
printk(KERN_ERR "uss720: sendbulk ep 1 buf %p len %zu rlen %u\n", buffer, len, rlen);
|
2005-04-17 05:20:36 +07:00
|
|
|
change_mode(pp, ECR_PS2);
|
|
|
|
return rlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t parport_uss720_ecp_read_data(struct parport *pp, void *buffer, size_t len, int flags)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
struct usb_device *usbdev = priv->usbdev;
|
|
|
|
int rlen;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!usbdev)
|
|
|
|
return 0;
|
|
|
|
if (change_mode(pp, ECR_ECP))
|
|
|
|
return 0;
|
|
|
|
i = usb_bulk_msg(usbdev, usb_rcvbulkpipe(usbdev, 2), buffer, len, &rlen, 20000);
|
|
|
|
if (i)
|
2017-02-28 05:30:02 +07:00
|
|
|
printk(KERN_ERR "uss720: recvbulk ep 2 buf %p len %zu rlen %u\n", buffer, len, rlen);
|
2005-04-17 05:20:36 +07:00
|
|
|
change_mode(pp, ECR_PS2);
|
|
|
|
return rlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t parport_uss720_ecp_write_addr(struct parport *pp, const void *buffer, size_t len, int flags)
|
|
|
|
{
|
|
|
|
size_t written = 0;
|
|
|
|
|
|
|
|
if (change_mode(pp, ECR_ECP))
|
|
|
|
return 0;
|
|
|
|
for (; written < len; written++) {
|
2005-09-09 15:43:50 +07:00
|
|
|
if (set_1284_register(pp, 5, *(char *)buffer, GFP_KERNEL))
|
2005-04-17 05:20:36 +07:00
|
|
|
break;
|
|
|
|
buffer++;
|
|
|
|
}
|
|
|
|
change_mode(pp, ECR_PS2);
|
|
|
|
return written;
|
|
|
|
}
|
|
|
|
|
|
|
|
static size_t parport_uss720_write_compat(struct parport *pp, const void *buffer, size_t len, int flags)
|
|
|
|
{
|
|
|
|
struct parport_uss720_private *priv = pp->private_data;
|
|
|
|
struct usb_device *usbdev = priv->usbdev;
|
|
|
|
int rlen;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!usbdev)
|
|
|
|
return 0;
|
|
|
|
if (change_mode(pp, ECR_PPF))
|
|
|
|
return 0;
|
|
|
|
i = usb_bulk_msg(usbdev, usb_sndbulkpipe(usbdev, 1), (void *)buffer, len, &rlen, 20000);
|
|
|
|
if (i)
|
2017-02-28 05:30:02 +07:00
|
|
|
printk(KERN_ERR "uss720: sendbulk ep 1 buf %p len %zu rlen %u\n", buffer, len, rlen);
|
2005-04-17 05:20:36 +07:00
|
|
|
change_mode(pp, ECR_PS2);
|
|
|
|
return rlen;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static struct parport_operations parport_uss720_ops =
|
|
|
|
{
|
|
|
|
.owner = THIS_MODULE,
|
|
|
|
.write_data = parport_uss720_write_data,
|
|
|
|
.read_data = parport_uss720_read_data,
|
|
|
|
|
|
|
|
.write_control = parport_uss720_write_control,
|
|
|
|
.read_control = parport_uss720_read_control,
|
|
|
|
.frob_control = parport_uss720_frob_control,
|
|
|
|
|
|
|
|
.read_status = parport_uss720_read_status,
|
|
|
|
|
|
|
|
.enable_irq = parport_uss720_enable_irq,
|
|
|
|
.disable_irq = parport_uss720_disable_irq,
|
|
|
|
|
|
|
|
.data_forward = parport_uss720_data_forward,
|
|
|
|
.data_reverse = parport_uss720_data_reverse,
|
|
|
|
|
|
|
|
.init_state = parport_uss720_init_state,
|
|
|
|
.save_state = parport_uss720_save_state,
|
|
|
|
.restore_state = parport_uss720_restore_state,
|
|
|
|
|
|
|
|
.epp_write_data = parport_uss720_epp_write_data,
|
|
|
|
.epp_read_data = parport_uss720_epp_read_data,
|
|
|
|
.epp_write_addr = parport_uss720_epp_write_addr,
|
|
|
|
.epp_read_addr = parport_uss720_epp_read_addr,
|
|
|
|
|
|
|
|
.ecp_write_data = parport_uss720_ecp_write_data,
|
|
|
|
.ecp_read_data = parport_uss720_ecp_read_data,
|
|
|
|
.ecp_write_addr = parport_uss720_ecp_write_addr,
|
|
|
|
|
|
|
|
.compat_write_data = parport_uss720_write_compat,
|
|
|
|
.nibble_read_data = parport_ieee1284_read_nibble,
|
|
|
|
.byte_read_data = parport_ieee1284_read_byte,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
static int uss720_probe(struct usb_interface *intf,
|
|
|
|
const struct usb_device_id *id)
|
|
|
|
{
|
2005-09-09 15:43:50 +07:00
|
|
|
struct usb_device *usbdev = usb_get_dev(interface_to_usbdev(intf));
|
2005-04-17 05:20:36 +07:00
|
|
|
struct usb_host_interface *interface;
|
2017-03-17 17:35:44 +07:00
|
|
|
struct usb_endpoint_descriptor *epd;
|
2005-04-17 05:20:36 +07:00
|
|
|
struct parport_uss720_private *priv;
|
|
|
|
struct parport *pp;
|
2005-09-09 15:43:50 +07:00
|
|
|
unsigned char reg;
|
2005-04-17 05:20:36 +07:00
|
|
|
int i;
|
|
|
|
|
2012-05-02 11:34:07 +07:00
|
|
|
dev_dbg(&intf->dev, "probe: vendor id 0x%x, device id 0x%x\n",
|
|
|
|
le16_to_cpu(usbdev->descriptor.idVendor),
|
|
|
|
le16_to_cpu(usbdev->descriptor.idProduct));
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
/* our known interfaces have 3 alternate settings */
|
2005-09-09 15:43:50 +07:00
|
|
|
if (intf->num_altsetting != 3) {
|
|
|
|
usb_put_dev(usbdev);
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENODEV;
|
2005-09-09 15:43:50 +07:00
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
i = usb_set_interface(usbdev, intf->altsetting->desc.bInterfaceNumber, 2);
|
2013-03-16 18:53:05 +07:00
|
|
|
dev_dbg(&intf->dev, "set interface result %d\n", i);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
|
|
|
interface = intf->cur_altsetting;
|
|
|
|
|
2017-03-13 19:47:50 +07:00
|
|
|
if (interface->desc.bNumEndpoints < 3) {
|
|
|
|
usb_put_dev(usbdev);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* Allocate parport interface
|
|
|
|
*/
|
2015-04-30 16:33:07 +07:00
|
|
|
priv = kzalloc(sizeof(struct parport_uss720_private), GFP_KERNEL);
|
|
|
|
if (!priv) {
|
2005-09-09 15:43:50 +07:00
|
|
|
usb_put_dev(usbdev);
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENOMEM;
|
2005-09-09 15:43:50 +07:00
|
|
|
}
|
|
|
|
priv->pp = NULL;
|
|
|
|
priv->usbdev = usbdev;
|
|
|
|
kref_init(&priv->ref_count);
|
|
|
|
spin_lock_init(&priv->asynclock);
|
|
|
|
INIT_LIST_HEAD(&priv->asynclist);
|
2015-04-30 16:33:07 +07:00
|
|
|
pp = parport_register_port(0, PARPORT_IRQ_NONE, PARPORT_DMA_NONE, &parport_uss720_ops);
|
|
|
|
if (!pp) {
|
2008-08-14 23:37:34 +07:00
|
|
|
printk(KERN_WARNING "uss720: could not register parport\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
goto probe_abort;
|
|
|
|
}
|
|
|
|
|
2005-09-09 15:43:50 +07:00
|
|
|
priv->pp = pp;
|
2005-04-17 05:20:36 +07:00
|
|
|
pp->private_data = priv;
|
|
|
|
pp->modes = PARPORT_MODE_PCSPP | PARPORT_MODE_TRISTATE | PARPORT_MODE_EPP | PARPORT_MODE_ECP | PARPORT_MODE_COMPAT;
|
|
|
|
|
|
|
|
/* set the USS720 control register to manual mode, no ECP compression, enable all ints */
|
2005-09-09 15:43:50 +07:00
|
|
|
set_1284_register(pp, 7, 0x00, GFP_KERNEL);
|
|
|
|
set_1284_register(pp, 6, 0x30, GFP_KERNEL); /* PS/2 mode */
|
|
|
|
set_1284_register(pp, 2, 0x0c, GFP_KERNEL);
|
2005-04-17 05:20:36 +07:00
|
|
|
/* debugging */
|
2005-09-09 15:43:50 +07:00
|
|
|
get_1284_register(pp, 0, ®, GFP_KERNEL);
|
2014-12-29 19:35:29 +07:00
|
|
|
dev_dbg(&intf->dev, "reg: %7ph\n", priv->reg);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2017-03-17 17:35:44 +07:00
|
|
|
i = usb_find_last_int_in_endpoint(interface, &epd);
|
|
|
|
if (!i) {
|
|
|
|
dev_dbg(&intf->dev, "epaddr %d interval %d\n",
|
|
|
|
epd->bEndpointAddress, epd->bInterval);
|
|
|
|
}
|
2005-04-17 05:20:36 +07:00
|
|
|
parport_announce_port(pp);
|
|
|
|
|
2005-09-09 15:43:50 +07:00
|
|
|
usb_set_intfdata(intf, pp);
|
2005-04-17 05:20:36 +07:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
probe_abort:
|
2005-09-09 15:43:50 +07:00
|
|
|
kill_all_async_requests_priv(priv);
|
|
|
|
kref_put(&priv->ref_count, destroy_priv);
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void uss720_disconnect(struct usb_interface *intf)
|
|
|
|
{
|
2005-09-09 15:43:50 +07:00
|
|
|
struct parport *pp = usb_get_intfdata(intf);
|
2005-04-17 05:20:36 +07:00
|
|
|
struct parport_uss720_private *priv;
|
|
|
|
|
2012-05-02 11:34:07 +07:00
|
|
|
dev_dbg(&intf->dev, "disconnect\n");
|
2005-09-09 15:43:50 +07:00
|
|
|
usb_set_intfdata(intf, NULL);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (pp) {
|
|
|
|
priv = pp->private_data;
|
|
|
|
priv->usbdev = NULL;
|
2005-09-09 15:43:50 +07:00
|
|
|
priv->pp = NULL;
|
2012-05-02 11:34:07 +07:00
|
|
|
dev_dbg(&intf->dev, "parport_remove_port\n");
|
2005-09-09 15:43:50 +07:00
|
|
|
parport_remove_port(pp);
|
2005-04-17 05:20:36 +07:00
|
|
|
parport_put_port(pp);
|
2005-09-09 15:43:50 +07:00
|
|
|
kill_all_async_requests_priv(priv);
|
|
|
|
kref_put(&priv->ref_count, destroy_priv);
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
2012-05-02 11:34:07 +07:00
|
|
|
dev_dbg(&intf->dev, "disconnect done\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* table of cables that work through this driver */
|
2010-01-10 21:34:45 +07:00
|
|
|
static const struct usb_device_id uss720_table[] = {
|
2005-04-17 05:20:36 +07:00
|
|
|
{ USB_DEVICE(0x047e, 0x1001) },
|
2018-03-20 17:58:47 +07:00
|
|
|
{ USB_DEVICE(0x04b8, 0x0002) },
|
|
|
|
{ USB_DEVICE(0x04b8, 0x0003) },
|
|
|
|
{ USB_DEVICE(0x050d, 0x0002) },
|
|
|
|
{ USB_DEVICE(0x050d, 0x1202) },
|
2005-04-17 05:20:36 +07:00
|
|
|
{ USB_DEVICE(0x0557, 0x2001) },
|
2018-03-20 17:58:47 +07:00
|
|
|
{ USB_DEVICE(0x05ab, 0x0002) },
|
|
|
|
{ USB_DEVICE(0x06c6, 0x0100) },
|
2005-04-17 05:20:36 +07:00
|
|
|
{ USB_DEVICE(0x0729, 0x1284) },
|
|
|
|
{ USB_DEVICE(0x1293, 0x0002) },
|
|
|
|
{ } /* Terminating entry */
|
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE (usb, uss720_table);
|
|
|
|
|
|
|
|
|
|
|
|
static struct usb_driver uss720_driver = {
|
|
|
|
.name = "uss720",
|
|
|
|
.probe = uss720_probe,
|
|
|
|
.disconnect = uss720_disconnect,
|
|
|
|
.id_table = uss720_table,
|
|
|
|
};
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|
|
|
|
|
2005-09-09 15:43:50 +07:00
|
|
|
MODULE_AUTHOR(DRIVER_AUTHOR);
|
|
|
|
MODULE_DESCRIPTION(DRIVER_DESC);
|
2005-04-17 05:20:36 +07:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
static int __init uss720_init(void)
|
|
|
|
{
|
|
|
|
int retval;
|
|
|
|
retval = usb_register(&uss720_driver);
|
|
|
|
if (retval)
|
|
|
|
goto out;
|
|
|
|
|
2017-07-19 19:17:41 +07:00
|
|
|
printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n");
|
2008-08-19 03:21:04 +07:00
|
|
|
printk(KERN_INFO KBUILD_MODNAME ": NOTE: this is a special purpose "
|
|
|
|
"driver to allow nonstandard\n");
|
|
|
|
printk(KERN_INFO KBUILD_MODNAME ": protocols (eg. bitbang) over "
|
|
|
|
"USS720 usb to parallel cables\n");
|
|
|
|
printk(KERN_INFO KBUILD_MODNAME ": If you just want to connect to a "
|
|
|
|
"printer, use usblp instead\n");
|
2005-04-17 05:20:36 +07:00
|
|
|
out:
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void __exit uss720_cleanup(void)
|
|
|
|
{
|
|
|
|
usb_deregister(&uss720_driver);
|
|
|
|
}
|
|
|
|
|
|
|
|
module_init(uss720_init);
|
|
|
|
module_exit(uss720_cleanup);
|
|
|
|
|
|
|
|
/* --------------------------------------------------------------------- */
|