xo1-rfkill.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /*
  2. * Support for rfkill through the OLPC XO-1 laptop embedded controller
  3. *
  4. * Copyright (C) 2010 One Laptop per Child
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/rfkill.h>
  14. #include <linux/olpc-ec.h>
  15. static bool card_blocked;
  16. static int rfkill_set_block(void *data, bool blocked)
  17. {
  18. unsigned char cmd;
  19. int r;
  20. if (blocked == card_blocked)
  21. return 0;
  22. if (blocked)
  23. cmd = EC_WLAN_ENTER_RESET;
  24. else
  25. cmd = EC_WLAN_LEAVE_RESET;
  26. r = olpc_ec_cmd(cmd, NULL, 0, NULL, 0);
  27. if (r == 0)
  28. card_blocked = blocked;
  29. return r;
  30. }
  31. static const struct rfkill_ops rfkill_ops = {
  32. .set_block = rfkill_set_block,
  33. };
  34. static int xo1_rfkill_probe(struct platform_device *pdev)
  35. {
  36. struct rfkill *rfk;
  37. int r;
  38. rfk = rfkill_alloc(pdev->name, &pdev->dev, RFKILL_TYPE_WLAN,
  39. &rfkill_ops, NULL);
  40. if (!rfk)
  41. return -ENOMEM;
  42. r = rfkill_register(rfk);
  43. if (r) {
  44. rfkill_destroy(rfk);
  45. return r;
  46. }
  47. platform_set_drvdata(pdev, rfk);
  48. return 0;
  49. }
  50. static int xo1_rfkill_remove(struct platform_device *pdev)
  51. {
  52. struct rfkill *rfk = platform_get_drvdata(pdev);
  53. rfkill_unregister(rfk);
  54. rfkill_destroy(rfk);
  55. return 0;
  56. }
  57. static struct platform_driver xo1_rfkill_driver = {
  58. .driver = {
  59. .name = "xo1-rfkill",
  60. },
  61. .probe = xo1_rfkill_probe,
  62. .remove = xo1_rfkill_remove,
  63. };
  64. module_platform_driver(xo1_rfkill_driver);
  65. MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>");
  66. MODULE_LICENSE("GPL");
  67. MODULE_ALIAS("platform:xo1-rfkill");