qmc.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * QMC management
  4. *
  5. * Copyright 2022 CS GROUP France
  6. *
  7. * Author: Herve Codina <herve.codina@bootlin.com>
  8. */
  9. #ifndef __SOC_FSL_QMC_H__
  10. #define __SOC_FSL_QMC_H__
  11. #include <linux/bits.h>
  12. #include <linux/types.h>
  13. struct device_node;
  14. struct device;
  15. struct qmc_chan;
  16. int qmc_chan_count_phandles(struct device_node *np, const char *phandles_name);
  17. struct qmc_chan *qmc_chan_get_byphandles_index(struct device_node *np,
  18. const char *phandles_name,
  19. int index);
  20. struct qmc_chan *devm_qmc_chan_get_byphandles_index(struct device *dev,
  21. struct device_node *np,
  22. const char *phandles_name,
  23. int index);
  24. static inline struct qmc_chan *qmc_chan_get_byphandle(struct device_node *np,
  25. const char *phandle_name)
  26. {
  27. return qmc_chan_get_byphandles_index(np, phandle_name, 0);
  28. }
  29. static inline struct qmc_chan *devm_qmc_chan_get_byphandle(struct device *dev,
  30. struct device_node *np,
  31. const char *phandle_name)
  32. {
  33. return devm_qmc_chan_get_byphandles_index(dev, np, phandle_name, 0);
  34. }
  35. struct qmc_chan *qmc_chan_get_bychild(struct device_node *np);
  36. void qmc_chan_put(struct qmc_chan *chan);
  37. struct qmc_chan *devm_qmc_chan_get_bychild(struct device *dev, struct device_node *np);
  38. enum qmc_mode {
  39. QMC_TRANSPARENT,
  40. QMC_HDLC,
  41. };
  42. struct qmc_chan_info {
  43. enum qmc_mode mode;
  44. unsigned long rx_fs_rate;
  45. unsigned long rx_bit_rate;
  46. u8 nb_rx_ts;
  47. unsigned long tx_fs_rate;
  48. unsigned long tx_bit_rate;
  49. u8 nb_tx_ts;
  50. };
  51. int qmc_chan_get_info(struct qmc_chan *chan, struct qmc_chan_info *info);
  52. struct qmc_chan_ts_info {
  53. u64 rx_ts_mask_avail;
  54. u64 tx_ts_mask_avail;
  55. u64 rx_ts_mask;
  56. u64 tx_ts_mask;
  57. };
  58. int qmc_chan_get_ts_info(struct qmc_chan *chan, struct qmc_chan_ts_info *ts_info);
  59. int qmc_chan_set_ts_info(struct qmc_chan *chan, const struct qmc_chan_ts_info *ts_info);
  60. struct qmc_chan_param {
  61. enum qmc_mode mode;
  62. union {
  63. struct {
  64. u16 max_rx_buf_size;
  65. u16 max_rx_frame_size;
  66. bool is_crc32;
  67. } hdlc;
  68. struct {
  69. u16 max_rx_buf_size;
  70. } transp;
  71. };
  72. };
  73. int qmc_chan_set_param(struct qmc_chan *chan, const struct qmc_chan_param *param);
  74. int qmc_chan_write_submit(struct qmc_chan *chan, dma_addr_t addr, size_t length,
  75. void (*complete)(void *context), void *context);
  76. /* Flags available (ORed) for read complete() flags parameter in HDLC mode.
  77. * No flags are available in transparent mode and the read complete() flags
  78. * parameter has no meaning in transparent mode.
  79. */
  80. #define QMC_RX_FLAG_HDLC_LAST BIT(11) /* Last in frame */
  81. #define QMC_RX_FLAG_HDLC_FIRST BIT(10) /* First in frame */
  82. #define QMC_RX_FLAG_HDLC_OVF BIT(5) /* Data overflow */
  83. #define QMC_RX_FLAG_HDLC_UNA BIT(4) /* Unaligned (ie. bits received not multiple of 8) */
  84. #define QMC_RX_FLAG_HDLC_ABORT BIT(3) /* Received an abort sequence (seven consecutive ones) */
  85. #define QMC_RX_FLAG_HDLC_CRC BIT(2) /* CRC error */
  86. int qmc_chan_read_submit(struct qmc_chan *chan, dma_addr_t addr, size_t length,
  87. void (*complete)(void *context, size_t length,
  88. unsigned int flags),
  89. void *context);
  90. #define QMC_CHAN_READ (1<<0)
  91. #define QMC_CHAN_WRITE (1<<1)
  92. #define QMC_CHAN_ALL (QMC_CHAN_READ | QMC_CHAN_WRITE)
  93. int qmc_chan_start(struct qmc_chan *chan, int direction);
  94. int qmc_chan_stop(struct qmc_chan *chan, int direction);
  95. int qmc_chan_reset(struct qmc_chan *chan, int direction);
  96. #endif /* __SOC_FSL_QMC_H__ */