Merge tag 'iio-for-5.8a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio...
[linux-2.6-microblaze.git] / drivers / iio / industrialio-core.c
index eac63c1..6add449 100644 (file)
@@ -189,7 +189,12 @@ ssize_t iio_read_const_attr(struct device *dev,
 }
 EXPORT_SYMBOL(iio_read_const_attr);
 
-static int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)
+/**
+ * iio_device_set_clock() - Set current timestamping clock for the device
+ * @indio_dev: IIO device structure containing the device
+ * @clock_id: timestamping clock posix identifier to set.
+ */
+int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)
 {
        int ret;
        const struct iio_event_interface *ev_int = indio_dev->event_interface;
@@ -207,6 +212,7 @@ static int iio_device_set_clock(struct iio_dev *indio_dev, clockid_t clock_id)
 
        return 0;
 }
+EXPORT_SYMBOL(iio_device_set_clock);
 
 /**
  * iio_get_time_ns() - utility function to get a time stamp for events etc
@@ -566,46 +572,46 @@ static ssize_t __iio_format_value(char *buf, size_t len, unsigned int type,
 
        switch (type) {
        case IIO_VAL_INT:
-               return snprintf(buf, len, "%d", vals[0]);
+               return scnprintf(buf, len, "%d", vals[0]);
        case IIO_VAL_INT_PLUS_MICRO_DB:
                scale_db = true;
                /* fall through */
        case IIO_VAL_INT_PLUS_MICRO:
                if (vals[1] < 0)
