USB: ezusb: remove dependancy on usb_serial
[linux-2.6/btrfs-unstable.git] / drivers / usb / serial / ezusb.c
blob3048b52d2d39c4bff9a96ddcb944beeed98d71a9
1 /*
2 * EZ-USB specific functions used by some of the USB to Serial drivers.
4 * Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
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 */
11 #include <linux/kernel.h>
12 #include <linux/init.h>
13 #include <linux/slab.h>
14 #include <linux/module.h>
15 #include <linux/usb.h>
17 /* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */
18 #define CPUCS_REG 0x7F92
20 /* Command for writing to internal memory */
21 #define WRITE_INT_RAM 0xA0
23 int ezusb_writememory(struct usb_device *dev, int address,
24 unsigned char *data, int length, __u8 request)
26 int result;
27 unsigned char *transfer_buffer;
29 if (!dev) {
30 printk(KERN_ERR "ezusb: %s - no physical device present, "
31 "failing.\n", __func__);
32 return -ENODEV;
35 transfer_buffer = kmemdup(data, length, GFP_KERNEL);
36 if (!transfer_buffer) {
37 dev_err(&dev->dev, "%s - kmalloc(%d) failed.\n",
38 __func__, length);
39 return -ENOMEM;
41 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
42 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
43 address, 0, transfer_buffer, length, 3000);
45 kfree(transfer_buffer);
46 return result;
48 EXPORT_SYMBOL_GPL(ezusb_writememory);
50 int ezusb_set_reset(struct usb_device *dev, unsigned char reset_bit)
52 int response = ezusb_writememory(dev, CPUCS_REG, &reset_bit, 1, WRITE_INT_RAM);
53 if (response < 0)
54 dev_err(&dev->dev, "%s-%d failed: %d\n",
55 __func__, reset_bit, response);
56 return response;
58 EXPORT_SYMBOL_GPL(ezusb_set_reset);