ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / usb / serial / ezusb.c
1 /*
2  * EZ-USB specific functions used by some of the USB to Serial drivers.
3  *
4  * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
5  *
6  *      This program is free software; you can redistribute it and/or
7  *      modify it under the terms of the GNU General Public License version
8  *      2 as published by the Free Software Foundation.
9  */
10
11 #include <linux/config.h>
12 #include <linux/kernel.h>
13 #include <linux/errno.h>
14 #include <linux/init.h>
15 #include <linux/slab.h>
16 #include <linux/tty.h>
17 #include <linux/module.h>
18 #include <linux/usb.h>
19
20 #ifdef CONFIG_USB_SERIAL_DEBUG
21         static int debug = 1;
22 #else
23         static int debug;
24 #endif
25
26 #include "usb-serial.h"
27
28 /* EZ-USB Control and Status Register.  Bit 0 controls 8051 reset */
29 #define CPUCS_REG    0x7F92
30
31 int ezusb_writememory (struct usb_serial *serial, int address, unsigned char *data, int length, __u8 bRequest)
32 {
33         int result;
34         unsigned char *transfer_buffer;
35
36         /* dbg("ezusb_writememory %x, %d", address, length); */
37         if (!serial->dev) {
38                 dbg("%s - no physical device present, failing.", __FUNCTION__);
39                 return -ENODEV;
40         }
41
42         transfer_buffer =  kmalloc (length, GFP_KERNEL);
43         if (!transfer_buffer) {
44                 dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", __FUNCTION__, length);
45                 return -ENOMEM;
46         }
47         memcpy (transfer_buffer, data, length);
48         result = usb_control_msg (serial->dev, usb_sndctrlpipe(serial->dev, 0), bRequest, 0x40, address, 0, transfer_buffer, length, 3*HZ);
49         kfree (transfer_buffer);
50         return result;
51 }
52
53 int ezusb_set_reset (struct usb_serial *serial, unsigned char reset_bit)
54 {
55         int     response;
56         dbg("%s - %d", __FUNCTION__, reset_bit);
57         response = ezusb_writememory (serial, CPUCS_REG, &reset_bit, 1, 0xa0);
58         if (response < 0) {
59                 dev_err(&serial->dev->dev, "%s- %d failed\n", __FUNCTION__, reset_bit);
60         }
61         return response;
62 }
63
64
65 EXPORT_SYMBOL(ezusb_writememory);
66 EXPORT_SYMBOL(ezusb_set_reset);
67