aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget/f_ncm.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/usb/gadget/f_ncm.c')
-rw-r--r--drivers/usb/gadget/f_ncm.c58
1 files changed, 19 insertions, 39 deletions
diff --git a/drivers/usb/gadget/f_ncm.c b/drivers/usb/gadget/f_ncm.c
index 86902a60bcdb..ae69ed7e6b99 100644
--- a/drivers/usb/gadget/f_ncm.c
+++ b/drivers/usb/gadget/f_ncm.c
@@ -48,12 +48,6 @@
48#define NCM_NDP_HDR_CRC 0x01000000 48#define NCM_NDP_HDR_CRC 0x01000000
49#define NCM_NDP_HDR_NOCRC 0x00000000 49#define NCM_NDP_HDR_NOCRC 0x00000000
50 50
51struct ncm_ep_descs {
52 struct usb_endpoint_descriptor *in;
53 struct usb_endpoint_descriptor *out;
54 struct usb_endpoint_descriptor *notify;
55};
56
57enum ncm_notify_state { 51enum ncm_notify_state {
58 NCM_NOTIFY_NONE, /* don't notify */ 52 NCM_NOTIFY_NONE, /* don't notify */
59 NCM_NOTIFY_CONNECT, /* issue CONNECT next */ 53 NCM_NOTIFY_CONNECT, /* issue CONNECT next */
@@ -66,11 +60,7 @@ struct f_ncm {
66 60
67 char ethaddr[14]; 61 char ethaddr[14];
68 62
69 struct ncm_ep_descs fs;
70 struct ncm_ep_descs hs;
71
72 struct usb_ep *notify; 63 struct usb_ep *notify;
73 struct usb_endpoint_descriptor *notify_desc;
74 struct usb_request *notify_req; 64 struct usb_request *notify_req;
75 u8 notify_state; 65 u8 notify_state;
76 bool is_open; 66 bool is_open;
@@ -802,13 +792,14 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
802 if (ncm->notify->driver_data) { 792 if (ncm->notify->driver_data) {
803 DBG(cdev, "reset ncm control %d\n", intf); 793 DBG(cdev, "reset ncm control %d\n", intf);
804 usb_ep_disable(ncm->notify); 794 usb_ep_disable(ncm->notify);
805 } else { 795 }
796
797 if (!(ncm->notify->desc)) {
806 DBG(cdev, "init ncm ctrl %d\n", intf); 798 DBG(cdev, "init ncm ctrl %d\n", intf);
807 ncm->notify_desc = ep_choose(cdev->gadget, 799 if (config_ep_by_speed(cdev->gadget, f, ncm->notify))
808 ncm->hs.notify, 800 goto fail;
809 ncm->fs.notify);
810 } 801 }
811 usb_ep_enable(ncm->notify, ncm->notify_desc); 802 usb_ep_enable(ncm->notify);
812 ncm->notify->driver_data = ncm; 803 ncm->notify->driver_data = ncm;
813 804
814 /* Data interface has two altsettings, 0 and 1 */ 805 /* Data interface has two altsettings, 0 and 1 */
@@ -829,14 +820,17 @@ static int ncm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)
829 if (alt == 1) { 820 if (alt == 1) {
830 struct net_device *net; 821 struct net_device *net;
831 822
832 if (!ncm->port.in) { 823 if (!ncm->port.in_ep->desc ||
824 !ncm->port.out_ep->desc) {
833 DBG(cdev, "init ncm\n"); 825 DBG(cdev, "init ncm\n");
834 ncm->port.in = ep_choose(cdev->gadget, 826 if (config_ep_by_speed(cdev->gadget, f,
835 ncm->hs.in, 827 ncm->port.in_ep) ||
836 ncm->fs.in); 828 config_ep_by_speed(cdev->gadget, f,
837 ncm->port.out = ep_choose(cdev->gadget, 829 ncm->port.out_ep)) {
838 ncm->hs.out, 830 ncm->port.in_ep->desc = NULL;
839 ncm->fs.out); 831 ncm->port.out_ep->desc = NULL;
832 goto fail;
833 }
840 } 834 }
841 835
842 /* TODO */ 836 /* TODO */
@@ -1111,7 +1105,7 @@ static void ncm_disable(struct usb_function *f)
1111 if (ncm->notify->driver_data) { 1105 if (ncm->notify->driver_data) {
1112 usb_ep_disable(ncm->notify); 1106 usb_ep_disable(ncm->notify);
1113 ncm->notify->driver_data = NULL; 1107 ncm->notify->driver_data = NULL;
1114 ncm->notify_desc = NULL; 1108 ncm->notify->desc = NULL;
1115 } 1109 }
1116} 1110}
1117 1111
@@ -1228,13 +1222,6 @@ ncm_bind(struct usb_configuration *c, struct usb_function *f)
1228 if (!f->descriptors) 1222 if (!f->descriptors)
1229 goto fail; 1223 goto fail;
1230 1224
1231 ncm->fs.in = usb_find_endpoint(ncm_fs_function,
1232 f->descriptors, &fs_ncm_in_desc);
1233 ncm->fs.out = usb_find_endpoint(ncm_fs_function,
1234 f->descriptors, &fs_ncm_out_desc);
1235 ncm->fs.notify = usb_find_endpoint(ncm_fs_function,
1236 f->descriptors, &fs_ncm_notify_desc);
1237
1238 /* 1225 /*
1239 * support all relevant hardware speeds... we expect that when 1226 * support all relevant hardware speeds... we expect that when
1240 * hardware is dual speed, all bulk-capable endpoints work at 1227 * hardware is dual speed, all bulk-capable endpoints work at
@@ -1252,13 +1239,6 @@ ncm_bind(struct usb_configuration *c, struct usb_function *f)
1252 f->hs_descriptors = usb_copy_descriptors(ncm_hs_function); 1239 f->hs_descriptors = usb_copy_descriptors(ncm_hs_function);
1253 if (!f->hs_descriptors) 1240 if (!f->hs_descriptors)
1254 goto fail; 1241 goto fail;
1255
1256 ncm->hs.in = usb_find_endpoint(ncm_hs_function,
1257 f->hs_descriptors, &hs_ncm_in_desc);
1258 ncm->hs.out = usb_find_endpoint(ncm_hs_function,
1259 f->hs_descriptors, &hs_ncm_out_desc);
1260 ncm->hs.notify = usb_find_endpoint(ncm_hs_function,
1261 f->hs_descriptors, &hs_ncm_notify_desc);
1262 } 1242 }
1263 1243
1264 /* 1244 /*
@@ -1288,9 +1268,9 @@ fail:
1288 /* we might as well release our claims on endpoints */ 1268 /* we might as well release our claims on endpoints */
1289 if (ncm->notify) 1269 if (ncm->notify)
1290 ncm->notify->driver_data = NULL; 1270 ncm->notify->driver_data = NULL;
1291 if (ncm->port.out) 1271 if (ncm->port.out_ep->desc)
1292 ncm->port.out_ep->driver_data = NULL; 1272 ncm->port.out_ep->driver_data = NULL;
1293 if (ncm->port.in) 1273 if (ncm->port.in_ep->desc)
1294 ncm->port.in_ep->driver_data = NULL; 1274 ncm->port.in_ep->driver_data = NULL;
1295 1275
1296 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status); 1276 ERROR(cdev, "%s: can't bind, err %d\n", f->name, status);