cpm_uart_cpm1.c 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. *
  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. ushort val;
  47. volatile cpm8xx_t *cp = cpmp;
  48. switch (line) {
  49. case UART_SMC1:
  50. val = mk_cr_cmd(CPM_CR_CH_SMC1, cmd) | CPM_CR_FLG;
  51. break;
  52. case UART_SMC2:
  53. val = mk_cr_cmd(CPM_CR_CH_SMC2, cmd) | CPM_CR_FLG;
  54. break;
  55. case UART_SCC1:
  56. val = mk_cr_cmd(CPM_CR_CH_SCC1, cmd) | CPM_CR_FLG;
  57. break;
  58. case UART_SCC2:
  59. val = mk_cr_cmd(CPM_CR_CH_SCC2, cmd) | CPM_CR_FLG;
  60. break;
  61. case UART_SCC3:
  62. val = mk_cr_cmd(CPM_CR_CH_SCC3, cmd) | CPM_CR_FLG;
  63. break;
  64. case UART_SCC4:
  65. val = mk_cr_cmd(CPM_CR_CH_SCC4, cmd) | CPM_CR_FLG;
  66. break;
  67. default:
  68. return;
  69. }
  70. cp->cp_cpcr = val;
  71. while (cp->cp_cpcr & CPM_CR_FLG) ;
  72. }
  73. void smc1_lineif(struct uart_cpm_port *pinfo)
  74. {
  75. volatile cpm8xx_t *cp = cpmp;
  76. (void)cp; /* fix warning */
  77. #if defined (CONFIG_MPC885ADS)
  78. /* Enable SMC1 transceivers */
  79. {
  80. cp->cp_pepar |= 0x000000c0;
  81. cp->cp_pedir &= ~0x000000c0;
  82. cp->cp_peso &= ~0x00000040;
  83. cp->cp_peso |= 0x00000080;
  84. }
  85. #elif defined (CONFIG_MPC86XADS)
  86. unsigned int iobits = 0x000000c0;
  87. if (!pinfo->is_portb) {
  88. cp->cp_pbpar |= iobits;
  89. cp->cp_pbdir &= ~iobits;
  90. cp->cp_pbodr &= ~iobits;
  91. } else {
  92. ((immap_t *)IMAP_ADDR)->im_ioport.iop_papar |= iobits;
  93. ((immap_t *)IMAP_ADDR)->im_ioport.iop_padir &= ~iobits;
  94. ((immap_t *)IMAP_ADDR)->im_ioport.iop_paodr &= ~iobits;
  95. }
  96. #endif
  97. pinfo->brg = 1;
  98. }
  99. void smc2_lineif(struct uart_cpm_port *pinfo)
  100. {
  101. volatile cpm8xx_t *cp = cpmp;
  102. (void)cp; /* fix warning */
  103. #if defined (CONFIG_MPC885ADS)
  104. cp->cp_pepar |= 0x00000c00;
  105. cp->cp_pedir &= ~0x00000c00;
  106. cp->cp_peso &= ~0x00000400;
  107. cp->cp_peso |= 0x00000800;
  108. #elif defined (CONFIG_MPC86XADS)
  109. unsigned int iobits = 0x00000c00;
  110. if (!pinfo->is_portb) {
  111. cp->cp_pbpar |= iobits;
  112. cp->cp_pbdir &= ~iobits;
  113. cp->cp_pbodr &= ~iobits;
  114. } else {
  115. ((immap_t *)IMAP_ADDR)->im_ioport.iop_papar |= iobits;
  116. ((immap_t *)IMAP_ADDR)->im_ioport.iop_padir &= ~iobits;
  117. ((immap_t *)IMAP_ADDR)->im_ioport.iop_paodr &= ~iobits;
  118. }
  119. #endif
  120. pinfo->brg = 2;
  121. }
  122. void scc1_lineif(struct uart_cpm_port *pinfo)
  123. {
  124. /* XXX SCC1: insert port configuration here */
  125. pinfo->brg = 1;
  126. }
  127. void scc2_lineif(struct uart_cpm_port *pinfo)
  128. {
  129. /* XXX SCC2: insert port configuration here */
  130. pinfo->brg = 2;
  131. }
  132. void scc3_lineif(struct uart_cpm_port *pinfo)
  133. {
  134. /* XXX SCC3: insert port configuration here */
  135. pinfo->brg = 3;
  136. }
  137. void scc4_lineif(struct uart_cpm_port *pinfo)
  138. {
  139. /* XXX SCC4: insert port configuration here */
  140. pinfo->brg = 4;
  141. }
  142. /*
  143. * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
  144. * receive buffer descriptors from dual port ram, and a character
  145. * buffer area from host mem. If we are allocating for the console we need
  146. * to do it from bootmem
  147. */
  148. int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
  149. {
  150. int dpmemsz, memsz;
  151. u8 *dp_mem;
  152. uint dp_offset;
  153. u8 *mem_addr;
  154. dma_addr_t dma_addr = 0;
  155. pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
  156. dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
  157. dp_offset = cpm_dpalloc(dpmemsz, 8);
  158. if (IS_DPERR(dp_offset)) {
  159. printk(KERN_ERR
  160. "cpm_uart_cpm1.c: could not allocate buffer descriptors\n");
  161. return -ENOMEM;
  162. }
  163. dp_mem = cpm_dpram_addr(dp_offset);
  164. memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
  165. L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
  166. if (is_con) {
  167. /* was hostalloc but changed cause it blows away the */
  168. /* large tlb mapping when pinning the kernel area */
  169. mem_addr = (u8 *) cpm_dpram_addr(cpm_dpalloc(memsz, 8));
  170. dma_addr = 0;
  171. } else
  172. mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr,
  173. GFP_KERNEL);
  174. if (mem_addr == NULL) {
  175. cpm_dpfree(dp_offset);
  176. printk(KERN_ERR
  177. "cpm_uart_cpm1.c: could not allocate coherent memory\n");
  178. return -ENOMEM;
  179. }
  180. pinfo->dp_addr = dp_offset;
  181. pinfo->mem_addr = mem_addr;
  182. pinfo->dma_addr = dma_addr;
  183. pinfo->rx_buf = mem_addr;
  184. pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
  185. * pinfo->rx_fifosize);
  186. pinfo->rx_bd_base = (volatile cbd_t *)dp_mem;
  187. pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
  188. return 0;
  189. }
  190. void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
  191. {
  192. dma_free_coherent(NULL, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
  193. pinfo->rx_fifosize) +
  194. L1_CACHE_ALIGN(pinfo->tx_nrfifos *
  195. pinfo->tx_fifosize), pinfo->mem_addr,
  196. pinfo->dma_addr);
  197. cpm_dpfree(pinfo->dp_addr);
  198. }
  199. /* Setup any dynamic params in the uart desc */
  200. int cpm_uart_init_portdesc(void)
  201. {
  202. pr_debug("CPM uart[-]:init portdesc\n");
  203. cpm_uart_nr = 0;
  204. #ifdef CONFIG_SERIAL_CPM_SMC1
  205. cpm_uart_ports[UART_SMC1].smcp = &cpmp->cp_smc[0];
  206. /*
  207. * Is SMC1 being relocated?
  208. */
  209. # ifdef CONFIG_I2C_SPI_SMC1_UCODE_PATCH
  210. cpm_uart_ports[UART_SMC1].smcup =
  211. (smc_uart_t *) & cpmp->cp_dparam[0x3C0];
  212. # else
  213. cpm_uart_ports[UART_SMC1].smcup =
  214. (smc_uart_t *) & cpmp->cp_dparam[PROFF_SMC1];
  215. # endif
  216. cpm_uart_ports[UART_SMC1].port.mapbase =
  217. (unsigned long)&cpmp->cp_smc[0];
  218. cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  219. cpm_uart_ports[UART_SMC1].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  220. cpm_uart_ports[UART_SMC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  221. cpm_uart_port_map[cpm_uart_nr++] = UART_SMC1;
  222. #endif
  223. #ifdef CONFIG_SERIAL_CPM_SMC2
  224. cpm_uart_ports[UART_SMC2].smcp = &cpmp->cp_smc[1];
  225. cpm_uart_ports[UART_SMC2].smcup =
  226. (smc_uart_t *) & cpmp->cp_dparam[PROFF_SMC2];
  227. cpm_uart_ports[UART_SMC2].port.mapbase =
  228. (unsigned long)&cpmp->cp_smc[1];
  229. cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  230. cpm_uart_ports[UART_SMC2].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  231. cpm_uart_ports[UART_SMC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  232. cpm_uart_port_map[cpm_uart_nr++] = UART_SMC2;
  233. #endif
  234. #ifdef CONFIG_SERIAL_CPM_SCC1
  235. cpm_uart_ports[UART_SCC1].sccp = &cpmp->cp_scc[0];
  236. cpm_uart_ports[UART_SCC1].sccup =
  237. (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC1];
  238. cpm_uart_ports[UART_SCC1].port.mapbase =
  239. (unsigned long)&cpmp->cp_scc[0];
  240. cpm_uart_ports[UART_SCC1].sccp->scc_sccm &=
  241. ~(UART_SCCM_TX | UART_SCCM_RX);
  242. cpm_uart_ports[UART_SCC1].sccp->scc_gsmrl &=
  243. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  244. cpm_uart_ports[UART_SCC1].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  245. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC1;
  246. #endif
  247. #ifdef CONFIG_SERIAL_CPM_SCC2
  248. cpm_uart_ports[UART_SCC2].sccp = &cpmp->cp_scc[1];
  249. cpm_uart_ports[UART_SCC2].sccup =
  250. (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC2];
  251. cpm_uart_ports[UART_SCC2].port.mapbase =
  252. (unsigned long)&cpmp->cp_scc[1];
  253. cpm_uart_ports[UART_SCC2].sccp->scc_sccm &=
  254. ~(UART_SCCM_TX | UART_SCCM_RX);
  255. cpm_uart_ports[UART_SCC2].sccp->scc_gsmrl &=
  256. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  257. cpm_uart_ports[UART_SCC2].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  258. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC2;
  259. #endif
  260. #ifdef CONFIG_SERIAL_CPM_SCC3
  261. cpm_uart_ports[UART_SCC3].sccp = &cpmp->cp_scc[2];
  262. cpm_uart_ports[UART_SCC3].sccup =
  263. (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC3];
  264. cpm_uart_ports[UART_SCC3].port.mapbase =
  265. (unsigned long)&cpmp->cp_scc[2];
  266. cpm_uart_ports[UART_SCC3].sccp->scc_sccm &=
  267. ~(UART_SCCM_TX | UART_SCCM_RX);
  268. cpm_uart_ports[UART_SCC3].sccp->scc_gsmrl &=
  269. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  270. cpm_uart_ports[UART_SCC3].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  271. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC3;
  272. #endif
  273. #ifdef CONFIG_SERIAL_CPM_SCC4
  274. cpm_uart_ports[UART_SCC4].sccp = &cpmp->cp_scc[3];
  275. cpm_uart_ports[UART_SCC4].sccup =
  276. (scc_uart_t *) & cpmp->cp_dparam[PROFF_SCC4];
  277. cpm_uart_ports[UART_SCC4].port.mapbase =
  278. (unsigned long)&cpmp->cp_scc[3];
  279. cpm_uart_ports[UART_SCC4].sccp->scc_sccm &=
  280. ~(UART_SCCM_TX | UART_SCCM_RX);
  281. cpm_uart_ports[UART_SCC4].sccp->scc_gsmrl &=
  282. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  283. cpm_uart_ports[UART_SCC4].port.uartclk = (((bd_t *) __res)->bi_intfreq);
  284. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC4;
  285. #endif
  286. return 0;
  287. }