omap_ssi.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /* OMAP SSI internal interface.
  3. *
  4. * Copyright (C) 2010 Nokia Corporation. All rights reserved.
  5. * Copyright (C) 2013 Sebastian Reichel
  6. *
  7. * Contact: Carlos Chinea <[email protected]>
  8. */
  9. #ifndef __LINUX_HSI_OMAP_SSI_H__
  10. #define __LINUX_HSI_OMAP_SSI_H__
  11. #include <linux/device.h>
  12. #include <linux/module.h>
  13. #include <linux/platform_device.h>
  14. #include <linux/hsi/hsi.h>
  15. #include <linux/gpio/consumer.h>
  16. #include <linux/interrupt.h>
  17. #include <linux/io.h>
  18. #define SSI_MAX_CHANNELS 8
  19. #define SSI_MAX_GDD_LCH 8
  20. #define SSI_BYTES_TO_FRAMES(x) ((((x) - 1) >> 2) + 1)
  21. #define SSI_WAKE_EN 0
  22. /**
  23. * struct omap_ssm_ctx - OMAP synchronous serial module (TX/RX) context
  24. * @mode: Bit transmission mode
  25. * @channels: Number of channels
  26. * @framesize: Frame size in bits
  27. * @timeout: RX frame timeout
  28. * @divisor: TX divider
  29. * @arb_mode: Arbitration mode for TX frame (Round robin, priority)
  30. */
  31. struct omap_ssm_ctx {
  32. u32 mode;
  33. u32 channels;
  34. u32 frame_size;
  35. union {
  36. u32 timeout; /* Rx Only */
  37. struct {
  38. u32 arb_mode;
  39. u32 divisor;
  40. }; /* Tx only */
  41. };
  42. };
  43. /**
  44. * struct omap_ssi_port - OMAP SSI port data
  45. * @dev: device associated to the port (HSI port)
  46. * @pdev: platform device associated to the port
  47. * @sst_dma: SSI transmitter physical base address
  48. * @ssr_dma: SSI receiver physical base address
  49. * @sst_base: SSI transmitter base address
  50. * @ssr_base: SSI receiver base address
  51. * @wk_lock: spin lock to serialize access to the wake lines
  52. * @lock: Spin lock to serialize access to the SSI port
  53. * @channels: Current number of channels configured (1,2,4 or 8)
  54. * @txqueue: TX message queues
  55. * @rxqueue: RX message queues
  56. * @brkqueue: Queue of incoming HWBREAK requests (FRAME mode)
  57. * @errqueue: Queue for failed messages
  58. * @errqueue_work: Delayed Work for failed messages
  59. * @irq: IRQ number
  60. * @wake_irq: IRQ number for incoming wake line (-1 if none)
  61. * @wake_gpio: GPIO number for incoming wake line (-1 if none)
  62. * @flags: flags to keep track of states
  63. * @wk_refcount: Reference count for output wake line
  64. * @work: worker for starting TX
  65. * @sys_mpu_enable: Context for the interrupt enable register for irq 0
  66. * @sst: Context for the synchronous serial transmitter
  67. * @ssr: Context for the synchronous serial receiver
  68. */
  69. struct omap_ssi_port {
  70. struct device *dev;
  71. struct device *pdev;
  72. dma_addr_t sst_dma;
  73. dma_addr_t ssr_dma;
  74. void __iomem *sst_base;
  75. void __iomem *ssr_base;
  76. spinlock_t wk_lock;
  77. spinlock_t lock;
  78. unsigned int channels;
  79. struct list_head txqueue[SSI_MAX_CHANNELS];
  80. struct list_head rxqueue[SSI_MAX_CHANNELS];
  81. struct list_head brkqueue;
  82. struct list_head errqueue;
  83. struct delayed_work errqueue_work;
  84. unsigned int irq;
  85. int wake_irq;
  86. struct gpio_desc *wake_gpio;
  87. bool wktest:1; /* FIXME: HACK to be removed */
  88. unsigned long flags;
  89. unsigned int wk_refcount;
  90. struct work_struct work;
  91. /* OMAP SSI port context */
  92. u32 sys_mpu_enable; /* We use only one irq */
  93. struct omap_ssm_ctx sst;
  94. struct omap_ssm_ctx ssr;
  95. u32 loss_count;
  96. u32 port_id;
  97. #ifdef CONFIG_DEBUG_FS
  98. struct dentry *dir;
  99. #endif
  100. };
  101. /**
  102. * struct gdd_trn - GDD transaction data
  103. * @msg: Pointer to the HSI message being served
  104. * @sg: Pointer to the current sg entry being served
  105. */
  106. struct gdd_trn {
  107. struct hsi_msg *msg;
  108. struct scatterlist *sg;
  109. };
  110. /**
  111. * struct omap_ssi_controller - OMAP SSI controller data
  112. * @dev: device associated to the controller (HSI controller)
  113. * @sys: SSI I/O base address
  114. * @gdd: GDD I/O base address
  115. * @fck: SSI functional clock
  116. * @gdd_irq: IRQ line for GDD
  117. * @gdd_tasklet: bottom half for DMA transfers
  118. * @gdd_trn: Array of GDD transaction data for ongoing GDD transfers
  119. * @lock: lock to serialize access to GDD
  120. * @fck_nb: DVFS notfifier block
  121. * @fck_rate: clock rate
  122. * @loss_count: To follow if we need to restore context or not
  123. * @max_speed: Maximum TX speed (Kb/s) set by the clients.
  124. * @gdd_gcr: SSI GDD saved context
  125. * @get_loss: Pointer to omap_pm_get_dev_context_loss_count, if any
  126. * @port: Array of pointers of the ports of the controller
  127. * @dir: Debugfs SSI root directory
  128. */
  129. struct omap_ssi_controller {
  130. struct device *dev;
  131. void __iomem *sys;
  132. void __iomem *gdd;
  133. struct clk *fck;
  134. unsigned int gdd_irq;
  135. struct tasklet_struct gdd_tasklet;
  136. struct gdd_trn gdd_trn[SSI_MAX_GDD_LCH];
  137. spinlock_t lock;
  138. struct notifier_block fck_nb;
  139. unsigned long fck_rate;
  140. u32 loss_count;
  141. u32 max_speed;
  142. /* OMAP SSI Controller context */
  143. u32 gdd_gcr;
  144. int (*get_loss)(struct device *dev);
  145. struct omap_ssi_port **port;
  146. #ifdef CONFIG_DEBUG_FS
  147. struct dentry *dir;
  148. #endif
  149. };
  150. void omap_ssi_port_update_fclk(struct hsi_controller *ssi,
  151. struct omap_ssi_port *omap_port);
  152. extern struct platform_driver ssi_port_pdriver;
  153. #endif /* __LINUX_HSI_OMAP_SSI_H__ */