Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
pmc.c
Go to the documentation of this file.
1 /* pmc - Driver implementation for power management functions
2  * of Power Management Controller (PMC) on SPARCstation-Voyager.
3  *
4  * Copyright (c) 2002 Eric Brower ([email protected])
5  */
6 
7 #include <linux/kernel.h>
8 #include <linux/fs.h>
9 #include <linux/errno.h>
10 #include <linux/init.h>
11 #include <linux/pm.h>
12 #include <linux/of.h>
13 #include <linux/of_device.h>
14 #include <linux/module.h>
15 
16 #include <asm/io.h>
17 #include <asm/oplib.h>
18 #include <asm/uaccess.h>
19 #include <asm/auxio.h>
20 
21 /* Debug
22  *
23  * #define PMC_DEBUG_LED
24  * #define PMC_NO_IDLE
25  */
26 
27 #define PMC_OBPNAME "SUNW,pmc"
28 #define PMC_DEVNAME "pmc"
29 
30 #define PMC_IDLE_REG 0x00
31 #define PMC_IDLE_ON 0x01
32 
33 static u8 __iomem *regs;
34 
35 #define pmc_readb(offs) (sbus_readb(regs+offs))
36 #define pmc_writeb(val, offs) (sbus_writeb(val, regs+offs))
37 
38 /*
39  * CPU idle callback function
40  * See .../arch/sparc/kernel/process.c
41  */
42 static void pmc_swift_idle(void)
43 {
44 #ifdef PMC_DEBUG_LED
45  set_auxio(0x00, AUXIO_LED);
46 #endif
47 
49 
50 #ifdef PMC_DEBUG_LED
51  set_auxio(AUXIO_LED, 0x00);
52 #endif
53 }
54 
55 static int __devinit pmc_probe(struct platform_device *op)
56 {
57  regs = of_ioremap(&op->resource[0], 0,
58  resource_size(&op->resource[0]), PMC_OBPNAME);
59  if (!regs) {
60  printk(KERN_ERR "%s: unable to map registers\n", PMC_DEVNAME);
61  return -ENODEV;
62  }
63 
64 #ifndef PMC_NO_IDLE
65  /* Assign power management IDLE handler */
66  pm_idle = pmc_swift_idle;
67 #endif
68 
69  printk(KERN_INFO "%s: power management initialized\n", PMC_DEVNAME);
70  return 0;
71 }
72 
73 static struct of_device_id pmc_match[] = {
74  {
75  .name = PMC_OBPNAME,
76  },
77  {},
78 };
79 MODULE_DEVICE_TABLE(of, pmc_match);
80 
81 static struct platform_driver pmc_driver = {
82  .driver = {
83  .name = "pmc",
84  .owner = THIS_MODULE,
85  .of_match_table = pmc_match,
86  },
87  .probe = pmc_probe,
88 };
89 
90 static int __init pmc_init(void)
91 {
92  return platform_driver_register(&pmc_driver);
93 }
94 
95 /* This driver is not critical to the boot process
96  * and is easiest to ioremap when SBus is already
97  * initialized, so we install ourselves thusly:
98  */
99 __initcall(pmc_init);