Uri Shkolnik | 6d4e697 | 2009-05-12 07:57:54 -0300 | [diff] [blame] | 1 | /**************************************************************** |
| 2 | |
| 3 | Siano Mobile Silicon, Inc. |
| 4 | MDTV receiver kernel modules. |
| 5 | Copyright (C) 2005-2009, Uri Shkolnik, Anatoly Greenblat |
| 6 | |
| 7 | This program is free software: you can redistribute it and/or modify |
| 8 | it under the terms of the GNU General Public License as published by |
| 9 | the Free Software Foundation, either version 2 of the License, or |
| 10 | (at your option) any later version. |
| 11 | |
| 12 | This program is distributed in the hope that it will be useful, |
| 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | GNU General Public License for more details. |
| 16 | |
| 17 | You should have received a copy of the GNU General Public License |
| 18 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | ****************************************************************/ |
Steven Toth | 8d4f9d0 | 2008-05-22 18:05:26 -0300 | [diff] [blame] | 21 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 22 | #include <linux/kernel.h> |
| 23 | #include <linux/init.h> |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 24 | #include <linux/usb.h> |
| 25 | #include <linux/firmware.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 26 | #include <linux/slab.h> |
Paul Gortmaker | 7a707b8 | 2011-07-03 14:03:12 -0400 | [diff] [blame] | 27 | #include <linux/module.h> |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 28 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 29 | #include "smscoreapi.h" |
Michael Krufky | 1c11d54 | 2008-06-18 22:09:55 -0300 | [diff] [blame] | 30 | #include "sms-cards.h" |
Uri Shkolnik | c7ce8d3 | 2009-05-12 08:24:07 -0300 | [diff] [blame] | 31 | #include "smsendian.h" |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 32 | |
Michael Krufky | 0d02efe | 2009-02-27 02:42:16 -0300 | [diff] [blame] | 33 | static int sms_dbg; |
| 34 | module_param_named(debug, sms_dbg, int, 0644); |
| 35 | MODULE_PARM_DESC(debug, "set debug level (info=1, adv=2 (or-able))"); |
| 36 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 37 | #define USB1_BUFFER_SIZE 0x1000 |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 38 | #define USB2_BUFFER_SIZE 0x2000 |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 39 | |
| 40 | #define MAX_BUFFERS 50 |
| 41 | #define MAX_URBS 10 |
| 42 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 43 | struct smsusb_device_t; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 44 | |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 45 | enum smsusb_state { |
| 46 | SMSUSB_DISCONNECTED, |
| 47 | SMSUSB_SUSPENDED, |
| 48 | SMSUSB_ACTIVE |
| 49 | }; |
| 50 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 51 | struct smsusb_urb_t { |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 52 | struct list_head entry; |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 53 | struct smscore_buffer_t *cb; |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 54 | struct smsusb_device_t *dev; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 55 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 56 | struct urb urb; |
| 57 | }; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 58 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 59 | struct smsusb_device_t { |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 60 | struct usb_device *udev; |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 61 | struct smscore_device_t *coredev; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 62 | |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 63 | struct smsusb_urb_t surbs[MAX_URBS]; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 64 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 65 | int response_alignment; |
| 66 | int buffer_size; |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 67 | |
| 68 | unsigned char in_ep; |
| 69 | unsigned char out_ep; |
| 70 | enum smsusb_state state; |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 71 | }; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 72 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 73 | static int smsusb_submit_urb(struct smsusb_device_t *dev, |
| 74 | struct smsusb_urb_t *surb); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 75 | |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 76 | /** |
| 77 | * Completing URB's callback handler - top half (interrupt context) |
| 78 | * adds completing sms urb to the global surbs list and activtes the worker |
| 79 | * thread the surb |
| 80 | * IMPORTANT - blocking functions must not be called from here !!! |
| 81 | |
| 82 | * @param urb pointer to a completing urb object |
| 83 | */ |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 84 | static void smsusb_onresponse(struct urb *urb) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 85 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 86 | struct smsusb_urb_t *surb = (struct smsusb_urb_t *) urb->context; |
| 87 | struct smsusb_device_t *dev = surb->dev; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 88 | |
Uri Shkolnik | 8f12d0a | 2009-05-12 11:28:41 -0300 | [diff] [blame] | 89 | if (urb->status == -ESHUTDOWN) { |
| 90 | sms_err("error, urb status %d (-ESHUTDOWN), %d bytes", |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 91 | urb->status, urb->actual_length); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 92 | return; |
| 93 | } |
| 94 | |
Uri Shkolnik | 8f12d0a | 2009-05-12 11:28:41 -0300 | [diff] [blame] | 95 | if ((urb->actual_length > 0) && (urb->status == 0)) { |
| 96 | struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *)surb->cb->p; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 97 | |
Uri Shkolnik | 9c9c68a | 2009-05-14 16:27:16 -0300 | [diff] [blame] | 98 | smsendian_handle_message_header(phdr); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 99 | if (urb->actual_length >= phdr->msgLength) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 100 | surb->cb->size = phdr->msgLength; |
| 101 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 102 | if (dev->response_alignment && |
| 103 | (phdr->msgFlags & MSG_HDR_FLAG_SPLIT_MSG)) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 104 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 105 | surb->cb->offset = |
| 106 | dev->response_alignment + |
| 107 | ((phdr->msgFlags >> 8) & 3); |
| 108 | |
| 109 | /* sanity check */ |
| 110 | if (((int) phdr->msgLength + |
| 111 | surb->cb->offset) > urb->actual_length) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 112 | sms_err("invalid response " |
| 113 | "msglen %d offset %d " |
| 114 | "size %d", |
| 115 | phdr->msgLength, |
| 116 | surb->cb->offset, |
| 117 | urb->actual_length); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 118 | goto exit_and_resubmit; |
| 119 | } |
| 120 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 121 | /* move buffer pointer and |
| 122 | * copy header to its new location */ |
Michael Krufky | 55ad310 | 2008-05-06 03:52:44 -0300 | [diff] [blame] | 123 | memcpy((char *) phdr + surb->cb->offset, |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 124 | phdr, sizeof(struct SmsMsgHdr_ST)); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 125 | } else |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 126 | surb->cb->offset = 0; |
| 127 | |
Mauro Carvalho Chehab | 4c3bdb5 | 2013-03-09 09:27:39 -0300 | [diff] [blame] | 128 | sms_debug("received %s(%d) size: %d", |
| 129 | smscore_translate_msg(phdr->msgType), |
| 130 | phdr->msgType, phdr->msgLength); |
| 131 | |
Mauro Carvalho Chehab | 80ccb51 | 2013-03-09 11:34:56 -0300 | [diff] [blame^] | 132 | smsendian_handle_rx_message((struct SmsMsgData_ST *) phdr); |
| 133 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 134 | smscore_onresponse(dev->coredev, surb->cb); |
| 135 | surb->cb = NULL; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 136 | } else { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 137 | sms_err("invalid response " |
| 138 | "msglen %d actual %d", |
| 139 | phdr->msgLength, urb->actual_length); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 140 | } |
Uri Shkolnik | 8f12d0a | 2009-05-12 11:28:41 -0300 | [diff] [blame] | 141 | } else |
| 142 | sms_err("error, urb status %d, %d bytes", |
| 143 | urb->status, urb->actual_length); |
| 144 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 145 | |
| 146 | exit_and_resubmit: |
| 147 | smsusb_submit_urb(dev, surb); |
| 148 | } |
| 149 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 150 | static int smsusb_submit_urb(struct smsusb_device_t *dev, |
| 151 | struct smsusb_urb_t *surb) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 152 | { |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 153 | if (!surb->cb) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 154 | surb->cb = smscore_getbuffer(dev->coredev); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 155 | if (!surb->cb) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 156 | sms_err("smscore_getbuffer(...) returned NULL"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 157 | return -ENOMEM; |
| 158 | } |
| 159 | } |
| 160 | |
| 161 | usb_fill_bulk_urb( |
| 162 | &surb->urb, |
| 163 | dev->udev, |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 164 | usb_rcvbulkpipe(dev->udev, dev->in_ep), |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 165 | surb->cb->p, |
| 166 | dev->buffer_size, |
| 167 | smsusb_onresponse, |
| 168 | surb |
| 169 | ); |
| 170 | surb->urb.transfer_dma = surb->cb->phys; |
| 171 | surb->urb.transfer_flags |= URB_NO_TRANSFER_DMA_MAP; |
| 172 | |
| 173 | return usb_submit_urb(&surb->urb, GFP_ATOMIC); |
| 174 | } |
| 175 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 176 | static void smsusb_stop_streaming(struct smsusb_device_t *dev) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 177 | { |
| 178 | int i; |
| 179 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 180 | for (i = 0; i < MAX_URBS; i++) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 181 | usb_kill_urb(&dev->surbs[i].urb); |
| 182 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 183 | if (dev->surbs[i].cb) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 184 | smscore_putbuffer(dev->coredev, dev->surbs[i].cb); |
| 185 | dev->surbs[i].cb = NULL; |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 190 | static int smsusb_start_streaming(struct smsusb_device_t *dev) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 191 | { |
| 192 | int i, rc; |
| 193 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 194 | for (i = 0; i < MAX_URBS; i++) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 195 | rc = smsusb_submit_urb(dev, &dev->surbs[i]); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 196 | if (rc < 0) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 197 | sms_err("smsusb_submit_urb(...) failed"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 198 | smsusb_stop_streaming(dev); |
| 199 | break; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | return rc; |
| 204 | } |
| 205 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 206 | static int smsusb_sendrequest(void *context, void *buffer, size_t size) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 207 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 208 | struct smsusb_device_t *dev = (struct smsusb_device_t *) context; |
Mauro Carvalho Chehab | 4c3bdb5 | 2013-03-09 09:27:39 -0300 | [diff] [blame] | 209 | struct SmsMsgHdr_ST *phdr = (struct SmsMsgHdr_ST *) buffer; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 210 | int dummy; |
| 211 | |
Mauro Carvalho Chehab | 80ccb51 | 2013-03-09 11:34:56 -0300 | [diff] [blame^] | 212 | if (dev->state != SMSUSB_ACTIVE) |
| 213 | return -ENOENT; |
| 214 | |
Mauro Carvalho Chehab | 4c3bdb5 | 2013-03-09 09:27:39 -0300 | [diff] [blame] | 215 | sms_debug("sending %s(%d) size: %d", |
| 216 | smscore_translate_msg(phdr->msgType), phdr->msgType, |
| 217 | phdr->msgLength); |
| 218 | |
Mauro Carvalho Chehab | 80ccb51 | 2013-03-09 11:34:56 -0300 | [diff] [blame^] | 219 | smsendian_handle_tx_message((struct SmsMsgData_ST *) phdr); |
Uri Shkolnik | c7ce8d3 | 2009-05-12 08:24:07 -0300 | [diff] [blame] | 220 | smsendian_handle_message_header((struct SmsMsgHdr_ST *)buffer); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 221 | return usb_bulk_msg(dev->udev, usb_sndbulkpipe(dev->udev, 2), |
| 222 | buffer, size, &dummy, 1000); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 223 | } |
| 224 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 225 | static char *smsusb1_fw_lkup[] = { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 226 | "dvbt_stellar_usb.inp", |
| 227 | "dvbh_stellar_usb.inp", |
| 228 | "tdmb_stellar_usb.inp", |
| 229 | "none", |
| 230 | "dvbt_bda_stellar_usb.inp", |
| 231 | }; |
| 232 | |
Michael Krufky | 1fbc3ca | 2008-07-01 04:35:26 -0300 | [diff] [blame] | 233 | static inline char *sms_get_fw_name(int mode, int board_id) |
| 234 | { |
| 235 | char **fw = sms_get_board(board_id)->fw; |
| 236 | return (fw && fw[mode]) ? fw[mode] : smsusb1_fw_lkup[mode]; |
| 237 | } |
| 238 | |
| 239 | static int smsusb1_load_firmware(struct usb_device *udev, int id, int board_id) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 240 | { |
| 241 | const struct firmware *fw; |
Michael Krufky | a83ccdd | 2008-05-06 03:11:51 -0300 | [diff] [blame] | 242 | u8 *fw_buffer; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 243 | int rc, dummy; |
Michael Krufky | 1fbc3ca | 2008-07-01 04:35:26 -0300 | [diff] [blame] | 244 | char *fw_filename; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 245 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 246 | if (id < DEVICE_MODE_DVBT || id > DEVICE_MODE_DVBT_BDA) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 247 | sms_err("invalid firmware id specified %d", id); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 248 | return -EINVAL; |
| 249 | } |
| 250 | |
Michael Krufky | 1fbc3ca | 2008-07-01 04:35:26 -0300 | [diff] [blame] | 251 | fw_filename = sms_get_fw_name(id, board_id); |
| 252 | |
| 253 | rc = request_firmware(&fw, fw_filename, &udev->dev); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 254 | if (rc < 0) { |
Michael Krufky | 1fbc3ca | 2008-07-01 04:35:26 -0300 | [diff] [blame] | 255 | sms_warn("failed to open \"%s\" mode %d, " |
| 256 | "trying again with default firmware", fw_filename, id); |
| 257 | |
| 258 | fw_filename = smsusb1_fw_lkup[id]; |
| 259 | rc = request_firmware(&fw, fw_filename, &udev->dev); |
| 260 | if (rc < 0) { |
| 261 | sms_warn("failed to open \"%s\" mode %d", |
| 262 | fw_filename, id); |
| 263 | |
| 264 | return rc; |
| 265 | } |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | fw_buffer = kmalloc(fw->size, GFP_KERNEL); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 269 | if (fw_buffer) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 270 | memcpy(fw_buffer, fw->data, fw->size); |
| 271 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 272 | rc = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 2), |
| 273 | fw_buffer, fw->size, &dummy, 1000); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 274 | |
Michael Krufky | 0f2a1ee | 2008-06-28 20:53:45 -0300 | [diff] [blame] | 275 | sms_info("sent %zd(%d) bytes, rc %d", fw->size, dummy, rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 276 | |
| 277 | kfree(fw_buffer); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 278 | } else { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 279 | sms_err("failed to allocate firmware buffer"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 280 | rc = -ENOMEM; |
| 281 | } |
Michael Krufky | 1fbc3ca | 2008-07-01 04:35:26 -0300 | [diff] [blame] | 282 | sms_info("read FW %s, size=%zd", fw_filename, fw->size); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 283 | |
| 284 | release_firmware(fw); |
| 285 | |
| 286 | return rc; |
| 287 | } |
| 288 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 289 | static void smsusb1_detectmode(void *context, int *mode) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 290 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 291 | char *product_string = |
| 292 | ((struct smsusb_device_t *) context)->udev->product; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 293 | |
| 294 | *mode = DEVICE_MODE_NONE; |
| 295 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 296 | if (!product_string) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 297 | product_string = "none"; |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 298 | sms_err("product string not found"); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 299 | } else if (strstr(product_string, "DVBH")) |
| 300 | *mode = 1; |
| 301 | else if (strstr(product_string, "BDA")) |
| 302 | *mode = 4; |
| 303 | else if (strstr(product_string, "DVBT")) |
| 304 | *mode = 0; |
| 305 | else if (strstr(product_string, "TDMB")) |
| 306 | *mode = 2; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 307 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 308 | sms_info("%d \"%s\"", *mode, product_string); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 309 | } |
| 310 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 311 | static int smsusb1_setmode(void *context, int mode) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 312 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 313 | struct SmsMsgHdr_ST Msg = { MSG_SW_RELOAD_REQ, 0, HIF_TASK, |
| 314 | sizeof(struct SmsMsgHdr_ST), 0 }; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 315 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 316 | if (mode < DEVICE_MODE_DVBT || mode > DEVICE_MODE_DVBT_BDA) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 317 | sms_err("invalid firmware id specified %d", mode); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 318 | return -EINVAL; |
| 319 | } |
| 320 | |
| 321 | return smsusb_sendrequest(context, &Msg, sizeof(Msg)); |
| 322 | } |
| 323 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 324 | static void smsusb_term_device(struct usb_interface *intf) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 325 | { |
Joe Perches | 8350e15 | 2010-11-30 18:42:07 -0300 | [diff] [blame] | 326 | struct smsusb_device_t *dev = usb_get_intfdata(intf); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 327 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 328 | if (dev) { |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 329 | dev->state = SMSUSB_DISCONNECTED; |
| 330 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 331 | smsusb_stop_streaming(dev); |
| 332 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 333 | /* unregister from smscore */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 334 | if (dev->coredev) |
| 335 | smscore_unregister_device(dev->coredev); |
| 336 | |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 337 | sms_info("device 0x%p destroyed", dev); |
Jesper Juhl | 08921ac | 2011-04-21 18:11:25 -0300 | [diff] [blame] | 338 | kfree(dev); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | usb_set_intfdata(intf, NULL); |
| 342 | } |
| 343 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 344 | static int smsusb_init_device(struct usb_interface *intf, int board_id) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 345 | { |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 346 | struct smsdevice_params_t params; |
| 347 | struct smsusb_device_t *dev; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 348 | int i, rc; |
| 349 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 350 | /* create device object */ |
Michael Krufky | 18245e1 | 2008-06-15 17:52:24 -0300 | [diff] [blame] | 351 | dev = kzalloc(sizeof(struct smsusb_device_t), GFP_KERNEL); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 352 | if (!dev) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 353 | sms_err("kzalloc(sizeof(struct smsusb_device_t) failed"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 354 | return -ENOMEM; |
| 355 | } |
| 356 | |
| 357 | memset(¶ms, 0, sizeof(params)); |
| 358 | usb_set_intfdata(intf, dev); |
| 359 | dev->udev = interface_to_usbdev(intf); |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 360 | dev->state = SMSUSB_DISCONNECTED; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 361 | |
Michael Krufky | 2708e88 | 2008-06-21 05:24:38 -0300 | [diff] [blame] | 362 | params.device_type = sms_get_board(board_id)->type; |
Michael Krufky | 73104fb | 2008-06-14 18:27:18 -0300 | [diff] [blame] | 363 | |
Michael Krufky | 2708e88 | 2008-06-21 05:24:38 -0300 | [diff] [blame] | 364 | switch (params.device_type) { |
Michael Krufky | 1c11d54 | 2008-06-18 22:09:55 -0300 | [diff] [blame] | 365 | case SMS_STELLAR: |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 366 | dev->buffer_size = USB1_BUFFER_SIZE; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 367 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 368 | params.setmode_handler = smsusb1_setmode; |
| 369 | params.detectmode_handler = smsusb1_detectmode; |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 370 | break; |
| 371 | default: |
Michael Krufky | 2708e88 | 2008-06-21 05:24:38 -0300 | [diff] [blame] | 372 | sms_err("Unspecified sms device type!"); |
| 373 | /* fall-thru */ |
| 374 | case SMS_NOVA_A0: |
| 375 | case SMS_NOVA_B0: |
| 376 | case SMS_VEGA: |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 377 | case SMS_VENICE: |
| 378 | case SMS_DENVER_1530: |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 379 | dev->buffer_size = USB2_BUFFER_SIZE; |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 380 | dev->response_alignment = |
Uri Shkolnik | c7ce8d3 | 2009-05-12 08:24:07 -0300 | [diff] [blame] | 381 | le16_to_cpu(dev->udev->ep_in[1]->desc.wMaxPacketSize) - |
| 382 | sizeof(struct SmsMsgHdr_ST); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 383 | |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 384 | params.flags |= SMS_DEVICE_FAMILY2; |
| 385 | break; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 386 | } |
| 387 | |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 388 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { |
| 389 | if (intf->cur_altsetting->endpoint[i].desc. bEndpointAddress & USB_DIR_IN) |
| 390 | dev->in_ep = intf->cur_altsetting->endpoint[i].desc.bEndpointAddress; |
| 391 | else |
| 392 | dev->out_ep = intf->cur_altsetting->endpoint[i].desc.bEndpointAddress; |
| 393 | } |
| 394 | |
| 395 | sms_info("in_ep = %02x, out_ep = %02x", |
| 396 | dev->in_ep, dev->out_ep); |
| 397 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 398 | params.device = &dev->udev->dev; |
| 399 | params.buffer_size = dev->buffer_size; |
| 400 | params.num_buffers = MAX_BUFFERS; |
| 401 | params.sendrequest_handler = smsusb_sendrequest; |
| 402 | params.context = dev; |
Mauro Carvalho Chehab | 1722f3b | 2010-08-01 15:30:50 -0300 | [diff] [blame] | 403 | usb_make_path(dev->udev, params.devpath, sizeof(params.devpath)); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 404 | |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 405 | /* register in smscore */ |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 406 | rc = smscore_register_device(¶ms, &dev->coredev); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 407 | if (rc < 0) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 408 | sms_err("smscore_register_device(...) failed, rc %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 409 | smsusb_term_device(intf); |
| 410 | return rc; |
| 411 | } |
| 412 | |
Michael Krufky | 1c11d54 | 2008-06-18 22:09:55 -0300 | [diff] [blame] | 413 | smscore_set_board_id(dev->coredev, board_id); |
| 414 | |
Michael Krufky | fa830e8 | 2008-06-15 15:52:43 -0300 | [diff] [blame] | 415 | /* initialize urbs */ |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 416 | for (i = 0; i < MAX_URBS; i++) { |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 417 | dev->surbs[i].dev = dev; |
| 418 | usb_init_urb(&dev->surbs[i].urb); |
| 419 | } |
| 420 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 421 | sms_info("smsusb_start_streaming(...)."); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 422 | rc = smsusb_start_streaming(dev); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 423 | if (rc < 0) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 424 | sms_err("smsusb_start_streaming(...) failed"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 425 | smsusb_term_device(intf); |
| 426 | return rc; |
| 427 | } |
| 428 | |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 429 | dev->state = SMSUSB_ACTIVE; |
| 430 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 431 | rc = smscore_start_device(dev->coredev); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 432 | if (rc < 0) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 433 | sms_err("smscore_start_device(...) failed"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 434 | smsusb_term_device(intf); |
| 435 | return rc; |
| 436 | } |
| 437 | |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 438 | sms_info("device 0x%p created", dev); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 439 | |
| 440 | return rc; |
| 441 | } |
| 442 | |
Greg Kroah-Hartman | 4c62e97 | 2012-12-21 13:17:53 -0800 | [diff] [blame] | 443 | static int smsusb_probe(struct usb_interface *intf, |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 444 | const struct usb_device_id *id) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 445 | { |
| 446 | struct usb_device *udev = interface_to_usbdev(intf); |
Mauro Carvalho Chehab | 347d8f1 | 2013-03-05 22:35:44 -0300 | [diff] [blame] | 447 | char devpath[32]; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 448 | int i, rc; |
| 449 | |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 450 | sms_info("interface number %d", |
| 451 | intf->cur_altsetting->desc.bInterfaceNumber); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 452 | |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 453 | if (sms_get_board(id->driver_info)->intf_num != |
| 454 | intf->cur_altsetting->desc.bInterfaceNumber) { |
| 455 | sms_err("interface number is %d expecting %d", |
| 456 | sms_get_board(id->driver_info)->intf_num, |
| 457 | intf->cur_altsetting->desc.bInterfaceNumber); |
| 458 | return -ENODEV; |
| 459 | } |
| 460 | |
| 461 | if (intf->num_altsetting > 1) { |
| 462 | rc = usb_set_interface(udev, |
| 463 | intf->cur_altsetting->desc.bInterfaceNumber, |
| 464 | 0); |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 465 | if (rc < 0) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 466 | sms_err("usb_set_interface failed, rc %d", rc); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 467 | return rc; |
| 468 | } |
| 469 | } |
| 470 | |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 471 | sms_info("smsusb_probe %d", |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 472 | intf->cur_altsetting->desc.bInterfaceNumber); |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 473 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) { |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 474 | sms_info("endpoint %d %02x %02x %d", i, |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 475 | intf->cur_altsetting->endpoint[i].desc.bEndpointAddress, |
| 476 | intf->cur_altsetting->endpoint[i].desc.bmAttributes, |
| 477 | intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize); |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 478 | if (intf->cur_altsetting->endpoint[i].desc.bEndpointAddress & |
| 479 | USB_DIR_IN) |
| 480 | rc = usb_clear_halt(udev, usb_rcvbulkpipe(udev, |
| 481 | intf->cur_altsetting->endpoint[i].desc.bEndpointAddress)); |
| 482 | else |
| 483 | rc = usb_clear_halt(udev, usb_sndbulkpipe(udev, |
| 484 | intf->cur_altsetting->endpoint[i].desc.bEndpointAddress)); |
| 485 | } |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 486 | if ((udev->actconfig->desc.bNumInterfaces == 2) && |
| 487 | (intf->cur_altsetting->desc.bInterfaceNumber == 0)) { |
Michael Krufky | eb25094 | 2008-06-19 22:07:23 -0300 | [diff] [blame] | 488 | sms_err("rom interface 0 is not used"); |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 489 | return -ENODEV; |
| 490 | } |
| 491 | |
Mauro Carvalho Chehab | 347d8f1 | 2013-03-05 22:35:44 -0300 | [diff] [blame] | 492 | if (id->driver_info == SMS1XXX_BOARD_SIANO_STELLAR_ROM) { |
| 493 | sms_info("stellar device was found."); |
| 494 | snprintf(devpath, sizeof(devpath), "usb\\%d-%s", |
| 495 | udev->bus->busnum, udev->devpath); |
| 496 | sms_info("stellar device was found."); |
| 497 | return smsusb1_load_firmware( |
| 498 | udev, smscore_registry_getmode(devpath), |
| 499 | id->driver_info); |
| 500 | } |
| 501 | |
Michael Krufky | 1c11d54 | 2008-06-18 22:09:55 -0300 | [diff] [blame] | 502 | rc = smsusb_init_device(intf, id->driver_info); |
Michael Krufky | a0c0abc | 2008-06-19 20:35:21 -0300 | [diff] [blame] | 503 | sms_info("rc %d", rc); |
Michael Krufky | 05860f2 | 2008-08-31 17:39:58 -0300 | [diff] [blame] | 504 | sms_board_load_modules(id->driver_info); |
Michael Krufky | f17407a | 2008-06-14 00:43:26 -0300 | [diff] [blame] | 505 | return rc; |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 506 | } |
| 507 | |
Michael Krufky | 0c071f3 | 2008-06-21 02:44:02 -0300 | [diff] [blame] | 508 | static void smsusb_disconnect(struct usb_interface *intf) |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 509 | { |
| 510 | smsusb_term_device(intf); |
| 511 | } |
| 512 | |
Uri Shkolnik | 2f56c34 | 2008-11-22 14:08:46 -0300 | [diff] [blame] | 513 | static int smsusb_suspend(struct usb_interface *intf, pm_message_t msg) |
| 514 | { |
Joe Perches | 8350e15 | 2010-11-30 18:42:07 -0300 | [diff] [blame] | 515 | struct smsusb_device_t *dev = usb_get_intfdata(intf); |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 516 | printk(KERN_INFO "%s Entering status %d.\n", __func__, msg.event); |
| 517 | dev->state = SMSUSB_SUSPENDED; |
| 518 | /*smscore_set_power_mode(dev, SMS_POWER_MODE_SUSPENDED);*/ |
Uri Shkolnik | 2f56c34 | 2008-11-22 14:08:46 -0300 | [diff] [blame] | 519 | smsusb_stop_streaming(dev); |
| 520 | return 0; |
| 521 | } |
| 522 | |
| 523 | static int smsusb_resume(struct usb_interface *intf) |
| 524 | { |
| 525 | int rc, i; |
Joe Perches | 8350e15 | 2010-11-30 18:42:07 -0300 | [diff] [blame] | 526 | struct smsusb_device_t *dev = usb_get_intfdata(intf); |
Uri Shkolnik | 2f56c34 | 2008-11-22 14:08:46 -0300 | [diff] [blame] | 527 | struct usb_device *udev = interface_to_usbdev(intf); |
| 528 | |
Mauro Carvalho Chehab | 05f0ffb | 2013-03-06 09:53:50 -0300 | [diff] [blame] | 529 | printk(KERN_INFO "%s Entering.\n", __func__); |
| 530 | usb_clear_halt(udev, usb_rcvbulkpipe(udev, dev->in_ep)); |
| 531 | usb_clear_halt(udev, usb_sndbulkpipe(udev, dev->out_ep)); |
Uri Shkolnik | 2f56c34 | 2008-11-22 14:08:46 -0300 | [diff] [blame] | 532 | |
| 533 | for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) |
| 534 | printk(KERN_INFO "endpoint %d %02x %02x %d\n", i, |
| 535 | intf->cur_altsetting->endpoint[i].desc.bEndpointAddress, |
| 536 | intf->cur_altsetting->endpoint[i].desc.bmAttributes, |
| 537 | intf->cur_altsetting->endpoint[i].desc.wMaxPacketSize); |
| 538 | |
| 539 | if (intf->num_altsetting > 0) { |
| 540 | rc = usb_set_interface(udev, |
| 541 | intf->cur_altsetting->desc. |
| 542 | bInterfaceNumber, 0); |
| 543 | if (rc < 0) { |
Michael Krufky | b9391f4 | 2008-08-31 16:08:15 -0300 | [diff] [blame] | 544 | printk(KERN_INFO "%s usb_set_interface failed, " |
| 545 | "rc %d\n", __func__, rc); |
Uri Shkolnik | 2f56c34 | 2008-11-22 14:08:46 -0300 | [diff] [blame] | 546 | return rc; |
| 547 | } |
| 548 | } |
| 549 | |
| 550 | smsusb_start_streaming(dev); |
| 551 | return 0; |
| 552 | } |
| 553 | |
Greg Kroah-Hartman | d04dbd1 | 2012-08-17 17:48:26 -0700 | [diff] [blame] | 554 | static const struct usb_device_id smsusb_id_table[] = { |
Michael Krufky | 841a3f0 | 2008-08-31 17:03:15 -0300 | [diff] [blame] | 555 | { USB_DEVICE(0x187f, 0x0010), |
| 556 | .driver_info = SMS1XXX_BOARD_SIANO_STELLAR }, |
| 557 | { USB_DEVICE(0x187f, 0x0100), |
| 558 | .driver_info = SMS1XXX_BOARD_SIANO_STELLAR }, |
| 559 | { USB_DEVICE(0x187f, 0x0200), |
| 560 | .driver_info = SMS1XXX_BOARD_SIANO_NOVA_A }, |
| 561 | { USB_DEVICE(0x187f, 0x0201), |
| 562 | .driver_info = SMS1XXX_BOARD_SIANO_NOVA_B }, |
| 563 | { USB_DEVICE(0x187f, 0x0300), |
| 564 | .driver_info = SMS1XXX_BOARD_SIANO_VEGA }, |
Michael Krufky | 841a3f0 | 2008-08-31 17:03:15 -0300 | [diff] [blame] | 565 | { USB_DEVICE(0x2040, 0x1700), |
| 566 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_CATAMOUNT }, |
| 567 | { USB_DEVICE(0x2040, 0x1800), |
| 568 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_A }, |
| 569 | { USB_DEVICE(0x2040, 0x1801), |
| 570 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_OKEMO_B }, |
| 571 | { USB_DEVICE(0x2040, 0x2000), |
| 572 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD }, |
| 573 | { USB_DEVICE(0x2040, 0x2009), |
| 574 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD_R2 }, |
| 575 | { USB_DEVICE(0x2040, 0x200a), |
| 576 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD }, |
| 577 | { USB_DEVICE(0x2040, 0x2010), |
| 578 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD }, |
| 579 | { USB_DEVICE(0x2040, 0x2011), |
| 580 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD }, |
| 581 | { USB_DEVICE(0x2040, 0x2019), |
| 582 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_TIGER_MINICARD }, |
| 583 | { USB_DEVICE(0x2040, 0x5500), |
| 584 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
| 585 | { USB_DEVICE(0x2040, 0x5510), |
| 586 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
| 587 | { USB_DEVICE(0x2040, 0x5520), |
| 588 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
| 589 | { USB_DEVICE(0x2040, 0x5530), |
| 590 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
| 591 | { USB_DEVICE(0x2040, 0x5580), |
| 592 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
| 593 | { USB_DEVICE(0x2040, 0x5590), |
| 594 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
Uri Shkolnik | d0b66180 | 2009-05-19 09:51:41 -0300 | [diff] [blame] | 595 | { USB_DEVICE(0x187f, 0x0202), |
| 596 | .driver_info = SMS1XXX_BOARD_SIANO_NICE }, |
| 597 | { USB_DEVICE(0x187f, 0x0301), |
| 598 | .driver_info = SMS1XXX_BOARD_SIANO_VENICE }, |
Michael Krufky | 78c948a | 2009-10-21 18:27:29 -0300 | [diff] [blame] | 599 | { USB_DEVICE(0x2040, 0xb900), |
| 600 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
| 601 | { USB_DEVICE(0x2040, 0xb910), |
| 602 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
Michael Krufky | 20d15a2 | 2009-11-30 18:22:10 -0300 | [diff] [blame] | 603 | { USB_DEVICE(0x2040, 0xb980), |
| 604 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
| 605 | { USB_DEVICE(0x2040, 0xb990), |
| 606 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
Michael Krufky | 78c948a | 2009-10-21 18:27:29 -0300 | [diff] [blame] | 607 | { USB_DEVICE(0x2040, 0xc000), |
| 608 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
Michael Krufky | 20d15a2 | 2009-11-30 18:22:10 -0300 | [diff] [blame] | 609 | { USB_DEVICE(0x2040, 0xc010), |
| 610 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
| 611 | { USB_DEVICE(0x2040, 0xc080), |
| 612 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
| 613 | { USB_DEVICE(0x2040, 0xc090), |
| 614 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
Michael Krufky | 4d1b58b | 2012-03-22 13:55:05 -0300 | [diff] [blame] | 615 | { USB_DEVICE(0x2040, 0xc0a0), |
| 616 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
Michael Krufky | 3e1141e | 2012-05-25 09:29:12 -0300 | [diff] [blame] | 617 | { USB_DEVICE(0x2040, 0xf5a0), |
| 618 | .driver_info = SMS1XXX_BOARD_HAUPPAUGE_WINDHAM }, |
Mauro Carvalho Chehab | 347d8f1 | 2013-03-05 22:35:44 -0300 | [diff] [blame] | 619 | { USB_DEVICE(0x187f, 0x0202), |
| 620 | .driver_info = SMS1XXX_BOARD_SIANO_NICE }, |
| 621 | { USB_DEVICE(0x187f, 0x0301), |
| 622 | .driver_info = SMS1XXX_BOARD_SIANO_VENICE }, |
| 623 | { USB_DEVICE(0x187f, 0x0302), |
| 624 | .driver_info = SMS1XXX_BOARD_SIANO_VENICE }, |
| 625 | { USB_DEVICE(0x187f, 0x0310), |
| 626 | .driver_info = SMS1XXX_BOARD_SIANO_MING }, |
| 627 | { USB_DEVICE(0x187f, 0x0500), |
| 628 | .driver_info = SMS1XXX_BOARD_SIANO_PELE }, |
| 629 | { USB_DEVICE(0x187f, 0x0600), |
| 630 | .driver_info = SMS1XXX_BOARD_SIANO_RIO }, |
| 631 | { USB_DEVICE(0x187f, 0x0700), |
| 632 | .driver_info = SMS1XXX_BOARD_SIANO_DENVER_2160 }, |
| 633 | { USB_DEVICE(0x187f, 0x0800), |
| 634 | .driver_info = SMS1XXX_BOARD_SIANO_DENVER_1530 }, |
| 635 | { USB_DEVICE(0x19D2, 0x0086), |
| 636 | .driver_info = SMS1XXX_BOARD_ZTE_DVB_DATA_CARD }, |
| 637 | { USB_DEVICE(0x19D2, 0x0078), |
| 638 | .driver_info = SMS1XXX_BOARD_ONDA_MDTV_DATA_CARD }, |
Uri Shkolnik | d0b66180 | 2009-05-19 09:51:41 -0300 | [diff] [blame] | 639 | { } /* Terminating entry */ |
| 640 | }; |
| 641 | |
Michael Krufky | 841a3f0 | 2008-08-31 17:03:15 -0300 | [diff] [blame] | 642 | MODULE_DEVICE_TABLE(usb, smsusb_id_table); |
| 643 | |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 644 | static struct usb_driver smsusb_driver = { |
Uri Shkolnik | dba843a | 2008-08-31 00:44:04 -0300 | [diff] [blame] | 645 | .name = "smsusb", |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 646 | .probe = smsusb_probe, |
Michael Krufky | 8223741 | 2008-06-15 15:14:13 -0300 | [diff] [blame] | 647 | .disconnect = smsusb_disconnect, |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 648 | .id_table = smsusb_id_table, |
Uri Shkolnik | 2f56c34 | 2008-11-22 14:08:46 -0300 | [diff] [blame] | 649 | |
| 650 | .suspend = smsusb_suspend, |
| 651 | .resume = smsusb_resume, |
Michael Krufky | 2e5c1ec8 | 2008-05-19 18:56:13 -0300 | [diff] [blame] | 652 | }; |
| 653 | |
Greg Kroah-Hartman | ecb3b2b | 2011-11-18 09:46:12 -0800 | [diff] [blame] | 654 | module_usb_driver(smsusb_driver); |
Uri Shkolnik | e0f14c2 | 2008-08-31 00:44:04 -0300 | [diff] [blame] | 655 | |
Uri Shkolnik | 05a07376 | 2009-05-17 09:17:51 -0300 | [diff] [blame] | 656 | MODULE_DESCRIPTION("Driver for the Siano SMS1xxx USB dongle"); |
Uri Shkolnik | e0f14c2 | 2008-08-31 00:44:04 -0300 | [diff] [blame] | 657 | MODULE_AUTHOR("Siano Mobile Silicon, INC. (uris@siano-ms.com)"); |
| 658 | MODULE_LICENSE("GPL"); |