cpm_uart_cpm2.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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. *
  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. #ifdef CONFIG_MPC8560_ADS
  128. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  129. io->iop_ppard |= 0x00000018;
  130. io->iop_psord &= ~0x00000008; /* Rx */
  131. io->iop_psord &= ~0x00000010; /* Tx */
  132. io->iop_pdird &= ~0x00000008; /* Rx */
  133. io->iop_pdird |= 0x00000010; /* Tx */
  134. #else
  135. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  136. io->iop_pparb |= 0x008b0000;
  137. io->iop_pdirb |= 0x00880000;
  138. io->iop_psorb |= 0x00880000;
  139. io->iop_pdirb &= ~0x00030000;
  140. io->iop_psorb &= ~0x00030000;
  141. #endif
  142. #endif
  143. cpm2_immr->im_cpmux.cmx_scr &= 0xff00ffff;
  144. cpm2_immr->im_cpmux.cmx_scr |= 0x00090000;
  145. pinfo->brg = 2;
  146. }
  147. void scc3_lineif(struct uart_cpm_port *pinfo)
  148. {
  149. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  150. io->iop_pparb |= 0x008b0000;
  151. io->iop_pdirb |= 0x00880000;
  152. io->iop_psorb |= 0x00880000;
  153. io->iop_pdirb &= ~0x00030000;
  154. io->iop_psorb &= ~0x00030000;
  155. cpm2_immr->im_cpmux.cmx_scr &= 0xffff00ff;
  156. cpm2_immr->im_cpmux.cmx_scr |= 0x00001200;
  157. pinfo->brg = 3;
  158. }
  159. void scc4_lineif(struct uart_cpm_port *pinfo)
  160. {
  161. volatile iop_cpm2_t *io = &cpm2_immr->im_ioport;
  162. io->iop_ppard |= 0x00000600;
  163. io->iop_psord &= ~0x00000600; /* Tx/Rx */
  164. io->iop_pdird &= ~0x00000200; /* Rx */
  165. io->iop_pdird |= 0x00000400; /* Tx */
  166. cpm2_immr->im_cpmux.cmx_scr &= 0xffffff00;
  167. cpm2_immr->im_cpmux.cmx_scr |= 0x0000001b;
  168. pinfo->brg = 4;
  169. }
  170. /*
  171. * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
  172. * receive buffer descriptors from dual port ram, and a character
  173. * buffer area from host mem. If we are allocating for the console we need
  174. * to do it from bootmem
  175. */
  176. int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
  177. {
  178. int dpmemsz, memsz;
  179. u8 *dp_mem;
  180. uint dp_offset;
  181. u8 *mem_addr;
  182. dma_addr_t dma_addr = 0;
  183. pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
  184. dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
  185. dp_offset = cpm_dpalloc(dpmemsz, 8);
  186. if (IS_DPERR(dp_offset)) {
  187. printk(KERN_ERR
  188. "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
  189. return -ENOMEM;
  190. }
  191. dp_mem = cpm_dpram_addr(dp_offset);
  192. memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
  193. L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
  194. if (is_con)
  195. mem_addr = alloc_bootmem(memsz);
  196. else
  197. mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr,
  198. GFP_KERNEL);
  199. if (mem_addr == NULL) {
  200. cpm_dpfree(dp_offset);
  201. printk(KERN_ERR
  202. "cpm_uart_cpm.c: could not allocate coherent memory\n");
  203. return -ENOMEM;
  204. }
  205. pinfo->dp_addr = dp_offset;
  206. pinfo->mem_addr = mem_addr;
  207. pinfo->dma_addr = dma_addr;
  208. pinfo->rx_buf = mem_addr;
  209. pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
  210. * pinfo->rx_fifosize);
  211. pinfo->rx_bd_base = (volatile cbd_t *)dp_mem;
  212. pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
  213. return 0;
  214. }
  215. void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
  216. {
  217. dma_free_coherent(NULL, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
  218. pinfo->rx_fifosize) +
  219. L1_CACHE_ALIGN(pinfo->tx_nrfifos *
  220. pinfo->tx_fifosize), pinfo->mem_addr,
  221. pinfo->dma_addr);
  222. cpm_dpfree(pinfo->dp_addr);
  223. }
  224. /* Setup any dynamic params in the uart desc */
  225. int cpm_uart_init_portdesc(void)
  226. {
  227. pr_debug("CPM uart[-]:init portdesc\n");
  228. cpm_uart_nr = 0;
  229. #ifdef CONFIG_SERIAL_CPM_SMC1
  230. cpm_uart_ports[UART_SMC1].smcp = (smc_t *) & cpm2_immr->im_smc[0];
  231. cpm_uart_ports[UART_SMC1].smcup =
  232. (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC1];
  233. *(u16 *)(&cpm2_immr->im_dprambase[PROFF_SMC1_BASE]) = PROFF_SMC1;
  234. cpm_uart_ports[UART_SMC1].port.mapbase =
  235. (unsigned long)&cpm2_immr->im_smc[0];
  236. cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  237. cpm_uart_ports[UART_SMC1].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  238. cpm_uart_ports[UART_SMC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  239. cpm_uart_port_map[cpm_uart_nr++] = UART_SMC1;
  240. #endif
  241. #ifdef CONFIG_SERIAL_CPM_SMC2
  242. cpm_uart_ports[UART_SMC2].smcp = (smc_t *) & cpm2_immr->im_smc[1];
  243. cpm_uart_ports[UART_SMC2].smcup =
  244. (smc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SMC2];
  245. *(u16 *)(&cpm2_immr->im_dprambase[PROFF_SMC2_BASE]) = PROFF_SMC2;
  246. cpm_uart_ports[UART_SMC2].port.mapbase =
  247. (unsigned long)&cpm2_immr->im_smc[1];
  248. cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  249. cpm_uart_ports[UART_SMC2].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  250. cpm_uart_ports[UART_SMC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  251. cpm_uart_port_map[cpm_uart_nr++] = UART_SMC2;
  252. #endif
  253. #ifdef CONFIG_SERIAL_CPM_SCC1
  254. cpm_uart_ports[UART_SCC1].sccp = (scc_t *) & cpm2_immr->im_scc[0];
  255. cpm_uart_ports[UART_SCC1].sccup =
  256. (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC1];
  257. cpm_uart_ports[UART_SCC1].port.mapbase =
  258. (unsigned long)&cpm2_immr->im_scc[0];
  259. cpm_uart_ports[UART_SCC1].sccp->scc_sccm &=
  260. ~(UART_SCCM_TX | UART_SCCM_RX);
  261. cpm_uart_ports[UART_SCC1].sccp->scc_gsmrl &=
  262. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  263. cpm_uart_ports[UART_SCC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  264. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC1;
  265. #endif
  266. #ifdef CONFIG_SERIAL_CPM_SCC2
  267. cpm_uart_ports[UART_SCC2].sccp = (scc_t *) & cpm2_immr->im_scc[1];
  268. cpm_uart_ports[UART_SCC2].sccup =
  269. (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC2];
  270. cpm_uart_ports[UART_SCC2].port.mapbase =
  271. (unsigned long)&cpm2_immr->im_scc[1];
  272. cpm_uart_ports[UART_SCC2].sccp->scc_sccm &=
  273. ~(UART_SCCM_TX | UART_SCCM_RX);
  274. cpm_uart_ports[UART_SCC2].sccp->scc_gsmrl &=
  275. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  276. cpm_uart_ports[UART_SCC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  277. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC2;
  278. #endif
  279. #ifdef CONFIG_SERIAL_CPM_SCC3
  280. cpm_uart_ports[UART_SCC3].sccp = (scc_t *) & cpm2_immr->im_scc[2];
  281. cpm_uart_ports[UART_SCC3].sccup =
  282. (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC3];
  283. cpm_uart_ports[UART_SCC3].port.mapbase =
  284. (unsigned long)&cpm2_immr->im_scc[2];
  285. cpm_uart_ports[UART_SCC3].sccp->scc_sccm &=
  286. ~(UART_SCCM_TX | UART_SCCM_RX);
  287. cpm_uart_ports[UART_SCC3].sccp->scc_gsmrl &=
  288. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  289. cpm_uart_ports[UART_SCC3].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  290. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC3;
  291. #endif
  292. #ifdef CONFIG_SERIAL_CPM_SCC4
  293. cpm_uart_ports[UART_SCC4].sccp = (scc_t *) & cpm2_immr->im_scc[3];
  294. cpm_uart_ports[UART_SCC4].sccup =
  295. (scc_uart_t *) & cpm2_immr->im_dprambase[PROFF_SCC4];
  296. cpm_uart_ports[UART_SCC4].port.mapbase =
  297. (unsigned long)&cpm2_immr->im_scc[3];
  298. cpm_uart_ports[UART_SCC4].sccp->scc_sccm &=
  299. ~(UART_SCCM_TX | UART_SCCM_RX);
  300. cpm_uart_ports[UART_SCC4].sccp->scc_gsmrl &=
  301. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  302. cpm_uart_ports[UART_SCC4].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  303. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC4;
  304. #endif
  305. return 0;
  306. }