aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/staging')
-rw-r--r--drivers/staging/Kconfig4
-rw-r--r--drivers/staging/Makefile2
-rw-r--r--drivers/staging/android/Kconfig2
-rw-r--r--drivers/staging/android/Makefile1
-rw-r--r--drivers/staging/android/switch/Kconfig11
-rw-r--r--drivers/staging/android/switch/Makefile4
-rw-r--r--drivers/staging/android/switch/switch.h53
-rw-r--r--drivers/staging/android/switch/switch_class.c174
-rw-r--r--drivers/staging/android/switch/switch_gpio.c172
-rw-r--r--drivers/staging/ccg/Kconfig20
-rw-r--r--drivers/staging/ccg/Makefile4
-rw-r--r--drivers/staging/ccg/TODO6
-rw-r--r--drivers/staging/ccg/ccg.c1299
-rw-r--r--drivers/staging/ccg/sysfs-class-ccg_usb158
-rw-r--r--drivers/staging/media/as102/as102_drv.c34
-rw-r--r--drivers/staging/media/as102/as102_usb_drv.c7
-rw-r--r--drivers/staging/media/go7007/go7007.txt1
-rw-r--r--drivers/staging/octeon/ethernet-tx.c2
-rw-r--r--drivers/staging/quatech_usb2/Kconfig15
-rw-r--r--drivers/staging/quatech_usb2/Makefile1
-rw-r--r--drivers/staging/quatech_usb2/TODO8
-rw-r--r--drivers/staging/quatech_usb2/quatech_usb2.c1976
-rw-r--r--drivers/staging/ramster/cluster/tcp.c2
-rw-r--r--drivers/staging/serqt_usb2/serqt_usb2.c74
24 files changed, 1501 insertions, 2529 deletions
diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 7e0e5e4317a..05e33c70075 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -66,8 +66,6 @@ source "drivers/staging/octeon/Kconfig"
66 66
67source "drivers/staging/serqt_usb2/Kconfig" 67source "drivers/staging/serqt_usb2/Kconfig"
68 68
69source "drivers/staging/quatech_usb2/Kconfig"
70
71source "drivers/staging/vt6655/Kconfig" 69source "drivers/staging/vt6655/Kconfig"
72 70
73source "drivers/staging/vt6656/Kconfig" 71source "drivers/staging/vt6656/Kconfig"
@@ -128,6 +126,8 @@ source "drivers/staging/ramster/Kconfig"
128 126
129source "drivers/staging/ozwpan/Kconfig" 127source "drivers/staging/ozwpan/Kconfig"
130 128
129source "drivers/staging/ccg/Kconfig"
130
131source "drivers/staging/ipack/Kconfig" 131source "drivers/staging/ipack/Kconfig"
132 132
133source "drivers/staging/gdm72xx/Kconfig" 133source "drivers/staging/gdm72xx/Kconfig"
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index 30901057bd1..a987b3ad380 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -25,7 +25,6 @@ obj-$(CONFIG_TRANZPORT) += frontier/
25obj-$(CONFIG_IDE_PHISON) += phison/ 25obj-$(CONFIG_IDE_PHISON) += phison/
26obj-$(CONFIG_LINE6_USB) += line6/ 26obj-$(CONFIG_LINE6_USB) += line6/
27obj-$(CONFIG_USB_SERIAL_QUATECH2) += serqt_usb2/ 27obj-$(CONFIG_USB_SERIAL_QUATECH2) += serqt_usb2/
28obj-$(CONFIG_USB_SERIAL_QUATECH_USB2) += quatech_usb2/
29obj-$(CONFIG_OCTEON_ETHERNET) += octeon/ 28obj-$(CONFIG_OCTEON_ETHERNET) += octeon/
30obj-$(CONFIG_VT6655) += vt6655/ 29obj-$(CONFIG_VT6655) += vt6655/
31obj-$(CONFIG_VT6656) += vt6656/ 30obj-$(CONFIG_VT6656) += vt6656/
@@ -57,4 +56,5 @@ obj-$(CONFIG_ANDROID) += android/
57obj-$(CONFIG_PHONE) += telephony/ 56obj-$(CONFIG_PHONE) += telephony/
58obj-$(CONFIG_RAMSTER) += ramster/ 57obj-$(CONFIG_RAMSTER) += ramster/
59obj-$(CONFIG_USB_WPAN_HCD) += ozwpan/ 58obj-$(CONFIG_USB_WPAN_HCD) += ozwpan/
59obj-$(CONFIG_USB_G_CCG) += ccg/
60obj-$(CONFIG_WIMAX_GDM72XX) += gdm72xx/ 60obj-$(CONFIG_WIMAX_GDM72XX) += gdm72xx/
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 63f98223760..0e16b594460 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -45,8 +45,6 @@ config ANDROID_LOW_MEMORY_KILLER
45 ---help--- 45 ---help---
46 Register processes to be killed when memory is low 46 Register processes to be killed when memory is low
47 47
48source "drivers/staging/android/switch/Kconfig"
49
50config ANDROID_INTF_ALARM_DEV 48config ANDROID_INTF_ALARM_DEV
51 bool "Android alarm driver" 49 bool "Android alarm driver"
52 depends on RTC_CLASS 50 depends on RTC_CLASS
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 4677e7b0e07..98711e2b2af 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -5,5 +5,4 @@ obj-$(CONFIG_ANDROID_RAM_CONSOLE) += ram_console.o
5obj-$(CONFIG_ANDROID_TIMED_OUTPUT) += timed_output.o 5obj-$(CONFIG_ANDROID_TIMED_OUTPUT) += timed_output.o
6obj-$(CONFIG_ANDROID_TIMED_GPIO) += timed_gpio.o 6obj-$(CONFIG_ANDROID_TIMED_GPIO) += timed_gpio.o
7obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o 7obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o
8obj-$(CONFIG_ANDROID_SWITCH) += switch/
9obj-$(CONFIG_ANDROID_INTF_ALARM_DEV) += alarm-dev.o 8obj-$(CONFIG_ANDROID_INTF_ALARM_DEV) += alarm-dev.o
diff --git a/drivers/staging/android/switch/Kconfig b/drivers/staging/android/switch/Kconfig
deleted file mode 100644
index 36846f62f4b..00000000000
--- a/drivers/staging/android/switch/Kconfig
+++ /dev/null
@@ -1,11 +0,0 @@
1menuconfig ANDROID_SWITCH
2 tristate "Android Switch class support"
3 help
4 Say Y here to enable Android switch class support. This allows
5 monitoring switches by userspace via sysfs and uevent.
6
7config ANDROID_SWITCH_GPIO
8 tristate "Android GPIO Switch support"
9 depends on GENERIC_GPIO && ANDROID_SWITCH
10 help
11 Say Y here to enable GPIO based switch support.
diff --git a/drivers/staging/android/switch/Makefile b/drivers/staging/android/switch/Makefile
deleted file mode 100644
index d76bfdcedfa..00000000000
--- a/drivers/staging/android/switch/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
1# Android Switch Class Driver
2obj-$(CONFIG_ANDROID_SWITCH) += switch_class.o
3obj-$(CONFIG_ANDROID_SWITCH_GPIO) += switch_gpio.o
4
diff --git a/drivers/staging/android/switch/switch.h b/drivers/staging/android/switch/switch.h
deleted file mode 100644
index 4fcb3109875..00000000000
--- a/drivers/staging/android/switch/switch.h
+++ /dev/null
@@ -1,53 +0,0 @@
1/*
2 * Switch class driver
3 *
4 * Copyright (C) 2008 Google, Inc.
5 * Author: Mike Lockwood <lockwood@android.com>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16*/
17
18#ifndef __LINUX_SWITCH_H__
19#define __LINUX_SWITCH_H__
20
21struct switch_dev {
22 const char *name;
23 struct device *dev;
24 int index;
25 int state;
26
27 ssize_t (*print_name)(struct switch_dev *sdev, char *buf);
28 ssize_t (*print_state)(struct switch_dev *sdev, char *buf);
29};
30
31struct gpio_switch_platform_data {
32 const char *name;
33 unsigned gpio;
34
35 /* if NULL, switch_dev.name will be printed */
36 const char *name_on;
37 const char *name_off;
38 /* if NULL, "0" or "1" will be printed */
39 const char *state_on;
40 const char *state_off;
41};
42
43extern int switch_dev_register(struct switch_dev *sdev);
44extern void switch_dev_unregister(struct switch_dev *sdev);
45
46static inline int switch_get_state(struct switch_dev *sdev)
47{
48 return sdev->state;
49}
50
51extern void switch_set_state(struct switch_dev *sdev, int state);
52
53#endif /* __LINUX_SWITCH_H__ */
diff --git a/drivers/staging/android/switch/switch_class.c b/drivers/staging/android/switch/switch_class.c
deleted file mode 100644
index 74680446fc6..00000000000
--- a/drivers/staging/android/switch/switch_class.c
+++ /dev/null
@@ -1,174 +0,0 @@
1/*
2 * switch_class.c
3 *
4 * Copyright (C) 2008 Google, Inc.
5 * Author: Mike Lockwood <lockwood@android.com>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16*/
17
18#include <linux/module.h>
19#include <linux/types.h>
20#include <linux/init.h>
21#include <linux/device.h>
22#include <linux/fs.h>
23#include <linux/err.h>
24#include "switch.h"
25
26struct class *switch_class;
27static atomic_t device_count;
28
29static ssize_t state_show(struct device *dev, struct device_attribute *attr,
30 char *buf)
31{
32 struct switch_dev *sdev = (struct switch_dev *)
33 dev_get_drvdata(dev);
34
35 if (sdev->print_state) {
36 int ret = sdev->print_state(sdev, buf);
37 if (ret >= 0)
38 return ret;
39 }
40 return sprintf(buf, "%d\n", sdev->state);
41}
42
43static ssize_t name_show(struct device *dev, struct device_attribute *attr,
44 char *buf)
45{
46 struct switch_dev *sdev = (struct switch_dev *)
47 dev_get_drvdata(dev);
48
49 if (sdev->print_name) {
50 int ret = sdev->print_name(sdev, buf);
51 if (ret >= 0)
52 return ret;
53 }
54 return sprintf(buf, "%s\n", sdev->name);
55}
56
57static DEVICE_ATTR(state, S_IRUGO | S_IWUSR, state_show, NULL);
58static DEVICE_ATTR(name, S_IRUGO | S_IWUSR, name_show, NULL);
59
60void switch_set_state(struct switch_dev *sdev, int state)
61{
62 char name_buf[120];
63 char state_buf[120];
64 char *prop_buf;
65 char *envp[3];
66 int env_offset = 0;
67 int length;
68
69 if (sdev->state != state) {
70 sdev->state = state;
71
72 prop_buf = (char *)get_zeroed_page(GFP_KERNEL);
73 if (prop_buf) {
74 length = name_show(sdev->dev, NULL, prop_buf);
75 if (length > 0) {
76 if (prop_buf[length - 1] == '\n')
77 prop_buf[length - 1] = 0;
78 snprintf(name_buf, sizeof(name_buf),
79 "SWITCH_NAME=%s", prop_buf);
80 envp[env_offset++] = name_buf;
81 }
82 length = state_show(sdev->dev, NULL, prop_buf);
83 if (length > 0) {
84 if (prop_buf[length - 1] == '\n')
85 prop_buf[length - 1] = 0;
86 snprintf(state_buf, sizeof(state_buf),
87 "SWITCH_STATE=%s", prop_buf);
88 envp[env_offset++] = state_buf;
89 }
90 envp[env_offset] = NULL;
91 kobject_uevent_env(&sdev->dev->kobj, KOBJ_CHANGE, envp);
92 free_page((unsigned long)prop_buf);
93 } else {
94 printk(KERN_ERR "out of memory in switch_set_state\n");
95 kobject_uevent(&sdev->dev->kobj, KOBJ_CHANGE);
96 }
97 }
98}
99EXPORT_SYMBOL_GPL(switch_set_state);
100
101static int create_switch_class(void)
102{
103 if (!switch_class) {
104 switch_class = class_create(THIS_MODULE, "switch");
105 if (IS_ERR(switch_class))
106 return PTR_ERR(switch_class);
107 atomic_set(&device_count, 0);
108 }
109
110 return 0;
111}
112
113int switch_dev_register(struct switch_dev *sdev)
114{
115 int ret;
116
117 if (!switch_class) {
118 ret = create_switch_class();
119 if (ret < 0)
120 return ret;
121 }
122
123 sdev->index = atomic_inc_return(&device_count);
124 sdev->dev = device_create(switch_class, NULL,
125 MKDEV(0, sdev->index), NULL, sdev->name);
126 if (IS_ERR(sdev->dev))
127 return PTR_ERR(sdev->dev);
128
129 ret = device_create_file(sdev->dev, &dev_attr_state);
130 if (ret < 0)
131 goto err_create_file_1;
132 ret = device_create_file(sdev->dev, &dev_attr_name);
133 if (ret < 0)
134 goto err_create_file_2;
135
136 dev_set_drvdata(sdev->dev, sdev);
137 sdev->state = 0;
138 return 0;
139
140err_create_file_2:
141 device_remove_file(sdev->dev, &dev_attr_state);
142err_create_file_1:
143 device_destroy(switch_class, MKDEV(0, sdev->index));
144 printk(KERN_ERR "switch: Failed to register driver %s\n", sdev->name);
145
146 return ret;
147}
148EXPORT_SYMBOL_GPL(switch_dev_register);
149
150void switch_dev_unregister(struct switch_dev *sdev)
151{
152 device_remove_file(sdev->dev, &dev_attr_name);
153 device_remove_file(sdev->dev, &dev_attr_state);
154 device_destroy(switch_class, MKDEV(0, sdev->index));
155 dev_set_drvdata(sdev->dev, NULL);
156}
157EXPORT_SYMBOL_GPL(switch_dev_unregister);
158
159static int __init switch_class_init(void)
160{
161 return create_switch_class();
162}
163
164static void __exit switch_class_exit(void)
165{
166 class_destroy(switch_class);
167}
168
169module_init(switch_class_init);
170module_exit(switch_class_exit);
171
172MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>");
173MODULE_DESCRIPTION("Switch class driver");
174MODULE_LICENSE("GPL");
diff --git a/drivers/staging/android/switch/switch_gpio.c b/drivers/staging/android/switch/switch_gpio.c
deleted file mode 100644
index 38b2c2f6004..00000000000
--- a/drivers/staging/android/switch/switch_gpio.c
+++ /dev/null
@@ -1,172 +0,0 @@
1/*
2 * switch_gpio.c
3 *
4 * Copyright (C) 2008 Google, Inc.
5 * Author: Mike Lockwood <lockwood@android.com>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16*/
17
18#include <linux/module.h>
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/interrupt.h>
22#include <linux/platform_device.h>
23#include <linux/slab.h>
24#include <linux/workqueue.h>
25#include <linux/gpio.h>
26#include "switch.h"
27
28struct gpio_switch_data {
29 struct switch_dev sdev;
30 unsigned gpio;
31 const char *name_on;
32 const char *name_off;
33 const char *state_on;
34 const char *state_off;
35 int irq;
36 struct work_struct work;
37};
38
39static void gpio_switch_work(struct work_struct *work)
40{
41 int state;
42 struct gpio_switch_data *data =
43 container_of(work, struct gpio_switch_data, work);
44
45 state = gpio_get_value(data->gpio);
46 switch_set_state(&data->sdev, state);
47}
48
49static irqreturn_t gpio_irq_handler(int irq, void *dev_id)
50{
51 struct gpio_switch_data *switch_data =
52 (struct gpio_switch_data *)dev_id;
53
54 schedule_work(&switch_data->work);
55 return IRQ_HANDLED;
56}
57
58static ssize_t switch_gpio_print_state(struct switch_dev *sdev, char *buf)
59{
60 struct gpio_switch_data *switch_data =
61 container_of(sdev, struct gpio_switch_data, sdev);
62 const char *state;
63 if (switch_get_state(sdev))
64 state = switch_data->state_on;
65 else
66 state = switch_data->state_off;
67
68 if (state)
69 return sprintf(buf, "%s\n", state);
70 return -1;
71}
72
73static int gpio_switch_probe(struct platform_device *pdev)
74{
75 struct gpio_switch_platform_data *pdata = pdev->dev.platform_data;
76 struct gpio_switch_data *switch_data;
77 int ret = 0;
78
79 if (!pdata)
80 return -EBUSY;
81
82 switch_data = kzalloc(sizeof(struct gpio_switch_data), GFP_KERNEL);
83 if (!switch_data)
84 return -ENOMEM;
85
86 switch_data->sdev.name = pdata->name;
87 switch_data->gpio = pdata->gpio;
88 switch_data->name_on = pdata->name_on;
89 switch_data->name_off = pdata->name_off;
90 switch_data->state_on = pdata->state_on;
91 switch_data->state_off = pdata->state_off;
92 switch_data->sdev.print_state = switch_gpio_print_state;
93
94 ret = switch_dev_register(&switch_data->sdev);
95 if (ret < 0)
96 goto err_switch_dev_register;
97
98 ret = gpio_request(switch_data->gpio, pdev->name);
99 if (ret < 0)
100 goto err_request_gpio;
101
102 ret = gpio_direction_input(switch_data->gpio);
103 if (ret < 0)
104 goto err_set_gpio_input;
105
106 INIT_WORK(&switch_data->work, gpio_switch_work);
107
108 switch_data->irq = gpio_to_irq(switch_data->gpio);
109 if (switch_data->irq < 0) {
110 ret = switch_data->irq;
111 goto err_detect_irq_num_failed;
112 }
113
114 ret = request_irq(switch_data->irq, gpio_irq_handler,
115 IRQF_TRIGGER_LOW, pdev->name, switch_data);
116 if (ret < 0)
117 goto err_request_irq;
118
119 /* Perform initial detection */
120 gpio_switch_work(&switch_data->work);
121
122 return 0;
123
124err_request_irq:
125err_detect_irq_num_failed:
126err_set_gpio_input:
127 gpio_free(switch_data->gpio);
128err_request_gpio:
129 switch_dev_unregister(&switch_data->sdev);
130err_switch_dev_register:
131 kfree(switch_data);
132
133 return ret;
134}
135
136static int __devexit gpio_switch_remove(struct platform_device *pdev)
137{
138 struct gpio_switch_data *switch_data = platform_get_drvdata(pdev);
139
140 cancel_work_sync(&switch_data->work);
141 gpio_free(switch_data->gpio);
142 switch_dev_unregister(&switch_data->sdev);
143 kfree(switch_data);
144
145 return 0;
146}
147
148static struct platform_driver gpio_switch_driver = {
149 .probe = gpio_switch_probe,
150 .remove = __devexit_p(gpio_switch_remove),
151 .driver = {
152 .name = "switch-gpio",
153 .owner = THIS_MODULE,
154 },
155};
156
157static int __init gpio_switch_init(void)
158{
159 return platform_driver_register(&gpio_switch_driver);
160}
161
162static void __exit gpio_switch_exit(void)
163{
164 platform_driver_unregister(&gpio_switch_driver);
165}
166
167module_init(gpio_switch_init);
168module_exit(gpio_switch_exit);
169
170MODULE_AUTHOR("Mike Lockwood <lockwood@android.com>");
171MODULE_DESCRIPTION("GPIO Switch driver");
172MODULE_LICENSE("GPL");
diff --git a/drivers/staging/ccg/Kconfig b/drivers/staging/ccg/Kconfig
new file mode 100644
index 00000000000..ff05e52392b
--- /dev/null
+++ b/drivers/staging/ccg/Kconfig
@@ -0,0 +1,20 @@
1if USB_GADGET
2
3config USB_G_CCG
4 tristate "Configurable Composite Gadget (STAGING)"
5 depends on STAGING && !USB_ZERO && !USB_ZERO_HNPTEST && !USB_AUDIO && !GADGET_UAC1 && !USB_ETH && !USB_ETH_RNDIS && !USB_ETH_EEM && !USB_G_NCM && !USB_GADGETFS && !USB_FUNCTIONFS && !USB_FUNCTIONFS_ETH && !USB_FUNCTIONFS_RNDIS && !USB_FUNCTIONFS_GENERIC && !USB_FILE_STORAGE && !USB_FILE_STORAGE_TEST && !USB_MASS_STORAGE && !USB_G_SERIAL && !USB_MIDI_GADGET && !USB_G_PRINTER && !USB_CDC_COMPOSITE && !USB_G_NOKIA && !USB_G_ACM_MS && !USB_G_MULTI && !USB_G_MULTI_RNDIS && !USB_G_MULTI_CDC && !USB_G_HID && !USB_G_DBGP && !USB_G_WEBCAM
6 help
7 The Configurable Composite Gadget supports multiple USB
8 functions: acm, mass storage, rndis and FunctionFS.
9 Each function can be configured and enabled/disabled
10 dynamically from userspace through a sysfs interface.
11
12 In order to compile this (either as a module or built-in),
13 "USB Gadget Drivers" and anything under it must not be
14 selected compiled-in in
15 Device Drivers->USB Support->USB Gadget Support.
16 However, you can say "M" there, if you do, the
17 Configurable Composite Gadget can be compiled "M" only
18 or not at all.
19
20endif # USB_GADGET
diff --git a/drivers/staging/ccg/Makefile b/drivers/staging/ccg/Makefile
new file mode 100644
index 00000000000..693da637a6d
--- /dev/null
+++ b/drivers/staging/ccg/Makefile
@@ -0,0 +1,4 @@
1g_ccg-y := ccg.o
2ccflags-y += -Idrivers/usb/gadget
3
4obj-$(CONFIG_USB_G_CCG) += g_ccg.o
diff --git a/drivers/staging/ccg/TODO b/drivers/staging/ccg/TODO
new file mode 100644
index 00000000000..18612fe7017
--- /dev/null
+++ b/drivers/staging/ccg/TODO
@@ -0,0 +1,6 @@
1TODO:
2 - change configuration interface from sysfs to configfs
3
4Please send patches to Greg Kroah-Hartmann <gregkh@linuxfoundation.org>,
5Andrzej Pietrasiewicz <andrzej.p@samsung.com>, and
6Cc: Mike Lockwood <lockwood@android.com>
diff --git a/drivers/staging/ccg/ccg.c b/drivers/staging/ccg/ccg.c
new file mode 100644
index 00000000000..a5b36a97598
--- /dev/null
+++ b/drivers/staging/ccg/ccg.c
@@ -0,0 +1,1299 @@
1/*
2 * Configurable Composite Gadget
3 *
4 * Initially contributed as "Android Composite Gdaget" by:
5 *
6 * Copyright (C) 2008 Google, Inc.
7 * Author: Mike Lockwood <lockwood@android.com>
8 * Benoit Goby <benoit@android.com>
9 *
10 * Tailoring it to become a generic Configurable Composite Gadget is
11 *
12 * Copyright (C) 2012 Samsung Electronics
13 * Author: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
14 *
15 * This software is licensed under the terms of the GNU General Public
16 * License version 2, as published by the Free Software Foundation, and
17 * may be copied, distributed, and modified under those terms.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 */
25
26#include <linux/init.h>
27#include <linux/module.h>
28#include <linux/fs.h>
29#include <linux/delay.h>
30#include <linux/kernel.h>
31#include <linux/utsname.h>
32#include <linux/platform_device.h>
33
34#include <linux/usb/ch9.h>
35#include <linux/usb/composite.h>
36#include <linux/usb/gadget.h>
37
38#include "gadget_chips.h"
39
40/*
41 * Kbuild is not very cooperative with respect to linking separately
42 * compiled library objects into one module. So for now we won't use
43 * separate compilation ... ensuring init/exit sections work to shrink
44 * the runtime footprint, and giving us at least some parts of what
45 * a "gcc --combine ... part1.c part2.c part3.c ... " build would.
46 */
47#include "../../usb/gadget/usbstring.c"
48#include "../../usb/gadget/config.c"
49#include "../../usb/gadget/epautoconf.c"
50#include "../../usb/gadget/composite.c"
51
52#include "../../usb/gadget/f_mass_storage.c"
53#include "../../usb/gadget/u_serial.c"
54#include "../../usb/gadget/f_acm.c"
55#define USB_ETH_RNDIS y
56#include "../../usb/gadget/f_rndis.c"
57#include "../../usb/gadget/rndis.c"
58#include "../../usb/gadget/u_ether.c"
59#include "../../usb/gadget/f_fs.c"
60
61MODULE_AUTHOR("Mike Lockwood, Andrzej Pietrasiewicz");
62MODULE_DESCRIPTION("Configurable Composite USB Gadget");
63MODULE_LICENSE("GPL");
64MODULE_VERSION("1.0");
65
66static const char longname[] = "Configurable Composite Gadget";
67
68/* Default vendor and product IDs, overridden by userspace */
69#define VENDOR_ID 0x1d6b /* Linux Foundation */
70#define PRODUCT_ID 0x0107
71#define GFS_MAX_DEVS 10
72
73struct ccg_usb_function {
74 char *name;
75 void *config;
76
77 struct device *dev;
78 char *dev_name;
79 struct device_attribute **attributes;
80
81 /* for ccg_dev.enabled_functions */
82 struct list_head enabled_list;
83
84 /* Optional: initialization during gadget bind */
85 int (*init)(struct ccg_usb_function *, struct usb_composite_dev *);
86 /* Optional: cleanup during gadget unbind */
87 void (*cleanup)(struct ccg_usb_function *);
88
89 int (*bind_config)(struct ccg_usb_function *,
90 struct usb_configuration *);
91
92 /* Optional: called when the configuration is removed */
93 void (*unbind_config)(struct ccg_usb_function *,
94 struct usb_configuration *);
95 /* Optional: handle ctrl requests before the device is configured */
96 int (*ctrlrequest)(struct ccg_usb_function *,
97 struct usb_composite_dev *,
98 const struct usb_ctrlrequest *);
99};
100
101struct ffs_obj {
102 const char *name;
103 bool mounted;
104 bool desc_ready;
105 bool used;
106 struct ffs_data *ffs_data;
107};
108
109struct ccg_dev {
110 struct ccg_usb_function **functions;
111 struct list_head enabled_functions;
112 struct usb_composite_dev *cdev;
113 struct device *dev;
114
115 bool enabled;
116 struct mutex mutex;
117 bool connected;
118 bool sw_connected;
119 struct work_struct work;
120
121 unsigned int max_func_num;
122 unsigned int func_num;
123 struct ffs_obj ffs_tab[GFS_MAX_DEVS];
124};
125
126static struct class *ccg_class;
127static struct ccg_dev *_ccg_dev;
128static int ccg_bind_config(struct usb_configuration *c);
129static void ccg_unbind_config(struct usb_configuration *c);
130
131static char func_names_buf[256];
132
133static struct usb_device_descriptor device_desc = {
134 .bLength = sizeof(device_desc),
135 .bDescriptorType = USB_DT_DEVICE,
136 .bcdUSB = __constant_cpu_to_le16(0x0200),
137 .bDeviceClass = USB_CLASS_PER_INTERFACE,
138 .idVendor = __constant_cpu_to_le16(VENDOR_ID),
139 .idProduct = __constant_cpu_to_le16(PRODUCT_ID),
140 .bcdDevice = __constant_cpu_to_le16(0xffff),
141 .bNumConfigurations = 1,
142};
143
144static struct usb_configuration ccg_config_driver = {
145 .label = "ccg",
146 .unbind = ccg_unbind_config,
147 .bConfigurationValue = 1,
148 .bmAttributes = USB_CONFIG_ATT_ONE | USB_CONFIG_ATT_SELFPOWER,
149 .bMaxPower = 0xFA, /* 500ma */
150};
151
152static void ccg_work(struct work_struct *data)
153{
154 struct ccg_dev *dev = container_of(data, struct ccg_dev, work);
155 struct usb_composite_dev *cdev = dev->cdev;
156 static char *disconnected[2] = { "USB_STATE=DISCONNECTED", NULL };
157 static char *connected[2] = { "USB_STATE=CONNECTED", NULL };
158 static char *configured[2] = { "USB_STATE=CONFIGURED", NULL };
159 char **uevent_envp = NULL;
160 unsigned long flags;
161
162 spin_lock_irqsave(&cdev->lock, flags);
163 if (cdev->config)
164 uevent_envp = configured;
165 else if (dev->connected != dev->sw_connected)
166 uevent_envp = dev->connected ? connected : disconnected;
167 dev->sw_connected = dev->connected;
168 spin_unlock_irqrestore(&cdev->lock, flags);
169
170 if (uevent_envp) {
171 kobject_uevent_env(&dev->dev->kobj, KOBJ_CHANGE, uevent_envp);
172 pr_info("%s: sent uevent %s\n", __func__, uevent_envp[0]);
173 } else {
174 pr_info("%s: did not send uevent (%d %d %p)\n", __func__,
175 dev->connected, dev->sw_connected, cdev->config);
176 }
177}
178
179
180/*-------------------------------------------------------------------------*/
181/* Supported functions initialization */
182
183static struct ffs_obj *functionfs_find_dev(struct ccg_dev *dev,
184 const char *dev_name)
185{
186 int i;
187
188 for (i = 0; i < dev->max_func_num; i++)
189 if (strcmp(dev->ffs_tab[i].name, dev_name) == 0)
190 return &dev->ffs_tab[i];
191
192 return NULL;
193}
194
195static bool functionfs_all_ready(struct ccg_dev *dev)
196{
197 int i;
198
199 for (i = 0; i < dev->max_func_num; i++)
200 if (dev->ffs_tab[i].used && !dev->ffs_tab[i].desc_ready)
201 return false;
202
203 return true;
204}
205
206static int functionfs_ready_callback(struct ffs_data *ffs)
207{
208 struct ffs_obj *ffs_obj;
209 int ret;
210
211 mutex_lock(&_ccg_dev->mutex);
212
213 ffs_obj = ffs->private_data;
214 if (!ffs_obj) {
215 ret = -EINVAL;
216 goto done;
217 }
218 if (WARN_ON(ffs_obj->desc_ready)) {
219 ret = -EBUSY;
220 goto done;
221 }
222 ffs_obj->ffs_data = ffs;
223
224 if (functionfs_all_ready(_ccg_dev)) {
225 ret = -EBUSY;
226 goto done;
227 }
228 ffs_obj->desc_ready = true;
229
230done:
231 mutex_unlock(&_ccg_dev->mutex);
232 return ret;
233}
234
235static void reset_usb(struct ccg_dev *dev)
236{
237 /* Cancel pending control requests */
238 usb_ep_dequeue(dev->cdev->gadget->ep0, dev->cdev->req);
239 usb_remove_config(dev->cdev, &ccg_config_driver);
240 dev->enabled = false;
241 usb_gadget_disconnect(dev->cdev->gadget);
242}
243
244static void functionfs_closed_callback(struct ffs_data *ffs)
245{
246 struct ffs_obj *ffs_obj;
247
248 mutex_lock(&_ccg_dev->mutex);
249
250 ffs_obj = ffs->private_data;
251 if (!ffs_obj)
252 goto done;
253
254 ffs_obj->desc_ready = false;
255
256 if (_ccg_dev->enabled)
257 reset_usb(_ccg_dev);
258
259done:
260 mutex_unlock(&_ccg_dev->mutex);
261}
262
263static void *functionfs_acquire_dev_callback(const char *dev_name)
264{
265 struct ffs_obj *ffs_dev;
266
267 mutex_lock(&_ccg_dev->mutex);
268
269 ffs_dev = functionfs_find_dev(_ccg_dev, dev_name);
270 if (!ffs_dev) {
271 ffs_dev = ERR_PTR(-ENODEV);
272 goto done;
273 }
274
275 if (ffs_dev->mounted) {
276 ffs_dev = ERR_PTR(-EBUSY);
277 goto done;
278 }
279 ffs_dev->mounted = true;
280
281done:
282 mutex_unlock(&_ccg_dev->mutex);
283 return ffs_dev;
284}
285
286static void functionfs_release_dev_callback(struct ffs_data *ffs_data)
287{
288 struct ffs_obj *ffs_dev;
289
290 mutex_lock(&_ccg_dev->mutex);
291
292 ffs_dev = ffs_data->private_data;
293 if (ffs_dev)
294 ffs_dev->mounted = false;
295
296 mutex_unlock(&_ccg_dev->mutex);
297}
298
299static int functionfs_function_init(struct ccg_usb_function *f,
300 struct usb_composite_dev *cdev)
301{
302 return functionfs_init();
303}
304
305static void functionfs_function_cleanup(struct ccg_usb_function *f)
306{
307 functionfs_cleanup();
308}
309
310static int functionfs_function_bind_config(struct ccg_usb_function *f,
311 struct usb_configuration *c)
312{
313 struct ccg_dev *dev = _ccg_dev;
314 int i, ret;
315
316 for (i = dev->max_func_num; i--; ) {
317 if (!dev->ffs_tab[i].used)
318 continue;
319 ret = functionfs_bind(dev->ffs_tab[i].ffs_data, c->cdev);
320 if (unlikely(ret < 0)) {
321 while (++i < dev->max_func_num)
322 functionfs_unbind(dev->ffs_tab[i].ffs_data);
323 return ret;
324 }
325 }
326
327 for (i = dev->max_func_num; i--; ) {
328 if (!dev->ffs_tab[i].used)
329 continue;
330 ret = functionfs_bind_config(c->cdev, c,
331 dev->ffs_tab[i].ffs_data);
332 if (unlikely(ret < 0))
333 return ret;
334 }
335
336 return 0;
337}
338
339static void functionfs_function_unbind_config(struct ccg_usb_function *f,
340 struct usb_configuration *c)
341{
342 struct ccg_dev *dev = _ccg_dev;
343 int i;
344
345 for (i = dev->max_func_num; i--; )
346 if (dev->ffs_tab[i].ffs_data)
347 functionfs_unbind(dev->ffs_tab[i].ffs_data);
348}
349
350static ssize_t functionfs_user_functions_show(struct device *_dev,
351 struct device_attribute *attr,
352 char *buf)
353{
354 struct ccg_dev *dev = _ccg_dev;
355 char *buff = buf;
356 int i;
357
358 mutex_lock(&dev->mutex);
359
360 for (i = 0; i < dev->max_func_num; i++)
361 buff += snprintf(buff, PAGE_SIZE + buf - buff, "%s,",
362 dev->ffs_tab[i].name);
363
364 mutex_unlock(&dev->mutex);
365
366 if (buff != buf)
367 *(buff - 1) = '\n';
368 return buff - buf;
369}
370
371static ssize_t functionfs_user_functions_store(struct device *_dev,
372 struct device_attribute *attr,
373 const char *buff, size_t size)
374{
375 struct ccg_dev *dev = _ccg_dev;
376 char *name, *b;
377 ssize_t ret = size;
378 int i;
379
380 buff = skip_spaces(buff);
381 if (!*buff)
382 return -EINVAL;
383
384 mutex_lock(&dev->mutex);
385
386 if (dev->enabled) {
387 ret = -EBUSY;
388 goto end;
389 }
390
391 for (i = 0; i < dev->max_func_num; i++)
392 if (dev->ffs_tab[i].mounted) {
393 ret = -EBUSY;
394 goto end;
395 }
396
397 strlcpy(func_names_buf, buff, sizeof(func_names_buf));
398 b = strim(func_names_buf);
399
400 /* replace the list of functions */
401 dev->max_func_num = 0;
402 while (b) {
403 name = strsep(&b, ",");
404 if (dev->max_func_num == GFS_MAX_DEVS) {
405 ret = -ENOSPC;
406 goto end;
407 }
408 if (functionfs_find_dev(dev, name)) {
409 ret = -EEXIST;
410 continue;
411 }
412 dev->ffs_tab[dev->max_func_num++].name = name;
413 }
414
415end:
416 mutex_unlock(&dev->mutex);
417 return ret;
418}
419
420static DEVICE_ATTR(user_functions, S_IRUGO | S_IWUSR,
421 functionfs_user_functions_show,
422 functionfs_user_functions_store);
423
424static ssize_t functionfs_max_user_functions_show(struct device *_dev,
425 struct device_attribute *attr,
426 char *buf)
427{
428 return sprintf(buf, "%d", GFS_MAX_DEVS);
429}
430
431static DEVICE_ATTR(max_user_functions, S_IRUGO,
432 functionfs_max_user_functions_show, NULL);
433
434static struct device_attribute *functionfs_function_attributes[] = {
435 &dev_attr_user_functions,
436 &dev_attr_max_user_functions,
437 NULL
438};
439
440static struct ccg_usb_function functionfs_function = {
441 .name = "fs",
442 .init = functionfs_function_init,
443 .cleanup = functionfs_function_cleanup,
444 .bind_config = functionfs_function_bind_config,
445 .unbind_config = functionfs_function_unbind_config,
446 .attributes = functionfs_function_attributes,
447};
448
449#define MAX_ACM_INSTANCES 4
450struct acm_function_config {
451 int instances;
452};
453
454static int
455acm_function_init(struct ccg_usb_function *f, struct usb_composite_dev *cdev)
456{
457 f->config = kzalloc(sizeof(struct acm_function_config), GFP_KERNEL);
458 if (!f->config)
459 return -ENOMEM;
460
461 return gserial_setup(cdev->gadget, MAX_ACM_INSTANCES);
462}
463
464static void acm_function_cleanup(struct ccg_usb_function *f)
465{
466 gserial_cleanup();
467 kfree(f->config);
468 f->config = NULL;
469}
470
471static int
472acm_function_bind_config(struct ccg_usb_function *f,
473 struct usb_configuration *c)
474{
475 int i;
476 int ret = 0;
477 struct acm_function_config *config = f->config;
478
479 for (i = 0; i < config->instances; i++) {
480 ret = acm_bind_config(c, i);
481 if (ret) {
482 pr_err("Could not bind acm%u config\n", i);
483 break;
484 }
485 }
486
487 return ret;
488}
489
490static ssize_t acm_instances_show(struct device *dev,
491 struct device_attribute *attr, char *buf)
492{
493 struct ccg_usb_function *f = dev_get_drvdata(dev);
494 struct acm_function_config *config = f->config;
495 return sprintf(buf, "%d\n", config->instances);
496}
497
498static ssize_t acm_instances_store(struct device *dev,
499 struct device_attribute *attr, const char *buf, size_t size)
500{
501 struct ccg_usb_function *f = dev_get_drvdata(dev);
502 struct acm_function_config *config = f->config;
503 int value;
504 int ret = 0;
505
506 ret = kstrtoint(buf, 10, &value);
507 if (ret)
508 return ret;
509
510 if (value > MAX_ACM_INSTANCES)
511 return -EINVAL;
512
513 config->instances = value;
514
515 return size;
516}
517
518static DEVICE_ATTR(instances, S_IRUGO | S_IWUSR, acm_instances_show,
519 acm_instances_store);
520static struct device_attribute *acm_function_attributes[] = {
521 &dev_attr_instances,
522 NULL
523};
524
525static struct ccg_usb_function acm_function = {
526 .name = "acm",
527 .init = acm_function_init,
528 .cleanup = acm_function_cleanup,
529 .bind_config = acm_function_bind_config,
530 .attributes = acm_function_attributes,
531};
532
533struct rndis_function_config {
534 u8 ethaddr[ETH_ALEN];
535 u32 vendorID;
536 char manufacturer[256];
537 /* "Wireless" RNDIS; auto-detected by Windows */
538 bool wceis;
539};
540
541static int rndis_function_init(struct ccg_usb_function *f,
542 struct usb_composite_dev *cdev)
543{
544 f->config = kzalloc(sizeof(struct rndis_function_config), GFP_KERNEL);
545 if (!f->config)
546 return -ENOMEM;
547 return 0;
548}
549
550static void rndis_function_cleanup(struct ccg_usb_function *f)
551{
552 kfree(f->config);
553 f->config = NULL;
554}
555
556static int rndis_function_bind_config(struct ccg_usb_function *f,
557 struct usb_configuration *c)
558{
559 int ret;
560 struct rndis_function_config *rndis = f->config;
561
562 if (!rndis) {
563 pr_err("%s: rndis_pdata\n", __func__);
564 return -1;
565 }
566
567 pr_info("%s MAC: %02X:%02X:%02X:%02X:%02X:%02X\n", __func__,
568 rndis->ethaddr[0], rndis->ethaddr[1], rndis->ethaddr[2],
569 rndis->ethaddr[3], rndis->ethaddr[4], rndis->ethaddr[5]);
570
571 ret = gether_setup_name(c->cdev->gadget, rndis->ethaddr, "rndis");
572 if (ret) {
573 pr_err("%s: gether_setup failed\n", __func__);
574 return ret;
575 }
576
577 if (rndis->wceis) {
578 /* "Wireless" RNDIS; auto-detected by Windows */
579 rndis_iad_descriptor.bFunctionClass =
580 USB_CLASS_WIRELESS_CONTROLLER;
581 rndis_iad_descriptor.bFunctionSubClass = 0x01;
582 rndis_iad_descriptor.bFunctionProtocol = 0x03;
583 rndis_control_intf.bInterfaceClass =
584 USB_CLASS_WIRELESS_CONTROLLER;
585 rndis_control_intf.bInterfaceSubClass = 0x01;
586 rndis_control_intf.bInterfaceProtocol = 0x03;
587 }
588
589 return rndis_bind_config_vendor(c, rndis->ethaddr, rndis->vendorID,
590 rndis->manufacturer);
591}
592
593static void rndis_function_unbind_config(struct ccg_usb_function *f,
594 struct usb_configuration *c)
595{
596 gether_cleanup();
597}
598
599static ssize_t rndis_manufacturer_show(struct device *dev,
600 struct device_attribute *attr, char *buf)
601{
602 struct ccg_usb_function *f = dev_get_drvdata(dev);
603 struct rndis_function_config *config = f->config;
604 return sprintf(buf, "%s\n", config->manufacturer);
605}
606
607static ssize_t rndis_manufacturer_store(struct device *dev,
608 struct device_attribute *attr, const char *buf, size_t size)
609{
610 struct ccg_usb_function *f = dev_get_drvdata(dev);
611 struct rndis_function_config *config = f->config;
612
613 if (size >= sizeof(config->manufacturer))
614 return -EINVAL;
615 memcpy(config->manufacturer, buf, size);
616 config->manufacturer[size] = 0;
617
618 return size;
619}
620
621static DEVICE_ATTR(manufacturer, S_IRUGO | S_IWUSR, rndis_manufacturer_show,
622 rndis_manufacturer_store);
623
624static ssize_t rndis_wceis_show(struct device *dev,
625 struct device_attribute *attr, char *buf)
626{
627 struct ccg_usb_function *f = dev_get_drvdata(dev);
628 struct rndis_function_config *config = f->config;
629 return sprintf(buf, "%d\n", config->wceis);
630}
631
632static ssize_t rndis_wceis_store(struct device *dev,
633 struct device_attribute *attr, const char *buf, size_t size)
634{
635 struct ccg_usb_function *f = dev_get_drvdata(dev);
636 struct rndis_function_config *config = f->config;
637 int value;
638 int ret;
639
640 ret = kstrtoint(buf, 10, &value);
641 if (ret)
642 return ret;
643
644 config->wceis = value;
645
646 return size;
647}
648
649static DEVICE_ATTR(wceis, S_IRUGO | S_IWUSR, rndis_wceis_show,
650 rndis_wceis_store);
651
652static ssize_t rndis_ethaddr_show(struct device *dev,
653 struct device_attribute *attr, char *buf)
654{
655 struct ccg_usb_function *f = dev_get_drvdata(dev);
656 struct rndis_function_config *rndis = f->config;
657 return sprintf(buf, "%02x:%02x:%02x:%02x:%02x:%02x\n",
658 rndis->ethaddr[0], rndis->ethaddr[1], rndis->ethaddr[2],
659 rndis->ethaddr[3], rndis->ethaddr[4], rndis->ethaddr[5]);
660}
661
662static ssize_t rndis_ethaddr_store(struct device *dev,
663 struct device_attribute *attr, const char *buf, size_t size)
664{
665 struct ccg_usb_function *f = dev_get_drvdata(dev);
666 struct rndis_function_config *rndis = f->config;
667 unsigned char tmp[6];
668
669 if (sscanf(buf, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
670 tmp + 0, tmp + 1, tmp + 2, tmp + 3, tmp + 4, tmp + 5) !=
671 ETH_ALEN)
672 return -EINVAL;
673
674 memcpy(rndis->ethaddr, tmp, ETH_ALEN);
675
676 return ETH_ALEN;
677
678}
679
680static DEVICE_ATTR(ethaddr, S_IRUGO | S_IWUSR, rndis_ethaddr_show,
681 rndis_ethaddr_store);
682
683static ssize_t rndis_vendorID_show(struct device *dev,
684 struct device_attribute *attr, char *buf)
685{
686 struct ccg_usb_function *f = dev_get_drvdata(dev);
687 struct rndis_function_config *config = f->config;
688 return sprintf(buf, "%04x\n", config->vendorID);
689}
690
691static ssize_t rndis_vendorID_store(struct device *dev,
692 struct device_attribute *attr, const char *buf, size_t size)
693{
694 struct ccg_usb_function *f = dev_get_drvdata(dev);
695 struct rndis_function_config *config = f->config;
696 int value;
697 int ret;
698
699 ret = kstrtou32(buf, 16, &value);
700 if (ret)
701 return ret;
702
703 config->vendorID = value;
704
705 return size;
706}
707
708static DEVICE_ATTR(vendorID, S_IRUGO | S_IWUSR, rndis_vendorID_show,
709 rndis_vendorID_store);
710
711static struct device_attribute *rndis_function_attributes[] = {
712 &dev_attr_manufacturer,
713 &dev_attr_wceis,
714 &dev_attr_ethaddr,
715 &dev_attr_vendorID,
716 NULL
717};
718
719static struct ccg_usb_function rndis_function = {
720 .name = "rndis",
721 .init = rndis_function_init,
722 .cleanup = rndis_function_cleanup,
723 .bind_config = rndis_function_bind_config,
724 .unbind_config = rndis_function_unbind_config,
725 .attributes = rndis_function_attributes,
726};
727
728static int mass_storage_function_init(struct ccg_usb_function *f,
729 struct usb_composite_dev *cdev)
730{
731 struct fsg_config fsg;
732 struct fsg_common *common;
733 int err;
734
735 memset(&fsg, 0, sizeof fsg);
736 fsg.nluns = 1;
737 fsg.luns[0].removable = 1;
738 fsg.vendor_name = iManufacturer;
739 fsg.product_name = iProduct;
740
741 common = fsg_common_init(NULL, cdev, &fsg);
742 if (IS_ERR(common))
743 return PTR_ERR(common);
744
745 err = sysfs_create_link(&f->dev->kobj,
746 &common->luns[0].dev.kobj,
747 "lun");
748 if (err) {
749 fsg_common_put(common);
750 return err;
751 }
752
753 f->config = common;
754 return 0;
755}
756
757static void mass_storage_function_cleanup(struct ccg_usb_function *f)
758{
759 fsg_common_put(f->config);
760 f->config = NULL;
761}
762
763static int mass_storage_function_bind_config(struct ccg_usb_function *f,
764 struct usb_configuration *c)
765{
766 struct fsg_common *common = f->config;
767 return fsg_bind_config(c->cdev, c, common);
768}
769
770static struct ccg_usb_function mass_storage_function = {
771 .name = "mass_storage",
772 .init = mass_storage_function_init,
773 .cleanup = mass_storage_function_cleanup,
774 .bind_config = mass_storage_function_bind_config,
775};
776
777static struct ccg_usb_function *supported_functions[] = {
778 &functionfs_function,
779 &acm_function,
780 &rndis_function,
781 &mass_storage_function,
782 NULL
783};
784
785
786static int ccg_init_functions(struct ccg_usb_function **functions,
787 struct usb_composite_dev *cdev)
788{
789 struct ccg_dev *dev = _ccg_dev;
790 struct ccg_usb_function *f;
791 struct device_attribute **attrs;
792 struct device_attribute *attr;
793 int err;
794 int index = 0;
795
796 for (; (f = *functions++); index++) {
797 f->dev_name = kasprintf(GFP_KERNEL, "f_%s", f->name);
798 if (!f->dev_name) {
799 pr_err("%s: Failed to alloc name %s", __func__,
800 f->name);
801 err = -ENOMEM;
802 goto err_alloc;
803 }
804 f->dev = device_create(ccg_class, dev->dev,
805 MKDEV(0, index), f, f->dev_name);
806 if (IS_ERR(f->dev)) {
807 pr_err("%s: Failed to create dev %s", __func__,
808 f->dev_name);
809 err = PTR_ERR(f->dev);
810 f->dev = NULL;
811 goto err_create;
812 }
813
814 if (f->init) {
815 err = f->init(f, cdev);
816 if (err) {
817 pr_err("%s: Failed to init %s", __func__,
818 f->name);
819 goto err_out;
820 }
821 }
822
823 attrs = f->attributes;
824 if (attrs) {
825 while ((attr = *attrs++) && !err)
826 err = device_create_file(f->dev, attr);
827 }
828 if (err) {
829 pr_err("%s: Failed to create function %s attributes",
830 __func__, f->name);
831 goto err_uninit;
832 }
833 }
834 return 0;
835
836err_uninit:
837 if (f->cleanup)
838 f->cleanup(f);
839err_out:
840 device_destroy(ccg_class, f->dev->devt);
841 f->dev = NULL;
842err_create:
843 kfree(f->dev_name);
844err_alloc:
845 return err;
846}
847
848static void ccg_cleanup_functions(struct ccg_usb_function **functions)
849{
850 struct ccg_usb_function *f;
851
852 while (*functions) {
853 f = *functions++;
854
855 if (f->dev) {
856 if (f->cleanup)
857 f->cleanup(f);
858 device_destroy(ccg_class, f->dev->devt);
859 kfree(f->dev_name);
860 }
861 }
862}
863
864static int ccg_bind_enabled_functions(struct ccg_dev *dev,
865 struct usb_configuration *c)
866{
867 struct ccg_usb_function *f;
868 int ret;
869
870 list_for_each_entry(f, &dev->enabled_functions, enabled_list) {
871 ret = f->bind_config(f, c);
872 if (ret) {
873 pr_err("%s: %s failed", __func__, f->name);
874 return ret;
875 }
876 }
877 return 0;
878}
879
880static void ccg_unbind_enabled_functions(struct ccg_dev *dev,
881 struct usb_configuration *c)
882{
883 struct ccg_usb_function *f;
884
885 list_for_each_entry(f, &dev->enabled_functions, enabled_list)
886 if (f->unbind_config)
887 f->unbind_config(f, c);
888}
889
890static int ccg_enable_function(struct ccg_dev *dev, char *name)
891{
892 struct ccg_usb_function **functions = dev->functions;
893 struct ccg_usb_function *f;
894 while ((f = *functions++)) {
895 if (!strcmp(name, f->name)) {
896 list_add_tail(&f->enabled_list,
897 &dev->enabled_functions);
898 return 0;
899 }
900 }
901 return -EINVAL;
902}
903
904/*-------------------------------------------------------------------------*/
905/* /sys/class/ccg_usb/ccg%d/ interface */
906
907static ssize_t
908functions_show(struct device *pdev, struct device_attribute *attr, char *buf)
909{
910 struct ccg_dev *dev = dev_get_drvdata(pdev);
911 struct ccg_usb_function *f;
912 char *buff = buf;
913 int i;
914
915 mutex_lock(&dev->mutex);
916
917 list_for_each_entry(f, &dev->enabled_functions, enabled_list)
918 buff += sprintf(buff, "%s,", f->name);
919 for (i = 0; i < dev->max_func_num; i++)
920 if (dev->ffs_tab[i].used)
921 buff += sprintf(buff, "%s", dev->ffs_tab[i].name);
922
923 mutex_unlock(&dev->mutex);
924
925 if (buff != buf)
926 *(buff-1) = '\n';
927 return buff - buf;
928}
929
930static ssize_t
931functions_store(struct device *pdev, struct device_attribute *attr,
932 const char *buff, size_t size)
933{
934 struct ccg_dev *dev = dev_get_drvdata(pdev);
935 char *name;
936 char buf[256], *b;
937 int err, i;
938 bool functionfs_enabled;
939
940 buff = skip_spaces(buff);
941 if (!*buff)
942 return -EINVAL;
943
944 mutex_lock(&dev->mutex);
945
946 if (dev->enabled) {
947 mutex_unlock(&dev->mutex);
948 return -EBUSY;
949 }
950
951 INIT_LIST_HEAD(&dev->enabled_functions);
952 functionfs_enabled = false;
953 for (i = 0; i < dev->max_func_num; i++)
954 dev->ffs_tab[i].used = false;
955
956 strlcpy(buf, buff, sizeof(buf));
957 b = strim(buf);
958
959 while (b) {
960 struct ffs_obj *user_func;
961
962 name = strsep(&b, ",");
963 /* handle FunctionFS implicitly */
964 if (!strcmp(name, functionfs_function.name)) {
965 pr_err("ccg_usb: Cannot explicitly enable '%s'", name);
966 continue;
967 }
968 user_func = functionfs_find_dev(dev, name);
969 if (user_func)
970 name = functionfs_function.name;
971 err = 0;
972 if (!user_func || !functionfs_enabled)
973 err = ccg_enable_function(dev, name);
974 if (err)
975 pr_err("ccg_usb: Cannot enable '%s'", name);
976 else if (user_func) {
977 user_func->used = true;
978 dev->func_num++;
979 functionfs_enabled = true;
980 }
981 }
982
983 mutex_unlock(&dev->mutex);
984
985 return size;
986}
987
988static ssize_t enable_show(struct device *pdev, struct device_attribute *attr,
989 char *buf)
990{
991 struct ccg_dev *dev = dev_get_drvdata(pdev);
992 return sprintf(buf, "%d\n", dev->enabled);
993}
994
995static ssize_t enable_store(struct device *pdev, struct device_attribute *attr,
996 const char *buff, size_t size)
997{
998 struct ccg_dev *dev = dev_get_drvdata(pdev);
999 struct usb_composite_dev *cdev = dev->cdev;
1000 int enabled = 0;
1001
1002 mutex_lock(&dev->mutex);
1003 sscanf(buff, "%d", &enabled);
1004 if (enabled && dev->func_num && !functionfs_all_ready(dev)) {
1005 mutex_unlock(&dev->mutex);
1006 return -ENODEV;
1007 }
1008
1009 if (enabled && !dev->enabled) {
1010 int ret;
1011
1012 cdev->next_string_id = 0;
1013 /*
1014 * Update values in composite driver's copy of
1015 * device descriptor.
1016 */
1017 cdev->desc.bDeviceClass = device_desc.bDeviceClass;
1018 cdev->desc.bDeviceSubClass = device_desc.bDeviceSubClass;
1019 cdev->desc.bDeviceProtocol = device_desc.bDeviceProtocol;
1020 cdev->desc.idVendor = idVendor;
1021 cdev->desc.idProduct = idProduct;
1022 cdev->desc.bcdDevice = bcdDevice;
1023
1024 usb_add_config(cdev, &ccg_config_driver, ccg_bind_config);
1025 dev->enabled = true;
1026 ret = usb_gadget_connect(cdev->gadget);
1027 if (ret) {
1028 dev->enabled = false;
1029 usb_remove_config(cdev, &ccg_config_driver);
1030 }
1031 } else if (!enabled && dev->enabled) {
1032 reset_usb(dev);
1033 } else {
1034 pr_err("ccg_usb: already %s\n",
1035 dev->enabled ? "enabled" : "disabled");
1036 }
1037
1038 mutex_unlock(&dev->mutex);
1039 return size;
1040}
1041
1042static ssize_t state_show(struct device *pdev, struct device_attribute *attr,
1043 char *buf)
1044{
1045 struct ccg_dev *dev = dev_get_drvdata(pdev);
1046 struct usb_composite_dev *cdev = dev->cdev;
1047 char *state = "DISCONNECTED";
1048 unsigned long flags;
1049
1050 if (!cdev)
1051 goto out;
1052
1053 spin_lock_irqsave(&cdev->lock, flags);
1054 if (cdev->config)
1055 state = "CONFIGURED";
1056 else if (dev->connected)
1057 state = "CONNECTED";
1058 spin_unlock_irqrestore(&cdev->lock, flags);
1059out:
1060 return sprintf(buf, "%s\n", state);
1061}
1062
1063#define DESCRIPTOR_ATTR(field, format_string) \
1064static ssize_t \
1065field ## _show(struct device *dev, struct device_attribute *attr, \
1066 char *buf) \
1067{ \
1068 return sprintf(buf, format_string, device_desc.field); \
1069} \
1070static ssize_t \
1071field ## _store(struct device *dev, struct device_attribute *attr, \
1072 const char *buf, size_t size) \
1073{ \
1074 int value; \
1075 if (sscanf(buf, format_string, &value) == 1) { \
1076 device_desc.field = value; \
1077 return size; \
1078 } \
1079 return -1; \
1080} \
1081static DEVICE_ATTR(field, S_IRUGO | S_IWUSR, field ## _show, field ## _store);
1082
1083DESCRIPTOR_ATTR(bDeviceClass, "%d\n")
1084DESCRIPTOR_ATTR(bDeviceSubClass, "%d\n")
1085DESCRIPTOR_ATTR(bDeviceProtocol, "%d\n")
1086
1087static DEVICE_ATTR(functions, S_IRUGO | S_IWUSR, functions_show,
1088 functions_store);
1089static DEVICE_ATTR(enable, S_IRUGO | S_IWUSR, enable_show, enable_store);
1090static DEVICE_ATTR(state, S_IRUGO, state_show, NULL);
1091
1092static struct device_attribute *ccg_usb_attributes[] = {
1093 &dev_attr_bDeviceClass,
1094 &dev_attr_bDeviceSubClass,
1095 &dev_attr_bDeviceProtocol,
1096 &dev_attr_functions,
1097 &dev_attr_enable,
1098 &dev_attr_state,
1099 NULL
1100};
1101
1102/*-------------------------------------------------------------------------*/
1103/* Composite driver */
1104
1105static int ccg_bind_config(struct usb_configuration *c)
1106{
1107 struct ccg_dev *dev = _ccg_dev;
1108 int ret = 0;
1109
1110 ret = ccg_bind_enabled_functions(dev, c);
1111 if (ret)
1112 return ret;
1113
1114 return 0;
1115}
1116
1117static void ccg_unbind_config(struct usb_configuration *c)
1118{
1119 struct ccg_dev *dev = _ccg_dev;
1120
1121 ccg_unbind_enabled_functions(dev, c);
1122
1123 usb_ep_autoconfig_reset(dev->cdev->gadget);
1124}
1125
1126static int ccg_bind(struct usb_composite_dev *cdev)
1127{
1128 struct ccg_dev *dev = _ccg_dev;
1129 struct usb_gadget *gadget = cdev->gadget;
1130 int gcnum, ret;
1131
1132 /*
1133 * Start disconnected. Userspace will connect the gadget once
1134 * it is done configuring the functions.
1135 */
1136 usb_gadget_disconnect(gadget);
1137
1138 ret = ccg_init_functions(dev->functions, cdev);
1139 if (ret)
1140 return ret;
1141
1142 gcnum = usb_gadget_controller_number(gadget);
1143 if (gcnum >= 0)
1144 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
1145 else {
1146 pr_warning("%s: controller '%s' not recognized\n",
1147 longname, gadget->name);
1148 device_desc.bcdDevice = __constant_cpu_to_le16(0x9999);
1149 }
1150
1151 usb_gadget_set_selfpowered(gadget);
1152 dev->cdev = cdev;
1153
1154 return 0;
1155}
1156
1157static int ccg_usb_unbind(struct usb_composite_dev *cdev)
1158{
1159 struct ccg_dev *dev = _ccg_dev;
1160
1161 cancel_work_sync(&dev->work);
1162 ccg_cleanup_functions(dev->functions);
1163 return 0;
1164}
1165
1166static struct usb_composite_driver ccg_usb_driver = {
1167 .name = "configurable_usb",
1168 .dev = &device_desc,
1169 .unbind = ccg_usb_unbind,
1170 .needs_serial = true,
1171 .iManufacturer = "Linux Foundation",
1172 .iProduct = longname,
1173 .iSerialNumber = "1234567890123456",
1174};
1175
1176static int ccg_setup(struct usb_gadget *gadget, const struct usb_ctrlrequest *c)
1177{
1178 struct ccg_dev *dev = _ccg_dev;
1179 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1180 struct usb_request *req = cdev->req;
1181 struct ccg_usb_function *f;
1182 int value = -EOPNOTSUPP;
1183 unsigned long flags;
1184
1185 req->zero = 0;
1186 req->complete = composite_setup_complete;
1187 req->length = 0;
1188 gadget->ep0->driver_data = cdev;
1189
1190 list_for_each_entry(f, &dev->enabled_functions, enabled_list) {
1191 if (f->ctrlrequest) {
1192 value = f->ctrlrequest(f, cdev, c);
1193 if (value >= 0)
1194 break;
1195 }
1196 }
1197
1198 if (value < 0)
1199 value = composite_setup(gadget, c);
1200
1201 spin_lock_irqsave(&cdev->lock, flags);
1202 if (!dev->connected) {
1203 dev->connected = 1;
1204 schedule_work(&dev->work);
1205 } else if (c->bRequest == USB_REQ_SET_CONFIGURATION &&
1206 cdev->config) {
1207 schedule_work(&dev->work);
1208 }
1209 spin_unlock_irqrestore(&cdev->lock, flags);
1210
1211 return value;
1212}
1213
1214static void ccg_disconnect(struct usb_gadget *gadget)
1215{
1216 struct ccg_dev *dev = _ccg_dev;
1217 struct usb_composite_dev *cdev = get_gadget_data(gadget);
1218 unsigned long flags;
1219
1220 composite_disconnect(gadget);
1221
1222 spin_lock_irqsave(&cdev->lock, flags);
1223 dev->connected = 0;
1224 schedule_work(&dev->work);
1225 spin_unlock_irqrestore(&cdev->lock, flags);
1226}
1227
1228static int ccg_create_device(struct ccg_dev *dev)
1229{
1230 struct device_attribute **attrs = ccg_usb_attributes;
1231 struct device_attribute *attr;
1232 int err;
1233
1234 dev->dev = device_create(ccg_class, NULL, MKDEV(0, 0), NULL, "ccg0");
1235 if (IS_ERR(dev->dev))
1236 return PTR_ERR(dev->dev);
1237
1238 dev_set_drvdata(dev->dev, dev);
1239
1240 while ((attr = *attrs++)) {
1241 err = device_create_file(dev->dev, attr);
1242 if (err) {
1243 device_destroy(ccg_class, dev->dev->devt);
1244 return err;
1245 }
1246 }
1247 return 0;
1248}
1249
1250
1251static int __init init(void)
1252{
1253 struct ccg_dev *dev;
1254 int err;
1255
1256 ccg_class = class_create(THIS_MODULE, "ccg_usb");
1257 if (IS_ERR(ccg_class))
1258 return PTR_ERR(ccg_class);
1259
1260 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1261 if (!dev)
1262 return -ENOMEM;
1263
1264 dev->functions = supported_functions;
1265 INIT_LIST_HEAD(&dev->enabled_functions);
1266 INIT_WORK(&dev->work, ccg_work);
1267 mutex_init(&dev->mutex);
1268
1269 err = ccg_create_device(dev);
1270 if (err) {
1271 class_destroy(ccg_class);
1272 kfree(dev);
1273 return err;
1274 }
1275
1276 _ccg_dev = dev;
1277
1278 /* Override composite driver functions */
1279 composite_driver.setup = ccg_setup;
1280 composite_driver.disconnect = ccg_disconnect;
1281
1282 err = usb_composite_probe(&ccg_usb_driver, ccg_bind);
1283 if (err) {
1284 class_destroy(ccg_class);
1285 kfree(dev);
1286 }
1287
1288 return err;
1289}
1290module_init(init);
1291
1292static void __exit cleanup(void)
1293{
1294 usb_composite_unregister(&ccg_usb_driver);
1295 class_destroy(ccg_class);
1296 kfree(_ccg_dev);
1297 _ccg_dev = NULL;
1298}
1299module_exit(cleanup);
diff --git a/drivers/staging/ccg/sysfs-class-ccg_usb b/drivers/staging/ccg/sysfs-class-ccg_usb
new file mode 100644
index 00000000000..dd12a332fb0
--- /dev/null
+++ b/drivers/staging/ccg/sysfs-class-ccg_usb
@@ -0,0 +1,158 @@
1What: /sys/class/ccg_usb
2Date: May 2012
3KernelVersion: 3.4
4Contact: linux-usb@vger.kernel.org
5Description:
6 The ccg_usb/ class subdirectory belongs to ccg
7 USB gadget.
8
9What: /sys/class/ccg_usb/ccgX
10Date: May 2012
11KernelVersion: 3.4
12Contact: linux-usb@vger.kernel.org
13Description:
14 The /sys/class/ccg_usb/ccg{0,1,2,3...} class
15 subdirectories correspond to each ccg gadget device;
16 at the time of this writing there is only ccg0 and it
17 represents the ccg gadget.
18
19What: /sys/class/ccg_usb/ccgX/functions
20Date: May 2012
21KernelVersion: 3.4
22Contact: linux-usb@vger.kernel.org
23Description:
24 A comma-separated list of USB function names to be activated
25 in this ccg gadget. It includes both the functions provided
26 in-kernel by the ccg gadget and the functions provided from
27 userspace through FunctionFS.
28
29What: /sys/class/ccg_usb/ccgX/enable
30Date: May 2012
31KernelVersion: 3.4
32Contact: linux-usb@vger.kernel.org
33Description:
34 A flag activating/deactivating the ccg usb gadget.
35
36What: /sys/class/ccg_usb/ccgX/state
37Date: May 2012
38KernelVersion: 3.4
39Contact: linux-usb@vger.kernel.org
40Description:
41 Configurable usb gadget state:
42
43 DISCONNECTED
44 CONNECTED
45 CONFIGURED
46
47What: /sys/class/ccg_usb/ccgX/f_acm/
48Date: May 2012
49KernelVersion: 3.4
50Contact: linux-usb@vger.kernel.org
51Description:
52 The /sys/class/ccg_usb/ccgX/f_acm subdirectory
53 corresponds to the gadget's USB CDC serial (ACM) function
54 driver.
55
56What: /sys/class/ccg_usb/ccgX/f_acm/instances
57Date: May 2012
58KernelVersion: 3.4
59Contact: linux-usb@vger.kernel.org
60Description:
61 Maximum number of the /dev/ttyGS<X> interface the driver uses.
62
63What: /sys/class/ccg_usb/ccgX/f_fs
64Date: May 2012
65KernelVersion: 3.4
66Contact: linux-usb@vger.kernel.org
67Description:
68 The /sys/class/ccg_usb/ccgX/f_fs subdirectory
69 corresponds to the gadget's FunctionFS driver.
70
71What: /sys/class/ccg_usb/ccgX/f_fs/user_functions
72Date: May 2012
73KernelVersion: 3.4
74Contact: linux-usb@vger.kernel.org
75Description:
76 A comma-separeted list of USB function names to be supported
77 from userspace. No other userspace FunctionFS functions can
78 be supported than listed here. However, the actual activation
79 of these functions is still done through
80 /sys/class/ccg_usb/ccgX/functions, where it is possible
81 to specify any subset (including maximum and empty) of
82 /sys/class/ccg_usb/ccgX/f_fs/user_functions.
83
84What: /sys/class/ccg_usb/ccgX/f_fs/max_user_functions
85Date: May 2012
86KernelVersion: 3.4
87Contact: linux-usb@vger.kernel.org
88Description:
89 Maximum number of USB functions to be supported from userspace.
90
91What: /sys/class/ccg_usb/ccgX/f_rndis
92Date: May 2012
93KernelVersion: 3.4
94Contact: linux-usb@vger.kernel.org
95Description:
96 The /sys/class/ccg_usb/ccgX/f_rndis subdirectory
97 corresponds to the gadget's RNDIS driver.
98
99What: /sys/class/ccg_usb/ccgX/f_rndis/manufacturer
100Date: May 2012
101KernelVersion: 3.4
102Contact: linux-usb@vger.kernel.org
103Description:
104 RNDIS Ethernet port manufacturer string.
105
106What: /sys/class/ccg_usb/ccgX/f_rndis/wceis
107Date: May 2012
108KernelVersion: 3.4
109Contact: linux-usb@vger.kernel.org
110Description:
111 RNDIS Ethernet port wireless flag.
112
113What: /sys/class/ccg_usb/ccgX/f_rndis/ethaddr
114Date: May 2012
115KernelVersion: 3.4
116Contact: linux-usb@vger.kernel.org
117Description:
118 RNDIS Ethernet port Ethernet address.
119
120What: /sys/class/ccg_usb/ccgX/f_rndis/vendorID
121Date: May 2012
122KernelVersion: 3.4
123Contact: linux-usb@vger.kernel.org
124Description:
125 RNDIS Ethernet port vendor ID.
126
127What: /sys/class/ccg_usb/ccgX/f_mass_storage
128Date: May 2012
129KernelVersion: 3.4
130Contact: linux-usb@vger.kernel.org
131Description:
132 The /sys/class/ccg_usb/ccgX/f_mass_storage subdirectory
133 corresponds to the gadget's USB mass storage driver.
134
135What: /sys/class/ccg_usb/ccgX/f_mass_storage/lun
136Date: May 2012
137KernelVersion: 3.4
138Contact: linux-usb@vger.kernel.org
139Description:
140 The /sys/class/ccg_usb/ccgX/f_mass_storage/lun
141 subdirectory corresponds to the gadget's USB mass storage
142 driver and its underlying storage.
143
144What: /sys/class/ccg_usb/ccgX/f_mass_storage/lun
145Date: May 2012
146KernelVersion: 3.4
147Contact: linux-usb@vger.kernel.org
148Description:
149 The /sys/class/ccg_usb/ccgX/f_mass_storage/lun
150 subdirectory corresponds to the gadget's USB mass storage
151 driver and its underlying storage.
152
153What: /sys/class/ccg_usb/ccgX/f_mass_storage/lun/file
154Date: May 2012
155KernelVersion: 3.4
156Contact: linux-usb@vger.kernel.org
157Description:
158 Gadget's USB mass storage underlying file.
diff --git a/drivers/staging/media/as102/as102_drv.c b/drivers/staging/media/as102/as102_drv.c
index ea4f992de23..ac92eaf6c74 100644
--- a/drivers/staging/media/as102/as102_drv.c
+++ b/drivers/staging/media/as102/as102_drv.c
@@ -279,40 +279,8 @@ void as102_dvb_unregister(struct as102_dev_t *as102_dev)
279 pr_info("Unregistered device %s", as102_dev->name); 279 pr_info("Unregistered device %s", as102_dev->name);
280} 280}
281 281
282static int __init as102_driver_init(void) 282module_usb_driver(as102_usb_driver);
283{
284 int ret;
285
286 /* register this driver with the low level subsystem */
287 ret = usb_register(&as102_usb_driver);
288 if (ret)
289 err("usb_register failed (ret = %d)", ret);
290
291 return ret;
292}
293
294/*
295 * Mandatory function : Adds a special section to the module indicating
296 * where initialisation function is defined
297 */
298module_init(as102_driver_init);
299
300/**
301 * as102_driver_exit - as102 driver exit point
302 *
303 * This function is called when device has to be removed.
304 */
305static void __exit as102_driver_exit(void)
306{
307 /* deregister this driver with the low level bus subsystem */
308 usb_deregister(&as102_usb_driver);
309}
310 283
311/*
312 * required function for unload: Adds a special section to the module
313 * indicating where unload function is defined
314 */
315module_exit(as102_driver_exit);
316/* modinfo details */ 284/* modinfo details */
317MODULE_DESCRIPTION(DRIVER_FULL_NAME); 285MODULE_DESCRIPTION(DRIVER_FULL_NAME);
318MODULE_LICENSE("GPL"); 286MODULE_LICENSE("GPL");
diff --git a/drivers/staging/media/as102/as102_usb_drv.c b/drivers/staging/media/as102/as102_usb_drv.c
index 36150e5c62d..aaf1bc2ad1b 100644
--- a/drivers/staging/media/as102/as102_usb_drv.c
+++ b/drivers/staging/media/as102/as102_usb_drv.c
@@ -375,7 +375,7 @@ static int as102_usb_probe(struct usb_interface *intf,
375 375
376 as102_dev = kzalloc(sizeof(struct as102_dev_t), GFP_KERNEL); 376 as102_dev = kzalloc(sizeof(struct as102_dev_t), GFP_KERNEL);
377 if (as102_dev == NULL) { 377 if (as102_dev == NULL) {
378 err("%s: kzalloc failed", __func__); 378 dev_err(&intf->dev, "%s: kzalloc failed\n", __func__);
379 return -ENOMEM; 379 return -ENOMEM;
380 } 380 }
381 381
@@ -410,8 +410,9 @@ static int as102_usb_probe(struct usb_interface *intf,
410 ret = usb_register_dev(intf, &as102_usb_class_driver); 410 ret = usb_register_dev(intf, &as102_usb_class_driver);
411 if (ret < 0) { 411 if (ret < 0) {
412 /* something prevented us from registering this driver */ 412 /* something prevented us from registering this driver */
413 err("%s: usb_register_dev() failed (errno = %d)", 413 dev_err(&intf->dev,
414 __func__, ret); 414 "%s: usb_register_dev() failed (errno = %d)\n",
415 __func__, ret);
415 goto failed; 416 goto failed;
416 } 417 }
417 418
diff --git a/drivers/staging/media/go7007/go7007.txt b/drivers/staging/media/go7007/go7007.txt
index 9db1f3952fd..fcb3e235abb 100644
--- a/drivers/staging/media/go7007/go7007.txt
+++ b/drivers/staging/media/go7007/go7007.txt
@@ -87,7 +87,6 @@ kernel as built-in or modules:
87 CONFIG_SOUND - Sound card support 87 CONFIG_SOUND - Sound card support
88 CONFIG_SND - Advanced Linux Sound Architecture 88 CONFIG_SND - Advanced Linux Sound Architecture
89 CONFIG_USB - Support for Host-side USB 89 CONFIG_USB - Support for Host-side USB
90 CONFIG_USB_DEVICEFS - USB device filesystem
91 CONFIG_USB_EHCI_HCD - EHCI HCD (USB 2.0) support 90 CONFIG_USB_EHCI_HCD - EHCI HCD (USB 2.0) support
92 91
93Additionally, to use the example application, the following options need to 92Additionally, to use the example application, the following options need to
diff --git a/drivers/staging/octeon/ethernet-tx.c b/drivers/staging/octeon/ethernet-tx.c
index 2d4fcea892f..5631dd9f820 100644
--- a/drivers/staging/octeon/ethernet-tx.c
+++ b/drivers/staging/octeon/ethernet-tx.c
@@ -345,7 +345,7 @@ int cvm_oct_xmit(struct sk_buff *skb, struct net_device *dev)
345 } 345 }
346 if (unlikely 346 if (unlikely
347 (skb->truesize != 347 (skb->truesize !=
348 sizeof(*skb) + skb_end_pointer(skb) - skb->head)) { 348 sizeof(*skb) + skb_end_offset(skb))) {
349 /* 349 /*
350 printk("TX buffer truesize has been changed\n"); 350 printk("TX buffer truesize has been changed\n");
351 */ 351 */
diff --git a/drivers/staging/quatech_usb2/Kconfig b/drivers/staging/quatech_usb2/Kconfig
deleted file mode 100644
index 1494f42f3da..00000000000
--- a/drivers/staging/quatech_usb2/Kconfig
+++ /dev/null
@@ -1,15 +0,0 @@
1config USB_SERIAL_QUATECH_USB2
2 tristate "USB Quatech xSU2-[14]00 USB Serial Driver"
3 depends on USB_SERIAL
4 help
5 Say Y here if you want to use a Quatech USB2.0 to serial adaptor. This
6 driver supports the SSU2-100, DSU2-100, DSU2-400, QSU2-100, QSU2-400,
7 ESU2-400 and ESU2-100 USB2.0 to RS232 / 485 / 422 serial adaptors.
8
9 Some hardware has an incorrect product string and announces itself as
10 ESU-100 (which uses the serqt driver) even though it is an ESU2-100.
11 Check the label on the bottom of your device.
12
13 To compile this driver as a module, choose M here: the module will be
14 called quatech_usb2 .
15
diff --git a/drivers/staging/quatech_usb2/Makefile b/drivers/staging/quatech_usb2/Makefile
deleted file mode 100644
index bcd1f890d16..00000000000
--- a/drivers/staging/quatech_usb2/Makefile
+++ /dev/null
@@ -1 +0,0 @@
1obj-$(CONFIG_USB_SERIAL_QUATECH_USB2) += quatech_usb2.o
diff --git a/drivers/staging/quatech_usb2/TODO b/drivers/staging/quatech_usb2/TODO
deleted file mode 100644
index 67f61dbe14a..00000000000
--- a/drivers/staging/quatech_usb2/TODO
+++ /dev/null
@@ -1,8 +0,0 @@
1Incomplete list of things that this driver does not yet implement completely or
2at all. some of these may not be possible to implement because the hardware
3support does not exist. Others may be possible, but the magic control codes to
4make them happen are unknown, and some may just need the driver support to
5implement them writing.
6
7* Mark/Space parity is not implemented (reported back correctly)
8* IXANY flow control mode is not implemented (flag ignored completely)
diff --git a/drivers/staging/quatech_usb2/quatech_usb2.c b/drivers/staging/quatech_usb2/quatech_usb2.c
deleted file mode 100644
index 801b50d3bc3..00000000000
--- a/drivers/staging/quatech_usb2/quatech_usb2.c
+++ /dev/null
@@ -1,1976 +0,0 @@
1/*
2 * Driver for Quatech Inc USB2.0 to serial adaptors. Largely unrelated to the
3 * serqt_usb driver, based on a re-write of the vendor supplied serqt_usb2 code,
4 * which is unrelated to the serqt_usb2 in the staging kernel
5 */
6
7#include <linux/errno.h>
8#include <linux/init.h>
9#include <linux/slab.h>
10#include <linux/tty.h>
11#include <linux/tty_driver.h>
12#include <linux/tty_flip.h>
13#include <linux/module.h>
14#include <linux/serial.h>
15#include <linux/usb.h>
16#include <linux/usb/serial.h>
17#include <linux/uaccess.h>
18
19static bool debug;
20
21/* Version Information */
22#define DRIVER_VERSION "v2.00"
23#define DRIVER_AUTHOR "Tim Gobeli, Quatech, Inc"
24#define DRIVER_DESC "Quatech USB 2.0 to Serial Driver"
25
26/* vendor and device IDs */
27#define USB_VENDOR_ID_QUATECH 0x061d /* Quatech VID */
28#define QUATECH_SSU2_100 0xC120 /* RS232 single port */
29#define QUATECH_DSU2_100 0xC140 /* RS232 dual port */
30#define QUATECH_DSU2_400 0xC150 /* RS232/422/485 dual port */
31#define QUATECH_QSU2_100 0xC160 /* RS232 four port */
32#define QUATECH_QSU2_400 0xC170 /* RS232/422/485 four port */
33#define QUATECH_ESU2_100 0xC1A0 /* RS232 eight port */
34#define QUATECH_ESU2_400 0xC180 /* RS232/422/485 eight port */
35
36/* magic numbers go here, when we find out which ones are needed */
37
38#define QU2BOXPWRON 0x8000 /* magic number to turn FPGA power on */
39#define QU2BOX232 0x40 /* RS232 mode on MEI devices */
40#define QU2BOXSPD9600 0x60 /* set speed to 9600 baud */
41#define QT2_FIFO_DEPTH 1024 /* size of hardware fifos */
42#define QT2_TX_HEADER_LENGTH 5
43/* length of the header sent to the box with each write URB */
44
45/* directions for USB transfers */
46#define USBD_TRANSFER_DIRECTION_IN 0xc0
47#define USBD_TRANSFER_DIRECTION_OUT 0x40
48
49/* special Quatech command IDs. These are pushed down the
50 USB control pipe to get the box on the end to do things */
51#define QT_SET_GET_DEVICE 0xc2
52#define QT_OPEN_CLOSE_CHANNEL 0xca
53/*#define QT_GET_SET_PREBUF_TRIG_LVL 0xcc
54#define QT_SET_ATF 0xcd*/
55#define QT2_GET_SET_REGISTER 0xc0
56#define QT2_GET_SET_UART 0xc1
57#define QT2_HW_FLOW_CONTROL_MASK 0xc5
58#define QT2_SW_FLOW_CONTROL_MASK 0xc6
59#define QT2_SW_FLOW_CONTROL_DISABLE 0xc7
60#define QT2_BREAK_CONTROL 0xc8
61#define QT2_STOP_RECEIVE 0xe0
62#define QT2_FLUSH_DEVICE 0xc4
63#define QT2_GET_SET_QMCR 0xe1
64
65/* sorts of flush we can do on */
66#define QT2_FLUSH_RX 0x00
67#define QT2_FLUSH_TX 0x01
68
69/* port setting constants, used to set up serial port speeds, flow
70 * control and so on */
71#define QT2_SERIAL_MCR_DTR 0x01
72#define QT2_SERIAL_MCR_RTS 0x02
73#define QT2_SERIAL_MCR_LOOP 0x10
74
75#define QT2_SERIAL_MSR_CTS 0x10
76#define QT2_SERIAL_MSR_CD 0x80
77#define QT2_SERIAL_MSR_RI 0x40
78#define QT2_SERIAL_MSR_DSR 0x20
79#define QT2_SERIAL_MSR_MASK 0xf0
80
81#define QT2_SERIAL_8_DATA 0x03
82#define QT2_SERIAL_7_DATA 0x02
83#define QT2_SERIAL_6_DATA 0x01
84#define QT2_SERIAL_5_DATA 0x00
85
86#define QT2_SERIAL_ODD_PARITY 0x08
87#define QT2_SERIAL_EVEN_PARITY 0x18
88#define QT2_SERIAL_TWO_STOPB 0x04
89#define QT2_SERIAL_ONE_STOPB 0x00
90
91#define QT2_MAX_BAUD_RATE 921600
92#define QT2_MAX_BAUD_REMAINDER 4608
93
94#define QT2_SERIAL_LSR_OE 0x02
95#define QT2_SERIAL_LSR_PE 0x04
96#define QT2_SERIAL_LSR_FE 0x08
97#define QT2_SERIAL_LSR_BI 0x10
98
99/* value of Line Status Register when UART has completed
100 * emptying data out on the line */
101#define QT2_LSR_TEMT 0x40
102
103/* register numbers on each UART, for use with qt2_box_[get|set]_register*/
104#define QT2_XMT_HOLD_REGISTER 0x00
105#define QT2_XVR_BUFFER_REGISTER 0x00
106#define QT2_FIFO_CONTROL_REGISTER 0x02
107#define QT2_LINE_CONTROL_REGISTER 0x03
108#define QT2_MODEM_CONTROL_REGISTER 0x04
109#define QT2_LINE_STATUS_REGISTER 0x05
110#define QT2_MODEM_STATUS_REGISTER 0x06
111
112/* handy macros for doing escape sequence parsing on data reads */
113#define THISCHAR ((unsigned char *)(urb->transfer_buffer))[i]
114#define NEXTCHAR ((unsigned char *)(urb->transfer_buffer))[i + 1]
115#define THIRDCHAR ((unsigned char *)(urb->transfer_buffer))[i + 2]
116#define FOURTHCHAR ((unsigned char *)(urb->transfer_buffer))[i + 3]
117#define FIFTHCHAR ((unsigned char *)(urb->transfer_buffer))[i + 4]
118
119static const struct usb_device_id quausb2_id_table[] = {
120 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_SSU2_100)},
121 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_DSU2_100)},
122 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_DSU2_400)},
123 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_QSU2_100)},
124 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_QSU2_400)},
125 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_ESU2_100)},
126 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_ESU2_400)},
127 {} /* Terminating entry */
128};
129
130MODULE_DEVICE_TABLE(usb, quausb2_id_table);
131
132/* custom structures we need go here */
133static struct usb_driver quausb2_usb_driver = {
134 .name = "quatech-usb2-serial",
135 .probe = usb_serial_probe,
136 .disconnect = usb_serial_disconnect,
137 .id_table = quausb2_id_table,
138};
139
140/**
141 * quatech2_port: Structure in which to keep all the messy stuff that this
142 * driver needs alongside the usb_serial_port structure
143 * @read_urb_busy: Flag indicating that port->read_urb is in use
144 * @close_pending: flag indicating that this port is in the process of
145 * being closed (and so no new reads / writes should be started).
146 * @shadowLSR: Last received state of the line status register, holds the
147 * value of the line status flags from the port
148 * @shadowMSR: Last received state of the modem status register, holds
149 * the value of the modem status received from the port
150 * @rcv_flush: Flag indicating that a receive flush has occurred on
151 * the hardware.
152 * @xmit_flush: Flag indicating that a transmit flush has been processed by
153 * the hardware.
154 * @tx_pending_bytes: Number of bytes waiting to be sent. This total
155 * includes the size (excluding header) of URBs that have been submitted but
156 * have not yet been sent to to the device, and bytes that have been sent out
157 * of the port but not yet reported sent by the "xmit_empty" messages (which
158 * indicate the number of bytes sent each time they are received, despite the
159 * misleading name).
160 * - Starts at zero when port is initialised.
161 * - is incremented by the size of the data to be written (no headers)
162 * each time a write urb is dispatched.
163 * - is decremented each time a "transmit empty" message is received
164 * by the driver in the data stream.
165 * @lock: Mutex to lock access to this structure when we need to ensure that
166 * races don't occur to access bits of it.
167 * @open_count: The number of uses of the port currently having
168 * it open, i.e. the reference count.
169 */
170struct quatech2_port {
171 int magic;
172 bool read_urb_busy;
173 bool close_pending;
174 __u8 shadowLSR;
175 __u8 shadowMSR;
176 bool rcv_flush;
177 bool xmit_flush;
178 int tx_pending_bytes;
179 struct mutex modelock;
180 int open_count;
181
182 char active; /* someone has this device open */
183 unsigned char *xfer_to_tty_buffer;
184 wait_queue_head_t wait;
185 __u8 shadowLCR; /* last LCR value received */
186 __u8 shadowMCR; /* last MCR value received */
187 char RxHolding;
188 struct semaphore pend_xmit_sem; /* locks this structure */
189 spinlock_t lock;
190};
191
192/**
193 * Structure to hold device-wide internal status information
194 * @param ReadBulkStopped The last bulk read attempt ended in tears
195 * @param open_ports The number of serial ports currently in use on the box
196 * @param current_port Pointer to the serial port structure of the port which
197 * the read stream is currently directed to. Escape sequences in the read
198 * stream will change this around as data arrives from different ports on the
199 * box
200 * @buffer_size: The max size buffer each URB can take, used to set the size of
201 * the buffers allocated for writing to each port on the device (we need to
202 * store this because it is known only to the endpoint, but used each time a
203 * port is opened and a new buffer is allocated.
204 */
205struct quatech2_dev {
206 bool ReadBulkStopped;
207 char open_ports;
208 struct usb_serial_port *current_port;
209 int buffer_size;
210};
211
212/* structure which holds line and modem status flags */
213struct qt2_status_data {
214 __u8 line_status;
215 __u8 modem_status;
216};
217
218/* Function prototypes */
219static int qt2_boxpoweron(struct usb_serial *serial);
220static int qt2_boxsetQMCR(struct usb_serial *serial, __u16 Uart_Number,
221 __u8 QMCR_Value);
222static int port_paranoia_check(struct usb_serial_port *port,
223 const char *function);
224static int serial_paranoia_check(struct usb_serial *serial,
225 const char *function);
226static inline struct quatech2_port *qt2_get_port_private(struct usb_serial_port
227 *port);
228static inline void qt2_set_port_private(struct usb_serial_port *port,
229 struct quatech2_port *data);
230static inline struct quatech2_dev *qt2_get_dev_private(struct usb_serial
231 *serial);
232static inline void qt2_set_dev_private(struct usb_serial *serial,
233 struct quatech2_dev *data);
234static int qt2_openboxchannel(struct usb_serial *serial, __u16
235 Uart_Number, struct qt2_status_data *pDeviceData);
236static int qt2_closeboxchannel(struct usb_serial *serial, __u16
237 Uart_Number);
238static int qt2_conf_uart(struct usb_serial *serial, unsigned short Uart_Number,
239 unsigned short divisor, unsigned char LCR);
240static void qt2_read_bulk_callback(struct urb *urb);
241static void qt2_write_bulk_callback(struct urb *urb);
242static void qt2_process_line_status(struct usb_serial_port *port,
243 unsigned char LineStatus);
244static void qt2_process_modem_status(struct usb_serial_port *port,
245 unsigned char ModemStatus);
246static void qt2_process_xmit_empty(struct usb_serial_port *port,
247 unsigned char fourth_char, unsigned char fifth_char);
248static void qt2_process_port_change(struct usb_serial_port *port,
249 unsigned char New_Current_Port);
250static void qt2_process_rcv_flush(struct usb_serial_port *port);
251static void qt2_process_xmit_flush(struct usb_serial_port *port);
252static void qt2_process_rx_char(struct usb_serial_port *port,
253 unsigned char data);
254static int qt2_box_get_register(struct usb_serial *serial,
255 unsigned char uart_number, unsigned short register_num,
256 __u8 *pValue);
257static int qt2_box_set_register(struct usb_serial *serial,
258 unsigned short Uart_Number, unsigned short Register_Num,
259 unsigned short Value);
260static int qt2_boxsetuart(struct usb_serial *serial, unsigned short Uart_Number,
261 unsigned short default_divisor, unsigned char default_LCR);
262static int qt2_boxsethw_flowctl(struct usb_serial *serial,
263 unsigned int UartNumber, bool bSet);
264static int qt2_boxsetsw_flowctl(struct usb_serial *serial, __u16 UartNumber,
265 unsigned char stop_char, unsigned char start_char);
266static int qt2_boxunsetsw_flowctl(struct usb_serial *serial, __u16 UartNumber);
267static int qt2_boxstoprx(struct usb_serial *serial, unsigned short uart_number,
268 unsigned short stop);
269
270/* implementation functions, roughly in order of use, are here */
271static int qt2_calc_num_ports(struct usb_serial *serial)
272{
273 int num_ports;
274 int flag_as_400;
275 switch (serial->dev->descriptor.idProduct) {
276 case QUATECH_SSU2_100:
277 num_ports = 1;
278 break;
279
280 case QUATECH_DSU2_400:
281 flag_as_400 = true;
282 case QUATECH_DSU2_100:
283 num_ports = 2;
284 break;
285
286 case QUATECH_QSU2_400:
287 flag_as_400 = true;
288 case QUATECH_QSU2_100:
289 num_ports = 4;
290 break;
291
292 case QUATECH_ESU2_400:
293 flag_as_400 = true;
294 case QUATECH_ESU2_100:
295 num_ports = 8;
296 break;
297 default:
298 num_ports = 1;
299 break;
300 }
301 return num_ports;
302}
303
304static int qt2_attach(struct usb_serial *serial)
305{
306 struct usb_serial_port *port;
307 struct quatech2_port *qt2_port; /* port-specific private data pointer */
308 struct quatech2_dev *qt2_dev; /* dev-specific private data pointer */
309 int i;
310 /* stuff for storing endpoint addresses now */
311 struct usb_endpoint_descriptor *endpoint;
312 struct usb_host_interface *iface_desc;
313 struct usb_serial_port *port0; /* first port structure on device */
314
315 /* check how many endpoints there are on the device, for
316 * sanity's sake */
317 dbg("%s(): Endpoints: %d bulk in, %d bulk out, %d interrupt in",
318 __func__, serial->num_bulk_in,
319 serial->num_bulk_out, serial->num_interrupt_in);
320 if ((serial->num_bulk_in != 1) || (serial->num_bulk_out != 1)) {
321 dbg("Device has wrong number of bulk endpoints!");
322 return -ENODEV;
323 }
324 iface_desc = serial->interface->cur_altsetting;
325
326 /* Set up per-device private data, storing extra data alongside
327 * struct usb_serial */
328 qt2_dev = kzalloc(sizeof(*qt2_dev), GFP_KERNEL);
329 if (!qt2_dev) {
330 dbg("%s: kmalloc for quatech2_dev failed!",
331 __func__);
332 return -ENOMEM;
333 }
334 qt2_dev->open_ports = 0; /* no ports open */
335 qt2_set_dev_private(serial, qt2_dev); /* store private data */
336
337 /* Now setup per port private data, which replaces all the things
338 * that quatech added to standard kernel structures in their driver */
339 for (i = 0; i < serial->num_ports; i++) {
340 port = serial->port[i];
341 qt2_port = kzalloc(sizeof(*qt2_port), GFP_KERNEL);
342 if (!qt2_port) {
343 dbg("%s: kmalloc for quatech2_port (%d) failed!.",
344 __func__, i);
345 return -ENOMEM;
346 }
347 /* initialise stuff in the structure */
348 qt2_port->open_count = 0; /* port is not open */
349 spin_lock_init(&qt2_port->lock);
350 mutex_init(&qt2_port->modelock);
351 qt2_set_port_private(port, qt2_port);
352 }
353
354 /* gain access to port[0]'s structure because we want to store
355 * device-level stuff in it */
356 if (serial_paranoia_check(serial, __func__))
357 return -ENODEV;
358 port0 = serial->port[0]; /* get the first port's device structure */
359
360 /* print endpoint addresses so we can check them later
361 * by hand */
362 for (i = 0; i < iface_desc->desc.bNumEndpoints; ++i) {
363 endpoint = &iface_desc->endpoint[i].desc;
364 if ((endpoint->bEndpointAddress & 0x80) &&
365 ((endpoint->bmAttributes & 3) == 0x02)) {
366 /* we found a bulk in endpoint */
367 dbg("found bulk in at %#.2x",
368 endpoint->bEndpointAddress);
369 }
370
371 if (((endpoint->bEndpointAddress & 0x80) == 0x00) &&
372 ((endpoint->bmAttributes & 3) == 0x02)) {
373 /* we found a bulk out endpoint */
374 dbg("found bulk out at %#.2x",
375 endpoint->bEndpointAddress);
376 qt2_dev->buffer_size = endpoint->wMaxPacketSize;
377 /* max size of URB needs recording for the device */
378 }
379 } /* end printing endpoint addresses */
380
381 /* switch on power to the hardware */
382 if (qt2_boxpoweron(serial) < 0) {
383 dbg("qt2_boxpoweron() failed");
384 goto startup_error;
385 }
386 /* set all ports to RS232 mode */
387 for (i = 0; i < serial->num_ports; ++i) {
388 if (qt2_boxsetQMCR(serial, i, QU2BOX232) < 0) {
389 dbg("qt2_boxsetQMCR() on port %d failed",
390 i);
391 goto startup_error;
392 }
393 }
394
395 return 0;
396
397startup_error:
398 for (i = 0; i < serial->num_ports; i++) {
399 port = serial->port[i];
400 qt2_port = qt2_get_port_private(port);
401 kfree(qt2_port);
402 qt2_set_port_private(port, NULL);
403 }
404 qt2_dev = qt2_get_dev_private(serial);
405 kfree(qt2_dev);
406 qt2_set_dev_private(serial, NULL);
407
408 dbg("Exit fail %s\n", __func__);
409 return -EIO;
410}
411
412static void qt2_release(struct usb_serial *serial)
413{
414 struct usb_serial_port *port;
415 struct quatech2_port *qt_port;
416 int i;
417
418 dbg("enterting %s", __func__);
419
420 for (i = 0; i < serial->num_ports; i++) {
421 port = serial->port[i];
422 if (!port)
423 continue;
424
425 qt_port = usb_get_serial_port_data(port);
426 kfree(qt_port);
427 usb_set_serial_port_data(port, NULL);
428 }
429}
430/* This function is called once per serial port on the device, when
431 * that port is opened by a userspace application.
432 * The tty_struct and the usb_serial_port belong to this port,
433 * i.e. there are multiple ones for a multi-port device.
434 * However the usb_serial_port structure has a back-pointer
435 * to the parent usb_serial structure which belongs to the device,
436 * so we can access either the device-wide information or
437 * any other port's information (because there are also forward
438 * pointers) via that pointer.
439 * This is most helpful if the device shares resources (e.g. end
440 * points) between different ports
441 */
442int qt2_open(struct tty_struct *tty, struct usb_serial_port *port)
443{
444 struct usb_serial *serial; /* device structure */
445 struct usb_serial_port *port0; /* first port structure on device */
446 struct quatech2_port *port_extra; /* extra data for this port */
447 struct quatech2_port *port0_extra; /* extra data for first port */
448 struct quatech2_dev *dev_extra; /* extra data for the device */
449 struct qt2_status_data ChannelData;
450 unsigned short default_divisor = QU2BOXSPD9600;
451 unsigned char default_LCR = QT2_SERIAL_8_DATA;
452 int status;
453 int result;
454
455 if (port_paranoia_check(port, __func__))
456 return -ENODEV;
457
458 dbg("%s(): port %d", __func__, port->number);
459
460 serial = port->serial; /* get the parent device structure */
461 if (serial_paranoia_check(serial, __func__)) {
462 dbg("usb_serial struct failed sanity check");
463 return -ENODEV;
464 }
465 dev_extra = qt2_get_dev_private(serial);
466 /* get the device private data */
467 if (dev_extra == NULL) {
468 dbg("device extra data pointer is null");
469 return -ENODEV;
470 }
471 port0 = serial->port[0]; /* get the first port's device structure */
472 if (port_paranoia_check(port0, __func__)) {
473 dbg("port0 usb_serial_port struct failed sanity check");
474 return -ENODEV;
475 }
476
477 port_extra = qt2_get_port_private(port);
478 port0_extra = qt2_get_port_private(port0);
479 if (port_extra == NULL || port0_extra == NULL) {
480 dbg("failed to get private data for port or port0");
481 return -ENODEV;
482 }
483
484 /* FIXME: are these needed? Does it even do anything useful? */
485 /* get the modem and line status values from the UART */
486 status = qt2_openboxchannel(serial, port->number,
487 &ChannelData);
488 if (status < 0) {
489 dbg("qt2_openboxchannel on channel %d failed",
490 port->number);
491 return status;
492 }
493 port_extra->shadowLSR = ChannelData.line_status &
494 (QT2_SERIAL_LSR_OE | QT2_SERIAL_LSR_PE |
495 QT2_SERIAL_LSR_FE | QT2_SERIAL_LSR_BI);
496 port_extra->shadowMSR = ChannelData.modem_status &
497 (QT2_SERIAL_MSR_CTS | QT2_SERIAL_MSR_DSR |
498 QT2_SERIAL_MSR_RI | QT2_SERIAL_MSR_CD);
499
500/* port_extra->fifo_empty_flag = true;*/
501 dbg("qt2_openboxchannel on channel %d completed.",
502 port->number);
503
504 /* Set Baud rate to default and turn off flow control here */
505 status = qt2_conf_uart(serial, port->number, default_divisor,
506 default_LCR);
507 if (status < 0) {
508 dbg("qt2_conf_uart() failed on channel %d",
509 port->number);
510 return status;
511 }
512 dbg("qt2_conf_uart() completed on channel %d",
513 port->number);
514
515 /*
516 * At this point we will need some end points to make further progress.
517 * Handlily, the correct endpoint addresses have been filled out into
518 * the usb_serial_port structure for us by the driver core, so we
519 * already have access to them.
520 * As there is only one bulk in and one bulk out end-point, these are in
521 * port[0]'s structure, and the rest are uninitialised. Handily,
522 * when we do a write to a port, we will use the same endpoint
523 * regardless of the port, with a 5-byte header added on to
524 * tell the box which port it should eventually come out of, so we only
525 * need the one set of endpoints. We will have one URB per port for
526 * writing, so that multiple ports can be writing at once.
527 * Finally we need a bulk in URB to use for background reads from the
528 * device, which will deal with uplink data from the box to host.
529 */
530 dbg("port0 bulk in endpoint is %#.2x", port0->bulk_in_endpointAddress);
531 dbg("port0 bulk out endpoint is %#.2x",
532 port0->bulk_out_endpointAddress);
533
534 /* set up write_urb for bulk out transfers on this port. The USB
535 * serial framework will have allocated a blank URB, buffer etc for
536 * port0 when it put the endpoints there, but not for any of the other
537 * ports on the device because there are no more endpoints. Thus we
538 * have to allocate our own URBs for ports 1-7
539 */
540 if (port->write_urb == NULL) {
541 dbg("port->write_urb == NULL, allocating one");
542 port->write_urb = usb_alloc_urb(0, GFP_KERNEL);
543 if (!port->write_urb) {
544 dev_err(&port->dev, "Allocating write URB failed\n");
545 return -ENOMEM;
546 }
547 /* buffer same size as port0 */
548 port->bulk_out_size = dev_extra->buffer_size;
549 port->bulk_out_buffer = kmalloc(port->bulk_out_size,
550 GFP_KERNEL);
551 if (!port->bulk_out_buffer) {
552 dev_err(&port->dev, "Couldn't allocate bulk_out_buffer\n");
553 return -ENOMEM;
554 }
555 }
556 if (serial->dev == NULL)
557 dbg("serial->dev == NULL");
558 dbg("port->bulk_out_size is %d", port->bulk_out_size);
559
560 usb_fill_bulk_urb(port->write_urb, serial->dev,
561 usb_sndbulkpipe(serial->dev,
562 port0->bulk_out_endpointAddress),
563 port->bulk_out_buffer,
564 port->bulk_out_size,
565 qt2_write_bulk_callback,
566 port);
567 port_extra->tx_pending_bytes = 0;
568
569 if (dev_extra->open_ports == 0) {
570 /* this is first port to be opened, so need the read URB
571 * initialised for bulk in transfers (this is shared amongst
572 * all the ports on the device) */
573 usb_fill_bulk_urb(port0->read_urb, serial->dev,
574 usb_rcvbulkpipe(serial->dev,
575 port0->bulk_in_endpointAddress),
576 port0->bulk_in_buffer,
577 port0->bulk_in_size,
578 qt2_read_bulk_callback, serial);
579 dbg("port0 bulk in URB initialised");
580
581 /* submit URB, i.e. start reading from device (async) */
582 dev_extra->ReadBulkStopped = false;
583 port_extra->read_urb_busy = true;
584 result = usb_submit_urb(port->read_urb, GFP_KERNEL);
585 if (result) {
586 dev_err(&port->dev,
587 "%s(): Error %d submitting bulk in urb",
588 __func__, result);
589 port_extra->read_urb_busy = false;
590 dev_extra->ReadBulkStopped = true;
591 }
592
593 /* When the first port is opened, initialise the value of
594 * current_port in dev_extra to this port, so it is set
595 * to something. Once the box sends data it will send the
596 * relevant escape sequences to get it to the right port anyway
597 */
598 dev_extra->current_port = port;
599 }
600
601 /* initialize our wait queues */
602 init_waitqueue_head(&port_extra->wait);
603 /* increment the count of openings of this port by one */
604 port_extra->open_count++;
605
606 /* remember to store dev_extra, port_extra and port0_extra back again at
607 * end !*/
608 qt2_set_port_private(port, port_extra);
609 qt2_set_port_private(serial->port[0], port0_extra);
610 qt2_set_dev_private(serial, dev_extra);
611
612 dev_extra->open_ports++; /* one more port opened */
613
614 return 0;
615}
616
617/* called when a port is closed by userspace. It won't be called, however,
618 * until calls to chars_in_buffer() reveal that the port has completed
619 * sending buffered data, and there is nothing else to do. Thus we don't have
620 * to rely on forcing data through in this function. */
621/* Setting close_pending should keep new data from being written out,
622 * once all the data in the enpoint buffers is moved out we won't get
623 * any more. */
624/* BoxStopReceive would keep any more data from coming from a given
625 * port, but isn't called by the vendor driver, although their comments
626 * mention it. Should it be used here to stop the inbound data
627 * flow?
628 */
629static void qt2_close(struct usb_serial_port *port)
630{
631 /* time out value for flush loops */
632 unsigned long jift;
633 struct quatech2_port *port_extra; /* extra data for this port */
634 struct usb_serial *serial; /* device structure */
635 struct quatech2_dev *dev_extra; /* extra data for the device */
636 __u8 lsr_value = 0; /* value of Line Status Register */
637 int status; /* result of last USB comms function */
638
639 dbg("%s(): port %d", __func__, port->number);
640 serial = port->serial; /* get the parent device structure */
641 dev_extra = qt2_get_dev_private(serial);
642 /* get the device private data */
643 port_extra = qt2_get_port_private(port); /* port private data */
644
645 /* we can now (and only now) stop reading data */
646 port_extra->close_pending = true;
647 dbg("%s(): port_extra->close_pending = true", __func__);
648 /* although the USB side is now empty, the UART itself may
649 * still be pushing characters out over the line, so we have to
650 * wait testing the actual line status until the lines change
651 * indicating that the data is done transferring. */
652 /* FIXME: slow this polling down so it doesn't run the USB bus flat out
653 * if it actually has to spend any time in this loop (which it normally
654 * doesn't because the buffer is nearly empty) */
655 jift = jiffies + (10 * HZ); /* 10 sec timeout */
656 do {
657 status = qt2_box_get_register(serial, port->number,
658 QT2_LINE_STATUS_REGISTER, &lsr_value);
659 if (status < 0) {
660 dbg("%s(): qt2_box_get_register failed", __func__);
661 break;
662 }
663 if ((lsr_value & QT2_LSR_TEMT)) {
664 dbg("UART done sending");
665 break;
666 }
667 schedule();
668 } while (jiffies <= jift);
669
670 status = qt2_closeboxchannel(serial, port->number);
671 if (status < 0)
672 dbg("%s(): port %d qt2_box_open_close_channel failed",
673 __func__, port->number);
674 /* to avoid leaking URBs, we should now free the write_urb for this
675 * port and set the pointer to null so that next time the port is opened
676 * a new URB is allocated. This avoids leaking URBs when the device is
677 * removed */
678 usb_free_urb(port->write_urb);
679 kfree(port->bulk_out_buffer);
680 port->bulk_out_buffer = NULL;
681 port->bulk_out_size = 0;
682
683 /* decrement the count of openings of this port by one */
684 port_extra->open_count--;
685 /* one less overall open as well */
686 dev_extra->open_ports--;
687 dbg("%s(): Exit, dev_extra->open_ports = %d", __func__,
688 dev_extra->open_ports);
689}
690
691/**
692 * qt2_write - write bytes from the tty layer out to the USB device.
693 * @buf: The data to be written, size at least count.
694 * @count: The number of bytes requested for transmission.
695 * @return The number of bytes actually accepted for transmission to the device.
696 */
697static int qt2_write(struct tty_struct *tty, struct usb_serial_port *port,
698 const unsigned char *buf, int count)
699{
700 struct usb_serial *serial; /* parent device struct */
701 __u8 header_array[5]; /* header used to direct writes to the correct
702 port on the device */
703 struct quatech2_port *port_extra; /* extra data for this port */
704 int result;
705
706 serial = port->serial; /* get the parent device of the port */
707 port_extra = qt2_get_port_private(port); /* port extra info */
708 if (serial == NULL)
709 return -ENODEV;
710 dbg("%s(): port %d, requested to write %d bytes, %d already pending",
711 __func__, port->number, count, port_extra->tx_pending_bytes);
712
713 if (count <= 0) {
714 dbg("%s(): write request of <= 0 bytes", __func__);
715 return 0; /* no bytes written */
716 }
717
718 /* check if the write urb is already in use, i.e. data already being
719 * sent to this port */
720 if ((port->write_urb->status == -EINPROGRESS)) {
721 /* Fifo hasn't been emptied since last write to this port */
722 dbg("%s(): already writing, port->write_urb->status == "
723 "-EINPROGRESS", __func__);
724 /* schedule_work(&port->work); commented in vendor driver */
725 return 0;
726 } else if (port_extra->tx_pending_bytes >= QT2_FIFO_DEPTH) {
727 /* buffer is full (==). > should not occur, but would indicate
728 * that an overflow had occurred */
729 dbg("%s(): port transmit buffer is full!", __func__);
730 /* schedule_work(&port->work); commented in vendor driver */
731 return 0;
732 }
733
734 /* We must fill the first 5 bytes of anything we sent with a transmit
735 * header which directs the data to the correct port. The maximum
736 * size we can send out in one URB is port->bulk_out_size, which caps
737 * the number of bytes of real data we can send in each write. As the
738 * semantics of write allow us to write less than we were give, we cap
739 * the maximum we will ever write to the device as 5 bytes less than
740 * one URB's worth, by reducing the value of the count argument
741 * appropriately*/
742 if (count > port->bulk_out_size - QT2_TX_HEADER_LENGTH) {
743 count = port->bulk_out_size - QT2_TX_HEADER_LENGTH;
744 dbg("%s(): write request bigger than urb, only accepting "
745 "%d bytes", __func__, count);
746 }
747 /* we must also ensure that the FIFO at the other end can cope with the
748 * URB we send it, otherwise it will have problems. As above, we can
749 * restrict the write size by just shrinking count.*/
750 if (count > (QT2_FIFO_DEPTH - port_extra->tx_pending_bytes)) {
751 count = QT2_FIFO_DEPTH - port_extra->tx_pending_bytes;
752 dbg("%s(): not enough room in buffer, only accepting %d bytes",
753 __func__, count);
754 }
755 /* now build the header for transmission */
756 header_array[0] = 0x1b;
757 header_array[1] = 0x1b;
758 header_array[2] = (__u8)port->number;
759 header_array[3] = (__u8)count;
760 header_array[4] = (__u8)count >> 8;
761 /* copy header into URB */
762 memcpy(port->write_urb->transfer_buffer, header_array,
763 QT2_TX_HEADER_LENGTH);
764 /* and actual data to write */
765 memcpy(port->write_urb->transfer_buffer + 5, buf, count);
766
767 dbg("%s(): first data byte to send = %#.2x", __func__, *buf);
768
769 /* set up our urb */
770 usb_fill_bulk_urb(port->write_urb, serial->dev,
771 usb_sndbulkpipe(serial->dev,
772 port->bulk_out_endpointAddress),
773 port->write_urb->transfer_buffer, count + 5,
774 (qt2_write_bulk_callback), port);
775 /* send the data out the bulk port */
776 result = usb_submit_urb(port->write_urb, GFP_ATOMIC);
777 if (result) {
778 /* error couldn't submit urb */
779 result = 0; /* return 0 as nothing got written */
780 dbg("%s(): failed submitting write urb, error %d",
781 __func__, result);
782 } else {
783 port_extra->tx_pending_bytes += count;
784 result = count; /* return number of bytes written, i.e. count */
785 dbg("%s(): submitted write urb, wrote %d bytes, "
786 "total pending bytes %d",
787 __func__, result, port_extra->tx_pending_bytes);
788 }
789 return result;
790}
791
792/* This is used by the next layer up to know how much space is available
793 * in the buffer on the device. It is used on a device closure to avoid
794 * calling close() until the buffer is reported to be empty.
795 * The returned value must never go down by more than the number of bytes
796 * written for correct behaviour further up the driver stack, i.e. if I call
797 * it, then write 6 bytes, then call again I should get 6 less, or possibly
798 * only 5 less if one was written in the meantime, etc. I should never get 7
799 * less (or any bigger number) because I only wrote 6 bytes.
800 */
801static int qt2_write_room(struct tty_struct *tty)
802{
803 struct usb_serial_port *port = tty->driver_data;
804 /* parent usb_serial_port pointer */
805 struct quatech2_port *port_extra; /* extra data for this port */
806 int room = 0;
807 port_extra = qt2_get_port_private(port);
808
809 if (port_extra->close_pending == true) {
810 dbg("%s(): port_extra->close_pending == true", __func__);
811 return -ENODEV;
812 }
813 /* Q: how many bytes would a write() call actually succeed in writing
814 * if it happened now?
815 * A: one QT2_FIFO_DEPTH, less the number of bytes waiting to be sent
816 * out of the port, unless this is more than the size of the
817 * write_urb output buffer less the header, which is the maximum
818 * size write we can do.
819
820 * Most of the implementation of this is done when writes to the device
821 * are started or terminate. When we send a write to the device, we
822 * reduce the free space count by the size of the dispatched write.
823 * When a "transmit empty" message comes back up the USB read stream,
824 * we decrement the count by the number of bytes reported sent, thus
825 * keeping track of the difference between sent and received bytes.
826 */
827
828 room = (QT2_FIFO_DEPTH - port_extra->tx_pending_bytes);
829 /* space in FIFO */
830 if (room > port->bulk_out_size - QT2_TX_HEADER_LENGTH)
831 room = port->bulk_out_size - QT2_TX_HEADER_LENGTH;
832 /* if more than the URB can hold, then cap to that limit */
833
834 dbg("%s(): port %d: write room is %d", __func__, port->number, room);
835 return room;
836}
837
838static int qt2_chars_in_buffer(struct tty_struct *tty)
839{
840 struct usb_serial_port *port = tty->driver_data;
841 /* parent usb_serial_port pointer */
842 struct quatech2_port *port_extra; /* extra data for this port */
843 port_extra = qt2_get_port_private(port);
844
845 dbg("%s(): port %d: chars_in_buffer = %d", __func__,
846 port->number, port_extra->tx_pending_bytes);
847 return port_extra->tx_pending_bytes;
848}
849
850/* called when userspace does an ioctl() on the device. Note that
851 * TIOCMGET and TIOCMSET are filtered off to their own methods before they get
852 * here, so we don't have to handle them.
853 */
854static int qt2_ioctl(struct tty_struct *tty,
855 unsigned int cmd, unsigned long arg)
856{
857 struct usb_serial_port *port = tty->driver_data;
858 struct usb_serial *serial = port->serial;
859 __u8 mcr_value; /* Modem Control Register value */
860 __u8 msr_value; /* Modem Status Register value */
861 unsigned short prev_msr_value; /* Previous value of Modem Status
862 * Register used to implement waiting for a line status change to
863 * occur */
864 struct quatech2_port *port_extra; /* extra data for this port */
865 DECLARE_WAITQUEUE(wait, current);
866 /* Declare a wait queue named "wait" */
867
868 unsigned int value;
869 unsigned int UartNumber;
870
871 if (serial == NULL)
872 return -ENODEV;
873 UartNumber = tty->index - serial->minor;
874 port_extra = qt2_get_port_private(port);
875
876 dbg("%s(): port %d, UartNumber %d, tty =0x%p", __func__,
877 port->number, UartNumber, tty);
878
879 if (cmd == TIOCMBIS || cmd == TIOCMBIC) {
880 if (qt2_box_get_register(port->serial, UartNumber,
881 QT2_MODEM_CONTROL_REGISTER, &mcr_value) < 0)
882 return -ESPIPE;
883 if (copy_from_user(&value, (unsigned int *)arg,
884 sizeof(value)))
885 return -EFAULT;
886
887 switch (cmd) {
888 case TIOCMBIS:
889 if (value & TIOCM_RTS)
890 mcr_value |= QT2_SERIAL_MCR_RTS;
891 if (value & TIOCM_DTR)
892 mcr_value |= QT2_SERIAL_MCR_DTR;
893 if (value & TIOCM_LOOP)
894 mcr_value |= QT2_SERIAL_MCR_LOOP;
895 break;
896 case TIOCMBIC:
897 if (value & TIOCM_RTS)
898 mcr_value &= ~QT2_SERIAL_MCR_RTS;
899 if (value & TIOCM_DTR)
900 mcr_value &= ~QT2_SERIAL_MCR_DTR;
901 if (value & TIOCM_LOOP)
902 mcr_value &= ~QT2_SERIAL_MCR_LOOP;
903 break;
904 default:
905 break;
906 } /* end of local switch on cmd */
907 if (qt2_box_set_register(port->serial, UartNumber,
908 QT2_MODEM_CONTROL_REGISTER, mcr_value) < 0) {
909 return -ESPIPE;
910 } else {
911 port_extra->shadowMCR = mcr_value;
912 return 0;
913 }
914 } else if (cmd == TIOCMIWAIT) {
915 dbg("%s() port %d, cmd == TIOCMIWAIT enter",
916 __func__, port->number);
917 prev_msr_value = port_extra->shadowMSR & QT2_SERIAL_MSR_MASK;
918 barrier();
919 __set_current_state(TASK_INTERRUPTIBLE);
920 while (1) {
921 add_wait_queue(&port_extra->wait, &wait);
922 schedule();
923 dbg("%s(): port %d, cmd == TIOCMIWAIT here\n",
924 __func__, port->number);
925 remove_wait_queue(&port_extra->wait, &wait);
926 /* see if a signal woke us up */
927 if (signal_pending(current))
928 return -ERESTARTSYS;
929 set_current_state(TASK_INTERRUPTIBLE);
930 msr_value = port_extra->shadowMSR & QT2_SERIAL_MSR_MASK;
931 if (msr_value == prev_msr_value) {
932 __set_current_state(TASK_RUNNING);
933 return -EIO; /* no change - error */
934 }
935 if ((arg & TIOCM_RNG &&
936 ((prev_msr_value & QT2_SERIAL_MSR_RI) ==
937 (msr_value & QT2_SERIAL_MSR_RI))) ||
938 (arg & TIOCM_DSR &&
939 ((prev_msr_value & QT2_SERIAL_MSR_DSR) ==
940 (msr_value & QT2_SERIAL_MSR_DSR))) ||
941 (arg & TIOCM_CD &&
942 ((prev_msr_value & QT2_SERIAL_MSR_CD) ==
943 (msr_value & QT2_SERIAL_MSR_CD))) ||
944 (arg & TIOCM_CTS &&
945 ((prev_msr_value & QT2_SERIAL_MSR_CTS) ==
946 (msr_value & QT2_SERIAL_MSR_CTS)))) {
947 __set_current_state(TASK_RUNNING);
948 return 0;
949 }
950 } /* end inifinite while */
951 /* FIXME: This while loop needs a way to break out if the device
952 * is disconnected while a process is waiting for the MSR to
953 * change, because once it's disconnected, it isn't going to
954 * change state ... */
955 } else {
956 /* any other ioctls we don't know about come here */
957 dbg("%s(): No ioctl for that one. port = %d", __func__,
958 port->number);
959 return -ENOIOCTLCMD;
960 }
961}
962
963/* Called when the user wishes to change the port settings using the termios
964 * userspace interface */
965static void qt2_set_termios(struct tty_struct *tty,
966 struct usb_serial_port *port, struct ktermios *old_termios)
967{
968 struct usb_serial *serial; /* parent serial device */
969 int baud, divisor, remainder;
970 unsigned char LCR_change_to = 0;
971 int status;
972 __u16 UartNumber;
973
974 dbg("%s(): port %d", __func__, port->number);
975
976 serial = port->serial;
977
978 UartNumber = port->number;
979
980 if (old_termios && !tty_termios_hw_change(old_termios, tty->termios))
981 return;
982
983 switch (tty->termios->c_cflag) {
984 case CS5:
985 LCR_change_to |= QT2_SERIAL_5_DATA;
986 break;
987 case CS6:
988 LCR_change_to |= QT2_SERIAL_6_DATA;
989 break;
990 case CS7:
991 LCR_change_to |= QT2_SERIAL_7_DATA;
992 break;
993 default:
994 case CS8:
995 LCR_change_to |= QT2_SERIAL_8_DATA;
996 break;
997 }
998
999 /* Parity stuff */
1000 if (tty->termios->c_cflag & PARENB) {
1001 if (tty->termios->c_cflag & PARODD)
1002 LCR_change_to |= QT2_SERIAL_ODD_PARITY;
1003 else
1004 LCR_change_to |= QT2_SERIAL_EVEN_PARITY;
1005 }
1006 /* Because LCR_change_to is initialised to zero, we don't have to worry
1007 * about the case where PARENB is not set or clearing bits, because by
1008 * default all of them are cleared, turning parity off.
1009 * as we don't support mark/space parity, we should clear the
1010 * mark/space parity bit in c_cflag, so the caller can tell we have
1011 * ignored the request */
1012 tty->termios->c_cflag &= ~CMSPAR;
1013
1014 if (tty->termios->c_cflag & CSTOPB)
1015 LCR_change_to |= QT2_SERIAL_TWO_STOPB;
1016 else
1017 LCR_change_to |= QT2_SERIAL_ONE_STOPB;
1018
1019 /* Thats the LCR stuff, next we need to work out the divisor as the
1020 * LCR and the divisor are set together */
1021 baud = tty_get_baud_rate(tty);
1022 if (!baud) {
1023 /* pick a default, any default... */
1024 baud = 9600;
1025 }
1026 dbg("%s(): got baud = %d", __func__, baud);
1027
1028 divisor = QT2_MAX_BAUD_RATE / baud;
1029 remainder = QT2_MAX_BAUD_RATE % baud;
1030 /* Round to nearest divisor */
1031 if (((remainder * 2) >= baud) && (baud != 110))
1032 divisor++;
1033 dbg("%s(): setting divisor = %d, QT2_MAX_BAUD_RATE = %d , LCR = %#.2x",
1034 __func__, divisor, QT2_MAX_BAUD_RATE, LCR_change_to);
1035
1036 status = qt2_boxsetuart(serial, UartNumber, (unsigned short) divisor,
1037 LCR_change_to);
1038 if (status < 0) {
1039 dbg("qt2_boxsetuart() failed");
1040 return;
1041 } else {
1042 /* now encode the baud rate we actually set, which may be
1043 * different to the request */
1044 baud = QT2_MAX_BAUD_RATE / divisor;
1045 tty_encode_baud_rate(tty, baud, baud);
1046 }
1047
1048 /* Now determine flow control */
1049 if (tty->termios->c_cflag & CRTSCTS) {
1050 dbg("%s(): Enabling HW flow control port %d", __func__,
1051 port->number);
1052 /* Enable RTS/CTS flow control */
1053 status = qt2_boxsethw_flowctl(serial, UartNumber, true);
1054 if (status < 0) {
1055 dbg("qt2_boxsethw_flowctl() failed");
1056 return;
1057 }
1058 } else {
1059 /* Disable RTS/CTS flow control */
1060 dbg("%s(): disabling HW flow control port %d", __func__,
1061 port->number);
1062 status = qt2_boxsethw_flowctl(serial, UartNumber, false);
1063 if (status < 0) {
1064 dbg("qt2_boxsethw_flowctl failed");
1065 return;
1066 }
1067 }
1068 /* if we are implementing XON/XOFF, set the start and stop character
1069 * in the device */
1070 if (I_IXOFF(tty) || I_IXON(tty)) {
1071 unsigned char stop_char = STOP_CHAR(tty);
1072 unsigned char start_char = START_CHAR(tty);
1073 status = qt2_boxsetsw_flowctl(serial, UartNumber, stop_char,
1074 start_char);
1075 if (status < 0)
1076 dbg("qt2_boxsetsw_flowctl (enabled) failed");
1077 } else {
1078 /* disable SW flow control */
1079 status = qt2_boxunsetsw_flowctl(serial, UartNumber);
1080 if (status < 0)
1081 dbg("qt2_boxunsetsw_flowctl (disabling) failed");
1082 }
1083}
1084
1085static int qt2_tiocmget(struct tty_struct *tty)
1086{
1087 struct usb_serial_port *port = tty->driver_data;
1088 struct usb_serial *serial = port->serial;
1089
1090 __u8 mcr_value; /* Modem Control Register value */
1091 __u8 msr_value; /* Modem Status Register value */
1092 unsigned int result = 0;
1093 int status;
1094 unsigned int UartNumber;
1095
1096 if (serial == NULL)
1097 return -ENODEV;
1098
1099 dbg("%s(): port %d, tty =0x%p", __func__, port->number, tty);
1100 UartNumber = tty->index - serial->minor;
1101 dbg("UartNumber is %d", UartNumber);
1102
1103 status = qt2_box_get_register(port->serial, UartNumber,
1104 QT2_MODEM_CONTROL_REGISTER, &mcr_value);
1105 if (status >= 0) {
1106 status = qt2_box_get_register(port->serial, UartNumber,
1107 QT2_MODEM_STATUS_REGISTER, &msr_value);
1108 }
1109 if (status >= 0) {
1110 result = ((mcr_value & QT2_SERIAL_MCR_DTR) ? TIOCM_DTR : 0)
1111 /*DTR set */
1112 | ((mcr_value & QT2_SERIAL_MCR_RTS) ? TIOCM_RTS : 0)
1113 /*RTS set */
1114 | ((msr_value & QT2_SERIAL_MSR_CTS) ? TIOCM_CTS : 0)
1115 /* CTS set */
1116 | ((msr_value & QT2_SERIAL_MSR_CD) ? TIOCM_CAR : 0)
1117 /*Carrier detect set */
1118 | ((msr_value & QT2_SERIAL_MSR_RI) ? TIOCM_RI : 0)
1119 /* Ring indicator set */
1120 | ((msr_value & QT2_SERIAL_MSR_DSR) ? TIOCM_DSR : 0);
1121 /* DSR set */
1122 return result;
1123 } else {
1124 return -ESPIPE;
1125 }
1126}
1127
1128static int qt2_tiocmset(struct tty_struct *tty,
1129 unsigned int set, unsigned int clear)
1130{
1131 struct usb_serial_port *port = tty->driver_data;
1132 struct usb_serial *serial = port->serial;
1133 __u8 mcr_value; /* Modem Control Register value */
1134 int status;
1135 unsigned int UartNumber;
1136
1137 if (serial == NULL)
1138 return -ENODEV;
1139
1140 UartNumber = tty->index - serial->minor;
1141 dbg("%s(): port %d, UartNumber %d", __func__, port->number, UartNumber);
1142
1143 status = qt2_box_get_register(port->serial, UartNumber,
1144 QT2_MODEM_CONTROL_REGISTER, &mcr_value);
1145 if (status < 0)
1146 return -ESPIPE;
1147
1148 /* Turn off RTS, DTR and loopback, then only turn on what was asked
1149 * for */
1150 mcr_value &= ~(QT2_SERIAL_MCR_RTS | QT2_SERIAL_MCR_DTR |
1151 QT2_SERIAL_MCR_LOOP);
1152 if (set & TIOCM_RTS)
1153 mcr_value |= QT2_SERIAL_MCR_RTS;
1154 if (set & TIOCM_DTR)
1155 mcr_value |= QT2_SERIAL_MCR_DTR;
1156 if (set & TIOCM_LOOP)
1157 mcr_value |= QT2_SERIAL_MCR_LOOP;
1158
1159 status = qt2_box_set_register(port->serial, UartNumber,
1160 QT2_MODEM_CONTROL_REGISTER, mcr_value);
1161 if (status < 0)
1162 return -ESPIPE;
1163 else
1164 return 0;
1165}
1166
1167/** qt2_break - Turn BREAK on and off on the UARTs
1168 */
1169static void qt2_break(struct tty_struct *tty, int break_state)
1170{
1171 struct usb_serial_port *port = tty->driver_data; /* parent port */
1172 struct usb_serial *serial = port->serial; /* parent device */
1173 struct quatech2_port *port_extra; /* extra data for this port */
1174 __u16 break_value;
1175 unsigned int result;
1176
1177 port_extra = qt2_get_port_private(port);
1178 if (!serial) {
1179 dbg("%s(): port %d: no serial object", __func__, port->number);
1180 return;
1181 }
1182
1183 if (break_state == -1)
1184 break_value = 1;
1185 else
1186 break_value = 0;
1187 dbg("%s(): port %d, break_value %d", __func__, port->number,
1188 break_value);
1189
1190 mutex_lock(&port_extra->modelock);
1191 if (!port_extra->open_count) {
1192 dbg("%s(): port not open", __func__);
1193 goto exit;
1194 }
1195
1196 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1197 QT2_BREAK_CONTROL, 0x40, break_value,
1198 port->number, NULL, 0, 300);
1199exit:
1200 mutex_unlock(&port_extra->modelock);
1201 dbg("%s(): exit port %d", __func__, port->number);
1202
1203}
1204/**
1205 * qt2_throttle: - stop reading new data from the port
1206 */
1207static void qt2_throttle(struct tty_struct *tty)
1208{
1209 struct usb_serial_port *port = tty->driver_data;
1210 struct usb_serial *serial = port->serial;
1211 struct quatech2_port *port_extra; /* extra data for this port */
1212 dbg("%s(): port %d", __func__, port->number);
1213
1214 port_extra = qt2_get_port_private(port);
1215 if (!serial) {
1216 dbg("%s(): enter port %d no serial object", __func__,
1217 port->number);
1218 return;
1219 }
1220
1221 mutex_lock(&port_extra->modelock); /* lock structure */
1222 if (!port_extra->open_count) {
1223 dbg("%s(): port not open", __func__);
1224 goto exit;
1225 }
1226 /* Send command to box to stop receiving stuff. This will stop this
1227 * particular UART from filling the endpoint - in the multiport case the
1228 * FPGA UART will handle any flow control implemented, but for the single
1229 * port it's handed differently and we just quit submitting urbs
1230 */
1231 if (serial->dev->descriptor.idProduct != QUATECH_SSU2_100)
1232 qt2_boxstoprx(serial, port->number, 1);
1233
1234 port->throttled = 1;
1235exit:
1236 mutex_unlock(&port_extra->modelock);
1237 dbg("%s(): port %d: setting port->throttled", __func__, port->number);
1238 return;
1239}
1240
1241/**
1242 * qt2_unthrottle: - start receiving data through the port again after being
1243 * throttled
1244 */
1245static void qt2_unthrottle(struct tty_struct *tty)
1246{
1247 struct usb_serial_port *port = tty->driver_data;
1248 struct usb_serial *serial = port->serial;
1249 struct quatech2_port *port_extra; /* extra data for this port */
1250 struct usb_serial_port *port0; /* first port structure on device */
1251 struct quatech2_dev *dev_extra; /* extra data for the device */
1252
1253 if (!serial) {
1254 dbg("%s() enter port %d no serial object!", __func__,
1255 port->number);
1256 return;
1257 }
1258 dbg("%s(): enter port %d", __func__, port->number);
1259 dev_extra = qt2_get_dev_private(serial);
1260 port_extra = qt2_get_port_private(port);
1261 port0 = serial->port[0]; /* get the first port's device structure */
1262
1263 mutex_lock(&port_extra->modelock);
1264 if (!port_extra->open_count) {
1265 dbg("%s(): port %d not open", __func__, port->number);
1266 goto exit;
1267 }
1268
1269 if (port->throttled != 0) {
1270 dbg("%s(): port %d: unsetting port->throttled", __func__,
1271 port->number);
1272 port->throttled = 0;
1273 /* Send command to box to start receiving stuff */
1274 if (serial->dev->descriptor.idProduct != QUATECH_SSU2_100) {
1275 qt2_boxstoprx(serial, port->number, 0);
1276 } else if (dev_extra->ReadBulkStopped == true) {
1277 usb_fill_bulk_urb(port0->read_urb, serial->dev,
1278 usb_rcvbulkpipe(serial->dev,
1279 port0->bulk_in_endpointAddress),
1280 port0->bulk_in_buffer,
1281 port0->bulk_in_size,
1282 qt2_read_bulk_callback,
1283 serial);
1284 }
1285 }
1286exit:
1287 mutex_unlock(&port_extra->modelock);
1288 dbg("%s(): exit port %d", __func__, port->number);
1289 return;
1290}
1291
1292/* internal, private helper functions for the driver */
1293
1294/* Power up the FPGA in the box to get it working */
1295static int qt2_boxpoweron(struct usb_serial *serial)
1296{
1297 int result;
1298 __u8 Direcion;
1299 unsigned int pipe;
1300 Direcion = USBD_TRANSFER_DIRECTION_OUT;
1301 pipe = usb_rcvctrlpipe(serial->dev, 0);
1302 result = usb_control_msg(serial->dev, pipe, QT_SET_GET_DEVICE,
1303 Direcion, QU2BOXPWRON, 0x00, NULL, 0x00,
1304 5000);
1305 return result;
1306}
1307
1308/*
1309 * qt2_boxsetQMCR Issue a QT2_GET_SET_QMCR vendor-spcific request on the
1310 * default control pipe. If successful return the number of bytes written,
1311 * otherwise return a negative error number of the problem.
1312 */
1313static int qt2_boxsetQMCR(struct usb_serial *serial, __u16 Uart_Number,
1314 __u8 QMCR_Value)
1315{
1316 int result;
1317 __u16 PortSettings;
1318
1319 PortSettings = (__u16)(QMCR_Value);
1320
1321 dbg("%s(): Port = %d, PortSettings = 0x%x", __func__,
1322 Uart_Number, PortSettings);
1323
1324 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1325 QT2_GET_SET_QMCR, 0x40, PortSettings,
1326 (__u16)Uart_Number, NULL, 0, 5000);
1327 return result;
1328}
1329
1330static int port_paranoia_check(struct usb_serial_port *port,
1331 const char *function)
1332{
1333 if (!port) {
1334 dbg("%s - port == NULL", function);
1335 return -1;
1336 }
1337 if (!port->serial) {
1338 dbg("%s - port->serial == NULL\n", function);
1339 return -1;
1340 }
1341 return 0;
1342}
1343
1344static int serial_paranoia_check(struct usb_serial *serial,
1345 const char *function)
1346{
1347 if (!serial) {
1348 dbg("%s - serial == NULL\n", function);
1349 return -1;
1350 }
1351
1352 if (!serial->type) {
1353 dbg("%s - serial->type == NULL!", function);
1354 return -1;
1355 }
1356
1357 return 0;
1358}
1359
1360static inline struct quatech2_port *qt2_get_port_private(struct usb_serial_port
1361 *port)
1362{
1363 return (struct quatech2_port *)usb_get_serial_port_data(port);
1364}
1365
1366static inline void qt2_set_port_private(struct usb_serial_port *port,
1367 struct quatech2_port *data)
1368{
1369 usb_set_serial_port_data(port, (void *)data);
1370}
1371
1372static inline struct quatech2_dev *qt2_get_dev_private(struct usb_serial
1373 *serial)
1374{
1375 return (struct quatech2_dev *)usb_get_serial_data(serial);
1376}
1377static inline void qt2_set_dev_private(struct usb_serial *serial,
1378 struct quatech2_dev *data)
1379{
1380 usb_set_serial_data(serial, (void *)data);
1381}
1382
1383static int qt2_openboxchannel(struct usb_serial *serial, __u16
1384 Uart_Number, struct qt2_status_data *status)
1385{
1386 int result;
1387 __u16 length;
1388 __u8 Direcion;
1389 unsigned int pipe;
1390 length = sizeof(struct qt2_status_data);
1391 Direcion = USBD_TRANSFER_DIRECTION_IN;
1392 pipe = usb_rcvctrlpipe(serial->dev, 0);
1393 result = usb_control_msg(serial->dev, pipe, QT_OPEN_CLOSE_CHANNEL,
1394 Direcion, 0x00, Uart_Number, status, length, 5000);
1395 return result;
1396}
1397static int qt2_closeboxchannel(struct usb_serial *serial, __u16 Uart_Number)
1398{
1399 int result;
1400 __u8 direcion;
1401 unsigned int pipe;
1402 direcion = USBD_TRANSFER_DIRECTION_OUT;
1403 pipe = usb_sndctrlpipe(serial->dev, 0);
1404 result = usb_control_msg(serial->dev, pipe, QT_OPEN_CLOSE_CHANNEL,
1405 direcion, 0, Uart_Number, NULL, 0, 5000);
1406 return result;
1407}
1408
1409/* qt2_conf_uart Issue a SET_UART vendor-spcific request on the default
1410 * control pipe. If successful sets baud rate divisor and LCR value
1411 */
1412static int qt2_conf_uart(struct usb_serial *serial, unsigned short Uart_Number,
1413 unsigned short divisor, unsigned char LCR)
1414{
1415 int result;
1416 unsigned short UartNumandLCR;
1417
1418 UartNumandLCR = (LCR << 8) + Uart_Number;
1419
1420 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1421 QT2_GET_SET_UART, 0x40, divisor, UartNumandLCR,
1422 NULL, 0, 300);
1423 return result;
1424}
1425
1426/** @brief Callback for asynchronous submission of read URBs on bulk in
1427 * endpoints
1428 *
1429 * Registered in qt2_open_port(), used to deal with incomming data
1430 * from the box.
1431 */
1432static void qt2_read_bulk_callback(struct urb *urb)
1433{
1434 /* Get the device pointer (struct usb_serial) back out of the URB */
1435 struct usb_serial *serial = urb->context;
1436 /* get the extra struct for the device */
1437 struct quatech2_dev *dev_extra = qt2_get_dev_private(serial);
1438 /* Get first port structure from the device */
1439 struct usb_serial_port *port0 = serial->port[0];
1440 /* Get the currently active port structure from serial struct */
1441 struct usb_serial_port *active = dev_extra->current_port;
1442 /* get the extra struct for port 0 */
1443 struct quatech2_port *port0_extra = qt2_get_port_private(port0);
1444 /* and for the currently active port */
1445 struct quatech2_port *active_extra = qt2_get_port_private(active);
1446 /* When we finally get to doing some tty stuff, we will need this */
1447 struct tty_struct *tty_st;
1448 unsigned int RxCount; /* the length of the data to process */
1449 unsigned int i; /* loop counter over the data to process */
1450 int result; /* return value cache variable */
1451 bool escapeflag; /* flag set to true if this loop iteration is
1452 * parsing an escape sequence, rather than
1453 * ordinary data */
1454 dbg("%s(): callback running, active port is %d", __func__,
1455 active->number);
1456
1457 if (urb->status) {
1458 /* read didn't go well */
1459 dev_extra->ReadBulkStopped = true;
1460 dbg("%s(): nonzero bulk read status received: %d",
1461 __func__, urb->status);
1462 return;
1463 }
1464
1465 /* inline port_sofrint() here */
1466 if (port_paranoia_check(port0, __func__) != 0) {
1467 dbg("%s - port_paranoia_check on port0 failed, exiting\n",
1468__func__);
1469 return;
1470 }
1471 if (port_paranoia_check(active, __func__) != 0) {
1472 dbg("%s - port_paranoia_check on current_port "
1473 "failed, exiting", __func__);
1474 return;
1475 }
1476
1477/* This single callback function has to do for all the ports on
1478 * the device. Data being read up the USB can contain certain
1479 * escape sequences which are used to communicate out-of-band
1480 * information from the serial port in-band over the USB.
1481 * These escapes include sending modem and flow control line
1482 * status, and switching the port. The concept of a "Current Port"
1483 * is used, which is where data is going until a port change
1484 * escape seqence is received. This Current Port is kept between
1485 * callbacks so that when this function enters we know which the
1486 * currently active port is and can get to work right away without
1487 * the box having to send repeat escape sequences (anyway, how
1488 * would it know to do so?).
1489 */
1490
1491 if (active_extra->close_pending == true) {
1492 /* We are closing , stop reading */
1493 dbg("%s - (active->close_pending == true", __func__);
1494 if (dev_extra->open_ports <= 0) {
1495 /* If this is the only port left open - stop the
1496 * bulk read */
1497 dev_extra->ReadBulkStopped = true;
1498 dbg("%s - (ReadBulkStopped == true;", __func__);
1499 return;
1500 }
1501 }
1502
1503 /*
1504 * RxHolding is asserted by throttle, if we assert it, we're not
1505 * receiving any more characters and let the box handle the flow
1506 * control
1507 */
1508 if ((port0_extra->RxHolding == true) &&
1509 (serial->dev->descriptor.idProduct == QUATECH_SSU2_100)) {
1510 /* single port device, input is already stopped, so we don't
1511 * need any more input data */
1512 dev_extra->ReadBulkStopped = true;
1513 return;
1514 }
1515 /* finally, we are in a situation where we might consider the data
1516 * that is contained within the URB, and what to do about it.
1517 * This is likely to involved communicating up to the TTY layer, so
1518 * we will need to get hold of the tty for the port we are currently
1519 * dealing with */
1520
1521 /* active is a usb_serial_port. It has a member port which is a
1522 * tty_port. From this we get a tty_struct pointer which is what we
1523 * actually wanted, and keep it on tty_st */
1524 tty_st = tty_port_tty_get(&active->port);
1525 if (!tty_st) {
1526 dbg("%s - bad tty pointer - exiting", __func__);
1527 return;
1528 }
1529 RxCount = urb->actual_length; /* grab length of data handy */
1530
1531 if (RxCount) {
1532 /* skip all this if no data to process */
1533 for (i = 0; i < RxCount ; ++i) {
1534 /* Look ahead code here -works on several bytes at onc*/
1535 if ((i <= (RxCount - 3)) && (THISCHAR == 0x1b)
1536 && (NEXTCHAR == 0x1b)) {
1537 /* we are in an escape sequence, type
1538 * determined by the 3rd char */
1539 escapeflag = false;
1540 switch (THIRDCHAR) {
1541 case 0x00:
1542 /* Line status change 4th byte must
1543 * follow */
1544 if (i > (RxCount - 4)) {
1545 dbg("Illegal escape sequences "
1546 "in received data");
1547 break;
1548 }
1549 qt2_process_line_status(active,
1550 FOURTHCHAR);
1551 i += 3;
1552 escapeflag = true;
1553 break;
1554 case 0x01:
1555 /* Modem status status change 4th byte
1556 * must follow */
1557 if (i > (RxCount - 4)) {
1558 dbg("Illegal escape sequences "
1559 "in received data");
1560 break;
1561 }
1562 qt2_process_modem_status(active,
1563 FOURTHCHAR);
1564 i += 3;
1565 escapeflag = true;
1566 break;
1567 case 0x02:
1568 /* xmit hold empty 4th byte
1569 * must follow */
1570 if (i > (RxCount - 4)) {
1571 dbg("Illegal escape sequences "
1572 "in received data");
1573 break;
1574 }
1575 qt2_process_xmit_empty(active,
1576 FOURTHCHAR, FIFTHCHAR);
1577 i += 4;
1578 escapeflag = true;
1579 break;
1580 case 0x03:
1581 /* Port number change 4th byte
1582 * must follow */
1583 if (i > (RxCount - 4)) {
1584 dbg("Illegal escape sequences "
1585 "in received data");
1586 break;
1587 }
1588 /* Port change. If port open push
1589 * current data up to tty layer */
1590 if (active_extra->open_count > 0)
1591 tty_flip_buffer_push(tty_st);
1592
1593 dbg("Port Change: new port = %d",
1594 FOURTHCHAR);
1595 qt2_process_port_change(active,
1596 FOURTHCHAR);
1597 i += 3;
1598 escapeflag = true;
1599 /* having changed port, the pointers for
1600 * the currently active port are all out
1601 * of date and need updating */
1602 active = dev_extra->current_port;
1603 active_extra =
1604 qt2_get_port_private(active);
1605 tty_st = tty_port_tty_get(
1606 &active->port);
1607 break;
1608 case 0x04:
1609 /* Recv flush 3rd byte must
1610 * follow */
1611 if (i > (RxCount - 3)) {
1612 dbg("Illegal escape sequences "
1613 "in received data");
1614 break;
1615 }
1616 qt2_process_rcv_flush(active);
1617 i += 2;
1618 escapeflag = true;
1619 break;
1620 case 0x05:
1621 /* xmit flush 3rd byte must follow */
1622 if (i > (RxCount - 3)) {
1623 dbg("Illegal escape sequences "
1624 "in received data");
1625 break;
1626 }
1627 qt2_process_xmit_flush(active);
1628 i += 2;
1629 escapeflag = true;
1630 break;
1631 case 0xff:
1632 dbg("No status sequence");
1633 qt2_process_rx_char(active, THISCHAR);
1634 qt2_process_rx_char(active, NEXTCHAR);
1635 i += 2;
1636 break;
1637 default:
1638 qt2_process_rx_char(active, THISCHAR);
1639 i += 1;
1640 break;
1641 } /*end switch*/
1642 if (escapeflag == true)
1643 continue;
1644 /* if we did an escape char, we don't need
1645 * to mess around pushing data through the
1646 * tty layer, and can go round again */
1647 } /*endif*/
1648 if (tty_st && urb->actual_length) {
1649 tty_buffer_request_room(tty_st, 1);
1650 tty_insert_flip_string(tty_st, &(
1651 (unsigned char *)
1652 (urb->transfer_buffer)
1653 )[i], 1);
1654 }
1655 } /*endfor*/
1656 tty_flip_buffer_push(tty_st);
1657 } /*endif*/
1658
1659 /* at this point we have complete dealing with the data for this
1660 * callback. All we have to do now is to start the async read process
1661 * back off again. */
1662
1663 usb_fill_bulk_urb(port0->read_urb, serial->dev,
1664 usb_rcvbulkpipe(serial->dev, port0->bulk_in_endpointAddress),
1665 port0->bulk_in_buffer, port0->bulk_in_size,
1666 qt2_read_bulk_callback, serial);
1667 result = usb_submit_urb(port0->read_urb, GFP_ATOMIC);
1668 if (result) {
1669 dbg("%s(): failed resubmitting read urb, error %d",
1670 __func__, result);
1671 } else {
1672 dbg("%s() successfully resubmitted read urb", __func__);
1673 if (tty_st && RxCount) {
1674 /* if some inbound data was processed, then
1675 * we need to push that through the tty layer
1676 */
1677 tty_flip_buffer_push(tty_st);
1678 tty_schedule_flip(tty_st);
1679 }
1680 }
1681
1682 /* cribbed from serqt_usb2 driver, but not sure which work needs
1683 * scheduling - port0 or currently active port? */
1684 /* schedule_work(&port->work); */
1685 dbg("%s() completed", __func__);
1686 return;
1687}
1688
1689/** @brief Callback for asynchronous submission of write URBs on bulk in
1690 * endpoints
1691 *
1692 * Registered in qt2_write(), used to deal with outgoing data
1693 * to the box.
1694 */
1695static void qt2_write_bulk_callback(struct urb *urb)
1696{
1697 struct usb_serial_port *port = (struct usb_serial_port *)urb->context;
1698 struct usb_serial *serial = port->serial;
1699 dbg("%s(): port %d", __func__, port->number);
1700 if (!serial) {
1701 dbg("%s(): bad serial pointer, exiting", __func__);
1702 return;
1703 }
1704 if (urb->status) {
1705 dbg("%s(): nonzero write bulk status received: %d",
1706 __func__, urb->status);
1707 return;
1708 }
1709 /* FIXME What is supposed to be going on here?
1710 * does this actually do anything useful, and should it?
1711 */
1712 /*port_softint((void *) serial); commented in vendor driver */
1713 schedule_work(&port->work);
1714 dbg("%s(): port %d exit", __func__, port->number);
1715 return;
1716}
1717
1718static void qt2_process_line_status(struct usb_serial_port *port,
1719 unsigned char LineStatus)
1720{
1721 /* obtain the private structure for the port */
1722 struct quatech2_port *port_extra = qt2_get_port_private(port);
1723 port_extra->shadowLSR = LineStatus & (QT2_SERIAL_LSR_OE |
1724 QT2_SERIAL_LSR_PE | QT2_SERIAL_LSR_FE | QT2_SERIAL_LSR_BI);
1725}
1726static void qt2_process_modem_status(struct usb_serial_port *port,
1727 unsigned char ModemStatus)
1728{
1729 /* obtain the private structure for the port */
1730 struct quatech2_port *port_extra = qt2_get_port_private(port);
1731 port_extra->shadowMSR = ModemStatus;
1732 wake_up_interruptible(&port_extra->wait);
1733 /* this wakes up the otherwise indefinitely waiting code for
1734 * the TIOCMIWAIT ioctl, so that it can notice that
1735 * port_extra->shadowMSR has changed and the ioctl needs to return.
1736 */
1737}
1738
1739static void qt2_process_xmit_empty(struct usb_serial_port *port,
1740 unsigned char fourth_char, unsigned char fifth_char)
1741{
1742 int byte_count;
1743 /* obtain the private structure for the port */
1744 struct quatech2_port *port_extra = qt2_get_port_private(port);
1745
1746 byte_count = (int)(fifth_char * 16);
1747 byte_count += (int)fourth_char;
1748 /* byte_count indicates how many bytes the device has written out. This
1749 * message appears to occur regularly, and is used in the vendor driver
1750 * to keep track of the fill state of the port transmit buffer */
1751 port_extra->tx_pending_bytes -= byte_count;
1752 /* reduce the stored data queue length by the known number of bytes
1753 * sent */
1754 dbg("port %d: %d bytes reported sent, %d still pending", port->number,
1755 byte_count, port_extra->tx_pending_bytes);
1756
1757 /*port_extra->xmit_fifo_room_bytes = FIFO_DEPTH; ???*/
1758}
1759
1760static void qt2_process_port_change(struct usb_serial_port *port,
1761 unsigned char New_Current_Port)
1762{
1763 /* obtain the parent usb serial device structure */
1764 struct usb_serial *serial = port->serial;
1765 /* obtain the private structure for the device */
1766 struct quatech2_dev *dev_extra = qt2_get_dev_private(serial);
1767 dev_extra->current_port = serial->port[New_Current_Port];
1768 /* what should I do with this? commented out in upstream
1769 * driver */
1770 /*schedule_work(&port->work);*/
1771}
1772
1773static void qt2_process_rcv_flush(struct usb_serial_port *port)
1774{
1775 /* obtain the private structure for the port */
1776 struct quatech2_port *port_extra = qt2_get_port_private(port);
1777 port_extra->rcv_flush = true;
1778}
1779static void qt2_process_xmit_flush(struct usb_serial_port *port)
1780{
1781 /* obtain the private structure for the port */
1782 struct quatech2_port *port_extra = qt2_get_port_private(port);
1783 port_extra->xmit_flush = true;
1784}
1785
1786static void qt2_process_rx_char(struct usb_serial_port *port,
1787 unsigned char data)
1788{
1789 /* get the tty_struct for this port */
1790 struct tty_struct *tty = tty_port_tty_get(&(port->port));
1791 /* get the URB with the data in to push */
1792 struct urb *urb = port->serial->port[0]->read_urb;
1793
1794 if (tty && urb->actual_length) {
1795 tty_buffer_request_room(tty, 1);
1796 tty_insert_flip_string(tty, &data, 1);
1797 /* should this be commented out here? */
1798 /*tty_flip_buffer_push(tty);*/
1799 }
1800}
1801
1802/** @brief Retrieve the value of a register from the device
1803 *
1804 * Issues a GET_REGISTER vendor-spcific request over the USB control
1805 * pipe to obtain a value back from a specific register on a specific
1806 * UART
1807 * @param serial Serial device handle to access the device through
1808 * @param uart_number Which UART the value is wanted from
1809 * @param register_num Which register to read the value from
1810 * @param pValue Pointer to somewhere to put the retrieved value
1811 */
1812static int qt2_box_get_register(struct usb_serial *serial,
1813 unsigned char uart_number, unsigned short register_num,
1814 __u8 *pValue)
1815{
1816 int result;
1817 result = usb_control_msg(serial->dev, usb_rcvctrlpipe(serial->dev, 0),
1818 QT2_GET_SET_REGISTER, 0xC0, register_num,
1819 uart_number, (void *)pValue, sizeof(*pValue), 300);
1820 return result;
1821}
1822
1823/** qt2_box_set_register
1824 * Issue a SET_REGISTER vendor-specific request on the default control pipe
1825 */
1826static int qt2_box_set_register(struct usb_serial *serial,
1827 unsigned short Uart_Number, unsigned short Register_Num,
1828 unsigned short Value)
1829{
1830 int result;
1831 unsigned short reg_and_byte;
1832
1833 reg_and_byte = Value;
1834 reg_and_byte = reg_and_byte << 8;
1835 reg_and_byte = reg_and_byte + Register_Num;
1836
1837 result = usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1838 QT2_GET_SET_REGISTER, 0x40, reg_and_byte,
1839 Uart_Number, NULL, 0, 300);
1840 return result;
1841}
1842
1843/** qt2_boxsetuart - Issue a SET_UART vendor-spcific request on the default
1844 * control pipe. If successful sets baud rate divisor and LCR value.
1845 */
1846static int qt2_boxsetuart(struct usb_serial *serial, unsigned short Uart_Number,
1847 unsigned short default_divisor, unsigned char default_LCR)
1848{
1849 unsigned short UartNumandLCR;
1850
1851 UartNumandLCR = (default_LCR << 8) + Uart_Number;
1852
1853 return usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1854 QT2_GET_SET_UART, 0x40, default_divisor, UartNumandLCR,
1855 NULL, 0, 300);
1856}
1857
1858/** qt2_boxsethw_flowctl - Turn hardware (RTS/CTS) flow control on and off for
1859 * a hardware UART.
1860 */
1861static int qt2_boxsethw_flowctl(struct usb_serial *serial,
1862 unsigned int UartNumber, bool bSet)
1863{
1864 __u8 MCR_Value = 0;
1865 __u8 MSR_Value = 0;
1866 __u16 MOUT_Value = 0;
1867
1868 if (bSet == true) {
1869 MCR_Value = QT2_SERIAL_MCR_RTS;
1870 /* flow control, box will clear RTS line to prevent remote
1871 * device from transmitting more chars */
1872 } else {
1873 /* no flow control to remote device */
1874 MCR_Value = 0;
1875 }
1876 MOUT_Value = MCR_Value << 8;
1877
1878 if (bSet == true) {
1879 MSR_Value = QT2_SERIAL_MSR_CTS;
1880 /* flow control on, box will inhibit tx data if CTS line is
1881 * asserted */
1882 } else {
1883 /* Box will not inhibit tx data due to CTS line */
1884 MSR_Value = 0;
1885 }
1886 MOUT_Value |= MSR_Value;
1887 return usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1888 QT2_HW_FLOW_CONTROL_MASK, 0x40, MOUT_Value, UartNumber,
1889 NULL, 0, 300);
1890}
1891
1892/** qt2_boxsetsw_flowctl - Turn software (XON/XOFF) flow control on for
1893 * a hardware UART, and set the XON and XOFF characters.
1894 */
1895static int qt2_boxsetsw_flowctl(struct usb_serial *serial, __u16 UartNumber,
1896 unsigned char stop_char, unsigned char start_char)
1897{
1898 __u16 nSWflowout;
1899
1900 nSWflowout = start_char << 8;
1901 nSWflowout = (unsigned short)stop_char;
1902 return usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1903 QT2_SW_FLOW_CONTROL_MASK, 0x40, nSWflowout, UartNumber,
1904 NULL, 0, 300);
1905}
1906
1907/** qt2_boxunsetsw_flowctl - Turn software (XON/XOFF) flow control off for
1908 * a hardware UART.
1909 */
1910static int qt2_boxunsetsw_flowctl(struct usb_serial *serial, __u16 UartNumber)
1911{
1912 return usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1913 QT2_SW_FLOW_CONTROL_DISABLE, 0x40, 0, UartNumber, NULL,
1914 0, 300);
1915}
1916
1917/**
1918 * qt2_boxstoprx - Start and stop reception of data by the FPGA UART in
1919 * response to requests from the tty layer
1920 * @serial: pointer to the usb_serial structure for the parent device
1921 * @uart_number: which UART on the device we are addressing
1922 * @stop: Whether to start or stop data reception. Set to 1 to stop data being
1923 * received, and to 0 to start it being received.
1924 */
1925static int qt2_boxstoprx(struct usb_serial *serial, unsigned short uart_number,
1926 unsigned short stop)
1927{
1928 return usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1929 QT2_STOP_RECEIVE, 0x40, stop, uart_number, NULL, 0, 300);
1930}
1931
1932
1933/*
1934 * last things in file: stuff to register this driver into the generic
1935 * USB serial framework.
1936 */
1937
1938static struct usb_serial_driver quatech2_device = {
1939 .driver = {
1940 .owner = THIS_MODULE,
1941 .name = "quatech_usb2",
1942 },
1943 .description = DRIVER_DESC,
1944 .id_table = quausb2_id_table,
1945 .num_ports = 8,
1946 .open = qt2_open,
1947 .close = qt2_close,
1948 .write = qt2_write,
1949 .write_room = qt2_write_room,
1950 .chars_in_buffer = qt2_chars_in_buffer,
1951 .throttle = qt2_throttle,
1952 .unthrottle = qt2_unthrottle,
1953 .calc_num_ports = qt2_calc_num_ports,
1954 .ioctl = qt2_ioctl,
1955 .set_termios = qt2_set_termios,
1956 .break_ctl = qt2_break,
1957 .tiocmget = qt2_tiocmget,
1958 .tiocmset = qt2_tiocmset,
1959 .attach = qt2_attach,
1960 .release = qt2_release,
1961 .read_bulk_callback = qt2_read_bulk_callback,
1962 .write_bulk_callback = qt2_write_bulk_callback,
1963};
1964
1965static struct usb_serial_driver * const serial_drivers[] = {
1966 &quatech2_device, NULL
1967};
1968
1969module_usb_serial_driver(quausb2_usb_driver, serial_drivers);
1970
1971MODULE_AUTHOR(DRIVER_AUTHOR);
1972MODULE_DESCRIPTION(DRIVER_DESC);
1973MODULE_LICENSE("GPL");
1974
1975module_param(debug, bool, S_IRUGO | S_IWUSR);
1976MODULE_PARM_DESC(debug, "Debug enabled or not");
diff --git a/drivers/staging/ramster/cluster/tcp.c b/drivers/staging/ramster/cluster/tcp.c
index 3490192f8ca..d0a07d722b6 100644
--- a/drivers/staging/ramster/cluster/tcp.c
+++ b/drivers/staging/ramster/cluster/tcp.c
@@ -2106,7 +2106,7 @@ static int r2net_open_listening_sock(__be32 addr, __be16 port)
2106 r2net_listen_sock = sock; 2106 r2net_listen_sock = sock;
2107 INIT_WORK(&r2net_listen_work, r2net_accept_many); 2107 INIT_WORK(&r2net_listen_work, r2net_accept_many);
2108 2108
2109 sock->sk->sk_reuse = 1; 2109 sock->sk->sk_reuse = SK_CAN_REUSE;
2110 ret = sock->ops->bind(sock, (struct sockaddr *)&sin, sizeof(sin)); 2110 ret = sock->ops->bind(sock, (struct sockaddr *)&sin, sizeof(sin));
2111 if (ret < 0) { 2111 if (ret < 0) {
2112 printk(KERN_ERR "ramster: Error %d while binding socket at " 2112 printk(KERN_ERR "ramster: Error %d while binding socket at "
diff --git a/drivers/staging/serqt_usb2/serqt_usb2.c b/drivers/staging/serqt_usb2/serqt_usb2.c
index 0ec83aacee7..43045db982d 100644
--- a/drivers/staging/serqt_usb2/serqt_usb2.c
+++ b/drivers/staging/serqt_usb2/serqt_usb2.c
@@ -41,13 +41,6 @@ static bool debug;
41#define QUATECH_HSU200B 0xC0B1 /* HSU200B */ 41#define QUATECH_HSU200B 0xC0B1 /* HSU200B */
42#define QUATECH_HSU200C 0xC0B2 /* HSU200C */ 42#define QUATECH_HSU200C 0xC0B2 /* HSU200C */
43#define QUATECH_HSU200D 0xC0B3 /* HSU200D */ 43#define QUATECH_HSU200D 0xC0B3 /* HSU200D */
44#define QUATECH_SSU100_2 0xC120 /* SSU100_2 */
45#define QUATECH_DSU100_2 0xC140 /* DSU100_2 */
46#define QUATECH_DSU400_2 0xC150 /* DSU400_2 */
47#define QUATECH_QSU100_2 0xC160 /* QSU100_2 */
48#define QUATECH_QSU400_2 0xC170 /* QSU400_2 */
49#define QUATECH_ESU400_2 0xC180 /* ESU400_2 */
50#define QUATECH_ESU100_2 0xC1A0 /* ESU100_2 */
51 44
52#define QT_SET_GET_DEVICE 0xc2 45#define QT_SET_GET_DEVICE 0xc2
53#define QT_OPEN_CLOSE_CHANNEL 0xca 46#define QT_OPEN_CLOSE_CHANNEL 0xca
@@ -125,7 +118,7 @@ static bool debug;
125#define MODEM_CTRL 0x40 118#define MODEM_CTRL 0x40
126#define RS232_MODE 0x00 119#define RS232_MODE 0x00
127 120
128static const struct usb_device_id serqt_id_table[] = { 121static const struct usb_device_id id_table[] = {
129 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_SSU200)}, 122 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_SSU200)},
130 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_DSU100)}, 123 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_DSU100)},
131 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_DSU200)}, 124 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_DSU200)},
@@ -143,17 +136,9 @@ static const struct usb_device_id serqt_id_table[] = {
143 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU200B)}, 136 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU200B)},
144 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU200C)}, 137 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU200C)},
145 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU200D)}, 138 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_HSU200D)},
146 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_SSU100_2)},
147 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_DSU100_2)},
148 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_DSU400_2)},
149 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_QSU100_2)},
150 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_QSU400_2)},
151 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_ESU400_2)},
152 {USB_DEVICE(USB_VENDOR_ID_QUATECH, QUATECH_ESU100_2)},
153 {} /* Terminating entry */ 139 {} /* Terminating entry */
154}; 140};
155 141MODULE_DEVICE_TABLE(usb, id_table);
156MODULE_DEVICE_TABLE(usb, serqt_id_table);
157 142
158struct qt_get_device_data { 143struct qt_get_device_data {
159 __u8 porta; 144 __u8 porta;
@@ -195,13 +180,6 @@ struct quatech_port {
195 char closePending; 180 char closePending;
196}; 181};
197 182
198static struct usb_driver serqt_usb_driver = {
199 .name = "quatech-usb-serial",
200 .probe = usb_serial_probe,
201 .disconnect = usb_serial_disconnect,
202 .id_table = serqt_id_table,
203};
204
205static int port_paranoia_check(struct usb_serial_port *port, 183static int port_paranoia_check(struct usb_serial_port *port,
206 const char *function) 184 const char *function)
207{ 185{
@@ -304,8 +282,6 @@ static void qt_write_bulk_callback(struct urb *urb)
304 282
305 quatech_port = urb->context; 283 quatech_port = urb->context;
306 284
307 dbg("%s - port %d\n", __func__, quatech_port->port_num);
308
309 tty = tty_port_tty_get(&quatech_port->port->port); 285 tty = tty_port_tty_get(&quatech_port->port->port);
310 286
311 if (tty) 287 if (tty)
@@ -351,7 +327,6 @@ static void qt_read_bulk_callback(struct urb *urb)
351 /* index = MINOR(port->tty->device) - serial->minor; */ 327 /* index = MINOR(port->tty->device) - serial->minor; */
352 index = tty->index - serial->minor; 328 index = tty->index - serial->minor;
353 329
354 dbg("%s - port %d\n", __func__, port->number);
355 dbg("%s - port->RxHolding = %d\n", __func__, qt_port->RxHolding); 330 dbg("%s - port->RxHolding = %d\n", __func__, qt_port->RxHolding);
356 331
357 if (port_paranoia_check(port, __func__) != 0) { 332 if (port_paranoia_check(port, __func__) != 0) {
@@ -726,8 +701,6 @@ static int qt_startup(struct usb_serial *serial)
726 int i; 701 int i;
727 int status; 702 int status;
728 703
729 dbg("enterting %s", __func__);
730
731 /* Now setup per port private data */ 704 /* Now setup per port private data */
732 for (i = 0; i < serial->num_ports; i++) { 705 for (i = 0; i < serial->num_ports; i++) {
733 port = serial->port[i]; 706 port = serial->port[i];
@@ -855,8 +828,6 @@ static void qt_release(struct usb_serial *serial)
855 struct quatech_port *qt_port; 828 struct quatech_port *qt_port;
856 int i; 829 int i;
857 830
858 dbg("enterting %s", __func__);
859
860 for (i = 0; i < serial->num_ports; i++) { 831 for (i = 0; i < serial->num_ports; i++) {
861 port = serial->port[i]; 832 port = serial->port[i];
862 if (!port) 833 if (!port)
@@ -882,8 +853,6 @@ static int qt_open(struct tty_struct *tty,
882 if (port_paranoia_check(port, __func__)) 853 if (port_paranoia_check(port, __func__))
883 return -ENODEV; 854 return -ENODEV;
884 855
885 dbg("%s - port %d\n", __func__, port->number);
886
887 serial = port->serial; 856 serial = port->serial;
888 857
889 if (serial_paranoia_check(serial, __func__)) 858 if (serial_paranoia_check(serial, __func__))
@@ -1006,8 +975,6 @@ static int qt_chars_in_buffer(struct tty_struct *tty)
1006 975
1007 serial = get_usb_serial(port, __func__); 976 serial = get_usb_serial(port, __func__);
1008 977
1009 dbg("%s - port %d\n", __func__, port->number);
1010
1011 if (serial->num_bulk_out) { 978 if (serial->num_bulk_out) {
1012 if (port->write_urb->status == -EINPROGRESS) 979 if (port->write_urb->status == -EINPROGRESS)
1013 chars = port->write_urb->transfer_buffer_length; 980 chars = port->write_urb->transfer_buffer_length;
@@ -1054,8 +1021,6 @@ static void qt_close(struct usb_serial_port *port)
1054 unsigned int index; 1021 unsigned int index;
1055 status = 0; 1022 status = 0;
1056 1023
1057 dbg("%s - port %d\n", __func__, port->number);
1058
1059 tty = tty_port_tty_get(&port->port); 1024 tty = tty_port_tty_get(&port->port);
1060 index = tty->index - serial->minor; 1025 index = tty->index - serial->minor;
1061 1026
@@ -1109,8 +1074,6 @@ static int qt_write(struct tty_struct *tty, struct usb_serial_port *port,
1109 if (serial == NULL) 1074 if (serial == NULL)
1110 return -ENODEV; 1075 return -ENODEV;
1111 1076
1112 dbg("%s - port %d\n", __func__, port->number);
1113
1114 if (count == 0) { 1077 if (count == 0) {
1115 dbg("%s - write request of 0 bytes\n", __func__); 1078 dbg("%s - write request of 0 bytes\n", __func__);
1116 return 0; 1079 return 0;
@@ -1173,8 +1136,6 @@ static int qt_write_room(struct tty_struct *tty)
1173 1136
1174 mutex_lock(&qt_port->lock); 1137 mutex_lock(&qt_port->lock);
1175 1138
1176 dbg("%s - port %d\n", __func__, port->number);
1177
1178 if (serial->num_bulk_out) { 1139 if (serial->num_bulk_out) {
1179 if (port->write_urb->status != -EINPROGRESS) 1140 if (port->write_urb->status != -EINPROGRESS)
1180 retval = port->bulk_out_size; 1141 retval = port->bulk_out_size;
@@ -1241,8 +1202,6 @@ static void qt_set_termios(struct tty_struct *tty,
1241 int baud, divisor, remainder; 1202 int baud, divisor, remainder;
1242 int status; 1203 int status;
1243 1204
1244 dbg("%s", __func__);
1245
1246 index = tty->index - port->serial->minor; 1205 index = tty->index - port->serial->minor;
1247 1206
1248 switch (cflag) { 1207 switch (cflag) {
@@ -1365,8 +1324,6 @@ static void qt_break(struct tty_struct *tty, int break_state)
1365 1324
1366 mutex_lock(&qt_port->lock); 1325 mutex_lock(&qt_port->lock);
1367 1326
1368 dbg("%s - port %d\n", __func__, port->number);
1369
1370 result = 1327 result =
1371 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0), 1328 usb_control_msg(serial->dev, usb_sndctrlpipe(serial->dev, 0),
1372 QT_BREAK_CONTROL, 0x40, onoff, index, NULL, 0, 300); 1329 QT_BREAK_CONTROL, 0x40, onoff, index, NULL, 0, 300);
@@ -1385,8 +1342,6 @@ static inline int qt_real_tiocmget(struct tty_struct *tty,
1385 int status; 1342 int status;
1386 unsigned int index; 1343 unsigned int index;
1387 1344
1388 dbg("%s - port %d, tty =0x%p\n", __func__, port->number, tty);
1389
1390 index = tty->index - serial->minor; 1345 index = tty->index - serial->minor;
1391 status = 1346 status =
1392 BoxGetRegister(port->serial, index, MODEM_CONTROL_REGISTER, &mcr); 1347 BoxGetRegister(port->serial, index, MODEM_CONTROL_REGISTER, &mcr);
@@ -1426,8 +1381,6 @@ static inline int qt_real_tiocmset(struct tty_struct *tty,
1426 int status; 1381 int status;
1427 unsigned int index; 1382 unsigned int index;
1428 1383
1429 dbg("%s - port %d\n", __func__, port->number);
1430
1431 index = tty->index - serial->minor; 1384 index = tty->index - serial->minor;
1432 status = 1385 status =
1433 BoxGetRegister(port->serial, index, MODEM_CONTROL_REGISTER, &mcr); 1386 BoxGetRegister(port->serial, index, MODEM_CONTROL_REGISTER, &mcr);
@@ -1461,18 +1414,11 @@ static int qt_tiocmget(struct tty_struct *tty)
1461 struct quatech_port *qt_port = qt_get_port_private(port); 1414 struct quatech_port *qt_port = qt_get_port_private(port);
1462 int retval = -ENODEV; 1415 int retval = -ENODEV;
1463 1416
1464 dbg("In %s\n", __func__);
1465
1466 if (!serial) 1417 if (!serial)
1467 return -ENODEV; 1418 return -ENODEV;
1468 1419
1469 mutex_lock(&qt_port->lock); 1420 mutex_lock(&qt_port->lock);
1470
1471 dbg("%s - port %d\n", __func__, port->number);
1472 dbg("%s - port->RxHolding = %d\n", __func__, qt_port->RxHolding);
1473
1474 retval = qt_real_tiocmget(tty, port, serial); 1421 retval = qt_real_tiocmget(tty, port, serial);
1475
1476 mutex_unlock(&qt_port->lock); 1422 mutex_unlock(&qt_port->lock);
1477 return retval; 1423 return retval;
1478} 1424}
@@ -1486,18 +1432,11 @@ static int qt_tiocmset(struct tty_struct *tty,
1486 struct quatech_port *qt_port = qt_get_port_private(port); 1432 struct quatech_port *qt_port = qt_get_port_private(port);
1487 int retval = -ENODEV; 1433 int retval = -ENODEV;
1488 1434
1489 dbg("In %s\n", __func__);
1490
1491 if (!serial) 1435 if (!serial)
1492 return -ENODEV; 1436 return -ENODEV;
1493 1437
1494 mutex_lock(&qt_port->lock); 1438 mutex_lock(&qt_port->lock);
1495
1496 dbg("%s - port %d\n", __func__, port->number);
1497 dbg("%s - qt_port->RxHolding = %d\n", __func__, qt_port->RxHolding);
1498
1499 retval = qt_real_tiocmset(tty, port, serial, set); 1439 retval = qt_real_tiocmset(tty, port, serial, set);
1500
1501 mutex_unlock(&qt_port->lock); 1440 mutex_unlock(&qt_port->lock);
1502 return retval; 1441 return retval;
1503} 1442}
@@ -1508,8 +1447,6 @@ static void qt_throttle(struct tty_struct *tty)
1508 struct usb_serial *serial = get_usb_serial(port, __func__); 1447 struct usb_serial *serial = get_usb_serial(port, __func__);
1509 struct quatech_port *qt_port; 1448 struct quatech_port *qt_port;
1510 1449
1511 dbg("%s - port %d\n", __func__, port->number);
1512
1513 if (!serial) 1450 if (!serial)
1514 return; 1451 return;
1515 1452
@@ -1519,7 +1456,6 @@ static void qt_throttle(struct tty_struct *tty)
1519 1456
1520 /* pass on to the driver specific version of this function */ 1457 /* pass on to the driver specific version of this function */
1521 qt_port->RxHolding = 1; 1458 qt_port->RxHolding = 1;
1522 dbg("%s - port->RxHolding = 1\n", __func__);
1523 1459
1524 mutex_unlock(&qt_port->lock); 1460 mutex_unlock(&qt_port->lock);
1525 return; 1461 return;
@@ -1539,8 +1475,6 @@ static void qt_unthrottle(struct tty_struct *tty)
1539 1475
1540 mutex_lock(&qt_port->lock); 1476 mutex_lock(&qt_port->lock);
1541 1477
1542 dbg("%s - port %d\n", __func__, port->number);
1543
1544 if (qt_port->RxHolding == 1) { 1478 if (qt_port->RxHolding == 1) {
1545 dbg("%s -qt_port->RxHolding == 1\n", __func__); 1479 dbg("%s -qt_port->RxHolding == 1\n", __func__);
1546 1480
@@ -1590,7 +1524,7 @@ static struct usb_serial_driver quatech_device = {
1590 .name = "serqt", 1524 .name = "serqt",
1591 }, 1525 },
1592 .description = DRIVER_DESC, 1526 .description = DRIVER_DESC,
1593 .id_table = serqt_id_table, 1527 .id_table = id_table,
1594 .num_ports = 8, 1528 .num_ports = 8,
1595 .open = qt_open, 1529 .open = qt_open,
1596 .close = qt_close, 1530 .close = qt_close,
@@ -1613,7 +1547,7 @@ static struct usb_serial_driver * const serial_drivers[] = {
1613 &quatech_device, NULL 1547 &quatech_device, NULL
1614}; 1548};
1615 1549
1616module_usb_serial_driver(serqt_usb_driver, serial_drivers); 1550module_usb_serial_driver(serial_drivers, id_table);
1617 1551
1618MODULE_AUTHOR(DRIVER_AUTHOR); 1552MODULE_AUTHOR(DRIVER_AUTHOR);
1619MODULE_DESCRIPTION(DRIVER_DESC); 1553MODULE_DESCRIPTION(DRIVER_DESC);