2005-04-17 05:20:36 +07:00
|
|
|
/*
|
|
|
|
* EZ-USB specific functions used by some of the USB to Serial drivers.
|
|
|
|
*
|
|
|
|
* Copyright (C) 1999 - 2002 Greg Kroah-Hartman (greg@kroah.com)
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License version
|
|
|
|
* 2 as published by the Free Software Foundation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/usb.h>
|
|
|
|
|
|
|
|
/* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */
|
|
|
|
#define CPUCS_REG 0x7F92
|
|
|
|
|
2012-09-14 03:14:38 +07:00
|
|
|
/* Command for writing to internal memory */
|
|
|
|
#define WRITE_INT_RAM 0xA0
|
|
|
|
|
|
|
|
int ezusb_writememory(struct usb_device *dev, int address,
|
2008-07-22 17:09:16 +07:00
|
|
|
unsigned char *data, int length, __u8 request)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
|
|
|
int result;
|
|
|
|
unsigned char *transfer_buffer;
|
|
|
|
|
2012-09-18 22:55:48 +07:00
|
|
|
if (!dev)
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENODEV;
|
|
|
|
|
2006-10-27 02:06:24 +07:00
|
|
|
transfer_buffer = kmemdup(data, length, GFP_KERNEL);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (!transfer_buffer) {
|
2012-09-14 03:14:38 +07:00
|
|
|
dev_err(&dev->dev, "%s - kmalloc(%d) failed.\n",
|
2008-07-22 17:09:16 +07:00
|
|
|
__func__, length);
|
2005-04-17 05:20:36 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2012-09-14 03:14:38 +07:00
|
|
|
result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
|
|
|
|
USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
|
|
|
|
address, 0, transfer_buffer, length, 3000);
|
|
|
|
|
2008-07-22 17:09:16 +07:00
|
|
|
kfree(transfer_buffer);
|
2005-04-17 05:20:36 +07:00
|
|
|
return result;
|
|
|
|
}
|
2008-07-22 17:09:16 +07:00
|
|
|
EXPORT_SYMBOL_GPL(ezusb_writememory);
|
2005-04-17 05:20:36 +07:00
|
|
|
|
2012-09-14 03:14:38 +07:00
|
|
|
int ezusb_set_reset(struct usb_device *dev, unsigned char reset_bit)
|
2005-04-17 05:20:36 +07:00
|
|
|
{
|
2012-09-14 03:14:38 +07:00
|
|
|
int response = ezusb_writememory(dev, CPUCS_REG, &reset_bit, 1, WRITE_INT_RAM);
|
2005-04-17 05:20:36 +07:00
|
|
|
if (response < 0)
|
2012-09-14 03:14:38 +07:00
|
|
|
dev_err(&dev->dev, "%s-%d failed: %d\n",
|
|
|
|
__func__, reset_bit, response);
|
2005-04-17 05:20:36 +07:00
|
|
|
return response;
|
|
|
|
}
|
2008-01-12 21:23:17 +07:00
|
|
|
EXPORT_SYMBOL_GPL(ezusb_set_reset);
|
2005-04-17 05:20:36 +07:00
|
|
|
|