[rdc] sync kernel config
[15.05/openwrt.git] / target / linux / adm5120 / patches-2.6.25 / 902-usb_use_debugfs_instead_of_sysfs.patch
1 --- a/drivers/usb/host/adm5120.h
2 +++ b/drivers/usb/host/adm5120.h
3 @@ -431,6 +431,13 @@
4  #define        OHCI_QUIRK_BE_MMIO      0x10                    /* BE registers */
5  #define        OHCI_QUIRK_ZFMICRO      0x20                    /* Compaq ZFMicro chipset*/
6         // there are also chip quirks/bugs in init logic
7 +
8 +#ifdef DEBUG
9 +       struct dentry           *debug_dir;
10 +       struct dentry           *debug_async;
11 +       struct dentry           *debug_periodic;
12 +       struct dentry           *debug_registers;
13 +#endif
14  };
15  
16  /* convert between an hcd pointer and the corresponding ahcd_hcd */
17 --- a/drivers/usb/host/adm5120-hcd.c
18 +++ b/drivers/usb/host/adm5120-hcd.c
19 @@ -35,6 +35,7 @@
20  #include <linux/dma-mapping.h>
21  #include <linux/dmapool.h>
22  #include <linux/reboot.h>
23 +#include <linux/debugfs.h>
24  
25  #include <asm/io.h>
26  #include <asm/irq.h>
27 @@ -804,6 +805,14 @@
28         pr_info("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
29                 sizeof (struct ed), sizeof (struct td));
30  
31 +#ifdef DEBUG
32 +       admhc_debug_root = debugfs_create_dir("admhc", NULL);
33 +       if (!admhc_debug_root) {
34 +               ret = -ENOENT;
35 +               goto error_debug;
36 +       }
37 +#endif
38 +
39  #ifdef PLATFORM_DRIVER
40         ret = platform_driver_register(&PLATFORM_DRIVER);
41         if (ret < 0)
42 @@ -816,6 +825,12 @@
43         platform_driver_unregister(&PLATFORM_DRIVER);
44  error_platform:
45  #endif
46 +
47 +#ifdef DEBUG
48 +       debugfs_remove(admhc_debug_root);
49 +       admhc_debug_root = NULL;
50 +error_debug:
51 +#endif
52         return ret;
53  }
54  module_init(admhc_hcd_mod_init);
55 @@ -823,6 +838,9 @@
56  static void __exit admhc_hcd_mod_exit(void)
57  {
58         platform_driver_unregister(&PLATFORM_DRIVER);
59 +#ifdef DEBUG
60 +       debugfs_remove(admhc_debug_root);
61 +#endif
62  }
63  module_exit(admhc_hcd_mod_exit);
64  
65 --- a/drivers/usb/host/adm5120-dbg.c
66 +++ b/drivers/usb/host/adm5120-dbg.c
67 @@ -390,6 +390,42 @@
68  
69  #else
70  
71 +static int debug_async_open(struct inode *, struct file *);
72 +static int debug_periodic_open(struct inode *, struct file *);
73 +static int debug_registers_open(struct inode *, struct file *);
74 +static int debug_async_open(struct inode *, struct file *);
75 +static ssize_t debug_output(struct file*, char __user*, size_t, loff_t*);
76 +static int debug_close(struct inode *, struct file *);
77 +
78 +static const struct file_operations debug_async_fops = {
79 +       .owner          = THIS_MODULE,
80 +       .open           = debug_async_open,
81 +       .read           = debug_output,
82 +       .release        = debug_close,
83 +};
84 +static const struct file_operations debug_periodic_fops = {
85 +       .owner          = THIS_MODULE,
86 +       .open           = debug_periodic_open,
87 +       .read           = debug_output,
88 +       .release        = debug_close,
89 +};
90 +static const struct file_operations debug_registers_fops = {
91 +       .owner          = THIS_MODULE,
92 +       .open           = debug_registers_open,
93 +       .read           = debug_output,
94 +       .release        = debug_close,
95 +};
96 +
97 +static struct dentry *admhc_debug_root;
98 +
99 +struct debug_buffer {
100 +       ssize_t (*fill_func)(struct debug_buffer *);    /* fill method */
101 +       struct device *dev;
102 +       struct mutex mutex;     /* protect filling of buffer */
103 +       size_t count;           /* number of characters filled into buffer */
104 +       char *page;
105 +};
106 +
107  static ssize_t
108  show_list(struct admhcd *ahcd, char *buf, size_t count, struct ed *ed)
109  {
110 @@ -455,8 +491,7 @@
111         return count - size;
112  }
113  
114 -static ssize_t
115 -show_async(struct device *dev, struct device_attribute *attr, char *buf)
116 +static ssize_t fill_async_buffer(struct debug_buffer *buf)
117  {
118         struct usb_bus          *bus;
119         struct usb_hcd          *hcd;
120 @@ -464,24 +499,22 @@
121         size_t                  temp;
122         unsigned long           flags;
123  
124 -       bus = dev_get_drvdata(dev);
125 +       bus = dev_get_drvdata(buf->dev);
126         hcd = bus_to_hcd(bus);
127         ahcd = hcd_to_admhcd(hcd);
128  
129         /* display control and bulk lists together, for simplicity */
130         spin_lock_irqsave(&ahcd->lock, flags);
131 -       temp = show_list(ahcd, buf, PAGE_SIZE, ahcd->ed_head);
132 +       temp = show_list(ahcd, buf->page, buf->count, ahcd->ed_head);
133         spin_unlock_irqrestore(&ahcd->lock, flags);
134  
135         return temp;
136  }
137 -static DEVICE_ATTR(async, S_IRUGO, show_async, NULL);
138  
139  
140  #define DBG_SCHED_LIMIT 64
141  
142 -static ssize_t
143 -show_periodic(struct device *dev, struct device_attribute *attr, char *buf)
144 +static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
145  {
146         struct usb_bus          *bus;
147         struct usb_hcd          *hcd;
148 @@ -496,10 +529,10 @@
149                 return 0;
150         seen_count = 0;
151  
152 -       bus = dev_get_drvdata(dev);
153 +       bus = dev_get_drvdata(buf->dev);
154         hcd = bus_to_hcd(bus);
155         ahcd = hcd_to_admhcd(hcd);
156 -       next = buf;
157 +       next = buf->page;
158         size = PAGE_SIZE;
159  
160         temp = scnprintf(next, size, "size = %d\n", NUM_INTS);
161 @@ -574,13 +607,11 @@
162  
163         return PAGE_SIZE - size;
164  }
165 -static DEVICE_ATTR(periodic, S_IRUGO, show_periodic, NULL);
166  
167  
168  #undef DBG_SCHED_LIMIT
169  
170 -static ssize_t
171 -show_registers(struct device *dev, struct device_attribute *attr, char *buf)
172 +static ssize_t fill_registers_buffer(struct debug_buffer *buf)
173  {
174         struct usb_bus          *bus;
175         struct usb_hcd          *hcd;
176 @@ -591,11 +622,11 @@
177         char                    *next;
178         u32                     rdata;
179  
180 -       bus = dev_get_drvdata(dev);
181 +       bus = dev_get_drvdata(buf->dev);
182         hcd = bus_to_hcd(bus);
183         ahcd = hcd_to_admhcd(hcd);
184         regs = ahcd->regs;
185 -       next = buf;
186 +       next = buf->page;
187         size = PAGE_SIZE;
188  
189         spin_lock_irqsave(&ahcd->lock, flags);
190 @@ -656,27 +687,154 @@
191         spin_unlock_irqrestore(&ahcd->lock, flags);
192         return PAGE_SIZE - size;
193  }
194 -static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
195  
196  
197 -static inline void create_debug_files (struct admhcd *ahcd)
198 +static struct debug_buffer *alloc_buffer(struct device *dev,
199 +                               ssize_t (*fill_func)(struct debug_buffer *))
200  {
201 -       struct device *dev = admhcd_to_hcd(ahcd)->self.dev;
202 -       int retval;
203 +       struct debug_buffer *buf;
204  
205 -       retval = device_create_file(dev, &dev_attr_async);
206 -       retval = device_create_file(dev, &dev_attr_periodic);
207 -       retval = device_create_file(dev, &dev_attr_registers);
208 -       admhc_dbg(ahcd, "created debug files\n");
209 +       buf = kzalloc(sizeof(struct debug_buffer), GFP_KERNEL);
210 +
211 +       if (buf) {
212 +               buf->dev = dev;
213 +               buf->fill_func = fill_func;
214 +               mutex_init(&buf->mutex);
215 +       }
216 +
217 +       return buf;
218 +}
219 +
220 +static int fill_buffer(struct debug_buffer *buf)
221 +{
222 +       int ret = 0;
223 +
224 +       if (!buf->page)
225 +               buf->page = (char *)get_zeroed_page(GFP_KERNEL);
226 +
227 +       if (!buf->page) {
228 +               ret = -ENOMEM;
229 +               goto out;
230 +       }
231 +
232 +       ret = buf->fill_func(buf);
233 +
234 +       if (ret >= 0) {
235 +               buf->count = ret;
236 +               ret = 0;
237 +       }
238 +
239 +out:
240 +       return ret;
241 +}
242 +
243 +static ssize_t debug_output(struct file *file, char __user *user_buf,
244 +                       size_t len, loff_t *offset)
245 +{
246 +       struct debug_buffer *buf = file->private_data;
247 +       int ret = 0;
248 +
249 +       mutex_lock(&buf->mutex);
250 +       if (buf->count == 0) {
251 +               ret = fill_buffer(buf);
252 +               if (ret != 0) {
253 +                       mutex_unlock(&buf->mutex);
254 +                       goto out;
255 +               }
256 +       }
257 +       mutex_unlock(&buf->mutex);
258 +
259 +       ret = simple_read_from_buffer(user_buf, len, offset,
260 +                                       buf->page, buf->count);
261 +
262 +out:
263 +       return ret;
264 +}
265 +
266 +static int debug_close(struct inode *inode, struct file *file)
267 +{
268 +       struct debug_buffer *buf = file->private_data;
269 +
270 +       if (buf) {
271 +               if (buf->page)
272 +                       free_page((unsigned long)buf->page);
273 +               kfree(buf);
274 +       }
275 +
276 +       return 0;
277  }
278  
279 -static inline void remove_debug_files (struct admhcd *ahcd)
280 +static int debug_async_open(struct inode *inode, struct file *file)
281  {
282 -       struct device *dev = admhcd_to_hcd(ahcd)->self.dev;
283 +       file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
284 +
285 +       return file->private_data ? 0 : -ENOMEM;
286 +}
287 +
288 +static int debug_periodic_open(struct inode *inode, struct file *file)
289 +{
290 +       file->private_data = alloc_buffer(inode->i_private,
291 +                                               fill_periodic_buffer);
292 +
293 +       return file->private_data ? 0 : -ENOMEM;
294 +}
295  
296 -       device_remove_file(dev, &dev_attr_async);
297 -       device_remove_file(dev, &dev_attr_periodic);
298 -       device_remove_file(dev, &dev_attr_registers);
299 +static int debug_registers_open(struct inode *inode, struct file *file)
300 +{
301 +       file->private_data = alloc_buffer(inode->i_private,
302 +                                               fill_registers_buffer);
303 +
304 +       return file->private_data ? 0 : -ENOMEM;
305 +}
306 +
307 +static inline void create_debug_files(struct admhcd *ahcd)
308 +{
309 +       struct usb_bus *bus = &admhcd_to_hcd(ahcd)->self;
310 +       struct device *dev = bus->dev;
311 +
312 +       ahcd->debug_dir = debugfs_create_dir(bus->bus_name, admhc_debug_root);
313 +       if (!ahcd->debug_dir)
314 +               goto dir_error;
315 +
316 +       ahcd->debug_async = debugfs_create_file("async", S_IRUGO,
317 +                                               ahcd->debug_dir, dev,
318 +                                               &debug_async_fops);
319 +       if (!ahcd->debug_async)
320 +               goto async_error;
321 +
322 +       ahcd->debug_periodic = debugfs_create_file("periodic", S_IRUGO,
323 +                                               ahcd->debug_dir, dev,
324 +                                               &debug_periodic_fops);
325 +       if (!ahcd->debug_periodic)
326 +               goto periodic_error;
327 +
328 +       ahcd->debug_registers = debugfs_create_file("registers", S_IRUGO,
329 +                                               ahcd->debug_dir, dev,
330 +                                               &debug_registers_fops);
331 +       if (!ahcd->debug_registers)
332 +               goto registers_error;
333 +
334 +       admhc_dbg(ahcd, "created debug files\n");
335 +       return;
336 +
337 +registers_error:
338 +       debugfs_remove(ahcd->debug_periodic);
339 +periodic_error:
340 +       debugfs_remove(ahcd->debug_async);
341 +async_error:
342 +       debugfs_remove(ahcd->debug_dir);
343 +dir_error:
344 +       ahcd->debug_periodic = NULL;
345 +       ahcd->debug_async = NULL;
346 +       ahcd->debug_dir = NULL;
347 +}
348 +
349 +static inline void remove_debug_files(struct admhcd *ahcd)
350 +{
351 +       debugfs_remove(ahcd->debug_registers);
352 +       debugfs_remove(ahcd->debug_periodic);
353 +       debugfs_remove(ahcd->debug_async);
354 +       debugfs_remove(ahcd->debug_dir);
355  }
356  
357  #endif