Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved. |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | */ |
| 12 | |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 13 | /* add additional information to our printk's */ |
| 14 | #define pr_fmt(fmt) "%s: " fmt "\n", __func__ |
| 15 | |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 16 | #include <linux/kernel.h> |
| 17 | #include <linux/errno.h> |
| 18 | #include <linux/init.h> |
| 19 | #include <linux/slab.h> |
| 20 | #include <linux/module.h> |
| 21 | #include <linux/kref.h> |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 22 | #include <linux/mutex.h> |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 23 | #include <linux/platform_device.h> |
Jack Pham | cca0332 | 2012-06-14 19:00:31 -0700 | [diff] [blame] | 24 | #include <linux/ratelimit.h> |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 25 | #include <linux/uaccess.h> |
| 26 | #include <linux/usb.h> |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 27 | #include <linux/debugfs.h> |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 28 | #include <mach/diag_bridge.h> |
| 29 | |
| 30 | #define DRIVER_DESC "USB host diag bridge driver" |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 31 | #define DRIVER_VERSION "1.0" |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 32 | |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 33 | #define MAX_DIAG_BRIDGE_DEVS 2 |
Hemant Kumar | a3d4a6e | 2012-10-16 17:57:08 -0700 | [diff] [blame] | 34 | #define AUTOSUSP_DELAY_WITH_USB 1000 |
| 35 | |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 36 | struct diag_bridge { |
| 37 | struct usb_device *udev; |
| 38 | struct usb_interface *ifc; |
| 39 | struct usb_anchor submitted; |
| 40 | __u8 in_epAddr; |
| 41 | __u8 out_epAddr; |
Jack Pham | 3ae820f | 2011-12-14 16:21:04 -0800 | [diff] [blame] | 42 | int err; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 43 | struct kref kref; |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 44 | struct mutex ifc_mutex; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 45 | struct diag_bridge_ops *ops; |
| 46 | struct platform_device *pdev; |
Hemant Kumar | a3d4a6e | 2012-10-16 17:57:08 -0700 | [diff] [blame] | 47 | unsigned default_autosusp_delay; |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 48 | |
| 49 | /* debugging counters */ |
| 50 | unsigned long bytes_to_host; |
| 51 | unsigned long bytes_to_mdm; |
| 52 | unsigned pending_reads; |
| 53 | unsigned pending_writes; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 54 | }; |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 55 | struct diag_bridge *__dev[MAX_DIAG_BRIDGE_DEVS]; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 56 | |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 57 | int diag_bridge_open(int id, struct diag_bridge_ops *ops) |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 58 | { |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 59 | struct diag_bridge *dev; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 60 | |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 61 | if (id < 0 || id >= MAX_DIAG_BRIDGE_DEVS) { |
| 62 | pr_err("Invalid device ID"); |
| 63 | return -ENODEV; |
| 64 | } |
| 65 | |
| 66 | dev = __dev[id]; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 67 | if (!dev) { |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 68 | pr_err("dev is null"); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 69 | return -ENODEV; |
| 70 | } |
| 71 | |
Jack Pham | fbd2255 | 2012-09-07 17:29:08 -0700 | [diff] [blame] | 72 | if (dev->ops) { |
| 73 | pr_err("bridge already opened"); |
| 74 | return -EALREADY; |
| 75 | } |
| 76 | |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 77 | dev->ops = ops; |
Jack Pham | 3ae820f | 2011-12-14 16:21:04 -0800 | [diff] [blame] | 78 | dev->err = 0; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 79 | |
Hemant Kumar | a3d4a6e | 2012-10-16 17:57:08 -0700 | [diff] [blame] | 80 | #ifdef CONFIG_PM_RUNTIME |
| 81 | dev->default_autosusp_delay = dev->udev->dev.power.autosuspend_delay; |
| 82 | #endif |
| 83 | pm_runtime_set_autosuspend_delay(&dev->udev->dev, |
| 84 | AUTOSUSP_DELAY_WITH_USB); |
| 85 | |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 86 | kref_get(&dev->kref); |
| 87 | |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 88 | return 0; |
| 89 | } |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 90 | EXPORT_SYMBOL(diag_bridge_open); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 91 | |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 92 | static void diag_bridge_delete(struct kref *kref) |
| 93 | { |
| 94 | struct diag_bridge *dev = container_of(kref, struct diag_bridge, kref); |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 95 | int id = dev->pdev->id; |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 96 | |
| 97 | usb_put_dev(dev->udev); |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 98 | __dev[id] = 0; |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 99 | kfree(dev); |
| 100 | } |
| 101 | |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 102 | void diag_bridge_close(int id) |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 103 | { |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 104 | struct diag_bridge *dev; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 105 | |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 106 | if (id < 0 || id >= MAX_DIAG_BRIDGE_DEVS) { |
| 107 | pr_err("Invalid device ID"); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | dev = __dev[id]; |
Jack Pham | fbd2255 | 2012-09-07 17:29:08 -0700 | [diff] [blame] | 112 | if (!dev) { |
| 113 | pr_err("dev is null"); |
| 114 | return; |
| 115 | } |
| 116 | |
| 117 | if (!dev->ops) { |
| 118 | pr_err("can't close bridge that was not open"); |
| 119 | return; |
| 120 | } |
| 121 | |
Jack Pham | e874150 | 2012-06-13 17:34:07 -0700 | [diff] [blame] | 122 | dev_dbg(&dev->ifc->dev, "%s:\n", __func__); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 123 | |
| 124 | usb_kill_anchored_urbs(&dev->submitted); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 125 | dev->ops = 0; |
Hemant Kumar | a3d4a6e | 2012-10-16 17:57:08 -0700 | [diff] [blame] | 126 | |
| 127 | pm_runtime_set_autosuspend_delay(&dev->udev->dev, |
| 128 | dev->default_autosusp_delay); |
| 129 | |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 130 | kref_put(&dev->kref, diag_bridge_delete); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 131 | } |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 132 | EXPORT_SYMBOL(diag_bridge_close); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 133 | |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 134 | static void diag_bridge_read_cb(struct urb *urb) |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 135 | { |
| 136 | struct diag_bridge *dev = urb->context; |
| 137 | struct diag_bridge_ops *cbs = dev->ops; |
| 138 | |
Jack Pham | e874150 | 2012-06-13 17:34:07 -0700 | [diff] [blame] | 139 | dev_dbg(&dev->ifc->dev, "%s: status:%d actual:%d\n", __func__, |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 140 | urb->status, urb->actual_length); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 141 | |
Jack Pham | 3ec42b6 | 2012-08-31 15:36:27 -0700 | [diff] [blame] | 142 | /* save error so that subsequent read/write returns ENODEV */ |
| 143 | if (urb->status == -EPROTO) |
Jack Pham | 3ae820f | 2011-12-14 16:21:04 -0800 | [diff] [blame] | 144 | dev->err = urb->status; |
Jack Pham | 3ae820f | 2011-12-14 16:21:04 -0800 | [diff] [blame] | 145 | |
Vamsi Krishna | 9012564 | 2012-05-12 16:06:13 -0700 | [diff] [blame] | 146 | if (cbs && cbs->read_complete_cb) |
| 147 | cbs->read_complete_cb(cbs->ctxt, |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 148 | urb->transfer_buffer, |
| 149 | urb->transfer_buffer_length, |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 150 | urb->status < 0 ? urb->status : urb->actual_length); |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 151 | |
| 152 | dev->bytes_to_host += urb->actual_length; |
| 153 | dev->pending_reads--; |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 154 | kref_put(&dev->kref, diag_bridge_delete); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 155 | } |
| 156 | |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 157 | int diag_bridge_read(int id, char *data, int size) |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 158 | { |
| 159 | struct urb *urb = NULL; |
| 160 | unsigned int pipe; |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 161 | struct diag_bridge *dev; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 162 | int ret; |
| 163 | |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 164 | if (id < 0 || id >= MAX_DIAG_BRIDGE_DEVS) { |
| 165 | pr_err("Invalid device ID"); |
| 166 | return -ENODEV; |
| 167 | } |
| 168 | |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 169 | pr_debug("reading %d bytes", size); |
| 170 | |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 171 | dev = __dev[id]; |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 172 | if (!dev) { |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 173 | pr_err("device is disconnected"); |
| 174 | return -ENODEV; |
| 175 | } |
| 176 | |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 177 | mutex_lock(&dev->ifc_mutex); |
| 178 | if (!dev->ifc) { |
| 179 | ret = -ENODEV; |
| 180 | goto error; |
| 181 | } |
| 182 | |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 183 | if (!dev->ops) { |
| 184 | pr_err("bridge is not open"); |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 185 | ret = -ENODEV; |
| 186 | goto error; |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 187 | } |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 188 | |
| 189 | if (!size) { |
Jack Pham | e874150 | 2012-06-13 17:34:07 -0700 | [diff] [blame] | 190 | dev_err(&dev->ifc->dev, "invalid size:%d\n", size); |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 191 | ret = -EINVAL; |
| 192 | goto error; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Jack Pham | 3ae820f | 2011-12-14 16:21:04 -0800 | [diff] [blame] | 195 | /* if there was a previous unrecoverable error, just quit */ |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 196 | if (dev->err) { |
| 197 | ret = -ENODEV; |
| 198 | goto error; |
| 199 | } |
Jack Pham | 3ae820f | 2011-12-14 16:21:04 -0800 | [diff] [blame] | 200 | |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 201 | kref_get(&dev->kref); |
| 202 | |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 203 | urb = usb_alloc_urb(0, GFP_KERNEL); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 204 | if (!urb) { |
Jack Pham | e874150 | 2012-06-13 17:34:07 -0700 | [diff] [blame] | 205 | dev_err(&dev->ifc->dev, "unable to allocate urb\n"); |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 206 | ret = -ENOMEM; |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 207 | goto put_error; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 208 | } |
| 209 | |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 210 | ret = usb_autopm_get_interface(dev->ifc); |
Jack Pham | cca0332 | 2012-06-14 19:00:31 -0700 | [diff] [blame] | 211 | if (ret < 0 && ret != -EAGAIN && ret != -EACCES) { |
| 212 | pr_err_ratelimited("read: autopm_get failed:%d", ret); |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 213 | goto free_error; |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 214 | } |
| 215 | |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 216 | pipe = usb_rcvbulkpipe(dev->udev, dev->in_epAddr); |
| 217 | usb_fill_bulk_urb(urb, dev->udev, pipe, data, size, |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 218 | diag_bridge_read_cb, dev); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 219 | usb_anchor_urb(urb, &dev->submitted); |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 220 | dev->pending_reads++; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 221 | |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 222 | ret = usb_submit_urb(urb, GFP_KERNEL); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 223 | if (ret) { |
Jack Pham | cca0332 | 2012-06-14 19:00:31 -0700 | [diff] [blame] | 224 | pr_err_ratelimited("submitting urb failed err:%d", ret); |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 225 | dev->pending_reads--; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 226 | usb_unanchor_urb(urb); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 227 | } |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 228 | usb_autopm_put_interface(dev->ifc); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 229 | |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 230 | free_error: |
| 231 | usb_free_urb(urb); |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 232 | put_error: |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 233 | if (ret) /* otherwise this is done in the completion handler */ |
| 234 | kref_put(&dev->kref, diag_bridge_delete); |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 235 | error: |
| 236 | mutex_unlock(&dev->ifc_mutex); |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 237 | return ret; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 238 | } |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 239 | EXPORT_SYMBOL(diag_bridge_read); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 240 | |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 241 | static void diag_bridge_write_cb(struct urb *urb) |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 242 | { |
| 243 | struct diag_bridge *dev = urb->context; |
| 244 | struct diag_bridge_ops *cbs = dev->ops; |
| 245 | |
Jack Pham | e874150 | 2012-06-13 17:34:07 -0700 | [diff] [blame] | 246 | dev_dbg(&dev->ifc->dev, "%s:\n", __func__); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 247 | |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 248 | usb_autopm_put_interface_async(dev->ifc); |
| 249 | |
Jack Pham | 3ec42b6 | 2012-08-31 15:36:27 -0700 | [diff] [blame] | 250 | /* save error so that subsequent read/write returns ENODEV */ |
| 251 | if (urb->status == -EPROTO) |
Jack Pham | 3ae820f | 2011-12-14 16:21:04 -0800 | [diff] [blame] | 252 | dev->err = urb->status; |
Jack Pham | 3ae820f | 2011-12-14 16:21:04 -0800 | [diff] [blame] | 253 | |
Vamsi Krishna | 9012564 | 2012-05-12 16:06:13 -0700 | [diff] [blame] | 254 | if (cbs && cbs->write_complete_cb) |
| 255 | cbs->write_complete_cb(cbs->ctxt, |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 256 | urb->transfer_buffer, |
| 257 | urb->transfer_buffer_length, |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 258 | urb->status < 0 ? urb->status : urb->actual_length); |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 259 | |
| 260 | dev->bytes_to_mdm += urb->actual_length; |
| 261 | dev->pending_writes--; |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 262 | kref_put(&dev->kref, diag_bridge_delete); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 263 | } |
| 264 | |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 265 | int diag_bridge_write(int id, char *data, int size) |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 266 | { |
| 267 | struct urb *urb = NULL; |
| 268 | unsigned int pipe; |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 269 | struct diag_bridge *dev; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 270 | int ret; |
| 271 | |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 272 | if (id < 0 || id >= MAX_DIAG_BRIDGE_DEVS) { |
| 273 | pr_err("Invalid device ID"); |
| 274 | return -ENODEV; |
| 275 | } |
| 276 | |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 277 | pr_debug("writing %d bytes", size); |
| 278 | |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 279 | dev = __dev[id]; |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 280 | if (!dev) { |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 281 | pr_err("device is disconnected"); |
| 282 | return -ENODEV; |
| 283 | } |
| 284 | |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 285 | mutex_lock(&dev->ifc_mutex); |
| 286 | if (!dev->ifc) { |
| 287 | ret = -ENODEV; |
| 288 | goto error; |
| 289 | } |
| 290 | |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 291 | if (!dev->ops) { |
| 292 | pr_err("bridge is not open"); |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 293 | ret = -ENODEV; |
| 294 | goto error; |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 295 | } |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 296 | |
| 297 | if (!size) { |
Jack Pham | e874150 | 2012-06-13 17:34:07 -0700 | [diff] [blame] | 298 | dev_err(&dev->ifc->dev, "invalid size:%d\n", size); |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 299 | ret = -EINVAL; |
| 300 | goto error; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 301 | } |
| 302 | |
Jack Pham | 3ae820f | 2011-12-14 16:21:04 -0800 | [diff] [blame] | 303 | /* if there was a previous unrecoverable error, just quit */ |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 304 | if (dev->err) { |
| 305 | ret = -ENODEV; |
| 306 | goto error; |
| 307 | } |
Jack Pham | 3ae820f | 2011-12-14 16:21:04 -0800 | [diff] [blame] | 308 | |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 309 | kref_get(&dev->kref); |
| 310 | |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 311 | urb = usb_alloc_urb(0, GFP_KERNEL); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 312 | if (!urb) { |
Jack Pham | e874150 | 2012-06-13 17:34:07 -0700 | [diff] [blame] | 313 | dev_err(&dev->ifc->dev, "unable to allocate urb\n"); |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 314 | ret = -ENOMEM; |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 315 | goto put_error; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 318 | ret = usb_autopm_get_interface(dev->ifc); |
Jack Pham | cca0332 | 2012-06-14 19:00:31 -0700 | [diff] [blame] | 319 | if (ret < 0 && ret != -EAGAIN && ret != -EACCES) { |
| 320 | pr_err_ratelimited("write: autopm_get failed:%d", ret); |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 321 | goto free_error; |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 322 | } |
| 323 | |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 324 | pipe = usb_sndbulkpipe(dev->udev, dev->out_epAddr); |
| 325 | usb_fill_bulk_urb(urb, dev->udev, pipe, data, size, |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 326 | diag_bridge_write_cb, dev); |
Jack Pham | 5a10c6f | 2012-06-26 11:41:28 -0700 | [diff] [blame] | 327 | urb->transfer_flags |= URB_ZERO_PACKET; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 328 | usb_anchor_urb(urb, &dev->submitted); |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 329 | dev->pending_writes++; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 330 | |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 331 | ret = usb_submit_urb(urb, GFP_KERNEL); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 332 | if (ret) { |
Jack Pham | cca0332 | 2012-06-14 19:00:31 -0700 | [diff] [blame] | 333 | pr_err_ratelimited("submitting urb failed err:%d", ret); |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 334 | dev->pending_writes--; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 335 | usb_unanchor_urb(urb); |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 336 | usb_autopm_put_interface(dev->ifc); |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 337 | goto free_error; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 338 | } |
| 339 | |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 340 | free_error: |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 341 | usb_free_urb(urb); |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 342 | put_error: |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 343 | if (ret) /* otherwise this is done in the completion handler */ |
| 344 | kref_put(&dev->kref, diag_bridge_delete); |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 345 | error: |
| 346 | mutex_unlock(&dev->ifc_mutex); |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 347 | return ret; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 348 | } |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 349 | EXPORT_SYMBOL(diag_bridge_write); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 350 | |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 351 | #if defined(CONFIG_DEBUG_FS) |
| 352 | #define DEBUG_BUF_SIZE 512 |
| 353 | static ssize_t diag_read_stats(struct file *file, char __user *ubuf, |
| 354 | size_t count, loff_t *ppos) |
| 355 | { |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 356 | char *buf; |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 357 | int i, ret = 0; |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 358 | |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 359 | buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL); |
| 360 | if (!buf) |
| 361 | return -ENOMEM; |
| 362 | |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 363 | for (i = 0; i < MAX_DIAG_BRIDGE_DEVS; i++) { |
| 364 | struct diag_bridge *dev = __dev[i]; |
| 365 | if (!dev) |
| 366 | continue; |
| 367 | |
| 368 | ret += scnprintf(buf, DEBUG_BUF_SIZE, |
| 369 | "epin:%d, epout:%d\n" |
| 370 | "bytes to host: %lu\n" |
| 371 | "bytes to mdm: %lu\n" |
| 372 | "pending reads: %u\n" |
| 373 | "pending writes: %u\n" |
| 374 | "last error: %d\n", |
| 375 | dev->in_epAddr, dev->out_epAddr, |
| 376 | dev->bytes_to_host, dev->bytes_to_mdm, |
| 377 | dev->pending_reads, dev->pending_writes, |
| 378 | dev->err); |
| 379 | } |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 380 | |
| 381 | ret = simple_read_from_buffer(ubuf, count, ppos, buf, ret); |
| 382 | kfree(buf); |
| 383 | return ret; |
| 384 | } |
| 385 | |
| 386 | static ssize_t diag_reset_stats(struct file *file, const char __user *buf, |
| 387 | size_t count, loff_t *ppos) |
| 388 | { |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 389 | int i; |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 390 | |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 391 | for (i = 0; i < MAX_DIAG_BRIDGE_DEVS; i++) { |
| 392 | struct diag_bridge *dev = __dev[i]; |
| 393 | if (dev) { |
| 394 | dev->bytes_to_host = dev->bytes_to_mdm = 0; |
| 395 | dev->pending_reads = dev->pending_writes = 0; |
| 396 | } |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 397 | } |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 398 | |
| 399 | return count; |
| 400 | } |
| 401 | |
| 402 | const struct file_operations diag_stats_ops = { |
| 403 | .read = diag_read_stats, |
| 404 | .write = diag_reset_stats, |
| 405 | }; |
| 406 | |
| 407 | static struct dentry *dent; |
| 408 | |
| 409 | static void diag_bridge_debugfs_init(void) |
| 410 | { |
| 411 | struct dentry *dfile; |
| 412 | |
| 413 | dent = debugfs_create_dir("diag_bridge", 0); |
| 414 | if (IS_ERR(dent)) |
| 415 | return; |
| 416 | |
| 417 | dfile = debugfs_create_file("status", 0444, dent, 0, &diag_stats_ops); |
| 418 | if (!dfile || IS_ERR(dfile)) |
| 419 | debugfs_remove(dent); |
| 420 | } |
| 421 | |
| 422 | static void diag_bridge_debugfs_cleanup(void) |
| 423 | { |
| 424 | if (dent) { |
| 425 | debugfs_remove_recursive(dent); |
| 426 | dent = NULL; |
| 427 | } |
| 428 | } |
| 429 | #else |
| 430 | static inline void diag_bridge_debugfs_init(void) { } |
| 431 | static inline void diag_bridge_debugfs_cleanup(void) { } |
| 432 | #endif |
| 433 | |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 434 | static int |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 435 | diag_bridge_probe(struct usb_interface *ifc, const struct usb_device_id *id) |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 436 | { |
| 437 | struct diag_bridge *dev; |
| 438 | struct usb_host_interface *ifc_desc; |
| 439 | struct usb_endpoint_descriptor *ep_desc; |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 440 | int i, devid, ret = -ENOMEM; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 441 | __u8 ifc_num; |
| 442 | |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 443 | pr_debug("id:%lu", id->driver_info); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 444 | |
| 445 | ifc_num = ifc->cur_altsetting->desc.bInterfaceNumber; |
| 446 | |
| 447 | /* is this interface supported ? */ |
Jack Pham | f81139b | 2013-01-24 16:42:47 -0800 | [diff] [blame] | 448 | if (ifc_num != (id->driver_info & 0xFF)) |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 449 | return -ENODEV; |
| 450 | |
Jack Pham | f81139b | 2013-01-24 16:42:47 -0800 | [diff] [blame] | 451 | devid = (id->driver_info >> 8) & 0xFF; |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 452 | if (devid < 0 || devid >= MAX_DIAG_BRIDGE_DEVS) |
| 453 | return -ENODEV; |
| 454 | |
| 455 | /* already probed? */ |
| 456 | if (__dev[devid]) { |
| 457 | pr_err("Diag device already probed"); |
| 458 | return -ENODEV; |
| 459 | } |
| 460 | |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 461 | dev = kzalloc(sizeof(*dev), GFP_KERNEL); |
| 462 | if (!dev) { |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 463 | pr_err("unable to allocate dev"); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 464 | return -ENOMEM; |
| 465 | } |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 466 | dev->pdev = platform_device_alloc("diag_bridge", devid); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 467 | if (!dev->pdev) { |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 468 | pr_err("unable to allocate platform device"); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 469 | kfree(dev); |
| 470 | return -ENOMEM; |
| 471 | } |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 472 | __dev[devid] = dev; |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 473 | |
| 474 | dev->udev = usb_get_dev(interface_to_usbdev(ifc)); |
| 475 | dev->ifc = ifc; |
| 476 | kref_init(&dev->kref); |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 477 | mutex_init(&dev->ifc_mutex); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 478 | init_usb_anchor(&dev->submitted); |
| 479 | |
| 480 | ifc_desc = ifc->cur_altsetting; |
| 481 | for (i = 0; i < ifc_desc->desc.bNumEndpoints; i++) { |
| 482 | ep_desc = &ifc_desc->endpoint[i].desc; |
| 483 | |
| 484 | if (!dev->in_epAddr && usb_endpoint_is_bulk_in(ep_desc)) |
| 485 | dev->in_epAddr = ep_desc->bEndpointAddress; |
| 486 | |
| 487 | if (!dev->out_epAddr && usb_endpoint_is_bulk_out(ep_desc)) |
| 488 | dev->out_epAddr = ep_desc->bEndpointAddress; |
| 489 | } |
| 490 | |
| 491 | if (!(dev->in_epAddr && dev->out_epAddr)) { |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 492 | pr_err("could not find bulk in and bulk out endpoints"); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 493 | ret = -ENODEV; |
| 494 | goto error; |
| 495 | } |
| 496 | |
| 497 | usb_set_intfdata(ifc, dev); |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 498 | diag_bridge_debugfs_init(); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 499 | platform_device_add(dev->pdev); |
| 500 | |
Jack Pham | e874150 | 2012-06-13 17:34:07 -0700 | [diff] [blame] | 501 | dev_dbg(&dev->ifc->dev, "%s: complete\n", __func__); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 502 | |
| 503 | return 0; |
| 504 | |
| 505 | error: |
| 506 | if (dev) |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 507 | kref_put(&dev->kref, diag_bridge_delete); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 508 | |
| 509 | return ret; |
| 510 | } |
| 511 | |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 512 | static void diag_bridge_disconnect(struct usb_interface *ifc) |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 513 | { |
| 514 | struct diag_bridge *dev = usb_get_intfdata(ifc); |
| 515 | |
Jack Pham | e874150 | 2012-06-13 17:34:07 -0700 | [diff] [blame] | 516 | dev_dbg(&dev->ifc->dev, "%s:\n", __func__); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 517 | |
Jack Pham | 1b1ba47 | 2012-06-13 16:40:15 -0700 | [diff] [blame] | 518 | platform_device_unregister(dev->pdev); |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 519 | mutex_lock(&dev->ifc_mutex); |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 520 | dev->ifc = NULL; |
Jack Pham | b179554 | 2012-09-04 17:13:37 -0700 | [diff] [blame] | 521 | mutex_unlock(&dev->ifc_mutex); |
Jack Pham | 9a08de4 | 2012-02-06 15:43:23 -0800 | [diff] [blame] | 522 | diag_bridge_debugfs_cleanup(); |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 523 | kref_put(&dev->kref, diag_bridge_delete); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 524 | usb_set_intfdata(ifc, NULL); |
| 525 | } |
| 526 | |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 527 | static int diag_bridge_suspend(struct usb_interface *ifc, pm_message_t message) |
| 528 | { |
| 529 | struct diag_bridge *dev = usb_get_intfdata(ifc); |
| 530 | struct diag_bridge_ops *cbs = dev->ops; |
| 531 | int ret = 0; |
| 532 | |
| 533 | if (cbs && cbs->suspend) { |
| 534 | ret = cbs->suspend(cbs->ctxt); |
| 535 | if (ret) { |
Jack Pham | e874150 | 2012-06-13 17:34:07 -0700 | [diff] [blame] | 536 | dev_dbg(&dev->ifc->dev, |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 537 | "%s: diag veto'd suspend\n", __func__); |
| 538 | return ret; |
| 539 | } |
| 540 | |
| 541 | usb_kill_anchored_urbs(&dev->submitted); |
| 542 | } |
| 543 | |
| 544 | return ret; |
| 545 | } |
| 546 | |
| 547 | static int diag_bridge_resume(struct usb_interface *ifc) |
| 548 | { |
| 549 | struct diag_bridge *dev = usb_get_intfdata(ifc); |
| 550 | struct diag_bridge_ops *cbs = dev->ops; |
| 551 | |
| 552 | |
| 553 | if (cbs && cbs->resume) |
| 554 | cbs->resume(cbs->ctxt); |
| 555 | |
| 556 | return 0; |
| 557 | } |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 558 | |
| 559 | #define VALID_INTERFACE_NUM 0 |
Jack Pham | f81139b | 2013-01-24 16:42:47 -0800 | [diff] [blame] | 560 | #define DEV_ID(n) ((n)<<8) |
| 561 | |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 562 | static const struct usb_device_id diag_bridge_ids[] = { |
Hemant Kumar | 7a067f1 | 2012-01-05 15:35:15 -0800 | [diff] [blame] | 563 | { USB_DEVICE(0x5c6, 0x9001), |
Jack Pham | f81139b | 2013-01-24 16:42:47 -0800 | [diff] [blame] | 564 | .driver_info = VALID_INTERFACE_NUM | DEV_ID(0), }, |
Hemant Kumar | 7a067f1 | 2012-01-05 15:35:15 -0800 | [diff] [blame] | 565 | { USB_DEVICE(0x5c6, 0x9034), |
Jack Pham | f81139b | 2013-01-24 16:42:47 -0800 | [diff] [blame] | 566 | .driver_info = VALID_INTERFACE_NUM | DEV_ID(0), }, |
Hemant Kumar | 7f23683 | 2011-12-16 12:13:21 -0800 | [diff] [blame] | 567 | { USB_DEVICE(0x5c6, 0x9048), |
Jack Pham | f81139b | 2013-01-24 16:42:47 -0800 | [diff] [blame] | 568 | .driver_info = VALID_INTERFACE_NUM | DEV_ID(0), }, |
Hemant Kumar | cfc0dad | 2012-02-21 14:34:39 -0800 | [diff] [blame] | 569 | { USB_DEVICE(0x5c6, 0x904C), |
Jack Pham | f81139b | 2013-01-24 16:42:47 -0800 | [diff] [blame] | 570 | .driver_info = VALID_INTERFACE_NUM | DEV_ID(0), }, |
Hemant Kumar | ce3c5bf | 2012-12-06 15:52:02 -0800 | [diff] [blame] | 571 | { USB_DEVICE(0x5c6, 0x9075), |
Jack Pham | f81139b | 2013-01-24 16:42:47 -0800 | [diff] [blame] | 572 | .driver_info = VALID_INTERFACE_NUM | DEV_ID(0), }, |
| 573 | { USB_DEVICE(0x5c6, 0x9079), |
| 574 | .driver_info = VALID_INTERFACE_NUM | DEV_ID(1), }, |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 575 | |
| 576 | {} /* terminating entry */ |
| 577 | }; |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 578 | MODULE_DEVICE_TABLE(usb, diag_bridge_ids); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 579 | |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 580 | static struct usb_driver diag_bridge_driver = { |
| 581 | .name = "diag_bridge", |
| 582 | .probe = diag_bridge_probe, |
| 583 | .disconnect = diag_bridge_disconnect, |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 584 | .suspend = diag_bridge_suspend, |
| 585 | .resume = diag_bridge_resume, |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 586 | .id_table = diag_bridge_ids, |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 587 | .supports_autosuspend = 1, |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 588 | }; |
| 589 | |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 590 | static int __init diag_bridge_init(void) |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 591 | { |
| 592 | int ret; |
| 593 | |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 594 | ret = usb_register(&diag_bridge_driver); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 595 | if (ret) { |
Jack Pham | 76e61dd | 2012-06-14 18:48:53 -0700 | [diff] [blame] | 596 | pr_err("unable to register diag driver"); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 597 | return ret; |
| 598 | } |
| 599 | |
| 600 | return 0; |
| 601 | } |
| 602 | |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 603 | static void __exit diag_bridge_exit(void) |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 604 | { |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 605 | usb_deregister(&diag_bridge_driver); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 606 | } |
| 607 | |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 608 | module_init(diag_bridge_init); |
| 609 | module_exit(diag_bridge_exit); |
Jack Pham | e32cf32 | 2011-09-26 10:20:17 -0700 | [diff] [blame] | 610 | |
| 611 | MODULE_DESCRIPTION(DRIVER_DESC); |
Jack Pham | f6ed558 | 2011-11-02 16:08:31 -0700 | [diff] [blame] | 612 | MODULE_VERSION(DRIVER_VERSION); |
| 613 | MODULE_LICENSE("GPL v2"); |