Commit 2ef9d838 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman
Browse files

Merge tag 'iio-for-3.12d' of...

Merge tag 'iio-for-3.12d' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next

Jonathan writes:

Fourth round of IIO new drivers, functionality and cleanups for the 3.13 cycle.

New Drivers
* cm36651 combined RGB light and proximity sensor.

Core improvements

* Some more fixes and cleanups related to buffers.  These include the second
  half of a series which went is as fixes.  The basis for delaying until the
  next merge window is that some are too invasive for this late in a cycle
  and others only effect code paths current unused in the mainline tree.
  In this case we have:
   * protecting against concurrent userspace access
   * fixing a memory leak if a device goes away
   * avoiding always reallocating the buffer whether or not it has changed
     (a bug fix, but one with no functional changes other than a small speed
     improvement.)
   * Add reference counting for buffers to ensure they hang around if open
     from userspace or in kernel when the device is forcefully removed.
   * Return -ENODEV for buffer access operations when the device has gone
     away.
   * Add proper locking for iio_update_buffers (currently we only have one
     buffer per device in mainline, but an input bridge driver is under
     development which would make this bug 'real'.)
   * Wake up anyone waiting on a buffer if the device is unregistered.  A
     subsequent read will fail, notifying userspace that the device is no
     longer there rather than having it wait possibly for ever.

* Move the iio_sw_preenable functionality into the core.  This avoids drivers
  having to 'know' about how the buffers are implemented and is called by
  almost all drivers anyway.  Those that don't call it are not harmed by it
  being called.
* New registration approach for information (i.e. sysfs attributes) about
  events.  Much more generic and now similar to how the equivalent is
  handled for channel information.  The events infrastructure had been left
  behind by other changes so this brings it back in line.
* Using the new events registration approach, add a hysterisis event_info
  element and apply this to those drivers with this property.
* A little unitialized variable bug in the generic_buffer.c example.
* Factor out the code for freeing lists of IIO Device attributes to avoid
  some repitition.

Driver cleanups
* At91 driver gains touch screen support and some related fixes.
* Follow up series of patches removing the now redundant
  iio_sw_buffer_preenable calls.
* Lots of conversions to the new event registration methods.
* Another round of hmc5843 cleanups as that driver moves towards graduating
  from staging.
* Make some SoC drivers buildable if COMPILE_TEST is used.  Follow up fixes
  for a few bits and bobs that revealed.
