omap_ssi.h 5.3 KB

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