sh-sci-common.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __SH_SCI_COMMON_H__
  3. #define __SH_SCI_COMMON_H__
  4. #include <linux/serial_core.h>
  5. /* Private port IDs */
  6. enum SCI_PORT_TYPE {
  7. RSCI_PORT_SCIF16 = BIT(7) | 0,
  8. RSCI_PORT_SCIF32 = BIT(7) | 1,
  9. };
  10. enum SCI_CLKS {
  11. SCI_FCK, /* Functional Clock */
  12. SCI_SCK, /* Optional External Clock */
  13. SCI_BRG_INT, /* Optional BRG Internal Clock Source */
  14. SCI_SCIF_CLK, /* Optional BRG External Clock Source */
  15. SCI_FCK_DIV4, /* Optional Functional Clock frequency-divided by 4 */
  16. SCI_FCK_DIV16, /* Optional Functional Clock frequency-divided by 16 */
  17. SCI_FCK_DIV64, /* Optional Functional Clock frequency-divided by 64 */
  18. SCI_NUM_CLKS
  19. };
  20. /* Offsets into the sci_port->irqs array */
  21. enum {
  22. SCIx_ERI_IRQ,
  23. SCIx_RXI_IRQ,
  24. SCIx_TXI_IRQ,
  25. SCIx_BRI_IRQ,
  26. SCIx_DRI_IRQ,
  27. SCIx_TEI_IRQ,
  28. SCIx_NR_IRQS,
  29. SCIx_MUX_IRQ = SCIx_NR_IRQS, /* special case */
  30. };
  31. /* Bit x set means sampling rate x + 1 is supported */
  32. #define SCI_SR(x) BIT((x) - 1)
  33. #define SCI_SR_RANGE(x, y) GENMASK((y) - 1, (x) - 1)
  34. void sci_release_port(struct uart_port *port);
  35. int sci_request_port(struct uart_port *port);
  36. void sci_config_port(struct uart_port *port, int flags);
  37. int sci_verify_port(struct uart_port *port, struct serial_struct *ser);
  38. void sci_pm(struct uart_port *port, unsigned int state,
  39. unsigned int oldstate);
  40. struct plat_sci_reg {
  41. u8 offset;
  42. u8 size;
  43. };
  44. struct sci_port_params_bits {
  45. unsigned int rxtx_enable;
  46. unsigned int te_clear;
  47. unsigned int poll_sent_bits;
  48. };
  49. struct sci_common_regs {
  50. unsigned int status;
  51. unsigned int control;
  52. };
  53. /* The actual number of needed registers. This is used by sci only */
  54. #define SCI_NR_REGS 20
  55. struct sci_port_params {
  56. const struct plat_sci_reg regs[SCI_NR_REGS];
  57. const struct sci_common_regs *common_regs;
  58. const struct sci_port_params_bits *param_bits;
  59. unsigned int fifosize;
  60. unsigned int overrun_reg;
  61. unsigned int overrun_mask;
  62. unsigned int sampling_rate_mask;
  63. unsigned int error_mask;
  64. unsigned int error_clear;
  65. };
  66. struct sci_port_ops {
  67. u32 (*read_reg)(struct uart_port *port, int reg);
  68. void (*write_reg)(struct uart_port *port, int reg, int value);
  69. void (*clear_SCxSR)(struct uart_port *port, unsigned int mask);
  70. void (*transmit_chars)(struct uart_port *port);
  71. void (*receive_chars)(struct uart_port *port);
  72. void (*poll_put_char)(struct uart_port *port, unsigned char c);
  73. int (*set_rtrg)(struct uart_port *port, int rx_trig);
  74. int (*rtrg_enabled)(struct uart_port *port);
  75. void (*shutdown_complete)(struct uart_port *port);
  76. void (*prepare_console_write)(struct uart_port *port, u32 ctrl);
  77. void (*finish_console_write)(struct uart_port *port, u32 ctrl);
  78. void (*console_save)(struct uart_port *port);
  79. void (*console_restore)(struct uart_port *port);
  80. size_t (*suspend_regs_size)(void);
  81. };
  82. struct sci_of_data {
  83. const struct sci_port_params *params;
  84. const struct uart_ops *uart_ops;
  85. const struct sci_port_ops *ops;
  86. unsigned short regtype;
  87. unsigned short type;
  88. };
  89. struct sci_port {
  90. struct uart_port port;
  91. /* Platform configuration */
  92. const struct sci_port_params *params;
  93. const struct plat_sci_port *cfg;
  94. unsigned int sampling_rate_mask;
  95. resource_size_t reg_size;
  96. struct mctrl_gpios *gpios;
  97. /* Clocks */
  98. struct clk *clks[SCI_NUM_CLKS];
  99. unsigned long clk_rates[SCI_NUM_CLKS];
  100. int irqs[SCIx_NR_IRQS];
  101. char *irqstr[SCIx_NR_IRQS];
  102. struct dma_chan *chan_tx;
  103. struct dma_chan *chan_rx;
  104. struct reset_control *rstc;
  105. struct sci_suspend_regs *suspend_regs;
  106. #ifdef CONFIG_SERIAL_SH_SCI_DMA
  107. struct dma_chan *chan_tx_saved;
  108. struct dma_chan *chan_rx_saved;
  109. dma_cookie_t cookie_tx;
  110. dma_cookie_t cookie_rx[2];
  111. dma_cookie_t active_rx;
  112. dma_addr_t tx_dma_addr;
  113. unsigned int tx_dma_len;
  114. struct scatterlist sg_rx[2];
  115. void *rx_buf[2];
  116. size_t buf_len_rx;
  117. struct work_struct work_tx;
  118. struct hrtimer rx_timer;
  119. unsigned int rx_timeout; /* microseconds */
  120. #endif
  121. unsigned int rx_frame;
  122. int rx_trigger;
  123. struct timer_list rx_fifo_timer;
  124. int rx_fifo_timeout;
  125. u16 hscif_tot;
  126. u8 type;
  127. u8 regtype;
  128. const struct sci_port_ops *ops;
  129. bool has_rtscts;
  130. bool autorts;
  131. bool tx_occurred;
  132. };
  133. #define to_sci_port(uart) container_of((uart), struct sci_port, port)
  134. void sci_port_disable(struct sci_port *sci_port);
  135. void sci_port_enable(struct sci_port *sci_port);
  136. int sci_startup(struct uart_port *port);
  137. void sci_shutdown(struct uart_port *port);
  138. int sci_scbrr_calc(struct sci_port *s, unsigned int bps, unsigned int *brr,
  139. unsigned int *srr, unsigned int *cks);
  140. #define min_sr(_port) ffs((_port)->sampling_rate_mask)
  141. #define max_sr(_port) fls((_port)->sampling_rate_mask)
  142. #ifdef CONFIG_SERIAL_SH_SCI_EARLYCON
  143. int __init scix_early_console_setup(struct earlycon_device *device, const struct sci_of_data *data);
  144. #endif
  145. #endif /* __SH_SCI_COMMON_H__ */