devices.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. /*
  2. * linux/arch/arm/mach-mmp/devices.c
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. */
  8. #include <linux/init.h>
  9. #include <linux/platform_device.h>
  10. #include <linux/dma-mapping.h>
  11. #include <asm/irq.h>
  12. #include <mach/devices.h>
  13. int __init pxa_register_device(struct pxa_device_desc *desc,
  14. void *data, size_t size)
  15. {
  16. struct platform_device *pdev;
  17. struct resource res[2 + MAX_RESOURCE_DMA];
  18. int i, ret = 0, nres = 0;
  19. pdev = platform_device_alloc(desc->drv_name, desc->id);
  20. if (pdev == NULL)
  21. return -ENOMEM;
  22. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  23. memset(res, 0, sizeof(res));
  24. if (desc->start != -1ul && desc->size > 0) {
  25. res[nres].start = desc->start;
  26. res[nres].end = desc->start + desc->size - 1;
  27. res[nres].flags = IORESOURCE_MEM;
  28. nres++;
  29. }
  30. if (desc->irq != NO_IRQ) {
  31. res[nres].start = desc->irq;
  32. res[nres].end = desc->irq;
  33. res[nres].flags = IORESOURCE_IRQ;
  34. nres++;
  35. }
  36. for (i = 0; i < MAX_RESOURCE_DMA; i++, nres++) {
  37. if (desc->dma[i] == 0)
  38. break;
  39. res[nres].start = desc->dma[i];
  40. res[nres].end = desc->dma[i];
  41. res[nres].flags = IORESOURCE_DMA;
  42. }
  43. ret = platform_device_add_resources(pdev, res, nres);
  44. if (ret) {
  45. platform_device_put(pdev);
  46. return ret;
  47. }
  48. if (data && size) {
  49. ret = platform_device_add_data(pdev, data, size);
  50. if (ret) {
  51. platform_device_put(pdev);
  52. return ret;
  53. }
  54. }
  55. return platform_device_add(pdev);
  56. }