amilo-rfkill.c 4.3 KB

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