LMS 2012
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
d_usbhost.c
Go to the documentation of this file.
1 /*
2  * LEGO® MINDSTORMS EV3
3  *
4  * Copyright (C) 2010-2013 The LEGO Group
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19  */
20 
21 
29 #ifndef PCASM
30 #include <asm/types.h>
31 #endif
32 
33 #include "../../lms2012/source/lms2012.h"
34 #include "../../lms2012/source/am1808.h"
35 
36 
37 #define MODULE_NAME "usbhost_module"
38 #define DEVICE1_NAME USBHOST_DEVICE
39 
40 static int ModuleInit(void);
41 static void ModuleExit(void);
42 
43 #define __USE_POSIX
44 
45 #include <linux/kernel.h>
46 #include <linux/fs.h>
47 
48 #include <linux/sched.h>
49 
50 
51 #ifndef PCASM
52 #include <linux/hrtimer.h>
53 
54 #include <linux/mm.h>
55 #include <linux/hrtimer.h>
56 
57 #include <linux/init.h>
58 #include <linux/uaccess.h>
59 #include <linux/debugfs.h>
60 
61 #include <linux/ioport.h>
62 #include <asm/gpio.h>
63 #include <asm/io.h>
64 #include <linux/module.h>
65 #include <linux/miscdevice.h>
66 #include <asm/uaccess.h>
67 
68 MODULE_LICENSE("GPL");
69 MODULE_AUTHOR("The LEGO Group");
72 
73 module_init(ModuleInit);
74 module_exit(ModuleExit);
75 
76 #else
77 // Keep Eclipse happy
78 #endif
79 
80 
81 // DEVICE1 ********************************************************************
82 
83 
84 static ssize_t Device1Write(struct file *File,const char *Buffer,size_t Count,loff_t *Data)
85 {
86  int Lng = 0;
87 
88  Lng = Count;
89 
90  return (Lng);
91 }
92 
93 
94 static ssize_t Device1Read(struct file *File,char *Buffer,size_t Count,loff_t *Offset)
95 {
96  int Lng = 0;
97 
98  Lng = snprintf(Buffer,Count,"%s\r",DEVICE1_NAME);
99 
100  return (Lng);
101 }
102 
103 
104 static const struct file_operations Device1Entries =
105 {
106  .owner = THIS_MODULE,
107  .read = Device1Read,
108  .write = Device1Write
109 };
110 
111 
112 static struct miscdevice Device1 =
113 {
114  MISC_DYNAMIC_MINOR,
115  DEVICE1_NAME,
116  &Device1Entries
117 };
118 
119 
120 static int Device1Init(void)
121 {
122  int Result = -1;
123 
124  Result = misc_register(&Device1);
125  if (Result)
126  {
127  printk(" %s device register failed\n",DEVICE1_NAME);
128  }
129  else
130  {
131 #ifdef DEBUG
132  printk(" %s device register succes\n",DEVICE1_NAME);
133 #endif
134  }
135 
136  return (Result);
137 }
138 
139 
140 static void Device1Exit(void)
141 {
142  misc_deregister(&Device1);
143 #ifdef DEBUG
144  printk(" %s device unregistered\n",DEVICE1_NAME);
145 #endif
146 }
147 
148 
149 // MODULE *********************************************************************
150 
151 
152 static int ModuleInit(void)
153 {
154 #ifdef DEBUG
155  printk("%s init started\n",MODULE_NAME);
156 #endif
157 
158  Device1Init();
159 
160  return (0);
161 }
162 
163 
164 static void ModuleExit(void)
165 {
166 #ifdef DEBUG
167  printk("%s exit started\n",MODULE_NAME);
168 #endif
169 
170  Device1Exit();
171 
172 }
#define DEVICE1_NAME
Definition: d_usbhost.c:38
#define snprintf
Definition: c_input.c:141
#define MODULE_NAME
Definition: d_usbhost.c:37
module_init(ModuleInit)
MODULE_LICENSE("GPL")
MODULE_SUPPORTED_DEVICE(DEVICE1_NAME)
module_exit(ModuleExit)
MODULE_AUTHOR("The LEGO Group")
char Buffer[1024]
Definition: c_wifi.c:102
MODULE_DESCRIPTION(MODULE_NAME)