mpsc.c 26 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018
  1. /*
  2. * (C) Copyright 2001
  3. * John Clemens <clemens@mclx.com>, Mission Critical Linux, Inc.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. /*************************************************************************
  24. * changes for Marvell DB64360 eval board 2003 by Ingo Assmus <ingo.assmus@keymile.com>
  25. *
  26. ************************************************************************/
  27. /*
  28. * mpsc.c - driver for console over the MPSC.
  29. */
  30. #include <common.h>
  31. #include <config.h>
  32. #include <asm/cache.h>
  33. #include <malloc.h>
  34. #include "mpsc.h"
  35. #include "mv_regs.h"
  36. #include "../../Marvell/include/memory.h"
  37. /* Define this if you wish to use the MPSC as a register based UART.
  38. * This will force the serial port to not use the SDMA engine at all.
  39. */
  40. #undef CONFIG_MPSC_DEBUG_PORT
  41. int (*mpsc_putchar) (char ch) = mpsc_putchar_early;
  42. char (*mpsc_getchar) (void) = mpsc_getchar_debug;
  43. int (*mpsc_test_char) (void) = mpsc_test_char_debug;
  44. static volatile unsigned int *rx_desc_base = NULL;
  45. static unsigned int rx_desc_index = 0;
  46. static volatile unsigned int *tx_desc_base = NULL;
  47. static unsigned int tx_desc_index = 0;
  48. /* local function declarations */
  49. static int galmpsc_connect (int channel, int connect);
  50. static int galmpsc_route_rx_clock (int channel, int brg);
  51. static int galmpsc_route_tx_clock (int channel, int brg);
  52. static int galmpsc_write_config_regs (int mpsc, int mode);
  53. static int galmpsc_config_channel_regs (int mpsc);
  54. static int galmpsc_set_char_length (int mpsc, int value);
  55. static int galmpsc_set_stop_bit_length (int mpsc, int value);
  56. static int galmpsc_set_parity (int mpsc, int value);
  57. static int galmpsc_enter_hunt (int mpsc);
  58. static int galmpsc_set_brkcnt (int mpsc, int value);
  59. static int galmpsc_set_tcschar (int mpsc, int value);
  60. static int galmpsc_set_snoop (int mpsc, int value);
  61. static int galmpsc_shutdown (int mpsc);
  62. static int galsdma_set_RFT (int channel);
  63. static int galsdma_set_SFM (int channel);
  64. static int galsdma_set_rxle (int channel);
  65. static int galsdma_set_txle (int channel);
  66. static int galsdma_set_burstsize (int channel, unsigned int value);
  67. static int galsdma_set_RC (int channel, unsigned int value);
  68. static int galbrg_set_CDV (int channel, int value);
  69. static int galbrg_enable (int channel);
  70. static int galbrg_disable (int channel);
  71. static int galbrg_set_clksrc (int channel, int value);
  72. static int galbrg_set_CUV (int channel, int value);
  73. static void galsdma_enable_rx (void);
  74. static int galsdma_set_mem_space (unsigned int memSpace,
  75. unsigned int memSpaceTarget,
  76. unsigned int memSpaceAttr,
  77. unsigned int baseAddress,
  78. unsigned int size);
  79. #define SOFTWARE_CACHE_MANAGEMENT
  80. #ifdef SOFTWARE_CACHE_MANAGEMENT
  81. #define FLUSH_DCACHE(a,b) if(dcache_status()){clean_dcache_range((u32)(a),(u32)(b));}
  82. #define FLUSH_AND_INVALIDATE_DCACHE(a,b) if(dcache_status()){flush_dcache_range((u32)(a),(u32)(b));}
  83. #define INVALIDATE_DCACHE(a,b) if(dcache_status()){invalidate_dcache_range((u32)(a),(u32)(b));}
  84. #else
  85. #define FLUSH_DCACHE(a,b)
  86. #define FLUSH_AND_INVALIDATE_DCACHE(a,b)
  87. #define INVALIDATE_DCACHE(a,b)
  88. #endif
  89. #ifdef CONFIG_MPSC_DEBUG_PORT
  90. static void mpsc_debug_init (void)
  91. {
  92. volatile unsigned int temp;
  93. /* Clear the CFR (CHR4) */
  94. /* Write random 'Z' bit (bit 29) of CHR4 to enable debug uart *UNDOCUMENTED FEATURE* */
  95. temp = GTREGREAD (GALMPSC_CHANNELREG_4 + (CHANNEL * GALMPSC_REG_GAP));
  96. temp &= 0xffffff00;
  97. temp |= BIT29;
  98. GT_REG_WRITE (GALMPSC_CHANNELREG_4 + (CHANNEL * GALMPSC_REG_GAP),
  99. temp);
  100. /* Set the Valid bit 'V' (bit 12) and int generation bit 'INT' (bit 15) */
  101. temp = GTREGREAD (GALMPSC_CHANNELREG_5 + (CHANNEL * GALMPSC_REG_GAP));
  102. temp |= (BIT12 | BIT15);
  103. GT_REG_WRITE (GALMPSC_CHANNELREG_5 + (CHANNEL * GALMPSC_REG_GAP),
  104. temp);
  105. /* Set int mask */
  106. temp = GTREGREAD (GALMPSC_0_INT_MASK);
  107. temp |= BIT6;
  108. GT_REG_WRITE (GALMPSC_0_INT_MASK, temp);
  109. }
  110. #endif
  111. char mpsc_getchar_debug (void)
  112. {
  113. volatile int temp;
  114. volatile unsigned int cause;
  115. cause = GTREGREAD (GALMPSC_0_INT_CAUSE);
  116. while ((cause & BIT6) == 0) {
  117. cause = GTREGREAD (GALMPSC_0_INT_CAUSE);
  118. }
  119. temp = GTREGREAD (GALMPSC_CHANNELREG_10 +
  120. (CHANNEL * GALMPSC_REG_GAP));
  121. /* By writing 1's to the set bits, the register is cleared */
  122. GT_REG_WRITE (GALMPSC_CHANNELREG_10 + (CHANNEL * GALMPSC_REG_GAP),
  123. temp);
  124. GT_REG_WRITE (GALMPSC_0_INT_CAUSE, cause & ~BIT6);
  125. return (temp >> 16) & 0xff;
  126. }
  127. /* special function for running out of flash. doesn't modify any
  128. * global variables [josh] */
  129. int mpsc_putchar_early (char ch)
  130. {
  131. DECLARE_GLOBAL_DATA_PTR;
  132. int mpsc = CHANNEL;
  133. int temp =
  134. GTREGREAD (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP));
  135. galmpsc_set_tcschar (mpsc, ch);
  136. GT_REG_WRITE (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP),
  137. temp | 0x200);
  138. #define MAGIC_FACTOR (10*1000000)
  139. udelay (MAGIC_FACTOR / gd->baudrate);
  140. return 0;
  141. }
  142. /* This is used after relocation, see serial.c and mpsc_init2 */
  143. static int mpsc_putchar_sdma (char ch)
  144. {
  145. volatile unsigned int *p;
  146. unsigned int temp;
  147. /* align the descriptor */
  148. p = tx_desc_base;
  149. memset ((void *) p, 0, 8 * sizeof (unsigned int));
  150. /* fill one 64 bit buffer */
  151. /* word swap, pad with 0 */
  152. p[4] = 0; /* x */
  153. p[5] = (unsigned int) ch; /* x */
  154. /* CHANGED completely according to GT64260A dox - NTL */
  155. p[0] = 0x00010001; /* 0 */
  156. p[1] = DESC_OWNER_BIT | DESC_FIRST | DESC_LAST; /* 4 */
  157. p[2] = 0; /* 8 */
  158. p[3] = (unsigned int) &p[4]; /* c */
  159. #if 0
  160. p[9] = DESC_FIRST | DESC_LAST;
  161. p[10] = (unsigned int) &p[0];
  162. p[11] = (unsigned int) &p[12];
  163. #endif
  164. FLUSH_DCACHE (&p[0], &p[8]);
  165. GT_REG_WRITE (GALSDMA_0_CUR_TX_PTR + (CHANNEL * GALSDMA_REG_DIFF),
  166. (unsigned int) &p[0]);
  167. GT_REG_WRITE (GALSDMA_0_FIR_TX_PTR + (CHANNEL * GALSDMA_REG_DIFF),
  168. (unsigned int) &p[0]);
  169. temp = GTREGREAD (GALSDMA_0_COM_REG + (CHANNEL * GALSDMA_REG_DIFF));
  170. temp |= (TX_DEMAND | TX_STOP);
  171. GT_REG_WRITE (GALSDMA_0_COM_REG + (CHANNEL * GALSDMA_REG_DIFF), temp);
  172. INVALIDATE_DCACHE (&p[1], &p[2]);
  173. while (p[1] & DESC_OWNER_BIT) {
  174. udelay (100);
  175. INVALIDATE_DCACHE (&p[1], &p[2]);
  176. }
  177. return 0;
  178. }
  179. char mpsc_getchar_sdma (void)
  180. {
  181. static unsigned int done = 0;
  182. volatile char ch;
  183. unsigned int len = 0, idx = 0, temp;
  184. volatile unsigned int *p;
  185. do {
  186. p = &rx_desc_base[rx_desc_index * 8];
  187. INVALIDATE_DCACHE (&p[0], &p[1]);
  188. /* Wait for character */
  189. while (p[1] & DESC_OWNER_BIT) {
  190. udelay (100);
  191. INVALIDATE_DCACHE (&p[0], &p[1]);
  192. }
  193. /* Handle error case */
  194. if (p[1] & (1 << 15)) {
  195. printf ("oops, error: %08x\n", p[1]);
  196. temp = GTREGREAD (GALMPSC_CHANNELREG_2 +
  197. (CHANNEL * GALMPSC_REG_GAP));
  198. temp |= (1 << 23);
  199. GT_REG_WRITE (GALMPSC_CHANNELREG_2 +
  200. (CHANNEL * GALMPSC_REG_GAP), temp);
  201. /* Can't poll on abort bit, so we just wait. */
  202. udelay (100);
  203. galsdma_enable_rx ();
  204. }
  205. /* Number of bytes left in this descriptor */
  206. len = p[0] & 0xffff;
  207. if (len) {
  208. /* Where to look */
  209. idx = 5;
  210. if (done > 3)
  211. idx = 4;
  212. if (done > 7)
  213. idx = 7;
  214. if (done > 11)
  215. idx = 6;
  216. INVALIDATE_DCACHE (&p[idx], &p[idx + 1]);
  217. ch = p[idx] & 0xff;
  218. done++;
  219. }
  220. if (done < len) {
  221. /* this descriptor has more bytes still
  222. * shift down the char we just read, and leave the
  223. * buffer in place for the next time around
  224. */
  225. p[idx] = p[idx] >> 8;
  226. FLUSH_DCACHE (&p[idx], &p[idx + 1]);
  227. }
  228. if (done == len) {
  229. /* nothing left in this descriptor.
  230. * go to next one
  231. */
  232. p[1] = DESC_OWNER_BIT | DESC_FIRST | DESC_LAST;
  233. p[0] = 0x00100000;
  234. FLUSH_DCACHE (&p[0], &p[1]);
  235. /* Next descriptor */
  236. rx_desc_index = (rx_desc_index + 1) % RX_DESC;
  237. done = 0;
  238. }
  239. } while (len == 0); /* galileo bug.. len might be zero */
  240. return ch;
  241. }
  242. int mpsc_test_char_debug (void)
  243. {
  244. if ((GTREGREAD (GALMPSC_0_INT_CAUSE) & BIT6) == 0)
  245. return 0;
  246. else {
  247. return 1;
  248. }
  249. }
  250. int mpsc_test_char_sdma (void)
  251. {
  252. volatile unsigned int *p = &rx_desc_base[rx_desc_index * 8];
  253. INVALIDATE_DCACHE (&p[1], &p[2]);
  254. if (p[1] & DESC_OWNER_BIT)
  255. return 0;
  256. else
  257. return 1;
  258. }
  259. int mpsc_init (int baud)
  260. {
  261. /* BRG CONFIG */
  262. galbrg_set_baudrate (CHANNEL, baud);
  263. galbrg_set_clksrc (CHANNEL, 8); /* set source=Tclk */
  264. galbrg_set_CUV (CHANNEL, 0); /* set up CountUpValue */
  265. galbrg_enable (CHANNEL); /* Enable BRG */
  266. /* Set up clock routing */
  267. galmpsc_connect (CHANNEL, GALMPSC_CONNECT); /* connect it */
  268. galmpsc_route_rx_clock (CHANNEL, CHANNEL); /* chosse BRG0 for Rx */
  269. galmpsc_route_tx_clock (CHANNEL, CHANNEL); /* chose BRG0 for Tx */
  270. /* reset MPSC state */
  271. galmpsc_shutdown (CHANNEL);
  272. /* SDMA CONFIG */
  273. galsdma_set_burstsize (CHANNEL, L1_CACHE_BYTES / 8); /* in 64 bit words (8 bytes) */
  274. galsdma_set_txle (CHANNEL);
  275. galsdma_set_rxle (CHANNEL);
  276. galsdma_set_RC (CHANNEL, 0xf);
  277. galsdma_set_SFM (CHANNEL);
  278. galsdma_set_RFT (CHANNEL);
  279. /* MPSC CONFIG */
  280. galmpsc_write_config_regs (CHANNEL, GALMPSC_UART);
  281. galmpsc_config_channel_regs (CHANNEL);
  282. galmpsc_set_char_length (CHANNEL, GALMPSC_CHAR_LENGTH_8); /* 8 */
  283. galmpsc_set_parity (CHANNEL, GALMPSC_PARITY_NONE); /* N */
  284. galmpsc_set_stop_bit_length (CHANNEL, GALMPSC_STOP_BITS_1); /* 1 */
  285. #ifdef CONFIG_MPSC_DEBUG_PORT
  286. mpsc_debug_init ();
  287. #endif
  288. /* COMM_MPSC CONFIG */
  289. #ifdef SOFTWARE_CACHE_MANAGEMENT
  290. galmpsc_set_snoop (CHANNEL, 0); /* disable snoop */
  291. #else
  292. galmpsc_set_snoop (CHANNEL, 1); /* enable snoop */
  293. #endif
  294. return 0;
  295. }
  296. void mpsc_sdma_init (void)
  297. {
  298. /* Setup SDMA channel0 SDMA_CONFIG_REG*/
  299. GT_REG_WRITE (SDMA_CONFIG_REG (0), 0x000020ff);
  300. /* Enable MPSC-Window0 for DRAM Bank0 */
  301. if (galsdma_set_mem_space (MV64360_CUNIT_BASE_ADDR_WIN_0_BIT,
  302. MV64360_SDMA_DRAM_CS_0_TARGET,
  303. 0,
  304. memoryGetBankBaseAddress
  305. (CS_0_LOW_DECODE_ADDRESS),
  306. memoryGetBankSize (BANK0)) != true)
  307. printf ("%s: SDMA_Window0 memory setup failed !!! \n",
  308. __FUNCTION__);
  309. /* Disable MPSC-Window1 */
  310. if (galsdma_set_mem_space (MV64360_CUNIT_BASE_ADDR_WIN_1_BIT,
  311. MV64360_SDMA_DRAM_CS_0_TARGET,
  312. 0,
  313. memoryGetBankBaseAddress
  314. (CS_1_LOW_DECODE_ADDRESS),
  315. memoryGetBankSize (BANK3)) != true)
  316. printf ("%s: SDMA_Window1 memory setup failed !!! \n",
  317. __FUNCTION__);
  318. /* Disable MPSC-Window2 */
  319. if (galsdma_set_mem_space (MV64360_CUNIT_BASE_ADDR_WIN_2_BIT,
  320. MV64360_SDMA_DRAM_CS_0_TARGET,
  321. 0,
  322. memoryGetBankBaseAddress
  323. (CS_2_LOW_DECODE_ADDRESS),
  324. memoryGetBankSize (BANK3)) != true)
  325. printf ("%s: SDMA_Window2 memory setup failed !!! \n",
  326. __FUNCTION__);
  327. /* Disable MPSC-Window3 */
  328. if (galsdma_set_mem_space (MV64360_CUNIT_BASE_ADDR_WIN_3_BIT,
  329. MV64360_SDMA_DRAM_CS_0_TARGET,
  330. 0,
  331. memoryGetBankBaseAddress
  332. (CS_3_LOW_DECODE_ADDRESS),
  333. memoryGetBankSize (BANK3)) != true)
  334. printf ("%s: SDMA_Window3 memory setup failed !!! \n",
  335. __FUNCTION__);
  336. /* Setup MPSC0 access mode Window0 full access */
  337. GT_SET_REG_BITS (MPSC0_ACCESS_PROTECTION_REG,
  338. (MV64360_SDMA_WIN_ACCESS_FULL <<
  339. (MV64360_CUNIT_BASE_ADDR_WIN_0_BIT * 2)));
  340. /* Setup MPSC1 access mode Window1 full access */
  341. GT_SET_REG_BITS (MPSC1_ACCESS_PROTECTION_REG,
  342. (MV64360_SDMA_WIN_ACCESS_FULL <<
  343. (MV64360_CUNIT_BASE_ADDR_WIN_0_BIT * 2)));
  344. /* Setup MPSC internal address space base address */
  345. GT_REG_WRITE (CUNIT_INTERNAL_SPACE_BASE_ADDR_REG, CFG_GT_REGS);
  346. /* no high address remap*/
  347. GT_REG_WRITE (CUNIT_HIGH_ADDR_REMAP_REG0, 0x00);
  348. GT_REG_WRITE (CUNIT_HIGH_ADDR_REMAP_REG1, 0x00);
  349. /* clear interrupt cause register for MPSC (fault register)*/
  350. GT_REG_WRITE (CUNIT_INTERRUPT_CAUSE_REG, 0x00);
  351. }
  352. void mpsc_init2 (void)
  353. {
  354. int i;
  355. #ifndef CONFIG_MPSC_DEBUG_PORT
  356. mpsc_putchar = mpsc_putchar_sdma;
  357. mpsc_getchar = mpsc_getchar_sdma;
  358. mpsc_test_char = mpsc_test_char_sdma;
  359. #endif
  360. /* RX descriptors */
  361. rx_desc_base = (unsigned int *) malloc (((RX_DESC + 1) * 8) *
  362. sizeof (unsigned int));
  363. /* align descriptors */
  364. rx_desc_base = (unsigned int *)
  365. (((unsigned int) rx_desc_base + 32) & 0xFFFFFFF0);
  366. rx_desc_index = 0;
  367. memset ((void *) rx_desc_base, 0,
  368. (RX_DESC * 8) * sizeof (unsigned int));
  369. for (i = 0; i < RX_DESC; i++) {
  370. rx_desc_base[i * 8 + 3] = (unsigned int) &rx_desc_base[i * 8 + 4]; /* Buffer */
  371. rx_desc_base[i * 8 + 2] = (unsigned int) &rx_desc_base[(i + 1) * 8]; /* Next descriptor */
  372. rx_desc_base[i * 8 + 1] = DESC_OWNER_BIT | DESC_FIRST | DESC_LAST; /* Command & control */
  373. rx_desc_base[i * 8] = 0x00100000;
  374. }
  375. rx_desc_base[(i - 1) * 8 + 2] = (unsigned int) &rx_desc_base[0];
  376. FLUSH_DCACHE (&rx_desc_base[0], &rx_desc_base[RX_DESC * 8]);
  377. GT_REG_WRITE (GALSDMA_0_CUR_RX_PTR + (CHANNEL * GALSDMA_REG_DIFF),
  378. (unsigned int) &rx_desc_base[0]);
  379. /* TX descriptors */
  380. tx_desc_base = (unsigned int *) malloc (((TX_DESC + 1) * 8) *
  381. sizeof (unsigned int));
  382. /* align descriptors */
  383. tx_desc_base = (unsigned int *)
  384. (((unsigned int) tx_desc_base + 32) & 0xFFFFFFF0);
  385. tx_desc_index = -1;
  386. memset ((void *) tx_desc_base, 0,
  387. (TX_DESC * 8) * sizeof (unsigned int));
  388. for (i = 0; i < TX_DESC; i++) {
  389. tx_desc_base[i * 8 + 5] = (unsigned int) 0x23232323;
  390. tx_desc_base[i * 8 + 4] = (unsigned int) 0x23232323;
  391. tx_desc_base[i * 8 + 3] =
  392. (unsigned int) &tx_desc_base[i * 8 + 4];
  393. tx_desc_base[i * 8 + 2] =
  394. (unsigned int) &tx_desc_base[(i + 1) * 8];
  395. tx_desc_base[i * 8 + 1] =
  396. DESC_OWNER_BIT | DESC_FIRST | DESC_LAST;
  397. /* set sbytecnt and shadow byte cnt to 1 */
  398. tx_desc_base[i * 8] = 0x00010001;
  399. }
  400. tx_desc_base[(i - 1) * 8 + 2] = (unsigned int) &tx_desc_base[0];
  401. FLUSH_DCACHE (&tx_desc_base[0], &tx_desc_base[TX_DESC * 8]);
  402. udelay (100);
  403. galsdma_enable_rx ();
  404. return;
  405. }
  406. int galbrg_set_baudrate (int channel, int rate)
  407. {
  408. DECLARE_GLOBAL_DATA_PTR;
  409. int clock;
  410. galbrg_disable (channel); /*ok */
  411. #ifdef ZUMA_NTL
  412. /* from tclk */
  413. clock = (CFG_TCLK / (16 * rate)) - 1;
  414. #else
  415. clock = (CFG_TCLK / (16 * rate)) - 1;
  416. #endif
  417. galbrg_set_CDV (channel, clock); /* set timer Reg. for BRG */
  418. galbrg_enable (channel);
  419. gd->baudrate = rate;
  420. return 0;
  421. }
  422. /* ------------------------------------------------------------------ */
  423. /* Below are all the private functions that no one else needs */
  424. static int galbrg_set_CDV (int channel, int value)
  425. {
  426. unsigned int temp;
  427. temp = GTREGREAD (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP));
  428. temp &= 0xFFFF0000;
  429. temp |= (value & 0x0000FFFF);
  430. GT_REG_WRITE (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP), temp);
  431. return 0;
  432. }
  433. static int galbrg_enable (int channel)
  434. {
  435. unsigned int temp;
  436. temp = GTREGREAD (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP));
  437. temp |= 0x00010000;
  438. GT_REG_WRITE (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP), temp);
  439. return 0;
  440. }
  441. static int galbrg_disable (int channel)
  442. {
  443. unsigned int temp;
  444. temp = GTREGREAD (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP));
  445. temp &= 0xFFFEFFFF;
  446. GT_REG_WRITE (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP), temp);
  447. return 0;
  448. }
  449. static int galbrg_set_clksrc (int channel, int value)
  450. {
  451. unsigned int temp;
  452. temp = GTREGREAD (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP));
  453. temp &= 0xFFC3FFFF; /* Bit 18 - 21 (MV 64260 18-22) */
  454. temp |= (value << 18);
  455. GT_REG_WRITE (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP), temp);
  456. return 0;
  457. }
  458. static int galbrg_set_CUV (int channel, int value)
  459. {
  460. /* set CountUpValue */
  461. GT_REG_WRITE (GALBRG_0_BTREG + (channel * GALBRG_REG_GAP), value);
  462. return 0;
  463. }
  464. #if 0
  465. static int galbrg_reset (int channel)
  466. {
  467. unsigned int temp;
  468. temp = GTREGREAD (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP));
  469. temp |= 0x20000;
  470. GT_REG_WRITE (GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP), temp);
  471. return 0;
  472. }
  473. #endif
  474. static int galsdma_set_RFT (int channel)
  475. {
  476. unsigned int temp;
  477. temp = GTREGREAD (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF));
  478. temp |= 0x00000001;
  479. GT_REG_WRITE (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF),
  480. temp);
  481. return 0;
  482. }
  483. static int galsdma_set_SFM (int channel)
  484. {
  485. unsigned int temp;
  486. temp = GTREGREAD (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF));
  487. temp |= 0x00000002;
  488. GT_REG_WRITE (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF),
  489. temp);
  490. return 0;
  491. }
  492. static int galsdma_set_rxle (int channel)
  493. {
  494. unsigned int temp;
  495. temp = GTREGREAD (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF));
  496. temp |= 0x00000040;
  497. GT_REG_WRITE (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF),
  498. temp);
  499. return 0;
  500. }
  501. static int galsdma_set_txle (int channel)
  502. {
  503. unsigned int temp;
  504. temp = GTREGREAD (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF));
  505. temp |= 0x00000080;
  506. GT_REG_WRITE (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF),
  507. temp);
  508. return 0;
  509. }
  510. static int galsdma_set_RC (int channel, unsigned int value)
  511. {
  512. unsigned int temp;
  513. temp = GTREGREAD (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF));
  514. temp &= ~0x0000003c;
  515. temp |= (value << 2);
  516. GT_REG_WRITE (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF),
  517. temp);
  518. return 0;
  519. }
  520. static int galsdma_set_burstsize (int channel, unsigned int value)
  521. {
  522. unsigned int temp;
  523. temp = GTREGREAD (GALSDMA_0_CONF_REG + (channel * GALSDMA_REG_DIFF));
  524. temp &= 0xFFFFCFFF;
  525. switch (value) {
  526. case 8:
  527. GT_REG_WRITE (GALSDMA_0_CONF_REG +
  528. (channel * GALSDMA_REG_DIFF),
  529. (temp | (0x3 << 12)));
  530. break;
  531. case 4:
  532. GT_REG_WRITE (GALSDMA_0_CONF_REG +
  533. (channel * GALSDMA_REG_DIFF),
  534. (temp | (0x2 << 12)));
  535. break;
  536. case 2:
  537. GT_REG_WRITE (GALSDMA_0_CONF_REG +
  538. (channel * GALSDMA_REG_DIFF),
  539. (temp | (0x1 << 12)));
  540. break;
  541. case 1:
  542. GT_REG_WRITE (GALSDMA_0_CONF_REG +
  543. (channel * GALSDMA_REG_DIFF),
  544. (temp | (0x0 << 12)));
  545. break;
  546. default:
  547. return -1;
  548. break;
  549. }
  550. return 0;
  551. }
  552. static int galmpsc_connect (int channel, int connect)
  553. {
  554. unsigned int temp;
  555. temp = GTREGREAD (GALMPSC_ROUTING_REGISTER);
  556. if ((channel == 0) && connect)
  557. temp &= ~0x00000007;
  558. else if ((channel == 1) && connect)
  559. temp &= ~(0x00000007 << 6);
  560. else if ((channel == 0) && !connect)
  561. temp |= 0x00000007;
  562. else
  563. temp |= (0x00000007 << 6);
  564. /* Just in case... */
  565. temp &= 0x3fffffff;
  566. GT_REG_WRITE (GALMPSC_ROUTING_REGISTER, temp);
  567. return 0;
  568. }
  569. static int galmpsc_route_rx_clock (int channel, int brg)
  570. {
  571. unsigned int temp;
  572. temp = GTREGREAD (GALMPSC_RxC_ROUTE);
  573. if (channel == 0) {
  574. temp &= ~0x0000000F;
  575. temp |= brg;
  576. } else {
  577. temp &= ~0x00000F00;
  578. temp |= (brg << 8);
  579. }
  580. GT_REG_WRITE (GALMPSC_RxC_ROUTE, temp);
  581. return 0;
  582. }
  583. static int galmpsc_route_tx_clock (int channel, int brg)
  584. {
  585. unsigned int temp;
  586. temp = GTREGREAD (GALMPSC_TxC_ROUTE);
  587. if (channel == 0) {
  588. temp &= ~0x0000000F;
  589. temp |= brg;
  590. } else {
  591. temp &= ~0x00000F00;
  592. temp |= (brg << 8);
  593. }
  594. GT_REG_WRITE (GALMPSC_TxC_ROUTE, temp);
  595. return 0;
  596. }
  597. static int galmpsc_write_config_regs (int mpsc, int mode)
  598. {
  599. if (mode == GALMPSC_UART) {
  600. /* Main config reg Low (Null modem, Enable Tx/Rx, UART mode) */
  601. GT_REG_WRITE (GALMPSC_MCONF_LOW + (mpsc * GALMPSC_REG_GAP),
  602. 0x000004c4);
  603. /* Main config reg High (32x Rx/Tx clock mode, width=8bits */
  604. GT_REG_WRITE (GALMPSC_MCONF_HIGH + (mpsc * GALMPSC_REG_GAP),
  605. 0x024003f8);
  606. /* 22 2222 1111 */
  607. /* 54 3210 9876 */
  608. /* 0000 0010 0000 0000 */
  609. /* 1 */
  610. /* 098 7654 3210 */
  611. /* 0000 0011 1111 1000 */
  612. } else
  613. return -1;
  614. return 0;
  615. }
  616. static int galmpsc_config_channel_regs (int mpsc)
  617. {
  618. GT_REG_WRITE (GALMPSC_CHANNELREG_1 + (mpsc * GALMPSC_REG_GAP), 0);
  619. GT_REG_WRITE (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP), 0);
  620. GT_REG_WRITE (GALMPSC_CHANNELREG_3 + (mpsc * GALMPSC_REG_GAP), 1);
  621. GT_REG_WRITE (GALMPSC_CHANNELREG_4 + (mpsc * GALMPSC_REG_GAP), 0);
  622. GT_REG_WRITE (GALMPSC_CHANNELREG_5 + (mpsc * GALMPSC_REG_GAP), 0);
  623. GT_REG_WRITE (GALMPSC_CHANNELREG_6 + (mpsc * GALMPSC_REG_GAP), 0);
  624. GT_REG_WRITE (GALMPSC_CHANNELREG_7 + (mpsc * GALMPSC_REG_GAP), 0);
  625. GT_REG_WRITE (GALMPSC_CHANNELREG_8 + (mpsc * GALMPSC_REG_GAP), 0);
  626. GT_REG_WRITE (GALMPSC_CHANNELREG_9 + (mpsc * GALMPSC_REG_GAP), 0);
  627. GT_REG_WRITE (GALMPSC_CHANNELREG_10 + (mpsc * GALMPSC_REG_GAP), 0);
  628. galmpsc_set_brkcnt (mpsc, 0x3);
  629. galmpsc_set_tcschar (mpsc, 0xab);
  630. return 0;
  631. }
  632. static int galmpsc_set_brkcnt (int mpsc, int value)
  633. {
  634. unsigned int temp;
  635. temp = GTREGREAD (GALMPSC_CHANNELREG_1 + (mpsc * GALMPSC_REG_GAP));
  636. temp &= 0x0000FFFF;
  637. temp |= (value << 16);
  638. GT_REG_WRITE (GALMPSC_CHANNELREG_1 + (mpsc * GALMPSC_REG_GAP), temp);
  639. return 0;
  640. }
  641. static int galmpsc_set_tcschar (int mpsc, int value)
  642. {
  643. unsigned int temp;
  644. temp = GTREGREAD (GALMPSC_CHANNELREG_1 + (mpsc * GALMPSC_REG_GAP));
  645. temp &= 0xFFFF0000;
  646. temp |= value;
  647. GT_REG_WRITE (GALMPSC_CHANNELREG_1 + (mpsc * GALMPSC_REG_GAP), temp);
  648. return 0;
  649. }
  650. static int galmpsc_set_char_length (int mpsc, int value)
  651. {
  652. unsigned int temp;
  653. temp = GTREGREAD (GALMPSC_PROTOCONF_REG + (mpsc * GALMPSC_REG_GAP));
  654. temp &= 0xFFFFCFFF;
  655. temp |= (value << 12);
  656. GT_REG_WRITE (GALMPSC_PROTOCONF_REG + (mpsc * GALMPSC_REG_GAP), temp);
  657. return 0;
  658. }
  659. static int galmpsc_set_stop_bit_length (int mpsc, int value)
  660. {
  661. unsigned int temp;
  662. temp = GTREGREAD (GALMPSC_PROTOCONF_REG + (mpsc * GALMPSC_REG_GAP));
  663. temp &= 0xFFFFBFFF;
  664. temp |= (value << 14);
  665. GT_REG_WRITE (GALMPSC_PROTOCONF_REG + (mpsc * GALMPSC_REG_GAP), temp);
  666. return 0;
  667. }
  668. static int galmpsc_set_parity (int mpsc, int value)
  669. {
  670. unsigned int temp;
  671. temp = GTREGREAD (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP));
  672. if (value != -1) {
  673. temp &= 0xFFF3FFF3;
  674. temp |= ((value << 18) | (value << 2));
  675. temp |= ((value << 17) | (value << 1));
  676. } else {
  677. temp &= 0xFFF1FFF1;
  678. }
  679. GT_REG_WRITE (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP), temp);
  680. return 0;
  681. }
  682. static int galmpsc_enter_hunt (int mpsc)
  683. {
  684. int temp;
  685. temp = GTREGREAD (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP));
  686. temp |= 0x80000000;
  687. GT_REG_WRITE (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP), temp);
  688. while (GTREGREAD (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP)) &
  689. MPSC_ENTER_HUNT) {
  690. udelay (1);
  691. }
  692. return 0;
  693. }
  694. static int galmpsc_shutdown (int mpsc)
  695. {
  696. unsigned int temp;
  697. /* cause RX abort (clears RX) */
  698. temp = GTREGREAD (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP));
  699. temp |= MPSC_RX_ABORT | MPSC_TX_ABORT;
  700. temp &= ~MPSC_ENTER_HUNT;
  701. GT_REG_WRITE (GALMPSC_CHANNELREG_2 + (mpsc * GALMPSC_REG_GAP), temp);
  702. GT_REG_WRITE (GALSDMA_0_COM_REG, 0);
  703. GT_REG_WRITE (GALSDMA_0_COM_REG, SDMA_TX_ABORT | SDMA_RX_ABORT);
  704. /* shut down the MPSC */
  705. GT_REG_WRITE (GALMPSC_MCONF_LOW, 0);
  706. GT_REG_WRITE (GALMPSC_MCONF_HIGH, 0);
  707. GT_REG_WRITE (GALMPSC_PROTOCONF_REG + (mpsc * GALMPSC_REG_GAP), 0);
  708. udelay (100);
  709. /* shut down the sdma engines. */
  710. /* reset config to default */
  711. GT_REG_WRITE (GALSDMA_0_CONF_REG, 0x000000fc);
  712. udelay (100);
  713. /* clear the SDMA current and first TX and RX pointers */
  714. GT_REG_WRITE (GALSDMA_0_CUR_RX_PTR, 0);
  715. GT_REG_WRITE (GALSDMA_0_CUR_TX_PTR, 0);
  716. GT_REG_WRITE (GALSDMA_0_FIR_TX_PTR, 0);
  717. udelay (100);
  718. return 0;
  719. }
  720. static void galsdma_enable_rx (void)
  721. {
  722. int temp;
  723. /* Enable RX processing */
  724. temp = GTREGREAD (GALSDMA_0_COM_REG + (CHANNEL * GALSDMA_REG_DIFF));
  725. temp |= RX_ENABLE;
  726. GT_REG_WRITE (GALSDMA_0_COM_REG + (CHANNEL * GALSDMA_REG_DIFF), temp);
  727. galmpsc_enter_hunt (CHANNEL);
  728. }
  729. static int galmpsc_set_snoop (int mpsc, int value)
  730. {
  731. int reg =
  732. mpsc ? MPSC_1_ADDRESS_CONTROL_LOW :
  733. MPSC_0_ADDRESS_CONTROL_LOW;
  734. int temp = GTREGREAD (reg);
  735. if (value)
  736. temp |= (1 << 6) | (1 << 14) | (1 << 22) | (1 << 30);
  737. else
  738. temp &= ~((1 << 6) | (1 << 14) | (1 << 22) | (1 << 30));
  739. GT_REG_WRITE (reg, temp);
  740. return 0;
  741. }
  742. /*******************************************************************************
  743. * galsdma_set_mem_space - Set MV64360 IDMA memory decoding map.
  744. *
  745. * DESCRIPTION:
  746. * the MV64360 SDMA has its own address decoding map that is de-coupled
  747. * from the CPU interface address decoding windows. The SDMA channels
  748. * share four address windows. Each region can be individually configured
  749. * by this function by associating it to a target interface and setting
  750. * base and size values.
  751. *
  752. * NOTE!!!
  753. * The size must be in 64Kbyte granularity.
  754. * The base address must be aligned to the size.
  755. * The size must be a series of 1s followed by a series of zeros
  756. *
  757. * OUTPUT:
  758. * None.
  759. *
  760. * RETURN:
  761. * True for success, false otherwise.
  762. *
  763. *******************************************************************************/
  764. static int galsdma_set_mem_space (unsigned int memSpace,
  765. unsigned int memSpaceTarget,
  766. unsigned int memSpaceAttr,
  767. unsigned int baseAddress, unsigned int size)
  768. {
  769. unsigned int temp;
  770. if (size == 0) {
  771. GT_RESET_REG_BITS (MV64360_CUNIT_BASE_ADDR_ENABLE_REG,
  772. 1 << memSpace);
  773. return true;
  774. }
  775. /* The base address must be aligned to the size. */
  776. if (baseAddress % size != 0) {
  777. return false;
  778. }
  779. if (size < 0x10000) {
  780. return false;
  781. }
  782. /* Align size and base to 64K */
  783. baseAddress &= 0xffff0000;
  784. size &= 0xffff0000;
  785. temp = size >> 16;
  786. /* Checking that the size is a sequence of '1' followed by a
  787. sequence of '0' starting from LSB to MSB. */
  788. while ((temp > 0) && (temp & 0x1)) {
  789. temp = temp >> 1;
  790. }
  791. if (temp != 0) {
  792. GT_REG_WRITE (MV64360_CUNIT_BASE_ADDR_REG0 + memSpace * 8,
  793. (baseAddress | memSpaceTarget | memSpaceAttr));
  794. GT_REG_WRITE ((MV64360_CUNIT_SIZE0 + memSpace * 8),
  795. (size - 1) & 0xffff0000);
  796. GT_RESET_REG_BITS (MV64360_CUNIT_BASE_ADDR_ENABLE_REG,
  797. 1 << memSpace);
  798. } else {
  799. /* An invalid size was specified */
  800. return false;
  801. }
  802. return true;
  803. }