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 * $FreeBSD$ 27855feb68SLuiz Otavio O Souza */ 28855feb68SLuiz Otavio O Souza 29855feb68SLuiz Otavio O Souza #ifndef _TI_ADCVAR_H_ 30855feb68SLuiz Otavio O Souza #define _TI_ADCVAR_H_ 31855feb68SLuiz Otavio O Souza 32f7eebb77SLuiz Otavio O Souza #define TI_ADC_NPINS 8 33855feb68SLuiz Otavio O Souza 34855feb68SLuiz Otavio O Souza #define ADC_READ4(_sc, reg) bus_read_4((_sc)->sc_mem_res, reg) 35855feb68SLuiz Otavio O Souza #define ADC_WRITE4(_sc, reg, value) \ 36855feb68SLuiz Otavio O Souza bus_write_4((_sc)->sc_mem_res, reg, value) 37855feb68SLuiz Otavio O Souza 38855feb68SLuiz Otavio O Souza struct ti_adc_softc { 39855feb68SLuiz Otavio O Souza device_t sc_dev; 40855feb68SLuiz Otavio O Souza int sc_last_state; 41855feb68SLuiz Otavio O Souza struct mtx sc_mtx; 42855feb68SLuiz Otavio O Souza struct resource *sc_mem_res; 43855feb68SLuiz Otavio O Souza struct resource *sc_irq_res; 44855feb68SLuiz Otavio O Souza void *sc_intrhand; 45*651f7544SOleksandr Tymoshenko int sc_tsc_wires; 46*651f7544SOleksandr Tymoshenko int sc_tsc_wire_config[TI_ADC_NPINS]; 47*651f7544SOleksandr Tymoshenko int sc_coord_readouts; 48*651f7544SOleksandr Tymoshenko int sc_x_plate_resistance; 49*651f7544SOleksandr Tymoshenko int sc_charge_delay; 50*651f7544SOleksandr Tymoshenko int sc_adc_nchannels; 51*651f7544SOleksandr Tymoshenko int sc_adc_channels[TI_ADC_NPINS]; 52*651f7544SOleksandr Tymoshenko int sc_xp_bit, sc_xp_inp; 53*651f7544SOleksandr Tymoshenko int sc_xn_bit, sc_xn_inp; 54*651f7544SOleksandr Tymoshenko int sc_yp_bit, sc_yp_inp; 55*651f7544SOleksandr Tymoshenko int sc_yn_bit, sc_yn_inp; 56*651f7544SOleksandr Tymoshenko uint32_t sc_tsc_enabled; 57*651f7544SOleksandr Tymoshenko int sc_pen_down; 58855feb68SLuiz Otavio O Souza }; 59855feb68SLuiz Otavio O Souza 60855feb68SLuiz Otavio O Souza struct ti_adc_input { 61855feb68SLuiz Otavio O Souza int32_t enable; /* input enabled */ 62855feb68SLuiz Otavio O Souza int32_t samples; /* samples average */ 63855feb68SLuiz Otavio O Souza int32_t input; /* input number */ 64855feb68SLuiz Otavio O Souza int32_t value; /* raw converted value */ 65855feb68SLuiz Otavio O Souza uint32_t stepconfig; /* step config register */ 66855feb68SLuiz Otavio O Souza uint32_t stepdelay; /* step delay register */ 67855feb68SLuiz Otavio O Souza struct ti_adc_softc *sc; /* pointer to adc softc */ 68855feb68SLuiz Otavio O Souza }; 69855feb68SLuiz Otavio O Souza 70855feb68SLuiz Otavio O Souza #define TI_ADC_LOCK(_sc) \ 71855feb68SLuiz Otavio O Souza mtx_lock(&(_sc)->sc_mtx) 72855feb68SLuiz Otavio O Souza #define TI_ADC_UNLOCK(_sc) \ 73855feb68SLuiz Otavio O Souza mtx_unlock(&(_sc)->sc_mtx) 74855feb68SLuiz Otavio O Souza #define TI_ADC_LOCK_INIT(_sc) \ 75855feb68SLuiz Otavio O Souza mtx_init(&_sc->sc_mtx, device_get_nameunit(_sc->sc_dev), \ 76855feb68SLuiz Otavio O Souza "ti_adc", MTX_DEF) 77855feb68SLuiz Otavio O Souza #define TI_ADC_LOCK_DESTROY(_sc) \ 78855feb68SLuiz Otavio O Souza mtx_destroy(&_sc->sc_mtx); 79855feb68SLuiz Otavio O Souza #define TI_ADC_LOCK_ASSERT(_sc) \ 80855feb68SLuiz Otavio O Souza mtx_assert(&(_sc)->sc_mtx, MA_OWNED) 81855feb68SLuiz Otavio O Souza 82855feb68SLuiz Otavio O Souza #endif /* _TI_ADCVAR_H_ */ 83