blob: 4258627d076a1b6e432df7c951f8df1f2134797e [file] [log] [blame]
Patil, Rachna01636eb2012-10-16 12:55:43 +05301#ifndef __LINUX_TI_AM335X_TSCADC_MFD_H
2#define __LINUX_TI_AM335X_TSCADC_MFD_H
3
4/*
5 * TI Touch Screen / ADC MFD driver
6 *
7 * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation version 2.
12 *
13 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
14 * kind, whether express or implied; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19#include <linux/mfd/core.h>
20
21#define REG_RAWIRQSTATUS 0x024
22#define REG_IRQSTATUS 0x028
23#define REG_IRQENABLE 0x02C
24#define REG_IRQCLR 0x030
25#define REG_IRQWAKEUP 0x034
26#define REG_CTRL 0x040
27#define REG_ADCFSM 0x044
28#define REG_CLKDIV 0x04C
29#define REG_SE 0x054
30#define REG_IDLECONFIG 0x058
31#define REG_CHARGECONFIG 0x05C
32#define REG_CHARGEDELAY 0x060
33#define REG_STEPCONFIG(n) (0x64 + ((n - 1) * 8))
34#define REG_STEPDELAY(n) (0x68 + ((n - 1) * 8))
35#define REG_FIFO0CNT 0xE4
36#define REG_FIFO0THR 0xE8
37#define REG_FIFO1CNT 0xF0
38#define REG_FIFO1THR 0xF4
39#define REG_FIFO0 0x100
40#define REG_FIFO1 0x200
41
42/* Register Bitfields */
43/* IRQ wakeup enable */
44#define IRQWKUP_ENB BIT(0)
45
46/* Step Enable */
47#define STEPENB_MASK (0x1FFFF << 0)
48#define STEPENB(val) ((val) << 0)
Patil, Rachna01636eb2012-10-16 12:55:43 +053049
50/* IRQ enable */
51#define IRQENB_HW_PEN BIT(0)
52#define IRQENB_FIFO0THRES BIT(2)
53#define IRQENB_FIFO1THRES BIT(5)
54#define IRQENB_PENUP BIT(9)
55
56/* Step Configuration */
57#define STEPCONFIG_MODE_MASK (3 << 0)
58#define STEPCONFIG_MODE(val) ((val) << 0)
59#define STEPCONFIG_MODE_HWSYNC STEPCONFIG_MODE(2)
60#define STEPCONFIG_AVG_MASK (7 << 2)
61#define STEPCONFIG_AVG(val) ((val) << 2)
62#define STEPCONFIG_AVG_16 STEPCONFIG_AVG(4)
63#define STEPCONFIG_XPP BIT(5)
64#define STEPCONFIG_XNN BIT(6)
65#define STEPCONFIG_YPP BIT(7)
66#define STEPCONFIG_YNN BIT(8)
67#define STEPCONFIG_XNP BIT(9)
68#define STEPCONFIG_YPN BIT(10)
69#define STEPCONFIG_INM_MASK (0xF << 15)
70#define STEPCONFIG_INM(val) ((val) << 15)
71#define STEPCONFIG_INM_ADCREFM STEPCONFIG_INM(8)
72#define STEPCONFIG_INP_MASK (0xF << 19)
73#define STEPCONFIG_INP(val) ((val) << 19)
74#define STEPCONFIG_INP_AN2 STEPCONFIG_INP(2)
75#define STEPCONFIG_INP_AN3 STEPCONFIG_INP(3)
76#define STEPCONFIG_INP_AN4 STEPCONFIG_INP(4)
77#define STEPCONFIG_INP_ADCREFM STEPCONFIG_INP(8)
78#define STEPCONFIG_FIFO1 BIT(26)
79
80/* Delay register */
81#define STEPDELAY_OPEN_MASK (0x3FFFF << 0)
82#define STEPDELAY_OPEN(val) ((val) << 0)
83#define STEPCONFIG_OPENDLY STEPDELAY_OPEN(0x098)
84#define STEPDELAY_SAMPLE_MASK (0xFF << 24)
85#define STEPDELAY_SAMPLE(val) ((val) << 24)
86#define STEPCONFIG_SAMPLEDLY STEPDELAY_SAMPLE(0)
87
88/* Charge Config */
89#define STEPCHARGE_RFP_MASK (7 << 12)
90#define STEPCHARGE_RFP(val) ((val) << 12)
91#define STEPCHARGE_RFP_XPUL STEPCHARGE_RFP(1)
92#define STEPCHARGE_INM_MASK (0xF << 15)
93#define STEPCHARGE_INM(val) ((val) << 15)
94#define STEPCHARGE_INM_AN1 STEPCHARGE_INM(1)
95#define STEPCHARGE_INP_MASK (0xF << 19)
96#define STEPCHARGE_INP(val) ((val) << 19)
97#define STEPCHARGE_INP_AN1 STEPCHARGE_INP(1)
98#define STEPCHARGE_RFM_MASK (3 << 23)
99#define STEPCHARGE_RFM(val) ((val) << 23)
100#define STEPCHARGE_RFM_XNUR STEPCHARGE_RFM(1)
101
102/* Charge delay */
103#define CHARGEDLY_OPEN_MASK (0x3FFFF << 0)
104#define CHARGEDLY_OPEN(val) ((val) << 0)
105#define CHARGEDLY_OPENDLY CHARGEDLY_OPEN(1)
106
107/* Control register */
108#define CNTRLREG_TSCSSENB BIT(0)
109#define CNTRLREG_STEPID BIT(1)
110#define CNTRLREG_STEPCONFIGWRT BIT(2)
111#define CNTRLREG_POWERDOWN BIT(4)
112#define CNTRLREG_AFE_CTRL_MASK (3 << 5)
113#define CNTRLREG_AFE_CTRL(val) ((val) << 5)
114#define CNTRLREG_4WIRE CNTRLREG_AFE_CTRL(1)
115#define CNTRLREG_5WIRE CNTRLREG_AFE_CTRL(2)
116#define CNTRLREG_8WIRE CNTRLREG_AFE_CTRL(3)
117#define CNTRLREG_TSCENB BIT(7)
118
119#define ADC_CLK 3000000
120#define MAX_CLK_DIV 7
Patil, Rachna5e53a692012-10-16 12:55:45 +0530121#define TOTAL_STEPS 16
122#define TOTAL_CHANNELS 8
Patil, Rachna01636eb2012-10-16 12:55:43 +0530123
Patil, Rachna5e53a692012-10-16 12:55:45 +0530124#define TSCADC_CELLS 2
Patil, Rachna2b99baf2012-10-16 12:55:44 +0530125
126enum tscadc_cells {
127 TSC_CELL,
Patil, Rachna5e53a692012-10-16 12:55:45 +0530128 ADC_CELL,
Patil, Rachna2b99baf2012-10-16 12:55:44 +0530129};
Patil, Rachna01636eb2012-10-16 12:55:43 +0530130
131struct mfd_tscadc_board {
132 struct tsc_data *tsc_init;
Patil, Rachna5e53a692012-10-16 12:55:45 +0530133 struct adc_data *adc_init;
Patil, Rachna01636eb2012-10-16 12:55:43 +0530134};
135
136struct ti_tscadc_dev {
137 struct device *dev;
138 struct regmap *regmap_tscadc;
139 void __iomem *tscadc_base;
140 int irq;
141 struct mfd_cell cells[TSCADC_CELLS];
Patil, Rachnaabeccee2013-01-24 03:45:05 +0000142 u32 reg_se_cache;
143 spinlock_t reg_lock;
Patil, Rachna2b99baf2012-10-16 12:55:44 +0530144
145 /* tsc device */
146 struct titsc *tsc;
Patil, Rachna5e53a692012-10-16 12:55:45 +0530147
148 /* adc device */
149 struct adc_device *adc;
Patil, Rachna01636eb2012-10-16 12:55:43 +0530150};
151
Sebastian Andrzej Siewiora9bce1b2013-06-05 16:13:47 +0200152static inline struct ti_tscadc_dev *ti_tscadc_dev_get(struct platform_device *p)
153{
154 struct ti_tscadc_dev **tscadc_dev = p->dev.platform_data;
155
156 return *tscadc_dev;
157}
158
Patil, Rachnaabeccee2013-01-24 03:45:05 +0000159void am335x_tsc_se_update(struct ti_tscadc_dev *tsadc);
160void am335x_tsc_se_set(struct ti_tscadc_dev *tsadc, u32 val);
161void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val);
162
Patil, Rachna01636eb2012-10-16 12:55:43 +0530163#endif