sysfs.c 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /*
  2. * linux/drivers/mmc/core/sysfs.c
  3. *
  4. * Copyright (C) 2003 Russell King, All Rights Reserved.
  5. * Copyright 2007 Pierre Ossman
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * MMC sysfs/driver model support.
  12. */
  13. #include <linux/module.h>
  14. #include <linux/init.h>
  15. #include <linux/device.h>
  16. #include <linux/idr.h>
  17. #include <linux/workqueue.h>
  18. #include <linux/mmc/card.h>
  19. #include <linux/mmc/host.h>
  20. #include "bus.h"
  21. #include "host.h"
  22. #include "sysfs.h"
  23. int mmc_add_attrs(struct mmc_card *card, struct device_attribute *attrs)
  24. {
  25. int error = 0;
  26. int i;
  27. for (i = 0; attr_name(attrs[i]); i++) {
  28. error = device_create_file(&card->dev, &attrs[i]);
  29. if (error) {
  30. while (--i >= 0)
  31. device_remove_file(&card->dev, &attrs[i]);
  32. break;
  33. }
  34. }
  35. return error;
  36. }
  37. void mmc_remove_attrs(struct mmc_card *card, struct device_attribute *attrs)
  38. {
  39. int i;
  40. for (i = 0; attr_name(attrs[i]); i++)
  41. device_remove_file(&card->dev, &attrs[i]);
  42. }
  43. static struct workqueue_struct *workqueue;
  44. /*
  45. * Internal function. Schedule delayed work in the MMC work queue.
  46. */
  47. int mmc_schedule_delayed_work(struct delayed_work *work, unsigned long delay)
  48. {
  49. return queue_delayed_work(workqueue, work, delay);
  50. }
  51. /*
  52. * Internal function. Flush all scheduled work from the MMC work queue.
  53. */
  54. void mmc_flush_scheduled_work(void)
  55. {
  56. flush_workqueue(workqueue);
  57. }
  58. static int __init mmc_init(void)
  59. {
  60. int ret;
  61. workqueue = create_singlethread_workqueue("kmmcd");
  62. if (!workqueue)
  63. return -ENOMEM;
  64. ret = mmc_register_bus();
  65. if (ret == 0) {
  66. ret = mmc_register_host_class();
  67. if (ret)
  68. mmc_unregister_bus();
  69. }
  70. return ret;
  71. }
  72. static void __exit mmc_exit(void)
  73. {
  74. mmc_unregister_host_class();
  75. mmc_unregister_bus();
  76. destroy_workqueue(workqueue);
  77. }
  78. module_init(mmc_init);
  79. module_exit(mmc_exit);