driver_pcicore.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /*
  2. * Sonics Silicon Backplane
  3. * Broadcom PCI-core driver
  4. *
  5. * Copyright 2005, Broadcom Corporation
  6. * Copyright 2006, 2007, Michael Buesch <mb@bu3sch.de>
  7. *
  8. * Licensed under the GNU/GPL. See COPYING for details.
  9. */
  10. #include <linux/ssb/ssb.h>
  11. #include <linux/pci.h>
  12. #include <linux/delay.h>
  13. #include <linux/ssb/ssb_embedded.h>
  14. #include "ssb_private.h"
  15. static inline
  16. u32 pcicore_read32(struct ssb_pcicore *pc, u16 offset)
  17. {
  18. return ssb_read32(pc->dev, offset);
  19. }
  20. static inline
  21. void pcicore_write32(struct ssb_pcicore *pc, u16 offset, u32 value)
  22. {
  23. ssb_write32(pc->dev, offset, value);
  24. }
  25. static inline
  26. u16 pcicore_read16(struct ssb_pcicore *pc, u16 offset)
  27. {
  28. return ssb_read16(pc->dev, offset);
  29. }
  30. static inline
  31. void pcicore_write16(struct ssb_pcicore *pc, u16 offset, u16 value)
  32. {
  33. ssb_write16(pc->dev, offset, value);
  34. }
  35. /**************************************************
  36. * Code for hostmode operation.
  37. **************************************************/
  38. #ifdef CONFIG_SSB_PCICORE_HOSTMODE
  39. #include <asm/paccess.h>
  40. /* Probe a 32bit value on the bus and catch bus exceptions.
  41. * Returns nonzero on a bus exception.
  42. * This is MIPS specific */
  43. #define mips_busprobe32(val, addr) get_dbe((val), ((u32 *)(addr)))
  44. /* Assume one-hot slot wiring */
  45. #define SSB_PCI_SLOT_MAX 16
  46. /* Global lock is OK, as we won't have more than one extpci anyway. */
  47. static DEFINE_SPINLOCK(cfgspace_lock);
  48. /* Core to access the external PCI config space. Can only have one. */
  49. static struct ssb_pcicore *extpci_core;
  50. static u32 get_cfgspace_addr(struct ssb_pcicore *pc,
  51. unsigned int bus, unsigned int dev,
  52. unsigned int func, unsigned int off)
  53. {
  54. u32 addr = 0;
  55. u32 tmp;
  56. /* We do only have one cardbus device behind the bridge. */
  57. if (pc->cardbusmode && (dev >= 1))
  58. goto out;
  59. if (bus == 0) {
  60. /* Type 0 transaction */
  61. if (unlikely(dev >= SSB_PCI_SLOT_MAX))
  62. goto out;
  63. /* Slide the window */
  64. tmp = SSB_PCICORE_SBTOPCI_CFG0;
  65. tmp |= ((1 << (dev + 16)) & SSB_PCICORE_SBTOPCI1_MASK);
  66. pcicore_write32(pc, SSB_PCICORE_SBTOPCI1, tmp);
  67. /* Calculate the address */
  68. addr = SSB_PCI_CFG;
  69. addr |= ((1 << (dev + 16)) & ~SSB_PCICORE_SBTOPCI1_MASK);
  70. addr |= (func << 8);
  71. addr |= (off & ~3);
  72. } else {
  73. /* Type 1 transaction */
  74. pcicore_write32(pc, SSB_PCICORE_SBTOPCI1,
  75. SSB_PCICORE_SBTOPCI_CFG1);
  76. /* Calculate the address */
  77. addr = SSB_PCI_CFG;
  78. addr |= (bus << 16);
  79. addr |= (dev << 11);
  80. addr |= (func << 8);
  81. addr |= (off & ~3);
  82. }
  83. out:
  84. return addr;
  85. }
  86. static int ssb_extpci_read_config(struct ssb_pcicore *pc,
  87. unsigned int bus, unsigned int dev,
  88. unsigned int func, unsigned int off,
  89. void *buf, int len)
  90. {
  91. int err = -EINVAL;
  92. u32 addr, val;
  93. void __iomem *mmio;
  94. SSB_WARN_ON(!pc->hostmode);
  95. if (unlikely(len != 1 && len != 2 && len != 4))
  96. goto out;
  97. addr = get_cfgspace_addr(pc, bus, dev, func, off);
  98. if (unlikely(!addr))
  99. goto out;
  100. err = -ENOMEM;
  101. mmio = ioremap_nocache(addr, len);
  102. if (!mmio)
  103. goto out;
  104. if (mips_busprobe32(val, mmio)) {
  105. val = 0xffffffff;
  106. goto unmap;
  107. }
  108. val = readl(mmio);
  109. val >>= (8 * (off & 3));
  110. switch (len) {
  111. case 1:
  112. *((u8 *)buf) = (u8)val;
  113. break;
  114. case 2:
  115. *((u16 *)buf) = (u16)val;
  116. break;
  117. case 4:
  118. *((u32 *)buf) = (u32)val;
  119. break;
  120. }
  121. err = 0;
  122. unmap:
  123. iounmap(mmio);
  124. out:
  125. return err;
  126. }
  127. static int ssb_extpci_write_config(struct ssb_pcicore *pc,
  128. unsigned int bus, unsigned int dev,
  129. unsigned int func, unsigned int off,
  130. const void *buf, int len)
  131. {
  132. int err = -EINVAL;
  133. u32 addr, val = 0;
  134. void __iomem *mmio;
  135. SSB_WARN_ON(!pc->hostmode);
  136. if (unlikely(len != 1 && len != 2 && len != 4))
  137. goto out;
  138. addr = get_cfgspace_addr(pc, bus, dev, func, off);
  139. if (unlikely(!addr))
  140. goto out;
  141. err = -ENOMEM;
  142. mmio = ioremap_nocache(addr, len);
  143. if (!mmio)
  144. goto out;
  145. if (mips_busprobe32(val, mmio)) {
  146. val = 0xffffffff;
  147. goto unmap;
  148. }
  149. switch (len) {
  150. case 1:
  151. val = readl(mmio);
  152. val &= ~(0xFF << (8 * (off & 3)));
  153. val |= *((const u8 *)buf) << (8 * (off & 3));
  154. break;
  155. case 2:
  156. val = readl(mmio);
  157. val &= ~(0xFFFF << (8 * (off & 3)));
  158. val |= *((const u16 *)buf) << (8 * (off & 3));
  159. break;
  160. case 4:
  161. val = *((const u32 *)buf);
  162. break;
  163. }
  164. writel(val, mmio);
  165. err = 0;
  166. unmap:
  167. iounmap(mmio);
  168. out:
  169. return err;
  170. }
  171. static int ssb_pcicore_read_config(struct pci_bus *bus, unsigned int devfn,
  172. int reg, int size, u32 *val)
  173. {
  174. unsigned long flags;
  175. int err;
  176. spin_lock_irqsave(&cfgspace_lock, flags);
  177. err = ssb_extpci_read_config(extpci_core, bus->number, PCI_SLOT(devfn),
  178. PCI_FUNC(devfn), reg, val, size);
  179. spin_unlock_irqrestore(&cfgspace_lock, flags);
  180. return err ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
  181. }
  182. static int ssb_pcicore_write_config(struct pci_bus *bus, unsigned int devfn,
  183. int reg, int size, u32 val)
  184. {
  185. unsigned long flags;
  186. int err;
  187. spin_lock_irqsave(&cfgspace_lock, flags);
  188. err = ssb_extpci_write_config(extpci_core, bus->number, PCI_SLOT(devfn),
  189. PCI_FUNC(devfn), reg, &val, size);
  190. spin_unlock_irqrestore(&cfgspace_lock, flags);
  191. return err ? PCIBIOS_DEVICE_NOT_FOUND : PCIBIOS_SUCCESSFUL;
  192. }
  193. static struct pci_ops ssb_pcicore_pciops = {
  194. .read = ssb_pcicore_read_config,
  195. .write = ssb_pcicore_write_config,
  196. };
  197. static struct resource ssb_pcicore_mem_resource = {
  198. .name = "SSB PCIcore external memory",
  199. .start = SSB_PCI_DMA,
  200. .end = SSB_PCI_DMA + SSB_PCI_DMA_SZ - 1,
  201. .flags = IORESOURCE_MEM | IORESOURCE_PCI_FIXED,
  202. };
  203. static struct resource ssb_pcicore_io_resource = {
  204. .name = "SSB PCIcore external I/O",
  205. .start = 0x100,
  206. .end = 0x7FF,
  207. .flags = IORESOURCE_IO | IORESOURCE_PCI_FIXED,
  208. };
  209. static struct pci_controller ssb_pcicore_controller = {
  210. .pci_ops = &ssb_pcicore_pciops,
  211. .io_resource = &ssb_pcicore_io_resource,
  212. .mem_resource = &ssb_pcicore_mem_resource,
  213. };
  214. /* This function is called when doing a pci_enable_device().
  215. * We must first check if the device is a device on the PCI-core bridge. */
  216. int ssb_pcicore_plat_dev_init(struct pci_dev *d)
  217. {
  218. if (d->bus->ops != &ssb_pcicore_pciops) {
  219. /* This is not a device on the PCI-core bridge. */
  220. return -ENODEV;
  221. }
  222. ssb_printk(KERN_INFO "PCI: Fixing up device %s\n",
  223. pci_name(d));
  224. /* Fix up interrupt lines */
  225. d->irq = ssb_mips_irq(extpci_core->dev) + 2;
  226. pci_write_config_byte(d, PCI_INTERRUPT_LINE, d->irq);
  227. return 0;
  228. }
  229. /* Early PCI fixup for a device on the PCI-core bridge. */
  230. static void ssb_pcicore_fixup_pcibridge(struct pci_dev *dev)
  231. {
  232. u8 lat;
  233. if (dev->bus->ops != &ssb_pcicore_pciops) {
  234. /* This is not a device on the PCI-core bridge. */
  235. return;
  236. }
  237. if (dev->bus->number != 0 || PCI_SLOT(dev->devfn) != 0)
  238. return;
  239. ssb_printk(KERN_INFO "PCI: Fixing up bridge %s\n", pci_name(dev));
  240. /* Enable PCI bridge bus mastering and memory space */
  241. pci_set_master(dev);
  242. if (pcibios_enable_device(dev, ~0) < 0) {
  243. ssb_printk(KERN_ERR "PCI: SSB bridge enable failed\n");
  244. return;
  245. }
  246. /* Enable PCI bridge BAR1 prefetch and burst */
  247. pci_write_config_dword(dev, SSB_BAR1_CONTROL, 3);
  248. /* Make sure our latency is high enough to handle the devices behind us */
  249. lat = 168;
  250. ssb_printk(KERN_INFO "PCI: Fixing latency timer of device %s to %u\n",
  251. pci_name(dev), lat);
  252. pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat);
  253. }
  254. DECLARE_PCI_FIXUP_EARLY(PCI_ANY_ID, PCI_ANY_ID, ssb_pcicore_fixup_pcibridge);
  255. /* PCI device IRQ mapping. */
  256. int ssb_pcicore_pcibios_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
  257. {
  258. if (dev->bus->ops != &ssb_pcicore_pciops) {
  259. /* This is not a device on the PCI-core bridge. */
  260. return -ENODEV;
  261. }
  262. return ssb_mips_irq(extpci_core->dev) + 2;
  263. }
  264. static void ssb_pcicore_init_hostmode(struct ssb_pcicore *pc)
  265. {
  266. u32 val;
  267. if (WARN_ON(extpci_core))
  268. return;
  269. extpci_core = pc;
  270. ssb_dprintk(KERN_INFO PFX "PCIcore in host mode found\n");
  271. /* Reset devices on the external PCI bus */
  272. val = SSB_PCICORE_CTL_RST_OE;
  273. val |= SSB_PCICORE_CTL_CLK_OE;
  274. pcicore_write32(pc, SSB_PCICORE_CTL, val);
  275. val |= SSB_PCICORE_CTL_CLK; /* Clock on */
  276. pcicore_write32(pc, SSB_PCICORE_CTL, val);
  277. udelay(150); /* Assertion time demanded by the PCI standard */
  278. val |= SSB_PCICORE_CTL_RST; /* Deassert RST# */
  279. pcicore_write32(pc, SSB_PCICORE_CTL, val);
  280. val = SSB_PCICORE_ARBCTL_INTERN;
  281. pcicore_write32(pc, SSB_PCICORE_ARBCTL, val);
  282. udelay(1); /* Assertion time demanded by the PCI standard */
  283. if (pc->dev->bus->has_cardbus_slot) {
  284. ssb_dprintk(KERN_INFO PFX "CardBus slot detected\n");
  285. pc->cardbusmode = 1;
  286. /* GPIO 1 resets the bridge */
  287. ssb_gpio_out(pc->dev->bus, 1, 1);
  288. ssb_gpio_outen(pc->dev->bus, 1, 1);
  289. pcicore_write16(pc, SSB_PCICORE_SPROM(0),
  290. pcicore_read16(pc, SSB_PCICORE_SPROM(0))
  291. | 0x0400);
  292. }
  293. /* 64MB I/O window */
  294. pcicore_write32(pc, SSB_PCICORE_SBTOPCI0,
  295. SSB_PCICORE_SBTOPCI_IO);
  296. /* 64MB config space */
  297. pcicore_write32(pc, SSB_PCICORE_SBTOPCI1,
  298. SSB_PCICORE_SBTOPCI_CFG0);
  299. /* 1GB memory window */
  300. pcicore_write32(pc, SSB_PCICORE_SBTOPCI2,
  301. SSB_PCICORE_SBTOPCI_MEM | SSB_PCI_DMA);
  302. /* Enable PCI bridge BAR0 prefetch and burst */
  303. val = PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY;
  304. ssb_extpci_write_config(pc, 0, 0, 0, PCI_COMMAND, &val, 2);
  305. /* Clear error conditions */
  306. val = 0;
  307. ssb_extpci_write_config(pc, 0, 0, 0, PCI_STATUS, &val, 2);
  308. /* Enable PCI interrupts */
  309. pcicore_write32(pc, SSB_PCICORE_IMASK,
  310. SSB_PCICORE_IMASK_INTA);
  311. /* Ok, ready to run, register it to the system.
  312. * The following needs change, if we want to port hostmode
  313. * to non-MIPS platform. */
  314. ssb_pcicore_controller.io_map_base = (unsigned long)ioremap_nocache(SSB_PCI_MEM, 0x04000000);
  315. set_io_port_base(ssb_pcicore_controller.io_map_base);
  316. /* Give some time to the PCI controller to configure itself with the new
  317. * values. Not waiting at this point causes crashes of the machine. */
  318. mdelay(10);
  319. register_pci_controller(&ssb_pcicore_controller);
  320. }
  321. static int pcicore_is_in_hostmode(struct ssb_pcicore *pc)
  322. {
  323. struct ssb_bus *bus = pc->dev->bus;
  324. u16 chipid_top;
  325. u32 tmp;
  326. chipid_top = (bus->chip_id & 0xFF00);
  327. if (chipid_top != 0x4700 &&
  328. chipid_top != 0x5300)
  329. return 0;
  330. if (bus->sprom.boardflags_lo & SSB_PCICORE_BFL_NOPCI)
  331. return 0;
  332. /* The 200-pin BCM4712 package does not bond out PCI. Even when
  333. * PCI is bonded out, some boards may leave the pins floating. */
  334. if (bus->chip_id == 0x4712) {
  335. if (bus->chip_package == SSB_CHIPPACK_BCM4712S)
  336. return 0;
  337. if (bus->chip_package == SSB_CHIPPACK_BCM4712M)
  338. return 0;
  339. }
  340. if (bus->chip_id == 0x5350)
  341. return 0;
  342. return !mips_busprobe32(tmp, (bus->mmio + (pc->dev->core_index * SSB_CORE_SIZE)));
  343. }
  344. #endif /* CONFIG_SSB_PCICORE_HOSTMODE */
  345. /**************************************************
  346. * Generic and Clientmode operation code.
  347. **************************************************/
  348. static void ssb_pcicore_init_clientmode(struct ssb_pcicore *pc)
  349. {
  350. /* Disable PCI interrupts. */
  351. ssb_write32(pc->dev, SSB_INTVEC, 0);
  352. }
  353. void ssb_pcicore_init(struct ssb_pcicore *pc)
  354. {
  355. struct ssb_device *dev = pc->dev;
  356. if (!dev)
  357. return;
  358. if (!ssb_device_is_enabled(dev))
  359. ssb_device_enable(dev, 0);
  360. #ifdef CONFIG_SSB_PCICORE_HOSTMODE
  361. pc->hostmode = pcicore_is_in_hostmode(pc);
  362. if (pc->hostmode)
  363. ssb_pcicore_init_hostmode(pc);
  364. #endif /* CONFIG_SSB_PCICORE_HOSTMODE */
  365. if (!pc->hostmode)
  366. ssb_pcicore_init_clientmode(pc);
  367. }
  368. static u32 ssb_pcie_read(struct ssb_pcicore *pc, u32 address)
  369. {
  370. pcicore_write32(pc, 0x130, address);
  371. return pcicore_read32(pc, 0x134);
  372. }
  373. static void ssb_pcie_write(struct ssb_pcicore *pc, u32 address, u32 data)
  374. {
  375. pcicore_write32(pc, 0x130, address);
  376. pcicore_write32(pc, 0x134, data);
  377. }
  378. static void ssb_pcie_mdio_set_phy(struct ssb_pcicore *pc, u8 phy)
  379. {
  380. const u16 mdio_control = 0x128;
  381. const u16 mdio_data = 0x12C;
  382. u32 v;
  383. int i;
  384. v = (1 << 30); /* Start of Transaction */
  385. v |= (1 << 28); /* Write Transaction */
  386. v |= (1 << 17); /* Turnaround */
  387. v |= (0x1F << 18);
  388. v |= (phy << 4);
  389. pcicore_write32(pc, mdio_data, v);
  390. udelay(10);
  391. for (i = 0; i < 200; i++) {
  392. v = pcicore_read32(pc, mdio_control);
  393. if (v & 0x100 /* Trans complete */)
  394. break;
  395. msleep(1);
  396. }
  397. }
  398. #if 0
  399. //done but not used yet
  400. static u16 ssb_pcie_mdio_read(struct ssb_pcicore *pc, u8 device, u8 address)
  401. {
  402. const u16 mdio_control = 0x128;
  403. const u16 mdio_data = 0x12C;
  404. int max_retries = 10;
  405. u16 ret = 0;
  406. u32 v;
  407. int i;
  408. v = 0x80; /* Enable Preamble Sequence */
  409. v |= 0x2; /* MDIO Clock Divisor */
  410. pcicore_write32(pc, mdio_control, v);
  411. if (pc->dev->id.revision >= 10) {
  412. max_retries = 200;
  413. ssb_pcie_mdio_set_phy(pc, device);
  414. }
  415. v = (1 << 30); /* Start of Transaction */
  416. v |= (1 << 29); /* Read Transaction */
  417. v |= (1 << 17); /* Turnaround */
  418. if (pc->dev->id.revision < 10)
  419. v |= (u32)device << 22;
  420. v |= (u32)address << 18;
  421. pcicore_write32(pc, mdio_data, v);
  422. /* Wait for the device to complete the transaction */
  423. udelay(10);
  424. for (i = 0; i < 200; i++) {
  425. v = pcicore_read32(pc, mdio_control);
  426. if (v & 0x100 /* Trans complete */) {
  427. udelay(10);
  428. ret = pcicore_read32(pc, mdio_data);
  429. break;
  430. }
  431. msleep(1);
  432. }
  433. pcicore_write32(pc, mdio_control, 0);
  434. return ret;
  435. }
  436. #endif
  437. static void ssb_pcie_mdio_write(struct ssb_pcicore *pc, u8 device,
  438. u8 address, u16 data)
  439. {
  440. const u16 mdio_control = 0x128;
  441. const u16 mdio_data = 0x12C;
  442. int max_retries = 10;
  443. u32 v;
  444. int i;
  445. v = 0x80; /* Enable Preamble Sequence */
  446. v |= 0x2; /* MDIO Clock Divisor */
  447. pcicore_write32(pc, mdio_control, v);
  448. if (pc->dev->id.revision >= 10) {
  449. max_retries = 200;
  450. ssb_pcie_mdio_set_phy(pc, device);
  451. }
  452. v = (1 << 30); /* Start of Transaction */
  453. v |= (1 << 28); /* Write Transaction */
  454. v |= (1 << 17); /* Turnaround */
  455. if (pc->dev->id.revision < 10)
  456. v |= (u32)device << 22;
  457. v |= (u32)address << 18;
  458. v |= data;
  459. pcicore_write32(pc, mdio_data, v);
  460. /* Wait for the device to complete the transaction */
  461. udelay(10);
  462. for (i = 0; i < max_retries; i++) {
  463. v = pcicore_read32(pc, mdio_control);
  464. if (v & 0x100 /* Trans complete */)
  465. break;
  466. msleep(1);
  467. }
  468. pcicore_write32(pc, mdio_control, 0);
  469. }
  470. static void ssb_broadcast_value(struct ssb_device *dev,
  471. u32 address, u32 data)
  472. {
  473. /* This is used for both, PCI and ChipCommon core, so be careful. */
  474. BUILD_BUG_ON(SSB_PCICORE_BCAST_ADDR != SSB_CHIPCO_BCAST_ADDR);
  475. BUILD_BUG_ON(SSB_PCICORE_BCAST_DATA != SSB_CHIPCO_BCAST_DATA);
  476. ssb_write32(dev, SSB_PCICORE_BCAST_ADDR, address);
  477. ssb_read32(dev, SSB_PCICORE_BCAST_ADDR); /* flush */
  478. ssb_write32(dev, SSB_PCICORE_BCAST_DATA, data);
  479. ssb_read32(dev, SSB_PCICORE_BCAST_DATA); /* flush */
  480. }
  481. static void ssb_commit_settings(struct ssb_bus *bus)
  482. {
  483. struct ssb_device *dev;
  484. dev = bus->chipco.dev ? bus->chipco.dev : bus->pcicore.dev;
  485. if (WARN_ON(!dev))
  486. return;
  487. /* This forces an update of the cached registers. */
  488. ssb_broadcast_value(dev, 0xFD8, 0);
  489. }
  490. int ssb_pcicore_dev_irqvecs_enable(struct ssb_pcicore *pc,
  491. struct ssb_device *dev)
  492. {
  493. struct ssb_device *pdev = pc->dev;
  494. struct ssb_bus *bus;
  495. int err = 0;
  496. u32 tmp;
  497. if (dev->bus->bustype != SSB_BUSTYPE_PCI) {
  498. /* This SSB device is not on a PCI host-bus. So the IRQs are
  499. * not routed through the PCI core.
  500. * So we must not enable routing through the PCI core. */
  501. goto out;
  502. }
  503. if (!pdev)
  504. goto out;
  505. bus = pdev->bus;
  506. might_sleep_if(pdev->id.coreid != SSB_DEV_PCI);
  507. /* Enable interrupts for this device. */
  508. if ((pdev->id.revision >= 6) || (pdev->id.coreid == SSB_DEV_PCIE)) {
  509. u32 coremask;
  510. /* Calculate the "coremask" for the device. */
  511. coremask = (1 << dev->core_index);
  512. SSB_WARN_ON(bus->bustype != SSB_BUSTYPE_PCI);
  513. err = pci_read_config_dword(bus->host_pci, SSB_PCI_IRQMASK, &tmp);
  514. if (err)
  515. goto out;
  516. tmp |= coremask << 8;
  517. err = pci_write_config_dword(bus->host_pci, SSB_PCI_IRQMASK, tmp);
  518. if (err)
  519. goto out;
  520. } else {
  521. u32 intvec;
  522. intvec = ssb_read32(pdev, SSB_INTVEC);
  523. tmp = ssb_read32(dev, SSB_TPSFLAG);
  524. tmp &= SSB_TPSFLAG_BPFLAG;
  525. intvec |= (1 << tmp);
  526. ssb_write32(pdev, SSB_INTVEC, intvec);
  527. }
  528. /* Setup PCIcore operation. */
  529. if (pc->setup_done)
  530. goto out;
  531. if (pdev->id.coreid == SSB_DEV_PCI) {
  532. tmp = pcicore_read32(pc, SSB_PCICORE_SBTOPCI2);
  533. tmp |= SSB_PCICORE_SBTOPCI_PREF;
  534. tmp |= SSB_PCICORE_SBTOPCI_BURST;
  535. pcicore_write32(pc, SSB_PCICORE_SBTOPCI2, tmp);
  536. if (pdev->id.revision < 5) {
  537. tmp = ssb_read32(pdev, SSB_IMCFGLO);
  538. tmp &= ~SSB_IMCFGLO_SERTO;
  539. tmp |= 2;
  540. tmp &= ~SSB_IMCFGLO_REQTO;
  541. tmp |= 3 << SSB_IMCFGLO_REQTO_SHIFT;
  542. ssb_write32(pdev, SSB_IMCFGLO, tmp);
  543. ssb_commit_settings(bus);
  544. } else if (pdev->id.revision >= 11) {
  545. tmp = pcicore_read32(pc, SSB_PCICORE_SBTOPCI2);
  546. tmp |= SSB_PCICORE_SBTOPCI_MRM;
  547. pcicore_write32(pc, SSB_PCICORE_SBTOPCI2, tmp);
  548. }
  549. } else {
  550. WARN_ON(pdev->id.coreid != SSB_DEV_PCIE);
  551. //TODO: Better make defines for all these magic PCIE values.
  552. if ((pdev->id.revision == 0) || (pdev->id.revision == 1)) {
  553. /* TLP Workaround register. */
  554. tmp = ssb_pcie_read(pc, 0x4);
  555. tmp |= 0x8;
  556. ssb_pcie_write(pc, 0x4, tmp);
  557. }
  558. if (pdev->id.revision == 0) {
  559. const u8 serdes_rx_device = 0x1F;
  560. ssb_pcie_mdio_write(pc, serdes_rx_device,
  561. 2 /* Timer */, 0x8128);
  562. ssb_pcie_mdio_write(pc, serdes_rx_device,
  563. 6 /* CDR */, 0x0100);
  564. ssb_pcie_mdio_write(pc, serdes_rx_device,
  565. 7 /* CDR BW */, 0x1466);
  566. } else if (pdev->id.revision == 1) {
  567. /* DLLP Link Control register. */
  568. tmp = ssb_pcie_read(pc, 0x100);
  569. tmp |= 0x40;
  570. ssb_pcie_write(pc, 0x100, tmp);
  571. }
  572. }
  573. pc->setup_done = 1;
  574. out:
  575. return err;
  576. }
  577. EXPORT_SYMBOL(ssb_pcicore_dev_irqvecs_enable);