platform-ipu-core.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /*
  2. * Copyright (C) 2011 Pengutronix
  3. * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it under
  6. * the terms of the GNU General Public License version 2 as published by the
  7. * Free Software Foundation.
  8. */
  9. #include <linux/dma-mapping.h>
  10. #include "../hardware.h"
  11. #include "devices-common.h"
  12. #define imx_ipu_core_entry_single(soc) \
  13. { \
  14. .iobase = soc ## _IPU_CTRL_BASE_ADDR, \
  15. .synirq = soc ## _INT_IPU_SYN, \
  16. .errirq = soc ## _INT_IPU_ERR, \
  17. }
  18. #ifdef CONFIG_SOC_IMX31
  19. const struct imx_ipu_core_data imx31_ipu_core_data __initconst =
  20. imx_ipu_core_entry_single(MX31);
  21. #endif
  22. #ifdef CONFIG_SOC_IMX35
  23. const struct imx_ipu_core_data imx35_ipu_core_data __initconst =
  24. imx_ipu_core_entry_single(MX35);
  25. #endif
  26. static struct platform_device *imx_ipu_coredev __initdata;
  27. struct platform_device *__init imx_add_ipu_core(
  28. const struct imx_ipu_core_data *data)
  29. {
  30. /* The resource order is important! */
  31. struct resource res[] = {
  32. {
  33. .start = data->iobase,
  34. .end = data->iobase + 0x5f,
  35. .flags = IORESOURCE_MEM,
  36. }, {
  37. .start = data->iobase + 0x88,
  38. .end = data->iobase + 0xb3,
  39. .flags = IORESOURCE_MEM,
  40. }, {
  41. .start = data->synirq,
  42. .end = data->synirq,
  43. .flags = IORESOURCE_IRQ,
  44. }, {
  45. .start = data->errirq,
  46. .end = data->errirq,
  47. .flags = IORESOURCE_IRQ,
  48. },
  49. };
  50. return imx_ipu_coredev = imx_add_platform_device("ipu-core", -1,
  51. res, ARRAY_SIZE(res), NULL, 0);
  52. }
  53. struct platform_device *__init imx_alloc_mx3_camera(
  54. const struct imx_ipu_core_data *data,
  55. const struct mx3_camera_pdata *pdata)
  56. {
  57. struct resource res[] = {
  58. {
  59. .start = data->iobase + 0x60,
  60. .end = data->iobase + 0x87,
  61. .flags = IORESOURCE_MEM,
  62. },
  63. };
  64. int ret = -ENOMEM;
  65. struct platform_device *pdev;
  66. if (IS_ERR_OR_NULL(imx_ipu_coredev))
  67. return ERR_PTR(-ENODEV);
  68. pdev = platform_device_alloc("mx3-camera", 0);
  69. if (!pdev)
  70. return ERR_PTR(-ENOMEM);
  71. pdev->dev.dma_mask = kmalloc(sizeof(*pdev->dev.dma_mask), GFP_KERNEL);
  72. if (!pdev->dev.dma_mask)
  73. goto err;
  74. *pdev->dev.dma_mask = DMA_BIT_MASK(32);
  75. pdev->dev.coherent_dma_mask = DMA_BIT_MASK(32);
  76. ret = platform_device_add_resources(pdev, res, ARRAY_SIZE(res));
  77. if (ret)
  78. goto err;
  79. if (pdata) {
  80. struct mx3_camera_pdata *copied_pdata;
  81. ret = platform_device_add_data(pdev, pdata, sizeof(*pdata));
  82. if (ret) {
  83. err:
  84. kfree(pdev->dev.dma_mask);
  85. platform_device_put(pdev);
  86. return ERR_PTR(-ENODEV);
  87. }
  88. copied_pdata = dev_get_platdata(&pdev->dev);
  89. copied_pdata->dma_dev = &imx_ipu_coredev->dev;
  90. }
  91. return pdev;
  92. }
  93. struct platform_device *__init imx_add_mx3_sdc_fb(
  94. const struct imx_ipu_core_data *data,
  95. struct mx3fb_platform_data *pdata)
  96. {
  97. struct resource res[] = {
  98. {
  99. .start = data->iobase + 0xb4,
  100. .end = data->iobase + 0x1bf,
  101. .flags = IORESOURCE_MEM,
  102. },
  103. };
  104. if (IS_ERR_OR_NULL(imx_ipu_coredev))
  105. return ERR_PTR(-ENODEV);
  106. pdata->dma_dev = &imx_ipu_coredev->dev;
  107. return imx_add_platform_device_dmamask("mx3_sdc_fb", -1,
  108. res, ARRAY_SIZE(res), pdata, sizeof(*pdata),
  109. DMA_BIT_MASK(32));
  110. }