lm.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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 <asm/arch/lm.h>
  14. #define to_lm_device(d) container_of(d, struct lm_device, dev)
  15. #define to_lm_driver(d) container_of(d, struct lm_driver, drv)
  16. static int lm_match(struct device *dev, struct device_driver *drv)
  17. {
  18. return 1;
  19. }
  20. static struct bus_type lm_bustype = {
  21. .name = "logicmodule",
  22. .match = lm_match,
  23. // .suspend = lm_suspend,
  24. // .resume = lm_resume,
  25. };
  26. static int __init lm_init(void)
  27. {
  28. return bus_register(&lm_bustype);
  29. }
  30. postcore_initcall(lm_init);
  31. static int lm_bus_probe(struct device *dev)
  32. {
  33. struct lm_device *lmdev = to_lm_device(dev);
  34. struct lm_driver *lmdrv = to_lm_driver(dev->driver);
  35. return lmdrv->probe(lmdev);
  36. }
  37. static int lm_bus_remove(struct device *dev)
  38. {
  39. struct lm_device *lmdev = to_lm_device(dev);
  40. struct lm_driver *lmdrv = to_lm_driver(dev->driver);
  41. lmdrv->remove(lmdev);
  42. return 0;
  43. }
  44. int lm_driver_register(struct lm_driver *drv)
  45. {
  46. drv->drv.bus = &lm_bustype;
  47. drv->drv.probe = lm_bus_probe;
  48. drv->drv.remove = lm_bus_remove;
  49. return driver_register(&drv->drv);
  50. }
  51. void lm_driver_unregister(struct lm_driver *drv)
  52. {
  53. driver_unregister(&drv->drv);
  54. }
  55. static void lm_device_release(struct device *dev)
  56. {
  57. struct lm_device *d = to_lm_device(dev);
  58. kfree(d);
  59. }
  60. int lm_device_register(struct lm_device *dev)
  61. {
  62. int ret;
  63. dev->dev.release = lm_device_release;
  64. dev->dev.bus = &lm_bustype;
  65. snprintf(dev->dev.bus_id, sizeof(dev->dev.bus_id), "lm%d", dev->id);
  66. dev->resource.name = dev->dev.bus_id;
  67. ret = request_resource(&iomem_resource, &dev->resource);
  68. if (ret == 0) {
  69. ret = device_register(&dev->dev);
  70. if (ret)
  71. release_resource(&dev->resource);
  72. }
  73. return ret;
  74. }
  75. EXPORT_SYMBOL(lm_driver_register);
  76. EXPORT_SYMBOL(lm_driver_unregister);