summaryrefslogtreecommitdiff
path: root/arch/arm/mach-wmt/include/mach/wmt_saradc.h
blob: 676fb59b9df74f0dcb570f5106f1a513422f1bfd (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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*++
linux/drivers/input/keyboard/wmt_kpad.c

Some descriptions of such software. Copyright (c) 2008  WonderMedia Technologies, 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, see <http://www.gnu.org/licenses/>.

WonderMedia Technologies, Inc.
10F, 529, Chung-Cheng Road, Hsin-Tien, Taipei 231, R.O.C.
--*/

#include <linux/module.h>
#include <linux/init.h>
#include <linux/interrupt.h>
#include <linux/types.h>
#include <linux/input.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/device.h>
#include <linux/platform_device.h>
#include <linux/cpufreq.h>
#include <linux/delay.h>
#include <asm/io.h>
#include <asm/irq.h>
#include <asm/errno.h>
#include <asm/mach-types.h>
#include <mach/hardware.h>
#include <linux/suspend.h>


/*=============================================================================
//
// WM3498 SARADC control registers.
//
// Registers Abbreviations:
//
// ADCCtrl0_REG  ADC Control0 Register.
//
// ADCCtrl1_REG  ADC Control1 Register.
//
// ADCCTRL2_REG  ADC Control2 Register.
//
//=============================================================================*/
/*=============================================================================
//
// Address constant for each register.
//
//============================================================================*/
#define ADCCtl0_ADDR	(ADC_BASE_ADDR + 0x00)
#define ADCCtl1_ADDR	(ADC_BASE_ADDR + 0x04)
#define ADCCtl2_ADDR	(ADC_BASE_ADDR + 0x08)

/*=============================================================================
//
// Register pointer.
//
//=============================================================================*/
#define ADCCtl0_REG		(REG32_PTR(ADCCtl0_ADDR))
#define ADCCtl1_REG		(REG32_PTR(ADCCtl1_ADDR))
#define ADCCtl2_REG		(REG32_PTR(ADCCtl2_ADDR))

/*=============================================================================
//
// Register value.
//
//=============================================================================*/
#define ADCCtl0_VAL		(REG32_VAL(ADCCtl0_ADDR))
#define ADCCtl1_VAL		(REG32_VAL(ADCCtl1_ADDR))
#define ADCCtl2_VAL		(REG32_VAL(ADCCtl2_ADDR))

/*=============================================================================
//
// ADCCtl0_REG  ADC Control0 Register.
//
//=============================================================================*/
#define TOutDlyMask         0xFFFF          /* Time Out Interrupt Delay Value */
#define TOutDly(x)          ((x) & TOutDlyMask)
#define ClrIntTOut          BIT16           /* ADC Timeout Interrupt CLEAR signal */
#define ClrIntADC           BIT17           /* ADC sample point Conversion Finished Interrupt CLEAR signal */
#define EndcIntEn           BIT18           /* ADC Conversion Finished Interrupt Enable. */
#define TOutEn              BIT19           /* Time Out Interrupt Enable. */
#define TempEn              BIT20           /* Manual output valid. */
#define AutoMode            BIT21           /* Auto mode select. */
#define SDataSel            BIT22           /* Serial DATA select. */
#define DigClkEn            BIT23           /* Digital clock enable. */
#define StartEn             BIT24           /* A/D conversion starts by enable. */
#define AdcChSel            BIT25           /* Analog input channel selection */
#define DBNSMASK            0x00000007      /* DBNS_SIZE bits can detect certain MSB bits comparison. */
#define DbnsSize(x)         (((x) >>  26) & DBNSMASK)
#define PMSel               BIT29           /* SAR ADC works in Power Mode. */
#define PD                  BIT30           /* SAR ADC Power */
#define TestMode            BIT31           /* SAR ADC Test Mode */

/*=============================================================================
//
// ADCCtrl1_REG  ADC Control1 Register.
//
//=============================================================================*/
#define SARCodeMask         0x1FF           /* SARADC data output. */
#define SARCode(x)          ((x) & SARCodeMask)
#define BufRd               BIT13           /* Buffer read signal */
#define ValDetIntEn         BIT14           /* ADC value changing detection INTERRUPT ENABLE */
#define ClrIntValDet        BIT15           /* ADC value changing detection Interrupt CLEAR signal */
#define AutoTmpSlotMask     0xFFFF          /* This value controls SAMPLE RATE */
#define AutoTmpSlot(x)      (((x) >> 16) & AutoTmpSlotMask)

/*=============================================================================
//
// ADCCtrl2_REG  ADC Control1 Register.
//
//=============================================================================*/
#define SARCodeVld          BIT0            /* SARADC valid signal. */
#define BufEmpty            BIT8            /* Buffer empty signal */
#define TestDataMask        0x7F            /* Test DATA */
#define TestData(x)         (((x) >> 9) & TestDataMask)
#define EndcIntStatus       BIT16           /* ADC Conversion Finished Interrupt status */
#define BufDataMask         0x1FF           /* Buffer read data (changed value saved in buffer) */
#define BufData(x)	        (((x) >> 17) & BufDataMask)
#define TOutStatus          BIT26           /* Time Out interrupt status */
#define ValDetIntStatus     BIT27           /* Value changing detection interrupt status */


/*
 * Saradc register set structure
 */
struct saradc_regs_s {
	unsigned int volatile Ctr0;
	unsigned int volatile Ctr1;
	unsigned int volatile Ctr2;
};


/*
 * wmt keypad operation structure.
 */
struct wmt_saradc_s {
	/* Module reference counter */
	unsigned int ref;

	/* I/O Resource */
	struct resource *res;

	/* Saradc I/O register set. */
	struct saradc_regs_s *regs;

	/* Interrupt number and status counters. */
	unsigned int irq;

};

extern int wmt_getsyspara(char *varname, unsigned char *varval, int *varlen);
extern unsigned int wmt_read_oscr(void);

MODULE_AUTHOR("WonderMedia Technologies, Inc.");
MODULE_DESCRIPTION("WMT [generic keypad] driver");
MODULE_LICENSE("GPL");