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> |
| 12 | #include <linux/errno.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/slab.h> |
| 15 | #include <linux/tty.h> |
| 16 | #include <linux/module.h> |
| 17 | #include <linux/usb.h> |
Greg Kroah-Hartman | a969888 | 2006-07-11 21:22:58 -0700 | [diff] [blame] | 18 | #include <linux/usb/serial.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | |
| 20 | /* EZ-USB Control and Status Register. Bit 0 controls 8051 reset */ |
| 21 | #define CPUCS_REG 0x7F92 |
| 22 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 23 | int ezusb_writememory(struct usb_serial *serial, int address, |
| 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 | |
| 29 | /* dbg("ezusb_writememory %x, %d", address, length); */ |
| 30 | if (!serial->dev) { |
Greg Kroah-Hartman | 194343d | 2008-08-20 16:56:34 -0700 | [diff] [blame] | 31 | printk(KERN_ERR "ezusb: %s - no physical device present, " |
| 32 | "failing.\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | return -ENODEV; |
| 34 | } |
| 35 | |
Eric Sesterhenn | 5d7efe5 | 2006-10-26 21:06:24 +0200 | [diff] [blame] | 36 | transfer_buffer = kmemdup(data, length, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | if (!transfer_buffer) { |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 38 | dev_err(&serial->dev->dev, "%s - kmalloc(%d) failed.\n", |
| 39 | __func__, length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | return -ENOMEM; |
| 41 | } |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 42 | result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), |
| 43 | request, 0x40, address, 0, transfer_buffer, length, 3000); |
| 44 | kfree(transfer_buffer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | return result; |
| 46 | } |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 47 | EXPORT_SYMBOL_GPL(ezusb_writememory); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 49 | int ezusb_set_reset(struct usb_serial *serial, unsigned char reset_bit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | { |
| 51 | int response; |
| 52 | |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 53 | /* dbg("%s - %d", __func__, reset_bit); */ |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 54 | response = ezusb_writememory(serial, CPUCS_REG, &reset_bit, 1, 0xa0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | if (response < 0) |
Alan Cox | 80359a9 | 2008-07-22 11:09:16 +0100 | [diff] [blame] | 56 | dev_err(&serial->dev->dev, "%s- %d failed\n", |
| 57 | __func__, reset_bit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | return response; |
| 59 | } |
Paul Chavent | 7bd4b20 | 2008-01-12 15:23:17 +0100 | [diff] [blame] | 60 | EXPORT_SYMBOL_GPL(ezusb_set_reset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 61 | |