s5p-dev-mfc.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. /*
  2. * Copyright (C) 2010-2011 Samsung Electronics Co.Ltd
  3. *
  4. * Base S5P MFC resource and device definitions
  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/kernel.h>
  11. #include <linux/interrupt.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/dma-mapping.h>
  14. #include <linux/memblock.h>
  15. #include <linux/ioport.h>
  16. #include <linux/of_fdt.h>
  17. #include <linux/of.h>
  18. #include <plat/mfc.h>
  19. #ifdef CONFIG_SAMSUNG_ATAGS
  20. #include <mach/map.h>
  21. #include <mach/irqs.h>
  22. #include <plat/devs.h>
  23. static struct resource s5p_mfc_resource[] = {
  24. [0] = DEFINE_RES_MEM(S5P_PA_MFC, SZ_64K),
  25. [1] = DEFINE_RES_IRQ(IRQ_MFC),
  26. };
  27. struct platform_device s5p_device_mfc = {
  28. .name = "s5p-mfc",
  29. .id = -1,
  30. .num_resources = ARRAY_SIZE(s5p_mfc_resource),
  31. .resource = s5p_mfc_resource,
  32. };
  33. /*
  34. * MFC hardware has 2 memory interfaces which are modelled as two separate
  35. * platform devices to let dma-mapping distinguish between them.
  36. *
  37. * MFC parent device (s5p_device_mfc) must be registered before memory
  38. * interface specific devices (s5p_device_mfc_l and s5p_device_mfc_r).
  39. */
  40. struct platform_device s5p_device_mfc_l = {
  41. .name = "s5p-mfc-l",
  42. .id = -1,
  43. .dev = {
  44. .parent = &s5p_device_mfc.dev,
  45. .dma_mask = &s5p_device_mfc_l.dev.coherent_dma_mask,
  46. .coherent_dma_mask = DMA_BIT_MASK(32),
  47. },
  48. };
  49. struct platform_device s5p_device_mfc_r = {
  50. .name = "s5p-mfc-r",
  51. .id = -1,
  52. .dev = {
  53. .parent = &s5p_device_mfc.dev,
  54. .dma_mask = &s5p_device_mfc_r.dev.coherent_dma_mask,
  55. .coherent_dma_mask = DMA_BIT_MASK(32),
  56. },
  57. };
  58. #else
  59. static struct platform_device s5p_device_mfc_l;
  60. static struct platform_device s5p_device_mfc_r;
  61. #endif
  62. struct s5p_mfc_reserved_mem {
  63. phys_addr_t base;
  64. unsigned long size;
  65. struct device *dev;
  66. };
  67. static struct s5p_mfc_reserved_mem s5p_mfc_mem[2] __initdata;
  68. void __init s5p_mfc_reserve_mem(phys_addr_t rbase, unsigned int rsize,
  69. phys_addr_t lbase, unsigned int lsize)
  70. {
  71. int i;
  72. s5p_mfc_mem[0].dev = &s5p_device_mfc_r.dev;
  73. s5p_mfc_mem[0].base = rbase;
  74. s5p_mfc_mem[0].size = rsize;
  75. s5p_mfc_mem[1].dev = &s5p_device_mfc_l.dev;
  76. s5p_mfc_mem[1].base = lbase;
  77. s5p_mfc_mem[1].size = lsize;
  78. for (i = 0; i < ARRAY_SIZE(s5p_mfc_mem); i++) {
  79. struct s5p_mfc_reserved_mem *area = &s5p_mfc_mem[i];
  80. if (memblock_remove(area->base, area->size)) {
  81. printk(KERN_ERR "Failed to reserve memory for MFC device (%ld bytes at 0x%08lx)\n",
  82. area->size, (unsigned long) area->base);
  83. area->base = 0;
  84. }
  85. }
  86. }
  87. #ifdef CONFIG_SAMSUNG_ATAGS
  88. static int __init s5p_mfc_memory_init(void)
  89. {
  90. int i;
  91. for (i = 0; i < ARRAY_SIZE(s5p_mfc_mem); i++) {
  92. struct s5p_mfc_reserved_mem *area = &s5p_mfc_mem[i];
  93. if (!area->base)
  94. continue;
  95. if (dma_declare_coherent_memory(area->dev, area->base,
  96. area->base, area->size,
  97. DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) == 0)
  98. printk(KERN_ERR "Failed to declare coherent memory for MFC device (%ld bytes at 0x%08lx)\n",
  99. area->size, (unsigned long) area->base);
  100. }
  101. return 0;
  102. }
  103. device_initcall(s5p_mfc_memory_init);
  104. #endif
  105. #ifdef CONFIG_OF
  106. int __init s5p_fdt_find_mfc_mem(unsigned long node, const char *uname,
  107. int depth, void *data)
  108. {
  109. __be32 *prop;
  110. unsigned long len;
  111. struct s5p_mfc_dt_meminfo *mfc_mem = data;
  112. if (!data)
  113. return 0;
  114. if (!of_flat_dt_is_compatible(node, mfc_mem->compatible))
  115. return 0;
  116. prop = of_get_flat_dt_prop(node, "samsung,mfc-l", &len);
  117. if (!prop || (len != 2 * sizeof(unsigned long)))
  118. return 0;
  119. mfc_mem->loff = be32_to_cpu(prop[0]);
  120. mfc_mem->lsize = be32_to_cpu(prop[1]);
  121. prop = of_get_flat_dt_prop(node, "samsung,mfc-r", &len);
  122. if (!prop || (len != 2 * sizeof(unsigned long)))
  123. return 0;
  124. mfc_mem->roff = be32_to_cpu(prop[0]);
  125. mfc_mem->rsize = be32_to_cpu(prop[1]);
  126. return 1;
  127. }
  128. #endif