diff mbox series

[V5,1/1] gpio: vf610: add optional clock support

Message ID 1541426614-17299-1-git-send-email-aisheng.dong@nxp.com
State New
Headers show
Series [V5,1/1] gpio: vf610: add optional clock support | expand

Commit Message

Dong Aisheng Nov. 5, 2018, 2:08 p.m. UTC
Some SoCs need the gpio clock to be enabled before accessing
HW registers. This patch add the optional clock handling.

Cc: Linus Walleij <linus.walleij@linaro.org>
Cc: Stefan Agner <stefan@agner.ch>
Cc: Shawn Guo <shawnguo@kernel.org>
Cc: linux-gpio@vger.kernel.org
Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
---
v4->v5:
 * refine gpio clk get
 * add remove
v3->v4: no changes
v2->v3:
 * error checking updated according to Russell's suggestion:
   ptr == ERR_PTR(-EPROBE_DEFER)
 * clock independently checking
v1->v2:
 * new patch
---
 drivers/gpio/gpio-vf610.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)

Comments

Linus Walleij Nov. 9, 2018, 9:53 a.m. UTC | #1
On Mon, Nov 5, 2018 at 3:08 PM A.s. Dong <aisheng.dong@nxp.com> wrote:

> Some SoCs need the gpio clock to be enabled before accessing
> HW registers. This patch add the optional clock handling.
>
> Cc: Linus Walleij <linus.walleij@linaro.org>
> Cc: Stefan Agner <stefan@agner.ch>
> Cc: Shawn Guo <shawnguo@kernel.org>
> Cc: linux-gpio@vger.kernel.org
> Signed-off-by: Dong Aisheng <aisheng.dong@nxp.com>
> ---
> v4->v5:
>  * refine gpio clk get
>  * add remove

This looks good but doesn't apply to the GPIO "devel" branch
for some reason:

$ git am --signoff dong1.patch
Applying: gpio: vf610: add optional clock support
error: patch failed: drivers/gpio/gpio-vf610.c:16
error: drivers/gpio/gpio-vf610.c: patch does not apply
Patch failed at 0001 gpio: vf610: add optional clock support
Use 'git am --show-current-patch' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

$ patch -p1 < dong1.patch
patching file drivers/gpio/gpio-vf610.c
Hunk #1 succeeded at 7 with fuzz 2 (offset -9 lines).
Hunk #2 FAILED at 42.
patch: **** malformed patch at line 136: ev)

Can you check and rebase/resend?

Yours,
Linus Walleij
Dong Aisheng Nov. 10, 2018, 2:25 p.m. UTC | #2
[...]
> 
> This looks good but doesn't apply to the GPIO "devel" branch for some reason:
> 
> $ git am --signoff dong1.patch
> Applying: gpio: vf610: add optional clock support
> error: patch failed: drivers/gpio/gpio-vf610.c:16
> error: drivers/gpio/gpio-vf610.c: patch does not apply Patch failed at 0001
> gpio: vf610: add optional clock support Use 'git am --show-current-patch' to
> see the failed patch When you have resolved this problem, run "git am
> --continue".
> If you prefer to skip this patch, run "git am --skip" instead.
> To restore the original branch and stop patching, run "git am --abort".
> 
> $ patch -p1 < dong1.patch
> patching file drivers/gpio/gpio-vf610.c
> Hunk #1 succeeded at 7 with fuzz 2 (offset -9 lines).
> Hunk #2 FAILED at 42.
> patch: **** malformed patch at line 136: ev)
> 
> Can you check and rebase/resend?

Thanks for reporting this. I just resent the patch after rebase against gpio tree.
Sorry for the inconvenience.
Please let me know if any issue.

Regards
Dong Aisheng
> 
> Yours,
> Linus Walleij
diff mbox series

Patch

diff --git a/drivers/gpio/gpio-vf610.c b/drivers/gpio/gpio-vf610.c
index d4ad6d0..23fdb77 100644
--- a/drivers/gpio/gpio-vf610.c
+++ b/drivers/gpio/gpio-vf610.c
@@ -16,6 +16,7 @@ 
  */
 
 #include <linux/bitops.h>
+#include <linux/clk.h>
 #include <linux/err.h>
 #include <linux/gpio.h>
 #include <linux/init.h>
@@ -41,6 +42,8 @@  struct vf610_gpio_port {
 	void __iomem *gpio_base;
 	const struct fsl_gpio_soc_data *sdata;
 	u8 irqc[VF610_GPIO_PER_PORT];
+	struct clk *clk_port;
+	struct clk *clk_gpio;
 	int irq;
 };
 
@@ -280,6 +283,33 @@  static int vf610_gpio_probe(struct platform_device *pdev)
 	if (port->irq < 0)
 		return port->irq;
 
+	port->clk_port = devm_clk_get(&pdev->dev, "port");
+	if (!IS_ERR(port->clk_port)) {
+		ret = clk_prepare_enable(port->clk_port);
+		if (ret)
+			return ret;
+	} else if (port->clk_port == ERR_PTR(-EPROBE_DEFER)) {
+		/*
+		 * Percolate deferrals, for anything else,
+		 * just live without the clocking.
+		 */
+		return PTR_ERR(port->clk_port);
+	}
+
+	port->clk_gpio = devm_clk_get(&pdev->dev, "gpio");
+	if (!IS_ERR(port->clk_gpio)) {
+		ret = clk_prepare_enable(port->clk_gpio);
+		if (ret) {
+			clk_disable_unprepare(port->clk_port);
+			return ret;
+		}
+	} else if (port->clk_gpio == ERR_PTR(-EPROBE_DEFER)) {
+		clk_disable_unprepare(port->clk_port);
+		return PTR_ERR(port->clk_gpio);
+	}
+
+	platform_set_drvdata(pdev, port);
+
 	gc = &port->gc;
 	gc->of_node = np;
 	gc->parent = dev;
@@ -314,12 +344,26 @@  static int vf610_gpio_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static int vf610_gpio_remove(struct platform_device *pdev)
+{
+	struct vf610_gpio_port *port = platform_get_drvdata(pdev);
+
+	gpiochip_remove(&port->gc);
+	if (!IS_ERR(port->clk_port))
+		clk_disable_unprepare(port->clk_port);
+	if (!IS_ERR(port->clk_gpio))
+		clk_disable_unprepare(port->clk_gpio);
+
+	return 0;
+}
+
 static struct platform_driver vf610_gpio_driver = {
 	.driver		= {
 		.name	= "gpio-vf610",
 		.of_match_table = vf610_gpio_dt_ids,
 	},
 	.probe		= vf610_gpio_probe,
+	.remove		= vf610_gpio_remove,
 };
 
 builtin_platform_driver(vf610_gpio_driver);