sw_device.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * Industrial I/O software device interface
  3. *
  4. * Copyright (c) 2016 Intel Corporation
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms of the GNU General Public License version 2 as published by
  8. * the Free Software Foundation.
  9. */
  10. #ifndef __IIO_SW_DEVICE
  11. #define __IIO_SW_DEVICE
  12. #include <linux/module.h>
  13. #include <linux/device.h>
  14. #include <linux/iio/iio.h>
  15. #include <linux/configfs.h>
  16. #define module_iio_sw_device_driver(__iio_sw_device_type) \
  17. module_driver(__iio_sw_device_type, iio_register_sw_device_type, \
  18. iio_unregister_sw_device_type)
  19. struct iio_sw_device_ops;
  20. struct iio_sw_device_type {
  21. const char *name;
  22. struct module *owner;
  23. const struct iio_sw_device_ops *ops;
  24. struct list_head list;
  25. struct config_group *group;
  26. };
  27. struct iio_sw_device {
  28. struct iio_dev *device;
  29. struct iio_sw_device_type *device_type;
  30. struct config_group group;
  31. };
  32. struct iio_sw_device_ops {
  33. struct iio_sw_device* (*probe)(const char *);
  34. int (*remove)(struct iio_sw_device *);
  35. };
  36. static inline
  37. struct iio_sw_device *to_iio_sw_device(struct config_item *item)
  38. {
  39. return container_of(to_config_group(item), struct iio_sw_device,
  40. group);
  41. }
  42. int iio_register_sw_device_type(struct iio_sw_device_type *dt);
  43. void iio_unregister_sw_device_type(struct iio_sw_device_type *dt);
  44. struct iio_sw_device *iio_sw_device_create(const char *, const char *);
  45. void iio_sw_device_destroy(struct iio_sw_device *);
  46. int iio_sw_device_type_configfs_register(struct iio_sw_device_type *dt);
  47. void iio_sw_device_type_configfs_unregister(struct iio_sw_device_type *dt);
  48. static inline
  49. void iio_swd_group_init_type_name(struct iio_sw_device *d,
  50. const char *name,
  51. struct config_item_type *type)
  52. {
  53. #if IS_ENABLED(CONFIG_CONFIGFS_FS)
  54. config_group_init_type_name(&d->group, name, type);
  55. #endif
  56. }
  57. #endif /* __IIO_SW_DEVICE */