blob: 3048b52d2d39c4bff9a96ddcb944beeed98d71a9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012#include <linux/init.h>
13#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/module.h>
15#include <linux/usb.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
17/* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */
18#define CPUCS_REG 0x7F92
19
Rene Buergel99495c72012-09-13 22:14:38 +020020/* Command for writing to internal memory */
21#define WRITE_INT_RAM 0xA0
22
23int ezusb_writememory(struct usb_device *dev, int address,
Alan Cox80359a92008-07-22 11:09:16 +010024 unsigned char *data, int length, __u8 request)
Linus Torvalds1da177e2005-04-16 15:20:36 -070025{
26 int result;
27 unsigned char *transfer_buffer;
28
Rene Buergel99495c72012-09-13 22:14:38 +020029 if (!dev) {
Greg Kroah-Hartman194343d2008-08-20 16:56:34 -070030 printk(KERN_ERR "ezusb: %s - no physical device present, "
31 "failing.\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 return -ENODEV;
33 }
34
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +020035 transfer_buffer = kmemdup(data, length, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 if (!transfer_buffer) {
Rene Buergel99495c72012-09-13 22:14:38 +020037 dev_err(&dev->dev, "%s - kmalloc(%d) failed.\n",
Alan Cox80359a92008-07-22 11:09:16 +010038 __func__, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 return -ENOMEM;
40 }
Rene Buergel99495c72012-09-13 22:14:38 +020041 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);
44
Alan Cox80359a92008-07-22 11:09:16 +010045 kfree(transfer_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 return result;
47}
Alan Cox80359a92008-07-22 11:09:16 +010048EXPORT_SYMBOL_GPL(ezusb_writememory);
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Rene Buergel99495c72012-09-13 22:14:38 +020050int ezusb_set_reset(struct usb_device *dev, unsigned char reset_bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -070051{
Rene Buergel99495c72012-09-13 22:14:38 +020052 int response = ezusb_writememory(dev, CPUCS_REG, &reset_bit, 1, WRITE_INT_RAM);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 if (response < 0)
Rene Buergel99495c72012-09-13 22:14:38 +020054 dev_err(&dev->dev, "%s-%d failed: %d\n",
55 __func__, reset_bit, response);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 return response;
57}
Paul Chavent7bd4b202008-01-12 15:23:17 +010058EXPORT_SYMBOL_GPL(ezusb_set_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059