cregit-Linux how code gets into the kernel

Release 4.11 drivers/input/touchscreen/ads7846.c

/*
 * ADS7846 based touchscreen and sensor driver
 *
 * Copyright (c) 2005 David Brownell
 * Copyright (c) 2006 Nokia Corporation
 * Various changes: Imre Deak <imre.deak@nokia.com>
 *
 * Using code from:
 *  - corgi_ts.c
 *      Copyright (C) 2004-2005 Richard Purdie
 *  - omap_ts.[hc], ads7846.h, ts_osk.c
 *      Copyright (C) 2002 MontaVista Software
 *      Copyright (C) 2004 Texas Instruments
 *      Copyright (C) 2005 Dirk Behme
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 */
#include <linux/types.h>
#include <linux/hwmon.h>
#include <linux/err.h>
#include <linux/sched.h>
#include <linux/delay.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/slab.h>
#include <linux/pm.h>
#include <linux/of.h>
#include <linux/of_gpio.h>
#include <linux/of_device.h>
#include <linux/gpio.h>
#include <linux/spi/spi.h>
#include <linux/spi/ads7846.h>
#include <linux/regulator/consumer.h>
#include <linux/module.h>
#include <asm/irq.h>

/*
 * This code has been heavily tested on a Nokia 770, and lightly
 * tested on other ads7846 devices (OSK/Mistral, Lubbock, Spitz).
 * TSC2046 is just newer ads7846 silicon.
 * Support for ads7843 tested on Atmel at91sam926x-EK.
 * Support for ads7845 has only been stubbed in.
 * Support for Analog Devices AD7873 and AD7843 tested.
 *
 * IRQ handling needs a workaround because of a shortcoming in handling
 * edge triggered IRQs on some platforms like the OMAP1/2. These
 * platforms don't handle the ARM lazy IRQ disabling properly, thus we
 * have to maintain our own SW IRQ disabled status. This should be
 * removed as soon as the affected platform's IRQ handling is fixed.
 *
 * App note sbaa036 talks in more detail about accurate sampling...
 * that ought to help in situations like LCDs inducing noise (which
 * can also be helped by using synch signals) and more generally.
 * This driver tries to utilize the measures described in the app
 * note. The strength of filtering can be set in the board-* specific
 * files.
 */


#define TS_POLL_DELAY	1	
/* ms delay before the first sample */

#define TS_POLL_PERIOD	5	
/* ms delay between samples */

/* this driver doesn't aim at the peak continuous sample rate */

#define	SAMPLE_BITS	(8 /*cmd*/ + 16 /*sample*/ + 2 /* before, after */)


struct ts_event {
	/*
         * For portability, we can't read 12 bit values using SPI (which
         * would make the controller deliver them as native byte order u16
         * with msbs zeroed).  Instead, we read them as two 8-bit values,
         * *** WHICH NEED BYTESWAPPING *** and range adjustment.
         */
	
u16	x;
	
u16	y;
	

u16	z1, z2;
	
bool	ignore;
	
u8	x_buf[3];
	
u8	y_buf[3];
};

/*
 * We allocate this separately to avoid cache line sharing issues when
 * driver is used with DMA-based SPI controllers (like atmel_spi) on
 * systems where main memory is not DMA-coherent (most non-x86 boards).
 */

struct ads7846_packet {
	




u8			read_x, read_y, read_z1, read_z2, pwrdown;
	
u16			dummy;		/* for the pwrdown read */
	
struct ts_event		tc;
	/* for ads7845 with mpc5121 psc spi we use 3-byte buffers */
	


u8			read_x_cmd[3], read_y_cmd[3], pwrdown_cmd[3];
};


struct ads7846 {
	
struct input_dev	*input;
	
char			phys[32];
	
char			name[32];

	
struct spi_device	*spi;
	
struct regulator	*reg;

#if IS_ENABLED(CONFIG_HWMON)
	
struct device		*hwmon;
#endif

	
u16			model;
	
u16			vref_mv;
	
u16			vref_delay_usecs;
	
u16			x_plate_ohms;
	
u16			pressure_max;

	
bool			swap_xy;
	
bool			use_internal;

	
struct ads7846_packet	*packet;

	
struct spi_transfer	xfer[18];
	
struct spi_message	msg[5];
	
int			msg_count;
	
wait_queue_head_t	wait;

	
bool			pendown;

	
int			read_cnt;
	
int			read_rep;
	
int			last_read;

	
u16			debounce_max;
	
u16			debounce_tol;
	
u16			debounce_rep;

	
u16			penirq_recheck_delay_usecs;

	
struct mutex		lock;
	
bool			stopped;	/* P: lock */
	
bool			disabled;	/* P: lock */
	
bool			suspended;	/* P: lock */

	
int			(*filter)(void *data, int data_idx, int *val);
	
void			*filter_data;
	
void			(*filter_cleanup)(void *data);
	
int			(*get_pendown_state)(void);
	
int			gpio_pendown;

	
void			(*wait_for_sync)(void);
};

