162306a36Sopenharmony_ci/*
262306a36Sopenharmony_ci * OMAP Dual-Mode Timers
362306a36Sopenharmony_ci *
462306a36Sopenharmony_ci * Copyright (C) 2010 Texas Instruments Incorporated - https://www.ti.com/
562306a36Sopenharmony_ci * Tarun Kanti DebBarma <tarun.kanti@ti.com>
662306a36Sopenharmony_ci * Thara Gopinath <thara@ti.com>
762306a36Sopenharmony_ci *
862306a36Sopenharmony_ci * Platform device conversion and hwmod support.
962306a36Sopenharmony_ci *
1062306a36Sopenharmony_ci * Copyright (C) 2005 Nokia Corporation
1162306a36Sopenharmony_ci * Author: Lauri Leukkunen <lauri.leukkunen@nokia.com>
1262306a36Sopenharmony_ci * PWM and clock framwork support by Timo Teras.
1362306a36Sopenharmony_ci *
1462306a36Sopenharmony_ci * This program is free software; you can redistribute it and/or modify it
1562306a36Sopenharmony_ci * under the terms of the GNU General Public License as published by the
1662306a36Sopenharmony_ci * Free Software Foundation; either version 2 of the License, or (at your
1762306a36Sopenharmony_ci * option) any later version.
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
2062306a36Sopenharmony_ci * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
2162306a36Sopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
2262306a36Sopenharmony_ci * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2362306a36Sopenharmony_ci * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2462306a36Sopenharmony_ci * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2562306a36Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2662306a36Sopenharmony_ci * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2762306a36Sopenharmony_ci *
2862306a36Sopenharmony_ci * You should have received a copy of the  GNU General Public License along
2962306a36Sopenharmony_ci * with this program; if not, write  to the Free Software Foundation, Inc.,
3062306a36Sopenharmony_ci * 675 Mass Ave, Cambridge, MA 02139, USA.
3162306a36Sopenharmony_ci */
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ci#include <linux/delay.h>
3462306a36Sopenharmony_ci#include <linux/io.h>
3562306a36Sopenharmony_ci#include <linux/platform_device.h>
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ci#ifndef __CLOCKSOURCE_DMTIMER_H
3862306a36Sopenharmony_ci#define __CLOCKSOURCE_DMTIMER_H
3962306a36Sopenharmony_ci
4062306a36Sopenharmony_ci/* clock sources */
4162306a36Sopenharmony_ci#define OMAP_TIMER_SRC_SYS_CLK			0x00
4262306a36Sopenharmony_ci#define OMAP_TIMER_SRC_32_KHZ			0x01
4362306a36Sopenharmony_ci#define OMAP_TIMER_SRC_EXT_CLK			0x02
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci/* timer interrupt enable bits */
4662306a36Sopenharmony_ci#define OMAP_TIMER_INT_CAPTURE			(1 << 2)
4762306a36Sopenharmony_ci#define OMAP_TIMER_INT_OVERFLOW			(1 << 1)
4862306a36Sopenharmony_ci#define OMAP_TIMER_INT_MATCH			(1 << 0)
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci/* trigger types */
5162306a36Sopenharmony_ci#define OMAP_TIMER_TRIGGER_NONE			0x00
5262306a36Sopenharmony_ci#define OMAP_TIMER_TRIGGER_OVERFLOW		0x01
5362306a36Sopenharmony_ci#define OMAP_TIMER_TRIGGER_OVERFLOW_AND_COMPARE	0x02
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_ci/* timer capabilities used in hwmod database */
5662306a36Sopenharmony_ci#define OMAP_TIMER_SECURE				0x80000000
5762306a36Sopenharmony_ci#define OMAP_TIMER_ALWON				0x40000000
5862306a36Sopenharmony_ci#define OMAP_TIMER_HAS_PWM				0x20000000
5962306a36Sopenharmony_ci#define OMAP_TIMER_NEEDS_RESET				0x10000000
6062306a36Sopenharmony_ci#define OMAP_TIMER_HAS_DSP_IRQ				0x08000000
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_cistruct omap_dm_timer {
6362306a36Sopenharmony_ci};
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ciu32 omap_dm_timer_modify_idlect_mask(u32 inputmask);
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci/*
6862306a36Sopenharmony_ci * Do not use the defines below, they are not needed. They should be only
6962306a36Sopenharmony_ci * used by dmtimer.c and sys_timer related code.
7062306a36Sopenharmony_ci */
7162306a36Sopenharmony_ci
7262306a36Sopenharmony_ci/*
7362306a36Sopenharmony_ci * The interrupt registers are different between v1 and v2 ip.
7462306a36Sopenharmony_ci * These registers are offsets from timer->iobase.
7562306a36Sopenharmony_ci */
7662306a36Sopenharmony_ci#define OMAP_TIMER_ID_OFFSET		0x00
7762306a36Sopenharmony_ci#define OMAP_TIMER_OCP_CFG_OFFSET	0x10
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci#define OMAP_TIMER_V1_SYS_STAT_OFFSET	0x14
8062306a36Sopenharmony_ci#define OMAP_TIMER_V1_STAT_OFFSET	0x18
8162306a36Sopenharmony_ci#define OMAP_TIMER_V1_INT_EN_OFFSET	0x1c
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci#define OMAP_TIMER_V2_IRQSTATUS_RAW	0x24
8462306a36Sopenharmony_ci#define OMAP_TIMER_V2_IRQSTATUS		0x28
8562306a36Sopenharmony_ci#define OMAP_TIMER_V2_IRQENABLE_SET	0x2c
8662306a36Sopenharmony_ci#define OMAP_TIMER_V2_IRQENABLE_CLR	0x30
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci/*
8962306a36Sopenharmony_ci * The functional registers have a different base on v1 and v2 ip.
9062306a36Sopenharmony_ci * These registers are offsets from timer->func_base. The func_base
9162306a36Sopenharmony_ci * is samae as io_base for v1 and io_base + 0x14 for v2 ip.
9262306a36Sopenharmony_ci *
9362306a36Sopenharmony_ci */
9462306a36Sopenharmony_ci#define OMAP_TIMER_V2_FUNC_OFFSET		0x14
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ci#define _OMAP_TIMER_WAKEUP_EN_OFFSET	0x20
9762306a36Sopenharmony_ci#define _OMAP_TIMER_CTRL_OFFSET		0x24
9862306a36Sopenharmony_ci#define		OMAP_TIMER_CTRL_GPOCFG		(1 << 14)
9962306a36Sopenharmony_ci#define		OMAP_TIMER_CTRL_CAPTMODE	(1 << 13)
10062306a36Sopenharmony_ci#define		OMAP_TIMER_CTRL_PT		(1 << 12)
10162306a36Sopenharmony_ci#define		OMAP_TIMER_CTRL_TCM_LOWTOHIGH	(0x1 << 8)
10262306a36Sopenharmony_ci#define		OMAP_TIMER_CTRL_TCM_HIGHTOLOW	(0x2 << 8)
10362306a36Sopenharmony_ci#define		OMAP_TIMER_CTRL_TCM_BOTHEDGES	(0x3 << 8)
10462306a36Sopenharmony_ci#define		OMAP_TIMER_CTRL_SCPWM		(1 << 7)
10562306a36Sopenharmony_ci#define		OMAP_TIMER_CTRL_CE		(1 << 6) /* compare enable */
10662306a36Sopenharmony_ci#define		OMAP_TIMER_CTRL_PRE		(1 << 5) /* prescaler enable */
10762306a36Sopenharmony_ci#define		OMAP_TIMER_CTRL_PTV_SHIFT	2 /* prescaler value shift */
10862306a36Sopenharmony_ci#define		OMAP_TIMER_CTRL_POSTED		(1 << 2)
10962306a36Sopenharmony_ci#define		OMAP_TIMER_CTRL_AR		(1 << 1) /* auto-reload enable */
11062306a36Sopenharmony_ci#define		OMAP_TIMER_CTRL_ST		(1 << 0) /* start timer */
11162306a36Sopenharmony_ci#define _OMAP_TIMER_COUNTER_OFFSET	0x28
11262306a36Sopenharmony_ci#define _OMAP_TIMER_LOAD_OFFSET		0x2c
11362306a36Sopenharmony_ci#define _OMAP_TIMER_TRIGGER_OFFSET	0x30
11462306a36Sopenharmony_ci#define _OMAP_TIMER_WRITE_PEND_OFFSET	0x34
11562306a36Sopenharmony_ci#define		WP_NONE			0	/* no write pending bit */
11662306a36Sopenharmony_ci#define		WP_TCLR			(1 << 0)
11762306a36Sopenharmony_ci#define		WP_TCRR			(1 << 1)
11862306a36Sopenharmony_ci#define		WP_TLDR			(1 << 2)
11962306a36Sopenharmony_ci#define		WP_TTGR			(1 << 3)
12062306a36Sopenharmony_ci#define		WP_TMAR			(1 << 4)
12162306a36Sopenharmony_ci#define		WP_TPIR			(1 << 5)
12262306a36Sopenharmony_ci#define		WP_TNIR			(1 << 6)
12362306a36Sopenharmony_ci#define		WP_TCVR			(1 << 7)
12462306a36Sopenharmony_ci#define		WP_TOCR			(1 << 8)
12562306a36Sopenharmony_ci#define		WP_TOWR			(1 << 9)
12662306a36Sopenharmony_ci#define _OMAP_TIMER_MATCH_OFFSET	0x38
12762306a36Sopenharmony_ci#define _OMAP_TIMER_CAPTURE_OFFSET	0x3c
12862306a36Sopenharmony_ci#define _OMAP_TIMER_IF_CTRL_OFFSET	0x40
12962306a36Sopenharmony_ci#define _OMAP_TIMER_CAPTURE2_OFFSET		0x44	/* TCAR2, 34xx only */
13062306a36Sopenharmony_ci#define _OMAP_TIMER_TICK_POS_OFFSET		0x48	/* TPIR, 34xx only */
13162306a36Sopenharmony_ci#define _OMAP_TIMER_TICK_NEG_OFFSET		0x4c	/* TNIR, 34xx only */
13262306a36Sopenharmony_ci#define _OMAP_TIMER_TICK_COUNT_OFFSET		0x50	/* TCVR, 34xx only */
13362306a36Sopenharmony_ci#define _OMAP_TIMER_TICK_INT_MASK_SET_OFFSET	0x54	/* TOCR, 34xx only */
13462306a36Sopenharmony_ci#define _OMAP_TIMER_TICK_INT_MASK_COUNT_OFFSET	0x58	/* TOWR, 34xx only */
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci#endif /* __CLOCKSOURCE_DMTIMER_H */
137