Merge tag 'v4.12-rc3' into for-linus
[linux-2.6-block.git] / drivers / clk / ti / clkt_iclk.c
CommitLineData
530e544f
PW
1/*
2 * OMAP2/3 interface clock control
3 *
4 * Copyright (C) 2011 Nokia Corporation
5 * Paul Walmsley
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11#undef DEBUG
12
13#include <linux/kernel.h>
32cc0021 14#include <linux/clk-provider.h>
530e544f 15#include <linux/io.h>
ef14db09 16#include <linux/clk/ti.h>
530e544f 17
530e544f 18#include "clock.h"
acd052bb
TK
19
20/* Register offsets */
d5a04ddd 21#define OMAP24XX_CM_FCLKEN2 0x04
acd052bb
TK
22#define CM_AUTOIDLE 0x30
23#define CM_ICLKEN 0x10
d5a04ddd
TK
24#define CM_IDLEST 0x20
25
26#define OMAP24XX_CM_IDLEST_VAL 0
530e544f
PW
27
28/* Private functions */
29
30/* XXX */
b4777a21 31void omap2_clkt_iclk_allow_idle(struct clk_hw_omap *clk)
530e544f 32{
519ab8b2 33 u32 v;
6c0afb50 34 struct clk_omap_reg r;
530e544f 35
6c0afb50
TK
36 memcpy(&r, &clk->enable_reg, sizeof(r));
37 r.offset ^= (CM_AUTOIDLE ^ CM_ICLKEN);
530e544f 38
6c0afb50 39 v = ti_clk_ll_ops->clk_readl(&r);
530e544f 40 v |= (1 << clk->enable_bit);
6c0afb50 41 ti_clk_ll_ops->clk_writel(v, &r);
530e544f
PW
42}
43
44/* XXX */
b4777a21 45void omap2_clkt_iclk_deny_idle(struct clk_hw_omap *clk)
530e544f 46{
519ab8b2 47 u32 v;
6c0afb50 48 struct clk_omap_reg r;
530e544f 49
6c0afb50 50 memcpy(&r, &clk->enable_reg, sizeof(r));
530e544f 51
6c0afb50
TK
52 r.offset ^= (CM_AUTOIDLE ^ CM_ICLKEN);
53
54 v = ti_clk_ll_ops->clk_readl(&r);
530e544f 55 v &= ~(1 << clk->enable_bit);
6c0afb50 56 ti_clk_ll_ops->clk_writel(v, &r);
530e544f
PW
57}
58
d5a04ddd
TK
59/**
60 * omap2430_clk_i2chs_find_idlest - return CM_IDLEST info for 2430 I2CHS
61 * @clk: struct clk * being enabled
62 * @idlest_reg: void __iomem ** to store CM_IDLEST reg address into
63 * @idlest_bit: pointer to a u8 to store the CM_IDLEST bit shift into
64 * @idlest_val: pointer to a u8 to store the CM_IDLEST indicator
65 *
66 * OMAP2430 I2CHS CM_IDLEST bits are in CM_IDLEST1_CORE, but the
67 * CM_*CLKEN bits are in CM_{I,F}CLKEN2_CORE. This custom function
68 * passes back the correct CM_IDLEST register address for I2CHS
69 * modules. No return value.
70 */
71static void omap2430_clk_i2chs_find_idlest(struct clk_hw_omap *clk,
6c0afb50 72 struct clk_omap_reg *idlest_reg,
d5a04ddd
TK
73 u8 *idlest_bit,
74 u8 *idlest_val)
75{
6c0afb50
TK
76 memcpy(idlest_reg, &clk->enable_reg, sizeof(*idlest_reg));
77 idlest_reg->offset ^= (OMAP24XX_CM_FCLKEN2 ^ CM_IDLEST);
d5a04ddd
TK
78 *idlest_bit = clk->enable_bit;
79 *idlest_val = OMAP24XX_CM_IDLEST_VAL;
80}
81
530e544f
PW
82/* Public data */
83
b4777a21
RN
84const struct clk_hw_omap_ops clkhwops_iclk = {
85 .allow_idle = omap2_clkt_iclk_allow_idle,
86 .deny_idle = omap2_clkt_iclk_deny_idle,
87};
88
32cc0021
MT
89const struct clk_hw_omap_ops clkhwops_iclk_wait = {
90 .allow_idle = omap2_clkt_iclk_allow_idle,
91 .deny_idle = omap2_clkt_iclk_deny_idle,
92 .find_idlest = omap2_clk_dflt_find_idlest,
93 .find_companion = omap2_clk_dflt_find_companion,
94};
d5a04ddd
TK
95
96/* 2430 I2CHS has non-standard IDLEST register */
97const struct clk_hw_omap_ops clkhwops_omap2430_i2chs_wait = {
98 .find_idlest = omap2430_clk_i2chs_find_idlest,
99 .find_companion = omap2_clk_dflt_find_companion,
100};