setup.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158
  1. /*
  2. * linux/arch/mips/tx4938/toshiba_rbtx4938/setup.c
  3. *
  4. * Setup pointers to hardware-dependent routines.
  5. * Copyright (C) 2000-2001 Toshiba Corporation
  6. *
  7. * 2003-2005 (c) MontaVista Software, Inc. This file is licensed under the
  8. * terms of the GNU General Public License version 2. This program is
  9. * licensed "as is" without any warranty of any kind, whether express
  10. * or implied.
  11. *
  12. * Support for TX4938 in 2.6 - Manish Lachwani (mlachwani@mvista.com)
  13. */
  14. #include <linux/init.h>
  15. #include <linux/types.h>
  16. #include <linux/ioport.h>
  17. #include <linux/delay.h>
  18. #include <linux/interrupt.h>
  19. #include <linux/console.h>
  20. #include <linux/pci.h>
  21. #include <linux/pm.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/clk.h>
  24. #include <asm/wbflush.h>
  25. #include <asm/reboot.h>
  26. #include <asm/irq.h>
  27. #include <asm/time.h>
  28. #include <asm/txx9tmr.h>
  29. #include <asm/uaccess.h>
  30. #include <asm/io.h>
  31. #include <asm/bootinfo.h>
  32. #include <asm/tx4938/rbtx4938.h>
  33. #ifdef CONFIG_SERIAL_TXX9
  34. #include <linux/tty.h>
  35. #include <linux/serial.h>
  36. #include <linux/serial_core.h>
  37. #endif
  38. #include <linux/spi/spi.h>
  39. #include <asm/tx4938/spi.h>
  40. #include <asm/gpio.h>
  41. extern char * __init prom_getcmdline(void);
  42. static inline void tx4938_report_pcic_status1(struct tx4938_pcic_reg *pcicptr);
  43. /* These functions are used for rebooting or halting the machine*/
  44. extern void rbtx4938_machine_restart(char *command);
  45. extern void rbtx4938_machine_halt(void);
  46. extern void rbtx4938_machine_power_off(void);
  47. /* clocks */
  48. unsigned int txx9_master_clock;
  49. unsigned int txx9_cpu_clock;
  50. unsigned int txx9_gbus_clock;
  51. unsigned long rbtx4938_ce_base[8];
  52. unsigned long rbtx4938_ce_size[8];
  53. int txboard_pci66_mode;
  54. static int tx4938_pcic_trdyto; /* default: disabled */
  55. static int tx4938_pcic_retryto; /* default: disabled */
  56. static int tx4938_ccfg_toeon = 1;
  57. struct tx4938_pcic_reg *pcicptrs[4] = {
  58. tx4938_pcicptr /* default setting for TX4938 */
  59. };
  60. static struct {
  61. unsigned long base;
  62. unsigned long size;
  63. } phys_regions[16] __initdata;
  64. static int num_phys_regions __initdata;
  65. #define PHYS_REGION_MINSIZE 0x10000
  66. void rbtx4938_machine_halt(void)
  67. {
  68. printk(KERN_NOTICE "System Halted\n");
  69. local_irq_disable();
  70. while (1)
  71. __asm__(".set\tmips3\n\t"
  72. "wait\n\t"
  73. ".set\tmips0");
  74. }
  75. void rbtx4938_machine_power_off(void)
  76. {
  77. rbtx4938_machine_halt();
  78. /* no return */
  79. }
  80. void rbtx4938_machine_restart(char *command)
  81. {
  82. local_irq_disable();
  83. printk("Rebooting...");
  84. *rbtx4938_softresetlock_ptr = 1;
  85. *rbtx4938_sfvol_ptr = 1;
  86. *rbtx4938_softreset_ptr = 1;
  87. wbflush();
  88. while(1);
  89. }
  90. void __init
  91. txboard_add_phys_region(unsigned long base, unsigned long size)
  92. {
  93. if (num_phys_regions >= ARRAY_SIZE(phys_regions)) {
  94. printk("phys_region overflow\n");
  95. return;
  96. }
  97. phys_regions[num_phys_regions].base = base;
  98. phys_regions[num_phys_regions].size = size;
  99. num_phys_regions++;
  100. }
  101. unsigned long __init
  102. txboard_find_free_phys_region(unsigned long begin, unsigned long end,
  103. unsigned long size)
  104. {
  105. unsigned long base;
  106. int i;
  107. for (base = begin / size * size; base < end; base += size) {
  108. for (i = 0; i < num_phys_regions; i++) {
  109. if (phys_regions[i].size &&
  110. base <= phys_regions[i].base + (phys_regions[i].size - 1) &&
  111. base + (size - 1) >= phys_regions[i].base)
  112. break;
  113. }
  114. if (i == num_phys_regions)
  115. return base;
  116. }
  117. return 0;
  118. }
  119. unsigned long __init
  120. txboard_find_free_phys_region_shrink(unsigned long begin, unsigned long end,
  121. unsigned long *size)
  122. {
  123. unsigned long sz, base;
  124. for (sz = *size; sz >= PHYS_REGION_MINSIZE; sz /= 2) {
  125. base = txboard_find_free_phys_region(begin, end, sz);
  126. if (base) {
  127. *size = sz;
  128. return base;
  129. }
  130. }
  131. return 0;
  132. }
  133. unsigned long __init
  134. txboard_request_phys_region_range(unsigned long begin, unsigned long end,
  135. unsigned long size)
  136. {
  137. unsigned long base;
  138. base = txboard_find_free_phys_region(begin, end, size);
  139. if (base)
  140. txboard_add_phys_region(base, size);
  141. return base;
  142. }
  143. unsigned long __init
  144. txboard_request_phys_region(unsigned long size)
  145. {
  146. unsigned long base;
  147. unsigned long begin = 0, end = 0x20000000; /* search low 512MB */
  148. base = txboard_find_free_phys_region(begin, end, size);
  149. if (base)
  150. txboard_add_phys_region(base, size);
  151. return base;
  152. }
  153. unsigned long __init
  154. txboard_request_phys_region_shrink(unsigned long *size)
  155. {
  156. unsigned long base;
  157. unsigned long begin = 0, end = 0x20000000; /* search low 512MB */
  158. base = txboard_find_free_phys_region_shrink(begin, end, size);
  159. if (base)
  160. txboard_add_phys_region(base, *size);
  161. return base;
  162. }
  163. #ifdef CONFIG_PCI
  164. void __init
  165. tx4938_pcic_setup(struct tx4938_pcic_reg *pcicptr,
  166. struct pci_controller *channel,
  167. unsigned long pci_io_base,
  168. int extarb)
  169. {
  170. int i;
  171. /* Disable All Initiator Space */
  172. pcicptr->pciccfg &= ~(TX4938_PCIC_PCICCFG_G2PMEN(0)|
  173. TX4938_PCIC_PCICCFG_G2PMEN(1)|
  174. TX4938_PCIC_PCICCFG_G2PMEN(2)|
  175. TX4938_PCIC_PCICCFG_G2PIOEN);
  176. /* GB->PCI mappings */
  177. pcicptr->g2piomask = (channel->io_resource->end - channel->io_resource->start) >> 4;
  178. pcicptr->g2piogbase = pci_io_base |
  179. #ifdef __BIG_ENDIAN
  180. TX4938_PCIC_G2PIOGBASE_ECHG
  181. #else
  182. TX4938_PCIC_G2PIOGBASE_BSDIS
  183. #endif
  184. ;
  185. pcicptr->g2piopbase = 0;
  186. for (i = 0; i < 3; i++) {
  187. pcicptr->g2pmmask[i] = 0;
  188. pcicptr->g2pmgbase[i] = 0;
  189. pcicptr->g2pmpbase[i] = 0;
  190. }
  191. if (channel->mem_resource->end) {
  192. pcicptr->g2pmmask[0] = (channel->mem_resource->end - channel->mem_resource->start) >> 4;
  193. pcicptr->g2pmgbase[0] = channel->mem_resource->start |
  194. #ifdef __BIG_ENDIAN
  195. TX4938_PCIC_G2PMnGBASE_ECHG
  196. #else
  197. TX4938_PCIC_G2PMnGBASE_BSDIS
  198. #endif
  199. ;
  200. pcicptr->g2pmpbase[0] = channel->mem_resource->start;
  201. }
  202. /* PCI->GB mappings (I/O 256B) */
  203. pcicptr->p2giopbase = 0; /* 256B */
  204. pcicptr->p2giogbase = 0;
  205. /* PCI->GB mappings (MEM 512MB (64MB on R1.x)) */
  206. pcicptr->p2gm0plbase = 0;
  207. pcicptr->p2gm0pubase = 0;
  208. pcicptr->p2gmgbase[0] = 0 |
  209. TX4938_PCIC_P2GMnGBASE_TMEMEN |
  210. #ifdef __BIG_ENDIAN
  211. TX4938_PCIC_P2GMnGBASE_TECHG
  212. #else
  213. TX4938_PCIC_P2GMnGBASE_TBSDIS
  214. #endif
  215. ;
  216. /* PCI->GB mappings (MEM 16MB) */
  217. pcicptr->p2gm1plbase = 0xffffffff;
  218. pcicptr->p2gm1pubase = 0xffffffff;
  219. pcicptr->p2gmgbase[1] = 0;
  220. /* PCI->GB mappings (MEM 1MB) */
  221. pcicptr->p2gm2pbase = 0xffffffff; /* 1MB */
  222. pcicptr->p2gmgbase[2] = 0;
  223. pcicptr->pciccfg &= TX4938_PCIC_PCICCFG_GBWC_MASK;
  224. /* Enable Initiator Memory Space */
  225. if (channel->mem_resource->end)
  226. pcicptr->pciccfg |= TX4938_PCIC_PCICCFG_G2PMEN(0);
  227. /* Enable Initiator I/O Space */
  228. if (channel->io_resource->end)
  229. pcicptr->pciccfg |= TX4938_PCIC_PCICCFG_G2PIOEN;
  230. /* Enable Initiator Config */
  231. pcicptr->pciccfg |=
  232. TX4938_PCIC_PCICCFG_ICAEN |
  233. TX4938_PCIC_PCICCFG_TCAR;
  234. /* Do not use MEMMUL, MEMINF: YMFPCI card causes M_ABORT. */
  235. pcicptr->pcicfg1 = 0;
  236. pcicptr->g2ptocnt &= ~0xffff;
  237. if (tx4938_pcic_trdyto >= 0) {
  238. pcicptr->g2ptocnt &= ~0xff;
  239. pcicptr->g2ptocnt |= (tx4938_pcic_trdyto & 0xff);
  240. }
  241. if (tx4938_pcic_retryto >= 0) {
  242. pcicptr->g2ptocnt &= ~0xff00;
  243. pcicptr->g2ptocnt |= ((tx4938_pcic_retryto<<8) & 0xff00);
  244. }
  245. /* Clear All Local Bus Status */
  246. pcicptr->pcicstatus = TX4938_PCIC_PCICSTATUS_ALL;
  247. /* Enable All Local Bus Interrupts */
  248. pcicptr->pcicmask = TX4938_PCIC_PCICSTATUS_ALL;
  249. /* Clear All Initiator Status */
  250. pcicptr->g2pstatus = TX4938_PCIC_G2PSTATUS_ALL;
  251. /* Enable All Initiator Interrupts */
  252. pcicptr->g2pmask = TX4938_PCIC_G2PSTATUS_ALL;
  253. /* Clear All PCI Status Error */
  254. pcicptr->pcistatus =
  255. (pcicptr->pcistatus & 0x0000ffff) |
  256. (TX4938_PCIC_PCISTATUS_ALL << 16);
  257. /* Enable All PCI Status Error Interrupts */
  258. pcicptr->pcimask = TX4938_PCIC_PCISTATUS_ALL;
  259. if (!extarb) {
  260. /* Reset Bus Arbiter */
  261. pcicptr->pbacfg = TX4938_PCIC_PBACFG_RPBA;
  262. pcicptr->pbabm = 0;
  263. /* Enable Bus Arbiter */
  264. pcicptr->pbacfg = TX4938_PCIC_PBACFG_PBAEN;
  265. }
  266. /* PCIC Int => IRC IRQ16 */
  267. pcicptr->pcicfg2 =
  268. (pcicptr->pcicfg2 & 0xffffff00) | TX4938_IR_PCIC;
  269. pcicptr->pcistatus = PCI_COMMAND_MASTER |
  270. PCI_COMMAND_MEMORY |
  271. PCI_COMMAND_PARITY | PCI_COMMAND_SERR;
  272. }
  273. int __init
  274. tx4938_report_pciclk(void)
  275. {
  276. unsigned long pcode = TX4938_REV_PCODE();
  277. int pciclk = 0;
  278. printk("TX%lx PCIC --%s PCICLK:",
  279. pcode,
  280. (tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI66) ? " PCI66" : "");
  281. if (tx4938_ccfgptr->pcfg & TX4938_PCFG_PCICLKEN_ALL) {
  282. switch ((unsigned long)tx4938_ccfgptr->ccfg & TX4938_CCFG_PCIDIVMODE_MASK) {
  283. case TX4938_CCFG_PCIDIVMODE_4:
  284. pciclk = txx9_cpu_clock / 4; break;
  285. case TX4938_CCFG_PCIDIVMODE_4_5:
  286. pciclk = txx9_cpu_clock * 2 / 9; break;
  287. case TX4938_CCFG_PCIDIVMODE_5:
  288. pciclk = txx9_cpu_clock / 5; break;
  289. case TX4938_CCFG_PCIDIVMODE_5_5:
  290. pciclk = txx9_cpu_clock * 2 / 11; break;
  291. case TX4938_CCFG_PCIDIVMODE_8:
  292. pciclk = txx9_cpu_clock / 8; break;
  293. case TX4938_CCFG_PCIDIVMODE_9:
  294. pciclk = txx9_cpu_clock / 9; break;
  295. case TX4938_CCFG_PCIDIVMODE_10:
  296. pciclk = txx9_cpu_clock / 10; break;
  297. case TX4938_CCFG_PCIDIVMODE_11:
  298. pciclk = txx9_cpu_clock / 11; break;
  299. }
  300. printk("Internal(%dMHz)", pciclk / 1000000);
  301. } else {
  302. printk("External");
  303. pciclk = -1;
  304. }
  305. printk("\n");
  306. return pciclk;
  307. }
  308. void __init set_tx4938_pcicptr(int ch, struct tx4938_pcic_reg *pcicptr)
  309. {
  310. pcicptrs[ch] = pcicptr;
  311. }
  312. struct tx4938_pcic_reg *get_tx4938_pcicptr(int ch)
  313. {
  314. return pcicptrs[ch];
  315. }
  316. static struct pci_dev *fake_pci_dev(struct pci_controller *hose,
  317. int top_bus, int busnr, int devfn)
  318. {
  319. static struct pci_dev dev;
  320. static struct pci_bus bus;
  321. dev.sysdata = bus.sysdata = hose;
  322. dev.devfn = devfn;
  323. bus.number = busnr;
  324. bus.ops = hose->pci_ops;
  325. bus.parent = NULL;
  326. dev.bus = &bus;
  327. return &dev;
  328. }
  329. #define EARLY_PCI_OP(rw, size, type) \
  330. static int early_##rw##_config_##size(struct pci_controller *hose, \
  331. int top_bus, int bus, int devfn, int offset, type value) \
  332. { \
  333. return pci_##rw##_config_##size( \
  334. fake_pci_dev(hose, top_bus, bus, devfn), \
  335. offset, value); \
  336. }
  337. EARLY_PCI_OP(read, word, u16 *)
  338. int txboard_pci66_check(struct pci_controller *hose, int top_bus, int current_bus)
  339. {
  340. u32 pci_devfn;
  341. unsigned short vid;
  342. int devfn_start = 0;
  343. int devfn_stop = 0xff;
  344. int cap66 = -1;
  345. u16 stat;
  346. printk("PCI: Checking 66MHz capabilities...\n");
  347. for (pci_devfn=devfn_start; pci_devfn<devfn_stop; pci_devfn++) {
  348. if (early_read_config_word(hose, top_bus, current_bus,
  349. pci_devfn, PCI_VENDOR_ID,
  350. &vid) != PCIBIOS_SUCCESSFUL)
  351. continue;
  352. if (vid == 0xffff) continue;
  353. /* check 66MHz capability */
  354. if (cap66 < 0)
  355. cap66 = 1;
  356. if (cap66) {
  357. early_read_config_word(hose, top_bus, current_bus, pci_devfn,
  358. PCI_STATUS, &stat);
  359. if (!(stat & PCI_STATUS_66MHZ)) {
  360. printk(KERN_DEBUG "PCI: %02x:%02x not 66MHz capable.\n",
  361. current_bus, pci_devfn);
  362. cap66 = 0;
  363. break;
  364. }
  365. }
  366. }
  367. return cap66 > 0;
  368. }
  369. int __init
  370. tx4938_pciclk66_setup(void)
  371. {
  372. int pciclk;
  373. /* Assert M66EN */
  374. tx4938_ccfgptr->ccfg |= TX4938_CCFG_PCI66;
  375. /* Double PCICLK (if possible) */
  376. if (tx4938_ccfgptr->pcfg & TX4938_PCFG_PCICLKEN_ALL) {
  377. unsigned int pcidivmode =
  378. tx4938_ccfgptr->ccfg & TX4938_CCFG_PCIDIVMODE_MASK;
  379. switch (pcidivmode) {
  380. case TX4938_CCFG_PCIDIVMODE_8:
  381. case TX4938_CCFG_PCIDIVMODE_4:
  382. pcidivmode = TX4938_CCFG_PCIDIVMODE_4;
  383. pciclk = txx9_cpu_clock / 4;
  384. break;
  385. case TX4938_CCFG_PCIDIVMODE_9:
  386. case TX4938_CCFG_PCIDIVMODE_4_5:
  387. pcidivmode = TX4938_CCFG_PCIDIVMODE_4_5;
  388. pciclk = txx9_cpu_clock * 2 / 9;
  389. break;
  390. case TX4938_CCFG_PCIDIVMODE_10:
  391. case TX4938_CCFG_PCIDIVMODE_5:
  392. pcidivmode = TX4938_CCFG_PCIDIVMODE_5;
  393. pciclk = txx9_cpu_clock / 5;
  394. break;
  395. case TX4938_CCFG_PCIDIVMODE_11:
  396. case TX4938_CCFG_PCIDIVMODE_5_5:
  397. default:
  398. pcidivmode = TX4938_CCFG_PCIDIVMODE_5_5;
  399. pciclk = txx9_cpu_clock * 2 / 11;
  400. break;
  401. }
  402. tx4938_ccfgptr->ccfg =
  403. (tx4938_ccfgptr->ccfg & ~TX4938_CCFG_PCIDIVMODE_MASK)
  404. | pcidivmode;
  405. printk(KERN_DEBUG "PCICLK: ccfg:%08lx\n",
  406. (unsigned long)tx4938_ccfgptr->ccfg);
  407. } else {
  408. pciclk = -1;
  409. }
  410. return pciclk;
  411. }
  412. extern struct pci_controller tx4938_pci_controller[];
  413. static int __init tx4938_pcibios_init(void)
  414. {
  415. unsigned long mem_base[2];
  416. unsigned long mem_size[2] = {TX4938_PCIMEM_SIZE_0, TX4938_PCIMEM_SIZE_1}; /* MAX 128M,64K */
  417. unsigned long io_base[2];
  418. unsigned long io_size[2] = {TX4938_PCIIO_SIZE_0, TX4938_PCIIO_SIZE_1}; /* MAX 16M,64K */
  419. /* TX4938 PCIC1: 64K MEM/IO is enough for ETH0,ETH1 */
  420. int extarb = !(tx4938_ccfgptr->ccfg & TX4938_CCFG_PCIXARB);
  421. PCIBIOS_MIN_IO = 0x00001000UL;
  422. mem_base[0] = txboard_request_phys_region_shrink(&mem_size[0]);
  423. io_base[0] = txboard_request_phys_region_shrink(&io_size[0]);
  424. printk("TX4938 PCIC -- DID:%04x VID:%04x RID:%02x Arbiter:%s\n",
  425. (unsigned short)(tx4938_pcicptr->pciid >> 16),
  426. (unsigned short)(tx4938_pcicptr->pciid & 0xffff),
  427. (unsigned short)(tx4938_pcicptr->pciccrev & 0xff),
  428. extarb ? "External" : "Internal");
  429. /* setup PCI area */
  430. tx4938_pci_controller[0].io_resource->start = io_base[0];
  431. tx4938_pci_controller[0].io_resource->end = (io_base[0] + io_size[0]) - 1;
  432. tx4938_pci_controller[0].mem_resource->start = mem_base[0];
  433. tx4938_pci_controller[0].mem_resource->end = mem_base[0] + mem_size[0] - 1;
  434. set_tx4938_pcicptr(0, tx4938_pcicptr);
  435. register_pci_controller(&tx4938_pci_controller[0]);
  436. if (tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI66) {
  437. printk("TX4938_CCFG_PCI66 already configured\n");
  438. txboard_pci66_mode = -1; /* already configured */
  439. }
  440. /* Reset PCI Bus */
  441. *rbtx4938_pcireset_ptr = 0;
  442. /* Reset PCIC */
  443. tx4938_ccfgptr->clkctr |= TX4938_CLKCTR_PCIRST;
  444. if (txboard_pci66_mode > 0)
  445. tx4938_pciclk66_setup();
  446. mdelay(10);
  447. /* clear PCIC reset */
  448. tx4938_ccfgptr->clkctr &= ~TX4938_CLKCTR_PCIRST;
  449. *rbtx4938_pcireset_ptr = 1;
  450. wbflush();
  451. tx4938_report_pcic_status1(tx4938_pcicptr);
  452. tx4938_report_pciclk();
  453. tx4938_pcic_setup(tx4938_pcicptr, &tx4938_pci_controller[0], io_base[0], extarb);
  454. if (txboard_pci66_mode == 0 &&
  455. txboard_pci66_check(&tx4938_pci_controller[0], 0, 0)) {
  456. /* Reset PCI Bus */
  457. *rbtx4938_pcireset_ptr = 0;
  458. /* Reset PCIC */
  459. tx4938_ccfgptr->clkctr |= TX4938_CLKCTR_PCIRST;
  460. tx4938_pciclk66_setup();
  461. mdelay(10);
  462. /* clear PCIC reset */
  463. tx4938_ccfgptr->clkctr &= ~TX4938_CLKCTR_PCIRST;
  464. *rbtx4938_pcireset_ptr = 1;
  465. wbflush();
  466. /* Reinitialize PCIC */
  467. tx4938_report_pciclk();
  468. tx4938_pcic_setup(tx4938_pcicptr, &tx4938_pci_controller[0], io_base[0], extarb);
  469. }
  470. mem_base[1] = txboard_request_phys_region_shrink(&mem_size[1]);
  471. io_base[1] = txboard_request_phys_region_shrink(&io_size[1]);
  472. /* Reset PCIC1 */
  473. tx4938_ccfgptr->clkctr |= TX4938_CLKCTR_PCIC1RST;
  474. /* PCI1DMD==0 => PCI1CLK==GBUSCLK/2 => PCI66 */
  475. if (!(tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI1DMD))
  476. tx4938_ccfgptr->ccfg |= TX4938_CCFG_PCI1_66;
  477. else
  478. tx4938_ccfgptr->ccfg &= ~TX4938_CCFG_PCI1_66;
  479. mdelay(10);
  480. /* clear PCIC1 reset */
  481. tx4938_ccfgptr->clkctr &= ~TX4938_CLKCTR_PCIC1RST;
  482. tx4938_report_pcic_status1(tx4938_pcic1ptr);
  483. printk("TX4938 PCIC1 -- DID:%04x VID:%04x RID:%02x",
  484. (unsigned short)(tx4938_pcic1ptr->pciid >> 16),
  485. (unsigned short)(tx4938_pcic1ptr->pciid & 0xffff),
  486. (unsigned short)(tx4938_pcic1ptr->pciccrev & 0xff));
  487. printk("%s PCICLK:%dMHz\n",
  488. (tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI1_66) ? " PCI66" : "",
  489. txx9_gbus_clock /
  490. ((tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI1DMD) ? 4 : 2) /
  491. 1000000);
  492. /* assumption: CPHYSADDR(mips_io_port_base) == io_base[0] */
  493. tx4938_pci_controller[1].io_resource->start =
  494. io_base[1] - io_base[0];
  495. tx4938_pci_controller[1].io_resource->end =
  496. io_base[1] - io_base[0] + io_size[1] - 1;
  497. tx4938_pci_controller[1].mem_resource->start = mem_base[1];
  498. tx4938_pci_controller[1].mem_resource->end =
  499. mem_base[1] + mem_size[1] - 1;
  500. set_tx4938_pcicptr(1, tx4938_pcic1ptr);
  501. register_pci_controller(&tx4938_pci_controller[1]);
  502. tx4938_pcic_setup(tx4938_pcic1ptr, &tx4938_pci_controller[1], io_base[1], extarb);
  503. /* map ioport 0 to PCI I/O space address 0 */
  504. set_io_port_base(KSEG1 + io_base[0]);
  505. return 0;
  506. }
  507. arch_initcall(tx4938_pcibios_init);
  508. #endif /* CONFIG_PCI */
  509. /* SPI support */
  510. /* chip select for SPI devices */
  511. #define SEEPROM1_CS 7 /* PIO7 */
  512. #define SEEPROM2_CS 0 /* IOC */
  513. #define SEEPROM3_CS 1 /* IOC */
  514. #define SRTC_CS 2 /* IOC */
  515. #ifdef CONFIG_PCI
  516. static int __init rbtx4938_ethaddr_init(void)
  517. {
  518. unsigned char dat[17];
  519. unsigned char sum;
  520. int i;
  521. /* 0-3: "MAC\0", 4-9:eth0, 10-15:eth1, 16:sum */
  522. if (spi_eeprom_read(SEEPROM1_CS, 0, dat, sizeof(dat))) {
  523. printk(KERN_ERR "seeprom: read error.\n");
  524. return -ENODEV;
  525. } else {
  526. if (strcmp(dat, "MAC") != 0)
  527. printk(KERN_WARNING "seeprom: bad signature.\n");
  528. for (i = 0, sum = 0; i < sizeof(dat); i++)
  529. sum += dat[i];
  530. if (sum)
  531. printk(KERN_WARNING "seeprom: bad checksum.\n");
  532. }
  533. for (i = 0; i < 2; i++) {
  534. unsigned int id =
  535. TXX9_IRQ_BASE + (i ? TX4938_IR_ETH1 : TX4938_IR_ETH0);
  536. struct platform_device *pdev;
  537. if (!(tx4938_ccfgptr->pcfg &
  538. (i ? TX4938_PCFG_ETH1_SEL : TX4938_PCFG_ETH0_SEL)))
  539. continue;
  540. pdev = platform_device_alloc("tc35815-mac", id);
  541. if (!pdev ||
  542. platform_device_add_data(pdev, &dat[4 + 6 * i], 6) ||
  543. platform_device_add(pdev))
  544. platform_device_put(pdev);
  545. }
  546. return 0;
  547. }
  548. device_initcall(rbtx4938_ethaddr_init);
  549. #endif /* CONFIG_PCI */
  550. static void __init rbtx4938_spi_setup(void)
  551. {
  552. /* set SPI_SEL */
  553. tx4938_ccfgptr->pcfg |= TX4938_PCFG_SPI_SEL;
  554. /* chip selects for SPI devices */
  555. tx4938_pioptr->dout |= (1 << SEEPROM1_CS);
  556. tx4938_pioptr->dir |= (1 << SEEPROM1_CS);
  557. }
  558. static struct resource rbtx4938_fpga_resource;
  559. static char pcode_str[8];
  560. static struct resource tx4938_reg_resource = {
  561. .start = TX4938_REG_BASE,
  562. .end = TX4938_REG_BASE + TX4938_REG_SIZE,
  563. .name = pcode_str,
  564. .flags = IORESOURCE_MEM
  565. };
  566. void __init tx4938_board_setup(void)
  567. {
  568. int i;
  569. unsigned long divmode;
  570. int cpuclk = 0;
  571. unsigned long pcode = TX4938_REV_PCODE();
  572. ioport_resource.start = 0x1000;
  573. ioport_resource.end = 0xffffffff;
  574. iomem_resource.start = 0x1000;
  575. iomem_resource.end = 0xffffffff; /* expand to 4GB */
  576. sprintf(pcode_str, "TX%lx", pcode);
  577. /* SDRAMC,EBUSC are configured by PROM */
  578. for (i = 0; i < 8; i++) {
  579. if (!(tx4938_ebuscptr->cr[i] & 0x8))
  580. continue; /* disabled */
  581. rbtx4938_ce_base[i] = (unsigned long)TX4938_EBUSC_BA(i);
  582. txboard_add_phys_region(rbtx4938_ce_base[i], TX4938_EBUSC_SIZE(i));
  583. }
  584. /* clocks */
  585. if (txx9_master_clock) {
  586. /* calculate gbus_clock and cpu_clock_freq from master_clock */
  587. divmode = (unsigned long)tx4938_ccfgptr->ccfg & TX4938_CCFG_DIVMODE_MASK;
  588. switch (divmode) {
  589. case TX4938_CCFG_DIVMODE_8:
  590. case TX4938_CCFG_DIVMODE_10:
  591. case TX4938_CCFG_DIVMODE_12:
  592. case TX4938_CCFG_DIVMODE_16:
  593. case TX4938_CCFG_DIVMODE_18:
  594. txx9_gbus_clock = txx9_master_clock * 4; break;
  595. default:
  596. txx9_gbus_clock = txx9_master_clock;
  597. }
  598. switch (divmode) {
  599. case TX4938_CCFG_DIVMODE_2:
  600. case TX4938_CCFG_DIVMODE_8:
  601. cpuclk = txx9_gbus_clock * 2; break;
  602. case TX4938_CCFG_DIVMODE_2_5:
  603. case TX4938_CCFG_DIVMODE_10:
  604. cpuclk = txx9_gbus_clock * 5 / 2; break;
  605. case TX4938_CCFG_DIVMODE_3:
  606. case TX4938_CCFG_DIVMODE_12:
  607. cpuclk = txx9_gbus_clock * 3; break;
  608. case TX4938_CCFG_DIVMODE_4:
  609. case TX4938_CCFG_DIVMODE_16:
  610. cpuclk = txx9_gbus_clock * 4; break;
  611. case TX4938_CCFG_DIVMODE_4_5:
  612. case TX4938_CCFG_DIVMODE_18:
  613. cpuclk = txx9_gbus_clock * 9 / 2; break;
  614. }
  615. txx9_cpu_clock = cpuclk;
  616. } else {
  617. if (txx9_cpu_clock == 0) {
  618. txx9_cpu_clock = 300000000; /* 300MHz */
  619. }
  620. /* calculate gbus_clock and master_clock from cpu_clock_freq */
  621. cpuclk = txx9_cpu_clock;
  622. divmode = (unsigned long)tx4938_ccfgptr->ccfg & TX4938_CCFG_DIVMODE_MASK;
  623. switch (divmode) {
  624. case TX4938_CCFG_DIVMODE_2:
  625. case TX4938_CCFG_DIVMODE_8:
  626. txx9_gbus_clock = cpuclk / 2; break;
  627. case TX4938_CCFG_DIVMODE_2_5:
  628. case TX4938_CCFG_DIVMODE_10:
  629. txx9_gbus_clock = cpuclk * 2 / 5; break;
  630. case TX4938_CCFG_DIVMODE_3:
  631. case TX4938_CCFG_DIVMODE_12:
  632. txx9_gbus_clock = cpuclk / 3; break;
  633. case TX4938_CCFG_DIVMODE_4:
  634. case TX4938_CCFG_DIVMODE_16:
  635. txx9_gbus_clock = cpuclk / 4; break;
  636. case TX4938_CCFG_DIVMODE_4_5:
  637. case TX4938_CCFG_DIVMODE_18:
  638. txx9_gbus_clock = cpuclk * 2 / 9; break;
  639. }
  640. switch (divmode) {
  641. case TX4938_CCFG_DIVMODE_8:
  642. case TX4938_CCFG_DIVMODE_10:
  643. case TX4938_CCFG_DIVMODE_12:
  644. case TX4938_CCFG_DIVMODE_16:
  645. case TX4938_CCFG_DIVMODE_18:
  646. txx9_master_clock = txx9_gbus_clock / 4; break;
  647. default:
  648. txx9_master_clock = txx9_gbus_clock;
  649. }
  650. }
  651. /* change default value to udelay/mdelay take reasonable time */
  652. loops_per_jiffy = txx9_cpu_clock / HZ / 2;
  653. /* CCFG */
  654. /* clear WatchDogReset,BusErrorOnWrite flag (W1C) */
  655. tx4938_ccfgptr->ccfg |= TX4938_CCFG_WDRST | TX4938_CCFG_BEOW;
  656. /* clear PCIC1 reset */
  657. if (tx4938_ccfgptr->clkctr & TX4938_CLKCTR_PCIC1RST)
  658. tx4938_ccfgptr->clkctr &= ~TX4938_CLKCTR_PCIC1RST;
  659. /* enable Timeout BusError */
  660. if (tx4938_ccfg_toeon)
  661. tx4938_ccfgptr->ccfg |= TX4938_CCFG_TOE;
  662. /* DMA selection */
  663. tx4938_ccfgptr->pcfg &= ~TX4938_PCFG_DMASEL_ALL;
  664. /* Use external clock for external arbiter */
  665. if (!(tx4938_ccfgptr->ccfg & TX4938_CCFG_PCIXARB))
  666. tx4938_ccfgptr->pcfg &= ~TX4938_PCFG_PCICLKEN_ALL;
  667. printk("%s -- %dMHz(M%dMHz) CRIR:%08lx CCFG:%Lx PCFG:%Lx\n",
  668. pcode_str,
  669. cpuclk / 1000000, txx9_master_clock / 1000000,
  670. (unsigned long)tx4938_ccfgptr->crir,
  671. tx4938_ccfgptr->ccfg,
  672. tx4938_ccfgptr->pcfg);
  673. printk("%s SDRAMC --", pcode_str);
  674. for (i = 0; i < 4; i++) {
  675. unsigned long long cr = tx4938_sdramcptr->cr[i];
  676. unsigned long ram_base, ram_size;
  677. if (!((unsigned long)cr & 0x00000400))
  678. continue; /* disabled */
  679. ram_base = (unsigned long)(cr >> 49) << 21;
  680. ram_size = ((unsigned long)(cr >> 33) + 1) << 21;
  681. if (ram_base >= 0x20000000)
  682. continue; /* high memory (ignore) */
  683. printk(" CR%d:%016Lx", i, cr);
  684. txboard_add_phys_region(ram_base, ram_size);
  685. }
  686. printk(" TR:%09Lx\n", tx4938_sdramcptr->tr);
  687. /* SRAM */
  688. if (pcode == 0x4938 && tx4938_sramcptr->cr & 1) {
  689. unsigned int size = 0x800;
  690. unsigned long base =
  691. (tx4938_sramcptr->cr >> (39-11)) & ~(size - 1);
  692. txboard_add_phys_region(base, size);
  693. }
  694. /* TMR */
  695. for (i = 0; i < TX4938_NR_TMR; i++)
  696. txx9_tmr_init(TX4938_TMR_REG(i) & 0xfffffffffULL);
  697. /* enable DMA */
  698. TX4938_WR64(0xff1fb150, TX4938_DMA_MCR_MSTEN);
  699. TX4938_WR64(0xff1fb950, TX4938_DMA_MCR_MSTEN);
  700. /* PIO */
  701. tx4938_pioptr->maskcpu = 0;
  702. tx4938_pioptr->maskext = 0;
  703. /* TX4938 internal registers */
  704. if (request_resource(&iomem_resource, &tx4938_reg_resource))
  705. printk("request resource for internal registers failed\n");
  706. }
  707. #ifdef CONFIG_PCI
  708. static inline void tx4938_report_pcic_status1(struct tx4938_pcic_reg *pcicptr)
  709. {
  710. unsigned short pcistatus = (unsigned short)(pcicptr->pcistatus >> 16);
  711. unsigned long g2pstatus = pcicptr->g2pstatus;
  712. unsigned long pcicstatus = pcicptr->pcicstatus;
  713. static struct {
  714. unsigned long flag;
  715. const char *str;
  716. } pcistat_tbl[] = {
  717. { PCI_STATUS_DETECTED_PARITY, "DetectedParityError" },
  718. { PCI_STATUS_SIG_SYSTEM_ERROR, "SignaledSystemError" },
  719. { PCI_STATUS_REC_MASTER_ABORT, "ReceivedMasterAbort" },
  720. { PCI_STATUS_REC_TARGET_ABORT, "ReceivedTargetAbort" },
  721. { PCI_STATUS_SIG_TARGET_ABORT, "SignaledTargetAbort" },
  722. { PCI_STATUS_PARITY, "MasterParityError" },
  723. }, g2pstat_tbl[] = {
  724. { TX4938_PCIC_G2PSTATUS_TTOE, "TIOE" },
  725. { TX4938_PCIC_G2PSTATUS_RTOE, "RTOE" },
  726. }, pcicstat_tbl[] = {
  727. { TX4938_PCIC_PCICSTATUS_PME, "PME" },
  728. { TX4938_PCIC_PCICSTATUS_TLB, "TLB" },
  729. { TX4938_PCIC_PCICSTATUS_NIB, "NIB" },
  730. { TX4938_PCIC_PCICSTATUS_ZIB, "ZIB" },
  731. { TX4938_PCIC_PCICSTATUS_PERR, "PERR" },
  732. { TX4938_PCIC_PCICSTATUS_SERR, "SERR" },
  733. { TX4938_PCIC_PCICSTATUS_GBE, "GBE" },
  734. { TX4938_PCIC_PCICSTATUS_IWB, "IWB" },
  735. };
  736. int i;
  737. printk("pcistat:%04x(", pcistatus);
  738. for (i = 0; i < ARRAY_SIZE(pcistat_tbl); i++)
  739. if (pcistatus & pcistat_tbl[i].flag)
  740. printk("%s ", pcistat_tbl[i].str);
  741. printk("), g2pstatus:%08lx(", g2pstatus);
  742. for (i = 0; i < ARRAY_SIZE(g2pstat_tbl); i++)
  743. if (g2pstatus & g2pstat_tbl[i].flag)
  744. printk("%s ", g2pstat_tbl[i].str);
  745. printk("), pcicstatus:%08lx(", pcicstatus);
  746. for (i = 0; i < ARRAY_SIZE(pcicstat_tbl); i++)
  747. if (pcicstatus & pcicstat_tbl[i].flag)
  748. printk("%s ", pcicstat_tbl[i].str);
  749. printk(")\n");
  750. }
  751. void tx4938_report_pcic_status(void)
  752. {
  753. int i;
  754. struct tx4938_pcic_reg *pcicptr;
  755. for (i = 0; (pcicptr = get_tx4938_pcicptr(i)) != NULL; i++)
  756. tx4938_report_pcic_status1(pcicptr);
  757. }
  758. #endif /* CONFIG_PCI */
  759. void __init plat_time_init(void)
  760. {
  761. mips_hpt_frequency = txx9_cpu_clock / 2;
  762. if (tx4938_ccfgptr->ccfg & TX4938_CCFG_TINTDIS)
  763. txx9_clockevent_init(TX4938_TMR_REG(0) & 0xfffffffffULL,
  764. TXX9_IRQ_BASE + TX4938_IR_TMR(0),
  765. txx9_gbus_clock / 2);
  766. }
  767. void __init toshiba_rbtx4938_setup(void)
  768. {
  769. unsigned long long pcfg;
  770. char *argptr;
  771. iomem_resource.end = 0xffffffff; /* 4GB */
  772. if (txx9_master_clock == 0)
  773. txx9_master_clock = 25000000; /* 25MHz */
  774. tx4938_board_setup();
  775. /* setup serial stuff */
  776. TX4938_WR(0xff1ff314, 0x00000000); /* h/w flow control off */
  777. TX4938_WR(0xff1ff414, 0x00000000); /* h/w flow control off */
  778. #ifndef CONFIG_PCI
  779. set_io_port_base(RBTX4938_ETHER_BASE);
  780. #endif
  781. #ifdef CONFIG_SERIAL_TXX9
  782. {
  783. extern int early_serial_txx9_setup(struct uart_port *port);
  784. int i;
  785. struct uart_port req;
  786. for(i = 0; i < 2; i++) {
  787. memset(&req, 0, sizeof(req));
  788. req.line = i;
  789. req.iotype = UPIO_MEM;
  790. req.membase = (char *)(0xff1ff300 + i * 0x100);
  791. req.mapbase = 0xff1ff300 + i * 0x100;
  792. req.irq = RBTX4938_IRQ_IRC_SIO(i);
  793. req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
  794. req.uartclk = 50000000;
  795. early_serial_txx9_setup(&req);
  796. }
  797. }
  798. #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  799. argptr = prom_getcmdline();
  800. if (strstr(argptr, "console=") == NULL) {
  801. strcat(argptr, " console=ttyS0,38400");
  802. }
  803. #endif
  804. #endif
  805. #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_PIO58_61
  806. printk("PIOSEL: disabling both ata and nand selection\n");
  807. local_irq_disable();
  808. tx4938_ccfgptr->pcfg &= ~(TX4938_PCFG_NDF_SEL | TX4938_PCFG_ATA_SEL);
  809. #endif
  810. #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_NAND
  811. printk("PIOSEL: enabling nand selection\n");
  812. tx4938_ccfgptr->pcfg |= TX4938_PCFG_NDF_SEL;
  813. tx4938_ccfgptr->pcfg &= ~TX4938_PCFG_ATA_SEL;
  814. #endif
  815. #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_ATA
  816. printk("PIOSEL: enabling ata selection\n");
  817. tx4938_ccfgptr->pcfg |= TX4938_PCFG_ATA_SEL;
  818. tx4938_ccfgptr->pcfg &= ~TX4938_PCFG_NDF_SEL;
  819. #endif
  820. #ifdef CONFIG_IP_PNP
  821. argptr = prom_getcmdline();
  822. if (strstr(argptr, "ip=") == NULL) {
  823. strcat(argptr, " ip=any");
  824. }
  825. #endif
  826. #ifdef CONFIG_FB
  827. {
  828. conswitchp = &dummy_con;
  829. }
  830. #endif
  831. rbtx4938_spi_setup();
  832. pcfg = tx4938_ccfgptr->pcfg; /* updated */
  833. /* fixup piosel */
  834. if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
  835. TX4938_PCFG_ATA_SEL) {
  836. *rbtx4938_piosel_ptr = (*rbtx4938_piosel_ptr & 0x03) | 0x04;
  837. }
  838. else if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
  839. TX4938_PCFG_NDF_SEL) {
  840. *rbtx4938_piosel_ptr = (*rbtx4938_piosel_ptr & 0x03) | 0x08;
  841. }
  842. else {
  843. *rbtx4938_piosel_ptr &= ~(0x08 | 0x04);
  844. }
  845. rbtx4938_fpga_resource.name = "FPGA Registers";
  846. rbtx4938_fpga_resource.start = CPHYSADDR(RBTX4938_FPGA_REG_ADDR);
  847. rbtx4938_fpga_resource.end = CPHYSADDR(RBTX4938_FPGA_REG_ADDR) + 0xffff;
  848. rbtx4938_fpga_resource.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  849. if (request_resource(&iomem_resource, &rbtx4938_fpga_resource))
  850. printk("request resource for fpga failed\n");
  851. /* disable all OnBoard I/O interrupts */
  852. *rbtx4938_imask_ptr = 0;
  853. _machine_restart = rbtx4938_machine_restart;
  854. _machine_halt = rbtx4938_machine_halt;
  855. pm_power_off = rbtx4938_machine_power_off;
  856. *rbtx4938_led_ptr = 0xff;
  857. printk("RBTX4938 --- FPGA(Rev %02x)", *rbtx4938_fpga_rev_ptr);
  858. printk(" DIPSW:%02x,%02x\n",
  859. *rbtx4938_dipsw_ptr, *rbtx4938_bdipsw_ptr);
  860. }
  861. static int __init rbtx4938_ne_init(void)
  862. {
  863. struct resource res[] = {
  864. {
  865. .start = RBTX4938_RTL_8019_BASE,
  866. .end = RBTX4938_RTL_8019_BASE + 0x20 - 1,
  867. .flags = IORESOURCE_IO,
  868. }, {
  869. .start = RBTX4938_RTL_8019_IRQ,
  870. .flags = IORESOURCE_IRQ,
  871. }
  872. };
  873. struct platform_device *dev =
  874. platform_device_register_simple("ne", -1,
  875. res, ARRAY_SIZE(res));
  876. return IS_ERR(dev) ? PTR_ERR(dev) : 0;
  877. }
  878. device_initcall(rbtx4938_ne_init);
  879. /* GPIO support */
  880. static DEFINE_SPINLOCK(rbtx4938_spi_gpio_lock);
  881. static void rbtx4938_spi_gpio_set(unsigned gpio, int value)
  882. {
  883. u8 val;
  884. unsigned long flags;
  885. gpio -= 16;
  886. spin_lock_irqsave(&rbtx4938_spi_gpio_lock, flags);
  887. val = *rbtx4938_spics_ptr;
  888. if (value)
  889. val |= 1 << gpio;
  890. else
  891. val &= ~(1 << gpio);
  892. *rbtx4938_spics_ptr = val;
  893. mmiowb();
  894. spin_unlock_irqrestore(&rbtx4938_spi_gpio_lock, flags);
  895. }
  896. static int rbtx4938_spi_gpio_dir_out(unsigned gpio, int value)
  897. {
  898. rbtx4938_spi_gpio_set(gpio, value);
  899. return 0;
  900. }
  901. static DEFINE_SPINLOCK(tx4938_gpio_lock);
  902. static int tx4938_gpio_get(unsigned gpio)
  903. {
  904. return tx4938_pioptr->din & (1 << gpio);
  905. }
  906. static void tx4938_gpio_set_raw(unsigned gpio, int value)
  907. {
  908. u32 val;
  909. val = tx4938_pioptr->dout;
  910. if (value)
  911. val |= 1 << gpio;
  912. else
  913. val &= ~(1 << gpio);
  914. tx4938_pioptr->dout = val;
  915. }
  916. static void tx4938_gpio_set(unsigned gpio, int value)
  917. {
  918. unsigned long flags;
  919. spin_lock_irqsave(&tx4938_gpio_lock, flags);
  920. tx4938_gpio_set_raw(gpio, value);
  921. mmiowb();
  922. spin_unlock_irqrestore(&tx4938_gpio_lock, flags);
  923. }
  924. static int tx4938_gpio_dir_in(unsigned gpio)
  925. {
  926. spin_lock_irq(&tx4938_gpio_lock);
  927. tx4938_pioptr->dir &= ~(1 << gpio);
  928. mmiowb();
  929. spin_unlock_irq(&tx4938_gpio_lock);
  930. return 0;
  931. }
  932. static int tx4938_gpio_dir_out(unsigned int gpio, int value)
  933. {
  934. spin_lock_irq(&tx4938_gpio_lock);
  935. tx4938_gpio_set_raw(gpio, value);
  936. tx4938_pioptr->dir |= 1 << gpio;
  937. mmiowb();
  938. spin_unlock_irq(&tx4938_gpio_lock);
  939. return 0;
  940. }
  941. int gpio_direction_input(unsigned gpio)
  942. {
  943. if (gpio < 16)
  944. return tx4938_gpio_dir_in(gpio);
  945. return -EINVAL;
  946. }
  947. int gpio_direction_output(unsigned gpio, int value)
  948. {
  949. if (gpio < 16)
  950. return tx4938_gpio_dir_out(gpio, value);
  951. if (gpio < 16 + 3)
  952. return rbtx4938_spi_gpio_dir_out(gpio, value);
  953. return -EINVAL;
  954. }
  955. int gpio_get_value(unsigned gpio)
  956. {
  957. if (gpio < 16)
  958. return tx4938_gpio_get(gpio);
  959. return 0;
  960. }
  961. void gpio_set_value(unsigned gpio, int value)
  962. {
  963. if (gpio < 16)
  964. tx4938_gpio_set(gpio, value);
  965. else
  966. rbtx4938_spi_gpio_set(gpio, value);
  967. }
  968. /* SPI support */
  969. static void __init txx9_spi_init(unsigned long base, int irq)
  970. {
  971. struct resource res[] = {
  972. {
  973. .start = base,
  974. .end = base + 0x20 - 1,
  975. .flags = IORESOURCE_MEM,
  976. .parent = &tx4938_reg_resource,
  977. }, {
  978. .start = irq,
  979. .flags = IORESOURCE_IRQ,
  980. },
  981. };
  982. platform_device_register_simple("spi_txx9", 0,
  983. res, ARRAY_SIZE(res));
  984. }
  985. static int __init rbtx4938_spi_init(void)
  986. {
  987. struct spi_board_info srtc_info = {
  988. .modalias = "rtc-rs5c348",
  989. .max_speed_hz = 1000000, /* 1.0Mbps @ Vdd 2.0V */
  990. .bus_num = 0,
  991. .chip_select = 16 + SRTC_CS,
  992. /* Mode 1 (High-Active, Shift-Then-Sample), High Avtive CS */
  993. .mode = SPI_MODE_1 | SPI_CS_HIGH,
  994. };
  995. spi_register_board_info(&srtc_info, 1);
  996. spi_eeprom_register(SEEPROM1_CS);
  997. spi_eeprom_register(16 + SEEPROM2_CS);
  998. spi_eeprom_register(16 + SEEPROM3_CS);
  999. txx9_spi_init(TX4938_SPI_REG & 0xfffffffffULL, RBTX4938_IRQ_IRC_SPI);
  1000. return 0;
  1001. }
  1002. arch_initcall(rbtx4938_spi_init);
  1003. /* Minimum CLK support */
  1004. struct clk *clk_get(struct device *dev, const char *id)
  1005. {
  1006. if (!strcmp(id, "spi-baseclk"))
  1007. return (struct clk *)(txx9_gbus_clock / 2 / 4);
  1008. return ERR_PTR(-ENOENT);
  1009. }
  1010. EXPORT_SYMBOL(clk_get);
  1011. int clk_enable(struct clk *clk)
  1012. {
  1013. return 0;
  1014. }
  1015. EXPORT_SYMBOL(clk_enable);
  1016. void clk_disable(struct clk *clk)
  1017. {
  1018. }
  1019. EXPORT_SYMBOL(clk_disable);
  1020. unsigned long clk_get_rate(struct clk *clk)
  1021. {
  1022. return (unsigned long)clk;
  1023. }
  1024. EXPORT_SYMBOL(clk_get_rate);
  1025. void clk_put(struct clk *clk)
  1026. {
  1027. }
  1028. EXPORT_SYMBOL(clk_put);