40 #include <asm/types.h>
43 #include "../../lms2012/source/lms2012.h"
44 #include "../../lms2012/source/am1808.h"
47 #define MODULE_NAME "usbdev_module"
48 #define DEVICE1_NAME USBDEV_DEVICE
52 static int ModuleInit(
void);
53 static void ModuleExit(
void);
57 #include <linux/kernel.h>
60 #include <linux/sched.h>
64 #include <linux/hrtimer.h>
67 #include <linux/hrtimer.h>
69 #include <linux/init.h>
70 #include <linux/uaccess.h>
71 #include <linux/debugfs.h>
73 #include <linux/ioport.h>
76 #include <linux/module.h>
77 #include <linux/miscdevice.h>
78 #include <asm/uaccess.h>
79 #include <linux/hid.h>
80 #include <linux/utsname.h>
81 #include <linux/device.h>
84 #include <../drivers/usb/gadget/gadget_chips.h>
85 #include <../drivers/usb/gadget/usbstring.c>
86 #include <../drivers/usb/gadget/config.c>
87 #include <../drivers/usb/gadget/epautoconf.c>
100 #include <../drivers/usb/gadget/g_zero.h>
101 #define MAX_EP_SIZE 1024
102 #define MAX_FULLSPEED_EP_SIZE 64
111 #define SHM_LENGTH (sizeof(UsbSpeedDefault))
112 #define NPAGES ((SHM_LENGTH + PAGE_SIZE - 1) / PAGE_SIZE)
113 static void *kmalloc_ptr;
133 #define DRIVER_VERSION "31jan2011->"
141 static int loopdefault = 0;
148 #define DRIVER_VENDOR_NUM 0x0694 // LEGO Group
149 #define DRIVER_PRODUCT_NUM 0x0005 // No. 5 in a row
150 #define DEFAULT_AUTORESUME 0
168 static struct usb_device_descriptor device_desc = {
169 .bLength =
sizeof device_desc,
170 .bDescriptorType = USB_DT_DEVICE,
172 .bcdUSB = cpu_to_le16(0x0200),
174 .bDeviceSubClass = 0,
175 .bDeviceProtocol = 0,
180 .bNumConfigurations = 1,
183 #ifdef CONFIG_USB_OTG
184 struct usb_otg_descriptor otg_descriptor = {
185 .bLength =
sizeof otg_descriptor,
186 .bDescriptorType = USB_DT_OTG,
191 .bmAttributes = USB_OTG_SRP | USB_OTG_HNP,
194 const struct usb_descriptor_header *otg_desc[] = {
195 (
struct usb_descriptor_header *) &otg_descriptor,
202 #define STRING_MANUFACTURER_IDX 0
203 #define STRING_PRODUCT_IDX 1
204 #define STRING_SERIAL_IDX 2
206 static char manufacturer[] =
"LEGO Group";
207 static char serial[] =
"123456789ABC ";
208 static char longname[] =
"EV3 brick ";
210 static struct usb_string strings_dev[3] = {
217 static struct usb_gadget_strings stringtab_dev = {
219 .strings = strings_dev,
222 static struct usb_gadget_strings *dev_strings[] = {
231 struct usb_request *req;
233 req = usb_ep_alloc_request(ep, GFP_ATOMIC);
236 req->buf = kmalloc(
buflen, GFP_ATOMIC);
238 usb_ep_free_request(ep, req);
248 usb_ep_free_request(ep, req);
251 static void disable_ep(
struct usb_composite_dev *cdev,
struct usb_ep *ep)
255 if (ep->driver_data) {
256 value = usb_ep_disable(ep);
258 DBG(cdev,
"disable %s --> %d\n",
260 ep->driver_data =
NULL;
265 struct usb_ep *in,
struct usb_ep *out)
267 disable_ep(cdev, in);
268 disable_ep(cdev, out);
273 static struct timer_list autoresume_timer;
275 static void zero_autoresume(
unsigned long _c)
277 struct usb_composite_dev *cdev = (
void *)_c;
278 struct usb_gadget *g = cdev->gadget;
283 printk(
"zero_autoresume\n\r");
294 if (g->speed != USB_SPEED_UNKNOWN) {
295 int status = usb_gadget_wakeup(g);
296 INFO(cdev,
"%s --> %d\n", __func__, status);
300 static void zero_suspend(
struct usb_composite_dev *cdev)
305 printk(
"zero_suspend\n\r");
308 if (cdev->gadget->speed == USB_SPEED_UNKNOWN)
312 mod_timer(&autoresume_timer, jiffies + (HZ *
autoresume));
313 DBG(cdev,
"suspend, wakeup in %d seconds\n",
autoresume);
315 DBG(cdev,
"%s\n", __func__);
318 static void zero_resume(
struct usb_composite_dev *cdev)
320 DBG(cdev,
"%s\n", __func__);
325 printk(
"zero_resume\n\r");
328 del_timer(&autoresume_timer);
333 static int zero_bind(
struct usb_composite_dev *cdev)
336 struct usb_gadget *gadget = cdev->gadget;
347 device_desc.iManufacturer = id;
355 device_desc.iProduct = id;
363 device_desc.iSerialNumber = id;
365 setup_timer(&autoresume_timer, zero_autoresume, (
unsigned long) cdev);
369 gcnum = usb_gadget_controller_number(gadget);
371 device_desc.bcdDevice = cpu_to_le16(0x0200 + gcnum);
380 pr_warning(
"%s: controller '%s' not recognized\n",
381 longname, gadget->name);
382 device_desc.bcdDevice = cpu_to_le16(0x9999);
387 static int zero_unbind(
struct usb_composite_dev *cdev)
392 printk(
"zero_unbind\n\r");
395 del_timer_sync(&autoresume_timer);
399 static struct usb_composite_driver zero_driver = {
402 .strings = dev_strings,
404 .unbind = zero_unbind,
405 .suspend = zero_suspend,
406 .resume = zero_resume,
409 static int dUsbInit(
void)
414 printk(
"dUsbInit\n\r");
418 (*pUsbSpeed).Speed = FULL_SPEED;
423 static void dUsbExit(
void)
430 static ssize_t Device1Write(
struct file *File,
const char *
Buffer,
size_t Count,loff_t *Data)
444 BytesWritten = Count;
462 printk(
"DATA_PENDING SECOND time and reset!! in Device1Write\n\r");
471 printk(
"USB_DATA_READY in Device1Write\n\r");
485 printk(
"DATA_PENDING in Device1Write\n\r");
493 printk(
"usbdev %d written\n\r", BytesWritten);
496 return (BytesWritten);
499 static ssize_t Device1Read(
struct file *File,
char *Buffer,
size_t Count,loff_t *Offset)
509 printk(
"Some bytes to READ?\n\r");
519 static int Device1Mmap(
struct file *filp,
struct vm_area_struct *vma)
523 ret = remap_pfn_range(vma,vma->vm_start,virt_to_phys((
void*)((
unsigned long)
pUsbSpeed)) >> PAGE_SHIFT,vma->vm_end-vma->vm_start,PAGE_SHARED);
532 static const struct file_operations Device1Entries =
534 .owner = THIS_MODULE,
536 .write = Device1Write,
541 static struct miscdevice Device1 =
549 static int Device1Init(
void)
555 Result = misc_register(&Device1);
574 if ((kmalloc_ptr = kmalloc((
NPAGES + 2) * PAGE_SIZE, GFP_KERNEL)) !=
NULL)
577 pTemp = (
UWORD*)((((
unsigned long)kmalloc_ptr) + PAGE_SIZE - 1) & PAGE_MASK);
579 for (i = 0; i <
NPAGES * PAGE_SIZE; i += PAGE_SIZE)
581 SetPageReserved(virt_to_page(((
unsigned long)pTemp) + i));
593 static void Device1Exit(
void)
602 for (i = 0; i <
NPAGES * PAGE_SIZE; i+= PAGE_SIZE)
604 ClearPageReserved(virt_to_page(((
unsigned long)pTemp) + i));
615 misc_deregister(&Device1);
633 static int ModuleInit(
void)
645 printk(
"This is DEFAULT NAME: %s\n\r", longname);
651 printk(
"\n\rThis is the HostStr: %s\n\r", HostStr);
654 strcpy(longname, HostStr);
659 printk(
"\n\rThis is the INSMODed NAME: %s\n\r", longname);
665 printk(
"\n\rThis is the DEFAULT SerialNumber: %s\n\r", serial);
671 printk(
"\n\rThis is the SerialStr: %s\n\r", SerialStr);
674 strcpy(serial, SerialStr);
679 printk(
"\n\rThis is the INSMODed SerialNumber (BT mac): %s\n\r", serial);
687 static void ModuleExit(
void)
int usb_string_id(struct usb_composite_dev *cdev)
MODULE_PARM_DESC(autoresume,"zero, or seconds before remote wakeup")
char usb_full_buffer_out[MAX_FULLSPEED_EP_SIZE]
#define DRIVER_VENDOR_NUM
struct usb_request * save_in_req
#define STRING_MANUFACTURER_IDX
MODULE_AUTHOR("The LEGO Group")
#define STRING_SERIAL_IDX
struct usb_ep * save_in_ep
int rudolf_add(struct usb_composite_dev *cdev, bool autoresume)
module_param(buflen, uint, 0)
int usb_composite_register(struct usb_composite_driver *driver)
MODULE_DESCRIPTION(MODULE_NAME)
void usb_composite_unregister(struct usb_composite_driver *driver)
void disable_endpoints(struct usb_composite_dev *cdev, struct usb_ep *in, struct usb_ep *out)
void free_ep_req(struct usb_ep *ep, struct usb_request *req)
struct usb_request * alloc_ep_req(struct usb_ep *ep)
#define DEFAULT_AUTORESUME
#define STRING_PRODUCT_IDX
MODULE_SUPPORTED_DEVICE(DEVICE1_NAME)
unsigned short UWORD
Basic Type used to symbolise 16 bit unsigned values.
#define DRIVER_PRODUCT_NUM
char usb_full_buffer_in[MAX_FULLSPEED_EP_SIZE]
char usb_char_buffer_out[MAX_EP_SIZE]
char usb_char_buffer_in[MAX_EP_SIZE]
#define MAX_FULLSPEED_EP_SIZE