1 --- a/drivers/usb/host/adm5120.h
2 +++ b/drivers/usb/host/adm5120.h
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
9 + struct dentry *debug_dir;
10 + struct dentry *debug_async;
11 + struct dentry *debug_periodic;
12 + struct dentry *debug_registers;
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
20 #include <linux/dma-mapping.h>
21 #include <linux/dmapool.h>
22 #include <linux/reboot.h>
23 +#include <linux/debugfs.h>
28 pr_info("%s: block sizes: ed %Zd td %Zd\n", hcd_name,
29 sizeof (struct ed), sizeof (struct td));
32 + admhc_debug_root = debugfs_create_dir("admhc", NULL);
33 + if (!admhc_debug_root) {
39 #ifdef PLATFORM_DRIVER
40 ret = platform_driver_register(&PLATFORM_DRIVER);
43 platform_driver_unregister(&PLATFORM_DRIVER);
48 + debugfs_remove(admhc_debug_root);
49 + admhc_debug_root = NULL;
54 module_init(admhc_hcd_mod_init);
56 static void __exit admhc_hcd_mod_exit(void)
58 platform_driver_unregister(&PLATFORM_DRIVER);
60 + debugfs_remove(admhc_debug_root);
63 module_exit(admhc_hcd_mod_exit);
65 --- a/drivers/usb/host/adm5120-dbg.c
66 +++ b/drivers/usb/host/adm5120-dbg.c
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 *);
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,
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,
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,
97 +static struct dentry *admhc_debug_root;
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 */
108 show_list(struct admhcd *ahcd, char *buf, size_t count, struct ed *ed)
115 -show_async(struct device *dev, struct device_attribute *attr, char *buf)
116 +static ssize_t fill_async_buffer(struct debug_buffer *buf)
120 @@ -464,24 +499,22 @@
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);
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);
137 -static DEVICE_ATTR(async, S_IRUGO, show_async, NULL);
140 #define DBG_SCHED_LIMIT 64
143 -show_periodic(struct device *dev, struct device_attribute *attr, char *buf)
144 +static ssize_t fill_periodic_buffer(struct debug_buffer *buf)
148 @@ -496,10 +529,10 @@
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);
160 temp = scnprintf(next, size, "size = %d\n", NUM_INTS);
161 @@ -574,13 +607,11 @@
163 return PAGE_SIZE - size;
165 -static DEVICE_ATTR(periodic, S_IRUGO, show_periodic, NULL);
168 #undef DBG_SCHED_LIMIT
171 -show_registers(struct device *dev, struct device_attribute *attr, char *buf)
172 +static ssize_t fill_registers_buffer(struct debug_buffer *buf)
176 @@ -591,11 +622,11 @@
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);
189 spin_lock_irqsave(&ahcd->lock, flags);
190 @@ -656,27 +687,154 @@
191 spin_unlock_irqrestore(&ahcd->lock, flags);
192 return PAGE_SIZE - size;
194 -static DEVICE_ATTR(registers, S_IRUGO, show_registers, NULL);
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 *))
201 - struct device *dev = admhcd_to_hcd(ahcd)->self.dev;
203 + struct debug_buffer *buf;
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);
213 + buf->fill_func = fill_func;
214 + mutex_init(&buf->mutex);
220 +static int fill_buffer(struct debug_buffer *buf)
225 + buf->page = (char *)get_zeroed_page(GFP_KERNEL);
232 + ret = buf->fill_func(buf);
243 +static ssize_t debug_output(struct file *file, char __user *user_buf,
244 + size_t len, loff_t *offset)
246 + struct debug_buffer *buf = file->private_data;
249 + mutex_lock(&buf->mutex);
250 + if (buf->count == 0) {
251 + ret = fill_buffer(buf);
253 + mutex_unlock(&buf->mutex);
257 + mutex_unlock(&buf->mutex);
259 + ret = simple_read_from_buffer(user_buf, len, offset,
260 + buf->page, buf->count);
266 +static int debug_close(struct inode *inode, struct file *file)
268 + struct debug_buffer *buf = file->private_data;
272 + free_page((unsigned long)buf->page);
279 -static inline void remove_debug_files (struct admhcd *ahcd)
280 +static int debug_async_open(struct inode *inode, struct file *file)
282 - struct device *dev = admhcd_to_hcd(ahcd)->self.dev;
283 + file->private_data = alloc_buffer(inode->i_private, fill_async_buffer);
285 + return file->private_data ? 0 : -ENOMEM;
288 +static int debug_periodic_open(struct inode *inode, struct file *file)
290 + file->private_data = alloc_buffer(inode->i_private,
291 + fill_periodic_buffer);
293 + return file->private_data ? 0 : -ENOMEM;
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)
301 + file->private_data = alloc_buffer(inode->i_private,
302 + fill_registers_buffer);
304 + return file->private_data ? 0 : -ENOMEM;
307 +static inline void create_debug_files(struct admhcd *ahcd)
309 + struct usb_bus *bus = &admhcd_to_hcd(ahcd)->self;
310 + struct device *dev = bus->dev;
312 + ahcd->debug_dir = debugfs_create_dir(bus->bus_name, admhc_debug_root);
313 + if (!ahcd->debug_dir)
316 + ahcd->debug_async = debugfs_create_file("async", S_IRUGO,
317 + ahcd->debug_dir, dev,
318 + &debug_async_fops);
319 + if (!ahcd->debug_async)
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;
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;
334 + admhc_dbg(ahcd, "created debug files\n");
338 + debugfs_remove(ahcd->debug_periodic);
340 + debugfs_remove(ahcd->debug_async);
342 + debugfs_remove(ahcd->debug_dir);
344 + ahcd->debug_periodic = NULL;
345 + ahcd->debug_async = NULL;
346 + ahcd->debug_dir = NULL;
349 +static inline void remove_debug_files(struct admhcd *ahcd)
351 + debugfs_remove(ahcd->debug_registers);
352 + debugfs_remove(ahcd->debug_periodic);
353 + debugfs_remove(ahcd->debug_async);
354 + debugfs_remove(ahcd->debug_dir);