cpm_uart_cpm1.c 8.7 KB

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