cpm_uart_cpm1.c 8.9 KB

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