cpm_uart.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Driver for CPM (SCC/SMC) serial ports
  3. *
  4. * Copyright (C) 2004 Freescale Semiconductor, Inc.
  5. *
  6. * 2006 (c) MontaVista Software, Inc.
  7. * Vitaly Bordug <vbordug@ru.mvista.com>
  8. *
  9. * This file is licensed under the terms of the GNU General Public License
  10. * version 2. This program is licensed "as is" without any warranty of any
  11. * kind, whether express or implied.
  12. *
  13. */
  14. #ifndef CPM_UART_H
  15. #define CPM_UART_H
  16. #include <linux/platform_device.h>
  17. #include <linux/fs_uart_pd.h>
  18. #if defined(CONFIG_CPM2)
  19. #include "cpm_uart_cpm2.h"
  20. #elif defined(CONFIG_8xx)
  21. #include "cpm_uart_cpm1.h"
  22. #endif
  23. #define SERIAL_CPM_MAJOR 204
  24. #define SERIAL_CPM_MINOR 46
  25. #define IS_SMC(pinfo) (pinfo->flags & FLAG_SMC)
  26. #define IS_DISCARDING(pinfo) (pinfo->flags & FLAG_DISCARDING)
  27. #define FLAG_DISCARDING 0x00000004 /* when set, don't discard */
  28. #define FLAG_SMC 0x00000002
  29. #define FLAG_CONSOLE 0x00000001
  30. #define UART_SMC1 fsid_smc1_uart
  31. #define UART_SMC2 fsid_smc2_uart
  32. #define UART_SCC1 fsid_scc1_uart
  33. #define UART_SCC2 fsid_scc2_uart
  34. #define UART_SCC3 fsid_scc3_uart
  35. #define UART_SCC4 fsid_scc4_uart
  36. #define UART_NR fs_uart_nr
  37. #define RX_NUM_FIFO 4
  38. #define RX_BUF_SIZE 32
  39. #define TX_NUM_FIFO 4
  40. #define TX_BUF_SIZE 32
  41. #define SCC_WAIT_CLOSING 100
  42. #define GPIO_CTS 0
  43. #define GPIO_RTS 1
  44. #define GPIO_DCD 2
  45. #define GPIO_DSR 3
  46. #define GPIO_DTR 4
  47. #define GPIO_RI 5
  48. #define NUM_GPIOS (GPIO_RI+1)
  49. struct uart_cpm_port {
  50. struct uart_port port;
  51. u16 rx_nrfifos;
  52. u16 rx_fifosize;
  53. u16 tx_nrfifos;
  54. u16 tx_fifosize;
  55. smc_t __iomem *smcp;
  56. smc_uart_t __iomem *smcup;
  57. scc_t __iomem *sccp;
  58. scc_uart_t __iomem *sccup;
  59. cbd_t __iomem *rx_bd_base;
  60. cbd_t __iomem *rx_cur;
  61. cbd_t __iomem *tx_bd_base;
  62. cbd_t __iomem *tx_cur;
  63. unsigned char *tx_buf;
  64. unsigned char *rx_buf;
  65. u32 flags;
  66. struct clk *clk;
  67. u8 brg;
  68. uint dp_addr;
  69. void *mem_addr;
  70. dma_addr_t dma_addr;
  71. u32 mem_size;
  72. /* wait on close if needed */
  73. int wait_closing;
  74. /* value to combine with opcode to form cpm command */
  75. u32 command;
  76. int gpios[NUM_GPIOS];
  77. };
  78. extern int cpm_uart_nr;
  79. extern struct uart_cpm_port cpm_uart_ports[UART_NR];
  80. /* these are located in their respective files */
  81. void cpm_line_cr_cmd(struct uart_cpm_port *port, int cmd);
  82. void __iomem *cpm_uart_map_pram(struct uart_cpm_port *port,
  83. struct device_node *np);
  84. void cpm_uart_unmap_pram(struct uart_cpm_port *port, void __iomem *pram);
  85. int cpm_uart_init_portdesc(void);
  86. int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con);
  87. void cpm_uart_freebuf(struct uart_cpm_port *pinfo);
  88. void smc1_lineif(struct uart_cpm_port *pinfo);
  89. void smc2_lineif(struct uart_cpm_port *pinfo);
  90. void scc1_lineif(struct uart_cpm_port *pinfo);
  91. void scc2_lineif(struct uart_cpm_port *pinfo);
  92. void scc3_lineif(struct uart_cpm_port *pinfo);
  93. void scc4_lineif(struct uart_cpm_port *pinfo);
  94. /*
  95. virtual to phys transtalion
  96. */
  97. static inline unsigned long cpu2cpm_addr(void *addr,
  98. struct uart_cpm_port *pinfo)
  99. {
  100. int offset;
  101. u32 val = (u32)addr;
  102. u32 mem = (u32)pinfo->mem_addr;
  103. /* sane check */
  104. if (likely(val >= mem && val < mem + pinfo->mem_size)) {
  105. offset = val - mem;
  106. return pinfo->dma_addr + offset;
  107. }
  108. /* something nasty happened */
  109. BUG();
  110. return 0;
  111. }
  112. static inline void *cpm2cpu_addr(unsigned long addr,
  113. struct uart_cpm_port *pinfo)
  114. {
  115. int offset;
  116. u32 val = addr;
  117. u32 dma = (u32)pinfo->dma_addr;
  118. /* sane check */
  119. if (likely(val >= dma && val < dma + pinfo->mem_size)) {
  120. offset = val - dma;
  121. return pinfo->mem_addr + offset;
  122. }
  123. /* something nasty happened */
  124. BUG();
  125. return NULL;
  126. }
  127. #endif /* CPM_UART_H */