devices.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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/slab.h>
  20. #include <linux/init.h>
  21. #include <linux/err.h>
  22. #include <linux/platform_device.h>
  23. #include <mach/common.h>
  24. struct platform_device *__init mxs_add_platform_device_dmamask(
  25. const char *name, int id,
  26. const struct resource *res, unsigned int num_resources,
  27. const void *data, size_t size_data, u64 dmamask)
  28. {
  29. int ret = -ENOMEM;
  30. struct platform_device *pdev;
  31. pdev = platform_device_alloc(name, id);
  32. if (!pdev)
  33. goto err;
  34. if (dmamask) {
  35. /*
  36. * This memory isn't freed when the device is put,
  37. * I don't have a nice idea for that though. Conceptually
  38. * dma_mask in struct device should not be a pointer.
  39. * See http://thread.gmane.org/gmane.linux.kernel.pci/9081
  40. */
  41. pdev->dev.dma_mask =
  42. kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
  43. if (!pdev->dev.dma_mask)
  44. /* ret is still -ENOMEM; */
  45. goto err;
  46. *pdev->dev.dma_mask = dmamask;
  47. pdev->dev.coherent_dma_mask = dmamask;
  48. }
  49. if (res) {
  50. ret = platform_device_add_resources(pdev, res, num_resources);
  51. if (ret)
  52. goto err;
  53. }
  54. if (data) {
  55. ret = platform_device_add_data(pdev, data, size_data);
  56. if (ret)
  57. goto err;
  58. }
  59. ret = platform_device_add(pdev);
  60. if (ret) {
  61. err:
  62. platform_device_put(pdev);
  63. return ERR_PTR(ret);
  64. }
  65. return pdev;
  66. }