mpsc.c 26 KB

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