* Add explicit includes of linux/of.h to those drivers making us of linux/of.h
parents 1c3e56f9 43e01bed
......@@ -537,6 +537,62 @@ Description:
value is in raw device units or in processed units (as _raw
and _input do on sysfs direct channel read attributes).
What: /sys/.../events/in_accel_x_thresh_rising_hysteresis
What: /sys/.../events/in_accel_x_thresh_falling_hysteresis
What: /sys/.../events/in_accel_x_thresh_either_hysteresis
What: /sys/.../events/in_accel_y_thresh_rising_hysteresis
What: /sys/.../events/in_accel_y_thresh_falling_hysteresis
What: /sys/.../events/in_accel_y_thresh_either_hysteresis
What: /sys/.../events/in_accel_z_thresh_rising_hysteresis
What: /sys/.../events/in_accel_z_thresh_falling_hysteresis
What: /sys/.../events/in_accel_z_thresh_either_hysteresis
What: /sys/.../events/in_anglvel_x_thresh_rising_hysteresis
What: /sys/.../events/in_anglvel_x_thresh_falling_hysteresis
What: /sys/.../events/in_anglvel_x_thresh_either_hysteresis
What: /sys/.../events/in_anglvel_y_thresh_rising_hysteresis
What: /sys/.../events/in_anglvel_y_thresh_falling_hysteresis
What: /sys/.../events/in_anglvel_y_thresh_either_hysteresis
What: /sys/.../events/in_anglvel_z_thresh_rising_hysteresis
What: /sys/.../events/in_anglvel_z_thresh_falling_hysteresis
What: /sys/.../events/in_anglvel_z_thresh_either_hysteresis
What: /sys/.../events/in_magn_x_thresh_rising_hysteresis
What: /sys/.../events/in_magn_x_thresh_falling_hysteresis
What: /sys/.../events/in_magn_x_thresh_either_hysteresis
What: /sys/.../events/in_magn_y_thresh_rising_hysteresis
What: /sys/.../events/in_magn_y_thresh_falling_hysteresis
What: /sys/.../events/in_magn_y_thresh_either_hysteresis
What: /sys/.../events/in_magn_z_thresh_rising_hysteresis
What: /sys/.../events/in_magn_z_thresh_falling_hysteresis
What: /sys/.../events/in_magn_z_thresh_either_hysteresis
What: /sys/.../events/in_voltageY_thresh_rising_hysteresis
What: /sys/.../events/in_voltageY_thresh_falling_hysteresis
What: /sys/.../events/in_voltageY_thresh_either_hysteresis
What: /sys/.../events/in_tempY_thresh_rising_hysteresis
What: /sys/.../events/in_tempY_thresh_falling_hysteresis
What: /sys/.../events/in_tempY_thresh_either_hysteresis
What: /sys/.../events/in_illuminance0_thresh_falling_hysteresis
what: /sys/.../events/in_illuminance0_thresh_rising_hysteresis
what: /sys/.../events/in_illuminance0_thresh_either_hysteresis
what: /sys/.../events/in_proximity0_thresh_falling_hysteresis
what: /sys/.../events/in_proximity0_thresh_rising_hysteresis
what: /sys/.../events/in_proximity0_thresh_either_hysteresis
KernelVersion: 3.13
Contact: linux-iio@vger.kernel.org
Description:
Specifies the hysteresis of threshold that the device is comparing
against for the events enabled by
<type>Y[_name]_thresh[_(rising|falling)]_hysteresis.
If separate attributes exist for the two directions, but
direction is not specified for this attribute, then a single
hysteresis value applies to both directions.
For falling events the hysteresis is added to the _value attribute for
this event to get the upper threshold for when the event goes back to
normal, for rising events the hysteresis is subtracted from the _value
attribute. E.g. if in_voltage0_raw_thresh_rising_value is set to 1200
and in_voltage0_raw_thresh_rising_hysteresis is set to 50. The event
will get activated once in_voltage0_raw goes above 1200 and will become
deactived again once the value falls below 1150.
What: /sys/.../events/in_accel_x_raw_roc_rising_value
What: /sys/.../events/in_accel_x_raw_roc_falling_value
What: /sys/.../events/in_accel_y_raw_roc_rising_value
......
......@@ -7,7 +7,6 @@ Required properties:
- interrupts: Should contain the IRQ line for the ADC
- atmel,adc-channels-used: Bitmask of the channels muxed and enable for this
device
- atmel,adc-num-channels: Number of channels available in the ADC
- atmel,adc-startup-time: Startup Time of the ADC in microseconds as
defined in the datasheet
- atmel,adc-vref: Reference voltage in millivolts for the conversions
......@@ -24,6 +23,13 @@ Optional properties:
resolution will be used.
- atmel,adc-sleep-mode: Boolean to enable sleep mode when no conversion
- atmel,adc-sample-hold-time: Sample and Hold Time in microseconds
- atmel,adc-ts-wires: Number of touch screen wires. Should be 4 or 5. If this
value is set, then adc driver will enable touch screen
support.
NOTE: when adc touch screen enabled, the adc hardware trigger will be
disabled. Since touch screen will occupied the trigger register.
- atmel,adc-ts-pressure-threshold: a pressure threshold for touchscreen. It
make touch detect more precision.
Optional trigger Nodes:
- Required properties:
......
* Capella CM36651 I2C Proximity and Color Light sensor
Required properties:
- compatible: must be "capella,cm36651"
- reg: the I2C address of the device
- interrupts: interrupt-specifier for the sole interrupt
generated by the device
- vled-supply: regulator for the IR LED. IR_LED is a part
of the cm36651 for proximity detection.
As covered in ../../regulator/regulator.txt
Example:
i2c_cm36651: i2c-gpio {
/* ... */
cm36651@18 {
compatible = "capella,cm36651";
reg = <0x18>;
interrupt-parent = <&gpx0>;
interrupts = <2 0>;
vled-supply = <&ps_als_reg>;
};
/* ... */
};
......@@ -15,6 +15,7 @@ atmel Atmel Corporation
avago Avago Technologies
bosch Bosch Sensortec GmbH
brcm Broadcom Corporation
capella Capella Microsystems, Inc
cavium Cavium, Inc.
chrp Common Hardware Reference Platform
cirrus Cirrus Logic, Inc.
......
......@@ -60,14 +60,48 @@
#define AT91_ADC_IER 0x24 /* Interrupt Enable Register */
#define AT91_ADC_IDR 0x28 /* Interrupt Disable Register */
#define AT91_ADC_IMR 0x2C /* Interrupt Mask Register */
#define AT91_ADC_IER_PEN (1 << 29)
#define AT91_ADC_IER_NOPEN (1 << 30)
#define AT91_ADC_IER_XRDY (1 << 20)
#define AT91_ADC_IER_YRDY (1 << 21)
#define AT91_ADC_IER_PRDY (1 << 22)
#define AT91_ADC_ISR_PENS (1 << 31)
#define AT91_ADC_CHR(n) (0x30 + ((n) * 4)) /* Channel Data Register N */
#define AT91_ADC_DATA (0x3ff)
#define AT91_ADC_CDR0_9X5 (0x50) /* Channel Data Register 0 for 9X5 */
#define AT91_ADC_ACR 0x94 /* Analog Control Register */
#define AT91_ADC_ACR_PENDETSENS (0x3 << 0) /* pull-up resistor */
#define AT91_ADC_TSMR 0xB0
#define AT91_ADC_TSMR_TSMODE (3 << 0) /* Touch Screen Mode */
#define AT91_ADC_TSMR_TSMODE_NONE (0 << 0)
#define AT91_ADC_TSMR_TSMODE_4WIRE_NO_PRESS (1 << 0)
#define AT91_ADC_TSMR_TSMODE_4WIRE_PRESS (2 << 0)
#define AT91_ADC_TSMR_TSMODE_5WIRE (3 << 0)
#define AT91_ADC_TSMR_TSAV (3 << 4) /* Averages samples */
#define AT91_ADC_TSMR_TSAV_(x) ((x) << 4)
#define AT91_ADC_TSMR_SCTIM (0x0f << 16) /* Switch closure time */
#define AT91_ADC_TSMR_PENDBC (0x0f << 28) /* Pen Debounce time */
#define AT91_ADC_TSMR_PENDBC_(x) ((x) << 28)
#define AT91_ADC_TSMR_NOTSDMA (1 << 22) /* No Touchscreen DMA */
#define AT91_ADC_TSMR_PENDET_DIS (0 << 24) /* Pen contact detection disable */
#define AT91_ADC_TSMR_PENDET_ENA (1 << 24) /* Pen contact detection enable */
#define AT91_ADC_TSXPOSR 0xB4
#define AT91_ADC_TSYPOSR 0xB8
#define AT91_ADC_TSPRESSR 0xBC
#define AT91_ADC_TRGR_9260 AT91_ADC_MR
#define AT91_ADC_TRGR_9G45 0x08
#define AT91_ADC_TRGR_9X5 0xC0
/* Trigger Register bit field */
#define AT91_ADC_TRGR_TRGPER (0xffff << 16)
#define AT91_ADC_TRGR_TRGPER_(x) ((x) << 16)
#define AT91_ADC_TRGR_TRGMOD (0x7 << 0)
#define AT91_ADC_TRGR_MOD_PERIOD_TRIG (5 << 0)
#endif
......@@ -32,16 +32,7 @@ int st_accel_trig_set_state(struct iio_trigger *trig, bool state)
static int st_accel_buffer_preenable(struct iio_dev *indio_dev)
{
int err;
err = st_sensors_set_enable(indio_dev, true);
if (err < 0)
goto st_accel_set_enable_error;
err = iio_sw_buffer_preenable(indio_dev);
st_accel_set_enable_error:
return err;
return st_sensors_set_enable(indio_dev, true);
}
static int st_accel_buffer_postenable(struct iio_dev *indio_dev)
......
......@@ -61,17 +61,7 @@ static int ad7266_powerdown(struct ad7266_state *st)
static int ad7266_preenable(struct iio_dev *indio_dev)
{
struct ad7266_state *st = iio_priv(indio_dev);
int ret;
ret = ad7266_wakeup(st);
if (ret)
return ret;
ret = iio_sw_buffer_preenable(indio_dev);
if (ret)
ad7266_powerdown(st);
return ret;
return ad7266_wakeup(st);
}
static int ad7266_postdisable(struct iio_dev *indio_dev)
......
......@@ -78,11 +78,6 @@ enum ad7887_supported_device_ids {
static int ad7887_ring_preenable(struct iio_dev *indio_dev)
{
struct ad7887_state *st = iio_priv(indio_dev);
int ret;
ret = iio_sw_buffer_preenable(indio_dev);
if (ret < 0)
return ret;
/* We know this is a single long so can 'cheat' */
switch (*indio_dev->active_scan_mask) {
......
......@@ -397,7 +397,6 @@ static irqreturn_t ad_sd_trigger_handler(int irq, void *p)
}
static const struct iio_buffer_setup_ops ad_sd_buffer_setup_ops = {
.preenable = &iio_sw_buffer_preenable,
.postenable = &ad_sd_buffer_postenable,
.predisable = &iio_triggered_buffer_predisable,
.postdisable = &ad_sd_buffer_postdisable,
......
......@@ -11,6 +11,7 @@
#include <linux/clk.h>
#include <linux/err.h>
#include <linux/io.h>
#include <linux/input.h>
#include <linux/interrupt.h>
#include <linux/jiffies.h>
#include <linux/kernel.h>
......@@ -39,10 +40,36 @@
#define at91_adc_writel(st, reg, val) \
(writel_relaxed(val, st->reg_base + reg))
#define DRIVER_NAME "at91_adc"
#define MAX_POS_BITS 12
#define TOUCH_SAMPLE_PERIOD_US 2000 /* 2ms */
#define TOUCH_PEN_DETECT_DEBOUNCE_US 200
struct at91_adc_caps {
bool has_ts; /* Support touch screen */
bool has_tsmr; /* only at91sam9x5, sama5d3 have TSMR reg */
/*
* Numbers of sampling data will be averaged. Can be 0~3.
* Hardware can average (2 ^ ts_filter_average) sample data.
*/
u8 ts_filter_average;
/* Pen Detection input pull-up resistor, can be 0~3 */
u8 ts_pen_detect_sensitivity;
/* startup time calculate function */
u32 (*calc_startup_ticks)(u8 startup_time, u32 adc_clk_khz);
u8 num_channels;
struct at91_adc_reg_desc registers;
};
enum atmel_adc_ts_type {
ATMEL_ADC_TOUCHSCREEN_NONE = 0,
ATMEL_ADC_TOUCHSCREEN_4WIRE = 4,
ATMEL_ADC_TOUCHSCREEN_5WIRE = 5,
};
struct at91_adc_state {
struct clk *adc_clk;
u16 *buffer;
......@@ -67,6 +94,26 @@ struct at91_adc_state {
bool low_res; /* the resolution corresponds to the lowest one */
wait_queue_head_t wq_data_avail;
struct at91_adc_caps *caps;
/*
* Following ADC channels are shared by touchscreen:
*
* CH0 -- Touch screen XP/UL
* CH1 -- Touch screen XM/UR
* CH2 -- Touch screen YP/LL
* CH3 -- Touch screen YM/Sense
* CH4 -- Touch screen LR(5-wire only)
*
* The bitfields below represents the reserved channel in the
* touchscreen mode.
*/
#define CHAN_MASK_TOUCHSCREEN_4WIRE (0xf << 0)
#define CHAN_MASK_TOUCHSCREEN_5WIRE (0x1f << 0)
enum atmel_adc_ts_type touchscreen_type;
struct input_dev *ts_input;
u16 ts_sample_period_val;
u32 ts_pressure_threshold;
};
static irqreturn_t at91_adc_trigger_handler(int irq, void *p)
......@@ -95,14 +142,10 @@ static irqreturn_t at91_adc_trigger_handler(int irq, void *p)
return IRQ_HANDLED;
}
static irqreturn_t at91_adc_eoc_trigger(int irq, void *private)
/* Handler for classic adc channel eoc trigger */
void handle_adc_eoc_trigger(int irq, struct iio_dev *idev)
{
struct iio_dev *idev = private;
struct at91_adc_state *st = iio_priv(idev);
u32 status = at91_adc_readl(st, st->registers->status_register);
if (!(status & st->registers->drdy_mask))
return IRQ_HANDLED;
if (iio_buffer_enabled(idev)) {
disable_irq_nosync(irq);
......@@ -112,6 +155,115 @@ static irqreturn_t at91_adc_eoc_trigger(int irq, void *private)
st->done = true;
wake_up_interruptible(&st->wq_data_avail);
}
}
static int at91_ts_sample(struct at91_adc_state *st)
{
unsigned int xscale, yscale, reg, z1, z2;
unsigned int x, y, pres, xpos, ypos;
unsigned int rxp = 1;
unsigned int factor = 1000;
struct iio_dev *idev = iio_priv_to_dev(st);
unsigned int xyz_mask_bits = st->res;
unsigned int xyz_mask = (1 << xyz_mask_bits) - 1;
/* calculate position */
/* x position = (x / xscale) * max, max = 2^MAX_POS_BITS - 1 */
reg = at91_adc_readl(st, AT91_ADC_TSXPOSR);
xpos = reg & xyz_mask;
x = (xpos << MAX_POS_BITS) - xpos;
xscale = (reg >> 16) & xyz_mask;
if (xscale == 0) {
dev_err(&idev->dev, "Error: xscale == 0!\n");
return -1;
}
x /= xscale;
/* y position = (y / yscale) * max, max = 2^MAX_POS_BITS - 1 */
reg = at91_adc_readl(st, AT91_ADC_TSYPOSR);
ypos = reg & xyz_mask;
y = (ypos << MAX_POS_BITS) - ypos;
yscale = (reg >> 16) & xyz_mask;
if (yscale == 0) {
dev_err(&idev->dev, "Error: yscale == 0!\n");
return -1;
}
y /= yscale;
/* calculate the pressure */
reg = at91_adc_readl(st, AT91_ADC_TSPRESSR);
z1 = reg & xyz_mask;
z2 = (reg >> 16) & xyz_mask;
if (z1 != 0)
pres = rxp * (x * factor / 1024) * (z2 * factor / z1 - factor)
/ factor;
else
pres = st->ts_pressure_threshold; /* no pen contacted */
dev_dbg(&idev->dev, "xpos = %d, xscale = %d, ypos = %d, yscale = %d, z1 = %d, z2 = %d, press = %d\n",
xpos, xscale, ypos, yscale, z1, z2, pres);
if (pres < st->ts_pressure_threshold) {
dev_dbg(&idev->dev, "x = %d, y = %d, pressure = %d\n",
x, y, pres / factor);
input_report_abs(st->ts_input, ABS_X, x);
input_report_abs(st->ts_input, ABS_Y, y);
input_report_abs(st->ts_input, ABS_PRESSURE, pres);
input_report_key(st->ts_input, BTN_TOUCH, 1);
input_sync(st->ts_input);
} else {
dev_dbg(&idev->dev, "pressure too low: not reporting\n");
}
return 0;
}
static irqreturn_t at91_adc_interrupt(int irq, void *private)
{
struct iio_dev *idev = private;
struct at91_adc_state *st = iio_priv(idev);
u32 status = at91_adc_readl(st, st->registers->status_register);
const uint32_t ts_data_irq_mask =
AT91_ADC_IER_XRDY |
AT91_ADC_IER_YRDY |
AT91_ADC_IER_PRDY;
if (status & st->registers->drdy_mask)
handle_adc_eoc_trigger(irq, idev);
if (status & AT91_ADC_IER_PEN) {
at91_adc_writel(st, AT91_ADC_IDR, AT91_ADC_IER_PEN);
at91_adc_writel(st, AT91_ADC_IER, AT91_ADC_IER_NOPEN |
ts_data_irq_mask);
/* Set up period trigger for sampling */
at91_adc_writel(st, st->registers->trigger_register,
AT91_ADC_TRGR_MOD_PERIOD_TRIG |
AT91_ADC_TRGR_TRGPER_(st->ts_sample_period_val));
} else if (status & AT91_ADC_IER_NOPEN) {
at91_adc_writel(st, st->registers->trigger_register, 0);
at91_adc_writel(st, AT91_ADC_IDR, AT91_ADC_IER_NOPEN |
ts_data_irq_mask);
at91_adc_writel(st, AT91_ADC_IER, AT91_ADC_IER_PEN);
input_report_key(st->ts_input, BTN_TOUCH, 0);
input_sync(st->ts_input);
} else if ((status & ts_data_irq_mask) == ts_data_irq_mask) {
/* Now all touchscreen data is ready */
if (status & AT91_ADC_ISR_PENS) {
/* validate data by pen contact */
at91_ts_sample(st);
} else {
/* triggered by event that is no pen contact, just read
* them to clean the interrupt and discard all.
*/
at91_adc_readl(st, AT91_ADC_TSXPOSR);
at91_adc_readl(st, AT91_ADC_TSYPOSR);
at91_adc_readl(st, AT91_ADC_TSPRESSR);
}
}
return IRQ_HANDLED;
}
......@@ -121,6 +273,16 @@ static int at91_adc_channel_init(struct iio_dev *idev)
struct at91_adc_state *st = iio_priv(idev);
struct iio_chan_spec *chan_array, *timestamp;
int bit, idx = 0;
unsigned long rsvd_mask = 0;
/* If touchscreen is enable, then reserve the adc channels */
if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_4WIRE)
rsvd_mask = CHAN_MASK_TOUCHSCREEN_4WIRE;
else if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_5WIRE)
rsvd_mask = CHAN_MASK_TOUCHSCREEN_5WIRE;
/* set up the channel mask to reserve touchscreen channels */
st->channels_mask &= ~rsvd_mask;
idev->num_channels = bitmap_weight(&st->channels_mask,
st->num_channels) + 1;
......@@ -428,8 +590,80 @@ static int at91_adc_of_get_resolution(struct at91_adc_state *st,
return ret;
}
static u32 calc_startup_ticks_9260(u8 startup_time, u32 adc_clk_khz)
{
/*
* Number of ticks needed to cover the startup time of the ADC
* as defined in the electrical characteristics of the board,
* divided by 8. The formula thus is :
* Startup Time = (ticks + 1) * 8 / ADC Clock
*/
return round_up((startup_time * adc_clk_khz / 1000) - 1, 8) / 8;
}
static u32 calc_startup_ticks_9x5(u8 startup_time, u32 adc_clk_khz)
{
/*
* For sama5d3x and at91sam9x5, the formula changes to:
* Startup Time = <lookup_table_value> / ADC Clock
*/
const int startup_lookup[] = {
0 , 8 , 16 , 24 ,
64 , 80 , 96 , 112,
512, 576, 640, 704,
768, 832, 896, 960
};
int i, size = ARRAY_SIZE(startup_lookup);
unsigned int ticks;
ticks = startup_time * adc_clk_khz / 1000;
for (i = 0; i < size; i++)
if (ticks < startup_lookup[i])
break;
ticks = i;
if (ticks == size)
/* Reach the end of lookup table */
ticks = size - 1;
return ticks;
}
static const struct of_device_id at91_adc_dt_ids[];
static int at91_adc_probe_dt_ts(struct device_node *node,
struct at91_adc_state *st, struct device *dev)
{
int ret;
u32 prop;
ret = of_property_read_u32(node, "atmel,adc-ts-wires", &prop);
if (ret) {
dev_info(dev, "ADC Touch screen is disabled.\n");
return 0;
}
switch (prop) {
case 4:
case 5:
st->touchscreen_type = prop;
break;
default:
dev_err(dev, "Unsupported number of touchscreen wires (%d). Should be 4 or 5.\n", prop);
return -EINVAL;
}
prop = 0;
of_property_read_u32(node, "atmel,adc-ts-pressure-threshold", &prop);
st->ts_pressure_threshold = prop;
if (st->ts_pressure_threshold) {
return 0;
} else {
dev_err(dev, "Invalid pressure threshold for the touchscreen\n");
return -EINVAL;
}
}
static int at91_adc_probe_dt(struct at91_adc_state *st,
struct platform_device *pdev)
{
......@@ -454,13 +688,6 @@ static int at91_adc_probe_dt(struct at91_adc_state *st,
}
st->channels_mask = prop;
if (of_property_read_u32(node, "atmel,adc-num-channels", &prop)) {
dev_err(&idev->dev, "Missing adc-num-channels property in the DT.\n");
ret = -EINVAL;
goto error_ret;
}
st->num_channels = prop;
st->sleep_mode = of_property_read_bool(node, "atmel,adc-sleep-mode");
if (of_property_read_u32(node, "atmel,adc-startup-time", &prop)) {
......@@ -486,6 +713,7 @@ static int at91_adc_probe_dt(struct at91_adc_state *st,
goto error_ret;
st->registers = &st->caps->registers;
st->num_channels = st->caps->num_channels;
st->trigger_number = of_get_child_count(node);
st->trigger_list = devm_kzalloc(&idev->dev, st->trigger_number *
sizeof(struct at91_adc_trigger),
......@@ -517,6 +745,12 @@ static int at91_adc_probe_dt(struct at91_adc_state *st,
i++;
}
/* Check if touchscreen is supported. */
if (st->caps->has_ts)
return at91_adc_probe_dt_ts(node, st, &idev->dev);
else
dev_info(&idev->dev, "not support touchscreen in the adc compatible string.\n");
return 0;
error_ret:
......@@ -548,6 +782,114 @@ static const struct iio_info at91_adc_info = {
.read_raw = &at91_adc_read_raw,
};
/* Touchscreen related functions */
static int atmel_ts_open(struct input_dev *dev)
{
struct at91_adc_state *st = input_get_drvdata(dev);
at91_adc_writel(st, AT91_ADC_IER, AT91_ADC_IER_PEN);
return 0;
}
static void atmel_ts_close(struct input_dev *dev)
{
struct at91_adc_state *st = input_get_drvdata(dev);
at91_adc_writel(st, AT91_ADC_IDR, AT91_ADC_IER_PEN);
}
static int at91_ts_hw_init(struct at91_adc_state *st, u32 adc_clk_khz)
{
u32 reg = 0, pendbc;
int i = 0;
if (st->touchscreen_type == ATMEL_ADC_TOUCHSCREEN_4WIRE)
reg = AT91_ADC_TSMR_TSMODE_4WIRE_PRESS;
else
reg = AT91_ADC_TSMR_TSMODE_5WIRE;
/* a Pen Detect Debounce Time is necessary for the ADC Touch to avoid
* pen detect noise.
* The formula is : Pen Detect Debounce Time = (2 ^ pendbc) / ADCClock
*/
pendbc = round_up(TOUCH_PEN_DETECT_DEBOUNCE_US * adc_clk_khz / 1000, 1);
while (pendbc >> ++i)
; /* Empty! Find the shift offset */
if (abs(pendbc - (1 << i)) < abs(pendbc - (1 << (i - 1))))
pendbc = i;
else
pendbc = i - 1;
if (st->caps->has_tsmr) {
reg |= AT91_ADC_TSMR_TSAV_(st->caps->ts_filter_average)
& AT91_ADC_TSMR_TSAV;
reg |= AT91_ADC_TSMR_PENDBC_(pendbc) & AT91_ADC_TSMR_PENDBC;
reg |= AT91_ADC_TSMR_NOTSDMA;
reg |= AT91_ADC_TSMR_PENDET_ENA;
reg |= 0x03 << 8; /* TSFREQ, need bigger than TSAV */
at91_adc_writel(st, AT91_ADC_TSMR, reg);
} else {
/* TODO: for 9g45 which has no TSMR */
}