s5p-dev-mfc.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 <plat/devs.h>
  20. #include <plat/irqs.h>
  21. #include <plat/mfc.h>
  22. struct s5p_mfc_reserved_mem {
  23. phys_addr_t base;
  24. unsigned long size;
  25. struct device *dev;
  26. };
  27. static struct s5p_mfc_reserved_mem s5p_mfc_mem[2] __initdata;
  28. void __init s5p_mfc_reserve_mem(phys_addr_t rbase, unsigned int rsize,
  29. phys_addr_t lbase, unsigned int lsize)
  30. {
  31. int i;
  32. s5p_mfc_mem[0].dev = &s5p_device_mfc_r.dev;
  33. s5p_mfc_mem[0].base = rbase;
  34. s5p_mfc_mem[0].size = rsize;
  35. s5p_mfc_mem[1].dev = &s5p_device_mfc_l.dev;
  36. s5p_mfc_mem[1].base = lbase;
  37. s5p_mfc_mem[1].size = lsize;
  38. for (i = 0; i < ARRAY_SIZE(s5p_mfc_mem); i++) {
  39. struct s5p_mfc_reserved_mem *area = &s5p_mfc_mem[i];
  40. if (memblock_remove(area->base, area->size)) {
  41. printk(KERN_ERR "Failed to reserve memory for MFC device (%ld bytes at 0x%08lx)\n",
  42. area->size, (unsigned long) area->base);
  43. area->base = 0;
  44. }
  45. }
  46. }
  47. static int __init s5p_mfc_memory_init(void)
  48. {
  49. int i;
  50. for (i = 0; i < ARRAY_SIZE(s5p_mfc_mem); i++) {
  51. struct s5p_mfc_reserved_mem *area = &s5p_mfc_mem[i];
  52. if (!area->base)
  53. continue;
  54. if (dma_declare_coherent_memory(area->dev, area->base,
  55. area->base, area->size,
  56. DMA_MEMORY_MAP | DMA_MEMORY_EXCLUSIVE) == 0)
  57. printk(KERN_ERR "Failed to declare coherent memory for MFC device (%ld bytes at 0x%08lx)\n",
  58. area->size, (unsigned long) area->base);
  59. }
  60. return 0;
  61. }
  62. device_initcall(s5p_mfc_memory_init);
  63. #ifdef CONFIG_OF
  64. int __init s5p_fdt_find_mfc_mem(unsigned long node, const char *uname,
  65. int depth, void *data)
  66. {
  67. __be32 *prop;
  68. unsigned long len;
  69. struct s5p_mfc_dt_meminfo *mfc_mem = data;
  70. if (!data)
  71. return 0;
  72. if (!of_flat_dt_is_compatible(node, mfc_mem->compatible))
  73. return 0;
  74. prop = of_get_flat_dt_prop(node, "samsung,mfc-l", &len);
  75. if (!prop || (len != 2 * sizeof(unsigned long)))
  76. return 0;
  77. mfc_mem->loff = be32_to_cpu(prop[0]);
  78. mfc_mem->lsize = be32_to_cpu(prop[1]);
  79. prop = of_get_flat_dt_prop(node, "samsung,mfc-r", &len);
  80. if (!prop || (len != 2 * sizeof(unsigned long)))
  81. return 0;
  82. mfc_mem->roff = be32_to_cpu(prop[0]);
  83. mfc_mem->rsize = be32_to_cpu(prop[1]);
  84. return 1;
  85. }
  86. #endif