amilo-rfkill.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  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 __devinitdata 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 M7440"),
  77. },
  78. .driver_data = (void *)&amilo_m7440_rfkill_ops
  79. },
  80. {}
  81. };
  82. static struct platform_device *amilo_rfkill_pdev;
  83. static struct rfkill *amilo_rfkill_dev;
  84. static int __devinit amilo_rfkill_probe(struct platform_device *device)
  85. {
  86. int rc;
  87. const struct dmi_system_id *system_id =
  88. dmi_first_match(amilo_rfkill_id_table);
  89. if (!system_id)
  90. return -ENXIO;
  91. amilo_rfkill_dev = rfkill_alloc(KBUILD_MODNAME, &device->dev,
  92. RFKILL_TYPE_WLAN,
  93. system_id->driver_data, NULL);
  94. if (!amilo_rfkill_dev)
  95. return -ENOMEM;
  96. rc = rfkill_register(amilo_rfkill_dev);
  97. if (rc)
  98. goto fail;
  99. return 0;
  100. fail:
  101. rfkill_destroy(amilo_rfkill_dev);
  102. return rc;
  103. }
  104. static int amilo_rfkill_remove(struct platform_device *device)
  105. {
  106. rfkill_unregister(amilo_rfkill_dev);
  107. rfkill_destroy(amilo_rfkill_dev);
  108. return 0;
  109. }
  110. static struct platform_driver amilo_rfkill_driver = {
  111. .driver = {
  112. .name = KBUILD_MODNAME,
  113. .owner = THIS_MODULE,
  114. },
  115. .probe = amilo_rfkill_probe,
  116. .remove = amilo_rfkill_remove,
  117. };
  118. static int __init amilo_rfkill_init(void)
  119. {
  120. int rc;
  121. if (dmi_first_match(amilo_rfkill_id_table) == NULL)
  122. return -ENODEV;
  123. rc = platform_driver_register(&amilo_rfkill_driver);
  124. if (rc)
  125. return rc;
  126. amilo_rfkill_pdev = platform_device_register_simple(KBUILD_MODNAME, -1,
  127. NULL, 0);
  128. if (IS_ERR(amilo_rfkill_pdev)) {
  129. rc = PTR_ERR(amilo_rfkill_pdev);
  130. goto fail;
  131. }
  132. return 0;
  133. fail:
  134. platform_driver_unregister(&amilo_rfkill_driver);
  135. return rc;
  136. }
  137. static void __exit amilo_rfkill_exit(void)
  138. {
  139. platform_device_unregister(amilo_rfkill_pdev);
  140. platform_driver_unregister(&amilo_rfkill_driver);
  141. }
  142. MODULE_AUTHOR("Ben Hutchings <ben@decadent.org.uk>");
  143. MODULE_LICENSE("GPL");
  144. MODULE_DEVICE_TABLE(dmi, amilo_rfkill_id_table);
  145. module_init(amilo_rfkill_init);
  146. module_exit(amilo_rfkill_exit);