1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24#include <linux/moduleparam.h>
25#include <linux/module.h>
26#include <linux/platform_device.h>
27#include <linux/kernel.h>
28#include <linux/errno.h>
29#include <linux/delay.h>
30#include <linux/pm.h>
31#include <asm/io.h>
32
33#define IRIS_GIO_BASE 0x340
34#define IRIS_GIO_INPUT IRIS_GIO_BASE
35#define IRIS_GIO_OUTPUT (IRIS_GIO_BASE + 1)
36#define IRIS_GIO_PULSE 0x80
37#define IRIS_GIO_REST 0x00
38#define IRIS_GIO_NODEV 0xff
39
40MODULE_LICENSE("GPL");
41MODULE_AUTHOR("Sébastien Hinderer <Sebastien.Hinderer@ens-lyon.org>");
42MODULE_DESCRIPTION("A power_off handler for Iris devices from EuroBraille");
43MODULE_SUPPORTED_DEVICE("Eurobraille/Iris");
44
45static bool force;
46
47module_param(force, bool, 0);
48MODULE_PARM_DESC(force, "Set to one to force poweroff handler installation.");
49
50static void (*old_pm_power_off)(void);
51
52static void iris_power_off(void)
53{
54 outb(IRIS_GIO_PULSE, IRIS_GIO_OUTPUT);
55 msleep(850);
56 outb(IRIS_GIO_REST, IRIS_GIO_OUTPUT);
57}
58
59
60
61
62
63
64
65static int iris_probe(struct platform_device *pdev)
66{
67 unsigned char status = inb(IRIS_GIO_INPUT);
68 if (status == IRIS_GIO_NODEV) {
69 printk(KERN_ERR "This machine does not seem to be an Iris. "
70 "Power off handler not installed.\n");
71 return -ENODEV;
72 }
73 old_pm_power_off = pm_power_off;
74 pm_power_off = &iris_power_off;
75 printk(KERN_INFO "Iris power_off handler installed.\n");
76 return 0;
77}
78
79static int iris_remove(struct platform_device *pdev)
80{
81 pm_power_off = old_pm_power_off;
82 printk(KERN_INFO "Iris power_off handler uninstalled.\n");
83 return 0;
84}
85
86static struct platform_driver iris_driver = {
87 .driver = {
88 .name = "iris",
89 },
90 .probe = iris_probe,
91 .remove = iris_remove,
92};
93
94static struct resource iris_resources[] = {
95 {
96 .start = IRIS_GIO_BASE,
97 .end = IRIS_GIO_OUTPUT,
98 .flags = IORESOURCE_IO,
99 .name = "address"
100 }
101};
102
103static struct platform_device *iris_device;
104
105static int iris_init(void)
106{
107 int ret;
108 if (force != 1) {
109 printk(KERN_ERR "The force parameter has not been set to 1."
110 " The Iris poweroff handler will not be installed.\n");
111 return -ENODEV;
112 }
113 ret = platform_driver_register(&iris_driver);
114 if (ret < 0) {
115 printk(KERN_ERR "Failed to register iris platform driver: %d\n",
116 ret);
117 return ret;
118 }
119 iris_device = platform_device_register_simple("iris", (-1),
120 iris_resources, ARRAY_SIZE(iris_resources));
121 if (IS_ERR(iris_device)) {
122 printk(KERN_ERR "Failed to register iris platform device\n");
123 platform_driver_unregister(&iris_driver);
124 return PTR_ERR(iris_device);
125 }
126 return 0;
127}
128
129static void iris_exit(void)
130{
131 platform_device_unregister(iris_device);
132 platform_driver_unregister(&iris_driver);
133}
134
135module_init(iris_init);
136module_exit(iris_exit);
137