xo1-rfkill.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 <asm/olpc.h>
  15. static int rfkill_set_block(void *data, bool blocked)
  16. {
  17. unsigned char cmd;
  18. if (blocked)
  19. cmd = EC_WLAN_ENTER_RESET;
  20. else
  21. cmd = EC_WLAN_LEAVE_RESET;
  22. return olpc_ec_cmd(cmd, NULL, 0, NULL, 0);
  23. }
  24. static const struct rfkill_ops rfkill_ops = {
  25. .set_block = rfkill_set_block,
  26. };
  27. static int __devinit xo1_rfkill_probe(struct platform_device *pdev)
  28. {
  29. struct rfkill *rfk;
  30. int r;
  31. rfk = rfkill_alloc(pdev->name, &pdev->dev, RFKILL_TYPE_WLAN,
  32. &rfkill_ops, NULL);
  33. if (!rfk)
  34. return -ENOMEM;
  35. r = rfkill_register(rfk);
  36. if (r) {
  37. rfkill_destroy(rfk);
  38. return r;
  39. }
  40. platform_set_drvdata(pdev, rfk);
  41. return 0;
  42. }
  43. static int __devexit xo1_rfkill_remove(struct platform_device *pdev)
  44. {
  45. struct rfkill *rfk = platform_get_drvdata(pdev);
  46. rfkill_unregister(rfk);
  47. rfkill_destroy(rfk);
  48. return 0;
  49. }
  50. static struct platform_driver xo1_rfkill_driver = {
  51. .driver = {
  52. .name = "xo1-rfkill",
  53. .owner = THIS_MODULE,
  54. },
  55. .probe = xo1_rfkill_probe,
  56. .remove = __devexit_p(xo1_rfkill_remove),
  57. };
  58. static int __init xo1_rfkill_init(void)
  59. {
  60. return platform_driver_register(&xo1_rfkill_driver);
  61. }
  62. static void __exit xo1_rfkill_exit(void)
  63. {
  64. platform_driver_unregister(&xo1_rfkill_driver);
  65. }
  66. MODULE_AUTHOR("Daniel Drake <dsd@laptop.org>");
  67. MODULE_LICENSE("GPL");
  68. MODULE_ALIAS("platform:xo1-rfkill");
  69. module_init(xo1_rfkill_init);
  70. module_exit(xo1_rfkill_exit);