From: Dario Binacchi <dariobin@libero.it>
To: linux-kernel@vger.kernel.org
Cc: Dario Binacchi <dariobin@libero.it>,
Tony Lindgren <tony@atomide.com>,
Drew Fustini <drew@beagleboard.org>,
Linus Walleij <linus.walleij@linaro.org>,
Andy Shevchenko <andy.shevchenko@gmail.com>,
linux-gpio@vger.kernel.org
Subject: [PATCH v3 2/3] pinctrl: core: configure pinmux from pins debug file
Date: Thu, 20 May 2021 22:27:29 +0200 [thread overview]
Message-ID: <20210520202730.4444-3-dariobin@libero.it> (raw)
In-Reply-To: <20210520202730.4444-1-dariobin@libero.it>
The MPUs of some architectures (e.g AM335x) must be in privileged
operating mode to write on the pinmux registers. In such cases, where
writes will not work from user space, now it can be done from the pins
debug file if the platform driver exports the pin_dbg_set() helper among
the registered operations.
Signed-off-by: Dario Binacchi <dariobin@libero.it>
---
Changes in v3:
- Use strncpy_from_user() instead of copy_from_user().
- Do not shadow the error code returned by kstrtouint().
- Change pin_dbg_set() interface (char *buf --> unsigned int val).
- Describe pin_dbg_set().
drivers/pinctrl/core.c | 63 +++++++++++++++++++++++++++++++--
include/linux/pinctrl/pinctrl.h | 4 +++
2 files changed, 65 insertions(+), 2 deletions(-)
diff --git a/drivers/pinctrl/core.c b/drivers/pinctrl/core.c
index a4ac87c8b4f8..ab832044a0c3 100644
--- a/drivers/pinctrl/core.c
+++ b/drivers/pinctrl/core.c
@@ -1620,6 +1620,53 @@ EXPORT_SYMBOL_GPL(pinctrl_pm_select_idle_state);
#ifdef CONFIG_DEBUG_FS
+static ssize_t pinctrl_pins_write(struct file *file,
+ const char __user *user_buf, size_t count,
+ loff_t *ppos)
+{
+ struct seq_file *s = file->private_data;
+ struct pinctrl_dev *pctldev = s->private;
+ const struct pinctrl_ops *ops = pctldev->desc->pctlops;
+ char buf[32];
+ char *c = &buf[0];
+ char *token;
+ int ret;
+ unsigned int i, pin, val;
+
+ if (!ops->pin_dbg_set)
+ return -EFAULT;
+
+ ret = strncpy_from_user(buf, user_buf, sizeof(buf));
+ if (ret == 0 || ret == sizeof(buf))
+ ret = -ERANGE;
+
+ if (ret < 0)
+ return ret;
+
+ token = strsep(&c, " ");
+ ret = kstrtouint(token, 0, &pin);
+ if (ret)
+ return ret;
+
+ token = strsep(&c, " ");
+ ret = kstrtouint(token, 0, &val);
+ if (ret)
+ return ret;
+
+ for (i = 0; i < pctldev->desc->npins; i++) {
+ if (pin != pctldev->desc->pins[i].number)
+ continue;
+
+ ret = ops->pin_dbg_set(pctldev, pin, val);
+ if (ret)
+ return ret;
+
+ return count;
+ }
+
+ return -EINVAL;
+}
+
static int pinctrl_pins_show(struct seq_file *s, void *what)
{
struct pinctrl_dev *pctldev = s->private;
@@ -1677,7 +1724,11 @@ static int pinctrl_pins_show(struct seq_file *s, void *what)
return 0;
}
-DEFINE_SHOW_ATTRIBUTE(pinctrl_pins);
+
+static int pinctrl_pins_open(struct inode *inode, struct file *file)
+{
+ return single_open(file, pinctrl_pins_show, inode->i_private);
+}
static int pinctrl_groups_show(struct seq_file *s, void *what)
{
@@ -1886,6 +1937,14 @@ static int pinctrl_show(struct seq_file *s, void *what)
}
DEFINE_SHOW_ATTRIBUTE(pinctrl);
+static const struct file_operations pinctrl_pins_fops = {
+ .open = pinctrl_pins_open,
+ .read = seq_read,
+ .write = pinctrl_pins_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
static struct dentry *debugfs_root;
static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
@@ -1915,7 +1974,7 @@ static void pinctrl_init_device_debugfs(struct pinctrl_dev *pctldev)
dev_name(pctldev->dev));
return;
}
- debugfs_create_file("pins", 0444,
+ debugfs_create_file("pins", 0644,
device_root, pctldev, &pinctrl_pins_fops);
debugfs_create_file("pingroups", 0444,
device_root, pctldev, &pinctrl_groups_fops);
diff --git a/include/linux/pinctrl/pinctrl.h b/include/linux/pinctrl/pinctrl.h
index 70b45d28e7a9..7ae8aca3dfa5 100644
--- a/include/linux/pinctrl/pinctrl.h
+++ b/include/linux/pinctrl/pinctrl.h
@@ -75,6 +75,8 @@ struct pinctrl_gpio_range {
* group selector @pins, and the size of the array in @num_pins
* @pin_dbg_show: optional debugfs display hook that will provide per-device
* info for a certain pin in debugfs
+ * @pin_dbg_set: optional debugfs set hook that will write per-device pinmux
+ * register for a certain pin in debugfs
* @dt_node_to_map: parse a device tree "pin configuration node", and create
* mapping table entries for it. These are returned through the @map and
* @num_maps output parameters. This function is optional, and may be
@@ -95,6 +97,8 @@ struct pinctrl_ops {
unsigned *num_pins);
void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s,
unsigned offset);
+ int (*pin_dbg_set) (struct pinctrl_dev *pctldev, unsigned int offset,
+ unsigned int val);
int (*dt_node_to_map) (struct pinctrl_dev *pctldev,
struct device_node *np_config,
struct pinctrl_map **map, unsigned *num_maps);
--
2.17.1
next prev parent reply other threads:[~2021-05-20 20:29 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-05-20 20:27 [PATCH v3 0/3] am335x: set pinmux registers " Dario Binacchi
2021-05-20 20:27 ` [PATCH v3 1/3] docs/pinctrl: update `pins' description under debugfs Dario Binacchi
2021-05-20 20:27 ` Dario Binacchi [this message]
2021-05-21 6:44 ` [PATCH v3 2/3] pinctrl: core: configure pinmux from pins debug file Vladimir Zapolskiy
2021-05-24 17:28 ` Dario Binacchi
2021-05-24 18:52 ` Vladimir Zapolskiy
2021-05-25 5:15 ` Tony Lindgren
2021-05-27 19:23 ` Dario Binacchi
2021-05-27 19:57 ` Vladimir Zapolskiy
2021-05-27 20:33 ` Dario Binacchi
2021-05-28 8:34 ` Vladimir Zapolskiy
2021-05-28 9:07 ` Linus Walleij
2021-06-02 5:03 ` Tony Lindgren
2021-06-11 8:29 ` Dario Binacchi
2021-05-20 20:27 ` [PATCH v3 3/3] pinctrl: single: set " Dario Binacchi
2021-05-21 6:44 ` Vladimir Zapolskiy
2021-05-25 0:18 ` [PATCH v3 0/3] am335x: set pinmux registers " Linus Walleij
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210520202730.4444-3-dariobin@libero.it \
--to=dariobin@libero.it \
--cc=andy.shevchenko@gmail.com \
--cc=drew@beagleboard.org \
--cc=linus.walleij@linaro.org \
--cc=linux-gpio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®