linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mtd: nand: atmel_nand: retrieve NFC clock
@ 2014-09-11 14:43 Alexandre Belloni
  2014-09-11 15:20 ` Ezequiel Garcia
  0 siblings, 1 reply; 4+ messages in thread
From: Alexandre Belloni @ 2014-09-11 14:43 UTC (permalink / raw)
  To: linux-arm-kernel

From: Boris BREZILLON <boris.brezillon@free-electrons.com>

Signed-off-by: Boris BREZILLON <boris.brezillon@free-electrons.com>
---
 drivers/mtd/nand/atmel_nand.c | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 9c5f717bda54..ba64b1c91314 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -27,6 +27,7 @@
  *
  */
 
+#include <linux/clk.h>
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
 #include <linux/module.h>
@@ -96,6 +97,8 @@ struct atmel_nfc {
 	bool			use_nfc_sram;
 	bool			write_by_sram;
 
+	struct clk		*clk;
+
 	bool			is_initialized;
 	struct completion	comp_ready;
 	struct completion	comp_cmd_done;
@@ -2248,6 +2251,7 @@ static int atmel_nand_nfc_probe(struct platform_device *pdev)
 {
 	struct atmel_nfc *nfc = &nand_nfc;
 	struct resource *nfc_cmd_regs, *nfc_hsmc_regs, *nfc_sram;
+	int ret;
 
 	nfc_cmd_regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	nfc->base_cmd_regs = devm_ioremap_resource(&pdev->dev, nfc_cmd_regs);
@@ -2276,6 +2280,16 @@ static int atmel_nand_nfc_probe(struct platform_device *pdev)
 		}
 	}
 
+	nfc->clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(nfc->clk)) {
+		dev_warn(&pdev->dev, "NFC clock is missing");
+		return 0;
+	}
+
+	ret = clk_prepare_enable(nfc->clk);
+	if (ret)
+		return ret;
+
 	nfc_writel(nfc->hsmc_regs, IDR, 0xffffffff);
 	nfc_readl(nfc->hsmc_regs, SR);	/* clear the NFC_SR */
 
@@ -2284,6 +2298,16 @@ static int atmel_nand_nfc_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static int atmel_nand_nfc_remove(struct platform_device *pdev)
+{
+	struct atmel_nfc *nfc = &nand_nfc;
+
+	if (!IS_ERR(nfc->clk))
+		clk_disable_unprepare(nfc->clk);
+
+	return 0;
+}
+
 static const struct of_device_id atmel_nand_nfc_match[] = {
 	{ .compatible = "atmel,sama5d3-nfc" },
 	{ /* sentinel */ }
@@ -2297,6 +2321,7 @@ static struct platform_driver atmel_nand_nfc_driver = {
 		.of_match_table = of_match_ptr(atmel_nand_nfc_match),
 	},
 	.probe = atmel_nand_nfc_probe,
+	.remove = atmel_nand_nfc_remove,
 };
 
 static struct platform_driver atmel_nand_driver = {
-- 
1.9.1

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH] mtd: nand: atmel_nand: retrieve NFC clock
  2014-09-11 14:43 [PATCH] mtd: nand: atmel_nand: retrieve NFC clock Alexandre Belloni
@ 2014-09-11 15:20 ` Ezequiel Garcia
  2014-09-11 15:38   ` Boris BREZILLON
  0 siblings, 1 reply; 4+ messages in thread
From: Ezequiel Garcia @ 2014-09-11 15:20 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Alexandre,

On 11 Sep 04:43 PM, Alexandre Belloni wrote:
> @@ -2276,6 +2280,16 @@ static int atmel_nand_nfc_probe(struct platform_device *pdev)
>  		}
>  	}
>  
> +	nfc->clk = devm_clk_get(&pdev->dev, NULL);
> +	if (IS_ERR(nfc->clk)) {
> +		dev_warn(&pdev->dev, "NFC clock is missing");
> +		return 0;
> +	}
> +

The binding documentation makes no mention to a clock.

Anyway, with or without the docs I think this patch breaks DT backward
compatibility.

Or am I missing something?
-- 
Ezequiel Garc?a, Free Electrons
Embedded Linux, Kernel and Android Engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] mtd: nand: atmel_nand: retrieve NFC clock
  2014-09-11 15:20 ` Ezequiel Garcia
@ 2014-09-11 15:38   ` Boris BREZILLON
  2014-09-11 22:05     ` Thomas Petazzoni
  0 siblings, 1 reply; 4+ messages in thread
From: Boris BREZILLON @ 2014-09-11 15:38 UTC (permalink / raw)
  To: linux-arm-kernel

Hi Ezequiel,

On Thu, 11 Sep 2014 12:20:30 -0300
Ezequiel Garcia <ezequiel.garcia@free-electrons.com> wrote:

> Hi Alexandre,
> 
> On 11 Sep 04:43 PM, Alexandre Belloni wrote:
> > @@ -2276,6 +2280,16 @@ static int atmel_nand_nfc_probe(struct platform_device *pdev)
> >  		}
> >  	}
> >  
> > +	nfc->clk = devm_clk_get(&pdev->dev, NULL);
> > +	if (IS_ERR(nfc->clk)) {
> > +		dev_warn(&pdev->dev, "NFC clock is missing");
> > +		return 0;
> > +	}
> > +
> 
> The binding documentation makes no mention to a clock.

You're right, I didn't update atmel,nand DT binding doc.

> 
> Anyway, with or without the docs I think this patch breaks DT backward
> compatibility.
> 
> Or am I missing something?

Indeed, this block of code should be placed at the end of the probe
function. I'll fix that.

Note that if the clk is missing it just print a warning message and
return 0, so after moving the code, it should not break DT backward
compat ;-).

Best Regards,

Boris
-- 
Boris Brezillon, Free Electrons
Embedded Linux and Kernel engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH] mtd: nand: atmel_nand: retrieve NFC clock
  2014-09-11 15:38   ` Boris BREZILLON
@ 2014-09-11 22:05     ` Thomas Petazzoni
  0 siblings, 0 replies; 4+ messages in thread
From: Thomas Petazzoni @ 2014-09-11 22:05 UTC (permalink / raw)
  To: linux-arm-kernel

Dear Boris BREZILLON,

On Thu, 11 Sep 2014 17:38:54 +0200, Boris BREZILLON wrote:

> > Anyway, with or without the docs I think this patch breaks DT backward
> > compatibility.
> > 
> > Or am I missing something?
> 
> Indeed, this block of code should be placed at the end of the probe
> function. I'll fix that.
> 
> Note that if the clk is missing it just print a warning message and
> return 0, so after moving the code, it should not break DT backward
> compat ;-).

You may want to use:

	dev_warn(FW_WARN "NFC clock missing, update your Device	Tree\n");

Thomas
-- 
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2014-09-11 22:05 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-09-11 14:43 [PATCH] mtd: nand: atmel_nand: retrieve NFC clock Alexandre Belloni
2014-09-11 15:20 ` Ezequiel Garcia
2014-09-11 15:38   ` Boris BREZILLON
2014-09-11 22:05     ` Thomas Petazzoni

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).