setup.c 32 KB

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