cpm_uart_cpm1.c 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /*
  2. * linux/drivers/serial/cpm_uart.c
  3. *
  4. * Driver for CPM (SCC/SMC) serial ports; CPM1 definitions
  5. *
  6. * Maintainer: Kumar Gala (galak@kernel.crashing.org) (CPM2)
  7. * Pantelis Antoniou (panto@intracom.gr) (CPM1)
  8. *
  9. * Copyright (C) 2004 Freescale Semiconductor, Inc.
  10. * (C) 2004 Intracom, S.A.
  11. * (C) 2006 MontaVista Software, Inc.
  12. * Vitaly Bordug <vbordug@ru.mvista.com>
  13. *
  14. * This program is free software; you can redistribute it and/or modify
  15. * it under the terms of the GNU General Public License as published by
  16. * the Free Software Foundation; either version 2 of the License, or
  17. * (at your option) any later version.
  18. *
  19. * This program is distributed in the hope that it will be useful,
  20. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22. * GNU General Public License for more details.
  23. *
  24. * You should have received a copy of the GNU General Public License
  25. * along with this program; if not, write to the Free Software
  26. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27. *
  28. */
  29. #include <linux/module.h>
  30. #include <linux/tty.h>
  31. #include <linux/ioport.h>
  32. #include <linux/init.h>
  33. #include <linux/serial.h>
  34. #include <linux/console.h>
  35. #include <linux/sysrq.h>
  36. #include <linux/device.h>
  37. #include <linux/bootmem.h>
  38. #include <linux/dma-mapping.h>
  39. #include <asm/io.h>
  40. #include <asm/irq.h>
  41. #include <linux/serial_core.h>
  42. #include <linux/kernel.h>
  43. #include "cpm_uart.h"
  44. /**************************************************************/
  45. void cpm_line_cr_cmd(int line, int cmd)
  46. {
  47. ushort val;
  48. volatile cpm8xx_t *cp = cpmp;
  49. switch (line) {
  50. case UART_SMC1:
  51. val = mk_cr_cmd(CPM_CR_CH_SMC1, cmd) | CPM_CR_FLG;
  52. break;
  53. case UART_SMC2:
  54. val = mk_cr_cmd(CPM_CR_CH_SMC2, cmd) | CPM_CR_FLG;
  55. break;
  56. case UART_SCC1:
  57. val = mk_cr_cmd(CPM_CR_CH_SCC1, cmd) | CPM_CR_FLG;
  58. break;
  59. case UART_SCC2:
  60. val = mk_cr_cmd(CPM_CR_CH_SCC2, cmd) | CPM_CR_FLG;
  61. break;
  62. case UART_SCC3:
  63. val = mk_cr_cmd(CPM_CR_CH_SCC3, cmd) | CPM_CR_FLG;
  64. break;
  65. case UART_SCC4:
  66. val = mk_cr_cmd(CPM_CR_CH_SCC4, cmd) | CPM_CR_FLG;
  67. break;
  68. default:
  69. return;
  70. }
  71. cp->cp_cpcr = val;
  72. while (cp->cp_cpcr & CPM_CR_FLG) ;
  73. }
  74. void smc1_lineif(struct uart_cpm_port *pinfo)
  75. {
  76. pinfo->brg = 1;
  77. }
  78. void smc2_lineif(struct uart_cpm_port *pinfo)
  79. {
  80. pinfo->brg = 2;
  81. }
  82. void scc1_lineif(struct uart_cpm_port *pinfo)
  83. {
  84. /* XXX SCC1: insert port configuration here */
  85. pinfo->brg = 1;
  86. }
  87. void scc2_lineif(struct uart_cpm_port *pinfo)
  88. {
  89. /* XXX SCC2: insert port configuration here */
  90. pinfo->brg = 2;
  91. }
  92. void scc3_lineif(struct uart_cpm_port *pinfo)
  93. {
  94. /* XXX SCC3: insert port configuration here */
  95. pinfo->brg = 3;
  96. }
  97. void scc4_lineif(struct uart_cpm_port *pinfo)
  98. {
  99. /* XXX SCC4: insert port configuration here */
  100. pinfo->brg = 4;
  101. }
  102. /*
  103. * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
  104. * receive buffer descriptors from dual port ram, and a character
  105. * buffer area from host mem. If we are allocating for the console we need
  106. * to do it from bootmem
  107. */
  108. int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
  109. {
  110. int dpmemsz, memsz;
  111. u8 *dp_mem;
  112. uint dp_offset;
  113. u8 *mem_addr;
  114. dma_addr_t dma_addr = 0;
  115. pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
  116. dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
  117. dp_offset = cpm_dpalloc(dpmemsz, 8);
  118. if (IS_DPERR(dp_offset)) {
  119. printk(KERN_ERR
  120. "cpm_uart_cpm1.c: could not allocate buffer descriptors\n");
  121. return -ENOMEM;
  122. }
  123. dp_mem = cpm_dpram_addr(dp_offset);
  124. memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
  125. L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
  126. if (is_con) {
  127. /* was hostalloc but changed cause it blows away the */
  128. /* large tlb mapping when pinning the kernel area */
  129. mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
  130. dma_addr = (u32)mem_addr;
  131. } else
  132. mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr,
  133. GFP_KERNEL);
  134. if (mem_addr == NULL) {
  135. cpm_dpfree(dp_offset);
  136. printk(KERN_ERR
  137. "cpm_uart_cpm1.c: could not allocate coherent memory\n");
  138. return -ENOMEM;
  139. }
  140. pinfo->dp_addr = dp_offset;
  141. pinfo->mem_addr = mem_addr; /* virtual address*/
  142. pinfo->dma_addr = dma_addr; /* physical address*/
  143. pinfo->mem_size = memsz;
  144. pinfo->rx_buf = mem_addr;
  145. pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
  146. * pinfo->rx_fifosize);
  147. pinfo->rx_bd_base = (volatile cbd_t *)dp_mem;
  148. pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
  149. return 0;
  150. }
  151. void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
  152. {
  153. dma_free_coherent(NULL, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
  154. pinfo->rx_fifosize) +
  155. L1_CACHE_ALIGN(pinfo->tx_nrfifos *
  156. pinfo->tx_fifosize), pinfo->mem_addr,
  157. pinfo->dma_addr);
  158. cpm_dpfree(pinfo->dp_addr);
  159. }
  160. /* Setup any dynamic params in the uart desc */
  161. int cpm_uart_init_portdesc(void)
  162. {
  163. pr_debug("CPM uart[-]:init portdesc\n");
  164. cpm_uart_nr = 0;
  165. #ifdef CONFIG_SERIAL_CPM_SMC1
  166. cpm_uart_ports[UART_SMC1].smcp = &cpmp->cp_smc[0];
  167. /*
  168. * Is SMC1 being relocated?
  169. */
  170. # ifdef CONFIG_I2C_SPI_SMC1_UCODE_PATCH
  171. cpm_uart_ports[UART_SMC1].smcup =
  172. (smc_uart_t *) & cpmp->cp_dparam[0x3C0];
  173. # else
  174. cpm_uart_ports[UART_SMC1].smcup =
  175. (smc_uart_t *) & cpmp->cp_dparam[PROFF_SMC1];
  176. # endif
  177. cpm_uart_ports[UART_SMC1].port.mapbase =
  178. (unsigned long)&cpmp->cp_smc[0];
  179. cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  180. cpm_uart_ports[UART_SMC1].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  181. cpm_uart_ports[UART_SMC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  182. cpm_uart_port_map[cpm_uart_nr++] = UART_SMC1;
  183. #endif
  184. #ifdef CONFIG_SERIAL_CPM_SMC2
  185. cpm_uart_ports[UART_SMC2].smcp = &cpmp->cp_smc[1];
  186. cpm_uart_ports[UART_SMC2].smcup =
  187. (smc_uart_t *) & cpmp->cp_dparam[PROFF_SMC2];
  188. cpm_uart_ports[UART_SMC2].port.mapbase =
  189. (unsigned long)&cpmp->cp_smc[1];
  190. cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  191. cpm_uart_ports[UART_SMC2].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  192. cpm_uart_ports[UART_SMC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  193. cpm_uart_port_map[cpm_uart_nr++] = UART_SMC2;
  194. #endif
  195. #ifdef CONFIG_SERIAL_CPM_SCC1
  196. cpm_uart_ports[UART_SCC1].sccp = &cpmp->cp_scc[0];
  197. cpm_uart_ports[UART_SCC1].sccup =
  198. (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC1];
  199. cpm_uart_ports[UART_SCC1].port.mapbase =
  200. (unsigned long)&cpmp->cp_scc[0];
  201. cpm_uart_ports[UART_SCC1].sccp->scc_sccm &=
  202. ~(UART_SCCM_TX | UART_SCCM_RX);
  203. cpm_uart_ports[UART_SCC1].sccp->scc_gsmrl &=
  204. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  205. cpm_uart_ports[UART_SCC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  206. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC1;
  207. #endif
  208. #ifdef CONFIG_SERIAL_CPM_SCC2
  209. cpm_uart_ports[UART_SCC2].sccp = &cpmp->cp_scc[1];
  210. cpm_uart_ports[UART_SCC2].sccup =
  211. (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC2];
  212. cpm_uart_ports[UART_SCC2].port.mapbase =
  213. (unsigned long)&cpmp->cp_scc[1];
  214. cpm_uart_ports[UART_SCC2].sccp->scc_sccm &=
  215. ~(UART_SCCM_TX | UART_SCCM_RX);
  216. cpm_uart_ports[UART_SCC2].sccp->scc_gsmrl &=
  217. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  218. cpm_uart_ports[UART_SCC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  219. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC2;
  220. #endif
  221. #ifdef CONFIG_SERIAL_CPM_SCC3
  222. cpm_uart_ports[UART_SCC3].sccp = &cpmp->cp_scc[2];
  223. cpm_uart_ports[UART_SCC3].sccup =
  224. (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC3];
  225. cpm_uart_ports[UART_SCC3].port.mapbase =
  226. (unsigned long)&cpmp->cp_scc[2];
  227. cpm_uart_ports[UART_SCC3].sccp->scc_sccm &=
  228. ~(UART_SCCM_TX | UART_SCCM_RX);
  229. cpm_uart_ports[UART_SCC3].sccp->scc_gsmrl &=
  230. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  231. cpm_uart_ports[UART_SCC3].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  232. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC3;
  233. #endif
  234. #ifdef CONFIG_SERIAL_CPM_SCC4
  235. cpm_uart_ports[UART_SCC4].sccp = &cpmp->cp_scc[3];
  236. cpm_uart_ports[UART_SCC4].sccup =
  237. (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC4];
  238. cpm_uart_ports[UART_SCC4].port.mapbase =
  239. (unsigned long)&cpmp->cp_scc[3];
  240. cpm_uart_ports[UART_SCC4].sccp->scc_sccm &=
  241. ~(UART_SCCM_TX | UART_SCCM_RX);
  242. cpm_uart_ports[UART_SCC4].sccp->scc_gsmrl &=
  243. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  244. cpm_uart_ports[UART_SCC4].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  245. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC4;
  246. #endif
  247. return 0;
  248. }