Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: gadget: hid: convert to new interface of f_hid

Use the new f_hid interface in order for the old to be removed.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com>
Signed-off-by: Felipe Balbi <balbi@ti.com>

authored by

Andrzej Pietrasiewicz and committed by
Felipe Balbi
4bc8a33f cb382536

+56 -23
+1
drivers/usb/gadget/legacy/Kconfig
··· 420 420 config USB_G_HID 421 421 tristate "HID Gadget" 422 422 select USB_LIBCOMPOSITE 423 + select USB_F_HID 423 424 help 424 425 The HID gadget driver provides generic emulation of USB 425 426 Human Interface Devices (HID).
+55 -23
drivers/usb/gadget/legacy/hid.c
··· 17 17 #include <linux/list.h> 18 18 #include <linux/module.h> 19 19 #include <linux/usb/composite.h> 20 + #include <linux/usb/g_hid.h> 20 21 21 22 #include "gadget_chips.h" 22 23 #define DRIVER_DESC "HID Gadget" 23 24 #define DRIVER_VERSION "2010/03/16" 25 + 26 + #include "u_hid.h" 24 27 25 28 /*-------------------------------------------------------------------------*/ 26 29 ··· 32 29 33 30 /*-------------------------------------------------------------------------*/ 34 31 35 - /* 36 - * kbuild is not very cooperative with respect to linking separately 37 - * compiled library objects into one module. So for now we won't use 38 - * separate compilation ... ensuring init/exit sections work to shrink 39 - * the runtime footprint, and giving us at least some parts of what 40 - * a "gcc --combine ... part1.c part2.c part3.c ... " build would. 41 - */ 42 - #define USBF_HID_INCLUDED 43 - #include "f_hid.c" 44 - 45 - 46 32 struct hidg_func_node { 33 + struct usb_function_instance *fi; 34 + struct usb_function *f; 47 35 struct list_head node; 48 36 struct hidg_func_descriptor *func; 49 37 }; ··· 108 114 109 115 static int __init do_config(struct usb_configuration *c) 110 116 { 111 - struct hidg_func_node *e; 112 - int func = 0, status = 0; 117 + struct hidg_func_node *e, *n; 118 + int status = 0; 113 119 114 120 if (gadget_is_otg(c->cdev->gadget)) { 115 121 c->descriptors = otg_desc; ··· 117 123 } 118 124 119 125 list_for_each_entry(e, &hidg_func_list, node) { 120 - status = hidg_bind_config(c, e->func, func++); 121 - if (status) 122 - break; 126 + e->f = usb_get_function(e->fi); 127 + if (IS_ERR(e->f)) 128 + goto put; 129 + status = usb_add_function(c, e->f); 130 + if (status < 0) { 131 + usb_put_function(e->f); 132 + goto put; 133 + } 123 134 } 124 135 136 + return 0; 137 + put: 138 + list_for_each_entry(n, &hidg_func_list, node) { 139 + if (n == e) 140 + break; 141 + usb_remove_function(c, n->f); 142 + usb_put_function(n->f); 143 + } 125 144 return status; 126 145 } 127 146 ··· 151 144 { 152 145 struct usb_gadget *gadget = cdev->gadget; 153 146 struct list_head *tmp; 147 + struct hidg_func_node *n, *m; 148 + struct f_hid_opts *hid_opts; 154 149 int status, funcs = 0; 155 150 156 151 list_for_each(tmp, &hidg_func_list) ··· 161 152 if (!funcs) 162 153 return -ENODEV; 163 154 164 - /* set up HID */ 165 - status = ghid_setup(cdev->gadget, funcs); 166 - if (status < 0) 167 - return status; 155 + list_for_each_entry(n, &hidg_func_list, node) { 156 + n->fi = usb_get_function_instance("hid"); 157 + if (IS_ERR(n->fi)) { 158 + status = PTR_ERR(n->fi); 159 + goto put; 160 + } 161 + hid_opts = container_of(n->fi, struct f_hid_opts, func_inst); 162 + hid_opts->subclass = n->func->subclass; 163 + hid_opts->protocol = n->func->protocol; 164 + hid_opts->report_length = n->func->report_length; 165 + hid_opts->report_desc_length = n->func->report_desc_length; 166 + hid_opts->report_desc = n->func->report_desc; 167 + } 168 + 168 169 169 170 /* Allocate string descriptor numbers ... note that string 170 171 * contents can be overridden by the composite_dev glue. ··· 182 163 183 164 status = usb_string_ids_tab(cdev, strings_dev); 184 165 if (status < 0) 185 - return status; 166 + goto put; 186 167 device_desc.iManufacturer = strings_dev[USB_GADGET_MANUFACTURER_IDX].id; 187 168 device_desc.iProduct = strings_dev[USB_GADGET_PRODUCT_IDX].id; 188 169 189 170 /* register our configuration */ 190 171 status = usb_add_config(cdev, &config_driver, do_config); 191 172 if (status < 0) 192 - return status; 173 + goto put; 193 174 194 175 usb_composite_overwrite_options(cdev, &coverwrite); 195 176 dev_info(&gadget->dev, DRIVER_DESC ", version: " DRIVER_VERSION "\n"); 196 177 197 178 return 0; 179 + 180 + put: 181 + list_for_each_entry(m, &hidg_func_list, node) { 182 + if (m == n) 183 + break; 184 + usb_put_function_instance(m->fi); 185 + } 186 + return status; 198 187 } 199 188 200 189 static int __exit hid_unbind(struct usb_composite_dev *cdev) 201 190 { 202 - ghid_cleanup(); 191 + struct hidg_func_node *n; 192 + 193 + list_for_each_entry(n, &hidg_func_list, node) { 194 + usb_put_function(n->f); 195 + usb_put_function_instance(n->fi); 196 + } 203 197 return 0; 204 198 } 205 199