industrialio-core.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280
  1. /* 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. #define pr_fmt(fmt) "iio-core: " fmt
  12. #include <linux/kernel.h>
  13. #include <linux/module.h>
  14. #include <linux/idr.h>
  15. #include <linux/kdev_t.h>
  16. #include <linux/err.h>
  17. #include <linux/device.h>
  18. #include <linux/fs.h>
  19. #include <linux/poll.h>
  20. #include <linux/sched.h>
  21. #include <linux/wait.h>
  22. #include <linux/cdev.h>
  23. #include <linux/slab.h>
  24. #include <linux/anon_inodes.h>
  25. #include <linux/debugfs.h>
  26. #include <linux/iio/iio.h>
  27. #include "iio_core.h"
  28. #include "iio_core_trigger.h"
  29. #include <linux/iio/sysfs.h>
  30. #include <linux/iio/events.h>
  31. #include <linux/iio/buffer.h>
  32. /* IDA to assign each registered device a unique id */
  33. static DEFINE_IDA(iio_ida);
  34. static dev_t iio_devt;
  35. #define IIO_DEV_MAX 256
  36. struct bus_type iio_bus_type = {
  37. .name = "iio",
  38. };
  39. EXPORT_SYMBOL(iio_bus_type);
  40. static struct dentry *iio_debugfs_dentry;
  41. static const char * const iio_direction[] = {
  42. [0] = "in",
  43. [1] = "out",
  44. };
  45. static const char * const iio_chan_type_name_spec[] = {
  46. [IIO_VOLTAGE] = "voltage",
  47. [IIO_CURRENT] = "current",
  48. [IIO_POWER] = "power",
  49. [IIO_ACCEL] = "accel",
  50. [IIO_ANGL_VEL] = "anglvel",
  51. [IIO_MAGN] = "magn",
  52. [IIO_LIGHT] = "illuminance",
  53. [IIO_INTENSITY] = "intensity",
  54. [IIO_PROXIMITY] = "proximity",
  55. [IIO_TEMP] = "temp",
  56. [IIO_INCLI] = "incli",
  57. [IIO_ROT] = "rot",
  58. [IIO_ANGL] = "angl",
  59. [IIO_TIMESTAMP] = "timestamp",
  60. [IIO_CAPACITANCE] = "capacitance",
  61. [IIO_ALTVOLTAGE] = "altvoltage",
  62. [IIO_CCT] = "cct",
  63. [IIO_PRESSURE] = "pressure",
  64. [IIO_HUMIDITYRELATIVE] = "humidityrelative",
  65. };
  66. static const char * const iio_modifier_names[] = {
  67. [IIO_MOD_X] = "x",
  68. [IIO_MOD_Y] = "y",
  69. [IIO_MOD_Z] = "z",
  70. [IIO_MOD_ROOT_SUM_SQUARED_X_Y] = "sqrt(x^2+y^2)",
  71. [IIO_MOD_SUM_SQUARED_X_Y_Z] = "x^2+y^2+z^2",
  72. [IIO_MOD_LIGHT_BOTH] = "both",
  73. [IIO_MOD_LIGHT_IR] = "ir",
  74. [IIO_MOD_LIGHT_CLEAR] = "clear",
  75. [IIO_MOD_LIGHT_RED] = "red",
  76. [IIO_MOD_LIGHT_GREEN] = "green",
  77. [IIO_MOD_LIGHT_BLUE] = "blue",
  78. [IIO_MOD_QUATERNION] = "quaternion",
  79. [IIO_MOD_TEMP_AMBIENT] = "ambient",
  80. [IIO_MOD_TEMP_OBJECT] = "object",
  81. };
  82. /* relies on pairs of these shared then separate */
  83. static const char * const iio_chan_info_postfix[] = {
  84. [IIO_CHAN_INFO_RAW] = "raw",
  85. [IIO_CHAN_INFO_PROCESSED] = "input",
  86. [IIO_CHAN_INFO_SCALE] = "scale",
  87. [IIO_CHAN_INFO_OFFSET] = "offset",
  88. [IIO_CHAN_INFO_CALIBSCALE] = "calibscale",
  89. [IIO_CHAN_INFO_CALIBBIAS] = "calibbias",
  90. [IIO_CHAN_INFO_PEAK] = "peak_raw",
  91. [IIO_CHAN_INFO_PEAK_SCALE] = "peak_scale",
  92. [IIO_CHAN_INFO_QUADRATURE_CORRECTION_RAW] = "quadrature_correction_raw",
  93. [IIO_CHAN_INFO_AVERAGE_RAW] = "mean_raw",
  94. [IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY]
  95. = "filter_low_pass_3db_frequency",
  96. [IIO_CHAN_INFO_SAMP_FREQ] = "sampling_frequency",
  97. [IIO_CHAN_INFO_FREQUENCY] = "frequency",
  98. [IIO_CHAN_INFO_PHASE] = "phase",
  99. [IIO_CHAN_INFO_HARDWAREGAIN] = "hardwaregain",
  100. [IIO_CHAN_INFO_HYSTERESIS] = "hysteresis",
  101. [IIO_CHAN_INFO_INT_TIME] = "integration_time",
  102. };
  103. /**
  104. * iio_find_channel_from_si() - get channel from its scan index
  105. * @indio_dev: device
  106. * @si: scan index to match
  107. */
  108. const struct iio_chan_spec
  109. *iio_find_channel_from_si(struct iio_dev *indio_dev, int si)
  110. {
  111. int i;
  112. for (i = 0; i < indio_dev->num_channels; i++)
  113. if (indio_dev->channels[i].scan_index == si)
  114. return &indio_dev->channels[i];
  115. return NULL;
  116. }
  117. /* This turns up an awful lot */
  118. ssize_t iio_read_const_attr(struct device *dev,
  119. struct device_attribute *attr,
  120. char *buf)
  121. {
  122. return sprintf(buf, "%s\n", to_iio_const_attr(attr)->string);
  123. }
  124. EXPORT_SYMBOL(iio_read_const_attr);
  125. static int __init iio_init(void)
  126. {
  127. int ret;
  128. /* Register sysfs bus */
  129. ret = bus_register(&iio_bus_type);
  130. if (ret < 0) {
  131. pr_err("could not register bus type\n");
  132. goto error_nothing;
  133. }
  134. ret = alloc_chrdev_region(&iio_devt, 0, IIO_DEV_MAX, "iio");
  135. if (ret < 0) {
  136. pr_err("failed to allocate char dev region\n");
  137. goto error_unregister_bus_type;
  138. }
  139. iio_debugfs_dentry = debugfs_create_dir("iio", NULL);
  140. return 0;
  141. error_unregister_bus_type:
  142. bus_unregister(&iio_bus_type);
  143. error_nothing:
  144. return ret;
  145. }
  146. static void __exit iio_exit(void)
  147. {
  148. if (iio_devt)
  149. unregister_chrdev_region(iio_devt, IIO_DEV_MAX);
  150. bus_unregister(&iio_bus_type);
  151. debugfs_remove(iio_debugfs_dentry);
  152. }
  153. #if defined(CONFIG_DEBUG_FS)
  154. static ssize_t iio_debugfs_read_reg(struct file *file, char __user *userbuf,
  155. size_t count, loff_t *ppos)
  156. {
  157. struct iio_dev *indio_dev = file->private_data;
  158. char buf[20];
  159. unsigned val = 0;
  160. ssize_t len;
  161. int ret;
  162. ret = indio_dev->info->debugfs_reg_access(indio_dev,
  163. indio_dev->cached_reg_addr,
  164. 0, &val);
  165. if (ret)
  166. dev_err(indio_dev->dev.parent, "%s: read failed\n", __func__);
  167. len = snprintf(buf, sizeof(buf), "0x%X\n", val);
  168. return simple_read_from_buffer(userbuf, count, ppos, buf, len);
  169. }
  170. static ssize_t iio_debugfs_write_reg(struct file *file,
  171. const char __user *userbuf, size_t count, loff_t *ppos)
  172. {
  173. struct iio_dev *indio_dev = file->private_data;
  174. unsigned reg, val;
  175. char buf[80];
  176. int ret;
  177. count = min_t(size_t, count, (sizeof(buf)-1));
  178. if (copy_from_user(buf, userbuf, count))
  179. return -EFAULT;
  180. buf[count] = 0;
  181. ret = sscanf(buf, "%i %i", &reg, &val);
  182. switch (ret) {
  183. case 1:
  184. indio_dev->cached_reg_addr = reg;
  185. break;
  186. case 2:
  187. indio_dev->cached_reg_addr = reg;
  188. ret = indio_dev->info->debugfs_reg_access(indio_dev, reg,
  189. val, NULL);
  190. if (ret) {
  191. dev_err(indio_dev->dev.parent, "%s: write failed\n",
  192. __func__);
  193. return ret;
  194. }
  195. break;
  196. default:
  197. return -EINVAL;
  198. }
  199. return count;
  200. }
  201. static const struct file_operations iio_debugfs_reg_fops = {
  202. .open = simple_open,
  203. .read = iio_debugfs_read_reg,
  204. .write = iio_debugfs_write_reg,
  205. };
  206. static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
  207. {
  208. debugfs_remove_recursive(indio_dev->debugfs_dentry);
  209. }
  210. static int iio_device_register_debugfs(struct iio_dev *indio_dev)
  211. {
  212. struct dentry *d;
  213. if (indio_dev->info->debugfs_reg_access == NULL)
  214. return 0;
  215. if (!iio_debugfs_dentry)
  216. return 0;
  217. indio_dev->debugfs_dentry =
  218. debugfs_create_dir(dev_name(&indio_dev->dev),
  219. iio_debugfs_dentry);
  220. if (indio_dev->debugfs_dentry == NULL) {
  221. dev_warn(indio_dev->dev.parent,
  222. "Failed to create debugfs directory\n");
  223. return -EFAULT;
  224. }
  225. d = debugfs_create_file("direct_reg_access", 0644,
  226. indio_dev->debugfs_dentry,
  227. indio_dev, &iio_debugfs_reg_fops);
  228. if (!d) {
  229. iio_device_unregister_debugfs(indio_dev);
  230. return -ENOMEM;
  231. }
  232. return 0;
  233. }
  234. #else
  235. static int iio_device_register_debugfs(struct iio_dev *indio_dev)
  236. {
  237. return 0;
  238. }
  239. static void iio_device_unregister_debugfs(struct iio_dev *indio_dev)
  240. {
  241. }
  242. #endif /* CONFIG_DEBUG_FS */
  243. static ssize_t iio_read_channel_ext_info(struct device *dev,
  244. struct device_attribute *attr,
  245. char *buf)
  246. {
  247. struct iio_dev *indio_dev = dev_to_iio_dev(dev);
  248. struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
  249. const struct iio_chan_spec_ext_info *ext_info;
  250. ext_info = &this_attr->c->ext_info[this_attr->address];
  251. return ext_info->read(indio_dev, ext_info->private, this_attr->c, buf);
  252. }
  253. static ssize_t iio_write_channel_ext_info(struct device *dev,
  254. struct device_attribute *attr,
  255. const char *buf,
  256. size_t len)
  257. {
  258. struct iio_dev *indio_dev = dev_to_iio_dev(dev);
  259. struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
  260. const struct iio_chan_spec_ext_info *ext_info;
  261. ext_info = &this_attr->c->ext_info[this_attr->address];
  262. return ext_info->write(indio_dev, ext_info->private,
  263. this_attr->c, buf, len);
  264. }
  265. ssize_t iio_enum_available_read(struct iio_dev *indio_dev,
  266. uintptr_t priv, const struct iio_chan_spec *chan, char *buf)
  267. {
  268. const struct iio_enum *e = (const struct iio_enum *)priv;
  269. unsigned int i;
  270. size_t len = 0;
  271. if (!e->num_items)
  272. return 0;
  273. for (i = 0; i < e->num_items; ++i)
  274. len += scnprintf(buf + len, PAGE_SIZE - len, "%s ", e->items[i]);
  275. /* replace last space with a newline */
  276. buf[len - 1] = '\n';
  277. return len;
  278. }
  279. EXPORT_SYMBOL_GPL(iio_enum_available_read);
  280. ssize_t iio_enum_read(struct iio_dev *indio_dev,
  281. uintptr_t priv, const struct iio_chan_spec *chan, char *buf)
  282. {
  283. const struct iio_enum *e = (const struct iio_enum *)priv;
  284. int i;
  285. if (!e->get)
  286. return -EINVAL;
  287. i = e->get(indio_dev, chan);
  288. if (i < 0)
  289. return i;
  290. else if (i >= e->num_items)
  291. return -EINVAL;
  292. return snprintf(buf, PAGE_SIZE, "%s\n", e->items[i]);
  293. }
  294. EXPORT_SYMBOL_GPL(iio_enum_read);
  295. ssize_t iio_enum_write(struct iio_dev *indio_dev,
  296. uintptr_t priv, const struct iio_chan_spec *chan, const char *buf,
  297. size_t len)
  298. {
  299. const struct iio_enum *e = (const struct iio_enum *)priv;
  300. unsigned int i;
  301. int ret;
  302. if (!e->set)
  303. return -EINVAL;
  304. for (i = 0; i < e->num_items; i++) {
  305. if (sysfs_streq(buf, e->items[i]))
  306. break;
  307. }
  308. if (i == e->num_items)
  309. return -EINVAL;
  310. ret = e->set(indio_dev, chan, i);
  311. return ret ? ret : len;
  312. }
  313. EXPORT_SYMBOL_GPL(iio_enum_write);
  314. /**
  315. * iio_format_value() - Formats a IIO value into its string representation
  316. * @buf: The buffer to which the formated value gets written
  317. * @type: One of the IIO_VAL_... constants. This decides how the val and val2
  318. * parameters are formatted.
  319. * @vals: pointer to the values, exact meaning depends on the type parameter.
  320. */
  321. ssize_t iio_format_value(char *buf, unsigned int type, int size, int *vals)
  322. {
  323. unsigned long long tmp;
  324. bool scale_db = false;
  325. switch (type) {
  326. case IIO_VAL_INT:
  327. return sprintf(buf, "%d\n", vals[0]);
  328. case IIO_VAL_INT_PLUS_MICRO_DB:
  329. scale_db = true;
  330. case IIO_VAL_INT_PLUS_MICRO:
  331. if (vals[1] < 0)
  332. return sprintf(buf, "-%ld.%06u%s\n", abs(vals[0]),
  333. -vals[1],
  334. scale_db ? " dB" : "");
  335. else
  336. return sprintf(buf, "%d.%06u%s\n", vals[0], vals[1],
  337. scale_db ? " dB" : "");
  338. case IIO_VAL_INT_PLUS_NANO:
  339. if (vals[1] < 0)
  340. return sprintf(buf, "-%ld.%09u\n", abs(vals[0]),
  341. -vals[1]);
  342. else
  343. return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
  344. case IIO_VAL_FRACTIONAL:
  345. tmp = div_s64((s64)vals[0] * 1000000000LL, vals[1]);
  346. vals[1] = do_div(tmp, 1000000000LL);
  347. vals[0] = tmp;
  348. return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
  349. case IIO_VAL_FRACTIONAL_LOG2:
  350. tmp = (s64)vals[0] * 1000000000LL >> vals[1];
  351. vals[1] = do_div(tmp, 1000000000LL);
  352. vals[0] = tmp;
  353. return sprintf(buf, "%d.%09u\n", vals[0], vals[1]);
  354. case IIO_VAL_INT_MULTIPLE:
  355. {
  356. int i;
  357. int len = 0;
  358. for (i = 0; i < size; ++i)
  359. len += snprintf(&buf[len], PAGE_SIZE - len, "%d ",
  360. vals[i]);
  361. len += snprintf(&buf[len], PAGE_SIZE - len, "\n");
  362. return len;
  363. }
  364. default:
  365. return 0;
  366. }
  367. }
  368. static ssize_t iio_read_channel_info(struct device *dev,
  369. struct device_attribute *attr,
  370. char *buf)
  371. {
  372. struct iio_dev *indio_dev = dev_to_iio_dev(dev);
  373. struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
  374. int vals[INDIO_MAX_RAW_ELEMENTS];
  375. int ret;
  376. int val_len = 2;
  377. if (indio_dev->info->read_raw_multi)
  378. ret = indio_dev->info->read_raw_multi(indio_dev, this_attr->c,
  379. INDIO_MAX_RAW_ELEMENTS,
  380. vals, &val_len,
  381. this_attr->address);
  382. else
  383. ret = indio_dev->info->read_raw(indio_dev, this_attr->c,
  384. &vals[0], &vals[1], this_attr->address);
  385. if (ret < 0)
  386. return ret;
  387. return iio_format_value(buf, ret, val_len, vals);
  388. }
  389. /**
  390. * iio_str_to_fixpoint() - Parse a fixed-point number from a string
  391. * @str: The string to parse
  392. * @fract_mult: Multiplier for the first decimal place, should be a power of 10
  393. * @integer: The integer part of the number
  394. * @fract: The fractional part of the number
  395. *
  396. * Returns 0 on success, or a negative error code if the string could not be
  397. * parsed.
  398. */
  399. int iio_str_to_fixpoint(const char *str, int fract_mult,
  400. int *integer, int *fract)
  401. {
  402. int i = 0, f = 0;
  403. bool integer_part = true, negative = false;
  404. if (str[0] == '-') {
  405. negative = true;
  406. str++;
  407. } else if (str[0] == '+') {
  408. str++;
  409. }
  410. while (*str) {
  411. if ('0' <= *str && *str <= '9') {
  412. if (integer_part) {
  413. i = i * 10 + *str - '0';
  414. } else {
  415. f += fract_mult * (*str - '0');
  416. fract_mult /= 10;
  417. }
  418. } else if (*str == '\n') {
  419. if (*(str + 1) == '\0')
  420. break;
  421. else
  422. return -EINVAL;
  423. } else if (*str == '.' && integer_part) {
  424. integer_part = false;
  425. } else {
  426. return -EINVAL;
  427. }
  428. str++;
  429. }
  430. if (negative) {
  431. if (i)
  432. i = -i;
  433. else
  434. f = -f;
  435. }
  436. *integer = i;
  437. *fract = f;
  438. return 0;
  439. }
  440. EXPORT_SYMBOL_GPL(iio_str_to_fixpoint);
  441. static ssize_t iio_write_channel_info(struct device *dev,
  442. struct device_attribute *attr,
  443. const char *buf,
  444. size_t len)
  445. {
  446. struct iio_dev *indio_dev = dev_to_iio_dev(dev);
  447. struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
  448. int ret, fract_mult = 100000;
  449. int integer, fract;
  450. /* Assumes decimal - precision based on number of digits */
  451. if (!indio_dev->info->write_raw)
  452. return -EINVAL;
  453. if (indio_dev->info->write_raw_get_fmt)
  454. switch (indio_dev->info->write_raw_get_fmt(indio_dev,
  455. this_attr->c, this_attr->address)) {
  456. case IIO_VAL_INT_PLUS_MICRO:
  457. fract_mult = 100000;
  458. break;
  459. case IIO_VAL_INT_PLUS_NANO:
  460. fract_mult = 100000000;
  461. break;
  462. default:
  463. return -EINVAL;
  464. }
  465. ret = iio_str_to_fixpoint(buf, fract_mult, &integer, &fract);
  466. if (ret)
  467. return ret;
  468. ret = indio_dev->info->write_raw(indio_dev, this_attr->c,
  469. integer, fract, this_attr->address);
  470. if (ret)
  471. return ret;
  472. return len;
  473. }
  474. static
  475. int __iio_device_attr_init(struct device_attribute *dev_attr,
  476. const char *postfix,
  477. struct iio_chan_spec const *chan,
  478. ssize_t (*readfunc)(struct device *dev,
  479. struct device_attribute *attr,
  480. char *buf),
  481. ssize_t (*writefunc)(struct device *dev,
  482. struct device_attribute *attr,
  483. const char *buf,
  484. size_t len),
  485. enum iio_shared_by shared_by)
  486. {
  487. int ret = 0;
  488. char *name = NULL;
  489. char *full_postfix;
  490. sysfs_attr_init(&dev_attr->attr);
  491. /* Build up postfix of <extend_name>_<modifier>_postfix */
  492. if (chan->modified && (shared_by == IIO_SEPARATE)) {
  493. if (chan->extend_name)
  494. full_postfix = kasprintf(GFP_KERNEL, "%s_%s_%s",
  495. iio_modifier_names[chan
  496. ->channel2],
  497. chan->extend_name,
  498. postfix);
  499. else
  500. full_postfix = kasprintf(GFP_KERNEL, "%s_%s",
  501. iio_modifier_names[chan
  502. ->channel2],
  503. postfix);
  504. } else {
  505. if (chan->extend_name == NULL || shared_by != IIO_SEPARATE)
  506. full_postfix = kstrdup(postfix, GFP_KERNEL);
  507. else
  508. full_postfix = kasprintf(GFP_KERNEL,
  509. "%s_%s",
  510. chan->extend_name,
  511. postfix);
  512. }
  513. if (full_postfix == NULL)
  514. return -ENOMEM;
  515. if (chan->differential) { /* Differential can not have modifier */
  516. switch (shared_by) {
  517. case IIO_SHARED_BY_ALL:
  518. name = kasprintf(GFP_KERNEL, "%s", full_postfix);
  519. break;
  520. case IIO_SHARED_BY_DIR:
  521. name = kasprintf(GFP_KERNEL, "%s_%s",
  522. iio_direction[chan->output],
  523. full_postfix);
  524. break;
  525. case IIO_SHARED_BY_TYPE:
  526. name = kasprintf(GFP_KERNEL, "%s_%s-%s_%s",
  527. iio_direction[chan->output],
  528. iio_chan_type_name_spec[chan->type],
  529. iio_chan_type_name_spec[chan->type],
  530. full_postfix);
  531. break;
  532. case IIO_SEPARATE:
  533. if (!chan->indexed) {
  534. WARN_ON("Differential channels must be indexed\n");
  535. ret = -EINVAL;
  536. goto error_free_full_postfix;
  537. }
  538. name = kasprintf(GFP_KERNEL,
  539. "%s_%s%d-%s%d_%s",
  540. iio_direction[chan->output],
  541. iio_chan_type_name_spec[chan->type],
  542. chan->channel,
  543. iio_chan_type_name_spec[chan->type],
  544. chan->channel2,
  545. full_postfix);
  546. break;
  547. }
  548. } else { /* Single ended */
  549. switch (shared_by) {
  550. case IIO_SHARED_BY_ALL:
  551. name = kasprintf(GFP_KERNEL, "%s", full_postfix);
  552. break;
  553. case IIO_SHARED_BY_DIR:
  554. name = kasprintf(GFP_KERNEL, "%s_%s",
  555. iio_direction[chan->output],
  556. full_postfix);
  557. break;
  558. case IIO_SHARED_BY_TYPE:
  559. name = kasprintf(GFP_KERNEL, "%s_%s_%s",
  560. iio_direction[chan->output],
  561. iio_chan_type_name_spec[chan->type],
  562. full_postfix);
  563. break;
  564. case IIO_SEPARATE:
  565. if (chan->indexed)
  566. name = kasprintf(GFP_KERNEL, "%s_%s%d_%s",
  567. iio_direction[chan->output],
  568. iio_chan_type_name_spec[chan->type],
  569. chan->channel,
  570. full_postfix);
  571. else
  572. name = kasprintf(GFP_KERNEL, "%s_%s_%s",
  573. iio_direction[chan->output],
  574. iio_chan_type_name_spec[chan->type],
  575. full_postfix);
  576. break;
  577. }
  578. }
  579. if (name == NULL) {
  580. ret = -ENOMEM;
  581. goto error_free_full_postfix;
  582. }
  583. dev_attr->attr.name = name;
  584. if (readfunc) {
  585. dev_attr->attr.mode |= S_IRUGO;
  586. dev_attr->show = readfunc;
  587. }
  588. if (writefunc) {
  589. dev_attr->attr.mode |= S_IWUSR;
  590. dev_attr->store = writefunc;
  591. }
  592. error_free_full_postfix:
  593. kfree(full_postfix);
  594. return ret;
  595. }
  596. static void __iio_device_attr_deinit(struct device_attribute *dev_attr)
  597. {
  598. kfree(dev_attr->attr.name);
  599. }
  600. int __iio_add_chan_devattr(const char *postfix,
  601. struct iio_chan_spec const *chan,
  602. ssize_t (*readfunc)(struct device *dev,
  603. struct device_attribute *attr,
  604. char *buf),
  605. ssize_t (*writefunc)(struct device *dev,
  606. struct device_attribute *attr,
  607. const char *buf,
  608. size_t len),
  609. u64 mask,
  610. enum iio_shared_by shared_by,
  611. struct device *dev,
  612. struct list_head *attr_list)
  613. {
  614. int ret;
  615. struct iio_dev_attr *iio_attr, *t;
  616. iio_attr = kzalloc(sizeof(*iio_attr), GFP_KERNEL);
  617. if (iio_attr == NULL)
  618. return -ENOMEM;
  619. ret = __iio_device_attr_init(&iio_attr->dev_attr,
  620. postfix, chan,
  621. readfunc, writefunc, shared_by);
  622. if (ret)
  623. goto error_iio_dev_attr_free;
  624. iio_attr->c = chan;
  625. iio_attr->address = mask;
  626. list_for_each_entry(t, attr_list, l)
  627. if (strcmp(t->dev_attr.attr.name,
  628. iio_attr->dev_attr.attr.name) == 0) {
  629. if (shared_by == IIO_SEPARATE)
  630. dev_err(dev, "tried to double register : %s\n",
  631. t->dev_attr.attr.name);
  632. ret = -EBUSY;
  633. goto error_device_attr_deinit;
  634. }
  635. list_add(&iio_attr->l, attr_list);
  636. return 0;
  637. error_device_attr_deinit:
  638. __iio_device_attr_deinit(&iio_attr->dev_attr);
  639. error_iio_dev_attr_free:
  640. kfree(iio_attr);
  641. return ret;
  642. }
  643. static int iio_device_add_info_mask_type(struct iio_dev *indio_dev,
  644. struct iio_chan_spec const *chan,
  645. enum iio_shared_by shared_by,
  646. const long *infomask)
  647. {
  648. int i, ret, attrcount = 0;
  649. for_each_set_bit(i, infomask, sizeof(infomask)*8) {
  650. if (i >= ARRAY_SIZE(iio_chan_info_postfix))
  651. return -EINVAL;
  652. ret = __iio_add_chan_devattr(iio_chan_info_postfix[i],
  653. chan,
  654. &iio_read_channel_info,
  655. &iio_write_channel_info,
  656. i,
  657. shared_by,
  658. &indio_dev->dev,
  659. &indio_dev->channel_attr_list);
  660. if ((ret == -EBUSY) && (shared_by != IIO_SEPARATE))
  661. continue;
  662. else if (ret < 0)
  663. return ret;
  664. attrcount++;
  665. }
  666. return attrcount;
  667. }
  668. static int iio_device_add_channel_sysfs(struct iio_dev *indio_dev,
  669. struct iio_chan_spec const *chan)
  670. {
  671. int ret, attrcount = 0;
  672. const struct iio_chan_spec_ext_info *ext_info;
  673. if (chan->channel < 0)
  674. return 0;
  675. ret = iio_device_add_info_mask_type(indio_dev, chan,
  676. IIO_SEPARATE,
  677. &chan->info_mask_separate);
  678. if (ret < 0)
  679. return ret;
  680. attrcount += ret;
  681. ret = iio_device_add_info_mask_type(indio_dev, chan,
  682. IIO_SHARED_BY_TYPE,
  683. &chan->info_mask_shared_by_type);
  684. if (ret < 0)
  685. return ret;
  686. attrcount += ret;
  687. ret = iio_device_add_info_mask_type(indio_dev, chan,
  688. IIO_SHARED_BY_DIR,
  689. &chan->info_mask_shared_by_dir);
  690. if (ret < 0)
  691. return ret;
  692. attrcount += ret;
  693. ret = iio_device_add_info_mask_type(indio_dev, chan,
  694. IIO_SHARED_BY_ALL,
  695. &chan->info_mask_shared_by_all);
  696. if (ret < 0)
  697. return ret;
  698. attrcount += ret;
  699. if (chan->ext_info) {
  700. unsigned int i = 0;
  701. for (ext_info = chan->ext_info; ext_info->name; ext_info++) {
  702. ret = __iio_add_chan_devattr(ext_info->name,
  703. chan,
  704. ext_info->read ?
  705. &iio_read_channel_ext_info : NULL,
  706. ext_info->write ?
  707. &iio_write_channel_ext_info : NULL,
  708. i,
  709. ext_info->shared,
  710. &indio_dev->dev,
  711. &indio_dev->channel_attr_list);
  712. i++;
  713. if (ret == -EBUSY && ext_info->shared)
  714. continue;
  715. if (ret)
  716. return ret;
  717. attrcount++;
  718. }
  719. }
  720. return attrcount;
  721. }
  722. /**
  723. * iio_free_chan_devattr_list() - Free a list of IIO device attributes
  724. * @attr_list: List of IIO device attributes
  725. *
  726. * This function frees the memory allocated for each of the IIO device
  727. * attributes in the list. Note: if you want to reuse the list after calling
  728. * this function you have to reinitialize it using INIT_LIST_HEAD().
  729. */
  730. void iio_free_chan_devattr_list(struct list_head *attr_list)
  731. {
  732. struct iio_dev_attr *p, *n;
  733. list_for_each_entry_safe(p, n, attr_list, l) {
  734. kfree(p->dev_attr.attr.name);
  735. kfree(p);
  736. }
  737. }
  738. static ssize_t iio_show_dev_name(struct device *dev,
  739. struct device_attribute *attr,
  740. char *buf)
  741. {
  742. struct iio_dev *indio_dev = dev_to_iio_dev(dev);
  743. return snprintf(buf, PAGE_SIZE, "%s\n", indio_dev->name);
  744. }
  745. static DEVICE_ATTR(name, S_IRUGO, iio_show_dev_name, NULL);
  746. static int iio_device_register_sysfs(struct iio_dev *indio_dev)
  747. {
  748. int i, ret = 0, attrcount, attrn, attrcount_orig = 0;
  749. struct iio_dev_attr *p;
  750. struct attribute **attr;
  751. /* First count elements in any existing group */
  752. if (indio_dev->info->attrs) {
  753. attr = indio_dev->info->attrs->attrs;
  754. while (*attr++ != NULL)
  755. attrcount_orig++;
  756. }
  757. attrcount = attrcount_orig;
  758. /*
  759. * New channel registration method - relies on the fact a group does
  760. * not need to be initialized if its name is NULL.
  761. */
  762. if (indio_dev->channels)
  763. for (i = 0; i < indio_dev->num_channels; i++) {
  764. ret = iio_device_add_channel_sysfs(indio_dev,
  765. &indio_dev
  766. ->channels[i]);
  767. if (ret < 0)
  768. goto error_clear_attrs;
  769. attrcount += ret;
  770. }
  771. if (indio_dev->name)
  772. attrcount++;
  773. indio_dev->chan_attr_group.attrs = kcalloc(attrcount + 1,
  774. sizeof(indio_dev->chan_attr_group.attrs[0]),
  775. GFP_KERNEL);
  776. if (indio_dev->chan_attr_group.attrs == NULL) {
  777. ret = -ENOMEM;
  778. goto error_clear_attrs;
  779. }
  780. /* Copy across original attributes */
  781. if (indio_dev->info->attrs)
  782. memcpy(indio_dev->chan_attr_group.attrs,
  783. indio_dev->info->attrs->attrs,
  784. sizeof(indio_dev->chan_attr_group.attrs[0])
  785. *attrcount_orig);
  786. attrn = attrcount_orig;
  787. /* Add all elements from the list. */
  788. list_for_each_entry(p, &indio_dev->channel_attr_list, l)
  789. indio_dev->chan_attr_group.attrs[attrn++] = &p->dev_attr.attr;
  790. if (indio_dev->name)
  791. indio_dev->chan_attr_group.attrs[attrn++] = &dev_attr_name.attr;
  792. indio_dev->groups[indio_dev->groupcounter++] =
  793. &indio_dev->chan_attr_group;
  794. return 0;
  795. error_clear_attrs:
  796. iio_free_chan_devattr_list(&indio_dev->channel_attr_list);
  797. return ret;
  798. }
  799. static void iio_device_unregister_sysfs(struct iio_dev *indio_dev)
  800. {
  801. iio_free_chan_devattr_list(&indio_dev->channel_attr_list);
  802. kfree(indio_dev->chan_attr_group.attrs);
  803. }
  804. static void iio_dev_release(struct device *device)
  805. {
  806. struct iio_dev *indio_dev = dev_to_iio_dev(device);
  807. if (indio_dev->modes & INDIO_BUFFER_TRIGGERED)
  808. iio_device_unregister_trigger_consumer(indio_dev);
  809. iio_device_unregister_eventset(indio_dev);
  810. iio_device_unregister_sysfs(indio_dev);
  811. iio_buffer_put(indio_dev->buffer);
  812. ida_simple_remove(&iio_ida, indio_dev->id);
  813. kfree(indio_dev);
  814. }
  815. struct device_type iio_device_type = {
  816. .name = "iio_device",
  817. .release = iio_dev_release,
  818. };
  819. /**
  820. * iio_device_alloc() - allocate an iio_dev from a driver
  821. * @sizeof_priv: Space to allocate for private structure.
  822. **/
  823. struct iio_dev *iio_device_alloc(int sizeof_priv)
  824. {
  825. struct iio_dev *dev;
  826. size_t alloc_size;
  827. alloc_size = sizeof(struct iio_dev);
  828. if (sizeof_priv) {
  829. alloc_size = ALIGN(alloc_size, IIO_ALIGN);
  830. alloc_size += sizeof_priv;
  831. }
  832. /* ensure 32-byte alignment of whole construct ? */
  833. alloc_size += IIO_ALIGN - 1;
  834. dev = kzalloc(alloc_size, GFP_KERNEL);
  835. if (dev) {
  836. dev->dev.groups = dev->groups;
  837. dev->dev.type = &iio_device_type;
  838. dev->dev.bus = &iio_bus_type;
  839. device_initialize(&dev->dev);
  840. dev_set_drvdata(&dev->dev, (void *)dev);
  841. mutex_init(&dev->mlock);
  842. mutex_init(&dev->info_exist_lock);
  843. INIT_LIST_HEAD(&dev->channel_attr_list);
  844. dev->id = ida_simple_get(&iio_ida, 0, 0, GFP_KERNEL);
  845. if (dev->id < 0) {
  846. /* cannot use a dev_err as the name isn't available */
  847. pr_err("failed to get device id\n");
  848. kfree(dev);
  849. return NULL;
  850. }
  851. dev_set_name(&dev->dev, "iio:device%d", dev->id);
  852. INIT_LIST_HEAD(&dev->buffer_list);
  853. }
  854. return dev;
  855. }
  856. EXPORT_SYMBOL(iio_device_alloc);
  857. /**
  858. * iio_device_free() - free an iio_dev from a driver
  859. * @dev: the iio_dev associated with the device
  860. **/
  861. void iio_device_free(struct iio_dev *dev)
  862. {
  863. if (dev)
  864. put_device(&dev->dev);
  865. }
  866. EXPORT_SYMBOL(iio_device_free);
  867. static void devm_iio_device_release(struct device *dev, void *res)
  868. {
  869. iio_device_free(*(struct iio_dev **)res);
  870. }
  871. static int devm_iio_device_match(struct device *dev, void *res, void *data)
  872. {
  873. struct iio_dev **r = res;
  874. if (!r || !*r) {
  875. WARN_ON(!r || !*r);
  876. return 0;
  877. }
  878. return *r == data;
  879. }
  880. /**
  881. * devm_iio_device_alloc - Resource-managed iio_device_alloc()
  882. * @dev: Device to allocate iio_dev for
  883. * @sizeof_priv: Space to allocate for private structure.
  884. *
  885. * Managed iio_device_alloc. iio_dev allocated with this function is
  886. * automatically freed on driver detach.
  887. *
  888. * If an iio_dev allocated with this function needs to be freed separately,
  889. * devm_iio_device_free() must be used.
  890. *
  891. * RETURNS:
  892. * Pointer to allocated iio_dev on success, NULL on failure.
  893. */
  894. struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv)
  895. {
  896. struct iio_dev **ptr, *iio_dev;
  897. ptr = devres_alloc(devm_iio_device_release, sizeof(*ptr),
  898. GFP_KERNEL);
  899. if (!ptr)
  900. return NULL;
  901. /* use raw alloc_dr for kmalloc caller tracing */
  902. iio_dev = iio_device_alloc(sizeof_priv);
  903. if (iio_dev) {
  904. *ptr = iio_dev;
  905. devres_add(dev, ptr);
  906. } else {
  907. devres_free(ptr);
  908. }
  909. return iio_dev;
  910. }
  911. EXPORT_SYMBOL_GPL(devm_iio_device_alloc);
  912. /**
  913. * devm_iio_device_free - Resource-managed iio_device_free()
  914. * @dev: Device this iio_dev belongs to
  915. * @iio_dev: the iio_dev associated with the device
  916. *
  917. * Free iio_dev allocated with devm_iio_device_alloc().
  918. */
  919. void devm_iio_device_free(struct device *dev, struct iio_dev *iio_dev)
  920. {
  921. int rc;
  922. rc = devres_release(dev, devm_iio_device_release,
  923. devm_iio_device_match, iio_dev);
  924. WARN_ON(rc);
  925. }
  926. EXPORT_SYMBOL_GPL(devm_iio_device_free);
  927. /**
  928. * iio_chrdev_open() - chrdev file open for buffer access and ioctls
  929. **/
  930. static int iio_chrdev_open(struct inode *inode, struct file *filp)
  931. {
  932. struct iio_dev *indio_dev = container_of(inode->i_cdev,
  933. struct iio_dev, chrdev);
  934. if (test_and_set_bit(IIO_BUSY_BIT_POS, &indio_dev->flags))
  935. return -EBUSY;
  936. iio_device_get(indio_dev);
  937. filp->private_data = indio_dev;
  938. return 0;
  939. }
  940. /**
  941. * iio_chrdev_release() - chrdev file close buffer access and ioctls
  942. **/
  943. static int iio_chrdev_release(struct inode *inode, struct file *filp)
  944. {
  945. struct iio_dev *indio_dev = container_of(inode->i_cdev,
  946. struct iio_dev, chrdev);
  947. clear_bit(IIO_BUSY_BIT_POS, &indio_dev->flags);
  948. iio_device_put(indio_dev);
  949. return 0;
  950. }
  951. /* Somewhat of a cross file organization violation - ioctls here are actually
  952. * event related */
  953. static long iio_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
  954. {
  955. struct iio_dev *indio_dev = filp->private_data;
  956. int __user *ip = (int __user *)arg;
  957. int fd;
  958. if (!indio_dev->info)
  959. return -ENODEV;
  960. if (cmd == IIO_GET_EVENT_FD_IOCTL) {
  961. fd = iio_event_getfd(indio_dev);
  962. if (copy_to_user(ip, &fd, sizeof(fd)))
  963. return -EFAULT;
  964. return 0;
  965. }
  966. return -EINVAL;
  967. }
  968. static const struct file_operations iio_buffer_fileops = {
  969. .read = iio_buffer_read_first_n_outer_addr,
  970. .release = iio_chrdev_release,
  971. .open = iio_chrdev_open,
  972. .poll = iio_buffer_poll_addr,
  973. .owner = THIS_MODULE,
  974. .llseek = noop_llseek,
  975. .unlocked_ioctl = iio_ioctl,
  976. .compat_ioctl = iio_ioctl,
  977. };
  978. static const struct iio_buffer_setup_ops noop_ring_setup_ops;
  979. /**
  980. * iio_device_register() - register a device with the IIO subsystem
  981. * @indio_dev: Device structure filled by the device driver
  982. **/
  983. int iio_device_register(struct iio_dev *indio_dev)
  984. {
  985. int ret;
  986. /* If the calling driver did not initialize of_node, do it here */
  987. if (!indio_dev->dev.of_node && indio_dev->dev.parent)
  988. indio_dev->dev.of_node = indio_dev->dev.parent->of_node;
  989. /* configure elements for the chrdev */
  990. indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
  991. ret = iio_device_register_debugfs(indio_dev);
  992. if (ret) {
  993. dev_err(indio_dev->dev.parent,
  994. "Failed to register debugfs interfaces\n");
  995. return ret;
  996. }
  997. ret = iio_device_register_sysfs(indio_dev);
  998. if (ret) {
  999. dev_err(indio_dev->dev.parent,
  1000. "Failed to register sysfs interfaces\n");
  1001. goto error_unreg_debugfs;
  1002. }
  1003. ret = iio_device_register_eventset(indio_dev);
  1004. if (ret) {
  1005. dev_err(indio_dev->dev.parent,
  1006. "Failed to register event set\n");
  1007. goto error_free_sysfs;
  1008. }
  1009. if (indio_dev->modes & INDIO_BUFFER_TRIGGERED)
  1010. iio_device_register_trigger_consumer(indio_dev);
  1011. if ((indio_dev->modes & INDIO_ALL_BUFFER_MODES) &&
  1012. indio_dev->setup_ops == NULL)
  1013. indio_dev->setup_ops = &noop_ring_setup_ops;
  1014. cdev_init(&indio_dev->chrdev, &iio_buffer_fileops);
  1015. indio_dev->chrdev.owner = indio_dev->info->driver_module;
  1016. indio_dev->chrdev.kobj.parent = &indio_dev->dev.kobj;
  1017. ret = cdev_add(&indio_dev->chrdev, indio_dev->dev.devt, 1);
  1018. if (ret < 0)
  1019. goto error_unreg_eventset;
  1020. ret = device_add(&indio_dev->dev);
  1021. if (ret < 0)
  1022. goto error_cdev_del;
  1023. return 0;
  1024. error_cdev_del:
  1025. cdev_del(&indio_dev->chrdev);
  1026. error_unreg_eventset:
  1027. iio_device_unregister_eventset(indio_dev);
  1028. error_free_sysfs:
  1029. iio_device_unregister_sysfs(indio_dev);
  1030. error_unreg_debugfs:
  1031. iio_device_unregister_debugfs(indio_dev);
  1032. return ret;
  1033. }
  1034. EXPORT_SYMBOL(iio_device_register);
  1035. /**
  1036. * iio_device_unregister() - unregister a device from the IIO subsystem
  1037. * @indio_dev: Device structure representing the device.
  1038. **/
  1039. void iio_device_unregister(struct iio_dev *indio_dev)
  1040. {
  1041. mutex_lock(&indio_dev->info_exist_lock);
  1042. device_del(&indio_dev->dev);
  1043. if (indio_dev->chrdev.dev)
  1044. cdev_del(&indio_dev->chrdev);
  1045. iio_device_unregister_debugfs(indio_dev);
  1046. iio_disable_all_buffers(indio_dev);
  1047. indio_dev->info = NULL;
  1048. iio_device_wakeup_eventset(indio_dev);
  1049. iio_buffer_wakeup_poll(indio_dev);
  1050. mutex_unlock(&indio_dev->info_exist_lock);
  1051. }
  1052. EXPORT_SYMBOL(iio_device_unregister);
  1053. static void devm_iio_device_unreg(struct device *dev, void *res)
  1054. {
  1055. iio_device_unregister(*(struct iio_dev **)res);
  1056. }
  1057. /**
  1058. * devm_iio_device_register - Resource-managed iio_device_register()
  1059. * @dev: Device to allocate iio_dev for
  1060. * @indio_dev: Device structure filled by the device driver
  1061. *
  1062. * Managed iio_device_register. The IIO device registered with this
  1063. * function is automatically unregistered on driver detach. This function
  1064. * calls iio_device_register() internally. Refer to that function for more
  1065. * information.
  1066. *
  1067. * If an iio_dev registered with this function needs to be unregistered
  1068. * separately, devm_iio_device_unregister() must be used.
  1069. *
  1070. * RETURNS:
  1071. * 0 on success, negative error number on failure.
  1072. */
  1073. int devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev)
  1074. {
  1075. struct iio_dev **ptr;
  1076. int ret;
  1077. ptr = devres_alloc(devm_iio_device_unreg, sizeof(*ptr), GFP_KERNEL);
  1078. if (!ptr)
  1079. return -ENOMEM;
  1080. *ptr = indio_dev;
  1081. ret = iio_device_register(indio_dev);
  1082. if (!ret)
  1083. devres_add(dev, ptr);
  1084. else
  1085. devres_free(ptr);
  1086. return ret;
  1087. }
  1088. EXPORT_SYMBOL_GPL(devm_iio_device_register);
  1089. /**
  1090. * devm_iio_device_unregister - Resource-managed iio_device_unregister()
  1091. * @dev: Device this iio_dev belongs to
  1092. * @indio_dev: the iio_dev associated with the device
  1093. *
  1094. * Unregister iio_dev registered with devm_iio_device_register().
  1095. */
  1096. void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev)
  1097. {
  1098. int rc;
  1099. rc = devres_release(dev, devm_iio_device_unreg,
  1100. devm_iio_device_match, indio_dev);
  1101. WARN_ON(rc);
  1102. }
  1103. EXPORT_SYMBOL_GPL(devm_iio_device_unregister);
  1104. subsys_initcall(iio_init);
  1105. module_exit(iio_exit);
  1106. MODULE_AUTHOR("Jonathan Cameron <jic23@kernel.org>");
  1107. MODULE_DESCRIPTION("Industrial I/O core");
  1108. MODULE_LICENSE("GPL");