/* leave chip selected when we're done, for quicker re-select? */
#if	0
#define	CS_CHANGE(xfer)	((xfer).cs_change = 1)
#else

#define	CS_CHANGE(xfer)	((xfer).cs_change = 0)
#endif

/*--------------------------------------------------------------------------*/

/* The ADS7846 has touchscreen and other sensors.
 * Earlier ads784x chips are somewhat compatible.
 */

#define	ADS_START		(1 << 7)

#define	ADS_A2A1A0_d_y		(1 << 4)	
/* differential */

#define	ADS_A2A1A0_d_z1		(3 << 4)	
/* differential */

#define	ADS_A2A1A0_d_z2		(4 << 4)	
/* differential */

#define	ADS_A2A1A0_d_x		(5 << 4)	
/* differential */

#define	ADS_A2A1A0_temp0	(0 << 4)	
/* non-differential */

#define	ADS_A2A1A0_vbatt	(2 << 4)	
/* non-differential */

#define	ADS_A2A1A0_vaux		(6 << 4)	
/* non-differential */

#define	ADS_A2A1A0_temp1	(7 << 4)	
/* non-differential */

#define	ADS_8_BIT		(1 << 3)

#define	ADS_12_BIT		(0 << 3)

#define	ADS_SER			(1 << 2)	
/* non-differential */

#define	ADS_DFR			(0 << 2)	
/* differential */

#define	ADS_PD10_PDOWN		(0 << 0)	
/* low power mode + penirq */

#define	ADS_PD10_ADC_ON		(1 << 0)	
/* ADC on */

#define	ADS_PD10_REF_ON		(2 << 0)	
/* vREF on + penirq */

#define	ADS_PD10_ALL_ON		(3 << 0)	
/* ADC + vREF on */


#define	MAX_12BIT	((1<<12)-1)

/* leave ADC powered up (disables penirq) between differential samples */

#define	READ_12BIT_DFR(x, adc, vref) (ADS_START | ADS_A2A1A0_d_ ## x \
        | ADS_12_BIT | ADS_DFR | \
        (adc ? ADS_PD10_ADC_ON : 0) | (vref ? ADS_PD10_REF_ON : 0))


#define	READ_Y(vref)	(READ_12BIT_DFR(y,  1, vref))

#define	READ_Z1(vref)	(READ_12BIT_DFR(z1, 1, vref))

#define	READ_Z2(vref)	(READ_12BIT_DFR(z2, 1, vref))


#define	READ_X(vref)	(READ_12BIT_DFR(x,  1, vref))

#define	PWRDOWN		(READ_12BIT_DFR(y,  0, 0))	
/* LAST */

/* single-ended samples need to first power up reference voltage;
 * we leave both ADC and VREF powered
 */

#define	READ_12BIT_SER(x) (ADS_START | ADS_A2A1A0_ ## x \
        | ADS_12_BIT | ADS_SER)


#define	REF_ON	(READ_12BIT_DFR(x, 1, 1))

#define	REF_OFF	(READ_12BIT_DFR(y, 0, 0))

/* Must be called with ts->lock held */

static void ads7846_stop(struct ads7846 *ts) { if (!ts->disabled && !ts->suspended) { /* Signal IRQ thread to stop polling and disable the handler. */ ts->stopped = true; mb(); wake_up(&ts->wait); disable_irq(ts->spi->irq); } }

Contributors

PersonTokensPropCommitsCommitProp
Jason (Hui) Wang4484.62%150.00%
Imre Deak815.38%150.00%
Total52100.00%2100.00%

/* Must be called with ts->lock held */
static void ads7846_restart(struct ads7846 *ts) { if (!ts->disabled && !ts->suspended) { /* Tell IRQ thread that it may poll the device. */ ts->stopped = false; mb(); enable_irq(ts->spi->irq); } }

Contributors

PersonTokensPropCommitsCommitProp
Jason (Hui) Wang3681.82%150.00%
Imre Deak818.18%150.00%
Total44100.00%2100.00%

