0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #include <linux/moduleparam.h>
0012 #include <linux/module.h>
0013 #include <linux/platform_device.h>
0014 #include <linux/kernel.h>
0015 #include <linux/errno.h>
0016 #include <linux/delay.h>
0017 #include <linux/pm.h>
0018 #include <asm/io.h>
0019
0020 #define IRIS_GIO_BASE 0x340
0021 #define IRIS_GIO_INPUT IRIS_GIO_BASE
0022 #define IRIS_GIO_OUTPUT (IRIS_GIO_BASE + 1)
0023 #define IRIS_GIO_PULSE 0x80
0024 #define IRIS_GIO_REST 0x00
0025 #define IRIS_GIO_NODEV 0xff
0026
0027 MODULE_LICENSE("GPL");
0028 MODULE_AUTHOR("Sébastien Hinderer <Sebastien.Hinderer@ens-lyon.org>");
0029 MODULE_DESCRIPTION("A power_off handler for Iris devices from EuroBraille");
0030
0031 static bool force;
0032
0033 module_param(force, bool, 0);
0034 MODULE_PARM_DESC(force, "Set to one to force poweroff handler installation.");
0035
0036 static void (*old_pm_power_off)(void);
0037
0038 static void iris_power_off(void)
0039 {
0040 outb(IRIS_GIO_PULSE, IRIS_GIO_OUTPUT);
0041 msleep(850);
0042 outb(IRIS_GIO_REST, IRIS_GIO_OUTPUT);
0043 }
0044
0045
0046
0047
0048
0049
0050
0051 static int iris_probe(struct platform_device *pdev)
0052 {
0053 unsigned char status = inb(IRIS_GIO_INPUT);
0054 if (status == IRIS_GIO_NODEV) {
0055 printk(KERN_ERR "This machine does not seem to be an Iris. "
0056 "Power off handler not installed.\n");
0057 return -ENODEV;
0058 }
0059 old_pm_power_off = pm_power_off;
0060 pm_power_off = &iris_power_off;
0061 printk(KERN_INFO "Iris power_off handler installed.\n");
0062 return 0;
0063 }
0064
0065 static int iris_remove(struct platform_device *pdev)
0066 {
0067 pm_power_off = old_pm_power_off;
0068 printk(KERN_INFO "Iris power_off handler uninstalled.\n");
0069 return 0;
0070 }
0071
0072 static struct platform_driver iris_driver = {
0073 .driver = {
0074 .name = "iris",
0075 },
0076 .probe = iris_probe,
0077 .remove = iris_remove,
0078 };
0079
0080 static struct resource iris_resources[] = {
0081 {
0082 .start = IRIS_GIO_BASE,
0083 .end = IRIS_GIO_OUTPUT,
0084 .flags = IORESOURCE_IO,
0085 .name = "address"
0086 }
0087 };
0088
0089 static struct platform_device *iris_device;
0090
0091 static int iris_init(void)
0092 {
0093 int ret;
0094 if (force != 1) {
0095 printk(KERN_ERR "The force parameter has not been set to 1."
0096 " The Iris poweroff handler will not be installed.\n");
0097 return -ENODEV;
0098 }
0099 ret = platform_driver_register(&iris_driver);
0100 if (ret < 0) {
0101 printk(KERN_ERR "Failed to register iris platform driver: %d\n",
0102 ret);
0103 return ret;
0104 }
0105 iris_device = platform_device_register_simple("iris", (-1),
0106 iris_resources, ARRAY_SIZE(iris_resources));
0107 if (IS_ERR(iris_device)) {
0108 printk(KERN_ERR "Failed to register iris platform device\n");
0109 platform_driver_unregister(&iris_driver);
0110 return PTR_ERR(iris_device);
0111 }
0112 return 0;
0113 }
0114
0115 static void iris_exit(void)
0116 {
0117 platform_device_unregister(iris_device);
0118 platform_driver_unregister(&iris_driver);
0119 }
0120
0121 module_init(iris_init);
0122 module_exit(iris_exit);