Paul Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 1 | /* |
| 2 | * OMAP3517/3505-specific clock framework functions |
| 3 | * |
| 4 | * Copyright (C) 2010 Texas Instruments, Inc. |
Paul Walmsley | ec538e3 | 2011-02-25 15:39:30 -0700 | [diff] [blame] | 5 | * Copyright (C) 2011 Nokia Corporation |
Paul Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 6 | * |
| 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 Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 24 | #include "clock.h" |
| 25 | #include "clock3517.h" |
Paul Walmsley | ff4ae5d | 2012-10-21 01:01:11 -0600 | [diff] [blame] | 26 | #include "cm3xxx.h" |
Paul Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 27 | #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 Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame^] | 50 | #ifdef CONFIG_COMMON_CLK |
| 51 | static void am35xx_clk_find_idlest(struct clk_hw_omap *clk, |
| 52 | #else |
Paul Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 53 | static void am35xx_clk_find_idlest(struct clk *clk, |
Rajendra Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame^] | 54 | #endif |
Paul Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 55 | 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 Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame^] | 78 | #ifdef CONFIG_COMMON_CLK |
| 79 | static void am35xx_clk_find_companion(struct clk_hw_omap *clk, |
| 80 | void __iomem **other_reg, |
| 81 | #else |
| 82 | static void am35xx_clk_find_companion(struct clk *clk, |
| 83 | void __iomem **other_reg, |
| 84 | #endif |
| 85 | u8 *other_bit) |
Paul Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 86 | { |
| 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 Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame^] | 93 | #ifdef CONFIG_COMMON_CLK |
| 94 | const 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 Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 99 | const 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 Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame^] | 105 | #endif |
Paul Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 106 | |
| 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 Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame^] | 118 | #ifdef CONFIG_COMMON_CLK |
| 119 | static void am35xx_clk_ipss_find_idlest(struct clk_hw_omap *clk, |
| 120 | #else |
Paul Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 121 | static void am35xx_clk_ipss_find_idlest(struct clk *clk, |
Rajendra Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame^] | 122 | #endif |
Paul Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 123 | 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 Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame^] | 134 | #ifdef CONFIG_COMMON_CLK |
| 135 | const 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 Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 142 | const 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 Walmsley | ec538e3 | 2011-02-25 15:39:30 -0700 | [diff] [blame] | 147 | .allow_idle = omap2_clkt_iclk_allow_idle, |
| 148 | .deny_idle = omap2_clkt_iclk_deny_idle, |
Paul Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 149 | }; |
Rajendra Nayak | b4777a2 | 2012-04-27 15:53:48 +0530 | [diff] [blame^] | 150 | #endif |
Paul Walmsley | 657ebfa | 2010-02-22 22:09:20 -0700 | [diff] [blame] | 151 | |