cpm_uart_cpm2.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388
  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. * (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. void cpm_line_cr_cmd(int line, int cmd)
  47. {
  48. ulong val;
  49. volatile cpm_cpm2_t *cp = cpm2_map(im_cpm);
  50. switch (line) {
  51. case UART_SMC1:
  52. val = mk_cr_cmd(CPM_CR_SMC1_PAGE, CPM_CR_SMC1_SBLOCK, 0,
  53. cmd) | CPM_CR_FLG;
  54. break;
  55. case UART_SMC2:
  56. val = mk_cr_cmd(CPM_CR_SMC2_PAGE, CPM_CR_SMC2_SBLOCK, 0,
  57. cmd) | CPM_CR_FLG;
  58. break;
  59. case UART_SCC1:
  60. val = mk_cr_cmd(CPM_CR_SCC1_PAGE, CPM_CR_SCC1_SBLOCK, 0,
  61. cmd) | CPM_CR_FLG;
  62. break;
  63. case UART_SCC2:
  64. val = mk_cr_cmd(CPM_CR_SCC2_PAGE, CPM_CR_SCC2_SBLOCK, 0,
  65. cmd) | CPM_CR_FLG;
  66. break;
  67. case UART_SCC3:
  68. val = mk_cr_cmd(CPM_CR_SCC3_PAGE, CPM_CR_SCC3_SBLOCK, 0,
  69. cmd) | CPM_CR_FLG;
  70. break;
  71. case UART_SCC4:
  72. val = mk_cr_cmd(CPM_CR_SCC4_PAGE, CPM_CR_SCC4_SBLOCK, 0,
  73. cmd) | CPM_CR_FLG;
  74. break;
  75. default:
  76. return;
  77. }
  78. cp->cp_cpcr = val;
  79. while (cp->cp_cpcr & CPM_CR_FLG) ;
  80. cpm2_unmap(cp);
  81. }
  82. void smc1_lineif(struct uart_cpm_port *pinfo)
  83. {
  84. volatile iop_cpm2_t *io = cpm2_map(im_ioport);
  85. volatile cpmux_t *cpmux = cpm2_map(im_cpmux);
  86. /* SMC1 is only on port D */
  87. io->iop_ppard |= 0x00c00000;
  88. io->iop_pdird |= 0x00400000;
  89. io->iop_pdird &= ~0x00800000;
  90. io->iop_psord &= ~0x00c00000;
  91. /* Wire BRG1 to SMC1 */
  92. cpmux->cmx_smr &= 0x0f;
  93. pinfo->brg = 1;
  94. cpm2_unmap(cpmux);
  95. cpm2_unmap(io);
  96. }
  97. void smc2_lineif(struct uart_cpm_port *pinfo)
  98. {
  99. volatile iop_cpm2_t *io = cpm2_map(im_ioport);
  100. volatile cpmux_t *cpmux = cpm2_map(im_cpmux);
  101. /* SMC2 is only on port A */
  102. io->iop_ppara |= 0x00c00000;
  103. io->iop_pdira |= 0x00400000;
  104. io->iop_pdira &= ~0x00800000;
  105. io->iop_psora &= ~0x00c00000;
  106. /* Wire BRG2 to SMC2 */
  107. cpmux->cmx_smr &= 0xf0;
  108. pinfo->brg = 2;
  109. cpm2_unmap(cpmux);
  110. cpm2_unmap(io);
  111. }
  112. void scc1_lineif(struct uart_cpm_port *pinfo)
  113. {
  114. volatile iop_cpm2_t *io = cpm2_map(im_ioport);
  115. volatile cpmux_t *cpmux = cpm2_map(im_cpmux);
  116. /* Use Port D for SCC1 instead of other functions. */
  117. io->iop_ppard |= 0x00000003;
  118. io->iop_psord &= ~0x00000001; /* Rx */
  119. io->iop_psord |= 0x00000002; /* Tx */
  120. io->iop_pdird &= ~0x00000001; /* Rx */
  121. io->iop_pdird |= 0x00000002; /* Tx */
  122. /* Wire BRG1 to SCC1 */
  123. cpmux->cmx_scr &= 0x00ffffff;
  124. cpmux->cmx_scr |= 0x00000000;
  125. pinfo->brg = 1;
  126. cpm2_unmap(cpmux);
  127. cpm2_unmap(io);
  128. }
  129. void scc2_lineif(struct uart_cpm_port *pinfo)
  130. {
  131. /*
  132. * STx GP3 uses the SCC2 secondary option pin assignment
  133. * which this driver doesn't account for in the static
  134. * pin assignments. This kind of board specific info
  135. * really has to get out of the driver so boards can
  136. * be supported in a sane fashion.
  137. */
  138. #ifndef CONFIG_STX_GP3
  139. volatile iop_cpm2_t *io = cpm2_map(im_ioport);
  140. volatile cpmux_t *cpmux = cpm2_map(im_cpmux);
  141. io->iop_pparb |= 0x008b0000;
  142. io->iop_pdirb |= 0x00880000;
  143. io->iop_psorb |= 0x00880000;
  144. io->iop_pdirb &= ~0x00030000;
  145. io->iop_psorb &= ~0x00030000;
  146. #endif
  147. cpmux->cmx_scr &= 0xff00ffff;
  148. cpmux->cmx_scr |= 0x00090000;
  149. pinfo->brg = 2;
  150. cpm2_unmap(cpmux);
  151. cpm2_unmap(io);
  152. }
  153. void scc3_lineif(struct uart_cpm_port *pinfo)
  154. {
  155. volatile iop_cpm2_t *io = cpm2_map(im_ioport);
  156. volatile cpmux_t *cpmux = cpm2_map(im_cpmux);
  157. io->iop_pparb |= 0x008b0000;
  158. io->iop_pdirb |= 0x00880000;
  159. io->iop_psorb |= 0x00880000;
  160. io->iop_pdirb &= ~0x00030000;
  161. io->iop_psorb &= ~0x00030000;
  162. cpmux->cmx_scr &= 0xffff00ff;
  163. cpmux->cmx_scr |= 0x00001200;
  164. pinfo->brg = 3;
  165. cpm2_unmap(cpmux);
  166. cpm2_unmap(io);
  167. }
  168. void scc4_lineif(struct uart_cpm_port *pinfo)
  169. {
  170. volatile iop_cpm2_t *io = cpm2_map(im_ioport);
  171. volatile cpmux_t *cpmux = cpm2_map(im_cpmux);
  172. io->iop_ppard |= 0x00000600;
  173. io->iop_psord &= ~0x00000600; /* Tx/Rx */
  174. io->iop_pdird &= ~0x00000200; /* Rx */
  175. io->iop_pdird |= 0x00000400; /* Tx */
  176. cpmux->cmx_scr &= 0xffffff00;
  177. cpmux->cmx_scr |= 0x0000001b;
  178. pinfo->brg = 4;
  179. cpm2_unmap(cpmux);
  180. cpm2_unmap(io);
  181. }
  182. /*
  183. * Allocate DP-Ram and memory buffers. We need to allocate a transmit and
  184. * receive buffer descriptors from dual port ram, and a character
  185. * buffer area from host mem. If we are allocating for the console we need
  186. * to do it from bootmem
  187. */
  188. int cpm_uart_allocbuf(struct uart_cpm_port *pinfo, unsigned int is_con)
  189. {
  190. int dpmemsz, memsz;
  191. u8 *dp_mem;
  192. uint dp_offset;
  193. u8 *mem_addr;
  194. dma_addr_t dma_addr = 0;
  195. pr_debug("CPM uart[%d]:allocbuf\n", pinfo->port.line);
  196. dpmemsz = sizeof(cbd_t) * (pinfo->rx_nrfifos + pinfo->tx_nrfifos);
  197. dp_offset = cpm_dpalloc(dpmemsz, 8);
  198. if (IS_DPERR(dp_offset)) {
  199. printk(KERN_ERR
  200. "cpm_uart_cpm.c: could not allocate buffer descriptors\n");
  201. return -ENOMEM;
  202. }
  203. dp_mem = cpm_dpram_addr(dp_offset);
  204. memsz = L1_CACHE_ALIGN(pinfo->rx_nrfifos * pinfo->rx_fifosize) +
  205. L1_CACHE_ALIGN(pinfo->tx_nrfifos * pinfo->tx_fifosize);
  206. if (is_con) {
  207. mem_addr = alloc_bootmem(memsz);
  208. dma_addr = virt_to_bus(mem_addr);
  209. }
  210. else
  211. mem_addr = dma_alloc_coherent(NULL, memsz, &dma_addr,
  212. GFP_KERNEL);
  213. if (mem_addr == NULL) {
  214. cpm_dpfree(dp_offset);
  215. printk(KERN_ERR
  216. "cpm_uart_cpm.c: could not allocate coherent memory\n");
  217. return -ENOMEM;
  218. }
  219. pinfo->dp_addr = dp_offset;
  220. pinfo->mem_addr = mem_addr;
  221. pinfo->dma_addr = dma_addr;
  222. pinfo->mem_size = memsz;
  223. pinfo->rx_buf = mem_addr;
  224. pinfo->tx_buf = pinfo->rx_buf + L1_CACHE_ALIGN(pinfo->rx_nrfifos
  225. * pinfo->rx_fifosize);
  226. pinfo->rx_bd_base = (volatile cbd_t *)dp_mem;
  227. pinfo->tx_bd_base = pinfo->rx_bd_base + pinfo->rx_nrfifos;
  228. return 0;
  229. }
  230. void cpm_uart_freebuf(struct uart_cpm_port *pinfo)
  231. {
  232. dma_free_coherent(NULL, L1_CACHE_ALIGN(pinfo->rx_nrfifos *
  233. pinfo->rx_fifosize) +
  234. L1_CACHE_ALIGN(pinfo->tx_nrfifos *
  235. pinfo->tx_fifosize), pinfo->mem_addr,
  236. pinfo->dma_addr);
  237. cpm_dpfree(pinfo->dp_addr);
  238. }
  239. /* Setup any dynamic params in the uart desc */
  240. int cpm_uart_init_portdesc(void)
  241. {
  242. #if defined(CONFIG_SERIAL_CPM_SMC1) || defined(CONFIG_SERIAL_CPM_SMC2)
  243. u32 addr;
  244. #endif
  245. pr_debug("CPM uart[-]:init portdesc\n");
  246. cpm_uart_nr = 0;
  247. #ifdef CONFIG_SERIAL_CPM_SMC1
  248. cpm_uart_ports[UART_SMC1].smcp = (smc_t *) cpm2_map(im_smc[0]);
  249. cpm_uart_ports[UART_SMC1].port.mapbase =
  250. (unsigned long)cpm_uart_ports[UART_SMC1].smcp;
  251. cpm_uart_ports[UART_SMC1].smcup =
  252. (smc_uart_t *) cpm2_map_size(im_dprambase[PROFF_SMC1], PROFF_SMC_SIZE);
  253. addr = (u16 *)cpm2_map_size(im_dprambase[PROFF_SMC1_BASE], 2);
  254. *addr = PROFF_SMC1;
  255. cpm2_unmap(addr);
  256. cpm_uart_ports[UART_SMC1].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  257. cpm_uart_ports[UART_SMC1].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  258. cpm_uart_ports[UART_SMC1].port.uartclk = uart_clock();
  259. cpm_uart_port_map[cpm_uart_nr++] = UART_SMC1;
  260. #endif
  261. #ifdef CONFIG_SERIAL_CPM_SMC2
  262. cpm_uart_ports[UART_SMC2].smcp = (smc_t *) cpm2_map(im_smc[1]);
  263. cpm_uart_ports[UART_SMC2].port.mapbase =
  264. (unsigned long)cpm_uart_ports[UART_SMC2].smcp;
  265. cpm_uart_ports[UART_SMC2].smcup =
  266. (smc_uart_t *) cpm2_map_size(im_dprambase[PROFF_SMC2], PROFF_SMC_SIZE);
  267. addr = (u16 *)cpm2_map_size(im_dprambase[PROFF_SMC2_BASE], 2);
  268. *addr = PROFF_SMC2;
  269. cpm2_unmap(addr);
  270. cpm_uart_ports[UART_SMC2].smcp->smc_smcm |= (SMCM_RX | SMCM_TX);
  271. cpm_uart_ports[UART_SMC2].smcp->smc_smcmr &= ~(SMCMR_REN | SMCMR_TEN);
  272. cpm_uart_ports[UART_SMC2].port.uartclk = uart_clock();
  273. cpm_uart_port_map[cpm_uart_nr++] = UART_SMC2;
  274. #endif
  275. #ifdef CONFIG_SERIAL_CPM_SCC1
  276. cpm_uart_ports[UART_SCC1].sccp = (scc_t *) cpm2_map(im_scc[0]);
  277. cpm_uart_ports[UART_SCC1].port.mapbase =
  278. (unsigned long)cpm_uart_ports[UART_SCC1].sccp;
  279. cpm_uart_ports[UART_SCC1].sccup =
  280. (scc_uart_t *) cpm2_map_size(im_dprambase[PROFF_SCC1], PROFF_SCC_SIZE);
  281. cpm_uart_ports[UART_SCC1].sccp->scc_sccm &=
  282. ~(UART_SCCM_TX | UART_SCCM_RX);
  283. cpm_uart_ports[UART_SCC1].sccp->scc_gsmrl &=
  284. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  285. cpm_uart_ports[UART_SCC1].port.uartclk = uart_clock();
  286. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC1;
  287. #endif
  288. #ifdef CONFIG_SERIAL_CPM_SCC2
  289. cpm_uart_ports[UART_SCC2].sccp = (scc_t *) cpm2_map(im_scc[1]);
  290. cpm_uart_ports[UART_SCC2].port.mapbase =
  291. (unsigned long)cpm_uart_ports[UART_SCC2].sccp;
  292. cpm_uart_ports[UART_SCC2].sccup =
  293. (scc_uart_t *) cpm2_map_size(im_dprambase[PROFF_SCC2], PROFF_SCC_SIZE);
  294. cpm_uart_ports[UART_SCC2].sccp->scc_sccm &=
  295. ~(UART_SCCM_TX | UART_SCCM_RX);
  296. cpm_uart_ports[UART_SCC2].sccp->scc_gsmrl &=
  297. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  298. cpm_uart_ports[UART_SCC2].port.uartclk = uart_clock();
  299. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC2;
  300. #endif
  301. #ifdef CONFIG_SERIAL_CPM_SCC3
  302. cpm_uart_ports[UART_SCC3].sccp = (scc_t *) cpm2_map(im_scc[2]);
  303. cpm_uart_ports[UART_SCC3].port.mapbase =
  304. (unsigned long)cpm_uart_ports[UART_SCC3].sccp;
  305. cpm_uart_ports[UART_SCC3].sccup =
  306. (scc_uart_t *) cpm2_map_size(im_dprambase[PROFF_SCC3], PROFF_SCC_SIZE);
  307. cpm_uart_ports[UART_SCC3].sccp->scc_sccm &=
  308. ~(UART_SCCM_TX | UART_SCCM_RX);
  309. cpm_uart_ports[UART_SCC3].sccp->scc_gsmrl &=
  310. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  311. cpm_uart_ports[UART_SCC3].port.uartclk = uart_clock();
  312. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC3;
  313. #endif
  314. #ifdef CONFIG_SERIAL_CPM_SCC4
  315. cpm_uart_ports[UART_SCC4].sccp = (scc_t *) cpm2_map(im_scc[3]);
  316. cpm_uart_ports[UART_SCC4].port.mapbase =
  317. (unsigned long)cpm_uart_ports[UART_SCC4].sccp;
  318. cpm_uart_ports[UART_SCC4].sccup =
  319. (scc_uart_t *) cpm2_map_size(im_dprambase[PROFF_SCC4], PROFF_SCC_SIZE);
  320. cpm_uart_ports[UART_SCC4].sccp->scc_sccm &=
  321. ~(UART_SCCM_TX | UART_SCCM_RX);
  322. cpm_uart_ports[UART_SCC4].sccp->scc_gsmrl &=
  323. ~(SCC_GSMRL_ENR | SCC_GSMRL_ENT);
  324. cpm_uart_ports[UART_SCC4].port.uartclk = uart_clock();
  325. cpm_uart_port_map[cpm_uart_nr++] = UART_SCC4;
  326. #endif
  327. return 0;
  328. }