mpsc.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854
  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. * mpsc.c - driver for console over the MPSC.
  25. */
  26. #include <common.h>
  27. #include <config.h>
  28. #include <asm/cache.h>
  29. #include <malloc.h>
  30. #include "mpsc.h"
  31. DECLARE_GLOBAL_DATA_PTR;
  32. int (*mpsc_putchar)(char ch) = mpsc_putchar_early;
  33. static volatile unsigned int *rx_desc_base=NULL;
  34. static unsigned int rx_desc_index=0;
  35. static volatile unsigned int *tx_desc_base=NULL;
  36. static unsigned int tx_desc_index=0;
  37. /* local function declarations */
  38. static int galmpsc_connect(int channel, int connect);
  39. static int galmpsc_route_serial(int channel, int connect);
  40. static int galmpsc_route_rx_clock(int channel, int brg);
  41. static int galmpsc_route_tx_clock(int channel, int brg);
  42. static int galmpsc_write_config_regs(int mpsc, int mode);
  43. static int galmpsc_config_channel_regs(int mpsc);
  44. static int galmpsc_set_char_length(int mpsc, int value);
  45. static int galmpsc_set_stop_bit_length(int mpsc, int value);
  46. static int galmpsc_set_parity(int mpsc, int value);
  47. static int galmpsc_enter_hunt(int mpsc);
  48. static int galmpsc_set_brkcnt(int mpsc, int value);
  49. static int galmpsc_set_tcschar(int mpsc, int value);
  50. static int galmpsc_set_snoop(int mpsc, int value);
  51. static int galmpsc_shutdown(int mpsc);
  52. static int galsdma_set_RFT(int channel);
  53. static int galsdma_set_SFM(int channel);
  54. static int galsdma_set_rxle(int channel);
  55. static int galsdma_set_txle(int channel);
  56. static int galsdma_set_burstsize(int channel, unsigned int value);
  57. static int galsdma_set_RC(int channel, unsigned int value);
  58. static int galbrg_set_CDV(int channel, int value);
  59. static int galbrg_enable(int channel);
  60. static int galbrg_disable(int channel);
  61. static int galbrg_set_clksrc(int channel, int value);
  62. static int galbrg_set_CUV(int channel, int value);
  63. static void galsdma_enable_rx(void);
  64. /* static int galbrg_reset(int channel); */
  65. #define SOFTWARE_CACHE_MANAGEMENT
  66. #ifdef SOFTWARE_CACHE_MANAGEMENT
  67. #define FLUSH_DCACHE(a,b) if(dcache_status()){clean_dcache_range((u32)(a),(u32)(b));}
  68. #define FLUSH_AND_INVALIDATE_DCACHE(a,b) if(dcache_status()){flush_dcache_range((u32)(a),(u32)(b));}
  69. #define INVALIDATE_DCACHE(a,b) if(dcache_status()){invalidate_dcache_range((u32)(a),(u32)(b));}
  70. #else
  71. #define FLUSH_DCACHE(a,b)
  72. #define FLUSH_AND_INVALIDATE_DCACHE(a,b)
  73. #define INVALIDATE_DCACHE(a,b)
  74. #endif
  75. /* GT64240A errata: cant read MPSC/BRG registers... so make mirrors in ram for read/modify write */
  76. #define MIRROR_HACK ((struct _tag_mirror_hack *)&(gd->mirror_hack))
  77. #define GT_REG_WRITE_MIRROR_G(a,d) {MIRROR_HACK->a ## _M = d; GT_REG_WRITE(a,d);}
  78. #define GTREGREAD_MIRROR_G(a) (MIRROR_HACK->a ## _M)
  79. #define GT_REG_WRITE_MIRROR(a,i,g,d) {MIRROR_HACK->a ## _M[i] = d; GT_REG_WRITE(a + (i*g),d);}
  80. #define GTREGREAD_MIRROR(a,i,g) (MIRROR_HACK->a ## _M[i])
  81. /* make sure this isn't bigger than 16 long words (u-boot.h) */
  82. struct _tag_mirror_hack {
  83. unsigned GALMPSC_PROTOCONF_REG_M[2]; /* 8008 */
  84. unsigned GALMPSC_CHANNELREG_1_M[2]; /* 800c */
  85. unsigned GALMPSC_CHANNELREG_2_M[2]; /* 8010 */
  86. unsigned GALBRG_0_CONFREG_M[2]; /* b200 */
  87. unsigned GALMPSC_ROUTING_REGISTER_M; /* b400 */
  88. unsigned GALMPSC_RxC_ROUTE_M; /* b404 */
  89. unsigned GALMPSC_TxC_ROUTE_M; /* b408 */
  90. unsigned int baudrate; /* current baudrate, for tsc delay calc */
  91. };
  92. /* static struct _tag_mirror_hack *mh = NULL; */
  93. /* special function for running out of flash. doesn't modify any
  94. * global variables [josh] */
  95. int
  96. mpsc_putchar_early(char ch)
  97. {
  98. int mpsc=CHANNEL;
  99. int temp=GTREGREAD_MIRROR(GALMPSC_CHANNELREG_2,mpsc,GALMPSC_REG_GAP);
  100. galmpsc_set_tcschar(mpsc,ch);
  101. GT_REG_WRITE(GALMPSC_CHANNELREG_2+(mpsc*GALMPSC_REG_GAP), temp|0x200);
  102. #define MAGIC_FACTOR (10*1000000)
  103. udelay(MAGIC_FACTOR / MIRROR_HACK->baudrate);
  104. return 0;
  105. }
  106. /* This is used after relocation, see serial.c and mpsc_init2 */
  107. static int
  108. mpsc_putchar_sdma(char ch)
  109. {
  110. volatile unsigned int *p;
  111. unsigned int temp;
  112. /* align the descriptor */
  113. p = tx_desc_base;
  114. memset((void *)p, 0, 8 * sizeof(unsigned int));
  115. /* fill one 64 bit buffer */
  116. /* word swap, pad with 0 */
  117. p[4] = 0; /* x */
  118. p[5] = (unsigned int)ch; /* x */
  119. /* CHANGED completely according to GT64260A dox - NTL */
  120. p[0] = 0x00010001; /* 0 */
  121. p[1] = DESC_OWNER | DESC_FIRST | DESC_LAST; /* 4 */
  122. p[2] = 0; /* 8 */
  123. p[3] = (unsigned int)&p[4]; /* c */
  124. #if 0
  125. p[9] = DESC_FIRST | DESC_LAST;
  126. p[10] = (unsigned int)&p[0];
  127. p[11] = (unsigned int)&p[12];
  128. #endif
  129. FLUSH_DCACHE(&p[0], &p[8]);
  130. GT_REG_WRITE(GALSDMA_0_CUR_TX_PTR+(CHANNEL*GALSDMA_REG_DIFF),
  131. (unsigned int)&p[0]);
  132. GT_REG_WRITE(GALSDMA_0_FIR_TX_PTR+(CHANNEL*GALSDMA_REG_DIFF),
  133. (unsigned int)&p[0]);
  134. temp = GTREGREAD(GALSDMA_0_COM_REG+(CHANNEL*GALSDMA_REG_DIFF));
  135. temp |= (TX_DEMAND | TX_STOP);
  136. GT_REG_WRITE(GALSDMA_0_COM_REG+(CHANNEL*GALSDMA_REG_DIFF), temp);
  137. INVALIDATE_DCACHE(&p[1], &p[2]);
  138. while(p[1] & DESC_OWNER) {
  139. udelay(100);
  140. INVALIDATE_DCACHE(&p[1], &p[2]);
  141. }
  142. return 0;
  143. }
  144. char mpsc_getchar (void)
  145. {
  146. static unsigned int done = 0;
  147. volatile char ch;
  148. unsigned int len = 0, idx = 0, temp;
  149. volatile unsigned int *p;
  150. do {
  151. p = &rx_desc_base[rx_desc_index * 8];
  152. INVALIDATE_DCACHE (&p[0], &p[1]);
  153. /* Wait for character */
  154. while (p[1] & DESC_OWNER) {
  155. udelay (100);
  156. INVALIDATE_DCACHE (&p[0], &p[1]);
  157. }
  158. /* Handle error case */
  159. if (p[1] & (1 << 15)) {
  160. printf ("oops, error: %08x\n", p[1]);
  161. temp = GTREGREAD_MIRROR (GALMPSC_CHANNELREG_2,
  162. CHANNEL, GALMPSC_REG_GAP);
  163. temp |= (1 << 23);
  164. GT_REG_WRITE_MIRROR (GALMPSC_CHANNELREG_2, CHANNEL,
  165. GALMPSC_REG_GAP, temp);
  166. /* Can't poll on abort bit, so we just wait. */
  167. udelay (100);
  168. galsdma_enable_rx ();
  169. }
  170. /* Number of bytes left in this descriptor */
  171. len = p[0] & 0xffff;
  172. if (len) {
  173. /* Where to look */
  174. idx = 5;
  175. if (done > 3)
  176. idx = 4;
  177. if (done > 7)
  178. idx = 7;
  179. if (done > 11)
  180. idx = 6;
  181. INVALIDATE_DCACHE (&p[idx], &p[idx + 1]);
  182. ch = p[idx] & 0xff;
  183. done++;
  184. }
  185. if (done < len) {
  186. /* this descriptor has more bytes still
  187. * shift down the char we just read, and leave the
  188. * buffer in place for the next time around
  189. */
  190. p[idx] = p[idx] >> 8;
  191. FLUSH_DCACHE (&p[idx], &p[idx + 1]);
  192. }
  193. if (done == len) {
  194. /* nothing left in this descriptor.
  195. * go to next one
  196. */
  197. p[1] = DESC_OWNER | DESC_FIRST | DESC_LAST;
  198. p[0] = 0x00100000;
  199. FLUSH_DCACHE (&p[0], &p[1]);
  200. /* Next descriptor */
  201. rx_desc_index = (rx_desc_index + 1) % RX_DESC;
  202. done = 0;
  203. }
  204. } while (len == 0); /* galileo bug.. len might be zero */
  205. return ch;
  206. }
  207. int
  208. mpsc_test_char(void)
  209. {
  210. volatile unsigned int *p=&rx_desc_base[rx_desc_index*8];
  211. INVALIDATE_DCACHE(&p[1], &p[2]);
  212. if (p[1] & DESC_OWNER) return 0;
  213. else return 1;
  214. }
  215. int
  216. mpsc_init(int baud)
  217. {
  218. memset(MIRROR_HACK, 0, sizeof(struct _tag_mirror_hack));
  219. MIRROR_HACK->GALMPSC_ROUTING_REGISTER_M=0x3fffffff;
  220. /* BRG CONFIG */
  221. galbrg_set_baudrate(CHANNEL, baud);
  222. #if defined(CONFIG_ZUMA_V2) || defined(CONFIG_P3G4)
  223. galbrg_set_clksrc(CHANNEL,0x8); /* connect TCLK -> BRG */
  224. #else
  225. galbrg_set_clksrc(CHANNEL,0);
  226. #endif
  227. galbrg_set_CUV(CHANNEL, 0);
  228. galbrg_enable(CHANNEL);
  229. /* Set up clock routing */
  230. galmpsc_connect(CHANNEL, GALMPSC_CONNECT);
  231. galmpsc_route_serial(CHANNEL, GALMPSC_CONNECT);
  232. galmpsc_route_rx_clock(CHANNEL, CHANNEL);
  233. galmpsc_route_tx_clock(CHANNEL, CHANNEL);
  234. /* reset MPSC state */
  235. galmpsc_shutdown(CHANNEL);
  236. /* SDMA CONFIG */
  237. galsdma_set_burstsize(CHANNEL, L1_CACHE_BYTES/8); /* in 64 bit words (8 bytes) */
  238. galsdma_set_txle(CHANNEL);
  239. galsdma_set_rxle(CHANNEL);
  240. galsdma_set_RC(CHANNEL, 0xf);
  241. galsdma_set_SFM(CHANNEL);
  242. galsdma_set_RFT(CHANNEL);
  243. /* MPSC CONFIG */
  244. galmpsc_write_config_regs(CHANNEL, GALMPSC_UART);
  245. galmpsc_config_channel_regs(CHANNEL);
  246. galmpsc_set_char_length(CHANNEL, GALMPSC_CHAR_LENGTH_8); /* 8 */
  247. galmpsc_set_parity(CHANNEL, GALMPSC_PARITY_NONE); /* N */
  248. galmpsc_set_stop_bit_length(CHANNEL, GALMPSC_STOP_BITS_1); /* 1 */
  249. /* COMM_MPSC CONFIG */
  250. #ifdef SOFTWARE_CACHE_MANAGEMENT
  251. galmpsc_set_snoop(CHANNEL, 0); /* disable snoop */
  252. #else
  253. galmpsc_set_snoop(CHANNEL, 1); /* enable snoop */
  254. #endif
  255. return 0;
  256. }
  257. void
  258. mpsc_init2(void)
  259. {
  260. int i;
  261. mpsc_putchar = mpsc_putchar_sdma;
  262. /* RX descriptors */
  263. rx_desc_base = (unsigned int *)malloc(((RX_DESC+1)*8) *
  264. sizeof(unsigned int));
  265. /* align descriptors */
  266. rx_desc_base = (unsigned int *)
  267. (((unsigned int)rx_desc_base+32) & 0xFFFFFFF0);
  268. rx_desc_index = 0;
  269. memset((void *)rx_desc_base, 0, (RX_DESC*8)*sizeof(unsigned int));
  270. for (i = 0; i < RX_DESC; i++) {
  271. rx_desc_base[i*8 + 3] = (unsigned int)&rx_desc_base[i*8 + 4]; /* Buffer */
  272. rx_desc_base[i*8 + 2] = (unsigned int)&rx_desc_base[(i+1)*8]; /* Next descriptor */
  273. rx_desc_base[i*8 + 1] = DESC_OWNER | DESC_FIRST | DESC_LAST; /* Command & control */
  274. rx_desc_base[i*8] = 0x00100000;
  275. }
  276. rx_desc_base[(i-1)*8 + 2] = (unsigned int)&rx_desc_base[0];
  277. FLUSH_DCACHE(&rx_desc_base[0], &rx_desc_base[RX_DESC*8]);
  278. GT_REG_WRITE(GALSDMA_0_CUR_RX_PTR+(CHANNEL*GALSDMA_REG_DIFF),
  279. (unsigned int)&rx_desc_base[0]);
  280. /* TX descriptors */
  281. tx_desc_base = (unsigned int *)malloc(((TX_DESC+1)*8) *
  282. sizeof(unsigned int));
  283. /* align descriptors */
  284. tx_desc_base = (unsigned int *)
  285. (((unsigned int)tx_desc_base+32) & 0xFFFFFFF0);
  286. tx_desc_index = -1;
  287. memset((void *)tx_desc_base, 0, (TX_DESC*8)*sizeof(unsigned int));
  288. for (i = 0; i < TX_DESC; i++) {
  289. tx_desc_base[i*8 + 5] = (unsigned int)0x23232323;
  290. tx_desc_base[i*8 + 4] = (unsigned int)0x23232323;
  291. tx_desc_base[i*8 + 3] = (unsigned int)&tx_desc_base[i*8 + 4];
  292. tx_desc_base[i*8 + 2] = (unsigned int)&tx_desc_base[(i+1)*8];
  293. tx_desc_base[i*8 + 1] = DESC_OWNER | DESC_FIRST | DESC_LAST;
  294. /* set sbytecnt and shadow byte cnt to 1 */
  295. tx_desc_base[i*8] = 0x00010001;
  296. }
  297. tx_desc_base[(i-1)*8 + 2] = (unsigned int)&tx_desc_base[0];
  298. FLUSH_DCACHE(&tx_desc_base[0], &tx_desc_base[TX_DESC*8]);
  299. udelay(100);
  300. galsdma_enable_rx();
  301. return;
  302. }
  303. int
  304. galbrg_set_baudrate(int channel, int rate)
  305. {
  306. int clock;
  307. galbrg_disable(channel);
  308. #if defined(CONFIG_ZUMA_V2) || defined(CONFIG_P3G4)
  309. /* from tclk */
  310. clock = (CFG_BUS_HZ/(16*rate)) - 1;
  311. #else
  312. clock = (3686400/(16*rate)) - 1;
  313. #endif
  314. galbrg_set_CDV(channel, clock);
  315. galbrg_enable(channel);
  316. MIRROR_HACK->baudrate = rate;
  317. return 0;
  318. }
  319. /* ------------------------------------------------------------------ */
  320. /* Below are all the private functions that no one else needs */
  321. static int
  322. galbrg_set_CDV(int channel, int value)
  323. {
  324. unsigned int temp;
  325. temp = GTREGREAD_MIRROR(GALBRG_0_CONFREG, channel, GALBRG_REG_GAP);
  326. temp &= 0xFFFF0000;
  327. temp |= (value & 0x0000FFFF);
  328. GT_REG_WRITE_MIRROR(GALBRG_0_CONFREG,channel,GALBRG_REG_GAP, temp);
  329. return 0;
  330. }
  331. static int
  332. galbrg_enable(int channel)
  333. {
  334. unsigned int temp;
  335. temp = GTREGREAD_MIRROR(GALBRG_0_CONFREG, channel, GALBRG_REG_GAP);
  336. temp |= 0x00010000;
  337. GT_REG_WRITE_MIRROR(GALBRG_0_CONFREG, channel, GALBRG_REG_GAP,temp);
  338. return 0;
  339. }
  340. static int
  341. galbrg_disable(int channel)
  342. {
  343. unsigned int temp;
  344. temp = GTREGREAD_MIRROR(GALBRG_0_CONFREG, channel, GALBRG_REG_GAP);
  345. temp &= 0xFFFEFFFF;
  346. GT_REG_WRITE_MIRROR(GALBRG_0_CONFREG, channel, GALBRG_REG_GAP,temp);
  347. return 0;
  348. }
  349. static int
  350. galbrg_set_clksrc(int channel, int value)
  351. {
  352. unsigned int temp;
  353. temp = GTREGREAD_MIRROR(GALBRG_0_CONFREG,channel, GALBRG_REG_GAP);
  354. temp &= 0xFF83FFFF;
  355. temp |= (value << 18);
  356. GT_REG_WRITE_MIRROR(GALBRG_0_CONFREG,channel, GALBRG_REG_GAP,temp);
  357. return 0;
  358. }
  359. static int
  360. galbrg_set_CUV(int channel, int value)
  361. {
  362. GT_REG_WRITE(GALBRG_0_BTREG + (channel * GALBRG_REG_GAP), value);
  363. return 0;
  364. }
  365. #if 0
  366. static int
  367. galbrg_reset(int channel)
  368. {
  369. unsigned int temp;
  370. temp = GTREGREAD(GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP));
  371. temp |= 0x20000;
  372. GT_REG_WRITE(GALBRG_0_CONFREG + (channel * GALBRG_REG_GAP), temp);
  373. return 0;
  374. }
  375. #endif
  376. static int
  377. galsdma_set_RFT(int channel)
  378. {
  379. unsigned int temp;
  380. temp = GTREGREAD(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF));
  381. temp |= 0x00000001;
  382. GT_REG_WRITE(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF), temp);
  383. return 0;
  384. }
  385. static int
  386. galsdma_set_SFM(int channel)
  387. {
  388. unsigned int temp;
  389. temp = GTREGREAD(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF));
  390. temp |= 0x00000002;
  391. GT_REG_WRITE(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF), temp);
  392. return 0;
  393. }
  394. static int
  395. galsdma_set_rxle(int channel)
  396. {
  397. unsigned int temp;
  398. temp = GTREGREAD(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF));
  399. temp |= 0x00000040;
  400. GT_REG_WRITE(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF), temp);
  401. return 0;
  402. }
  403. static int
  404. galsdma_set_txle(int channel)
  405. {
  406. unsigned int temp;
  407. temp = GTREGREAD(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF));
  408. temp |= 0x00000080;
  409. GT_REG_WRITE(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF), temp);
  410. return 0;
  411. }
  412. static int
  413. galsdma_set_RC(int channel, unsigned int value)
  414. {
  415. unsigned int temp;
  416. temp = GTREGREAD(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF));
  417. temp &= ~0x0000003c;
  418. temp |= (value << 2);
  419. GT_REG_WRITE(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF), temp);
  420. return 0;
  421. }
  422. static int
  423. galsdma_set_burstsize(int channel, unsigned int value)
  424. {
  425. unsigned int temp;
  426. temp = GTREGREAD(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF));
  427. temp &= 0xFFFFCFFF;
  428. switch (value) {
  429. case 8:
  430. GT_REG_WRITE(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF),
  431. (temp | (0x3 << 12)));
  432. break;
  433. case 4:
  434. GT_REG_WRITE(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF),
  435. (temp | (0x2 << 12)));
  436. break;
  437. case 2:
  438. GT_REG_WRITE(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF),
  439. (temp | (0x1 << 12)));
  440. break;
  441. case 1:
  442. GT_REG_WRITE(GALSDMA_0_CONF_REG+(channel*GALSDMA_REG_DIFF),
  443. (temp | (0x0 << 12)));
  444. break;
  445. default:
  446. return -1;
  447. break;
  448. }
  449. return 0;
  450. }
  451. static int
  452. galmpsc_connect(int channel, int connect)
  453. {
  454. unsigned int temp;
  455. temp = GTREGREAD_MIRROR_G(GALMPSC_ROUTING_REGISTER);
  456. if ((channel == 0) && connect)
  457. temp &= ~0x00000007;
  458. else if ((channel == 1) && connect)
  459. temp &= ~(0x00000007 << 6);
  460. else if ((channel == 0) && !connect)
  461. temp |= 0x00000007;
  462. else
  463. temp |= (0x00000007 << 6);
  464. /* Just in case... */
  465. temp &= 0x3fffffff;
  466. GT_REG_WRITE_MIRROR_G(GALMPSC_ROUTING_REGISTER, temp);
  467. return 0;
  468. }
  469. static int
  470. galmpsc_route_serial(int channel, int connect)
  471. {
  472. unsigned int temp;
  473. temp = GTREGREAD(GALMPSC_SERIAL_MULTIPLEX);
  474. if ((channel == 0) && connect)
  475. temp |= 0x00000100;
  476. else if ((channel == 1) && connect)
  477. temp |= 0x00001000;
  478. else if ((channel == 0) && !connect)
  479. temp &= ~0x00000100;
  480. else
  481. temp &= ~0x00001000;
  482. GT_REG_WRITE(GALMPSC_SERIAL_MULTIPLEX,temp);
  483. return 0;
  484. }
  485. static int
  486. galmpsc_route_rx_clock(int channel, int brg)
  487. {
  488. unsigned int temp;
  489. temp = GTREGREAD_MIRROR_G(GALMPSC_RxC_ROUTE);
  490. if (channel == 0)
  491. temp |= brg;
  492. else
  493. temp |= (brg << 8);
  494. GT_REG_WRITE_MIRROR_G(GALMPSC_RxC_ROUTE,temp);
  495. return 0;
  496. }
  497. static int
  498. galmpsc_route_tx_clock(int channel, int brg)
  499. {
  500. unsigned int temp;
  501. temp = GTREGREAD_MIRROR_G(GALMPSC_TxC_ROUTE);
  502. if (channel == 0)
  503. temp |= brg;
  504. else
  505. temp |= (brg << 8);
  506. GT_REG_WRITE_MIRROR_G(GALMPSC_TxC_ROUTE,temp);
  507. return 0;
  508. }
  509. static int
  510. galmpsc_write_config_regs(int mpsc, int mode)
  511. {
  512. if (mode == GALMPSC_UART) {
  513. /* Main config reg Low (Null modem, Enable Tx/Rx, UART mode) */
  514. GT_REG_WRITE(GALMPSC_MCONF_LOW + (mpsc*GALMPSC_REG_GAP),
  515. 0x000004c4);
  516. /* Main config reg High (32x Rx/Tx clock mode, width=8bits */
  517. GT_REG_WRITE(GALMPSC_MCONF_HIGH +(mpsc*GALMPSC_REG_GAP),
  518. 0x024003f8);
  519. /* 22 2222 1111 */
  520. /* 54 3210 9876 */
  521. /* 0000 0010 0000 0000 */
  522. /* 1 */
  523. /* 098 7654 3210 */
  524. /* 0000 0011 1111 1000 */
  525. } else
  526. return -1;
  527. return 0;
  528. }
  529. static int
  530. galmpsc_config_channel_regs(int mpsc)
  531. {
  532. GT_REG_WRITE_MIRROR(GALMPSC_CHANNELREG_1,mpsc,GALMPSC_REG_GAP, 0);
  533. GT_REG_WRITE_MIRROR(GALMPSC_CHANNELREG_2,mpsc,GALMPSC_REG_GAP, 0);
  534. GT_REG_WRITE(GALMPSC_CHANNELREG_3+(mpsc*GALMPSC_REG_GAP), 1);
  535. GT_REG_WRITE(GALMPSC_CHANNELREG_4+(mpsc*GALMPSC_REG_GAP), 0);
  536. GT_REG_WRITE(GALMPSC_CHANNELREG_5+(mpsc*GALMPSC_REG_GAP), 0);
  537. GT_REG_WRITE(GALMPSC_CHANNELREG_6+(mpsc*GALMPSC_REG_GAP), 0);
  538. GT_REG_WRITE(GALMPSC_CHANNELREG_7+(mpsc*GALMPSC_REG_GAP), 0);
  539. GT_REG_WRITE(GALMPSC_CHANNELREG_8+(mpsc*GALMPSC_REG_GAP), 0);
  540. GT_REG_WRITE(GALMPSC_CHANNELREG_9+(mpsc*GALMPSC_REG_GAP), 0);
  541. GT_REG_WRITE(GALMPSC_CHANNELREG_10+(mpsc*GALMPSC_REG_GAP), 0);
  542. galmpsc_set_brkcnt(mpsc, 0x3);
  543. galmpsc_set_tcschar(mpsc, 0xab);
  544. return 0;
  545. }
  546. static int
  547. galmpsc_set_brkcnt(int mpsc, int value)
  548. {
  549. unsigned int temp;
  550. temp = GTREGREAD_MIRROR(GALMPSC_CHANNELREG_1,mpsc,GALMPSC_REG_GAP);
  551. temp &= 0x0000FFFF;
  552. temp |= (value << 16);
  553. GT_REG_WRITE_MIRROR(GALMPSC_CHANNELREG_1,mpsc,GALMPSC_REG_GAP, temp);
  554. return 0;
  555. }
  556. static int
  557. galmpsc_set_tcschar(int mpsc, int value)
  558. {
  559. unsigned int temp;
  560. temp = GTREGREAD_MIRROR(GALMPSC_CHANNELREG_1,mpsc,GALMPSC_REG_GAP);
  561. temp &= 0xFFFF0000;
  562. temp |= value;
  563. GT_REG_WRITE_MIRROR(GALMPSC_CHANNELREG_1,mpsc,GALMPSC_REG_GAP, temp);
  564. return 0;
  565. }
  566. static int
  567. galmpsc_set_char_length(int mpsc, int value)
  568. {
  569. unsigned int temp;
  570. temp = GTREGREAD_MIRROR(GALMPSC_PROTOCONF_REG,mpsc,GALMPSC_REG_GAP);
  571. temp &= 0xFFFFCFFF;
  572. temp |= (value << 12);
  573. GT_REG_WRITE_MIRROR(GALMPSC_PROTOCONF_REG,mpsc,GALMPSC_REG_GAP, temp);
  574. return 0;
  575. }
  576. static int
  577. galmpsc_set_stop_bit_length(int mpsc, int value)
  578. {
  579. unsigned int temp;
  580. temp = GTREGREAD_MIRROR(GALMPSC_PROTOCONF_REG,mpsc,GALMPSC_REG_GAP);
  581. temp |= (value << 14);
  582. GT_REG_WRITE_MIRROR(GALMPSC_PROTOCONF_REG,mpsc,GALMPSC_REG_GAP,temp);
  583. return 0;
  584. }
  585. static int
  586. galmpsc_set_parity(int mpsc, int value)
  587. {
  588. unsigned int temp;
  589. temp = GTREGREAD_MIRROR(GALMPSC_CHANNELREG_2,mpsc,GALMPSC_REG_GAP);
  590. if (value != -1) {
  591. temp &= 0xFFF3FFF3;
  592. temp |= ((value << 18) | (value << 2));
  593. temp |= ((value << 17) | (value << 1));
  594. } else {
  595. temp &= 0xFFF1FFF1;
  596. }
  597. GT_REG_WRITE_MIRROR(GALMPSC_CHANNELREG_2,mpsc,GALMPSC_REG_GAP, temp);
  598. return 0;
  599. }
  600. static int
  601. galmpsc_enter_hunt(int mpsc)
  602. {
  603. int temp;
  604. temp = GTREGREAD_MIRROR(GALMPSC_CHANNELREG_2,mpsc,GALMPSC_REG_GAP);
  605. temp |= 0x80000000;
  606. GT_REG_WRITE_MIRROR(GALMPSC_CHANNELREG_2,mpsc,GALMPSC_REG_GAP, temp);
  607. /* Should Poll on Enter Hunt bit, but the register is write-only */
  608. /* errata suggests pausing 100 system cycles */
  609. udelay(100);
  610. return 0;
  611. }
  612. static int
  613. galmpsc_shutdown(int mpsc)
  614. {
  615. #if 0
  616. unsigned int temp;
  617. /* cause RX abort (clears RX) */
  618. temp = GTREGREAD_MIRROR(GALMPSC_CHANNELREG_2,mpsc,GALMPSC_REG_GAP);
  619. temp |= MPSC_RX_ABORT | MPSC_TX_ABORT;
  620. temp &= ~MPSC_ENTER_HUNT;
  621. GT_REG_WRITE_MIRROR(GALMPSC_CHANNELREG_2,mpsc,GALMPSC_REG_GAP,temp);
  622. #endif
  623. GT_REG_WRITE(GALSDMA_0_COM_REG + CHANNEL * GALSDMA_REG_DIFF, 0);
  624. GT_REG_WRITE(GALSDMA_0_COM_REG + CHANNEL * GALSDMA_REG_DIFF,
  625. SDMA_TX_ABORT | SDMA_RX_ABORT);
  626. /* shut down the MPSC */
  627. GT_REG_WRITE(GALMPSC_MCONF_LOW, 0);
  628. GT_REG_WRITE(GALMPSC_MCONF_HIGH, 0);
  629. GT_REG_WRITE_MIRROR(GALMPSC_PROTOCONF_REG, mpsc, GALMPSC_REG_GAP,0);
  630. udelay(100);
  631. /* shut down the sdma engines. */
  632. /* reset config to default */
  633. GT_REG_WRITE(GALSDMA_0_CONF_REG + CHANNEL * GALSDMA_REG_DIFF,
  634. 0x000000fc);
  635. udelay(100);
  636. /* clear the SDMA current and first TX and RX pointers */
  637. GT_REG_WRITE(GALSDMA_0_CUR_RX_PTR + CHANNEL * GALSDMA_REG_DIFF, 0);
  638. GT_REG_WRITE(GALSDMA_0_CUR_TX_PTR + CHANNEL * GALSDMA_REG_DIFF, 0);
  639. GT_REG_WRITE(GALSDMA_0_FIR_TX_PTR + CHANNEL * GALSDMA_REG_DIFF, 0);
  640. udelay(100);
  641. return 0;
  642. }
  643. static void
  644. galsdma_enable_rx(void)
  645. {
  646. int temp;
  647. /* Enable RX processing */
  648. temp = GTREGREAD(GALSDMA_0_COM_REG+(CHANNEL*GALSDMA_REG_DIFF));
  649. temp |= RX_ENABLE;
  650. GT_REG_WRITE(GALSDMA_0_COM_REG+(CHANNEL*GALSDMA_REG_DIFF), temp);
  651. galmpsc_enter_hunt(CHANNEL);
  652. }
  653. static int
  654. galmpsc_set_snoop(int mpsc, int value)
  655. {
  656. int reg = mpsc ? MPSC_1_ADDRESS_CONTROL_LOW : MPSC_0_ADDRESS_CONTROL_LOW;
  657. int temp=GTREGREAD(reg);
  658. if(value)
  659. temp |= (1<< 6) | (1<<14) | (1<<22) | (1<<30);
  660. else
  661. temp &= ~((1<< 6) | (1<<14) | (1<<22) | (1<<30));
  662. GT_REG_WRITE(reg, temp);
  663. return 0;
  664. }