Commit 3feb0797 authored by Jonathan Cameron's avatar Jonathan Cameron Committed by Greg Kroah-Hartman

staging:iio: Buffer device flattening.

Given we now only have one device we don't need the extra layer any more.
Hence this patch removes it.
Signed-off-by: default avatarJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent b9d40a9d
...@@ -106,72 +106,60 @@ static const struct file_operations iio_ring_fileops = { ...@@ -106,72 +106,60 @@ static const struct file_operations iio_ring_fileops = {
.llseek = noop_llseek, .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 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); cdev_del(&buf->access_handler.chrdev);
iio_device_free_chrdev_minor(MINOR(dev->devt)); iio_device_free_chrdev_minor(MINOR(dev->devt));
} }
EXPORT_SYMBOL(iio_ring_access_release);
static struct device_type iio_ring_access_type = {
.release = iio_ring_access_release,
};
static inline int static inline int
__iio_request_ring_buffer_access_chrdev(struct iio_ring_buffer *buf, __iio_request_ring_buffer_chrdev(struct iio_ring_buffer *buf,
int id,
struct module *owner) struct module *owner)
{ {
int ret, minor; int ret, minor;
buf->access_handler.flags = 0; buf->access_handler.flags = 0;
buf->access_dev.parent = &buf->dev; buf->dev.bus = &iio_bus_type;
buf->access_dev.bus = &iio_bus_type; device_initialize(&buf->dev);
buf->access_dev.type = &iio_ring_access_type;
device_initialize(&buf->access_dev);
minor = iio_device_get_chrdev_minor(); minor = iio_device_get_chrdev_minor();
if (minor < 0) { if (minor < 0) {
ret = minor; ret = minor;
goto error_device_put; goto error_device_put;
} }
buf->access_dev.devt = MKDEV(MAJOR(iio_devt), minor); buf->dev.devt = MKDEV(MAJOR(iio_devt), minor);
dev_set_name(&buf->dev, "%s:buffer%d",
dev_name(buf->dev.parent),
buf->access_id = id; buf->id);
ret = device_add(&buf->dev);
dev_set_name(&buf->access_dev, "%s:access%d",
dev_name(&buf->dev),
buf->access_id);
ret = device_add(&buf->access_dev);
if (ret < 0) { 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; goto error_device_put;
} }
cdev_init(&buf->access_handler.chrdev, &iio_ring_fileops); cdev_init(&buf->access_handler.chrdev, &iio_ring_fileops);
buf->access_handler.chrdev.owner = owner; buf->access_handler.chrdev.owner = owner;
ret = cdev_add(&buf->access_handler.chrdev, buf->dev.devt, 1);
ret = cdev_add(&buf->access_handler.chrdev, buf->access_dev.devt, 1);
if (ret) { 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; goto error_device_unregister;
} }
return 0; return 0;
error_device_unregister: error_device_unregister:
device_unregister(&buf->access_dev); device_unregister(&buf->dev);
error_device_put: error_device_put:
put_device(&buf->access_dev); put_device(&buf->dev);
return ret; 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, void iio_ring_buffer_init(struct iio_ring_buffer *ring,
...@@ -344,36 +332,25 @@ int iio_ring_buffer_register_ex(struct iio_ring_buffer *ring, int id, ...@@ -344,36 +332,25 @@ int iio_ring_buffer_register_ex(struct iio_ring_buffer *ring, int id,
ring->id = id; ring->id = id;
dev_set_name(&ring->dev, "%s:buffer%d", ret = __iio_request_ring_buffer_chrdev(ring, ring->owner);
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);
if (ret) if (ret)
goto error_remove_device; goto error_ret;
if (ring->scan_el_attrs) { if (ring->scan_el_attrs) {
ret = sysfs_create_group(&ring->dev.kobj, ret = sysfs_create_group(&ring->dev.kobj,
ring->scan_el_attrs); ring->scan_el_attrs);
if (ret) { if (ret) {
dev_err(&ring->dev, dev_err(&ring->dev,
"Failed to add sysfs scan elements\n"); "Failed to add sysfs scan elements\n");
goto error_free_ring_buffer_access_chrdev; goto error_free_ring_buffer_chrdev;
} }
} else if (channels) { } else if (channels) {
ret = sysfs_create_group(&ring->dev.kobj, ret = sysfs_create_group(&ring->dev.kobj,
&iio_scan_el_dummy_group); &iio_scan_el_dummy_group);
if (ret) 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_dev_attr_list);
INIT_LIST_HEAD(&ring->scan_el_en_attr_list); INIT_LIST_HEAD(&ring->scan_el_en_attr_list);
if (channels) { if (channels) {
...@@ -388,10 +365,8 @@ int iio_ring_buffer_register_ex(struct iio_ring_buffer *ring, int id, ...@@ -388,10 +365,8 @@ int iio_ring_buffer_register_ex(struct iio_ring_buffer *ring, int id,
return 0; return 0;
error_cleanup_dynamic: error_cleanup_dynamic:
__iio_ring_attr_cleanup(ring); __iio_ring_attr_cleanup(ring);
error_free_ring_buffer_access_chrdev: error_free_ring_buffer_chrdev:
__iio_free_ring_buffer_access_chrdev(ring); __iio_free_ring_buffer_chrdev(ring);
error_remove_device:
device_del(&ring->dev);
error_ret: error_ret:
return ret; return ret;
} }
...@@ -406,8 +381,7 @@ EXPORT_SYMBOL(iio_ring_buffer_register); ...@@ -406,8 +381,7 @@ EXPORT_SYMBOL(iio_ring_buffer_register);
void iio_ring_buffer_unregister(struct iio_ring_buffer *ring) void iio_ring_buffer_unregister(struct iio_ring_buffer *ring)
{ {
__iio_ring_attr_cleanup(ring); __iio_ring_attr_cleanup(ring);
__iio_free_ring_buffer_access_chrdev(ring); __iio_free_ring_buffer_chrdev(ring);
device_del(&ring->dev);
} }
EXPORT_SYMBOL(iio_ring_buffer_unregister); EXPORT_SYMBOL(iio_ring_buffer_unregister);
......
...@@ -68,11 +68,9 @@ struct iio_ring_access_funcs { ...@@ -68,11 +68,9 @@ struct iio_ring_access_funcs {
/** /**
* struct iio_ring_buffer - general ring buffer structure * struct iio_ring_buffer - general ring buffer structure
* @dev: ring buffer device struct * @dev: ring buffer device struct
* @access_dev: system device struct for the chrdev
* @indio_dev: industrial I/O device structure * @indio_dev: industrial I/O device structure
* @owner: module that owns the ring buffer (for ref counting) * @owner: module that owns the ring buffer (for ref counting)
* @id: unique id number * @id: unique id number
* @access_id: device id number
* @length: [DEVICE] number of datums in ring * @length: [DEVICE] number of datums in ring
* @bytes_per_datum: [DEVICE] size of individual datum including timestamp * @bytes_per_datum: [DEVICE] size of individual datum including timestamp
* @bpe: [DEVICE] size of individual channel value * @bpe: [DEVICE] size of individual channel value
...@@ -92,11 +90,9 @@ struct iio_ring_access_funcs { ...@@ -92,11 +90,9 @@ struct iio_ring_access_funcs {
**/ **/
struct iio_ring_buffer { struct iio_ring_buffer {
struct device dev; struct device dev;
struct device access_dev;
struct iio_dev *indio_dev; struct iio_dev *indio_dev;
struct module *owner; struct module *owner;
int id; int id;
int access_id;
int length; int length;
int bytes_per_datum; int bytes_per_datum;
int bpe; int bpe;
...@@ -398,8 +394,6 @@ static inline void iio_put_ring_buffer(struct iio_ring_buffer *ring) ...@@ -398,8 +394,6 @@ static inline void iio_put_ring_buffer(struct iio_ring_buffer *ring)
#define to_iio_ring_buffer(d) \ #define to_iio_ring_buffer(d) \
container_of(d, struct iio_ring_buffer, dev) 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 * iio_ring_buffer_register() - register the buffer with IIO core
...@@ -416,6 +410,8 @@ int iio_ring_buffer_register_ex(struct iio_ring_buffer *ring, int id, ...@@ -416,6 +410,8 @@ int iio_ring_buffer_register_ex(struct iio_ring_buffer *ring, int id,
const struct iio_chan_spec *channels, const struct iio_chan_spec *channels,
int num_channels); int num_channels);
void iio_ring_access_release(struct device *dev);
/** /**
* iio_ring_buffer_unregister() - unregister the buffer from IIO core * iio_ring_buffer_unregister() - unregister the buffer from IIO core
* @ring: the buffer to be unregistered * @ring: the buffer to be unregistered
......
...@@ -375,6 +375,7 @@ EXPORT_SYMBOL(iio_mark_update_needed_sw_rb); ...@@ -375,6 +375,7 @@ EXPORT_SYMBOL(iio_mark_update_needed_sw_rb);
static void iio_sw_rb_release(struct device *dev) static void iio_sw_rb_release(struct device *dev)
{ {
struct iio_ring_buffer *r = to_iio_ring_buffer(dev); struct iio_ring_buffer *r = to_iio_ring_buffer(dev);
iio_ring_access_release(&r->dev);
kfree(iio_to_sw_ring(r)); kfree(iio_to_sw_ring(r));
} }
...@@ -416,9 +417,7 @@ struct iio_ring_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev) ...@@ -416,9 +417,7 @@ struct iio_ring_buffer *iio_sw_rb_allocate(struct iio_dev *indio_dev)
iio_ring_buffer_init(buf, indio_dev); iio_ring_buffer_init(buf, indio_dev);
__iio_init_sw_ring_buffer(ring); __iio_init_sw_ring_buffer(ring);
buf->dev.type = &iio_sw_ring_type; buf->dev.type = &iio_sw_ring_type;
device_initialize(&buf->dev);
buf->dev.parent = &indio_dev->dev; buf->dev.parent = &indio_dev->dev;
buf->dev.bus = &iio_bus_type;
dev_set_drvdata(&buf->dev, (void *)buf); dev_set_drvdata(&buf->dev, (void *)buf);
return buf; return buf;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment