ops-tx4927.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464
  1. /*
  2. * Define the pci_ops for the PCIC on Toshiba TX4927, TX4938, etc.
  3. *
  4. * Based on linux/arch/mips/pci/ops-tx4938.c,
  5. * linux/arch/mips/pci/fixup-rbtx4938.c,
  6. * linux/arch/mips/txx9/rbtx4938/setup.c,
  7. * and RBTX49xx patch from CELF patch archive.
  8. *
  9. * 2003-2005 (c) MontaVista Software, Inc.
  10. * Copyright (C) 2004 by Ralf Baechle (ralf@linux-mips.org)
  11. * (C) Copyright TOSHIBA CORPORATION 2000-2001, 2004-2007
  12. *
  13. * This program is free software; you can redistribute it and/or modify it
  14. * under the terms of the GNU General Public License as published by the
  15. * Free Software Foundation; either version 2 of the License, or (at your
  16. * option) any later version.
  17. */
  18. #include <linux/kernel.h>
  19. #include <asm/txx9/tx4927pcic.h>
  20. static struct {
  21. struct pci_controller *channel;
  22. struct tx4927_pcic_reg __iomem *pcicptr;
  23. } pcicptrs[2]; /* TX4938 has 2 pcic */
  24. static void __init set_tx4927_pcicptr(struct pci_controller *channel,
  25. struct tx4927_pcic_reg __iomem *pcicptr)
  26. {
  27. int i;
  28. for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) {
  29. if (pcicptrs[i].channel == channel) {
  30. pcicptrs[i].pcicptr = pcicptr;
  31. return;
  32. }
  33. }
  34. for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) {
  35. if (!pcicptrs[i].channel) {
  36. pcicptrs[i].channel = channel;
  37. pcicptrs[i].pcicptr = pcicptr;
  38. return;
  39. }
  40. }
  41. BUG();
  42. }
  43. struct tx4927_pcic_reg __iomem *get_tx4927_pcicptr(
  44. struct pci_controller *channel)
  45. {
  46. int i;
  47. for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) {
  48. if (pcicptrs[i].channel == channel)
  49. return pcicptrs[i].pcicptr;
  50. }
  51. return NULL;
  52. }
  53. static int mkaddr(struct pci_bus *bus, unsigned int devfn, int where,
  54. struct tx4927_pcic_reg __iomem *pcicptr)
  55. {
  56. if (bus->parent == NULL &&
  57. devfn >= PCI_DEVFN(TX4927_PCIC_MAX_DEVNU, 0))
  58. return -1;
  59. __raw_writel(((bus->number & 0xff) << 0x10)
  60. | ((devfn & 0xff) << 0x08) | (where & 0xfc)
  61. | (bus->parent ? 1 : 0),
  62. &pcicptr->g2pcfgadrs);
  63. /* clear M_ABORT and Disable M_ABORT Int. */
  64. __raw_writel((__raw_readl(&pcicptr->pcistatus) & 0x0000ffff)
  65. | (PCI_STATUS_REC_MASTER_ABORT << 16),
  66. &pcicptr->pcistatus);
  67. return 0;
  68. }
  69. static int check_abort(struct tx4927_pcic_reg __iomem *pcicptr)
  70. {
  71. int code = PCIBIOS_SUCCESSFUL;
  72. /* wait write cycle completion before checking error status */
  73. while (__raw_readl(&pcicptr->pcicstatus) & TX4927_PCIC_PCICSTATUS_IWB)
  74. ;
  75. if (__raw_readl(&pcicptr->pcistatus)
  76. & (PCI_STATUS_REC_MASTER_ABORT << 16)) {
  77. __raw_writel((__raw_readl(&pcicptr->pcistatus) & 0x0000ffff)
  78. | (PCI_STATUS_REC_MASTER_ABORT << 16),
  79. &pcicptr->pcistatus);
  80. /* flush write buffer */
  81. iob();
  82. code = PCIBIOS_DEVICE_NOT_FOUND;
  83. }
  84. return code;
  85. }
  86. static u8 icd_readb(int offset, struct tx4927_pcic_reg __iomem *pcicptr)
  87. {
  88. #ifdef __BIG_ENDIAN
  89. offset ^= 3;
  90. #endif
  91. return __raw_readb((void __iomem *)&pcicptr->g2pcfgdata + offset);
  92. }
  93. static u16 icd_readw(int offset, struct tx4927_pcic_reg __iomem *pcicptr)
  94. {
  95. #ifdef __BIG_ENDIAN
  96. offset ^= 2;
  97. #endif
  98. return __raw_readw((void __iomem *)&pcicptr->g2pcfgdata + offset);
  99. }
  100. static u32 icd_readl(struct tx4927_pcic_reg __iomem *pcicptr)
  101. {
  102. return __raw_readl(&pcicptr->g2pcfgdata);
  103. }
  104. static void icd_writeb(u8 val, int offset,
  105. struct tx4927_pcic_reg __iomem *pcicptr)
  106. {
  107. #ifdef __BIG_ENDIAN
  108. offset ^= 3;
  109. #endif
  110. __raw_writeb(val, (void __iomem *)&pcicptr->g2pcfgdata + offset);
  111. }
  112. static void icd_writew(u16 val, int offset,
  113. struct tx4927_pcic_reg __iomem *pcicptr)
  114. {
  115. #ifdef __BIG_ENDIAN
  116. offset ^= 2;
  117. #endif
  118. __raw_writew(val, (void __iomem *)&pcicptr->g2pcfgdata + offset);
  119. }
  120. static void icd_writel(u32 val, struct tx4927_pcic_reg __iomem *pcicptr)
  121. {
  122. __raw_writel(val, &pcicptr->g2pcfgdata);
  123. }
  124. static struct tx4927_pcic_reg __iomem *pci_bus_to_pcicptr(struct pci_bus *bus)
  125. {
  126. struct pci_controller *channel = bus->sysdata;
  127. return get_tx4927_pcicptr(channel);
  128. }
  129. static int tx4927_pci_config_read(struct pci_bus *bus, unsigned int devfn,
  130. int where, int size, u32 *val)
  131. {
  132. struct tx4927_pcic_reg __iomem *pcicptr = pci_bus_to_pcicptr(bus);
  133. if (mkaddr(bus, devfn, where, pcicptr)) {
  134. *val = 0xffffffff;
  135. return -1;
  136. }
  137. switch (size) {
  138. case 1:
  139. *val = icd_readb(where & 3, pcicptr);
  140. break;
  141. case 2:
  142. *val = icd_readw(where & 3, pcicptr);
  143. break;
  144. default:
  145. *val = icd_readl(pcicptr);
  146. }
  147. return check_abort(pcicptr);
  148. }
  149. static int tx4927_pci_config_write(struct pci_bus *bus, unsigned int devfn,
  150. int where, int size, u32 val)
  151. {
  152. struct tx4927_pcic_reg __iomem *pcicptr = pci_bus_to_pcicptr(bus);
  153. if (mkaddr(bus, devfn, where, pcicptr))
  154. return -1;
  155. switch (size) {
  156. case 1:
  157. icd_writeb(val, where & 3, pcicptr);
  158. break;
  159. case 2:
  160. icd_writew(val, where & 3, pcicptr);
  161. break;
  162. default:
  163. icd_writel(val, pcicptr);
  164. }
  165. return check_abort(pcicptr);
  166. }
  167. static struct pci_ops tx4927_pci_ops = {
  168. .read = tx4927_pci_config_read,
  169. .write = tx4927_pci_config_write,
  170. };
  171. static struct {
  172. u8 trdyto;
  173. u8 retryto;
  174. u16 gbwc;
  175. } tx4927_pci_opts __devinitdata = {
  176. .trdyto = 0,
  177. .retryto = 0,
  178. .gbwc = 0xfe0, /* 4064 GBUSCLK for CCFG.GTOT=0b11 */
  179. };
  180. char *__devinit tx4927_pcibios_setup(char *str)
  181. {
  182. unsigned long val;
  183. if (!strncmp(str, "trdyto=", 7)) {
  184. if (strict_strtoul(str + 7, 0, &val) == 0)
  185. tx4927_pci_opts.trdyto = val;
  186. return NULL;
  187. }
  188. if (!strncmp(str, "retryto=", 8)) {
  189. if (strict_strtoul(str + 8, 0, &val) == 0)
  190. tx4927_pci_opts.retryto = val;
  191. return NULL;
  192. }
  193. if (!strncmp(str, "gbwc=", 5)) {
  194. if (strict_strtoul(str + 5, 0, &val) == 0)
  195. tx4927_pci_opts.gbwc = val;
  196. return NULL;
  197. }
  198. return str;
  199. }
  200. void __init tx4927_pcic_setup(struct tx4927_pcic_reg __iomem *pcicptr,
  201. struct pci_controller *channel, int extarb)
  202. {
  203. int i;
  204. unsigned long flags;
  205. set_tx4927_pcicptr(channel, pcicptr);
  206. if (!channel->pci_ops)
  207. printk(KERN_INFO
  208. "PCIC -- DID:%04x VID:%04x RID:%02x Arbiter:%s\n",
  209. __raw_readl(&pcicptr->pciid) >> 16,
  210. __raw_readl(&pcicptr->pciid) & 0xffff,
  211. __raw_readl(&pcicptr->pciccrev) & 0xff,
  212. extarb ? "External" : "Internal");
  213. channel->pci_ops = &tx4927_pci_ops;
  214. local_irq_save(flags);
  215. /* Disable All Initiator Space */
  216. __raw_writel(__raw_readl(&pcicptr->pciccfg)
  217. & ~(TX4927_PCIC_PCICCFG_G2PMEN(0)
  218. | TX4927_PCIC_PCICCFG_G2PMEN(1)
  219. | TX4927_PCIC_PCICCFG_G2PMEN(2)
  220. | TX4927_PCIC_PCICCFG_G2PIOEN),
  221. &pcicptr->pciccfg);
  222. /* GB->PCI mappings */
  223. __raw_writel((channel->io_resource->end - channel->io_resource->start)
  224. >> 4,
  225. &pcicptr->g2piomask);
  226. ____raw_writeq((channel->io_resource->start +
  227. channel->io_map_base - IO_BASE) |
  228. #ifdef __BIG_ENDIAN
  229. TX4927_PCIC_G2PIOGBASE_ECHG
  230. #else
  231. TX4927_PCIC_G2PIOGBASE_BSDIS
  232. #endif
  233. , &pcicptr->g2piogbase);
  234. ____raw_writeq(channel->io_resource->start - channel->io_offset,
  235. &pcicptr->g2piopbase);
  236. for (i = 0; i < 3; i++) {
  237. __raw_writel(0, &pcicptr->g2pmmask[i]);
  238. ____raw_writeq(0, &pcicptr->g2pmgbase[i]);
  239. ____raw_writeq(0, &pcicptr->g2pmpbase[i]);
  240. }
  241. if (channel->mem_resource->end) {
  242. __raw_writel((channel->mem_resource->end
  243. - channel->mem_resource->start) >> 4,
  244. &pcicptr->g2pmmask[0]);
  245. ____raw_writeq(channel->mem_resource->start |
  246. #ifdef __BIG_ENDIAN
  247. TX4927_PCIC_G2PMnGBASE_ECHG
  248. #else
  249. TX4927_PCIC_G2PMnGBASE_BSDIS
  250. #endif
  251. , &pcicptr->g2pmgbase[0]);
  252. ____raw_writeq(channel->mem_resource->start -
  253. channel->mem_offset,
  254. &pcicptr->g2pmpbase[0]);
  255. }
  256. /* PCI->GB mappings (I/O 256B) */
  257. __raw_writel(0, &pcicptr->p2giopbase); /* 256B */
  258. ____raw_writeq(0, &pcicptr->p2giogbase);
  259. /* PCI->GB mappings (MEM 512MB (64MB on R1.x)) */
  260. __raw_writel(0, &pcicptr->p2gm0plbase);
  261. __raw_writel(0, &pcicptr->p2gm0pubase);
  262. ____raw_writeq(TX4927_PCIC_P2GMnGBASE_TMEMEN |
  263. #ifdef __BIG_ENDIAN
  264. TX4927_PCIC_P2GMnGBASE_TECHG
  265. #else
  266. TX4927_PCIC_P2GMnGBASE_TBSDIS
  267. #endif
  268. , &pcicptr->p2gmgbase[0]);
  269. /* PCI->GB mappings (MEM 16MB) */
  270. __raw_writel(0xffffffff, &pcicptr->p2gm1plbase);
  271. __raw_writel(0xffffffff, &pcicptr->p2gm1pubase);
  272. ____raw_writeq(0, &pcicptr->p2gmgbase[1]);
  273. /* PCI->GB mappings (MEM 1MB) */
  274. __raw_writel(0xffffffff, &pcicptr->p2gm2pbase); /* 1MB */
  275. ____raw_writeq(0, &pcicptr->p2gmgbase[2]);
  276. /* Clear all (including IRBER) except for GBWC */
  277. __raw_writel((tx4927_pci_opts.gbwc << 16)
  278. & TX4927_PCIC_PCICCFG_GBWC_MASK,
  279. &pcicptr->pciccfg);
  280. /* Enable Initiator Memory Space */
  281. if (channel->mem_resource->end)
  282. __raw_writel(__raw_readl(&pcicptr->pciccfg)
  283. | TX4927_PCIC_PCICCFG_G2PMEN(0),
  284. &pcicptr->pciccfg);
  285. /* Enable Initiator I/O Space */
  286. if (channel->io_resource->end)
  287. __raw_writel(__raw_readl(&pcicptr->pciccfg)
  288. | TX4927_PCIC_PCICCFG_G2PIOEN,
  289. &pcicptr->pciccfg);
  290. /* Enable Initiator Config */
  291. __raw_writel(__raw_readl(&pcicptr->pciccfg)
  292. | TX4927_PCIC_PCICCFG_ICAEN | TX4927_PCIC_PCICCFG_TCAR,
  293. &pcicptr->pciccfg);
  294. /* Do not use MEMMUL, MEMINF: YMFPCI card causes M_ABORT. */
  295. __raw_writel(0, &pcicptr->pcicfg1);
  296. __raw_writel((__raw_readl(&pcicptr->g2ptocnt) & ~0xffff)
  297. | (tx4927_pci_opts.trdyto & 0xff)
  298. | ((tx4927_pci_opts.retryto & 0xff) << 8),
  299. &pcicptr->g2ptocnt);
  300. /* Clear All Local Bus Status */
  301. __raw_writel(TX4927_PCIC_PCICSTATUS_ALL, &pcicptr->pcicstatus);
  302. /* Enable All Local Bus Interrupts */
  303. __raw_writel(TX4927_PCIC_PCICSTATUS_ALL, &pcicptr->pcicmask);
  304. /* Clear All Initiator Status */
  305. __raw_writel(TX4927_PCIC_G2PSTATUS_ALL, &pcicptr->g2pstatus);
  306. /* Enable All Initiator Interrupts */
  307. __raw_writel(TX4927_PCIC_G2PSTATUS_ALL, &pcicptr->g2pmask);
  308. /* Clear All PCI Status Error */
  309. __raw_writel((__raw_readl(&pcicptr->pcistatus) & 0x0000ffff)
  310. | (TX4927_PCIC_PCISTATUS_ALL << 16),
  311. &pcicptr->pcistatus);
  312. /* Enable All PCI Status Error Interrupts */
  313. __raw_writel(TX4927_PCIC_PCISTATUS_ALL, &pcicptr->pcimask);
  314. if (!extarb) {
  315. /* Reset Bus Arbiter */
  316. __raw_writel(TX4927_PCIC_PBACFG_RPBA, &pcicptr->pbacfg);
  317. __raw_writel(0, &pcicptr->pbabm);
  318. /* Enable Bus Arbiter */
  319. __raw_writel(TX4927_PCIC_PBACFG_PBAEN, &pcicptr->pbacfg);
  320. }
  321. __raw_writel(PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY
  322. | PCI_COMMAND_PARITY | PCI_COMMAND_SERR,
  323. &pcicptr->pcistatus);
  324. local_irq_restore(flags);
  325. printk(KERN_DEBUG
  326. "PCI: COMMAND=%04x,PCIMASK=%04x,"
  327. "TRDYTO=%02x,RETRYTO=%02x,GBWC=%03x\n",
  328. __raw_readl(&pcicptr->pcistatus) & 0xffff,
  329. __raw_readl(&pcicptr->pcimask) & 0xffff,
  330. __raw_readl(&pcicptr->g2ptocnt) & 0xff,
  331. (__raw_readl(&pcicptr->g2ptocnt) & 0xff00) >> 8,
  332. (__raw_readl(&pcicptr->pciccfg) >> 16) & 0xfff);
  333. }
  334. static void tx4927_report_pcic_status1(struct tx4927_pcic_reg __iomem *pcicptr)
  335. {
  336. __u16 pcistatus = (__u16)(__raw_readl(&pcicptr->pcistatus) >> 16);
  337. __u32 g2pstatus = __raw_readl(&pcicptr->g2pstatus);
  338. __u32 pcicstatus = __raw_readl(&pcicptr->pcicstatus);
  339. static struct {
  340. __u32 flag;
  341. const char *str;
  342. } pcistat_tbl[] = {
  343. { PCI_STATUS_DETECTED_PARITY, "DetectedParityError" },
  344. { PCI_STATUS_SIG_SYSTEM_ERROR, "SignaledSystemError" },
  345. { PCI_STATUS_REC_MASTER_ABORT, "ReceivedMasterAbort" },
  346. { PCI_STATUS_REC_TARGET_ABORT, "ReceivedTargetAbort" },
  347. { PCI_STATUS_SIG_TARGET_ABORT, "SignaledTargetAbort" },
  348. { PCI_STATUS_PARITY, "MasterParityError" },
  349. }, g2pstat_tbl[] = {
  350. { TX4927_PCIC_G2PSTATUS_TTOE, "TIOE" },
  351. { TX4927_PCIC_G2PSTATUS_RTOE, "RTOE" },
  352. }, pcicstat_tbl[] = {
  353. { TX4927_PCIC_PCICSTATUS_PME, "PME" },
  354. { TX4927_PCIC_PCICSTATUS_TLB, "TLB" },
  355. { TX4927_PCIC_PCICSTATUS_NIB, "NIB" },
  356. { TX4927_PCIC_PCICSTATUS_ZIB, "ZIB" },
  357. { TX4927_PCIC_PCICSTATUS_PERR, "PERR" },
  358. { TX4927_PCIC_PCICSTATUS_SERR, "SERR" },
  359. { TX4927_PCIC_PCICSTATUS_GBE, "GBE" },
  360. { TX4927_PCIC_PCICSTATUS_IWB, "IWB" },
  361. };
  362. int i, cont;
  363. printk(KERN_ERR "");
  364. if (pcistatus & TX4927_PCIC_PCISTATUS_ALL) {
  365. printk(KERN_CONT "pcistat:%04x(", pcistatus);
  366. for (i = 0, cont = 0; i < ARRAY_SIZE(pcistat_tbl); i++)
  367. if (pcistatus & pcistat_tbl[i].flag)
  368. printk(KERN_CONT "%s%s",
  369. cont++ ? " " : "", pcistat_tbl[i].str);
  370. printk(KERN_CONT ") ");
  371. }
  372. if (g2pstatus & TX4927_PCIC_G2PSTATUS_ALL) {
  373. printk(KERN_CONT "g2pstatus:%08x(", g2pstatus);
  374. for (i = 0, cont = 0; i < ARRAY_SIZE(g2pstat_tbl); i++)
  375. if (g2pstatus & g2pstat_tbl[i].flag)
  376. printk(KERN_CONT "%s%s",
  377. cont++ ? " " : "", g2pstat_tbl[i].str);
  378. printk(KERN_CONT ") ");
  379. }
  380. if (pcicstatus & TX4927_PCIC_PCICSTATUS_ALL) {
  381. printk(KERN_CONT "pcicstatus:%08x(", pcicstatus);
  382. for (i = 0, cont = 0; i < ARRAY_SIZE(pcicstat_tbl); i++)
  383. if (pcicstatus & pcicstat_tbl[i].flag)
  384. printk(KERN_CONT "%s%s",
  385. cont++ ? " " : "", pcicstat_tbl[i].str);
  386. printk(KERN_CONT ")");
  387. }
  388. printk(KERN_CONT "\n");
  389. }
  390. void tx4927_report_pcic_status(void)
  391. {
  392. int i;
  393. for (i = 0; i < ARRAY_SIZE(pcicptrs); i++) {
  394. if (pcicptrs[i].pcicptr)
  395. tx4927_report_pcic_status1(pcicptrs[i].pcicptr);
  396. }
  397. }
  398. #ifdef CONFIG_TOSHIBA_FPCIB0
  399. static void __init tx4927_quirk_slc90e66_bridge(struct pci_dev *dev)
  400. {
  401. struct tx4927_pcic_reg __iomem *pcicptr = pci_bus_to_pcicptr(dev->bus);
  402. if (!pcicptr)
  403. return;
  404. if (__raw_readl(&pcicptr->pbacfg) & TX4927_PCIC_PBACFG_PBAEN) {
  405. /* Reset Bus Arbiter */
  406. __raw_writel(TX4927_PCIC_PBACFG_RPBA, &pcicptr->pbacfg);
  407. /*
  408. * swap reqBP and reqXP (raise priority of SLC90E66).
  409. * SLC90E66(PCI-ISA bridge) is connected to REQ2 on
  410. * PCI Backplane board.
  411. */
  412. __raw_writel(0x72543610, &pcicptr->pbareqport);
  413. __raw_writel(0, &pcicptr->pbabm);
  414. /* Use Fixed ParkMaster (required by SLC90E66) */
  415. __raw_writel(TX4927_PCIC_PBACFG_FIXPA, &pcicptr->pbacfg);
  416. /* Enable Bus Arbiter */
  417. __raw_writel(TX4927_PCIC_PBACFG_FIXPA |
  418. TX4927_PCIC_PBACFG_PBAEN,
  419. &pcicptr->pbacfg);
  420. printk(KERN_INFO "PCI: Use Fixed Park Master (REQPORT %08x)\n",
  421. __raw_readl(&pcicptr->pbareqport));
  422. }
  423. }
  424. #define PCI_DEVICE_ID_EFAR_SLC90E66_0 0x9460
  425. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_EFAR, PCI_DEVICE_ID_EFAR_SLC90E66_0,
  426. tx4927_quirk_slc90e66_bridge);
  427. #endif