cpm_uart_cpm2.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 (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. volatile cpm_cpm2_t *cp = cpmp;
  48. ulong val;
  49. switch (line) {
  50. case UART_SMC1:
  51. val = mk_cr_cmd(CPM_CR_SMC1_PAGE, CPM_CR_SMC1_SBLOCK, 0,
  52. cmd) | CPM_CR_FLG;
  53. break;
  54. case UART_SMC2:
  55. val = mk_cr_cmd(CPM_CR_SMC2_PAGE, CPM_CR_SMC2_SBLOCK, 0,
  56. cmd) | CPM_CR_FLG;
  57. break;
  58. case UART_SCC1:
  59. val = mk_cr_cmd(CPM_CR_SCC1_PAGE, CPM_CR_SCC1_SBLOCK, 0,
  60. cmd) | CPM_CR_FLG;
  61. break;
  62. case UART_SCC2:
  63. val = mk_cr_cmd(CPM_CR_SCC2_PAGE, CPM_CR_SCC2_SBLOCK, 0,
  64. cmd) | CPM_CR_FLG;
  65. break;
  66. case UART_SCC3:
  67. val = mk_cr_cmd(CPM_CR_SCC3_PAGE, CPM_CR_SCC3_SBLOCK, 0,
  68. cmd) | CPM_CR_FLG;
  69. break;
  70. case UART_SCC4:
  71. val = mk_cr_cmd(CPM_CR_SCC4_PAGE, CPM_CR_SCC4_SBLOCK, 0,
  72. cmd) | CPM_CR_FLG;
  73. break;
  74. default:
  75. return;
  76. }
  77. cp->cp_cpcr = val;
  78. while (cp->cp_cpcr & CPM_CR_FLG) ;
  79. }
  80. void smc1_lineif(struct uart_cpm_port *pinfo)
  81. {
  82. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  83. /* SMC1 is only on port D */
  84. io->iop_ppard |= 0x00c00000;
  85. io->iop_pdird |= 0x00400000;
  86. io->iop_pdird &= ~0x00800000;
  87. io->iop_psord &= ~0x00c00000;
  88. /* Wire BRG1 to SMC1 */
  89. cpm2_immr->im_cpmux.cmx_smr &= 0x0f;
  90. pinfo->brg = 1;
  91. }
  92. void smc2_lineif(struct uart_cpm_port *pinfo)
  93. {
  94. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  95. /* SMC2 is only on port A */
  96. io->iop_ppara |= 0x00c00000;
  97. io->iop_pdira |= 0x00400000;
  98. io->iop_pdira &= ~0x00800000;
  99. io->iop_psora &= ~0x00c00000;
  100. /* Wire BRG2 to SMC2 */
  101. cpm2_immr->im_cpmux.cmx_smr &= 0xf0;
  102. pinfo->brg = 2;
  103. }
  104. void scc1_lineif(struct uart_cpm_port *pinfo)
  105. {
  106. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  107. /* Use Port D for SCC1 instead of other functions. */
  108. io->iop_ppard |= 0x00000003;
  109. io->iop_psord &= ~0x00000001; /* Rx */
  110. io->iop_psord |= 0x00000002; /* Tx */
  111. io->iop_pdird &= ~0x00000001; /* Rx */
  112. io->iop_pdird |= 0x00000002; /* Tx */
  113. /* Wire BRG1 to SCC1 */
  114. cpm2_immr->im_cpmux.cmx_scr &= 0x00ffffff;
  115. cpm2_immr->im_cpmux.cmx_scr |= 0x00000000;
  116. pinfo->brg = 1;
  117. }
  118. void scc2_lineif(struct uart_cpm_port *pinfo)
  119. {
  120. /*
  121. * STx GP3 uses the SCC2 secondary option pin assignment
  122. * which this driver doesn't account for in the static
  123. * pin assignments. This kind of board specific info
  124. * really has to get out of the driver so boards can
  125. * be supported in a sane fashion.
  126. */
  127. #ifndef CONFIG_STX_GP3
  128. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  129. io->iop_pparb |= 0x008b0000;
  130. io->iop_pdirb |= 0x00880000;
  131. io->iop_psorb |= 0x00880000;
  132. io->iop_pdirb &= ~0x00030000;
  133. io->iop_psorb &= ~0x00030000;
  134. #endif
  135. cpm2_immr->im_cpmux.cmx_scr &= 0xff00ffff;
  136. cpm2_immr->im_cpmux.cmx_scr |= 0x00090000;
  137. pinfo->brg = 2;
  138. }
  139. void scc3_lineif(struct uart_cpm_port *pinfo)
  140. {
  141. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  142. io->iop_pparb |= 0x008b0000;
  143. io->iop_pdirb |= 0x00880000;
  144. io->iop_psorb |= 0x00880000;
  145. io->iop_pdirb &= ~0x00030000;
  146. io->iop_psorb &= ~0x00030000;
  147. cpm2_immr->im_cpmux.cmx_scr &= 0xffff00ff;
  148. cpm2_immr->im_cpmux.cmx_scr |= 0x00001200;
  149. pinfo->brg = 3;
  150. }
  151. void scc4_lineif(struct uart_cpm_port *pinfo)
  152. {
  153. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  154. io->iop_ppard |= 0x00000600;
  155. io->iop_psord &= ~0x00000600; /* Tx/Rx */
  156. io->iop_pdird &= ~0x00000200; /* Rx */
  157. io->iop_pdird |= 0x00000400; /* Tx */
  158. cpm2_immr->im_cpmux.cmx_scr &= 0xffffff00;
  159. cpm2_immr->im_cpmux.cmx_scr |= 0x0000001b;
  160. pinfo->brg = 4;
  161. }
  162. /*
  163. * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
  164. * receive buffer descriptors from dual port ram, and a character
  165. * buffer area from host mem. If we are allocating for the console we need
  166. * to do it from bootmem
  167. */
  168. int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
  169. {
  170. int dpmemsz, memsz;
  171. u8 *dp_mem;
  172. uint dp_offset;
  173. u8 *mem_addr;
  174. dma_addr_t dma_addr = 0;
  175. pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
  176. dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
  177. dp_offset = cpm_dpalloc(dpmemsz, 8);
  178. if (IS_DPERR(dp_offset)) {
  179. printk(KERN_ERR
  180. "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
  181. return -ENOMEM;
  182. }
  183. dp_mem = cpm_dpram_addr(dp_offset);
  184. memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
  185. L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
  186. if (is_con) {
  187. mem_addr = alloc_bootmem(memsz);
  188. dma_addr = virt_to_bus(mem_addr);
  189. }
  190. else
  191. mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr,
  192. GFP_KERNEL);
  193. if (mem_addr == NULL) {
  194. cpm_dpfree(dp_offset);
  195. printk(KERN_ERR
  196. "cpm_uart_cpm.c: could not allocate coherent memory\n");
  197. return -ENOMEM;
  198. }
  199. pinfo->dp_addr = dp_offset;
  200. pinfo->mem_addr = mem_addr;
  201. pinfo->dma_addr = dma_addr;
  202. pinfo->mem_size = memsz;
  203. pinfo->rx_buf = mem_addr;
  204. pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
  205. * pinfo->rx_fifosize);
  206. pinfo->rx_bd_base = (volatile cbd_t *)dp_mem;
  207. pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
  208. return 0;
  209. }
  210. void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
  211. {
  212. dma_free_coherent(NULL, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
  213. pinfo->rx_fifosize) +
  214. L1_CACHE_ALIGN(pinfo->tx_nrfifos *
  215. pinfo->tx_fifosize), pinfo->mem_addr,
  216. pinfo->dma_addr);
  217. cpm_dpfree(pinfo->dp_addr);
  218. }
  219. /* Setup any dynamic params in the uart desc */
  220. int cpm_uart_init_portdesc(void)
  221. {
  222. pr_debug("CPM uart[-]:init portdesc\n");
  223. cpm_uart_nr = 0;
  224. #ifdef CONFIG_SERIAL_CPM_SMC1
  225. cpm_uart_ports[UART_SMC1].smcp = (smc_t *) & cpm2_immr->im_smc[0];
  226. cpm_uart_ports[UART_SMC1].smcup =
  227. (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC1];
  228. *(u16 *)(&cpm2_immr->im_dprambase[PROFF_SMC1_BASE]) = PROFF_SMC1;
  229. cpm_uart_ports[UART_SMC1].port.mapbase =
  230. (unsigned long)&cpm2_immr->im_smc[0];
  231. cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  232. cpm_uart_ports[UART_SMC1].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  233. cpm_uart_ports[UART_SMC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  234. cpm_uart_port_map[cpm_uart_nr++] = UART_SMC1;
  235. #endif
  236. #ifdef CONFIG_SERIAL_CPM_SMC2
  237. cpm_uart_ports[UART_SMC2].smcp = (smc_t *) & cpm2_immr->im_smc[1];
  238. cpm_uart_ports[UART_SMC2].smcup =
  239. (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC2];
  240. *(u16 *)(&cpm2_immr->im_dprambase[PROFF_SMC2_BASE]) = PROFF_SMC2;
  241. cpm_uart_ports[UART_SMC2].port.mapbase =
  242. (unsigned long)&cpm2_immr->im_smc[1];
  243. cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  244. cpm_uart_ports[UART_SMC2].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  245. cpm_uart_ports[UART_SMC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  246. cpm_uart_port_map[cpm_uart_nr++] = UART_SMC2;
  247. #endif
  248. #ifdef CONFIG_SERIAL_CPM_SCC1
  249. cpm_uart_ports[UART_SCC1].sccp = (scc_t *) & cpm2_immr->im_scc[0];
  250. cpm_uart_ports[UART_SCC1].sccup =
  251. (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC1];
  252. cpm_uart_ports[UART_SCC1].port.mapbase =
  253. (unsigned long)&cpm2_immr->im_scc[0];
  254. cpm_uart_ports[UART_SCC1].sccp->scc_sccm &=
  255. ~(UART_SCCM_TX | UART_SCCM_RX);
  256. cpm_uart_ports[UART_SCC1].sccp->scc_gsmrl &=
  257. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  258. cpm_uart_ports[UART_SCC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  259. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC1;
  260. #endif
  261. #ifdef CONFIG_SERIAL_CPM_SCC2
  262. cpm_uart_ports[UART_SCC2].sccp = (scc_t *) & cpm2_immr->im_scc[1];
  263. cpm_uart_ports[UART_SCC2].sccup =
  264. (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC2];
  265. cpm_uart_ports[UART_SCC2].port.mapbase =
  266. (unsigned long)&cpm2_immr->im_scc[1];
  267. cpm_uart_ports[UART_SCC2].sccp->scc_sccm &=
  268. ~(UART_SCCM_TX | UART_SCCM_RX);
  269. cpm_uart_ports[UART_SCC2].sccp->scc_gsmrl &=
  270. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  271. cpm_uart_ports[UART_SCC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  272. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC2;
  273. #endif
  274. #ifdef CONFIG_SERIAL_CPM_SCC3
  275. cpm_uart_ports[UART_SCC3].sccp = (scc_t *) & cpm2_immr->im_scc[2];
  276. cpm_uart_ports[UART_SCC3].sccup =
  277. (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC3];
  278. cpm_uart_ports[UART_SCC3].port.mapbase =
  279. (unsigned long)&cpm2_immr->im_scc[2];
  280. cpm_uart_ports[UART_SCC3].sccp->scc_sccm &=
  281. ~(UART_SCCM_TX | UART_SCCM_RX);
  282. cpm_uart_ports[UART_SCC3].sccp->scc_gsmrl &=
  283. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  284. cpm_uart_ports[UART_SCC3].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  285. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC3;
  286. #endif
  287. #ifdef CONFIG_SERIAL_CPM_SCC4
  288. cpm_uart_ports[UART_SCC4].sccp = (scc_t *) & cpm2_immr->im_scc[3];
  289. cpm_uart_ports[UART_SCC4].sccup =
  290. (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC4];
  291. cpm_uart_ports[UART_SCC4].port.mapbase =
  292. (unsigned long)&cpm2_immr->im_scc[3];
  293. cpm_uart_ports[UART_SCC4].sccp->scc_sccm &=
  294. ~(UART_SCCM_TX | UART_SCCM_RX);
  295. cpm_uart_ports[UART_SCC4].sccp->scc_gsmrl &=
  296. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  297. cpm_uart_ports[UART_SCC4].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  298. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC4;
  299. #endif
  300. return 0;
  301. }