Commit 82020b0e authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio:max1363 move to new abi.

Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 1722762c
...@@ -7,6 +7,7 @@ config MAX1363 ...@@ -7,6 +7,7 @@ config MAX1363
tristate "MAXIM max1363 ADC driver" tristate "MAXIM max1363 ADC driver"
depends on I2C depends on I2C
select IIO_TRIGGER if IIO_RING_BUFFER select IIO_TRIGGER if IIO_RING_BUFFER
select MAX1363_RING_BUFFER
help help
Say yes here to build support for many MAXIM i2c analog to digital Say yes here to build support for many MAXIM i2c analog to digital
convertors (ADC). (max1361, max1362, max1363, max1364, max1136, convertors (ADC). (max1361, max1362, max1363, max1364, max1136,
......
...@@ -3,6 +3,6 @@ ...@@ -3,6 +3,6 @@
# #
max1363-y := max1363_core.o max1363-y := max1363_core.o
max1363-$(CONFIG_MAX1363_RING_BUFFER) += max1363_ring.o max1363-y += max1363_ring.o
obj-$(CONFIG_MAX1363) += max1363.o obj-$(CONFIG_MAX1363) += max1363.o
...@@ -72,77 +72,54 @@ ...@@ -72,77 +72,54 @@
* @numvals: The number of values returned by a single scan * @numvals: The number of values returned by a single scan
*/ */
struct max1363_mode { struct max1363_mode {
const char *name;
int8_t conf; int8_t conf;
int numvals; long modemask;
}; };
#define MAX1363_MODE_SINGLE(_num) { \ #define MAX1363_MODE_SINGLE(_num, _mask) { \
.name = #_num, \ .conf = MAX1363_CHANNEL_SEL(_num) \
.conf = MAX1363_CHANNEL_SEL(_num) \
| MAX1363_CONFIG_SCAN_SINGLE_1 \ | MAX1363_CONFIG_SCAN_SINGLE_1 \
| MAX1363_CONFIG_SE, \ | MAX1363_CONFIG_SE, \
.numvals = 1, \ .modemask = _mask, \
} }
#define MAX1363_MODE_SINGLE_TIMES_8(_num) { \ #define MAX1363_MODE_SCAN_TO_CHANNEL(_num, _mask) { \
.name = #_num"x8", \ .conf = MAX1363_CHANNEL_SEL(_num) \
.conf = MAX1363_CHANNEL_SEL(_num) \
| MAX1363_CONFIG_SCAN_SINGLE_8 \
| MAX1363_CONFIG_SE, \
.numvals = 8, \
}
#define MAX1363_MODE_SCAN_TO_CHANNEL(_num) { \
.name = "0..."#_num, \
.conf = MAX1363_CHANNEL_SEL(_num) \
| MAX1363_CONFIG_SCAN_TO_CS \ | MAX1363_CONFIG_SCAN_TO_CS \
| MAX1363_CONFIG_SE, \ | MAX1363_CONFIG_SE, \
.numvals = _num + 1, \ .modemask = _mask, \
} }
/* note not available for max1363 hence naming */ /* note not available for max1363 hence naming */
#define MAX1236_MODE_SCAN_MID_TO_CHANNEL(_mid, _num) { \ #define MAX1236_MODE_SCAN_MID_TO_CHANNEL(_mid, _num, _mask) { \
.name = #_mid"..."#_num, \ .conf = MAX1363_CHANNEL_SEL(_num) \
.conf = MAX1363_CHANNEL_SEL(_num) \
| MAX1236_SCAN_MID_TO_CHANNEL \ | MAX1236_SCAN_MID_TO_CHANNEL \
| MAX1363_CONFIG_SE, \ | MAX1363_CONFIG_SE, \
.numvals = _num - _mid + 1 \ .modemask = _mask \
} }
#define MAX1363_MODE_DIFF_SINGLE(_nump, _numm) { \ #define MAX1363_MODE_DIFF_SINGLE(_nump, _numm, _mask) { \
.name = #_nump"-"#_numm, \ .conf = MAX1363_CHANNEL_SEL(_nump) \
.conf = MAX1363_CHANNEL_SEL(_nump) \
| MAX1363_CONFIG_SCAN_SINGLE_1 \ | MAX1363_CONFIG_SCAN_SINGLE_1 \
| MAX1363_CONFIG_DE, \ | MAX1363_CONFIG_DE, \
.numvals = 1, \ .modemask = _mask \
}
#define MAX1363_MODE_DIFF_SINGLE_TIMES_8(_nump, _numm) { \
.name = #_nump"-"#_numm, \
.conf = MAX1363_CHANNEL_SEL(_nump) \
| MAX1363_CONFIG_SCAN_SINGLE_8 \
| MAX1363_CONFIG_DE, \
.numvals = 1, \
} }
/* Can't think how to automate naming so specify for now */ /* Can't think how to automate naming so specify for now */
#define MAX1363_MODE_DIFF_SCAN_TO_CHANNEL_NAMED(_name, _num, _numvals) { \ #define MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(_num, _numvals, _mask) { \
.name = #_name, \ .conf = MAX1363_CHANNEL_SEL(_num) \
.conf = MAX1363_CHANNEL_SEL(_num) \
| MAX1363_CONFIG_SCAN_TO_CS \ | MAX1363_CONFIG_SCAN_TO_CS \
| MAX1363_CONFIG_DE, \ | MAX1363_CONFIG_DE, \
.numvals = _numvals, \ .modemask = _mask \
} }
/* note only available for max1363 hence naming */ /* note only available for max1363 hence naming */
#define MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL_NAMED(_name, _num, _numvals) { \ #define MAX1236_MODE_DIFF_SCAN_MID_TO_CHANNEL(_num, _numvals, _mask) { \
.name = #_name, \ .conf = MAX1363_CHANNEL_SEL(_num) \
.conf = MAX1363_CHANNEL_SEL(_num) \
| MAX1236_SCAN_MID_TO_CHANNEL \ | MAX1236_SCAN_MID_TO_CHANNEL \
| MAX1363_CONFIG_SE, \ | MAX1363_CONFIG_SE, \
.numvals = _numvals, \ .modemask = _mask \
} }
/* Not currently handled */ /* Not currently handled */
...@@ -158,35 +135,43 @@ struct max1363_mode { ...@@ -158,35 +135,43 @@ struct max1363_mode {
* clear what all the various options actually do. Alternative suggestions * clear what all the various options actually do. Alternative suggestions
* that don't require user to have intimate knowledge of the chip welcomed. * that don't require user to have intimate knowledge of the chip welcomed.
*/ */
enum max1363_channels {
max1363_in0, max1363_in1, max1363_in2, max1363_in3,
max1363_in4, max1363_in5, max1363_in6, max1363_in7,
max1363_in8, max1363_in9, max1363_in10, max1363_in11,
max1363_in0min1, max1363_in2min3,
max1363_in4min5, max1363_in6min7,
max1363_in8min9, max1363_in10min11,
max1363_in1min0, max1363_in3min2,
max1363_in5min4, max1363_in7min6,
max1363_in9min8, max1363_in11min10,
};
/* This must be maintained along side the max1363_mode_table in max1363_core */ /* This must be maintained along side the max1363_mode_table in max1363_core */
enum max1363_modes { enum max1363_modes {
/* Single read of a single channel */ /* Single read of a single channel */
_s0, _s1, _s2, _s3, _s4, _s5, _s6, _s7, _s8, _s9, _s10, _s11, _s0, _s1, _s2, _s3, _s4, _s5, _s6, _s7, _s8, _s9, _s10, _s11,
/* Eight reads of a single channel */
se0, se1, se2, se3, se4, se5, se6, se7, se8, se9, se10, se11,
/* Scan to channel */
s0to1, s0to2, s0to3, s0to4, s0to5, s0to6,
s0to7, s0to8, s0to9, s0to10, s0to11,
/* Differential single read */ /* Differential single read */
d0m1, d2m3, d4m5, d6m7, d8m9, d10m11, d0m1, d2m3, d4m5, d6m7, d8m9, d10m11,
d1m0, d3m2, d5m4, d7m6, d9m8, d11m10, d1m0, d3m2, d5m4, d7m6, d9m8, d11m10,
/* Differential single read 8 times */ /* Scan to channel and mid to channel where overlapping */
de0m1, de2m3, de4m5, de6m7, de8m9, de10m11, s0to1, s0to2, s2to3, s0to3, s0to4, s0to5, s0to6,
de1m0, de3m2, de5m4, de7m6, de9m8, de11m10, s6to7, s0to7, s6to8, s0to8, s6to9,
/* Differential scan to channel */ s0to9, s6to10, s0to10, s6to11, s0to11,
d0m1to2m3, d0m1to4m5, d0m1to6m7, d0m1to8m9, d0m1to10m11, /* Differential scan to channel and mid to channel where overlapping */
d1m0to3m2, d1m0to5m4, d1m0to7m6, d1m0to9m8, d1m0to11m10, d0m1to2m3, d0m1to4m5, d0m1to6m7, d6m7to8m9,
/* Scan mid to channel max123{6-9} only */ d0m1to8m9, d6m7to10m11, d0m1to10m11, d1m0to3m2,
s2to3, s6to7, s6to8, s6to9, s6to10, s6to11, d1m0to5m4, d1m0to7m6, d7m6to9m8, d1m0to9m8,
/* Differential scan mid to channel */ d7m6to11m10, d1m0to11m10,
s6m7to8m9, s6m7to10m11, s7m6to9m8, s7m6to11m10,
}; };
/** /**
* struct max1363_chip_info - chip specifc information * struct max1363_chip_info - chip specifc information
* @name: indentification string for chip * @name: indentification string for chip
* @num_inputs: number of physical inputs on chip * @num_inputs: number of physical inputs on chip
* @bits: accuracy of the adc in bits
* @int_vref_mv: the internal reference voltage * @int_vref_mv: the internal reference voltage
* @monitor_mode: whether the chip supports monitor interrupts * @monitor_mode: whether the chip supports monitor interrupts
* @mode_list: array of available scan modes * @mode_list: array of available scan modes
...@@ -196,11 +181,14 @@ enum max1363_modes { ...@@ -196,11 +181,14 @@ enum max1363_modes {
struct max1363_chip_info { struct max1363_chip_info {
const char *name; const char *name;
u8 num_inputs; u8 num_inputs;
u8 bits;
u16 int_vref_mv; u16 int_vref_mv;
bool monitor_mode; bool monitor_mode;
const enum max1363_modes *mode_list; const enum max1363_modes *mode_list;
int num_modes; int num_modes;
enum max1363_modes default_mode; enum max1363_modes default_mode;
struct attribute_group *dev_attrs;
struct attribute_group *scan_attrs;
}; };
...@@ -212,6 +200,7 @@ struct max1363_chip_info { ...@@ -212,6 +200,7 @@ struct max1363_chip_info {
* @configbyte: cache of current device config byte * @configbyte: cache of current device config byte
* @chip_info: chip model specific constants, available modes etc * @chip_info: chip model specific constants, available modes etc
* @current_mode: the scan mode of this chip * @current_mode: the scan mode of this chip
* @requestedmask: a valid requested set of channels
* @poll_work: bottom half of polling interrupt handler * @poll_work: bottom half of polling interrupt handler
* @protect_ring: used to ensure only one polling bh running at a time * @protect_ring: used to ensure only one polling bh running at a time
* @reg: supply regulator * @reg: supply regulator
...@@ -223,16 +212,21 @@ struct max1363_state { ...@@ -223,16 +212,21 @@ struct max1363_state {
char configbyte; char configbyte;
const struct max1363_chip_info *chip_info; const struct max1363_chip_info *chip_info;
const struct max1363_mode *current_mode; const struct max1363_mode *current_mode;
u32 requestedmask;
struct work_struct poll_work; struct work_struct poll_work;
atomic_t protect_ring; atomic_t protect_ring;
struct iio_trigger *trig; struct iio_trigger *trig;
struct regulator *reg; struct regulator *reg;
}; };
const struct max1363_mode
*max1363_match_mode(u32 mask, const struct max1363_chip_info *ci);
int max1363_set_scan_mode(struct max1363_state *st);
#ifdef CONFIG_MAX1363_RING_BUFFER #ifdef CONFIG_MAX1363_RING_BUFFER
ssize_t max1363_scan_from_ring(struct device *dev, int max1363_single_channel_from_ring(long mask, struct max1363_state *st);
struct device_attribute *attr,
char *buf);
int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev); int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev);
void max1363_ring_cleanup(struct iio_dev *indio_dev); void max1363_ring_cleanup(struct iio_dev *indio_dev);
...@@ -250,14 +244,12 @@ static inline int max1363_initialize_ring(struct iio_ring_buffer *ring) ...@@ -250,14 +244,12 @@ static inline int max1363_initialize_ring(struct iio_ring_buffer *ring)
return 0; return 0;
}; };
int max1363_single_channel_from_ring(long mask, struct max1363_state *st)
static inline ssize_t max1363_scan_from_ring(struct device *dev,
struct device_attribute *attr,
char *buf)
{ {
return 0; return -EINVAL;
}; };
static inline int static inline int
max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev) max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev)
{ {
......
This diff is collapsed.
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/sysfs.h> #include <linux/sysfs.h>
#include <linux/list.h> #include <linux/list.h>
#include <linux/i2c.h> #include <linux/i2c.h>
#include <linux/bitops.h>
#include "../iio.h" #include "../iio.h"
#include "../ring_generic.h" #include "../ring_generic.h"
...@@ -26,32 +27,36 @@ ...@@ -26,32 +27,36 @@
#include "max1363.h" #include "max1363.h"
ssize_t max1363_scan_from_ring(struct device *dev, /* Todo: test this */
struct device_attribute *attr, int max1363_single_channel_from_ring(long mask, struct max1363_state *st)
char *buf)
{ {
struct iio_dev *dev_info = dev_get_drvdata(dev); unsigned long numvals;
struct max1363_state *info = dev_info->dev_data; int count = 0, ret;
int i, ret, len = 0; u8 *ring_data;
char *ring_data; if (!(st->current_mode->modemask & mask)) {
ret = -EBUSY;
goto error_ret;
}
numvals = hweight_long(st->current_mode->modemask);
ring_data = kmalloc(info->current_mode->numvals*2, GFP_KERNEL); ring_data = kmalloc(numvals*2, GFP_KERNEL);
if (ring_data == NULL) { if (ring_data == NULL) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_ret; goto error_ret;
} }
ret = dev_info->ring->access.read_last(dev_info->ring, ring_data); ret = st->indio_dev->ring->access.read_last(st->indio_dev->ring,
ring_data);
if (ret) if (ret)
goto error_free_ring_data; goto error_free_ring_data;
len += sprintf(buf+len, "ring "); /* Need a count of channels prior to this one */
for (i = 0; i < info->current_mode->numvals; i++) mask >>= 1;
len += sprintf(buf + len, "%d ", while (mask) {
((int)(ring_data[i*2 + 0] & 0x0F) << 8) if (mask && st->current_mode->modemask)
+ ((int)(ring_data[i*2 + 1]))); count++;
len += sprintf(buf + len, "\n"); mask >>= 1;
kfree(ring_data); }
return ((int)(ring_data[count*2 + 0] & 0x0F) << 8)
return len; + (int)(ring_data[count*2 + 1]);
error_free_ring_data: error_free_ring_data:
kfree(ring_data); kfree(ring_data);
...@@ -70,9 +75,22 @@ static int max1363_ring_preenable(struct iio_dev *indio_dev) ...@@ -70,9 +75,22 @@ static int max1363_ring_preenable(struct iio_dev *indio_dev)
{ {
struct max1363_state *st = indio_dev->dev_data; struct max1363_state *st = indio_dev->dev_data;
size_t d_size; size_t d_size;
unsigned long numvals;
/*
* Need to figure out the current mode based upon the requested
* scan mask in iio_dev
*/
st->current_mode = max1363_match_mode(st->indio_dev->scan_mask,
st->chip_info);
if (!st->current_mode)
return -EINVAL;
max1363_set_scan_mode(st);
numvals = hweight_long(st->current_mode->modemask);
if (indio_dev->ring->access.set_bpd) { if (indio_dev->ring->access.set_bpd) {
d_size = st->current_mode->numvals*2 + sizeof(s64); d_size = numvals*2 + sizeof(s64);
if (d_size % 8) if (d_size % 8)
d_size += 8 - (d_size % 8); d_size += 8 - (d_size % 8);
indio_dev->ring->access.set_bpd(indio_dev->ring, d_size); indio_dev->ring->access.set_bpd(indio_dev->ring, d_size);
...@@ -145,9 +163,10 @@ static void max1363_poll_bh_to_ring(struct work_struct *work_s) ...@@ -145,9 +163,10 @@ static void max1363_poll_bh_to_ring(struct work_struct *work_s)
__u8 *rxbuf; __u8 *rxbuf;
int b_sent; int b_sent;
size_t d_size; size_t d_size;
unsigned long numvals = hweight_long(st->current_mode->modemask);
/* Ensure the timestamp is 8 byte aligned */ /* Ensure the timestamp is 8 byte aligned */
d_size = st->current_mode->numvals*2 + sizeof(s64); d_size = numvals*2 + sizeof(s64);
if (d_size % sizeof(s64)) if (d_size % sizeof(s64))
d_size += sizeof(s64) - (d_size % sizeof(s64)); d_size += sizeof(s64) - (d_size % sizeof(s64));
...@@ -159,16 +178,14 @@ static void max1363_poll_bh_to_ring(struct work_struct *work_s) ...@@ -159,16 +178,14 @@ static void max1363_poll_bh_to_ring(struct work_struct *work_s)
* might as well have this test in here in the meantime as it does * might as well have this test in here in the meantime as it does
* no harm. * no harm.
*/ */
if (st->current_mode->numvals == 0) if (numvals == 0)
return; return;
rxbuf = kmalloc(d_size, GFP_KERNEL); rxbuf = kmalloc(d_size, GFP_KERNEL);
if (rxbuf == NULL) if (rxbuf == NULL)
return; return;
b_sent = i2c_master_recv(st->client, b_sent = i2c_master_recv(st->client, rxbuf, numvals*2);
rxbuf,
st->current_mode->numvals*2);
if (b_sent < 0) if (b_sent < 0)
goto done; goto done;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment