usb: chipidea: move role to debugfs
authorAlexander Shishkin <alexander.shishkin@linux.intel.com>
Sat, 30 Mar 2013 10:53:52 +0000 (12:53 +0200)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 30 Mar 2013 15:08:39 +0000 (08:08 -0700)
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>
drivers/usb/chipidea/core.c
drivers/usb/chipidea/debug.c

index 42f224936a8eea6c30c3da7eb361c25f049f4b0e..5270156591e0ebf4dea4f80aba4bdf28b070e631 100644 (file)
@@ -280,38 +280,6 @@ static void ci_role_work(struct work_struct *work)
        }
 }
 
-static ssize_t show_role(struct device *dev, struct device_attribute *attr,
-                        char *buf)
-{
-       struct ci13xxx *ci = dev_get_drvdata(dev);
-
-       return sprintf(buf, "%s\n", ci_role(ci)->name);
-}
-
-static ssize_t store_role(struct device *dev, struct device_attribute *attr,
-                         const char *buf, size_t count)
-{
-       struct ci13xxx *ci = dev_get_drvdata(dev);
-       enum ci_role role;
-       int ret;
-
-       for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++)
-               if (ci->roles[role] && !strcmp(buf, ci->roles[role]->name))
-                       break;
-
-       if (role == CI_ROLE_END || role == ci->role)
-               return -EINVAL;
-
-       ci_role_stop(ci);
-       ret = ci_role_start(ci, role);
-       if (ret)
-               return ret;
-
-       return count;
-}
-
-static DEVICE_ATTR(role, S_IRUSR | S_IWUSR, show_role, store_role);
-
 static irqreturn_t ci_irq(int irq, void *data)
 {
        struct ci13xxx *ci = data;
@@ -484,17 +452,11 @@ static int ci_hdrc_probe(struct platform_device *pdev)
        if (ret)
                goto stop;
 
-       ret = device_create_file(dev, &dev_attr_role);
-       if (ret)
-               goto rm_attr;
-
        if (ci->is_otg)
                hw_write(ci, OP_OTGSC, OTGSC_IDIE, OTGSC_IDIE);
 
        return ret;
 
-rm_attr:
-       device_remove_file(dev, &dev_attr_role);
 stop:
        ci_role_stop(ci);
 rm_wq:
@@ -510,7 +472,6 @@ static int ci_hdrc_remove(struct platform_device *pdev)
 
        flush_workqueue(ci->wq);
        destroy_workqueue(ci->wq);
-       device_remove_file(ci->dev, &dev_attr_role);
        free_irq(ci->irq, ci);
        ci_role_stop(ci);
 
index 057ae09025bfcc15456bd86152329d7f193b6d93..5738079734e388eebc7bb261d9f6a23ae1986e7c 100644 (file)
@@ -199,6 +199,55 @@ static const struct file_operations ci_requests_fops = {
        .release        = single_release,
 };
 
+static int ci_role_show(struct seq_file *s, void *data)
+{
+       struct ci13xxx *ci = s->private;
+
+       seq_printf(s, "%s\n", ci_role(ci)->name);
+
+       return 0;
+}
+
+static ssize_t ci_role_write(struct file *file, const char __user *ubuf,
+                            size_t count, loff_t *ppos)
+{
+       struct seq_file *s = file->private_data;
+       struct ci13xxx *ci = s->private;
+       enum ci_role role;
+       char buf[8];
+       int ret;
+
+       if (copy_from_user(buf, ubuf, min_t(size_t, sizeof(buf) - 1, count)))
+               return -EFAULT;
+
+       for (role = CI_ROLE_HOST; role < CI_ROLE_END; role++)
+               if (ci->roles[role] &&
+                   !strncmp(buf, ci->roles[role]->name,
+                            strlen(ci->roles[role]->name)))
+                       break;
+
+       if (role == CI_ROLE_END || role == ci->role)
+               return -EINVAL;
+
+       ci_role_stop(ci);
+       ret = ci_role_start(ci, role);
+
+       return ret ? ret : count;
+}
+
+static int ci_role_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, ci_role_show, inode->i_private);
+}
+
+static const struct file_operations ci_role_fops = {
+       .open           = ci_role_open,
+       .write          = ci_role_write,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+
 /**
  * dbg_create_files: initializes the attribute interface
  * @ci: device
@@ -230,6 +279,11 @@ int dbg_create_files(struct ci13xxx *ci)
 
        dent = debugfs_create_file("requests", S_IRUGO, ci->debugfs, ci,
                                   &ci_requests_fops);
+       if (!dent)
+               goto err;
+
+       dent = debugfs_create_file("role", S_IRUGO | S_IWUSR, ci->debugfs, ci,
+                                  &ci_role_fops);
        if (dent)
                return 0;
 err: