hci.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. /*
  3. * Copyright (c) 2020, MIPI Alliance, Inc.
  4. *
  5. * Author: Nicolas Pitre <[email protected]>
  6. *
  7. * Common HCI stuff
  8. */
  9. #ifndef HCI_H
  10. #define HCI_H
  11. /* Handy logging macro to save on line length */
  12. #define DBG(x, ...) pr_devel("%s: " x "\n", __func__, ##__VA_ARGS__)
  13. /* 32-bit word aware bit and mask macros */
  14. #define W0_MASK(h, l) GENMASK((h) - 0, (l) - 0)
  15. #define W1_MASK(h, l) GENMASK((h) - 32, (l) - 32)
  16. #define W2_MASK(h, l) GENMASK((h) - 64, (l) - 64)
  17. #define W3_MASK(h, l) GENMASK((h) - 96, (l) - 96)
  18. /* Same for single bit macros (trailing _ to align with W*_MASK width) */
  19. #define W0_BIT_(x) BIT((x) - 0)
  20. #define W1_BIT_(x) BIT((x) - 32)
  21. #define W2_BIT_(x) BIT((x) - 64)
  22. #define W3_BIT_(x) BIT((x) - 96)
  23. struct hci_cmd_ops;
  24. /* Our main structure */
  25. struct i3c_hci {
  26. struct i3c_master_controller master;
  27. void __iomem *base_regs;
  28. void __iomem *DAT_regs;
  29. void __iomem *DCT_regs;
  30. void __iomem *RHS_regs;
  31. void __iomem *PIO_regs;
  32. void __iomem *EXTCAPS_regs;
  33. void __iomem *AUTOCMD_regs;
  34. void __iomem *DEBUG_regs;
  35. const struct hci_io_ops *io;
  36. void *io_data;
  37. const struct hci_cmd_ops *cmd;
  38. atomic_t next_cmd_tid;
  39. u32 caps;
  40. unsigned int quirks;
  41. unsigned int DAT_entries;
  42. unsigned int DAT_entry_size;
  43. void *DAT_data;
  44. unsigned int DCT_entries;
  45. unsigned int DCT_entry_size;
  46. u8 version_major;
  47. u8 version_minor;
  48. u8 revision;
  49. u32 vendor_mipi_id;
  50. u32 vendor_version_id;
  51. u32 vendor_product_id;
  52. void *vendor_data;
  53. };
  54. /*
  55. * Structure to represent a master initiated transfer.
  56. * The rnw, data and data_len fields must be initialized before calling any
  57. * hci->cmd->*() method. The cmd method will initialize cmd_desc[] and
  58. * possibly modify (clear) the data field. Then xfer->cmd_desc[0] can
  59. * be augmented with CMD_0_ROC and/or CMD_0_TOC.
  60. * The completion field needs to be initialized before queueing with
  61. * hci->io->queue_xfer(), and requires CMD_0_ROC to be set.
  62. */
  63. struct hci_xfer {
  64. u32 cmd_desc[4];
  65. u32 response;
  66. bool rnw;
  67. void *data;
  68. unsigned int data_len;
  69. unsigned int cmd_tid;
  70. struct completion *completion;
  71. union {
  72. struct {
  73. /* PIO specific */
  74. struct hci_xfer *next_xfer;
  75. struct hci_xfer *next_data;
  76. struct hci_xfer *next_resp;
  77. unsigned int data_left;
  78. u32 data_word_before_partial;
  79. };
  80. struct {
  81. /* DMA specific */
  82. dma_addr_t data_dma;
  83. int ring_number;
  84. int ring_entry;
  85. };
  86. };
  87. };
  88. static inline struct hci_xfer *hci_alloc_xfer(unsigned int n)
  89. {
  90. return kcalloc(n, sizeof(struct hci_xfer), GFP_KERNEL);
  91. }
  92. static inline void hci_free_xfer(struct hci_xfer *xfer, unsigned int n)
  93. {
  94. kfree(xfer);
  95. }
  96. /* This abstracts PIO vs DMA operations */
  97. struct hci_io_ops {
  98. bool (*irq_handler)(struct i3c_hci *hci, unsigned int mask);
  99. int (*queue_xfer)(struct i3c_hci *hci, struct hci_xfer *xfer, int n);
  100. bool (*dequeue_xfer)(struct i3c_hci *hci, struct hci_xfer *xfer, int n);
  101. int (*request_ibi)(struct i3c_hci *hci, struct i3c_dev_desc *dev,
  102. const struct i3c_ibi_setup *req);
  103. void (*free_ibi)(struct i3c_hci *hci, struct i3c_dev_desc *dev);
  104. void (*recycle_ibi_slot)(struct i3c_hci *hci, struct i3c_dev_desc *dev,
  105. struct i3c_ibi_slot *slot);
  106. int (*init)(struct i3c_hci *hci);
  107. void (*cleanup)(struct i3c_hci *hci);
  108. };
  109. extern const struct hci_io_ops mipi_i3c_hci_pio;
  110. extern const struct hci_io_ops mipi_i3c_hci_dma;
  111. /* Our per device master private data */
  112. struct i3c_hci_dev_data {
  113. int dat_idx;
  114. void *ibi_data;
  115. };
  116. /* list of quirks */
  117. #define HCI_QUIRK_RAW_CCC BIT(1) /* CCC framing must be explicit */
  118. /* global functions */
  119. void mipi_i3c_hci_resume(struct i3c_hci *hci);
  120. void mipi_i3c_hci_pio_reset(struct i3c_hci *hci);
  121. void mipi_i3c_hci_dct_index_reset(struct i3c_hci *hci);
  122. #endif