Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 249782
b: refs/heads/master
c: 9b5d9b0
h: refs/heads/master
v: v3
  • Loading branch information
Jonathan Cameron authored and Greg Kroah-Hartman committed May 19, 2011
1 parent 30c361c commit 52ab72d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 89 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: db9afe2fc0c59f84bc1950b9b78767bbcdc80f13
refs/heads/master: 9b5d9b06a4ae41705f856b68ccac507219250de6
121 changes: 33 additions & 88 deletions trunk/drivers/staging/iio/adc/ad7150.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@
*/

#include <linux/interrupt.h>
#include <linux/gpio.h>
#include <linux/workqueue.h>
#include <linux/device.h>
#include <linux/kernel.h>
#include <linux/slab.h>
#include <linux/sysfs.h>
#include <linux/list.h>
#include <linux/i2c.h>
#include <linux/rtc.h>

#include "../iio.h"
#include "../sysfs.h"
Expand Down Expand Up @@ -66,9 +61,7 @@ struct ad7150_chip_info {
const char *name;
struct i2c_client *client;
struct iio_dev *indio_dev;
struct work_struct thresh_work;
bool inter;
s64 last_timestamp;
u16 ch1_threshold; /* Ch1 Threshold (in fixed threshold mode) */
u8 ch1_sensitivity; /* Ch1 Sensitivity (in adaptive threshold mode) */
u8 ch1_timeout; /* Ch1 Timeout (in adaptive threshold mode) */
Expand All @@ -88,7 +81,8 @@ struct ad7150_conversion_mode {
u8 reg_cfg;
};

struct ad7150_conversion_mode ad7150_conv_mode_table[AD7150_MAX_CONV_MODE] = {
static struct ad7150_conversion_mode
ad7150_conv_mode_table[AD7150_MAX_CONV_MODE] = {
{ "idle", 0 },
{ "continuous-conversion", 1 },
{ "single-conversion", 2 },
Expand Down Expand Up @@ -666,91 +660,45 @@ static const struct attribute_group ad7150_attribute_group = {
#define IIO_EVENT_CODE_CH2_HIGH IIO_BUFFER_EVENT_CODE(2)
#define IIO_EVENT_CODE_CH2_LOW IIO_BUFFER_EVENT_CODE(3)

#define IIO_EVENT_ATTR_CH1_HIGH_SH(_evlist, _show, _store, _mask) \
IIO_EVENT_ATTR_SH(ch1_high, _evlist, _show, _store, _mask)

#define IIO_EVENT_ATTR_CH2_HIGH_SH(_evlist, _show, _store, _mask) \
IIO_EVENT_ATTR_SH(ch2_high, _evlist, _show, _store, _mask)

#define IIO_EVENT_ATTR_CH1_LOW_SH(_evlist, _show, _store, _mask) \
IIO_EVENT_ATTR_SH(ch1_low, _evlist, _show, _store, _mask)

#define IIO_EVENT_ATTR_CH2_LOW_SH(_evlist, _show, _store, _mask) \
IIO_EVENT_ATTR_SH(ch2_low, _evlist, _show, _store, _mask)

static void ad7150_interrupt_handler_bh(struct work_struct *work_s)
static irqreturn_t ad7150_event_handler(int irq, void *private)
{
struct ad7150_chip_info *chip =
container_of(work_s, struct ad7150_chip_info, thresh_work);
struct iio_dev *indio_dev = private;
struct ad7150_chip_info *chip = iio_dev_get_devdata(indio_dev);
u8 int_status;

enable_irq(chip->client->irq);
s64 timestamp = iio_get_time_ns();

ad7150_i2c_read(chip, AD7150_STATUS, &int_status, 1);

if ((int_status & AD7150_STATUS_OUT1) && !(chip->old_state & AD7150_STATUS_OUT1))
iio_push_event(chip->indio_dev, 0,
iio_push_event(indio_dev, 0,
IIO_EVENT_CODE_CH1_HIGH,
chip->last_timestamp);
timestamp);
else if ((!(int_status & AD7150_STATUS_OUT1)) && (chip->old_state & AD7150_STATUS_OUT1))
iio_push_event(chip->indio_dev, 0,
iio_push_event(indio_dev, 0,
IIO_EVENT_CODE_CH1_LOW,
chip->last_timestamp);
timestamp);

if ((int_status & AD7150_STATUS_OUT2) && !(chip->old_state & AD7150_STATUS_OUT2))
iio_push_event(chip->indio_dev, 0,
iio_push_event(indio_dev, 0,
IIO_EVENT_CODE_CH2_HIGH,
chip->last_timestamp);
timestamp);
else if ((!(int_status & AD7150_STATUS_OUT2)) && (chip->old_state & AD7150_STATUS_OUT2))
iio_push_event(chip->indio_dev, 0,
iio_push_event(indio_dev, 0,
IIO_EVENT_CODE_CH2_LOW,
chip->last_timestamp);
}

static int ad7150_interrupt_handler_th(struct iio_dev *dev_info,
int index,
s64 timestamp,
int no_test)
{
struct ad7150_chip_info *chip = dev_info->dev_data;

chip->last_timestamp = timestamp;
schedule_work(&chip->thresh_work);

return 0;
timestamp);
return IRQ_HANDLED;
}

IIO_EVENT_SH(threshold, &ad7150_interrupt_handler_th);

static ssize_t ad7150_query_out_mode(struct device *dev,
struct device_attribute *attr,
char *buf)
{
/*
* AD7150 provides two logic output channels, which can be used as interrupt
* but the pins are not configurable
*/
return sprintf(buf, "1\n");
}

static ssize_t ad7150_set_out_mode(struct device *dev,
struct device_attribute *attr,
const char *buf,
size_t len)
{
return len;
}

IIO_EVENT_ATTR_CH1_HIGH_SH(iio_event_threshold, ad7150_query_out_mode, ad7150_set_out_mode, 0);
IIO_EVENT_ATTR_CH2_HIGH_SH(iio_event_threshold, ad7150_query_out_mode, ad7150_set_out_mode, 0);
IIO_EVENT_ATTR_CH1_LOW_SH(iio_event_threshold, ad7150_query_out_mode, ad7150_set_out_mode, 0);
IIO_EVENT_ATTR_CH2_LOW_SH(iio_event_threshold, ad7150_query_out_mode, ad7150_set_out_mode, 0);
static IIO_CONST_ATTR(ch1_high_en, "1");
static IIO_CONST_ATTR(ch2_high_en, "1");
static IIO_CONST_ATTR(ch1_low_en, "1");
static IIO_CONST_ATTR(ch2_low_en, "1");

static struct attribute *ad7150_event_attributes[] = {
&iio_event_attr_ch1_high.dev_attr.attr,
&iio_event_attr_ch2_high.dev_attr.attr,
&iio_event_attr_ch1_low.dev_attr.attr,
&iio_event_attr_ch2_low.dev_attr.attr,
&iio_const_attr_ch1_high_en.dev_attr.attr,
&iio_const_attr_ch2_high_en.dev_attr.attr,
&iio_const_attr_ch1_low_en.dev_attr.attr,
&iio_const_attr_ch2_low_en.dev_attr.attr,
NULL,
};

Expand Down Expand Up @@ -798,19 +746,16 @@ static int __devinit ad7150_probe(struct i2c_client *client,
goto error_free_dev;
regdone = 1;

if (client->irq && gpio_is_valid(irq_to_gpio(client->irq)) > 0) {
ret = iio_register_interrupt_line(client->irq,
chip->indio_dev,
0,
IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
"ad7150");
if (client->irq) {
ret = request_threaded_irq(client->irq,
NULL,
&ad7150_event_handler,
IRQF_TRIGGER_RISING |
IRQF_TRIGGER_FALLING,
"ad7150",
chip->indio_dev);
if (ret)
goto error_free_dev;

iio_add_event_to_list(iio_event_attr_ch2_low.listel,
&chip->indio_dev->interrupts[0]->ev_list);

INIT_WORK(&chip->thresh_work, ad7150_interrupt_handler_bh);
}

dev_err(&client->dev, "%s capacitive sensor registered, irq: %d\n", id->name, client->irq);
Expand All @@ -833,8 +778,8 @@ static int __devexit ad7150_remove(struct i2c_client *client)
struct ad7150_chip_info *chip = i2c_get_clientdata(client);
struct iio_dev *indio_dev = chip->indio_dev;

if (client->irq && gpio_is_valid(irq_to_gpio(client->irq)) > 0)
iio_unregister_interrupt_line(indio_dev, 0);
if (client->irq)
free_irq(client->irq, indio_dev);
iio_device_unregister(indio_dev);
kfree(chip);

Expand Down

0 comments on commit 52ab72d

Please sign in to comment.