s5p-dev-mfc.c 3.6 KB

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