blob: 467d8bc6b4aaf891e06bff2d89589a3dede0ef5f [file] [log] [blame]
Paul Walmsley657ebfa2010-02-22 22:09:20 -07001/*
2 * OMAP3517/3505-specific clock framework functions
3 *
4 * Copyright (C) 2010 Texas Instruments, Inc.
Paul Walmsleyec538e32011-02-25 15:39:30 -07005 * Copyright (C) 2011 Nokia Corporation
Paul Walmsley657ebfa2010-02-22 22:09:20 -07006 *
7 * Ranjith Lohithakshan
8 * Paul Walmsley
9 *
10 * Parts of this code are based on code written by
11 * Richard Woodruff, Tony Lindgren, Tuukka Tikkanen, Karthik Dasu,
12 * Russell King
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18#undef DEBUG
19
20#include <linux/kernel.h>
21#include <linux/clk.h>
22#include <linux/io.h>
23
Paul Walmsley657ebfa2010-02-22 22:09:20 -070024#include "clock.h"
25#include "clock3517.h"
Paul Walmsleyff4ae5d2012-10-21 01:01:11 -060026#include "cm3xxx.h"
Paul Walmsley657ebfa2010-02-22 22:09:20 -070027#include "cm-regbits-34xx.h"
28
29/*
30 * In AM35xx IPSS, the {ICK,FCK} enable bits for modules are exported
31 * in the same register at a bit offset of 0x8. The EN_ACK for ICK is
32 * at an offset of 4 from ICK enable bit.
33 */
34#define AM35XX_IPSS_ICK_MASK 0xF
35#define AM35XX_IPSS_ICK_EN_ACK_OFFSET 0x4
36#define AM35XX_IPSS_ICK_FCK_OFFSET 0x8
37#define AM35XX_IPSS_CLK_IDLEST_VAL 0
38
39/**
40 * am35xx_clk_find_idlest - return clock ACK info for AM35XX IPSS
41 * @clk: struct clk * being enabled
42 * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
43 * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
44 * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
45 *
46 * The interface clocks on AM35xx IPSS reflects the clock idle status
47 * in the enable register itsel at a bit offset of 4 from the enable
48 * bit. A value of 1 indicates that clock is enabled.
49 */
Rajendra Nayakb4777a22012-04-27 15:53:48 +053050#ifdef CONFIG_COMMON_CLK
51static void am35xx_clk_find_idlest(struct clk_hw_omap *clk,
52#else
Paul Walmsley657ebfa2010-02-22 22:09:20 -070053static void am35xx_clk_find_idlest(struct clk *clk,
Rajendra Nayakb4777a22012-04-27 15:53:48 +053054#endif
Paul Walmsley657ebfa2010-02-22 22:09:20 -070055 void __iomem **idlest_reg,
56 u8 *idlest_bit,
57 u8 *idlest_val)
58{
59 *idlest_reg = (__force void __iomem *)(clk->enable_reg);
60 *idlest_bit = clk->enable_bit + AM35XX_IPSS_ICK_EN_ACK_OFFSET;
61 *idlest_val = AM35XX_IPSS_CLK_IDLEST_VAL;
62}
63
64/**
65 * am35xx_clk_find_companion - find companion clock to @clk
66 * @clk: struct clk * to find the companion clock of
67 * @other_reg: void __iomem ** to return the companion clock CM_*CLKEN va in
68 * @other_bit: u8 ** to return the companion clock bit shift in
69 *
70 * Some clocks don't have companion clocks. For example, modules with
71 * only an interface clock (such as HECC) don't have a companion
72 * clock. Right now, this code relies on the hardware exporting a bit
73 * in the correct companion register that indicates that the
74 * nonexistent 'companion clock' is active. Future patches will
75 * associate this type of code with per-module data structures to
76 * avoid this issue, and remove the casts. No return value.
77 */
Rajendra Nayakb4777a22012-04-27 15:53:48 +053078#ifdef CONFIG_COMMON_CLK
79static void am35xx_clk_find_companion(struct clk_hw_omap *clk,
80 void __iomem **other_reg,
81#else
82static void am35xx_clk_find_companion(struct clk *clk,
83 void __iomem **other_reg,
84#endif
85 u8 *other_bit)
Paul Walmsley657ebfa2010-02-22 22:09:20 -070086{
87 *other_reg = (__force void __iomem *)(clk->enable_reg);
88 if (clk->enable_bit & AM35XX_IPSS_ICK_MASK)
89 *other_bit = clk->enable_bit + AM35XX_IPSS_ICK_FCK_OFFSET;
90 else
91 *other_bit = clk->enable_bit - AM35XX_IPSS_ICK_FCK_OFFSET;
92}
Rajendra Nayakb4777a22012-04-27 15:53:48 +053093#ifdef CONFIG_COMMON_CLK
94const struct clk_hw_omap_ops clkhwops_am35xx_ipss_module_wait = {
95 .find_idlest = am35xx_clk_find_idlest,
96 .find_companion = am35xx_clk_find_companion,
97};
98#else
Paul Walmsley657ebfa2010-02-22 22:09:20 -070099const struct clkops clkops_am35xx_ipss_module_wait = {
100 .enable = omap2_dflt_clk_enable,
101 .disable = omap2_dflt_clk_disable,
102 .find_idlest = am35xx_clk_find_idlest,
103 .find_companion = am35xx_clk_find_companion,
104};
Rajendra Nayakb4777a22012-04-27 15:53:48 +0530105#endif
Paul Walmsley657ebfa2010-02-22 22:09:20 -0700106
107/**
108 * am35xx_clk_ipss_find_idlest - return CM_IDLEST info for IPSS
109 * @clk: struct clk * being enabled
110 * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
111 * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
112 * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
113 *
114 * The IPSS target CM_IDLEST bit is at a different shift from the
115 * CM_{I,F}CLKEN bit. Pass back the correct info via @idlest_reg
116 * and @idlest_bit. No return value.
117 */
Rajendra Nayakb4777a22012-04-27 15:53:48 +0530118#ifdef CONFIG_COMMON_CLK
119static void am35xx_clk_ipss_find_idlest(struct clk_hw_omap *clk,
120#else
Paul Walmsley657ebfa2010-02-22 22:09:20 -0700121static void am35xx_clk_ipss_find_idlest(struct clk *clk,
Rajendra Nayakb4777a22012-04-27 15:53:48 +0530122#endif
Paul Walmsley657ebfa2010-02-22 22:09:20 -0700123 void __iomem **idlest_reg,
124 u8 *idlest_bit,
125 u8 *idlest_val)
126{
127 u32 r;
128
129 r = (((__force u32)clk->enable_reg & ~0xf0) | 0x20);
130 *idlest_reg = (__force void __iomem *)r;
131 *idlest_bit = AM35XX_ST_IPSS_SHIFT;
132 *idlest_val = OMAP34XX_CM_IDLEST_VAL;
133}
Rajendra Nayakb4777a22012-04-27 15:53:48 +0530134#ifdef CONFIG_COMMON_CLK
135const struct clk_hw_omap_ops clkhwops_am35xx_ipss_wait = {
136 .allow_idle = omap2_clkt_iclk_allow_idle,
137 .deny_idle = omap2_clkt_iclk_deny_idle,
138 .find_idlest = am35xx_clk_ipss_find_idlest,
139 .find_companion = omap2_clk_dflt_find_companion,
140};
141#else
Paul Walmsley657ebfa2010-02-22 22:09:20 -0700142const struct clkops clkops_am35xx_ipss_wait = {
143 .enable = omap2_dflt_clk_enable,
144 .disable = omap2_dflt_clk_disable,
145 .find_idlest = am35xx_clk_ipss_find_idlest,
146 .find_companion = omap2_clk_dflt_find_companion,
Paul Walmsleyec538e32011-02-25 15:39:30 -0700147 .allow_idle = omap2_clkt_iclk_allow_idle,
148 .deny_idle = omap2_clkt_iclk_deny_idle,
Paul Walmsley657ebfa2010-02-22 22:09:20 -0700149};
Rajendra Nayakb4777a22012-04-27 15:53:48 +0530150#endif
Paul Walmsley657ebfa2010-02-22 22:09:20 -0700151