iris.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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 <Sebastien.Hinderer@ens-lyon.org>
  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 <Sebastien.Hinderer@ens-lyon.org>");
  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 void 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. }
  61. static struct platform_driver iris_driver = {
  62. .driver = {
  63. .name = "iris",
  64. },
  65. .probe = iris_probe,
  66. .remove_new = iris_remove,
  67. };
  68. static struct resource iris_resources[] = {
  69. {
  70. .start = IRIS_GIO_BASE,
  71. .end = IRIS_GIO_OUTPUT,
  72. .flags = IORESOURCE_IO,
  73. .name = "address"
  74. }
  75. };
  76. static struct platform_device *iris_device;
  77. static int iris_init(void)
  78. {
  79. int ret;
  80. if (force != 1) {
  81. printk(KERN_ERR "The force parameter has not been set to 1."
  82. " The Iris poweroff handler will not be installed.\n");
  83. return -ENODEV;
  84. }
  85. ret = platform_driver_register(&iris_driver);
  86. if (ret < 0) {
  87. printk(KERN_ERR "Failed to register iris platform driver: %d\n",
  88. ret);
  89. return ret;
  90. }
  91. iris_device = platform_device_register_simple("iris", (-1),
  92. iris_resources, ARRAY_SIZE(iris_resources));
  93. if (IS_ERR(iris_device)) {
  94. printk(KERN_ERR "Failed to register iris platform device\n");
  95. platform_driver_unregister(&iris_driver);
  96. return PTR_ERR(iris_device);
  97. }
  98. return 0;
  99. }
  100. static void iris_exit(void)
  101. {
  102. platform_device_unregister(iris_device);
  103. platform_driver_unregister(&iris_driver);
  104. }
  105. module_init(iris_init);
  106. module_exit(iris_exit);