blob: a9b5263221fa49725081faebe78329e3327aacc7 [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
Greg Kroah-Hartmanc6ab0152012-09-18 16:55:48 +010029 if (!dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Eric Sesterhenn5d7efe52006-10-26 21:06:24 +020032 transfer_buffer = kmemdup(data, length, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070033 if (!transfer_buffer) {
Rene Buergel99495c72012-09-13 22:14:38 +020034 dev_err(&dev->dev, "%s - kmalloc(%d) failed.\n",
Alan Cox80359a92008-07-22 11:09:16 +010035 __func__, length);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 return -ENOMEM;
37 }
Rene Buergel99495c72012-09-13 22:14:38 +020038 result = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), request,
39 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
40 address, 0, transfer_buffer, length, 3000);
41
Alan Cox80359a92008-07-22 11:09:16 +010042 kfree(transfer_buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 return result;
44}
Alan Cox80359a92008-07-22 11:09:16 +010045EXPORT_SYMBOL_GPL(ezusb_writememory);
Linus Torvalds1da177e2005-04-16 15:20:36 -070046
Rene Buergel99495c72012-09-13 22:14:38 +020047int ezusb_set_reset(struct usb_device *dev, unsigned char reset_bit)
Linus Torvalds1da177e2005-04-16 15:20:36 -070048{
Rene Buergel99495c72012-09-13 22:14:38 +020049 int response = ezusb_writememory(dev, CPUCS_REG, &reset_bit, 1, WRITE_INT_RAM);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050 if (response < 0)
Rene Buergel99495c72012-09-13 22:14:38 +020051 dev_err(&dev->dev, "%s-%d failed: %d\n",
52 __func__, reset_bit, response);
Linus Torvalds1da177e2005-04-16 15:20:36 -070053 return response;
54}
Paul Chavent7bd4b202008-01-12 15:23:17 +010055EXPORT_SYMBOL_GPL(ezusb_set_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056