linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gary Bisson <gary.bisson@boundarydevices.com>
To: linus.walleij@linaro.org, fabio.estevam@nxp.com
Cc: shawnguo@kernel.org, linux-gpio@vger.kernel.org,
	linux-kernel@vger.kernel.org, pantelis.antoniou@konsulko.com,
	vladimir_zapolskiy@mentor.com,
	Gary Bisson <gary.bisson@boundarydevices.com>
Subject: [RFC v2 3/3] pinctrl: imx: add of_notifier for dynamic pinctrl changes
Date: Fri,  2 Dec 2016 17:35:20 +0100	[thread overview]
Message-ID: <20161202163520.22927-4-gary.bisson@boundarydevices.com> (raw)
In-Reply-To: <20161202163520.22927-1-gary.bisson@boundarydevices.com>

Currently the implementation is limited:
- can only add a new function
- if function already exists, it is discarded
- requires the dtso to know about this architecture

Another option would be to do like the pinctrl-single where each
group has its own function. Therefore it is easy to manage them.

Currently there's no easy way to add/remove groups to an existing
function.

Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com>
---
Hi all,

This implementation is far from ideal. It must be seen as a starting
point more than anything else.

The goal was to have the simplest patch possible. Here a group cannot
be added to an existing function. But a new function can be created.

There's currently no way to remove the group that has been added.

Regards,
Gary
---
 drivers/pinctrl/freescale/pinctrl-imx.c | 103 ++++++++++++++++++++++++++++++++
 1 file changed, 103 insertions(+)

diff --git a/drivers/pinctrl/freescale/pinctrl-imx.c b/drivers/pinctrl/freescale/pinctrl-imx.c
index e832a2c..5951a31 100644
--- a/drivers/pinctrl/freescale/pinctrl-imx.c
+++ b/drivers/pinctrl/freescale/pinctrl-imx.c
@@ -811,6 +811,106 @@ static void imx_free_resources(struct imx_pinctrl *ipctl)
 	imx_free_pingroups(ipctl->info);
 }
 
+#if IS_ENABLED(CONFIG_OF_DYNAMIC)
+static int imx_pinctrl_add_function(struct device_node *np,
+				    struct imx_pinctrl_soc_info *info)
+{
+	struct imx_pmx_func *func;
+	u32 i = 0;
+
+	for (i = 0; i < info->nfunctions; i++) {
+		struct imx_pmx_func *func;
+
+		func = radix_tree_lookup(&info->ftree, i);
+		if (!func)
+			continue;
+
+		if (!strcmp(func->name, np->name)) {
+			dev_err(info->dev, "function %s already exists!\n",
+				np->name);
+			return -EINVAL;
+		}
+	}
+
+	/* Create a new function */
+	func = devm_kzalloc(info->dev, sizeof(*func), GFP_KERNEL);
+	if (!func)
+		return -ENOMEM;
+
+	mutex_lock(&info->mutex);
+	radix_tree_insert(&info->ftree, info->nfunctions, func);
+	info->ngroups += of_get_child_count(np);
+	mutex_unlock(&info->mutex);
+
+	imx_pinctrl_parse_functions(np, info, info->nfunctions);
+
+	mutex_lock(&info->mutex);
+	info->nfunctions++;
+	mutex_unlock(&info->mutex);
+
+	return 0;
+}
+
+static inline struct platform_device *imx_get_device(struct device_node *np)
+{
+	struct platform_device *pdev = of_find_device_by_node(np->parent);
+
+	if (!pdev)
+		pdev = of_find_device_by_node(np->parent->parent);
+
+	return pdev;
+}
+
+static int of_pinctrl_notify(struct notifier_block *nb, unsigned long action,
+			     void *arg)
+{
+	struct of_reconfig_data *rd = arg;
+	struct platform_device *pdev;
+	struct imx_pinctrl *ipctl;
+	int ret;
+
+	/* Looking for a pinctrl group node */
+	if (!of_property_read_bool(rd->dn, "fsl,pins"))
+		return NOTIFY_OK; /* not for us */
+
+	switch (of_reconfig_get_state_change(action, rd)) {
+	case OF_RECONFIG_CHANGE_ADD:
+		pdev = imx_get_device(rd->dn);
+		if (!pdev) {
+			pr_err("%s: couldn't find device\n", __func__);
+			return NOTIFY_OK;
+		}
+
+		ipctl = dev_get_drvdata(&pdev->dev);
+		if (!pdev) {
+			dev_err(&pdev->dev, "driver data not found\n");
+			return NOTIFY_OK;
+		}
+
+		ret = imx_pinctrl_add_function(rd->dn->parent, ipctl->info);
+		if (ret < 0)
+			dev_err(&pdev->dev, "couldn't add function: %d\n", ret);
+
+		break;
+	case OF_RECONFIG_CHANGE_REMOVE:
+		pdev = imx_get_device(rd->dn);
+		if (!pdev) {
+			pr_err("%s: couldn't find device\n", __func__);
+			return NOTIFY_OK;
+		}
+		dev_err(&pdev->dev, "removing a function isn't supported\n");
+		break;
+	}
+
+	return NOTIFY_OK;
+}
+static struct notifier_block pinctrl_of_notifier = {
+	.notifier_call = of_pinctrl_notify,
+};
+#else
+extern struct notifier_block pinctrl_of_notifier;
+#endif /* CONFIG_OF_DYNAMIC */
+
 int imx_pinctrl_probe(struct platform_device *pdev,
 		      struct imx_pinctrl_soc_info *info)
 {
@@ -906,6 +1006,9 @@ int imx_pinctrl_probe(struct platform_device *pdev,
 		goto free;
 	}
 
+	if (IS_ENABLED(CONFIG_OF_DYNAMIC))
+		WARN_ON(of_reconfig_notifier_register(&pinctrl_of_notifier));
+
 	dev_info(&pdev->dev, "initialized IMX pinctrl driver\n");
 
 	return 0;
-- 
2.9.3

      parent reply	other threads:[~2016-12-02 16:35 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-24 23:38 [RFC] pinctrl: imx: use radix trees for groups and functions Gary Bisson
2016-11-30 12:48 ` Linus Walleij
2016-11-30 13:19 ` Fabio Estevam
2016-11-30 14:09   ` Gary Bisson
2016-12-02 16:35 ` [RFC v2 0/3] pinctrl: imx: add support for dt-overlays Gary Bisson
2016-12-02 16:35   ` [RFC v2 1/3] pinctrl: imx: remove const qualifier of imx_pinctrl_soc_info Gary Bisson
2016-12-29 11:23     ` Fabio Estevam
2016-12-30 13:23     ` Linus Walleij
2016-12-02 16:35   ` [RFC v2 2/3] pinctrl: imx: use radix trees for groups and functions Gary Bisson
2016-12-27 13:05     ` Linus Walleij
2016-12-27 13:11       ` Fabio Estevam
2016-12-27 22:07     ` Linus Walleij
2016-12-29  9:44       ` Gary Bisson
2016-12-30 13:21         ` Linus Walleij
2016-12-30 13:25     ` Linus Walleij
2016-12-02 16:35   ` Gary Bisson [this message]

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=20161202163520.22927-4-gary.bisson@boundarydevices.com \
    --to=gary.bisson@boundarydevices.com \
    --cc=fabio.estevam@nxp.com \
    --cc=linus.walleij@linaro.org \
    --cc=linux-gpio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pantelis.antoniou@konsulko.com \
    --cc=shawnguo@kernel.org \
    --cc=vladimir_zapolskiy@mentor.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;
as well as URLs for NNTP newsgroup(s).