#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/ioport.h>
#include <linux/sched.h>
#include <linux/slab.h>
#include <linux/mutex.h>
#include <linux/errno.h>
#include <linux/init.h>
#include <linux/idr.h>
#include <linux/timer.h>
#include <linux/list.h>
#include <linux/interrupt.h>
#include <linux/device.h>
#include <linux/moduleparam.h>
#include <linux/fs.h>
#include <linux/poll.h>
#include <linux/types.h>
#include <linux/ctype.h>
#include <linux/cdev.h>
#include <linux/kref.h>
#include <asm/byteorder.h>
#include <linux/io.h>
#include <linux/irq.h>
#include <linux/uaccess.h>
#include <linux/unaligned.h>
#include <linux/usb/ch9.h>
#include <linux/usb/composite.h>
#include <linux/usb/gadget.h>
#include <linux/usb/g_printer.h>
#include "u_printer.h"
#define PRINTER_MINORS …
#define GET_DEVICE_ID …
#define GET_PORT_STATUS …
#define SOFT_RESET …
#define DEFAULT_Q_LEN …
static int major, minors;
static const struct class usb_gadget_class = …;
static DEFINE_IDA(printer_ida);
static DEFINE_MUTEX(printer_ida_lock);
struct printer_dev { … };
static inline struct printer_dev *func_to_printer(struct usb_function *f)
{ … }
#define USB_DESC_BUFSIZE …
#define USB_BUFSIZE …
static struct usb_interface_descriptor intf_desc = …;
static struct usb_endpoint_descriptor fs_ep_in_desc = …;
static struct usb_endpoint_descriptor fs_ep_out_desc = …;
static struct usb_descriptor_header *fs_printer_function[] = …;
static struct usb_endpoint_descriptor hs_ep_in_desc = …;
static struct usb_endpoint_descriptor hs_ep_out_desc = …;
static struct usb_descriptor_header *hs_printer_function[] = …;
static struct usb_endpoint_descriptor ss_ep_in_desc = …;
static struct usb_ss_ep_comp_descriptor ss_ep_in_comp_desc = …;
static struct usb_endpoint_descriptor ss_ep_out_desc = …;
static struct usb_ss_ep_comp_descriptor ss_ep_out_comp_desc = …;
static struct usb_descriptor_header *ss_printer_function[] = …;
static inline struct usb_endpoint_descriptor *ep_desc(struct usb_gadget *gadget,
struct usb_endpoint_descriptor *fs,
struct usb_endpoint_descriptor *hs,
struct usb_endpoint_descriptor *ss)
{ … }
static void printer_dev_free(struct kref *kref)
{ … }
static struct usb_request *
printer_req_alloc(struct usb_ep *ep, unsigned len, gfp_t gfp_flags)
{ … }
static void
printer_req_free(struct usb_ep *ep, struct usb_request *req)
{ … }
static void rx_complete(struct usb_ep *ep, struct usb_request *req)
{ … }
static void tx_complete(struct usb_ep *ep, struct usb_request *req)
{ … }
static int
printer_open(struct inode *inode, struct file *fd)
{ … }
static int
printer_close(struct inode *inode, struct file *fd)
{ … }
static void
setup_rx_reqs(struct printer_dev *dev)
{ … }
static ssize_t
printer_read(struct file *fd, char __user *buf, size_t len, loff_t *ptr)
{ … }
static ssize_t
printer_write(struct file *fd, const char __user *buf, size_t len, loff_t *ptr)
{ … }
static int
printer_fsync(struct file *fd, loff_t start, loff_t end, int datasync)
{ … }
static __poll_t
printer_poll(struct file *fd, poll_table *wait)
{ … }
static long
printer_ioctl(struct file *fd, unsigned int code, unsigned long arg)
{ … }
static const struct file_operations printer_io_operations = …;
static int
set_printer_interface(struct printer_dev *dev)
{ … }
static void printer_reset_interface(struct printer_dev *dev)
{ … }
static int set_interface(struct printer_dev *dev, unsigned number)
{ … }
static void printer_soft_reset(struct printer_dev *dev)
{ … }
static bool gprinter_req_match(struct usb_function *f,
const struct usb_ctrlrequest *ctrl,
bool config0)
{ … }
static int printer_func_setup(struct usb_function *f,
const struct usb_ctrlrequest *ctrl)
{ … }
static int printer_func_bind(struct usb_configuration *c,
struct usb_function *f)
{ … }
static int printer_func_set_alt(struct usb_function *f,
unsigned intf, unsigned alt)
{ … }
static void printer_func_disable(struct usb_function *f)
{ … }
static inline struct f_printer_opts
*to_f_printer_opts(struct config_item *item)
{ … }
static void printer_attr_release(struct config_item *item)
{ … }
static struct configfs_item_operations printer_item_ops = …;
static ssize_t f_printer_opts_pnp_string_show(struct config_item *item,
char *page)
{ … }
static ssize_t f_printer_opts_pnp_string_store(struct config_item *item,
const char *page, size_t len)
{ … }
CONFIGFS_ATTR(…);
static ssize_t f_printer_opts_q_len_show(struct config_item *item,
char *page)
{ … }
static ssize_t f_printer_opts_q_len_store(struct config_item *item,
const char *page, size_t len)
{ … }
CONFIGFS_ATTR(…);
static struct configfs_attribute *printer_attrs[] = …;
static const struct config_item_type printer_func_type = …;
static inline int gprinter_get_minor(void)
{ … }
static inline void gprinter_put_minor(int minor)
{ … }
static int gprinter_setup(int);
static void gprinter_cleanup(void);
static void gprinter_free_inst(struct usb_function_instance *f)
{ … }
static struct usb_function_instance *gprinter_alloc_inst(void)
{ … }
static void gprinter_free(struct usb_function *f)
{ … }
static void printer_func_unbind(struct usb_configuration *c,
struct usb_function *f)
{ … }
static struct usb_function *gprinter_alloc(struct usb_function_instance *fi)
{ … }
DECLARE_USB_FUNCTION_INIT(printer, gprinter_alloc_inst, gprinter_alloc);
MODULE_DESCRIPTION(…) …;
MODULE_LICENSE(…) …;
MODULE_AUTHOR(…) …;
static int gprinter_setup(int count)
{ … }
static void gprinter_cleanup(void)
{ … }