setup.c 31 KB

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