/* Must be called with ts->lock held */
static void __ads7846_disable(struct ads7846 *ts) { ads7846_stop(ts); regulator_disable(ts->reg); /* * We know the chip's in low power mode since we always * leave it that way after every request */ }

Contributors

PersonTokensPropCommitsCommitProp
Jason (Hui) Wang1354.17%133.33%
Imre Deak1041.67%133.33%
David Brownell14.17%133.33%
Total24100.00%3100.00%

/* Must be called with ts->lock held */
static void __ads7846_enable(struct ads7846 *ts) { int error; error = regulator_enable(ts->reg); if (error != 0) dev_err(&ts->spi->dev, "Failed to enable supply: %d\n", error); ads7846_restart(ts); }

Contributors

PersonTokensPropCommitsCommitProp
Mark Brown2552.08%133.33%
Jason (Hui) Wang1735.42%133.33%
David Brownell612.50%133.33%
Total48100.00%3100.00%


static void ads7846_disable(struct ads7846 *ts) { mutex_lock(&ts->lock); if (!ts->disabled) { if (!ts->suspended) __ads7846_disable(ts); ts->disabled = true; } mutex_unlock(&ts->lock); }

Contributors

PersonTokensPropCommitsCommitProp
Jason (Hui) Wang54100.00%1100.00%
Total54100.00%1100.00%


static void ads7846_enable(struct ads7846 *ts) { mutex_lock(&ts->lock); if (ts->disabled) { ts->disabled = false; if (!ts->suspended) __ads7846_enable(ts); } mutex_unlock(&ts->lock); }

Contributors

PersonTokensPropCommitsCommitProp
Jason (Hui) Wang53100.00%1100.00%
Total53100.00%1100.00%

/*--------------------------------------------------------------------------*/ /* * Non-touchscreen sensors only use single-ended conversions. * The range is GND..vREF. The ads7843 and ads7835 must use external vREF; * ads7846 lets that pin be unconnected, to use internal vREF. */ struct ser_req { u8 ref_on; u8 command; u8 ref_off; u16 scratch; struct spi_message msg; struct spi_transfer xfer[6]; /* * DMA (thus cache coherency maintenance) requires the * transfer buffers to live in their own cache lines. */ __be16 sample ____cacheline_aligned; }; struct ads7845_ser_req { u8 command[3]; struct spi_message msg; struct spi_transfer xfer[2]; /* * DMA (thus cache coherency maintenance) requires the * transfer buffers to live in their own cache lines. */ u8 sample[3] ____cacheline_aligned; };
static int ads7846_read12_ser(struct device *dev, unsigned command) { struct spi_device *spi = to_spi_device(dev); struct ads7846 *ts = dev_get_drvdata(dev); struct ser_req *req; int status; req = kzalloc(sizeof *req, GFP_KERNEL); if (!req) return -ENOMEM; spi_message_init(&req->msg); /* maybe turn on internal vREF, and let it settle */ if (ts->use_internal) { req->ref_on = REF_ON; req->xfer[0].tx_buf = &req->ref_on; req->xfer[0].len = 1; spi_message_add_tail(&req->xfer[0], &req->msg); req->xfer[1].rx_buf = &req->scratch; req->xfer[1].len = 2; /* for 1uF, settle for 800 usec; no cap, 100 usec. */ req->xfer[1].delay_usecs = ts->vref_delay_usecs; spi_message_add_tail(&req->xfer[1], &req->msg); /* Enable reference voltage */ command |= ADS_PD10_REF_ON; } /* Enable ADC in every case */ command |= ADS_PD10_ADC_ON; /* take sample */ req->command = (u8) command; req->xfer[2].tx_buf = &req->command; req->xfer[2].len = 1; spi_message_add_tail(&req->xfer[2], &req->msg); req->xfer[3].rx_buf = &req->sample; req->xfer[3].len = 2; spi_message_add_tail(&req->xfer[3], &req->msg); /* REVISIT: take a few more samples, and compare ... */ /* converter in low power mode & enable PENIRQ */ req->ref_off = PWRDOWN; req->xfer[4].tx_buf = &req->ref_off; req->xfer[4].len = 1; spi_message_add_tail(&req->xfer[4], &req->msg); req->xfer[5].rx_buf = &req->scratch; req->xfer[5].len = 2; CS_CHANGE(req->xfer[5]); spi_message_add_tail(&req->xfer[5], &req->msg); mutex_lock(&ts->lock); ads7846_stop(ts); status = spi_sync(spi, &req->msg); ads7846_restart(ts); mutex_unlock(&ts->lock); if (status == 0) { /* on-wire is a must-ignore bit, a BE12 value, then padding */ status = be16_to_cpu(req->sample); status = status >> 3; status &= 0x0fff; } kfree(req); return status; }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell38183.37%538.46%
Jason (Hui) Wang367.88%17.69%
Vitaly Wool153.28%17.69%
Alexander Stein122.63%17.69%
Imre Deak61.31%215.38%
Marc Pignat40.88%17.69%
Nicolas Ferre20.44%17.69%
Christoph Lameter10.22%17.69%
Total457100.00%13100.00%


