cpm_uart_cpm2.c 11 KB

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