lm.c 2.1 KB

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