cpm_uart_cpm1.c 8.4 KB

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