aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/usb/gadget
diff options
context:
space:
mode:
authorAndrzej Pietrasiewicz <andrzej.p@samsung.com>2015-03-03 04:52:29 -0500
committerFelipe Balbi <balbi@ti.com>2015-03-10 16:33:40 -0400
commit69504f808d6770940f1404b6f6f43c50cfe0be72 (patch)
tree1f78deeda95133f3bc3880d63293fe86f2e55697 /drivers/usb/gadget
parentb26394bd567e5ebe57ec4dee7fe6cd14023c96e9 (diff)
usb: gadget: printer: convert to new interface of f_printer
The goal is to remove the old function interface, so its (only) user must be converted to the new interface. Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@samsung.com> Signed-off-by: Felipe Balbi <balbi@ti.com>
Diffstat (limited to 'drivers/usb/gadget')
-rw-r--r--drivers/usb/gadget/legacy/Kconfig1
-rw-r--r--drivers/usb/gadget/legacy/printer.c50
2 files changed, 37 insertions, 14 deletions
diff --git a/drivers/usb/gadget/legacy/Kconfig b/drivers/usb/gadget/legacy/Kconfig
index 113c87e22117..d5a7102de696 100644
--- a/drivers/usb/gadget/legacy/Kconfig
+++ b/drivers/usb/gadget/legacy/Kconfig
@@ -301,6 +301,7 @@ config USB_MIDI_GADGET
301config USB_G_PRINTER 301config USB_G_PRINTER
302 tristate "Printer Gadget" 302 tristate "Printer Gadget"
303 select USB_LIBCOMPOSITE 303 select USB_LIBCOMPOSITE
304 select USB_F_PRINTER
304 help 305 help
305 The Printer Gadget channels data between the USB host and a 306 The Printer Gadget channels data between the USB host and a
306 userspace program driving the print engine. The user space 307 userspace program driving the print engine. The user space
diff --git a/drivers/usb/gadget/legacy/printer.c b/drivers/usb/gadget/legacy/printer.c
index 770b5041323e..a8050f8cbe11 100644
--- a/drivers/usb/gadget/legacy/printer.c
+++ b/drivers/usb/gadget/legacy/printer.c
@@ -29,12 +29,7 @@ USB_GADGET_COMPOSITE_OPTIONS();
29static const char shortname [] = "printer"; 29static const char shortname [] = "printer";
30static const char driver_desc [] = DRIVER_DESC; 30static const char driver_desc [] = DRIVER_DESC;
31 31
32/* 32#include "u_printer.h"
33 * This will be changed when f_printer is converted
34 * to the new function interface.
35 */
36#define USBF_PRINTER_INCLUDED
37#include "f_printer.c"
38 33
39/*-------------------------------------------------------------------------*/ 34/*-------------------------------------------------------------------------*/
40 35
@@ -65,6 +60,9 @@ module_param(qlen, uint, S_IRUGO|S_IWUSR);
65 60
66#define QLEN qlen 61#define QLEN qlen
67 62
63static struct usb_function_instance *fi_printer;
64static struct usb_function *f_printer;
65
68/*-------------------------------------------------------------------------*/ 66/*-------------------------------------------------------------------------*/
69 67
70/* 68/*
@@ -131,6 +129,7 @@ static struct usb_configuration printer_cfg_driver = {
131static int __init printer_do_config(struct usb_configuration *c) 129static int __init printer_do_config(struct usb_configuration *c)
132{ 130{
133 struct usb_gadget *gadget = c->cdev->gadget; 131 struct usb_gadget *gadget = c->cdev->gadget;
132 int status = 0;
134 133
135 usb_ep_autoconfig_reset(gadget); 134 usb_ep_autoconfig_reset(gadget);
136 135
@@ -142,20 +141,41 @@ static int __init printer_do_config(struct usb_configuration *c)
142 printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP; 141 printer_cfg_driver.bmAttributes |= USB_CONFIG_ATT_WAKEUP;
143 } 142 }
144 143
145 return f_printer_bind_config(c, iPNPstring, pnp_string, QLEN, 0); 144 f_printer = usb_get_function(fi_printer);
145 if (IS_ERR(f_printer))
146 return PTR_ERR(f_printer);
147
148 status = usb_add_function(c, f_printer);
149 if (status < 0)
150 usb_put_function(f_printer);
151
152 return status;
146} 153}
147 154
148static int __init printer_bind(struct usb_composite_dev *cdev) 155static int __init printer_bind(struct usb_composite_dev *cdev)
149{ 156{
150 int ret; 157 struct f_printer_opts *opts;
158 int ret, len;
151 159
152 ret = gprinter_setup(PRINTER_MINORS); 160 fi_printer = usb_get_function_instance("printer");
153 if (ret) 161 if (IS_ERR(fi_printer))
154 return ret; 162 return PTR_ERR(fi_printer);
163
164 if (iPNPstring)
165 strlcpy(&pnp_string[2], iPNPstring, PNP_STRING_LEN - 2);
166
167 len = strlen(pnp_string);
168 pnp_string[0] = (len >> 8) & 0xFF;
169 pnp_string[1] = len & 0xFF;
170
171 opts = container_of(fi_printer, struct f_printer_opts, func_inst);
172 opts->minor = 0;
173 memcpy(opts->pnp_string, pnp_string, PNP_STRING_LEN);
174 opts->q_len = QLEN;
155 175
156 ret = usb_string_ids_tab(cdev, strings); 176 ret = usb_string_ids_tab(cdev, strings);
157 if (ret < 0) { 177 if (ret < 0) {
158 gprinter_cleanup(); 178 usb_put_function_instance(fi_printer);
159 return ret; 179 return ret;
160 } 180 }
161 device_desc.iManufacturer = strings[USB_GADGET_MANUFACTURER_IDX].id; 181 device_desc.iManufacturer = strings[USB_GADGET_MANUFACTURER_IDX].id;
@@ -164,7 +184,7 @@ static int __init printer_bind(struct usb_composite_dev *cdev)
164 184
165 ret = usb_add_config(cdev, &printer_cfg_driver, printer_do_config); 185 ret = usb_add_config(cdev, &printer_cfg_driver, printer_do_config);
166 if (ret) { 186 if (ret) {
167 gprinter_cleanup(); 187 usb_put_function_instance(fi_printer);
168 return ret; 188 return ret;
169 } 189 }
170 usb_composite_overwrite_options(cdev, &coverwrite); 190 usb_composite_overwrite_options(cdev, &coverwrite);
@@ -173,7 +193,9 @@ static int __init printer_bind(struct usb_composite_dev *cdev)
173 193
174static int __exit printer_unbind(struct usb_composite_dev *cdev) 194static int __exit printer_unbind(struct usb_composite_dev *cdev)
175{ 195{
176 gprinter_cleanup(); 196 usb_put_function(f_printer);
197 usb_put_function_instance(fi_printer);
198
177 return 0; 199 return 0;
178} 200}
179 201