amilo-rfkill.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Support for rfkill on some Fujitsu-Siemens Amilo laptops.
  4. * Copyright 2011 Ben Hutchings.
  5. *
  6. * Based in part on the fsam7440 driver, which is:
  7. * Copyright 2005 Alejandro Vidal Mata & Javier Vidal Mata.
  8. * and on the fsaa1655g driver, which is:
  9. * Copyright 2006 Martin Večeřa.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/dmi.h>
  13. #include <linux/i8042.h>
  14. #include <linux/io.h>
  15. #include <linux/moduleparam.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/rfkill.h>
  18. /*
  19. * These values were obtained from disassembling and debugging the
  20. * PM.exe program installed in the Fujitsu-Siemens AMILO A1655G
  21. */
  22. #define A1655_WIFI_COMMAND 0x10C5
  23. #define A1655_WIFI_ON 0x25
  24. #define A1655_WIFI_OFF 0x45
  25. static int amilo_a1655_rfkill_set_block(void *data, bool blocked)
  26. {
  27. u8 param = blocked ? A1655_WIFI_OFF : A1655_WIFI_ON;
  28. int rc;
  29. i8042_lock_chip();
  30. rc = i8042_command(&param, A1655_WIFI_COMMAND);
  31. i8042_unlock_chip();
  32. return rc;
  33. }
  34. static const struct rfkill_ops amilo_a1655_rfkill_ops = {
  35. .set_block = amilo_a1655_rfkill_set_block
  36. };
  37. /*
  38. * These values were obtained from disassembling the PM.exe program
  39. * installed in the Fujitsu-Siemens AMILO M 7440
  40. */
  41. #define M7440_PORT1 0x118f
  42. #define M7440_PORT2 0x118e
  43. #define M7440_RADIO_ON1 0x12
  44. #define M7440_RADIO_ON2 0x80
  45. #define M7440_RADIO_OFF1 0x10
  46. #define M7440_RADIO_OFF2 0x00
  47. static int amilo_m7440_rfkill_set_block(void *data, bool blocked)
  48. {
  49. u8 val1 = blocked ? M7440_RADIO_OFF1 : M7440_RADIO_ON1;
  50. u8 val2 = blocked ? M7440_RADIO_OFF2 : M7440_RADIO_ON2;
  51. outb(val1, M7440_PORT1);
  52. outb(val2, M7440_PORT2);
  53. /* Check whether the state has changed correctly */
  54. if (inb(M7440_PORT1) != val1 || inb(M7440_PORT2) != val2)
  55. return -EIO;
  56. return 0;
  57. }
  58. static const struct rfkill_ops amilo_m7440_rfkill_ops = {
  59. .set_block = amilo_m7440_rfkill_set_block
  60. };
  61. static const struct dmi_system_id amilo_rfkill_id_table[] = {
  62. {
  63. .matches = {
  64. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  65. DMI_MATCH(DMI_BOARD_NAME, "AMILO A1655"),
  66. },
  67. .driver_data = (void *)&amilo_a1655_rfkill_ops
  68. },
  69. {
  70. .matches = {
  71. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  72. DMI_MATCH(DMI_BOARD_NAME, "AMILO L1310"),
  73. },
  74. .driver_data = (void *)&amilo_a1655_rfkill_ops
  75. },
  76. {
  77. .matches = {
  78. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  79. DMI_MATCH(DMI_BOARD_NAME, "AMILO M7440"),
  80. },
  81. .driver_data = (void *)&amilo_m7440_rfkill_ops
  82. },
  83. {}
  84. };
  85. static struct platform_device *amilo_rfkill_pdev;
  86. static struct rfkill *amilo_rfkill_dev;
  87. static int amilo_rfkill_probe(struct platform_device *device)
  88. {
  89. int rc;
  90. const struct dmi_system_id *system_id =
  91. dmi_first_match(amilo_rfkill_id_table);
  92. if (!system_id)
  93. return -ENXIO;
  94. amilo_rfkill_dev = rfkill_alloc(KBUILD_MODNAME, &device->dev,
  95. RFKILL_TYPE_WLAN,
  96. system_id->driver_data, NULL);
  97. if (!amilo_rfkill_dev)
  98. return -ENOMEM;
  99. rc = rfkill_register(amilo_rfkill_dev);
  100. if (rc)
  101. goto fail;
  102. return 0;
  103. fail:
  104. rfkill_destroy(amilo_rfkill_dev);
  105. return rc;
  106. }
  107. static int amilo_rfkill_remove(struct platform_device *device)
  108. {
  109. rfkill_unregister(amilo_rfkill_dev);
  110. rfkill_destroy(amilo_rfkill_dev);
  111. return 0;
  112. }
  113. static struct platform_driver amilo_rfkill_driver = {
  114. .driver = {
  115. .name = KBUILD_MODNAME,
  116. },
  117. .probe = amilo_rfkill_probe,
  118. .remove = amilo_rfkill_remove,
  119. };
  120. static int __init amilo_rfkill_init(void)
  121. {
  122. int rc;
  123. if (dmi_first_match(amilo_rfkill_id_table) == NULL)
  124. return -ENODEV;
  125. rc = platform_driver_register(&amilo_rfkill_driver);
  126. if (rc)
  127. return rc;
  128. amilo_rfkill_pdev = platform_device_register_simple(KBUILD_MODNAME,
  129. PLATFORM_DEVID_NONE,
  130. NULL, 0);
  131. if (IS_ERR(amilo_rfkill_pdev)) {
  132. rc = PTR_ERR(amilo_rfkill_pdev);
  133. goto fail;
  134. }
  135. return 0;
  136. fail:
  137. platform_driver_unregister(&amilo_rfkill_driver);
  138. return rc;
  139. }
  140. static void __exit amilo_rfkill_exit(void)
  141. {
  142. platform_device_unregister(amilo_rfkill_pdev);
  143. platform_driver_unregister(&amilo_rfkill_driver);
  144. }
  145. MODULE_AUTHOR("Ben Hutchings <[email protected]>");
  146. MODULE_LICENSE("GPL");
  147. MODULE_DEVICE_TABLE(dmi, amilo_rfkill_id_table);
  148. module_init(amilo_rfkill_init);
  149. module_exit(amilo_rfkill_exit);