-                       return snprintf(buf, len, "-%d.%06u%s", abs(vals[0]),
+                       return scnprintf(buf, len, "-%d.%06u%s", abs(vals[0]),
                                        -vals[1], scale_db ? " dB" : "");
                else
-                       return snprintf(buf, len, "%d.%06u%s", vals[0], vals[1],
+                       return scnprintf(buf, len, "%d.%06u%s", vals[0], vals[1],
                                        scale_db ? " dB" : "");
        case IIO_VAL_INT_PLUS_NANO:
                if (vals[1] < 0)
-                       return snprintf(buf, len, "-%d.%09u", abs(vals[0]),
+                       return scnprintf(buf, len, "-%d.%09u", abs(vals[0]),
                                        -vals[1]);
                else
-                       return snprintf(buf, len, "%d.%09u", vals[0], vals[1]);
+                       return scnprintf(buf, len, "%d.%09u", vals[0], vals[1]);
        case IIO_VAL_FRACTIONAL:
                tmp = div_s64((s64)vals[0] * 1000000000LL, vals[1]);
                tmp1 = vals[1];
                tmp0 = (int)div_s64_rem(tmp, 1000000000, &tmp1);
-               return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
+               return scnprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
        case IIO_VAL_FRACTIONAL_LOG2:
                tmp = shift_right((s64)vals[0] * 1000000000LL, vals[1]);
                tmp0 = (int)div_s64_rem(tmp, 1000000000LL, &tmp1);
-               return snprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
+               return scnprintf(buf, len, "%d.%09u", tmp0, abs(tmp1));
        case IIO_VAL_INT_MULTIPLE:
        {
                int i;
                int l = 0;
 
                for (i = 0; i < size; ++i) {
-                       l += snprintf(&buf[l], len - l, "%d ", vals[i]);
+                       l += scnprintf(&buf[l], len - l, "%d ", vals[i]);
                        if (l >= len)
                                break;
                }
                return l;
        }
        case IIO_VAL_CHAR:
-               return snprintf(buf, len, "%c", (char)vals[0]);
+               return scnprintf(buf, len, "%c", (char)vals[0]);
        default:
                return 0;
        }
@@ -676,10 +682,10 @@ static ssize_t iio_format_avail_list(char *buf, const int *vals,
                        if (len >= PAGE_SIZE)
                                return -EFBIG;
                        if (i < length - 1)
-                               len += snprintf(buf + len, PAGE_SIZE - len,
+                               len += scnprintf(buf + len, PAGE_SIZE - len,
                                                " ");
                        else
-                               len += snprintf(buf + len, PAGE_SIZE - len,
+                               len += scnprintf(buf + len, PAGE_SIZE - len,
                                                "\n");
                        if (len >= PAGE_SIZE)
                                return -EFBIG;
@@ -692,10 +698,10 @@ static ssize_t iio_format_avail_list(char *buf, const int *vals,
                        if (len >= PAGE_SIZE)
                                return -EFBIG;
                        if (i < length / 2 - 1)
-                               len += snprintf(buf + len, PAGE_SIZE - len,
+                               len += scnprintf(buf + len, PAGE_SIZE - len,
                                                " ");
                        else
-                               len += snprintf(buf + len, PAGE_SIZE - len,
+                               len += scnprintf(buf + len, PAGE_SIZE - len,
                                                "\n");
                        if (len >= PAGE_SIZE)
                                return -EFBIG;
@@ -719,10 +725,10 @@ static ssize_t iio_format_avail_range(char *buf, const int *vals, int type)
                        if (len >= PAGE_SIZE)
                                return -EFBIG;
                        if (i < 2)
-                               len += snprintf(buf + len, PAGE_SIZE - len,
+                               len += scnprintf(buf + len, PAGE_SIZE - len,
                                                " ");
                        else
-                               len += snprintf(buf + len, PAGE_SIZE - len,
+                               len += scnprintf(buf + len, PAGE_SIZE - len,
                                                "]\n");
                        if (len >= PAGE_SIZE)
                                return -EFBIG;
@@ -735,10 +741,10 @@ static ssize_t iio_format_avail_range(char *buf, const int *vals, int type)
                        if (len >= PAGE_SIZE)
                                return -EFBIG;
                        if (i < 2)
-                               len += snprintf(buf + len, PAGE_SIZE - len,
+                               len += scnprintf(buf + len, PAGE_SIZE - len,
                                                " ");
                        else
-                               len += snprintf(buf + len, PAGE_SIZE - len,
+                               len += scnprintf(buf + len, PAGE_SIZE - len,
                                                "]\n");
                        if (len >= PAGE_SIZE)
                                return -EFBIG;
@@ -1546,17 +1552,6 @@ static void devm_iio_device_release(struct device *dev, void *res)
        iio_device_free(*(struct iio_dev **)res);
 }
 
-int devm_iio_device_match(struct device *dev, void *res, void *data)
-{
-       struct iio_dev **r = res;
-       if (!r || !*r) {
-               WARN_ON(!r || !*r);
-               return 0;
-       }
-       return *r == data;
-}
-EXPORT_SYMBOL_GPL(devm_iio_device_match);
-
 /**
  * devm_iio_device_alloc - Resource-managed iio_device_alloc()
  * @dev:               Device to allocate iio_dev for
@@ -1565,9 +1560,6 @@ EXPORT_SYMBOL_GPL(devm_iio_device_match);
  * Managed iio_device_alloc. iio_dev allocated with this function is
  * automatically freed on driver detach.
  *
- * If an iio_dev allocated with this function needs to be freed separately,
- * devm_iio_device_free() must be used.
- *
  * RETURNS:
  * Pointer to allocated iio_dev on success, NULL on failure.
  */
@@ -1592,23 +1584,6 @@ struct iio_dev *devm_iio_device_alloc(struct device *dev, int sizeof_priv)
 }
 EXPORT_SYMBOL_GPL(devm_iio_device_alloc);
 
-/**
- * devm_iio_device_free - Resource-managed iio_device_free()
- * @dev:               Device this iio_dev belongs to
- * @iio_dev:           the iio_dev associated with the device
- *
- * Free iio_dev allocated with devm_iio_device_alloc().
- */
-void devm_iio_device_free(struct device *dev, struct iio_dev *iio_dev)
-{
-       int rc;
-
-       rc = devres_release(dev, devm_iio_device_release,
-                           devm_iio_device_match, iio_dev);
-       WARN_ON(rc);
-}
-EXPORT_SYMBOL_GPL(devm_iio_device_free);
-
 /**
  * iio_chrdev_open() - chrdev file open for buffer access and ioctls
  * @inode:     Inode structure for identifying the device in the file system
@@ -1711,6 +1686,9 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
 {
        int ret;
 
+       if (!indio_dev->info)
+               return -EINVAL;
+
        indio_dev->driver_module = this_mod;
        /* If the calling driver did not initialize of_node, do it here */
        if (!indio_dev->dev.of_node && indio_dev->dev.parent)
@@ -1723,9 +1701,6 @@ int __iio_device_register(struct iio_dev *indio_dev, struct module *this_mod)
        if (ret < 0)
                return ret;
 
-       if (!indio_dev->info)
-               return -EINVAL;
-
        /* configure elements for the chrdev */
        indio_dev->dev.devt = MKDEV(MAJOR(iio_devt), indio_dev->id);
 
@@ -1830,23 +1805,6 @@ int __devm_iio_device_register(struct device *dev, struct iio_dev *indio_dev,
 }
 EXPORT_SYMBOL_GPL(__devm_iio_device_register);
 
-/**
- * devm_iio_device_unregister - Resource-managed iio_device_unregister()
- * @dev:       Device this iio_dev belongs to
- * @indio_dev: the iio_dev associated with the device
- *
- * Unregister iio_dev registered with devm_iio_device_register().
- */
-void devm_iio_device_unregister(struct device *dev, struct iio_dev *indio_dev)
-{
-       int rc;
-
-       rc = devres_release(dev, devm_iio_device_unreg,
-                           devm_iio_device_match, indio_dev);
-       WARN_ON(rc);
-}
-EXPORT_SYMBOL_GPL(devm_iio_device_unregister);
-
 /**
  * iio_device_claim_direct_mode - Keep device in direct mode
  * @indio_dev: the iio_dev associated with the device