ssp_iio_ring.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. /*
  2. * Copyright (C) 2011, Samsung Electronics Co. Ltd. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  16. #include <linux/module.h>
  17. #include <linux/init.h>
  18. #include <linux/slab.h>
  19. #include <linux/i2c.h>
  20. #include <linux/err.h>
  21. #include <linux/delay.h>
  22. #include <linux/sysfs.h>
  23. #include <linux/jiffies.h>
  24. #include <linux/irq.h>
  25. #include <linux/interrupt.h>
  26. #include <linux/kfifo.h>
  27. #include <linux/poll.h>
  28. #include <linux/miscdevice.h>
  29. #include "ssp.h"
  30. #include "../../staging/iio/iio.h"
  31. #include "../../staging/iio/kfifo_buf.h"
  32. #include "../../staging/iio/trigger_consumer.h"
  33. #include "../../staging/iio/sysfs.h"
  34. void ssp_iio_unconfigure_ring(struct iio_dev *indio_dev)
  35. {
  36. iio_kfifo_free(indio_dev->buffer);
  37. };
  38. static int ssp_predisable(struct iio_dev *indio_dev)
  39. {
  40. /* sch0317 need to implement
  41. struct inv_mpu_state *st = iio_priv(indio_dev);
  42. int result;
  43. if (st->chip_config.enable) {
  44. result = set_inv_enable(indio_dev, false);
  45. if (result)
  46. return result;
  47. result = st->set_power_state(st, false);
  48. if (result)
  49. return result;
  50. }
  51. */
  52. return 0;
  53. }
  54. static int ssp_preenable(struct iio_dev *indio_dev)
  55. {
  56. int result;
  57. //result = inv_check_conflict_sysfs(indio_dev);
  58. //if (result)
  59. // return result;
  60. result = iio_sw_buffer_preenable(indio_dev);
  61. return result;
  62. }
  63. static const struct iio_buffer_setup_ops ssp_iio_ring_setup_ops = {
  64. .preenable = &ssp_preenable,
  65. .predisable = &ssp_predisable,
  66. };
  67. int ssp_iio_configure_ring(struct iio_dev *indio_dev)
  68. {
  69. struct iio_buffer *ring;
  70. ring = iio_kfifo_allocate(indio_dev);
  71. if (!ring)
  72. return -ENOMEM;
  73. ring->bytes_per_datum = 8;
  74. indio_dev->buffer = ring;
  75. /* setup ring buffer */
  76. ring->scan_timestamp = true;
  77. indio_dev->setup_ops = &ssp_iio_ring_setup_ops;
  78. /*scan count double count timestamp. should subtract 1. but
  79. number of channels still includes timestamp*/
  80. indio_dev->modes |= INDIO_BUFFER_HARDWARE; // INDIO_BUFFER_TRIGGERED
  81. return 0;
  82. }