xref: /freebsd/sys/arm/ti/ti_adcvar.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
1855feb68SLuiz Otavio O Souza /*-
2855feb68SLuiz Otavio O Souza  * Copyright 2014 Luiz Otavio O Souza <loos@freebsd.org>
3855feb68SLuiz Otavio O Souza  * All rights reserved.
4855feb68SLuiz Otavio O Souza  *
5855feb68SLuiz Otavio O Souza  * Redistribution and use in source and binary forms, with or without
6855feb68SLuiz Otavio O Souza  * modification, are permitted provided that the following conditions
7855feb68SLuiz Otavio O Souza  * are met:
8855feb68SLuiz Otavio O Souza  * 1. Redistributions of source code must retain the above copyright
9855feb68SLuiz Otavio O Souza  *    notice, this list of conditions and the following disclaimer.
10855feb68SLuiz Otavio O Souza  * 2. Redistributions in binary form must reproduce the above copyright
11855feb68SLuiz Otavio O Souza  *    notice, this list of conditions and the following disclaimer in the
12855feb68SLuiz Otavio O Souza  *    documentation and/or other materials provided with the distribution.
13855feb68SLuiz Otavio O Souza  *
14855feb68SLuiz Otavio O Souza  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15855feb68SLuiz Otavio O Souza  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16855feb68SLuiz Otavio O Souza  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17855feb68SLuiz Otavio O Souza  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18855feb68SLuiz Otavio O Souza  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19855feb68SLuiz Otavio O Souza  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20855feb68SLuiz Otavio O Souza  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21855feb68SLuiz Otavio O Souza  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22855feb68SLuiz Otavio O Souza  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23855feb68SLuiz Otavio O Souza  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24855feb68SLuiz Otavio O Souza  * SUCH DAMAGE.
25855feb68SLuiz Otavio O Souza  */
26855feb68SLuiz Otavio O Souza 
27855feb68SLuiz Otavio O Souza #ifndef _TI_ADCVAR_H_
28855feb68SLuiz Otavio O Souza #define _TI_ADCVAR_H_
29855feb68SLuiz Otavio O Souza 
30f7eebb77SLuiz Otavio O Souza #define	TI_ADC_NPINS	8
31855feb68SLuiz Otavio O Souza 
32855feb68SLuiz Otavio O Souza #define	ADC_READ4(_sc, reg)	bus_read_4((_sc)->sc_mem_res, reg)
33855feb68SLuiz Otavio O Souza #define	ADC_WRITE4(_sc, reg, value)	\
34855feb68SLuiz Otavio O Souza 	bus_write_4((_sc)->sc_mem_res, reg, value)
35855feb68SLuiz Otavio O Souza 
36855feb68SLuiz Otavio O Souza struct ti_adc_softc {
37855feb68SLuiz Otavio O Souza 	device_t		sc_dev;
38855feb68SLuiz Otavio O Souza 	int			sc_last_state;
39855feb68SLuiz Otavio O Souza 	struct mtx		sc_mtx;
40855feb68SLuiz Otavio O Souza 	struct resource		*sc_mem_res;
41855feb68SLuiz Otavio O Souza 	struct resource		*sc_irq_res;
42855feb68SLuiz Otavio O Souza 	void			*sc_intrhand;
43651f7544SOleksandr Tymoshenko 	int			sc_tsc_wires;
44651f7544SOleksandr Tymoshenko 	int			sc_tsc_wire_config[TI_ADC_NPINS];
45651f7544SOleksandr Tymoshenko 	int			sc_coord_readouts;
46651f7544SOleksandr Tymoshenko 	int			sc_x_plate_resistance;
47651f7544SOleksandr Tymoshenko 	int			sc_charge_delay;
48651f7544SOleksandr Tymoshenko 	int			sc_adc_nchannels;
49651f7544SOleksandr Tymoshenko 	int			sc_adc_channels[TI_ADC_NPINS];
50651f7544SOleksandr Tymoshenko 	int			sc_xp_bit, sc_xp_inp;
51651f7544SOleksandr Tymoshenko 	int			sc_xn_bit, sc_xn_inp;
52651f7544SOleksandr Tymoshenko 	int			sc_yp_bit, sc_yp_inp;
53651f7544SOleksandr Tymoshenko 	int			sc_yn_bit, sc_yn_inp;
54651f7544SOleksandr Tymoshenko 	uint32_t		sc_tsc_enabled;
55651f7544SOleksandr Tymoshenko 	int			sc_pen_down;
56*a6b15a34SOleksandr Tymoshenko #ifdef EVDEV_SUPPORT
57fbeb453bSOleksandr Tymoshenko 	int			sc_x;
58fbeb453bSOleksandr Tymoshenko 	int			sc_y;
59fbeb453bSOleksandr Tymoshenko 	struct evdev_dev *sc_evdev;
60fbeb453bSOleksandr Tymoshenko #endif
61855feb68SLuiz Otavio O Souza };
62855feb68SLuiz Otavio O Souza 
63855feb68SLuiz Otavio O Souza struct ti_adc_input {
64855feb68SLuiz Otavio O Souza 	int32_t			enable;		/* input enabled */
65855feb68SLuiz Otavio O Souza 	int32_t			samples;	/* samples average */
66855feb68SLuiz Otavio O Souza 	int32_t			input;		/* input number */
67855feb68SLuiz Otavio O Souza 	int32_t			value;		/* raw converted value */
68855feb68SLuiz Otavio O Souza 	uint32_t		stepconfig;	/* step config register */
69855feb68SLuiz Otavio O Souza 	uint32_t		stepdelay;	/* step delay register */
70855feb68SLuiz Otavio O Souza 	struct ti_adc_softc	*sc;		/* pointer to adc softc */
71855feb68SLuiz Otavio O Souza };
72855feb68SLuiz Otavio O Souza 
73855feb68SLuiz Otavio O Souza #define	TI_ADC_LOCK(_sc)		\
74855feb68SLuiz Otavio O Souza 	mtx_lock(&(_sc)->sc_mtx)
75855feb68SLuiz Otavio O Souza #define	TI_ADC_UNLOCK(_sc)		\
76855feb68SLuiz Otavio O Souza 	mtx_unlock(&(_sc)->sc_mtx)
77855feb68SLuiz Otavio O Souza #define	TI_ADC_LOCK_INIT(_sc)	\
78855feb68SLuiz Otavio O Souza 	mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->sc_dev), \
79855feb68SLuiz Otavio O Souza 	    "ti_adc", MTX_DEF)
80855feb68SLuiz Otavio O Souza #define	TI_ADC_LOCK_DESTROY(_sc)	\
81855feb68SLuiz Otavio O Souza 	mtx_destroy(&_sc->sc_mtx);
82855feb68SLuiz Otavio O Souza #define	TI_ADC_LOCK_ASSERT(_sc)	\
83855feb68SLuiz Otavio O Souza 	mtx_assert(&(_sc)->sc_mtx, MA_OWNED)
84855feb68SLuiz Otavio O Souza 
85855feb68SLuiz Otavio O Souza #endif /* _TI_ADCVAR_H_ */
86