setup.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  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. .parent = &tx4938_reg_resource,
  917. }, {
  918. .start = irq,
  919. .flags = IORESOURCE_IRQ,
  920. },
  921. };
  922. platform_device_register_simple("spi_txx9", 0,
  923. res, ARRAY_SIZE(res));
  924. }
  925. static int __init rbtx4938_spi_init(void)
  926. {
  927. struct spi_board_info srtc_info = {
  928. .modalias = "rtc-rs5c348",
  929. .max_speed_hz = 1000000, /* 1.0Mbps @ Vdd 2.0V */
  930. .bus_num = 0,
  931. .chip_select = 16 + SRTC_CS,
  932. /* Mode 1 (High-Active, Shift-Then-Sample), High Avtive CS */
  933. .mode = SPI_MODE_1 | SPI_CS_HIGH,
  934. };
  935. spi_register_board_info(&srtc_info, 1);
  936. spi_eeprom_register(SEEPROM1_CS);
  937. spi_eeprom_register(16 + SEEPROM2_CS);
  938. spi_eeprom_register(16 + SEEPROM3_CS);
  939. gpio_request(16 + SRTC_CS, "rtc-rs5c348");
  940. gpio_direction_output(16 + SRTC_CS, 0);
  941. gpio_request(SEEPROM1_CS, "seeprom1");
  942. gpio_direction_output(SEEPROM1_CS, 1);
  943. gpio_request(16 + SEEPROM2_CS, "seeprom2");
  944. gpio_direction_output(16 + SEEPROM2_CS, 1);
  945. gpio_request(16 + SEEPROM3_CS, "seeprom3");
  946. gpio_direction_output(16 + SEEPROM3_CS, 1);
  947. txx9_spi_init(TX4938_SPI_REG & 0xfffffffffULL, RBTX4938_IRQ_IRC_SPI);
  948. return 0;
  949. }
  950. static int __init rbtx4938_arch_init(void)
  951. {
  952. txx9_gpio_init(TX4938_PIO_REG & 0xfffffffffULL, 0, 16);
  953. gpiochip_add(&rbtx4938_spi_gpio_chip);
  954. return rbtx4938_spi_init();
  955. }
  956. arch_initcall(rbtx4938_arch_init);
  957. /* Watchdog support */
  958. static int __init txx9_wdt_init(unsigned long base)
  959. {
  960. struct resource res = {
  961. .start = base,
  962. .end = base + 0x100 - 1,
  963. .flags = IORESOURCE_MEM,
  964. .parent = &tx4938_reg_resource,
  965. };
  966. struct platform_device *dev =
  967. platform_device_register_simple("txx9wdt", -1, &res, 1);
  968. return IS_ERR(dev) ? PTR_ERR(dev) : 0;
  969. }
  970. static int __init rbtx4938_wdt_init(void)
  971. {
  972. return txx9_wdt_init(TX4938_TMR_REG(2) & 0xfffffffffULL);
  973. }
  974. device_initcall(rbtx4938_wdt_init);
  975. /* Minimum CLK support */
  976. struct clk *clk_get(struct device *dev, const char *id)
  977. {
  978. if (!strcmp(id, "spi-baseclk"))
  979. return (struct clk *)(txx9_gbus_clock / 2 / 4);
  980. if (!strcmp(id, "imbus_clk"))
  981. return (struct clk *)(txx9_gbus_clock / 2);
  982. return ERR_PTR(-ENOENT);
  983. }
  984. EXPORT_SYMBOL(clk_get);
  985. int clk_enable(struct clk *clk)
  986. {
  987. return 0;
  988. }
  989. EXPORT_SYMBOL(clk_enable);
  990. void clk_disable(struct clk *clk)
  991. {
  992. }
  993. EXPORT_SYMBOL(clk_disable);
  994. unsigned long clk_get_rate(struct clk *clk)
  995. {
  996. return (unsigned long)clk;
  997. }
  998. EXPORT_SYMBOL(clk_get_rate);
  999. void clk_put(struct clk *clk)
  1000. {
  1001. }
  1002. EXPORT_SYMBOL(clk_put);