blob: 45bb3a43afacdf157667219b9ccc5766da52efe3 [file] [log] [blame]
Jonathan Cameron847ec802009-08-18 18:06:19 +01001/* The industrial I/O core
2 *
3 * Copyright (c) 2008 Jonathan Cameron
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 as published by
7 * the Free Software Foundation.
8 *
9 * Based on elements of hwmon and input subsystems.
10 */
11
Sachin Kamat3176dd52013-10-24 12:53:00 +010012#define pr_fmt(fmt) "iio-core: " fmt
13
Jonathan Cameron847ec802009-08-18 18:06:19 +010014#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/idr.h>
17#include <linux/kdev_t.h>
18#include <linux/err.h>
19#include <linux/device.h>
20#include <linux/fs.h>
Jonathan Cameron847ec802009-08-18 18:06:19 +010021#include <linux/poll.h>
Jonathan Cameronffc18af2009-10-12 19:18:09 +010022#include <linux/sched.h>
Jeff Mahoney4439c932009-10-12 17:10:34 -040023#include <linux/wait.h>
Jonathan Cameron847ec802009-08-18 18:06:19 +010024#include <linux/cdev.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090025#include <linux/slab.h>
Jonathan Cameron8e7d9672011-08-30 12:32:45 +010026#include <linux/anon_inodes.h>
Michael Henneriche553f182012-03-01 10:51:03 +010027#include <linux/debugfs.h>
Jonathan Cameron06458e22012-04-25 15:54:58 +010028#include <linux/iio/iio.h>
Jonathan Camerondf9c1c42011-08-12 17:56:03 +010029#include "iio_core.h"
Jonathan Cameron6aea1c32011-08-24 17:28:38 +010030#include "iio_core_trigger.h"
Jonathan Cameron06458e22012-04-25 15:54:58 +010031#include <linux/iio/sysfs.h>
32#include <linux/iio/events.h>
Lars-Peter Clausen9e69c932013-10-04 12:06:00 +010033#include <linux/iio/buffer.h>
Jonathan Cameron9dd1cb32011-08-30 12:41:15 +010034
Peter Meerwald99698b42012-08-26 13:43:00 +010035/* IDA to assign each registered device a unique id */
Jonathan Cameronb156cf72010-09-04 17:54:43 +010036static DEFINE_IDA(iio_ida);
Jonathan Cameron847ec802009-08-18 18:06:19 +010037
Jonathan Cameronf625cb92011-08-30 12:32:48 +010038static dev_t iio_devt;
Jonathan Cameron847ec802009-08-18 18:06:19 +010039
40#define IIO_DEV_MAX 256
Jonathan Cameron5aaaeba2010-05-04 14:43:00 +010041struct bus_type iio_bus_type = {
Jonathan Cameron847ec802009-08-18 18:06:19 +010042 .name = "iio",
Jonathan Cameron847ec802009-08-18 18:06:19 +010043};
Jonathan Cameron5aaaeba2010-05-04 14:43:00 +010044EXPORT_SYMBOL(iio_bus_type);
Jonathan Cameron847ec802009-08-18 18:06:19 +010045
Michael Henneriche553f182012-03-01 10:51:03 +010046static struct dentry *iio_debugfs_dentry;
47
Jonathan Cameronc6fc8062011-09-02 17:14:34 +010048static const char * const iio_direction[] = {
49 [0] = "in",
50 [1] = "out",
51};
52
Jonathan Cameronade7ef72011-09-02 17:14:45 +010053static const char * const iio_chan_type_name_spec[] = {
Jonathan Cameronc6fc8062011-09-02 17:14:34 +010054 [IIO_VOLTAGE] = "voltage",
Michael Hennerichfaf290e2011-05-18 14:42:02 +010055 [IIO_CURRENT] = "current",
56 [IIO_POWER] = "power",
Bryan Freed9bff02f2011-07-07 12:01:54 -070057 [IIO_ACCEL] = "accel",
Jonathan Cameron41ea0402011-10-05 15:27:59 +010058 [IIO_ANGL_VEL] = "anglvel",
Jonathan Cameron1d892712011-05-18 14:40:51 +010059 [IIO_MAGN] = "magn",
Bryan Freed9bff02f2011-07-07 12:01:54 -070060 [IIO_LIGHT] = "illuminance",
61 [IIO_INTENSITY] = "intensity",
Bryan Freedf09f2c82011-07-07 12:01:55 -070062 [IIO_PROXIMITY] = "proximity",
Bryan Freed9bff02f2011-07-07 12:01:54 -070063 [IIO_TEMP] = "temp",
Jonathan Cameron1d892712011-05-18 14:40:51 +010064 [IIO_INCLI] = "incli",
65 [IIO_ROT] = "rot",
Jonathan Cameron1d892712011-05-18 14:40:51 +010066 [IIO_ANGL] = "angl",
Bryan Freed9bff02f2011-07-07 12:01:54 -070067 [IIO_TIMESTAMP] = "timestamp",
Jonathan Cameron66dbe702011-09-02 17:14:43 +010068 [IIO_CAPACITANCE] = "capacitance",
Michael Hennericha6b12852012-04-27 10:58:34 +020069 [IIO_ALTVOLTAGE] = "altvoltage",
Jon Brenner21cd1fa2012-05-16 10:46:42 -050070 [IIO_CCT] = "cct",
Lars-Peter Clausenc4f0c692012-11-20 13:36:00 +000071 [IIO_PRESSURE] = "pressure",
Harald Geyerac216aa2013-12-01 15:08:00 +000072 [IIO_HUMIDITYRELATIVE] = "humidityrelative",
Daniel Baluta55aebeb2014-11-10 14:45:30 +020073 [IIO_ACTIVITY] = "activity",
Irina Tirdeaa88bfe72014-11-10 14:45:32 +020074 [IIO_STEPS] = "steps",
Jonathan Cameron1d892712011-05-18 14:40:51 +010075};
76
Jonathan Cameron330c6c52011-09-02 17:14:39 +010077static const char * const iio_modifier_names[] = {
Jonathan Cameron1d892712011-05-18 14:40:51 +010078 [IIO_MOD_X] = "x",
79 [IIO_MOD_Y] = "y",
80 [IIO_MOD_Z] = "z",
Jonathan Cameron8f5879b2012-05-05 10:39:22 +010081 [IIO_MOD_ROOT_SUM_SQUARED_X_Y] = "sqrt(x^2+y^2)",
Jonathan Cameroncf82cb82012-05-05 10:56:41 +010082 [IIO_MOD_SUM_SQUARED_X_Y_Z] = "x^2+y^2+z^2",
Jonathan Cameron330c6c52011-09-02 17:14:39 +010083 [IIO_MOD_LIGHT_BOTH] = "both",
84 [IIO_MOD_LIGHT_IR] = "ir",
Jon Brenner21cd1fa2012-05-16 10:46:42 -050085 [IIO_MOD_LIGHT_CLEAR] = "clear",
86 [IIO_MOD_LIGHT_RED] = "red",
87 [IIO_MOD_LIGHT_GREEN] = "green",
88 [IIO_MOD_LIGHT_BLUE] = "blue",
Srinivas Pandruvada5082f402014-04-29 00:51:00 +010089 [IIO_MOD_QUATERNION] = "quaternion",
Peter Meerwald638b43b2014-02-05 16:57:00 +000090 [IIO_MOD_TEMP_AMBIENT] = "ambient",
91 [IIO_MOD_TEMP_OBJECT] = "object",
Reyad Attiyat11b8dda2014-07-17 19:18:00 +010092 [IIO_MOD_NORTH_MAGN] = "from_north_magnetic",
93 [IIO_MOD_NORTH_TRUE] = "from_north_true",
94 [IIO_MOD_NORTH_MAGN_TILT_COMP] = "from_north_magnetic_tilt_comp",
95 [IIO_MOD_NORTH_TRUE_TILT_COMP] = "from_north_true_tilt_comp",
Daniel Baluta55aebeb2014-11-10 14:45:30 +020096 [IIO_MOD_RUNNING] = "running",
97 [IIO_MOD_JOGGING] = "jogging",
98 [IIO_MOD_WALKING] = "walking",
99 [IIO_MOD_STILL] = "still",
Jonathan Cameron1d892712011-05-18 14:40:51 +0100100};
101
102/* relies on pairs of these shared then separate */
103static const char * const iio_chan_info_postfix[] = {
Jonathan Cameron75a973c2012-04-15 17:41:30 +0100104 [IIO_CHAN_INFO_RAW] = "raw",
105 [IIO_CHAN_INFO_PROCESSED] = "input",
Jonathan Cameronc8a9f802011-10-26 17:41:36 +0100106 [IIO_CHAN_INFO_SCALE] = "scale",
107 [IIO_CHAN_INFO_OFFSET] = "offset",
108 [IIO_CHAN_INFO_CALIBSCALE] = "calibscale",
109 [IIO_CHAN_INFO_CALIBBIAS] = "calibbias",
110 [IIO_CHAN_INFO_PEAK] = "peak_raw",
111 [IIO_CHAN_INFO_PEAK_SCALE] = "peak_scale",
112 [IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW] = "quadrature_correction_raw",
113 [IIO_CHAN_INFO_AVERAGE_RAW] = "mean_raw",
Jonathan Camerondf94aba2011-11-27 11:39:12 +0000114 [IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY]
115 = "filter_low_pass_3db_frequency",
Laxman Dewangance85a1c2012-04-13 16:03:31 +0530116 [IIO_CHAN_INFO_SAMP_FREQ] = "sampling_frequency",
Michael Hennericha6b12852012-04-27 10:58:34 +0200117 [IIO_CHAN_INFO_FREQUENCY] = "frequency",
118 [IIO_CHAN_INFO_PHASE] = "phase",
Michael Hennerichb65d6212012-05-11 11:36:53 +0200119 [IIO_CHAN_INFO_HARDWAREGAIN] = "hardwaregain",
srinivas pandruvada7c9ab032012-09-05 13:56:00 +0100120 [IIO_CHAN_INFO_HYSTERESIS] = "hysteresis",
Peter Meerwald899d90b2013-09-08 16:20:00 +0100121 [IIO_CHAN_INFO_INT_TIME] = "integration_time",
Irina Tirdeaa88bfe72014-11-10 14:45:32 +0200122 [IIO_CHAN_INFO_ENABLE] = "en",
Irina Tirdeabcdf28f2014-11-10 14:45:33 +0200123 [IIO_CHAN_INFO_CALIBHEIGHT] = "calibheight",
Jonathan Cameron1d892712011-05-18 14:40:51 +0100124};
125
Sachin Kamata7e57dc2013-10-29 11:39:00 +0000126/**
127 * iio_find_channel_from_si() - get channel from its scan index
128 * @indio_dev: device
129 * @si: scan index to match
130 */
Jonathan Cameron5fb21c82011-12-05 21:37:10 +0000131const struct iio_chan_spec
132*iio_find_channel_from_si(struct iio_dev *indio_dev, int si)
133{
134 int i;
135
136 for (i = 0; i < indio_dev->num_channels; i++)
137 if (indio_dev->channels[i].scan_index == si)
138 return &indio_dev->channels[i];
139 return NULL;
140}
141
Jonathan Cameron847ec802009-08-18 18:06:19 +0100142/* This turns up an awful lot */
143ssize_t iio_read_const_attr(struct device *dev,
144 struct device_attribute *attr,
145 char *buf)
146{
147 return sprintf(buf, "%s\n", to_iio_const_attr(attr)->string);
148}
149EXPORT_SYMBOL(iio_read_const_attr);
150
Jonathan Cameron847ec802009-08-18 18:06:19 +0100151static int __init iio_init(void)
152{
153 int ret;
154
Jonathan Cameron5aaaeba2010-05-04 14:43:00 +0100155 /* Register sysfs bus */
156 ret = bus_register(&iio_bus_type);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100157 if (ret < 0) {
Sachin Kamat3176dd52013-10-24 12:53:00 +0100158 pr_err("could not register bus type\n");
Jonathan Cameron847ec802009-08-18 18:06:19 +0100159 goto error_nothing;
160 }
161
Jonathan Cameron9aa1a162011-08-12 17:08:50 +0100162 ret = alloc_chrdev_region(&iio_devt, 0, IIO_DEV_MAX, "iio");
163 if (ret < 0) {
Sachin Kamat3176dd52013-10-24 12:53:00 +0100164 pr_err("failed to allocate char dev region\n");
Jonathan Cameron5aaaeba2010-05-04 14:43:00 +0100165 goto error_unregister_bus_type;
Jonathan Cameron9aa1a162011-08-12 17:08:50 +0100166 }
Jonathan Cameron847ec802009-08-18 18:06:19 +0100167
Michael Henneriche553f182012-03-01 10:51:03 +0100168 iio_debugfs_dentry = debugfs_create_dir("iio", NULL);
169
Jonathan Cameron847ec802009-08-18 18:06:19 +0100170 return 0;
171
Jonathan Cameron5aaaeba2010-05-04 14:43:00 +0100172error_unregister_bus_type:
173 bus_unregister(&iio_bus_type);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100174error_nothing:
175 return ret;
176}
177
178static void __exit iio_exit(void)
179{
Jonathan Cameron9aa1a162011-08-12 17:08:50 +0100180 if (iio_devt)
181 unregister_chrdev_region(iio_devt, IIO_DEV_MAX);
Jonathan Cameron5aaaeba2010-05-04 14:43:00 +0100182 bus_unregister(&iio_bus_type);
Michael Henneriche553f182012-03-01 10:51:03 +0100183 debugfs_remove(iio_debugfs_dentry);
184}
185
186#if defined(CONFIG_DEBUG_FS)
Michael Henneriche553f182012-03-01 10:51:03 +0100187static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf,
188 size_t count, loff_t *ppos)
189{
190 struct iio_dev *indio_dev = file->private_data;
191 char buf[20];
192 unsigned val = 0;
193 ssize_t len;
194 int ret;
195
196 ret = indio_dev->info->debugfs_reg_access(indio_dev,
197 indio_dev->cached_reg_addr,
198 0, &val);
199 if (ret)
200 dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__);
201
202 len = snprintf(buf, sizeof(buf), "0x%X\n", val);
203
204 return simple_read_from_buffer(userbuf, count, ppos, buf, len);
205}
206
207static ssize_t iio_debugfs_write_reg(struct file *file,
208 const char __user *userbuf, size_t count, loff_t *ppos)
209{
210 struct iio_dev *indio_dev = file->private_data;
211 unsigned reg, val;
212 char buf[80];
213 int ret;
214
215 count = min_t(size_t, count, (sizeof(buf)-1));
216 if (copy_from_user(buf, userbuf, count))
217 return -EFAULT;
218
219 buf[count] = 0;
220
221 ret = sscanf(buf, "%i %i", &reg, &val);
222
223 switch (ret) {
224 case 1:
225 indio_dev->cached_reg_addr = reg;
226 break;
227 case 2:
228 indio_dev->cached_reg_addr = reg;
229 ret = indio_dev->info->debugfs_reg_access(indio_dev, reg,
230 val, NULL);
231 if (ret) {
232 dev_err(indio_dev->dev.parent, "%s: write failed\n",
233 __func__);
234 return ret;
235 }
236 break;
237 default:
238 return -EINVAL;
239 }
240
241 return count;
242}
243
244static const struct file_operations iio_debugfs_reg_fops = {
Axel Lin5a28c872012-05-03 09:50:51 +0800245 .open = simple_open,
Michael Henneriche553f182012-03-01 10:51:03 +0100246 .read = iio_debugfs_read_reg,
247 .write = iio_debugfs_write_reg,
248};
249
250static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
251{
252 debugfs_remove_recursive(indio_dev->debugfs_dentry);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100253}
254
Michael Henneriche553f182012-03-01 10:51:03 +0100255static int iio_device_register_debugfs(struct iio_dev *indio_dev)
256{
257 struct dentry *d;
258
259 if (indio_dev->info->debugfs_reg_access == NULL)
260 return 0;
261
Axel Linabd5a2f2012-05-03 22:56:58 +0800262 if (!iio_debugfs_dentry)
Michael Henneriche553f182012-03-01 10:51:03 +0100263 return 0;
264
265 indio_dev->debugfs_dentry =
266 debugfs_create_dir(dev_name(&indio_dev->dev),
267 iio_debugfs_dentry);
Michael Henneriche553f182012-03-01 10:51:03 +0100268 if (indio_dev->debugfs_dentry == NULL) {
269 dev_warn(indio_dev->dev.parent,
270 "Failed to create debugfs directory\n");
271 return -EFAULT;
272 }
273
274 d = debugfs_create_file("direct_reg_access", 0644,
275 indio_dev->debugfs_dentry,
276 indio_dev, &iio_debugfs_reg_fops);
277 if (!d) {
278 iio_device_unregister_debugfs(indio_dev);
279 return -ENOMEM;
280 }
281
282 return 0;
283}
284#else
285static int iio_device_register_debugfs(struct iio_dev *indio_dev)
286{
287 return 0;
288}
289
290static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
291{
292}
293#endif /* CONFIG_DEBUG_FS */
294
Lars-Peter Clausen4fee7e12012-03-06 20:43:45 +0100295static ssize_t iio_read_channel_ext_info(struct device *dev,
296 struct device_attribute *attr,
297 char *buf)
298{
Lars-Peter Clausene53f5ac2012-05-12 15:39:33 +0200299 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
Lars-Peter Clausen4fee7e12012-03-06 20:43:45 +0100300 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
301 const struct iio_chan_spec_ext_info *ext_info;
302
303 ext_info = &this_attr->c->ext_info[this_attr->address];
304
Michael Hennerichfc6d1132012-04-27 10:58:36 +0200305 return ext_info->read(indio_dev, ext_info->private, this_attr->c, buf);
Lars-Peter Clausen4fee7e12012-03-06 20:43:45 +0100306}
307
308static ssize_t iio_write_channel_ext_info(struct device *dev,
309 struct device_attribute *attr,
310 const char *buf,
311 size_t len)
312{
Lars-Peter Clausene53f5ac2012-05-12 15:39:33 +0200313 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
Lars-Peter Clausen4fee7e12012-03-06 20:43:45 +0100314 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
315 const struct iio_chan_spec_ext_info *ext_info;
316
317 ext_info = &this_attr->c->ext_info[this_attr->address];
318
Michael Hennerichfc6d1132012-04-27 10:58:36 +0200319 return ext_info->write(indio_dev, ext_info->private,
320 this_attr->c, buf, len);
Lars-Peter Clausen4fee7e12012-03-06 20:43:45 +0100321}
322
Lars-Peter Clausen5212cc82012-06-04 11:36:11 +0200323ssize_t iio_enum_available_read(struct iio_dev *indio_dev,
324 uintptr_t priv, const struct iio_chan_spec *chan, char *buf)
325{
326 const struct iio_enum *e = (const struct iio_enum *)priv;
327 unsigned int i;
328 size_t len = 0;
329
330 if (!e->num_items)
331 return 0;
332
333 for (i = 0; i < e->num_items; ++i)
Lars-Peter Clausen74dcd432012-06-05 18:24:12 +0200334 len += scnprintf(buf + len, PAGE_SIZE - len, "%s ", e->items[i]);
Lars-Peter Clausen5212cc82012-06-04 11:36:11 +0200335
336 /* replace last space with a newline */
337 buf[len - 1] = '\n';
338
339 return len;
340}
341EXPORT_SYMBOL_GPL(iio_enum_available_read);
342
343ssize_t iio_enum_read(struct iio_dev *indio_dev,
344 uintptr_t priv, const struct iio_chan_spec *chan, char *buf)
345{
346 const struct iio_enum *e = (const struct iio_enum *)priv;
347 int i;
348
349 if (!e->get)
350 return -EINVAL;
351
352 i = e->get(indio_dev, chan);
353 if (i < 0)
354 return i;
355 else if (i >= e->num_items)
356 return -EINVAL;
357
Kees Cook598db582014-03-13 16:46:00 +0000358 return snprintf(buf, PAGE_SIZE, "%s\n", e->items[i]);
Lars-Peter Clausen5212cc82012-06-04 11:36:11 +0200359}
360EXPORT_SYMBOL_GPL(iio_enum_read);
361
362ssize_t iio_enum_write(struct iio_dev *indio_dev,
363 uintptr_t priv, const struct iio_chan_spec *chan, const char *buf,
364 size_t len)
365{
366 const struct iio_enum *e = (const struct iio_enum *)priv;
367 unsigned int i;
368 int ret;
369
370 if (!e->set)
371 return -EINVAL;
372
373 for (i = 0; i < e->num_items; i++) {
374 if (sysfs_streq(buf, e->items[i]))
375 break;
376 }
377
378 if (i == e->num_items)
379 return -EINVAL;
380
381 ret = e->set(indio_dev, chan, i);
382 return ret ? ret : len;
383}
384EXPORT_SYMBOL_GPL(iio_enum_write);
385
Lars-Peter Clausen3661f3f2013-10-07 15:11:00 +0100386/**
387 * iio_format_value() - Formats a IIO value into its string representation
388 * @buf: The buffer to which the formated value gets written
389 * @type: One of the IIO_VAL_... constants. This decides how the val and val2
390 * parameters are formatted.
Srinivas Pandruvada9fbfb4b2014-04-29 00:51:00 +0100391 * @vals: pointer to the values, exact meaning depends on the type parameter.
Lars-Peter Clausen3661f3f2013-10-07 15:11:00 +0100392 */
Srinivas Pandruvada9fbfb4b2014-04-29 00:51:00 +0100393ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals)
Jonathan Cameron847ec802009-08-18 18:06:19 +0100394{
Lars-Peter Clausen7985e7c2012-09-14 16:21:00 +0100395 unsigned long long tmp;
Michael Hennerich67eedba2012-05-11 11:36:52 +0200396 bool scale_db = false;
Jonathan Cameron847ec802009-08-18 18:06:19 +0100397
Lars-Peter Clausen3661f3f2013-10-07 15:11:00 +0100398 switch (type) {
Michael Hennerich67eedba2012-05-11 11:36:52 +0200399 case IIO_VAL_INT:
Srinivas Pandruvada9fbfb4b2014-04-29 00:51:00 +0100400 return sprintf(buf, "%d\n", vals[0]);
Michael Hennerich67eedba2012-05-11 11:36:52 +0200401 case IIO_VAL_INT_PLUS_MICRO_DB:
402 scale_db = true;
403 case IIO_VAL_INT_PLUS_MICRO:
Srinivas Pandruvada9fbfb4b2014-04-29 00:51:00 +0100404 if (vals[1] < 0)
405 return sprintf(buf, "-%ld.%06u%s\n", abs(vals[0]),
406 -vals[1],
Michael Hennerich67eedba2012-05-11 11:36:52 +0200407 scale_db ? " dB" : "");
Jonathan Cameron1d892712011-05-18 14:40:51 +0100408 else
Srinivas Pandruvada9fbfb4b2014-04-29 00:51:00 +0100409 return sprintf(buf, "%d.%06u%s\n", vals[0], vals[1],
Michael Hennerich67eedba2012-05-11 11:36:52 +0200410 scale_db ? " dB" : "");
411 case IIO_VAL_INT_PLUS_NANO:
Srinivas Pandruvada9fbfb4b2014-04-29 00:51:00 +0100412 if (vals[1] < 0)
413 return sprintf(buf, "-%ld.%09u\n", abs(vals[0]),
414 -vals[1]);
Michael Hennerich71646e22011-06-27 13:07:07 +0100415 else
Srinivas Pandruvada9fbfb4b2014-04-29 00:51:00 +0100416 return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
Lars-Peter Clausen7985e7c2012-09-14 16:21:00 +0100417 case IIO_VAL_FRACTIONAL:
Srinivas Pandruvada9fbfb4b2014-04-29 00:51:00 +0100418 tmp = div_s64((s64)vals[0] * 1000000000LL, vals[1]);
419 vals[1] = do_div(tmp, 1000000000LL);
420 vals[0] = tmp;
421 return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
Lars-Peter Clausen103d9fb2012-10-16 17:29:00 +0100422 case IIO_VAL_FRACTIONAL_LOG2:
Srinivas Pandruvada9fbfb4b2014-04-29 00:51:00 +0100423 tmp = (s64)vals[0] * 1000000000LL >> vals[1];
424 vals[1] = do_div(tmp, 1000000000LL);
425 vals[0] = tmp;
426 return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
427 case IIO_VAL_INT_MULTIPLE:
428 {
429 int i;
430 int len = 0;
431
432 for (i = 0; i < size; ++i)
433 len += snprintf(&buf[len], PAGE_SIZE - len, "%d ",
434 vals[i]);
435 len += snprintf(&buf[len], PAGE_SIZE - len, "\n");
436 return len;
437 }
Michael Hennerich67eedba2012-05-11 11:36:52 +0200438 default:
Jonathan Cameron1d892712011-05-18 14:40:51 +0100439 return 0;
Michael Hennerich67eedba2012-05-11 11:36:52 +0200440 }
Jonathan Cameron1d892712011-05-18 14:40:51 +0100441}
442
Lars-Peter Clausen3661f3f2013-10-07 15:11:00 +0100443static ssize_t iio_read_channel_info(struct device *dev,
444 struct device_attribute *attr,
445 char *buf)
446{
447 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
448 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
Srinivas Pandruvada9fbfb4b2014-04-29 00:51:00 +0100449 int vals[INDIO_MAX_RAW_ELEMENTS];
450 int ret;
451 int val_len = 2;
452
453 if (indio_dev->info->read_raw_multi)
454 ret = indio_dev->info->read_raw_multi(indio_dev, this_attr->c,
455 INDIO_MAX_RAW_ELEMENTS,
456 vals, &val_len,
457 this_attr->address);
458 else
459 ret = indio_dev->info->read_raw(indio_dev, this_attr->c,
460 &vals[0], &vals[1], this_attr->address);
Lars-Peter Clausen3661f3f2013-10-07 15:11:00 +0100461
462 if (ret < 0)
463 return ret;
464
Srinivas Pandruvada9fbfb4b2014-04-29 00:51:00 +0100465 return iio_format_value(buf, ret, val_len, vals);
Lars-Peter Clausen3661f3f2013-10-07 15:11:00 +0100466}
467
Lars-Peter Clausen6807d722012-11-20 13:36:00 +0000468/**
469 * iio_str_to_fixpoint() - Parse a fixed-point number from a string
470 * @str: The string to parse
471 * @fract_mult: Multiplier for the first decimal place, should be a power of 10
472 * @integer: The integer part of the number
473 * @fract: The fractional part of the number
474 *
475 * Returns 0 on success, or a negative error code if the string could not be
476 * parsed.
477 */
478int iio_str_to_fixpoint(const char *str, int fract_mult,
479 int *integer, int *fract)
480{
481 int i = 0, f = 0;
482 bool integer_part = true, negative = false;
483
484 if (str[0] == '-') {
485 negative = true;
486 str++;
487 } else if (str[0] == '+') {
488 str++;
489 }
490
491 while (*str) {
492 if ('0' <= *str && *str <= '9') {
493 if (integer_part) {
494 i = i * 10 + *str - '0';
495 } else {
496 f += fract_mult * (*str - '0');
497 fract_mult /= 10;
498 }
499 } else if (*str == '\n') {
500 if (*(str + 1) == '\0')
501 break;
502 else
503 return -EINVAL;
504 } else if (*str == '.' && integer_part) {
505 integer_part = false;
506 } else {
507 return -EINVAL;
508 }
509 str++;
510 }
511
512 if (negative) {
513 if (i)
514 i = -i;
515 else
516 f = -f;
517 }
518
519 *integer = i;
520 *fract = f;
521
522 return 0;
523}
524EXPORT_SYMBOL_GPL(iio_str_to_fixpoint);
525
Jonathan Cameron1d892712011-05-18 14:40:51 +0100526static ssize_t iio_write_channel_info(struct device *dev,
527 struct device_attribute *attr,
528 const char *buf,
529 size_t len)
530{
Lars-Peter Clausene53f5ac2012-05-12 15:39:33 +0200531 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
Jonathan Cameron1d892712011-05-18 14:40:51 +0100532 struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
Lars-Peter Clausen6807d722012-11-20 13:36:00 +0000533 int ret, fract_mult = 100000;
534 int integer, fract;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100535
536 /* Assumes decimal - precision based on number of digits */
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100537 if (!indio_dev->info->write_raw)
Jonathan Cameron1d892712011-05-18 14:40:51 +0100538 return -EINVAL;
Michael Hennerich5c04af02011-06-27 13:07:10 +0100539
540 if (indio_dev->info->write_raw_get_fmt)
541 switch (indio_dev->info->write_raw_get_fmt(indio_dev,
542 this_attr->c, this_attr->address)) {
543 case IIO_VAL_INT_PLUS_MICRO:
544 fract_mult = 100000;
545 break;
546 case IIO_VAL_INT_PLUS_NANO:
547 fract_mult = 100000000;
548 break;
549 default:
550 return -EINVAL;
551 }
552
Lars-Peter Clausen6807d722012-11-20 13:36:00 +0000553 ret = iio_str_to_fixpoint(buf, fract_mult, &integer, &fract);
554 if (ret)
555 return ret;
Jonathan Cameron847ec802009-08-18 18:06:19 +0100556
Jonathan Cameron6fe81352011-05-18 14:42:37 +0100557 ret = indio_dev->info->write_raw(indio_dev, this_attr->c,
Michael Hennerich5c04af02011-06-27 13:07:10 +0100558 integer, fract, this_attr->address);
Jonathan Cameron1d892712011-05-18 14:40:51 +0100559 if (ret)
560 return ret;
561
562 return len;
563}
564
Jonathan Camerondf9c1c42011-08-12 17:56:03 +0100565static
Jonathan Cameron1d892712011-05-18 14:40:51 +0100566int __iio_device_attr_init(struct device_attribute *dev_attr,
567 const char *postfix,
568 struct iio_chan_spec const *chan,
569 ssize_t (*readfunc)(struct device *dev,
570 struct device_attribute *attr,
571 char *buf),
572 ssize_t (*writefunc)(struct device *dev,
573 struct device_attribute *attr,
574 const char *buf,
575 size_t len),
Jonathan Cameron37044322013-09-08 14:57:00 +0100576 enum iio_shared_by shared_by)
Jonathan Cameron1d892712011-05-18 14:40:51 +0100577{
Jonathan Cameron37044322013-09-08 14:57:00 +0100578 int ret = 0;
Lars-Peter Clausen7bbcf7e2014-02-14 14:19:00 +0000579 char *name = NULL;
Jonathan Cameron37044322013-09-08 14:57:00 +0100580 char *full_postfix;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100581 sysfs_attr_init(&dev_attr->attr);
Jonathan Cameronade7ef72011-09-02 17:14:45 +0100582
583 /* Build up postfix of <extend_name>_<modifier>_postfix */
Jonathan Cameron37044322013-09-08 14:57:00 +0100584 if (chan->modified && (shared_by == IIO_SEPARATE)) {
Jonathan Cameronade7ef72011-09-02 17:14:45 +0100585 if (chan->extend_name)
586 full_postfix = kasprintf(GFP_KERNEL, "%s_%s_%s",
587 iio_modifier_names[chan
588 ->channel2],
589 chan->extend_name,
590 postfix);
591 else
592 full_postfix = kasprintf(GFP_KERNEL, "%s_%s",
593 iio_modifier_names[chan
594 ->channel2],
595 postfix);
596 } else {
Lars-Peter Clausen77bfa8b2014-02-14 14:19:00 +0000597 if (chan->extend_name == NULL || shared_by != IIO_SEPARATE)
Jonathan Cameronade7ef72011-09-02 17:14:45 +0100598 full_postfix = kstrdup(postfix, GFP_KERNEL);
599 else
600 full_postfix = kasprintf(GFP_KERNEL,
601 "%s_%s",
602 chan->extend_name,
603 postfix);
604 }
Jonathan Cameron37044322013-09-08 14:57:00 +0100605 if (full_postfix == NULL)
606 return -ENOMEM;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100607
Justin P. Mattock4abf6f82012-02-29 22:00:38 -0800608 if (chan->differential) { /* Differential can not have modifier */
Jonathan Cameron37044322013-09-08 14:57:00 +0100609 switch (shared_by) {
Jonathan Cameronc006ec82013-09-08 14:57:00 +0100610 case IIO_SHARED_BY_ALL:
Lars-Peter Clausen7bbcf7e2014-02-14 14:19:00 +0000611 name = kasprintf(GFP_KERNEL, "%s", full_postfix);
Jonathan Cameronc006ec82013-09-08 14:57:00 +0100612 break;
613 case IIO_SHARED_BY_DIR:
Lars-Peter Clausen7bbcf7e2014-02-14 14:19:00 +0000614 name = kasprintf(GFP_KERNEL, "%s_%s",
Jonathan Cameronc006ec82013-09-08 14:57:00 +0100615 iio_direction[chan->output],
616 full_postfix);
617 break;
Jonathan Cameron37044322013-09-08 14:57:00 +0100618 case IIO_SHARED_BY_TYPE:
Lars-Peter Clausen7bbcf7e2014-02-14 14:19:00 +0000619 name = kasprintf(GFP_KERNEL, "%s_%s-%s_%s",
Jonathan Cameronade7ef72011-09-02 17:14:45 +0100620 iio_direction[chan->output],
621 iio_chan_type_name_spec[chan->type],
622 iio_chan_type_name_spec[chan->type],
623 full_postfix);
Jonathan Cameron37044322013-09-08 14:57:00 +0100624 break;
625 case IIO_SEPARATE:
626 if (!chan->indexed) {
627 WARN_ON("Differential channels must be indexed\n");
628 ret = -EINVAL;
629 goto error_free_full_postfix;
630 }
Lars-Peter Clausen7bbcf7e2014-02-14 14:19:00 +0000631 name = kasprintf(GFP_KERNEL,
Jonathan Cameron37044322013-09-08 14:57:00 +0100632 "%s_%s%d-%s%d_%s",
Jonathan Cameronade7ef72011-09-02 17:14:45 +0100633 iio_direction[chan->output],
634 iio_chan_type_name_spec[chan->type],
635 chan->channel,
636 iio_chan_type_name_spec[chan->type],
637 chan->channel2,
638 full_postfix);
Jonathan Cameron37044322013-09-08 14:57:00 +0100639 break;
Jonathan Cameronade7ef72011-09-02 17:14:45 +0100640 }
641 } else { /* Single ended */
Jonathan Cameron37044322013-09-08 14:57:00 +0100642 switch (shared_by) {
Jonathan Cameronc006ec82013-09-08 14:57:00 +0100643 case IIO_SHARED_BY_ALL:
Lars-Peter Clausen7bbcf7e2014-02-14 14:19:00 +0000644 name = kasprintf(GFP_KERNEL, "%s", full_postfix);
Jonathan Cameronc006ec82013-09-08 14:57:00 +0100645 break;
646 case IIO_SHARED_BY_DIR:
Lars-Peter Clausen7bbcf7e2014-02-14 14:19:00 +0000647 name = kasprintf(GFP_KERNEL, "%s_%s",
Jonathan Cameronc006ec82013-09-08 14:57:00 +0100648 iio_direction[chan->output],
649 full_postfix);
650 break;
Jonathan Cameron37044322013-09-08 14:57:00 +0100651 case IIO_SHARED_BY_TYPE:
Lars-Peter Clausen7bbcf7e2014-02-14 14:19:00 +0000652 name = kasprintf(GFP_KERNEL, "%s_%s_%s",
Jonathan Cameronade7ef72011-09-02 17:14:45 +0100653 iio_direction[chan->output],
654 iio_chan_type_name_spec[chan->type],
655 full_postfix);
Jonathan Cameron37044322013-09-08 14:57:00 +0100656 break;
657
658 case IIO_SEPARATE:
659 if (chan->indexed)
Lars-Peter Clausen7bbcf7e2014-02-14 14:19:00 +0000660 name = kasprintf(GFP_KERNEL, "%s_%s%d_%s",
Jonathan Cameron37044322013-09-08 14:57:00 +0100661 iio_direction[chan->output],
662 iio_chan_type_name_spec[chan->type],
663 chan->channel,
664 full_postfix);
665 else
Lars-Peter Clausen7bbcf7e2014-02-14 14:19:00 +0000666 name = kasprintf(GFP_KERNEL, "%s_%s_%s",
Jonathan Cameron37044322013-09-08 14:57:00 +0100667 iio_direction[chan->output],
668 iio_chan_type_name_spec[chan->type],
669 full_postfix);
670 break;
671 }
Jonathan Cameronade7ef72011-09-02 17:14:45 +0100672 }
Lars-Peter Clausen7bbcf7e2014-02-14 14:19:00 +0000673 if (name == NULL) {
Jonathan Cameron1d892712011-05-18 14:40:51 +0100674 ret = -ENOMEM;
675 goto error_free_full_postfix;
676 }
Lars-Peter Clausen7bbcf7e2014-02-14 14:19:00 +0000677 dev_attr->attr.name = name;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100678
679 if (readfunc) {
680 dev_attr->attr.mode |= S_IRUGO;
681 dev_attr->show = readfunc;
682 }
683
684 if (writefunc) {
685 dev_attr->attr.mode |= S_IWUSR;
686 dev_attr->store = writefunc;
687 }
Lars-Peter Clausen7bbcf7e2014-02-14 14:19:00 +0000688
Jonathan Cameron1d892712011-05-18 14:40:51 +0100689error_free_full_postfix:
690 kfree(full_postfix);
Jonathan Cameron37044322013-09-08 14:57:00 +0100691
Jonathan Cameron847ec802009-08-18 18:06:19 +0100692 return ret;
693}
694
Jonathan Camerondf9c1c42011-08-12 17:56:03 +0100695static void __iio_device_attr_deinit(struct device_attribute *dev_attr)
Jonathan Cameron1d892712011-05-18 14:40:51 +0100696{
697 kfree(dev_attr->attr.name);
698}
699
700int __iio_add_chan_devattr(const char *postfix,
Jonathan Cameron1d892712011-05-18 14:40:51 +0100701 struct iio_chan_spec const *chan,
702 ssize_t (*readfunc)(struct device *dev,
703 struct device_attribute *attr,
704 char *buf),
705 ssize_t (*writefunc)(struct device *dev,
706 struct device_attribute *attr,
707 const char *buf,
708 size_t len),
Jonathan Camerone614a542011-09-02 17:14:41 +0100709 u64 mask,
Jonathan Cameron37044322013-09-08 14:57:00 +0100710 enum iio_shared_by shared_by,
Jonathan Cameron1d892712011-05-18 14:40:51 +0100711 struct device *dev,
712 struct list_head *attr_list)
713{
714 int ret;
715 struct iio_dev_attr *iio_attr, *t;
716
Sachin Kamat670c1102013-10-24 12:53:00 +0100717 iio_attr = kzalloc(sizeof(*iio_attr), GFP_KERNEL);
Hartmut Knaack92825ff2014-02-16 11:53:00 +0000718 if (iio_attr == NULL)
719 return -ENOMEM;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100720 ret = __iio_device_attr_init(&iio_attr->dev_attr,
721 postfix, chan,
Jonathan Cameron37044322013-09-08 14:57:00 +0100722 readfunc, writefunc, shared_by);
Jonathan Cameron1d892712011-05-18 14:40:51 +0100723 if (ret)
724 goto error_iio_dev_attr_free;
725 iio_attr->c = chan;
726 iio_attr->address = mask;
727 list_for_each_entry(t, attr_list, l)
728 if (strcmp(t->dev_attr.attr.name,
729 iio_attr->dev_attr.attr.name) == 0) {
Jonathan Cameron37044322013-09-08 14:57:00 +0100730 if (shared_by == IIO_SEPARATE)
Jonathan Cameron1d892712011-05-18 14:40:51 +0100731 dev_err(dev, "tried to double register : %s\n",
732 t->dev_attr.attr.name);
733 ret = -EBUSY;
734 goto error_device_attr_deinit;
735 }
Jonathan Cameron1d892712011-05-18 14:40:51 +0100736 list_add(&iio_attr->l, attr_list);
737
738 return 0;
739
740error_device_attr_deinit:
741 __iio_device_attr_deinit(&iio_attr->dev_attr);
742error_iio_dev_attr_free:
743 kfree(iio_attr);
Jonathan Cameron1d892712011-05-18 14:40:51 +0100744 return ret;
745}
746
Jonathan Cameron37044322013-09-08 14:57:00 +0100747static int iio_device_add_info_mask_type(struct iio_dev *indio_dev,
748 struct iio_chan_spec const *chan,
749 enum iio_shared_by shared_by,
750 const long *infomask)
751{
752 int i, ret, attrcount = 0;
753
754 for_each_set_bit(i, infomask, sizeof(infomask)*8) {
Jonathan Cameronef4b4852014-01-03 22:24:00 +0000755 if (i >= ARRAY_SIZE(iio_chan_info_postfix))
756 return -EINVAL;
Jonathan Cameron37044322013-09-08 14:57:00 +0100757 ret = __iio_add_chan_devattr(iio_chan_info_postfix[i],
758 chan,
759 &iio_read_channel_info,
760 &iio_write_channel_info,
761 i,
762 shared_by,
763 &indio_dev->dev,
764 &indio_dev->channel_attr_list);
765 if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))
766 continue;
767 else if (ret < 0)
768 return ret;
769 attrcount++;
770 }
771
772 return attrcount;
773}
774
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100775static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
Jonathan Cameron1d892712011-05-18 14:40:51 +0100776 struct iio_chan_spec const *chan)
777{
Jonathan Cameron5ccb3ad2012-04-15 17:41:16 +0100778 int ret, attrcount = 0;
Lars-Peter Clausen5f420b42012-02-21 18:38:12 +0100779 const struct iio_chan_spec_ext_info *ext_info;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100780
Jonathan Cameron1d892712011-05-18 14:40:51 +0100781 if (chan->channel < 0)
782 return 0;
Jonathan Cameron37044322013-09-08 14:57:00 +0100783 ret = iio_device_add_info_mask_type(indio_dev, chan,
784 IIO_SEPARATE,
785 &chan->info_mask_separate);
786 if (ret < 0)
787 return ret;
788 attrcount += ret;
789
790 ret = iio_device_add_info_mask_type(indio_dev, chan,
791 IIO_SHARED_BY_TYPE,
792 &chan->info_mask_shared_by_type);
793 if (ret < 0)
794 return ret;
795 attrcount += ret;
Lars-Peter Clausen5f420b42012-02-21 18:38:12 +0100796
Jonathan Cameronc006ec82013-09-08 14:57:00 +0100797 ret = iio_device_add_info_mask_type(indio_dev, chan,
798 IIO_SHARED_BY_DIR,
799 &chan->info_mask_shared_by_dir);
800 if (ret < 0)
801 return ret;
802 attrcount += ret;
803
804 ret = iio_device_add_info_mask_type(indio_dev, chan,
805 IIO_SHARED_BY_ALL,
806 &chan->info_mask_shared_by_all);
807 if (ret < 0)
808 return ret;
809 attrcount += ret;
810
Lars-Peter Clausen5f420b42012-02-21 18:38:12 +0100811 if (chan->ext_info) {
812 unsigned int i = 0;
813 for (ext_info = chan->ext_info; ext_info->name; ext_info++) {
814 ret = __iio_add_chan_devattr(ext_info->name,
815 chan,
816 ext_info->read ?
817 &iio_read_channel_ext_info : NULL,
818 ext_info->write ?
819 &iio_write_channel_ext_info : NULL,
820 i,
821 ext_info->shared,
822 &indio_dev->dev,
823 &indio_dev->channel_attr_list);
824 i++;
825 if (ret == -EBUSY && ext_info->shared)
826 continue;
827
828 if (ret)
Jonathan Cameron37044322013-09-08 14:57:00 +0100829 return ret;
Lars-Peter Clausen5f420b42012-02-21 18:38:12 +0100830
831 attrcount++;
832 }
833 }
834
Jonathan Cameron37044322013-09-08 14:57:00 +0100835 return attrcount;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100836}
837
Lars-Peter Clausen84088eb2013-10-07 12:50:00 +0100838/**
839 * iio_free_chan_devattr_list() - Free a list of IIO device attributes
840 * @attr_list: List of IIO device attributes
841 *
842 * This function frees the memory allocated for each of the IIO device
843 * attributes in the list. Note: if you want to reuse the list after calling
844 * this function you have to reinitialize it using INIT_LIST_HEAD().
845 */
846void iio_free_chan_devattr_list(struct list_head *attr_list)
Jonathan Cameron1d892712011-05-18 14:40:51 +0100847{
Lars-Peter Clausen84088eb2013-10-07 12:50:00 +0100848 struct iio_dev_attr *p, *n;
849
850 list_for_each_entry_safe(p, n, attr_list, l) {
851 kfree(p->dev_attr.attr.name);
852 kfree(p);
853 }
Jonathan Cameron1d892712011-05-18 14:40:51 +0100854}
855
Jonathan Cameron1b732882011-05-18 14:41:43 +0100856static ssize_t iio_show_dev_name(struct device *dev,
857 struct device_attribute *attr,
858 char *buf)
859{
Lars-Peter Clausene53f5ac2012-05-12 15:39:33 +0200860 struct iio_dev *indio_dev = dev_to_iio_dev(dev);
Kees Cook598db582014-03-13 16:46:00 +0000861 return snprintf(buf, PAGE_SIZE, "%s\n", indio_dev->name);
Jonathan Cameron1b732882011-05-18 14:41:43 +0100862}
863
864static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL);
865
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100866static int iio_device_register_sysfs(struct iio_dev *indio_dev)
Jonathan Cameron1d892712011-05-18 14:40:51 +0100867{
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100868 int i, ret = 0, attrcount, attrn, attrcount_orig = 0;
Lars-Peter Clausen84088eb2013-10-07 12:50:00 +0100869 struct iio_dev_attr *p;
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100870 struct attribute **attr;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100871
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100872 /* First count elements in any existing group */
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100873 if (indio_dev->info->attrs) {
874 attr = indio_dev->info->attrs->attrs;
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100875 while (*attr++ != NULL)
876 attrcount_orig++;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100877 }
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100878 attrcount = attrcount_orig;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100879 /*
880 * New channel registration method - relies on the fact a group does
Peter Meerwaldd25b3802012-08-26 13:43:00 +0100881 * not need to be initialized if its name is NULL.
Jonathan Cameron1d892712011-05-18 14:40:51 +0100882 */
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100883 if (indio_dev->channels)
884 for (i = 0; i < indio_dev->num_channels; i++) {
885 ret = iio_device_add_channel_sysfs(indio_dev,
886 &indio_dev
Jonathan Cameron1d892712011-05-18 14:40:51 +0100887 ->channels[i]);
888 if (ret < 0)
889 goto error_clear_attrs;
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100890 attrcount += ret;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100891 }
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100892
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100893 if (indio_dev->name)
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100894 attrcount++;
895
Thomas Meyerd83fb182011-11-29 22:08:00 +0100896 indio_dev->chan_attr_group.attrs = kcalloc(attrcount + 1,
897 sizeof(indio_dev->chan_attr_group.attrs[0]),
898 GFP_KERNEL);
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100899 if (indio_dev->chan_attr_group.attrs == NULL) {
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100900 ret = -ENOMEM;
901 goto error_clear_attrs;
Jonathan Cameron1b732882011-05-18 14:41:43 +0100902 }
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100903 /* Copy across original attributes */
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100904 if (indio_dev->info->attrs)
905 memcpy(indio_dev->chan_attr_group.attrs,
906 indio_dev->info->attrs->attrs,
907 sizeof(indio_dev->chan_attr_group.attrs[0])
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100908 *attrcount_orig);
909 attrn = attrcount_orig;
910 /* Add all elements from the list. */
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100911 list_for_each_entry(p, &indio_dev->channel_attr_list, l)
912 indio_dev->chan_attr_group.attrs[attrn++] = &p->dev_attr.attr;
913 if (indio_dev->name)
914 indio_dev->chan_attr_group.attrs[attrn++] = &dev_attr_name.attr;
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100915
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100916 indio_dev->groups[indio_dev->groupcounter++] =
917 &indio_dev->chan_attr_group;
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100918
Jonathan Cameron1d892712011-05-18 14:40:51 +0100919 return 0;
Jonathan Cameron1b732882011-05-18 14:41:43 +0100920
Jonathan Cameron1d892712011-05-18 14:40:51 +0100921error_clear_attrs:
Lars-Peter Clausen84088eb2013-10-07 12:50:00 +0100922 iio_free_chan_devattr_list(&indio_dev->channel_attr_list);
Jonathan Cameron1d892712011-05-18 14:40:51 +0100923
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100924 return ret;
Jonathan Cameron1d892712011-05-18 14:40:51 +0100925}
926
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100927static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
Jonathan Cameron847ec802009-08-18 18:06:19 +0100928{
Jonathan Cameron1d892712011-05-18 14:40:51 +0100929
Lars-Peter Clausen84088eb2013-10-07 12:50:00 +0100930 iio_free_chan_devattr_list(&indio_dev->channel_attr_list);
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100931 kfree(indio_dev->chan_attr_group.attrs);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100932}
933
Jonathan Cameron847ec802009-08-18 18:06:19 +0100934static void iio_dev_release(struct device *device)
935{
Lars-Peter Clausene53f5ac2012-05-12 15:39:33 +0200936 struct iio_dev *indio_dev = dev_to_iio_dev(device);
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +0100937 if (indio_dev->modes & INDIO_BUFFER_TRIGGERED)
938 iio_device_unregister_trigger_consumer(indio_dev);
939 iio_device_unregister_eventset(indio_dev);
940 iio_device_unregister_sysfs(indio_dev);
Lars-Peter Clausene407fd62012-06-04 10:41:42 +0200941
Lars-Peter Clausen9e69c932013-10-04 12:06:00 +0100942 iio_buffer_put(indio_dev->buffer);
943
Lars-Peter Clausene407fd62012-06-04 10:41:42 +0200944 ida_simple_remove(&iio_ida, indio_dev->id);
945 kfree(indio_dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100946}
947
Guenter Roeck17d82b42013-02-07 17:09:00 +0000948struct device_type iio_device_type = {
Jonathan Cameron847ec802009-08-18 18:06:19 +0100949 .name = "iio_device",
950 .release = iio_dev_release,
951};
952
Sachin Kamata7e57dc2013-10-29 11:39:00 +0000953/**
954 * iio_device_alloc() - allocate an iio_dev from a driver
955 * @sizeof_priv: Space to allocate for private structure.
956 **/
Lars-Peter Clausen7cbb7532012-04-26 13:35:01 +0200957struct iio_dev *iio_device_alloc(int sizeof_priv)
Jonathan Cameron847ec802009-08-18 18:06:19 +0100958{
Jonathan Cameron6f7c8ee2011-04-15 18:55:56 +0100959 struct iio_dev *dev;
960 size_t alloc_size;
961
962 alloc_size = sizeof(struct iio_dev);
963 if (sizeof_priv) {
964 alloc_size = ALIGN(alloc_size, IIO_ALIGN);
965 alloc_size += sizeof_priv;
966 }
967 /* ensure 32-byte alignment of whole construct ? */
968 alloc_size += IIO_ALIGN - 1;
969
970 dev = kzalloc(alloc_size, GFP_KERNEL);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100971
972 if (dev) {
Jonathan Cameron26d25ae2011-09-02 17:14:40 +0100973 dev->dev.groups = dev->groups;
Guenter Roeck17d82b42013-02-07 17:09:00 +0000974 dev->dev.type = &iio_device_type;
Jonathan Cameron5aaaeba2010-05-04 14:43:00 +0100975 dev->dev.bus = &iio_bus_type;
Jonathan Cameron847ec802009-08-18 18:06:19 +0100976 device_initialize(&dev->dev);
977 dev_set_drvdata(&dev->dev, (void *)dev);
978 mutex_init(&dev->mlock);
Jonathan Cameronac917a82012-02-15 19:48:00 +0000979 mutex_init(&dev->info_exist_lock);
Lars-Peter Clausene407fd62012-06-04 10:41:42 +0200980 INIT_LIST_HEAD(&dev->channel_attr_list);
Jonathan Camerona9e39f92011-09-14 13:01:25 +0100981
982 dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
983 if (dev->id < 0) {
984 /* cannot use a dev_err as the name isn't available */
Sachin Kamat3176dd52013-10-24 12:53:00 +0100985 pr_err("failed to get device id\n");
Jonathan Camerona9e39f92011-09-14 13:01:25 +0100986 kfree(dev);
987 return NULL;
988 }
989 dev_set_name(&dev->dev, "iio:device%d", dev->id);
Jonathan Cameron84b36ce2012-06-30 20:06:00 +0100990 INIT_LIST_HEAD(&dev->buffer_list);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100991 }
992
993 return dev;
994}
Lars-Peter Clausen7cbb7532012-04-26 13:35:01 +0200995EXPORT_SYMBOL(iio_device_alloc);
Jonathan Cameron847ec802009-08-18 18:06:19 +0100996
Sachin Kamata7e57dc2013-10-29 11:39:00 +0000997/**
998 * iio_device_free() - free an iio_dev from a driver
999 * @dev: the iio_dev associated with the device
1000 **/
Lars-Peter Clausen7cbb7532012-04-26 13:35:01 +02001001void iio_device_free(struct iio_dev *dev)
Jonathan Cameron847ec802009-08-18 18:06:19 +01001002{
Lars-Peter Clausene407fd62012-06-04 10:41:42 +02001003 if (dev)
1004 put_device(&dev->dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +01001005}
Lars-Peter Clausen7cbb7532012-04-26 13:35:01 +02001006EXPORT_SYMBOL(iio_device_free);
Jonathan Cameron847ec802009-08-18 18:06:19 +01001007
Grygorii Strashko9dabaf52013-07-18 11:19:00 +01001008static void devm_iio_device_release(struct device *dev, void *res)
1009{
1010 iio_device_free(*(struct iio_dev **)res);
1011}
1012
1013static int devm_iio_device_match(struct device *dev, void *res, void *data)
1014{
1015 struct iio_dev **r = res;
1016 if (!r || !*r) {
1017 WARN_ON(!r || !*r);
1018 return 0;
1019 }
1020 return *r == data;
1021}
1022
Sachin Kamata7e57dc2013-10-29 11:39:00 +00001023/**
1024 * devm_iio_device_alloc - Resource-managed iio_device_alloc()
1025 * @dev: Device to allocate iio_dev for
1026 * @sizeof_priv: Space to allocate for private structure.
1027 *
1028 * Managed iio_device_alloc. iio_dev allocated with this function is
1029 * automatically freed on driver detach.
1030 *
1031 * If an iio_dev allocated with this function needs to be freed separately,
1032 * devm_iio_device_free() must be used.
1033 *
1034 * RETURNS:
1035 * Pointer to allocated iio_dev on success, NULL on failure.
1036 */
Grygorii Strashko9dabaf52013-07-18 11:19:00 +01001037struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv)
1038{
1039 struct iio_dev **ptr, *iio_dev;
1040
1041 ptr = devres_alloc(devm_iio_device_release, sizeof(*ptr),
1042 GFP_KERNEL);
1043 if (!ptr)
1044 return NULL;
1045
1046 /* use raw alloc_dr for kmalloc caller tracing */
1047 iio_dev = iio_device_alloc(sizeof_priv);
1048 if (iio_dev) {
1049 *ptr = iio_dev;
1050 devres_add(dev, ptr);
1051 } else {
1052 devres_free(ptr);
1053 }
1054
1055 return iio_dev;
1056}
1057EXPORT_SYMBOL_GPL(devm_iio_device_alloc);
1058
Sachin Kamata7e57dc2013-10-29 11:39:00 +00001059/**
1060 * devm_iio_device_free - Resource-managed iio_device_free()
1061 * @dev: Device this iio_dev belongs to
1062 * @iio_dev: the iio_dev associated with the device
1063 *
1064 * Free iio_dev allocated with devm_iio_device_alloc().
1065 */
Grygorii Strashko9dabaf52013-07-18 11:19:00 +01001066void devm_iio_device_free(struct device *dev, struct iio_dev *iio_dev)
1067{
1068 int rc;
1069
1070 rc = devres_release(dev, devm_iio_device_release,
1071 devm_iio_device_match, iio_dev);
1072 WARN_ON(rc);
1073}
1074EXPORT_SYMBOL_GPL(devm_iio_device_free);
1075
Jonathan Cameron1aa04272011-08-30 12:32:47 +01001076/**
Jonathan Cameron14555b12011-09-21 11:15:57 +01001077 * iio_chrdev_open() - chrdev file open for buffer access and ioctls
Jonathan Cameron1aa04272011-08-30 12:32:47 +01001078 **/
1079static int iio_chrdev_open(struct inode *inode, struct file *filp)
1080{
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001081 struct iio_dev *indio_dev = container_of(inode->i_cdev,
Jonathan Cameron1aa04272011-08-30 12:32:47 +01001082 struct iio_dev, chrdev);
Lars-Peter Clausenbb014432011-12-19 15:23:45 +01001083
1084 if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags))
1085 return -EBUSY;
1086
Lars-Peter Clausencadc2122013-09-18 21:02:00 +01001087 iio_device_get(indio_dev);
1088
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001089 filp->private_data = indio_dev;
Jonathan Cameron30eb82f2011-09-21 11:16:02 +01001090
Lars-Peter Clausen79335142011-12-19 15:23:49 +01001091 return 0;
Jonathan Cameron1aa04272011-08-30 12:32:47 +01001092}
1093
1094/**
Jonathan Cameron14555b12011-09-21 11:15:57 +01001095 * iio_chrdev_release() - chrdev file close buffer access and ioctls
Jonathan Cameron1aa04272011-08-30 12:32:47 +01001096 **/
1097static int iio_chrdev_release(struct inode *inode, struct file *filp)
1098{
Lars-Peter Clausenbb014432011-12-19 15:23:45 +01001099 struct iio_dev *indio_dev = container_of(inode->i_cdev,
1100 struct iio_dev, chrdev);
Lars-Peter Clausenbb014432011-12-19 15:23:45 +01001101 clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
Lars-Peter Clausencadc2122013-09-18 21:02:00 +01001102 iio_device_put(indio_dev);
1103
Jonathan Cameron1aa04272011-08-30 12:32:47 +01001104 return 0;
1105}
1106
1107/* Somewhat of a cross file organization violation - ioctls here are actually
1108 * event related */
1109static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
1110{
1111 struct iio_dev *indio_dev = filp->private_data;
1112 int __user *ip = (int __user *)arg;
1113 int fd;
1114
Lars-Peter Clausenf18e7a02013-10-04 12:06:00 +01001115 if (!indio_dev->info)
1116 return -ENODEV;
1117
Jonathan Cameron1aa04272011-08-30 12:32:47 +01001118 if (cmd == IIO_GET_EVENT_FD_IOCTL) {
1119 fd = iio_event_getfd(indio_dev);
1120 if (copy_to_user(ip, &fd, sizeof(fd)))
1121 return -EFAULT;
1122 return 0;
1123 }
1124 return -EINVAL;
1125}
1126
Jonathan Cameron14555b12011-09-21 11:15:57 +01001127static const struct file_operations iio_buffer_fileops = {
1128 .read = iio_buffer_read_first_n_outer_addr,
Jonathan Cameron1aa04272011-08-30 12:32:47 +01001129 .release = iio_chrdev_release,
1130 .open = iio_chrdev_open,
Jonathan Cameron14555b12011-09-21 11:15:57 +01001131 .poll = iio_buffer_poll_addr,
Jonathan Cameron1aa04272011-08-30 12:32:47 +01001132 .owner = THIS_MODULE,
1133 .llseek = noop_llseek,
1134 .unlocked_ioctl = iio_ioctl,
1135 .compat_ioctl = iio_ioctl,
1136};
1137
Michael Hennerich0f1acee2012-03-01 10:51:04 +01001138static const struct iio_buffer_setup_ops noop_ring_setup_ops;
1139
Sachin Kamata7e57dc2013-10-29 11:39:00 +00001140/**
1141 * iio_device_register() - register a device with the IIO subsystem
1142 * @indio_dev: Device structure filled by the device driver
1143 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001144int iio_device_register(struct iio_dev *indio_dev)
Jonathan Cameron847ec802009-08-18 18:06:19 +01001145{
1146 int ret;
1147
Guenter Roeck17d82b42013-02-07 17:09:00 +00001148 /* If the calling driver did not initialize of_node, do it here */
1149 if (!indio_dev->dev.of_node && indio_dev->dev.parent)
1150 indio_dev->dev.of_node = indio_dev->dev.parent->of_node;
1151
Jonathan Cameron1aa04272011-08-30 12:32:47 +01001152 /* configure elements for the chrdev */
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001153 indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
Jonathan Cameron847ec802009-08-18 18:06:19 +01001154
Michael Henneriche553f182012-03-01 10:51:03 +01001155 ret = iio_device_register_debugfs(indio_dev);
1156 if (ret) {
1157 dev_err(indio_dev->dev.parent,
1158 "Failed to register debugfs interfaces\n");
Hartmut Knaack92825ff2014-02-16 11:53:00 +00001159 return ret;
Michael Henneriche553f182012-03-01 10:51:03 +01001160 }
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001161 ret = iio_device_register_sysfs(indio_dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +01001162 if (ret) {
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001163 dev_err(indio_dev->dev.parent,
Jonathan Cameron847ec802009-08-18 18:06:19 +01001164 "Failed to register sysfs interfaces\n");
Michael Henneriche553f182012-03-01 10:51:03 +01001165 goto error_unreg_debugfs;
Jonathan Cameron847ec802009-08-18 18:06:19 +01001166 }
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001167 ret = iio_device_register_eventset(indio_dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +01001168 if (ret) {
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001169 dev_err(indio_dev->dev.parent,
Roel Van Nyenc849d252010-04-29 19:27:31 +02001170 "Failed to register event set\n");
Jonathan Cameron847ec802009-08-18 18:06:19 +01001171 goto error_free_sysfs;
1172 }
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001173 if (indio_dev->modes & INDIO_BUFFER_TRIGGERED)
1174 iio_device_register_trigger_consumer(indio_dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +01001175
Michael Hennerich0f1acee2012-03-01 10:51:04 +01001176 if ((indio_dev->modes & INDIO_ALL_BUFFER_MODES) &&
1177 indio_dev->setup_ops == NULL)
1178 indio_dev->setup_ops = &noop_ring_setup_ops;
1179
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001180 cdev_init(&indio_dev->chrdev, &iio_buffer_fileops);
1181 indio_dev->chrdev.owner = indio_dev->info->driver_module;
Lars-Peter Clausen0d5b7da2013-09-18 21:02:00 +01001182 indio_dev->chrdev.kobj.parent = &indio_dev->dev.kobj;
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001183 ret = cdev_add(&indio_dev->chrdev, indio_dev->dev.devt, 1);
Jonathan Cameron26d25ae2011-09-02 17:14:40 +01001184 if (ret < 0)
Lars-Peter Clausen0d5b7da2013-09-18 21:02:00 +01001185 goto error_unreg_eventset;
Jonathan Cameron847ec802009-08-18 18:06:19 +01001186
Lars-Peter Clausen0d5b7da2013-09-18 21:02:00 +01001187 ret = device_add(&indio_dev->dev);
1188 if (ret < 0)
1189 goto error_cdev_del;
1190
1191 return 0;
1192error_cdev_del:
1193 cdev_del(&indio_dev->chrdev);
Jonathan Cameron26d25ae2011-09-02 17:14:40 +01001194error_unreg_eventset:
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001195 iio_device_unregister_eventset(indio_dev);
Jonathan Cameron26d25ae2011-09-02 17:14:40 +01001196error_free_sysfs:
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001197 iio_device_unregister_sysfs(indio_dev);
Michael Henneriche553f182012-03-01 10:51:03 +01001198error_unreg_debugfs:
1199 iio_device_unregister_debugfs(indio_dev);
Jonathan Cameron847ec802009-08-18 18:06:19 +01001200 return ret;
1201}
1202EXPORT_SYMBOL(iio_device_register);
1203
Sachin Kamata7e57dc2013-10-29 11:39:00 +00001204/**
1205 * iio_device_unregister() - unregister a device from the IIO subsystem
1206 * @indio_dev: Device structure representing the device.
1207 **/
Jonathan Cameronf8c6f4e2011-10-06 17:14:35 +01001208void iio_device_unregister(struct iio_dev *indio_dev)
Jonathan Cameron847ec802009-08-18 18:06:19 +01001209{
Jonathan Cameronac917a82012-02-15 19:48:00 +00001210 mutex_lock(&indio_dev->info_exist_lock);
Lars-Peter Clausena87c82e2013-09-18 21:02:00 +01001211
1212 device_del(&indio_dev->dev);
1213
Lars-Peter Clausen0d5b7da2013-09-18 21:02:00 +01001214 if (indio_dev->chrdev.dev)
1215 cdev_del(&indio_dev->chrdev);
Lars-Peter Clausenbc4c9612013-09-21 16:21:00 +01001216 iio_device_unregister_debugfs(indio_dev);
Lars-Peter Clausen0d5b7da2013-09-18 21:02:00 +01001217
Lars-Peter Clausena87c82e2013-09-18 21:02:00 +01001218 iio_disable_all_buffers(indio_dev);
1219
Jonathan Cameronac917a82012-02-15 19:48:00 +00001220 indio_dev->info = NULL;
Lars-Peter Clausend2f0a482013-10-04 12:07:00 +01001221
1222 iio_device_wakeup_eventset(indio_dev);
1223 iio_buffer_wakeup_poll(indio_dev);
1224
Jonathan Cameronac917a82012-02-15 19:48:00 +00001225 mutex_unlock(&indio_dev->info_exist_lock);
Jonathan Cameron847ec802009-08-18 18:06:19 +01001226}
1227EXPORT_SYMBOL(iio_device_unregister);
Sachin Kamat8caa07c2013-10-29 11:39:00 +00001228
1229static void devm_iio_device_unreg(struct device *dev, void *res)
1230{
1231 iio_device_unregister(*(struct iio_dev **)res);
1232}
1233
1234/**
1235 * devm_iio_device_register - Resource-managed iio_device_register()
1236 * @dev: Device to allocate iio_dev for
1237 * @indio_dev: Device structure filled by the device driver
1238 *
1239 * Managed iio_device_register. The IIO device registered with this
1240 * function is automatically unregistered on driver detach. This function
1241 * calls iio_device_register() internally. Refer to that function for more
1242 * information.
1243 *
1244 * If an iio_dev registered with this function needs to be unregistered
1245 * separately, devm_iio_device_unregister() must be used.
1246 *
1247 * RETURNS:
1248 * 0 on success, negative error number on failure.
1249 */
1250int devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev)
1251{
1252 struct iio_dev **ptr;
1253 int ret;
1254
1255 ptr = devres_alloc(devm_iio_device_unreg, sizeof(*ptr), GFP_KERNEL);
1256 if (!ptr)
1257 return -ENOMEM;
1258
1259 *ptr = indio_dev;
1260 ret = iio_device_register(indio_dev);
1261 if (!ret)
1262 devres_add(dev, ptr);
1263 else
1264 devres_free(ptr);
1265
1266 return ret;
1267}
1268EXPORT_SYMBOL_GPL(devm_iio_device_register);
1269
1270/**
1271 * devm_iio_device_unregister - Resource-managed iio_device_unregister()
1272 * @dev: Device this iio_dev belongs to
1273 * @indio_dev: the iio_dev associated with the device
1274 *
1275 * Unregister iio_dev registered with devm_iio_device_register().
1276 */
1277void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev)
1278{
1279 int rc;
1280
1281 rc = devres_release(dev, devm_iio_device_unreg,
1282 devm_iio_device_match, indio_dev);
1283 WARN_ON(rc);
1284}
1285EXPORT_SYMBOL_GPL(devm_iio_device_unregister);
1286
Jonathan Cameron847ec802009-08-18 18:06:19 +01001287subsys_initcall(iio_init);
1288module_exit(iio_exit);
1289
Jonathan Cameronc8b95952012-09-02 21:27:56 +01001290MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>");
Jonathan Cameron847ec802009-08-18 18:06:19 +01001291MODULE_DESCRIPTION("Industrial I/O core");
1292MODULE_LICENSE("GPL");