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
Person | Tokens | Prop | Commits | CommitProp |
Jason (Hui) Wang | 44 | 84.62% | 1 | 50.00% |
Imre Deak | 8 | 15.38% | 1 | 50.00% |
Total | 52 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Jason (Hui) Wang | 36 | 81.82% | 1 | 50.00% |
Imre Deak | 8 | 18.18% | 1 | 50.00% |
Total | 44 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Jason (Hui) Wang | 13 | 54.17% | 1 | 33.33% |
Imre Deak | 10 | 41.67% | 1 | 33.33% |
David Brownell | 1 | 4.17% | 1 | 33.33% |
Total | 24 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Mark Brown | 25 | 52.08% | 1 | 33.33% |
Jason (Hui) Wang | 17 | 35.42% | 1 | 33.33% |
David Brownell | 6 | 12.50% | 1 | 33.33% |
Total | 48 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Jason (Hui) Wang | 54 | 100.00% | 1 | 100.00% |
Total | 54 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Jason (Hui) Wang | 53 | 100.00% | 1 | 100.00% |
Total | 53 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David Brownell | 381 | 83.37% | 5 | 38.46% |
Jason (Hui) Wang | 36 | 7.88% | 1 | 7.69% |
Vitaly Wool | 15 | 3.28% | 1 | 7.69% |
Alexander Stein | 12 | 2.63% | 1 | 7.69% |
Imre Deak | 6 | 1.31% | 2 | 15.38% |
Marc Pignat | 4 | 0.88% | 1 | 7.69% |
Nicolas Ferre | 2 | 0.44% | 1 | 7.69% |
Christoph Lameter | 1 | 0.22% | 1 | 7.69% |
Total | 457 | 100.00% | 13 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Anatolij Gustschin | 199 | 90.45% | 1 | 50.00% |
Jason (Hui) Wang | 21 | 9.55% | 1 | 50.00% |
Total | 220 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David Brownell | 18 | 100.00% | 1 | 100.00% |
Total | 18 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David Brownell | 36 | 100.00% | 2 | 100.00% |
Total | 36 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David Brownell | 41 | 100.00% | 1 | 100.00% |
Total | 41 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Guenter Roeck | 81 | 100.00% | 1 | 100.00% |
Total | 81 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
David Brownell | 107 | 88.43% | 2 | 40.00% |
Guenter Roeck | 7 | 5.79% | 1 | 20.00% |
Alexander Stein | 6 | 4.96% | 1 | 20.00% |
Javier Martinez Canillas | 1 | 0.83% | 1 | 20.00% |
Total | 121 | 100.00% | 5 | 100.00% |
static void ads784x_hwmon_unregister(struct spi_device *spi,
struct ads7846 *ts)
{
if (ts->hwmon)
hwmon_device_unregister(ts->hwmon);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
David Brownell | 29 | 100.00% | 1 | 100.00% |
Total | 29 | 100.00% | 1 | 100.00% |
#else
static inline int ads784x_hwmon_register(struct spi_device *spi,
struct ads7846 *ts)
{
return 0;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
David Brownell | 20 | 100.00% | 2 | 100.00% |
Total | 20 | 100.00% | 2 | 100.00% |
static inline void ads784x_hwmon_unregister(struct spi_device *spi,
struct ads7846 *ts)
{
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
David Brownell | 16 | 100.00% | 2 | 100.00% |
Total | 16 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Imre Deak | 29 | 69.05% | 1 | 50.00% |
Jason (Hui) Wang | 13 | 30.95% | 1 | 50.00% |
Total | 42 | 100.00% | 2 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Imre Deak | 42 | 100.00% | 1 | 100.00% |
Total | 42 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Imre Deak | 59 | 75.64% | 1 | 25.00% |
JJ Ding | 12 | 15.38% | 1 | 25.00% |
Joe Rouvier | 6 | 7.69% | 1 | 25.00% |
Harvey Harrison | 1 | 1.28% | 1 | 25.00% |
Total | 78 | 100.00% | 4 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Eric Miao | 32 | 100.00% | 1 | 100.00% |
Total | 32 | 100.00% | 1 | 100.00% |
static void null_wait_for_sync(void)
{
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Eric Miao | 7 | 100.00% | 1 | 100.00% |
Total | 7 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Imre Deak | 52 | 36.88% | 3 | 42.86% |
Jason (Hui) Wang | 48 | 34.04% | 1 | 14.29% |
David Brownell | 23 | 16.31% | 1 | 14.29% |
Hans-Christian Noren Egtvedt | 9 | 6.38% | 1 | 14.29% |
Anatolij Gustschin | 9 | 6.38% | 1 | 14.29% |
Total | 141 | 100.00% | 7 | 100.00% |
static int ads7846_no_filter(void *ads, int data_idx, int *val)
{
return ADS7846_FILTER_OK;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Imre Deak | 20 | 100.00% | 1 | 100.00% |
Total | 20 | 100.00% | 1 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Anatolij Gustschin | 45 | 45.00% | 1 | 16.67% |
Imre Deak | 20 | 20.00% | 1 | 16.67% |
Andrey Gelman | 17 | 17.00% | 1 | 16.67% |
Jason (Hui) Wang | 10 | 10.00% | 1 | 16.67% |
Harvey Harrison | 7 | 7.00% | 1 | 16.67% |
Dmitry Torokhov | 1 | 1.00% | 1 | 16.67% |
Total | 100 | 100.00% | 6 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Jason (Hui) Wang | 42 | 95.45% | 1 | 33.33% |
Imre Deak | 1 | 2.27% | 1 | 33.33% |
Anatolij Gustschin | 1 | 2.27% | 1 | 33.33% |
Total | 44 | 100.00% | 3 | 100.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
Person | Tokens | Prop | Commits | CommitProp |
Jason (Hui) Wang | 143 | 70.10% | 1 | 14.29% |
Imre Deak | 53 | 25.98% | 3 | 42.86% |
David Brownell | 5 | 2.45% | 1 | 14.29% |
Dmitry Torokhov | 2 | 0.98% | 1 | 14.29% |
Mark Brown | 1 | 0.49% | 1 | 14.29% |
Total | 204 | 100.00% | 7 | 100.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 */