static int ads7845_read12_ser(struct device *dev, unsigned command) { struct spi_device *spi = to_spi_device(dev); struct ads7846 *ts = dev_get_drvdata(dev); struct ads7845_ser_req *req; int status; req = kzalloc(sizeof *req, GFP_KERNEL); if (!req) return -ENOMEM; spi_message_init(&req->msg); req->command[0] = (u8) command; req->xfer[0].tx_buf = req->command; req->xfer[0].rx_buf = req->sample; req->xfer[0].len = 3; spi_message_add_tail(&req->xfer[0], &req->msg); mutex_lock(&ts->lock); ads7846_stop(ts); status = spi_sync(spi, &req->msg); ads7846_restart(ts); mutex_unlock(&ts->lock); if (status == 0) { /* BE12 value, then padding */ status = be16_to_cpu(*((u16 *)&req->sample[1])); status = status >> 3; status &= 0x0fff; } kfree(req); return status; }

Contributors

PersonTokensPropCommitsCommitProp
Anatolij Gustschin19990.45%150.00%
Jason (Hui) Wang219.55%150.00%
Total220100.00%2100.00%

#if IS_ENABLED(CONFIG_HWMON) #define SHOW(name, var, adjust) static ssize_t \ name ## _show(struct device *dev, struct device_attribute *attr, char *buf) \ { \ struct ads7846 *ts = dev_get_drvdata(dev); \ ssize_t v = ads7846_read12_ser(&ts->spi->dev, \ READ_12BIT_SER(var)); \ if (v < 0) \ return v; \ return sprintf(buf, "%u\n", adjust(ts, v)); \ } \ static DEVICE_ATTR(name, S_IRUGO, name ## _show, NULL); /* Sysfs conventions report temperatures in millidegrees Celsius. * ADS7846 could use the low-accuracy two-sample scheme, but can't do the high * accuracy scheme without calibration data. For now we won't try either; * userspace sees raw sensor values, and must scale/calibrate appropriately. */
static inline unsigned null_adjust(struct ads7846 *ts, ssize_t v) { return v; }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell18100.00%1100.00%
Total18100.00%1100.00%

SHOW(temp0, temp0, null_adjust) /* temp1_input */ SHOW(temp1, temp1, null_adjust) /* temp2_input */ /* sysfs conventions report voltages in millivolts. We can convert voltages * if we know vREF. userspace may need to scale vAUX to match the board's * external resistors; we assume that vBATT only uses the internal ones. */
static inline unsigned vaux_adjust(struct ads7846 *ts, ssize_t v) { unsigned retval = v; /* external resistors may scale vAUX into 0..vREF */ retval *= ts->vref_mv; retval = retval >> 12; return retval; }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell36100.00%2100.00%
Total36100.00%2100.00%


static inline unsigned vbatt_adjust(struct ads7846 *ts, ssize_t v) { unsigned retval = vaux_adjust(ts, v); /* ads7846 has a resistor ladder to scale this signal down */ if (ts->model == 7846) retval *= 4; return retval; }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell41100.00%1100.00%
Total41100.00%1100.00%

SHOW(in0_input, vaux, vaux_adjust) SHOW(in1_input, vbatt, vbatt_adjust)
static umode_t ads7846_is_visible(struct kobject *kobj, struct attribute *attr, int index) { struct device *dev = container_of(kobj, struct device, kobj); struct ads7846 *ts = dev_get_drvdata(dev); if (ts->model == 7843 && index < 2) /* in0, in1 */ return 0; if (ts->model == 7845 && index != 2) /* in0 */ return 0; return attr->mode; }

Contributors

PersonTokensPropCommitsCommitProp
Guenter Roeck81100.00%1100.00%
Total81100.00%1100.00%

