aboutsummaryrefslogtreecommitdiffstats
path: root/arch/mips/pci/pci-alchemy.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/mips/pci/pci-alchemy.c')
-rw-r--r--arch/mips/pci/pci-alchemy.c138
1 files changed, 68 insertions, 70 deletions
diff --git a/arch/mips/pci/pci-alchemy.c b/arch/mips/pci/pci-alchemy.c
index b5ce041cdaf..ec125bed721 100644
--- a/arch/mips/pci/pci-alchemy.c
+++ b/arch/mips/pci/pci-alchemy.c
@@ -13,9 +13,11 @@
13#include <linux/platform_device.h> 13#include <linux/platform_device.h>
14#include <linux/kernel.h> 14#include <linux/kernel.h>
15#include <linux/init.h> 15#include <linux/init.h>
16#include <linux/syscore_ops.h>
16#include <linux/vmalloc.h> 17#include <linux/vmalloc.h>
17 18
18#include <asm/mach-au1x00/au1000.h> 19#include <asm/mach-au1x00/au1000.h>
20#include <asm/tlbmisc.h>
19 21
20#ifdef CONFIG_DEBUG_PCI 22#ifdef CONFIG_DEBUG_PCI
21#define DBG(x...) printk(KERN_DEBUG x) 23#define DBG(x...) printk(KERN_DEBUG x)
@@ -41,6 +43,12 @@ struct alchemy_pci_context {
41 int (*board_pci_idsel)(unsigned int devsel, int assert); 43 int (*board_pci_idsel)(unsigned int devsel, int assert);
42}; 44};
43 45
46/* for syscore_ops. There's only one PCI controller on Alchemy chips, so this
47 * should suffice for now.
48 */
49static struct alchemy_pci_context *__alchemy_pci_ctx;
50
51
44/* IO/MEM resources for PCI. Keep the memres in sync with __fixup_bigphys_addr 52/* IO/MEM resources for PCI. Keep the memres in sync with __fixup_bigphys_addr
45 * in arch/mips/alchemy/common/setup.c 53 * in arch/mips/alchemy/common/setup.c
46 */ 54 */
@@ -99,18 +107,6 @@ static int config_access(unsigned char access_type, struct pci_bus *bus,
99 return -1; 107 return -1;
100 } 108 }
101 109
102 /* YAMON on all db1xxx boards wipes the TLB and writes zero to C0_wired
103 * on resume, clearing our wired entry. Unfortunately the ->resume()
104 * callback is called way way way too late (and ->suspend() too early)
105 * to have them destroy and recreate it. Instead just test if c0_wired
106 * is now lower than the index we retrieved before suspending and then
107 * recreate the entry if necessary. Of course this is totally bonkers
108 * and breaks as soon as someone else adds another wired entry somewhere
109 * else. Anyone have any ideas how to handle this better?
110 */
111 if (unlikely(read_c0_wired() < ctx->wired_entry))
112 alchemy_pci_wired_entry(ctx);
113
114 local_irq_save(flags); 110 local_irq_save(flags);
115 r = __raw_readl(ctx->regs + PCI_REG_STATCMD) & 0x0000ffff; 111 r = __raw_readl(ctx->regs + PCI_REG_STATCMD) & 0x0000ffff;
116 r |= PCI_STATCMD_STATUS(0x2000); 112 r |= PCI_STATCMD_STATUS(0x2000);
@@ -304,6 +300,62 @@ static int alchemy_pci_def_idsel(unsigned int devsel, int assert)
304 return 1; /* success */ 300 return 1; /* success */
305} 301}
306 302
303/* save PCI controller register contents. */
304static int alchemy_pci_suspend(void)
305{
306 struct alchemy_pci_context *ctx = __alchemy_pci_ctx;
307 if (!ctx)
308 return 0;
309
310 ctx->pm[0] = __raw_readl(ctx->regs + PCI_REG_CMEM);
311 ctx->pm[1] = __raw_readl(ctx->regs + PCI_REG_CONFIG) & 0x0009ffff;
312 ctx->pm[2] = __raw_readl(ctx->regs + PCI_REG_B2BMASK_CCH);
313 ctx->pm[3] = __raw_readl(ctx->regs + PCI_REG_B2BBASE0_VID);
314 ctx->pm[4] = __raw_readl(ctx->regs + PCI_REG_B2BBASE1_SID);
315 ctx->pm[5] = __raw_readl(ctx->regs + PCI_REG_MWMASK_DEV);
316 ctx->pm[6] = __raw_readl(ctx->regs + PCI_REG_MWBASE_REV_CCL);
317 ctx->pm[7] = __raw_readl(ctx->regs + PCI_REG_ID);
318 ctx->pm[8] = __raw_readl(ctx->regs + PCI_REG_CLASSREV);
319 ctx->pm[9] = __raw_readl(ctx->regs + PCI_REG_PARAM);
320 ctx->pm[10] = __raw_readl(ctx->regs + PCI_REG_MBAR);
321 ctx->pm[11] = __raw_readl(ctx->regs + PCI_REG_TIMEOUT);
322
323 return 0;
324}
325
326static void alchemy_pci_resume(void)
327{
328 struct alchemy_pci_context *ctx = __alchemy_pci_ctx;
329 if (!ctx)
330 return;
331
332 __raw_writel(ctx->pm[0], ctx->regs + PCI_REG_CMEM);
333 __raw_writel(ctx->pm[2], ctx->regs + PCI_REG_B2BMASK_CCH);
334 __raw_writel(ctx->pm[3], ctx->regs + PCI_REG_B2BBASE0_VID);
335 __raw_writel(ctx->pm[4], ctx->regs + PCI_REG_B2BBASE1_SID);
336 __raw_writel(ctx->pm[5], ctx->regs + PCI_REG_MWMASK_DEV);
337 __raw_writel(ctx->pm[6], ctx->regs + PCI_REG_MWBASE_REV_CCL);
338 __raw_writel(ctx->pm[7], ctx->regs + PCI_REG_ID);
339 __raw_writel(ctx->pm[8], ctx->regs + PCI_REG_CLASSREV);
340 __raw_writel(ctx->pm[9], ctx->regs + PCI_REG_PARAM);
341 __raw_writel(ctx->pm[10], ctx->regs + PCI_REG_MBAR);
342 __raw_writel(ctx->pm[11], ctx->regs + PCI_REG_TIMEOUT);
343 wmb();
344 __raw_writel(ctx->pm[1], ctx->regs + PCI_REG_CONFIG);
345 wmb();
346
347 /* YAMON on all db1xxx boards wipes the TLB and writes zero to C0_wired
348 * on resume, making it necessary to recreate it as soon as possible.
349 */
350 ctx->wired_entry = 8191; /* impossibly high value */
351 alchemy_pci_wired_entry(ctx); /* install it */
352}
353
354static struct syscore_ops alchemy_pci_pmops = {
355 .suspend = alchemy_pci_suspend,
356 .resume = alchemy_pci_resume,
357};
358
307static int __devinit alchemy_pci_probe(struct platform_device *pdev) 359static int __devinit alchemy_pci_probe(struct platform_device *pdev)
308{ 360{
309 struct alchemy_pci_platdata *pd = pdev->dev.platform_data; 361 struct alchemy_pci_platdata *pd = pdev->dev.platform_data;
@@ -396,7 +448,8 @@ static int __devinit alchemy_pci_probe(struct platform_device *pdev)
396 ret = -ENOMEM; 448 ret = -ENOMEM;
397 goto out4; 449 goto out4;
398 } 450 }
399 ctx->wired_entry = 8192; /* impossibly high value */ 451 ctx->wired_entry = 8191; /* impossibly high value */
452 alchemy_pci_wired_entry(ctx); /* install it */
400 453
401 set_io_port_base((unsigned long)ctx->alchemy_pci_ctrl.io_map_base); 454 set_io_port_base((unsigned long)ctx->alchemy_pci_ctrl.io_map_base);
402 455
@@ -408,7 +461,9 @@ static int __devinit alchemy_pci_probe(struct platform_device *pdev)
408 __raw_writel(val, ctx->regs + PCI_REG_CONFIG); 461 __raw_writel(val, ctx->regs + PCI_REG_CONFIG);
409 wmb(); 462 wmb();
410 463
464 __alchemy_pci_ctx = ctx;
411 platform_set_drvdata(pdev, ctx); 465 platform_set_drvdata(pdev, ctx);
466 register_syscore_ops(&alchemy_pci_pmops);
412 register_pci_controller(&ctx->alchemy_pci_ctrl); 467 register_pci_controller(&ctx->alchemy_pci_ctrl);
413 468
414 return 0; 469 return 0;
@@ -425,68 +480,11 @@ out:
425 return ret; 480 return ret;
426} 481}
427 482
428
429#ifdef CONFIG_PM
430/* save PCI controller register contents. */
431static int alchemy_pci_suspend(struct device *dev)
432{
433 struct alchemy_pci_context *ctx = dev_get_drvdata(dev);
434
435 ctx->pm[0] = __raw_readl(ctx->regs + PCI_REG_CMEM);
436 ctx->pm[1] = __raw_readl(ctx->regs + PCI_REG_CONFIG) & 0x0009ffff;
437 ctx->pm[2] = __raw_readl(ctx->regs + PCI_REG_B2BMASK_CCH);
438 ctx->pm[3] = __raw_readl(ctx->regs + PCI_REG_B2BBASE0_VID);
439 ctx->pm[4] = __raw_readl(ctx->regs + PCI_REG_B2BBASE1_SID);
440 ctx->pm[5] = __raw_readl(ctx->regs + PCI_REG_MWMASK_DEV);
441 ctx->pm[6] = __raw_readl(ctx->regs + PCI_REG_MWBASE_REV_CCL);
442 ctx->pm[7] = __raw_readl(ctx->regs + PCI_REG_ID);
443 ctx->pm[8] = __raw_readl(ctx->regs + PCI_REG_CLASSREV);
444 ctx->pm[9] = __raw_readl(ctx->regs + PCI_REG_PARAM);
445 ctx->pm[10] = __raw_readl(ctx->regs + PCI_REG_MBAR);
446 ctx->pm[11] = __raw_readl(ctx->regs + PCI_REG_TIMEOUT);
447
448 return 0;
449}
450
451static int alchemy_pci_resume(struct device *dev)
452{
453 struct alchemy_pci_context *ctx = dev_get_drvdata(dev);
454
455 __raw_writel(ctx->pm[0], ctx->regs + PCI_REG_CMEM);
456 __raw_writel(ctx->pm[2], ctx->regs + PCI_REG_B2BMASK_CCH);
457 __raw_writel(ctx->pm[3], ctx->regs + PCI_REG_B2BBASE0_VID);
458 __raw_writel(ctx->pm[4], ctx->regs + PCI_REG_B2BBASE1_SID);
459 __raw_writel(ctx->pm[5], ctx->regs + PCI_REG_MWMASK_DEV);
460 __raw_writel(ctx->pm[6], ctx->regs + PCI_REG_MWBASE_REV_CCL);
461 __raw_writel(ctx->pm[7], ctx->regs + PCI_REG_ID);
462 __raw_writel(ctx->pm[8], ctx->regs + PCI_REG_CLASSREV);
463 __raw_writel(ctx->pm[9], ctx->regs + PCI_REG_PARAM);
464 __raw_writel(ctx->pm[10], ctx->regs + PCI_REG_MBAR);
465 __raw_writel(ctx->pm[11], ctx->regs + PCI_REG_TIMEOUT);
466 wmb();
467 __raw_writel(ctx->pm[1], ctx->regs + PCI_REG_CONFIG);
468 wmb();
469
470 return 0;
471}
472
473static const struct dev_pm_ops alchemy_pci_pmops = {
474 .suspend = alchemy_pci_suspend,
475 .resume = alchemy_pci_resume,
476};
477
478#define ALCHEMY_PCICTL_PM (&alchemy_pci_pmops)
479
480#else
481#define ALCHEMY_PCICTL_PM NULL
482#endif
483
484static struct platform_driver alchemy_pcictl_driver = { 483static struct platform_driver alchemy_pcictl_driver = {
485 .probe = alchemy_pci_probe, 484 .probe = alchemy_pci_probe,
486 .driver = { 485 .driver = {
487 .name = "alchemy-pci", 486 .name = "alchemy-pci",
488 .owner = THIS_MODULE, 487 .owner = THIS_MODULE,
489 .pm = ALCHEMY_PCICTL_PM,
490 }, 488 },
491}; 489};
492 490