2 * This file is subject to the terms and conditions of the GNU General Public
3 * License. See the file "COPYING" in the main directory of this archive
6 * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
9 #include <linux/module.h>
10 #include <linux/mutex.h>
11 #include <linux/err.h>
12 #include <linux/clk.h>
13 #include <bcm63xx_cpu.h>
14 #include <bcm63xx_io.h>
15 #include <bcm63xx_regs.h>
16 #include <bcm63xx_clk.h>
18 DEFINE_MUTEX(clocks_mutex
);
21 static void clk_enable_unlocked(struct clk
*clk
)
23 if (clk
->set
&& (clk
->usage
++) == 0)
27 static void clk_disable_unlocked(struct clk
*clk
)
29 if (clk
->set
&& (--clk
->usage
) == 0)
33 static void bcm_hwclock_set(u32 mask
, int enable
)
37 reg
= bcm_perf_readl(PERF_CKCTL_REG
);
42 bcm_perf_writel(reg
, PERF_CKCTL_REG
);
46 * Ethernet MAC "misc" clock: dma clocks and main clock on 6348
48 static void enet_misc_set(struct clk
*clk
, int enable
)
53 mask
= CKCTL_6348_ENET_EN
;
56 mask
= CKCTL_6358_EMUSB_EN
;
57 bcm_hwclock_set(mask
, enable
);
60 static struct clk clk_enet_misc
= {
65 * Ethernet MAC clocks: only revelant on 6358, silently enable misc
68 static void enetx_set(struct clk
*clk
, int enable
)
71 clk_enable_unlocked(&clk_enet_misc
);
73 clk_disable_unlocked(&clk_enet_misc
);
75 if (BCMCPU_IS_6358()) {
79 mask
= CKCTL_6358_ENET0_EN
;
81 mask
= CKCTL_6358_ENET1_EN
;
82 bcm_hwclock_set(mask
, enable
);
86 static struct clk clk_enet0
= {
91 static struct clk clk_enet1
= {
99 static void ephy_set(struct clk
*clk
, int enable
)
101 if (!BCMCPU_IS_6358())
103 bcm_hwclock_set(CKCTL_6358_EPHY_EN
, enable
);
107 static struct clk clk_ephy
= {
114 static void pcm_set(struct clk
*clk
, int enable
)
116 if (!BCMCPU_IS_6358())
118 bcm_hwclock_set(CKCTL_6358_PCM_EN
, enable
);
121 static struct clk clk_pcm
= {
128 static void usbh_set(struct clk
*clk
, int enable
)
130 if (!BCMCPU_IS_6348())
132 bcm_hwclock_set(CKCTL_6348_USBH_EN
, enable
);
135 static struct clk clk_usbh
= {
142 static void usbs_set(struct clk
*clk
, int enable
)
146 switch(bcm63xx_get_cpu_id()) {
147 case BCM6338_CPU_ID
: mask
= CKCTL_6338_USBS_EN
; break;
148 case BCM6348_CPU_ID
: mask
= CKCTL_6348_USBS_EN
; break;
152 bcm_hwclock_set(mask
, enable
);
155 static struct clk clk_usbs
= {
162 static void spi_set(struct clk
*clk
, int enable
)
166 if (BCMCPU_IS_6348())
167 mask
= CKCTL_6348_SPI_EN
;
170 mask
= CKCTL_6358_SPI_EN
;
171 bcm_hwclock_set(mask
, enable
);
174 static struct clk clk_spi
= {
179 * Internal peripheral clock
181 static struct clk clk_periph
= {
182 .rate
= (50 * 1000 * 1000),
187 * Linux clock API implementation
189 int clk_enable(struct clk
*clk
)
191 mutex_lock(&clocks_mutex
);
192 clk_enable_unlocked(clk
);
193 mutex_unlock(&clocks_mutex
);
197 EXPORT_SYMBOL(clk_enable
);
199 void clk_disable(struct clk
*clk
)
201 mutex_lock(&clocks_mutex
);
202 clk_disable_unlocked(clk
);
203 mutex_unlock(&clocks_mutex
);
206 EXPORT_SYMBOL(clk_disable
);
208 unsigned long clk_get_rate(struct clk
*clk
)
213 EXPORT_SYMBOL(clk_get_rate
);
215 struct clk
*clk_get(struct device
*dev
, const char *id
)
217 if (!strcmp(id
, "enet0"))
219 if (!strcmp(id
, "enet1"))
221 if (!strcmp(id
, "ephy"))
223 if (!strcmp(id
, "usbh"))
225 if (!strcmp(id
, "usbs"))
227 if (!strcmp(id
, "spi"))
229 if (!strcmp(id
, "periph"))
231 if (BCMCPU_IS_6358() && !strcmp(id
, "pcm"))
233 return ERR_PTR(-ENOENT
);
236 EXPORT_SYMBOL(clk_get
);
238 void clk_put(struct clk
*clk
)
242 EXPORT_SYMBOL(clk_put
);
This page took 0.053266 seconds and 5 git commands to generate.