Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 1 | #include <linux/kernel.h> |
Alexander Shishkin | 3c37bb6 | 2013-03-30 02:46:17 +0200 | [diff] [blame] | 2 | #include <linux/device.h> |
| 3 | #include <linux/types.h> |
| 4 | #include <linux/spinlock.h> |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 5 | #include <linux/debugfs.h> |
| 6 | #include <linux/seq_file.h> |
| 7 | #include <linux/uaccess.h> |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 8 | #include <linux/usb/ch9.h> |
| 9 | #include <linux/usb/gadget.h> |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 10 | |
| 11 | #include "ci.h" |
| 12 | #include "udc.h" |
| 13 | #include "bits.h" |
| 14 | #include "debug.h" |
Li Jun | c4a8b63 | 2014-04-23 15:56:40 +0800 | [diff] [blame^] | 15 | #include "otg.h" |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 16 | |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 17 | /** |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 18 | * ci_device_show: prints information about device capabilities and status |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 19 | */ |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 20 | static int ci_device_show(struct seq_file *s, void *data) |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 21 | { |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 22 | struct ci_hdrc *ci = s->private; |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 23 | struct usb_gadget *gadget = &ci->gadget; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 24 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 25 | seq_printf(s, "speed = %d\n", gadget->speed); |
| 26 | seq_printf(s, "max_speed = %d\n", gadget->max_speed); |
| 27 | seq_printf(s, "is_otg = %d\n", gadget->is_otg); |
| 28 | seq_printf(s, "is_a_peripheral = %d\n", gadget->is_a_peripheral); |
| 29 | seq_printf(s, "b_hnp_enable = %d\n", gadget->b_hnp_enable); |
| 30 | seq_printf(s, "a_hnp_support = %d\n", gadget->a_hnp_support); |
| 31 | seq_printf(s, "a_alt_hnp_support = %d\n", gadget->a_alt_hnp_support); |
| 32 | seq_printf(s, "name = %s\n", |
| 33 | (gadget->name ? gadget->name : "")); |
| 34 | |
| 35 | if (!ci->driver) |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 36 | return 0; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 37 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 38 | seq_printf(s, "gadget function = %s\n", |
| 39 | (ci->driver->function ? ci->driver->function : "")); |
| 40 | seq_printf(s, "gadget max speed = %d\n", ci->driver->max_speed); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 41 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 42 | return 0; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 43 | } |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 44 | |
| 45 | static int ci_device_open(struct inode *inode, struct file *file) |
| 46 | { |
| 47 | return single_open(file, ci_device_show, inode->i_private); |
| 48 | } |
| 49 | |
| 50 | static const struct file_operations ci_device_fops = { |
| 51 | .open = ci_device_open, |
| 52 | .read = seq_read, |
| 53 | .llseek = seq_lseek, |
| 54 | .release = single_release, |
| 55 | }; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 56 | |
| 57 | /** |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 58 | * ci_port_test_show: reads port test mode |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 59 | */ |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 60 | static int ci_port_test_show(struct seq_file *s, void *data) |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 61 | { |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 62 | struct ci_hdrc *ci = s->private; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 63 | unsigned long flags; |
| 64 | unsigned mode; |
| 65 | |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 66 | spin_lock_irqsave(&ci->lock, flags); |
| 67 | mode = hw_port_test_get(ci); |
| 68 | spin_unlock_irqrestore(&ci->lock, flags); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 69 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 70 | seq_printf(s, "mode = %u\n", mode); |
| 71 | |
| 72 | return 0; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /** |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 76 | * ci_port_test_write: writes port test mode |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 77 | */ |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 78 | static ssize_t ci_port_test_write(struct file *file, const char __user *ubuf, |
| 79 | size_t count, loff_t *ppos) |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 80 | { |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 81 | struct seq_file *s = file->private_data; |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 82 | struct ci_hdrc *ci = s->private; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 83 | unsigned long flags; |
| 84 | unsigned mode; |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 85 | char buf[32]; |
| 86 | int ret; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 87 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 88 | if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 89 | return -EFAULT; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 90 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 91 | if (sscanf(buf, "%u", &mode) != 1) |
| 92 | return -EINVAL; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 93 | |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 94 | spin_lock_irqsave(&ci->lock, flags); |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 95 | ret = hw_port_test_set(ci, mode); |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 96 | spin_unlock_irqrestore(&ci->lock, flags); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 97 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 98 | return ret ? ret : count; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 99 | } |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 100 | |
| 101 | static int ci_port_test_open(struct inode *inode, struct file *file) |
| 102 | { |
| 103 | return single_open(file, ci_port_test_show, inode->i_private); |
| 104 | } |
| 105 | |
| 106 | static const struct file_operations ci_port_test_fops = { |
| 107 | .open = ci_port_test_open, |
| 108 | .write = ci_port_test_write, |
| 109 | .read = seq_read, |
| 110 | .llseek = seq_lseek, |
| 111 | .release = single_release, |
| 112 | }; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 113 | |
| 114 | /** |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 115 | * ci_qheads_show: DMA contents of all queue heads |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 116 | */ |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 117 | static int ci_qheads_show(struct seq_file *s, void *data) |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 118 | { |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 119 | struct ci_hdrc *ci = s->private; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 120 | unsigned long flags; |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 121 | unsigned i, j; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 122 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 123 | if (ci->role != CI_ROLE_GADGET) { |
| 124 | seq_printf(s, "not in gadget mode\n"); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 125 | return 0; |
| 126 | } |
| 127 | |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 128 | spin_lock_irqsave(&ci->lock, flags); |
| 129 | for (i = 0; i < ci->hw_ep_max/2; i++) { |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 130 | struct ci_hw_ep *hweprx = &ci->ci_hw_ep[i]; |
| 131 | struct ci_hw_ep *hweptx = |
| 132 | &ci->ci_hw_ep[i + ci->hw_ep_max/2]; |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 133 | seq_printf(s, "EP=%02i: RX=%08X TX=%08X\n", |
Alexander Shishkin | 2dbc5c4 | 2013-06-13 18:00:03 +0300 | [diff] [blame] | 134 | i, (u32)hweprx->qh.dma, (u32)hweptx->qh.dma); |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 135 | for (j = 0; j < (sizeof(struct ci_hw_qh)/sizeof(u32)); j++) |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 136 | seq_printf(s, " %04X: %08X %08X\n", j, |
Alexander Shishkin | 2dbc5c4 | 2013-06-13 18:00:03 +0300 | [diff] [blame] | 137 | *((u32 *)hweprx->qh.ptr + j), |
| 138 | *((u32 *)hweptx->qh.ptr + j)); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 139 | } |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 140 | spin_unlock_irqrestore(&ci->lock, flags); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 141 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 142 | return 0; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 143 | } |
| 144 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 145 | static int ci_qheads_open(struct inode *inode, struct file *file) |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 146 | { |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 147 | return single_open(file, ci_qheads_show, inode->i_private); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 148 | } |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 149 | |
| 150 | static const struct file_operations ci_qheads_fops = { |
| 151 | .open = ci_qheads_open, |
| 152 | .read = seq_read, |
| 153 | .llseek = seq_lseek, |
| 154 | .release = single_release, |
| 155 | }; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 156 | |
| 157 | /** |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 158 | * ci_requests_show: DMA contents of all requests currently queued (all endpts) |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 159 | */ |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 160 | static int ci_requests_show(struct seq_file *s, void *data) |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 161 | { |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 162 | struct ci_hdrc *ci = s->private; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 163 | unsigned long flags; |
| 164 | struct list_head *ptr = NULL; |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 165 | struct ci_hw_req *req = NULL; |
Michael Grzeschik | cc9e6c4 | 2013-06-13 17:59:53 +0300 | [diff] [blame] | 166 | struct td_node *node, *tmpnode; |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 167 | unsigned i, j, qsize = sizeof(struct ci_hw_td)/sizeof(u32); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 168 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 169 | if (ci->role != CI_ROLE_GADGET) { |
| 170 | seq_printf(s, "not in gadget mode\n"); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 171 | return 0; |
| 172 | } |
| 173 | |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 174 | spin_lock_irqsave(&ci->lock, flags); |
| 175 | for (i = 0; i < ci->hw_ep_max; i++) |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 176 | list_for_each(ptr, &ci->ci_hw_ep[i].qh.queue) { |
| 177 | req = list_entry(ptr, struct ci_hw_req, queue); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 178 | |
Michael Grzeschik | cc9e6c4 | 2013-06-13 17:59:53 +0300 | [diff] [blame] | 179 | list_for_each_entry_safe(node, tmpnode, &req->tds, td) { |
| 180 | seq_printf(s, "EP=%02i: TD=%08X %s\n", |
| 181 | i % (ci->hw_ep_max / 2), |
| 182 | (u32)node->dma, |
| 183 | ((i < ci->hw_ep_max/2) ? |
| 184 | "RX" : "TX")); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 185 | |
Michael Grzeschik | cc9e6c4 | 2013-06-13 17:59:53 +0300 | [diff] [blame] | 186 | for (j = 0; j < qsize; j++) |
| 187 | seq_printf(s, " %04X: %08X\n", j, |
| 188 | *((u32 *)node->ptr + j)); |
| 189 | } |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 190 | } |
Richard Zhao | 26c696c | 2012-07-07 22:56:40 +0800 | [diff] [blame] | 191 | spin_unlock_irqrestore(&ci->lock, flags); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 192 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 193 | return 0; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 194 | } |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 195 | |
| 196 | static int ci_requests_open(struct inode *inode, struct file *file) |
| 197 | { |
| 198 | return single_open(file, ci_requests_show, inode->i_private); |
| 199 | } |
| 200 | |
| 201 | static const struct file_operations ci_requests_fops = { |
| 202 | .open = ci_requests_open, |
| 203 | .read = seq_read, |
| 204 | .llseek = seq_lseek, |
| 205 | .release = single_release, |
| 206 | }; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 207 | |
Alexander Shishkin | c8e333a | 2013-03-30 12:53:52 +0200 | [diff] [blame] | 208 | static int ci_role_show(struct seq_file *s, void *data) |
| 209 | { |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 210 | struct ci_hdrc *ci = s->private; |
Alexander Shishkin | c8e333a | 2013-03-30 12:53:52 +0200 | [diff] [blame] | 211 | |
| 212 | seq_printf(s, "%s\n", ci_role(ci)->name); |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | |
| 217 | static ssize_t ci_role_write(struct file *file, const char __user *ubuf, |
| 218 | size_t count, loff_t *ppos) |
| 219 | { |
| 220 | struct seq_file *s = file->private_data; |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 221 | struct ci_hdrc *ci = s->private; |
Alexander Shishkin | c8e333a | 2013-03-30 12:53:52 +0200 | [diff] [blame] | 222 | enum ci_role role; |
| 223 | char buf[8]; |
| 224 | int ret; |
| 225 | |
| 226 | if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) |
| 227 | return -EFAULT; |
| 228 | |
| 229 | for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++) |
| 230 | if (ci->roles[role] && |
| 231 | !strncmp(buf, ci->roles[role]->name, |
| 232 | strlen(ci->roles[role]->name))) |
| 233 | break; |
| 234 | |
| 235 | if (role == CI_ROLE_END || role == ci->role) |
| 236 | return -EINVAL; |
| 237 | |
| 238 | ci_role_stop(ci); |
| 239 | ret = ci_role_start(ci, role); |
| 240 | |
| 241 | return ret ? ret : count; |
| 242 | } |
| 243 | |
| 244 | static int ci_role_open(struct inode *inode, struct file *file) |
| 245 | { |
| 246 | return single_open(file, ci_role_show, inode->i_private); |
| 247 | } |
| 248 | |
| 249 | static const struct file_operations ci_role_fops = { |
| 250 | .open = ci_role_open, |
| 251 | .write = ci_role_write, |
| 252 | .read = seq_read, |
| 253 | .llseek = seq_lseek, |
| 254 | .release = single_release, |
| 255 | }; |
| 256 | |
Li Jun | c4a8b63 | 2014-04-23 15:56:40 +0800 | [diff] [blame^] | 257 | int ci_registers_show(struct seq_file *s, void *unused) |
| 258 | { |
| 259 | struct ci_hdrc *ci = s->private; |
| 260 | u32 tmp_reg; |
| 261 | |
| 262 | if (!ci) |
| 263 | return 0; |
| 264 | |
| 265 | /* ------ Registers ----- */ |
| 266 | tmp_reg = hw_read_intr_enable(ci); |
| 267 | seq_printf(s, "USBINTR reg: %08x\n", tmp_reg); |
| 268 | |
| 269 | tmp_reg = hw_read_intr_status(ci); |
| 270 | seq_printf(s, "USBSTS reg: %08x\n", tmp_reg); |
| 271 | |
| 272 | tmp_reg = hw_read(ci, OP_USBMODE, ~0); |
| 273 | seq_printf(s, "USBMODE reg: %08x\n", tmp_reg); |
| 274 | |
| 275 | tmp_reg = hw_read(ci, OP_USBCMD, ~0); |
| 276 | seq_printf(s, "USBCMD reg: %08x\n", tmp_reg); |
| 277 | |
| 278 | tmp_reg = hw_read(ci, OP_PORTSC, ~0); |
| 279 | seq_printf(s, "PORTSC reg: %08x\n", tmp_reg); |
| 280 | |
| 281 | if (ci->is_otg) { |
| 282 | tmp_reg = hw_read_otgsc(ci, ~0); |
| 283 | seq_printf(s, "OTGSC reg: %08x\n", tmp_reg); |
| 284 | } |
| 285 | |
| 286 | return 0; |
| 287 | } |
| 288 | |
| 289 | static int ci_registers_open(struct inode *inode, struct file *file) |
| 290 | { |
| 291 | return single_open(file, ci_registers_show, inode->i_private); |
| 292 | } |
| 293 | |
| 294 | static const struct file_operations ci_registers_fops = { |
| 295 | .open = ci_registers_open, |
| 296 | .read = seq_read, |
| 297 | .llseek = seq_lseek, |
| 298 | .release = single_release, |
| 299 | }; |
| 300 | |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 301 | /** |
| 302 | * dbg_create_files: initializes the attribute interface |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 303 | * @ci: device |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 304 | * |
| 305 | * This function returns an error code |
| 306 | */ |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 307 | int dbg_create_files(struct ci_hdrc *ci) |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 308 | { |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 309 | struct dentry *dent; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 310 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 311 | ci->debugfs = debugfs_create_dir(dev_name(ci->dev), NULL); |
| 312 | if (!ci->debugfs) |
| 313 | return -ENOMEM; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 314 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 315 | dent = debugfs_create_file("device", S_IRUGO, ci->debugfs, ci, |
| 316 | &ci_device_fops); |
| 317 | if (!dent) |
| 318 | goto err; |
| 319 | |
| 320 | dent = debugfs_create_file("port_test", S_IRUGO | S_IWUSR, ci->debugfs, |
| 321 | ci, &ci_port_test_fops); |
| 322 | if (!dent) |
| 323 | goto err; |
| 324 | |
| 325 | dent = debugfs_create_file("qheads", S_IRUGO, ci->debugfs, ci, |
| 326 | &ci_qheads_fops); |
| 327 | if (!dent) |
| 328 | goto err; |
| 329 | |
| 330 | dent = debugfs_create_file("requests", S_IRUGO, ci->debugfs, ci, |
| 331 | &ci_requests_fops); |
Alexander Shishkin | c8e333a | 2013-03-30 12:53:52 +0200 | [diff] [blame] | 332 | if (!dent) |
| 333 | goto err; |
| 334 | |
| 335 | dent = debugfs_create_file("role", S_IRUGO | S_IWUSR, ci->debugfs, ci, |
| 336 | &ci_role_fops); |
Li Jun | c4a8b63 | 2014-04-23 15:56:40 +0800 | [diff] [blame^] | 337 | if (!dent) |
| 338 | goto err; |
| 339 | |
| 340 | dent = debugfs_create_file("registers", S_IRUGO, ci->debugfs, ci, |
| 341 | &ci_registers_fops); |
| 342 | |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 343 | if (dent) |
| 344 | return 0; |
| 345 | err: |
| 346 | debugfs_remove_recursive(ci->debugfs); |
| 347 | return -ENOMEM; |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 348 | } |
| 349 | |
| 350 | /** |
| 351 | * dbg_remove_files: destroys the attribute interface |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 352 | * @ci: device |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 353 | */ |
Alexander Shishkin | 8e22978 | 2013-06-24 14:46:36 +0300 | [diff] [blame] | 354 | void dbg_remove_files(struct ci_hdrc *ci) |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 355 | { |
Alexander Shishkin | 2d65128 | 2013-03-30 12:53:51 +0200 | [diff] [blame] | 356 | debugfs_remove_recursive(ci->debugfs); |
Alexander Shishkin | e443b33 | 2012-05-11 17:25:46 +0300 | [diff] [blame] | 357 | } |