devices.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * Copyright 2008 Sascha Hauer, kernel@pengutronix.de
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software
  15. * Foundation, Inc., 51 Franklin Street, Fifth Floor,
  16. * Boston, MA 02110-1301, USA.
  17. */
  18. #include <linux/kernel.h>
  19. #include <linux/init.h>
  20. #include <linux/err.h>
  21. #include <linux/platform_device.h>
  22. #include <mach/common.h>
  23. int __init mxc_register_device(struct platform_device *pdev, void *data)
  24. {
  25. int ret;
  26. pdev->dev.platform_data = data;
  27. ret = platform_device_register(pdev);
  28. if (ret)
  29. pr_debug("Unable to register platform device '%s': %d\n",
  30. pdev->name, ret);
  31. return ret;
  32. }
  33. struct platform_device *__init imx_add_platform_device(const char *name, int id,
  34. const struct resource *res, unsigned int num_resources,
  35. const void *data, size_t size_data)
  36. {
  37. int ret = -ENOMEM;
  38. struct platform_device *pdev;
  39. pdev = platform_device_alloc(name, id);
  40. if (!pdev)
  41. goto err;
  42. if (res) {
  43. ret = platform_device_add_resources(pdev, res, num_resources);
  44. if (ret)
  45. goto err;
  46. }
  47. if (data) {
  48. ret = platform_device_add_data(pdev, data, size_data);
  49. if (ret)
  50. goto err;
  51. }
  52. ret = platform_device_add(pdev);
  53. if (ret) {
  54. err:
  55. platform_device_put(pdev);
  56. return ERR_PTR(ret);
  57. }
  58. return pdev;
  59. }