.llseek = noop_llseek,
};
-static void iio_ring_access_release(struct device *dev)
+void iio_ring_access_release(struct device *dev)
{
struct iio_ring_buffer *buf
- = access_dev_to_iio_ring_buffer(dev);
+ = container_of(dev, struct iio_ring_buffer, dev);
cdev_del(&buf->access_handler.chrdev);
iio_device_free_chrdev_minor(MINOR(dev->devt));
}
-
-static struct device_type iio_ring_access_type = {
- .release = iio_ring_access_release,
-};
+EXPORT_SYMBOL(iio_ring_access_release);
static inline int
-__iio_request_ring_buffer_access_chrdev(struct iio_ring_buffer *buf,
- int id,
+__iio_request_ring_buffer_chrdev(struct iio_ring_buffer *buf,
struct module *owner)
{
int ret, minor;
buf->access_handler.flags = 0;
- buf->access_dev.parent = &buf->dev;
- buf->access_dev.bus = &iio_bus_type;
- buf->access_dev.type = &iio_ring_access_type;
- device_initialize(&buf->access_dev);
+ buf->dev.bus = &iio_bus_type;
+ device_initialize(&buf->dev);
minor = iio_device_get_chrdev_minor();
if (minor < 0) {
ret = minor;
goto error_device_put;
}
- buf->access_dev.devt = MKDEV(MAJOR(iio_devt), minor);
-
-
- buf->access_id = id;
-
- dev_set_name(&buf->access_dev, "%s:access%d",
- dev_name(&buf->dev),
- buf->access_id);
- ret = device_add(&buf->access_dev);
+ buf->dev.devt = MKDEV(MAJOR(iio_devt), minor);
+ dev_set_name(&buf->dev, "%s:buffer%d",
+ dev_name(buf->dev.parent),
+ buf->id);
+ ret = device_add(&buf->dev);
if (ret < 0) {
- printk(KERN_ERR "failed to add the ring access dev\n");
+ printk(KERN_ERR "failed to add the ring dev\n");
goto error_device_put;
}
-
cdev_init(&buf->access_handler.chrdev, &iio_ring_fileops);
buf->access_handler.chrdev.owner = owner;
-
- ret = cdev_add(&buf->access_handler.chrdev, buf->access_dev.devt, 1);
+ ret = cdev_add(&buf->access_handler.chrdev, buf->dev.devt, 1);
if (ret) {
- printk(KERN_ERR "failed to allocate ring access chrdev\n");
+ printk(KERN_ERR "failed to allocate ring chrdev\n");
goto error_device_unregister;
}
return 0;
error_device_unregister:
- device_unregister(&buf->access_dev);
+ device_unregister(&buf->dev);
error_device_put:
- put_device(&buf->access_dev);
+ put_device(&buf->dev);
return ret;
}
-static void __iio_free_ring_buffer_access_chrdev(struct iio_ring_buffer *buf)
+static void __iio_free_ring_buffer_chrdev(struct iio_ring_buffer *buf)
{
- device_unregister(&buf->access_dev);
+ device_unregister(&buf->dev);
}
void iio_ring_buffer_init(struct iio_ring_buffer *ring,
ring->id = id;
- dev_set_name(&ring->dev, "%s:buffer%d",
- dev_name(ring->dev.parent),
- ring->id);
- ret = device_add(&ring->dev);
- if (ret)
- goto error_ret;
-
- ret = __iio_request_ring_buffer_access_chrdev(ring,
- 0,
- ring->owner);
+ ret = __iio_request_ring_buffer_chrdev(ring, ring->owner);
if (ret)
- goto error_remove_device;
-
+ goto error_ret;
if (ring->scan_el_attrs) {
ret = sysfs_create_group(&ring->dev.kobj,
ring->scan_el_attrs);
if (ret) {
dev_err(&ring->dev,
"Failed to add sysfs scan elements\n");
- goto error_free_ring_buffer_access_chrdev;
+ goto error_free_ring_buffer_chrdev;
}
} else if (channels) {
ret = sysfs_create_group(&ring->dev.kobj,
&iio_scan_el_dummy_group);
if (ret)
- goto error_free_ring_buffer_access_chrdev;
+ goto error_free_ring_buffer_chrdev;
}
-
INIT_LIST_HEAD(&ring->scan_el_dev_attr_list);
INIT_LIST_HEAD(&ring->scan_el_en_attr_list);
if (channels) {
return 0;
error_cleanup_dynamic:
__iio_ring_attr_cleanup(ring);
-error_free_ring_buffer_access_chrdev:
- __iio_free_ring_buffer_access_chrdev(ring);
-error_remove_device:
- device_del(&ring->dev);
+error_free_ring_buffer_chrdev:
+ __iio_free_ring_buffer_chrdev(ring);
error_ret:
return ret;
}
void iio_ring_buffer_unregister(struct iio_ring_buffer *ring)
{
__iio_ring_attr_cleanup(ring);
- __iio_free_ring_buffer_access_chrdev(ring);
- device_del(&ring->dev);
+ __iio_free_ring_buffer_chrdev(ring);
}
EXPORT_SYMBOL(iio_ring_buffer_unregister);
/**
* struct iio_ring_buffer - general ring buffer structure
* @dev: ring buffer device struct
- * @access_dev: system device struct for the chrdev
* @indio_dev: industrial I/O device structure
* @owner: module that owns the ring buffer (for ref counting)
* @id: unique id number
- * @access_id: device id number
* @length: [DEVICE] number of datums in ring
* @bytes_per_datum: [DEVICE] size of individual datum including timestamp
* @bpe: [DEVICE] size of individual channel value
**/
struct iio_ring_buffer {
struct device dev;
- struct device access_dev;
struct iio_dev *indio_dev;
struct module *owner;
int id;
- int access_id;
int length;
int bytes_per_datum;
int bpe;
#define to_iio_ring_buffer(d) \
container_of(d, struct iio_ring_buffer, dev)
-#define access_dev_to_iio_ring_buffer(d) \
- container_of(d, struct iio_ring_buffer, access_dev)
/**
* iio_ring_buffer_register() - register the buffer with IIO core
const struct iio_chan_spec *channels,
int num_channels);
+void iio_ring_access_release(struct device *dev);
+
/**
* iio_ring_buffer_unregister() - unregister the buffer from IIO core
* @ring: the buffer to be unregistered