summaryrefslogtreecommitdiff
path: root/arch/arm/mach-ns9xxx/include/mach/ns9xxx-pwm.h
blob: b48527482cd38d060c14a4d00066d01b9e11a9b9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/*
 * drivers/pwm/ns9xxx-pwm.h
 *
 * Copyright (C) 2009 Digi International Inc.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#ifndef __NS9XXX_PWM_HEADER_H
#define __NS9XXX_PWM_HEADER_H

/* Maximal number of available channels */
#define NS9XXX_PWM_CHANNEL_MAX		10

/* This is the data for the PWM channels */
struct ns9xxx_pwm_channel {
	int timer;
	int gpio;

	/* Additional channel configuration variables ... */
};

/* */
struct ns9xxx_pwm_pdata {
	unsigned int number_channels;
 	struct ns9xxx_pwm_channel *channels;
};




#define NS921X_TMC_T0E			(1 << 0)	/* Timer enable */
#define NS921X_TMC_T1E			(1 << 1)
#define NS921X_TMC_T2E			(1 << 2)
#define NS921X_TMC_T3E			(1 << 3)
#define NS921X_TMC_T4E			(1 << 4)
#define NS921X_TMC_T5E			(1 << 5)
#define NS921X_TMC_T6E			(1 << 6)
#define NS921X_TMC_T7E			(1 << 7)
#define NS921X_TMC_T8E			(1 << 8)
#define NS921X_TMC_T9E			(1 << 9)
#define NS921X_TMC_T6HSE		(1 << 10)	/* High step enable */
#define NS921X_TMC_T6LSE		(1 << 11)	/* Low step enable */
#define NS921X_TMC_T6RSE		(1 << 12)	/* Reload step enable */
#define NS921X_TMC_T7HSE		(1 << 13)
#define NS921X_TMC_T7LSE		(1 << 14)
#define NS921X_TMC_T7RSE		(1 << 15)
#define NS921X_TMC_T8HSE		(1 << 16)
#define NS921X_TMC_T8LSE		(1 << 17)
#define NS921X_TMC_T8RSE		(1 << 18)
#define NS921X_TMC_T9HSE		(1 << 19)
#define NS921X_TMC_T9LSE		(1 << 20)
#define NS921X_TMC_T9RSE		(1 << 21)

#define NS921X_TCR_RELOADEN		(1 << 0)	/* Reload enable */
#define NS921X_TCR_BITTIMER		(1 << 1)	/* 32 or 16 bit timer */
#define NS921X_TCR_UPDOWN		(1 << 2)	/* Up/Down select */
#define NS921X_TCR_INTSEL		(1 << 3)	/* Interrupt select */

#define NS921X_TCR_TMODE(x)		((x) & (0x3 << 4))	/* Timer mode */
#define NS921X_TCR_TMODE_MASK		(0x3 << 4)
#define NS921X_TCR_TMODE_INT            (0 << 4)
#define NS921X_TCR_TMODE_EXTLOW         (1 << 4)
#define NS921X_TCR_TMODE_EXTHIGH        (2 << 4)
/* @TODO: Complete the remaining macros */
//#define NS921X_TCR_TMODE		(2 << 4)	/* Timer mode */

#define NS921X_TCR_TCLKSEL		(0xf << 6)	/* Timer clock set */
#define NS921X_TCR_TCLKSEL_MASK		(0xf << 6)
#define NS921X_TCR_TCLKSEL_AHB		(0x1 << 6)
#define NS921X_TCR_INTCLR		(1 << 10)	/* Interrupt clear */
#define NS921X_TCR_DEBUGMODE		(1 << 11)	/* Debug mode */
#define NS921X_TCR_CAPCOMP		(7 << 12)	/* Capture and compare mode functions */
#define NS921X_TCR_TE			(1 << 15)	/* Timer enable */
#define NS921X_TCR_TMODE2		(3 << 16)	/* Timer mode 2 */
#define NS921X_TCR_TMODE2_PWM		(1 << 16)	/* Timer mode 2 */

#define NS921X_TCR_RELOADMODE2		(1 << 18)	/* Reload mode */

#define NS921X_THIGHREG			(32 << 0)	/* PWM output toggles high when timer counter reaches this value */
#define NS921X_TLOWREG			(32 << 0)	/* PWM toggles low when counter reaches this value */

#define NS921X_HISTEP_DIR		(1 << 31)	/* High step direction */
#define NS921X_HISTEP			(15 << 16)	/* High step */
#define NS921X_LOWSTEP_DIR		(1 << 15)	/* Low step direction */
#define NS921X_LOWSTEP			(15 << 0)	/* Low step */

#define NS921X_RELOADSTEPDIR		(1 << 15)	/* Reload step direction */
#define NS921X_RELOADSTEP		(15 << 0)	/* Reload step */

#define NS921X_TIMECOMP			(16 << 16)	/* Timer compare register or timer reload bits 31:16 count register */
#define NS921X_TIMERELOADBITS		(16 << 0)	/* Timer reload bits 15:00 count register */

#define NS921X_TIMERCAP			(16 << 16)	/* Timer capture register or timer read bits 31:16 register */
#define NS921X_TIMERREAD		(16 << 0)	/* Timer read bits 15:00 register */



#if 0
struct pwm_channel {
	void __iomem	*regs;
	unsigned	index;
	unsigned long	mck;
};

extern int pwm_channel_alloc(int index, struct pwm_channel *ch);
extern int pwm_channel_free(struct pwm_channel *ch);

extern int pwm_clk_alloc(unsigned prescale, unsigned div);
extern void pwm_clk_free(unsigned clk);

extern int __pwm_channel_onoff(struct pwm_channel *ch, int enabled);

#define pwm_channel_enable(ch)	__pwm_channel_onoff((ch), 1)
#define pwm_channel_disable(ch)	__pwm_channel_onoff((ch), 0)

/* periodic interrupts, mostly for CUPD changes to period or cycle */
extern int pwm_channel_handler(struct pwm_channel *ch,
		void (*handler)(struct pwm_channel *ch));

static inline void
pwm_channel_writel(struct pwm_channel *pwmc, unsigned offset, u32 val)
{
	__raw_writel(val, pwmc->regs + offset);
}

static inline u32 pwm_channel_readl(struct pwm_channel *pwmc, unsigned offset)
{
	return __raw_readl(pwmc->regs + offset);
}

#endif /* __LINUX_NS9XXX_PWM_H */

#endif /* __NS9XXX_PWM_HEADER_H */