lkml.org 
[lkml]   [2014]   [Mar]   [25]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[RFC 08/47] mtd: nand: stm_nand_bch: supply clock support
Date
Add support for clocks when, and only when, they are supplied. It is
not yet compulsory to provide the BCH and EMI clocks, as Common Clk isn't
supported Mainline yet. Until an implementation lands upstream all clocks
located on STM boards default to always-on.

Signed-off-by: Lee Jones <lee.jones@linaro.org>
---
drivers/mtd/nand/stm_nand_bch.c | 49 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 49 insertions(+)

diff --git a/drivers/mtd/nand/stm_nand_bch.c b/drivers/mtd/nand/stm_nand_bch.c
index 1a93f8d..cc0159e 100644
--- a/drivers/mtd/nand/stm_nand_bch.c
+++ b/drivers/mtd/nand/stm_nand_bch.c
@@ -16,6 +16,7 @@
#include <linux/module.h>
#include <linux/delay.h>
#include <linux/io.h>
+#include <linux/clk.h>
#include <linux/interrupt.h>
#include <linux/device.h>
#include <linux/platform_device.h>
@@ -28,6 +29,9 @@
struct nandi_controller {
void __iomem *base; /* Controller base*/
void __iomem *dma; /* DMA control base */
+
+ struct clk *bch_clk;
+ struct clk *emi_clk;
/* IRQ-triggered Completions: */
struct completion seq_completed; /* SEQ Over */
struct completion rbn_completed; /* RBn */
@@ -103,6 +107,44 @@ static void nandi_disable_interrupts(struct nandi_controller *nandi,
writel(val, nandi->base + NANDBCH_INT_EN);
}

+static void nandi_clk_enable(struct nandi_controller *nandi)
+{
+ if (nandi->emi_clk)
+ clk_prepare_enable(nandi->emi_clk);
+ if (nandi->bch_clk)
+ clk_prepare_enable(nandi->bch_clk);
+}
+
+static void nandi_clk_disable(struct nandi_controller *nandi)
+{
+ if (nandi->emi_clk)
+ clk_disable_unprepare(nandi->emi_clk);
+ if (nandi->bch_clk)
+ clk_disable_unprepare(nandi->bch_clk);
+}
+
+static struct clk *nandi_clk_setup(struct nandi_controller *nandi,
+ char *clkname)
+{
+ struct clk *clk;
+ int ret;
+
+ clk = clk_get(nandi->dev, clkname);
+ if (IS_ERR_OR_NULL(clk)) {
+ dev_warn(nandi->dev, "Failed to get %s clock\n", clkname);
+ return NULL;
+ }
+
+ ret = clk_prepare_enable(clk);
+ if (ret) {
+ dev_warn(nandi->dev, "Failed to enable %s clock\n", clkname);
+ clk_put(clk);
+ return NULL;
+ }
+
+ return clk;
+}
+
static void nandi_init_bch(struct nandi_controller *nandi, int emi_bank)
{
dev_dbg(nandi->dev, "%s\n", __func__);
@@ -217,6 +259,9 @@ nandi_init_resources(struct platform_device *pdev)
return ERR_PTR(err);
}

+ nandi->emi_clk = nandi_clk_setup(nandi, "emi_clk");
+ nandi->bch_clk = nandi_clk_setup(nandi, "bch_clk");
+
platform_set_drvdata(pdev, nandi);

return nandi;
@@ -251,6 +296,10 @@ static int stm_nand_bch_probe(struct platform_device *pdev)

static int stm_nand_bch_remove(struct platform_device *pdev)
{
+ struct nandi_controller *nandi = platform_get_drvdata(pdev);
+
+ nandi_clk_disable(nandi);
+
return 0;
}

--
1.8.3.2


\
 
 \ /
  Last update: 2014-03-25 10:41    [W:0.328 / U:0.076 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site