101636eb9SPatil, Rachna #ifndef __LINUX_TI_AM335X_TSCADC_MFD_H
201636eb9SPatil, Rachna #define __LINUX_TI_AM335X_TSCADC_MFD_H
301636eb9SPatil, Rachna 
401636eb9SPatil, Rachna /*
501636eb9SPatil, Rachna  * TI Touch Screen / ADC MFD driver
601636eb9SPatil, Rachna  *
701636eb9SPatil, Rachna  * Copyright (C) 2012 Texas Instruments Incorporated - http://www.ti.com/
801636eb9SPatil, Rachna  *
901636eb9SPatil, Rachna  * This program is free software; you can redistribute it and/or
1001636eb9SPatil, Rachna  * modify it under the terms of the GNU General Public License as
1101636eb9SPatil, Rachna  * published by the Free Software Foundation version 2.
1201636eb9SPatil, Rachna  *
1301636eb9SPatil, Rachna  * This program is distributed "as is" WITHOUT ANY WARRANTY of any
1401636eb9SPatil, Rachna  * kind, whether express or implied; without even the implied warranty
1501636eb9SPatil, Rachna  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1601636eb9SPatil, Rachna  * GNU General Public License for more details.
1701636eb9SPatil, Rachna  */
1801636eb9SPatil, Rachna 
1901636eb9SPatil, Rachna #include <linux/mfd/core.h>
2001636eb9SPatil, Rachna 
2101636eb9SPatil, Rachna #define REG_RAWIRQSTATUS	0x024
2201636eb9SPatil, Rachna #define REG_IRQSTATUS		0x028
2301636eb9SPatil, Rachna #define REG_IRQENABLE		0x02C
2401636eb9SPatil, Rachna #define REG_IRQCLR		0x030
2501636eb9SPatil, Rachna #define REG_IRQWAKEUP		0x034
2601636eb9SPatil, Rachna #define REG_CTRL		0x040
2701636eb9SPatil, Rachna #define REG_ADCFSM		0x044
2801636eb9SPatil, Rachna #define REG_CLKDIV		0x04C
2901636eb9SPatil, Rachna #define REG_SE			0x054
3001636eb9SPatil, Rachna #define REG_IDLECONFIG		0x058
3101636eb9SPatil, Rachna #define REG_CHARGECONFIG	0x05C
3201636eb9SPatil, Rachna #define REG_CHARGEDELAY		0x060
338c896308SSebastian Andrzej Siewior #define REG_STEPCONFIG(n)	(0x64 + ((n) * 8))
348c896308SSebastian Andrzej Siewior #define REG_STEPDELAY(n)	(0x68 + ((n) * 8))
3501636eb9SPatil, Rachna #define REG_FIFO0CNT		0xE4
3601636eb9SPatil, Rachna #define REG_FIFO0THR		0xE8
3701636eb9SPatil, Rachna #define REG_FIFO1CNT		0xF0
3801636eb9SPatil, Rachna #define REG_FIFO1THR		0xF4
3901636eb9SPatil, Rachna #define REG_FIFO0		0x100
4001636eb9SPatil, Rachna #define REG_FIFO1		0x200
4101636eb9SPatil, Rachna 
4201636eb9SPatil, Rachna /*	Register Bitfields	*/
4301636eb9SPatil, Rachna /* IRQ wakeup enable */
4401636eb9SPatil, Rachna #define IRQWKUP_ENB		BIT(0)
4501636eb9SPatil, Rachna 
4601636eb9SPatil, Rachna /* Step Enable */
4701636eb9SPatil, Rachna #define STEPENB_MASK		(0x1FFFF << 0)
4801636eb9SPatil, Rachna #define STEPENB(val)		((val) << 0)
4901636eb9SPatil, Rachna 
5001636eb9SPatil, Rachna /* IRQ enable */
5101636eb9SPatil, Rachna #define IRQENB_HW_PEN		BIT(0)
5201636eb9SPatil, Rachna #define IRQENB_FIFO0THRES	BIT(2)
5301636eb9SPatil, Rachna #define IRQENB_FIFO1THRES	BIT(5)
5401636eb9SPatil, Rachna #define IRQENB_PENUP		BIT(9)
5501636eb9SPatil, Rachna 
5601636eb9SPatil, Rachna /* Step Configuration */
5701636eb9SPatil, Rachna #define STEPCONFIG_MODE_MASK	(3 << 0)
5801636eb9SPatil, Rachna #define STEPCONFIG_MODE(val)	((val) << 0)
5901636eb9SPatil, Rachna #define STEPCONFIG_MODE_HWSYNC	STEPCONFIG_MODE(2)
6001636eb9SPatil, Rachna #define STEPCONFIG_AVG_MASK	(7 << 2)
6101636eb9SPatil, Rachna #define STEPCONFIG_AVG(val)	((val) << 2)
6201636eb9SPatil, Rachna #define STEPCONFIG_AVG_16	STEPCONFIG_AVG(4)
6301636eb9SPatil, Rachna #define STEPCONFIG_XPP		BIT(5)
6401636eb9SPatil, Rachna #define STEPCONFIG_XNN		BIT(6)
6501636eb9SPatil, Rachna #define STEPCONFIG_YPP		BIT(7)
6601636eb9SPatil, Rachna #define STEPCONFIG_YNN		BIT(8)
6701636eb9SPatil, Rachna #define STEPCONFIG_XNP		BIT(9)
6801636eb9SPatil, Rachna #define STEPCONFIG_YPN		BIT(10)
6901636eb9SPatil, Rachna #define STEPCONFIG_INM_MASK	(0xF << 15)
7001636eb9SPatil, Rachna #define STEPCONFIG_INM(val)	((val) << 15)
7101636eb9SPatil, Rachna #define STEPCONFIG_INM_ADCREFM	STEPCONFIG_INM(8)
7201636eb9SPatil, Rachna #define STEPCONFIG_INP_MASK	(0xF << 19)
7301636eb9SPatil, Rachna #define STEPCONFIG_INP(val)	((val) << 19)
7401636eb9SPatil, Rachna #define STEPCONFIG_INP_AN4	STEPCONFIG_INP(4)
7501636eb9SPatil, Rachna #define STEPCONFIG_INP_ADCREFM	STEPCONFIG_INP(8)
7601636eb9SPatil, Rachna #define STEPCONFIG_FIFO1	BIT(26)
7701636eb9SPatil, Rachna 
7801636eb9SPatil, Rachna /* Delay register */
7901636eb9SPatil, Rachna #define STEPDELAY_OPEN_MASK	(0x3FFFF << 0)
8001636eb9SPatil, Rachna #define STEPDELAY_OPEN(val)	((val) << 0)
8101636eb9SPatil, Rachna #define STEPCONFIG_OPENDLY	STEPDELAY_OPEN(0x098)
8201636eb9SPatil, Rachna #define STEPDELAY_SAMPLE_MASK	(0xFF << 24)
8301636eb9SPatil, Rachna #define STEPDELAY_SAMPLE(val)	((val) << 24)
8401636eb9SPatil, Rachna #define STEPCONFIG_SAMPLEDLY	STEPDELAY_SAMPLE(0)
8501636eb9SPatil, Rachna 
8601636eb9SPatil, Rachna /* Charge Config */
8701636eb9SPatil, Rachna #define STEPCHARGE_RFP_MASK	(7 << 12)
8801636eb9SPatil, Rachna #define STEPCHARGE_RFP(val)	((val) << 12)
8901636eb9SPatil, Rachna #define STEPCHARGE_RFP_XPUL	STEPCHARGE_RFP(1)
9001636eb9SPatil, Rachna #define STEPCHARGE_INM_MASK	(0xF << 15)
9101636eb9SPatil, Rachna #define STEPCHARGE_INM(val)	((val) << 15)
9201636eb9SPatil, Rachna #define STEPCHARGE_INM_AN1	STEPCHARGE_INM(1)
9301636eb9SPatil, Rachna #define STEPCHARGE_INP_MASK	(0xF << 19)
9401636eb9SPatil, Rachna #define STEPCHARGE_INP(val)	((val) << 19)
9501636eb9SPatil, Rachna #define STEPCHARGE_RFM_MASK	(3 << 23)
9601636eb9SPatil, Rachna #define STEPCHARGE_RFM(val)	((val) << 23)
9701636eb9SPatil, Rachna #define STEPCHARGE_RFM_XNUR	STEPCHARGE_RFM(1)
9801636eb9SPatil, Rachna 
9901636eb9SPatil, Rachna /* Charge delay */
10001636eb9SPatil, Rachna #define CHARGEDLY_OPEN_MASK	(0x3FFFF << 0)
10101636eb9SPatil, Rachna #define CHARGEDLY_OPEN(val)	((val) << 0)
10201636eb9SPatil, Rachna #define CHARGEDLY_OPENDLY	CHARGEDLY_OPEN(1)
10301636eb9SPatil, Rachna 
10401636eb9SPatil, Rachna /* Control register */
10501636eb9SPatil, Rachna #define CNTRLREG_TSCSSENB	BIT(0)
10601636eb9SPatil, Rachna #define CNTRLREG_STEPID		BIT(1)
10701636eb9SPatil, Rachna #define CNTRLREG_STEPCONFIGWRT	BIT(2)
10801636eb9SPatil, Rachna #define CNTRLREG_POWERDOWN	BIT(4)
10901636eb9SPatil, Rachna #define CNTRLREG_AFE_CTRL_MASK	(3 << 5)
11001636eb9SPatil, Rachna #define CNTRLREG_AFE_CTRL(val)	((val) << 5)
11101636eb9SPatil, Rachna #define CNTRLREG_4WIRE		CNTRLREG_AFE_CTRL(1)
11201636eb9SPatil, Rachna #define CNTRLREG_5WIRE		CNTRLREG_AFE_CTRL(2)
11301636eb9SPatil, Rachna #define CNTRLREG_8WIRE		CNTRLREG_AFE_CTRL(3)
11401636eb9SPatil, Rachna #define CNTRLREG_TSCENB		BIT(7)
11501636eb9SPatil, Rachna 
116b1451e54SPatil, Rachna /* FIFO READ Register */
117b1451e54SPatil, Rachna #define FIFOREAD_DATA_MASK (0xfff << 0)
118b1451e54SPatil, Rachna #define FIFOREAD_CHNLID_MASK (0xf << 16)
119b1451e54SPatil, Rachna 
120b1451e54SPatil, Rachna /* Sequencer Status */
121b1451e54SPatil, Rachna #define SEQ_STATUS BIT(5)
122b1451e54SPatil, Rachna 
12301636eb9SPatil, Rachna #define ADC_CLK			3000000
12401636eb9SPatil, Rachna #define	MAX_CLK_DIV		7
1255e53a69bSPatil, Rachna #define TOTAL_STEPS		16
1265e53a69bSPatil, Rachna #define TOTAL_CHANNELS		8
12701636eb9SPatil, Rachna 
128b1451e54SPatil, Rachna /*
129b1451e54SPatil, Rachna * ADC runs at 3MHz, and it takes
130b1451e54SPatil, Rachna * 15 cycles to latch one data output.
131b1451e54SPatil, Rachna * Hence the idle time for ADC to
132b1451e54SPatil, Rachna * process one sample data would be
133b1451e54SPatil, Rachna * around 5 micro seconds.
134b1451e54SPatil, Rachna */
135b1451e54SPatil, Rachna #define IDLE_TIMEOUT 5 /* microsec */
136b1451e54SPatil, Rachna 
1375e53a69bSPatil, Rachna #define TSCADC_CELLS		2
1382b99bafaSPatil, Rachna 
13901636eb9SPatil, Rachna struct ti_tscadc_dev {
14001636eb9SPatil, Rachna 	struct device *dev;
14101636eb9SPatil, Rachna 	struct regmap *regmap_tscadc;
14201636eb9SPatil, Rachna 	void __iomem *tscadc_base;
14301636eb9SPatil, Rachna 	int irq;
14424d5c82fSPantelis Antoniou 	int used_cells;	/* 1-2 */
14524d5c82fSPantelis Antoniou 	int tsc_cell;	/* -1 if not used */
14624d5c82fSPantelis Antoniou 	int adc_cell;	/* -1 if not used */
14701636eb9SPatil, Rachna 	struct mfd_cell cells[TSCADC_CELLS];
148abeccee4SPatil, Rachna 	u32 reg_se_cache;
149abeccee4SPatil, Rachna 	spinlock_t reg_lock;
1502b99bafaSPatil, Rachna 
1512b99bafaSPatil, Rachna 	/* tsc device */
1522b99bafaSPatil, Rachna 	struct titsc *tsc;
1535e53a69bSPatil, Rachna 
1545e53a69bSPatil, Rachna 	/* adc device */
1555e53a69bSPatil, Rachna 	struct adc_device *adc;
15601636eb9SPatil, Rachna };
15701636eb9SPatil, Rachna 
158a9bce1b0SSebastian Andrzej Siewior static inline struct ti_tscadc_dev *ti_tscadc_dev_get(struct platform_device *p)
159a9bce1b0SSebastian Andrzej Siewior {
160a9bce1b0SSebastian Andrzej Siewior 	struct ti_tscadc_dev **tscadc_dev = p->dev.platform_data;
161a9bce1b0SSebastian Andrzej Siewior 
162a9bce1b0SSebastian Andrzej Siewior 	return *tscadc_dev;
163a9bce1b0SSebastian Andrzej Siewior }
164a9bce1b0SSebastian Andrzej Siewior 
165abeccee4SPatil, Rachna void am335x_tsc_se_update(struct ti_tscadc_dev *tsadc);
166abeccee4SPatil, Rachna void am335x_tsc_se_set(struct ti_tscadc_dev *tsadc, u32 val);
167abeccee4SPatil, Rachna void am335x_tsc_se_clr(struct ti_tscadc_dev *tsadc, u32 val);
168abeccee4SPatil, Rachna 
16901636eb9SPatil, Rachna #endif
170