mpsc.c 21 KB

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