aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Cameron <jic23@kernel.org>2012-10-06 09:10:05 -0400
committerJonathan Cameron <jic23@kernel.org>2012-11-10 05:17:28 -0500
commitb3bcbfcfece186f3a3799460aea3da30577615f9 (patch)
tree814766714f9f477b5ba2997cac5bc997b1ccdf22
parent0d331e4fd26c6caafa27ff4048294b2bb9263b2a (diff)
staging:iio:adc:max1363 consolidate files.
For a long while now the max1363 core has selected the buffer anyway. For a while I meant to make the separation work again, but given how long it has been it is probably time to conclude it will never happen and settle for tidying up what we have. Signed-off-by: Jonathan Cameron <jic23@kernel.org>
-rw-r--r--drivers/staging/iio/adc/Kconfig16
-rw-r--r--drivers/staging/iio/adc/Makefile3
-rw-r--r--drivers/staging/iio/adc/max1363.c (renamed from drivers/staging/iio/adc/max1363_core.c)267
-rw-r--r--drivers/staging/iio/adc/max1363.h177
-rw-r--r--drivers/staging/iio/adc/max1363_ring.c139
5 files changed, 269 insertions, 333 deletions
diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig
index e662a5c55b5..4d348048b39 100644
--- a/drivers/staging/iio/adc/Kconfig
+++ b/drivers/staging/iio/adc/Kconfig
@@ -133,8 +133,10 @@ config AD7280
133config MAX1363 133config MAX1363
134 tristate "Maxim max1363 ADC driver" 134 tristate "Maxim max1363 ADC driver"
135 depends on I2C 135 depends on I2C
136 select IIO_TRIGGER if IIO_BUFFER 136 select IIO_TRIGGER
137 select MAX1363_RING_BUFFER 137 select MAX1363_RING_BUFFER
138 select IIO_BUFFER
139 select IIO_KFIFO_BUF
138 help 140 help
139 Say yes here to build support for many Maxim i2c analog to digital 141 Say yes here to build support for many Maxim i2c analog to digital
140 converters (ADC). (max1361, max1362, max1363, max1364, max1036, 142 converters (ADC). (max1361, max1362, max1363, max1364, max1036,
@@ -143,16 +145,8 @@ config MAX1363
143 max11602, max11603, max11604, max11605, max11606, max11607, 145 max11602, max11603, max11604, max11605, max11606, max11607,
144 max11608, max11609, max11610, max11611, max11612, max11613, 146 max11608, max11609, max11610, max11611, max11612, max11613,
145 max11614, max11615, max11616, max11617, max11644, max11645, 147 max11614, max11615, max11616, max11617, max11644, max11645,
146 max11646, max11647) Provides direct access via sysfs. 148 max11646, max11647) Provides direct access via sysfs and buffered
147 149 data via the iio dev interface.
148config MAX1363_RING_BUFFER
149 bool "Maxim max1363: use ring buffer"
150 depends on MAX1363
151 select IIO_BUFFER
152 select IIO_KFIFO_BUF
153 help
154 Say yes here to include ring buffer support in the MAX1363
155 ADC driver.
156 150
157config LPC32XX_ADC 151config LPC32XX_ADC
158 tristate "NXP LPC32XX ADC" 152 tristate "NXP LPC32XX ADC"
diff --git a/drivers/staging/iio/adc/Makefile b/drivers/staging/iio/adc/Makefile
index c56b41ee285..33979e62871 100644
--- a/drivers/staging/iio/adc/Makefile
+++ b/drivers/staging/iio/adc/Makefile
@@ -2,9 +2,6 @@
2# Makefile for industrial I/O ADC drivers 2# Makefile for industrial I/O ADC drivers
3# 3#
4 4
5max1363-y := max1363_core.o
6max1363-y += max1363_ring.o
7
8obj-$(CONFIG_MAX1363) += max1363.o 5obj-$(CONFIG_MAX1363) += max1363.o
9 6
10ad7606-y := ad7606_core.o 7ad7606-y := ad7606_core.o
diff --git a/drivers/staging/iio/adc/max1363_core.c b/drivers/staging/iio/adc/max1363.c
index d7b4ffcfa05..72715a4d594 100644
--- a/drivers/staging/iio/adc/max1363_core.c
+++ b/drivers/staging/iio/adc/max1363.c
@@ -37,8 +37,152 @@
37#include <linux/iio/events.h> 37#include <linux/iio/events.h>
38#include <linux/iio/buffer.h> 38#include <linux/iio/buffer.h>
39#include <linux/iio/driver.h> 39#include <linux/iio/driver.h>
40#include <linux/iio/kfifo_buf.h>
41#include <linux/iio/trigger_consumer.h>
42
43#define MAX1363_SETUP_BYTE(a) ((a) | 0x80)
44
45/* There is a fair bit more defined here than currently
46 * used, but the intention is to support everything these
47 * chips do in the long run */
48
49/* see data sheets */
50/* max1363 and max1236, max1237, max1238, max1239 */
51#define MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_VDD 0x00
52#define MAX1363_SETUP_AIN3_IS_REF_EXT_TO_REF 0x20
53#define MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_INT 0x40
54#define MAX1363_SETUP_AIN3_IS_REF_REF_IS_INT 0x60
55#define MAX1363_SETUP_POWER_UP_INT_REF 0x10
56#define MAX1363_SETUP_POWER_DOWN_INT_REF 0x00
57
58/* think about includeing max11600 etc - more settings */
59#define MAX1363_SETUP_EXT_CLOCK 0x08
60#define MAX1363_SETUP_INT_CLOCK 0x00
61#define MAX1363_SETUP_UNIPOLAR 0x00
62#define MAX1363_SETUP_BIPOLAR 0x04
63#define MAX1363_SETUP_RESET 0x00
64#define MAX1363_SETUP_NORESET 0x02
65/* max1363 only - though don't care on others.
66 * For now monitor modes are not implemented as the relevant
67 * line is not connected on my test board.
68 * The definitions are here as I intend to add this soon.
69 */
70#define MAX1363_SETUP_MONITOR_SETUP 0x01
71
72/* Specific to the max1363 */
73#define MAX1363_MON_RESET_CHAN(a) (1 << ((a) + 4))
74#define MAX1363_MON_INT_ENABLE 0x01
75
76/* defined for readability reasons */
77/* All chips */
78#define MAX1363_CONFIG_BYTE(a) ((a))
79
80#define MAX1363_CONFIG_SE 0x01
81#define MAX1363_CONFIG_DE 0x00
82#define MAX1363_CONFIG_SCAN_TO_CS 0x00
83#define MAX1363_CONFIG_SCAN_SINGLE_8 0x20
84#define MAX1363_CONFIG_SCAN_MONITOR_MODE 0x40
85#define MAX1363_CONFIG_SCAN_SINGLE_1 0x60
86/* max123{6-9} only */
87#define MAX1236_SCAN_MID_TO_CHANNEL 0x40
88
89/* max1363 only - merely part of channel selects or don't care for others*/
90#define MAX1363_CONFIG_EN_MON_MODE_READ 0x18
91
92#define MAX1363_CHANNEL_SEL(a) ((a) << 1)
93
94/* max1363 strictly 0x06 - but doesn't matter */
95#define MAX1363_CHANNEL_SEL_MASK 0x1E
96#define MAX1363_SCAN_MASK 0x60
97#define MAX1363_SE_DE_MASK 0x01
98
99#define MAX1363_MAX_CHANNELS 25
100/**
101 * struct max1363_mode - scan mode information
102 * @conf: The corresponding value of the configuration register
103 * @modemask: Bit mask corresponding to channels enabled in this mode
104 */
105struct max1363_mode {
106 int8_t conf;
107 DECLARE_BITMAP(modemask, MAX1363_MAX_CHANNELS);
108};
40 109
41#include "max1363.h" 110/* This must be maintained along side the max1363_mode_table in max1363_core */
111enum max1363_modes {
112 /* Single read of a single channel */
113 _s0, _s1, _s2, _s3, _s4, _s5, _s6, _s7, _s8, _s9, _s10, _s11,
114 /* Differential single read */
115 d0m1, d2m3, d4m5, d6m7, d8m9, d10m11,
116 d1m0, d3m2, d5m4, d7m6, d9m8, d11m10,
117 /* Scan to channel and mid to channel where overlapping */
118 s0to1, s0to2, s2to3, s0to3, s0to4, s0to5, s0to6,
119 s6to7, s0to7, s6to8, s0to8, s6to9,
120 s0to9, s6to10, s0to10, s6to11, s0to11,
121 /* Differential scan to channel and mid to channel where overlapping */
122 d0m1to2m3, d0m1to4m5, d0m1to6m7, d6m7to8m9,
123 d0m1to8m9, d6m7to10m11, d0m1to10m11, d1m0to3m2,
124 d1m0to5m4, d1m0to7m6, d7m6to9m8, d1m0to9m8,
125 d7m6to11m10, d1m0to11m10,
126};
127
128/**
129 * struct max1363_chip_info - chip specifc information
130 * @name: indentification string for chip
131 * @bits: accuracy of the adc in bits
132 * @int_vref_mv: the internal reference voltage
133 * @info: iio core function callbacks structure
134 * @mode_list: array of available scan modes
135 * @num_modes: the number of scan modes available
136 * @default_mode: the scan mode in which the chip starts up
137 * @channel: channel specification
138 * @num_channels: number of channels
139 */
140struct max1363_chip_info {
141 const struct iio_info *info;
142 const struct iio_chan_spec *channels;
143 int num_channels;
144 const enum max1363_modes *mode_list;
145 enum max1363_modes default_mode;
146 u16 int_vref_mv;
147 u8 num_modes;
148 u8 bits;
149};
150
151/**
152 * struct max1363_state - driver instance specific data
153 * @client: i2c_client
154 * @setupbyte: cache of current device setup byte
155 * @configbyte: cache of current device config byte
156 * @chip_info: chip model specific constants, available modes etc
157 * @current_mode: the scan mode of this chip
158 * @requestedmask: a valid requested set of channels
159 * @reg: supply regulator
160 * @monitor_on: whether monitor mode is enabled
161 * @monitor_speed: parameter corresponding to device monitor speed setting
162 * @mask_high: bitmask for enabled high thresholds
163 * @mask_low: bitmask for enabled low thresholds
164 * @thresh_high: high threshold values
165 * @thresh_low: low threshold values
166 */
167struct max1363_state {
168 struct i2c_client *client;
169 u8 setupbyte;
170 u8 configbyte;
171 const struct max1363_chip_info *chip_info;
172 const struct max1363_mode *current_mode;
173 u32 requestedmask;
174 struct regulator *reg;
175
176 /* Using monitor modes and buffer at the same time is
177 currently not supported */
178 bool monitor_on;
179 unsigned int monitor_speed:3;
180 u8 mask_high;
181 u8 mask_low;
182 /* 4x unipolar first then the fours bipolar ones */
183 s16 thresh_high[8];
184 s16 thresh_low[8];
185};
42 186
43#define MAX1363_MODE_SINGLE(_num, _mask) { \ 187#define MAX1363_MODE_SINGLE(_num, _mask) { \
44 .conf = MAX1363_CHANNEL_SEL(_num) \ 188 .conf = MAX1363_CHANNEL_SEL(_num) \
@@ -148,7 +292,7 @@ static const struct max1363_mode max1363_mode_table[] = {
148 MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(11, 6, 0xFC0000), 292 MAX1363_MODE_DIFF_SCAN_TO_CHANNEL(11, 6, 0xFC0000),
149}; 293};
150 294
151const struct max1363_mode 295static const struct max1363_mode
152*max1363_match_mode(const unsigned long *mask, 296*max1363_match_mode(const unsigned long *mask,
153const struct max1363_chip_info *ci) 297const struct max1363_chip_info *ci)
154{ 298{
@@ -172,7 +316,7 @@ static int max1363_write_basic_config(struct i2c_client *client,
172 return i2c_master_send(client, tx_buf, 2); 316 return i2c_master_send(client, tx_buf, 2);
173} 317}
174 318
175int max1363_set_scan_mode(struct max1363_state *st) 319static int max1363_set_scan_mode(struct max1363_state *st)
176{ 320{
177 st->configbyte &= ~(MAX1363_CHANNEL_SEL_MASK 321 st->configbyte &= ~(MAX1363_CHANNEL_SEL_MASK
178 | MAX1363_SCAN_MASK 322 | MAX1363_SCAN_MASK
@@ -828,6 +972,21 @@ static struct attribute_group max1363_event_attribute_group = {
828 972
829#define MAX1363_EVENT_FUNCS \ 973#define MAX1363_EVENT_FUNCS \
830 974
975static int max1363_update_scan_mode(struct iio_dev *indio_dev,
976 const unsigned long *scan_mask)
977{
978 struct max1363_state *st = iio_priv(indio_dev);
979
980 /*
981 * Need to figure out the current mode based upon the requested
982 * scan mask in iio_dev
983 */
984 st->current_mode = max1363_match_mode(scan_mask, st->chip_info);
985 if (!st->current_mode)
986 return -EINVAL;
987 max1363_set_scan_mode(st);
988 return 0;
989}
831 990
832static const struct iio_info max1238_info = { 991static const struct iio_info max1238_info = {
833 .read_raw = &max1363_read_raw, 992 .read_raw = &max1363_read_raw,
@@ -1269,6 +1428,108 @@ static int __devinit max1363_alloc_scan_masks(struct iio_dev *indio_dev)
1269 return 0; 1428 return 0;
1270} 1429}
1271 1430
1431
1432static irqreturn_t max1363_trigger_handler(int irq, void *p)
1433{
1434 struct iio_poll_func *pf = p;
1435 struct iio_dev *indio_dev = pf->indio_dev;
1436 struct max1363_state *st = iio_priv(indio_dev);
1437 s64 time_ns;
1438 __u8 *rxbuf;
1439 int b_sent;
1440 size_t d_size;
1441 unsigned long numvals = bitmap_weight(st->current_mode->modemask,
1442 MAX1363_MAX_CHANNELS);
1443
1444 /* Ensure the timestamp is 8 byte aligned */
1445 if (st->chip_info->bits != 8)
1446 d_size = numvals*2;
1447 else
1448 d_size = numvals;
1449 if (indio_dev->scan_timestamp) {
1450 d_size += sizeof(s64);
1451 if (d_size % sizeof(s64))
1452 d_size += sizeof(s64) - (d_size % sizeof(s64));
1453 }
1454 /* Monitor mode prevents reading. Whilst not currently implemented
1455 * might as well have this test in here in the meantime as it does
1456 * no harm.
1457 */
1458 if (numvals == 0)
1459 goto done;
1460
1461 rxbuf = kmalloc(d_size, GFP_KERNEL);
1462 if (rxbuf == NULL)
1463 goto done;
1464 if (st->chip_info->bits != 8)
1465 b_sent = i2c_master_recv(st->client, rxbuf, numvals*2);
1466 else
1467 b_sent = i2c_master_recv(st->client, rxbuf, numvals);
1468 if (b_sent < 0)
1469 goto done_free;
1470
1471 time_ns = iio_get_time_ns();
1472
1473 if (indio_dev->scan_timestamp)
1474 memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
1475 iio_push_to_buffers(indio_dev, rxbuf);
1476
1477done_free:
1478 kfree(rxbuf);
1479done:
1480 iio_trigger_notify_done(indio_dev->trig);
1481
1482 return IRQ_HANDLED;
1483}
1484
1485static const struct iio_buffer_setup_ops max1363_ring_setup_ops = {
1486 .postenable = &iio_triggered_buffer_postenable,
1487 .preenable = &iio_sw_buffer_preenable,
1488 .predisable = &iio_triggered_buffer_predisable,
1489};
1490
1491static int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev)
1492{
1493 struct max1363_state *st = iio_priv(indio_dev);
1494 int ret = 0;
1495
1496 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
1497 if (!indio_dev->buffer) {
1498 ret = -ENOMEM;
1499 goto error_ret;
1500 }
1501 indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
1502 &max1363_trigger_handler,
1503 IRQF_ONESHOT,
1504 indio_dev,
1505 "%s_consumer%d",
1506 st->client->name,
1507 indio_dev->id);
1508 if (indio_dev->pollfunc == NULL) {
1509 ret = -ENOMEM;
1510 goto error_deallocate_sw_rb;
1511 }
1512 /* Ring buffer functions - here trigger setup related */
1513 indio_dev->setup_ops = &max1363_ring_setup_ops;
1514
1515 /* Flag that polled ring buffering is possible */
1516 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
1517
1518 return 0;
1519
1520error_deallocate_sw_rb:
1521 iio_kfifo_free(indio_dev->buffer);
1522error_ret:
1523 return ret;
1524}
1525
1526static void max1363_ring_cleanup(struct iio_dev *indio_dev)
1527{
1528 /* ensure that the trigger has been detached */
1529 iio_dealloc_pollfunc(indio_dev->pollfunc);
1530 iio_kfifo_free(indio_dev->buffer);
1531}
1532
1272static int __devinit max1363_probe(struct i2c_client *client, 1533static int __devinit max1363_probe(struct i2c_client *client,
1273 const struct i2c_device_id *id) 1534 const struct i2c_device_id *id)
1274{ 1535{
diff --git a/drivers/staging/iio/adc/max1363.h b/drivers/staging/iio/adc/max1363.h
deleted file mode 100644
index c746918683f..00000000000
--- a/drivers/staging/iio/adc/max1363.h
+++ /dev/null
@@ -1,177 +0,0 @@
1#ifndef _MAX1363_H_
2#define _MAX1363_H_
3
4#define MAX1363_SETUP_BYTE(a) ((a) | 0x80)
5
6/* There is a fair bit more defined here than currently
7 * used, but the intention is to support everything these
8 * chips do in the long run */
9
10/* see data sheets */
11/* max1363 and max1236, max1237, max1238, max1239 */
12#define MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_VDD 0x00
13#define MAX1363_SETUP_AIN3_IS_REF_EXT_TO_REF 0x20
14#define MAX1363_SETUP_AIN3_IS_AIN3_REF_IS_INT 0x40
15#define MAX1363_SETUP_AIN3_IS_REF_REF_IS_INT 0x60
16#define MAX1363_SETUP_POWER_UP_INT_REF 0x10
17#define MAX1363_SETUP_POWER_DOWN_INT_REF 0x00
18
19/* think about includeing max11600 etc - more settings */
20#define MAX1363_SETUP_EXT_CLOCK 0x08
21#define MAX1363_SETUP_INT_CLOCK 0x00
22#define MAX1363_SETUP_UNIPOLAR 0x00
23#define MAX1363_SETUP_BIPOLAR 0x04
24#define MAX1363_SETUP_RESET 0x00
25#define MAX1363_SETUP_NORESET 0x02
26/* max1363 only - though don't care on others.
27 * For now monitor modes are not implemented as the relevant
28 * line is not connected on my test board.
29 * The definitions are here as I intend to add this soon.
30 */
31#define MAX1363_SETUP_MONITOR_SETUP 0x01
32
33/* Specific to the max1363 */
34#define MAX1363_MON_RESET_CHAN(a) (1 << ((a) + 4))
35#define MAX1363_MON_INT_ENABLE 0x01
36
37/* defined for readability reasons */
38/* All chips */
39#define MAX1363_CONFIG_BYTE(a) ((a))
40
41#define MAX1363_CONFIG_SE 0x01
42#define MAX1363_CONFIG_DE 0x00
43#define MAX1363_CONFIG_SCAN_TO_CS 0x00
44#define MAX1363_CONFIG_SCAN_SINGLE_8 0x20
45#define MAX1363_CONFIG_SCAN_MONITOR_MODE 0x40
46#define MAX1363_CONFIG_SCAN_SINGLE_1 0x60
47/* max123{6-9} only */
48#define MAX1236_SCAN_MID_TO_CHANNEL 0x40
49
50/* max1363 only - merely part of channel selects or don't care for others*/
51#define MAX1363_CONFIG_EN_MON_MODE_READ 0x18
52
53#define MAX1363_CHANNEL_SEL(a) ((a) << 1)
54
55/* max1363 strictly 0x06 - but doesn't matter */
56#define MAX1363_CHANNEL_SEL_MASK 0x1E
57#define MAX1363_SCAN_MASK 0x60
58#define MAX1363_SE_DE_MASK 0x01
59
60#define MAX1363_MAX_CHANNELS 25
61/**
62 * struct max1363_mode - scan mode information
63 * @conf: The corresponding value of the configuration register
64 * @modemask: Bit mask corresponding to channels enabled in this mode
65 */
66struct max1363_mode {
67 int8_t conf;
68 DECLARE_BITMAP(modemask, MAX1363_MAX_CHANNELS);
69};
70
71/* This must be maintained along side the max1363_mode_table in max1363_core */
72enum max1363_modes {
73 /* Single read of a single channel */
74 _s0, _s1, _s2, _s3, _s4, _s5, _s6, _s7, _s8, _s9, _s10, _s11,
75 /* Differential single read */
76 d0m1, d2m3, d4m5, d6m7, d8m9, d10m11,
77 d1m0, d3m2, d5m4, d7m6, d9m8, d11m10,
78 /* Scan to channel and mid to channel where overlapping */
79 s0to1, s0to2, s2to3, s0to3, s0to4, s0to5, s0to6,
80 s6to7, s0to7, s6to8, s0to8, s6to9,
81 s0to9, s6to10, s0to10, s6to11, s0to11,
82 /* Differential scan to channel and mid to channel where overlapping */
83 d0m1to2m3, d0m1to4m5, d0m1to6m7, d6m7to8m9,
84 d0m1to8m9, d6m7to10m11, d0m1to10m11, d1m0to3m2,
85 d1m0to5m4, d1m0to7m6, d7m6to9m8, d1m0to9m8,
86 d7m6to11m10, d1m0to11m10,
87};
88
89/**
90 * struct max1363_chip_info - chip specifc information
91 * @name: indentification string for chip
92 * @bits: accuracy of the adc in bits
93 * @int_vref_mv: the internal reference voltage
94 * @info: iio core function callbacks structure
95 * @mode_list: array of available scan modes
96 * @num_modes: the number of scan modes available
97 * @default_mode: the scan mode in which the chip starts up
98 * @channel: channel specification
99 * @num_channels: number of channels
100 */
101struct max1363_chip_info {
102 const struct iio_info *info;
103 const struct iio_chan_spec *channels;
104 int num_channels;
105 const enum max1363_modes *mode_list;
106 enum max1363_modes default_mode;
107 u16 int_vref_mv;
108 u8 num_modes;
109 u8 bits;
110};
111
112/**
113 * struct max1363_state - driver instance specific data
114 * @client: i2c_client
115 * @setupbyte: cache of current device setup byte
116 * @configbyte: cache of current device config byte
117 * @chip_info: chip model specific constants, available modes etc
118 * @current_mode: the scan mode of this chip
119 * @requestedmask: a valid requested set of channels
120 * @reg: supply regulator
121 * @monitor_on: whether monitor mode is enabled
122 * @monitor_speed: parameter corresponding to device monitor speed setting
123 * @mask_high: bitmask for enabled high thresholds
124 * @mask_low: bitmask for enabled low thresholds
125 * @thresh_high: high threshold values
126 * @thresh_low: low threshold values
127 */
128struct max1363_state {
129 struct i2c_client *client;
130 u8 setupbyte;
131 u8 configbyte;
132 const struct max1363_chip_info *chip_info;
133 const struct max1363_mode *current_mode;
134 u32 requestedmask;
135 struct regulator *reg;
136
137 /* Using monitor modes and buffer at the same time is
138 currently not supported */
139 bool monitor_on;
140 unsigned int monitor_speed:3;
141 u8 mask_high;
142 u8 mask_low;
143 /* 4x unipolar first then the fours bipolar ones */
144 s16 thresh_high[8];
145 s16 thresh_low[8];
146};
147
148const struct max1363_mode
149*max1363_match_mode(const unsigned long *mask,
150 const struct max1363_chip_info *ci);
151
152int max1363_set_scan_mode(struct max1363_state *st);
153
154#ifdef CONFIG_MAX1363_RING_BUFFER
155int max1363_update_scan_mode(struct iio_dev *indio_dev,
156 const unsigned long *scan_mask);
157int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev);
158void max1363_ring_cleanup(struct iio_dev *indio_dev);
159
160#else /* CONFIG_MAX1363_RING_BUFFER */
161int max1363_update_scan_mode(struct iio_dev *indio_dev,
162 const long *scan_mask)
163{
164 return 0;
165}
166
167static inline int
168max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev)
169{
170 return 0;
171}
172
173static inline void max1363_ring_cleanup(struct iio_dev *indio_dev)
174{
175}
176#endif /* CONFIG_MAX1363_RING_BUFFER */
177#endif /* _MAX1363_H_ */
diff --git a/drivers/staging/iio/adc/max1363_ring.c b/drivers/staging/iio/adc/max1363_ring.c
deleted file mode 100644
index 41af17b5e74..00000000000
--- a/drivers/staging/iio/adc/max1363_ring.c
+++ /dev/null
@@ -1,139 +0,0 @@
1/*
2 * Copyright (C) 2008 Jonathan Cameron
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * max1363_ring.c
9 */
10
11#include <linux/interrupt.h>
12#include <linux/slab.h>
13#include <linux/kernel.h>
14#include <linux/i2c.h>
15#include <linux/bitops.h>
16
17#include <linux/iio/iio.h>
18#include <linux/iio/buffer.h>
19#include <linux/iio/kfifo_buf.h>
20#include <linux/iio/trigger_consumer.h>
21
22#include "max1363.h"
23
24int max1363_update_scan_mode(struct iio_dev *indio_dev,
25 const unsigned long *scan_mask)
26{
27 struct max1363_state *st = iio_priv(indio_dev);
28
29 /*
30 * Need to figure out the current mode based upon the requested
31 * scan mask in iio_dev
32 */
33 st->current_mode = max1363_match_mode(scan_mask, st->chip_info);
34 if (!st->current_mode)
35 return -EINVAL;
36 max1363_set_scan_mode(st);
37 return 0;
38}
39
40static irqreturn_t max1363_trigger_handler(int irq, void *p)
41{
42 struct iio_poll_func *pf = p;
43 struct iio_dev *indio_dev = pf->indio_dev;
44 struct max1363_state *st = iio_priv(indio_dev);
45 s64 time_ns;
46 __u8 *rxbuf;
47 int b_sent;
48 size_t d_size;
49 unsigned long numvals = bitmap_weight(st->current_mode->modemask,
50 MAX1363_MAX_CHANNELS);
51
52 /* Ensure the timestamp is 8 byte aligned */
53 if (st->chip_info->bits != 8)
54 d_size = numvals*2;
55 else
56 d_size = numvals;
57 if (indio_dev->scan_timestamp) {
58 d_size += sizeof(s64);
59 if (d_size % sizeof(s64))
60 d_size += sizeof(s64) - (d_size % sizeof(s64));
61 }
62 /* Monitor mode prevents reading. Whilst not currently implemented
63 * might as well have this test in here in the meantime as it does
64 * no harm.
65 */
66 if (numvals == 0)
67 goto done;
68
69 rxbuf = kmalloc(d_size, GFP_KERNEL);
70 if (rxbuf == NULL)
71 goto done;
72 if (st->chip_info->bits != 8)
73 b_sent = i2c_master_recv(st->client, rxbuf, numvals*2);
74 else
75 b_sent = i2c_master_recv(st->client, rxbuf, numvals);
76 if (b_sent < 0)
77 goto done_free;
78
79 time_ns = iio_get_time_ns();
80
81 if (indio_dev->scan_timestamp)
82 memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
83 iio_push_to_buffers(indio_dev, rxbuf);
84
85done_free:
86 kfree(rxbuf);
87done:
88 iio_trigger_notify_done(indio_dev->trig);
89
90 return IRQ_HANDLED;
91}
92
93static const struct iio_buffer_setup_ops max1363_ring_setup_ops = {
94 .postenable = &iio_triggered_buffer_postenable,
95 .preenable = &iio_sw_buffer_preenable,
96 .predisable = &iio_triggered_buffer_predisable,
97};
98
99int max1363_register_ring_funcs_and_init(struct iio_dev *indio_dev)
100{
101 struct max1363_state *st = iio_priv(indio_dev);
102 int ret = 0;
103
104 indio_dev->buffer = iio_kfifo_allocate(indio_dev);
105 if (!indio_dev->buffer) {
106 ret = -ENOMEM;
107 goto error_ret;
108 }
109 indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
110 &max1363_trigger_handler,
111 IRQF_ONESHOT,
112 indio_dev,
113 "%s_consumer%d",
114 st->client->name,
115 indio_dev->id);
116 if (indio_dev->pollfunc == NULL) {
117 ret = -ENOMEM;
118 goto error_deallocate_sw_rb;
119 }
120 /* Ring buffer functions - here trigger setup related */
121 indio_dev->setup_ops = &max1363_ring_setup_ops;
122
123 /* Flag that polled ring buffering is possible */
124 indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
125
126 return 0;
127
128error_deallocate_sw_rb:
129 iio_kfifo_free(indio_dev->buffer);
130error_ret:
131 return ret;
132}
133
134void max1363_ring_cleanup(struct iio_dev *indio_dev)
135{
136 /* ensure that the trigger has been detached */
137 iio_dealloc_pollfunc(indio_dev->pollfunc);
138 iio_kfifo_free(indio_dev->buffer);
139}