lm.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * linux/arch/arm/mach-integrator/lm.c
  3. *
  4. * Copyright (C) 2003 Deep Blue Solutions Ltd, All Rights Reserved.
  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 version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <linux/module.h>
  11. #include <linux/init.h>
  12. #include <linux/device.h>
  13. #include <linux/slab.h>
  14. #include "lm.h"
  15. #define to_lm_device(d) container_of(d, struct lm_device, dev)
  16. #define to_lm_driver(d) container_of(d, struct lm_driver, drv)
  17. static int lm_match(struct device *dev, struct device_driver *drv)
  18. {
  19. return 1;
  20. }
  21. static int lm_bus_probe(struct device *dev)
  22. {
  23. struct lm_device *lmdev = to_lm_device(dev);
  24. struct lm_driver *lmdrv = to_lm_driver(dev->driver);
  25. return lmdrv->probe(lmdev);
  26. }
  27. static int lm_bus_remove(struct device *dev)
  28. {
  29. struct lm_device *lmdev = to_lm_device(dev);
  30. struct lm_driver *lmdrv = to_lm_driver(dev->driver);
  31. if (lmdrv->remove)
  32. lmdrv->remove(lmdev);
  33. return 0;
  34. }
  35. static struct bus_type lm_bustype = {
  36. .name = "logicmodule",
  37. .match = lm_match,
  38. .probe = lm_bus_probe,
  39. .remove = lm_bus_remove,
  40. // .suspend = lm_bus_suspend,
  41. // .resume = lm_bus_resume,
  42. };
  43. static int __init lm_init(void)
  44. {
  45. return bus_register(&lm_bustype);
  46. }
  47. postcore_initcall(lm_init);
  48. int lm_driver_register(struct lm_driver *drv)
  49. {
  50. drv->drv.bus = &lm_bustype;
  51. return driver_register(&drv->drv);
  52. }
  53. void lm_driver_unregister(struct lm_driver *drv)
  54. {
  55. driver_unregister(&drv->drv);
  56. }
  57. static void lm_device_release(struct device *dev)
  58. {
  59. struct lm_device *d = to_lm_device(dev);
  60. kfree(d);
  61. }
  62. int lm_device_register(struct lm_device *dev)
  63. {
  64. int ret;
  65. dev->dev.release = lm_device_release;
  66. dev->dev.bus = &lm_bustype;
  67. ret = dev_set_name(&dev->dev, "lm%d", dev->id);
  68. if (ret)
  69. return ret;
  70. dev->resource.name = dev_name(&dev->dev);
  71. ret = request_resource(&iomem_resource, &dev->resource);
  72. if (ret == 0) {
  73. ret = device_register(&dev->dev);
  74. if (ret)
  75. release_resource(&dev->resource);
  76. }
  77. return ret;
  78. }
  79. EXPORT_SYMBOL(lm_driver_register);
  80. EXPORT_SYMBOL(lm_driver_unregister);