From patchwork Thu May 1 09:56:16 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lee Jones X-Patchwork-Id: 29452 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ve0-f198.google.com (mail-ve0-f198.google.com [209.85.128.198]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 4DF87203F3 for ; Thu, 1 May 2014 09:57:26 +0000 (UTC) Received: by mail-ve0-f198.google.com with SMTP id oz11sf10141324veb.1 for ; Thu, 01 May 2014 02:57:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :list-post:list-help:list-archive:list-unsubscribe; bh=+FoZ/6nYXmZZfTUIDit5bwdr6HtoYGxjXdjzKMvbwyo=; b=gBSXLjVPeHrkrHCYayf+6KPJt4PI/fozSn7V7GxilDVyrBD2fvwkaTOB1f6QqIJrI+ J1cSv8RC41CkS7TENCfH4heHRV3mRzKSfWbHU5MPjxoMLfBdrqEYjMF0lIe/RaE5uTqF hEVOkSUh+2PYI8OTcb6fcgBrpHIUkqobqLDcY3AMdXEpZnLJmMFNClKCcv3ecb6E4H/u DkmnScEhuc4w1voo2NPSKN55hPHvGG8bvfifSjWtl6F6Rmx42P3jx1itmyp/RKKz61Tz cnpsYxNFR5nbMGFe23j8UJWZDnrUMqQYtrovd7vxZd79L/rGAh+SjpazDLH/xvdm7yVe lBRA== X-Gm-Message-State: ALoCoQnwgi1gZYT2/L3YfJZmsH6xLmZ/+EvwPN0DzVXMd1OaN9jfux4jxOqzTn88WN+OZJbjDRWD X-Received: by 10.236.36.33 with SMTP id v21mr4099525yha.53.1398938246042; Thu, 01 May 2014 02:57:26 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.42.20 with SMTP id b20ls997482qga.5.gmail; Thu, 01 May 2014 02:57:25 -0700 (PDT) X-Received: by 10.58.187.9 with SMTP id fo9mr8129609vec.4.1398938245915; Thu, 01 May 2014 02:57:25 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id v2si5960986vet.142.2014.05.01.02.57.25 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:25 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id oz11so3603357veb.6 for ; Thu, 01 May 2014 02:57:25 -0700 (PDT) X-Received: by 10.58.46.207 with SMTP id x15mr8411750vem.17.1398938245848; Thu, 01 May 2014 02:57:25 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.220.221.72 with SMTP id ib8csp12894vcb; Thu, 1 May 2014 02:57:25 -0700 (PDT) X-Received: by 10.194.1.242 with SMTP id 18mr8392948wjp.22.1398938245016; Thu, 01 May 2014 02:57:25 -0700 (PDT) Received: from mail-we0-f178.google.com (mail-we0-f178.google.com [74.125.82.178]) by mx.google.com with ESMTPS id r7si10526722wjw.198.2014.05.01.02.57.24 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:25 -0700 (PDT) Received-SPF: none (google.com: lee.jones@linaro.org does not designate permitted sender hosts) client-ip=74.125.82.178; Received: by mail-we0-f178.google.com with SMTP id u56so1954891wes.23 for ; Thu, 01 May 2014 02:57:24 -0700 (PDT) X-Received: by 10.180.188.134 with SMTP id ga6mr1490874wic.58.1398938244516; Thu, 01 May 2014 02:57:24 -0700 (PDT) Received: from lee--X1.home (host109-148-238-223.range109-148.btcentralplus.com. [109.148.238.223]) by mx.google.com with ESMTPSA id bj5sm2696494wib.3.2014.05.01.02.57.22 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 01 May 2014 02:57:23 -0700 (PDT) From: Lee Jones To: linux-kernel@vger.kernel.org Cc: computersforpeace@gmail.com, linux-mtd@lists.infradead.org, kernel@stlinux.com, Lee Jones Subject: [PATCH 09/47] mtd: nand: stm_nand_bch: supply clock support Date: Thu, 1 May 2014 10:56:16 +0100 Message-Id: <1398938214-17847-10-git-send-email-lee.jones@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1398938214-17847-1-git-send-email-lee.jones@linaro.org> References: <1398938214-17847-1-git-send-email-lee.jones@linaro.org> X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lee.jones@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 --- 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 62a41de..8e28da0 100644 --- a/drivers/mtd/nand/stm_nand_bch.c +++ b/drivers/mtd/nand/stm_nand_bch.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -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 */ @@ -270,6 +274,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__); @@ -384,6 +426,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; @@ -413,6 +458,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; }