iris.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Eurobraille/Iris power off support.
  4. *
  5. * Eurobraille's Iris machine is a PC with no APM or ACPI support.
  6. * It is shutdown by a special I/O sequence which this module provides.
  7. *
  8. * Copyright (C) Shérab <[email protected]>
  9. */
  10. #include <linux/moduleparam.h>
  11. #include <linux/module.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/kernel.h>
  14. #include <linux/errno.h>
  15. #include <linux/delay.h>
  16. #include <linux/pm.h>
  17. #include <asm/io.h>
  18. #define IRIS_GIO_BASE 0x340
  19. #define IRIS_GIO_INPUT IRIS_GIO_BASE
  20. #define IRIS_GIO_OUTPUT (IRIS_GIO_BASE + 1)
  21. #define IRIS_GIO_PULSE 0x80 /* First byte to send */
  22. #define IRIS_GIO_REST 0x00 /* Second byte to send */
  23. #define IRIS_GIO_NODEV 0xff /* Likely not an Iris */
  24. MODULE_LICENSE("GPL");
  25. MODULE_AUTHOR("Sébastien Hinderer <[email protected]>");
  26. MODULE_DESCRIPTION("A power_off handler for Iris devices from EuroBraille");
  27. static bool force;
  28. module_param(force, bool, 0);
  29. MODULE_PARM_DESC(force, "Set to one to force poweroff handler installation.");
  30. static void (*old_pm_power_off)(void);
  31. static void iris_power_off(void)
  32. {
  33. outb(IRIS_GIO_PULSE, IRIS_GIO_OUTPUT);
  34. msleep(850);
  35. outb(IRIS_GIO_REST, IRIS_GIO_OUTPUT);
  36. }
  37. /*
  38. * Before installing the power_off handler, try to make sure the OS is
  39. * running on an Iris. Since Iris does not support DMI, this is done
  40. * by reading its input port and seeing whether the read value is
  41. * meaningful.
  42. */
  43. static int iris_probe(struct platform_device *pdev)
  44. {
  45. unsigned char status = inb(IRIS_GIO_INPUT);
  46. if (status == IRIS_GIO_NODEV) {
  47. printk(KERN_ERR "This machine does not seem to be an Iris. "
  48. "Power off handler not installed.\n");
  49. return -ENODEV;
  50. }
  51. old_pm_power_off = pm_power_off;
  52. pm_power_off = &iris_power_off;
  53. printk(KERN_INFO "Iris power_off handler installed.\n");
  54. return 0;
  55. }
  56. static int iris_remove(struct platform_device *pdev)
  57. {
  58. pm_power_off = old_pm_power_off;
  59. printk(KERN_INFO "Iris power_off handler uninstalled.\n");
  60. return 0;
  61. }
  62. static struct platform_driver iris_driver = {
  63. .driver = {
  64. .name = "iris",
  65. },
  66. .probe = iris_probe,
  67. .remove = iris_remove,
  68. };
  69. static struct resource iris_resources[] = {
  70. {
  71. .start = IRIS_GIO_BASE,
  72. .end = IRIS_GIO_OUTPUT,
  73. .flags = IORESOURCE_IO,
  74. .name = "address"
  75. }
  76. };
  77. static struct platform_device *iris_device;
  78. static int iris_init(void)
  79. {
  80. int ret;
  81. if (force != 1) {
  82. printk(KERN_ERR "The force parameter has not been set to 1."
  83. " The Iris poweroff handler will not be installed.\n");
  84. return -ENODEV;
  85. }
  86. ret = platform_driver_register(&iris_driver);
  87. if (ret < 0) {
  88. printk(KERN_ERR "Failed to register iris platform driver: %d\n",
  89. ret);
  90. return ret;
  91. }
  92. iris_device = platform_device_register_simple("iris", (-1),
  93. iris_resources, ARRAY_SIZE(iris_resources));
  94. if (IS_ERR(iris_device)) {
  95. printk(KERN_ERR "Failed to register iris platform device\n");
  96. platform_driver_unregister(&iris_driver);
  97. return PTR_ERR(iris_device);
  98. }
  99. return 0;
  100. }
  101. static void iris_exit(void)
  102. {
  103. platform_device_unregister(iris_device);
  104. platform_driver_unregister(&iris_driver);
  105. }
  106. module_init(iris_init);
  107. module_exit(iris_exit);