static struct attribute *ads7846_attributes[] = { &dev_attr_temp0.attr, /* 0 */ &dev_attr_temp1.attr, /* 1 */ &dev_attr_in0_input.attr, /* 2 */ &dev_attr_in1_input.attr, /* 3 */ NULL, }; static struct attribute_group ads7846_attr_group = { .attrs = ads7846_attributes, .is_visible = ads7846_is_visible, }; __ATTRIBUTE_GROUPS(ads7846_attr);
static int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts) { /* hwmon sensors need a reference voltage */ switch (ts->model) { case 7846: if (!ts->vref_mv) { dev_dbg(&spi->dev, "assuming 2.5V internal vREF\n"); ts->vref_mv = 2500; ts->use_internal = true; } break; case 7845: case 7843: if (!ts->vref_mv) { dev_warn(&spi->dev, "external vREF for ADS%d not specified\n", ts->model); return 0; } break; } ts->hwmon = hwmon_device_register_with_groups(&spi->dev, spi->modalias, ts, ads7846_attr_groups); return PTR_ERR_OR_ZERO(ts->hwmon); }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell10788.43%240.00%
Guenter Roeck75.79%120.00%
Alexander Stein64.96%120.00%
Javier Martinez Canillas10.83%120.00%
Total121100.00%5100.00%


static void ads784x_hwmon_unregister(struct spi_device *spi, struct ads7846 *ts) { if (ts->hwmon) hwmon_device_unregister(ts->hwmon); }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell29100.00%1100.00%
Total29100.00%1100.00%

#else
static inline int ads784x_hwmon_register(struct spi_device *spi, struct ads7846 *ts) { return 0; }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell20100.00%2100.00%
Total20100.00%2100.00%


static inline void ads784x_hwmon_unregister(struct spi_device *spi, struct ads7846 *ts) { }

Contributors

PersonTokensPropCommitsCommitProp
David Brownell16100.00%2100.00%
Total16100.00%2100.00%

#endif
static ssize_t ads7846_pen_down_show(struct device *dev, struct device_attribute *attr, char *buf) { struct ads7846 *ts = dev_get_drvdata(dev); return sprintf(buf, "%u\n", ts->pendown); }

Contributors

PersonTokensPropCommitsCommitProp
Imre Deak2969.05%150.00%
Jason (Hui) Wang1330.95%150.00%
Total42100.00%2100.00%

static DEVICE_ATTR(pen_down, S_IRUGO, ads7846_pen_down_show, NULL);
static ssize_t ads7846_disable_show(struct device *dev, struct device_attribute *attr, char *buf) { struct ads7846 *ts = dev_get_drvdata(dev); return sprintf(buf, "%u\n", ts->disabled); }

Contributors

PersonTokensPropCommitsCommitProp
Imre Deak42100.00%1100.00%
Total42100.00%1100.00%


static ssize_t ads7846_disable_store(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) { struct ads7846 *ts = dev_get_drvdata(dev); unsigned int i; int err; err = kstrtouint(buf, 10, &i); if (err) return err; if (i) ads7846_disable(ts); else ads7846_enable(ts); return count; }

Contributors

PersonTokensPropCommitsCommitProp
Imre Deak5975.64%125.00%
JJ Ding1215.38%125.00%
Joe Rouvier67.69%125.00%
Harvey Harrison11.28%125.00%
Total78100.00%4100.00%

static DEVICE_ATTR(disable, 0664, ads7846_disable_show, ads7846_disable_store); static struct attribute *ads784x_attributes[] = { &dev_attr_pen_down.attr, &dev_attr_disable.attr, NULL, }; static struct attribute_group ads784x_attr_group = { .attrs = ads784x_attributes, }; /*--------------------------------------------------------------------------*/
static int get_pendown_state(struct ads7846 *ts) { if (ts->get_pendown_state) return ts->get_pendown_state(); return !gpio_get_value(ts->gpio_pendown); }

Contributors

PersonTokensPropCommitsCommitProp
Eric Miao32100.00%1100.00%
Total32100.00%1100.00%


static void null_wait_for_sync(void) { }

Contributors

PersonTokensPropCommitsCommitProp
Eric Miao7100.00%1100.00%
Total7100.00%1100.00%


