aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/clk
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/clk')
-rw-r--r--drivers/clk/Makefile1
-rw-r--r--drivers/clk/clk-devres.c55
-rw-r--r--drivers/clk/clkdev.c45
-rw-r--r--drivers/clk/mxs/Makefile2
-rw-r--r--drivers/clk/mxs/clk-ssp.c62
5 files changed, 119 insertions, 46 deletions
diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile
index 5869ea387054..72ce247a0e8d 100644
--- a/drivers/clk/Makefile
+++ b/drivers/clk/Makefile
@@ -1,4 +1,5 @@
1# common clock types 1# common clock types
2obj-$(CONFIG_HAVE_CLK) += clk-devres.o
2obj-$(CONFIG_CLKDEV_LOOKUP) += clkdev.o 3obj-$(CONFIG_CLKDEV_LOOKUP) += clkdev.o
3obj-$(CONFIG_COMMON_CLK) += clk.o clk-fixed-rate.o clk-gate.o \ 4obj-$(CONFIG_COMMON_CLK) += clk.o clk-fixed-rate.o clk-gate.o \
4 clk-mux.o clk-divider.o clk-fixed-factor.o 5 clk-mux.o clk-divider.o clk-fixed-factor.o
diff --git a/drivers/clk/clk-devres.c b/drivers/clk/clk-devres.c
new file mode 100644
index 000000000000..8f571548870f
--- /dev/null
+++ b/drivers/clk/clk-devres.c
@@ -0,0 +1,55 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 */
6
7#include <linux/clk.h>
8#include <linux/device.h>
9#include <linux/export.h>
10#include <linux/gfp.h>
11
12static void devm_clk_release(struct device *dev, void *res)
13{
14 clk_put(*(struct clk **)res);
15}
16
17struct clk *devm_clk_get(struct device *dev, const char *id)
18{
19 struct clk **ptr, *clk;
20
21 ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL);
22 if (!ptr)
23 return ERR_PTR(-ENOMEM);
24
25 clk = clk_get(dev, id);
26 if (!IS_ERR(clk)) {
27 *ptr = clk;
28 devres_add(dev, ptr);
29 } else {
30 devres_free(ptr);
31 }
32
33 return clk;
34}
35EXPORT_SYMBOL(devm_clk_get);
36
37static int devm_clk_match(struct device *dev, void *res, void *data)
38{
39 struct clk **c = res;
40 if (!c || !*c) {
41 WARN_ON(!c || !*c);
42 return 0;
43 }
44 return *c == data;
45}
46
47void devm_clk_put(struct device *dev, struct clk *clk)
48{
49 int ret;
50
51 ret = devres_release(dev, devm_clk_release, devm_clk_match, clk);
52
53 WARN_ON(ret);
54}
55EXPORT_SYMBOL(devm_clk_put);
diff --git a/drivers/clk/clkdev.c b/drivers/clk/clkdev.c
index d423c9bdd71a..442a31363873 100644
--- a/drivers/clk/clkdev.c
+++ b/drivers/clk/clkdev.c
@@ -171,51 +171,6 @@ void clk_put(struct clk *clk)
171} 171}
172EXPORT_SYMBOL(clk_put); 172EXPORT_SYMBOL(clk_put);
173 173
174static void devm_clk_release(struct device *dev, void *res)
175{
176 clk_put(*(struct clk **)res);
177}
178
179struct clk *devm_clk_get(struct device *dev, const char *id)
180{
181 struct clk **ptr, *clk;
182
183 ptr = devres_alloc(devm_clk_release, sizeof(*ptr), GFP_KERNEL);
184 if (!ptr)
185 return ERR_PTR(-ENOMEM);
186
187 clk = clk_get(dev, id);
188 if (!IS_ERR(clk)) {
189 *ptr = clk;
190 devres_add(dev, ptr);
191 } else {
192 devres_free(ptr);
193 }
194
195 return clk;
196}
197EXPORT_SYMBOL(devm_clk_get);
198
199static int devm_clk_match(struct device *dev, void *res, void *data)
200{
201 struct clk **c = res;
202 if (!c || !*c) {
203 WARN_ON(!c || !*c);
204 return 0;
205 }
206 return *c == data;
207}
208
209void devm_clk_put(struct device *dev, struct clk *clk)
210{
211 int ret;
212
213 ret = devres_destroy(dev, devm_clk_release, devm_clk_match, clk);
214
215 WARN_ON(ret);
216}
217EXPORT_SYMBOL(devm_clk_put);
218
219void clkdev_add(struct clk_lookup *cl) 174void clkdev_add(struct clk_lookup *cl)
220{ 175{
221 mutex_lock(&clocks_mutex); 176 mutex_lock(&clocks_mutex);
diff --git a/drivers/clk/mxs/Makefile b/drivers/clk/mxs/Makefile
index 7bedeec08524..a6a22237e860 100644
--- a/drivers/clk/mxs/Makefile
+++ b/drivers/clk/mxs/Makefile
@@ -2,7 +2,7 @@
2# Makefile for mxs specific clk 2# Makefile for mxs specific clk
3# 3#
4 4
5obj-y += clk.o clk-pll.o clk-ref.o clk-div.o clk-frac.o 5obj-y += clk.o clk-pll.o clk-ref.o clk-div.o clk-frac.o clk-ssp.o
6 6
7obj-$(CONFIG_SOC_IMX23) += clk-imx23.o 7obj-$(CONFIG_SOC_IMX23) += clk-imx23.o
8obj-$(CONFIG_SOC_IMX28) += clk-imx28.o 8obj-$(CONFIG_SOC_IMX28) += clk-imx28.o
diff --git a/drivers/clk/mxs/clk-ssp.c b/drivers/clk/mxs/clk-ssp.c
new file mode 100644
index 000000000000..af7bdbf9ebd7
--- /dev/null
+++ b/drivers/clk/mxs/clk-ssp.c
@@ -0,0 +1,62 @@
1/*
2 * Copyright 2012 DENX Software Engineering, GmbH
3 *
4 * Pulled from code:
5 * Portions copyright (C) 2003 Russell King, PXA MMCI Driver
6 * Portions copyright (C) 2004-2005 Pierre Ossman, W83L51xD SD/MMC driver
7 *
8 * Copyright 2008 Embedded Alley Solutions, Inc.
9 * Copyright 2009-2011 Freescale Semiconductor, Inc.
10 *
11 * The code contained herein is licensed under the GNU General Public
12 * License. You may obtain a copy of the GNU General Public License
13 * Version 2 or later at the following locations:
14 *
15 * http://www.opensource.org/licenses/gpl-license.html
16 * http://www.gnu.org/copyleft/gpl.html
17 */
18
19#include <linux/kernel.h>
20#include <linux/init.h>
21#include <linux/clk.h>
22#include <linux/module.h>
23#include <linux/device.h>
24#include <linux/io.h>
25#include <linux/spi/mxs-spi.h>
26
27void mxs_ssp_set_clk_rate(struct mxs_ssp *ssp, unsigned int rate)
28{
29 unsigned int ssp_clk, ssp_sck;
30 u32 clock_divide, clock_rate;
31 u32 val;
32
33 ssp_clk = clk_get_rate(ssp->clk);
34
35 for (clock_divide = 2; clock_divide <= 254; clock_divide += 2) {
36 clock_rate = DIV_ROUND_UP(ssp_clk, rate * clock_divide);
37 clock_rate = (clock_rate > 0) ? clock_rate - 1 : 0;
38 if (clock_rate <= 255)
39 break;
40 }
41
42 if (clock_divide > 254) {
43 dev_err(ssp->dev,
44 "%s: cannot set clock to %d\n", __func__, rate);
45 return;
46 }
47
48 ssp_sck = ssp_clk / clock_divide / (1 + clock_rate);
49
50 val = readl(ssp->base + HW_SSP_TIMING(ssp));
51 val &= ~(BM_SSP_TIMING_CLOCK_DIVIDE | BM_SSP_TIMING_CLOCK_RATE);
52 val |= BF_SSP(clock_divide, TIMING_CLOCK_DIVIDE);
53 val |= BF_SSP(clock_rate, TIMING_CLOCK_RATE);
54 writel(val, ssp->base + HW_SSP_TIMING(ssp));
55
56 ssp->clk_rate = ssp_sck;
57
58 dev_dbg(ssp->dev,
59 "%s: clock_divide %d, clock_rate %d, ssp_clk %d, rate_actual %d, rate_requested %d\n",
60 __func__, clock_divide, clock_rate, ssp_clk, ssp_sck, rate);
61}
62EXPORT_SYMBOL_GPL(mxs_ssp_set_clk_rate);