Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/init.h> |
| 13 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/module.h> |
| 15 | #include <linux/usb.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | /* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */ |
| 18 | #define CPUCS_REG 0x7F92 |
| 19 | |
Rene Buergel | 99495c7 | 2012-09-13 22:14:38 +0200 | [diff] [blame^] | 20 | /* Command for writing to internal memory */ |
| 21 | #define WRITE_INT_RAM 0xA0 |
| 22 | |
| 23 | int ezusb_writememory(struct usb_device *dev, int address, |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 24 | unsigned char *data, int length, __u8 request) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | { |
| 26 | int result; |
| 27 | unsigned char *transfer_buffer; |
| 28 | |
Rene Buergel | 99495c7 | 2012-09-13 22:14:38 +0200 | [diff] [blame^] | 29 | if (!dev) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 30 | printk(KERN_ERR "ezusb: %s - no physical device present, " |
| 31 | "failing.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | return -ENODEV; |
| 33 | } |
| 34 | |
Eric Sesterhenn | 5d7efe5 | 2006-10-26 21:06:24 +0200 | [diff] [blame] | 35 | transfer_buffer = kmemdup(data, length, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | if (!transfer_buffer) { |
Rene Buergel | 99495c7 | 2012-09-13 22:14:38 +0200 | [diff] [blame^] | 37 | dev_err(&dev->dev, "%s - kmalloc(%d) failed.\n", |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 38 | __func__, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | return -ENOMEM; |
| 40 | } |
Rene Buergel | 99495c7 | 2012-09-13 22:14:38 +0200 | [diff] [blame^] | 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); |
| 44 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 45 | kfree(transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 46 | return result; |
| 47 | } |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 48 | EXPORT_SYMBOL_GPL(ezusb_writememory); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
Rene Buergel | 99495c7 | 2012-09-13 22:14:38 +0200 | [diff] [blame^] | 50 | int ezusb_set_reset(struct usb_device *dev, unsigned char reset_bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | { |
Rene Buergel | 99495c7 | 2012-09-13 22:14:38 +0200 | [diff] [blame^] | 52 | int response = ezusb_writememory(dev, CPUCS_REG, &reset_bit, 1, WRITE_INT_RAM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | if (response < 0) |
Rene Buergel | 99495c7 | 2012-09-13 22:14:38 +0200 | [diff] [blame^] | 54 | dev_err(&dev->dev, "%s-%d failed: %d\n", |
| 55 | __func__, reset_bit, response); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | return response; |
| 57 | } |
Paul Chavent | 7bd4b20 | 2008-01-12 15:23:17 +0100 | [diff] [blame] | 58 | EXPORT_SYMBOL_GPL(ezusb_set_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |