diff options
author | Alexander Shishkin <alexander.shishkin@linux.intel.com> | 2013-03-30 06:53:52 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-03-30 11:08:39 -0400 |
commit | c8e333a3b17050800a5aa536feb628f18d2a01a2 (patch) | |
tree | ffb59bccb212e3e28802d3deed5cf43869e6c2b0 | |
parent | 2d6512892c106556f07e502939005e73cdc6e2cc (diff) |
usb: chipidea: move role to debugfs
Manual role switching function is there for debugging purposes, so has
to move to debugfs.
Signed-off-by: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
-rw-r--r-- | drivers/usb/chipidea/core.c | 39 | ||||
-rw-r--r-- | drivers/usb/chipidea/debug.c | 54 |
2 files changed, 54 insertions, 39 deletions
diff --git a/drivers/usb/chipidea/core.c b/drivers/usb/chipidea/core.c index 42f224936a8e..5270156591e0 100644 --- a/drivers/usb/chipidea/core.c +++ b/drivers/usb/chipidea/core.c | |||
@@ -280,38 +280,6 @@ static void ci_role_work(struct work_struct *work) | |||
280 | } | 280 | } |
281 | } | 281 | } |
282 | 282 | ||
283 | static ssize_t show_role(struct device *dev, struct device_attribute *attr, | ||
284 | char *buf) | ||
285 | { | ||
286 | struct ci13xxx *ci = dev_get_drvdata(dev); | ||
287 | |||
288 | return sprintf(buf, "%s\n", ci_role(ci)->name); | ||
289 | } | ||
290 | |||
291 | static ssize_t store_role(struct device *dev, struct device_attribute *attr, | ||
292 | const char *buf, size_t count) | ||
293 | { | ||
294 | struct ci13xxx *ci = dev_get_drvdata(dev); | ||
295 | enum ci_role role; | ||
296 | int ret; | ||
297 | |||
298 | for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++) | ||
299 | if (ci->roles[role] && !strcmp(buf, ci->roles[role]->name)) | ||
300 | break; | ||
301 | |||
302 | if (role == CI_ROLE_END || role == ci->role) | ||
303 | return -EINVAL; | ||
304 | |||
305 | ci_role_stop(ci); | ||
306 | ret = ci_role_start(ci, role); | ||
307 | if (ret) | ||
308 | return ret; | ||
309 | |||
310 | return count; | ||
311 | } | ||
312 | |||
313 | static DEVICE_ATTR(role, S_IRUSR | S_IWUSR, show_role, store_role); | ||
314 | |||
315 | static irqreturn_t ci_irq(int irq, void *data) | 283 | static irqreturn_t ci_irq(int irq, void *data) |
316 | { | 284 | { |
317 | struct ci13xxx *ci = data; | 285 | struct ci13xxx *ci = data; |
@@ -484,17 +452,11 @@ static int ci_hdrc_probe(struct platform_device *pdev) | |||
484 | if (ret) | 452 | if (ret) |
485 | goto stop; | 453 | goto stop; |
486 | 454 | ||
487 | ret = device_create_file(dev, &dev_attr_role); | ||
488 | if (ret) | ||
489 | goto rm_attr; | ||
490 | |||
491 | if (ci->is_otg) | 455 | if (ci->is_otg) |
492 | hw_write(ci, OP_OTGSC, OTGSC_IDIE, OTGSC_IDIE); | 456 | hw_write(ci, OP_OTGSC, OTGSC_IDIE, OTGSC_IDIE); |
493 | 457 | ||
494 | return ret; | 458 | return ret; |
495 | 459 | ||
496 | rm_attr: | ||
497 | device_remove_file(dev, &dev_attr_role); | ||
498 | stop: | 460 | stop: |
499 | ci_role_stop(ci); | 461 | ci_role_stop(ci); |
500 | rm_wq: | 462 | rm_wq: |
@@ -510,7 +472,6 @@ static int ci_hdrc_remove(struct platform_device *pdev) | |||
510 | 472 | ||
511 | flush_workqueue(ci->wq); | 473 | flush_workqueue(ci->wq); |
512 | destroy_workqueue(ci->wq); | 474 | destroy_workqueue(ci->wq); |
513 | device_remove_file(ci->dev, &dev_attr_role); | ||
514 | free_irq(ci->irq, ci); | 475 | free_irq(ci->irq, ci); |
515 | ci_role_stop(ci); | 476 | ci_role_stop(ci); |
516 | 477 | ||
diff --git a/drivers/usb/chipidea/debug.c b/drivers/usb/chipidea/debug.c index 057ae09025bf..5738079734e3 100644 --- a/drivers/usb/chipidea/debug.c +++ b/drivers/usb/chipidea/debug.c | |||
@@ -199,6 +199,55 @@ static const struct file_operations ci_requests_fops = { | |||
199 | .release = single_release, | 199 | .release = single_release, |
200 | }; | 200 | }; |
201 | 201 | ||
202 | static int ci_role_show(struct seq_file *s, void *data) | ||
203 | { | ||
204 | struct ci13xxx *ci = s->private; | ||
205 | |||
206 | seq_printf(s, "%s\n", ci_role(ci)->name); | ||
207 | |||
208 | return 0; | ||
209 | } | ||
210 | |||
211 | static ssize_t ci_role_write(struct file *file, const char __user *ubuf, | ||
212 | size_t count, loff_t *ppos) | ||
213 | { | ||
214 | struct seq_file *s = file->private_data; | ||
215 | struct ci13xxx *ci = s->private; | ||
216 | enum ci_role role; | ||
217 | char buf[8]; | ||
218 | int ret; | ||
219 | |||
220 | if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count))) | ||
221 | return -EFAULT; | ||
222 | |||
223 | for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++) | ||
224 | if (ci->roles[role] && | ||
225 | !strncmp(buf, ci->roles[role]->name, | ||
226 | strlen(ci->roles[role]->name))) | ||
227 | break; | ||
228 | |||
229 | if (role == CI_ROLE_END || role == ci->role) | ||
230 | return -EINVAL; | ||
231 | |||
232 | ci_role_stop(ci); | ||
233 | ret = ci_role_start(ci, role); | ||
234 | |||
235 | return ret ? ret : count; | ||
236 | } | ||
237 | |||
238 | static int ci_role_open(struct inode *inode, struct file *file) | ||
239 | { | ||
240 | return single_open(file, ci_role_show, inode->i_private); | ||
241 | } | ||
242 | |||
243 | static const struct file_operations ci_role_fops = { | ||
244 | .open = ci_role_open, | ||
245 | .write = ci_role_write, | ||
246 | .read = seq_read, | ||
247 | .llseek = seq_lseek, | ||
248 | .release = single_release, | ||
249 | }; | ||
250 | |||
202 | /** | 251 | /** |
203 | * dbg_create_files: initializes the attribute interface | 252 | * dbg_create_files: initializes the attribute interface |
204 | * @ci: device | 253 | * @ci: device |
@@ -230,6 +279,11 @@ int dbg_create_files(struct ci13xxx *ci) | |||
230 | 279 | ||
231 | dent = debugfs_create_file("requests", S_IRUGO, ci->debugfs, ci, | 280 | dent = debugfs_create_file("requests", S_IRUGO, ci->debugfs, ci, |
232 | &ci_requests_fops); | 281 | &ci_requests_fops); |
282 | if (!dent) | ||
283 | goto err; | ||
284 | |||
285 | dent = debugfs_create_file("role", S_IRUGO | S_IWUSR, ci->debugfs, ci, | ||
286 | &ci_role_fops); | ||
233 | if (dent) | 287 | if (dent) |
234 | return 0; | 288 | return 0; |
235 | err: | 289 | err: |