driver_pcicore.c 18 KB

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