setup.c 32 KB

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