blob: e6cb80f620afffc8882e6bcdaf627b1c32215d41 [file] [log] [blame]
Shérab82148d12010-09-25 06:06:57 +02001/*
2 * Eurobraille/Iris power off support.
3 *
4 * Eurobraille's Iris machine is a PC with no APM or ACPI support.
5 * It is shutdown by a special I/O sequence which this module provides.
6 *
7 * Copyright (C) Shérab <Sebastien.Hinderer@ens-lyon.org>
8 *
9 * This program is free software ; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation ; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY ; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with the program ; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24#include <linux/moduleparam.h>
25#include <linux/module.h>
Shérab88d67ee2012-12-18 14:21:21 -080026#include <linux/platform_device.h>
Shérab82148d12010-09-25 06:06:57 +020027#include <linux/kernel.h>
28#include <linux/errno.h>
29#include <linux/delay.h>
30#include <linux/init.h>
31#include <linux/pm.h>
32#include <asm/io.h>
33
34#define IRIS_GIO_BASE 0x340
35#define IRIS_GIO_INPUT IRIS_GIO_BASE
36#define IRIS_GIO_OUTPUT (IRIS_GIO_BASE + 1)
37#define IRIS_GIO_PULSE 0x80 /* First byte to send */
38#define IRIS_GIO_REST 0x00 /* Second byte to send */
39#define IRIS_GIO_NODEV 0xff /* Likely not an Iris */
40
41MODULE_LICENSE("GPL");
42MODULE_AUTHOR("Sébastien Hinderer <Sebastien.Hinderer@ens-lyon.org>");
43MODULE_DESCRIPTION("A power_off handler for Iris devices from EuroBraille");
44MODULE_SUPPORTED_DEVICE("Eurobraille/Iris");
45
Rusty Russell476bc002012-01-13 09:32:18 +103046static bool force;
Shérab82148d12010-09-25 06:06:57 +020047
48module_param(force, bool, 0);
49MODULE_PARM_DESC(force, "Set to one to force poweroff handler installation.");
50
51static void (*old_pm_power_off)(void);
52
53static void iris_power_off(void)
54{
55 outb(IRIS_GIO_PULSE, IRIS_GIO_OUTPUT);
56 msleep(850);
57 outb(IRIS_GIO_REST, IRIS_GIO_OUTPUT);
58}
59
60/*
61 * Before installing the power_off handler, try to make sure the OS is
62 * running on an Iris. Since Iris does not support DMI, this is done
63 * by reading its input port and seeing whether the read value is
64 * meaningful.
65 */
Shérab88d67ee2012-12-18 14:21:21 -080066static int iris_probe(struct platform_device *pdev)
Shérab82148d12010-09-25 06:06:57 +020067{
Shérab88d67ee2012-12-18 14:21:21 -080068 unsigned char status = inb(IRIS_GIO_INPUT);
Shérab82148d12010-09-25 06:06:57 +020069 if (status == IRIS_GIO_NODEV) {
Shérab88d67ee2012-12-18 14:21:21 -080070 printk(KERN_ERR "This machine does not seem to be an Iris. "
71 "Power off handler not installed.\n");
Shérab82148d12010-09-25 06:06:57 +020072 return -ENODEV;
73 }
74 old_pm_power_off = pm_power_off;
75 pm_power_off = &iris_power_off;
76 printk(KERN_INFO "Iris power_off handler installed.\n");
Shérab88d67ee2012-12-18 14:21:21 -080077 return 0;
78}
Shérab82148d12010-09-25 06:06:57 +020079
Shérab88d67ee2012-12-18 14:21:21 -080080static int iris_remove(struct platform_device *pdev)
81{
82 pm_power_off = old_pm_power_off;
83 printk(KERN_INFO "Iris power_off handler uninstalled.\n");
84 return 0;
85}
86
87static struct platform_driver iris_driver = {
88 .driver = {
89 .name = "iris",
90 .owner = THIS_MODULE,
91 },
92 .probe = iris_probe,
93 .remove = iris_remove,
94};
95
96static struct resource iris_resources[] = {
97 {
98 .start = IRIS_GIO_BASE,
99 .end = IRIS_GIO_OUTPUT,
100 .flags = IORESOURCE_IO,
101 .name = "address"
102 }
103};
104
105static struct platform_device *iris_device;
106
107static int iris_init(void)
108{
109 int ret;
110 if (force != 1) {
111 printk(KERN_ERR "The force parameter has not been set to 1."
112 " The Iris poweroff handler will not be installed.\n");
113 return -ENODEV;
114 }
115 ret = platform_driver_register(&iris_driver);
116 if (ret < 0) {
117 printk(KERN_ERR "Failed to register iris platform driver: %d\n",
118 ret);
119 return ret;
120 }
121 iris_device = platform_device_register_simple("iris", (-1),
122 iris_resources, ARRAY_SIZE(iris_resources));
123 if (IS_ERR(iris_device)) {
124 printk(KERN_ERR "Failed to register iris platform device\n");
125 platform_driver_unregister(&iris_driver);
126 return PTR_ERR(iris_device);
127 }
Shérab82148d12010-09-25 06:06:57 +0200128 return 0;
129}
130
131static void iris_exit(void)
132{
Shérab88d67ee2012-12-18 14:21:21 -0800133 platform_device_unregister(iris_device);
134 platform_driver_unregister(&iris_driver);
Shérab82148d12010-09-25 06:06:57 +0200135}
136
137module_init(iris_init);
138module_exit(iris_exit);