iris.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  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. #include <linux/moduleparam.h>
  24. #include <linux/module.h>
  25. #include <linux/platform_device.h>
  26. #include <linux/kernel.h>
  27. #include <linux/errno.h>
  28. #include <linux/delay.h>
  29. #include <linux/init.h>
  30. #include <linux/pm.h>
  31. #include <asm/io.h>
  32. #define IRIS_GIO_BASE 0x340
  33. #define IRIS_GIO_INPUT IRIS_GIO_BASE
  34. #define IRIS_GIO_OUTPUT (IRIS_GIO_BASE + 1)
  35. #define IRIS_GIO_PULSE 0x80 /* First byte to send */
  36. #define IRIS_GIO_REST 0x00 /* Second byte to send */
  37. #define IRIS_GIO_NODEV 0xff /* Likely not an Iris */
  38. MODULE_LICENSE("GPL");
  39. MODULE_AUTHOR("Sébastien Hinderer <Sebastien.Hinderer@ens-lyon.org>");
  40. MODULE_DESCRIPTION("A power_off handler for Iris devices from EuroBraille");
  41. MODULE_SUPPORTED_DEVICE("Eurobraille/Iris");
  42. static bool force;
  43. module_param(force, bool, 0);
  44. MODULE_PARM_DESC(force, "Set to one to force poweroff handler installation.");
  45. static void (*old_pm_power_off)(void);
  46. static void iris_power_off(void)
  47. {
  48. outb(IRIS_GIO_PULSE, IRIS_GIO_OUTPUT);
  49. msleep(850);
  50. outb(IRIS_GIO_REST, IRIS_GIO_OUTPUT);
  51. }
  52. /*
  53. * Before installing the power_off handler, try to make sure the OS is
  54. * running on an Iris. Since Iris does not support DMI, this is done
  55. * by reading its input port and seeing whether the read value is
  56. * meaningful.
  57. */
  58. static int iris_probe(struct platform_device *pdev)
  59. {
  60. unsigned char status = inb(IRIS_GIO_INPUT);
  61. if (status == IRIS_GIO_NODEV) {
  62. printk(KERN_ERR "This machine does not seem to be an Iris. "
  63. "Power off handler not installed.\n");
  64. return -ENODEV;
  65. }
  66. old_pm_power_off = pm_power_off;
  67. pm_power_off = &iris_power_off;
  68. printk(KERN_INFO "Iris power_off handler installed.\n");
  69. return 0;
  70. }
  71. static int iris_remove(struct platform_device *pdev)
  72. {
  73. pm_power_off = old_pm_power_off;
  74. printk(KERN_INFO "Iris power_off handler uninstalled.\n");
  75. return 0;
  76. }
  77. static struct platform_driver iris_driver = {
  78. .driver = {
  79. .name = "iris",
  80. .owner = THIS_MODULE,
  81. },
  82. .probe = iris_probe,
  83. .remove = iris_remove,
  84. };
  85. static struct resource iris_resources[] = {
  86. {
  87. .start = IRIS_GIO_BASE,
  88. .end = IRIS_GIO_OUTPUT,
  89. .flags = IORESOURCE_IO,
  90. .name = "address"
  91. }
  92. };
  93. static struct platform_device *iris_device;
  94. static int iris_init(void)
  95. {
  96. int ret;
  97. if (force != 1) {
  98. printk(KERN_ERR "The force parameter has not been set to 1."
  99. " The Iris poweroff handler will not be installed.\n");
  100. return -ENODEV;
  101. }
  102. ret = platform_driver_register(&iris_driver);
  103. if (ret < 0) {
  104. printk(KERN_ERR "Failed to register iris platform driver: %d\n",
  105. ret);
  106. return ret;
  107. }
  108. iris_device = platform_device_register_simple("iris", (-1),
  109. iris_resources, ARRAY_SIZE(iris_resources));
  110. if (IS_ERR(iris_device)) {
  111. printk(KERN_ERR "Failed to register iris platform device\n");
  112. platform_driver_unregister(&iris_driver);
  113. return PTR_ERR(iris_device);
  114. }
  115. return 0;
  116. }
  117. static void iris_exit(void)
  118. {
  119. platform_device_unregister(iris_device);
  120. platform_driver_unregister(&iris_driver);
  121. }
  122. module_init(iris_init);
  123. module_exit(iris_exit);