static int ads7846_debounce_filter(void *ads, int data_idx, int *val) { struct ads7846 *ts = ads; if (!ts->read_cnt || (abs(ts->last_read - *val) > ts->debounce_tol)) { /* Start over collecting consistent readings. */ ts->read_rep = 0; /* * Repeat it, if this was the first read or the read * wasn't consistent enough. */ if (ts->read_cnt < ts->debounce_max) { ts->last_read = *val; ts->read_cnt++; return ADS7846_FILTER_REPEAT; } else { /* * Maximum number of debouncing reached and still * not enough number of consistent readings. Abort * the whole sample, repeat it in the next sampling * period. */ ts->read_cnt = 0; return ADS7846_FILTER_IGNORE; } } else { if (++ts->read_rep > ts->debounce_rep) { /* * Got a good reading for this coordinate, * go for the next one. */ ts->read_cnt = 0; ts->read_rep = 0; return ADS7846_FILTER_OK; } else { /* Read more values that are consistent. */ ts->read_cnt++; return ADS7846_FILTER_REPEAT; } } }

Contributors

PersonTokensPropCommitsCommitProp
Imre Deak5236.88%342.86%
Jason (Hui) Wang4834.04%114.29%
David Brownell2316.31%114.29%
Hans-Christian Noren Egtvedt96.38%114.29%
Anatolij Gustschin96.38%114.29%
Total141100.00%7100.00%


static int ads7846_no_filter(void *ads, int data_idx, int *val) { return ADS7846_FILTER_OK; }

Contributors

PersonTokensPropCommitsCommitProp
Imre Deak20100.00%1100.00%
Total20100.00%1100.00%


static int ads7846_get_value(struct ads7846 *ts, struct spi_message *m) { int value; struct spi_transfer *t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list); if (ts->model == 7845) { value = be16_to_cpup((__be16 *)&(((char *)t->rx_buf)[1])); } else { /* * adjust: on-wire is a must-ignore bit, a BE12 value, then * padding; built from two 8 bit values written msb-first. */ value = be16_to_cpup((__be16 *)t->rx_buf); } /* enforce ADC output is 12 bits width */ return (value >> 3) & 0xfff; }

Contributors

PersonTokensPropCommitsCommitProp
Anatolij Gustschin4545.00%116.67%
Imre Deak2020.00%116.67%
Andrey Gelman1717.00%116.67%
Jason (Hui) Wang1010.00%116.67%
Harvey Harrison77.00%116.67%
Dmitry Torokhov11.00%116.67%
Total100100.00%6100.00%


static void ads7846_update_value(struct spi_message *m, int val) { struct spi_transfer *t = list_entry(m->transfers.prev, struct spi_transfer, transfer_list); *(u16 *)t->rx_buf = val; }

Contributors

PersonTokensPropCommitsCommitProp
Jason (Hui) Wang4295.45%133.33%
Imre Deak12.27%133.33%
Anatolij Gustschin12.27%133.33%
Total44100.00%3100.00%


static void ads7846_read_state(struct ads7846 *ts) { struct ads7846_packet *packet = ts->packet; struct spi_message *m; int msg_idx = 0; int val; int action; int error; while (msg_idx < ts->msg_count) { ts->wait_for_sync(); m = &ts->msg[msg_idx]; error = spi_sync(ts->spi, m); if (error) { dev_err(&ts->spi->dev, "spi_sync --> %d\n", error); packet->tc.ignore = true; return; } /* * Last message is power down request, no need to convert * or filter the value. */ if (msg_idx < ts->msg_count - 1) { val = ads7846_get_value(ts, m); action = ts->filter(ts->filter_data, msg_idx, &val); switch (action) { case ADS7846_FILTER_REPEAT: continue; case ADS7846_FILTER_IGNORE: packet->tc.ignore = true; msg_idx = ts->msg_count - 1; continue; case ADS7846_FILTER_OK: ads7846_update_value(m, val); packet->tc.ignore = false; msg_idx++; break; default: BUG(); } } else { msg_idx++; } } }

Contributors

PersonTokensPropCommitsCommitProp
Jason (Hui) Wang14370.10%114.29%
Imre Deak5325.98%342.86%
David Brownell52.45%114.29%
Dmitry Torokhov20.98%114.29%
Mark Brown10.49%114.29%
Total204100.00%7100.00%


static void ads7846_report_state(struct ads7846 *ts) { struct ads7846_packet *packet = ts->packet; unsigned int Rt; u16 x, y, z1, z2; /* * ads7846_get_value() does in-place conversion (including byte swap) * from on-the-wire format as part of debouncing to get stable * readings. */ if (ts->model == 7845) { x = *(u16 *)packet->tc.x_buf; y = *(u16 *)packet->tc.y_buf; z1 = 0; z2 = 0; } else { x = packet->tc.x; y = packet->tc.y; z1 = packet->tc.z1; z2 = packet->tc.z2; } /* range filtering */