aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Horman <horms+renesas@verge.net.au>2014-04-22 21:01:02 -0400
committerSimon Horman <horms+renesas@verge.net.au>2014-04-22 21:01:02 -0400
commit1c41ecb60b3de08d341be13de1dfc3d907b82694 (patch)
tree36918914f8925b41a52189878e097f7347bc8d69
parentd3a088d459aeb2bd8c96110958acd50875f1e731 (diff)
parent346f5e76b3822a2530a03f33b00ee89dfc463326 (diff)
Merge branch 'clockevents/cmt-mtu2-tmu-cleanups' of git://git.linaro.org/people/daniel.lezcano/linux into cmt-mtu2-tmu-cleanups-for-v3.16
-rw-r--r--drivers/clocksource/sh_cmt.c956
-rw-r--r--drivers/clocksource/sh_mtu2.c488
-rw-r--r--drivers/clocksource/sh_tmu.c541
-rw-r--r--include/linux/sh_timer.h1
4 files changed, 1306 insertions, 680 deletions
diff --git a/drivers/clocksource/sh_cmt.c b/drivers/clocksource/sh_cmt.c
index 0b1836a6c539..bc8d025ce861 100644
--- a/drivers/clocksource/sh_cmt.c
+++ b/drivers/clocksource/sh_cmt.c
@@ -11,40 +11,93 @@
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details. 13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 */ 14 */
19 15
16#include <linux/clk.h>
17#include <linux/clockchips.h>
18#include <linux/clocksource.h>
19#include <linux/delay.h>
20#include <linux/err.h>
20#include <linux/init.h> 21#include <linux/init.h>
21#include <linux/platform_device.h>
22#include <linux/spinlock.h>
23#include <linux/interrupt.h> 22#include <linux/interrupt.h>
24#include <linux/ioport.h>
25#include <linux/io.h> 23#include <linux/io.h>
26#include <linux/clk.h> 24#include <linux/ioport.h>
27#include <linux/irq.h> 25#include <linux/irq.h>
28#include <linux/err.h>
29#include <linux/delay.h>
30#include <linux/clocksource.h>
31#include <linux/clockchips.h>
32#include <linux/sh_timer.h>
33#include <linux/slab.h>
34#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/platform_device.h>
35#include <linux/pm_domain.h> 28#include <linux/pm_domain.h>
36#include <linux/pm_runtime.h> 29#include <linux/pm_runtime.h>
30#include <linux/sh_timer.h>
31#include <linux/slab.h>
32#include <linux/spinlock.h>
33
34struct sh_cmt_device;
35
36/*
37 * The CMT comes in 5 different identified flavours, depending not only on the
38 * SoC but also on the particular instance. The following table lists the main
39 * characteristics of those flavours.
40 *
41 * 16B 32B 32B-F 48B 48B-2
42 * -----------------------------------------------------------------------------
43 * Channels 2 1/4 1 6 2/8
44 * Control Width 16 16 16 16 32
45 * Counter Width 16 32 32 32/48 32/48
46 * Shared Start/Stop Y Y Y Y N
47 *
48 * The 48-bit gen2 version has a per-channel start/stop register located in the
49 * channel registers block. All other versions have a shared start/stop register
50 * located in the global space.
51 *
52 * Channels are indexed from 0 to N-1 in the documentation. The channel index
53 * infers the start/stop bit position in the control register and the channel
54 * registers block address. Some CMT instances have a subset of channels
55 * available, in which case the index in the documentation doesn't match the
56 * "real" index as implemented in hardware. This is for instance the case with
57 * CMT0 on r8a7740, which is a 32-bit variant with a single channel numbered 0
58 * in the documentation but using start/stop bit 5 and having its registers
59 * block at 0x60.
60 *
61 * Similarly CMT0 on r8a73a4, r8a7790 and r8a7791, while implementing 32-bit
62 * channels only, is a 48-bit gen2 CMT with the 48-bit channels unavailable.
63 */
64
65enum sh_cmt_model {
66 SH_CMT_16BIT,
67 SH_CMT_32BIT,
68 SH_CMT_32BIT_FAST,
69 SH_CMT_48BIT,
70 SH_CMT_48BIT_GEN2,
71};
72
73struct sh_cmt_info {
74 enum sh_cmt_model model;
37 75
38struct sh_cmt_priv {
39 void __iomem *mapbase;
40 void __iomem *mapbase_str;
41 struct clk *clk;
42 unsigned long width; /* 16 or 32 bit version of hardware block */ 76 unsigned long width; /* 16 or 32 bit version of hardware block */
43 unsigned long overflow_bit; 77 unsigned long overflow_bit;
44 unsigned long clear_bits; 78 unsigned long clear_bits;
45 struct irqaction irqaction;
46 struct platform_device *pdev;
47 79
80 /* callbacks for CMSTR and CMCSR access */
81 unsigned long (*read_control)(void __iomem *base, unsigned long offs);
82 void (*write_control)(void __iomem *base, unsigned long offs,
83 unsigned long value);
84
85 /* callbacks for CMCNT and CMCOR access */
86 unsigned long (*read_count)(void __iomem *base, unsigned long offs);
87 void (*write_count)(void __iomem *base, unsigned long offs,
88 unsigned long value);
89};
90
91struct sh_cmt_channel {
92 struct sh_cmt_device *cmt;
93
94 unsigned int index; /* Index in the documentation */
95 unsigned int hwidx; /* Real hardware index */
96
97 void __iomem *iostart;
98 void __iomem *ioctrl;
99
100 unsigned int timer_bit;
48 unsigned long flags; 101 unsigned long flags;
49 unsigned long match_value; 102 unsigned long match_value;
50 unsigned long next_match_value; 103 unsigned long next_match_value;
@@ -55,38 +108,52 @@ struct sh_cmt_priv {
55 struct clocksource cs; 108 struct clocksource cs;
56 unsigned long total_cycles; 109 unsigned long total_cycles;
57 bool cs_enabled; 110 bool cs_enabled;
111};
58 112
59 /* callbacks for CMSTR and CMCSR access */ 113struct sh_cmt_device {
60 unsigned long (*read_control)(void __iomem *base, unsigned long offs); 114 struct platform_device *pdev;
61 void (*write_control)(void __iomem *base, unsigned long offs,
62 unsigned long value);
63 115
64 /* callbacks for CMCNT and CMCOR access */ 116 const struct sh_cmt_info *info;
65 unsigned long (*read_count)(void __iomem *base, unsigned long offs); 117 bool legacy;
66 void (*write_count)(void __iomem *base, unsigned long offs, 118
67 unsigned long value); 119 void __iomem *mapbase_ch;
120 void __iomem *mapbase;
121 struct clk *clk;
122
123 struct sh_cmt_channel *channels;
124 unsigned int num_channels;
125
126 bool has_clockevent;
127 bool has_clocksource;
68}; 128};
69 129
70/* Examples of supported CMT timer register layouts and I/O access widths: 130#define SH_CMT16_CMCSR_CMF (1 << 7)
71 * 131#define SH_CMT16_CMCSR_CMIE (1 << 6)
72 * "16-bit counter and 16-bit control" as found on sh7263: 132#define SH_CMT16_CMCSR_CKS8 (0 << 0)
73 * CMSTR 0xfffec000 16-bit 133#define SH_CMT16_CMCSR_CKS32 (1 << 0)
74 * CMCSR 0xfffec002 16-bit 134#define SH_CMT16_CMCSR_CKS128 (2 << 0)
75 * CMCNT 0xfffec004 16-bit 135#define SH_CMT16_CMCSR_CKS512 (3 << 0)
76 * CMCOR 0xfffec006 16-bit 136#define SH_CMT16_CMCSR_CKS_MASK (3 << 0)
77 * 137
78 * "32-bit counter and 16-bit control" as found on sh7372, sh73a0, r8a7740: 138#define SH_CMT32_CMCSR_CMF (1 << 15)
79 * CMSTR 0xffca0000 16-bit 139#define SH_CMT32_CMCSR_OVF (1 << 14)
80 * CMCSR 0xffca0060 16-bit 140#define SH_CMT32_CMCSR_WRFLG (1 << 13)
81 * CMCNT 0xffca0064 32-bit 141#define SH_CMT32_CMCSR_STTF (1 << 12)
82 * CMCOR 0xffca0068 32-bit 142#define SH_CMT32_CMCSR_STPF (1 << 11)
83 * 143#define SH_CMT32_CMCSR_SSIE (1 << 10)
84 * "32-bit counter and 32-bit control" as found on r8a73a4 and r8a7790: 144#define SH_CMT32_CMCSR_CMS (1 << 9)
85 * CMSTR 0xffca0500 32-bit 145#define SH_CMT32_CMCSR_CMM (1 << 8)
86 * CMCSR 0xffca0510 32-bit 146#define SH_CMT32_CMCSR_CMTOUT_IE (1 << 7)
87 * CMCNT 0xffca0514 32-bit 147#define SH_CMT32_CMCSR_CMR_NONE (0 << 4)
88 * CMCOR 0xffca0518 32-bit 148#define SH_CMT32_CMCSR_CMR_DMA (1 << 4)
89 */ 149#define SH_CMT32_CMCSR_CMR_IRQ (2 << 4)