cpm_uart_cpm2.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. /*
  2. * linux/drivers/serial/cpm_uart_cpm2.c
  3. *
  4. * Driver for CPM (SCC/SMC) serial ports; CPM2 definitions
  5. *
  6. * Maintainer: Kumar Gala (kumar.gala@freescale.com) (CPM2)
  7. * Pantelis Antoniou (panto@intracom.gr) (CPM1)
  8. *
  9. * Copyright (C) 2004 Freescale Semiconductor, Inc.
  10. * (C) 2004 Intracom, S.A.
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. *
  26. */
  27. #include <linux/config.h>
  28. #include <linux/module.h>
  29. #include <linux/tty.h>
  30. #include <linux/ioport.h>
  31. #include <linux/init.h>
  32. #include <linux/serial.h>
  33. #include <linux/console.h>
  34. #include <linux/sysrq.h>
  35. #include <linux/device.h>
  36. #include <linux/bootmem.h>
  37. #include <linux/dma-mapping.h>
  38. #include <asm/io.h>
  39. #include <asm/irq.h>
  40. #include <linux/serial_core.h>
  41. #include <linux/kernel.h>
  42. #include "cpm_uart.h"
  43. /**************************************************************/
  44. void cpm_line_cr_cmd(int line, int cmd)
  45. {
  46. volatile cpm_cpm2_t *cp = cpmp;
  47. ulong val;
  48. switch (line) {
  49. case UART_SMC1:
  50. val = mk_cr_cmd(CPM_CR_SMC1_PAGE, CPM_CR_SMC1_SBLOCK, 0,
  51. cmd) | CPM_CR_FLG;
  52. break;
  53. case UART_SMC2:
  54. val = mk_cr_cmd(CPM_CR_SMC2_PAGE, CPM_CR_SMC2_SBLOCK, 0,
  55. cmd) | CPM_CR_FLG;
  56. break;
  57. case UART_SCC1:
  58. val = mk_cr_cmd(CPM_CR_SCC1_PAGE, CPM_CR_SCC1_SBLOCK, 0,
  59. cmd) | CPM_CR_FLG;
  60. break;
  61. case UART_SCC2:
  62. val = mk_cr_cmd(CPM_CR_SCC2_PAGE, CPM_CR_SCC2_SBLOCK, 0,
  63. cmd) | CPM_CR_FLG;
  64. break;
  65. case UART_SCC3:
  66. val = mk_cr_cmd(CPM_CR_SCC3_PAGE, CPM_CR_SCC3_SBLOCK, 0,
  67. cmd) | CPM_CR_FLG;
  68. break;
  69. case UART_SCC4:
  70. val = mk_cr_cmd(CPM_CR_SCC4_PAGE, CPM_CR_SCC4_SBLOCK, 0,
  71. cmd) | CPM_CR_FLG;
  72. break;
  73. default:
  74. return;
  75. }
  76. cp->cp_cpcr = val;
  77. while (cp->cp_cpcr & CPM_CR_FLG) ;
  78. }
  79. void smc1_lineif(struct uart_cpm_port *pinfo)
  80. {
  81. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  82. /* SMC1 is only on port D */
  83. io->iop_ppard |= 0x00c00000;
  84. io->iop_pdird |= 0x00400000;
  85. io->iop_pdird &= ~0x00800000;
  86. io->iop_psord &= ~0x00c00000;
  87. /* Wire BRG1 to SMC1 */
  88. cpm2_immr->im_cpmux.cmx_smr &= 0x0f;
  89. pinfo->brg = 1;
  90. }
  91. void smc2_lineif(struct uart_cpm_port *pinfo)
  92. {
  93. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  94. /* SMC2 is only on port A */
  95. io->iop_ppara |= 0x00c00000;
  96. io->iop_pdira |= 0x00400000;
  97. io->iop_pdira &= ~0x00800000;
  98. io->iop_psora &= ~0x00c00000;
  99. /* Wire BRG2 to SMC2 */
  100. cpm2_immr->im_cpmux.cmx_smr &= 0xf0;
  101. pinfo->brg = 2;
  102. }
  103. void scc1_lineif(struct uart_cpm_port *pinfo)
  104. {
  105. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  106. /* Use Port D for SCC1 instead of other functions. */
  107. io->iop_ppard |= 0x00000003;
  108. io->iop_psord &= ~0x00000001; /* Rx */
  109. io->iop_psord |= 0x00000002; /* Tx */
  110. io->iop_pdird &= ~0x00000001; /* Rx */
  111. io->iop_pdird |= 0x00000002; /* Tx */
  112. /* Wire BRG1 to SCC1 */
  113. cpm2_immr->im_cpmux.cmx_scr &= 0x00ffffff;
  114. cpm2_immr->im_cpmux.cmx_scr |= 0x00000000;
  115. pinfo->brg = 1;
  116. }
  117. void scc2_lineif(struct uart_cpm_port *pinfo)
  118. {
  119. /*
  120. * STx GP3 uses the SCC2 secondary option pin assignment
  121. * which this driver doesn't account for in the static
  122. * pin assignments. This kind of board specific info
  123. * really has to get out of the driver so boards can
  124. * be supported in a sane fashion.
  125. */
  126. #ifndef CONFIG_STX_GP3
  127. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  128. io->iop_pparb |= 0x008b0000;
  129. io->iop_pdirb |= 0x00880000;
  130. io->iop_psorb |= 0x00880000;
  131. io->iop_pdirb &= ~0x00030000;
  132. io->iop_psorb &= ~0x00030000;
  133. #endif
  134. cpm2_immr->im_cpmux.cmx_scr &= 0xff00ffff;
  135. cpm2_immr->im_cpmux.cmx_scr |= 0x00090000;
  136. pinfo->brg = 2;
  137. }
  138. void scc3_lineif(struct uart_cpm_port *pinfo)
  139. {
  140. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  141. io->iop_pparb |= 0x008b0000;
  142. io->iop_pdirb |= 0x00880000;
  143. io->iop_psorb |= 0x00880000;
  144. io->iop_pdirb &= ~0x00030000;
  145. io->iop_psorb &= ~0x00030000;
  146. cpm2_immr->im_cpmux.cmx_scr &= 0xffff00ff;
  147. cpm2_immr->im_cpmux.cmx_scr |= 0x00001200;
  148. pinfo->brg = 3;
  149. }
  150. void scc4_lineif(struct uart_cpm_port *pinfo)
  151. {
  152. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  153. io->iop_ppard |= 0x00000600;
  154. io->iop_psord &= ~0x00000600; /* Tx/Rx */
  155. io->iop_pdird &= ~0x00000200; /* Rx */
  156. io->iop_pdird |= 0x00000400; /* Tx */
  157. cpm2_immr->im_cpmux.cmx_scr &= 0xffffff00;
  158. cpm2_immr->im_cpmux.cmx_scr |= 0x0000001b;
  159. pinfo->brg = 4;
  160. }
  161. /*
  162. * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
  163. * receive buffer descriptors from dual port ram, and a character
  164. * buffer area from host mem. If we are allocating for the console we need
  165. * to do it from bootmem
  166. */
  167. int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
  168. {
  169. int dpmemsz, memsz;
  170. u8 *dp_mem;
  171. uint dp_offset;
  172. u8 *mem_addr;
  173. dma_addr_t dma_addr = 0;
  174. pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
  175. dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
  176. dp_offset = cpm_dpalloc(dpmemsz, 8);
  177. if (IS_DPERR(dp_offset)) {
  178. printk(KERN_ERR
  179. "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
  180. return -ENOMEM;
  181. }
  182. dp_mem = cpm_dpram_addr(dp_offset);
  183. memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
  184. L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
  185. if (is_con)
  186. mem_addr = alloc_bootmem(memsz);
  187. else
  188. mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr,
  189. GFP_KERNEL);
  190. if (mem_addr == NULL) {
  191. cpm_dpfree(dp_offset);
  192. printk(KERN_ERR
  193. "cpm_uart_cpm.c: could not allocate coherent memory\n");
  194. return -ENOMEM;
  195. }
  196. pinfo->dp_addr = dp_offset;
  197. pinfo->mem_addr = mem_addr;
  198. pinfo->dma_addr = dma_addr;
  199. pinfo->rx_buf = mem_addr;
  200. pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
  201. * pinfo->rx_fifosize);
  202. pinfo->rx_bd_base = (volatile cbd_t *)dp_mem;
  203. pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
  204. return 0;
  205. }
  206. void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
  207. {
  208. dma_free_coherent(NULL, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
  209. pinfo->rx_fifosize) +
  210. L1_CACHE_ALIGN(pinfo->tx_nrfifos *
  211. pinfo->tx_fifosize), pinfo->mem_addr,
  212. pinfo->dma_addr);
  213. cpm_dpfree(pinfo->dp_addr);
  214. }
  215. /* Setup any dynamic params in the uart desc */
  216. int cpm_uart_init_portdesc(void)
  217. {
  218. pr_debug("CPM uart[-]:init portdesc\n");
  219. cpm_uart_nr = 0;
  220. #ifdef CONFIG_SERIAL_CPM_SMC1
  221. cpm_uart_ports[UART_SMC1].smcp = (smc_t *) & cpm2_immr->im_smc[0];
  222. cpm_uart_ports[UART_SMC1].smcup =
  223. (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC1];
  224. cpm_uart_ports[UART_SMC1].port.mapbase =
  225. (unsigned long)&cpm2_immr->im_smc[0];
  226. cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  227. cpm_uart_ports[UART_SMC1].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  228. cpm_uart_ports[UART_SMC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  229. cpm_uart_port_map[cpm_uart_nr++] = UART_SMC1;
  230. #endif
  231. #ifdef CONFIG_SERIAL_CPM_SMC2
  232. cpm_uart_ports[UART_SMC2].smcp = (smc_t *) & cpm2_immr->im_smc[1];
  233. cpm_uart_ports[UART_SMC2].smcup =
  234. (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC2];
  235. cpm_uart_ports[UART_SMC2].port.mapbase =
  236. (unsigned long)&cpm2_immr->im_smc[1];
  237. cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  238. cpm_uart_ports[UART_SMC2].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  239. cpm_uart_ports[UART_SMC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  240. cpm_uart_port_map[cpm_uart_nr++] = UART_SMC2;
  241. #endif
  242. #ifdef CONFIG_SERIAL_CPM_SCC1
  243. cpm_uart_ports[UART_SCC1].sccp = (scc_t *) & cpm2_immr->im_scc[0];
  244. cpm_uart_ports[UART_SCC1].sccup =
  245. (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC1];
  246. cpm_uart_ports[UART_SCC1].port.mapbase =
  247. (unsigned long)&cpm2_immr->im_scc[0];
  248. cpm_uart_ports[UART_SCC1].sccp->scc_sccm &=
  249. ~(UART_SCCM_TX | UART_SCCM_RX);
  250. cpm_uart_ports[UART_SCC1].sccp->scc_gsmrl &=
  251. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  252. cpm_uart_ports[UART_SCC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  253. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC1;
  254. #endif
  255. #ifdef CONFIG_SERIAL_CPM_SCC2
  256. cpm_uart_ports[UART_SCC2].sccp = (scc_t *) & cpm2_immr->im_scc[1];
  257. cpm_uart_ports[UART_SCC2].sccup =
  258. (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC2];
  259. cpm_uart_ports[UART_SCC2].port.mapbase =
  260. (unsigned long)&cpm2_immr->im_scc[1];
  261. cpm_uart_ports[UART_SCC2].sccp->scc_sccm &=
  262. ~(UART_SCCM_TX | UART_SCCM_RX);
  263. cpm_uart_ports[UART_SCC2].sccp->scc_gsmrl &=
  264. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  265. cpm_uart_ports[UART_SCC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  266. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC2;
  267. #endif
  268. #ifdef CONFIG_SERIAL_CPM_SCC3
  269. cpm_uart_ports[UART_SCC3].sccp = (scc_t *) & cpm2_immr->im_scc[2];
  270. cpm_uart_ports[UART_SCC3].sccup =
  271. (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC3];
  272. cpm_uart_ports[UART_SCC3].port.mapbase =
  273. (unsigned long)&cpm2_immr->im_scc[2];
  274. cpm_uart_ports[UART_SCC3].sccp->scc_sccm &=
  275. ~(UART_SCCM_TX | UART_SCCM_RX);
  276. cpm_uart_ports[UART_SCC3].sccp->scc_gsmrl &=
  277. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  278. cpm_uart_ports[UART_SCC3].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  279. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC3;
  280. #endif
  281. #ifdef CONFIG_SERIAL_CPM_SCC4
  282. cpm_uart_ports[UART_SCC4].sccp = (scc_t *) & cpm2_immr->im_scc[3];
  283. cpm_uart_ports[UART_SCC4].sccup =
  284. (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC4];
  285. cpm_uart_ports[UART_SCC4].port.mapbase =
  286. (unsigned long)&cpm2_immr->im_scc[3];
  287. cpm_uart_ports[UART_SCC4].sccp->scc_sccm &=
  288. ~(UART_SCCM_TX | UART_SCCM_RX);
  289. cpm_uart_ports[UART_SCC4].sccp->scc_gsmrl &=
  290. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  291. cpm_uart_ports[UART_SCC4].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  292. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC4;
  293. #endif
  294. return 0;
  295. }