setup.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  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 = bus.sysdata = hose;
  322. dev.devfn = devfn;
  323. bus.number = busnr;
  324. bus.ops = hose->pci_ops;
  325. bus.parent = NULL;
  326. dev.bus = &bus;
  327. return &dev;
  328. }
  329. #define EARLY_PCI_OP(rw, size, type) \
  330. static int early_##rw##_config_##size(struct pci_controller *hose, \
  331. int top_bus, int bus, int devfn, int offset, type value) \
  332. { \
  333. return pci_##rw##_config_##size( \
  334. fake_pci_dev(hose, top_bus, bus, devfn), \
  335. offset, value); \
  336. }
  337. EARLY_PCI_OP(read, word, u16 *)
  338. int txboard_pci66_check(struct pci_controller *hose, int top_bus, int current_bus)
  339. {
  340. u32 pci_devfn;
  341. unsigned short vid;
  342. int devfn_start = 0;
  343. int devfn_stop = 0xff;
  344. int cap66 = -1;
  345. u16 stat;
  346. printk("PCI: Checking 66MHz capabilities...\n");
  347. for (pci_devfn=devfn_start; pci_devfn<devfn_stop; pci_devfn++) {
  348. if (early_read_config_word(hose, top_bus, current_bus,
  349. pci_devfn, PCI_VENDOR_ID,
  350. &vid) != PCIBIOS_SUCCESSFUL)
  351. continue;
  352. if (vid == 0xffff) continue;
  353. /* check 66MHz capability */
  354. if (cap66 < 0)
  355. cap66 = 1;
  356. if (cap66) {
  357. early_read_config_word(hose, top_bus, current_bus, pci_devfn,
  358. PCI_STATUS, &stat);
  359. if (!(stat & PCI_STATUS_66MHZ)) {
  360. printk(KERN_DEBUG "PCI: %02x:%02x not 66MHz capable.\n",
  361. current_bus, pci_devfn);
  362. cap66 = 0;
  363. break;
  364. }
  365. }
  366. }
  367. return cap66 > 0;
  368. }
  369. int __init
  370. tx4938_pciclk66_setup(void)
  371. {
  372. int pciclk;
  373. /* Assert M66EN */
  374. tx4938_ccfgptr->ccfg |= TX4938_CCFG_PCI66;
  375. /* Double PCICLK (if possible) */
  376. if (tx4938_ccfgptr->pcfg & TX4938_PCFG_PCICLKEN_ALL) {
  377. unsigned int pcidivmode =
  378. tx4938_ccfgptr->ccfg & TX4938_CCFG_PCIDIVMODE_MASK;
  379. switch (pcidivmode) {
  380. case TX4938_CCFG_PCIDIVMODE_8:
  381. case TX4938_CCFG_PCIDIVMODE_4:
  382. pcidivmode = TX4938_CCFG_PCIDIVMODE_4;
  383. pciclk = txx9_cpu_clock / 4;
  384. break;
  385. case TX4938_CCFG_PCIDIVMODE_9:
  386. case TX4938_CCFG_PCIDIVMODE_4_5:
  387. pcidivmode = TX4938_CCFG_PCIDIVMODE_4_5;
  388. pciclk = txx9_cpu_clock * 2 / 9;
  389. break;
  390. case TX4938_CCFG_PCIDIVMODE_10:
  391. case TX4938_CCFG_PCIDIVMODE_5:
  392. pcidivmode = TX4938_CCFG_PCIDIVMODE_5;
  393. pciclk = txx9_cpu_clock / 5;
  394. break;
  395. case TX4938_CCFG_PCIDIVMODE_11:
  396. case TX4938_CCFG_PCIDIVMODE_5_5:
  397. default:
  398. pcidivmode = TX4938_CCFG_PCIDIVMODE_5_5;
  399. pciclk = txx9_cpu_clock * 2 / 11;
  400. break;
  401. }
  402. tx4938_ccfgptr->ccfg =
  403. (tx4938_ccfgptr->ccfg & ~TX4938_CCFG_PCIDIVMODE_MASK)
  404. | pcidivmode;
  405. printk(KERN_DEBUG "PCICLK: ccfg:%08lx\n",
  406. (unsigned long)tx4938_ccfgptr->ccfg);
  407. } else {
  408. pciclk = -1;
  409. }
  410. return pciclk;
  411. }
  412. extern struct pci_controller tx4938_pci_controller[];
  413. static int __init tx4938_pcibios_init(void)
  414. {
  415. unsigned long mem_base[2];
  416. unsigned long mem_size[2] = {TX4938_PCIMEM_SIZE_0,TX4938_PCIMEM_SIZE_1}; /* MAX 128M,64K */
  417. unsigned long io_base[2];
  418. unsigned long io_size[2] = {TX4938_PCIIO_SIZE_0,TX4938_PCIIO_SIZE_1}; /* MAX 16M,64K */
  419. /* TX4938 PCIC1: 64K MEM/IO is enough for ETH0,ETH1 */
  420. int extarb = !(tx4938_ccfgptr->ccfg & TX4938_CCFG_PCIXARB);
  421. PCIBIOS_MIN_IO = 0x00001000UL;
  422. mem_base[0] = txboard_request_phys_region_shrink(&mem_size[0]);
  423. io_base[0] = txboard_request_phys_region_shrink(&io_size[0]);
  424. printk("TX4938 PCIC -- DID:%04x VID:%04x RID:%02x Arbiter:%s\n",
  425. (unsigned short)(tx4938_pcicptr->pciid >> 16),
  426. (unsigned short)(tx4938_pcicptr->pciid & 0xffff),
  427. (unsigned short)(tx4938_pcicptr->pciccrev & 0xff),
  428. extarb ? "External" : "Internal");
  429. /* setup PCI area */
  430. tx4938_pci_controller[0].io_resource->start = io_base[0];
  431. tx4938_pci_controller[0].io_resource->end = (io_base[0] + io_size[0]) - 1;
  432. tx4938_pci_controller[0].mem_resource->start = mem_base[0];
  433. tx4938_pci_controller[0].mem_resource->end = mem_base[0] + mem_size[0] - 1;
  434. set_tx4938_pcicptr(0, tx4938_pcicptr);
  435. register_pci_controller(&tx4938_pci_controller[0]);
  436. if (tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI66) {
  437. printk("TX4938_CCFG_PCI66 already configured\n");
  438. txboard_pci66_mode = -1; /* already configured */
  439. }
  440. /* Reset PCI Bus */
  441. *rbtx4938_pcireset_ptr = 0;
  442. /* Reset PCIC */
  443. tx4938_ccfgptr->clkctr |= TX4938_CLKCTR_PCIRST;
  444. if (txboard_pci66_mode > 0)
  445. tx4938_pciclk66_setup();
  446. mdelay(10);
  447. /* clear PCIC reset */
  448. tx4938_ccfgptr->clkctr &= ~TX4938_CLKCTR_PCIRST;
  449. *rbtx4938_pcireset_ptr = 1;
  450. wbflush();
  451. tx4938_report_pcic_status1(tx4938_pcicptr);
  452. tx4938_report_pciclk();
  453. tx4938_pcic_setup(tx4938_pcicptr, &tx4938_pci_controller[0], io_base[0], extarb);
  454. if (txboard_pci66_mode == 0 &&
  455. txboard_pci66_check(&tx4938_pci_controller[0], 0, 0)) {
  456. /* Reset PCI Bus */
  457. *rbtx4938_pcireset_ptr = 0;
  458. /* Reset PCIC */
  459. tx4938_ccfgptr->clkctr |= TX4938_CLKCTR_PCIRST;
  460. tx4938_pciclk66_setup();
  461. mdelay(10);
  462. /* clear PCIC reset */
  463. tx4938_ccfgptr->clkctr &= ~TX4938_CLKCTR_PCIRST;
  464. *rbtx4938_pcireset_ptr = 1;
  465. wbflush();
  466. /* Reinitialize PCIC */
  467. tx4938_report_pciclk();
  468. tx4938_pcic_setup(tx4938_pcicptr, &tx4938_pci_controller[0], io_base[0], extarb);
  469. }
  470. mem_base[1] = txboard_request_phys_region_shrink(&mem_size[1]);
  471. io_base[1] = txboard_request_phys_region_shrink(&io_size[1]);
  472. /* Reset PCIC1 */
  473. tx4938_ccfgptr->clkctr |= TX4938_CLKCTR_PCIC1RST;
  474. /* PCI1DMD==0 => PCI1CLK==GBUSCLK/2 => PCI66 */
  475. if (!(tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI1DMD))
  476. tx4938_ccfgptr->ccfg |= TX4938_CCFG_PCI1_66;
  477. else
  478. tx4938_ccfgptr->ccfg &= ~TX4938_CCFG_PCI1_66;
  479. mdelay(10);
  480. /* clear PCIC1 reset */
  481. tx4938_ccfgptr->clkctr &= ~TX4938_CLKCTR_PCIC1RST;
  482. tx4938_report_pcic_status1(tx4938_pcic1ptr);
  483. printk("TX4938 PCIC1 -- DID:%04x VID:%04x RID:%02x",
  484. (unsigned short)(tx4938_pcic1ptr->pciid >> 16),
  485. (unsigned short)(tx4938_pcic1ptr->pciid & 0xffff),
  486. (unsigned short)(tx4938_pcic1ptr->pciccrev & 0xff));
  487. printk("%s PCICLK:%dMHz\n",
  488. (tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI1_66) ? " PCI66" : "",
  489. txx9_gbus_clock /
  490. ((tx4938_ccfgptr->ccfg & TX4938_CCFG_PCI1DMD) ? 4 : 2) /
  491. 1000000);
  492. /* assumption: CPHYSADDR(mips_io_port_base) == io_base[0] */
  493. tx4938_pci_controller[1].io_resource->start =
  494. io_base[1] - io_base[0];
  495. tx4938_pci_controller[1].io_resource->end =
  496. io_base[1] - io_base[0] + io_size[1] - 1;
  497. tx4938_pci_controller[1].mem_resource->start = mem_base[1];
  498. tx4938_pci_controller[1].mem_resource->end =
  499. mem_base[1] + mem_size[1] - 1;
  500. set_tx4938_pcicptr(1, tx4938_pcic1ptr);
  501. register_pci_controller(&tx4938_pci_controller[1]);
  502. tx4938_pcic_setup(tx4938_pcic1ptr, &tx4938_pci_controller[1], io_base[1], extarb);
  503. /* map ioport 0 to PCI I/O space address 0 */
  504. set_io_port_base(KSEG1 + io_base[0]);
  505. return 0;
  506. }
  507. arch_initcall(tx4938_pcibios_init);
  508. #endif /* CONFIG_PCI */
  509. /* SPI support */
  510. /* chip select for SPI devices */
  511. #define SEEPROM1_CS 7 /* PIO7 */
  512. #define SEEPROM2_CS 0 /* IOC */
  513. #define SEEPROM3_CS 1 /* IOC */
  514. #define SRTC_CS 2 /* IOC */
  515. #ifdef CONFIG_PCI
  516. static int __init rbtx4938_ethaddr_init(void)
  517. {
  518. unsigned char dat[17];
  519. unsigned char sum;
  520. int i;
  521. /* 0-3: "MAC\0", 4-9:eth0, 10-15:eth1, 16:sum */
  522. if (spi_eeprom_read(SEEPROM1_CS, 0, dat, sizeof(dat))) {
  523. printk(KERN_ERR "seeprom: read error.\n");
  524. return -ENODEV;
  525. } else {
  526. if (strcmp(dat, "MAC") != 0)
  527. printk(KERN_WARNING "seeprom: bad signature.\n");
  528. for (i = 0, sum = 0; i < sizeof(dat); i++)
  529. sum += dat[i];
  530. if (sum)
  531. printk(KERN_WARNING "seeprom: bad checksum.\n");
  532. }
  533. for (i = 0; i < 2; i++) {
  534. unsigned int slot = TX4938_PCIC_IDSEL_AD_TO_SLOT(31 - i);
  535. unsigned int id = (1 << 8) | PCI_DEVFN(slot, 0); /* bus 1 */
  536. struct platform_device *pdev;
  537. if (!(tx4938_ccfgptr->pcfg &
  538. (i ? TX4938_PCFG_ETH1_SEL : TX4938_PCFG_ETH0_SEL)))
  539. continue;
  540. pdev = platform_device_alloc("tc35815-mac", id);
  541. if (!pdev ||
  542. platform_device_add_data(pdev, &dat[4 + 6 * i], 6) ||
  543. platform_device_add(pdev))
  544. platform_device_put(pdev);
  545. }
  546. return 0;
  547. }
  548. device_initcall(rbtx4938_ethaddr_init);
  549. #endif /* CONFIG_PCI */
  550. static void __init rbtx4938_spi_setup(void)
  551. {
  552. /* set SPI_SEL */
  553. tx4938_ccfgptr->pcfg |= TX4938_PCFG_SPI_SEL;
  554. /* chip selects for SPI devices */
  555. tx4938_pioptr->dout |= (1 << SEEPROM1_CS);
  556. tx4938_pioptr->dir |= (1 << SEEPROM1_CS);
  557. }
  558. static struct resource rbtx4938_fpga_resource;
  559. static char pcode_str[8];
  560. static struct resource tx4938_reg_resource = {
  561. .start = TX4938_REG_BASE,
  562. .end = TX4938_REG_BASE + TX4938_REG_SIZE,
  563. .name = pcode_str,
  564. .flags = IORESOURCE_MEM
  565. };
  566. void __init tx4938_board_setup(void)
  567. {
  568. int i;
  569. unsigned long divmode;
  570. int cpuclk = 0;
  571. unsigned long pcode = TX4938_REV_PCODE();
  572. ioport_resource.start = 0x1000;
  573. ioport_resource.end = 0xffffffff;
  574. iomem_resource.start = 0x1000;
  575. iomem_resource.end = 0xffffffff; /* expand to 4GB */
  576. sprintf(pcode_str, "TX%lx", pcode);
  577. /* SDRAMC,EBUSC are configured by PROM */
  578. for (i = 0; i < 8; i++) {
  579. if (!(tx4938_ebuscptr->cr[i] & 0x8))
  580. continue; /* disabled */
  581. rbtx4938_ce_base[i] = (unsigned long)TX4938_EBUSC_BA(i);
  582. txboard_add_phys_region(rbtx4938_ce_base[i], TX4938_EBUSC_SIZE(i));
  583. }
  584. /* clocks */
  585. if (txx9_master_clock) {
  586. /* calculate gbus_clock and cpu_clock from master_clock */
  587. divmode = (unsigned long)tx4938_ccfgptr->ccfg & TX4938_CCFG_DIVMODE_MASK;
  588. switch (divmode) {
  589. case TX4938_CCFG_DIVMODE_8:
  590. case TX4938_CCFG_DIVMODE_10:
  591. case TX4938_CCFG_DIVMODE_12:
  592. case TX4938_CCFG_DIVMODE_16:
  593. case TX4938_CCFG_DIVMODE_18:
  594. txx9_gbus_clock = txx9_master_clock * 4; break;
  595. default:
  596. txx9_gbus_clock = txx9_master_clock;
  597. }
  598. switch (divmode) {
  599. case TX4938_CCFG_DIVMODE_2:
  600. case TX4938_CCFG_DIVMODE_8:
  601. cpuclk = txx9_gbus_clock * 2; break;
  602. case TX4938_CCFG_DIVMODE_2_5:
  603. case TX4938_CCFG_DIVMODE_10:
  604. cpuclk = txx9_gbus_clock * 5 / 2; break;
  605. case TX4938_CCFG_DIVMODE_3:
  606. case TX4938_CCFG_DIVMODE_12:
  607. cpuclk = txx9_gbus_clock * 3; break;
  608. case TX4938_CCFG_DIVMODE_4:
  609. case TX4938_CCFG_DIVMODE_16:
  610. cpuclk = txx9_gbus_clock * 4; break;
  611. case TX4938_CCFG_DIVMODE_4_5:
  612. case TX4938_CCFG_DIVMODE_18:
  613. cpuclk = txx9_gbus_clock * 9 / 2; break;
  614. }
  615. txx9_cpu_clock = cpuclk;
  616. } else {
  617. if (txx9_cpu_clock == 0) {
  618. txx9_cpu_clock = 300000000; /* 300MHz */
  619. }
  620. /* calculate gbus_clock and master_clock from cpu_clock */
  621. cpuclk = txx9_cpu_clock;
  622. divmode = (unsigned long)tx4938_ccfgptr->ccfg & TX4938_CCFG_DIVMODE_MASK;
  623. switch (divmode) {
  624. case TX4938_CCFG_DIVMODE_2:
  625. case TX4938_CCFG_DIVMODE_8:
  626. txx9_gbus_clock = cpuclk / 2; break;
  627. case TX4938_CCFG_DIVMODE_2_5:
  628. case TX4938_CCFG_DIVMODE_10:
  629. txx9_gbus_clock = cpuclk * 2 / 5; break;
  630. case TX4938_CCFG_DIVMODE_3:
  631. case TX4938_CCFG_DIVMODE_12:
  632. txx9_gbus_clock = cpuclk / 3; break;
  633. case TX4938_CCFG_DIVMODE_4:
  634. case TX4938_CCFG_DIVMODE_16:
  635. txx9_gbus_clock = cpuclk / 4; break;
  636. case TX4938_CCFG_DIVMODE_4_5:
  637. case TX4938_CCFG_DIVMODE_18:
  638. txx9_gbus_clock = cpuclk * 2 / 9; break;
  639. }
  640. switch (divmode) {
  641. case TX4938_CCFG_DIVMODE_8:
  642. case TX4938_CCFG_DIVMODE_10:
  643. case TX4938_CCFG_DIVMODE_12:
  644. case TX4938_CCFG_DIVMODE_16:
  645. case TX4938_CCFG_DIVMODE_18:
  646. txx9_master_clock = txx9_gbus_clock / 4; break;
  647. default:
  648. txx9_master_clock = txx9_gbus_clock;
  649. }
  650. }
  651. /* change default value to udelay/mdelay take reasonable time */
  652. loops_per_jiffy = txx9_cpu_clock / HZ / 2;
  653. /* CCFG */
  654. /* clear WatchDogReset,BusErrorOnWrite flag (W1C) */
  655. tx4938_ccfgptr->ccfg |= TX4938_CCFG_WDRST | TX4938_CCFG_BEOW;
  656. /* clear PCIC1 reset */
  657. if (tx4938_ccfgptr->clkctr & TX4938_CLKCTR_PCIC1RST)
  658. tx4938_ccfgptr->clkctr &= ~TX4938_CLKCTR_PCIC1RST;
  659. /* enable Timeout BusError */
  660. if (tx4938_ccfg_toeon)
  661. tx4938_ccfgptr->ccfg |= TX4938_CCFG_TOE;
  662. /* DMA selection */
  663. tx4938_ccfgptr->pcfg &= ~TX4938_PCFG_DMASEL_ALL;
  664. /* Use external clock for external arbiter */
  665. if (!(tx4938_ccfgptr->ccfg & TX4938_CCFG_PCIXARB))
  666. tx4938_ccfgptr->pcfg &= ~TX4938_PCFG_PCICLKEN_ALL;
  667. printk("%s -- %dMHz(M%dMHz) CRIR:%08lx CCFG:%Lx PCFG:%Lx\n",
  668. pcode_str,
  669. cpuclk / 1000000, txx9_master_clock / 1000000,
  670. (unsigned long)tx4938_ccfgptr->crir,
  671. tx4938_ccfgptr->ccfg,
  672. tx4938_ccfgptr->pcfg);
  673. printk("%s SDRAMC --", pcode_str);
  674. for (i = 0; i < 4; i++) {
  675. unsigned long long cr = tx4938_sdramcptr->cr[i];
  676. unsigned long ram_base, ram_size;
  677. if (!((unsigned long)cr & 0x00000400))
  678. continue; /* disabled */
  679. ram_base = (unsigned long)(cr >> 49) << 21;
  680. ram_size = ((unsigned long)(cr >> 33) + 1) << 21;
  681. if (ram_base >= 0x20000000)
  682. continue; /* high memory (ignore) */
  683. printk(" CR%d:%016Lx", i, cr);
  684. txboard_add_phys_region(ram_base, ram_size);
  685. }
  686. printk(" TR:%09Lx\n", tx4938_sdramcptr->tr);
  687. /* SRAM */
  688. if (pcode == 0x4938 && tx4938_sramcptr->cr & 1) {
  689. unsigned int size = 0x800;
  690. unsigned long base =
  691. (tx4938_sramcptr->cr >> (39-11)) & ~(size - 1);
  692. txboard_add_phys_region(base, size);
  693. }
  694. /* IRC */
  695. /* disable interrupt control */
  696. tx4938_ircptr->cer = 0;
  697. /* TMR */
  698. /* disable all timers */
  699. for (i = 0; i < TX4938_NR_TMR; i++) {
  700. tx4938_tmrptr(i)->tcr = 0x00000020;
  701. tx4938_tmrptr(i)->tisr = 0;
  702. tx4938_tmrptr(i)->cpra = 0xffffffff;
  703. tx4938_tmrptr(i)->itmr = 0;
  704. tx4938_tmrptr(i)->ccdr = 0;
  705. tx4938_tmrptr(i)->pgmr = 0;
  706. }
  707. /* enable DMA */
  708. TX4938_WR64(0xff1fb150, TX4938_DMA_MCR_MSTEN);
  709. TX4938_WR64(0xff1fb950, TX4938_DMA_MCR_MSTEN);
  710. /* PIO */
  711. tx4938_pioptr->maskcpu = 0;
  712. tx4938_pioptr->maskext = 0;
  713. /* TX4938 internal registers */
  714. if (request_resource(&iomem_resource, &tx4938_reg_resource))
  715. printk("request resource for internal registers failed\n");
  716. }
  717. #ifdef CONFIG_PCI
  718. static inline void tx4938_report_pcic_status1(struct tx4938_pcic_reg *pcicptr)
  719. {
  720. unsigned short pcistatus = (unsigned short)(pcicptr->pcistatus >> 16);
  721. unsigned long g2pstatus = pcicptr->g2pstatus;
  722. unsigned long pcicstatus = pcicptr->pcicstatus;
  723. static struct {
  724. unsigned long flag;
  725. const char *str;
  726. } pcistat_tbl[] = {
  727. { PCI_STATUS_DETECTED_PARITY, "DetectedParityError" },
  728. { PCI_STATUS_SIG_SYSTEM_ERROR, "SignaledSystemError" },
  729. { PCI_STATUS_REC_MASTER_ABORT, "ReceivedMasterAbort" },
  730. { PCI_STATUS_REC_TARGET_ABORT, "ReceivedTargetAbort" },
  731. { PCI_STATUS_SIG_TARGET_ABORT, "SignaledTargetAbort" },
  732. { PCI_STATUS_PARITY, "MasterParityError" },
  733. }, g2pstat_tbl[] = {
  734. { TX4938_PCIC_G2PSTATUS_TTOE, "TIOE" },
  735. { TX4938_PCIC_G2PSTATUS_RTOE, "RTOE" },
  736. }, pcicstat_tbl[] = {
  737. { TX4938_PCIC_PCICSTATUS_PME, "PME" },
  738. { TX4938_PCIC_PCICSTATUS_TLB, "TLB" },
  739. { TX4938_PCIC_PCICSTATUS_NIB, "NIB" },
  740. { TX4938_PCIC_PCICSTATUS_ZIB, "ZIB" },
  741. { TX4938_PCIC_PCICSTATUS_PERR, "PERR" },
  742. { TX4938_PCIC_PCICSTATUS_SERR, "SERR" },
  743. { TX4938_PCIC_PCICSTATUS_GBE, "GBE" },
  744. { TX4938_PCIC_PCICSTATUS_IWB, "IWB" },
  745. };
  746. int i;
  747. printk("pcistat:%04x(", pcistatus);
  748. for (i = 0; i < ARRAY_SIZE(pcistat_tbl); i++)
  749. if (pcistatus & pcistat_tbl[i].flag)
  750. printk("%s ", pcistat_tbl[i].str);
  751. printk("), g2pstatus:%08lx(", g2pstatus);
  752. for (i = 0; i < ARRAY_SIZE(g2pstat_tbl); i++)
  753. if (g2pstatus & g2pstat_tbl[i].flag)
  754. printk("%s ", g2pstat_tbl[i].str);
  755. printk("), pcicstatus:%08lx(", pcicstatus);
  756. for (i = 0; i < ARRAY_SIZE(pcicstat_tbl); i++)
  757. if (pcicstatus & pcicstat_tbl[i].flag)
  758. printk("%s ", pcicstat_tbl[i].str);
  759. printk(")\n");
  760. }
  761. void tx4938_report_pcic_status(void)
  762. {
  763. int i;
  764. struct tx4938_pcic_reg *pcicptr;
  765. for (i = 0; (pcicptr = get_tx4938_pcicptr(i)) != NULL; i++)
  766. tx4938_report_pcic_status1(pcicptr);
  767. }
  768. #endif /* CONFIG_PCI */
  769. /* We use onchip r4k counter or TMR timer as our system wide timer
  770. * interrupt running at 100HZ. */
  771. void __init rbtx4938_time_init(void)
  772. {
  773. mips_hpt_frequency = txx9_cpu_clock / 2;
  774. }
  775. void __init toshiba_rbtx4938_setup(void)
  776. {
  777. unsigned long long pcfg;
  778. char *argptr;
  779. iomem_resource.end = 0xffffffff; /* 4GB */
  780. if (txx9_master_clock == 0)
  781. txx9_master_clock = 25000000; /* 25MHz */
  782. tx4938_board_setup();
  783. /* setup irq stuff */
  784. TX4938_WR(TX4938_MKA(TX4938_IRC_IRDM0), 0x00000000); /* irq trigger */
  785. TX4938_WR(TX4938_MKA(TX4938_IRC_IRDM1), 0x00000000); /* irq trigger */
  786. /* setup serial stuff */
  787. TX4938_WR(0xff1ff314, 0x00000000); /* h/w flow control off */
  788. TX4938_WR(0xff1ff414, 0x00000000); /* h/w flow control off */
  789. #ifndef CONFIG_PCI
  790. set_io_port_base(RBTX4938_ETHER_BASE);
  791. #endif
  792. #ifdef CONFIG_SERIAL_TXX9
  793. {
  794. extern int early_serial_txx9_setup(struct uart_port *port);
  795. int i;
  796. struct uart_port req;
  797. for(i = 0; i < 2; i++) {
  798. memset(&req, 0, sizeof(req));
  799. req.line = i;
  800. req.iotype = UPIO_MEM;
  801. req.membase = (char *)(0xff1ff300 + i * 0x100);
  802. req.mapbase = 0xff1ff300 + i * 0x100;
  803. req.irq = 32 + i;
  804. req.flags |= UPF_BUGGY_UART /*HAVE_CTS_LINE*/;
  805. req.uartclk = 50000000;
  806. early_serial_txx9_setup(&req);
  807. }
  808. }
  809. #ifdef CONFIG_SERIAL_TXX9_CONSOLE
  810. argptr = prom_getcmdline();
  811. if (strstr(argptr, "console=") == NULL) {
  812. strcat(argptr, " console=ttyS0,38400");
  813. }
  814. #endif
  815. #endif
  816. #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_PIO58_61
  817. printk("PIOSEL: disabling both ata and nand selection\n");
  818. local_irq_disable();
  819. tx4938_ccfgptr->pcfg &= ~(TX4938_PCFG_NDF_SEL | TX4938_PCFG_ATA_SEL);
  820. #endif
  821. #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_NAND
  822. printk("PIOSEL: enabling nand selection\n");
  823. tx4938_ccfgptr->pcfg |= TX4938_PCFG_NDF_SEL;
  824. tx4938_ccfgptr->pcfg &= ~TX4938_PCFG_ATA_SEL;
  825. #endif
  826. #ifdef CONFIG_TOSHIBA_RBTX4938_MPLEX_ATA
  827. printk("PIOSEL: enabling ata selection\n");
  828. tx4938_ccfgptr->pcfg |= TX4938_PCFG_ATA_SEL;
  829. tx4938_ccfgptr->pcfg &= ~TX4938_PCFG_NDF_SEL;
  830. #endif
  831. #ifdef CONFIG_IP_PNP
  832. argptr = prom_getcmdline();
  833. if (strstr(argptr, "ip=") == NULL) {
  834. strcat(argptr, " ip=any");
  835. }
  836. #endif
  837. #ifdef CONFIG_FB
  838. {
  839. conswitchp = &dummy_con;
  840. }
  841. #endif
  842. rbtx4938_spi_setup();
  843. pcfg = tx4938_ccfgptr->pcfg; /* updated */
  844. /* fixup piosel */
  845. if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
  846. TX4938_PCFG_ATA_SEL) {
  847. *rbtx4938_piosel_ptr = (*rbtx4938_piosel_ptr & 0x03) | 0x04;
  848. }
  849. else if ((pcfg & (TX4938_PCFG_ATA_SEL | TX4938_PCFG_NDF_SEL)) ==
  850. TX4938_PCFG_NDF_SEL) {
  851. *rbtx4938_piosel_ptr = (*rbtx4938_piosel_ptr & 0x03) | 0x08;
  852. }
  853. else {
  854. *rbtx4938_piosel_ptr &= ~(0x08 | 0x04);
  855. }
  856. rbtx4938_fpga_resource.name = "FPGA Registers";
  857. rbtx4938_fpga_resource.start = CPHYSADDR(RBTX4938_FPGA_REG_ADDR);
  858. rbtx4938_fpga_resource.end = CPHYSADDR(RBTX4938_FPGA_REG_ADDR) + 0xffff;
  859. rbtx4938_fpga_resource.flags = IORESOURCE_MEM | IORESOURCE_BUSY;
  860. if (request_resource(&iomem_resource, &rbtx4938_fpga_resource))
  861. printk("request resource for fpga failed\n");
  862. /* disable all OnBoard I/O interrupts */
  863. *rbtx4938_imask_ptr = 0;
  864. _machine_restart = rbtx4938_machine_restart;
  865. _machine_halt = rbtx4938_machine_halt;
  866. pm_power_off = rbtx4938_machine_power_off;
  867. *rbtx4938_led_ptr = 0xff;
  868. printk("RBTX4938 --- FPGA(Rev %02x)", *rbtx4938_fpga_rev_ptr);
  869. printk(" DIPSW:%02x,%02x\n",
  870. *rbtx4938_dipsw_ptr, *rbtx4938_bdipsw_ptr);
  871. }
  872. static int __init rbtx4938_ne_init(void)
  873. {
  874. struct resource res[] = {
  875. {
  876. .start = RBTX4938_RTL_8019_BASE,
  877. .end = RBTX4938_RTL_8019_BASE + 0x20 - 1,
  878. .flags = IORESOURCE_IO,
  879. }, {
  880. .start = RBTX4938_RTL_8019_IRQ,
  881. .flags = IORESOURCE_IRQ,
  882. }
  883. };
  884. struct platform_device *dev =
  885. platform_device_register_simple("ne", -1,
  886. res, ARRAY_SIZE(res));
  887. return IS_ERR(dev) ? PTR_ERR(dev) : 0;
  888. }
  889. device_initcall(rbtx4938_ne_init);
  890. /* GPIO support */
  891. static DEFINE_SPINLOCK(rbtx4938_spi_gpio_lock);
  892. static void rbtx4938_spi_gpio_set(unsigned gpio, int value)
  893. {
  894. u8 val;
  895. unsigned long flags;
  896. gpio -= 16;
  897. spin_lock_irqsave(&rbtx4938_spi_gpio_lock, flags);
  898. val = *rbtx4938_spics_ptr;
  899. if (value)
  900. val |= 1 << gpio;
  901. else
  902. val &= ~(1 << gpio);
  903. *rbtx4938_spics_ptr = val;
  904. mmiowb();
  905. spin_unlock_irqrestore(&rbtx4938_spi_gpio_lock, flags);
  906. }
  907. static int rbtx4938_spi_gpio_dir_out(unsigned gpio, int value)
  908. {
  909. rbtx4938_spi_gpio_set(gpio, value);
  910. return 0;
  911. }
  912. static DEFINE_SPINLOCK(tx4938_gpio_lock);
  913. static int tx4938_gpio_get(unsigned gpio)
  914. {
  915. return tx4938_pioptr->din & (1 << gpio);
  916. }
  917. static void tx4938_gpio_set_raw(unsigned gpio, int value)
  918. {
  919. u32 val;
  920. val = tx4938_pioptr->dout;
  921. if (value)
  922. val |= 1 << gpio;
  923. else
  924. val &= ~(1 << gpio);
  925. tx4938_pioptr->dout = val;
  926. }
  927. static void tx4938_gpio_set(unsigned gpio, int value)
  928. {
  929. unsigned long flags;
  930. spin_lock_irqsave(&tx4938_gpio_lock, flags);
  931. tx4938_gpio_set_raw(gpio, value);
  932. mmiowb();
  933. spin_unlock_irqrestore(&tx4938_gpio_lock, flags);
  934. }
  935. static int tx4938_gpio_dir_in(unsigned gpio)
  936. {
  937. spin_lock_irq(&tx4938_gpio_lock);
  938. tx4938_pioptr->dir &= ~(1 << gpio);
  939. mmiowb();
  940. spin_unlock_irq(&tx4938_gpio_lock);
  941. return 0;
  942. }
  943. static int tx4938_gpio_dir_out(unsigned int gpio, int value)
  944. {
  945. spin_lock_irq(&tx4938_gpio_lock);
  946. tx4938_gpio_set_raw(gpio, value);
  947. tx4938_pioptr->dir |= 1 << gpio;
  948. mmiowb();
  949. spin_unlock_irq(&tx4938_gpio_lock);
  950. return 0;
  951. }
  952. int gpio_direction_input(unsigned gpio)
  953. {
  954. if (gpio < 16)
  955. return tx4938_gpio_dir_in(gpio);
  956. return -EINVAL;
  957. }
  958. int gpio_direction_output(unsigned gpio, int value)
  959. {
  960. if (gpio < 16)
  961. return tx4938_gpio_dir_out(gpio, value);
  962. if (gpio < 16 + 3)
  963. return rbtx4938_spi_gpio_dir_out(gpio, value);
  964. return -EINVAL;
  965. }
  966. int gpio_get_value(unsigned gpio)
  967. {
  968. if (gpio < 16)
  969. return tx4938_gpio_get(gpio);
  970. return 0;
  971. }
  972. void gpio_set_value(unsigned gpio, int value)
  973. {
  974. if (gpio < 16)
  975. tx4938_gpio_set(gpio, value);
  976. else
  977. rbtx4938_spi_gpio_set(gpio, value);
  978. }
  979. /* SPI support */
  980. static void __init txx9_spi_init(unsigned long base, int irq)
  981. {
  982. struct resource res[] = {
  983. {
  984. .start = base,
  985. .end = base + 0x20 - 1,
  986. .flags = IORESOURCE_MEM,
  987. .parent = &tx4938_reg_resource,
  988. }, {
  989. .start = irq,
  990. .flags = IORESOURCE_IRQ,
  991. },
  992. };
  993. platform_device_register_simple("txx9spi", 0,
  994. res, ARRAY_SIZE(res));
  995. }
  996. static int __init rbtx4938_spi_init(void)
  997. {
  998. struct spi_board_info srtc_info = {
  999. .modalias = "rs5c348",
  1000. .max_speed_hz = 1000000, /* 1.0Mbps @ Vdd 2.0V */
  1001. .bus_num = 0,
  1002. .chip_select = 16 + SRTC_CS,
  1003. /* Mode 1 (High-Active, Shift-Then-Sample), High Avtive CS */
  1004. .mode = SPI_MODE_1 | SPI_CS_HIGH,
  1005. };
  1006. spi_register_board_info(&srtc_info, 1);
  1007. spi_eeprom_register(SEEPROM1_CS);
  1008. spi_eeprom_register(16 + SEEPROM2_CS);
  1009. spi_eeprom_register(16 + SEEPROM3_CS);
  1010. txx9_spi_init(TX4938_SPI_REG & 0xfffffffffULL, RBTX4938_IRQ_IRC_SPI);
  1011. return 0;
  1012. }
  1013. arch_initcall(rbtx4938_spi_init);
  1014. /* Minimum CLK support */
  1015. struct clk *clk_get(struct device *dev, const char *id)
  1016. {
  1017. if (!strcmp(id, "spi-baseclk"))
  1018. return (struct clk *)(txx9_gbus_clock / 2 / 4);
  1019. return ERR_PTR(-ENOENT);
  1020. }
  1021. EXPORT_SYMBOL(clk_get);
  1022. int clk_enable(struct clk *clk)
  1023. {
  1024. return 0;
  1025. }
  1026. EXPORT_SYMBOL(clk_enable);
  1027. void clk_disable(struct clk *clk)
  1028. {
  1029. }
  1030. EXPORT_SYMBOL(clk_disable);
  1031. unsigned long clk_get_rate(struct clk *clk)
  1032. {
  1033. return (unsigned long)clk;
  1034. }
  1035. EXPORT_SYMBOL(clk_get_rate);
  1036. void clk_put(struct clk *clk)
  1037. {
  1038. }
  1039. EXPORT_SYMBOL(clk_put);